Trading with Smart Accounts

In version 0.15 we are enabling the feature of trading with Smart Accounts.
How does it work?

Scripts now have the ability to validate ExchangeTransaction and Order.

When an exchange transaction goes to the UTX Pool and further to the blockchain:
Orders are checked by traders’ account scripts (in case they are smart).
Exhange Transaction is checked by transaction sender’s (Matcher’s) script account if it’s set.

Smart%20Account%20on%20Matcher-Page-3%20(1)

We also added trader’s script check in Matcher.
When it receives an order from a smart account, it executes the script for the order.
Current implementation of the Matcher executes script in a restricted context - it only allows non-blockchain calls, which is the case e.g. for pure multisig script.
In case there is some call to ‘height’, ‘balance’, account data like ‘getInteger’ etc. Matcher will decline such an order. It is implemented in such way because we want to avoid situations when script returns true while placing the order, and returns false after some time when it’s matched and the exchange transaction goes to the blockchain.

Smart%20Account%20on%20Matcher-Page-4%20(1)

Examples

An account can trade only with BTC:

let cooperPubKey = base58'BVqYXrapgJP9atQccdBPAgJPwHDKkh6A8'
let BTCId = base58'8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS'
match tx {
   case o: Order =>
      sigVerify(tx.bodyBytes, tx.proofs[0], cooperPubKey ) && (o.assetPair.priceAsset == BTCId || o.assetPair.amountAsset == BTCId)
   case _ => sigVerify(tx.bodyBytes, tx.proofs[0], cooperPubKey )
}

Buy back custom asset on specified price in WAVES:

let myAssetId = base58'BVqYXrapgJP9atQccdBPAgJPwHDKkh6B9'

let cooperPubKey = base58'BVqYXrapgJP9atQccdBPAgJPwHDKkh6A8'

match tx {
   case o: Order =>
      o.assetPair.priceAsset == base58'' && o.assetPair.amountAsset == myAssetId && o.price == 500000 && o.amount == 1000 && o.orderType == Buy
   case _ => sigVerify(tx.bodyBytes, tx.proofs[0], cooperPubKey )

}

This feature will be available on TestNet in the nearest release.
Vote for Feature #10 very soon!

1 Like

i suggest to create separate block on doc.wavesplatform about different smart-contract examples and even add these examples to IDE for the users to start experimenting with.

I like the idea btw. It seems that it is possible to even set minimum price in specific asset to be able to trade it on dex :smiley: or max price :slight_smile: that could be used for swap option from ordinary token to smart_account

Check here, is it what you wanted?
https://docs.wavesplatform.com/en/technical-details/video-tutorials-and-articles.html

Will that be efficient when you compare with current matcher?

It will take more time to place orders from scripted accounts comparing to the simple accounts.
In other aspects we are not expecting significant changes.

1 Like

Smart accounts? Is it still popular?