Uniswap / v3-subgraph

Subgraph for Uniswap V3
GNU General Public License v3.0
338 stars 464 forks source link

fix decimal overflow issue #194

Open DyT9qC opened 7 months ago

DyT9qC commented 7 months ago

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 commented 7 months ago

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

All Uniswap subgraphs are down because of this

brianluong commented 7 months ago

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

RitzyDevBox commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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: @.***>

paymog commented 5 months ago

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 commented 5 months ago

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