Skip to content

Commit

Permalink
Merge pull request #205 from dappradar/eralend-fix
Browse files Browse the repository at this point in the history
eralend fix
  • Loading branch information
mantasfam authored Sep 14, 2023
2 parents 196306f + 6bd042e commit 9af71db
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
17 changes: 16 additions & 1 deletion src/factory/providers/zksync-era/eralend/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -11,14 +13,27 @@ async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> {
return { balances: {} };
}

const balances = await unitroller.getTvl(
let balances = await unitroller.getTvl(
[ERALEND_CONTRACT],
block,
chain,
provider,
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 };
Expand Down
2 changes: 1 addition & 1 deletion src/factory/providers/zksync-era/syncswap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
16 changes: 14 additions & 2 deletions src/util/blockchainUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 9af71db

Please sign in to comment.