Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase to pull in upstream Ambient changes and improvements #3

Open
wants to merge 63 commits into
base: main
Choose a base branch
from

Conversation

jkilpatr
Copy link
Contributor

This pr rebases our current changes onto the upstream crocswap dex repo

…ke L2s. Add script for printing storage layout
Addresses existing issue where some swap() calls made with 0 quantity
were causing very small payouts to the caller without receiving any tokens.

Change to core code in this patch is:

Check all swaps for 0 qty or reached limit price at the start of swap
call. If swap already meets these terminating conditions, skip entire
operation and make zero change to curve and set token flows to 0 instead
of carrying out first leg of swap step. This change has no effect for normal
swaps with non-zero quantity and non-zero limit order slippage.

Add additional assert checks in the swapToLimit() step operation to abort the
transaction if any invariants are violated. These assert checks do not alter
swap logic, state changes, or value transferred in any way. The only difference
is that some swap transctions will revert, but this will not affect any ordinary
swap transactions. The addition invariant asserts added are:

   - Assert limit price direction relative to curve price matches swap's isBuy flag
     before swapOverCurve() calculates price change and swap flow
   - Assert the price movement direction of the rollFlow() operation matches the
     swap's isBuy direction. This assert specifically detects the mismatch that
     caused some qty=0 to pay instead of receive the rounding collateral.
   - Assert the price movement of the full swapToLimit() step matches the swap's
     isBuy direction.

Allows the HotProxy sidecar to execute swaps regardless of the hotPathOpen_ flag
setting. Since patching existing conracts will require closing the hotPathOpen_ flag
this allows for graceful installation and handover on existing deployments.
Mister-Meeseeks and others added 30 commits August 14, 2024 12:36
When hotPathOpen_ && inSafeMode_ it was possible to execute a swap on
CrocSwapDex but not on any proxy paths. For safety this has been
disabled and will return a "LK" revert message to indicate that the DEX
is locked.

Several common revert situations now return an error string to aid in
debugging.

The authority_ and inSafeMode_ variables are exposed through public view
authority() and safeMode() functions, respectively
Added InitPool, Swap MintRanged, MintAmbient, BurnRanged, BurnAmbient, and
Harvest events to CrocEvents and inserted them in the Hot, Cold, Warm,
and Long paths where they take place. In the case of LongPath it is
possible for many events to happen on the same block, one event should
be created for each swap, mint, burn, etc.
Initially the new events had the absolute value of involved flows and
were renamed to e.g. baseQty for ease of consumer understanding. Due to
accounting needs these have been changed to the raw flow values, where
positive indicates tokens flowing into the pool and negative flowing
out.
While it is possible to derive the portion of a proven knockout claim's
baseFlow and quoteFlow which came from fees, it is quite hard to do so
without perfect context. Instead of reporting that the WithdrawKnockout
event was proven, we now report the amount of the baseFlow/quoteFlow
which comes from fees (0 for no fees or forfeiture).
This is a yarn project so we should not have a npm lock checked in.
Also restores some transfer checks that where removed.
The solidity upgrade seems to just slot in with no other changes.
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.

3 participants