Skip to content

Commit

Permalink
Resolve implementation update (#2300)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaryash90 authored Feb 12, 2024
1 parent ecd82b4 commit 94a699c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-walls-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/sdk": patch
---

Minimal proxy pattern update
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@ export function extractMinimalProxyImplementationAddress(
return `0x${implementationAddress}`;
}

if (bytecode.startsWith("0x36600080376020600036600073")) {
const implementationAddress = bytecode.slice(28, 28 + 40);
return `0x${implementationAddress}`;
}

return undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,28 @@ export async function resolveImplementation(
utils.isAddress(implementationAddress) &&
implementationAddress !== constants.AddressZero
) {
return {
address: implementationAddress,
bytecode: await fetchBytecode(implementationAddress, provider),
};
try {
const implBytecode = await fetchBytecode(
implementationAddress,
provider,
);
return {
address: implementationAddress,
bytecode: implBytecode,
};
} catch (e) {
if (e instanceof Error) {
// Ignore if fetchBytecode throws the error below, implying that bytecode is 0x.
// In that case we don't want to throw, and just return the original contract address and bytecode.
if (
!e.message.includes(
`Contract at ${implementationAddress} does not exist on chain`,
)
) {
throw e;
}
}
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions packages/sdk/test/evm/feature-detection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ describe("Feature Detection", async () => {
);
});

it("should extract implementation address for new minimal proxy pattern", async () => {
const code =
"0x36600080376020600036600073bebebebebebebebebebebebebebebebebebebebe6102c65a03f41515602d57fe5b60206000f3";
const implementationAddress =
extractMinimalProxyImplementationAddress(code);
expect(implementationAddress).to.equal(
"0xbebebebebebebebebebebebebebebebebebebebe",
);
});

it("should extract features", async () => {
let features = detectFeatures(TokenERC721__factory.abi);
expect(
Expand Down

0 comments on commit 94a699c

Please sign in to comment.