Skip to content

Commit

Permalink
feat: update zkLend staked amount (DefiLlama#11364)
Browse files Browse the repository at this point in the history
* feat: update zkLend staked amount

* minor fix

---------

Co-authored-by: g1nt0ki <[email protected]>
  • Loading branch information
2 people authored and tlatkdgus1 committed Nov 25, 2024
1 parent d88aafc commit 19c94e6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 28 deletions.
32 changes: 31 additions & 1 deletion projects/zklend/abi.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,37 @@ const market = [
]
const marketAbi = {}
market.forEach(i => marketAbi[i.name] = i)
const staking = [
{
name: "core::integer::u256",
type: "struct",
members: [
{
name: "low",
type: "core::integer::u128",
},
{
name: "high",
type: "core::integer::u128",
},
],
},
{
"type": "function",
"name": "get_total_staked_amount",
"inputs": [],
"outputs": [
{
"type": "core::integer::u256"
}
],
"state_mutability": "view"
},
]
const stakingAbi = {}
staking.forEach(i => stakingAbi[i.name] = i)

module.exports = {
marketAbi
marketAbi,
stakingAbi,
}
50 changes: 23 additions & 27 deletions projects/zklend/index.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
const ADDRESSES = require('../helper/coreAssets.json')
const { multiCall, sumTokens } = require('../helper/chain/starknet')
const { marketAbi } = require('./abi');
const { multiCall, sumTokens, call } = require('../helper/chain/starknet')
const { marketAbi, stakingAbi, } = require('./abi');

const market = '0x4c0a5193d58f74fbace4b74dcf65481e734ed1714121bdc571da345540efa05'
const stakingContract = '0x0212c219a68c8fe38f37951123d1ec877570dfa891de270aa4f8634c5e60bc23'

const assets = [
ADDRESSES.starknet.WBTC,
ADDRESSES.starknet.ETH,
ADDRESSES.starknet.USDC,
ADDRESSES.starknet.DAI,
ADDRESSES.starknet.DAI_1,
ADDRESSES.starknet.USDT,
ADDRESSES.starknet.WSTETH,
ADDRESSES.starknet.STRK
ADDRESSES.starknet.WBTC,
ADDRESSES.starknet.ETH,
ADDRESSES.starknet.USDC,
ADDRESSES.starknet.DAI,
ADDRESSES.starknet.DAI_1,
ADDRESSES.starknet.USDT,
ADDRESSES.starknet.WSTETH,
ADDRESSES.starknet.STRK
]

async function tvl(api) {
return sumTokens({ api, owner: market, tokens: assets })
return sumTokens({ api, owner: market, tokens: assets })
}

async function staking(api) {
return sumTokens({
api,
owner: stakingContract,
tokens: [
ADDRESSES.starknet.ZEND
]
})
const amountStakedAtStakingContract = await call({ target: stakingContract, abi: stakingAbi.get_total_staked_amount })
api.add(ADDRESSES.starknet.ZEND, amountStakedAtStakingContract)
return sumTokens({ api, owner: market, tokens: [ADDRESSES.starknet.ZEND] })
}

async function borrowed(api) {
let data = await multiCall({ calls: assets, target: market, abi: marketAbi.get_total_debt_for_token });
data = data.map(i => +i)
api.addTokens(assets, data)
let data = await multiCall({ calls: assets, target: market, abi: marketAbi.get_total_debt_for_token });
data = data.map(i => +i)
api.addTokens(assets, data)
}

module.exports = {
methodology: 'Value of user supplied asset on zkLend is considered as TVL',
starknet: {
tvl,
borrowed,
staking,
},
methodology: 'Value of user supplied asset on zkLend is considered as TVL',
starknet: {
tvl,
borrowed,
staking,
},
}

0 comments on commit 19c94e6

Please sign in to comment.