Add vault invariants, risk limits, oracle failure tests, and nightly benches - #1293
Merged
Conversation
|
@amanosiadnan-cmyk Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Owner
|
Resolved merge conflicts and merged via local rebase. Content is now on main. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
closes #1166
closes #1173
closes #1231
closes #1235
PR description
Summary
This PR hardens YieldVault accounting and exposure, then adds the oracle failure suite and nightly contract benchmarks. The repo is Stellar/Soroban (Rust), not EVM, so Foundry/Anvil acceptance criteria are implemented with Soroban
Envtests, mock oracles, host CPU/memory metering, and GitHub Actions.#1166 — Contract-level total-supply and share-price invariants
Vault accounting is now checked before
VaultStateis persisted, not only in off-chain tests.Invariants (enforced in
persist_accounting_state):total_shares >= 0andtotal_assets >= 0total_shares > 0⇒total_assets > 0)0share_price == floor(total_assets * 10^18 / total_shares)and> 0Broken snapshots return
VaultError::MathOverflow(error enum is capped at 50 cases). Donated assets with zero shares remain allowed.Hooks:
deposit,gasless_deposit,batch_deposit,withdraw, queued withdraw,accrue_yield,report_benji_yield.Tests: unit violation snapshots in
invariants.rs; transition/regression coverage ininvariant_tests.rs.Docs:
docs/VAULT_INVARIANTS.md#1173 — Protocol-level risk limits for vault exposure
Hard caps on top of per-strategy
StrategyCap/StrategyRiskThreshold. Defaults are unlimited so existing flows stay unchanged.0(off)invest,rebalanceinvest,rebalanceStress mode uses
min(normal, stress)so it can only tighten. Overrun then recover: withdraw (TVL) or divest (concentration), then the same op is allowed again.Overrides (documented, no force-invest backdoor):
set_max_vault_tvl,set_max_conc_bps,set_max_deployed_bps); TVL0= unlimitedLiquidityCrisis/OracleFailure) as a full haltStorage is nested under
DataKeyExt::Risk(RiskExtKey)to stay within Soroban key limits.Tests: overrun + recovery for TVL, strategy cap, concentration, and stress-mode override.
Docs:
docs/PROTOCOL_RISK_LIMITS.md#1235 — Oracle failure test suite
Mock oracle failure modes: stale heartbeat, zero/negative price, invalid decimals, deviation spike (3×), future timestamp, network partition, timeout.
Vault wiring:
execute_price_oracle_changetotal_assets(and thusinvest)Tests: validator edge cases + mock oracle wired into the vault (
cargo test -p vault oracle); mock crate tests all pass (cargo test -p mock-strategy→ 6/6).Docs:
docs/ORACLE_FAILURE_HANDLING.md(classify → halt → rotate/resume; no stale-price fallback)#1235 — Nightly contract benchmarks
Soroban equivalent of
forge test --gas-report:contracts/vault/tests/benchmarks.rsmeasures host CPU/memory for deposit, withdraw, invest, switch strategy on two Benji strategy instances (v1 vs v2)contracts/vault/scripts/benchmark.shparsesBENCHlines, writes the report, fails if any op exceeds baseline + 15%.github/workflows/nightly-benchmarks.ymlruns at 02:00 UTC, uploads the summary, and posts/comments a GitHub Issue (nightly-benchmark)Docs:
docs/PERFORMANCE_REGRESSION.mdBaseline:
contracts/vault/benches/baseline.jsonHow to verify