Skip to content

Commit 1133ccc

Browse files
fix: improve ABI resolution fallback (#4753)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on fixing ABI resolution fallback in `resolve-abi.ts`. ### Detailed summary - Removed unnecessary imports - Updated ABI resolution logic with new imports - Improved handling of root ABI merging - Enhanced efficiency in joining ABIs > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 3eef910 commit 1133ccc

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

.changeset/loud-beds-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix abi resolution fallback

packages/thirdweb/src/contract/actions/resolve-abi.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { type Abi, formatAbi, parseAbi } from "abitype";
2-
import { getInstalledModules } from "../../extensions/modules/__generated__/IModularCore/read/getInstalledModules.js";
32
import { download } from "../../storage/download.js";
4-
import { extractIPFSUri } from "../../utils/bytecode/extractIPFS.js";
53
import { getClientFetch } from "../../utils/fetch.js";
64
import type { ThirdwebContract } from "../contract.js";
7-
import { getBytecode } from "./get-bytecode.js";
85

96
const ABI_RESOLUTION_CACHE = new WeakMap<ThirdwebContract<Abi>, Promise<Abi>>();
107

@@ -117,7 +114,11 @@ export async function resolveAbiFromBytecode(
117114
// biome-ignore lint/suspicious/noExplicitAny: library function that accepts any contract type
118115
contract: ThirdwebContract<any>,
119116
): Promise<Abi> {
120-
const bytecode = await getBytecode(contract);
117+
const [{ resolveImplementation }, { extractIPFSUri }] = await Promise.all([
118+
import("../../utils/bytecode/resolveImplementation.js"),
119+
import("../../utils/bytecode/extractIPFS.js"),
120+
]);
121+
const { bytecode } = await resolveImplementation(contract);
121122
if (bytecode === "0x") {
122123
const { id, name } = contract.chain;
123124
throw new Error(
@@ -366,6 +367,9 @@ async function resolveModularModuleAddresses(
366367
contract: ThirdwebContract,
367368
): Promise<string[]> {
368369
try {
370+
const { getInstalledModules } = await import(
371+
"../../extensions/modules/__generated__/IModularCore/read/getInstalledModules.js"
372+
);
369373
const modules = await getInstalledModules({ contract });
370374
// if there are no plugins, return the root ABI
371375
if (!modules.length) {
@@ -434,14 +438,15 @@ function joinAbis(options: JoinAbisOptions): Abi {
434438
.filter((item) => item.type !== "constructor");
435439

436440
if (options.rootAbi) {
437-
mergedPlugins = [...(options.rootAbi || []), ...mergedPlugins].filter(
438-
Boolean,
439-
);
441+
mergedPlugins = [...options.rootAbi, ...mergedPlugins]
442+
.filter((item) => item.type !== "fallback" && item.type !== "receive")
443+
.filter(Boolean);
440444
}
441445

442446
// unique by formatting every abi and then throwing them in a set
443447
// TODO: this may not be super efficient...
444448
const humanReadableAbi = [...new Set(formatAbi(mergedPlugins))];
449+
445450
// finally parse it back out
446451
return parseAbi(humanReadableAbi);
447452
}

0 commit comments

Comments
 (0)