Skip to content

Commit

Permalink
Update index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
mantasfam committed Aug 7, 2023
1 parent 821426a commit 29892a6
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/factory/providers/optimism/clipper/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
import util from '../../../../util/blockchainUtil';
import formatter from '../../../../util/formatter';
import axios from 'axios';
import basicUtil from '../../../../util/basicUtil';
import { log } from '../../../../util/logger/logger';
import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl';

const clipperRfqUrlForOptimism =
'https://api.clipper.exchange/rfq/pool?chain_id=10';
const startBlock = 3183055;

async function getChainData() {
const {
data: {
pool: { address: poolAddress },
assets,
},
} = await axios.get(clipperRfqUrlForOptimism);
return {
poolAddress,
tokens: assets.map(({ address }) => address),
};
async function getChainData(chain, provider) {
let poolInfo: { poolAddress: string; tokens: string[] };

try {
const {
data: {
pool: { address: poolAddress },
assets,
},
} = await axios.get(clipperRfqUrlForOptimism);

poolInfo = {
poolAddress,
tokens: assets.map(({ address }) => address),
};

await basicUtil.saveIntoCache(poolInfo, 'poolInfo.json', chain, provider);
} catch (e) {
log.error({
message: `Issue with Clipper API`,
stack: e.stack,
detail: `Error: getChainData of optimism/clipper`,
endpoint: 'getChainData',
});
poolInfo = await basicUtil.readFromCache('poolInfo.json', chain, provider);
}

return poolInfo;
}

async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> {
Expand All @@ -27,7 +46,7 @@ async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> {
}

const balances = {};
const { poolAddress, tokens } = await getChainData();
const { poolAddress, tokens } = await getChainData(chain, provider);
const tokenBalances = await util.getTokenBalances(
poolAddress,
tokens,
Expand Down

0 comments on commit 29892a6

Please sign in to comment.