tx · 2TXNUoCatBrgcHKhwMQcQstCekjbmLRbzv2i4wygavVN 3N61RYWc9QuqKUwLvowpZZLpgUnqpQSFwLq: -0.01000000 Waves 2024.03.04 14:44 [3003221] smart account 3N61RYWc9QuqKUwLvowpZZLpgUnqpQSFwLq > SELF 0.00000000 Waves
{ "type": 13, "id": "2TXNUoCatBrgcHKhwMQcQstCekjbmLRbzv2i4wygavVN", "fee": 1000000, "feeAssetId": null, "timestamp": 1709552664285, "version": 2, "chainId": 84, "sender": "3N61RYWc9QuqKUwLvowpZZLpgUnqpQSFwLq", "senderPublicKey": "HdwFH8HPYu3HG27yK6bszu1CdR4uik4HgzyTimeSfcYf", "proofs": [ "2Ht2LbUff4N4cParJ3doDTykLnYnG7g2rKr5HfnSTjFD1jduZZ9NBPMaXUFaVGDSvs3Ds2UAJ5KDJChR6kPYe7Bo" ], "script": "base64:BgIOCAISABIDCgEBEgMKAQgPABBhbW91bnRBc3NldElkS2V5Ag1hbW91bnRBc3NldElkAA9wcmljZUFzc2V0SWRLZXkCDHByaWNlQXNzZXRJZAAKZmVlUmF0ZUtleQIHZmVlUmF0ZQEKZ2V0QXNzZXRJZAENYXNzZXRJZFN0cmluZwMJAAACBQ1hc3NldElkU3RyaW5nAgVXQVZFUwUEdW5pdAkA2QQBBQ1hc3NldElkU3RyaW5nAQ9nZXRBc3NldEJhbGFuY2UBB2Fzc2V0SWQEByRtYXRjaDAFB2Fzc2V0SWQDCQABAgUHJG1hdGNoMAIKQnl0ZVZlY3RvcgQCaWQFByRtYXRjaDAJAPAHAgUEdGhpcwUCaWQICQDvBwEFBHRoaXMJYXZhaWxhYmxlABNhbW91bnRBc3NldElkU3RyaW5nCQERQGV4dHJOYXRpdmUoMTA1MykCBQR0aGlzBRBhbW91bnRBc3NldElkS2V5AA1hbW91bnRBc3NldElkCQEKZ2V0QXNzZXRJZAEFE2Ftb3VudEFzc2V0SWRTdHJpbmcAEnByaWNlQXNzZXRJZFN0cmluZwkBEUBleHRyTmF0aX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XRpdmUoMTA2MikBBQdhZGRyZXNzBQFpAKqErUs=", "height": 3003221, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 7KgSYbDidQ1pC6WWZLTPHFsv2oYMaLdLx6BcXrkuVCGN Next: AUT1JaVsQcktijNetUsnNgs9p94j3aQHep5BLzF3mtAF Diff:
Old | New | Differences | |
---|---|---|---|
32 | 32 | ||
33 | 33 | let feeRate = valueOrElse(getInteger(this, feeRateKey), 200000) | |
34 | 34 | ||
35 | + | func calcPrice () = fraction(getAssetBalance(amountAssetId), SCALE8, getAssetBalance(priceAssetId)) | |
36 | + | ||
37 | + | ||
35 | 38 | func calcRawSendAmount (initAmBal,initPrBal,paymentAmount) = { | |
36 | 39 | let newPrBal = (initPrBal + paymentAmount) | |
37 | 40 | let newAmBal = fraction(initAmBal, initPrBal, newPrBal) | |
41 | 44 | ||
42 | 45 | ||
43 | 46 | func calcSendAmount (paymentAssetId,paymentAmount) = { | |
44 | - | let $ | |
47 | + | let $t013381490 = if ((paymentAssetId == amountAssetId)) | |
45 | 48 | then $Tuple2(priceAssetId, amountAssetId) | |
46 | 49 | else $Tuple2(amountAssetId, priceAssetId) | |
47 | - | let amAssetId = $ | |
48 | - | let prAssetId = $ | |
50 | + | let amAssetId = $t013381490._1 | |
51 | + | let prAssetId = $t013381490._2 | |
49 | 52 | let initAmBal = getAssetBalance(amAssetId) | |
50 | 53 | let initPrBal = (getAssetBalance(prAssetId) - paymentAmount) | |
51 | 54 | let rawSendAmount = calcRawSendAmount(initAmBal, initPrBal, paymentAmount) | |
68 | 71 | then { | |
69 | 72 | let paymentAssetId = i.payments[0].assetId | |
70 | 73 | let paymentAmount = i.payments[0].amount | |
71 | - | let $ | |
72 | - | let sendAmount = $ | |
73 | - | let feeAmount = $ | |
74 | - | let sendAssetId = $ | |
75 | - | let userRealPrice = $ | |
74 | + | let $t024672570 = calcSendAmount(paymentAssetId, paymentAmount) | |
75 | + | let sendAmount = $t024672570._1 | |
76 | + | let feeAmount = $t024672570._2 | |
77 | + | let sendAssetId = $t024672570._3 | |
78 | + | let userRealPrice = $t024672570._4 | |
76 | 79 | let sendActions = if ((feeAmount > 0)) | |
77 | 80 | then [ScriptTransfer(address, sendAmount, sendAssetId)] | |
78 | 81 | else throw("amount is too low") | |
89 | 92 | ||
90 | 93 | @Callable(i) | |
91 | 94 | func swapNoLess (minAmount) = { | |
92 | - | let $ | |
93 | - | let sendActions = $ | |
94 | - | let tuple = $ | |
95 | - | let $ | |
96 | - | let sendAmount = $ | |
97 | - | let feeAmount = $ | |
98 | - | let sendAssetId = $ | |
99 | - | let userRealPrice = $ | |
95 | + | let $t029282980 = swapInternal(i.caller, i) | |
96 | + | let sendActions = $t029282980._1 | |
97 | + | let tuple = $t029282980._2 | |
98 | + | let $t029853048 = tuple | |
99 | + | let sendAmount = $t029853048._1 | |
100 | + | let feeAmount = $t029853048._2 | |
101 | + | let sendAssetId = $t029853048._3 | |
102 | + | let userRealPrice = $t029853048._4 | |
100 | 103 | if ((minAmount > sendAmount)) | |
101 | 104 | then throw(makeString(["Price slipped. minAmount: ", toString(minAmount), " swapAmount: ", toString(sendAmount)], "")) | |
102 | 105 | else $Tuple2(sendActions, tuple) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let amountAssetIdKey = "amountAssetId" | |
5 | 5 | ||
6 | 6 | let priceAssetIdKey = "priceAssetId" | |
7 | 7 | ||
8 | 8 | let feeRateKey = "feeRate" | |
9 | 9 | ||
10 | 10 | func getAssetId (assetIdString) = if ((assetIdString == "WAVES")) | |
11 | 11 | then unit | |
12 | 12 | else fromBase58String(assetIdString) | |
13 | 13 | ||
14 | 14 | ||
15 | 15 | func getAssetBalance (assetId) = match assetId { | |
16 | 16 | case id: ByteVector => | |
17 | 17 | assetBalance(this, id) | |
18 | 18 | case _ => | |
19 | 19 | wavesBalance(this).available | |
20 | 20 | } | |
21 | 21 | ||
22 | 22 | ||
23 | 23 | let amountAssetIdString = getStringValue(this, amountAssetIdKey) | |
24 | 24 | ||
25 | 25 | let amountAssetId = getAssetId(amountAssetIdString) | |
26 | 26 | ||
27 | 27 | let priceAssetIdString = getStringValue(this, priceAssetIdKey) | |
28 | 28 | ||
29 | 29 | let priceAssetId = getAssetId(priceAssetIdString) | |
30 | 30 | ||
31 | 31 | let SCALE8 = 100000000 | |
32 | 32 | ||
33 | 33 | let feeRate = valueOrElse(getInteger(this, feeRateKey), 200000) | |
34 | 34 | ||
35 | + | func calcPrice () = fraction(getAssetBalance(amountAssetId), SCALE8, getAssetBalance(priceAssetId)) | |
36 | + | ||
37 | + | ||
35 | 38 | func calcRawSendAmount (initAmBal,initPrBal,paymentAmount) = { | |
36 | 39 | let newPrBal = (initPrBal + paymentAmount) | |
37 | 40 | let newAmBal = fraction(initAmBal, initPrBal, newPrBal) | |
38 | 41 | let sendAmount = (initAmBal - newAmBal) | |
39 | 42 | sendAmount | |
40 | 43 | } | |
41 | 44 | ||
42 | 45 | ||
43 | 46 | func calcSendAmount (paymentAssetId,paymentAmount) = { | |
44 | - | let $ | |
47 | + | let $t013381490 = if ((paymentAssetId == amountAssetId)) | |
45 | 48 | then $Tuple2(priceAssetId, amountAssetId) | |
46 | 49 | else $Tuple2(amountAssetId, priceAssetId) | |
47 | - | let amAssetId = $ | |
48 | - | let prAssetId = $ | |
50 | + | let amAssetId = $t013381490._1 | |
51 | + | let prAssetId = $t013381490._2 | |
49 | 52 | let initAmBal = getAssetBalance(amAssetId) | |
50 | 53 | let initPrBal = (getAssetBalance(prAssetId) - paymentAmount) | |
51 | 54 | let rawSendAmount = calcRawSendAmount(initAmBal, initPrBal, paymentAmount) | |
52 | 55 | let feeAmount = fraction(rawSendAmount, feeRate, SCALE8) | |
53 | 56 | let sendAmount = (rawSendAmount - feeAmount) | |
54 | 57 | let userRealPrice = if ((paymentAssetId == amountAssetId)) | |
55 | 58 | then fraction(sendAmount, SCALE8, paymentAmount) | |
56 | 59 | else fraction(paymentAmount, SCALE8, sendAmount) | |
57 | 60 | $Tuple4(sendAmount, feeAmount, amAssetId, userRealPrice) | |
58 | 61 | } | |
59 | 62 | ||
60 | 63 | ||
61 | 64 | func swapInternal (address,i) = { | |
62 | 65 | let checks = [if ((size(i.payments) > 0)) | |
63 | 66 | then true | |
64 | 67 | else throw("should be with 1 payment"), if (containsElement([amountAssetId, priceAssetId], i.payments[0].assetId)) | |
65 | 68 | then true | |
66 | 69 | else throw(makeString(["payment assetId should be", amountAssetIdString, "or", priceAssetIdString], " "))] | |
67 | 70 | if ((checks == checks)) | |
68 | 71 | then { | |
69 | 72 | let paymentAssetId = i.payments[0].assetId | |
70 | 73 | let paymentAmount = i.payments[0].amount | |
71 | - | let $ | |
72 | - | let sendAmount = $ | |
73 | - | let feeAmount = $ | |
74 | - | let sendAssetId = $ | |
75 | - | let userRealPrice = $ | |
74 | + | let $t024672570 = calcSendAmount(paymentAssetId, paymentAmount) | |
75 | + | let sendAmount = $t024672570._1 | |
76 | + | let feeAmount = $t024672570._2 | |
77 | + | let sendAssetId = $t024672570._3 | |
78 | + | let userRealPrice = $t024672570._4 | |
76 | 79 | let sendActions = if ((feeAmount > 0)) | |
77 | 80 | then [ScriptTransfer(address, sendAmount, sendAssetId)] | |
78 | 81 | else throw("amount is too low") | |
79 | 82 | $Tuple2(sendActions, $Tuple4(sendAmount, feeAmount, sendAssetId, userRealPrice)) | |
80 | 83 | } | |
81 | 84 | else throw("Strict value is not equal to itself.") | |
82 | 85 | } | |
83 | 86 | ||
84 | 87 | ||
85 | 88 | @Callable(i) | |
86 | 89 | func swap () = swapInternal(i.caller, i) | |
87 | 90 | ||
88 | 91 | ||
89 | 92 | ||
90 | 93 | @Callable(i) | |
91 | 94 | func swapNoLess (minAmount) = { | |
92 | - | let $ | |
93 | - | let sendActions = $ | |
94 | - | let tuple = $ | |
95 | - | let $ | |
96 | - | let sendAmount = $ | |
97 | - | let feeAmount = $ | |
98 | - | let sendAssetId = $ | |
99 | - | let userRealPrice = $ | |
95 | + | let $t029282980 = swapInternal(i.caller, i) | |
96 | + | let sendActions = $t029282980._1 | |
97 | + | let tuple = $t029282980._2 | |
98 | + | let $t029853048 = tuple | |
99 | + | let sendAmount = $t029853048._1 | |
100 | + | let feeAmount = $t029853048._2 | |
101 | + | let sendAssetId = $t029853048._3 | |
102 | + | let userRealPrice = $t029853048._4 | |
100 | 103 | if ((minAmount > sendAmount)) | |
101 | 104 | then throw(makeString(["Price slipped. minAmount: ", toString(minAmount), " swapAmount: ", toString(sendAmount)], "")) | |
102 | 105 | else $Tuple2(sendActions, tuple) | |
103 | 106 | } | |
104 | 107 | ||
105 | 108 | ||
106 | 109 | ||
107 | 110 | @Callable(i) | |
108 | 111 | func swapFor (address) = swapInternal(addressFromStringValue(address), i) | |
109 | 112 | ||
110 | 113 |
github/deemru/w8io/169f3d6 37.13 ms ◑