@nifty-island/market-maker v1.0.8
Island Market Maker Contracts
The Nifty Island Market Maker is a razor thin protocol allowing people to trustlessly list, bid, and trade NFTs in any ERC20 currency.
It provides two market implementations, NonFungibleTokenMarket
for trading ERC721 tokens and MultiTokenMarket
for trading ERC1155 tokens. Both implementations support the same event structure and implement a similar interface, with minor deviations where appropriate.
Table of Contents
Addresses
Rinkeby
NonFungibleTokenMarket: 0x8eDd2583e446E5b73d5dB0C902fA908585B52128
MultiTokenMarket: 0x46138F55D06944AD2d7b0F7384779F6a37C2dc0c
Mainnet
NonFungibleTokenMarket: 0x...
MultiTokenMarket: 0x...
Architecture
Create Market
returns (uint256 marketId)
Before calling, the token owner must approve
the TokenMarket to handle the NFT(s). This way, the token owner retains ownership of the token, only transferring ownership when a bid is accepted. For the MultiTokenMarket, the owner must specify what quantity he wants to put on the market.
NonFungibleTokenMarket
Name | Type | Description |
---|---|---|
tokenContract | address | The token contract to use in the market |
tokenId | uint256 | The tokenID to use in the market |
stakeholders | Stakeholder[] | List of stakeholders: { address stakeholder, uint8 stake percentage } |
MultiTokenMarket
Name | Type | Description |
---|---|---|
tokenContract | address | The token contract to use in the market |
tokenId | uint256 | The tokenID to use in the amount |
tokenCount | uint256 | The number of tokens to put up on the market |
stakeholders | Stakeholder[] | List of stakeholders: { address stakeholder, uint8 stake percentage } |
Remove Market
Can only be called by the market creator (owner of the NFT)
| Name | Type | Description |
|------------------------|----------------|------------------------------------------------------------------------------------------------|
| marketId
| uint256
| The market ID |
Set Ask
Each market only has one ask at a time. An ask can be thought of as a buy-now price for a single token. Any bid which exceeds the ask will automatically complete the transfer, without the normal "accept bid" step on the part of the market creator.
| Name | Type | Description |
|------------------------|----------------|------------------------------------------------------------------------------------------------|
| marketId
| uint256
| The market ID |
| curency
| address
| The address of the ERC20 currency to set the ask in |
| amount
| uint256
| The ask amount |
Remove Ask
Removes the current ask for the specified market. Must be called by the creator of the market.
| Name | Type | Description |
|------------------------|----------------|------------------------------------------------------------------------------------------------|
| marketId
| uint256
| The market ID |
Create Bid
Prior to calling, the caller must approve()
the TokenMarket to spend their currency. If the bid matches the given ask, the market trades the NFT and tokens to their respective parties, and removes the market. The MultiTokenMarket works the same way, except it decrements the transferred tokenCount
from the market. If the market drops to a tokenCount
of 0, the market is removed.
NonFungibleTokenMarket Bid
Name | Type | Description |
---|---|---|
marketId | uint256 | The market ID |
amount | uint256 | The bid amount |
currency | uint256 | The bid currency |
MultiTokenMarket Bid
Name | Type | Description |
---|---|---|
marketId | uint256 | The market ID |
amount | uint256 | The bid amount |
currency | uint256 | The bid currency |
tokenCount | uint256 | The number of tokens this bid is for |
Remove Bid
Removes the specified bid, if it exists. Only users that have created bids can erase them.
| Name | Type | Description |
|------------------------|----------------|------------------------------------------------------------------------------------------------|
| marketId
| uint256
| The market ID |
| bidIndex
| uint256
| The index of the bid in the Bids array |
Accept Bid
If the token owner likes a specified bid, then they can accept the bid, and the assets will be traded. Reverts if approve()
al has been revoked by either party since creation.
| Name | Type | Description |
|------------------------|----------------|------------------------------------------------------------------------------------------------|
| marketId
| uint256
| The market ID |
| bidIndex
| uint256
| The index of the bid in the Bids array |
Events
Events are used by both Market types, though the tokenCount
field for events created by the NonFungibleTokenMarket
is always 1.
event MarketCreated(uint256 indexed marketId, address indexed tokenContract, uint256 indexed tokenId, uint256 tokenCount, address owner);
event TransferFinalized(uint256 indexed marketId, address indexed tokenContract, uint256 indexed tokenId, uint256 tokenCount, address currency, uint256 amount, address buyer);
event MarketRemoved(uint256 indexed marketId, address indexed tokenContract, uint256 indexed tokenId, uint256 tokenCount, address owner);
event BidCreated(uint256 indexed marketId, address tokenContract, uint256 tokenId, uint256 bidIndex, uint256 tokenCount, address indexed currency, uint256 indexed amount, address bidder);
event BidRemoved(uint256 indexed marketId, address tokenContract, uint256 tokenId, uint256 bidIndex, uint256 tokenCount, address indexed currency, uint256 indexed amount, address bidder);
event AskCreated(uint256 indexed marketId, address tokenContract, uint256 tokenId, address indexed currency, uint256 indexed amount);
event AskRemoved(uint256 indexed marketId, address tokenContract, uint256 tokenId, address indexed currency, uint256 indexed amount);
event MarketStakeholderAdded(uint256 indexed marketId, address tokenContract, uint256 tokenId, address indexed stakeholder, uint8 indexed stakePercentage);
event MarketFeeSet(address indexed marketContract, address indexed currencyAddress, uint8 indexed feePercentage);
Local Development
The following assumes node >= 12
Install Dependencies
npm install
Compile Contracts
npx hardhat compile
Run Tests
npm run test