Skip to content

Commit 8c932bf

Browse files
refrence working with overrides
1 parent 826063c commit 8c932bf

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";
@@ -331,9 +332,9 @@ async function createSmartAccount(
331332
});
332333
if (isModularFactory) {
333334
// add validator address
334-
sig = encodeAbiParameters(
335-
[{ type: "address" }, { type: "bytes" }],
336-
[ZERO_ADDRESS, sig],
335+
sig = encodePacked(
336+
["address", "bytes"],
337+
["0x6DF8ea6FF6Ca55f367CDA45510CA40dC78993DEC", sig],
337338
);
338339
}
339340
} else {

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { toSerializableTransaction } from "../../../transaction/actions/to-seria
1414
import type { PreparedTransaction } from "../../../transaction/prepare-transaction.js";
1515
import type { TransactionReceipt } from "../../../transaction/types.js";
1616
import { isContractDeployed } from "../../../utils/bytecode/is-contract-deployed.js";
17-
import { type Hex, toHex } from "../../../utils/encoding/hex.js";
17+
import type { Hex } from "../../../utils/encoding/hex.js";
1818
import { hexToBytes } from "../../../utils/encoding/to-bytes.js";
1919
import { isThirdwebUrl } from "../../../utils/fetch.js";
2020
import { resolvePromisedValue } from "../../../utils/promise/resolve-promised-value.js";
@@ -412,7 +412,7 @@ async function populateUserOp_v0_6(args: {
412412
sponsorGas: boolean;
413413
overrides?: SmartWalletOptions["overrides"];
414414
isDeployed: boolean;
415-
nonce: bigint;
415+
nonce: bigint | Hex;
416416
callData: Hex;
417417
callGasLimit?: bigint;
418418
maxFeePerGas: bigint;
@@ -628,7 +628,7 @@ async function getAccountNonce(options: {
628628
client: ThirdwebClient;
629629
entrypointAddress?: string;
630630
getNonceOverride?: (accountContract: ThirdwebContract) => Promise<bigint>;
631-
}) {
631+
}): Promise<bigint> {
632632
const {
633633
accountContract,
634634
chain,
@@ -639,7 +639,7 @@ async function getAccountNonce(options: {
639639
if (getNonceOverride) {
640640
return getNonceOverride(accountContract);
641641
}
642-
const nonce = await getNonce({
642+
return await getNonce({
643643
contract: getContract({
644644
address: entrypointAddress || ENTRYPOINT_ADDRESS_v0_6,
645645
chain,
@@ -648,11 +648,6 @@ async function getAccountNonce(options: {
648648
key: generateRandomUint192(),
649649
sender: accountContract.address,
650650
});
651-
// FIXME - only for modular accounts to pass validator in
652-
const withValidator = `0x${"0".repeat(40)}${toHex(nonce).slice(42)}`;
653-
console.log("withValidator", withValidator);
654-
console.log("withValidator", withValidator.length);
655-
return withValidator;
656651
}
657652

658653
/**

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)