-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add Valdora Finance yield adapter #2746
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
Merged
+114
−0
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5585c5a
Add Valdora Finance yield adapter
permapod-rsk 13e7291
valdora-finance: address review feedback
permapod-rsk d0409e4
fix: replace non-existent exchange_rate query with total_supply
permapod-rsk 4f796c1
valdora-finance: validate contract balances
permapod-rsk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }; | ||
|
|
||
| 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', | ||
|
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. add |
||
| }, | ||
| ].filter((pool) => utils.keepFinite(pool)); | ||
| }; | ||
|
|
||
| module.exports = { | ||
| protocolId: '6991', | ||
| timetravel: false, | ||
| apy, | ||
| url: 'https://valdora.finance/stake', | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should these be hardcoded or can we get dynamically to ensure they stay up to date?