-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #234 from dappradar/linea
Linea dapps
- Loading branch information
Showing
24 changed files
with
2,604 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
Oops, something went wrong.