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.
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.
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!