Pxswap
Inherits: SwapData, Ownable, HandleERC20, HandleERC721, ERC721Holder
Authors: pxswap (https://github.com/pxswap-xyz/pxswap/blob/main/src/Pxswap.sol), Ali Konuk - @alikonuk1
This contract is for buying, selling and swapping non-fungible tokens (NFTs)
Please reach out to ali@pxswap.xyz if you find any issues
State Variables
swaps
Swap[] public swaps;
protocol
address public protocol;
pxNft
address public pxNft;
flatFee
uint256 public flatFee;
discountedFee
uint256 public discountedFee;
fee
uint256 public fee;
mutex
bool public mutex;
Functions
putSwap
Creates a new swap by the seller with the specified NFTs and tokens offered.
function putSwap(
address[] memory nftsGiven,
uint256[] memory idsGiven,
address[] memory nftsWanted,
address buyer,
address tokenWanted,
uint256 amount,
uint256 ethAmount
) external noReentrancy;
Parameters
Name | Type | Description |
---|---|---|
nftsGiven | address[] | Array of addresses of the NFTs given by the seller. |
idsGiven | uint256[] | Array of IDs of the NFTs given by the seller. |
nftsWanted | address[] | Array of addresses of the NFTs wanted by the seller. |
buyer | address | The address of the buyer for the swap. |
tokenWanted | address | The address of the ERC20 token wanted by the seller. |
amount | uint256 | The amount of ERC20 tokens wanted by the seller. |
ethAmount | uint256 | The amount of ether wanted by the seller. Emits a {PutSwap} event indicating the creation of the swap and its ID. |
cancelSwap
Allows the seller to cancel an active swap and transfer the ERC721 tokens back to the seller.
function cancelSwap(uint256 id) external noReentrancy;
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | The ID of the swap to be cancelled. |
acceptSwap
Allows the buyer to accept a swap by ID and transfer the assets to the respective parties.
function acceptSwap(uint256 id, uint256[] memory tokenIds) public payable noReentrancy;
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | The ID of the swap to be accepted. |
tokenIds | uint256[] | An array of token IDs for ERC721 tokens. |
setProtocol
Function to set the protocol address.
function setProtocol(address protocol_) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
protocol_ | address | The address of the protocol. |
setFee
Allows the contract owner to set the transaction fee.
function setFee(uint256 fee_) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
fee_ | uint256 | The new transaction fee. |
setDiscountedFee
Allows the contract owner to set the discounted transaction fee.
function setDiscountedFee(uint256 discountedFee_) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
discountedFee_ | uint256 | The new discounted transaction fee. |
setFlatFee
Allows the contract owner to set the flat transaction fee.
function setFlatFee(uint256 flatFee_) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
flatFee_ | uint256 | The new flat transaction fee. |
setPxNft
Allows the contract owner to set the pxswap's nft contract address.
function setPxNft(address pxNft_) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
pxNft_ | address | pxswap's nft contract address. |
noReentrancy
modifier noReentrancy();
_nonReentrantBefore
function _nonReentrantBefore() internal;
_nonReentrantAfter
function _nonReentrantAfter() internal;
getLength
Returns the number of swaps in the contract.
function getLength() external view returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The length of the swaps array. |
getSwap
Returns the details of a specific swap by its ID.
function getSwap(uint256 id) external view returns (Swap memory);
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | The ID of the swap to be retrieved. |
Returns
Name | Type | Description |
---|---|---|
<none> | Swap | The details of the swap as a memory struct. |
Events
PutSwap
event PutSwap(uint256 indexed id);
CancelSwap
event CancelSwap(uint256 indexed id);
AcceptSwap
event AcceptSwap(uint256 indexed id);
Errors
Unauthorized
error Unauthorized();
NotActive
error NotActive();
NotEnoughEth
error NotEnoughEth();