Skip to content

Commit 2ec6cc0

Browse files
d4mrjoaquim-verges
andauthored
[SDK] Feature: Allow forcing deploy/skip_deploy behaviour (#6361)
Co-authored-by: Joaquim Verges <joaquim.verges@gmail.com>
1 parent 28392b4 commit 2ec6cc0

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { prepareContractCall } from "../../../transaction/prepare-contract-call.
88
import type { PreparedTransaction } from "../../../transaction/prepare-transaction.js";
99
import { readContract } from "../../../transaction/read-contract.js";
1010
import { isHex, stringToHex } from "../../../utils/encoding/hex.js";
11+
import { withCache } from "../../../utils/promise/withCache.js";
1112
import type { SendTransactionOption } from "../../interfaces/wallet.js";
1213
import { DEFAULT_ACCOUNT_FACTORY_V0_6 } from "./constants.js";
1314

@@ -90,15 +91,23 @@ export async function predictAddress(args: {
9091
"Account address is required to predict the smart wallet address.",
9192
);
9293
}
93-
const saltHex =
94-
accountSalt && isHex(accountSalt)
95-
? accountSalt
96-
: stringToHex(accountSalt ?? "");
97-
return readContract({
98-
contract: factoryContract,
99-
method: "function getAddress(address, bytes) returns (address)",
100-
params: [adminAddress, saltHex],
101-
});
94+
return withCache(
95+
async () => {
96+
const saltHex =
97+
accountSalt && isHex(accountSalt)
98+
? accountSalt
99+
: stringToHex(accountSalt ?? "");
100+
return readContract({
101+
contract: factoryContract,
102+
method: "function getAddress(address, bytes) returns (address)",
103+
params: [adminAddress, saltHex],
104+
});
105+
},
106+
{
107+
cacheKey: `${args.factoryContract.chain.id}-${args.factoryContract.address}-${args.adminAddress}-${args.accountSalt}`,
108+
cacheTime: 1000 * 60 * 60 * 24, // 1 day
109+
},
110+
);
102111
}
103112

104113
/**

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export async function createUnsignedUserOp(args: {
136136
adminAddress: string;
137137
sponsorGas: boolean;
138138
waitForDeployment?: boolean;
139+
isDeployedOverride?: boolean;
139140
overrides?: SmartWalletOptions["overrides"];
140141
}): Promise<UserOperationV06 | UserOperationV07> {
141142
const {
@@ -146,6 +147,7 @@ export async function createUnsignedUserOp(args: {
146147
overrides,
147148
sponsorGas,
148149
waitForDeployment = true,
150+
isDeployedOverride,
149151
} = args;
150152
const chain = executeTx.chain;
151153
const client = executeTx.client;
@@ -163,7 +165,11 @@ export async function createUnsignedUserOp(args: {
163165

164166
const [isDeployed, callData, callGasLimit, gasFees, nonce] =
165167
await Promise.all([
166-
isContractDeployed(accountContract),
168+
typeof isDeployedOverride === "boolean"
169+
? isDeployedOverride
170+
: isContractDeployed(accountContract).then(
171+
(isDeployed) => isDeployed || isAccountDeploying(accountContract),
172+
),
167173
encode(executeTx),
168174
resolvePromisedValue(executeTx.gas),
169175
getGasFees({
@@ -299,7 +305,7 @@ async function populateUserOp_v0_7(args: {
299305

300306
let factory: string | undefined;
301307
let factoryData: Hex;
302-
if (isDeployed || isAccountDeploying(accountContract)) {
308+
if (isDeployed) {
303309
factoryData = "0x";
304310
if (waitForDeployment) {
305311
// lock until account is deployed if needed to avoid 'sender already created' errors when sending multiple transactions in parallel
@@ -462,7 +468,7 @@ async function populateUserOp_v0_6(args: {
462468
const { chain, client } = bundlerOptions;
463469
let initCode: Hex;
464470

465-
if (isDeployed || isAccountDeploying(accountContract)) {
471+
if (isDeployed) {
466472
initCode = "0x";
467473
if (waitForDeployment) {
468474
// lock until account is deployed if needed to avoid 'sender already created' errors when sending multiple transactions in parallel
@@ -699,6 +705,7 @@ export async function createAndSignUserOp(options: {
699705
client: ThirdwebClient;
700706
smartWalletOptions: SmartWalletOptions;
701707
waitForDeployment?: boolean;
708+
isDeployedOverride?: boolean;
702709
}) {
703710
const config = options.smartWalletOptions;
704711
const factoryContract = getContract({
@@ -757,6 +764,7 @@ export async function createAndSignUserOp(options: {
757764
sponsorGas: "sponsorGas" in config ? config.sponsorGas : config.gasless,
758765
overrides: config.overrides,
759766
waitForDeployment: options.waitForDeployment,
767+
isDeployedOverride: options.isDeployedOverride,
760768
});
761769
const signedUserOp = await signUserOp({
762770
client: options.client,

0 commit comments

Comments
 (0)