Skip to content

#599 Fixed-Point-Math | Constant Product Invariants via U256 High-Precision Engine - #3

Merged
oraimoitel merged 2 commits into
mainfrom
feature/fixed-point-math-599
Oct 18, 2026
Merged

oraimoitel merged 2 commits into
mainfrom
feature/fixed-point-math-599

Conversation

@oraimoitel

Copy link
Copy Markdown
Owner

Description

Core AMM swap module maintaining constant product (x * y = k) invariants without precision loss or rounding vulnerabilities.

Changes

  • Created src/amm/invariant.rs with U256 struct (two u128 words) for 256-bit intermediate products
  • compute_swap_out: out = reserve_out * amount_in / (reserve_in + amount_in) with floor rounding
  • compute_lp_shares: min(a * total / reserve_a, b * total / reserve_b) with floor rounding
  • compute_remove_liquidity: proportional withdrawals with floor rounding
  • assert_invariant_stable: verifies k is non-decreasing after swaps
  • All rounding directional bias favors pool reserves (floor division)
  • Unit tests covering basic ops, max bounds, high-volume scenarios

Closes StellarFlow-Network#599

StellarFlow Developer and others added 2 commits July 26, 2026 09:14
…igh-precision engine

Core AMM swap math maintaining x*y=k without precision loss:
- U256 struct for 256-bit intermediate products of two u128 values
- mul_div with full precision, always rounding down (favors pool reserves)
- compute_swap_out, compute_lp_shares, compute_remove_liquidity
- assert_invariant_stable checks k is non-decreasing
- Unit tests covering basic ops, max bounds, high volume scenarios
@oraimoitel
oraimoitel merged commit cba28b5 into main Oct 18, 2026
0 of 2 checks passed
oraimoitel pushed a commit that referenced this pull request Oct 18, 2026
…or-warning-monitor

feat: add dynamic vault health warning monitor
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.

1 participant