Pxswap

Git Source

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

NameTypeDescription
nftsGivenaddress[]Array of addresses of the NFTs given by the seller.
idsGivenuint256[]Array of IDs of the NFTs given by the seller.
nftsWantedaddress[]Array of addresses of the NFTs wanted by the seller.
buyeraddressThe address of the buyer for the swap.
tokenWantedaddressThe address of the ERC20 token wanted by the seller.
amountuint256The amount of ERC20 tokens wanted by the seller.
ethAmountuint256The 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

NameTypeDescription
iduint256The 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

NameTypeDescription
iduint256The ID of the swap to be accepted.
tokenIdsuint256[]An array of token IDs for ERC721 tokens.

setProtocol

Function to set the protocol address.

function setProtocol(address protocol_) external onlyOwner;

Parameters

NameTypeDescription
protocol_addressThe address of the protocol.

setFee

Allows the contract owner to set the transaction fee.

function setFee(uint256 fee_) external onlyOwner;

Parameters

NameTypeDescription
fee_uint256The new transaction fee.

setDiscountedFee

Allows the contract owner to set the discounted transaction fee.

function setDiscountedFee(uint256 discountedFee_) external onlyOwner;

Parameters

NameTypeDescription
discountedFee_uint256The new discounted transaction fee.

setFlatFee

Allows the contract owner to set the flat transaction fee.

function setFlatFee(uint256 flatFee_) external onlyOwner;

Parameters

NameTypeDescription
flatFee_uint256The new flat transaction fee.

setPxNft

Allows the contract owner to set the pxswap's nft contract address.

function setPxNft(address pxNft_) external onlyOwner;

Parameters

NameTypeDescription
pxNft_addresspxswap'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

NameTypeDescription
<none>uint256The 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

NameTypeDescription
iduint256The ID of the swap to be retrieved.

Returns

NameTypeDescription
<none>SwapThe 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();