tx · 9WzgvqcCxRSBPRa9QiZstfGGNY4MmkqsGYAD47KMPHMi 3Mzep1R5kHeC1ecKFkWjuhU3Gw4LAdCib9N: -0.01300000 Waves 2024.02.02 12:44 [2958486] smart account 3Mzep1R5kHeC1ecKFkWjuhU3Gw4LAdCib9N > SELF 0.00000000 Waves
{ "type": 13, "id": "9WzgvqcCxRSBPRa9QiZstfGGNY4MmkqsGYAD47KMPHMi", "fee": 1300000, "feeAssetId": null, "timestamp": 1706867090670, "version": 2, "chainId": 84, "sender": "3Mzep1R5kHeC1ecKFkWjuhU3Gw4LAdCib9N", "senderPublicKey": "41THq9VrFxHEvVGJyz2oMpJQErnSkkqJXpBypSDxa5Mv", "proofs": [ "2PczNqpHQCyBgJaFkhwREEsj3EJ8UTtMMV62PjQZEtgNUWm7YbxHdQcfFCbvswDMNJckGoGZK11dig5PSx6LekWS" ], "script": "base64:BwIeCAISAwoBGBIDCgEYEgQKAgIYEgQKAgIYEgQKAgIYJgAHY2hhaW5JZAkAyQECCQDKAQIIBQR0aGlzBWJ5dGVzAAEAAQAIY2hhaW5JZFQBAVQACGNoYWluSWRXAQFXAANTRVACAl9fAAVXQVZFUwIFV0FWRVMAEGNvbnRyYWN0RmlsZW5hbWUCFXd4ZGFvX2NhbGN1bGF0b3IucmlkZQAFbXVsdDgAgMLXLwAGbXVsdDE4CQC2AgEAgICQu7rWrfANAA13YXZlc0RlY2ltYWxzAAgADHVzZHREZWNpbWFscwAGAQV0b1gxOAIHb3JpZ1ZhbA1vcmlnU2NhbGVNdWx0CQC8AgMJALYCAQUHb3JpZ1ZhbAUGbXVsdDE4CQC2AgEFDW9yaWdTY2FsZU11bHQBB2Zyb21YMTgCA3ZhbA9yZXN1bHRTY2FsZU11bHQJAKADAQkAvAIDBQN2YWwJALYCAQUPcmVzdWx0U2NhbGVNdWx0BQZtdWx0MTgBB3dyYXBFcnIBAXMJAKwCAgkArAICBRBjb250cmFjdEZpbGVuYW1lAgI6IAUBcwEIdGhyb3dFcn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QWRkcmVzcwkAbAYACgAABQx1c2R0RGVjaW1hbHMAAAAABQRET1dOCQCUCgIFA25pbAUNdHJlYXN1cnlWYWx1ZQECdHgBBnZlcmlmeQAJAAACBQdjaGFpbklkBQhjaGFpbklkVCknhE8=", "height": 2958486, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: EgR72zW5AVazXcXRMMTG27dEZ3681ZKQazCoYHvThLPn Next: 8SzYkYqU1NM7wNRUa84T3d5jm4e4DuvJ9JW7QvQaV2NU Diff:
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 7 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let separator = "__" | |
5 | - | ||
6 | 4 | let chainId = take(drop(this.bytes, 1), 1) | |
7 | 5 | ||
8 | 6 | let chainIdT = base58'2T' | |
9 | 7 | ||
10 | 8 | let chainIdW = base58'2W' | |
11 | - | ||
12 | - | func mustAddress (i,address) = if ((i.caller == address)) | |
13 | - | then true | |
14 | - | else throw("permission denied") | |
15 | - | ||
16 | - | ||
17 | - | func mustThis (i) = mustAddress(i, this) | |
18 | - | ||
19 | 9 | ||
20 | 10 | let SEP = "__" | |
21 | 11 | ||
25 | 15 | ||
26 | 16 | let mult8 = 100000000 | |
27 | 17 | ||
18 | + | let mult18 = toBigInt(1000000000000000000) | |
19 | + | ||
20 | + | let wavesDecimals = 8 | |
21 | + | ||
22 | + | let usdtDecimals = 6 | |
23 | + | ||
24 | + | func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), mult18, toBigInt(origScaleMult)) | |
25 | + | ||
26 | + | ||
27 | + | func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), mult18)) | |
28 | + | ||
29 | + | ||
28 | 30 | func wrapErr (s) = ((contractFilename + ": ") + s) | |
29 | 31 | ||
30 | 32 | ||
31 | 33 | func throwErr (s) = throw(wrapErr(s)) | |
32 | 34 | ||
35 | + | ||
36 | + | let wxAssetId = if ((chainId == chainIdW)) | |
37 | + | then base58'Atqv59EYzjFGuitKVnMRk6H8FukjoV3ktPorbEys25on' | |
38 | + | else if ((chainId == chainIdT)) | |
39 | + | then base58'EMAMLxDnv3xiz8RXg8Btj33jcEw3wLczL3JKYYmuubpc' | |
40 | + | else throwErr("invalid chain id") | |
33 | 41 | ||
34 | 42 | func keyCurrentPeriod () = makeString(["%s", "currentPeriod"], SEP) | |
35 | 43 | ||
41 | 49 | ||
42 | 50 | ||
43 | 51 | func keyTreasuryValueByPeriod (period) = makeString(["%s%d", "treasuryValue", toString(period)], SEP) | |
52 | + | ||
53 | + | ||
54 | + | func keySkinTotal (treasuryAddress) = ("skin_total_" + toString(treasuryAddress)) | |
44 | 55 | ||
45 | 56 | ||
46 | 57 | func keyPowerConfigAddress () = "%s__powerConfigAddress" | |
113 | 124 | func getLpAssetId (factoryAddress) = fromBase58String(valueOrErrorMessage(getString(factoryAddress, keyLpAssetId()), wrapErr("invalid lp asset id"))) | |
114 | 125 | ||
115 | 126 | ||
127 | + | func getAssetInfoOrFail (assetId) = valueOrErrorMessage(assetInfo(assetId), wrapErr("invalid asset info")) | |
128 | + | ||
129 | + | ||
116 | 130 | func getAssetsBalances (targetAddress,assetIdList) = { | |
117 | 131 | func map (acc,nextAssetIdStr) = { | |
118 | 132 | let balance = if ((nextAssetIdStr == WAVES)) | |
119 | - | then wavesBalance(targetAddress) | |
120 | - | else assetBalance(targetAddress, fromBase58String(nextAssetIdStr)) | |
133 | + | then toX18(wavesBalance(targetAddress).available, pow(10, 0, wavesDecimals, 0, 0, DOWN)) | |
134 | + | else { | |
135 | + | let assetId = fromBase58String(nextAssetIdStr) | |
136 | + | let assetDecimals = getAssetInfoOrFail(assetId).decimals | |
137 | + | toX18(assetBalance(targetAddress, assetId), pow(10, 0, assetDecimals, 0, 0, DOWN)) | |
138 | + | } | |
121 | 139 | (acc :+ balance) | |
122 | 140 | } | |
123 | 141 | ||
139 | 157 | func getAssetsPrices (poolsFactoryAddress,assetIdList) = if ((chainId == chainIdW)) | |
140 | 158 | then { | |
141 | 159 | let wavesUsdtAddressStr = "3PKfrupEydU2nZAghVjZAfvCwMBkzuR1F52" | |
142 | - | let wavesUsdtPrice = { | |
160 | + | let wavesUsdtPrice = parseBigIntValue({ | |
143 | 161 | let @ = invoke(poolsFactoryAddress, "getPrice", [wavesUsdtAddressStr], nil) | |
144 | - | if ($isInstanceOf(@, " | |
162 | + | if ($isInstanceOf(@, "String")) | |
145 | 163 | then @ | |
146 | - | else throw(($getType(@) + " couldn't be cast to | |
147 | - | } | |
164 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
165 | + | }) | |
148 | 166 | let wavesXtnAddressStr = "3PPZWgFNRKHLvM51pwS934C8VZ7d2F4Z58g" | |
149 | - | let wavesXtnPrice = { | |
167 | + | let wavesXtnPrice = parseBigIntValue({ | |
150 | 168 | let @ = invoke(poolsFactoryAddress, "getPrice", [wavesXtnAddressStr], nil) | |
151 | - | if ($isInstanceOf(@, " | |
169 | + | if ($isInstanceOf(@, "String")) | |
152 | 170 | then @ | |
153 | - | else throw(($getType(@) + " couldn't be cast to | |
154 | - | } | |
155 | - | let xtnUsdtPrice = fraction(wavesUsdtPrice, | |
171 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
172 | + | }) | |
173 | + | let xtnUsdtPrice = fraction(wavesUsdtPrice, mult18, wavesXtnPrice) | |
156 | 174 | func map (acc,nextAssetId) = { | |
157 | 175 | let price = match nextAssetId { | |
158 | 176 | case _ => | |
159 | 177 | if (("2thsACuHmzDMuNezPM32wg9a3BwUzBWDeSKakgz3cw21" == $match0)) | |
160 | 178 | then { | |
161 | 179 | let pwrWavesAddressStr = "3PDi7Qq8pLQYvtKyTfQuqqPUWyhoYbU957t" | |
162 | - | let pwrWavesPrice = { | |
180 | + | let pwrWavesPrice = parseBigIntValue({ | |
163 | 181 | let @ = invoke(poolsFactoryAddress, "getPrice", [pwrWavesAddressStr], nil) | |
164 | - | if ($isInstanceOf(@, " | |
182 | + | if ($isInstanceOf(@, "String")) | |
165 | 183 | then @ | |
166 | - | else throw(($getType(@) + " couldn't be cast to | |
167 | - | } | |
168 | - | fraction(pwrWavesPrice, wavesUsdtPrice, | |
184 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
185 | + | }) | |
186 | + | fraction(pwrWavesPrice, wavesUsdtPrice, mult18) | |
169 | 187 | } | |
170 | 188 | else if (("Atqv59EYzjFGuitKVnMRk6H8FukjoV3ktPorbEys25on" == $match0)) | |
171 | 189 | then { | |
172 | 190 | let wxWavesAddressStr = "3PFzaH2ghpwANHFgjeva83N1yxzErELx2eh" | |
173 | - | let wxWavesPrice = { | |
191 | + | let wxWavesPrice = parseBigIntValue({ | |
174 | 192 | let @ = invoke(poolsFactoryAddress, "getPrice", [wxWavesAddressStr], nil) | |
175 | - | if ($isInstanceOf(@, " | |
193 | + | if ($isInstanceOf(@, "String")) | |
176 | 194 | then @ | |
177 | - | else throw(($getType(@) + " couldn't be cast to | |
178 | - | } | |
179 | - | fraction(wxWavesPrice, wavesUsdtPrice, | |
195 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
196 | + | }) | |
197 | + | fraction(wxWavesPrice, wavesUsdtPrice, mult18) | |
180 | 198 | } | |
181 | 199 | else if (("34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ" == $match0)) | |
182 | 200 | then { | |
183 | - | let | |
184 | - | let | |
185 | - | let @ = invoke(poolsFactoryAddress, "getPrice", [ | |
186 | - | if ($isInstanceOf(@, " | |
201 | + | let wavesUsdtwxgAddressStr = "3PKMVZ7kQeaREajYi8Yc25Ro6mcNw5D6QSa" | |
202 | + | let wavesUsdtwxgPrice = parseBigIntValue({ | |
203 | + | let @ = invoke(poolsFactoryAddress, "getPrice", [wavesUsdtwxgAddressStr], nil) | |
204 | + | if ($isInstanceOf(@, "String")) | |
187 | 205 | then @ | |
188 | - | else throw(($getType(@) + " couldn't be cast to | |
189 | - | } | |
190 | - | fraction( | |
206 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
207 | + | }) | |
208 | + | fraction(wavesUsdtPrice, mult18, wavesUsdtwxgPrice) | |
191 | 209 | } | |
192 | 210 | else if (("6XtHjpXbs9RRJP2Sr9GUyVqzACcby9TkThHXnjVC5CDJ" == $match0)) | |
193 | 211 | then { | |
194 | 212 | let wavesUsdcwxgAddressStr = "3P3g3eipfG2NZKKQE8DZXt2E9tRJqii9jcX" | |
195 | - | let | |
213 | + | let wavesUsdcwxgPrice = parseBigIntValue({ | |
196 | 214 | let @ = invoke(poolsFactoryAddress, "getPrice", [wavesUsdcwxgAddressStr], nil) | |
197 | - | if ($isInstanceOf(@, " | |
215 | + | if ($isInstanceOf(@, "String")) | |
198 | 216 | then @ | |
199 | - | else throw(($getType(@) + " couldn't be cast to | |
200 | - | } | |
201 | - | fraction(wavesUsdtPrice, | |
217 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
218 | + | }) | |
219 | + | fraction(wavesUsdtPrice, mult18, wavesUsdcwxgPrice) | |
202 | 220 | } | |
203 | 221 | else if (("HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk" == $match0)) | |
204 | 222 | then { | |
205 | 223 | let ltcwxgXtnAddressStr = "3P94wvu5gA7VhjPgAB3twaeqdwHCwNK2vsn" | |
206 | - | let ltcwxgXtnPrice = { | |
224 | + | let ltcwxgXtnPrice = parseBigIntValue({ | |
207 | 225 | let @ = invoke(poolsFactoryAddress, "getPrice", [ltcwxgXtnAddressStr], nil) | |
208 | - | if ($isInstanceOf(@, " | |
226 | + | if ($isInstanceOf(@, "String")) | |
209 | 227 | then @ | |
210 | - | else throw(($getType(@) + " couldn't be cast to Int")) | |
228 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
229 | + | }) | |
230 | + | fraction(ltcwxgXtnPrice, xtnUsdtPrice, mult18) | |
231 | + | } | |
232 | + | else if (("474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu" == $match0)) | |
233 | + | then { | |
234 | + | let ethwxgWavesAddressStr = "3P3XGTN6s292g9iwYhs3TEqJqHiffQYojuE" | |
235 | + | let ethwxgWavesPrice = parseBigIntValue({ | |
236 | + | let @ = invoke(poolsFactoryAddress, "getPrice", [ethwxgWavesAddressStr], nil) | |
237 | + | if ($isInstanceOf(@, "String")) | |
238 | + | then @ | |
239 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
240 | + | }) | |
241 | + | fraction(ethwxgWavesPrice, wavesUsdtPrice, mult18) | |
211 | 242 | } | |
212 | - | fraction(ltcwxgXtnPrice, xtnUsdtPrice, mult8) | |
213 | - | } | |
214 | - | else if (("HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk" == $match0)) | |
215 | - | then { | |
216 | - | let ethwxgXtnAddressStr = "3P3XGTN6s292g9iwYhs3TEqJqHiffQYojuE" | |
217 | - | let ethwxgXtnPrice = { | |
218 | - | let @ = invoke(poolsFactoryAddress, "getPrice", [ethwxgXtnAddressStr], nil) | |
219 | - | if ($isInstanceOf(@, "Int")) | |
220 | - | then @ | |
221 | - | else throw(($getType(@) + " couldn't be cast to Int")) | |
222 | - | } | |
223 | - | fraction(ethwxgXtnPrice, wavesUsdtPrice, mult8) | |
224 | - | } | |
225 | - | else if (("HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk" == $match0)) | |
243 | + | else if (("8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS" == $match0)) | |
226 | 244 | then { | |
227 | 245 | let btcwxgXtnAddressStr = "3PCBWDTA6jrFswd7gQgaE3Xk7gLM5RKofvp" | |
228 | - | let btcwxgXtnPrice = { | |
246 | + | let btcwxgXtnPrice = parseBigIntValue({ | |
229 | 247 | let @ = invoke(poolsFactoryAddress, "getPrice", [btcwxgXtnAddressStr], nil) | |
230 | - | if ($isInstanceOf(@, " | |
248 | + | if ($isInstanceOf(@, "String")) | |
231 | 249 | then @ | |
232 | - | else throw(($getType(@) + " couldn't be cast to | |
233 | - | } | |
234 | - | fraction(btcwxgXtnPrice, | |
250 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
251 | + | }) | |
252 | + | fraction(btcwxgXtnPrice, xtnUsdtPrice, mult18) | |
235 | 253 | } | |
236 | 254 | else throwErr("invalid asset id") | |
237 | 255 | } | |
259 | 277 | if (("EMAMLxDnv3xiz8RXg8Btj33jcEw3wLczL3JKYYmuubpc" == $match0)) | |
260 | 278 | then { | |
261 | 279 | let wxUsdtAddressStr = "3MrULQRLc52GWrJF1tMcAm4M78fPe57o9Kt" | |
262 | - | let wxUsdtPrice = { | |
280 | + | let wxUsdtPrice = parseBigIntValue({ | |
263 | 281 | let @ = invoke(poolsFactoryAddress, "getPrice", [wxUsdtAddressStr], nil) | |
264 | - | if ($isInstanceOf(@, " | |
282 | + | if ($isInstanceOf(@, "String")) | |
265 | 283 | then @ | |
266 | - | else throw(($getType(@) + " couldn't be cast to | |
267 | - | } | |
284 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
285 | + | }) | |
268 | 286 | wxUsdtPrice | |
269 | 287 | } | |
270 | 288 | else if (("A7Ksh7fXyqm1KhKAiK3bAB2aiPSitQQF6v1pyu9SS3FR" == $match0)) | |
271 | 289 | then { | |
272 | 290 | let usdcUsdtAddressStr = "3MzKSdTH2jFbypLsoNfrH7QgkzSbx3EYwCA" | |
273 | - | let usdcUsdtPrice = { | |
291 | + | let usdcUsdtPrice = parseBigIntValue({ | |
274 | 292 | let @ = invoke(poolsFactoryAddress, "getPrice", [usdcUsdtAddressStr], nil) | |
275 | - | if ($isInstanceOf(@, " | |
293 | + | if ($isInstanceOf(@, "String")) | |
276 | 294 | then @ | |
277 | - | else throw(($getType(@) + " couldn't be cast to | |
278 | - | } | |
295 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
296 | + | }) | |
279 | 297 | usdcUsdtPrice | |
280 | 298 | } | |
281 | 299 | else if (("8Q6SE2ANebufw8JuPjJVRjZD6drD8ihjNjM8xaGUSfdR" == $match0)) | |
315 | 333 | let index = valueOrErrorMessage(indexOf(assetsStr, nextAssetIdStr), wrapErr("invalid asset id")) | |
316 | 334 | let balance = assetsBalances[index] | |
317 | 335 | let price = assetsPrices[index] | |
318 | - | let assetValue = fraction(balance, price, | |
336 | + | let assetValue = fraction(balance, price, mult18) | |
319 | 337 | (acc + assetValue) | |
320 | 338 | } | |
321 | 339 | ||
322 | 340 | let treasuryValue = { | |
323 | 341 | let $l = assetsStr | |
324 | 342 | let $s = size($l) | |
325 | - | let $acc0 = 0 | |
343 | + | let $acc0 = toBigInt(0) | |
326 | 344 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
327 | 345 | then $a | |
328 | 346 | else reduce($a, $l[$i]) | |
374 | 392 | let pwrBalance = assetBalance(factoryAddress, getPowerAssetId(factoryAddress)) | |
375 | 393 | if ((pwrBalance == pwrBalance)) | |
376 | 394 | then { | |
377 | - | let treasuryAddress = getTreasuryAddress(factoryAddress) | |
378 | - | let assetsBalances = getAssetsBalances(treasuryAddress, assetsStr) | |
379 | - | func map (acc,nextAssetIdStr) = { | |
380 | - | let assetId = fromBase58String(nextAssetIdStr) | |
381 | - | let index = valueOrErrorMessage(indexOf(assetsStr, nextAssetIdStr), wrapErr("invalid asset balance")) | |
382 | - | let balance = assetsBalances[index] | |
383 | - | let amount = fraction(balance, pwrAmount, pwrBalance) | |
384 | - | if ((amount > 0)) | |
385 | - | then $Tuple2((acc._1 :+ assetId), (acc._2 :+ amount)) | |
386 | - | else acc | |
387 | - | } | |
395 | + | let wxdaoQuantity = getAssetInfoOrFail(getLpAssetId(factoryAddress)).quantity | |
396 | + | if ((wxdaoQuantity == wxdaoQuantity)) | |
397 | + | then { | |
398 | + | let assetsBalances = getAssetsBalances(factoryAddress, assetsStr) | |
399 | + | func map (acc,nextAssetIdStr) = { | |
400 | + | let assetId = fromBase58String(nextAssetIdStr) | |
401 | + | let index = valueOrErrorMessage(indexOf(assetsStr, nextAssetIdStr), wrapErr("invalid asset balance")) | |
402 | + | let assetDecimals = getAssetInfoOrFail(assetId).decimals | |
403 | + | let balance = fromX18(assetsBalances[index], pow(10, 0, assetDecimals, 0, 0, DOWN)) | |
404 | + | let amount = fraction(balance, payment.amount, wxdaoQuantity) | |
405 | + | if ((amount > 0)) | |
406 | + | then $Tuple2((acc._1 :+ assetId), (acc._2 :+ amount)) | |
407 | + | else acc | |
408 | + | } | |
388 | 409 | ||
389 | - | let transfers = { | |
390 | - | let $l = assetsStr | |
391 | - | let $s = size($l) | |
392 | - | let $acc0 = $Tuple2(nil, nil) | |
393 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
394 | - | then $a | |
395 | - | else map($a, $l[$i]) | |
410 | + | let transfers = { | |
411 | + | let $l = assetsStr | |
412 | + | let $s = size($l) | |
413 | + | let $acc0 = $Tuple2(nil, nil) | |
414 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
415 | + | then $a | |
416 | + | else map($a, $l[$i]) | |
396 | 417 | ||
397 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
398 | - | then $a | |
399 | - | else throw("List size exceeds 6") | |
418 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
419 | + | then $a | |
420 | + | else throw("List size exceeds 6") | |
400 | 421 | ||
401 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6) | |
402 | - | } | |
403 | - | if ((transfers == transfers)) | |
404 | - | then { | |
405 | - | let additionalLockRounds = 0 | |
406 | - | let factoryActions = ([invoke(factoryAddress, "commitAfterStartWithLockRoundFor", [toString(powerContractAddress(factoryAddress)), toString(factoryAddress), toString(userAddress), additionalLockRounds, getPowerAssetId(factoryAddress), pwrAmount], nil)] ++ (if ((size(transfers._1) == 0)) | |
407 | - | then nil | |
408 | - | else [invoke(factoryAddress, "transferAssets", [userAddress.bytes, transfers._1, transfers._2], nil)])) | |
409 | - | $Tuple2([Burn(paymentAssetId, payment.amount)], factoryActions) | |
422 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6) | |
423 | + | } | |
424 | + | if ((transfers == transfers)) | |
425 | + | then { | |
426 | + | let additionalLockRounds = 0 | |
427 | + | let factoryActions = ([invoke(factoryAddress, "commitAfterStartWithLockRoundFor", [toString(powerContractAddress(factoryAddress)), toString(factoryAddress), toString(userAddress), additionalLockRounds, getPowerAssetId(factoryAddress), pwrAmount], nil)] ++ (if ((size(transfers._1) == 0)) | |
428 | + | then nil | |
429 | + | else [invoke(factoryAddress, "transferAssets", [userAddress.bytes, transfers._1, transfers._2], nil)])) | |
430 | + | $Tuple2([Burn(paymentAssetId, payment.amount)], factoryActions) | |
431 | + | } | |
432 | + | else throw("Strict value is not equal to itself.") | |
410 | 433 | } | |
411 | 434 | else throw("Strict value is not equal to itself.") | |
412 | 435 | } | |
418 | 441 | @Callable(i) | |
419 | 442 | func price (callerPublicKey,args) = { | |
420 | 443 | let factoryAddress = i.caller | |
444 | + | let poolsFactoryAddress = getPoolsFactoryAddress(factoryAddress) | |
421 | 445 | let currentPeriod = valueOrErrorMessage(getInteger(factoryAddress, keyCurrentPeriod()), wrapErr("invalid current period")) | |
422 | 446 | let startTreasuryValue = valueOrErrorMessage(getInteger(factoryAddress, keyTreasuryValueByPeriod(currentPeriod)), wrapErr(("invalid treasury value for period " + toString(currentPeriod)))) | |
423 | - | let treasuryValue = calcTreasuryValue(factoryAddress) | |
447 | + | let treasuryValue = fromX18(calcTreasuryValue(factoryAddress), pow(10, 0, usdtDecimals, 0, 0, DOWN)) | |
424 | 448 | let treasuryValueDiff = (treasuryValue - startTreasuryValue) | |
425 | - | let pwrPriceRaw = getAssetsPrices(factoryAddress, [toBase58String(getPowerAssetId(factoryAddress))])[0] | |
426 | - | let pwrPrice = if ((pwrPriceRaw > 0)) | |
427 | - | then pwrPriceRaw | |
449 | + | let pwrAssetId = getPowerAssetId(factoryAddress) | |
450 | + | let pwrPriceRaw = getAssetsPrices(poolsFactoryAddress, [toBase58String(pwrAssetId)])[0] | |
451 | + | let pwrPrice = if ((pwrPriceRaw > toBigInt(0))) | |
452 | + | then fromX18(pwrPriceRaw, pow(10, 0, usdtDecimals, 0, 0, DOWN)) | |
428 | 453 | else throwErr("invalid PWR price") | |
429 | - | let price = if ((0 > treasuryValueDiff)) | |
430 | - | then (pwrPrice / 100) | |
431 | - | else ((fraction(treasuryValueDiff, 2, 10000) + pwrPrice) / 100) | |
454 | + | let treasuryAddress = getTreasuryAddress(factoryAddress) | |
455 | + | let skinTotal = valueOrElse(getInteger(powerContractAddress(factoryAddress), keySkinTotal(treasuryAddress)), 0) | |
456 | + | let pwrRemaining = (getAssetInfoOrFail(getLpAssetId(factoryAddress)).quantity / 100) | |
457 | + | let pwrAmount = (skinTotal + pwrRemaining) | |
458 | + | let factoryAddressWxBalanceRaw = getAssetsBalances(factoryAddress, [toBase58String(getLpAssetId(factoryAddress))])[0] | |
459 | + | let factoryAddressWxBalance = if ((factoryAddressWxBalanceRaw > toBigInt(0))) | |
460 | + | then fromX18(factoryAddressWxBalanceRaw, pow(10, 0, usdtDecimals, 0, 0, DOWN)) | |
461 | + | else throwErr("invalid factory wx balance") | |
462 | + | let wxPriceRaw = getAssetsPrices(poolsFactoryAddress, [toBase58String(wxAssetId)])[0] | |
463 | + | let wxPrice = if ((wxPriceRaw > toBigInt(0))) | |
464 | + | then fromX18(wxPriceRaw, pow(10, 0, usdtDecimals, 0, 0, DOWN)) | |
465 | + | else throwErr("invalid wx price") | |
466 | + | let wxdaoQuantity = getAssetInfoOrFail(getLpAssetId(factoryAddress)).quantity | |
467 | + | let price = (((pwrPrice / 100) + fraction(factoryAddressWxBalance, wxPrice, wxdaoQuantity)) + fraction(max([treasuryValueDiff, 0]), 2, (1000 * pwrAmount))) | |
432 | 468 | $Tuple2(nil, price) | |
433 | 469 | } | |
434 | 470 | ||
437 | 473 | @Callable(i) | |
438 | 474 | func getTreasuryValue (callerPublicKey,args) = { | |
439 | 475 | let factoryAddress = i.caller | |
440 | - | let treasuryValue = calcTreasuryValue(factoryAddress) | |
476 | + | let treasuryValue = fromX18(calcTreasuryValue(factoryAddress), pow(10, 0, usdtDecimals, 0, 0, DOWN)) | |
441 | 477 | $Tuple2(nil, treasuryValue) | |
442 | 478 | } | |
443 | 479 |
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 7 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let separator = "__" | |
5 | - | ||
6 | 4 | let chainId = take(drop(this.bytes, 1), 1) | |
7 | 5 | ||
8 | 6 | let chainIdT = base58'2T' | |
9 | 7 | ||
10 | 8 | let chainIdW = base58'2W' | |
11 | - | ||
12 | - | func mustAddress (i,address) = if ((i.caller == address)) | |
13 | - | then true | |
14 | - | else throw("permission denied") | |
15 | - | ||
16 | - | ||
17 | - | func mustThis (i) = mustAddress(i, this) | |
18 | - | ||
19 | 9 | ||
20 | 10 | let SEP = "__" | |
21 | 11 | ||
22 | 12 | let WAVES = "WAVES" | |
23 | 13 | ||
24 | 14 | let contractFilename = "wxdao_calculator.ride" | |
25 | 15 | ||
26 | 16 | let mult8 = 100000000 | |
27 | 17 | ||
18 | + | let mult18 = toBigInt(1000000000000000000) | |
19 | + | ||
20 | + | let wavesDecimals = 8 | |
21 | + | ||
22 | + | let usdtDecimals = 6 | |
23 | + | ||
24 | + | func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), mult18, toBigInt(origScaleMult)) | |
25 | + | ||
26 | + | ||
27 | + | func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), mult18)) | |
28 | + | ||
29 | + | ||
28 | 30 | func wrapErr (s) = ((contractFilename + ": ") + s) | |
29 | 31 | ||
30 | 32 | ||
31 | 33 | func throwErr (s) = throw(wrapErr(s)) | |
32 | 34 | ||
35 | + | ||
36 | + | let wxAssetId = if ((chainId == chainIdW)) | |
37 | + | then base58'Atqv59EYzjFGuitKVnMRk6H8FukjoV3ktPorbEys25on' | |
38 | + | else if ((chainId == chainIdT)) | |
39 | + | then base58'EMAMLxDnv3xiz8RXg8Btj33jcEw3wLczL3JKYYmuubpc' | |
40 | + | else throwErr("invalid chain id") | |
33 | 41 | ||
34 | 42 | func keyCurrentPeriod () = makeString(["%s", "currentPeriod"], SEP) | |
35 | 43 | ||
36 | 44 | ||
37 | 45 | func keyStartHeightByPeriod (period) = makeString(["%s%d", "startHeight", toString(period)], SEP) | |
38 | 46 | ||
39 | 47 | ||
40 | 48 | func keyPeriodLength () = makeString(["%s", "periodLength"], SEP) | |
41 | 49 | ||
42 | 50 | ||
43 | 51 | func keyTreasuryValueByPeriod (period) = makeString(["%s%d", "treasuryValue", toString(period)], SEP) | |
52 | + | ||
53 | + | ||
54 | + | func keySkinTotal (treasuryAddress) = ("skin_total_" + toString(treasuryAddress)) | |
44 | 55 | ||
45 | 56 | ||
46 | 57 | func keyPowerConfigAddress () = "%s__powerConfigAddress" | |
47 | 58 | ||
48 | 59 | ||
49 | 60 | func powerConfigAddress (factoryAddress) = valueOrErrorMessage(match getString(factoryAddress, keyPowerConfigAddress()) { | |
50 | 61 | case s: String => | |
51 | 62 | addressFromString(s) | |
52 | 63 | case _: Unit => | |
53 | 64 | unit | |
54 | 65 | case _ => | |
55 | 66 | throw("Match error") | |
56 | 67 | }, wrapErr("invalid power config address")) | |
57 | 68 | ||
58 | 69 | ||
59 | 70 | func keyPowerAssetId () = "powerAssetId" | |
60 | 71 | ||
61 | 72 | ||
62 | 73 | func getPowerAssetId (factoryAddress) = fromBase58String(valueOrErrorMessage(getString(powerConfigAddress(factoryAddress), keyPowerAssetId()), wrapErr("invalid power asset id"))) | |
63 | 74 | ||
64 | 75 | ||
65 | 76 | func keyPowerContractAddress () = "%s__powerContractAddress" | |
66 | 77 | ||
67 | 78 | ||
68 | 79 | func powerContractAddress (factoryAddress) = valueOrErrorMessage(match getString(factoryAddress, keyPowerContractAddress()) { | |
69 | 80 | case s: String => | |
70 | 81 | addressFromString(s) | |
71 | 82 | case _: Unit => | |
72 | 83 | unit | |
73 | 84 | case _ => | |
74 | 85 | throw("Match error") | |
75 | 86 | }, wrapErr("invalid power contract address")) | |
76 | 87 | ||
77 | 88 | ||
78 | 89 | func keyPoolsFactoryAddress () = "%s__poolsFactoryAddress" | |
79 | 90 | ||
80 | 91 | ||
81 | 92 | func getPoolsFactoryAddress (factoryAddress) = valueOrErrorMessage(match getString(factoryAddress, keyPoolsFactoryAddress()) { | |
82 | 93 | case s: String => | |
83 | 94 | addressFromString(s) | |
84 | 95 | case _: Unit => | |
85 | 96 | unit | |
86 | 97 | case _ => | |
87 | 98 | throw("Match error") | |
88 | 99 | }, wrapErr("invalid pools factory address")) | |
89 | 100 | ||
90 | 101 | ||
91 | 102 | func keyTreasuryAddress () = "%s__treasuryAddress" | |
92 | 103 | ||
93 | 104 | ||
94 | 105 | func getTreasuryAddress (factoryAddress) = valueOrErrorMessage(match getString(factoryAddress, keyTreasuryAddress()) { | |
95 | 106 | case s: String => | |
96 | 107 | addressFromString(s) | |
97 | 108 | case _: Unit => | |
98 | 109 | unit | |
99 | 110 | case _ => | |
100 | 111 | throw("Match error") | |
101 | 112 | }, wrapErr("invalid treasury address")) | |
102 | 113 | ||
103 | 114 | ||
104 | 115 | func keyAssets () = "%s__assets" | |
105 | 116 | ||
106 | 117 | ||
107 | 118 | func getAssetsStr (factoryAddress) = valueOrErrorMessage(getString(factoryAddress, keyAssets()), wrapErr("invalid assets")) | |
108 | 119 | ||
109 | 120 | ||
110 | 121 | func keyLpAssetId () = "%s__lpAssetId" | |
111 | 122 | ||
112 | 123 | ||
113 | 124 | func getLpAssetId (factoryAddress) = fromBase58String(valueOrErrorMessage(getString(factoryAddress, keyLpAssetId()), wrapErr("invalid lp asset id"))) | |
114 | 125 | ||
115 | 126 | ||
127 | + | func getAssetInfoOrFail (assetId) = valueOrErrorMessage(assetInfo(assetId), wrapErr("invalid asset info")) | |
128 | + | ||
129 | + | ||
116 | 130 | func getAssetsBalances (targetAddress,assetIdList) = { | |
117 | 131 | func map (acc,nextAssetIdStr) = { | |
118 | 132 | let balance = if ((nextAssetIdStr == WAVES)) | |
119 | - | then wavesBalance(targetAddress) | |
120 | - | else assetBalance(targetAddress, fromBase58String(nextAssetIdStr)) | |
133 | + | then toX18(wavesBalance(targetAddress).available, pow(10, 0, wavesDecimals, 0, 0, DOWN)) | |
134 | + | else { | |
135 | + | let assetId = fromBase58String(nextAssetIdStr) | |
136 | + | let assetDecimals = getAssetInfoOrFail(assetId).decimals | |
137 | + | toX18(assetBalance(targetAddress, assetId), pow(10, 0, assetDecimals, 0, 0, DOWN)) | |
138 | + | } | |
121 | 139 | (acc :+ balance) | |
122 | 140 | } | |
123 | 141 | ||
124 | 142 | let $l = assetIdList | |
125 | 143 | let $s = size($l) | |
126 | 144 | let $acc0 = nil | |
127 | 145 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
128 | 146 | then $a | |
129 | 147 | else map($a, $l[$i]) | |
130 | 148 | ||
131 | 149 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
132 | 150 | then $a | |
133 | 151 | else throw("List size exceeds 10") | |
134 | 152 | ||
135 | 153 | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) | |
136 | 154 | } | |
137 | 155 | ||
138 | 156 | ||
139 | 157 | func getAssetsPrices (poolsFactoryAddress,assetIdList) = if ((chainId == chainIdW)) | |
140 | 158 | then { | |
141 | 159 | let wavesUsdtAddressStr = "3PKfrupEydU2nZAghVjZAfvCwMBkzuR1F52" | |
142 | - | let wavesUsdtPrice = { | |
160 | + | let wavesUsdtPrice = parseBigIntValue({ | |
143 | 161 | let @ = invoke(poolsFactoryAddress, "getPrice", [wavesUsdtAddressStr], nil) | |
144 | - | if ($isInstanceOf(@, " | |
162 | + | if ($isInstanceOf(@, "String")) | |
145 | 163 | then @ | |
146 | - | else throw(($getType(@) + " couldn't be cast to | |
147 | - | } | |
164 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
165 | + | }) | |
148 | 166 | let wavesXtnAddressStr = "3PPZWgFNRKHLvM51pwS934C8VZ7d2F4Z58g" | |
149 | - | let wavesXtnPrice = { | |
167 | + | let wavesXtnPrice = parseBigIntValue({ | |
150 | 168 | let @ = invoke(poolsFactoryAddress, "getPrice", [wavesXtnAddressStr], nil) | |
151 | - | if ($isInstanceOf(@, " | |
169 | + | if ($isInstanceOf(@, "String")) | |
152 | 170 | then @ | |
153 | - | else throw(($getType(@) + " couldn't be cast to | |
154 | - | } | |
155 | - | let xtnUsdtPrice = fraction(wavesUsdtPrice, | |
171 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
172 | + | }) | |
173 | + | let xtnUsdtPrice = fraction(wavesUsdtPrice, mult18, wavesXtnPrice) | |
156 | 174 | func map (acc,nextAssetId) = { | |
157 | 175 | let price = match nextAssetId { | |
158 | 176 | case _ => | |
159 | 177 | if (("2thsACuHmzDMuNezPM32wg9a3BwUzBWDeSKakgz3cw21" == $match0)) | |
160 | 178 | then { | |
161 | 179 | let pwrWavesAddressStr = "3PDi7Qq8pLQYvtKyTfQuqqPUWyhoYbU957t" | |
162 | - | let pwrWavesPrice = { | |
180 | + | let pwrWavesPrice = parseBigIntValue({ | |
163 | 181 | let @ = invoke(poolsFactoryAddress, "getPrice", [pwrWavesAddressStr], nil) | |
164 | - | if ($isInstanceOf(@, " | |
182 | + | if ($isInstanceOf(@, "String")) | |
165 | 183 | then @ | |
166 | - | else throw(($getType(@) + " couldn't be cast to | |
167 | - | } | |
168 | - | fraction(pwrWavesPrice, wavesUsdtPrice, | |
184 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
185 | + | }) | |
186 | + | fraction(pwrWavesPrice, wavesUsdtPrice, mult18) | |
169 | 187 | } | |
170 | 188 | else if (("Atqv59EYzjFGuitKVnMRk6H8FukjoV3ktPorbEys25on" == $match0)) | |
171 | 189 | then { | |
172 | 190 | let wxWavesAddressStr = "3PFzaH2ghpwANHFgjeva83N1yxzErELx2eh" | |
173 | - | let wxWavesPrice = { | |
191 | + | let wxWavesPrice = parseBigIntValue({ | |
174 | 192 | let @ = invoke(poolsFactoryAddress, "getPrice", [wxWavesAddressStr], nil) | |
175 | - | if ($isInstanceOf(@, " | |
193 | + | if ($isInstanceOf(@, "String")) | |
176 | 194 | then @ | |
177 | - | else throw(($getType(@) + " couldn't be cast to | |
178 | - | } | |
179 | - | fraction(wxWavesPrice, wavesUsdtPrice, | |
195 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
196 | + | }) | |
197 | + | fraction(wxWavesPrice, wavesUsdtPrice, mult18) | |
180 | 198 | } | |
181 | 199 | else if (("34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ" == $match0)) | |
182 | 200 | then { | |
183 | - | let | |
184 | - | let | |
185 | - | let @ = invoke(poolsFactoryAddress, "getPrice", [ | |
186 | - | if ($isInstanceOf(@, " | |
201 | + | let wavesUsdtwxgAddressStr = "3PKMVZ7kQeaREajYi8Yc25Ro6mcNw5D6QSa" | |
202 | + | let wavesUsdtwxgPrice = parseBigIntValue({ | |
203 | + | let @ = invoke(poolsFactoryAddress, "getPrice", [wavesUsdtwxgAddressStr], nil) | |
204 | + | if ($isInstanceOf(@, "String")) | |
187 | 205 | then @ | |
188 | - | else throw(($getType(@) + " couldn't be cast to | |
189 | - | } | |
190 | - | fraction( | |
206 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
207 | + | }) | |
208 | + | fraction(wavesUsdtPrice, mult18, wavesUsdtwxgPrice) | |
191 | 209 | } | |
192 | 210 | else if (("6XtHjpXbs9RRJP2Sr9GUyVqzACcby9TkThHXnjVC5CDJ" == $match0)) | |
193 | 211 | then { | |
194 | 212 | let wavesUsdcwxgAddressStr = "3P3g3eipfG2NZKKQE8DZXt2E9tRJqii9jcX" | |
195 | - | let | |
213 | + | let wavesUsdcwxgPrice = parseBigIntValue({ | |
196 | 214 | let @ = invoke(poolsFactoryAddress, "getPrice", [wavesUsdcwxgAddressStr], nil) | |
197 | - | if ($isInstanceOf(@, " | |
215 | + | if ($isInstanceOf(@, "String")) | |
198 | 216 | then @ | |
199 | - | else throw(($getType(@) + " couldn't be cast to | |
200 | - | } | |
201 | - | fraction(wavesUsdtPrice, | |
217 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
218 | + | }) | |
219 | + | fraction(wavesUsdtPrice, mult18, wavesUsdcwxgPrice) | |
202 | 220 | } | |
203 | 221 | else if (("HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk" == $match0)) | |
204 | 222 | then { | |
205 | 223 | let ltcwxgXtnAddressStr = "3P94wvu5gA7VhjPgAB3twaeqdwHCwNK2vsn" | |
206 | - | let ltcwxgXtnPrice = { | |
224 | + | let ltcwxgXtnPrice = parseBigIntValue({ | |
207 | 225 | let @ = invoke(poolsFactoryAddress, "getPrice", [ltcwxgXtnAddressStr], nil) | |
208 | - | if ($isInstanceOf(@, " | |
226 | + | if ($isInstanceOf(@, "String")) | |
209 | 227 | then @ | |
210 | - | else throw(($getType(@) + " couldn't be cast to Int")) | |
228 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
229 | + | }) | |
230 | + | fraction(ltcwxgXtnPrice, xtnUsdtPrice, mult18) | |
231 | + | } | |
232 | + | else if (("474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu" == $match0)) | |
233 | + | then { | |
234 | + | let ethwxgWavesAddressStr = "3P3XGTN6s292g9iwYhs3TEqJqHiffQYojuE" | |
235 | + | let ethwxgWavesPrice = parseBigIntValue({ | |
236 | + | let @ = invoke(poolsFactoryAddress, "getPrice", [ethwxgWavesAddressStr], nil) | |
237 | + | if ($isInstanceOf(@, "String")) | |
238 | + | then @ | |
239 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
240 | + | }) | |
241 | + | fraction(ethwxgWavesPrice, wavesUsdtPrice, mult18) | |
211 | 242 | } | |
212 | - | fraction(ltcwxgXtnPrice, xtnUsdtPrice, mult8) | |
213 | - | } | |
214 | - | else if (("HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk" == $match0)) | |
215 | - | then { | |
216 | - | let ethwxgXtnAddressStr = "3P3XGTN6s292g9iwYhs3TEqJqHiffQYojuE" | |
217 | - | let ethwxgXtnPrice = { | |
218 | - | let @ = invoke(poolsFactoryAddress, "getPrice", [ethwxgXtnAddressStr], nil) | |
219 | - | if ($isInstanceOf(@, "Int")) | |
220 | - | then @ | |
221 | - | else throw(($getType(@) + " couldn't be cast to Int")) | |
222 | - | } | |
223 | - | fraction(ethwxgXtnPrice, wavesUsdtPrice, mult8) | |
224 | - | } | |
225 | - | else if (("HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk" == $match0)) | |
243 | + | else if (("8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS" == $match0)) | |
226 | 244 | then { | |
227 | 245 | let btcwxgXtnAddressStr = "3PCBWDTA6jrFswd7gQgaE3Xk7gLM5RKofvp" | |
228 | - | let btcwxgXtnPrice = { | |
246 | + | let btcwxgXtnPrice = parseBigIntValue({ | |
229 | 247 | let @ = invoke(poolsFactoryAddress, "getPrice", [btcwxgXtnAddressStr], nil) | |
230 | - | if ($isInstanceOf(@, " | |
248 | + | if ($isInstanceOf(@, "String")) | |
231 | 249 | then @ | |
232 | - | else throw(($getType(@) + " couldn't be cast to | |
233 | - | } | |
234 | - | fraction(btcwxgXtnPrice, | |
250 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
251 | + | }) | |
252 | + | fraction(btcwxgXtnPrice, xtnUsdtPrice, mult18) | |
235 | 253 | } | |
236 | 254 | else throwErr("invalid asset id") | |
237 | 255 | } | |
238 | 256 | (acc :+ price) | |
239 | 257 | } | |
240 | 258 | ||
241 | 259 | let $l = assetIdList | |
242 | 260 | let $s = size($l) | |
243 | 261 | let $acc0 = nil | |
244 | 262 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
245 | 263 | then $a | |
246 | 264 | else map($a, $l[$i]) | |
247 | 265 | ||
248 | 266 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
249 | 267 | then $a | |
250 | 268 | else throw("List size exceeds 10") | |
251 | 269 | ||
252 | 270 | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) | |
253 | 271 | } | |
254 | 272 | else if ((chainId == chainIdT)) | |
255 | 273 | then { | |
256 | 274 | func map (acc,nextAssetId) = { | |
257 | 275 | let price = match nextAssetId { | |
258 | 276 | case _ => | |
259 | 277 | if (("EMAMLxDnv3xiz8RXg8Btj33jcEw3wLczL3JKYYmuubpc" == $match0)) | |
260 | 278 | then { | |
261 | 279 | let wxUsdtAddressStr = "3MrULQRLc52GWrJF1tMcAm4M78fPe57o9Kt" | |
262 | - | let wxUsdtPrice = { | |
280 | + | let wxUsdtPrice = parseBigIntValue({ | |
263 | 281 | let @ = invoke(poolsFactoryAddress, "getPrice", [wxUsdtAddressStr], nil) | |
264 | - | if ($isInstanceOf(@, " | |
282 | + | if ($isInstanceOf(@, "String")) | |
265 | 283 | then @ | |
266 | - | else throw(($getType(@) + " couldn't be cast to | |
267 | - | } | |
284 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
285 | + | }) | |
268 | 286 | wxUsdtPrice | |
269 | 287 | } | |
270 | 288 | else if (("A7Ksh7fXyqm1KhKAiK3bAB2aiPSitQQF6v1pyu9SS3FR" == $match0)) | |
271 | 289 | then { | |
272 | 290 | let usdcUsdtAddressStr = "3MzKSdTH2jFbypLsoNfrH7QgkzSbx3EYwCA" | |
273 | - | let usdcUsdtPrice = { | |
291 | + | let usdcUsdtPrice = parseBigIntValue({ | |
274 | 292 | let @ = invoke(poolsFactoryAddress, "getPrice", [usdcUsdtAddressStr], nil) | |
275 | - | if ($isInstanceOf(@, " | |
293 | + | if ($isInstanceOf(@, "String")) | |
276 | 294 | then @ | |
277 | - | else throw(($getType(@) + " couldn't be cast to | |
278 | - | } | |
295 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
296 | + | }) | |
279 | 297 | usdcUsdtPrice | |
280 | 298 | } | |
281 | 299 | else if (("8Q6SE2ANebufw8JuPjJVRjZD6drD8ihjNjM8xaGUSfdR" == $match0)) | |
282 | 300 | then { | |
283 | 301 | let price = 100000000 | |
284 | 302 | price | |
285 | 303 | } | |
286 | 304 | else throwErr("invalid asset id") | |
287 | 305 | } | |
288 | 306 | (acc :+ price) | |
289 | 307 | } | |
290 | 308 | ||
291 | 309 | let $l = assetIdList | |
292 | 310 | let $s = size($l) | |
293 | 311 | let $acc0 = nil | |
294 | 312 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
295 | 313 | then $a | |
296 | 314 | else map($a, $l[$i]) | |
297 | 315 | ||
298 | 316 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
299 | 317 | then $a | |
300 | 318 | else throw("List size exceeds 10") | |
301 | 319 | ||
302 | 320 | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) | |
303 | 321 | } | |
304 | 322 | else throwErr("invalid chain id") | |
305 | 323 | ||
306 | 324 | ||
307 | 325 | func calcTreasuryValue (factoryAddress) = { | |
308 | 326 | let treasuryAddress = getTreasuryAddress(factoryAddress) | |
309 | 327 | let poolsFactoryAddress = getPoolsFactoryAddress(factoryAddress) | |
310 | 328 | let assetsStr = split(getAssetsStr(factoryAddress), SEP) | |
311 | 329 | let assetsBalances = getAssetsBalances(treasuryAddress, assetsStr) | |
312 | 330 | let assetsPrices = getAssetsPrices(poolsFactoryAddress, assetsStr) | |
313 | 331 | func reduce (acc,nextAssetIdStr) = { | |
314 | 332 | let assetId = fromBase58String(nextAssetIdStr) | |
315 | 333 | let index = valueOrErrorMessage(indexOf(assetsStr, nextAssetIdStr), wrapErr("invalid asset id")) | |
316 | 334 | let balance = assetsBalances[index] | |
317 | 335 | let price = assetsPrices[index] | |
318 | - | let assetValue = fraction(balance, price, | |
336 | + | let assetValue = fraction(balance, price, mult18) | |
319 | 337 | (acc + assetValue) | |
320 | 338 | } | |
321 | 339 | ||
322 | 340 | let treasuryValue = { | |
323 | 341 | let $l = assetsStr | |
324 | 342 | let $s = size($l) | |
325 | - | let $acc0 = 0 | |
343 | + | let $acc0 = toBigInt(0) | |
326 | 344 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
327 | 345 | then $a | |
328 | 346 | else reduce($a, $l[$i]) | |
329 | 347 | ||
330 | 348 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
331 | 349 | then $a | |
332 | 350 | else throw("List size exceeds 10") | |
333 | 351 | ||
334 | 352 | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) | |
335 | 353 | } | |
336 | 354 | treasuryValue | |
337 | 355 | } | |
338 | 356 | ||
339 | 357 | ||
340 | 358 | @Callable(i) | |
341 | 359 | func withdraw (args) = { | |
342 | 360 | let recipient = addressFromStringValue(args[0]) | |
343 | 361 | let amount = parseIntValue(args[1]) | |
344 | 362 | let result = invoke(i.caller, "transferWaves", [recipient.bytes, amount], nil) | |
345 | 363 | $Tuple2(nil, result) | |
346 | 364 | } | |
347 | 365 | ||
348 | 366 | ||
349 | 367 | ||
350 | 368 | @Callable(i) | |
351 | 369 | func setIntParam (args) = { | |
352 | 370 | let key = args[0] | |
353 | 371 | let val = parseIntValue(args[1]) | |
354 | 372 | let result = invoke(i.caller, "integerEntry", [key, val], nil) | |
355 | 373 | $Tuple2(nil, result) | |
356 | 374 | } | |
357 | 375 | ||
358 | 376 | ||
359 | 377 | ||
360 | 378 | @Callable(i) | |
361 | 379 | func swap (callerPublicKey,args) = { | |
362 | 380 | let factoryAddress = i.caller | |
363 | 381 | let userAddress = addressFromPublicKey(callerPublicKey) | |
364 | 382 | let payment = if ((size(i.payments) == 1)) | |
365 | 383 | then i.payments[0] | |
366 | 384 | else throwErr("1 payment is required") | |
367 | 385 | let err = wrapErr("invalid payment asset id") | |
368 | 386 | let paymentAssetId = if ((valueOrErrorMessage(payment.assetId, err) == getLpAssetId(factoryAddress))) | |
369 | 387 | then value(payment.assetId) | |
370 | 388 | else throwErr(err) | |
371 | 389 | let pwrPrice = 100 | |
372 | 390 | let pwrAmount = (payment.amount / pwrPrice) | |
373 | 391 | let assetsStr = split(getAssetsStr(factoryAddress), SEP) | |
374 | 392 | let pwrBalance = assetBalance(factoryAddress, getPowerAssetId(factoryAddress)) | |
375 | 393 | if ((pwrBalance == pwrBalance)) | |
376 | 394 | then { | |
377 | - | let treasuryAddress = getTreasuryAddress(factoryAddress) | |
378 | - | let assetsBalances = getAssetsBalances(treasuryAddress, assetsStr) | |
379 | - | func map (acc,nextAssetIdStr) = { | |
380 | - | let assetId = fromBase58String(nextAssetIdStr) | |
381 | - | let index = valueOrErrorMessage(indexOf(assetsStr, nextAssetIdStr), wrapErr("invalid asset balance")) | |
382 | - | let balance = assetsBalances[index] | |
383 | - | let amount = fraction(balance, pwrAmount, pwrBalance) | |
384 | - | if ((amount > 0)) | |
385 | - | then $Tuple2((acc._1 :+ assetId), (acc._2 :+ amount)) | |
386 | - | else acc | |
387 | - | } | |
395 | + | let wxdaoQuantity = getAssetInfoOrFail(getLpAssetId(factoryAddress)).quantity | |
396 | + | if ((wxdaoQuantity == wxdaoQuantity)) | |
397 | + | then { | |
398 | + | let assetsBalances = getAssetsBalances(factoryAddress, assetsStr) | |
399 | + | func map (acc,nextAssetIdStr) = { | |
400 | + | let assetId = fromBase58String(nextAssetIdStr) | |
401 | + | let index = valueOrErrorMessage(indexOf(assetsStr, nextAssetIdStr), wrapErr("invalid asset balance")) | |
402 | + | let assetDecimals = getAssetInfoOrFail(assetId).decimals | |
403 | + | let balance = fromX18(assetsBalances[index], pow(10, 0, assetDecimals, 0, 0, DOWN)) | |
404 | + | let amount = fraction(balance, payment.amount, wxdaoQuantity) | |
405 | + | if ((amount > 0)) | |
406 | + | then $Tuple2((acc._1 :+ assetId), (acc._2 :+ amount)) | |
407 | + | else acc | |
408 | + | } | |
388 | 409 | ||
389 | - | let transfers = { | |
390 | - | let $l = assetsStr | |
391 | - | let $s = size($l) | |
392 | - | let $acc0 = $Tuple2(nil, nil) | |
393 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
394 | - | then $a | |
395 | - | else map($a, $l[$i]) | |
410 | + | let transfers = { | |
411 | + | let $l = assetsStr | |
412 | + | let $s = size($l) | |
413 | + | let $acc0 = $Tuple2(nil, nil) | |
414 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
415 | + | then $a | |
416 | + | else map($a, $l[$i]) | |
396 | 417 | ||
397 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
398 | - | then $a | |
399 | - | else throw("List size exceeds 6") | |
418 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
419 | + | then $a | |
420 | + | else throw("List size exceeds 6") | |
400 | 421 | ||
401 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6) | |
402 | - | } | |
403 | - | if ((transfers == transfers)) | |
404 | - | then { | |
405 | - | let additionalLockRounds = 0 | |
406 | - | let factoryActions = ([invoke(factoryAddress, "commitAfterStartWithLockRoundFor", [toString(powerContractAddress(factoryAddress)), toString(factoryAddress), toString(userAddress), additionalLockRounds, getPowerAssetId(factoryAddress), pwrAmount], nil)] ++ (if ((size(transfers._1) == 0)) | |
407 | - | then nil | |
408 | - | else [invoke(factoryAddress, "transferAssets", [userAddress.bytes, transfers._1, transfers._2], nil)])) | |
409 | - | $Tuple2([Burn(paymentAssetId, payment.amount)], factoryActions) | |
422 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6) | |
423 | + | } | |
424 | + | if ((transfers == transfers)) | |
425 | + | then { | |
426 | + | let additionalLockRounds = 0 | |
427 | + | let factoryActions = ([invoke(factoryAddress, "commitAfterStartWithLockRoundFor", [toString(powerContractAddress(factoryAddress)), toString(factoryAddress), toString(userAddress), additionalLockRounds, getPowerAssetId(factoryAddress), pwrAmount], nil)] ++ (if ((size(transfers._1) == 0)) | |
428 | + | then nil | |
429 | + | else [invoke(factoryAddress, "transferAssets", [userAddress.bytes, transfers._1, transfers._2], nil)])) | |
430 | + | $Tuple2([Burn(paymentAssetId, payment.amount)], factoryActions) | |
431 | + | } | |
432 | + | else throw("Strict value is not equal to itself.") | |
410 | 433 | } | |
411 | 434 | else throw("Strict value is not equal to itself.") | |
412 | 435 | } | |
413 | 436 | else throw("Strict value is not equal to itself.") | |
414 | 437 | } | |
415 | 438 | ||
416 | 439 | ||
417 | 440 | ||
418 | 441 | @Callable(i) | |
419 | 442 | func price (callerPublicKey,args) = { | |
420 | 443 | let factoryAddress = i.caller | |
444 | + | let poolsFactoryAddress = getPoolsFactoryAddress(factoryAddress) | |
421 | 445 | let currentPeriod = valueOrErrorMessage(getInteger(factoryAddress, keyCurrentPeriod()), wrapErr("invalid current period")) | |
422 | 446 | let startTreasuryValue = valueOrErrorMessage(getInteger(factoryAddress, keyTreasuryValueByPeriod(currentPeriod)), wrapErr(("invalid treasury value for period " + toString(currentPeriod)))) | |
423 | - | let treasuryValue = calcTreasuryValue(factoryAddress) | |
447 | + | let treasuryValue = fromX18(calcTreasuryValue(factoryAddress), pow(10, 0, usdtDecimals, 0, 0, DOWN)) | |
424 | 448 | let treasuryValueDiff = (treasuryValue - startTreasuryValue) | |
425 | - | let pwrPriceRaw = getAssetsPrices(factoryAddress, [toBase58String(getPowerAssetId(factoryAddress))])[0] | |
426 | - | let pwrPrice = if ((pwrPriceRaw > 0)) | |
427 | - | then pwrPriceRaw | |
449 | + | let pwrAssetId = getPowerAssetId(factoryAddress) | |
450 | + | let pwrPriceRaw = getAssetsPrices(poolsFactoryAddress, [toBase58String(pwrAssetId)])[0] | |
451 | + | let pwrPrice = if ((pwrPriceRaw > toBigInt(0))) | |
452 | + | then fromX18(pwrPriceRaw, pow(10, 0, usdtDecimals, 0, 0, DOWN)) | |
428 | 453 | else throwErr("invalid PWR price") | |
429 | - | let price = if ((0 > treasuryValueDiff)) | |
430 | - | then (pwrPrice / 100) | |
431 | - | else ((fraction(treasuryValueDiff, 2, 10000) + pwrPrice) / 100) | |
454 | + | let treasuryAddress = getTreasuryAddress(factoryAddress) | |
455 | + | let skinTotal = valueOrElse(getInteger(powerContractAddress(factoryAddress), keySkinTotal(treasuryAddress)), 0) | |
456 | + | let pwrRemaining = (getAssetInfoOrFail(getLpAssetId(factoryAddress)).quantity / 100) | |
457 | + | let pwrAmount = (skinTotal + pwrRemaining) | |
458 | + | let factoryAddressWxBalanceRaw = getAssetsBalances(factoryAddress, [toBase58String(getLpAssetId(factoryAddress))])[0] | |
459 | + | let factoryAddressWxBalance = if ((factoryAddressWxBalanceRaw > toBigInt(0))) | |
460 | + | then fromX18(factoryAddressWxBalanceRaw, pow(10, 0, usdtDecimals, 0, 0, DOWN)) | |
461 | + | else throwErr("invalid factory wx balance") | |
462 | + | let wxPriceRaw = getAssetsPrices(poolsFactoryAddress, [toBase58String(wxAssetId)])[0] | |
463 | + | let wxPrice = if ((wxPriceRaw > toBigInt(0))) | |
464 | + | then fromX18(wxPriceRaw, pow(10, 0, usdtDecimals, 0, 0, DOWN)) | |
465 | + | else throwErr("invalid wx price") | |
466 | + | let wxdaoQuantity = getAssetInfoOrFail(getLpAssetId(factoryAddress)).quantity | |
467 | + | let price = (((pwrPrice / 100) + fraction(factoryAddressWxBalance, wxPrice, wxdaoQuantity)) + fraction(max([treasuryValueDiff, 0]), 2, (1000 * pwrAmount))) | |
432 | 468 | $Tuple2(nil, price) | |
433 | 469 | } | |
434 | 470 | ||
435 | 471 | ||
436 | 472 | ||
437 | 473 | @Callable(i) | |
438 | 474 | func getTreasuryValue (callerPublicKey,args) = { | |
439 | 475 | let factoryAddress = i.caller | |
440 | - | let treasuryValue = calcTreasuryValue(factoryAddress) | |
476 | + | let treasuryValue = fromX18(calcTreasuryValue(factoryAddress), pow(10, 0, usdtDecimals, 0, 0, DOWN)) | |
441 | 477 | $Tuple2(nil, treasuryValue) | |
442 | 478 | } | |
443 | 479 | ||
444 | 480 | ||
445 | 481 | @Verifier(tx) | |
446 | 482 | func verify () = (chainId == chainIdT) | |
447 | 483 |
github/deemru/w8io/026f985 84.38 ms ◑