Skip to content

Commit da178bb

Browse files
authored
uni on chain (#11073)
1 parent 8972faf commit da178bb

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

coins/src/adapters/markets/uniswap/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const alternateGetReservesAbi =
77
"function getReserves() view returns (uint112 _reserve0, uint112 _reserve1)";
88

99
const config = {
10-
uniswap: { endpoint: sdk.graph.modifyEndpoint('A3Np3RQbaBA6oKJgiwDJeo5T3zrYfGHPWFYayMwtNDum'), chain: 'ethereum' },
10+
uniswap: { factory: '0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f', chain: 'ethereum' },
1111
sushiswap: [
1212
{ endpoint: sdk.graph.modifyEndpoint('6NUtT5mGjZ1tSshKLf5Q3uEEJtjBZJo1TpL5MXsUBqrT'), chain: 'ethereum', factory: '0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac', },
1313
{ endpoint: sdk.graph.modifyEndpoint('8nFDCAhdnJQEhQF3ZRnfWkJ6FkRsfAiiVabVn4eGoAZH'), chain: 'arbitrum', factory: sushiFactory, },

coins/src/adapters/utils/uniV2.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,42 @@ export function getUniV2Adapter({
234234
factory = factory!.toLowerCase();
235235
const cacheKey = `tvl-adapter-cache/cache/uniswap-forks/${factory}-${chain}.json`;
236236

237-
let res = await cache.readCache(cacheKey, { readFromR2Cache: true });
238-
let { pairs, token0s, token1s, symbols } = res;
239-
if (!pairs?.length)
240-
throw new Error("No pairs found, is there TVL adapter for this already?");
241-
if (pairs.length > 20 * 1000)
242-
throw new Error("Too many pairs found, try using the graph?");
237+
let pairs: any, symbols: any, token0s: any, token1s: any;
238+
if (factory == '0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f') {
239+
const pairsLength = await api.call({
240+
abi: 'function allPairsLength() view returns (uint256)',
241+
target: factory,
242+
});
243+
pairs = await api.multiCall({
244+
abi: 'function allPairs(uint256) view returns (address)',
245+
calls: Array.from({ length: pairsLength }, (_, i) => ({
246+
target: factory,
247+
params: [i],
248+
})),
249+
});
250+
token0s = await api.multiCall({
251+
abi: 'function token0() view returns (address)',
252+
calls: pairs.map((i: any) => ({
253+
target: i,
254+
})),
255+
});
256+
token1s = await api.multiCall({
257+
abi: 'function token1() view returns (address)',
258+
calls: pairs.map((i: any) => ({
259+
target: i,
260+
})),
261+
});
262+
} else {
263+
let res = await cache.readCache(cacheKey, { readFromR2Cache: true });
264+
pairs = res.pairs;
265+
token0s = res.token0s;
266+
token1s = res.token1s;
267+
symbols = res.symbols;
268+
if (!pairs?.length)
269+
throw new Error("No pairs found, is there TVL adapter for this already?");
270+
if (pairs.length > 20 * 1000)
271+
throw new Error("Too many pairs found, try using the graph?");
272+
}
243273

244274
pairs = pairs.map((i: any) => i.toLowerCase());
245275
token0s = token0s.map((i: any) => i.toLowerCase());

0 commit comments

Comments
 (0)