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

Flash swap feature #123

Merged
merged 7 commits into from
Apr 10, 2024
Merged

Flash swap feature #123

merged 7 commits into from
Apr 10, 2024

Conversation

Alexangelj
Copy link
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
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 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
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
Copy link
Contributor

clemlak commented Apr 10, 2024

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
5 checks passed
@kinrezC kinrezC deleted the feat/flash-swap branch April 10, 2024 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 feature New features 🧹 improvement Code improvements or cleanup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants