Skip to content

Commit

Permalink
fix isAccountDeploying logic
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges committed Feb 27, 2025
1 parent 9858781 commit a37e16b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
63 changes: 36 additions & 27 deletions packages/thirdweb/src/wallets/smart/lib/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { prepareContractCall } from "../../../transaction/prepare-contract-call.
import type { PreparedTransaction } from "../../../transaction/prepare-transaction.js";
import { readContract } from "../../../transaction/read-contract.js";
import { isHex, stringToHex } from "../../../utils/encoding/hex.js";
import { withCache } from "../../../utils/promise/withCache.js";
import type { SendTransactionOption } from "../../interfaces/wallet.js";
import { DEFAULT_ACCOUNT_FACTORY_V0_6 } from "./constants.js";

Expand Down Expand Up @@ -72,33 +73,41 @@ export async function predictAddress(args: {
accountSalt?: string;
accountAddress?: string;
}): Promise<string> {
const {
factoryContract,
predictAddressOverride: predictAddress,
adminAddress,
accountSalt,
accountAddress,
} = args;
if (predictAddress) {
return predictAddress(factoryContract, adminAddress);
}
if (accountAddress) {
return accountAddress;
}
if (!adminAddress) {
throw new Error(
"Account address is required to predict the smart wallet address.",
);
}
const saltHex =
accountSalt && isHex(accountSalt)
? accountSalt
: stringToHex(accountSalt ?? "");
return readContract({
contract: factoryContract,
method: "function getAddress(address, bytes) returns (address)",
params: [adminAddress, saltHex],
});
return withCache(
async () => {
const {
factoryContract,
predictAddressOverride: predictAddress,
adminAddress,
accountSalt,
accountAddress,
} = args;
if (predictAddress) {
return predictAddress(factoryContract, adminAddress);
}
if (accountAddress) {
return accountAddress;
}
if (!adminAddress) {
throw new Error(
"Account address is required to predict the smart wallet address.",
);
}
const saltHex =
accountSalt && isHex(accountSalt)
? accountSalt
: stringToHex(accountSalt ?? "");
return readContract({
contract: factoryContract,
method: "function getAddress(address, bytes) returns (address)",
params: [adminAddress, saltHex],
});
},
{
cacheKey: `${args.factoryContract.address}-${args.adminAddress}-${args.accountSalt}`,
cacheTime: 1000 * 60 * 60 * 24, // 1 day
},
);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions packages/thirdweb/src/wallets/smart/lib/userop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ export async function createUnsignedUserOp(args: {
await Promise.all([
typeof isDeployedOverride === "boolean"
? isDeployedOverride
: isContractDeployed(accountContract) ||
isAccountDeploying(accountContract),
: isContractDeployed(accountContract).then(
(isDeployed) => isDeployed || isAccountDeploying(accountContract),
),
encode(executeTx),
resolvePromisedValue(executeTx.gas),
getGasFees({
Expand Down

0 comments on commit a37e16b

Please sign in to comment.