Help me. Is my code wrong?

I made a code because I want to fix the tokens and the price that can be exchanged.

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
let PAR7Id = base58’2UDVrBQuBpyVayA8giH4NjPE5F31WxkD7CzMvNRzZXHh’
let Price = 1000

match tx {
case e : ExchangeTransaction =>
e.sellOrder.assetPair.priceAsset == PAR7Id && e.price == Price
|| throw(“Now you can only exchange swap PAR7 ! Thank you for your patience.”)
case _ => true
}
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
This code made all exchanges impossible. Is something wrong?
Help me. thank you for reading(:slight_smile:)

You forgot counter-order validations, please refer to this post: Smart Assets Distinctions

Spoiler:

1 Like

Thank you for teaching me.
I tried a lot of code based on your teachings, but it didn’t work. I do not seem to understand counter-order validations(_)

How do I write counter-order validations?
I also have to study English(+_+)

Maybe i was wrong about counter-order hard things.

Look close to that pair you want to trade, for example, if you trade in your_asset_ID/WAVES, then you assetId would be always e.sellOrder.assetPair.amountAsset and e.buyOrder.assetPair.amountAsset.

Another thing to notice is price. Price in exchanges is different. It contains difference in decimals multiplied by fixed value 100000000.

For example, if you trade your_asset_ID with 0 decimals versus WAVES (8 decimals), selling your 1 token for 1 WAVES gets the price equal to 10000000000000000 ( = 100000000 (1 WAVES with 8 decimals versus your 1 token with 0 decimals ) * 100000000 (fixed multiply value)).

By the way, if you have any problem with understanding there is always a straight way of throwing debug information about all problematic variables.

1 Like

Thank you!
I understand it because it was easy to understand your explanation!

It was very helpful! Thank you very much!!!

arigatou!
ありがとう!

Please tell me one more thing.
Thanks to you this code is made.

let PAR7 = base58’2UDVrBQuBpyVayA8giH4NjPE5F31WxkD7CzMvNRzZXHh’ # 2 decimals
let PAR7Price = 10000000000 # PAR7 2 decimels VS Par7 2 desimels

match tx {
case e : ExchangeTransaction =>
e.buyOrder.assetPair.priceAsset == PAR7 && e.price ==PAR7Price

case s : SetAssetScriptTransaction | SetScriptTransaction =>true

case _ => false
}

Is it possible to add exchanges with waves to this code?

let WAVESPrice = 10000000000 #0.0001waves
match tx {
case e: ExchangeTransaction =>
let pair = e.buyOrder.assetPair
let tradedForWaves = ! isDefined(pair.amountAsset) ||
! isDefined(pair.priceAsset)
tradedForWaves && e.price == WAVESPrice

I am grateful to you. Thank you(:slight_smile:)

I could solve this problem myself! Thank you!