Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CDP Loop functionality #12830

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 14 additions & 64 deletions projects/loopfi/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

var ethers = require("ethers");
const ADDRESSES = require('../helper/coreAssets.json')
const { sumTokensExport } = require("../helper/unwrapLPs")

Expand Down Expand Up @@ -45,71 +44,22 @@ const spectraVault = "0x9BfCD3788f923186705259ae70A1192F601BeB47"
const spectraLPToken = "0x2408569177553A427dd6956E1717f2fBE1a96F1D"


async function tvlEthereum(_timestamp,_block,_,{api}){
const block = await api.getBlock();
const lpETHTotalSupply = await api.call({
abi: "function totalSupply() view returns (uint256)",
target: lpETH,
params: [],
block
})
const totalBorrowed = await api.call({
abi: "function totalBorrowed() view returns (uint256)",
target: lpETH,
params: [],
block
})

const spotPrice = await api.call({
abi: "function spotPrice() view returns (uint256)",
target: spectraVault,
params: [],
block
})
const vaultTVL = await api.call({
abi: "function balanceOf(address user) view returns (uint256)",
target: spectraLPToken,
params: [spectraVault],
block
})

// Chainlink WETH price feed
const wethPrice = await api.call({
abi: "function latestAnswer() view returns (uint256)",
target: "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419",
params: [], block
})

// This is the total collateral value locked
api.addToken(spectraLPToken, vaultTVL)

// Since there is no price feed for Spectra LP token we use the internal price feed + chainlink
const spectraLPTokenUSD = parseFloat(ethers.formatEther(vaultTVL)) * parseFloat(ethers.formatEther(spotPrice)) * parseFloat(ethers.formatUnits(wethPrice, 8));


// lpETH value is backed 1:1 with WETH, so we count it as WETH
await api.add(tokens.WETH, lpETHTotalSupply - totalBorrowed)
await sumTokensExport({
ownerTokens: [[Object.values(tokens), LOOP_PRELAUNCH], [Object.values(tokensBtc), LOOP_PRELAUNCH_BTC], [Object.values(tokensYieldnest), LOOP_PRELAUNCH_YNETH]],
})(api)

const balances = await api.getBalances()

return { ...balances,
usd: spectraLPTokenUSD
}
async function tvlEthereum(api) {
const calls = [lpETH]
const assets = await api.multiCall({ abi: 'address:asset', calls, })
const ownerTokens = [
[Object.values(tokens), LOOP_PRELAUNCH],
[Object.values(tokensBtc), LOOP_PRELAUNCH_BTC],
[Object.values(tokensYieldnest), LOOP_PRELAUNCH_YNETH],
[[spectraLPToken], spectraVault],
]
assets.forEach((asset, i) => ownerTokens.push([[asset], calls[i]]))
return api.sumTokens({ ownerTokens })
}

async function tvlBnb(_timestamp,_block,_,{api}){
const block = await api.getBlock();
const lpBNBTotalSupply = await api.call({
abi: "function totalSupply() view returns (uint256)",
target: lpBNB,
params: [],
block
})
await api.add(ADDRESSES.bsc.WBNB, lpBNBTotalSupply)

async function tvlBnb(api) {
const assets = await api.multiCall({ abi: 'address:asset', calls: [lpBNB] })
return api.sumTokens({ tokensAndOwners2: [assets, [lpBNB]] })
}

module.exports = {
Expand Down
Loading