tx · 6KYVAw5XzxsofqQhM5rsfFRR6im2PGwTENNmbNiZmJiA 3N61RYWc9QuqKUwLvowpZZLpgUnqpQSFwLq: -0.01000000 Waves 2024.03.04 12:40 [3003089] smart account 3N61RYWc9QuqKUwLvowpZZLpgUnqpQSFwLq > SELF 0.00000000 Waves
{ "type": 13, "id": "6KYVAw5XzxsofqQhM5rsfFRR6im2PGwTENNmbNiZmJiA", "fee": 1000000, "feeAssetId": null, "timestamp": 1709545213972, "version": 2, "chainId": 84, "sender": "3N61RYWc9QuqKUwLvowpZZLpgUnqpQSFwLq", "senderPublicKey": "HdwFH8HPYu3HG27yK6bszu1CdR4uik4HgzyTimeSfcYf", "proofs": [ "v2aBg47zsymhTHg6bYBXrTM8m5UNFdWGQFeUNh4VqVMZVHUE7fpQU21a5k84qR6FdwRfQnJZtQcUaoijc2LX7qM" ], "script": "base64:BgIJCAISABIDCgEIEQAQYW1vdW50QXNzZXRJZEtleQINYW1vdW50QXNzZXRJZAAPcHJpY2VBc3NldElkS2V5AgxwcmljZUFzc2V0SWQACmZlZVJhdGVLZXkCB2ZlZVJhdGUBCmdldEFzc2V0SWQBDWFzc2V0SWRTdHJpbmcDCQAAAgUNYXNzZXRJZFN0cmluZwIFV0FWRVMFBHVuaXQJANkEAQUNYXNzZXRJZFN0cmluZwEPZ2V0QXNzZXRCYWxhbmNlAQdhc3NldElkBAckbWF0Y2gwBQdhc3NldElkAwkAAQIFByRtYXRjaDACCkJ5dGVWZWN0b3IEAmlkBQckbWF0Y2gwCQDwBwIFBHRoaXMFAmlkCAkA7wcBBQR0aGlzCWF2YWlsYWJsZQATYW1vdW50QXNzZXRJZFN0cmluZwkBEUBleHRyTmF0aXZlKDEwNTMpAgUEdGhpcwUQYW1vdW50QXNzZXRJZEtleQANYW1vdW50QXNzZXRJZAkBCmdldEFzc2V0SWQBBRNhbW91bnRBc3NldElkU3RyaW5nABJhbW91bnRBc3NldEJhbGFuY2UJAQ9nZXRBc3NldEJhbGFuY2UBBQ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UoMTA2MikBBQdhZGRyZXNzBQFpAKhIVsM=", "height": 3003089, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 3RSuSX2HnzPk9WDn8is6wWyhe6fPwMcxBZvWSQF8mABE Next: 84HimeExGbNgyFFNkU9A4yjPrvhocm7dgrGYy3yxz3vb Diff:
Old | New | Differences | |
---|---|---|---|
38 | 38 | ||
39 | 39 | func ammCalc (initAmBal,initPrBal,paymentAmount) = { | |
40 | 40 | let newPrBal = (initPrBal + paymentAmount) | |
41 | - | let newAmBal = | |
41 | + | let newAmBal = fraction(initAmBal, initPrBal, newPrBal) | |
42 | 42 | let sendAmount = (initAmBal - newAmBal) | |
43 | 43 | let newK = (newAmBal * newPrBal) | |
44 | 44 | let oldK = (initAmBal * initPrBal) | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func calcRawSendAmount (amBal,prBal,paymentAmount) = { | |
50 | - | let $ | |
51 | - | let sendAmount = $ | |
52 | - | let initAmBal = $ | |
53 | - | let initPrBal = $ | |
54 | - | let oldK = $ | |
55 | - | let newAmBal = $ | |
56 | - | let newPrBal = $ | |
57 | - | let newK = $ | |
50 | + | let $t015221693 = ammCalc(amBal, prBal, paymentAmount) | |
51 | + | let sendAmount = $t015221693._1 | |
52 | + | let initAmBal = $t015221693._2 | |
53 | + | let initPrBal = $t015221693._3 | |
54 | + | let oldK = $t015221693._4 | |
55 | + | let newAmBal = $t015221693._5 | |
56 | + | let newPrBal = $t015221693._6 | |
57 | + | let newK = $t015221693._7 | |
58 | 58 | sendAmount | |
59 | 59 | } | |
60 | 60 | ||
61 | 61 | ||
62 | 62 | func calcSendAmount (paymentAssetId,paymentAmount) = { | |
63 | - | let $ | |
63 | + | let $t017941946 = if ((paymentAssetId == amountAssetId)) | |
64 | 64 | then $Tuple2(priceAssetId, amountAssetId) | |
65 | 65 | else $Tuple2(amountAssetId, priceAssetId) | |
66 | - | let amAssetId = $ | |
67 | - | let prAssetId = $ | |
66 | + | let amAssetId = $t017941946._1 | |
67 | + | let prAssetId = $t017941946._2 | |
68 | 68 | let initAmBal = getAssetBalance(amAssetId) | |
69 | 69 | let initPrBal = (getAssetBalance(prAssetId) - paymentAmount) | |
70 | 70 | let rawSendAmount = calcRawSendAmount(initAmBal, initPrBal, paymentAmount) | |
89 | 89 | then { | |
90 | 90 | let paymentAssetId = i.payments[0].assetId | |
91 | 91 | let paymentAmount = i.payments[0].amount | |
92 | - | let $ | |
93 | - | let sendAmount = $ | |
94 | - | let feeAmount = $ | |
95 | - | let sendAssetId = $ | |
96 | - | let userRealPrice = $ | |
92 | + | let $t029433046 = calcSendAmount(paymentAssetId, paymentAmount) | |
93 | + | let sendAmount = $t029433046._1 | |
94 | + | let feeAmount = $t029433046._2 | |
95 | + | let sendAssetId = $t029433046._3 | |
96 | + | let userRealPrice = $t029433046._4 | |
97 | 97 | let sendActions = if ((feeAmount != 0)) | |
98 | 98 | then [ScriptTransfer(address, sendAmount, sendAssetId)] | |
99 | 99 | 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 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 newPrBal = (initPrBal + paymentAmount) | |
41 | - | let newAmBal = | |
41 | + | let newAmBal = fraction(initAmBal, initPrBal, newPrBal) | |
42 | 42 | let sendAmount = (initAmBal - newAmBal) | |
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 (amBal,prBal,paymentAmount) = { | |
50 | - | let $ | |
51 | - | let sendAmount = $ | |
52 | - | let initAmBal = $ | |
53 | - | let initPrBal = $ | |
54 | - | let oldK = $ | |
55 | - | let newAmBal = $ | |
56 | - | let newPrBal = $ | |
57 | - | let newK = $ | |
50 | + | let $t015221693 = ammCalc(amBal, prBal, paymentAmount) | |
51 | + | let sendAmount = $t015221693._1 | |
52 | + | let initAmBal = $t015221693._2 | |
53 | + | let initPrBal = $t015221693._3 | |
54 | + | let oldK = $t015221693._4 | |
55 | + | let newAmBal = $t015221693._5 | |
56 | + | let newPrBal = $t015221693._6 | |
57 | + | let newK = $t015221693._7 | |
58 | 58 | sendAmount | |
59 | 59 | } | |
60 | 60 | ||
61 | 61 | ||
62 | 62 | func calcSendAmount (paymentAssetId,paymentAmount) = { | |
63 | - | let $ | |
63 | + | let $t017941946 = if ((paymentAssetId == amountAssetId)) | |
64 | 64 | then $Tuple2(priceAssetId, amountAssetId) | |
65 | 65 | else $Tuple2(amountAssetId, priceAssetId) | |
66 | - | let amAssetId = $ | |
67 | - | let prAssetId = $ | |
66 | + | let amAssetId = $t017941946._1 | |
67 | + | let prAssetId = $t017941946._2 | |
68 | 68 | let initAmBal = getAssetBalance(amAssetId) | |
69 | 69 | let initPrBal = (getAssetBalance(prAssetId) - paymentAmount) | |
70 | 70 | let rawSendAmount = calcRawSendAmount(initAmBal, initPrBal, paymentAmount) | |
71 | 71 | let feeAmount = fraction(rawSendAmount, feeRate, SCALE8) | |
72 | 72 | let sendAmount = (rawSendAmount - feeAmount) | |
73 | 73 | let userRealPrice = if ((paymentAssetId == amountAssetId)) | |
74 | 74 | then fraction(sendAmount, SCALE8, paymentAmount) | |
75 | 75 | else fraction(paymentAmount, SCALE8, sendAmount) | |
76 | 76 | $Tuple4(sendAmount, feeAmount, amAssetId, userRealPrice) | |
77 | 77 | } | |
78 | 78 | ||
79 | 79 | ||
80 | 80 | func swapInternal (address,i) = { | |
81 | 81 | let checks = [if ((size(i.payments) > 0)) | |
82 | 82 | then true | |
83 | 83 | else throw("should be with 1 payment"), if (if ((i.payments[0].assetId == amountAssetId)) | |
84 | 84 | then true | |
85 | 85 | else (i.payments[0].assetId == priceAssetId)) | |
86 | 86 | then true | |
87 | 87 | else throw(makeString(["payment assetId should be (", amountAssetIdString, ") or (", priceAssetIdString, ")"], " "))] | |
88 | 88 | if ((checks == checks)) | |
89 | 89 | then { | |
90 | 90 | let paymentAssetId = i.payments[0].assetId | |
91 | 91 | let paymentAmount = i.payments[0].amount | |
92 | - | let $ | |
93 | - | let sendAmount = $ | |
94 | - | let feeAmount = $ | |
95 | - | let sendAssetId = $ | |
96 | - | let userRealPrice = $ | |
92 | + | let $t029433046 = calcSendAmount(paymentAssetId, paymentAmount) | |
93 | + | let sendAmount = $t029433046._1 | |
94 | + | let feeAmount = $t029433046._2 | |
95 | + | let sendAssetId = $t029433046._3 | |
96 | + | let userRealPrice = $t029433046._4 | |
97 | 97 | let sendActions = if ((feeAmount != 0)) | |
98 | 98 | then [ScriptTransfer(address, sendAmount, sendAssetId)] | |
99 | 99 | else throw("amount is too low") | |
100 | 100 | $Tuple2(sendActions, $Tuple4(sendAmount, feeAmount, sendAssetId, userRealPrice)) | |
101 | 101 | } | |
102 | 102 | else throw("Strict value is not equal to itself.") | |
103 | 103 | } | |
104 | 104 | ||
105 | 105 | ||
106 | 106 | @Callable(i) | |
107 | 107 | func swap () = swapInternal(i.caller, i) | |
108 | 108 | ||
109 | 109 | ||
110 | 110 | ||
111 | 111 | @Callable(i) | |
112 | 112 | func swapFor (address) = swapInternal(addressFromStringValue(address), i) | |
113 | 113 | ||
114 | 114 |
github/deemru/w8io/026f985 40.80 ms ◑