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