tradingstrategy-ai / web3-ethereum-defi

A Python library for trading automation on DeFi, data research and integration. Supporting Uniswap, Aave, Chainlink, USDC and other protocols.
https://tradingstrategy.ai
MIT License
591 stars 127 forks source link

More selective number → string conversion in `fetch_aave_reserves_shapshot` #148

Closed kenkunz closed 1 year ago

kenkunz commented 1 year ago

Issue

The fetch_aave_reserves_shapshot function converts all numeric values to strings. This conflicts with the type expectations of the @aave/math-utils module.

Details

The output from fetch_aave_reserves_shapshot is made available to frontend via the lending-reserve/details API. frontend needs to convert this data into human-readable USD values using @aave/math-utils.

When calling the formatReserveUSD function from the @aave package, the following error occurs:

Error: [BigNumber Error] Argument not a primitive number: 18

This is due to the decimals value being "18" (string) instead of 18 (number). The @aave/math-utils conversion functions fail when the wrong type is supplied.

Reviewing the ReserveData interface defined by @aave/math-utils, it appears the following properties should preserve the number type:

Other numeric values are expected to be strings in order to retain precision.

kenkunz commented 1 year ago

Per discussion at backlog meeting and on discord, we will address this by converting to the right type on frontend.