Skip to content

Commit a37e16b

Browse files
fix isAccountDeploying logic
1 parent 9858781 commit a37e16b

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

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

Lines changed: 36 additions & 27 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

@@ -72,33 +73,41 @@ export async function predictAddress(args: {
7273
accountSalt?: string;
7374
accountAddress?: string;
7475
}): Promise<string> {
75-
const {
76-
factoryContract,
77-
predictAddressOverride: predictAddress,
78-
adminAddress,
79-
accountSalt,
80-
accountAddress,
81-
} = args;
82-
if (predictAddress) {
83-
return predictAddress(factoryContract, adminAddress);
84-
}
85-
if (accountAddress) {
86-
return accountAddress;
87-
}
88-
if (!adminAddress) {
89-
throw new Error(
90-
"Account address is required to predict the smart wallet address.",
91-
);
92-
}
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-
});
76+
return withCache(
77+
async () => {
78+
const {
79+
factoryContract,
80+
predictAddressOverride: predictAddress,
81+
adminAddress,
82+
accountSalt,
83+
accountAddress,
84+
} = args;
85+
if (predictAddress) {
86+
return predictAddress(factoryContract, adminAddress);
87+
}
88+
if (accountAddress) {
89+
return accountAddress;
90+
}
91+
if (!adminAddress) {
92+
throw new Error(
93+
"Account address is required to predict the smart wallet address.",
94+
);
95+
}
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.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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ export async function createUnsignedUserOp(args: {
167167
await Promise.all([
168168
typeof isDeployedOverride === "boolean"
169169
? isDeployedOverride
170-
: isContractDeployed(accountContract) ||
171-
isAccountDeploying(accountContract),
170+
: isContractDeployed(accountContract).then(
171+
(isDeployed) => isDeployed || isAccountDeploying(accountContract),
172+
),
172173
encode(executeTx),
173174
resolvePromisedValue(executeTx.gas),
174175
getGasFees({

0 commit comments

Comments
 (0)