Skip to content

Commit 939a39a

Browse files
0xpelucheg1nt0ki
andauthored
Fix: Uni-v1 (Subgraph was Outdated) (DefiLlama#12034)
Co-authored-by: g1nt0ki <[email protected]>
1 parent f6660d7 commit 939a39a

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

projects/uniswap-v1/index.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
const { getChainTvl } = require('../helper/getUniSubgraphTvl');
1+
const { nullAddress } = require('../helper/unwrapLPs')
22

3-
const v1graph = getChainTvl({
4-
ethereum: 'ESnjgAG9NjfmHypk4Huu4PVvz55fUwpyrRqHF21thoLJ'
5-
}, "uniswaps", "totalLiquidityUSD")
3+
const uniFactory = '0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95'
4+
5+
const abi = {
6+
getExchange: "function getExchange(address token) view returns (address)",
7+
getTokenWithId: "function getTokenWithId(uint256 token_id) view returns (address)",
8+
tokenCount: "function tokenCount() view returns (uint256)",
9+
}
10+
11+
const tvl = async (api) => {
12+
let pools = await api.fetchList({ lengthAbi: abi.tokenCount, itemAbi: abi.getTokenWithId, target: uniFactory, itemAbi2: abi.getExchange, })
13+
pools = pools.filter(i => i !== nullAddress)
14+
await api.sumTokens({ owners: pools, tokens: [nullAddress] })
15+
const balancesV2 = api.getBalancesV2()
16+
return balancesV2.clone(2).getBalances() // // Since Uniswap V1 only allowed swaps against ETH, it's enough to know the amount of ETH and multiply it by two to determine the pool's value without needing to know the price of the collateral in question
17+
}
618

719
module.exports = {
820
misrepresentedTokens: true,
9-
methodology: `Counts the tokens locked on AMM pools, pulling the data from the 'ianlapham/uniswapv2' subgraph`,
10-
ethereum: {
11-
tvl: v1graph("ethereum"),
12-
}
13-
}
21+
methodology: `Counts the tokens in ETH value locked in AMM pools`,
22+
ethereum: { tvl }
23+
}

0 commit comments

Comments
 (0)