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.
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
SIP-399: Perps V3 Flash Loan Utility #2039
SIP-399: Perps V3 Flash Loan Utility #2039
Changes from all commits
76f80a0
b127c49
d637385
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please tell me which argument is given to ensure that sandwishes are constrained?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amountOutMinimum
: https://github.com/Synthetixio/synthetix-v3/blob/b8f01cdaa829f7630c2064ed5717c86d7c3c3dc3/auxiliary/PerpsFlashLoanUtil/contracts/PerpsFlashLoanUtil.sol#L119which is derived from uniswap's
IQuoter.quoteExactInput
:https://github.com/Uniswap/v3-periphery/blob/main/contracts/interfaces/IQuoter.sol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhh this
amountOutMinimum
is included incalldata
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we fetch it from the IQuoter at L119 in
executeOperation
:And then we use it to do the swap:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe i'm not clear, but how does the front-end is able to specify a minimum amount of USDC that he expects to receive for selling his wETH/wBTC margin so that he doesn't get rugged with a sandwish... Like to protect against this, the front-end gives a user a interface to specify a maximum amount of slippage against a centralized exchange price, that he is willing to accept.. If the return on the uniswap trade yields fewer USDC against the ETH that was to be sold all of it reverts... The uni/flash quoter, which uses on-chain data, I think ensures that the transaction goes through, but does not protect the trader against a sandwish attack which involves pushing uniswap prices around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see what you mean. Can we mitigate this by quoting the min amount of USDC in
requestFlashLoan
, and pass it toparams
for execution? The user can be shown the amount of USDC expected to close their position at the time of requesting.This way, the user requests a flash loan with a quoted amount in the first block. And then if the price moves down by the following block when the execution is processed, it can compare the initially quoted amount to a new quote and revert if outside the slippage range.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like let's do an example:
At no point in this set of transaction is the rate of swap ETH to USDC is specified. Uness we can configure the maximum amount of ETH margin is allowed to be spent somewhere, or the rate of ETH to USDC,