Last active
July 18, 2023 16:42
-
-
Save giovannidisiena/641aeb5a29bf2abe9b7ce020255f7cfe to your computer and use it in GitHub Desktop.
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
| // SPDX-License-Identifier: AGPL-3.0 | |
| pragma solidity ^0.8.0; | |
| contract LSSVMRouter { | |
| function _swapETHForSpecificNFTs( | |
| PairSwapSpecific[] calldata swapList, | |
| uint256 inputAmount, | |
| address payable ethRecipient, | |
| address nftRecipient | |
| ) internal virtual returns (uint256 remainingValue) { | |
| remainingValue = inputAmount; | |
| uint256 pairCost; | |
| CurveErrorCodes.Error error; | |
| // Do swaps | |
| uint256 numSwaps = swapList.length; | |
| for (uint256 i; i < numSwaps;) { | |
| // Calculate the cost per swap first to send exact amount of ETH over, saves gas by avoiding the need to send back excess ETH | |
| (error,,, pairCost,,) = swapList[i].pair.getBuyNFTQuote(swapList[i].nftIds[0], swapList[i].nftIds.length); | |
| // Require no errors | |
| require(error == CurveErrorCodes.Error.OK, "Bonding curve error"); | |
| // Total ETH taken from sender cannot exceed inputAmount | |
| // because otherwise the deduction from remainingValue will fail | |
| remainingValue -= swapList[i].pair.swapTokenForSpecificNFTs{value: pairCost}( | |
| swapList[i].nftIds, remainingValue, nftRecipient, true, msg.sender | |
| ); | |
| unchecked { | |
| ++i; | |
| } | |
| } | |
| // Return remaining value to sender | |
| if (remainingValue > 0) { | |
| ethRecipient.safeTransferETH(remainingValue); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment