Skip to content

Commit

Permalink
Merge pull request #234 from dappradar/linea
Browse files Browse the repository at this point in the history
Linea dapps
  • Loading branch information
mantasfam authored Nov 27, 2023
2 parents fa46fb4 + bc0efeb commit 02497ff
Show file tree
Hide file tree
Showing 24 changed files with 2,604 additions and 12 deletions.
1 change: 1 addition & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ZKSYNC-ERA_NODE_URL=https://mainnet.era.zksync.io
ELYSIUM_NODE_URL=https://rpc.elysiumchain.tech
CORE_NODE_URL=https://rpc-core.icecreamswap.com
BASE_NODE_URL=https://base.llamarpc.com
LINEA_NODE_URL=https://rpc.linea.build
##======================== LOGSTASH ========================
LOGSTASH_PORT=
LOGSTASH_HOST=
Expand Down
1 change: 1 addition & 0 deletions src/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ nodeUrls['ZKSYNC-ERA_NODE_URL'] = process.env['ZKSYNC-ERA_NODE_URL'];
nodeUrls['ELYSIUM_NODE_URL'] = process.env['ELYSIUM_NODE_URL'];
nodeUrls['BASE_NODE_URL'] = process.env['BASE_NODE_URL'];
nodeUrls['CORE_NODE_URL'] = process.env['CORE_NODE_URL'];
nodeUrls['LINEA_NODE_URL'] = process.env['LINEA_NODE_URL'];

export { config, nodeUrls };
33 changes: 22 additions & 11 deletions src/constants/contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"arbitrum": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
"zksync-era": "0x5aea5775959fbc2557cc8789bc1bf90a239d9a91",
"base": "0x4200000000000000000000000000000000000006",
"core": "0x40375C92d9FAf44d2f9db9Bd9ba41a3317a2404f"
"core": "0x40375C92d9FAf44d2f9db9Bd9ba41a3317a2404f",
"linea": "0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f"
},
"BULK_BALANCE_ADDRESSES": {
"ethereum": "0xb173393e08496209ad1cd9d57c769de76bdcea5a",
Expand All @@ -31,7 +32,8 @@
"arbitrum": "0x63acca16a1fcfd406d3ea8ec5137884861863828",
"zksync-era": "0x19b86d343394427ccc6c82c921b68305feaee833",
"base": "0x63acca16a1fcfd406d3ea8ec5137884861863828",
"core": "0xad4E66ac498FD091Af2E6185f204654B6Ac7bFcc"
"core": "0xad4E66ac498FD091Af2E6185f204654B6Ac7bFcc",
"linea": "0x63aCCa16a1fcfD406d3EA8Ec5137884861863828"
},
"BULK_BALANCE_DEPOLYED": {
"ethereum": 11439603,
Expand All @@ -48,7 +50,8 @@
"arbitrum": 86897490,
"zksync-era": 6397812,
"base": 4724504,
"core": 7653313
"core": 7653313,
"linea": 957303
},
"BULK_RESERVES_ADDRESSES": {
"ethereum": "0x4261b012f3d0d752ee9d738a4664df7117a148ab",
Expand All @@ -65,7 +68,8 @@
"arbitrum": "0xbb90c1a84f51d57c2046741b15156810d20f3592",
"zksync-era": "0xe7b54a13e456532675b4edc360a1c2818ef9f707",
"base": "0xbb90c1a84f51d57c2046741b15156810d20f3592",
"core": "0xc79D535188b27C8f7f3011931f7417A584b237Fc"
"core": "0xc79D535188b27C8f7f3011931f7417A584b237Fc",
"linea": "0xBb90C1A84F51d57c2046741B15156810D20f3592"
},
"BULK_RESERVES_DEPOLYED": {
"ethereum": 11438212,
Expand All @@ -82,7 +86,8 @@
"arbitrum": 86898048,
"zksync-era": 6398730,
"base": 4729900,
"core": 7653332
"core": 7653332,
"linea": 957341
},
"MULTIBALANCES_ADDRESSES": {
"ethereum": "0x09b6fd79f8c6bdaba4d94731f0fc90edd15742af",
Expand All @@ -99,7 +104,8 @@
"arbitrum": "0x47012c5a5a20893f342d279ddc6fd0847f196898",
"zksync-era": "0x7d1f4f2bc62bd7e7d1208ae4d8f3ad1b35467244",
"base": "0x7d9965aee6b51c944b20beb8954fe5018781fb19",
"core": "0x73AAB8664A7213517ecF93443EB3a2A6137fC892"
"core": "0x73AAB8664A7213517ecF93443EB3a2A6137fC892",
"linea": "0x7d9965AeE6b51C944b20beb8954Fe5018781fb19"
},
"MULTIBALANCES_DEPOLYED": {
"ethereum": 11606340,
Expand All @@ -116,7 +122,8 @@
"arbitrum": 86899235,
"zksync-era": 6399985,
"base": 4729971,
"core": 7653372
"core": 7653372,
"linea": 957390
},
"BULK_METADATA_ADDRESSES": {
"ethereum": "0x570B73444cC1077398f83777f34Bd672a50235cD",
Expand All @@ -133,7 +140,8 @@
"arbitrum": "0x7d9965aee6b51c944b20beb8954fe5018781fb19",
"zksync-era": "0x9ccc6685b99cc682e432441f704775550d8c5664",
"base": "0x47012c5a5a20893f342d279ddc6fd0847f196898",
"core": "0x6679aA0f478293eA24614f30f4eC23e855747bEB"
"core": "0x6679aA0f478293eA24614f30f4eC23e855747bEB",
"linea": "0x47012c5a5A20893f342d279DdC6Fd0847f196898"
},
"BULK_METADATA_DEPOLYED": {
"ethereum": 12825801,
Expand All @@ -150,7 +158,8 @@
"arbitrum": 86899489,
"zksync-era": 6399344,
"base": 4729939,
"core": 7653353
"core": 7653353,
"linea": 957366
},
"MULTICALL_ADDRESSES": {
"ethereum": "0x092C637b120Ad6C5DF6CFc2b2A9b284ed2E5b11F",
Expand All @@ -167,7 +176,8 @@
"arbitrum": "0x5a3cf2c199bbb28cd0a2f380d1f96b8d73d74b78",
"zksync-era": "0x9ce596f561ca117591bfb0f6f9a20f721290976b",
"base": "0x5a3cf2c199bbb28cd0a2f380d1f96b8d73d74b78",
"core": "0x97fFB44f17018475260332dcc3f4D9C45D498514"
"core": "0x97fFB44f17018475260332dcc3f4D9C45D498514",
"linea": "0x5a3CF2C199bBB28cD0A2f380d1f96B8d73D74B78"
},
"MULTICALL_DEPOLYED": {
"ethereum": 12949381,
Expand All @@ -184,6 +194,7 @@
"arbitrum": 86899646,
"zksync-era": 6400154,
"base": 4730173,
"core": 7653400
"core": 7653400,
"linea": 957405
}
}
25 changes: 25 additions & 0 deletions src/factory/providers/base/horizon/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl';
import uniswapV3 from '../../../../util/calculators/uniswapV3chain';

const V3_START_BLOCK = 2053334;
const V3_FACTORY_ADDRESS = '0x07AceD5690e09935b1c0e6E88B772d9440F64718';

async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> {
const { block, chain, provider, web3 } = params;
if (block < V3_START_BLOCK) {
return { balances: {} };
}

const balances = await uniswapV3.getTvl(
V3_FACTORY_ADDRESS,
V3_START_BLOCK,
block,
chain,
provider,
web3,
);

return { balances, poolBalances: {} };
}

export { tvl };
42 changes: 42 additions & 0 deletions src/factory/providers/linea/echodex/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import formatter from '../../../../util/formatter';
import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl';
import uniswapV2 from '../../../../util/calculators/uniswapV2';
import uniswapV3 from '../../../../util/calculators/uniswapV3chain';
import BigNumber from 'bignumber.js';

const START_BLOCK = 2344;
const V2_FACTORY_ADDRESS = '0x6D1063F2187442Cc9adbFAD2f55A96B846FCB399';
const V3_START_BLOCK = 120029;
const V3_FACTORY_ADDRESS = '0x559Fa53Be355835a038aC303A750E8788668636B';

async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> {
const { block, chain, provider, web3 } = params;
if (block < START_BLOCK) {
return { balances: {} };
}

const { balances, poolBalances } = await uniswapV2.getTvl(
V2_FACTORY_ADDRESS,
block,
chain,
provider,
web3,
);

const v3Balances = await uniswapV3.getTvl(
V3_FACTORY_ADDRESS,
V3_START_BLOCK,
block,
chain,
provider,
web3,
);

for (const [key, value] of Object.entries(v3Balances)) {
balances[key] = new BigNumber(balances[key] || 0).plus(value).toFixed();
}
formatter.convertBalancesToFixed(balances);
return { balances, poolBalances };
}

export { tvl };
25 changes: 25 additions & 0 deletions src/factory/providers/linea/horizon/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl';
import uniswapV3 from '../../../../util/calculators/uniswapV3chain';

const V3_START_BLOCK = 1150;
const V3_FACTORY_ADDRESS = '0x9Fe607e5dCd0Ea318dBB4D8a7B04fa553d6cB2c5';

async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> {
const { block, chain, provider, web3 } = params;
if (block < V3_START_BLOCK) {
return { balances: {} };
}

const balances = await uniswapV3.getTvl(
V3_FACTORY_ADDRESS,
V3_START_BLOCK,
block,
chain,
provider,
web3,
);

return { balances, poolBalances: {} };
}

export { tvl };
105 changes: 105 additions & 0 deletions src/factory/providers/linea/izumi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
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 = 2094;
const LIQUIDITY_MANAGERS = [
{ address: '0x1CB60033F61e4fc171c963f0d2d3F63Ece24319c', startBlock: 2094 },
];

async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> {
const { block, chain, provider, web3 } = params;
const balances = {};
if (block < START_BLOCK) {
return { balances };
}

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) {
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,
);

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

if (exit) break;
}

await basicUtil.saveIntoCache(
`${liquidityManager.address}_pools.json`,
'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 };
Loading

0 comments on commit 02497ff

Please sign in to comment.