Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save giovannidisiena/965baba8f5e76807704be7f474fe33a1 to your computer and use it in GitHub Desktop.

Select an option

Save giovannidisiena/965baba8f5e76807704be7f474fe33a1 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
contract LSSVMRouter {
function swapNFTsForSpecificNFTsThroughETH(
NFTsForSpecificNFTsTrade calldata trade,
uint256 minOutput,
address payable ethRecipient,
address nftRecipient,
uint256 deadline
) external payable checkDeadline(deadline) returns (uint256 outputAmount) {
// Swap NFTs for ETH
// minOutput of swap set to 0 since we're doing an aggregate slippage check
outputAmount = _swapNFTsForToken(trade.nftToTokenTrades, 0, payable(address(this)));
// Add extra value to buy NFTs
outputAmount += msg.value;
// Swap ETH for specific NFTs
// cost <= inputValue = outputAmount - minOutput, so outputAmount' = (outputAmount - minOutput - cost) + minOutput >= minOutput
outputAmount = _swapETHForSpecificNFTs(
trade.tokenToNFTTrades, outputAmount - minOutput, ethRecipient, nftRecipient
) + minOutput;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment