tx · E5mCvSeSZrZS7Giay7LM2G19PqQdGWpovMSdCzJcbVs8 3MvdzbvEZLHEE3EXHXxaRQjgpNqq28733ao: -0.01000000 Waves 2021.12.22 19:16 [1845693] smart account 3MvdzbvEZLHEE3EXHXxaRQjgpNqq28733ao > SELF 0.00000000 Waves
{ "type": 13, "id": "E5mCvSeSZrZS7Giay7LM2G19PqQdGWpovMSdCzJcbVs8", "fee": 1000000, "feeAssetId": null, "timestamp": 1640189804142, "version": 1, "sender": "3MvdzbvEZLHEE3EXHXxaRQjgpNqq28733ao", "senderPublicKey": "HQmnkZjA2Ehwb2iKXAadqRsrXsHGZChU6WfgmHRsMW8t", "proofs": [ "5nDH9ANhubfG29PS8arHifEC2vvULvDpHCcuyBPBH4VgdJqkypedJtbvfHaBUKZTJmFzmB77xQRSx1rEJekATEwq" ], "script": "base64:AAIFAAAAAAAAAAoIAhIGCgQICAEBAAAACAAAAAAJY29sbGVjdG9yCQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQmAAAAAQkBAAAAE3ZhbHVlT3JFcnJvck1lc3NhZ2UAAAACCQAEHQAAAAIFAAAABHRoaXMCAAAACWNvbGxlY3RvcgIAAAAAAgAAAAAAAAAABm9yYWNsZQkBAAAAE3ZhbHVlT3JFcnJvck1lc3NhZ2UAAAACCQAEJgAAAAEJAQAAABN2YWx1ZU9yRXJyb3JNZXNzYWdlAAAAAgkABB0AAAACBQAAAAR0aGlzAgAAAAZvcmFjbGUCAAAAAAIAAAAAAAAAAAVwb29scwkABLUAAAACCQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQdAAAAAgUAAAAGb3JhY2xlAgAAAAVwb29scwIAAAAAAgAAAAEsAQAAAApnZXRBc3NldElkAAAAAQAAAAVhc3NldAMJAAAAAAAAAgUAAAAFYXNzZXQCAAAABVdBVkVTBQAAAAR1bml0CQACWQAAAAEFAAAABWFzc2V0AQAAAApnZXRCYWxhbmNlAAAAAQAAAAdhc3NldElkBAA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1JlY2VpdmUFAAAAC21pblJlY2VpdmVkBQAAAAtlc3RSZWNlaXZlZAMDAwkAAAEAAAACCAUAAAAHJG1hdGNoMAAAAAJfMQIAAAADSW50CQAAAQAAAAIIBQAAAAckbWF0Y2gwAAAAAl8yAgAAAANJbnQHCQAAAQAAAAIFAAAAByRtYXRjaDACAAAACihJbnQsIEludCkHBAAAAAZiZWZvcmUIBQAAAAckbWF0Y2gwAAAAAl8xBAAAAAZpbmNvbWUIBQAAAAckbWF0Y2gwAAAAAl8yCQAFFAAAAAIFAAAABmJlZm9yZQUAAAAGaW5jb21lCQAAAgAAAAECAAAAAAQAAAANYmFsYW5jZUJlZm9yZQgFAAAACyR0MDI3MTYyOTIxAAAAAl8xBAAAAAhyZWNlaXZlZAgFAAAACyR0MDI3MTYyOTIxAAAAAl8yAwkAAGcAAAACAAAAAAAAAAAABQAAAAhyZWNlaXZlZAkAAAIAAAABAgAAAAAEAAAAA2ZlZQkBAAAACWRlZHVjdEZlZQAAAAEFAAAACHJlY2VpdmVkCQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMIBQAAAANpbnYAAAAGY2FsbGVyCQAAZQAAAAIFAAAACHJlY2VpdmVkBQAAAANmZWUFAAAAD2Fzc2V0UmVjZWl2ZWRJZAkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADBQAAAAljb2xsZWN0b3IFAAAAA2ZlZQUAAAAPYXNzZXRSZWNlaXZlZElkBQAAAANuaWwAAAAA0se4sQ==", "chainId": 84, "height": 1845693, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 28rFLZUpaFTfsrNinwV1sYCSHdfjkzRJbwFLBgUY5ps8 Next: FxjNe2pKqF72t9wPXdKqP31ovr2p7hjn4JqkJkMhYyBd Diff:
Old | New | Differences | |
---|---|---|---|
22 | 22 | } | |
23 | 23 | ||
24 | 24 | ||
25 | + | func deductFee (amount) = fraction(amount, 1, 1000) | |
26 | + | ||
27 | + | ||
28 | + | func deductFlatFee (amount) = fraction(amount, 1, 10000) | |
29 | + | ||
30 | + | ||
25 | 31 | func doSwap (pool,payment,assetReceived,minReceived,estReceived) = { | |
26 | 32 | let poolAddress = valueOrErrorMessage(addressFromString(pool), "") | |
27 | 33 | let assetReceivedId = getAssetId(assetReceived) | |
42 | 48 | let poolAssetIdB = getAssetId(poolAssetB) | |
43 | 49 | let versionMajor = valueOrErrorMessage(parseInt(split(valueOrErrorMessage(getString(poolAddress, "version"), ""), ".")[0]), "") | |
44 | 50 | let args = if ((versionMajor == 1)) | |
45 | - | then [minReceived] | |
51 | + | then [(minReceived + deductFee(minReceived))] | |
46 | 52 | else if ((versionMajor == 2)) | |
47 | 53 | then if ((0 >= estReceived)) | |
48 | 54 | then throw("") | |
49 | - | else [estReceived, minReceived] | |
55 | + | else [(estReceived + deductFlatFee(estReceived)), (minReceived + deductFlatFee(minReceived))] | |
50 | 56 | else throw("") | |
51 | 57 | invoke(poolAddress, "exchange", args, [payment]) | |
52 | 58 | } | |
70 | 76 | then inv.payments[0] | |
71 | 77 | else throw("") | |
72 | 78 | let assetReceivedId = getAssetId(assetToReceive) | |
73 | - | func deductFee (amount) = fraction(amount, 1, 1000) | |
74 | - | ||
75 | 79 | if ((0 >= minReceived)) | |
76 | 80 | then throw("") | |
77 | 81 | else { | |
78 | - | let $ | |
82 | + | let $t027162921 = match doSwap(pool, pmt, assetToReceive, minReceived, estReceived) { | |
79 | 83 | case _ => | |
80 | 84 | if (if (if ($isInstanceOf($match0._1, "Int")) | |
81 | 85 | then $isInstanceOf($match0._2, "Int") | |
89 | 93 | } | |
90 | 94 | else throw("") | |
91 | 95 | } | |
92 | - | let balanceBefore = $ | |
93 | - | let received = $ | |
96 | + | let balanceBefore = $t027162921._1 | |
97 | + | let received = $t027162921._2 | |
94 | 98 | if ((0 >= received)) | |
95 | 99 | then throw("") | |
96 | 100 | else { |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let collector = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(this, "collector"), "")), "") | |
5 | 5 | ||
6 | 6 | let oracle = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(this, "oracle"), "")), "") | |
7 | 7 | ||
8 | 8 | let pools = split(valueOrErrorMessage(getString(oracle, "pools"), ""), ",") | |
9 | 9 | ||
10 | 10 | func getAssetId (asset) = if ((asset == "WAVES")) | |
11 | 11 | then unit | |
12 | 12 | else fromBase58String(asset) | |
13 | 13 | ||
14 | 14 | ||
15 | 15 | func getBalance (assetId) = match assetId { | |
16 | 16 | case asset: ByteVector => | |
17 | 17 | assetBalance(this, asset) | |
18 | 18 | case waves: Unit => | |
19 | 19 | wavesBalance(this).available | |
20 | 20 | case _ => | |
21 | 21 | throw("Match error") | |
22 | 22 | } | |
23 | 23 | ||
24 | 24 | ||
25 | + | func deductFee (amount) = fraction(amount, 1, 1000) | |
26 | + | ||
27 | + | ||
28 | + | func deductFlatFee (amount) = fraction(amount, 1, 10000) | |
29 | + | ||
30 | + | ||
25 | 31 | func doSwap (pool,payment,assetReceived,minReceived,estReceived) = { | |
26 | 32 | let poolAddress = valueOrErrorMessage(addressFromString(pool), "") | |
27 | 33 | let assetReceivedId = getAssetId(assetReceived) | |
28 | 34 | if ((0 >= minReceived)) | |
29 | 35 | then throw("") | |
30 | 36 | else if ((0 > estReceived)) | |
31 | 37 | then throw("") | |
32 | 38 | else { | |
33 | 39 | let balanceBefore = getBalance(assetReceivedId) | |
34 | 40 | if ((balanceBefore == balanceBefore)) | |
35 | 41 | then { | |
36 | 42 | let result = if (!(containsElement(pools, pool))) | |
37 | 43 | then throw("") | |
38 | 44 | else { | |
39 | 45 | let poolAssetA = valueOrErrorMessage(getString(poolAddress, "A_asset_id"), "") | |
40 | 46 | let poolAssetB = valueOrErrorMessage(getString(poolAddress, "B_asset_id"), "") | |
41 | 47 | let poolAssetIdA = getAssetId(poolAssetA) | |
42 | 48 | let poolAssetIdB = getAssetId(poolAssetB) | |
43 | 49 | let versionMajor = valueOrErrorMessage(parseInt(split(valueOrErrorMessage(getString(poolAddress, "version"), ""), ".")[0]), "") | |
44 | 50 | let args = if ((versionMajor == 1)) | |
45 | - | then [minReceived] | |
51 | + | then [(minReceived + deductFee(minReceived))] | |
46 | 52 | else if ((versionMajor == 2)) | |
47 | 53 | then if ((0 >= estReceived)) | |
48 | 54 | then throw("") | |
49 | - | else [estReceived, minReceived] | |
55 | + | else [(estReceived + deductFlatFee(estReceived)), (minReceived + deductFlatFee(minReceived))] | |
50 | 56 | else throw("") | |
51 | 57 | invoke(poolAddress, "exchange", args, [payment]) | |
52 | 58 | } | |
53 | 59 | if ((result == result)) | |
54 | 60 | then { | |
55 | 61 | let received = (getBalance(assetReceivedId) - balanceBefore) | |
56 | 62 | if ((received == received)) | |
57 | 63 | then $Tuple2(balanceBefore, received) | |
58 | 64 | else throw("Strict value is not equal to itself.") | |
59 | 65 | } | |
60 | 66 | else throw("Strict value is not equal to itself.") | |
61 | 67 | } | |
62 | 68 | else throw("Strict value is not equal to itself.") | |
63 | 69 | } | |
64 | 70 | } | |
65 | 71 | ||
66 | 72 | ||
67 | 73 | @Callable(inv) | |
68 | 74 | func swap (pool,assetToReceive,minReceived,estReceived) = { | |
69 | 75 | let pmt = if ((size(inv.payments) > 0)) | |
70 | 76 | then inv.payments[0] | |
71 | 77 | else throw("") | |
72 | 78 | let assetReceivedId = getAssetId(assetToReceive) | |
73 | - | func deductFee (amount) = fraction(amount, 1, 1000) | |
74 | - | ||
75 | 79 | if ((0 >= minReceived)) | |
76 | 80 | then throw("") | |
77 | 81 | else { | |
78 | - | let $ | |
82 | + | let $t027162921 = match doSwap(pool, pmt, assetToReceive, minReceived, estReceived) { | |
79 | 83 | case _ => | |
80 | 84 | if (if (if ($isInstanceOf($match0._1, "Int")) | |
81 | 85 | then $isInstanceOf($match0._2, "Int") | |
82 | 86 | else false) | |
83 | 87 | then $isInstanceOf($match0, "(Int, Int)") | |
84 | 88 | else false) | |
85 | 89 | then { | |
86 | 90 | let before = $match0._1 | |
87 | 91 | let income = $match0._2 | |
88 | 92 | $Tuple2(before, income) | |
89 | 93 | } | |
90 | 94 | else throw("") | |
91 | 95 | } | |
92 | - | let balanceBefore = $ | |
93 | - | let received = $ | |
96 | + | let balanceBefore = $t027162921._1 | |
97 | + | let received = $t027162921._2 | |
94 | 98 | if ((0 >= received)) | |
95 | 99 | then throw("") | |
96 | 100 | else { | |
97 | 101 | let fee = deductFee(received) | |
98 | 102 | [ScriptTransfer(inv.caller, (received - fee), assetReceivedId), ScriptTransfer(collector, fee, assetReceivedId)] | |
99 | 103 | } | |
100 | 104 | } | |
101 | 105 | } | |
102 | 106 | ||
103 | 107 |
github/deemru/w8io/169f3d6 58.30 ms ◑