-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(world): dedupe functions in getWorldAbi result #3025
Conversation
|
can you fill in the PR description about why this is important to do? Unclear if the side effects of duplicate entries (and seems intended given solidity supports overloads) |
Definitely, solidity overloads should be taken into account but ABI should contain no duplicates imo. Included change description. |
thinking about another approach where, instead of deduplicating an ABI as a whole, we just construct to the world a bit differently for our use case, starting with the base ABI (since it has named params) and add the functions registered on the world that we haven't seen yet (using function selectors as the "key" for uniqueness check, since its ultimately what is called) const baseFunctionSelectors = IBaseWorldAbi.filter(isAbiFunction).map(toFunctionSelector);
const worldFunctionsAbi = worldFunctions
.map((func) => functionSignatureToAbiItem(`function ${func.signature}`))
.filter((abiItem) => !baseFunctionSelectors.includes(toFunctionSelector(abiItem)));
const worldAbi = [
...IBaseWorldAbi,
...worldFunctionsAbi,
]; |
I ended up liking this approach more too, somehow feels more clean. Only renamed the function to |
…ticexyz/mud into kumpis/deduplicate-world-abi
@@ -20,7 +24,10 @@ export async function getWorldAbi({ | |||
fromBlock, | |||
toBlock, | |||
}); | |||
const worldFunctionsAbi = worldFunctions.map((func) => functionSignatureToAbiItem(func.signature)); | |||
const baseFunctionSelectors = (IBaseWorldAbi as Abi).filter(isAbiFunction).map(toFunctionSelector); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is as Abi
casting necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without it, even with type predicate, typescript fails to recognize in the .map(..)
that it's of type AbiFunction
packages/world/ts/getWorldAbi.ts
Outdated
const baseFunctionSelectors = (IBaseWorldAbi as Abi).filter(isAbiFunction).map(toFunctionSelector); | ||
const worldFunctionsAbi = worldFunctions | ||
.map((func) => functionSignatureToAbiItem(func.signature)) | ||
.filter((abiItem) => !baseFunctionSelectors.includes(toFunctionSelector(abiItem as AbiFunction))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could prob improve the return type of functionSignatureToAbiItem
so we don't have to cast this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted to return AbiFunction
but in order for that to work, have to ensure that it indeed returns function ABI item, otherwise the function throws. Not sure how else to handle it
Dynamically fetched ABI from a deployed world returns user-created custom functions along with default world methods such as
batchCall
. However, it is not able to fetch system methods such assetField
that should also be included in the final ABI for completion.To include all system methods, the dynamically fetched ABI is concatenated with statically generated World's ABI, resulting in some duplicated functions.
deduplicateABI
removes all the duplicate functions, and in case a duplicate is encountered, favors the ABI item that has named imports (i.e. statically generated World ABI), so that the ABI contains as much information as possible. Inexplorer
case, for example, it's helpful to see the function parameter names when interacting with various functions.