Marketplace

Introduction

The Marketplace ADO is a smart contract that allows you to sell your NFTs in a marketplace. The seller sends their NFT to the Marketplace ADO and attaches the sale options such as the price and funds used to purchase the NFT. Once the NFT is sent, the sale will start at the time specified by the seller.

Purchasing the NFT can be customized to work with one of the following options:

  • Native: By specifying the denom of the chain in the StartSale message.

  • CW20: By specifying the contract address of the CW20 token to be used in the StartSale. The CW20 tokens allowed to be set as the purchasing token can be restricted by specifying authorized_cw20_address at instantiation. If this is not specified, then any CW20 token can be set.

Each sale is assigned an Id which starts at 1 and increments for each new sale.

Ado_type: marketplace

Version: 2.1.2-beta.1

InstantiateMsg

pub struct InstantiateMsg {
    pub authorized_cw20_address: Option<AndrAddr>,
    pub authorized_token_addresses: Option<Vec<AndrAddr>>,
    pub kernel_address: String,
    pub owner: Option<String>

}

ExecuteMsg

ReceiveNft

Receives a token from a SendNft and starts an auction based on the given parameters in the StartSale struct.

This message is not called by the user on this ADO, but is the case that handles receiving NFTs from a CW721 ADO.

 pub enum ExecuteMsg {
  ReceiveNft(Cw721ReceiveMsg)
}

Cw721ReceiveMsg

pub struct Cw721ReceiveMsg {
    pub sender: String,
    pub token_id: String,
    pub msg: Binary,
}

The msg in the Cw721ReceiveMsg should be a base64 encoded binary of a Cw721HookMsg.

Start Sale

A CW721 hook message that starts a new sale with the given parameters.

pub enum Cw721HookMsg {
    StartSale {
     price: Uint128,
     coin_denom: Asset,
     start_time: Option<Expiry>,
     duration: Option<MillisecondsDuration>,
     recipient: Option<Recipient>,
       }
   }

Receive

Receives tokens from a CW20 Send message to be used to buy an NFT.

This message is not called by the user on this ADO, but is the case that handles receiving CW20 tokens from a CW20 ADO.

 pub struct Cw20ReceiveMsg {
    pub sender: String,
    pub amount: Uint128,
    pub msg: Binary,
}

pub enum ExecuteMsg {
     Receive(Cw20ReceiveMsg),
    }

In order to buy and NFT using a CW20, you need to define the message of the Cw20ReceiveMsg as a Cw721HookMsg.

Buy (CW20)

Buys an NFT using the sent CW20 tokens.

You need to get the base64 encoded representation of the JSON message and attach it as the msg field for the CW20 Send message.

The Owner of the NFT is not allowed to buy it.

pub enum Cw20HookMsg {
    Buy {
        token_id: String,
        token_address: String,
    },
}

UpdateSale

Update the price and denom for the sale of the token.

Only available to the NFT owner.

pub enum ExecuteMsg {
    UpdateSale {
        token_id: String,
        token_address: String,
        price: Uint128,
        coin_denom: Asset,
        recipient:Option<Recipient>
    }
}

Buy

Buys the NFT that is for sale.

Dont forget to attach the required funds.

The Owner of the NFT is not allowed to buy it.

pub enum ExecuteMsg { 
 Buy {
        token_id: String,
        token_address: String,
     }
  }

CancelSale

Cancels the sale for the specified NFT.

Only the NFT owner can cancel the sale.

pub enum ExecuteMsg {
    CancelSale {
        token_id: String,
        token_address: String,
    }
}

Base Executes

The rest of the execute messages can be found in the ADO Base section.

QueryMsg

LatestSaleState

Gets the latest sale state for the given token. This will either be the current sale if there is one in progress or the last completed one.

 pub enum QueryMsg {
 #[returns(SaleStateResponse)]
 LatestSaleState {
        token_id: String,
        token_address: String,
     }
  }

SaleStateResponse

pub struct SaleStateResponse {
    pub sale_id: Uint128,
    pub coin_denom: String,
    pub price: Uint128,
    pub status: Status,
    pub start_time: Expiration,
    pub end_time: Expiration,
    pub recipient: Option<Recipient>,
}

SaleState

Gets the sale state for the given sale Id.

pub enum QueryMsg
#[returns(SaleStateResponse)]
 SaleState {
        sale_id: Uint128,
    }
}

Returns a SaleStateResponse.

SaleIds

Queries the sale Ids of the specified token.

pub enum QueryMsg {
     #[returns(SaleIdsResponse)]
     SaleIds {
        token_id: String,
        token_address: String,
    }
 }

Returns the Ids of the sales that have been conducted on the NFT.

SaleInfosForAddress

Get sale information on the provided CW721 token address.

pub enum QueryMsg {
 #[returns(Vec<SaleInfo>)]
 SaleInfosForAddress {
        token_address: String,
        start_after: Option<String>,
        limit: Option<u64>,
    }
 }

SaleInfo

A Vec<SaleInfo> is returned.

pub struct SaleInfo {
    pub sale_ids: Vec<Uint128>,
    pub token_address: String,
    pub token_id: String,
}

Base Queries

The rest of the query messages can be found in the ADO Base section.

Additional Resources

GithubWebsite