tx · iBsmVkuxC6T9pSjW4Q18jLYxsNPEGyPT5vnasyVTxT9 3MtbzcFZjxhPwaM1HoYr7sSSGDk7bjBsRNN: -0.03700000 Waves 2023.05.15 15:51 [2579098] smart account 3MtbzcFZjxhPwaM1HoYr7sSSGDk7bjBsRNN > SELF 0.00000000 Waves
{ "type": 13, "id": "iBsmVkuxC6T9pSjW4Q18jLYxsNPEGyPT5vnasyVTxT9", "fee": 3700000, "feeAssetId": null, "timestamp": 1684155155360, "version": 2, "chainId": 84, "sender": "3MtbzcFZjxhPwaM1HoYr7sSSGDk7bjBsRNN", "senderPublicKey": "269hMEydX4R6CjK9TRgFMec4TtjsckD91Vxo2pzLVzv4", "proofs": [ "5UoLaZyMAyxKb1PTB5VdaPztGQGYg1np18R5fYn5ncGnG1UTBANZpGJJHns3ZM3brFHuKZP8dUZZNnKkRRZZawN5" ], "script": "base64:BgIlCAISBQoDCAgIEgASABIECgIICBIECgIIARIAEgMKAQgSAwoBCBsAB2tfZnVuZHMCB2tfZnVuZHMAF2tfYXNzZXRfbWFuYWdlcl9hZGRyZXNzAhdrX2Fzc2V0X21hbmFnZXJfYWRkcmVzcwAUa19jb29yZGluYXRvckFkZHJlc3MCFGtfY29vcmRpbmF0b3JBZGRyZXNzABBrX29yZGVyc19hZGRyZXNzAhBrX29yZGVyc19hZGRyZXNzAA9rX3ZhdWx0X2FkZHJlc3MCD2tfdmF1bHRfYWRkcmVzcwAFa19hbW0CBWtfYW1tAA9rX2FkbWluX2FkZHJlc3MCD2tfYWRtaW5fYWRkcmVzcwARa19zdGFraW5nX2FkZHJlc3MCEWtfc3Rha2luZ19hZGRyZXNzAA5rX3Nwb3RfYWRkcmVzcwIOa19zcG90X2FkZHJlc3MAB2tfdmF1bHQCB2tfdmF1bHQADWtfaW5pdGlhbGl6ZWQCDWtfaW5pdGlhbGl6ZWQACGtfcGF1c2VkAghrX3BhdXNlZAEOdG9Db21wb3NpdGVLZXkCBF9rZXkIX2FkZHJlc3MJAKwCAg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ApAMBCQEJYmFsYW5jZU9mAQUIX2Fzc2V0SWQCASwJAKQDAQkAZAIJAQliYWxhbmNlT2YBBQhfYXNzZXRJZAUGcHJvZml0AgEsCQCkAwEFBnByb2ZpdAkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgECdHgBBnZlcmlmeQAEDmNvb3JkaW5hdG9yU3RyCQCdCAIFBHRoaXMFFGtfY29vcmRpbmF0b3JBZGRyZXNzAwkBCWlzRGVmaW5lZAEFDmNvb3JkaW5hdG9yU3RyBAVhZG1pbgkAnQgCCQERQGV4dHJOYXRpdmUoMTA2MikBCQEFdmFsdWUBBQ5jb29yZGluYXRvclN0cgUPa19hZG1pbl9hZGRyZXNzAwkBCWlzRGVmaW5lZAEFBWFkbWluCQELdmFsdWVPckVsc2UCCQCbCAIJARFAZXh0ck5hdGl2ZSgxMDYyKQEJAQV2YWx1ZQEFBWFkbWluCQCsAgIJAKwCAgkArAICAgdzdGF0dXNfCQClCAEFBHRoaXMCAV8JANgEAQgFAnR4AmlkBwkAAgECLnVuYWJsZSB0byB2ZXJpZnk6IGFkbWluIG5vdCBzZXQgaW4gY29vcmRpbmF0b3IJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAAIBQJ0eA9zZW5kZXJQdWJsaWNLZXnCyePe", "height": 2579098, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: GKpUL4v1hktsbMJje7x7Tb5r6xuAMvaDANtsHx2PPx3A Next: An4pt343oh4z2dwrLkH8FtgWRGYUqbyxeAp845jnGHDM Diff:
Old | New | Differences | |
---|---|---|---|
16 | 16 | let k_admin_address = "k_admin_address" | |
17 | 17 | ||
18 | 18 | let k_staking_address = "k_staking_address" | |
19 | + | ||
20 | + | let k_spot_address = "k_spot_address" | |
21 | + | ||
22 | + | let k_vault = "k_vault" | |
19 | 23 | ||
20 | 24 | let k_initialized = "k_initialized" | |
21 | 25 | ||
42 | 46 | func stakingAddress () = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(coordinator(), k_staking_address), "Staking address not set")), "Staking address invalid") | |
43 | 47 | ||
44 | 48 | ||
49 | + | func spotAddress () = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(coordinator(), k_spot_address), "Spot address not set")), "Spot address invalid") | |
50 | + | ||
51 | + | ||
45 | 52 | func initialized () = valueOrElse(getBoolean(this, k_initialized), false) | |
46 | 53 | ||
47 | 54 | ||
49 | 56 | ||
50 | 57 | ||
51 | 58 | func assetManagerAddress (_assetId) = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(this, toCompositeKey(k_asset_manager_address, _assetId)), ("No asset manager for token " + _assetId))), ("Invalid asset manager address for token " + _assetId)) | |
59 | + | ||
60 | + | ||
61 | + | func isSpotVault (_address) = { | |
62 | + | let spot = spotAddress() | |
63 | + | valueOrElse(getBoolean(spot, toCompositeKey(k_vault, _address)), false) | |
64 | + | } | |
52 | 65 | ||
53 | 66 | ||
54 | 67 | func isWhitelist (_address) = if (if ((_address == toString(stakingAddress()))) | |
59 | 72 | ||
60 | 73 | ||
61 | 74 | func updateFunds (_assetId,_value) = [IntegerEntry(toCompositeKey(k_funds, _assetId), _value)] | |
75 | + | ||
76 | + | ||
77 | + | func strAssetId (_asset) = if (isDefined(_asset)) | |
78 | + | then toBase58String(value(_asset)) | |
79 | + | else "WAVES" | |
62 | 80 | ||
63 | 81 | ||
64 | 82 | @Callable(i) | |
111 | 129 | if ((unstake == unstake)) | |
112 | 130 | then { | |
113 | 131 | let currentAssetBalance = (balanceOf(_assetId) - _amount) | |
114 | - | (updateFunds(_assetId, currentAssetBalance) ++ [ScriptTransfer(i.caller, _amount, fromBase58String(_assetId))]) | |
132 | + | (updateFunds(_assetId, currentAssetBalance) ++ [ScriptTransfer(i.caller, _amount, if ((_assetId == "WAVES")) | |
133 | + | then unit | |
134 | + | else fromBase58String(_assetId))]) | |
115 | 135 | } | |
116 | 136 | else throw("Strict value is not equal to itself.") | |
117 | 137 | } | |
121 | 141 | @Callable(i) | |
122 | 142 | func deposit () = { | |
123 | 143 | let _amount = i.payments[0].amount | |
124 | - | let _assetId = | |
144 | + | let _assetId = strAssetId(i.payments[0].assetId) | |
125 | 145 | if (if (if (if (!(initialized())) | |
126 | 146 | then true | |
127 | 147 | else if (!(isWhitelist(toString(i.caller)))) | |
160 | 180 | case _ => | |
161 | 181 | throw("Invalid claimProfit result type") | |
162 | 182 | } | |
163 | - | $Tuple2([ScriptTransfer(i.caller, profit, fromBase58String(_assetId))], profit) | |
183 | + | $Tuple2([ScriptTransfer(i.caller, profit, if ((_assetId == "WAVES")) | |
184 | + | then unit | |
185 | + | else fromBase58String(_assetId))], profit) | |
164 | 186 | } | |
165 | 187 | else throw("Strict value is not equal to itself.") | |
166 | 188 | } | |
186 | 208 | } | |
187 | 209 | ||
188 | 210 | ||
189 | - | ||
190 | - | @Callable(i) | |
191 | - | func migrate (_assetId) = { | |
192 | - | let _amount = balanceOf(_assetId) | |
193 | - | if (if (if (!(initialized())) | |
194 | - | then true | |
195 | - | else (i.caller != adminAddress())) | |
196 | - | then true | |
197 | - | else !(paused())) | |
198 | - | then throw("Invalid migrate params (manager)") | |
199 | - | else { | |
200 | - | let unstake = invoke(valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(this, "k_vires_address"), "No legacy vires address")), "Invalid legacy vires address"), "withdraw", [_assetId, _amount], nil) | |
201 | - | if ((unstake == unstake)) | |
202 | - | then { | |
203 | - | let stake = invoke(assetManagerAddress(_assetId), "deposit", nil, [AttachedPayment(fromBase58String(_assetId), _amount)]) | |
204 | - | if ((stake == stake)) | |
205 | - | then [DeleteEntry("k_vires_address"), DeleteEntry("k_vires_vault")] | |
206 | - | else throw("Strict value is not equal to itself.") | |
207 | - | } | |
208 | - | else throw("Strict value is not equal to itself.") | |
209 | - | } | |
210 | - | } | |
211 | - | ||
212 | - | ||
213 | 211 | @Verifier(tx) | |
214 | 212 | func verify () = { | |
215 | 213 | let coordinatorStr = getString(this, k_coordinatorAddress) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let k_funds = "k_funds" | |
5 | 5 | ||
6 | 6 | let k_asset_manager_address = "k_asset_manager_address" | |
7 | 7 | ||
8 | 8 | let k_coordinatorAddress = "k_coordinatorAddress" | |
9 | 9 | ||
10 | 10 | let k_orders_address = "k_orders_address" | |
11 | 11 | ||
12 | 12 | let k_vault_address = "k_vault_address" | |
13 | 13 | ||
14 | 14 | let k_amm = "k_amm" | |
15 | 15 | ||
16 | 16 | let k_admin_address = "k_admin_address" | |
17 | 17 | ||
18 | 18 | let k_staking_address = "k_staking_address" | |
19 | + | ||
20 | + | let k_spot_address = "k_spot_address" | |
21 | + | ||
22 | + | let k_vault = "k_vault" | |
19 | 23 | ||
20 | 24 | let k_initialized = "k_initialized" | |
21 | 25 | ||
22 | 26 | let k_paused = "k_paused" | |
23 | 27 | ||
24 | 28 | func toCompositeKey (_key,_address) = ((_key + "_") + _address) | |
25 | 29 | ||
26 | 30 | ||
27 | 31 | func balanceOf (_assetId) = valueOrElse(getInteger(this, toCompositeKey(k_funds, _assetId)), 0) | |
28 | 32 | ||
29 | 33 | ||
30 | 34 | func coordinator () = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(this, k_coordinatorAddress), "Coordinator not set Manager")), "Coordinator address invalid") | |
31 | 35 | ||
32 | 36 | ||
33 | 37 | func vaultAddress () = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(coordinator(), k_vault_address), "Vault address not set")), "Vault address invalid") | |
34 | 38 | ||
35 | 39 | ||
36 | 40 | func ordersAddress () = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(coordinator(), k_orders_address), "Orders address not set")), "Orders address invalid") | |
37 | 41 | ||
38 | 42 | ||
39 | 43 | func adminAddress () = addressFromString(valueOrErrorMessage(getString(coordinator(), k_admin_address), "Admin address not set")) | |
40 | 44 | ||
41 | 45 | ||
42 | 46 | func stakingAddress () = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(coordinator(), k_staking_address), "Staking address not set")), "Staking address invalid") | |
43 | 47 | ||
44 | 48 | ||
49 | + | func spotAddress () = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(coordinator(), k_spot_address), "Spot address not set")), "Spot address invalid") | |
50 | + | ||
51 | + | ||
45 | 52 | func initialized () = valueOrElse(getBoolean(this, k_initialized), false) | |
46 | 53 | ||
47 | 54 | ||
48 | 55 | func paused () = valueOrElse(getBoolean(this, k_paused), false) | |
49 | 56 | ||
50 | 57 | ||
51 | 58 | func assetManagerAddress (_assetId) = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(this, toCompositeKey(k_asset_manager_address, _assetId)), ("No asset manager for token " + _assetId))), ("Invalid asset manager address for token " + _assetId)) | |
59 | + | ||
60 | + | ||
61 | + | func isSpotVault (_address) = { | |
62 | + | let spot = spotAddress() | |
63 | + | valueOrElse(getBoolean(spot, toCompositeKey(k_vault, _address)), false) | |
64 | + | } | |
52 | 65 | ||
53 | 66 | ||
54 | 67 | func isWhitelist (_address) = if (if ((_address == toString(stakingAddress()))) | |
55 | 68 | then true | |
56 | 69 | else (_address == toString(vaultAddress()))) | |
57 | 70 | then true | |
58 | 71 | else (_address == toString(ordersAddress())) | |
59 | 72 | ||
60 | 73 | ||
61 | 74 | func updateFunds (_assetId,_value) = [IntegerEntry(toCompositeKey(k_funds, _assetId), _value)] | |
75 | + | ||
76 | + | ||
77 | + | func strAssetId (_asset) = if (isDefined(_asset)) | |
78 | + | then toBase58String(value(_asset)) | |
79 | + | else "WAVES" | |
62 | 80 | ||
63 | 81 | ||
64 | 82 | @Callable(i) | |
65 | 83 | func initialize (_coordinator,_quoteAssetId,_quoteAssetManager) = if (if (initialized()) | |
66 | 84 | then true | |
67 | 85 | else (i.caller != this)) | |
68 | 86 | then throw("Unable to initialize") | |
69 | 87 | else [StringEntry(k_coordinatorAddress, toString(addressFromStringValue(_coordinator))), StringEntry(toCompositeKey(k_asset_manager_address, _quoteAssetId), toString(addressFromStringValue(_quoteAssetManager))), BooleanEntry(k_initialized, true)] | |
70 | 88 | ||
71 | 89 | ||
72 | 90 | ||
73 | 91 | @Callable(i) | |
74 | 92 | func unpause () = if ((i.caller != adminAddress())) | |
75 | 93 | then throw("Invalid unpause params") | |
76 | 94 | else [BooleanEntry(k_paused, false)] | |
77 | 95 | ||
78 | 96 | ||
79 | 97 | ||
80 | 98 | @Callable(i) | |
81 | 99 | func pause () = if ((i.caller != adminAddress())) | |
82 | 100 | then throw("Invalid pause params") | |
83 | 101 | else [BooleanEntry(k_paused, true)] | |
84 | 102 | ||
85 | 103 | ||
86 | 104 | ||
87 | 105 | @Callable(i) | |
88 | 106 | func addAssetManager (_assetId,_vaultAddress) = if (if (if (!(initialized())) | |
89 | 107 | then true | |
90 | 108 | else (i.caller != adminAddress())) | |
91 | 109 | then true | |
92 | 110 | else if (isDefined(getString(toCompositeKey(k_asset_manager_address, _assetId)))) | |
93 | 111 | then (balanceOf(_assetId) > 0) | |
94 | 112 | else false) | |
95 | 113 | then throw("Invalid addTokenVault params") | |
96 | 114 | else [StringEntry(toCompositeKey(k_asset_manager_address, _assetId), toString(addressFromStringValue(_vaultAddress)))] | |
97 | 115 | ||
98 | 116 | ||
99 | 117 | ||
100 | 118 | @Callable(i) | |
101 | 119 | func withdraw (_assetId,_amount) = if (if (if (if (!(isWhitelist(toString(i.caller)))) | |
102 | 120 | then true | |
103 | 121 | else !(initialized())) | |
104 | 122 | then true | |
105 | 123 | else paused()) | |
106 | 124 | then true | |
107 | 125 | else (_amount > balanceOf(_assetId))) | |
108 | 126 | then throw(((("Invalid withdraw params (manager) " + toString(_amount)) + " > ") + toString(balanceOf(_assetId)))) | |
109 | 127 | else { | |
110 | 128 | let unstake = invoke(assetManagerAddress(_assetId), "withdraw", [_assetId, _amount], nil) | |
111 | 129 | if ((unstake == unstake)) | |
112 | 130 | then { | |
113 | 131 | let currentAssetBalance = (balanceOf(_assetId) - _amount) | |
114 | - | (updateFunds(_assetId, currentAssetBalance) ++ [ScriptTransfer(i.caller, _amount, fromBase58String(_assetId))]) | |
132 | + | (updateFunds(_assetId, currentAssetBalance) ++ [ScriptTransfer(i.caller, _amount, if ((_assetId == "WAVES")) | |
133 | + | then unit | |
134 | + | else fromBase58String(_assetId))]) | |
115 | 135 | } | |
116 | 136 | else throw("Strict value is not equal to itself.") | |
117 | 137 | } | |
118 | 138 | ||
119 | 139 | ||
120 | 140 | ||
121 | 141 | @Callable(i) | |
122 | 142 | func deposit () = { | |
123 | 143 | let _amount = i.payments[0].amount | |
124 | - | let _assetId = | |
144 | + | let _assetId = strAssetId(i.payments[0].assetId) | |
125 | 145 | if (if (if (if (!(initialized())) | |
126 | 146 | then true | |
127 | 147 | else if (!(isWhitelist(toString(i.caller)))) | |
128 | 148 | then (i.caller != adminAddress()) | |
129 | 149 | else false) | |
130 | 150 | then true | |
131 | 151 | else paused()) | |
132 | 152 | then true | |
133 | 153 | else (size(i.payments) != 1)) | |
134 | 154 | then throw("Invalid deposit params (manager)") | |
135 | 155 | else { | |
136 | 156 | let stake = invoke(assetManagerAddress(_assetId), "deposit", nil, [AttachedPayment(i.payments[0].assetId, _amount)]) | |
137 | 157 | if ((stake == stake)) | |
138 | 158 | then { | |
139 | 159 | let currentAssetBalance = (balanceOf(_assetId) + _amount) | |
140 | 160 | updateFunds(_assetId, currentAssetBalance) | |
141 | 161 | } | |
142 | 162 | else throw("Strict value is not equal to itself.") | |
143 | 163 | } | |
144 | 164 | } | |
145 | 165 | ||
146 | 166 | ||
147 | 167 | ||
148 | 168 | @Callable(i) | |
149 | 169 | func claimProfit (_assetId) = if (if (!(initialized())) | |
150 | 170 | then true | |
151 | 171 | else (i.caller != vaultAddress())) | |
152 | 172 | then throw("Invalid claimProfit params (manager)") | |
153 | 173 | else { | |
154 | 174 | let doClaimProfitResult = invoke(assetManagerAddress(_assetId), "claimProfit", [_assetId], nil) | |
155 | 175 | if ((doClaimProfitResult == doClaimProfitResult)) | |
156 | 176 | then { | |
157 | 177 | let profit = match doClaimProfitResult { | |
158 | 178 | case t: Int => | |
159 | 179 | t | |
160 | 180 | case _ => | |
161 | 181 | throw("Invalid claimProfit result type") | |
162 | 182 | } | |
163 | - | $Tuple2([ScriptTransfer(i.caller, profit, fromBase58String(_assetId))], profit) | |
183 | + | $Tuple2([ScriptTransfer(i.caller, profit, if ((_assetId == "WAVES")) | |
184 | + | then unit | |
185 | + | else fromBase58String(_assetId))], profit) | |
164 | 186 | } | |
165 | 187 | else throw("Strict value is not equal to itself.") | |
166 | 188 | } | |
167 | 189 | ||
168 | 190 | ||
169 | 191 | ||
170 | 192 | @Callable(i) | |
171 | 193 | func view_claimProfit (_assetId) = if (!(initialized())) | |
172 | 194 | then throw("Invalid view_claimProfit params (manager)") | |
173 | 195 | else { | |
174 | 196 | let doClaimProfitResult = invoke(assetManagerAddress(_assetId), "claimProfit", [_assetId], nil) | |
175 | 197 | if ((doClaimProfitResult == doClaimProfitResult)) | |
176 | 198 | then { | |
177 | 199 | let profit = match doClaimProfitResult { | |
178 | 200 | case t: Int => | |
179 | 201 | t | |
180 | 202 | case _ => | |
181 | 203 | throw("Invalid claimProfit result type") | |
182 | 204 | } | |
183 | 205 | throw(((((toString(balanceOf(_assetId)) + ",") + toString((balanceOf(_assetId) + profit))) + ",") + toString(profit))) | |
184 | 206 | } | |
185 | 207 | else throw("Strict value is not equal to itself.") | |
186 | 208 | } | |
187 | 209 | ||
188 | 210 | ||
189 | - | ||
190 | - | @Callable(i) | |
191 | - | func migrate (_assetId) = { | |
192 | - | let _amount = balanceOf(_assetId) | |
193 | - | if (if (if (!(initialized())) | |
194 | - | then true | |
195 | - | else (i.caller != adminAddress())) | |
196 | - | then true | |
197 | - | else !(paused())) | |
198 | - | then throw("Invalid migrate params (manager)") | |
199 | - | else { | |
200 | - | let unstake = invoke(valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(this, "k_vires_address"), "No legacy vires address")), "Invalid legacy vires address"), "withdraw", [_assetId, _amount], nil) | |
201 | - | if ((unstake == unstake)) | |
202 | - | then { | |
203 | - | let stake = invoke(assetManagerAddress(_assetId), "deposit", nil, [AttachedPayment(fromBase58String(_assetId), _amount)]) | |
204 | - | if ((stake == stake)) | |
205 | - | then [DeleteEntry("k_vires_address"), DeleteEntry("k_vires_vault")] | |
206 | - | else throw("Strict value is not equal to itself.") | |
207 | - | } | |
208 | - | else throw("Strict value is not equal to itself.") | |
209 | - | } | |
210 | - | } | |
211 | - | ||
212 | - | ||
213 | 211 | @Verifier(tx) | |
214 | 212 | func verify () = { | |
215 | 213 | let coordinatorStr = getString(this, k_coordinatorAddress) | |
216 | 214 | if (isDefined(coordinatorStr)) | |
217 | 215 | then { | |
218 | 216 | let admin = getString(addressFromStringValue(value(coordinatorStr)), k_admin_address) | |
219 | 217 | if (isDefined(admin)) | |
220 | 218 | then valueOrElse(getBoolean(addressFromStringValue(value(admin)), ((("status_" + toString(this)) + "_") + toBase58String(tx.id))), false) | |
221 | 219 | else throw("unable to verify: admin not set in coordinator") | |
222 | 220 | } | |
223 | 221 | else sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
224 | 222 | } | |
225 | 223 |
github/deemru/w8io/026f985 31.33 ms ◑