Skip to content

Commit f618c53

Browse files
[SDK] Handle entrypoint resolution inside createAndSignUserOp (#6615)
1 parent 04943d7 commit f618c53

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

.changeset/eight-pants-help.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
handle entrypoint resolution inside createAndSignUserOp

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { keccak256 } from "../../../utils/hashing/keccak256.js";
2323
import { stringify } from "../../../utils/json.js";
2424
import { resolvePromisedValue } from "../../../utils/promise/resolve-promised-value.js";
2525
import type { Account } from "../../interfaces/wallet.js";
26+
import { getEntrypointFromFactory } from "../index.js";
2627
import type {
2728
BundlerOptions,
2829
PaymasterResult,
@@ -749,6 +750,23 @@ export async function createAndSignUserOp(options: {
749750
waitForDeployment?: boolean;
750751
isDeployedOverride?: boolean;
751752
}) {
753+
// if factory is passed, but no entrypoint, try to resolve entrypoint from factory
754+
if (
755+
options.smartWalletOptions.factoryAddress &&
756+
!options.smartWalletOptions.overrides?.entrypointAddress
757+
) {
758+
const entrypointAddress = await getEntrypointFromFactory(
759+
options.smartWalletOptions.factoryAddress,
760+
options.client,
761+
options.smartWalletOptions.chain,
762+
);
763+
if (entrypointAddress) {
764+
options.smartWalletOptions.overrides = {
765+
...options.smartWalletOptions.overrides,
766+
entrypointAddress,
767+
};
768+
}
769+
}
752770
const unsignedUserOp = await prepareUserOp({
753771
transactions: options.transactions,
754772
adminAccount: options.adminAccount,

packages/thirdweb/src/wallets/smart/smart-wallet-integration-v07.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
confirmContractDeployment,
3434
deploySmartAccount,
3535
} from "./lib/signing.js";
36+
import { createAndSignUserOp } from "./lib/userop.js";
3637
import { smartWallet } from "./smart-wallet.js";
3738

3839
let wallet: Wallet;
@@ -363,5 +364,25 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
363364
isDeployed = await isContractDeployed(newSmartAccountContract);
364365
expect(isDeployed).toEqual(true);
365366
});
367+
368+
it("can prep a 0.7 userop", async () => {
369+
const tx = prepareTransaction({
370+
client,
371+
chain,
372+
to: smartAccount.address,
373+
value: 0n,
374+
});
375+
const uo = await createAndSignUserOp({
376+
transactions: [tx],
377+
adminAccount: personalAccount,
378+
client: TEST_CLIENT,
379+
smartWalletOptions: {
380+
chain,
381+
sponsorGas: true,
382+
factoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_7,
383+
},
384+
});
385+
expect(uo.callData.length).toBeGreaterThan(0);
386+
});
366387
},
367388
);

0 commit comments

Comments
 (0)