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