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

fix decimal overflow issue #194

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

fix decimal overflow issue #194

wants to merge 1 commit into from

Conversation

DyT9qC
Copy link

@DyT9qC DyT9qC commented Jan 27, 2024

Problem Scenario:

When the indexer attempts to call try_decimals(), if the decimal value exceeds uint8, the following error message will be triggered:

Mapping aborted at ~lib/@graphprotocol/graph-ts/common/collections.ts, line 150, column 9, with message: overflow converting 0x0000000000000000000000000000000000000000000000000000000067e53c31 to i32\twasm backtrace:\t 0: 0x3ddd - <unknown>!~lib/@graphprotocol/graph-ts/chain/ethereum/ethereum.Value#toI32\t 1: 0x3ed9 - <unknown>!src/types/Factory/ERC20/ERC20#try_decimals

Fix Solution:

Check if the decimal value is of type int or uint, and verify whether it is less than the maximum value of uint8. If both conditions are met, return the correct value; otherwise, return null.

@sogipec
Copy link

sogipec commented Jan 29, 2024

Pretty important PR, would be cool to have it merged.

All Uniswap subgraphs are down because of this

@brianluong
Copy link

Our uniswap subgraphs are failed on multiple chains. Would greatly appreciate this fix 🙏

@RitzyDevBox
Copy link

Are you sure this works?

I'm getting build errors when trying to use this PR.

decimalResult.value.kind == Ethereum.ValueKind.INT

Property kind does not exist in type ethereum.Value.

Is this branch dependent on a specific version in the package.lock?

@GuillaumeNervoXS
Copy link

GuillaumeNervoXS commented Feb 2, 2024

I

Are you sure this works?

I'm getting build errors when trying to use this PR.

decimalResult.value.kind == Ethereum.ValueKind.INT

Property kind does not exist in type ethereum.Value.

Is this branch dependent on a specific version in the package.lock?

It is because you are on a different package version, you need to downgrade the apiVersion in your subgraph.yaml file

@RitzyDevBox
Copy link

RitzyDevBox commented Feb 2, 2024 via email

@paymog
Copy link

paymog commented Apr 9, 2024

I checked out the proposal, installed packages, ran codegen and tried building but I'm getting issues

⠋ Compile subgraphERROR TS2339: Property 'kind' does not exist on type '~lib/array/Array<~lib/@graphprotocol/graph-ts/chain/ethereum/ethereum.Value>'.

     if (decimalResult.value.kind == ethereum.ValueKind.INT || decimalResult.value.kind == ethereum.ValueKind.UINT) {
                             ~~~~
 in src/utils/token.ts(81,28)

ERROR TS2339: Property 'kind' does not exist on type '~lib/array/Array<~lib/@graphprotocol/graph-ts/chain/ethereum/ethereum.Value>'.

     if (decimalResult.value.kind == ethereum.ValueKind.INT || decimalResult.value.kind == ethereum.ValueKind.UINT) {
                                                                                   ~~~~
 in src/utils/token.ts(81,82)

ERROR TS2339: Property 'kind' does not exist on type '~lib/array/Array<~lib/@graphprotocol/graph-ts/chain/ethereum/ethereum.Value>'.

     if (decimalResult.value.kind == ethereum.ValueKind.INT || decimalResult.value.kind == ethereum.ValueKind.UINT) {
                             ~~~~
 in src/utils/token.ts(81,28)

ERROR TS2339: Property 'kind' does not exist on type '~lib/array/Array<~lib/@graphprotocol/graph-ts/chain/ethereum/ethereum.Value>'.

     if (decimalResult.value.kind == ethereum.ValueKind.INT || decimalResult.value.kind == ethereum.ValueKind.UINT) {
                                                                                   ~~~~
 in src/utils/token.ts(81,82)

ERROR TS2339: Property 'toBigInt' does not exist on type '~lib/array/Array<~lib/@graphprotocol/graph-ts/chain/ethereum/ethereum.Value>'.

       if (decimalResult.value.toBigInt().le(BigInt.fromI32(255))) {
                               ~~~~~~~~
 in src/utils/token.ts(83,30)

ERROR TS2339: Property 'toBigInt' does not exist on type '~lib/array/Array<~lib/@graphprotocol/graph-ts/chain/ethereum/ethereum.Value>'.

       if (decimalResult.value.toBigInt().le(BigInt.fromI32(255))) {
                               ~~~~~~~~
 in src/utils/token.ts(83,30)

ERROR AS200: Conversion from type '~lib/array/Array<~lib/@graphprotocol/graph-ts/chain/ethereum/ethereum.Value>' to 'usize' requires an explicit cast.

         decimalValue = decimalResult.value
                        ~~~~~~~~~~~~~~~~~~~
 in src/utils/token.ts(84,23)

✖ Failed to compile subgraph: Failed to compile data source mapping: Compile error
Error: Failed to compile data source mapping: Compile error
    at Compiler._compileDataSourceMapping (/Users/paymahn/code/goldsky/DyT9qC-uniswap-v3/node_modules/@graphprotocol/graph-cli/src/compiler.js:312:13)
    at /Users/paymahn/code/goldsky/DyT9qC-uniswap-v3/node_modules/@graphprotocol/graph-cli/src/compiler.js:206:20
    at updateInDeepMap (/Users/paymahn/code/goldsky/DyT9qC-uniswap-v3/node_modules/immutable/dist/immutable.js:1971:22)
    at updateInDeepMap (/Users/paymahn/code/goldsky/DyT9qC-uniswap-v3/node_modules/immutable/dist/immutable.js:1980:23)
    at updateInDeepMap (/Users/paymahn/code/goldsky/DyT9qC-uniswap-v3/node_modules/immutable/dist/immutable.js:1980:23)
    at Map.updateIn (/Users/paymahn/code/goldsky/DyT9qC-uniswap-v3/node_modules/immutable/dist/immutable.js:1278:26)
    at /Users/paymahn/code/goldsky/DyT9qC-uniswap-v3/node_modules/@graphprotocol/graph-cli/src/compiler.js:205:24
    at /Users/paymahn/code/goldsky/DyT9qC-uniswap-v3/node_modules/immutable/dist/immutable.js:3016:46
    at List.__iterate (/Users/paymahn/code/goldsky/DyT9qC-uniswap-v3/node_modules/immutable/dist/immutable.js:2206:13)
    at mappedSequence.__iterateUncached (/Users/paymahn/code/goldsky/DyT9qC-uniswap-v3/node_modules/immutable/dist/immutable.js:3015:23)
error Command failed with exit code 1.

@paymog
Copy link

paymog commented Apr 9, 2024

seems that #206 fixed this

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

Successfully merging this pull request may close these issues.

6 participants