@@ -8,6 +8,7 @@ import { prepareContractCall } from "../../../transaction/prepare-contract-call.
88import type { PreparedTransaction } from "../../../transaction/prepare-transaction.js" ;
99import { readContract } from "../../../transaction/read-contract.js" ;
1010import { isHex , stringToHex } from "../../../utils/encoding/hex.js" ;
11+ import { withCache } from "../../../utils/promise/withCache.js" ;
1112import type { SendTransactionOption } from "../../interfaces/wallet.js" ;
1213import { 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/**
0 commit comments