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