Skip to content
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

[Balance] useBalance Viem symbol parsing error propagation (string -> bytes32) #4353

Open
1 task done
odcey opened this issue Oct 21, 2024 · 1 comment
Open
1 task done

Comments

@odcey
Copy link

odcey commented Oct 21, 2024

Check existing issues

Describe the bug

Reading the MKR balance on Ethereum is not possible
getBalance is trying to read symbol as a string instead of bytes32

Apparently there's a catch handling this here: https://github.com/wevm/wagmi/blob/main/packages/core/src/actions/getBalance.ts#L69
but we're never reaching this catch block that is supposed to format using bytes32 instead of string

Error sample:

Viem seems to be throwing the right error though.
This is the error type we get if we listen to onError(error) of useBalance on wagmi side

useBalance.ts:48 ContractFunctionExecutionError: Position `3.496116881397033e+76` is out of bounds (`0 < position < 32`).

Contract Call:
  address:   0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2
  function:  symbol()

Docs: https://viem.sh/docs/contract/readContract
Version: viem@2.21.32
    at getContractError (getContractError.js:34:12)
    at readContract (readContract.js:67:98)
    at async Promise.all (:3001/index 2)
    at async readContracts (readContracts.js:50:17)
    at async getTokenBalance (getBalance.js:83:39)
    at async Object.queryFn (getBalance.js:16:29)Caused by: PositionOutOfBoundsError: Position `3.496116881397033e+76` is out of bounds (`0 < position < 32`).

Version: viem@2.21.32
    at Object.assertPosition (cursor.js:23:19)
    at Object.setPosition (cursor.js:154:14)
    at decodeString (decodeAbiParameters.js:226:12)
    at decodeParameter (decodeAbiParameters.js:66:16)
    at decodeAbiParameters (decodeAbiParameters.js:41:35)
    at decodeFunctionResult (decodeFunctionResult.js:25:96)
    at readContract (readContract.js:59:104)
    at async Promise.all (:3001/index 2)
    at async readContracts (readContracts.js:50:17)
    at async getTokenBalance (getBalance.js:83:39)
    at async Object.queryFn (getBalance.js:16:29)

Link to Minimal Reproducible Example

No response

Steps To Reproduce

To replicate

Try to fetch MKR balance on Ethereum using useBalance
Viem will fail to read the symbol as string, should propagate an error that will be handled by wagmi, then retry formatting the symbol as bytes32, but code isn't reaching that catch block

link to contract symbol: https://etherscan.io/address/0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2#readContract#F7
value failed to be parsed: 0x4d4b520000000000000000000000000000000000000000000000000000000000

What Wagmi package(s) are you using?

@wagmi/core

Versions

"@wagmi/core": "2.13.8",
"wagmi": "2.12.20",
"viem": "2.21.32",

@jxom
Copy link
Member

jxom commented Oct 21, 2024

Why is MKR returning bytes32 instead of a string? This means it does not follow the ERC20 spec: https://eips.ethereum.org/EIPS/eip-20#symbol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants