tx · 9fj3ZmTGFxyvvQvRMp6zCJbStp2HExHRHauZGsuUG2MT 3MvdzbvEZLHEE3EXHXxaRQjgpNqq28733ao: -0.01000000 Waves 2021.12.22 16:18 [1845520] smart account 3MvdzbvEZLHEE3EXHXxaRQjgpNqq28733ao > SELF 0.00000000 Waves
{ "type": 13, "id": "9fj3ZmTGFxyvvQvRMp6zCJbStp2HExHRHauZGsuUG2MT", "fee": 1000000, "feeAssetId": null, "timestamp": 1640179161405, "version": 1, "sender": "3MvdzbvEZLHEE3EXHXxaRQjgpNqq28733ao", "senderPublicKey": "HQmnkZjA2Ehwb2iKXAadqRsrXsHGZChU6WfgmHRsMW8t", "proofs": [ "3BeUFzsFrumUc7ok7eZG6eZP2qqe2HuqcEph8L4LxbzqqA3UPTCRoULr5ofymyVrJJ1fwpeLUdYE2uvS34kpK2P3" ], "script": "base64:AAIFAAAAAAAAAAoIAhIGCgQICAEBAAAABwAAAAAJY29sbGVjdG9yCQEAAAAHQWRkcmVzcwAAAAEBAAAAAAAAAAAGb3JhY2xlCQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQmAAAAAQkBAAAAE3ZhbHVlT3JFcnJvck1lc3NhZ2UAAAACCQAEHQAAAAIFAAAABHRoaXMCAAAABm9yYWNsZQIAAAAAAgAAAAAAAAAABXBvb2xzCQAEtQAAAAIJAQAAABN2YWx1ZU9yRXJyb3JNZXNzYWdlAAAAAgkABB0AAAACBQAAAAZvcmFjbGUCAAAABXBvb2xzAgAAAAACAAAAASwBAAAACmdldEFzc2V0SWQAAAABAAAABWFzc2V0AwkAAAAAAAACBQAAAAVhc3NldAIAAAAFV0FWRVMFAAAABHVuaXQJAAJZAAAAAQUAAAAFYXNzZXQBAAAACmdldEJhbGFuY2UAAAABAAAAB2Fzc2V0SWQEAAAAByRtYXRjaDAFAAAAB2Fzc2V0SWQDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAACkJ5dGVWZWN0b3IEAAAABWFzc2V0BQAAAAckbW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original | compacted Prev: none Next: hJc2yCLUiTiqXXmM6Yfdxcx3mkVCU52bBFs721pry4S Full:
Old | New | Differences | |
---|---|---|---|
1 | - | # no script | |
1 | + | {-# STDLIB_VERSION 5 #-} | |
2 | + | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | + | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let collector = Address(base58'') | |
5 | + | ||
6 | + | let oracle = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(this, "oracle"), "")), "") | |
7 | + | ||
8 | + | let pools = split(valueOrErrorMessage(getString(oracle, "pools"), ""), ",") | |
9 | + | ||
10 | + | func getAssetId (asset) = if ((asset == "WAVES")) | |
11 | + | then unit | |
12 | + | else fromBase58String(asset) | |
13 | + | ||
14 | + | ||
15 | + | func getBalance (assetId) = match assetId { | |
16 | + | case asset: ByteVector => | |
17 | + | assetBalance(this, asset) | |
18 | + | case waves: Unit => | |
19 | + | wavesBalance(this).available | |
20 | + | case _ => | |
21 | + | throw("Match error") | |
22 | + | } | |
23 | + | ||
24 | + | ||
25 | + | let feeAssets = { | |
26 | + | let assets = split(valueOrErrorMessage(getString(this, "fee-assets"), ""), ",") | |
27 | + | func toAssetIds (acc,assetStr) = (acc :+ getAssetId(assetStr)) | |
28 | + | ||
29 | + | let $l = assets | |
30 | + | let $s = size($l) | |
31 | + | let $acc0 = nil | |
32 | + | func 1 ($a,$i) = if (($i >= $s)) | |
33 | + | then $a | |
34 | + | else toAssetIds($a, $l[$i]) | |
35 | + | ||
36 | + | func 2 ($a,$i) = if (($i >= $s)) | |
37 | + | then $a | |
38 | + | else throw("List size exceeds 10") | |
39 | + | ||
40 | + | 2(1(1(1(1(1(1(1(1(1(1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) | |
41 | + | } | |
42 | + | ||
43 | + | func doSwap (pool,payment,assetReceived,minReceived,estReceived) = { | |
44 | + | let poolAddress = valueOrErrorMessage(addressFromString(pool), "") | |
45 | + | let assetReceivedId = getAssetId(assetReceived) | |
46 | + | if ((0 >= minReceived)) | |
47 | + | then throw("") | |
48 | + | else if ((0 > estReceived)) | |
49 | + | then throw("") | |
50 | + | else { | |
51 | + | let balanceBefore = getBalance(assetReceivedId) | |
52 | + | if ((balanceBefore == balanceBefore)) | |
53 | + | then { | |
54 | + | let result = if (!(containsElement(pools, pool))) | |
55 | + | then throw("") | |
56 | + | else { | |
57 | + | let poolAssetA = valueOrErrorMessage(getString(poolAddress, "A_asset_id"), "") | |
58 | + | let poolAssetB = valueOrErrorMessage(getString(poolAddress, "B_asset_id"), "") | |
59 | + | let poolAssetIdA = getAssetId(poolAssetA) | |
60 | + | let poolAssetIdB = getAssetId(poolAssetB) | |
61 | + | let versionMajor = valueOrErrorMessage(parseInt(split(valueOrErrorMessage(getString(poolAddress, "version"), ""), ".")[0]), "") | |
62 | + | let args = if ((versionMajor == 1)) | |
63 | + | then [minReceived] | |
64 | + | else if ((versionMajor == 2)) | |
65 | + | then if ((0 >= estReceived)) | |
66 | + | then throw("") | |
67 | + | else [estReceived, minReceived] | |
68 | + | else throw("") | |
69 | + | invoke(poolAddress, "exchange", args, [payment]) | |
70 | + | } | |
71 | + | if ((result == result)) | |
72 | + | then { | |
73 | + | let received = (getBalance(assetReceivedId) - balanceBefore) | |
74 | + | if ((received == received)) | |
75 | + | then $Tuple2(balanceBefore, received) | |
76 | + | else throw("Strict value is not equal to itself.") | |
77 | + | } | |
78 | + | else throw("Strict value is not equal to itself.") | |
79 | + | } | |
80 | + | else throw("Strict value is not equal to itself.") | |
81 | + | } | |
82 | + | } | |
83 | + | ||
84 | + | ||
85 | + | @Callable(inv) | |
86 | + | func swap (pool,assetToReceive,minReceived,estReceived) = { | |
87 | + | let pmt = if ((size(inv.payments) > 0)) | |
88 | + | then inv.payments[0] | |
89 | + | else throw("") | |
90 | + | let assetReceivedId = getAssetId(assetToReceive) | |
91 | + | let isFeeFromPayment = { | |
92 | + | let indexAssetFrom = valueOrElse(indexOf(feeAssets, pmt.assetId), -1) | |
93 | + | let indexAssetTo = valueOrElse(indexOf(feeAssets, assetReceivedId), -1) | |
94 | + | (indexAssetTo > indexAssetFrom) | |
95 | + | } | |
96 | + | func deductFee (amount) = fraction(amount, 1, 1000) | |
97 | + | ||
98 | + | if ((0 >= minReceived)) | |
99 | + | then throw("") | |
100 | + | else { | |
101 | + | let from = if (isFeeFromPayment) | |
102 | + | then AttachedPayment(pmt.assetId, deductFee(pmt.amount)) | |
103 | + | else pmt | |
104 | + | let $t031513356 = match doSwap(pool, pmt, assetToReceive, minReceived, estReceived) { | |
105 | + | case _ => | |
106 | + | if (if (if ($isInstanceOf($match0._1, "Int")) | |
107 | + | then $isInstanceOf($match0._2, "Int") | |
108 | + | else false) | |
109 | + | then $isInstanceOf($match0, "(Int, Int)") | |
110 | + | else false) | |
111 | + | then { | |
112 | + | let before = $match0._1 | |
113 | + | let income = $match0._2 | |
114 | + | $Tuple2(before, income) | |
115 | + | } | |
116 | + | else throw("") | |
117 | + | } | |
118 | + | let balanceBefore = $t031513356._1 | |
119 | + | let received = $t031513356._2 | |
120 | + | if ((0 >= received)) | |
121 | + | then throw("") | |
122 | + | else if (isFeeFromPayment) | |
123 | + | then [ScriptTransfer(inv.caller, received, assetReceivedId), ScriptTransfer(collector, (pmt.amount - from.amount), from.assetId)] | |
124 | + | else { | |
125 | + | let fee = deductFee(received) | |
126 | + | [ScriptTransfer(inv.caller, (received - fee), assetReceivedId), ScriptTransfer(collector, fee, assetReceivedId)] | |
127 | + | } | |
128 | + | } | |
129 | + | } | |
130 | + | ||
131 | + |
github/deemru/w8io/169f3d6 26.89 ms ◑