NFT Marketplace

Overview

NFT Marketplacearrow-up-right is a decentralized NFT exchange that allows users to buy any ERC-721arrow-up-right compatible NFTs with coins and tokens.

These are the goals we had in mind when designing the protocol:

  • Make it as accessible as possible to sellers by not requiring them to perform blockchain transactions when listing their NFTs for sale, hence saving on gas fees.

  • Pay royalties by implementing the ERC-2981arrow-up-right standard as well as our own solution detailed in the IERC721Autenticaarrow-up-right interface.

  • Temporarily suspend the smart contract in the event of an emergency.

                                                                                                                                           
                                        ,-.                                                                                                
                                        `-'                                                                                                
                                        /|\                                                                                                
                          ,-.            |              ,-.                                                                                
                          `-'           / \             `-'                                                                                
                          /|\                           /|\                                                                                
    ,-.                    |         Investor            |                                                                                 
    `-'                   / \            ^              / \                                                                                
    /|\                                  |                                                                                                 
     |                  Creator         pay         Autentica                                                                              
    / \                    ^          investor           ^                                                                           ,-.   
                           |            [2]              |                                                                           `-'   
  Seller                   |    pay      |      pay      |                                                                           /|\   
     ^                     +- creator ---+-- Autentica --+                                                                            |    
     |                          [1]      |                            $$$$$$$$$$$$$$$$$$$$                                           / \   
     |                                   |                            $                  $                                                 
     |                                   |                     +------$  tradeForCoins   $<------+                                  Buyer ^
     |                   +------------------------------+      |      $                  $       |        +-----------------+         |   |
     |                   |                              |      |      $$$$$$$$$$$$$$$$$$$$       |        |                 |         |   |
     |                   |                              |      |                                 +--------| canPerformTrade |<--------+   |
     |                   |                              |      |                                 |        |                 |             |
     +--- pay owner -----|       NFT Marketplace        |<-----+      $$$$$$$$$$$$$$$$$$$$       |        +-----------------+             |
     |                   |                              |      |      $                  $       |                                        |
     |                   |                              |      +------$  tradeForTokens  $<------+                                        |
     |                   |                              |             $                  $                                                |
     |                   +--------------------------+---+             $$$$$$$$$$$$$$$$$$$$                                                |
     |                                   ^          |                                                                                     |
     |                                   |          |                                                                                     |
     +----approves marketplace ----------+          +---------------------------------------  sends NFT  ---------------------------------+
                                                                                                                                           
                                                                                                                                           
     * [1] the creator is payed if he is no longer the owner and the royalties are set to >0%                                              
     * [2] the investor is payed from creator's proceeds only if the NFT was minted by an investor                                         

How it Works

The smart contract's main public functions are canPerformTrade, tradeForCoins and tradeForTokens. All of these functions are meant to be called by the Buyer via Autentica Marketplacearrow-up-right. The first function called canPerformTrade is used to check if the user is allowed to perform a trade using the specified parameters, while the remaining two functions, tradeForCoins and tradeForTokens are used to perform an actual trade using coins (the native cryptocurrency of the platform, i.e.: ETH) or tokens (i.e.: AUT/USDT/USDC).

Behind the scenes, tradeForCoins and tradeForTokens functions are actually calling canPerformTrade and determine whether or not the user is allowed to perform a trade with the specified parameters, but the reason for why canPerformTrade is exposed publicly is to allow the user to check if the trade is possible without actually performing it. This avoids having to pay gas fees if the transaction fails due to unmet conditions.

Functions

canPerformTrade is executed to check if the user is allowed to perform a trade using the specified parameters.

This function validates the following conditions:

  • The smart contract is not paused;

  • The collection smart contract is a valid ERC-721 smart contract;

  • The owner approved this smart contract to transfer the NFT identified by tokenId on their behalf;

  • The royalty fee for the creator and marketplaceFee do not exceed 100%;

  • The ECDSA signature that encodes all these parameters and a few others has been signed by an authorized user.

tradeForCoins is used to perform a trade using coins (the native cryptocurrency of the platform, i.e.: ETH).

This function performs the following actions:

  • Guards against reentrancy;

  • Executes canPerformTrade to validate the parameters;

  • Sends the proceeds to each party involved if the amount is greater than zero:

    • Owner: The owner of the NFT;

    • Investor:

      • The investor who minted the NFT on behalf of the creator.

      • Note: The investor is payed from the proceeds of the creator.

    • Creator: The creator of the NFT if the royalty fee is greater than 0% and the creator is no longer the owner.

    • Marketplace: The Autentica Marketplace.

  • Transfers the NFT to the buyer.

  • Emits the TradedForCoins event.

tradeForTokens is used to perform a trade using tokens (i.e. : AUT/USDT/USDC).

This function performs the following actions:

  • Guards against reentrancy;

  • Validates that the ERC-20 token address is allowed to be used for trading;

  • Executes canPerformTrade to validate the parameters;

  • Sends the proceeds to each party involved if the amount is greater than zero:

    • Owner: The owner of the NFT;

    • Investor:

      • The investor who minted the NFT on behalf of the creator.

      • Note: The investor is payed from the proceeds of the creator.

    • Creator: The creator of the NFT if the royalty fee is greater than 0% and the creator is no longer the owner.

    • Marketplace: The Autentica Marketplace.

  • Transfers the NFT to the buyer.

  • Emits the TradedForTokens event.

Events

TradedForCoins is emitted when a trade is performed using coins (the native cryptocurrency of the platform, i.e. : ETH).

TradedForTokens is emitted when a trade is performed using tokens (i.e. : AUT/USDT/USDC).

Source Code

The source code for the smart contract can be found in the NFTMarketplace.solarrow-up-right file located in the contracts folder within our smart-contractsarrow-up-right repository.

Deployments

Last updated