Skip to content

Commit

Permalink
Merge pull request #194 from dappradar/zksync-integrations
Browse files Browse the repository at this point in the history
Izumi
  • Loading branch information
mantasfam authored Aug 9, 2023
2 parents ed95124 + 548ca19 commit 95b35c9
Showing 1 changed file with 81 additions and 57 deletions.
138 changes: 81 additions & 57 deletions src/factory/providers/zksync-era/izumi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl';
import LIQUIDITY_MANAGER_ABI from './liquidityManagerAbi.json';

const START_BLOCK = 225074;
const LIQUIDITY_MANAGER_ADDRESS = '0x936c9a1b8f88bfdbd5066ad08e5d773bc82eb15f';
const LIQUIDITY_MANAGERS = [
{ address: '0x936c9a1b8f88bfdbd5066ad08e5d773bc82eb15f', startBlock: 225074 },
{
address: '0x483FDE31bcE3DCc168E23a870831b50Ce2cCd1F1',
startBlock: 8842006,
},
];

async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> {
const { block, chain, provider, web3 } = params;
Expand All @@ -14,70 +20,88 @@ async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> {
return { balances };
}

let pools = {};
try {
pools = await basicUtil.readFromCache('pools.json', chain, provider);
} catch {}
for (const liquidityManager of LIQUIDITY_MANAGERS) {
if (block >= liquidityManager.startBlock) {
let pools = {};
try {
pools = await basicUtil.readFromCache(
`${liquidityManager.address}_pools.json`,
chain,
provider,
);
} catch {}

while (true) {
const poolMetas = await util.executeMultiCallsOfTarget(
LIQUIDITY_MANAGER_ADDRESS,
LIQUIDITY_MANAGER_ABI,
'poolMetas',
Array.from({ length: 10 }, (v, index) => [
index + 1 + Object.keys(pools).length,
]),
block,
chain,
web3,
);
while (true) {
let exit = false;

let exit = false;
const poolMetas = await util.executeMultiCallsOfTarget(
liquidityManager.address,
LIQUIDITY_MANAGER_ABI,
'poolMetas',
Array.from({ length: 10 }, (v, index) => [
index + 1 + Object.keys(pools).length,
]),
block,
chain,
web3,
);
const poolAddresses = await util.executeMultiCallsOfTarget(
liquidityManager.address,
LIQUIDITY_MANAGER_ABI,
'pool',
poolMetas
.filter((poolMeta) => {
if (
poolMeta.tokenX !== '0x0000000000000000000000000000000000000000'
) {
return poolMeta;
} else {
exit = true;
}
})
.map(
(poolMeta: { tokenX: string; tokenY: string; fee: string }) => [
poolMeta.tokenX,
poolMeta.tokenY,
poolMeta.fee,
],
),
block,
chain,
web3,
);

const poolAddresses = await util.executeMultiCallsOfTarget(
LIQUIDITY_MANAGER_ADDRESS,
LIQUIDITY_MANAGER_ABI,
'pool',
poolMetas
.filter((poolMeta) => {
if (
poolMeta.tokenX !== '0x0000000000000000000000000000000000000000'
) {
return poolMeta;
} else {
exit = true;
}
})
.map((poolMeta: { tokenX: string; tokenY: string; fee: string }) => [
poolMeta.tokenX,
poolMeta.tokenY,
poolMeta.fee,
]),
block,
chain,
web3,
);
poolAddresses.forEach((poolAddress, index) => {
pools[poolAddress] = [
poolMetas[index].tokenX,
poolMetas[index].tokenY,
];
});

poolAddresses.forEach((poolAddress, index) => {
pools[poolAddress] = [poolMetas[index].tokenX, poolMetas[index].tokenY];
});
if (exit) break;
}

if (exit) break;
}
await basicUtil.saveIntoCache(
`${liquidityManager.address}_pools.json`,
'pools.json',
chain,
provider,
);

await basicUtil.saveIntoCache(pools, 'pools.json', chain, provider);
const tokenBalances = await util.getTokenBalancesOfHolders(
Object.keys(pools).flatMap((i) => [i, i]),
Object.keys(pools)
.map((tokens) => pools[tokens])
.flat(1),
block,
chain,
web3,
);

const tokenBalances = await util.getTokenBalancesOfHolders(
Object.keys(pools).flatMap((i) => [i, i]),
Object.keys(pools)
.map((tokens) => pools[tokens])
.flat(1),
block,
chain,
web3,
);
formatter.sumMultiBalanceOf(balances, tokenBalances);
}
}

formatter.sumMultiBalanceOf(balances, tokenBalances);
formatter.convertBalancesToFixed(balances);
return { balances };
}
Expand Down

0 comments on commit 95b35c9

Please sign in to comment.