tx · 2jEweJXuiYX5zdXrsxjPp6Y7ub6HcqHtev8tiaS7QgoR 3N7psESThHV5T7gjWF2DLjztWtrhTF6FR3b: -0.03700000 Waves 2023.05.27 12:13 [2596170] smart account 3N7psESThHV5T7gjWF2DLjztWtrhTF6FR3b > SELF 0.00000000 Waves
{ "type": 13, "id": "2jEweJXuiYX5zdXrsxjPp6Y7ub6HcqHtev8tiaS7QgoR", "fee": 3700000, "feeAssetId": null, "timestamp": 1685178829999, "version": 2, "chainId": 84, "sender": "3N7psESThHV5T7gjWF2DLjztWtrhTF6FR3b", "senderPublicKey": "AgUKubvVDHDimcoQ6a6GnnzKdymyp2NYJRnjDFhiyM4e", "proofs": [ "3MWqZ3AfmNiGEmDz9fkP1zAYAi7cHPHxc8ZYGQXZwwWptdZD3C9qLfgNnVqwcozxq1gfZ98FgRjCjeNgHVgKeHv5" ], "script": "base64:BgIdCAISBgoECAgICBIECgIIARIFCgMICAgSBAoCCAgKAA1rX2luaXRpYWxpemVkAg1rX2luaXRpYWxpemVkABRrX2Nvb3JkaW5hdG9yQWRkcmVzcwIUa19jb29yZGluYXRvckFkZHJlc3MAD2tfYWRtaW5fYWRkcmVzcwIPa19hZG1pbl9hZGRyZXNzAAhrX21hcmtldAIIa19tYXJrZXQBDGdldE1hcmtldEtleQIFX2Zyb20DX3RvCQCsAgIJAKwCAgkArAICCQCsAgIFCGtfbWFya2V0AgFfBQVfZnJvbQIBXwUDX3RvAQtjb29yZGluYXRvcgAJARN2YWx1ZU9yRXJyb3JNZXNzYWdlAgkApggBCQETdmFsdWVPckVycm9yTWVzc2FnZQIJAJ0IAgUEdGhpcwUUa19jb29yZGluYXRvckFkZHJlc3MCGENvb3JkaW5hdG9yIG5vdCBzZXQgU3dhcAIbQ29vcmRpbmF0b3IgYWRkcmVzcyBpbnZhbGlkAQxhZG1pbkFkZHJlc3MACQCmCAEJARN2YWx1ZU9yRXJyb3JNZXNzYWdlAgkAnQgCCQELY29vcmRpbmF0b3IABQ9rX2F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AgkArAICCQCsAgICB3N0YXR1c18JAKUIAQUEdGhpcwIBXwkA2AQBCAUCdHgCaWQHCQACAQIudW5hYmxlIHRvIHZlcmlmeTogYWRtaW4gbm90IHNldCBpbiBjb29yZGluYXRvcgkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAgFAnR4D3NlbmRlclB1YmxpY0tleVns/ug=", "height": 2596170, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: DdEJRFzxpRx4tA46mbGapGbrcLHV3GEs8wYpADiackLa Next: none Diff:
Old | New | Differences | |
---|---|---|---|
21 | 21 | func initialized () = valueOrElse(getBoolean(this, k_initialized), false) | |
22 | 22 | ||
23 | 23 | ||
24 | + | func assetName (_asset) = if ((_asset == "WAVES")) | |
25 | + | then "WAVES" | |
26 | + | else value(assetInfo(fromBase58String(_asset))).name | |
27 | + | ||
28 | + | ||
24 | 29 | func getMarket (_from,_to) = { | |
25 | 30 | let key = getMarketKey(_from, _to) | |
26 | - | let fromName = | |
27 | - | let toName = | |
31 | + | let fromName = assetName(_from) | |
32 | + | let toName = assetName(_to) | |
28 | 33 | let errorDesc = (((((((_from + " [") + fromName) + "] -> ") + _to) + " [") + toName) + "]") | |
29 | 34 | let addressStr = valueOrErrorMessage(getString(this, key), ("No market for swap: " + errorDesc)) | |
30 | 35 | valueOrErrorMessage(addressFromString(addressStr), ("Invalid market address for swap: " + errorDesc)) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let k_initialized = "k_initialized" | |
5 | 5 | ||
6 | 6 | let k_coordinatorAddress = "k_coordinatorAddress" | |
7 | 7 | ||
8 | 8 | let k_admin_address = "k_admin_address" | |
9 | 9 | ||
10 | 10 | let k_market = "k_market" | |
11 | 11 | ||
12 | 12 | func getMarketKey (_from,_to) = ((((k_market + "_") + _from) + "_") + _to) | |
13 | 13 | ||
14 | 14 | ||
15 | 15 | func coordinator () = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(this, k_coordinatorAddress), "Coordinator not set Swap")), "Coordinator address invalid") | |
16 | 16 | ||
17 | 17 | ||
18 | 18 | func adminAddress () = addressFromString(valueOrErrorMessage(getString(coordinator(), k_admin_address), "Admin address not set")) | |
19 | 19 | ||
20 | 20 | ||
21 | 21 | func initialized () = valueOrElse(getBoolean(this, k_initialized), false) | |
22 | 22 | ||
23 | 23 | ||
24 | + | func assetName (_asset) = if ((_asset == "WAVES")) | |
25 | + | then "WAVES" | |
26 | + | else value(assetInfo(fromBase58String(_asset))).name | |
27 | + | ||
28 | + | ||
24 | 29 | func getMarket (_from,_to) = { | |
25 | 30 | let key = getMarketKey(_from, _to) | |
26 | - | let fromName = | |
27 | - | let toName = | |
31 | + | let fromName = assetName(_from) | |
32 | + | let toName = assetName(_to) | |
28 | 33 | let errorDesc = (((((((_from + " [") + fromName) + "] -> ") + _to) + " [") + toName) + "]") | |
29 | 34 | let addressStr = valueOrErrorMessage(getString(this, key), ("No market for swap: " + errorDesc)) | |
30 | 35 | valueOrErrorMessage(addressFromString(addressStr), ("Invalid market address for swap: " + errorDesc)) | |
31 | 36 | } | |
32 | 37 | ||
33 | 38 | ||
34 | 39 | @Callable(i) | |
35 | 40 | func initialize (_coordinator,_fromAssets,_toAssets,_markets) = if (if (initialized()) | |
36 | 41 | then true | |
37 | 42 | else (i.caller != this)) | |
38 | 43 | then throw("Unable to initialize") | |
39 | 44 | else { | |
40 | 45 | let fromAssets = split(_fromAssets, ",") | |
41 | 46 | let toAssets = split(_toAssets, ",") | |
42 | 47 | let markets = split(_markets, ",") | |
43 | 48 | if (if (if ((size(fromAssets) != size(toAssets))) | |
44 | 49 | then true | |
45 | 50 | else (size(fromAssets) != size(markets))) | |
46 | 51 | then true | |
47 | 52 | else (size(fromAssets) > 5)) | |
48 | 53 | then throw("Unable to initialize: invalid assets / markets") | |
49 | 54 | else { | |
50 | 55 | func handle (_acc,_idx) = if ((_idx >= size(fromAssets))) | |
51 | 56 | then _acc | |
52 | 57 | else { | |
53 | 58 | let from = fromAssets[_idx] | |
54 | 59 | let to = toAssets[_idx] | |
55 | 60 | let market = markets[_idx] | |
56 | 61 | if (if (if ((from == "")) | |
57 | 62 | then true | |
58 | 63 | else (to == "")) | |
59 | 64 | then true | |
60 | 65 | else !(isDefined(addressFromString(market)))) | |
61 | 66 | then throw(("Invalid market at index: " + toString(_idx))) | |
62 | 67 | else (_acc ++ [StringEntry(getMarketKey(from, to), market)]) | |
63 | 68 | } | |
64 | 69 | ||
65 | 70 | let doAddAllMarkets = { | |
66 | 71 | let $l = [0, 1, 2, 3, 4] | |
67 | 72 | let $s = size($l) | |
68 | 73 | let $acc0 = nil | |
69 | 74 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
70 | 75 | then $a | |
71 | 76 | else handle($a, $l[$i]) | |
72 | 77 | ||
73 | 78 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
74 | 79 | then $a | |
75 | 80 | else throw("List size exceeds 5") | |
76 | 81 | ||
77 | 82 | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5) | |
78 | 83 | } | |
79 | 84 | ([StringEntry(k_coordinatorAddress, toString(addressFromStringValue(_coordinator))), BooleanEntry(k_initialized, true)] ++ doAddAllMarkets) | |
80 | 85 | } | |
81 | 86 | } | |
82 | 87 | ||
83 | 88 | ||
84 | 89 | ||
85 | 90 | @Callable(i) | |
86 | 91 | func swap (_to,_expected) = if (if (if (!(initialized())) | |
87 | 92 | then true | |
88 | 93 | else (size(i.payments) != 1)) | |
89 | 94 | then true | |
90 | 95 | else (0 > _expected)) | |
91 | 96 | then throw("Invalid swap params: payment count") | |
92 | 97 | else { | |
93 | 98 | let assetId = i.payments[0].assetId | |
94 | 99 | let from = if (isDefined(assetId)) | |
95 | 100 | then toBase58String(value(assetId)) | |
96 | 101 | else "WAVES" | |
97 | 102 | let market = getMarket(from, _to) | |
98 | 103 | let amountBeforeSwap = assetBalance(this, fromBase58String(_to)) | |
99 | 104 | if ((amountBeforeSwap == amountBeforeSwap)) | |
100 | 105 | then { | |
101 | 106 | let doSwap = invoke(market, "swap", [_to, _expected], i.payments) | |
102 | 107 | if ((doSwap == doSwap)) | |
103 | 108 | then { | |
104 | 109 | let amountAfterSwap = assetBalance(this, fromBase58String(_to)) | |
105 | 110 | if ((amountAfterSwap == amountAfterSwap)) | |
106 | 111 | then { | |
107 | 112 | let delta = (amountAfterSwap - amountBeforeSwap) | |
108 | 113 | if ((delta == delta)) | |
109 | 114 | then $Tuple2([ScriptTransfer(i.caller, delta, fromBase58String(_to))], delta) | |
110 | 115 | else throw("Strict value is not equal to itself.") | |
111 | 116 | } | |
112 | 117 | else throw("Strict value is not equal to itself.") | |
113 | 118 | } | |
114 | 119 | else throw("Strict value is not equal to itself.") | |
115 | 120 | } | |
116 | 121 | else throw("Strict value is not equal to itself.") | |
117 | 122 | } | |
118 | 123 | ||
119 | 124 | ||
120 | 125 | ||
121 | 126 | @Callable(i) | |
122 | 127 | func addMarket (_from,_to,_market) = if (if (if (if (if (if ((i.caller != adminAddress())) | |
123 | 128 | then (i.caller != this) | |
124 | 129 | else false) | |
125 | 130 | then true | |
126 | 131 | else !(initialized())) | |
127 | 132 | then true | |
128 | 133 | else (_from == "")) | |
129 | 134 | then true | |
130 | 135 | else (_to == "")) | |
131 | 136 | then true | |
132 | 137 | else !(isDefined(addressFromString(_market)))) | |
133 | 138 | then throw("Invalid addMarket params") | |
134 | 139 | else [StringEntry(getMarketKey(_from, _to), _market)] | |
135 | 140 | ||
136 | 141 | ||
137 | 142 | ||
138 | 143 | @Callable(i) | |
139 | 144 | func removeMarket (_from,_to) = if (if (if (if ((i.caller != adminAddress())) | |
140 | 145 | then true | |
141 | 146 | else !(initialized())) | |
142 | 147 | then true | |
143 | 148 | else (_from == "")) | |
144 | 149 | then true | |
145 | 150 | else (_to == "")) | |
146 | 151 | then throw("Invalid addMarket params") | |
147 | 152 | else [DeleteEntry(getMarketKey(_from, _to))] | |
148 | 153 | ||
149 | 154 | ||
150 | 155 | @Verifier(tx) | |
151 | 156 | func verify () = { | |
152 | 157 | let coordinatorStr = getString(this, k_coordinatorAddress) | |
153 | 158 | if (isDefined(coordinatorStr)) | |
154 | 159 | then { | |
155 | 160 | let admin = getString(addressFromStringValue(value(coordinatorStr)), k_admin_address) | |
156 | 161 | if (isDefined(admin)) | |
157 | 162 | then valueOrElse(getBoolean(addressFromStringValue(value(admin)), ((("status_" + toString(this)) + "_") + toBase58String(tx.id))), false) | |
158 | 163 | else throw("unable to verify: admin not set in coordinator") | |
159 | 164 | } | |
160 | 165 | else sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
161 | 166 | } | |
162 | 167 |
github/deemru/w8io/026f985 38.41 ms ◑