Skip to content

Commit

Permalink
Merge pull request #302 from dappradar/SI-877
Browse files Browse the repository at this point in the history
SI-877/etherlink
  • Loading branch information
mantasfam authored Sep 10, 2024
2 parents f2b4dc2 + 66e748d commit 0a1c724
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ XAI_NODE_URL=
BAHAMUT_NODE_URL=https://rpc2.bahamut.io/
TONCENTER_API_KEY=
SKALE-EUROPA_NODE_URL=https://mainnet.skalenodes.com/v1/elated-tan-skat
ETHERLINK_NODE_URL=https://node.mainnet.etherlink.com
##======================== LOGSTASH ========================
LOGSTASH_PORT=
LOGSTASH_HOST=
Expand All @@ -34,7 +35,7 @@ LOGSTASH_INDEX=
SLACK_WEBHOOK_URL=
SLACK_LOGGING=false

REDIS_HOST=
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_USERNAME=
REDIS_PASSWORD=
1 change: 1 addition & 0 deletions src/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ nodeUrls['BTTC_NODE_URL'] = process.env['BTTC_NODE_URL'];
nodeUrls['XAI_NODE_URL'] = process.env['XAI_NODE_URL'];
nodeUrls['BAHAMUT_NODE_URL'] = process.env['BAHAMUT_NODE_URL'];
nodeUrls['SKALE-EUROPA_NODE_URL'] = process.env['SKALE-EUROPA_NODE_URL'];
nodeUrls['ETHERLINK_NODE_URL'] = process.env['ETHERLINK_NODE_URL'];

export { config, nodeUrls };
25 changes: 25 additions & 0 deletions src/factory/providers/etherlink/iguana/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 = 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 };
83 changes: 83 additions & 0 deletions src/factory/providers/etherlink/organicgrowth/index.ts
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 };
27 changes: 27 additions & 0 deletions src/factory/providers/etherlink/tachyswap/index.ts
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 };
6 changes: 3 additions & 3 deletions src/util/calculators/uniswapV3chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async function getTvl(
eventLog = (
await util.getLogs(
i,
Math.min(block, i + offset),
Math.min(block, i + offset - 1),
topic,
factoryAddress,
web3,
Expand All @@ -101,8 +101,8 @@ async function getTvl(
detail: `Error: tvl of ethereum/uniswapv3`,
endpoint: 'tvl',
});
if (offset > 3000) {
offset -= 2000;
if (offset >= 2000) {
offset -= 1000;
} else if (offset > 300) {
offset -= 200;
} else if (offset > 30) {
Expand Down
4 changes: 4 additions & 0 deletions src/util/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ const data = {
prefix: 'skeur_',
delay: 0,
},
etherlink: {
prefix: 'etherlink_',
delay: 0,
},
},
FILTERS: {
MarketCapInFiat: 'marketCapInFiat',
Expand Down

0 comments on commit 0a1c724

Please sign in to comment.