Skip to content

Commit

Permalink
Fix: Uni-v1 (Subgraph was Outdated) (DefiLlama#12034)
Browse files Browse the repository at this point in the history
Co-authored-by: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com>
  • Loading branch information
0xpeluche and g1nt0ki authored Oct 25, 2024
1 parent f6660d7 commit 939a39a
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions projects/uniswap-v1/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
const { getChainTvl } = require('../helper/getUniSubgraphTvl');
const { nullAddress } = require('../helper/unwrapLPs')

const v1graph = getChainTvl({
ethereum: 'ESnjgAG9NjfmHypk4Huu4PVvz55fUwpyrRqHF21thoLJ'
}, "uniswaps", "totalLiquidityUSD")
const uniFactory = '0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95'

const abi = {
getExchange: "function getExchange(address token) view returns (address)",
getTokenWithId: "function getTokenWithId(uint256 token_id) view returns (address)",
tokenCount: "function tokenCount() view returns (uint256)",
}

const tvl = async (api) => {
let pools = await api.fetchList({ lengthAbi: abi.tokenCount, itemAbi: abi.getTokenWithId, target: uniFactory, itemAbi2: abi.getExchange, })
pools = pools.filter(i => i !== nullAddress)
await api.sumTokens({ owners: pools, tokens: [nullAddress] })
const balancesV2 = api.getBalancesV2()
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
}

module.exports = {
misrepresentedTokens: true,
methodology: `Counts the tokens locked on AMM pools, pulling the data from the 'ianlapham/uniswapv2' subgraph`,
ethereum: {
tvl: v1graph("ethereum"),
}
}
methodology: `Counts the tokens in ETH value locked in AMM pools`,
ethereum: { tvl }
}

0 comments on commit 939a39a

Please sign in to comment.