[Contract] Add Flash Loan Protection Guard in Carbon AMM - #940
Open
Topmatrixmor2014 wants to merge 8 commits into
Open
[Contract] Add Flash Loan Protection Guard in Carbon AMM#940Topmatrixmor2014 wants to merge 8 commits into
Topmatrixmor2014 wants to merge 8 commits into
Conversation
added 5 commits
July 29, 2026 15:30
Topmatrixmor2014
force-pushed
the
feat/789-flash-loan-protection
branch
from
July 29, 2026 14:31
c491796 to
d52beb4
Compare
Contributor
Author
|
Conflicts Resolved |
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.
[Contract] Add Flash Loan Protection Guard in Carbon AMM
Closes #789
Summary
Adds a flash loan protection guard to the
carbon-dexliquidity pool contract that prevents single-block flash loan manipulations in pricing queries.Changes Made
New Error Code:
FlashLoanAttempt = 15emitted when a same-ledger interaction is detected on an existing positionStorage:
LastInteractionLedger(Address, Address)tracks the last ledger sequence for each (token, provider) positionConstants:
FLASH_LEDGER_BUFFER = 1minimum number of ledgers that must elapse between consecutive interactionsGuarded Functions:
deposit()callsassert_no_flash_loan()before processing andupdate_interaction_ledger()afterwithdraw()callsassert_no_flash_loan()before processing andupdate_interaction_ledger()afterNew Public View Function:
get_last_interaction_ledger(token, provider) -> u32returns the last ledger sequence when the position was modifiedInternal Helpers:
assert_no_flash_loan(env, token, provider)panics withFlashLoanAttemptif current ledger is within bufferupdate_interaction_ledger(env, token, provider)persists the current ledger sequenceCI Fixes Included
Testing
Acceptance Criteria