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