Skip to content

Commit

Permalink
Merge pull request #296 from dappradar/Refactoring
Browse files Browse the repository at this point in the history
sushiswap refactoring
  • Loading branch information
mantasfam authored Jul 25, 2024
2 parents 4ef654e + 0ecbaac commit a314ad1
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 437 deletions.
7 changes: 0 additions & 7 deletions src/factory/providers/arbitrum/sushiswap/data.json

This file was deleted.

51 changes: 10 additions & 41 deletions src/factory/providers/arbitrum/sushiswap/index.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,28 @@
import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl';
import uniswapV2 from '../../../../util/calculators/uniswapV2';
import { trident } from './trident';
import BigNumber from 'bignumber.js';
import formatter from '../../../../util/formatter';
import uniswapV2 from '../../../../util/calculators/uniswapV2';
import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl';

const START_BLOCK = 70;
const FACTORY_ADDRESS = '0xc35DADB65012eC5796536bD9864eD8773aBc74C4';
const GRAPHQL_API =
'https://api.thegraph.com/subgraphs/name/sushi-labs/kashi-arbitrum';
const QUERY_SIZE = 500;

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

const { balances: dexBalances, poolBalances } = await uniswapV2.getTvl(
if (block < START_BLOCK) {
return {};
}

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

//const { balances: tridentBalance } = await trident(params);
formatter.convertBalancesToFixed(balances);

const balances = formatter.sum([dexBalances /*, tridentBalance*/]);

for (const token in balances) {
if (BigNumber(balances[token] || 0).isLessThan(100000)) {
delete balances[token];
}
}
return { balances, poolBalances };
}

async function getPoolVolumes(pools, priorBlockNumber) {
const poolVolumes = await uniswapV2.getPoolVolumes(
GRAPHQL_API,
QUERY_SIZE,
pools,
priorBlockNumber,
null,
);

return poolVolumes;
}

async function getTokenVolumes(tokens, priorBlockNumber) {
const tokenVolumes = await uniswapV2.getTokenVolumes(
GRAPHQL_API,
QUERY_SIZE,
tokens,
priorBlockNumber,
null,
);

return tokenVolumes;
}

export { tvl, getPoolVolumes, getTokenVolumes };
export { tvl };
47 changes: 0 additions & 47 deletions src/factory/providers/arbitrum/sushiswap/trident.ts

This file was deleted.

28 changes: 28 additions & 0 deletions src/factory/providers/avalanche/sushiswap/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import formatter from '../../../../util/formatter';
import uniswapV2 from '../../../../util/calculators/uniswapV2';
import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl';

const START_BLOCK = 506190;
const FACTORY_ADDRESS = '0xc35DADB65012eC5796536bD9864eD8773aBc74C4';

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

if (block < START_BLOCK) {
return {};
}

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

formatter.convertBalancesToFixed(balances);

return { balances, poolBalances };
}

export { tvl };
7 changes: 0 additions & 7 deletions src/factory/providers/bsc/sushiswap/data.json

This file was deleted.

30 changes: 2 additions & 28 deletions src/factory/providers/bsc/sushiswap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl';

const START_BLOCK = 5205069;
const FACTORY_ADDRESS = '0xc35DADB65012eC5796536bD9864eD8773aBc74C4';
const GRAPHQL_API =
'https://api.thegraph.com/subgraphs/name/sushiswap/bsc-exchange';
const QUERY_SIZE = 400;

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

if (block < START_BLOCK) {
return {};
}
Expand All @@ -27,28 +25,4 @@ async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> {
return { balances, poolBalances };
}

async function getPoolVolumes(pools, priorBlockNumber) {
const poolVolumes = await uniswapV2.getPoolVolumes(
GRAPHQL_API,
QUERY_SIZE,
pools,
priorBlockNumber,
null,
);

return poolVolumes;
}

async function getTokenVolumes(tokens, priorBlockNumber) {
const tokenVolumes = await uniswapV2.getTokenVolumes(
GRAPHQL_API,
QUERY_SIZE,
tokens,
priorBlockNumber,
null,
);

return tokenVolumes;
}

export { tvl, getPoolVolumes, getTokenVolumes };
export { tvl };
7 changes: 0 additions & 7 deletions src/factory/providers/celo/sushiswap/data.json

This file was deleted.

32 changes: 3 additions & 29 deletions src/factory/providers/celo/sushiswap/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import uniswapV2 from '../../../../util/calculators/uniswapV2';
import formatter from '../../../../util/formatter';
import uniswapV2 from '../../../../util/calculators/uniswapV2';
import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl';

const START_BLOCK = 7253488;
const FACTORY_ADDRESS = '0xc35DADB65012eC5796536bD9864eD8773aBc74C4';
const GRAPHQL_API =
'https://api.thegraph.com/subgraphs/name/sushiswap/celo-exchange';
const QUERY_SIZE = 400;

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

if (block < START_BLOCK) {
return {};
}
Expand All @@ -27,28 +25,4 @@ async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> {
return { balances, poolBalances };
}

async function getPoolVolumes(pools, priorBlockNumber) {
const poolVolumes = await uniswapV2.getPoolVolumes(
GRAPHQL_API,
QUERY_SIZE,
pools,
priorBlockNumber,
null,
);

return poolVolumes;
}

async function getTokenVolumes(tokens, priorBlockNumber) {
const tokenVolumes = await uniswapV2.getTokenVolumes(
GRAPHQL_API,
QUERY_SIZE,
tokens,
priorBlockNumber,
null,
);

return tokenVolumes;
}

export { tvl, getPoolVolumes, getTokenVolumes };
export { tvl };
7 changes: 0 additions & 7 deletions src/factory/providers/ethereum/sushiswap/data.json

This file was deleted.

56 changes: 6 additions & 50 deletions src/factory/providers/ethereum/sushiswap/index.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,28 @@
import { kashiLending } from './kashi-lending';
import BigNumber from 'bignumber.js';
import formatter from '../../../../util/formatter';
import uniswapV2 from '../../../../util/calculators/uniswapV2';
import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl';
import formatter from '../../../../util/formatter';

const START_BLOCK = 10794229;
const FACTORY_ADDRESS = '0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac';
const GRAPHQL_API =
'https://api.thegraph.com/subgraphs/name/sushiswap/exchange';
const QUERY_SIZE = 400;
const FACTORY_ADDRESS = '0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac';

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

if (block < START_BLOCK) {
return {};
}

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

/*const kashiBalances = await kashiLending({
block,
chain,
provider,
web3,
} as ITvlParams);*/
const balances = formatter.sum([dexBalances /*, kashiBalances.balances*/]);

for (const token in balances) {
if (BigNumber(balances[token] || 0).isLessThan(100000)) {
delete balances[token];
}
}
formatter.convertBalancesToFixed(balances);

return { balances, poolBalances };
}

async function getPoolVolumes(pools, priorBlockNumber) {
const poolVolumes = await uniswapV2.getPoolVolumes(
GRAPHQL_API,
QUERY_SIZE,
pools,
priorBlockNumber,
null,
);

return poolVolumes;
}

async function getTokenVolumes(tokens, priorBlockNumber) {
const tokenVolumes = await uniswapV2.getTokenVolumes(
GRAPHQL_API,
QUERY_SIZE,
tokens,
priorBlockNumber,
null,
);

return tokenVolumes;
}

module.exports = {
tvl,
getPoolVolumes,
getTokenVolumes,
};
export { tvl };
Loading

0 comments on commit a314ad1

Please sign in to comment.