name: FairAuction
description: Decentralized auction to securely sell NFTs to the highest bidder
structs:
  Auction:
    nft: NftID # NFT of NFTs for sale
    creator: AgentID # issuer of start_auction transaction
    deposit: Uint64 # deposit by auction owner to cover the SC fees
    description: String # auction description
    duration: Uint32 # auction duration in minutes
    highestBid: Uint64 # the current highest bid amount
    highestBidder: AgentID # the current highest bidder
    minimumBid: Uint64 # minimum bid amount
    ownerMargin: Uint64 # auction owner's margin in promilles
    whenStarted: Uint64 # timestamp when auction started
  Bid:
    amount: Uint64 # cumulative amount of bids from same bidder
    index: Uint32 # index of bidder in bidder list
    timestamp: Uint64 # timestamp of most recent bid
typedefs:
  BidderList: AgentID[]
  Bids: map[AgentID]Bid
state:
  auctions: map[NftID]Auction
  bidderList: map[NftID]BidderList
  bids: map[NftID]Bids
  owner: AgentID
  ownerMargin: Uint64 # default auction owner's margin in promilles
funcs:
  init:
    params:
      owner: AgentID?
  startAuction:
    params:
      description: String? # description of the NFTs being auctioned
      duration: Uint32? # duration of auction in minutes
      minimumBid: Uint64 # minimum required amount for any bid
  finalizeAuction:
    access: self # only SC itself can invoke this function
    params:
      nft: NftID # NFT identifies the auction
  placeBid:
    params:
      nft: NftID # NFT identifies the auction
  setOwnerMargin:
    access: owner # only SC creator can set owner margin
    params:
      ownerMargin: Uint64 # new SC owner margin in promilles
views:
  getAuctionInfo:
    params: 
      nft: NftID # NFT identifies the auction
    results:
      bidders: Uint32 # nr of bidders
      nft: NftID # NFT of NFTs for sale
      creator: AgentID # issuer of start_auction transaction
      deposit: Uint64 # deposit by auction owner to cover the SC fees
      description: String # auction description
      duration: Uint32 # auction duration in minutes
      highestBid: Uint64 # the current highest bid amount
      highestBidder: AgentID # the current highest bidder
      minimumBid: Uint64 # minimum bid amount
      ownerMargin: Uint64 # auction owner's margin in promilles
      whenStarted: Uint64 # timestamp when auction started
