diff --git a/src/factory/providers/zksync-era/izumi/index.ts b/src/factory/providers/zksync-era/izumi/index.ts new file mode 100644 index 00000000..580a0024 --- /dev/null +++ b/src/factory/providers/zksync-era/izumi/index.ts @@ -0,0 +1,85 @@ +import util from '../../../../util/blockchainUtil'; +import basicUtil from '../../../../util/basicUtil'; +import formatter from '../../../../util/formatter'; +import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; +import LIQUIDITY_MANAGER_ABI from './liquidityManagerAbi.json'; + +const START_BLOCK = 225074; +const LIQUIDITY_MANAGER_ADDRESS = '0x936c9a1b8f88bfdbd5066ad08e5d773bc82eb15f'; + +async function tvl(params: ITvlParams): Promise> { + const { block, chain, provider, web3 } = params; + const balances = {}; + if (block < START_BLOCK) { + return { balances }; + } + + let pools = {}; + try { + pools = await basicUtil.readFromCache('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, + ); + + let exit = false; + + 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]; + }); + + if (exit) break; + } + + 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, + ); + + formatter.sumMultiBalanceOf(balances, tokenBalances); + formatter.convertBalancesToFixed(balances); + return { balances }; +} + +export { tvl }; diff --git a/src/factory/providers/zksync-era/izumi/liquidityManagerAbi.json b/src/factory/providers/zksync-era/izumi/liquidityManagerAbi.json new file mode 100644 index 00000000..9a51f91b --- /dev/null +++ b/src/factory/providers/zksync-era/izumi/liquidityManagerAbi.json @@ -0,0 +1,1108 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "factory", + "type": "address" + }, + { + "internalType": "address", + "name": "weth", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "nftId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "liquidityDelta", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountX", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountY", + "type": "uint256" + } + ], + "name": "AddLiquidity", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "approved", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "operator", + "type": "address" + }, + { + "indexed": false, + "internalType": "bool", + "name": "approved", + "type": "bool" + } + ], + "name": "ApprovalForAll", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "nftId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "liquidityDelta", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountX", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountY", + "type": "uint256" + } + ], + "name": "DecLiquidity", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [], + "name": "WETH9", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "lid", + "type": "uint256" + }, + { + "internalType": "uint128", + "name": "xLim", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "yLim", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "amountXMin", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "amountYMin", + "type": "uint128" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "internalType": "struct LiquidityManager.AddLiquidityParam", + "name": "addLiquidityParam", + "type": "tuple" + } + ], + "name": "addLiquidity", + "outputs": [ + { + "internalType": "uint128", + "name": "liquidityDelta", + "type": "uint128" + }, + { + "internalType": "uint256", + "name": "amountX", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountY", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "baseURI", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "lid", + "type": "uint256" + } + ], + "name": "burn", + "outputs": [ + { + "internalType": "bool", + "name": "success", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "lid", + "type": "uint256" + }, + { + "internalType": "uint128", + "name": "amountXLim", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "amountYLim", + "type": "uint128" + } + ], + "name": "collect", + "outputs": [ + { + "internalType": "uint256", + "name": "amountX", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountY", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenX", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenY", + "type": "address" + }, + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + }, + { + "internalType": "int24", + "name": "initialPoint", + "type": "int24" + } + ], + "name": "createPool", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "lid", + "type": "uint256" + }, + { + "internalType": "uint128", + "name": "liquidDelta", + "type": "uint128" + }, + { + "internalType": "uint256", + "name": "amountXMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountYMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "decLiquidity", + "outputs": [ + { + "internalType": "uint256", + "name": "amountX", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountY", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "factory", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getApproved", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "operator", + "type": "address" + } + ], + "name": "isApprovedForAll", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "liquidities", + "outputs": [ + { + "internalType": "int24", + "name": "leftPt", + "type": "int24" + }, + { + "internalType": "int24", + "name": "rightPt", + "type": "int24" + }, + { + "internalType": "uint128", + "name": "liquidity", + "type": "uint128" + }, + { + "internalType": "uint256", + "name": "lastFeeScaleX_128", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastFeeScaleY_128", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "remainTokenX", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "remainTokenY", + "type": "uint256" + }, + { + "internalType": "uint128", + "name": "poolId", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "liquidityNum", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "address", + "name": "miner", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenX", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenY", + "type": "address" + }, + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + }, + { + "internalType": "int24", + "name": "pl", + "type": "int24" + }, + { + "internalType": "int24", + "name": "pr", + "type": "int24" + }, + { + "internalType": "uint128", + "name": "xLim", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "yLim", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "amountXMin", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "amountYMin", + "type": "uint128" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "internalType": "struct LiquidityManager.MintParam", + "name": "mintParam", + "type": "tuple" + } + ], + "name": "mint", + "outputs": [ + { + "internalType": "uint256", + "name": "lid", + "type": "uint256" + }, + { + "internalType": "uint128", + "name": "liquidity", + "type": "uint128" + }, + { + "internalType": "uint256", + "name": "amountX", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountY", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "x", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "y", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "mintDepositCallback", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes[]", + "name": "data", + "type": "bytes[]" + } + ], + "name": "multicall", + "outputs": [ + { + "internalType": "bytes[]", + "name": "results", + "type": "bytes[]" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "ownerOf", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenX", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenY", + "type": "address" + }, + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + } + ], + "name": "pool", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "poolIds", + "outputs": [ + { + "internalType": "uint128", + "name": "", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "", + "type": "uint128" + } + ], + "name": "poolMetas", + "outputs": [ + { + "internalType": "address", + "name": "tokenX", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenY", + "type": "address" + }, + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "refundETH", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "_data", + "type": "bytes" + } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "operator", + "type": "address" + }, + { + "internalType": "bool", + "name": "approved", + "type": "bool" + } + ], + "name": "setApprovalForAll", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "newBaseURI", + "type": "string" + } + ], + "name": "setBaseURI", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes4", + "name": "interfaceId", + "type": "bytes4" + } + ], + "name": "supportsInterface", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "minAmount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + } + ], + "name": "sweepToken", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "tokenByIndex", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "tokenOfOwnerByIndex", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "tokenURI", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "minAmount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + } + ], + "name": "unwrapWETH9", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + } +] \ No newline at end of file