Repository navigation
feat(SC-006): AMM reentrancy guards, lp_token module, 0.3% fee tests - #1711
Open
esthertitilayo-dev wants to merge 1 commit into
Open
esthertitilayo-dev wants to merge 1 commit into
esthertitilayo-dev wants to merge 1 commit into
Conversation
…e math module (StellarDevHub#1627) - Add temporary-storage reentrancy mutex (error 405) to add_liquidity, remove_liquidity, swap_a_for_b, and swap_b_for_a (flash-swap defense) - Create contracts/amm/src/lp_token.rs with testable mint/burn share math (initial_shares, deposit_shares, withdrawal_amounts, isqrt) and no-dilution unit tests; lib.rs now delegates share accounting to this module - Align base swap fee with spec (0.3% = 30 bps) and add fee-accumulator test asserting 0.3% base + price-impact uplift - Add reentrancy tests: guard blocks double entry (#405) and is released after successful calls
|
@esthertitilayo-dev 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! 🚀 |
|
@esthertitilayo-dev is attempting to deploy a commit to the Ayomide Adeniran's projects Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
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.
Closes #1627
Summary
add_liquidity,remove_liquidity,swap_a_for_b,swap_b_for_a) now holds a temporary-storage mutex for the whole call; a reentrant entry reverts with new typed errorAmmError::Reentrancy(405). Temporary storage guarantees a stale lock cannot survive ledger close.lp_token.rs(spec key file): extracted LP share math into a dedicated, fully unit-tested module —initial_shares(sqrt minus dead shares),deposit_shares(min of the two reserve ratios ⇒ no dilution),withdrawal_amounts(pro-rata inverse of mint),isqrt.lib.rsdelegates to it.0.3% base + price-impact upliftandout = out_before - fee.Acceptance criteria
test_constant_product_invariant_swap+ fuzz tests verifyk_after >= k_beforeand slippage reverts protect reserves.deposit_shares_does_not_dilute_existing_lpsproves pre-existing claims never shrink;test_remove_liquiditycovers withdrawal.test_fuzz_amm_k_invariant_one_million_continuous_actionsruns 1,000,000 continuous actions;prop_fuzz_amm_arbitrary_tradesadds 50 proptest cases.Test plan
cargo test -p amm— 28 unit + 2 fuzz tests pass.cargo check -p amm— clean;rustfmt --checkclean on new/edited code (pre-existing fmt drift intwap.rs/get_twap_cumulativeuntouched).