Repository navigation
Conversation
|
@Emmazlee 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! 🚀 |
Author
|
this PR is ready for another review. I resolved the merge conflicts with the develop branch (pushed 5f964e3). |
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.
Overview
This PR hardens market-core by enforcing the solvency invariant at runtime. It adds a global
TotalLockedcounter and a per-marketlockedfigure, wraps every collateral transfer in a balance-delta check, adds a global solvency guard after outflows, and exposessolvency_report/global_solvencyviews. Silent insolvency (fee-on-transfer, clawback, buggy collateral) now reverts loudly at the first offending transfer instead of surfacing as a failed last redeemer.Related Issue
Changes
🔒 Runtime Solvency Accounting
[MODIFY]
oracledesk-stellar/contracts/market-core/src/lib.rsDataKey::TotalLocked(instance,i128, initialised to 0 in__constructor) andDataKey::Locked(u64)(persistent,i128), with asave_lockedhelper using the same TTL policy asMarket.transfer_in/transfer_outhelpers that measure the contract's actual balance delta and revert withError::CollateralMismatchon any mismatch;transfer_outdecrementsTotalLockedbefore running the global guardbalance >= TotalLocked(reverts withError::Insolvent).create_market,buy,sell,redeem,claim_pool_remainder,sweep_fees) with the checked helpers and applied the documented accounting deltas tolockedandTotalLocked.Error::CollateralMismatch = 19andError::Insolvent = 20.SolvencyReportcontracttype andsolvency_report(market_id)/global_solvency()views.set_treasurynow rejects the market-core address itself (self-transfer would be a zero-delta sweep).#[cfg(test)] mod skim_tokenmock SEP-41 token that skims a fee, plus asetup_market_with_tokenfixture and tests covering lifecycle tracking, skim-token reverts oncreate_marketandbuy, donations, void dust, andset_treasuryself-rejection.[MODIFY]
oracledesk-stellar/packages/bindings/market-core/src/index.tsSolvencyReporttype,solvency_report/global_solvencymethods, and theCollateralMismatch/Insolventerror entries.[MODIFY]
oracledesk-stellar/docs/architecture.mdVerification Results
DataKey::TotalLockedandDataKey::Locked(u64)exist and are updated at all six transfer sitestransfer_in/transfer_outwith balance-delta verificationError::CollateralMismatchandError::Insolventadded, each triggered by a testcreate_marketandbuyrevert withCollateralMismatchsolvency_reportandglobal_solvencyviews exist and are covered by testsset_treasuryrejects the market-core address itselfbuyandredeemdocumented in the PRenv.cost_estimate()before/aftermarket_core.wasmcargo test --workspaceandmake lintpass, bindings regenerateddocs/architecture.mddescribes the enforced invariant, accounting rules and clawback behaviourCloses #4