tx · 4qa9sF5Ct77GhVPnmvKGw1FueY37QqMAoFcgMEcdessd 3NCkVR5gTgfosVUNRTsUHc6kXdhh2V3betH: -0.03700000 Waves 2023.02.04 14:52 [2434846] smart account 3NCkVR5gTgfosVUNRTsUHc6kXdhh2V3betH > SELF 0.00000000 Waves
{ "type": 13, "id": "4qa9sF5Ct77GhVPnmvKGw1FueY37QqMAoFcgMEcdessd", "fee": 3700000, "feeAssetId": null, "timestamp": 1675511572501, "version": 2, "chainId": 84, "sender": "3NCkVR5gTgfosVUNRTsUHc6kXdhh2V3betH", "senderPublicKey": "3mgJJUcUNFHYP2pNkbkfB2C8D4gSEKEGisFByu2i6xoM", "proofs": [ "2jJJswvaViwg3ooHvAeQi2ogm1wSKZm8U28ma62W8J94VxNeHzce1wqiuAyoT992YcU1adhvzBmkmpedoQYxAAB1" ], "script": "base64:BgIiCAISBgoECAgICBIECgIICBIECgIIARIAEgMKAQgSAwoBCBoAB2tfZnVuZHMCB2tfZnVuZHMAD2tfdmlyZXNfYWRkcmVzcwIPa192aXJlc19hZGRyZXNzAA1rX3ZpcmVzX3ZhdWx0Ag1rX3ZpcmVzX3ZhdWx0ABZrX2Fzc2V0X2NsYWltZWRfcHJvZml0AhZrX2Fzc2V0X2NsYWltZWRfcHJvZml0ABRrX2Nvb3JkaW5hdG9yQWRkcmVzcwIUa19jb29yZGluYXRvckFkZHJlc3MAEGtfb3JkZXJzX2FkZHJlc3MCEGtfb3JkZXJzX2FkZHJlc3MAD2tfdmF1bHRfYWRkcmVzcwIPa192YXVsdF9hZGRyZXNzAAVrX2FtbQIFa19hbW0AD2tfYWRtaW5fYWRkcmVzcwIPa19hZG1pbl9hZGRyZXNzAA1rX3F1b3RlX2Fzc2V0Ag1rX3F1b3RlX2Fzc2V0AA9rX3F1b3RlX3N0YWtpbmcCD2tfcXVvdGVfc3Rha2luZwARa19zdGFraW5nX2FkZHJlc3MCEWtfc3Rha2luZ19hZGRyZXNzAA1rX2luaXRpYWxpemVkAg1r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0YXR1c18JAKUIAQUEdGhpcwIBXwkA2AQBCAUCdHgCaWQHCQACAQIudW5hYmxlIHRvIHZlcmlmeTogYWRtaW4gbm90IHNldCBpbiBjb29yZGluYXRvcgkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAgFAnR4D3NlbmRlclB1YmxpY0tleZaM9cQ=", "height": 2434846, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: B4bA9uX74UCSjD9ncDCNkXnUynwEX5MdnSxvExWypX1U Next: CT38S7wUUk2m8hxerk8xRbP7aC5HfhfDSxKEaQMMsLPu Diff:
Old | New | Differences | |
---|---|---|---|
11 | 11 | ||
12 | 12 | let k_coordinatorAddress = "k_coordinatorAddress" | |
13 | 13 | ||
14 | - | let k_insurance_address = "k_insurance_address" | |
15 | - | ||
16 | 14 | let k_orders_address = "k_orders_address" | |
17 | 15 | ||
18 | 16 | let k_vault_address = "k_vault_address" | |
20 | 18 | let k_amm = "k_amm" | |
21 | 19 | ||
22 | 20 | let k_admin_address = "k_admin_address" | |
23 | - | ||
24 | - | let k_admin_public_key = "k_admin_public_key" | |
25 | 21 | ||
26 | 22 | let k_quote_asset = "k_quote_asset" | |
27 | 23 | ||
40 | 36 | func coordinator () = valueOrErrorMessage(addressFromString(getStringValue(this, k_coordinatorAddress)), "Coordinator not set") | |
41 | 37 | ||
42 | 38 | ||
43 | - | func insuranceAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_insurance_address)), "Insurance not set") | |
44 | - | ||
45 | - | ||
46 | 39 | func vaultAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_vault_address)), "Vault not set") | |
47 | 40 | ||
48 | 41 | ||
49 | 42 | func ordersAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_orders_address)), "Orders not set") | |
50 | 43 | ||
51 | 44 | ||
52 | - | func isAmm (_address) = valueOrElse(getBoolean(coordinator(), toCompositeKey(k_amm, _address)), false) | |
53 | - | ||
54 | - | ||
55 | 45 | func initialized () = valueOrElse(getBoolean(this, k_initialized), false) | |
56 | 46 | ||
57 | 47 | ||
58 | 48 | func adminAddress () = addressFromString(getStringValue(coordinator(), k_admin_address)) | |
59 | - | ||
60 | - | ||
61 | - | func adminPublicKey () = fromBase58String(getStringValue(coordinator(), k_admin_public_key)) | |
62 | 49 | ||
63 | 50 | ||
64 | 51 | func quoteAsset () = fromBase58String(getStringValue(coordinator(), k_quote_asset)) | |
73 | 60 | func viresVault (_assetId) = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(this, toCompositeKey(k_vires_vault, _assetId)), ("No vault for token " + _assetId))), ("Invalid address for token " + _assetId)) | |
74 | 61 | ||
75 | 62 | ||
76 | - | func isWhitelist (_address) = if (if (if (if (isAmm(_address)) | |
77 | - | then true | |
78 | - | else (_address == toString(insuranceAddress()))) | |
79 | - | then true | |
80 | - | else (_address == toString(stakingAddress()))) | |
63 | + | func isWhitelist (_address) = if (if ((_address == toString(stakingAddress()))) | |
81 | 64 | then true | |
82 | 65 | else (_address == toString(vaultAddress()))) | |
83 | 66 | then true | |
88 | 71 | ||
89 | 72 | ||
90 | 73 | @Callable(i) | |
91 | - | func initialize (_coordinator,_viresAddress,_quoteAssetId,_quoteAssetVault) = if (initialized()) | |
92 | - | then throw("Already initialized") | |
93 | - | else [StringEntry(k_coordinatorAddress, _coordinator), StringEntry(k_vires_address, _viresAddress), StringEntry(toCompositeKey(k_vires_vault, _quoteAssetId), _quoteAssetVault), BooleanEntry(k_initialized, true)] | |
74 | + | func initialize (_coordinator,_viresAddress,_quoteAssetId,_quoteAssetVault) = if (if (initialized()) | |
75 | + | then true | |
76 | + | else (i.caller != this)) | |
77 | + | then throw("Unable to initialize") | |
78 | + | else [StringEntry(k_coordinatorAddress, toString(addressFromStringValue(_coordinator))), StringEntry(k_vires_address, toString(addressFromStringValue(_viresAddress))), StringEntry(toCompositeKey(k_vires_vault, _quoteAssetId), toString(addressFromStringValue(_quoteAssetVault))), BooleanEntry(k_initialized, true)] | |
94 | 79 | ||
95 | 80 | ||
96 | 81 | ||
99 | 84 | then true | |
100 | 85 | else (i.caller != adminAddress())) | |
101 | 86 | then throw("Invalid addTokenVault params") | |
102 | - | else [StringEntry(toCompositeKey(k_vires_vault, _assetId), _vaultAddress)] | |
87 | + | else [StringEntry(toCompositeKey(k_vires_vault, _assetId), toString(addressFromStringValue(_vaultAddress)))] | |
103 | 88 | ||
104 | 89 | ||
105 | 90 | ||
153 | 138 | then true | |
154 | 139 | else !(initialized())) | |
155 | 140 | then true | |
156 | - | else (i.caller != | |
141 | + | else (i.caller != vaultAddress())) | |
157 | 142 | then throw("Invalid claimProfit params") | |
158 | 143 | else { | |
159 | 144 | let currentAmount = invoke(viresVault(_assetId), "getCurrentTotals", [toString(this)], nil) | |
168 | 153 | let profit = (currentAssetBalance - balanceOf(_assetId)) | |
169 | 154 | let unstake = invoke(viresAddress(), "withdraw", [_assetId, profit], nil) | |
170 | 155 | if ((unstake == unstake)) | |
171 | - | then [ScriptTransfer(i.caller, profit, fromBase58String(_assetId))] | |
156 | + | then $Tuple2([ScriptTransfer(i.caller, profit, fromBase58String(_assetId))], profit) | |
172 | 157 | else throw("Strict value is not equal to itself.") | |
173 | 158 | } | |
174 | 159 | else throw("Strict value is not equal to itself.") | |
199 | 184 | ||
200 | 185 | ||
201 | 186 | @Verifier(tx) | |
202 | - | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], adminPublicKey()) | |
187 | + | func verify () = { | |
188 | + | let coordinatorStr = getString(this, k_coordinatorAddress) | |
189 | + | if (isDefined(coordinatorStr)) | |
190 | + | then { | |
191 | + | let admin = getString(addressFromStringValue(value(coordinatorStr)), k_admin_address) | |
192 | + | if (isDefined(admin)) | |
193 | + | then valueOrElse(getBoolean(addressFromStringValue(value(admin)), ((("status_" + toString(this)) + "_") + toBase58String(tx.id))), false) | |
194 | + | else throw("unable to verify: admin not set in coordinator") | |
195 | + | } | |
196 | + | else sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
197 | + | } | |
203 | 198 |
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_vires_address = "k_vires_address" | |
7 | 7 | ||
8 | 8 | let k_vires_vault = "k_vires_vault" | |
9 | 9 | ||
10 | 10 | let k_asset_claimed_profit = "k_asset_claimed_profit" | |
11 | 11 | ||
12 | 12 | let k_coordinatorAddress = "k_coordinatorAddress" | |
13 | 13 | ||
14 | - | let k_insurance_address = "k_insurance_address" | |
15 | - | ||
16 | 14 | let k_orders_address = "k_orders_address" | |
17 | 15 | ||
18 | 16 | let k_vault_address = "k_vault_address" | |
19 | 17 | ||
20 | 18 | let k_amm = "k_amm" | |
21 | 19 | ||
22 | 20 | let k_admin_address = "k_admin_address" | |
23 | - | ||
24 | - | let k_admin_public_key = "k_admin_public_key" | |
25 | 21 | ||
26 | 22 | let k_quote_asset = "k_quote_asset" | |
27 | 23 | ||
28 | 24 | let k_quote_staking = "k_quote_staking" | |
29 | 25 | ||
30 | 26 | let k_staking_address = "k_staking_address" | |
31 | 27 | ||
32 | 28 | let k_initialized = "k_initialized" | |
33 | 29 | ||
34 | 30 | func toCompositeKey (_key,_address) = ((_key + "_") + _address) | |
35 | 31 | ||
36 | 32 | ||
37 | 33 | func balanceOf (_assetId) = valueOrElse(getInteger(this, toCompositeKey(k_funds, _assetId)), 0) | |
38 | 34 | ||
39 | 35 | ||
40 | 36 | func coordinator () = valueOrErrorMessage(addressFromString(getStringValue(this, k_coordinatorAddress)), "Coordinator not set") | |
41 | 37 | ||
42 | 38 | ||
43 | - | func insuranceAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_insurance_address)), "Insurance not set") | |
44 | - | ||
45 | - | ||
46 | 39 | func vaultAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_vault_address)), "Vault not set") | |
47 | 40 | ||
48 | 41 | ||
49 | 42 | func ordersAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_orders_address)), "Orders not set") | |
50 | 43 | ||
51 | 44 | ||
52 | - | func isAmm (_address) = valueOrElse(getBoolean(coordinator(), toCompositeKey(k_amm, _address)), false) | |
53 | - | ||
54 | - | ||
55 | 45 | func initialized () = valueOrElse(getBoolean(this, k_initialized), false) | |
56 | 46 | ||
57 | 47 | ||
58 | 48 | func adminAddress () = addressFromString(getStringValue(coordinator(), k_admin_address)) | |
59 | - | ||
60 | - | ||
61 | - | func adminPublicKey () = fromBase58String(getStringValue(coordinator(), k_admin_public_key)) | |
62 | 49 | ||
63 | 50 | ||
64 | 51 | func quoteAsset () = fromBase58String(getStringValue(coordinator(), k_quote_asset)) | |
65 | 52 | ||
66 | 53 | ||
67 | 54 | func stakingAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_staking_address)), "Staking not set") | |
68 | 55 | ||
69 | 56 | ||
70 | 57 | func viresAddress () = valueOrErrorMessage(addressFromString(getStringValue(this, k_vires_address)), "Vires not set") | |
71 | 58 | ||
72 | 59 | ||
73 | 60 | func viresVault (_assetId) = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(this, toCompositeKey(k_vires_vault, _assetId)), ("No vault for token " + _assetId))), ("Invalid address for token " + _assetId)) | |
74 | 61 | ||
75 | 62 | ||
76 | - | func isWhitelist (_address) = if (if (if (if (isAmm(_address)) | |
77 | - | then true | |
78 | - | else (_address == toString(insuranceAddress()))) | |
79 | - | then true | |
80 | - | else (_address == toString(stakingAddress()))) | |
63 | + | func isWhitelist (_address) = if (if ((_address == toString(stakingAddress()))) | |
81 | 64 | then true | |
82 | 65 | else (_address == toString(vaultAddress()))) | |
83 | 66 | then true | |
84 | 67 | else (_address == toString(ordersAddress())) | |
85 | 68 | ||
86 | 69 | ||
87 | 70 | func updateFunds (_assetId,_value) = [IntegerEntry(toCompositeKey(k_funds, _assetId), _value)] | |
88 | 71 | ||
89 | 72 | ||
90 | 73 | @Callable(i) | |
91 | - | func initialize (_coordinator,_viresAddress,_quoteAssetId,_quoteAssetVault) = if (initialized()) | |
92 | - | then throw("Already initialized") | |
93 | - | else [StringEntry(k_coordinatorAddress, _coordinator), StringEntry(k_vires_address, _viresAddress), StringEntry(toCompositeKey(k_vires_vault, _quoteAssetId), _quoteAssetVault), BooleanEntry(k_initialized, true)] | |
74 | + | func initialize (_coordinator,_viresAddress,_quoteAssetId,_quoteAssetVault) = if (if (initialized()) | |
75 | + | then true | |
76 | + | else (i.caller != this)) | |
77 | + | then throw("Unable to initialize") | |
78 | + | else [StringEntry(k_coordinatorAddress, toString(addressFromStringValue(_coordinator))), StringEntry(k_vires_address, toString(addressFromStringValue(_viresAddress))), StringEntry(toCompositeKey(k_vires_vault, _quoteAssetId), toString(addressFromStringValue(_quoteAssetVault))), BooleanEntry(k_initialized, true)] | |
94 | 79 | ||
95 | 80 | ||
96 | 81 | ||
97 | 82 | @Callable(i) | |
98 | 83 | func addTokenVault (_assetId,_vaultAddress) = if (if (!(initialized())) | |
99 | 84 | then true | |
100 | 85 | else (i.caller != adminAddress())) | |
101 | 86 | then throw("Invalid addTokenVault params") | |
102 | - | else [StringEntry(toCompositeKey(k_vires_vault, _assetId), _vaultAddress)] | |
87 | + | else [StringEntry(toCompositeKey(k_vires_vault, _assetId), toString(addressFromStringValue(_vaultAddress)))] | |
103 | 88 | ||
104 | 89 | ||
105 | 90 | ||
106 | 91 | @Callable(i) | |
107 | 92 | func withdraw (_assetId,_amount) = if (if (if (!(isWhitelist(toString(i.caller)))) | |
108 | 93 | then true | |
109 | 94 | else !(initialized())) | |
110 | 95 | then true | |
111 | 96 | else (_amount > balanceOf(_assetId))) | |
112 | 97 | then throw(((("Invalid withdraw params (manager) " + toString(_amount)) + " > ") + toString(balanceOf(_assetId)))) | |
113 | 98 | else { | |
114 | 99 | let unstake = invoke(viresAddress(), "withdraw", [_assetId, _amount], nil) | |
115 | 100 | if ((unstake == unstake)) | |
116 | 101 | then { | |
117 | 102 | let currentAssetBalance = (balanceOf(_assetId) - _amount) | |
118 | 103 | (updateFunds(_assetId, currentAssetBalance) ++ [ScriptTransfer(i.caller, _amount, fromBase58String(_assetId))]) | |
119 | 104 | } | |
120 | 105 | else throw("Strict value is not equal to itself.") | |
121 | 106 | } | |
122 | 107 | ||
123 | 108 | ||
124 | 109 | ||
125 | 110 | @Callable(i) | |
126 | 111 | func deposit () = { | |
127 | 112 | let _amount = i.payments[0].amount | |
128 | 113 | let _assetId = toBase58String(valueOrErrorMessage(i.payments[0].assetId, "No assetId")) | |
129 | 114 | if (if (if ((i.payments[0].assetId != quoteAsset())) | |
130 | 115 | then true | |
131 | 116 | else !(initialized())) | |
132 | 117 | then true | |
133 | 118 | else if (!(isWhitelist(toString(i.caller)))) | |
134 | 119 | then (i.caller != adminAddress()) | |
135 | 120 | else false) | |
136 | 121 | then throw("Invalid deposit params (manager)") | |
137 | 122 | else { | |
138 | 123 | let vault = viresVault(_assetId) | |
139 | 124 | let stake = invoke(viresAddress(), "deposit", [toString(vault), false], [AttachedPayment(i.payments[0].assetId, _amount)]) | |
140 | 125 | if ((stake == stake)) | |
141 | 126 | then { | |
142 | 127 | let currentAssetBalance = (balanceOf(_assetId) + _amount) | |
143 | 128 | updateFunds(_assetId, currentAssetBalance) | |
144 | 129 | } | |
145 | 130 | else throw("Strict value is not equal to itself.") | |
146 | 131 | } | |
147 | 132 | } | |
148 | 133 | ||
149 | 134 | ||
150 | 135 | ||
151 | 136 | @Callable(i) | |
152 | 137 | func claimProfit (_assetId) = if (if (if ((fromBase58String(_assetId) != quoteAsset())) | |
153 | 138 | then true | |
154 | 139 | else !(initialized())) | |
155 | 140 | then true | |
156 | - | else (i.caller != | |
141 | + | else (i.caller != vaultAddress())) | |
157 | 142 | then throw("Invalid claimProfit params") | |
158 | 143 | else { | |
159 | 144 | let currentAmount = invoke(viresVault(_assetId), "getCurrentTotals", [toString(this)], nil) | |
160 | 145 | if ((currentAmount == currentAmount)) | |
161 | 146 | then { | |
162 | 147 | let currentAssetBalance = match currentAmount { | |
163 | 148 | case t: (Int, Int, Int, Int) => | |
164 | 149 | t._3 | |
165 | 150 | case _ => | |
166 | 151 | throw("Invalid currentAmount type") | |
167 | 152 | } | |
168 | 153 | let profit = (currentAssetBalance - balanceOf(_assetId)) | |
169 | 154 | let unstake = invoke(viresAddress(), "withdraw", [_assetId, profit], nil) | |
170 | 155 | if ((unstake == unstake)) | |
171 | - | then [ScriptTransfer(i.caller, profit, fromBase58String(_assetId))] | |
156 | + | then $Tuple2([ScriptTransfer(i.caller, profit, fromBase58String(_assetId))], profit) | |
172 | 157 | else throw("Strict value is not equal to itself.") | |
173 | 158 | } | |
174 | 159 | else throw("Strict value is not equal to itself.") | |
175 | 160 | } | |
176 | 161 | ||
177 | 162 | ||
178 | 163 | ||
179 | 164 | @Callable(i) | |
180 | 165 | func view_claimProfit (_assetId) = if (if ((fromBase58String(_assetId) != quoteAsset())) | |
181 | 166 | then true | |
182 | 167 | else !(initialized())) | |
183 | 168 | then throw("Invalid view_claimProfit params") | |
184 | 169 | else { | |
185 | 170 | let currentAmount = invoke(viresVault(_assetId), "getCurrentTotals", [toString(this)], nil) | |
186 | 171 | if ((currentAmount == currentAmount)) | |
187 | 172 | then { | |
188 | 173 | let currentAssetBalance = match currentAmount { | |
189 | 174 | case t: (Int, Int, Int, Int) => | |
190 | 175 | t._3 | |
191 | 176 | case _ => | |
192 | 177 | throw("Invalid currentAmount type") | |
193 | 178 | } | |
194 | 179 | let profit = (currentAssetBalance - balanceOf(_assetId)) | |
195 | 180 | throw(((((toString(balanceOf(_assetId)) + ",") + toString(currentAssetBalance)) + ",") + toString(profit))) | |
196 | 181 | } | |
197 | 182 | else throw("Strict value is not equal to itself.") | |
198 | 183 | } | |
199 | 184 | ||
200 | 185 | ||
201 | 186 | @Verifier(tx) | |
202 | - | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], adminPublicKey()) | |
187 | + | func verify () = { | |
188 | + | let coordinatorStr = getString(this, k_coordinatorAddress) | |
189 | + | if (isDefined(coordinatorStr)) | |
190 | + | then { | |
191 | + | let admin = getString(addressFromStringValue(value(coordinatorStr)), k_admin_address) | |
192 | + | if (isDefined(admin)) | |
193 | + | then valueOrElse(getBoolean(addressFromStringValue(value(admin)), ((("status_" + toString(this)) + "_") + toBase58String(tx.id))), false) | |
194 | + | else throw("unable to verify: admin not set in coordinator") | |
195 | + | } | |
196 | + | else sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
197 | + | } | |
203 | 198 |
github/deemru/w8io/026f985 45.00 ms ◑