Skip to content

Commit

Permalink
Update/ Substract CLM vault and CLM pool tvls from the parent clm (#1519
Browse files Browse the repository at this point in the history
)

* substract vaults and pools tvls from the parent clm

* remove CLM vault tvl from CLM pool tvl

---------

Co-authored-by: EREN <[email protected]>
  • Loading branch information
erenjaegar77 and EREN authored Jul 24, 2024
1 parent b260493 commit 27c54ab
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/api/stats/getChainTvl.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,34 @@ const getChainTvl = async chain => {
tvls = await setVaultsTvl(cowVaults, cowVaultBalances, chainId, tvls);
tvls = await setVaultsTvl(govVaults, govVaultBalances, chainId, tvls);

// separate CLM / CLM Pool / CLM Vault TVL
for (const clm of cowVaults) {
const clmId = clm.id;
const clmAddress = clm.earnContractAddress;

// TODO fix if we ever have more than one pool/vault per clm
const clmVault = lpVaults.find(vault => vault.tokenAddress === clmAddress);
const clmPool = govVaults.find(pool => pool.tokenAddress === clmAddress);

const clmVaultTvl = clmVault ? tvls[chainId]?.[clmVault.id] || 0 : 0;
const clmPoolTvl = clmPool ? tvls[chainId]?.[clmPool.id] || 0 : 0;
const clmTvl = tvls[chainId]?.[clmId] || 0;

// Vault deposits in to Pool
if (clmPool && clmVault) {
// On-chain pool TVL therefore also includes vault deposits, so remove them
const clmPoolItem = { [clmPool.id]: Math.max(0, clmPoolTvl - clmVaultTvl) };
tvls[chainId] = { ...tvls[chainId], ...clmPoolItem };
}

// Pool deposits in to CLM
if (clmPool) {
// On-chain CLM TVL therefore also includes pool deposits, so remove them
const clmItem = { [clmId]: Math.max(0, clmTvl - clmPoolTvl) };
tvls[chainId] = { ...tvls[chainId], ...clmItem };
}
}

return tvls;
};

Expand Down Expand Up @@ -66,18 +94,6 @@ const setVaultsTvl = async (vaults, balances, chainId, tvls) => {
item = { [vault.id]: tvl.toNumber() };
}

//subsctract the tvl from the parent clm
if (vault.type === 'gov' && vault.version === 2 && vault.id.endsWith('-rp')) {
const nakedCLmTvl = new BigNumber(tvls[chainId][vault.oracleId] || 0);
if (nakedCLmTvl.gt(0)) {
//sometimes the reward pool can have idle founds in the strategy and the tvl can be greater than the clm, in this case we set the naked clm tvl to 0
const clmItem = {
[vault.oracleId]: nakedCLmTvl.gt(tvl) ? nakedCLmTvl.minus(tvl).toNumber() : 0,
};
tvls[chainId] = { ...tvls[chainId], ...clmItem };
}
}

tvls[chainId] = { ...tvls[chainId], ...item };
}

Expand Down

0 comments on commit 27c54ab

Please sign in to comment.