This PR implements critical fixes, performance security enhancements, and robust verification tests across four key areas for the StellarYield platform:
-
Checked Arithmetic & Precision-Preserving Fees (Issue #714):
- Modified
settle_batchin thesettlementcontract to enforce checked addition (checked_add) fortotal_amount0andtotal_amount1against individual trade values. - Refactored
collect_feesto implement standard half-up rounding for fee calculations ((amount * fee_bps + 5000) / 10000). - Resolved Soroban authentication conflicts in tests by using
mock_all_auths_allowing_non_root_auth(). - Added comprehensive integration and unit tests covering sum validation, negative amounts, mismatch panics, and fee rounding logic.
- Modified
-
Cross-Protocol Yield Opportunity Ranking Engine (Issue #248):
- Implemented
server/src/services/opportunityRankingService.tswith min-max normalization to rank opportunities across Stellar DeFi protocols. - Exposed
/api/yields/rankingroute inserver/src/routes/yields.tssupporting custom APY, TVL, liquidity, maturity, and volatility weight inputs. - Verified the engine via extensive unit tests in
server/src/__tests__/opportunityRankingService.test.ts.
- Implemented
-
Secure Backend proxy for secrets & CI guardrails (Issue #717):
- Added
/api/offrampproxy endpoint underserver/src/routes/offramp.tsto keepOFFRAMP_API_KEYserver-side, preventing API key exposure to the browser. - Refactored
offRampService.tsandGoogleSheetsPanel.tsxto remove direct exposure ofVITE_OFFRAMP_API_KEYandVITE_GOOGLE_CLIENT_SECRET. - Introduced
scripts/check-frontend-env.jsas a CI check that automatically scans frontend builds and.envfiles to reject browser-exposed secrets.
- Added
-
Rewards Merkle Distributor Integration (Issue #719):
- Connected off-chain Merkle generator outputs to the
merkle_distributorcontract's validation logic. - Implemented
backend/rewards/src/__tests__/merkleDistributorIntegration.test.tsverifying the encoding invariant (off-chain SHA-256 vs. on-chaincompute_leaf), anti-double-claim bitmap tracking, and cross-epoch root rotation.
- Connected off-chain Merkle generator outputs to the
- Closes #714
- Closes #719
- Closes #717
- Closes #248
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing functionality to not work as expected)
- Documentation update
- Refactor
- Other (please describe):
- Smart Contracts: Ran
cargo test --package settlement --lib(10/10 passing). - Backend Rewards: Ran
npm run test(49/49 passing). - CI Env Guardrail: Verified
scripts/check-frontend-env.jscatches unsafeVITE_variables and exits with non-zero code.
- Frontend changes tested
- Backend changes tested
- Contracts changes tested
- Documentation updated
- Migrations tested (if applicable)
- Set
OFFRAMP_API_KEYandGOOGLE_CLIENT_SECRETin the backend environment variables. Do not prefix them withVITE_as they are now securely proxied via backend routers.