We have a breaking change coming to the Monster Market DEX Protocol that all marketplace or bot developers will need to support if they want their purchase transactions to go through. We plan to put this change into effect approximately one week from today (Friday, August 24th).
For anyone who is not doing market-related development, this post will probably not be relevant to you, but you're more than welcome to read it if you're interested, and your upvotes are always very much appreciated!
The Issue
Currently if two (or more) "sm_market_sale" transfers are made for the same market item at around the same time, only the transaction that appears first will be considered valid and have the cards transfered to the purchaser. Unfortunately, purchasers from the subsequent transactions have already transfered the funds but did not receive the cards, and have no way to get a refund (other than asking the seller nicely).
The Solution
In order to resolve this issue, purchasing cards through the decentralized market will need to be a two-step process. First the purchaser must obtain a lock on the market item(s) they wish to purchase. The purchaser can then check to make sure the lock was acquired before transfering the funds to the seller.
The "sm_market_sale" transfer must be sent within 20 blocks (1 minute) of the lock being obtained. After 20 blocks, if no "sm_market_sale" transfer is made with the appropriate info and amount of funds, then the lock will be released.
Once this change goes into effect, all "sm_market_sale" transfers will be considered invalid if the purchaser does not hold an active lock on the market items being purchased.
Acquiring and Checking the Locks
To acquire a lock on one or more market items, you must broadcast a transfer transaction with a sufficient amount of STEEM or SBD to purchase the indicated market items with the following memo format:
sm_market_purchase:market-item-1-id,market-item-2-id,...
When this transfer transaction is made, it will attempt to acquire a lock on all of the market items listed. To check if the locks were acquired successfully or not, you can look up the status of the transaction using the Steem Monsters API:
https://steemmonsters.com/transactions/lookup?trx_id=e750b8223a56f2e7b2ac4c7b3f6fc063d430a52e
Which returns the following response:
{
"trx_info": {
"id": "e750b8223a56f2e7b2ac4c7b3f6fc063d430a52e",
"block_id": "017f723234273329e9e70f9afaebd75f66bfdbfc",
"prev_block_id": "017f7231f533ffc70e1dc1d2448caa762791e886",
"type": "sm_market_purchase",
"player": "aggroedius",
"data": "sm_market_purchase:6b8b0074cbec6e4d7db01f96918f0f4ac423a553-0",
"success": true,
"error": null,
"block_num": 25129522,
"created_date": "2018-08-16T22:11:15.539Z",
"result": "[{\"sell_trx_id\":\"6b8b0074cbec6e4d7db01f96918f0f4ac423a553-0\",\"seller\":\"cryptkeeper17\",\"buy_price\":0.05,\"fee_percent\":200,\"payment\":0.052,\"currency\":\"SBD\",\"locked\":true,\"lock_block\":25129522}]"
}
}
As you can see in the "result" property, it shows "locked":true which means the market item was successfully locked by this transaction. This means that the purchaser can send the "sm_market_sale" transfer within the next 20 blocks in order to purchase the cards.
For Market Developers
For anyone developing a third party market (such as https://monsters.steempeak.com/) here's what you need to do:
- To initiate a purchase of one or more market items through your market, an account must transfer a sufficient amount of funds using the "sm_market_purchase" memo format described above.
- You must then check the transaction result to see if the market items were successfully locked or not by the transaction from step 1. Note that if multiple market items were specified in the "sm_market_purchase" transfer it is possible that some were able to acquire locks and some were not.
- For any market items for which a lock was successfully acquired, make sure it is within 20 blocks since the lock was acquired, and you can go ahead and send the "sm_market_sale" transfer with the appropriate memo and funds to the seller(s).
- For any market items for which a lock was NOT acquired, or if the lock has expired, transfer the funds back to the purchaser from step 1.
For Bot Developers
For anyone developing a card trading bot (looking at you !) you can do the following:
- Send an "sm_market_purchase" transfer to yourself using the memo format specified above.
- Check the result of that transaction to see if locks were acquired for the items being purchased.
- Only transfer funds to the seller using the "sm_market_sale" memo format if the lock was acquired and has not expired
Market Developers Discord Channel
I have created a private channel in the Steem Monsters Discord server for anyone doing market-related development to be able to discuss market-related development things. If you would like to be added to that channel please send me a direct message on Discord.