Skip to content

Commit 265a111

Browse files
refrence working with overrides
1 parent 67f2544 commit 265a111

File tree

3 files changed

+54
-17
lines changed

3 files changed

+54
-17
lines changed

packages/thirdweb/src/wallets/smart/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
type TypedData,
44
type TypedDataDefinition,
55
type TypedDataDomain,
6+
encodePacked,
67
hashTypedData,
78
maxUint96,
89
} from "viem";
@@ -354,9 +355,9 @@ async function createSmartAccount(
354355
});
355356
if (isModularFactory) {
356357
// add validator address
357-
sig = encodeAbiParameters(
358-
[{ type: "address" }, { type: "bytes" }],
359-
[ZERO_ADDRESS, sig],
358+
sig = encodePacked(
359+
["address", "bytes"],
360+
["0x6DF8ea6FF6Ca55f367CDA45510CA40dC78993DEC", sig],
360361
);
361362
}
362363
} else {

packages/thirdweb/src/wallets/smart/lib/userop.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type { PreparedTransaction } from "../../../transaction/prepare-transacti
1616
import type { TransactionReceipt } from "../../../transaction/types.js";
1717
import { encodeAbiParameters } from "../../../utils/abi/encodeAbiParameters.js";
1818
import { isContractDeployed } from "../../../utils/bytecode/is-contract-deployed.js";
19-
import { type Hex, toHex } from "../../../utils/encoding/hex.js";
19+
import type { Hex } from "../../../utils/encoding/hex.js";
2020
import { hexToBytes } from "../../../utils/encoding/to-bytes.js";
2121
import { isThirdwebUrl } from "../../../utils/fetch.js";
2222
import { resolvePromisedValue } from "../../../utils/promise/resolve-promised-value.js";
@@ -435,7 +435,7 @@ async function populateUserOp_v0_6(args: {
435435
sponsorGas: boolean;
436436
overrides?: SmartWalletOptions["overrides"];
437437
isDeployed: boolean;
438-
nonce: bigint;
438+
nonce: bigint | Hex;
439439
callData: Hex;
440440
callGasLimit?: bigint;
441441
maxFeePerGas: bigint;
@@ -651,7 +651,7 @@ async function getAccountNonce(options: {
651651
client: ThirdwebClient;
652652
entrypointAddress?: string;
653653
getNonceOverride?: (accountContract: ThirdwebContract) => Promise<bigint>;
654-
}) {
654+
}): Promise<bigint> {
655655
const {
656656
accountContract,
657657
chain,
@@ -662,7 +662,7 @@ async function getAccountNonce(options: {
662662
if (getNonceOverride) {
663663
return getNonceOverride(accountContract);
664664
}
665-
const nonce = await getNonce({
665+
return await getNonce({
666666
contract: getContract({
667667
address: entrypointAddress || ENTRYPOINT_ADDRESS_v0_6,
668668
chain,
@@ -671,11 +671,6 @@ async function getAccountNonce(options: {
671671
key: generateRandomUint192(),
672672
sender: accountContract.address,
673673
});
674-
// FIXME - only for modular accounts to pass validator in
675-
const withValidator = `0x${"0".repeat(40)}${toHex(nonce).slice(42)}`;
676-
console.log("withValidator", withValidator);
677-
console.log("withValidator", withValidator.length);
678-
return withValidator;
679674
}
680675

681676
/**

packages/thirdweb/src/wallets/smart/smart-wallet-modular.test.ts

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
import { Hex } from "ox";
2+
import { encodePacked, stringToHex, toHex } from "viem";
13
import { beforeAll, describe, expect, it } from "vitest";
24
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
35
import { TEST_ACCOUNT_A } from "../../../test/src/test-wallets.js";
46
import { baseSepolia } from "../../chains/chain-definitions/base-sepolia.js";
7+
import { ZERO_ADDRESS } from "../../constants/addresses.js";
58
import { type ThirdwebContract, getContract } from "../../contract/contract.js";
9+
import { getNonce } from "../../extensions/erc4337/__generated__/IEntryPoint/read/getNonce.js";
610
import { encodeSingleInitMSA } from "../../extensions/erc7579/__generated__/Bootstrap/write/singleInitMSA.js";
11+
import { execute } from "../../extensions/erc7579/__generated__/IERC7579Account/write/execute.js";
712
import { sendTransaction } from "../../transaction/actions/send-transaction.js";
813
import { prepareContractCall } from "../../transaction/prepare-contract-call.js";
914
import { prepareTransaction } from "../../transaction/prepare-transaction.js";
@@ -14,6 +19,7 @@ import { isContractDeployed } from "../../utils/bytecode/is-contract-deployed.js
1419
import { keccak256 } from "../../utils/hashing/keccak256.js";
1520
import type { Account, Wallet } from "../interfaces/wallet.js";
1621
import { ENTRYPOINT_ADDRESS_v0_7 } from "./lib/constants.js";
22+
import { generateRandomUint192 } from "./lib/utils.js";
1723
import { smartWallet } from "./smart-wallet.js";
1824
let wallet: Wallet;
1925
let smartAccount: Account;
@@ -38,6 +44,7 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
3844
// personalAccount = await generateAccount({
3945
// client,
4046
// });
47+
const VALIDATOR_ADDRESS = "0x6DF8ea6FF6Ca55f367CDA45510CA40dC78993DEC";
4148
wallet = smartWallet({
4249
chain,
4350
gasless: true,
@@ -53,9 +60,9 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
5360
encodeAbiParameters(
5461
[{ type: "address" }, { type: "bytes" }],
5562
[
56-
"0x1E919660050C68BFEf868945Cf5f9a26ad7E360b", // bootstrap
63+
"0xedd4503de72bac321dfeb65f1373d2def17403fc", // bootstrap
5764
encodeSingleInitMSA({
58-
validator: "0x11D02847245Df7cF19f48C8907ace59289D8aCEe", // mock validator
65+
validator: VALIDATOR_ADDRESS, // simple validator
5966
data: "0x",
6067
}),
6168
],
@@ -73,16 +80,50 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
7380
encodeAbiParameters(
7481
[{ type: "address" }, { type: "bytes" }],
7582
[
76-
"0x1E919660050C68BFEf868945Cf5f9a26ad7E360b", // bootstrap
83+
"0xedd4503de72bac321dfeb65f1373d2def17403fc", // bootstrap
7784
encodeSingleInitMSA({
78-
validator: "0x11D02847245Df7cF19f48C8907ace59289D8aCEe", // mock validator
85+
validator: VALIDATOR_ADDRESS, // simple validator
7986
data: "0x",
8087
}),
8188
],
8289
),
8390
],
8491
});
8592
},
93+
execute(accountContract, transaction) {
94+
return execute({
95+
contract: accountContract,
96+
async asyncParams() {
97+
return {
98+
mode: stringToHex("", { size: 32 }), // single execution
99+
executionCalldata: encodePacked(
100+
["address", "uint256", "bytes"],
101+
[
102+
transaction.to || ZERO_ADDRESS,
103+
transaction.value || 0n,
104+
transaction.data || "0x",
105+
],
106+
),
107+
};
108+
},
109+
});
110+
},
111+
async getAccountNonce(accountContract) {
112+
const nonce = await getNonce({
113+
contract: getContract({
114+
address: ENTRYPOINT_ADDRESS_v0_7,
115+
chain,
116+
client,
117+
}),
118+
key: generateRandomUint192(),
119+
sender: accountContract.address,
120+
});
121+
// FIXME - only for modular accounts to pass validator in
122+
const withValidator = `${VALIDATOR_ADDRESS}${toHex(nonce).slice(42)}`;
123+
console.log("DEBUG withValidator", withValidator);
124+
console.log("DEBUG withValidator", withValidator.length);
125+
return Hex.toBigInt(withValidator as Hex.Hex);
126+
},
86127
},
87128
});
88129
smartAccount = await wallet.connect({
@@ -101,7 +142,7 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
101142
expect(smartWalletAddress).toHaveLength(42);
102143

103144
// const d = decodeErrorResult({
104-
// data: "0xb927fe5e0000000000000000000000000000000000000000db72e07d8a92f3d9d30e3843",
145+
// data: "0x48c9cedab61d27f600000000000000000000000000000000000000000000000000000000",
105146
// abi: await resolveContractAbi({
106147
// address: smartWalletAddress,
107148
// client,

0 commit comments

Comments
 (0)