forked from DefiLlama/DefiLlama-Adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Uni-v1 (Subgraph was Outdated) (DefiLlama#12034)
Co-authored-by: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com>
- Loading branch information
Showing
1 changed file
with
19 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} |