Skip to content

Marketplace contract

alexaunter edited this page Jan 23, 2022 · 31 revisions

Lot lifecycle

Glossary

Roles of accounts in this example:

  • marketplace account - test_nearnames.testnet
  • lot - account being sold at auction - alice.test_nearnames.testnet
  • seller - receiver of rewards paid by bidders - bob.test_nearnames.testnet
  • bidder - anyone who places the bid on the lot - carol.test_nearnames.testnet
  • buyer - bidder that made the last bid and wins the auction
  • claimer - account that gains access to lot account

Main Flow

  • alice calls marketplace lot_offer method
  • alice deploys and initializes lock contract, removes all access keys
  • carol views marketplace lot_list method, sees alice account
  • carol ensures that alice is safe to buy account
  • carol calls marketplace lot_bid method
  • auction ends, because ending conditions are met
  • carol calls marketplace lot_claim method to gain access to the account
  • bob views marketplace profile_get to check amount of available rewards
  • bob calls marketplace profile_rewards_claim method to gain rewards buyer paid

Auction flow success

Auction flow success

Alternative flow, withdraw

  • alice calls marketplace lot_offer method
  • alice deploys escrow contract, removes all access keys
  • bob reconsiders, doesn't want to sell account anymore
  • bob calls marketplace lot_withdraw method, noone can make bids after that
  • bob calls marketplace lot_claim method to gain access to the account
  • bob gets no rewards, since there were no bids

Auction flow success

Safe to buy account

To ensure that buyer will receive control of account after auction finish, we require lot to be configured in a way that doesn't allow the buyer to regain access to it during and/or after the auction.

The requirements are the following:

  1. The account deployed contract with code_hash of our lock contract
  2. The account doesn't have any access keys
  3. The account owner (account that can add keys) is marketplace account

Auction ending conditions

Auction ends by reaching any of the following conditions:

  1. time_now > lot_offer call time + auction duration
  2. there exists a bid with amount >= buy_now price

Lock contract deploy and verification

Marketplace contract call lot_offer and lock deploy#Checking configuration

API

Clone this wiki locally