Add Valdora Finance yield adapter#2746
Conversation
📝 WalkthroughWalkthroughA new adapter module for Changesvaldora-finance stZIG Adapter
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The valdora-finance adapter exports pools: Test Suites: 1 passed, 1 total |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/adaptors/valdora-finance/index.js`:
- Around line 30-37: The Promise.all call in the commissions calculation causes
the entire operation to fail if any single validator request fails. Replace
Promise.all with Promise.allSettled to gracefully handle individual validator
failures, then filter the results to extract only the fulfilled promises' values
before calculating the average in the reduce function. This way, transient
errors from individual validator endpoints won't cause the entire APY pipeline
to fail.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6a3d7850-77e9-4199-82ef-3c4c3f41456b
📒 Files selected for processing (1)
src/adaptors/valdora-finance/index.js
|
@bheluga can you please review this commit ? I'm not sure if the symbol should be the liquid staking asset (stZIG) or the native coin (Zig). |
| underlyingTokens: ['uzig'], | ||
| searchTokenOverride: STZIG_DENOM, | ||
| isIntrinsicSource: true, | ||
| url: 'https://valdora.finance/stake', |
| const ZIG_PRICE_KEY = 'zigchain:uzig'; | ||
| const DECIMALS = 1e6; | ||
|
|
||
| const VALIDATORS = [ |
There was a problem hiding this comment.
should these be hardcoded or can we get dynamically to ensure they stay up to date?
| const bondedZig = Number(stakingPool.pool?.bonded_tokens || 0) / DECIMALS; | ||
|
|
||
| if (!bondedZig) return 0; | ||
| return (annualProvisionsZig / bondedZig) * (1 - averageCommission) * 100; |
There was a problem hiding this comment.
should the 10% performance fee and 2% community tax be deducted or is 6.34% the APR the user will receive?
hi @permapod-rsk - yes should be stZIG |
- Switch to Promise.allSettled for validator commission fetching so that a single unresponsive validator does not abort the entire APY pipeline; failed results are filtered out and the average is computed over the remaining ones (returns 0 if all fail) - Deduct the 10% performance fee and the 2% community tax from the APR formula; the displayed APY now reflects net yield for the staker - Add pricePerShare field by querying the exchange_rate from the staker contract, covering the stZIG→ZIG conversion ratio for liquid assets - Validator addresses remain hardcoded for now: the chain does not expose a public endpoint to enumerate Valdora's curated validator set
The contract does not expose an exchange_rate query endpoint, causing HTTP 500 errors. Compute pricePerShare from funds_raised / total_supply instead.
|
The valdora-finance adapter exports pools: Test Suites: 1 passed, 1 total |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/adaptors/valdora-finance/index.js`:
- Around line 78-81: The balance handling in the Valdora Finance adaptor is
defaulting missing contract values into valid-looking numbers, which can mask
bad responses. In the logic around the fundsRaised and totalSupply calculations,
validate that `fundsRaised.funds_raised` and `totalSupply.total_supply` are
present, numeric, and positive before computing `tvlUsd` and `pricePerShare`; if
either value is missing or malformed, return null/skip instead of falling back
to 0 or 1. Update the checks in the `index.js` flow so downstream ingestion
never receives a fabricated positive ratio from `pricePerShare`.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b691f0fa-5e3a-4f96-b374-cacf61434620
📒 Files selected for processing (1)
src/adaptors/valdora-finance/index.js
| const fundsRaisedValue = Number(fundsRaised.funds_raised || 0); | ||
| const totalSupplyValue = Number(totalSupply.total_supply || 1); | ||
| const tvlUsd = (fundsRaisedValue / DECIMALS) * zigPrice; | ||
| const pricePerShare = fundsRaisedValue / totalSupplyValue; |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Validate contract balances instead of defaulting missing values.
totalSupply.total_supply || 1 can publish a bogus positive pricePerShare when the contract response is missing or malformed, and fundsRaised.funds_raised || 0 can silently turn bad data into zero TVL. Since downstream only nulls non-finite/non-positive pricePerShare, this bad ratio can survive ingestion.
Suggested fix
- const fundsRaisedValue = Number(fundsRaised.funds_raised || 0);
- const totalSupplyValue = Number(totalSupply.total_supply || 1);
+ 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;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const fundsRaisedValue = Number(fundsRaised.funds_raised || 0); | |
| const totalSupplyValue = Number(totalSupply.total_supply || 1); | |
| const tvlUsd = (fundsRaisedValue / DECIMALS) * zigPrice; | |
| const pricePerShare = fundsRaisedValue / totalSupplyValue; | |
| 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; |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/adaptors/valdora-finance/index.js` around lines 78 - 81, The balance
handling in the Valdora Finance adaptor is defaulting missing contract values
into valid-looking numbers, which can mask bad responses. In the logic around
the fundsRaised and totalSupply calculations, validate that
`fundsRaised.funds_raised` and `totalSupply.total_supply` are present, numeric,
and positive before computing `tvlUsd` and `pricePerShare`; if either value is
missing or malformed, return null/skip instead of falling back to 0 or 1. Update
the checks in the `index.js` flow so downstream ingestion never receives a
fabricated positive ratio from `pricePerShare`.
There was a problem hiding this comment.
gm @permapod-rsk, can you fix this issue pls? falling back to these can ingest incorrect values
There was a problem hiding this comment.
@0xkr3p Agreed — those fallbacks can mask malformed contract responses and produce a bogus pricePerShare.
@permapod-rsk please update this so funds_raised and total_supply are validated explicitly before computing tvlUsd / pricePerShare, and skip or throw on invalid values instead of defaulting to 0 / 1.
Summary by CodeRabbit