-
Notifications
You must be signed in to change notification settings - Fork 1.1k
canto-lending: report available liquidity as TVL #2769
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
base: master
Are you sure you want to change the base?
Changes from all commits
5585c5a
13e7291
d0409e4
4f796c1
e46bc83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| const utils = require('../utils'); | ||
|
|
||
| const PROJECT = 'valdora-finance'; | ||
| const CHAIN = 'ZIGChain'; | ||
| const LCD = 'https://public-zigchain-lcd.numia.xyz'; | ||
|
|
||
| const STAKER_CONTRACT = | ||
| 'zig18nnde5tpn76xj3wm53n0tmuf3q06nruj3p6kdemcllzxqwzkpqzqk7ue55'; | ||
| const STZIG_DENOM = | ||
| 'coin.zig109f7g2rzl2aqee7z6gffn8kfe9cpqx0mjkk7ethmx8m2hq4xpe9snmaam2.stzig'; | ||
| const ZIG_PRICE_KEY = 'zigchain:uzig'; | ||
| const DECIMALS = 1e6; | ||
| const PERFORMANCE_FEE = 0.10; | ||
| const COMMUNITY_TAX = 0.02; | ||
|
|
||
| const VALIDATORS = [ | ||
| 'zigvaloper18vykgjgcmp2z4xzkt6mh74glrpd7qda8fqldrl', | ||
| 'zigvaloper1vd9ljpsgq5ev7yf7r6tu7t237qqpf2vehp4kvp', | ||
| 'zigvaloper1jh6jve7n4pu9vxnmr67eg4m6qk7d7s4lf4uu0j', | ||
| 'zigvaloper15pwqnx4hgkwq839xv3jgjxh9aj2wdg8p8dgy76', | ||
| ]; | ||
|
|
||
| const get = (path) => utils.getData(`${LCD}${path}`); | ||
|
|
||
| const queryContract = async (contract, data) => { | ||
| const query = Buffer.from(JSON.stringify(data)).toString('base64'); | ||
| const response = await get(`/cosmwasm/wasm/v1/contract/${contract}/smart/${query}`); | ||
| return response.data; | ||
| }; | ||
|
|
||
| const getAverageValidatorCommission = async () => { | ||
| const results = await Promise.allSettled( | ||
| VALIDATORS.map(async (validator) => { | ||
| const data = await get(`/cosmos/staking/v1beta1/validators/${validator}`); | ||
| return Number(data.validator?.commission?.commission_rates?.rate || 0); | ||
| }) | ||
| ); | ||
|
|
||
| const commissions = results | ||
| .filter((r) => r.status === 'fulfilled') | ||
| .map((r) => r.value); | ||
|
|
||
| if (!commissions.length) return 0; | ||
| return commissions.reduce((sum, value) => sum + value, 0) / commissions.length; | ||
| }; | ||
|
Comment on lines
+39
to
+45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Silent fallback masks upstream failures.
Suggested consistency fix if (!commissions.length) return 0;
+ // consider throwing instead, to match the fail-fast pattern used in apy()
+ // throw new Error('Unable to fetch validator commissions');
return commissions.reduce((sum, value) => sum + value, 0) / commissions.length;Also applies to: 56-57 🤖 Prompt for AI Agents |
||
|
|
||
| const getStzigApr = async () => { | ||
| const [annualProvisions, stakingPool, averageCommission] = await Promise.all([ | ||
| get('/cosmos/mint/v1beta1/annual_provisions'), | ||
| get('/cosmos/staking/v1beta1/pool'), | ||
| getAverageValidatorCommission(), | ||
| ]); | ||
|
|
||
| const annualProvisionsZig = Number(annualProvisions.annual_provisions) / DECIMALS; | ||
| const bondedZig = Number(stakingPool.pool?.bonded_tokens || 0) / DECIMALS; | ||
|
|
||
| if (!bondedZig) return 0; | ||
| return ( | ||
| (annualProvisionsZig / bondedZig) * | ||
| (1 - COMMUNITY_TAX) * | ||
| (1 - averageCommission) * | ||
| (1 - PERFORMANCE_FEE) * | ||
| 100 | ||
| ); | ||
| }; | ||
|
|
||
| const apy = async () => { | ||
| const [fundsRaised, apyBase, totalSupply, priceData] = await Promise.all([ | ||
| queryContract(STAKER_CONTRACT, { funds_raised: {} }), | ||
| getStzigApr(), | ||
| queryContract(STAKER_CONTRACT, { total_supply: {} }), | ||
| utils.getPriceApiData(`/prices/current/${ZIG_PRICE_KEY}`), | ||
| ]); | ||
|
|
||
| const zigPrice = priceData.coins[ZIG_PRICE_KEY]?.price; | ||
| if (!zigPrice) throw new Error('Unable to fetch ZIG price'); | ||
|
|
||
| const fundsRaisedValue = Number(fundsRaised.funds_raised); | ||
| const totalSupplyValue = Number(totalSupply.total_supply); | ||
|
|
||
| if (!Number.isFinite(fundsRaisedValue) || fundsRaisedValue < 0) { | ||
| throw new Error('Invalid funds_raised contract response'); | ||
| } | ||
|
|
||
| if (!Number.isFinite(totalSupplyValue) || totalSupplyValue <= 0) { | ||
| throw new Error('Invalid total_supply contract response'); | ||
| } | ||
|
|
||
| const tvlUsd = (fundsRaisedValue / DECIMALS) * zigPrice; | ||
| const pricePerShare = fundsRaisedValue / totalSupplyValue; | ||
|
|
||
| return [ | ||
| { | ||
| pool: `${STZIG_DENOM}-${CHAIN}`.toLowerCase(), | ||
| chain: CHAIN, | ||
| project: PROJECT, | ||
| symbol: 'stZIG', | ||
| tvlUsd, | ||
| apyBase, | ||
| pricePerShare, | ||
| underlyingTokens: ['uzig'], | ||
| searchTokenOverride: STZIG_DENOM, | ||
| isIntrinsicSource: true, | ||
| url: 'https://valdora.finance/stake', | ||
| }, | ||
| ].filter((pool) => utils.keepFinite(pool)); | ||
| }; | ||
|
|
||
| module.exports = { | ||
| protocolId: '6991', | ||
| timetravel: false, | ||
| apy, | ||
| url: 'https://valdora.finance/stake', | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: DefiLlama/yield-server
Length of output: 9426
🌐 Web query:
Canto blockchain average block time seconds💡 Result:
The Canto blockchain's average block time has evolved due to network upgrades. Historically, the Canto EVM maintained a block time of approximately 6 seconds [1][2]. Recent infrastructure updates, specifically through the "Callisto" upgrade, transitioned the network to the Cosmos SDK v0.50 with the ABCI 2.0 interface and Optimistic Block Execution. This upgrade significantly reduced block times to less than 2 seconds [3]. Furthermore, the Canto roadmap for its "Cyclone Stack" includes additional performance improvements—such as Optimistic Parallel Execution and MemIAVL integration—intended to achieve even faster, sub-second block times [3]. Because block times can fluctuate based on network conditions and specific validator performance, real-time block explorers may display slightly varying averages, often ranging between 5 and 6 seconds in older snapshots or depending on the indexing status of the explorer [4][5][6]. However, the technical target and optimized performance for the current architecture are significantly lower, moving toward sub-second finality [3].
Citations:
🏁 Script executed:
Repository: DefiLlama/yield-server
Length of output: 50378
Replace the hardcoded 6s block interval
calculateApyandcalculateRewardApyannualize per-block rates with a fixedBLOCK_TIME = 6; Canto’s block time no longer stays pinned to that assumption, so the APY drifts unless this comes from chain config.🤖 Prompt for AI Agents