diff --git a/src/factory/providers/zksync-era/syncswap/classicPoolAbi.json b/src/constants/abi/syncswapClassicPoolAbi.json similarity index 100% rename from src/factory/providers/zksync-era/syncswap/classicPoolAbi.json rename to src/constants/abi/syncswapClassicPoolAbi.json diff --git a/src/factory/providers/zksync-era/eralend/index.ts b/src/factory/providers/zksync-era/eralend/index.ts index 3ffffd80..ca05eb58 100644 --- a/src/factory/providers/zksync-era/eralend/index.ts +++ b/src/factory/providers/zksync-era/eralend/index.ts @@ -1,6 +1,8 @@ +import BigNumber from 'bignumber.js'; import formatter from '../../../../util/formatter'; import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; import unitroller from '../../../../util/calculators/unitroller'; +import util from '../../../../util/blockchainUtil'; const START_BLOCK = 561367; const ERALEND_CONTRACT = '0x0171cA5b372eb510245F5FA214F5582911934b3D'; @@ -11,7 +13,7 @@ async function tvl(params: ITvlParams): Promise> { return { balances: {} }; } - const balances = await unitroller.getTvl( + let balances = await unitroller.getTvl( [ERALEND_CONTRACT], block, chain, @@ -19,6 +21,19 @@ async function tvl(params: ITvlParams): Promise> { web3, ); + const tokenBalances = {}; + Object.keys(balances).forEach(function (key) { + tokenBalances[key] = BigNumber(balances[key]); + }); + + balances = await util.convertToUnderlyings( + tokenBalances, + block, + chain, + provider, + web3, + ); + formatter.convertBalancesToFixed(balances); return { balances }; diff --git a/src/factory/providers/zksync-era/syncswap/index.ts b/src/factory/providers/zksync-era/syncswap/index.ts index 335da3ca..a184d677 100644 --- a/src/factory/providers/zksync-era/syncswap/index.ts +++ b/src/factory/providers/zksync-era/syncswap/index.ts @@ -3,7 +3,7 @@ import util from '../../../../util/blockchainUtil'; import basicUtil from '../../../../util/basicUtil'; import formatter from '../../../../util/formatter'; import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; -import CLASSIC_POOL_ABI from './classicPoolAbi.json'; +import CLASSIC_POOL_ABI from '../../../../constants/abi/syncswapClassicPoolAbi.json'; const START_BLOCK = 9775; const FACTORIES = [ diff --git a/src/util/blockchainUtil.ts b/src/util/blockchainUtil.ts index ab2a55a5..92485018 100644 --- a/src/util/blockchainUtil.ts +++ b/src/util/blockchainUtil.ts @@ -4,6 +4,7 @@ import { AbiItem } from 'web3-utils'; import { request, gql } from 'graphql-request'; import ERC20_ABI from '../constants/abi/erc20.json'; import UNI_ABI from '../constants/abi/uni.json'; +import SYNCSWAP_CLASSIC_POOL_ABI from '../constants/abi/syncswapClassicPoolAbi.json'; import CURVE128_ABI from '../constants/abi/curve128.json'; import CURVE256_ABI from '../constants/abi/curve.json'; import ONEINCH_ABI from '../constants/abi/1inch.json'; @@ -1094,8 +1095,19 @@ async function GetUnderlyingBalance( const ratio = balance.div(totalSupply); try { - const contract = new web3.eth.Contract(UNI_ABI as AbiItem[], token); - const reserves = await contract.methods.getReserves().call(null, block); + let contract; + let reserves; + try { + contract = new web3.eth.Contract(UNI_ABI as AbiItem[], token); + reserves = await contract.methods.getReserves().call(null, block); + } catch (e) { + contract = new web3.eth.Contract( + SYNCSWAP_CLASSIC_POOL_ABI as AbiItem[], + token, + ); + reserves = await contract.methods.getReserves().call(null, block); + } + if (!underlyingData[key].token0) { underlyingData[key].token0 = ( await contract.methods.token0().call()