From c21dedb611618c80aabd7dcf5cbf4a90d31e835b Mon Sep 17 00:00:00 2001 From: Mantas S Date: Thu, 14 Sep 2023 14:38:27 +0300 Subject: [PATCH 1/2] eralend fix --- .../abi/syncswapClassicPoolAbi.json} | 0 .../providers/zksync-era/eralend/index.ts | 17 +++++++++++++++- .../providers/zksync-era/syncswap/index.ts | 2 +- src/util/blockchainUtil.ts | 20 +++++++++++++++++-- 4 files changed, 35 insertions(+), 4 deletions(-) rename src/{factory/providers/zksync-era/syncswap/classicPoolAbi.json => constants/abi/syncswapClassicPoolAbi.json} (100%) 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..a7642e12 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,23 @@ 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) { + if ((chain = 'zksync-era')) { + contract = new web3.eth.Contract( + SYNCSWAP_CLASSIC_POOL_ABI as AbiItem[], + token, + ); + reserves = await contract.methods.getReserves().call(null, block); + } else { + throw e; + } + } + if (!underlyingData[key].token0) { underlyingData[key].token0 = ( await contract.methods.token0().call() From 6bd042ed88560faf078cca3eb44d886996e82e65 Mon Sep 17 00:00:00 2001 From: Mantas S Date: Thu, 14 Sep 2023 15:13:50 +0300 Subject: [PATCH 2/2] Update blockchainUtil.ts --- src/util/blockchainUtil.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/util/blockchainUtil.ts b/src/util/blockchainUtil.ts index a7642e12..92485018 100644 --- a/src/util/blockchainUtil.ts +++ b/src/util/blockchainUtil.ts @@ -1101,15 +1101,11 @@ async function GetUnderlyingBalance( contract = new web3.eth.Contract(UNI_ABI as AbiItem[], token); reserves = await contract.methods.getReserves().call(null, block); } catch (e) { - if ((chain = 'zksync-era')) { - contract = new web3.eth.Contract( - SYNCSWAP_CLASSIC_POOL_ABI as AbiItem[], - token, - ); - reserves = await contract.methods.getReserves().call(null, block); - } else { - throw 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) {