Skip to content
This repository was archived by the owner on Oct 3, 2026. It is now read-only.

Flash swap feature - #123

Merged
kinrezC merged 7 commits into
feat/v0.3.0from
feat/flash-swap
Apr 10, 2024
Merged

kinrezC merged 7 commits into
feat/v0.3.0from
feat/flash-swap

Conversation

@Alexangelj

Copy link
Copy Markdown
Contributor

Flash swaps will optimistically send tokens out during swaps before the input tokens are requested. This will enable the output of a swap to be used for payments in other integrated protocols.

Changes:

  • Adds callbackData argument to swap(). This argument is passed to the callback() to msg.sender. If the length of data is 0, it will not do the callback and instead use _transferFrom().
  • Adds the ISwapCallback interface to define the callback function.
  • Re-orders the business logic of the swap token transfers to transfer the tokens to recipient before the input tokens are required/requested.

Concerns:

  • cross pool interaction using flash swaps
  • incorrect usage of callback
  • arbitrary data passed through the swap entrypoint is arbitrary (but only used in the callback call)

@Alexangelj
Alexangelj requested review from clemlak and kinrezC April 7, 2024 21:11
@Alexangelj Alexangelj added 💡 feature New features 🧹 improvement Code improvements or cleanup 🚧 DO NOT MERGE 🚧 Do not merge labels Apr 7, 2024
@Alexangelj

Copy link
Copy Markdown
Contributor Author

Do not merge until the compilation is fixed. fighting stack too deep

@clemlak clemlak removed the 🚧 DO NOT MERGE 🚧 Do not merge label Apr 10, 2024
@clemlak
clemlak marked this pull request as ready for review April 10, 2024 10:30
Comment thread src/DFMM.sol
Comment on lines +281 to +286
uint256 downscaledAmount =
downscaleUp(state.amountIn, computeScalingFactor(state.tokenIn));
uint256 postBalance = ERC20(state.tokenIn).balanceOf(address(this));
if (postBalance < preBalance + downscaledAmount) {
revert InvalidTransfer();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed a small issue here: some amounts were in WAD and some were not.

@clemlak

clemlak commented Apr 10, 2024

Copy link
Copy Markdown
Contributor

I fixed the stack too deep error, a small issue related to WAD units and added a couple of tests. We should be good now.

@kinrezC
kinrezC changed the base branch from main to feat/v0.3.0 April 10, 2024 16:49
@kinrezC
kinrezC merged commit 41e38be into feat/v0.3.0 Apr 10, 2024
@kinrezC
kinrezC deleted the feat/flash-swap branch April 10, 2024 18:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

💡 feature New features 🧹 improvement Code improvements or cleanup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants