Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/afraid-regions-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Resolve implementation from contract call
49 changes: 25 additions & 24 deletions packages/thirdweb/src/utils/bytecode/resolveImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,42 +47,43 @@
}

// 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
contract = getContract({
...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,
};
}

Check warning on line 80 in packages/thirdweb/src/utils/bytecode/resolveImplementation.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/utils/bytecode/resolveImplementation.ts#L76-L80

Added lines #L76 - L80 were not covered by tests

return {
address: contract.address,
bytecode: originalBytecode,
address: implementationAddress,
bytecode: implementationBytecode,
};
}

return {
address: implementationAddress,
bytecode: implementationBytecode,
};
}

return { address: contract.address, bytecode: originalBytecode };
Expand Down
Loading