Nft Swap
Tutorial on deployment, configuration and interaction with Nft Swap contracts suite, which consists of 3 parts: SwapSigner, NftSwap and SwapParams.
Description
SwapSigner - holds address for signature verification. It is used by NftSwap and SwapParams contracts.
NftSwap - part of Seascape marketplace platform. It allows users to obtain desired nfts in exchange for their offered nfts, a fee and an optional bounty
SwapParams - is nft params encoder/decoder, signature verifyer
Deployment
NftSwap works in conjunction with SwapSigner contract, which holds public address, required to verify signatures in createOffer() and acceptOffer(). SwapParams contracts are deployed for each nft series we want supported.
Deploy SwapSigner.sol
2. Deploy NftSwap.sol. Constructor takes 3 arguments:
_feeRate amount of fee to be spend by creator of offer. Parameter should be formatted with web3 wrapper. For example: _feeRate = web3.utils.toWei("1", "ether"); -> sets fee to 1 coin.
_crowns address of native currency to operate in NftSwap. _feeRate of _crowns is transfered from msg.sender to contract upon calling createOffer(). _feeRate of is then spend by contract when acceptOffer() is called. If using currency other than crowns, make sure it has spend method implemented.
_signer address of deployed SwapSigner contract from first step.
Before deploying double-check correctness of _crowns and _signer arguments as they can't be changed later.
3. Deploy SwapParams contracts for each nft series to be supported by NftSwap. Takes 1 argument:
_signer address of deployed SwapSigner contract from first step.
Again, make sure _signer argument is correct as it cant be changed.
After deployment contracts should be verified to enable interaction via Etherscan.
Configuration
Run init.js script available on Github or call the following methods via Etherscan.
SwapSigner.sol
In constructor signer is set to contract creator and should be changed. Call setSigner(address _signer) with different _signer address to change it.
2. NftSwap.sol
call addSupportedBountyAddress(address _bountyAddress) for each currency to be supported by contract.
call enableSupportedNftAddress( address _nftAddress, address _nftParamsAddress ) for each nft series to be supported by contract. _nftParamsAddress address from deployment step 3. Make sure _nftParamsAddress relates to the correct _nftAddress.
Interaction
SwapSigner.sol
getSigner() returns current signer
(onlyOwner) setSigner(address _signer) set new signer
2. NftSwap.sol
createOffer( uint8 _offeredTokensAmount, OfferedToken [5] memory _offeredTokens, uint8 _requestedTokensAmount, RequestedToken [5] memory _requestedTokens, uint256 _bounty, address _bountyAddress) by creating a new offer, seller will transfer offered tokens, fee and an optional bounty to the contract
acceptOffer( uint256 _offerId, uint256 [5] memory _requestedTokenIds, address [5] memory _requestedTokenAddresses, uint8 [5] memory _v, bytes32 [5] memory _r, bytes32 [5] memory _s) by accepting offer, buyer will transfer requested tokens to seller, in exchange for offered tokens and an optional bounty. Fee is spend.
cancelOffer(uint _offerId) offered tokens, fee, and an optional bounty is returned to seller
getOffer(uint _offerId) returns all properties of offer object at _offerId element
getLastOfferId() returns amount of offers
(onlyOwner) enableTrade(bool _tradeEnabled). Enable/disable createOffer() and acceptOffer() functionality
(onlyOwner) enableSupportedNftAddress(address _nftAddress, address _nftParamsAddress) enable additional nft series
(onlyOwner) disableSupportedNftAddress(address _nftAddress) disable nft series
(onlyOwner) addSupportedBountyAddress(address _bountyAddress) enable additional bounty currency
(onlyOwner) removeSupportedBountyAddress(address _bountyAddress) disable supported bounty currency
(onlyOwner) setFee(uint256 _feeRate) update fee value. Change will only apply to new offers.
3. SwapParams.sol
paramsAreValid (uint256 _offerId, bytes memory _encodedData, uint8 v, bytes32 r, bytes32 s) called by NftSwap CreateOffer(). Verifies offered tokens signature by using SwapSigner
*encodeParams(uint256 _offerId, uint256 _imgId, uint256 _generation, uint8 _quality) generates hash (_encodedData) of given arguments
*decodeParams (bytes memory _encodedData) derrives _offerId, _imgId, _generation and _quality from _encodedData. Reverse function to encodeParams
*Above example is for ScapeSwapParams.sol (Scapes). Other nft series will use different parameters. For example instead of _imgId, _generation and _quality, Riverboat nft uses uint256 _nftId, uint8 _category.
Last updated