-
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 #302 from dappradar/SI-877
SI-877/etherlink
- Loading branch information
Showing
7 changed files
with
145 additions
and
4 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
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 = 1960368; | ||
const V3_FACTORY_ADDRESS = '0x093cCBAEcb0E0006c8BfFca92E9929d117fEC583'; | ||
|
||
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,83 @@ | ||
import formatter from '../../../../util/formatter'; | ||
import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; | ||
import util from '../../../../util/blockchainUtil'; | ||
import basicUtil from '../../../../util/basicUtil'; | ||
import blockchainUtil from '../../../../util/blockchainUtil'; | ||
|
||
const START_BLOCK = 308542; | ||
const FACTORY_ADDRESS = '0x9767E409259E314F3C69fe1E7cA0D3161Bba4F5a'; | ||
const BLOCK_LIMIT = 1000; | ||
const OGW1_WXTZ = '0x3571aed54ccea5b69b00516d5a149a6baea77118'; | ||
const WXTZ = '0xc9b53ab2679f573e480d01e0f49e2b5cfb7a3eab'; | ||
|
||
async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> { | ||
const { block, chain, provider, web3 } = params; | ||
|
||
const balances = {}; | ||
if (block < START_BLOCK) { | ||
return { balances }; | ||
} | ||
|
||
let cache: { | ||
start: number; | ||
pairs: object; | ||
} = { start: START_BLOCK, pairs: {} }; | ||
try { | ||
cache = await basicUtil.readFromCache('cache.json', chain, provider); | ||
} catch {} | ||
|
||
for ( | ||
let i = Math.max(cache.start, START_BLOCK); | ||
i < block; | ||
i += BLOCK_LIMIT | ||
) { | ||
const logs = await util.getLogs( | ||
i, | ||
Math.min(i + BLOCK_LIMIT - 1, block), | ||
'0xa92a2b95c8d8436f6ac4c673c61487364f877efb9534d4296fad8ef904546c94', | ||
FACTORY_ADDRESS, | ||
web3, | ||
); | ||
|
||
logs.output.forEach((log) => { | ||
const weth = `0x${log.topics[1].substring(26, 66)}`; | ||
const token = `0x${log.topics[2].substring(26, 66)}`; | ||
const pair = `0x${log.data.substring(26, 66)}`; | ||
|
||
cache.start = i + BLOCK_LIMIT; | ||
cache.pairs[pair] = { weth, token }; | ||
basicUtil.saveIntoCache(cache, 'cache.json', chain, provider); | ||
}); | ||
} | ||
|
||
const tokens: string[] = []; | ||
const holders: string[] = []; | ||
|
||
for (const pair in cache.pairs) { | ||
if (cache.pairs.hasOwnProperty(pair)) { | ||
tokens.push(cache.pairs[pair].weth); | ||
holders.push(pair); | ||
} | ||
} | ||
|
||
const tokenBalances = await blockchainUtil.getTokenBalancesOfHolders( | ||
Object.keys(cache.pairs), | ||
Object.values(cache.pairs).map((pair) => pair.token), | ||
block, | ||
chain, | ||
web3, | ||
); | ||
|
||
formatter.sumMultiBalanceOf(balances, tokenBalances); | ||
formatter.sumMultiBalanceOf(balances, tokenBalances); // sum second time, to get other pair token value | ||
|
||
if (balances[OGW1_WXTZ]) { | ||
balances[WXTZ] = balances[OGW1_WXTZ]; | ||
delete balances[OGW1_WXTZ]; | ||
} | ||
|
||
formatter.convertBalancesToFixed(balances); | ||
return { balances }; | ||
} | ||
|
||
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,27 @@ | ||
import uniswapV2 from '../../../../util/calculators/uniswapV2'; | ||
import formatter from '../../../../util/formatter'; | ||
import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; | ||
|
||
const START_BLOCK = 384279; | ||
const FACTORY_ADDRESS = '0x033eff22bC5Bd30c597e1fdE8Ca6fB1C1274C688'; | ||
|
||
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( | ||
FACTORY_ADDRESS, | ||
block, | ||
chain, | ||
provider, | ||
web3, | ||
); | ||
|
||
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
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