Repository navigation
fix: read ERC-20 token details on chains without multicall3 - #1535
Open
selimaytac wants to merge 1 commit into
Open
selimaytac wants to merge 1 commit into
selimaytac wants to merge 1 commit into
Conversation
🟡 Heimdall Review Status
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #1533.
getTokenDetails()(erc20) readsname,decimalsandbalanceOfwithpublicClient.multicall(). On chains whose viem definition has nocontracts.multicall3(viem'sfoundrychain for a local Anvil, custom chains), viem throwsChainDoesNotSupportContractbefore sending any request, thecatchturns it intonull, andget_balance,transfer,approveandget_allowancealways answer "Could not fetch token details".With this change, when
multicall()throwsChainDoesNotSupportContract, the three values are read with plainreadContractcalls instead. Chains with Multicall3 keep the single multicall request, and any other error is handled as before (null). The error is matched by itsnamerather thaninstanceof, so it also works when the public client comes from another viem copy.Scope: this PR only adds the fallback. Surfacing the underlying error in the action output, the second point in the issue, changes what
getTokenDetailsreturns, and the erc20 actions andbaseAccountdepend on that, so I left it for a follow-up if you want it. The other helpers that multicall (cdp/swapUtils.ts,zeroX/utils.ts,truemarkets) only run on networks those services support, which all have Multicall3, so they are unchanged.Tests
Unit tests (
erc20ActionProvider.test.ts, Get Balance Action):ChainDoesNotSupportContractthe token is read with threereadContractcalls and the balance is returned (fails without the fix, passes with it)readContractis not called)jest src/action-providers/erc20 src/action-providers/baseAccount: 52 passed;eslint,prettierandtsc --noEmitcleanNo chatbot run; instead the repro from #1533 against a local Anvil, with the built package. Note: the repro in the issue builds
ViemWalletProviderwithoutrpcUrl, so its public client uses the chain's default RPC (port 8545) instead of the Anvil on 18545. That does not change the diagnosis (the multicall error is thrown before any request), but the fallback needs a reachable RPC, so for this run the provider is built as:Checklist