v3-subgraph icon indicating copy to clipboard operation
v3-subgraph copied to clipboard

fix decimal overflow issue

Open DyT9qC opened this issue 1 year ago • 7 comments

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.

DyT9qC avatar Jan 27 '24 04:01 DyT9qC

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

All Uniswap subgraphs are down because of this

sogipec avatar Jan 29 '24 14:01 sogipec

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

brianluong avatar Jan 30 '24 17:01 brianluong

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?

RitzyDevBox avatar Feb 02 '24 01:02 RitzyDevBox

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

GuillaumeNervoXS avatar Feb 02 '24 10:02 GuillaumeNervoXS

Everything the same on then than the addresses

On Fri, Feb 2, 2024, 5:08 AM gs8nrv @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/Uniswap/v3-subgraph/pull/194#issuecomment-1923481329, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYR4EL653NX6NZNCNZVUPZDYRS3JDAVCNFSM6AAAAABCNCCKDGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRTGQ4DCMZSHE . You are receiving this because you commented.Message ID: @.***>

RitzyDevBox avatar Feb 02 '24 17:02 RitzyDevBox

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 avatar Apr 09 '24 19:04 paymog

seems that https://github.com/Uniswap/v3-subgraph/pull/206 fixed this

paymog avatar Apr 09 '24 19:04 paymog