diff --git a/.changeset/afraid-regions-push.md b/.changeset/afraid-regions-push.md new file mode 100644 index 00000000000..8355fa89e90 --- /dev/null +++ b/.changeset/afraid-regions-push.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Resolve implementation from contract call diff --git a/packages/thirdweb/src/utils/bytecode/resolveImplementation.ts b/packages/thirdweb/src/utils/bytecode/resolveImplementation.ts index e2ab742fc53..afb9566ea66 100644 --- a/packages/thirdweb/src/utils/bytecode/resolveImplementation.ts +++ b/packages/thirdweb/src/utils/bytecode/resolveImplementation.ts @@ -47,8 +47,6 @@ export async function resolveImplementation( } // check other proxy types - let implementationAddress: string | undefined; - if (beacon && beacon !== AddressZero) { // In case of a BeaconProxy, it is setup as BeaconProxy --> Beacon --> Implementation // Hence we replace the proxy address with Beacon address, and continue further resolving below @@ -56,33 +54,36 @@ export async function resolveImplementation( ...contract, address: beacon, }); - - implementationAddress = await getImplementationFromContractCall(contract); - } else { - implementationAddress = await getImplementationFromStorageSlot(contract); } - if ( - implementationAddress && - isAddress(implementationAddress) && - implementationAddress !== AddressZero - ) { - const implementationBytecode = await getBytecode({ - ...contract, - address: implementationAddress, - }); - // return the original contract bytecode if the implementation bytecode is empty - if (implementationBytecode === "0x") { + const implementations = await Promise.all([ + getImplementationFromStorageSlot(contract), + getImplementationFromContractCall(contract), + ]); + + for (const implementationAddress of implementations) { + if ( + implementationAddress && + isAddress(implementationAddress) && + implementationAddress !== AddressZero + ) { + const implementationBytecode = await getBytecode({ + ...contract, + address: implementationAddress, + }); + // return the original contract bytecode if the implementation bytecode is empty + if (implementationBytecode === "0x") { + return { + address: contract.address, + bytecode: originalBytecode, + }; + } + return { - address: contract.address, - bytecode: originalBytecode, + address: implementationAddress, + bytecode: implementationBytecode, }; } - - return { - address: implementationAddress, - bytecode: implementationBytecode, - }; } return { address: contract.address, bytecode: originalBytecode };