subgraphs icon indicating copy to clipboard operation
subgraphs copied to clipboard

ERROR TS2322: Type 'BigInt' is not assignable to type 'i32'

Open gosuto-inzasheru opened this issue 2 years ago • 3 comments

https://github.com/messari/subgraphs/blob/82b9b3849bfe170f11dc0c42bc250d11ed46ff9c/subgraphs/reference/src/sdk/protocols/lending/token.ts#L157-L162

returning decimalValue here for me results in:

ERROR TS2322: Type '~lib/@graphprotocol/graph-ts/common/numbers/BigInt' is not assignable to type 'i32'.

this has to do with the try_decimals returning BigInt in the generated ERC20.ts:

  try_decimals(): ethereum.CallResult<BigInt> {
    let result = super.tryCall("decimals", "decimals():(uint256)", []);
    if (result.reverted) {
      return new ethereum.CallResult();
    }
    let value = result.value;
    return ethereum.CallResult.fromValue(value[0].toBigInt());
  }

also ref abis/ERC20.json: https://github.com/messari/subgraphs/blob/82b9b3849bfe170f11dc0c42bc250d11ed46ff9c/subgraphs/reference/abis/ERC20.json#L81-L92

i quick fixed it with return decimalValue.toI32() but would love to know if that is sufficient and worth a pr or if i am missing something :)

gosuto-inzasheru avatar Jun 29 '23 12:06 gosuto-inzasheru

@gosuto-inzasheru I checked compound v3 which uses the exact same abi and token mappings as _reference_. I also used the latest graph npm packages. And I do not have any issues, here is a snippet of the autogened code:

  try_decimals(): ethereum.CallResult<i32> {
    let result = super.tryCall("decimals", "decimals():(uint8)", []);
    if (result.reverted) {
      return new ethereum.CallResult();
    }
    let value = result.value;
    return ethereum.CallResult.fromValue(value[0].toI32());
  }

Without seeing your source code it is hard for me to say right now what the exact issue is.

melotik avatar Jun 30 '23 18:06 melotik

so problem stems from the following discrepancy in outputs.type (i assumed both interfaces to be the same): https://github.com/messari/subgraphs/blob/1c99de5d01e89ed54918de8bef920d96c788d052/subgraphs/reference/abis/ERC20.json#L81-L92

and

https://github.com/messari/subgraphs/blob/1c99de5d01e89ed54918de8bef920d96c788d052/subgraphs/reference/abis/Prices/ERC20.json#L641-L646

gosuto-inzasheru avatar Jul 05 '23 20:07 gosuto-inzasheru

solution is therefore to introduce two separate interfaces for erc20 in the template:

        ...
        - name: _ERC20
          file: ./abis/Prices/ERC20.json
        - name: ERC20
          file: ./abis/ERC20.json
        ...

not sure if this is by design or if both interfaces could be consolidated

gosuto-inzasheru avatar Jul 05 '23 20:07 gosuto-inzasheru