Understand waves type 7 (exchange) transactions

137 views Asked by At

I need some help trying to understand the type 7 tx data structure. For example I get this from the REST api when dealing with a type 7 tx.

{
    "senderPublicKey": "9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5",
    "amount": 2500000000,
    "fee": 300000,
    "type": 7,
    "version": 2,
    "sellMatcherFee": 300000,
    "sender": "3PEjHv3JGjcWNpYEEkif2w8NXV4kbhnoGgu",
    "feeAssetId": null,
    "proofs": ["3r7DJ7HyAePryf8334yMSoMccWwVcGqKZtB5GkQLLpwfxKqiMbRnXjzEtJXR3trPTwMWv9YN19VSBcibrDe4o41U"],
    "price": 16000,
    "id": "9h23sgpwoZHRXbFTJacK8saf8hqvmfYBuRc7De15Xzbg",
    "order2": {
      "version": 2,
      "id": "6QCudpHuJsQKw3fzNEzowyomJb8t6R38CX42j9Hr4thL",
      "sender": "3PAfzcstFHooUexfvZ77S4yGw3ftHWK47v6",
      "senderPublicKey": "EoSgBYUz7Dn2NyKeme9TC1mvTLgG2Z4E9QUsmyFoJbs1",
      "matcherPublicKey": "9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5",
      "assetPair": {
        "amountAsset": "HKJK3zswXJLbsgJ3pQNiYVNu6svy4SM9zucB8YEJFXqt",
        "priceAsset": null
      },
      "orderType": "sell",
      "amount": 2500000000,
      "price": 16000,
      "timestamp": 1582473059417,
      "expiration": 1582476659415,
      "matcherFee": 300000,
      "signature": "2wZ3uNPtnUec5HeobuJgok44foh3o195a8EYSi1YdKyakeuUJcDGXMMDM8QfqtLpFep1UP4MR2kRC2WQ9uzsgxNq",
      "proofs": ["2wZ3uNPtnUec5HeobuJgok44foh3o195a8EYSi1YdKyakeuUJcDGXMMDM8QfqtLpFep1UP4MR2kRC2WQ9uzsgxNq"]
    },
    "order1": {
      "version": 2,
      "id": "GfEhMC8s67GkWiTcJSo15UL1Y5FHY5GZzuy1JSaBeTZB",
      "sender": "3P9FCD1DBeaVTtpuXQAa57LPcqWdZAw7uue",
      "senderPublicKey": "svTLkS45BVUqwQLrCe1M4zMzk3PyDWtmWdxfxiCkcRt",
      "matcherPublicKey": "9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5",
      "assetPair": {
        "amountAsset": "HKJK3zswXJLbsgJ3pQNiYVNu6svy4SM9zucB8YEJFXqt",
        "priceAsset": null
      },
      "orderType": "buy",
      "amount": 2500000000,
      "price": 16000,
      "timestamp": 1582473193433,
      "expiration": 1584978793432,
      "matcherFee": 300000,
      "signature": "5zg1Hn2iv6H4BAkDCRngWXdCFMoiBryFvzyGX15QhSfwSwW5SctRPT82BHW7BCZy9ecfrPuP8nTmQPAgkByM7FLN",
      "proofs": ["5zg1Hn2iv6H4BAkDCRngWXdCFMoiBryFvzyGX15QhSfwSwW5SctRPT82BHW7BCZy9ecfrPuP8nTmQPAgkByM7FLN"]
    },
    "buyMatcherFee": 300000,
    "timestamp": 1582473196322,
    "height": 1943003
  }

Hypotetically, considering this 3P9FCD1DBeaVTtpuXQAa57LPcqWdZAw7uue as my address wallet, my questions are:

  • How do I know if this tx is Sending out WAVES or receiving WAVES?
  • order2 will always be a SELL type order?
  • In both order1 and order2 the amountAsset field has an asset id, but in some other txs I had the priceAsset field populated and amountAsset was empty.

Can you shed some lights?

2

There are 2 answers

2
TurtleNetwork On

If you look in the tx, you see that order1 has ordertype buy. This means you are buying one asset, in our case "HKJK3zswXJLbsgJ3pQNiYVNu6svy4SM9zucB8YEJFXqt" and selling in another asset, in our case "null".

We are not sending out or receiving waves here, we are swapping waves for another asset. In your case you are the buyer. Since you posted the order with type buy.

The asset null, means that you are talking about 'WAVES'. Waves is no asset and by following it doesn't have an assetId. An example to explain this a bit deeper:

  1. In WAVES/BTC pair, BTC is price asset and so amountasset = null
  2. In TN/WAVES pair, WAVES is price asset and so priceasset = null

The documentation provides all these insights. It also contains an overview from the value from each field in each part from the transaction.

Source: https://docs.waves.exchange/en/waves-matcher/matcher-api#entities

Another usefull link to check out in regards to transactions: https://docs.wavesplatform.com/en/blockchain/binary-format/transaction-binary-format/

0
msmolyakov On

An asset pair should consist of two different assets. For example, you cannot create an exchange between WAVES and WAVES.

The first asset in such a pair is called "amount asset", and the second is called "price asset". Thus, a Buy order means "I want to buy X amount asset coins for Y price asset coins." And, accordingly, a Sell order means "I want to sell X amount asset coins for Y price asset coins."

In Exchange, transaction "order1" is always of type "buy", and "order2" is of type "sell".

You can see example of transactions and their JSON:

  1. WAVES as amount asset: https://wavesexplorer.com/tx/76JYndC985gvVKF2R5ip9gAuKvfd6zYSqjcyByFiCKim
  2. WAVES as price asset: https://wavesexplorer.com/tx/C1G3ohpfHntLWp33pSRU6kzSWrqEigGp2tGCCa7SjBKD