Skip to content

Commit

Permalink
Feature:Add Permit Buy to buy offline signed NFT
Browse files Browse the repository at this point in the history
  • Loading branch information
imsoso committed Nov 2, 2024
1 parent 6fe3c53 commit 3cf84f5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions solidity-scripting/src/W4D1/NFTMarketWithPermit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,27 @@ contract NFTMarketV3 is Ownable(msg.sender), EIP712("OpenSpaceNFTMarket", "1") {
emit List(nft, tokenId, orderId, msg.sender, payToken, price, deadline);
}

function permitBuy(
bytes32 orderId,
uint256 amount,
uint256 deadline,
uint256 nonce,
uint8 v,
bytes32 r,
bytes32 s
) external {
bytes32 hash = keccak256(abi.encodePacked(msg.sender, orderId, amount, deadline, nonce));
address signer = ecrecover(hash, v, r, s);
require(signer == msg.sender, "Invalid signature");
SellOrder memory order = listingOrders[orderId];

IERC20(order.payToken).transferFrom(msg.sender, address(this), amount);
IERC721(order.nft).safeTransferFrom(address(this), msg.sender, order.tokenId);

emit PermitSold(orderId, msg.sender, signer);

}

event List(
address indexed nft,
uint256 indexed tokenId,
Expand All @@ -239,6 +260,7 @@ contract NFTMarketV3 is Ownable(msg.sender), EIP712("OpenSpaceNFTMarket", "1") {
);
event Cancel(bytes32 orderId);
event Sold(bytes32 orderId, address buyer, uint256 fee);
event PermitSold(bytes32 orderId, address buyer, address signer);
event SetFeeTo(address to);
event SetWhiteListSigner(address signer);
}

0 comments on commit 3cf84f5

Please sign in to comment.