tx · 3EkWVLxCyv7nZ5cY3GPJsqTUodzdYsD61AY3FN76aeZc
3N61RYWc9QuqKUwLvowpZZLpgUnqpQSFwLq: -0.01200000 Waves
2024.03.09 14:25 [3010438] smart account 3N61RYWc9QuqKUwLvowpZZLpgUnqpQSFwLq > SELF 0.00000000 Waves
{
"type": 13,
"id": "3EkWVLxCyv7nZ5cY3GPJsqTUodzdYsD61AY3FN76aeZc",
"fee": 1200000,
"feeAssetId": null,
"timestamp": 1709983548705,
"version": 2,
"chainId": 84,
"sender": "3N61RYWc9QuqKUwLvowpZZLpgUnqpQSFwLq",
"senderPublicKey": "HdwFH8HPYu3HG27yK6bszu1CdR4uik4HgzyTimeSfcYf",
"proofs": [
"5t7ni53pLRAwmmuJ3QyEva3A8qVQyZicQvdDJjycADLxAcb9NjtC5yBf9EPiLVfvuvDUhhBHDfMS3m9N46ExXNA7"
],
"script": "base64:BgITCAISABIDCgEBEgMKAQgSAwoBBBIAEGFtb3VudEFzc2V0SWRLZXkCDWFtb3VudEFzc2V0SWQAD3ByaWNlQXNzZXRJZEtleQIMcHJpY2VBc3NldElkAApmZWVSYXRlS2V5AgdmZWVSYXRlAAxmb3JjZVN0b3BLZXkCCWZvcmNlU3RvcAEKZ2V0QXNzZXRJZAENYXNzZXRJZFN0cmluZwMJAAACBQ1hc3NldElkU3RyaW5nAgVXQVZFUwUEdW5pdAkA2QQBBQ1hc3NldElkU3RyaW5nAQ9nZXRBc3NldEJhbGFuY2UBB2Fzc2V0SWQEByRtYXRjaDAFB2Fzc2V0SWQDCQABAgUHJG1hdGNoMAIKQnl0ZVZlY3RvcgQCaWQFByRtYXRjaDAJAPAHAgUEdGhpcwUCaWQICQDvBwEFBHRoaXMJYXZhaWxhYmxlABNhbW91bnRBc3NldElkU3RyaW5nCQERQGV4dHJOYXRpdmUoMTA1MykCBQR0aGlzBRBhbW91bnRBc3NldElkS2V5AA1hbW91bnRBc3NldElkCQEKZ2V0QXNzZXRJZAEFE2Ftb3VudEFzc2V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bmlsCQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAEsw0ho=",
"height": 3010438,
"applicationStatus": "succeeded",
"spentComplexity": 0
}
View: original | compacted
Prev: HhD2BVD5Nrzp9NkMnioivX7qSq4THeTBajYR1mXwDVQZ
Next: none
Diff:
Old | New | | Differences |
---|
6 | 6 | | let priceAssetIdKey = "priceAssetId" |
---|
7 | 7 | | |
---|
8 | 8 | | let feeRateKey = "feeRate" |
---|
| 9 | + | |
---|
| 10 | + | let forceStopKey = "forceStop" |
---|
9 | 11 | | |
---|
10 | 12 | | func getAssetId (assetIdString) = if ((assetIdString == "WAVES")) |
---|
11 | 13 | | then unit |
---|
|
32 | 34 | | |
---|
33 | 35 | | let feeRate = valueOrElse(getInteger(this, feeRateKey), 200000) |
---|
34 | 36 | | |
---|
| 37 | + | let isForceStopped = valueOrElse(getBoolean(this, forceStopKey), false) |
---|
| 38 | + | |
---|
35 | 39 | | func calcPrice () = fraction(getAssetBalance(priceAssetId), SCALE8, getAssetBalance(amountAssetId)) |
---|
36 | 40 | | |
---|
37 | 41 | | |
---|
38 | | - | func calcRawSendAmount (initAmBal,initPrBal,paymentAmount) = { |
---|
39 | | - | let newPrBal = (initPrBal + paymentAmount) |
---|
40 | | - | let newAmBal = fraction(initAmBal, initPrBal, newPrBal) |
---|
41 | | - | let sendAmount = (initAmBal - newAmBal) |
---|
| 42 | + | func calcRawSendAmount (asset1InitBalance,asset2InitBalance,asset2PaymentAmount) = { |
---|
| 43 | + | let newAsset2Balance = (asset2InitBalance + asset2PaymentAmount) |
---|
| 44 | + | let newAsset1Balance = fraction(asset1InitBalance, asset2InitBalance, newAsset2Balance) |
---|
| 45 | + | let sendAmount = (asset1InitBalance - newAsset1Balance) |
---|
42 | 46 | | sendAmount |
---|
43 | 47 | | } |
---|
44 | 48 | | |
---|
45 | 49 | | |
---|
46 | 50 | | func calcSendAmount (paymentAssetId,paymentAmount,readonly) = { |
---|
47 | | - | let $t013571509 = if ((paymentAssetId == amountAssetId)) |
---|
| 51 | + | let $t015551715 = if ((paymentAssetId == amountAssetId)) |
---|
48 | 52 | | then $Tuple2(priceAssetId, amountAssetId) |
---|
49 | 53 | | else $Tuple2(amountAssetId, priceAssetId) |
---|
50 | | - | let amAssetId = $t013571509._1 |
---|
51 | | - | let prAssetId = $t013571509._2 |
---|
52 | | - | let initAmBal = getAssetBalance(amAssetId) |
---|
53 | | - | let initPrBal = (getAssetBalance(prAssetId) - (if (readonly) |
---|
| 54 | + | let asset1AssetId = $t015551715._1 |
---|
| 55 | + | let asset2AssetId = $t015551715._2 |
---|
| 56 | + | let asset1InitBalance = getAssetBalance(asset1AssetId) |
---|
| 57 | + | let asset2InitBalance = (getAssetBalance(asset2AssetId) - (if (readonly) |
---|
54 | 58 | | then 0 |
---|
55 | 59 | | else paymentAmount)) |
---|
56 | | - | let rawSendAmount = calcRawSendAmount(initAmBal, initPrBal, paymentAmount) |
---|
| 60 | + | let rawSendAmount = calcRawSendAmount(asset1InitBalance, asset2InitBalance, paymentAmount) |
---|
57 | 61 | | let feeAmount = fraction(rawSendAmount, feeRate, SCALE8) |
---|
58 | 62 | | let sendAmount = (rawSendAmount - feeAmount) |
---|
59 | 63 | | let userRealPrice = if ((paymentAssetId == amountAssetId)) |
---|
60 | 64 | | then fraction(sendAmount, SCALE8, paymentAmount) |
---|
61 | 65 | | else fraction(paymentAmount, SCALE8, sendAmount) |
---|
62 | | - | $Tuple4(sendAmount, feeAmount, amAssetId, userRealPrice) |
---|
| 66 | + | $Tuple4(sendAmount, feeAmount, asset1AssetId, userRealPrice) |
---|
63 | 67 | | } |
---|
64 | 68 | | |
---|
65 | 69 | | |
---|
66 | 70 | | func swapInternal (address,i) = { |
---|
67 | | - | let checks = [if ((size(i.payments) > 0)) |
---|
| 71 | + | let checks = [if (!(isForceStopped)) |
---|
| 72 | + | then true |
---|
| 73 | + | else throw("contract is temporary stopped"), if ((size(i.payments) > 0)) |
---|
68 | 74 | | then true |
---|
69 | 75 | | else throw("should be with 1 payment"), if (containsElement([amountAssetId, priceAssetId], i.payments[0].assetId)) |
---|
70 | 76 | | then true |
---|
|
73 | 79 | | then { |
---|
74 | 80 | | let paymentAssetId = i.payments[0].assetId |
---|
75 | 81 | | let paymentAmount = i.payments[0].amount |
---|
76 | | - | let $t025142624 = calcSendAmount(paymentAssetId, paymentAmount, false) |
---|
77 | | - | let sendAmount = $t025142624._1 |
---|
78 | | - | let feeAmount = $t025142624._2 |
---|
79 | | - | let sendAssetId = $t025142624._3 |
---|
80 | | - | let userRealPrice = $t025142624._4 |
---|
| 82 | + | let $t028322942 = calcSendAmount(paymentAssetId, paymentAmount, false) |
---|
| 83 | + | let sendAmount = $t028322942._1 |
---|
| 84 | + | let feeAmount = $t028322942._2 |
---|
| 85 | + | let sendAssetId = $t028322942._3 |
---|
| 86 | + | let userRealPrice = $t028322942._4 |
---|
81 | 87 | | let sendActions = if ((feeAmount > 0)) |
---|
82 | 88 | | then [ScriptTransfer(address, sendAmount, sendAssetId)] |
---|
83 | 89 | | else throw("amount is too low") |
---|
|
88 | 94 | | |
---|
89 | 95 | | |
---|
90 | 96 | | func calcSendAmountREADONLY (paymentAssetString,paymentAmount) = { |
---|
91 | | - | let $t029563080 = calcSendAmount(getAssetId(paymentAssetString), paymentAmount, true) |
---|
92 | | - | let sendAmount = $t029563080._1 |
---|
93 | | - | let feeAmount = $t029563080._2 |
---|
94 | | - | let amAssetId = $t029563080._3 |
---|
95 | | - | let userRealPrice = $t029563080._4 |
---|
| 97 | + | let $t032743398 = calcSendAmount(getAssetId(paymentAssetString), paymentAmount, true) |
---|
| 98 | + | let sendAmount = $t032743398._1 |
---|
| 99 | + | let feeAmount = $t032743398._2 |
---|
| 100 | + | let amAssetId = $t032743398._3 |
---|
| 101 | + | let userRealPrice = $t032743398._4 |
---|
96 | 102 | | $Tuple3(sendAmount, userRealPrice, amAssetId) |
---|
97 | 103 | | } |
---|
98 | 104 | | |
---|
|
104 | 110 | | |
---|
105 | 111 | | @Callable(i) |
---|
106 | 112 | | func swapNoLess (minAmount) = { |
---|
107 | | - | let $t032623314 = swapInternal(i.caller, i) |
---|
108 | | - | let sendActions = $t032623314._1 |
---|
109 | | - | let tuple = $t032623314._2 |
---|
110 | | - | let $t033193382 = tuple |
---|
111 | | - | let sendAmount = $t033193382._1 |
---|
112 | | - | let feeAmount = $t033193382._2 |
---|
113 | | - | let sendAssetId = $t033193382._3 |
---|
114 | | - | let userRealPrice = $t033193382._4 |
---|
| 113 | + | let $t035803632 = swapInternal(i.caller, i) |
---|
| 114 | + | let sendActions = $t035803632._1 |
---|
| 115 | + | let tuple = $t035803632._2 |
---|
| 116 | + | let $t036373700 = tuple |
---|
| 117 | + | let sendAmount = $t036373700._1 |
---|
| 118 | + | let feeAmount = $t036373700._2 |
---|
| 119 | + | let sendAssetId = $t036373700._3 |
---|
| 120 | + | let userRealPrice = $t036373700._4 |
---|
115 | 121 | | if ((minAmount > sendAmount)) |
---|
116 | 122 | | then throw(makeString(["Price slipped. minAmount: ", toString(minAmount), " swapAmount: ", toString(sendAmount)], "")) |
---|
117 | 123 | | else $Tuple2(sendActions, tuple) |
---|
|
123 | 129 | | func swapFor (address) = swapInternal(addressFromStringValue(address), i) |
---|
124 | 130 | | |
---|
125 | 131 | | |
---|
| 132 | + | |
---|
| 133 | + | @Callable(i) |
---|
| 134 | + | func forceStop (stopFlag) = { |
---|
| 135 | + | let checks = [if ((i.caller == this)) |
---|
| 136 | + | then true |
---|
| 137 | + | else throw("permission denied")] |
---|
| 138 | + | if ((checks == checks)) |
---|
| 139 | + | then [BooleanEntry(forceStopKey, stopFlag)] |
---|
| 140 | + | else throw("Strict value is not equal to itself.") |
---|
| 141 | + | } |
---|
| 142 | + | |
---|
| 143 | + | |
---|
Full:
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 | + | |
---|
| 10 | + | let forceStopKey = "forceStop" |
---|
9 | 11 | | |
---|
10 | 12 | | func getAssetId (assetIdString) = if ((assetIdString == "WAVES")) |
---|
11 | 13 | | then unit |
---|
12 | 14 | | else fromBase58String(assetIdString) |
---|
13 | 15 | | |
---|
14 | 16 | | |
---|
15 | 17 | | func getAssetBalance (assetId) = match assetId { |
---|
16 | 18 | | case id: ByteVector => |
---|
17 | 19 | | assetBalance(this, id) |
---|
18 | 20 | | case _ => |
---|
19 | 21 | | wavesBalance(this).available |
---|
20 | 22 | | } |
---|
21 | 23 | | |
---|
22 | 24 | | |
---|
23 | 25 | | let amountAssetIdString = getStringValue(this, amountAssetIdKey) |
---|
24 | 26 | | |
---|
25 | 27 | | let amountAssetId = getAssetId(amountAssetIdString) |
---|
26 | 28 | | |
---|
27 | 29 | | let priceAssetIdString = getStringValue(this, priceAssetIdKey) |
---|
28 | 30 | | |
---|
29 | 31 | | let priceAssetId = getAssetId(priceAssetIdString) |
---|
30 | 32 | | |
---|
31 | 33 | | let SCALE8 = 100000000 |
---|
32 | 34 | | |
---|
33 | 35 | | let feeRate = valueOrElse(getInteger(this, feeRateKey), 200000) |
---|
34 | 36 | | |
---|
| 37 | + | let isForceStopped = valueOrElse(getBoolean(this, forceStopKey), false) |
---|
| 38 | + | |
---|
35 | 39 | | func calcPrice () = fraction(getAssetBalance(priceAssetId), SCALE8, getAssetBalance(amountAssetId)) |
---|
36 | 40 | | |
---|
37 | 41 | | |
---|
38 | | - | func calcRawSendAmount (initAmBal,initPrBal,paymentAmount) = { |
---|
39 | | - | let newPrBal = (initPrBal + paymentAmount) |
---|
40 | | - | let newAmBal = fraction(initAmBal, initPrBal, newPrBal) |
---|
41 | | - | let sendAmount = (initAmBal - newAmBal) |
---|
| 42 | + | func calcRawSendAmount (asset1InitBalance,asset2InitBalance,asset2PaymentAmount) = { |
---|
| 43 | + | let newAsset2Balance = (asset2InitBalance + asset2PaymentAmount) |
---|
| 44 | + | let newAsset1Balance = fraction(asset1InitBalance, asset2InitBalance, newAsset2Balance) |
---|
| 45 | + | let sendAmount = (asset1InitBalance - newAsset1Balance) |
---|
42 | 46 | | sendAmount |
---|
43 | 47 | | } |
---|
44 | 48 | | |
---|
45 | 49 | | |
---|
46 | 50 | | func calcSendAmount (paymentAssetId,paymentAmount,readonly) = { |
---|
47 | | - | let $t013571509 = if ((paymentAssetId == amountAssetId)) |
---|
| 51 | + | let $t015551715 = if ((paymentAssetId == amountAssetId)) |
---|
48 | 52 | | then $Tuple2(priceAssetId, amountAssetId) |
---|
49 | 53 | | else $Tuple2(amountAssetId, priceAssetId) |
---|
50 | | - | let amAssetId = $t013571509._1 |
---|
51 | | - | let prAssetId = $t013571509._2 |
---|
52 | | - | let initAmBal = getAssetBalance(amAssetId) |
---|
53 | | - | let initPrBal = (getAssetBalance(prAssetId) - (if (readonly) |
---|
| 54 | + | let asset1AssetId = $t015551715._1 |
---|
| 55 | + | let asset2AssetId = $t015551715._2 |
---|
| 56 | + | let asset1InitBalance = getAssetBalance(asset1AssetId) |
---|
| 57 | + | let asset2InitBalance = (getAssetBalance(asset2AssetId) - (if (readonly) |
---|
54 | 58 | | then 0 |
---|
55 | 59 | | else paymentAmount)) |
---|
56 | | - | let rawSendAmount = calcRawSendAmount(initAmBal, initPrBal, paymentAmount) |
---|
| 60 | + | let rawSendAmount = calcRawSendAmount(asset1InitBalance, asset2InitBalance, paymentAmount) |
---|
57 | 61 | | let feeAmount = fraction(rawSendAmount, feeRate, SCALE8) |
---|
58 | 62 | | let sendAmount = (rawSendAmount - feeAmount) |
---|
59 | 63 | | let userRealPrice = if ((paymentAssetId == amountAssetId)) |
---|
60 | 64 | | then fraction(sendAmount, SCALE8, paymentAmount) |
---|
61 | 65 | | else fraction(paymentAmount, SCALE8, sendAmount) |
---|
62 | | - | $Tuple4(sendAmount, feeAmount, amAssetId, userRealPrice) |
---|
| 66 | + | $Tuple4(sendAmount, feeAmount, asset1AssetId, userRealPrice) |
---|
63 | 67 | | } |
---|
64 | 68 | | |
---|
65 | 69 | | |
---|
66 | 70 | | func swapInternal (address,i) = { |
---|
67 | | - | let checks = [if ((size(i.payments) > 0)) |
---|
| 71 | + | let checks = [if (!(isForceStopped)) |
---|
| 72 | + | then true |
---|
| 73 | + | else throw("contract is temporary stopped"), if ((size(i.payments) > 0)) |
---|
68 | 74 | | then true |
---|
69 | 75 | | else throw("should be with 1 payment"), if (containsElement([amountAssetId, priceAssetId], i.payments[0].assetId)) |
---|
70 | 76 | | then true |
---|
71 | 77 | | else throw(makeString(["payment assetId should be", amountAssetIdString, "or", priceAssetIdString], " "))] |
---|
72 | 78 | | if ((checks == checks)) |
---|
73 | 79 | | then { |
---|
74 | 80 | | let paymentAssetId = i.payments[0].assetId |
---|
75 | 81 | | let paymentAmount = i.payments[0].amount |
---|
76 | | - | let $t025142624 = calcSendAmount(paymentAssetId, paymentAmount, false) |
---|
77 | | - | let sendAmount = $t025142624._1 |
---|
78 | | - | let feeAmount = $t025142624._2 |
---|
79 | | - | let sendAssetId = $t025142624._3 |
---|
80 | | - | let userRealPrice = $t025142624._4 |
---|
| 82 | + | let $t028322942 = calcSendAmount(paymentAssetId, paymentAmount, false) |
---|
| 83 | + | let sendAmount = $t028322942._1 |
---|
| 84 | + | let feeAmount = $t028322942._2 |
---|
| 85 | + | let sendAssetId = $t028322942._3 |
---|
| 86 | + | let userRealPrice = $t028322942._4 |
---|
81 | 87 | | let sendActions = if ((feeAmount > 0)) |
---|
82 | 88 | | then [ScriptTransfer(address, sendAmount, sendAssetId)] |
---|
83 | 89 | | else throw("amount is too low") |
---|
84 | 90 | | $Tuple2(sendActions, $Tuple4(sendAmount, feeAmount, sendAssetId, userRealPrice)) |
---|
85 | 91 | | } |
---|
86 | 92 | | else throw("Strict value is not equal to itself.") |
---|
87 | 93 | | } |
---|
88 | 94 | | |
---|
89 | 95 | | |
---|
90 | 96 | | func calcSendAmountREADONLY (paymentAssetString,paymentAmount) = { |
---|
91 | | - | let $t029563080 = calcSendAmount(getAssetId(paymentAssetString), paymentAmount, true) |
---|
92 | | - | let sendAmount = $t029563080._1 |
---|
93 | | - | let feeAmount = $t029563080._2 |
---|
94 | | - | let amAssetId = $t029563080._3 |
---|
95 | | - | let userRealPrice = $t029563080._4 |
---|
| 97 | + | let $t032743398 = calcSendAmount(getAssetId(paymentAssetString), paymentAmount, true) |
---|
| 98 | + | let sendAmount = $t032743398._1 |
---|
| 99 | + | let feeAmount = $t032743398._2 |
---|
| 100 | + | let amAssetId = $t032743398._3 |
---|
| 101 | + | let userRealPrice = $t032743398._4 |
---|
96 | 102 | | $Tuple3(sendAmount, userRealPrice, amAssetId) |
---|
97 | 103 | | } |
---|
98 | 104 | | |
---|
99 | 105 | | |
---|
100 | 106 | | @Callable(i) |
---|
101 | 107 | | func swap () = swapInternal(i.caller, i) |
---|
102 | 108 | | |
---|
103 | 109 | | |
---|
104 | 110 | | |
---|
105 | 111 | | @Callable(i) |
---|
106 | 112 | | func swapNoLess (minAmount) = { |
---|
107 | | - | let $t032623314 = swapInternal(i.caller, i) |
---|
108 | | - | let sendActions = $t032623314._1 |
---|
109 | | - | let tuple = $t032623314._2 |
---|
110 | | - | let $t033193382 = tuple |
---|
111 | | - | let sendAmount = $t033193382._1 |
---|
112 | | - | let feeAmount = $t033193382._2 |
---|
113 | | - | let sendAssetId = $t033193382._3 |
---|
114 | | - | let userRealPrice = $t033193382._4 |
---|
| 113 | + | let $t035803632 = swapInternal(i.caller, i) |
---|
| 114 | + | let sendActions = $t035803632._1 |
---|
| 115 | + | let tuple = $t035803632._2 |
---|
| 116 | + | let $t036373700 = tuple |
---|
| 117 | + | let sendAmount = $t036373700._1 |
---|
| 118 | + | let feeAmount = $t036373700._2 |
---|
| 119 | + | let sendAssetId = $t036373700._3 |
---|
| 120 | + | let userRealPrice = $t036373700._4 |
---|
115 | 121 | | if ((minAmount > sendAmount)) |
---|
116 | 122 | | then throw(makeString(["Price slipped. minAmount: ", toString(minAmount), " swapAmount: ", toString(sendAmount)], "")) |
---|
117 | 123 | | else $Tuple2(sendActions, tuple) |
---|
118 | 124 | | } |
---|
119 | 125 | | |
---|
120 | 126 | | |
---|
121 | 127 | | |
---|
122 | 128 | | @Callable(i) |
---|
123 | 129 | | func swapFor (address) = swapInternal(addressFromStringValue(address), i) |
---|
124 | 130 | | |
---|
125 | 131 | | |
---|
| 132 | + | |
---|
| 133 | + | @Callable(i) |
---|
| 134 | + | func forceStop (stopFlag) = { |
---|
| 135 | + | let checks = [if ((i.caller == this)) |
---|
| 136 | + | then true |
---|
| 137 | + | else throw("permission denied")] |
---|
| 138 | + | if ((checks == checks)) |
---|
| 139 | + | then [BooleanEntry(forceStopKey, stopFlag)] |
---|
| 140 | + | else throw("Strict value is not equal to itself.") |
---|
| 141 | + | } |
---|
| 142 | + | |
---|
| 143 | + | |
---|