Auctions

In Agence supports a built in Auction module. We can create our own auction to sell assets or buy new assets by bidding on existing auctions.

Create Auction

Agence support three types of auctions:

  1. BASIC: which is the most common type that the bidder with highest price wins at the end of the auction duration

    Creation commands in acmd:

    const auctionKind = api.createType("AuctionKind", 0)
    
    await api.tx.auctions.createAuction(auctionKind, [forgeId, assetKindId, assetId], startPrice, duration_millisec).signAndSend(keypair, result => {console.log(JSON.stringify(result))})
    
  2. WITH_BUY_NOW: which is the type that has both features of BASIC and BUY_ONLY type:

    Creation commands in acmd:

    const auctionKind = api.createType("AuctionKind", buyNowPrice, 1)
    
    await api.tx.auctions.createAuction(auctionKind, [forgeId, assetKindId, assetId], startPrice, duration_millisec).signAndSend(keypair, result => {console.log(JSON.stringify(result))})
    
  3. BUY_ONLY: which buyer can directly buy the asset for buyNowPrice

    Creation commands in acmd:

    const auctionKind = api.createType("AuctionKind", 2)
    
    await api.tx.auctions.createAuction(auctionKind, [forgeId, assetKindId, assetId], buyNowPrice, duration_millisec).signAndSend(keypair, result => {console.log(JSON.stringify(result))})
    

After executing the creation commands, we will get logs like:

{
  "dispatchInfo": {
    "weight": 1867546902,
    "class": "Normal",
    "paysFee": "Yes"
  },
  "events": [
    {
      "phase": {
        "ApplyExtrinsic": 1
      },
      "event": {
        "index": "0x1700",
        "data": [
          206,
          4,
          42
        ]
      },
      "topics": [
        
      ]
    },
    {
      "phase": {
        "ApplyExtrinsic": 1
      },
      "event": {
        "index": "0x0906",
        "data": [
          220800000
        ]
      },
      "topics": [
        
      ]
    },
    {
      "phase": {
        "ApplyExtrinsic": 1
      },
      "event": {
        "index": "0x0000",
        "data": [
          {
            "weight": 1867546902,
            "class": "Normal",
            "paysFee": "Yes"
          }
        ]
      },
      "topics": [
        
      ]
    }
  ],
  "status": {
    "InBlock": "0x0eb7d6540e3030a0662b988dc2fde2e38f1bdc11c94f27d1334301db67d25e2b"
  }
}

Pay attention on the event whose index is "0x1700". This indicates the auction/Created event that contains auctionId (ex: 206), forgeId(ex: 4), and assetKindId(ex: 42).

"event": {
    "index": "0x1700",
    "data": [
        206,
        4,
        42
    ]
}

As we can see in the event, we just put our asset which assetKind is 4x42 on a new auction 206.

Query Auction

We can query active auction using auctionId in acmd:

JSON.stringify(await api.query.auctions.auction(auctionId))

example output:

'{
  "active_index": 0,
  "auctioneer": "SUqyEgGoeQyCYMJiTGVkqnHHMeH4S6KNjKoV66ku4bLFn1rL",
  "kind": 
  {
    "WithBuyNow": 20000000000
  },
  "asset": [4,42,1],
  "starting_price": 10000000000, 
  "start_at": 1620189576002,
  "duration":60000
}'

Bid on Auction

For Basic or WithBuyNow type auction, we can bid on the auction through acmd by following command:

await api.tx.auctions.bid(auctionId, biddingPrice).signAndSend(keypair, result => {console.log(JSON.stringify(result))})

Directly buy through Auction

For BuyOnly or WithBuyNow type auction, we can directly buy the asset on auction through following command:

await api.tx.auctions.buy(auctionId).signAndSend(keypair, result => {console.log(JSON.stringify(result))})