Skip to content

docs(contracts): document RepoDvP margin and maturity semantics in AUDIT_NOTES (#204) - #1274

Merged
DevTobis merged 3 commits into
DevTobis:mainfrom
Anambraboi-1:docs/repo-dvp-margin-maturity-semantics
Nov 26, 2026
Merged

DevTobis merged 3 commits into
DevTobis:mainfrom
Anambraboi-1:docs/repo-dvp-margin-maturity-semantics

Conversation

@Anambraboi-1

Copy link
Copy Markdown
Contributor

Closes #204

Adds a Margin and maturity semantics list to the RepoDvP section of contracts/AUDIT_NOTES.md. Each item gives the behaviour, the code reference and what it means for consumers or lenders. Each also links to its tracking issue where one exists.

Behaviours documented

  1. margin_call_amount is a value shortfall, not a unit count. It is in post-haircut USDC base units (lib.rs:1067-1071). The item gives the formula that converts it to RWA units. It also notes that a partial top_up leaves the figure stale (RepoDvp.top_up leaves margin_call_amount stale after a partial top-up #847) and that its exact value is not yet asserted in tests (Assert the exact margin_call_amount computed by RepoDvp.call_margin #203).
  2. Exposure stops accruing at maturity_at. lib.rs:523 caps accrual at maturity, so margin, default_close and unwind all use the same figure. There is no late interest. (RepoDvp margin exposure keeps accruing after maturity but unwind charges only to maturity #218)
  3. Non-payment at maturity is remedied by default_at_maturity, not default_close. default_close needs an open margin call (lib.rs:1152-1154). default_at_maturity can act only after maturity_at + maturity_grace. (Add a maturity default path to RepoDvp for a borrower who does not repay at leg 2 #26)
  4. Neither default path acts without an Ok price. There is no last-good fallback (lib.rs:1163-1164, lib.rs:1239-1242), so the lender carries the price risk until the halt clears. Tests for these refusals are tracked in Test RepoDvp.default_close authorisation and precondition failures #237.

The "Cash legs are not escrowed" bullet now also covers the borrower-side allowance overwrite. Every accept_and_settle replaces the borrower's allowance, which is why the contract approves the running BorrowerDue sum. The bullet links #843.

Note on the issue text

Two facts in the issue are out of date on main:

The notes describe the code as it is now and say what changed.

Finding while writing this

default_at_maturity does not call release_borrower_due, but unwind and default_close do. As a result, a trade defaulted at maturity stays in the borrower's BorrowerDue sum, and every later settle approves more than the borrower owes. The notes record this. A code fix is out of scope for this docs PR.

Docs only. No code changes, so the WASM hash is unchanged.

@DevTobis

Copy link
Copy Markdown
Owner

Thanks @Anambraboi-1! You documented the RepoDvP margin and maturity semantics in AUDIT_NOTES for #204:

  • margin_call_amount is a post-haircut value shortfall, with the units formula;
  • exposure stops accruing at maturity;
  • non-payment at maturity is remedied by default_at_maturity, not default_close;
  • neither default acts without an Ok price;
  • the borrower-side allowance overwrite is noted in the cash-legs bullet.

Each item gives its consequence and links its issue. I merged main in, swapped the lib.rs:NNN line references for function names (they had already drifted), and noted that #203 now asserts the exact amount. This closes #204. Merging now.

@DevTobis
DevTobis merged commit 4b12cf5 into DevTobis:main Nov 26, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document RepoDvp margin and maturity semantics in AUDIT_NOTES

2 participants