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

update liquid slicing protocol tvl calculation methodology #12911

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
94 changes: 59 additions & 35 deletions projects/liquidity-slicing/index.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,79 @@
const sdk = require('@defillama/sdk')
const axios = require("axios")
const ADDRESSES = require('../helper/coreAssets.json')
const { ethers } = require('ethers');

const abi = {
"checkContract": "function checkContract(uint16,bytes32) view returns (uint256)",
"nodeStates": "function nodeStates(uint256,bytes32) view returns (uint256 totalStaked,uint256,uint256)"
"tvl": "function tvl() external view returns (uint256)"
}


const MANAGER_CONTRACT_ADDRESS = "0x1F0ea3b63F3Fca05719E54E7469Ef897754eF666";

const config = {
manta: {
transformToken: "manta-network",
chainId: 2,
decimals: 18,
delegator: {
"0x89060B31DB21C6cB4e946EaCB28EFefF085C275a": ["0x2847e7f2823a5048f4ae2cd808a5e978aa6ce41fcbb6e7e7bbbb1b64446b0639"]
},
validator: {
"0xaB21907461313127Ce944F6f168888d93C091363": ["0x8e8103383262ff2256490767e2338ffc452bf602b0addede203da3218cc9d241"]
}
fManta: "0x3008bEB3E883CC90f95344B875d8b0c6F224fDC0",
sManta: "0x56c02b7388dfce36c4b53878890Cf450145E23cA"
},
aleo: {
transformToken: "aleo",
chainId: 5,
decimals: 6,
delegator: {
"0x52ade9c48599d71603cf661f98c9b7bd21cfb8ba448efd6204e89096b969c30c": ["0xbb57045a8a9c39dfb06baaf5ed6cb02343a17feecbf63aba9b15a6694476140f"]
},
validator: {
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff": ["0x0000000000000000000000000000000000000000000000000000000000000005"]
}
fAleo: "0x16077d3455DE4Aae822eF46390ef216166803347",
sAleo: "0x6a8C66dEcb40FD2d1F1429AB12A125437c7988E9"
},
bnb: {
fBNB: "0xcB8FbEBAA1994A535cC7A87f021C7De65F165B36"
}
};

const coingeckoIds = {
manta: "manta-network",
aleo: "aleo",
bnb: "binancecoin"
}

const tokenMapping = {
manta: "0x95CeF13441Be50d20cA4558CC0a27B601aC544E5", // MANTA token address
// aleo: ADDRESSES.ALEO.ALEO, // ALEO token address
bnb: ADDRESSES.bsc.WBNB // BNB token address
};


const ALEO_PRICE = "0.956"
libaice marked this conversation as resolved.
Show resolved Hide resolved

async function tvl(api) {
for (const chain of Object.keys(config)) {
const { transformToken: tokenId, chainId, decimals, delegator, validator, } = config[chain];
const allConfig = { ...delegator, ...validator };

for (const [hostAddr, nodes] of Object.entries(allConfig)) {
const i = await api.call({ abi: abi.checkContract, target: MANAGER_CONTRACT_ADDRESS, params: [chainId, ethers.zeroPadValue(hostAddr, 32)] });
const calls = nodes.map(v => ({ params: [i, v] }))
const stakes = (await api.multiCall({ abi: abi.nodeStates, calls, target: MANAGER_CONTRACT_ADDRESS })).map(i => i.totalStaked)
stakes.forEach(val => api.addCGToken(tokenId, val / (10 ** decimals)))
const balances = {}
let totalUsdTvl = 0

const timestamp = Math.floor(Date.now() / 1000)
const prices = await axios.get(`https://coins.llama.fi/prices/current/${
Object.values(coingeckoIds).map(id => `coingecko:${id}`).join(',')
}`)

for (const [chain, contracts] of Object.entries(config)) {
const tokenAddress = tokenMapping[chain]
let chainTvl = 0

for (const [_, contractAddress] of Object.entries(contracts)) {
const tvlAmount = await api.call({
abi: abi.tvl,
libaice marked this conversation as resolved.
Show resolved Hide resolved
target: contractAddress
})


const price = prices.data.coins[`coingecko:${coingeckoIds[chain]}`]?.price
if (price) {

chainTvl += (Number(tvlAmount) / 1e18) * price
}
}

totalUsdTvl += chainTvl
}

return {
tether: totalUsdTvl
}

}

module.exports = {
arbitrum: {
tvl,
}
}
},
methodology: "Calculates TVL of staked tokens, using the price of ALEO from Coinmarketcap",
}
Loading