Skip to content

Commit 8ec681a

Browse files
Add parameter to override wallet's owner
1 parent 0307ffc commit 8ec681a

File tree

4 files changed

+109
-39
lines changed

4 files changed

+109
-39
lines changed

scripts/biconomy-migration/02-deploy-test-passport-wallet.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,22 @@ async function deployTestPassportWallet() {
4646
// ============================================================================
4747

4848
const [deployer] = await ethers.getSigners();
49-
console.log(`\n👤 Test Wallet Owner: ${deployer.address}`);
49+
50+
// Option to use a different wallet owner (to avoid address collision)
51+
// If you want a different address, create a new wallet and set MIGRATION_TEST_OWNER_PK in .env
52+
let walletOwner = deployer;
53+
54+
const customOwnerPk = process.env.MIGRATION_TEST_OWNER_PK;
55+
if (customOwnerPk) {
56+
walletOwner = new ethers.Wallet(customOwnerPk, ethers.provider);
57+
console.log("\n⚠️ Using custom owner from MIGRATION_TEST_OWNER_PK");
58+
}
59+
60+
console.log(`\n👤 Test Wallet Owner: ${walletOwner.address}`);
61+
console.log(`👤 Deployer (for funding): ${deployer.address}`);
5062

5163
const balance = await deployer.getBalance();
52-
console.log(`💰 Owner Balance: ${ethers.utils.formatEther(balance)} ETH\n`);
64+
console.log(`💰 Deployer Balance: ${ethers.utils.formatEther(balance)} ETH\n`);
5365

5466
if (balance.lt(ethers.utils.parseEther("0.01"))) {
5567
throw new Error("Insufficient balance for deployment (need at least 0.01 ETH)");
@@ -64,7 +76,7 @@ async function deployTestPassportWallet() {
6476
owners: [
6577
{
6678
weight: 1,
67-
address: deployer.address,
79+
address: walletOwner.address,
6880
}
6981
],
7082
};
@@ -138,13 +150,13 @@ async function deployTestPassportWallet() {
138150
delegateCall: false,
139151
revertOnError: true,
140152
gasLimit: ethers.BigNumber.from(200000), // 200K gas for simple transfer
141-
target: deployer.address, // Transfer back to deployer
153+
target: walletOwner.address, // Transfer to owner (not deployer)
142154
value: ethers.utils.parseEther("0.0001"), // 0.0001 ETH
143155
data: new Uint8Array([]), // Empty data for simple transfer
144156
},
145157
];
146158

147-
console.log(` Transaction: ETH transfer to ${deployer.address}`);
159+
console.log(` Transaction: ETH transfer to ${walletOwner.address}`);
148160
console.log(` Amount: 0.0001 ETH\n`);
149161
console.log("=".repeat(80));
150162

@@ -162,7 +174,7 @@ async function deployTestPassportWallet() {
162174

163175
// Sign with wallet owner
164176
const signature = await walletMultiSign(
165-
[{ weight: walletConfig.threshold, owner: deployer }],
177+
[{ weight: walletConfig.threshold, owner: walletOwner }],
166178
walletConfig.threshold,
167179
data
168180
);
@@ -256,7 +268,7 @@ async function deployTestPassportWallet() {
256268
timestamp: new Date().toISOString(),
257269
network: "base_sepolia",
258270
walletAddress: cfa,
259-
owner: deployer.address,
271+
owner: walletOwner.address,
260272
imageHash: salt,
261273
implementationAddress,
262274
deploymentTx: deployTx.hash,
@@ -278,7 +290,7 @@ async function deployTestPassportWallet() {
278290
console.log("\n🎉 TEST WALLET DEPLOYED SUCCESSFULLY!\n");
279291
console.log("📋 Summary:");
280292
console.log(` Address: ${cfa}`);
281-
console.log(` Owner: ${deployer.address}`);
293+
console.log(` Owner: ${walletOwner.address}`);
282294
console.log(` Implementation: ${implementationAddress}`);
283295
console.log(` Balance: ${ethers.utils.formatEther(walletBalance)} ETH`);
284296
console.log(` TX Hash: ${deployTx.hash}\n`);

scripts/biconomy-migration/03-migrate-passport-to-nexus.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ async function migratePassportToNexus() {
6161
const biconomyDeploymentPath = path.join(__dirname, "../biconomy/base-sepolia-deployment.json");
6262
const biconomyDeployment = JSON.parse(fs.readFileSync(biconomyDeploymentPath, "utf8"));
6363

64-
const nexusImplementation = biconomyDeployment.contracts.nexus.address;
65-
const nexusBootstrap = biconomyDeployment.contracts.nexusBootstrap.address;
66-
const k1Validator = "0x0000000031ef4155C978d48a8A7d4EDba03b04fE"; // MEE K1 Validator v1.0.3
64+
// Use Nexus v1.2.1 (experimental/deployed by us, but identical to official experimental)
65+
const nexusImplementation = ethers.utils.getAddress("0x0E12B6ED74b95aFEc6dc578Dc0b29292C0A95c90"); // v1.2.1 (experimental)
66+
const nexusFactory = ethers.utils.getAddress("0xDB1D73d8c7e8D50F760083449390b1D4080108dF"); // Factory (experimental)
67+
68+
// Use OFFICIAL Bootstrap & Validator
69+
const nexusBootstrap = ethers.utils.getAddress("0x0000003eDf18913c01cBc482C978bBD3D6E8ffA3"); // OFFICIAL Bootstrap v1.2.1
70+
const k1Validator = ethers.utils.getAddress("0x0000000031ef4155C978d48a8A7d4EDba03b04fE"); // OFFICIAL K1 Validator v1.0.3
6771

6872
console.log("\n📋 Migration Targets:");
6973
console.log("-".repeat(80));
@@ -76,21 +80,29 @@ async function migratePassportToNexus() {
7680
// CONNECT TO WALLET
7781
// ============================================================================
7882

79-
const [signer] = await ethers.getSigners();
83+
// Support custom owner (same as script 02)
84+
let signer = deployer;
85+
const customOwnerPk = process.env.MIGRATION_TEST_OWNER_PK;
86+
if (customOwnerPk) {
87+
signer = new ethers.Wallet(customOwnerPk, ethers.provider);
88+
console.log("\n⚠️ Using custom owner from MIGRATION_TEST_OWNER_PK");
89+
}
8090

8191
if (signer.address.toLowerCase() !== owner.toLowerCase()) {
8292
throw new Error(
83-
`Signer mismatch! Expected ${owner}, got ${signer.address}`
93+
`Signer mismatch! Expected ${owner}, got ${signer.address}. Make sure MIGRATION_TEST_OWNER_PK matches the wallet owner.`
8494
);
8595
}
8696

8797
console.log(`\n👤 Connected as: ${signer.address}`);
98+
console.log(`👤 Deployer (for gas): ${deployer.address}`);
8899

89-
const balance = await signer.getBalance();
90-
console.log(`💰 Balance: ${ethers.utils.formatEther(balance)} ETH\n`);
100+
// Check deployer balance (will pay for gas)
101+
const deployerBalance = await deployer.getBalance();
102+
console.log(`💰 Deployer Balance: ${ethers.utils.formatEther(deployerBalance)} ETH\n`);
91103

92-
if (balance.lt(ethers.utils.parseEther("0.001"))) {
93-
throw new Error("Insufficient balance for migration (need at least 0.001 ETH)");
104+
if (deployerBalance.lt(ethers.utils.parseEther("0.001"))) {
105+
throw new Error("Insufficient deployer balance for migration (need at least 0.001 ETH)");
94106
}
95107

96108
// Connect to wallet as MainModuleDynamicAuth
@@ -177,15 +189,15 @@ async function migratePassportToNexus() {
177189

178190
const transactions = [
179191
{
180-
delegateCall: false,
192+
delegateCall: false, // MUST be FALSE! (regular call, not delegatecall)
181193
revertOnError: true,
182194
gasLimit: ethers.BigNumber.from(2000000),
183195
target: walletAddress, // Call wallet itself
184196
value: ethers.BigNumber.from(0),
185197
data: updateImplementationCalldata,
186198
},
187199
{
188-
delegateCall: false,
200+
delegateCall: false, // MUST be FALSE! (regular call, not delegatecall)
189201
revertOnError: true,
190202
gasLimit: ethers.BigNumber.from(2000000),
191203
target: walletAddress, // Call wallet itself
@@ -217,9 +229,9 @@ async function migratePassportToNexus() {
217229
const chainId = await ethers.provider.getNetwork().then((n) => n.chainId);
218230
const data = encodeMetaTransactionsData(walletAddress, transactions, chainId, nonce);
219231

220-
// Sign using walletMultiSign helper
232+
// Sign using walletMultiSign helper (MUST use signer, not deployer!)
221233
const formattedSignature = await walletMultiSign(
222-
[{ weight: 1, owner: deployer }],
234+
[{ weight: 1, owner: signer }],
223235
1,
224236
data
225237
);

scripts/biconomy-migration/04-test-with-biconomy-sdk.ts

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,20 @@ async function testWithBiconomySDK() {
5555

5656
console.log("\n⚙️ Setting up Viem client...");
5757

58-
// Get owner's private key from environment or hardhat
59-
const [hardhatSigner] = await ethers.getSigners();
60-
61-
if (hardhatSigner.address.toLowerCase() !== ownerAddress.toLowerCase()) {
62-
throw new Error(
63-
`Signer mismatch! Expected ${ownerAddress}, got ${hardhatSigner.address}`
64-
);
58+
// Support custom owner (same as scripts 02 and 03)
59+
let privateKeyRaw: string | undefined;
60+
61+
const customOwnerPk = process.env.MIGRATION_TEST_OWNER_PK;
62+
if (customOwnerPk) {
63+
privateKeyRaw = customOwnerPk;
64+
console.log(" ⚠️ Using custom owner from MIGRATION_TEST_OWNER_PK");
65+
} else {
66+
// Get private key from .env (same as used for deployment)
67+
privateKeyRaw = process.env.BASE_SEPOLIA_PRIVATE_KEY || process.env.COLD_WALLET_PRIVATE_KEY;
6568
}
6669

67-
// Get private key from .env (same as used for deployment)
68-
const privateKeyRaw = process.env.BASE_SEPOLIA_PRIVATE_KEY || process.env.COLD_WALLET_PRIVATE_KEY;
69-
7070
if (!privateKeyRaw) {
71-
throw new Error("BASE_SEPOLIA_PRIVATE_KEY or COLD_WALLET_PRIVATE_KEY not found in .env");
71+
throw new Error("MIGRATION_TEST_OWNER_PK, BASE_SEPOLIA_PRIVATE_KEY or COLD_WALLET_PRIVATE_KEY not found");
7272
}
7373

7474
// Ensure it has 0x prefix
@@ -77,6 +77,14 @@ async function testWithBiconomySDK() {
7777
const eoaAccount = privateKeyToAccount(privateKey as `0x${string}`);
7878

7979
console.log(` EOA: ${eoaAccount.address}`);
80+
81+
// Verify it matches the owner
82+
if (eoaAccount.address.toLowerCase() !== ownerAddress.toLowerCase()) {
83+
throw new Error(
84+
`Signer mismatch! Expected ${ownerAddress}, got ${eoaAccount.address}`
85+
);
86+
}
87+
8088
console.log(" ✅ Viem client configured\n");
8189
console.log("=".repeat(80));
8290

@@ -86,8 +94,8 @@ async function testWithBiconomySDK() {
8694

8795
console.log("\n🔗 Creating Nexus Account with Biconomy SDK...");
8896

89-
// Use MEE version v2.1.0 (matches our deployment)
90-
const version = MEEVersion.V2_1_0;
97+
// Use MEE version v2.2.0 (Experimental - matches our Nexus v1.2.1 deployment)
98+
const version = MEEVersion.V2_2_0;
9199
const versionConfig = getMEEVersion(version);
92100

93101
console.log(` MEE Version: ${version}`);
@@ -113,7 +121,29 @@ async function testWithBiconomySDK() {
113121
);
114122
}
115123

116-
console.log(" ✅ Address matches migrated wallet\n");
124+
console.log(" ✅ Address matches migrated wallet");
125+
126+
// Check account initialization using Nexus contract
127+
// NOTE: nexusAccount from SDK does NOT have an isInitialized() method
128+
// We need to call the Nexus contract directly using ethers.js
129+
const Nexus = await ethers.getContractFactory("Nexus");
130+
const nexusContract = Nexus.attach(walletAddress);
131+
132+
try {
133+
const isInitialized = await nexusContract.isInitialized();
134+
console.log(` Initialization: ${isInitialized ? "✅ YES" : "❌ NO"}`);
135+
136+
if (!isInitialized) {
137+
console.log(" ⚠️ Warning: Wallet is not initialized!");
138+
}
139+
} catch (error: any) {
140+
console.log(` ⚠️ Could not check initialization: ${error.message}`);
141+
}
142+
143+
// Check account ID from SDK
144+
console.log(` Account ID: ${nexusAccount.accountId}`);
145+
146+
console.log();
117147
console.log("=".repeat(80));
118148

119149
// ========================================================================
@@ -172,7 +202,7 @@ async function testWithBiconomySDK() {
172202
// Get current gas prices from provider
173203
const feeData = await provider.getFeeData();
174204
console.log(` ⛽ Max Fee Per Gas: ${ethers.utils.formatUnits(feeData.maxFeePerGas || 0, "gwei")} gwei`);
175-
console.log(` ⛽ Max Priority Fee: ${ethers.utils.formatUnits(feeData.maxPriorityFeePerGas || 0, "gwei")} gwei`);
205+
console.log(` ⛽ Max Priority Fee: ${ethers.utils.formatUnits(feeData.maxPriorityFeePerGas || 0, "gwei")} gwei\n`);
176206

177207
const userOpHash = await bundlerClient.sendUserOperation({
178208
calls: [
@@ -181,9 +211,6 @@ async function testWithBiconomySDK() {
181211
value: testAmount,
182212
},
183213
],
184-
// Provide gas parameters manually to avoid bundler gas estimation issues
185-
maxFeePerGas: BigInt(feeData.maxFeePerGas?.toString() || "1000000000"), // 1 gwei fallback
186-
maxPriorityFeePerGas: BigInt(feeData.maxPriorityFeePerGas?.toString() || "1000000000"), // 1 gwei fallback
187214
});
188215

189216
console.log(` ✅ UserOp submitted: ${userOpHash}\n`);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ethers } from "hardhat";
2+
3+
async function fundCustomOwner() {
4+
const [deployer] = await ethers.getSigners();
5+
const customOwner = "0xA2De953eD1AeBd64E29eb3C4ACce0367e70Ef778"; // NEW owner
6+
7+
console.log(`Funding ${customOwner} with 0.01 ETH for gas...`);
8+
9+
const tx = await deployer.sendTransaction({
10+
to: customOwner,
11+
value: ethers.utils.parseEther("0.01")
12+
});
13+
14+
await tx.wait();
15+
console.log(`✅ Done! TX: ${tx.hash}`);
16+
}
17+
18+
fundCustomOwner().catch(console.error);
19+

0 commit comments

Comments
 (0)