Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Aug 21, 2024
1 parent 1f8cfa6 commit 19dcc84
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 63 deletions.
22 changes: 0 additions & 22 deletions projects/zklend/abi.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,7 @@ const staking = [
const stakingAbi = {}
staking.forEach(i => stakingAbi[i.name] = i)

const erc20 = [{
"name": "balanceOf",
"type": "function",
"inputs": [
{
"name": "account",
"type": "felt"
}
],
"outputs": [
{
"name": "balance",
"type": "Uint256"
}
],
"stateMutability": "view",
"customInput": 'address',
}]
const erc20Abi = {}
erc20.forEach(i => erc20Abi[i.name] = i)

module.exports = {
marketAbi,
stakingAbi,
erc20Abi
}
63 changes: 22 additions & 41 deletions projects/zklend/index.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,42 @@
const ADDRESSES = require('../helper/coreAssets.json')
const { multiCall, sumTokens, call } = require('../helper/chain/starknet')
const { marketAbi, stakingAbi, erc20Abi } = require('./abi');
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) {
const [amountStakedAtStakingContract, amountStakedAtMarketContract] = await Promise.all([
call({
target: stakingContract,
abi: stakingAbi.get_total_staked_amount
}),
call({
target: ADDRESSES.starknet.ZEND,
abi: erc20Abi.balanceOf,
params: [
market
]
})
])
const totalStaked = BigInt(amountStakedAtStakingContract) + BigInt(amountStakedAtMarketContract)
api.addTokens(
[
ADDRESSES.starknet.ZEND
],
[
totalStaked
]
)
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 19dcc84

Please sign in to comment.