tx · 33HXGRTLEydx9ES2EZ4HPKc3u7QdfMKTFKGnGxDSqMfc 3N61RYWc9QuqKUwLvowpZZLpgUnqpQSFwLq: -0.01000000 Waves 2024.03.04 14:32 [3003212] smart account 3N61RYWc9QuqKUwLvowpZZLpgUnqpQSFwLq > SELF 0.00000000 Waves
{ "type": 13, "id": "33HXGRTLEydx9ES2EZ4HPKc3u7QdfMKTFKGnGxDSqMfc", "fee": 1000000, "feeAssetId": null, "timestamp": 1709551978491, "version": 2, "chainId": 84, "sender": "3N61RYWc9QuqKUwLvowpZZLpgUnqpQSFwLq", "senderPublicKey": "HdwFH8HPYu3HG27yK6bszu1CdR4uik4HgzyTimeSfcYf", "proofs": [ "3ZcVK22RZKQe8fZ4rMuHB187ys7AZJ27Ei3VrxdgGthmQaBeHp2f1Ccaop2Bkngcy5uGAtJ5iBaMxTzJsP6jHCyE" ], "script": "base64:BgIJCAISABIDCgEIDgAQYW1vdW50QXNzZXRJZEtleQINYW1vdW50QXNzZXRJZAAPcHJpY2VBc3NldElkS2V5AgxwcmljZUFzc2V0SWQACmZlZVJhdGVLZXkCB2ZlZVJhdGUBCmdldEFzc2V0SWQBDWFzc2V0SWRTdHJpbmcDCQAAAgUNYXNzZXRJZFN0cmluZwIFV0FWRVMFBHVuaXQJANkEAQUNYXNzZXRJZFN0cmluZwEPZ2V0QXNzZXRCYWxhbmNlAQdhc3NldElkBAckbWF0Y2gwBQdhc3NldElkAwkAAQIFByRtYXRjaDACCkJ5dGVWZWN0b3IEAmlkBQckbWF0Y2gwCQDwBwIFBHRoaXMFAmlkCAkA7wcBBQR0aGlzCWF2YWlsYWJsZQATYW1vdW50QXNzZXRJZFN0cmluZwkBEUBleHRyTmF0aXZlKDEwNTMpAgUEdGhpcwUQYW1vdW50QXNzZXRJZEtleQANYW1vdW50QXNzZXRJZAkBCmdldEFzc2V0SWQBBRNhbW91bnRBc3NldElkU3RyaW5nABJwcmljZUFzc2V0SWRTdHJpbmcJARFAZXh0ck5hdGl2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AAAFCWZlZUFtb3VudAkAzAgCCQEOU2NyaXB0VHJhbnNmZXIDBQdhZGRyZXNzBQpzZW5kQW1vdW50BQtzZW5kQXNzZXRJZAUDbmlsCQACAQIRYW1vdW50IGlzIHRvbyBsb3cJAJQKAgULc2VuZEFjdGlvbnMJAJYKBAUKc2VuZEFtb3VudAUJZmVlQW1vdW50BQtzZW5kQXNzZXRJZAUNdXNlclJlYWxQcmljZQkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgIBaQEEc3dhcAAJAQxzd2FwSW50ZXJuYWwCCAUBaQZjYWxsZXIFAWkBaQEHc3dhcEZvcgEHYWRkcmVzcwkBDHN3YXBJbnRlcm5hbAIJARFAZXh0ck5hdGl2ZSgxMDYyKQEFB2FkZHJlc3MFAWkAvtOQIQ==", "height": 3003212, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 84HimeExGbNgyFFNkU9A4yjPrvhocm7dgrGYy3yxz3vb Next: 8uyPT7s4kuon3CLduEBBzpLXB9X6G1GyWGN9Fq94bVjd Diff:
Old | New | Differences | |
---|---|---|---|
24 | 24 | ||
25 | 25 | let amountAssetId = getAssetId(amountAssetIdString) | |
26 | 26 | ||
27 | - | let amountAssetBalance = getAssetBalance(amountAssetId) | |
28 | - | ||
29 | 27 | let priceAssetIdString = getStringValue(this, priceAssetIdKey) | |
30 | 28 | ||
31 | 29 | let priceAssetId = getAssetId(priceAssetIdString) | |
32 | 30 | ||
33 | - | let priceAssetBalance = getAssetBalance(priceAssetId) | |
34 | - | ||
35 | 31 | let SCALE8 = 100000000 | |
36 | 32 | ||
37 | - | let feeRate = valueOrElse(getInteger(this, feeRateKey), | |
33 | + | let feeRate = valueOrElse(getInteger(this, feeRateKey), 200000) | |
38 | 34 | ||
39 | 35 | func calcRawSendAmount (initAmBal,initPrBal,paymentAmount) = { | |
40 | 36 | let newPrBal = (initPrBal + paymentAmount) | |
45 | 41 | ||
46 | 42 | ||
47 | 43 | func calcSendAmount (paymentAssetId,paymentAmount) = { | |
48 | - | let $ | |
44 | + | let $t012301382 = if ((paymentAssetId == amountAssetId)) | |
49 | 45 | then $Tuple2(priceAssetId, amountAssetId) | |
50 | 46 | else $Tuple2(amountAssetId, priceAssetId) | |
51 | - | let amAssetId = $ | |
52 | - | let prAssetId = $ | |
47 | + | let amAssetId = $t012301382._1 | |
48 | + | let prAssetId = $t012301382._2 | |
53 | 49 | let initAmBal = getAssetBalance(amAssetId) | |
54 | 50 | let initPrBal = (getAssetBalance(prAssetId) - paymentAmount) | |
55 | 51 | let rawSendAmount = calcRawSendAmount(initAmBal, initPrBal, paymentAmount) | |
65 | 61 | func swapInternal (address,i) = { | |
66 | 62 | let checks = [if ((size(i.payments) > 0)) | |
67 | 63 | then true | |
68 | - | else throw("should be with 1 payment"), if (if ((i.payments[0].assetId == amountAssetId)) | |
69 | - | then true | |
70 | - | else (i.payments[0].assetId == priceAssetId)) | |
64 | + | else throw("should be with 1 payment"), if (containsElement([amountAssetId, priceAssetId], i.payments[0].assetId)) | |
71 | 65 | then true | |
72 | 66 | else throw(makeString(["payment assetId should be (", amountAssetIdString, ") or (", priceAssetIdString, ")"], " "))] | |
73 | 67 | if ((checks == checks)) | |
74 | 68 | then { | |
75 | 69 | let paymentAssetId = i.payments[0].assetId | |
76 | 70 | let paymentAmount = i.payments[0].amount | |
77 | - | let $ | |
78 | - | let sendAmount = $ | |
79 | - | let feeAmount = $ | |
80 | - | let sendAssetId = $ | |
81 | - | let userRealPrice = $ | |
82 | - | let sendActions = if (( | |
71 | + | let $t023702473 = calcSendAmount(paymentAssetId, paymentAmount) | |
72 | + | let sendAmount = $t023702473._1 | |
73 | + | let feeAmount = $t023702473._2 | |
74 | + | let sendAssetId = $t023702473._3 | |
75 | + | let userRealPrice = $t023702473._4 | |
76 | + | let sendActions = if ((0 >= feeAmount)) | |
83 | 77 | then [ScriptTransfer(address, sendAmount, sendAssetId)] | |
84 | 78 | else throw("amount is too low") | |
85 | 79 | $Tuple2(sendActions, $Tuple4(sendAmount, feeAmount, sendAssetId, userRealPrice)) |
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 | - | let amountAssetBalance = getAssetBalance(amountAssetId) | |
28 | - | ||
29 | 27 | let priceAssetIdString = getStringValue(this, priceAssetIdKey) | |
30 | 28 | ||
31 | 29 | let priceAssetId = getAssetId(priceAssetIdString) | |
32 | 30 | ||
33 | - | let priceAssetBalance = getAssetBalance(priceAssetId) | |
34 | - | ||
35 | 31 | let SCALE8 = 100000000 | |
36 | 32 | ||
37 | - | let feeRate = valueOrElse(getInteger(this, feeRateKey), | |
33 | + | let feeRate = valueOrElse(getInteger(this, feeRateKey), 200000) | |
38 | 34 | ||
39 | 35 | func calcRawSendAmount (initAmBal,initPrBal,paymentAmount) = { | |
40 | 36 | let newPrBal = (initPrBal + paymentAmount) | |
41 | 37 | let newAmBal = fraction(initAmBal, initPrBal, newPrBal) | |
42 | 38 | let sendAmount = (initAmBal - newAmBal) | |
43 | 39 | sendAmount | |
44 | 40 | } | |
45 | 41 | ||
46 | 42 | ||
47 | 43 | func calcSendAmount (paymentAssetId,paymentAmount) = { | |
48 | - | let $ | |
44 | + | let $t012301382 = if ((paymentAssetId == amountAssetId)) | |
49 | 45 | then $Tuple2(priceAssetId, amountAssetId) | |
50 | 46 | else $Tuple2(amountAssetId, priceAssetId) | |
51 | - | let amAssetId = $ | |
52 | - | let prAssetId = $ | |
47 | + | let amAssetId = $t012301382._1 | |
48 | + | let prAssetId = $t012301382._2 | |
53 | 49 | let initAmBal = getAssetBalance(amAssetId) | |
54 | 50 | let initPrBal = (getAssetBalance(prAssetId) - paymentAmount) | |
55 | 51 | let rawSendAmount = calcRawSendAmount(initAmBal, initPrBal, paymentAmount) | |
56 | 52 | let feeAmount = fraction(rawSendAmount, feeRate, SCALE8) | |
57 | 53 | let sendAmount = (rawSendAmount - feeAmount) | |
58 | 54 | let userRealPrice = if ((paymentAssetId == amountAssetId)) | |
59 | 55 | then fraction(sendAmount, SCALE8, paymentAmount) | |
60 | 56 | else fraction(paymentAmount, SCALE8, sendAmount) | |
61 | 57 | $Tuple4(sendAmount, feeAmount, amAssetId, userRealPrice) | |
62 | 58 | } | |
63 | 59 | ||
64 | 60 | ||
65 | 61 | func swapInternal (address,i) = { | |
66 | 62 | let checks = [if ((size(i.payments) > 0)) | |
67 | 63 | then true | |
68 | - | else throw("should be with 1 payment"), if (if ((i.payments[0].assetId == amountAssetId)) | |
69 | - | then true | |
70 | - | else (i.payments[0].assetId == priceAssetId)) | |
64 | + | else throw("should be with 1 payment"), if (containsElement([amountAssetId, priceAssetId], i.payments[0].assetId)) | |
71 | 65 | then true | |
72 | 66 | else throw(makeString(["payment assetId should be (", amountAssetIdString, ") or (", priceAssetIdString, ")"], " "))] | |
73 | 67 | if ((checks == checks)) | |
74 | 68 | then { | |
75 | 69 | let paymentAssetId = i.payments[0].assetId | |
76 | 70 | let paymentAmount = i.payments[0].amount | |
77 | - | let $ | |
78 | - | let sendAmount = $ | |
79 | - | let feeAmount = $ | |
80 | - | let sendAssetId = $ | |
81 | - | let userRealPrice = $ | |
82 | - | let sendActions = if (( | |
71 | + | let $t023702473 = calcSendAmount(paymentAssetId, paymentAmount) | |
72 | + | let sendAmount = $t023702473._1 | |
73 | + | let feeAmount = $t023702473._2 | |
74 | + | let sendAssetId = $t023702473._3 | |
75 | + | let userRealPrice = $t023702473._4 | |
76 | + | let sendActions = if ((0 >= feeAmount)) | |
83 | 77 | then [ScriptTransfer(address, sendAmount, sendAssetId)] | |
84 | 78 | else throw("amount is too low") | |
85 | 79 | $Tuple2(sendActions, $Tuple4(sendAmount, feeAmount, sendAssetId, userRealPrice)) | |
86 | 80 | } | |
87 | 81 | else throw("Strict value is not equal to itself.") | |
88 | 82 | } | |
89 | 83 | ||
90 | 84 | ||
91 | 85 | @Callable(i) | |
92 | 86 | func swap () = swapInternal(i.caller, i) | |
93 | 87 | ||
94 | 88 | ||
95 | 89 | ||
96 | 90 | @Callable(i) | |
97 | 91 | func swapFor (address) = swapInternal(addressFromStringValue(address), i) | |
98 | 92 | ||
99 | 93 |
github/deemru/w8io/026f985 39.70 ms ◑