Repository navigation
fix(repo-dvp): make the borrower's leg-2 allowance additive across settled trades - #1083
Merged
DevTobis merged 4 commits intoOct 23, 2026
Merged
Conversation
…ttled trades SEP-41 approve replaces the (owner, spender) allowance, so a borrower's second settled trade overwrote the first one's leg-2 allowance: at maturity the keeper's or lender's unwind(1) called transfer_from for more than the remaining allowance and reverted, leaving only the borrower's own signature able to close trade 1 — in either size order. accept_and_settle now approves the sum of the borrower's outstanding leg-2 due ceilings, tracked per borrower in contract storage (added on settle, released on unwind and default_close), and the allowance expiry is never shortened below what an earlier-settled trade still needs. A non-borrower unwind consumes its own share via transfer_from; a default's unconsumed share is replaced by the next settle's accurate sum or dies at expiry, since shrinking the live allowance would need the borrower's signature. Module docs and AUDIT_NOTES.md describe the model and its residue. The reproduction test fails on the previous code exactly as the issue describes (verified by running it against the unfixed lib) and passes now; reverse order and sizes covered; residual allowance after the last close is zero; a default releases its share so the next settle approves exactly its own due. Closes DevTobis#29
|
@Salmatcre8 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! 🚀 |
Salmatcre8
marked this pull request as ready for review
October 20, 2026 09:37
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.
Summary
Implements #29 with the issue's first option — an additive allowance:
accept_and_settleapproves the sum of the borrower's outstanding leg-2 due ceilings. The sum lives in contract storage (DataKey::BorrowerDue(Address), added on settle, released onunwindanddefault_close); each ceiling istotal_due(trade, proposed_at), the same deterministic figure the old single approve used (it is an argument to a nested authorized call, so it must come out identical at simulation and execution).BorrowerDueExpirykeeps the furthest expiry granted, so a later-settling, earlier-maturing trade cannot cut the window an earlier trade's keeper unwind still needs.unwindconsumes its own trade's share of the summed allowance viatransfer_from; a defaulted trade's unconsumed share stays in the live allowance only until the next settle re-approves the accurate sum or the allowance expires — shrinking it would need the borrower's own signature. The module docs and a new AUDIT_NOTES.md bullet describe the model and this residue, per the acceptance criteria.Tests (SAC-harness module, keeper-driven)
call_margin→ lapse →default_close, then the next settle approves exactly its own due, not the stale sum.Verification
cargo test -p ballast-repo-dvp: 22/22. Full contracts workspace: 131 passed, 0 failed.Heads-up: #31 (PR #1079) and #32 (PR #1080) also touch
contracts/repo-dvp/srcfrom the sibling account's assignments; all three are based onmainand whichever lands later gets a prompt rebase.Closes #29