11import { type Abi , formatAbi , parseAbi } from "abitype" ;
22import { download } from "../../storage/download.js" ;
3+ import { LruMap } from "../../utils/caching/lru.js" ;
34import { getClientFetch } from "../../utils/fetch.js" ;
45import { type ThirdwebContract , getContract } from "../contract.js" ;
56
6- const ABI_RESOLUTION_CACHE = new WeakMap < ThirdwebContract < Abi > , Promise < Abi > > ( ) ;
7+ const ABI_RESOLUTION_CACHE = new LruMap < Promise < Abi > > ( 1000 ) ;
78
89/**
910 * Resolves the ABI (Application Binary Interface) for a given contract.
@@ -32,8 +33,9 @@ export function resolveContractAbi<abi extends Abi>(
3233 contract : ThirdwebContract < abi > ,
3334 contractApiBaseUrl = "https://contract.thirdweb.com/abi" ,
3435) : Promise < abi > {
35- if ( ABI_RESOLUTION_CACHE . has ( contract ) ) {
36- return ABI_RESOLUTION_CACHE . get ( contract ) as Promise < abi > ;
36+ const key = `${ contract . chain . id } -${ contract . address } ` ;
37+ if ( ABI_RESOLUTION_CACHE . has ( key ) ) {
38+ return ABI_RESOLUTION_CACHE . get ( key ) as Promise < abi > ;
3739 }
3840
3941 const prom = ( async ( ) => {
@@ -55,7 +57,7 @@ export function resolveContractAbi<abi extends Abi>(
5557 return await resolveCompositeAbi ( contract as ThirdwebContract ) ;
5658 }
5759 } ) ( ) ;
58- ABI_RESOLUTION_CACHE . set ( contract , prom ) ;
60+ ABI_RESOLUTION_CACHE . set ( key , prom ) ;
5961 return prom as Promise < abi > ;
6062}
6163
0 commit comments