Skip to content

fix: Add AMMv1_3 amendment#690

Merged
RichardAH merged 2 commits intodevfrom
fixAMMv1_3
Feb 25, 2026
Merged

fix: Add AMMv1_3 amendment#690
RichardAH merged 2 commits intodevfrom
fixAMMv1_3

Conversation

@tequdev
Copy link
Member

@tequdev tequdev commented Feb 19, 2026

  • Add AMM bid/create/deposit/swap/withdraw/vote invariants:
    • Deposit, Withdrawal invariants: sqrt(asset1Balance * asset2Balance) >= LPTokens.
    • Bid: sqrt(asset1Balance * asset2Balance) > LPTokens and the pool balances don't change.
    • Create: sqrt(asset1Balance * assetBalance2) == LPTokens.
    • Swap: asset1BalanceAfter * asset2BalanceAfter >= asset1BalanceBefore * asset2BalanceBefore and LPTokens don't change.
    • Vote: LPTokens and pool balances don't change.
    • All AMM and swap transactions: amounts and tokens are greater than zero, except on withdrawal if all tokens are withdrawn.
  • Add AMM deposit and withdraw rounding to ensure AMM invariant:
    • On deposit, tokens out are rounded downward and deposit amount is rounded upward.
    • On withdrawal, tokens in are rounded upward and withdrawal amount is rounded downward.
  • Add Order Book Offer invariant to verify consumed amounts. Consumed amounts are less than the offer.
  • Fix Bid validation. AuthAccount can't have duplicate accounts or the submitter account.

XRPLF/rippled@621df42#diff-7dad437f303738675bcd6bee30905b526685288f8d752544538dc3b7040cf20d

* Add AMM bid/create/deposit/swap/withdraw/vote invariants:
  - Deposit, Withdrawal invariants: `sqrt(asset1Balance * asset2Balance) >= LPTokens`.
  - Bid: `sqrt(asset1Balance * asset2Balance) > LPTokens` and the pool balances don't change.
  - Create: `sqrt(asset1Balance * assetBalance2) == LPTokens`.
  - Swap: `asset1BalanceAfter * asset2BalanceAfter >= asset1BalanceBefore * asset2BalanceBefore`
     and `LPTokens` don't change.
  - Vote: `LPTokens` and pool balances don't change.
  - All AMM and swap transactions: amounts and tokens are greater than zero, except on withdrawal if all tokens
    are withdrawn.
* Add AMM deposit and withdraw rounding to ensure AMM invariant:
  - On deposit, tokens out are rounded downward and deposit amount is rounded upward.
  - On withdrawal, tokens in are rounded upward and withdrawal amount is rounded downward.
* Add Order Book Offer invariant to verify consumed amounts. Consumed amounts are less than the offer.
* Fix Bid validation. `AuthAccount` can't have duplicate accounts or the submitter account.
@tequdev tequdev changed the base branch from sync-2.4.0 to dev February 25, 2026 01:22
@RichardAH RichardAH merged commit ec65e62 into dev Feb 25, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants