tx · 3gkiUP4uBC5Q43keN7qzcHjCrUHvC1GRFYqASPfQeJjS 3MsXwm6KeMva32skLvFrFfYYmcxT2ZDc4fD: -0.03100000 Waves 2022.12.16 12:28 [2362678] smart account 3MsXwm6KeMva32skLvFrFfYYmcxT2ZDc4fD > SELF 0.00000000 Waves
{ "type": 13, "id": "3gkiUP4uBC5Q43keN7qzcHjCrUHvC1GRFYqASPfQeJjS", "fee": 3100000, "feeAssetId": null, "timestamp": 1671182900377, "version": 1, "sender": "3MsXwm6KeMva32skLvFrFfYYmcxT2ZDc4fD", "senderPublicKey": "33aHdznSeq5cGxgbnLJ54tzNfiqS5SCQYHgFGMFsNQzs", "proofs": [ "1pZS2NsbsQavmqFLpxom4QAbzDsvtMfo6fby4MLbYoZsyf7WTLgsYLswQPtVpzZr1RYrDjB71Vuwsqnx2Bqfo86" ], "script": "base64:BgK3JwgCEgMKAQgSABIECgIBBBIDCgEBEgQKAgEEEgQKAggBEgQKAggBEgQKAggBEgUKAwEIARIAEgQKAgEBEgMKAQESBQoDAQEBEgQKAggIEgASAwoBCBIFCgMBAQESBAoCAQESBAoCCAESBAoCCAgSCwoJCAEBAgECCAQEEgYKBAgIAQgSABIDCgEBEgMKAQESBAoCCAEiCmxQZGVjaW1hbHMiBnNjYWxlOCIMc2NhbGU4QmlnSW50IgdzY2FsZTE4Igp6ZXJvQmlnSW50IgRiaWcwIgRiaWcxIgRiaWcyIgt3YXZlc1N0cmluZyIDU0VQIgpQb29sQWN0aXZlIg9Qb29sUHV0RGlzYWJsZWQiE1Bvb2xNYXRjaGVyRGlzYWJsZWQiDFBvb2xTaHV0ZG93biIOaWR4UG9vbEFkZHJlc3MiDWlkeFBvb2xTdGF0dXMiEGlkeFBvb2xMUEFzc2V0SWQiDWlkeEFtdEFzc2V0SWQiD2lkeFByaWNlQXNzZXRJZCIOaWR4QW10QXNzZXREY20iEGlkeFByaWNlQXNzZXREY20iDmlkeElBbXRBc3NldElkIhBpZHhJUHJpY2VBc3NldElk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5dGVzCQCRAwIIBQJjUgZwcm9vZnMAAAgFAmNSD3NlbmRlclB1YmxpY0tleQQCYXQJAPQDAwgFAmNSCWJvZHlCeXRlcwkAkQMCCAUCY1IGcHJvb2ZzAAEFAmZMAwMDBQJhcgUCYXMHBQJhdAcGCQECYXEDBQJhcgUCYXMFAmF0AwkAAQIFAmRxAhRTZXRTY3JpcHRUcmFuc2FjdGlvbgQCZXcFAmRxBAJmTQkA9gMBCQEFdmFsdWUBCAUCZXcGc2NyaXB0BAJmTgkA2wQBCQEFdmFsdWUBCQCdCAIFAmFBCQECYW8ABAJmTwkA8QcBBQR0aGlzAwMJAAACBQJmTgUCZk0JAQIhPQIFAmZPBQJmTQcGCQD0AwMIBQJmSQlib2R5Qnl0ZXMJAJEDAggFAmZJBnByb29mcwAABQJmSwkA9AMDCAUCZkkJYm9keUJ5dGVzCQCRAwIIBQJmSQZwcm9vZnMAAAUCZkvBwFdz", "chainId": 84, "height": 2362678, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 297mULSKcXirBuXP6qvrcRoBHxdZHF4KNdJCsn4UnLk9 Next: C9RvPY8R39YDVHCCtewwy8P5o9VMw4qxLiTsK7jCcN9c Diff:
Old | New | Differences | |
---|---|---|---|
65 | 65 | func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18)) | |
66 | 66 | ||
67 | 67 | ||
68 | - | func fromX18Round (val,resultScaleMult,round) = toInt(fraction(val, toBigInt(resultScaleMult), scale18, round)) | |
69 | - | ||
70 | - | ||
71 | 68 | func toScale (amt,resScale,curScale) = fraction(amt, resScale, curScale) | |
72 | 69 | ||
73 | 70 | ||
108 | 105 | func pa () = "%s__priceAsset" | |
109 | 106 | ||
110 | 107 | ||
111 | - | let keyFee = "%s__fee" | |
112 | - | ||
113 | - | let feeDefault = fraction(10, scale8, 10000) | |
114 | - | ||
115 | - | let fee = valueOrElse(getInteger(this, keyFee), feeDefault) | |
116 | - | ||
117 | - | let keyKLp = makeString(["%s", "kLp"], SEP) | |
118 | - | ||
119 | - | let keyKLpRefreshedHeight = makeString(["%s", "kLpRefreshedHeight"], SEP) | |
120 | - | ||
121 | - | let keyKLpRefreshDelay = makeString(["%s", "refreshKLpDelay"], SEP) | |
122 | - | ||
123 | - | let kLpRefreshDelayDefault = 30 | |
124 | - | ||
125 | - | let kLpRefreshDelay = valueOrElse(getInteger(this, keyKLpRefreshDelay), kLpRefreshDelayDefault) | |
126 | - | ||
127 | 108 | func keyFactoryConfig () = "%s__factoryConfig" | |
128 | 109 | ||
129 | 110 | ||
162 | 143 | func throwErr (msg) = throw(makeString(["lp.ride:", msg], " ")) | |
163 | 144 | ||
164 | 145 | ||
165 | - | func fmtErr (msg) = makeString(["lp.ride:", msg], " ") | |
166 | - | ||
167 | - | ||
168 | 146 | let factoryContract = addressFromStringValue(getStringOrFail(this, fc())) | |
169 | 147 | ||
170 | 148 | let feeCollectorAddress = addressFromStringValue(getStringOrFail(factoryContract, keyFeeCollectorAddress)) | |
149 | + | ||
150 | + | let inFee = { | |
151 | + | let @ = invoke(factoryContract, "getInFeeREADONLY", [toString(this)], nil) | |
152 | + | if ($isInstanceOf(@, "Int")) | |
153 | + | then @ | |
154 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
155 | + | } | |
156 | + | ||
157 | + | let outFee = { | |
158 | + | let @ = invoke(factoryContract, "getOutFeeREADONLY", [toString(this)], nil) | |
159 | + | if ($isInstanceOf(@, "Int")) | |
160 | + | then @ | |
161 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
162 | + | } | |
171 | 163 | ||
172 | 164 | func isGlobalShutdown () = valueOrElse(getBoolean(factoryContract, keyAllPoolsShutdown()), false) | |
173 | 165 | ||
199 | 191 | ||
200 | 192 | let poolConfigParsed = parsePoolConfig(getPoolConfig()) | |
201 | 193 | ||
202 | - | let $ | |
194 | + | let $t076017767 = poolConfigParsed | |
203 | 195 | ||
204 | - | let cfgPoolAddress = $ | |
196 | + | let cfgPoolAddress = $t076017767._1 | |
205 | 197 | ||
206 | - | let cfgPoolStatus = $ | |
198 | + | let cfgPoolStatus = $t076017767._2 | |
207 | 199 | ||
208 | - | let cfgLpAssetId = $ | |
200 | + | let cfgLpAssetId = $t076017767._3 | |
209 | 201 | ||
210 | - | let cfgAmountAssetId = $ | |
202 | + | let cfgAmountAssetId = $t076017767._4 | |
211 | 203 | ||
212 | - | let cfgPriceAssetId = $ | |
204 | + | let cfgPriceAssetId = $t076017767._5 | |
213 | 205 | ||
214 | - | let cfgAmountAssetDecimals = $ | |
206 | + | let cfgAmountAssetDecimals = $t076017767._6 | |
215 | 207 | ||
216 | - | let cfgPriceAssetDecimals = $ | |
208 | + | let cfgPriceAssetDecimals = $t076017767._7 | |
217 | 209 | ||
218 | 210 | func getFactoryConfig () = split(getStringOrFail(factoryContract, keyFactoryConfig()), SEP) | |
219 | 211 | ||
234 | 226 | ||
235 | 227 | ||
236 | 228 | func calcPriceBigInt (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18) | |
237 | - | ||
238 | - | ||
239 | - | func calcPriceBigIntRound (prAmtX18,amAmtX18,round) = fraction(prAmtX18, scale18, amAmtX18, round) | |
240 | 229 | ||
241 | 230 | ||
242 | 231 | func privateCalcPrice (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
348 | 337 | then throw(((("Price slippage " + toString(slippageX18)) + " exceeded the passed limit of ") + toString(slippageToleranceX18))) | |
349 | 338 | else { | |
350 | 339 | let lpEmissionX18 = toX18(lpEmission, scale8) | |
351 | - | let prViaAmX18 = fraction(inAmAssetAmtX18, | |
352 | - | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, | |
340 | + | let prViaAmX18 = fraction(inAmAssetAmtX18, curPriceX18, scale18) | |
341 | + | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, curPriceX18) | |
353 | 342 | let expectedAmts = if ((prViaAmX18 > inPrAssetAmtX18)) | |
354 | 343 | then $Tuple2(amViaPrX18, inPrAssetAmtX18) | |
355 | 344 | else $Tuple2(inAmAssetAmtX18, prViaAmX18) | |
356 | 345 | let expAmtAssetAmtX18 = expectedAmts._1 | |
357 | 346 | let expPriceAssetAmtX18 = expectedAmts._2 | |
358 | - | let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18 | |
359 | - | $Tuple5( | |
347 | + | let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18) | |
348 | + | $Tuple5(fromX18(lpAmtX18, scale8), fromX18(expAmtAssetAmtX18, amtAssetDcm), fromX18(expPriceAssetAmtX18, priceAssetDcm), curPriceX18, slippageX18) | |
360 | 349 | } | |
361 | 350 | } | |
362 | 351 | let calcLpAmt = res._1 | |
379 | 368 | } | |
380 | 369 | ||
381 | 370 | ||
382 | - | func calcKLp (amountBalance,priceBalance,lpEmission) = { | |
383 | - | let updatedKLp = fraction(pow((amountBalance * priceBalance), 0, toBigInt(5), 1, 18, DOWN), big1, lpEmission) | |
384 | - | if ((lpEmission == big0)) | |
385 | - | then big0 | |
386 | - | else updatedKLp | |
387 | - | } | |
388 | - | ||
389 | - | ||
390 | - | func calcCurrentKLp (amountAssetDelta,priceAssetDelta,lpAssetEmissionDelta) = { | |
391 | - | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amountAssetDelta) | |
392 | - | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - priceAssetDelta) | |
393 | - | let lpAssetEmission = (toBigInt(value(assetInfo(cfgLpAssetId)).quantity) - lpAssetEmissionDelta) | |
394 | - | let currentKLp = calcKLp(amountAssetBalance, priceAssetBalance, lpAssetEmission) | |
395 | - | currentKLp | |
396 | - | } | |
397 | - | ||
398 | - | ||
399 | - | func refreshKLpInternal (amountAssetBalanceDelta,priceAssetBalanceDelta,lpAssetEmissionDelta) = { | |
400 | - | let amountAssetBalance = (getAccBalance(assetIdToString(cfgAmountAssetId)) + amountAssetBalanceDelta) | |
401 | - | let priceAssetBalance = (getAccBalance(assetIdToString(cfgPriceAssetId)) + priceAssetBalanceDelta) | |
402 | - | let lpAssetEmission = (value(assetInfo(cfgLpAssetId)).quantity + lpAssetEmissionDelta) | |
403 | - | let updatedKLp = calcKLp(toBigInt(amountAssetBalance), toBigInt(priceAssetBalance), toBigInt(lpAssetEmission)) | |
404 | - | let actions = [IntegerEntry(keyKLpRefreshedHeight, height), StringEntry(keyKLp, toString(updatedKLp))] | |
405 | - | $Tuple2(actions, updatedKLp) | |
406 | - | } | |
407 | - | ||
408 | - | ||
409 | - | func validateUpdatedKLp (oldKLp,updatedKLp) = if ((updatedKLp >= oldKLp)) | |
410 | - | then true | |
411 | - | else throwErr(makeString(["updated KLp lower than current KLp", toString(oldKLp), toString(updatedKLp)], " ")) | |
412 | - | ||
413 | - | ||
414 | 371 | func validateMatcherOrderAllowed (order) = { | |
415 | - | let amountAssetAmount = order.amount | |
416 | - | let priceAssetAmount = fraction(order.amount, order.price, scale8, FLOOR) | |
417 | - | let $t02077720989 = if ((order.orderType == Buy)) | |
418 | - | then $Tuple2(amountAssetAmount, -(priceAssetAmount)) | |
419 | - | else $Tuple2(-(amountAssetAmount), priceAssetAmount) | |
420 | - | let amountAssetBalanceDelta = $t02077720989._1 | |
421 | - | let priceAssetBalanceDelta = $t02077720989._2 | |
372 | + | let cfg = getPoolConfig() | |
373 | + | let amtAssetId = cfg[idxAmtAssetId] | |
374 | + | let priceAssetId = cfg[idxPriceAssetId] | |
375 | + | let poolStatus = parseIntValue(cfg[idxPoolStatus]) | |
376 | + | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
377 | + | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
378 | + | let accAmtAssetBalance = getAccBalance(amtAssetId) | |
379 | + | let accPriceAssetBalance = getAccBalance(priceAssetId) | |
380 | + | let curPriceX18 = if ((order.orderType == Buy)) | |
381 | + | then privateCalcPrice(amtAssetDcm, priceAssetDcm, (accAmtAssetBalance + order.amount), accPriceAssetBalance) | |
382 | + | else privateCalcPrice(amtAssetDcm, priceAssetDcm, (accAmtAssetBalance - order.amount), accPriceAssetBalance) | |
383 | + | let curPrice = fromX18(curPriceX18, scale8) | |
422 | 384 | if (if (if (isGlobalShutdown()) | |
423 | 385 | then true | |
424 | - | else ( | |
386 | + | else (poolStatus == PoolMatcherDisabled)) | |
425 | 387 | then true | |
426 | - | else ( | |
388 | + | else (poolStatus == PoolShutdown)) | |
427 | 389 | then throw("Exchange operations disabled") | |
428 | - | else if (if ((order.assetPair.amountAsset != cfgAmountAssetId)) | |
429 | - | then true | |
430 | - | else (order.assetPair.priceAsset != cfgPriceAssetId)) | |
431 | - | then throw("Wrong order assets.") | |
432 | - | else { | |
433 | - | let kLp = valueOrErrorMessage(parseBigInt(valueOrErrorMessage(getString(this, keyKLp), fmtErr("kLp is required"))), fmtErr("invalid kLp")) | |
434 | - | let $t02146021560 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
435 | - | let unusedActions = $t02146021560._1 | |
436 | - | let kLpNew = $t02146021560._2 | |
437 | - | let isOrderValid = (kLpNew >= kLp) | |
438 | - | isOrderValid | |
439 | - | } | |
390 | + | else { | |
391 | + | let orderAmtAsset = order.assetPair.amountAsset | |
392 | + | let orderAmtAssetStr = if ((orderAmtAsset == unit)) | |
393 | + | then "WAVES" | |
394 | + | else toBase58String(value(orderAmtAsset)) | |
395 | + | let orderPriceAsset = order.assetPair.priceAsset | |
396 | + | let orderPriceAssetStr = if ((orderPriceAsset == unit)) | |
397 | + | then "WAVES" | |
398 | + | else toBase58String(value(orderPriceAsset)) | |
399 | + | if (if ((orderAmtAssetStr != amtAssetId)) | |
400 | + | then true | |
401 | + | else (orderPriceAssetStr != priceAssetId)) | |
402 | + | then throw("Wrong order assets.") | |
403 | + | else { | |
404 | + | let orderPrice = order.price | |
405 | + | let priceDcm = fraction(scale8, priceAssetDcm, amtAssetDcm) | |
406 | + | let castedOrderPrice = toScale(orderPrice, scale8, priceDcm) | |
407 | + | let isOrderPriceValid = if ((order.orderType == Buy)) | |
408 | + | then (curPrice >= castedOrderPrice) | |
409 | + | else (castedOrderPrice >= curPrice) | |
410 | + | true | |
411 | + | } | |
412 | + | } | |
440 | 413 | } | |
441 | 414 | ||
442 | 415 | ||
494 | 467 | } | |
495 | 468 | ||
496 | 469 | ||
497 | - | func takeFee (amount) = { | |
498 | - | let feeAmount = fraction(amount, fee, scale8) | |
470 | + | func takeFee (amount,fee) = { | |
471 | + | let feeAmount = if ((fee == 0)) | |
472 | + | then 0 | |
473 | + | else fraction(amount, fee, scale8) | |
499 | 474 | $Tuple2((amount - feeAmount), feeAmount) | |
500 | 475 | } | |
501 | 476 | ||
509 | 484 | else if ((paymentAssetId == cfgPriceAssetId)) | |
510 | 485 | then false | |
511 | 486 | else throwErr("invalid asset") | |
512 | - | let $ | |
487 | + | let $t02266422957 = if (isEval) | |
513 | 488 | then $Tuple2(amountBalanceRaw, priceBalanceRaw) | |
514 | 489 | else if (paymentInAmountAsset) | |
515 | 490 | then $Tuple2((amountBalanceRaw - paymentAmountRaw), priceBalanceRaw) | |
516 | 491 | else $Tuple2(amountBalanceRaw, (priceBalanceRaw - paymentAmountRaw)) | |
517 | - | let amountBalanceOld = $ | |
518 | - | let priceBalanceOld = $ | |
519 | - | let $ | |
492 | + | let amountBalanceOld = $t02266422957._1 | |
493 | + | let priceBalanceOld = $t02266422957._2 | |
494 | + | let $t02296123110 = if (paymentInAmountAsset) | |
520 | 495 | then $Tuple2(paymentAmountRaw, 0) | |
521 | 496 | else $Tuple2(0, paymentAmountRaw) | |
522 | - | let amountAssetAmountRaw = $ | |
523 | - | let priceAssetAmountRaw = $ | |
524 | - | let amountAssetAmount = takeFee(amountAssetAmountRaw)._1 | |
525 | - | let priceAssetAmount = takeFee(priceAssetAmountRaw)._1 | |
526 | - | let $ | |
527 | - | let paymentAmount = $ | |
528 | - | let feeAmount = $ | |
497 | + | let amountAssetAmountRaw = $t02296123110._1 | |
498 | + | let priceAssetAmountRaw = $t02296123110._2 | |
499 | + | let amountAssetAmount = takeFee(amountAssetAmountRaw, inFee)._1 | |
500 | + | let priceAssetAmount = takeFee(priceAssetAmountRaw, inFee)._1 | |
501 | + | let $t02324223306 = takeFee(paymentAmountRaw, inFee) | |
502 | + | let paymentAmount = $t02324223306._1 | |
503 | + | let feeAmount = $t02324223306._2 | |
529 | 504 | let amountBalanceNew = (amountBalanceOld + amountAssetAmount) | |
530 | 505 | let priceBalanceNew = (priceBalanceOld + priceAssetAmount) | |
531 | 506 | let priceNewX18 = calcPriceBigInt(toX18(priceBalanceNew, cfgPriceAssetDecimals), toX18(amountBalanceNew, cfgAmountAssetDecimals)) | |
548 | 523 | let priceOldX18 = calcPriceBigInt(toX18(priceBalanceOld, cfgPriceAssetDecimals), toX18(amountBalanceOld, cfgAmountAssetDecimals)) | |
549 | 524 | let priceOld = fromX18(priceOldX18, scale8) | |
550 | 525 | let loss = { | |
551 | - | let $ | |
526 | + | let $t02478324950 = if (paymentInAmountAsset) | |
552 | 527 | then $Tuple2(amountAssetAmountRaw, amountBalanceOld) | |
553 | 528 | else $Tuple2(priceAssetAmountRaw, priceBalanceOld) | |
554 | - | let amount = $ | |
555 | - | let balance = $ | |
529 | + | let amount = $t02478324950._1 | |
530 | + | let balance = $t02478324950._2 | |
556 | 531 | let issueAmountBoth = toInt(fraction(supplyBigInt, toBigInt((amount / 2)), toBigInt(balance))) | |
557 | 532 | fraction((issueAmount - issueAmountBoth), scale8, issueAmountBoth) | |
558 | 533 | } | |
559 | - | $ | |
534 | + | $Tuple4(issueAmount, commonState, feeAmount, loss) | |
560 | 535 | } | |
561 | 536 | else throw("Strict value is not equal to itself.") | |
562 | 537 | } | |
586 | 561 | let supplyBigInt = toBigInt(valueOrErrorMessage(assetInfo(cfgLpAssetId), (("asset " + toBase58String(cfgLpAssetId)) + " doesn't exist")).quantity) | |
587 | 562 | let redeemedBigInt = toBigInt(paymentAmount) | |
588 | 563 | let amountRaw = max([0, toInt(((balanceBigInt * (scale18 - pow((scale18 - ((redeemedBigInt * scale18) / supplyBigInt)), 18, big2, 0, 18, DOWN))) / scale18))]) | |
589 | - | let $ | |
590 | - | let totalAmount = $ | |
591 | - | let feeAmount = $ | |
592 | - | let $ | |
564 | + | let $t02653026586 = takeFee(amountRaw, outFee) | |
565 | + | let totalAmount = $t02653026586._1 | |
566 | + | let feeAmount = $t02653026586._2 | |
567 | + | let $t02659026816 = if (outInAmountAsset) | |
593 | 568 | then $Tuple4(totalAmount, 0, (amBalanceOld - amountRaw), prBalanceOld) | |
594 | 569 | else $Tuple4(0, totalAmount, amBalanceOld, (prBalanceOld - amountRaw)) | |
595 | - | let outAmAmount = $ | |
596 | - | let outPrAmount = $ | |
597 | - | let amBalanceNew = $ | |
598 | - | let prBalanceNew = $ | |
570 | + | let outAmAmount = $t02659026816._1 | |
571 | + | let outPrAmount = $t02659026816._2 | |
572 | + | let amBalanceNew = $t02659026816._3 | |
573 | + | let prBalanceNew = $t02659026816._4 | |
599 | 574 | let priceNewX18 = calcPriceBigInt(toX18(prBalanceNew, cfgPriceAssetDecimals), toX18(amBalanceNew, cfgAmountAssetDecimals)) | |
600 | 575 | let priceNew = fromX18(priceNewX18, scale8) | |
601 | 576 | let commonState = if (isEval) | |
607 | 582 | let amountBothInPaymentAsset = (toInt(fraction(balanceBigInt, redeemedBigInt, supplyBigInt)) * 2) | |
608 | 583 | fraction((totalAmount - amountBothInPaymentAsset), scale8, amountBothInPaymentAsset) | |
609 | 584 | } | |
610 | - | $ | |
585 | + | $Tuple4(totalAmount, commonState, feeAmount, loss) | |
611 | 586 | } | |
612 | 587 | else throw("Strict value is not equal to itself.") | |
613 | 588 | } | |
707 | 682 | let prDiff = estPut._11 | |
708 | 683 | let amId = estPut._12 | |
709 | 684 | let prId = estPut._13 | |
710 | - | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
711 | - | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
712 | - | let currentKLp = calcCurrentKLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
713 | - | if ((currentKLp == currentKLp)) | |
685 | + | let emitInv = invoke(factoryContract, "emit", [emitLpAmt], nil) | |
686 | + | if ((emitInv == emitInv)) | |
714 | 687 | then { | |
715 | - | let emitInv = invoke(factoryContract, "emit", [emitLpAmt], nil) | |
716 | - | if ((emitInv == emitInv)) | |
688 | + | let emitInvLegacy = match emitInv { | |
689 | + | case legacyFactoryContract: Address => | |
690 | + | invoke(legacyFactoryContract, "emit", [emitLpAmt], nil) | |
691 | + | case _ => | |
692 | + | unit | |
693 | + | } | |
694 | + | if ((emitInvLegacy == emitInvLegacy)) | |
717 | 695 | then { | |
718 | - | let emitInvLegacy = match emitInv { | |
719 | - | case legacyFactoryContract: Address => | |
720 | - | invoke(legacyFactoryContract, "emit", [emitLpAmt], nil) | |
721 | - | case _ => | |
722 | - | unit | |
723 | - | } | |
724 | - | if ((emitInvLegacy == emitInvLegacy)) | |
696 | + | let slippageAInv = if ((amDiff > 0)) | |
697 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(amId, amDiff)]) | |
698 | + | else nil | |
699 | + | if ((slippageAInv == slippageAInv)) | |
725 | 700 | then { | |
726 | - | let | |
727 | - | then invoke(slippageContract, "put", nil, [AttachedPayment( | |
701 | + | let slippagePInv = if ((prDiff > 0)) | |
702 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(prId, prDiff)]) | |
728 | 703 | else nil | |
729 | - | if (( | |
704 | + | if ((slippagePInv == slippagePInv)) | |
730 | 705 | then { | |
731 | - | let slippagePInv = if ((prDiff > 0)) | |
732 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(prId, prDiff)]) | |
733 | - | else nil | |
734 | - | if ((slippagePInv == slippagePInv)) | |
706 | + | let lpTransfer = if (shouldAutoStake) | |
735 | 707 | then { | |
736 | - | let lpTransfer = if (shouldAutoStake) | |
737 | - | then { | |
738 | - | let slpStakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
739 | - | if ((slpStakeInv == slpStakeInv)) | |
740 | - | then nil | |
741 | - | else throw("Strict value is not equal to itself.") | |
742 | - | } | |
743 | - | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
744 | - | let $t03292633388 = refreshKLpInternal(0, 0, 0) | |
745 | - | if (($t03292633388 == $t03292633388)) | |
746 | - | then { | |
747 | - | let updatedKLp = $t03292633388._2 | |
748 | - | let refreshKLpActions = $t03292633388._1 | |
749 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
750 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
751 | - | then ((state ++ lpTransfer) ++ refreshKLpActions) | |
752 | - | else throw("Strict value is not equal to itself.") | |
753 | - | } | |
708 | + | let slpStakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
709 | + | if ((slpStakeInv == slpStakeInv)) | |
710 | + | then nil | |
754 | 711 | else throw("Strict value is not equal to itself.") | |
755 | 712 | } | |
756 | - | else throw("Strict value is not equal to itself.") | |
713 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
714 | + | (state ++ lpTransfer) | |
757 | 715 | } | |
758 | 716 | else throw("Strict value is not equal to itself.") | |
759 | 717 | } | |
771 | 729 | then throw("Invalid value passed") | |
772 | 730 | else { | |
773 | 731 | let estPut = commonPut(i, maxSlippage, false) | |
774 | - | let state = estPut._9 | |
775 | - | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
776 | - | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
777 | - | let currentKLp = calcCurrentKLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
778 | - | if ((currentKLp == currentKLp)) | |
779 | - | then { | |
780 | - | let $t03395034015 = refreshKLpInternal(0, 0, 0) | |
781 | - | let refreshKLpActions = $t03395034015._1 | |
782 | - | let updatedKLp = $t03395034015._2 | |
783 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
784 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
785 | - | then (state ++ refreshKLpActions) | |
786 | - | else throw("Strict value is not equal to itself.") | |
787 | - | } | |
788 | - | else throw("Strict value is not equal to itself.") | |
732 | + | estPut._9 | |
789 | 733 | } | |
790 | 734 | ||
791 | 735 | ||
817 | 761 | let payment = i.payments[0] | |
818 | 762 | let paymentAssetId = payment.assetId | |
819 | 763 | let paymentAmountRaw = payment.amount | |
820 | - | let currentKLp = if ((paymentAssetId == cfgAmountAssetId)) | |
821 | - | then calcCurrentKLp(toBigInt(paymentAmountRaw), toBigInt(0), toBigInt(0)) | |
822 | - | else if ((paymentAssetId == cfgPriceAssetId)) | |
823 | - | then calcCurrentKLp(toBigInt(0), toBigInt(paymentAmountRaw), toBigInt(0)) | |
824 | - | else throwErr("payment asset is not supported") | |
825 | 764 | let userAddress = i.caller | |
826 | 765 | let txId = i.transactionId | |
827 | - | let $ | |
828 | - | if (($ | |
766 | + | let $t03172331853 = calcPutOneToken(paymentAmountRaw, paymentAssetId, userAddress, txId) | |
767 | + | if (($t03172331853 == $t03172331853)) | |
829 | 768 | then { | |
830 | - | let paymentInAmountAsset = $t03520035352._5 | |
831 | - | let bonus = $t03520035352._4 | |
832 | - | let feeAmount = $t03520035352._3 | |
833 | - | let commonState = $t03520035352._2 | |
834 | - | let emitAmountEstimated = $t03520035352._1 | |
769 | + | let bonus = $t03172331853._4 | |
770 | + | let feeAmount = $t03172331853._3 | |
771 | + | let commonState = $t03172331853._2 | |
772 | + | let emitAmountEstimated = $t03172331853._1 | |
835 | 773 | let emitAmount = if (if ((minOutAmount > 0)) | |
836 | 774 | then (minOutAmount > emitAmountEstimated) | |
837 | 775 | else false) | |
851 | 789 | let sendFee = if ((feeAmount > 0)) | |
852 | 790 | then [ScriptTransfer(feeCollectorAddress, feeAmount, paymentAssetId)] | |
853 | 791 | else nil | |
854 | - | let $t03593836135 = if ((this == feeCollectorAddress)) | |
855 | - | then $Tuple2(0, 0) | |
856 | - | else if (paymentInAmountAsset) | |
857 | - | then $Tuple2(-(feeAmount), 0) | |
858 | - | else $Tuple2(0, -(feeAmount)) | |
859 | - | let amountAssetBalanceDelta = $t03593836135._1 | |
860 | - | let priceAssetBalanceDelta = $t03593836135._2 | |
861 | - | let $t03613836246 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
862 | - | let refreshKLpActions = $t03613836246._1 | |
863 | - | let updatedKLp = $t03613836246._2 | |
864 | - | let kLp = value(getString(keyKLp)) | |
865 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
866 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
867 | - | then $Tuple2((((commonState ++ lpTransfer) ++ sendFee) ++ refreshKLpActions), emitAmount) | |
868 | - | else throw("Strict value is not equal to itself.") | |
792 | + | $Tuple2(((commonState ++ lpTransfer) ++ sendFee), emitAmount) | |
869 | 793 | } | |
870 | 794 | else throw("Strict value is not equal to itself.") | |
871 | 795 | } | |
878 | 802 | ||
879 | 803 | @Callable(i) | |
880 | 804 | func putOneTknREADONLY (paymentAssetId,paymentAmountRaw) = { | |
881 | - | let $t03655236709 = calcPutOneToken(paymentAmountRaw, parseAssetId(paymentAssetId), unit, unit) | |
882 | - | let emitAmountEstimated = $t03655236709._1 | |
883 | - | let commonState = $t03655236709._2 | |
884 | - | let feeAmount = $t03655236709._3 | |
885 | - | let bonus = $t03655236709._4 | |
886 | - | let paymentInAmountAsset = $t03655236709._5 | |
805 | + | let $t03258232717 = calcPutOneToken(paymentAmountRaw, parseAssetId(paymentAssetId), unit, unit) | |
806 | + | let emitAmountEstimated = $t03258232717._1 | |
807 | + | let commonState = $t03258232717._2 | |
808 | + | let feeAmount = $t03258232717._3 | |
809 | + | let bonus = $t03258232717._4 | |
887 | 810 | $Tuple2(nil, $Tuple3(emitAmountEstimated, feeAmount, bonus)) | |
888 | 811 | } | |
889 | 812 | ||
915 | 838 | let payment = i.payments[0] | |
916 | 839 | let paymentAssetId = payment.assetId | |
917 | 840 | let paymentAmount = payment.amount | |
918 | - | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(paymentAmount)) | |
919 | 841 | let userAddress = i.caller | |
920 | 842 | let txId = i.transactionId | |
921 | - | let $ | |
922 | - | if (($ | |
843 | + | let $t03352233657 = calcGetOneToken(outAssetId, paymentAmount, paymentAssetId, userAddress, txId) | |
844 | + | if (($t03352233657 == $t03352233657)) | |
923 | 845 | then { | |
924 | - | let outInAmountAsset = $t03760337756._5 | |
925 | - | let bonus = $t03760337756._4 | |
926 | - | let feeAmount = $t03760337756._3 | |
927 | - | let commonState = $t03760337756._2 | |
928 | - | let amountEstimated = $t03760337756._1 | |
846 | + | let bonus = $t03352233657._4 | |
847 | + | let feeAmount = $t03352233657._3 | |
848 | + | let commonState = $t03352233657._2 | |
849 | + | let amountEstimated = $t03352233657._1 | |
929 | 850 | let amount = if (if ((minOutAmount > 0)) | |
930 | 851 | then (minOutAmount > amountEstimated) | |
931 | 852 | else false) | |
938 | 859 | let sendFee = if ((feeAmount > 0)) | |
939 | 860 | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)] | |
940 | 861 | else nil | |
941 | - | let $t03825638503 = { | |
942 | - | let feeAmountForCalc = if ((this == feeCollectorAddress)) | |
943 | - | then 0 | |
944 | - | else feeAmount | |
945 | - | if (outInAmountAsset) | |
946 | - | then $Tuple2(-((amount + feeAmountForCalc)), 0) | |
947 | - | else $Tuple2(0, -((amount + feeAmountForCalc))) | |
948 | - | } | |
949 | - | let amountAssetBalanceDelta = $t03825638503._1 | |
950 | - | let priceAssetBalanceDelta = $t03825638503._2 | |
951 | - | let $t03850638614 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
952 | - | let refreshKLpActions = $t03850638614._1 | |
953 | - | let updatedKLp = $t03850638614._2 | |
954 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
955 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
956 | - | then $Tuple2((((commonState ++ assetTransfer) ++ sendFee) ++ refreshKLpActions), amount) | |
957 | - | else throw("Strict value is not equal to itself.") | |
862 | + | $Tuple2(((commonState ++ assetTransfer) ++ sendFee), amount) | |
958 | 863 | } | |
959 | 864 | else throw("Strict value is not equal to itself.") | |
960 | 865 | } | |
967 | 872 | ||
968 | 873 | @Callable(i) | |
969 | 874 | func getOneTknREADONLY (outAssetId,paymentAmount) = { | |
970 | - | let $t03887139027 = calcGetOneToken(parseAssetId(outAssetId), paymentAmount, cfgLpAssetId, unit, unit) | |
971 | - | let amountEstimated = $t03887139027._1 | |
972 | - | let commonState = $t03887139027._2 | |
973 | - | let feeAmount = $t03887139027._3 | |
974 | - | let bonus = $t03887139027._4 | |
975 | - | let outInAmountAsset = $t03887139027._5 | |
875 | + | let $t03429234430 = calcGetOneToken(parseAssetId(outAssetId), paymentAmount, cfgLpAssetId, unit, unit) | |
876 | + | let amountEstimated = $t03429234430._1 | |
877 | + | let commonState = $t03429234430._2 | |
878 | + | let feeAmount = $t03429234430._3 | |
879 | + | let bonus = $t03429234430._4 | |
976 | 880 | $Tuple2(nil, $Tuple3(amountEstimated, feeAmount, bonus)) | |
977 | 881 | } | |
978 | 882 | ||
1003 | 907 | let outAssetId = parseAssetId(outAssetIdStr) | |
1004 | 908 | let userAddress = i.caller | |
1005 | 909 | let txId = i.transactionId | |
1006 | - | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1007 | 910 | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1008 | 911 | if ((unstakeInv == unstakeInv)) | |
1009 | 912 | then { | |
1010 | - | let $ | |
1011 | - | if (($ | |
913 | + | let $t03525535388 = calcGetOneToken(outAssetId, unstakeAmount, cfgLpAssetId, userAddress, txId) | |
914 | + | if (($t03525535388 == $t03525535388)) | |
1012 | 915 | then { | |
1013 | - | let outInAmountAsset = $t03992940080._5 | |
1014 | - | let bonus = $t03992940080._4 | |
1015 | - | let feeAmount = $t03992940080._3 | |
1016 | - | let commonState = $t03992940080._2 | |
1017 | - | let amountEstimated = $t03992940080._1 | |
916 | + | let bonus = $t03525535388._4 | |
917 | + | let feeAmount = $t03525535388._3 | |
918 | + | let commonState = $t03525535388._2 | |
919 | + | let amountEstimated = $t03525535388._1 | |
1018 | 920 | let amount = if (if ((minOutAmount > 0)) | |
1019 | 921 | then (minOutAmount > amountEstimated) | |
1020 | 922 | else false) | |
1027 | 929 | let sendFee = if ((feeAmount > 0)) | |
1028 | 930 | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)] | |
1029 | 931 | else nil | |
1030 | - | let $t04057540822 = { | |
1031 | - | let feeAmountForCalc = if ((this == feeCollectorAddress)) | |
1032 | - | then 0 | |
1033 | - | else feeAmount | |
1034 | - | if (outInAmountAsset) | |
1035 | - | then $Tuple2(-((amount + feeAmountForCalc)), 0) | |
1036 | - | else $Tuple2(0, -((amount + feeAmountForCalc))) | |
1037 | - | } | |
1038 | - | let amountAssetBalanceDelta = $t04057540822._1 | |
1039 | - | let priceAssetBalanceDelta = $t04057540822._2 | |
1040 | - | let $t04082540933 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1041 | - | let refreshKLpActions = $t04082540933._1 | |
1042 | - | let updatedKLp = $t04082540933._2 | |
1043 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1044 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1045 | - | then $Tuple2((((commonState ++ assetTransfer) ++ sendFee) ++ refreshKLpActions), amount) | |
1046 | - | else throw("Strict value is not equal to itself.") | |
932 | + | $Tuple2(((commonState ++ assetTransfer) ++ sendFee), amount) | |
1047 | 933 | } | |
1048 | 934 | else throw("Strict value is not equal to itself.") | |
1049 | 935 | } | |
1064 | 950 | let pmtAmt = res._3 | |
1065 | 951 | let pmtAssetId = res._4 | |
1066 | 952 | let state = res._5 | |
1067 | - | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(pmtAmt)) | |
1068 | 953 | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1069 | 954 | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1070 | - | then { | |
1071 | - | let $t04188141963 = refreshKLpInternal(-(outAmtAmt), -(outPrAmt), 0) | |
1072 | - | let refreshKLpActions = $t04188141963._1 | |
1073 | - | let updatedKLp = $t04188141963._2 | |
1074 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1075 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1076 | - | then (state ++ refreshKLpActions) | |
1077 | - | else throw("Strict value is not equal to itself.") | |
1078 | - | } | |
955 | + | then state | |
1079 | 956 | else throw("Strict value is not equal to itself.") | |
1080 | 957 | } | |
1081 | 958 | ||
1094 | 971 | else if ((noLessThenPriceAsset > outPrAmt)) | |
1095 | 972 | then throw(((("noLessThenPriceAsset failed: " + toString(outPrAmt)) + " < ") + toString(noLessThenPriceAsset))) | |
1096 | 973 | else { | |
1097 | - | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(pmtAmt)) | |
1098 | 974 | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1099 | 975 | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1100 | - | then { | |
1101 | - | let $t04291442995 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1102 | - | let refreshKLpActions = $t04291442995._1 | |
1103 | - | let updatedKLp = $t04291442995._2 | |
1104 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1105 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1106 | - | then (state ++ refreshKLpActions) | |
1107 | - | else throw("Strict value is not equal to itself.") | |
1108 | - | } | |
976 | + | then state | |
1109 | 977 | else throw("Strict value is not equal to itself.") | |
1110 | 978 | } | |
1111 | 979 | } | |
1121 | 989 | then { | |
1122 | 990 | let cfg = getPoolConfig() | |
1123 | 991 | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
1124 | - | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1125 | 992 | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(lpAssetId), amount], nil) | |
1126 | 993 | if ((unstakeInv == unstakeInv)) | |
1127 | 994 | then { | |
1128 | 995 | let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
1129 | - | let outAmAmt = res._1 | |
1130 | - | let outPrAmt = res._2 | |
1131 | 996 | let poolStatus = parseIntValue(res._9) | |
1132 | 997 | let state = res._10 | |
1133 | 998 | let checkPoolStatus = if (if (isGlobalShutdown()) | |
1139 | 1004 | then { | |
1140 | 1005 | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1141 | 1006 | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1142 | - | then { | |
1143 | - | let $t04411844199 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1144 | - | let refreshKLpActions = $t04411844199._1 | |
1145 | - | let updatedKLp = $t04411844199._2 | |
1146 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1147 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1148 | - | then (state ++ refreshKLpActions) | |
1149 | - | else throw("Strict value is not equal to itself.") | |
1150 | - | } | |
1007 | + | then state | |
1151 | 1008 | else throw("Strict value is not equal to itself.") | |
1152 | 1009 | } | |
1153 | 1010 | else throw("Strict value is not equal to itself.") | |
1171 | 1028 | else throw("no payments are expected")] | |
1172 | 1029 | if ((checks == checks)) | |
1173 | 1030 | then { | |
1174 | - | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1175 | 1031 | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1176 | 1032 | if ((unstakeInv == unstakeInv)) | |
1177 | 1033 | then { | |
1188 | 1044 | then { | |
1189 | 1045 | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1190 | 1046 | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1191 | - | then { | |
1192 | - | let $t04549145572 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1193 | - | let refreshKLpActions = $t04549145572._1 | |
1194 | - | let updatedKLp = $t04549145572._2 | |
1195 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1196 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1197 | - | then (state ++ refreshKLpActions) | |
1198 | - | else throw("Strict value is not equal to itself.") | |
1199 | - | } | |
1047 | + | then state | |
1200 | 1048 | else throw("Strict value is not equal to itself.") | |
1201 | 1049 | } | |
1202 | 1050 | else throw("Strict value is not equal to itself.") | |
1212 | 1060 | func activate (amtAssetStr,priceAssetStr) = if ((toString(i.caller) != toString(factoryContract))) | |
1213 | 1061 | then throw("permissions denied") | |
1214 | 1062 | else $Tuple2([StringEntry(aa(), amtAssetStr), StringEntry(pa(), priceAssetStr)], "success") | |
1215 | - | ||
1216 | - | ||
1217 | - | ||
1218 | - | @Callable(i) | |
1219 | - | func refreshKLp () = { | |
1220 | - | let lastRefreshedBlockHeight = valueOrElse(getInteger(keyKLpRefreshedHeight), 0) | |
1221 | - | let checkLastRefreshedBlockHeight = if (((height - lastRefreshedBlockHeight) >= kLpRefreshDelay)) | |
1222 | - | then unit | |
1223 | - | else throwErr(makeString([toString(kLpRefreshDelay), " blocks have not passed since the previous call"], "")) | |
1224 | - | if ((checkLastRefreshedBlockHeight == checkLastRefreshedBlockHeight)) | |
1225 | - | then { | |
1226 | - | let kLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyKLp), "0")), fmtErr("invalid kLp")) | |
1227 | - | let $t04675946823 = refreshKLpInternal(0, 0, 0) | |
1228 | - | let kLpUpdateActions = $t04675946823._1 | |
1229 | - | let updatedKLp = $t04675946823._2 | |
1230 | - | let actions = if ((kLp != updatedKLp)) | |
1231 | - | then kLpUpdateActions | |
1232 | - | else throwErr("nothing to refresh") | |
1233 | - | $Tuple2(actions, toString(updatedKLp)) | |
1234 | - | } | |
1235 | - | else throw("Strict value is not equal to itself.") | |
1236 | - | } | |
1237 | 1063 | ||
1238 | 1064 | ||
1239 | 1065 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let lPdecimals = 8 | |
5 | 5 | ||
6 | 6 | let scale8 = 100000000 | |
7 | 7 | ||
8 | 8 | let scale8BigInt = toBigInt(100000000) | |
9 | 9 | ||
10 | 10 | let scale18 = toBigInt(1000000000000000000) | |
11 | 11 | ||
12 | 12 | let zeroBigInt = toBigInt(0) | |
13 | 13 | ||
14 | 14 | let big0 = toBigInt(0) | |
15 | 15 | ||
16 | 16 | let big1 = toBigInt(1) | |
17 | 17 | ||
18 | 18 | let big2 = toBigInt(2) | |
19 | 19 | ||
20 | 20 | let wavesString = "WAVES" | |
21 | 21 | ||
22 | 22 | let SEP = "__" | |
23 | 23 | ||
24 | 24 | let PoolActive = 1 | |
25 | 25 | ||
26 | 26 | let PoolPutDisabled = 2 | |
27 | 27 | ||
28 | 28 | let PoolMatcherDisabled = 3 | |
29 | 29 | ||
30 | 30 | let PoolShutdown = 4 | |
31 | 31 | ||
32 | 32 | let idxPoolAddress = 1 | |
33 | 33 | ||
34 | 34 | let idxPoolStatus = 2 | |
35 | 35 | ||
36 | 36 | let idxPoolLPAssetId = 3 | |
37 | 37 | ||
38 | 38 | let idxAmtAssetId = 4 | |
39 | 39 | ||
40 | 40 | let idxPriceAssetId = 5 | |
41 | 41 | ||
42 | 42 | let idxAmtAssetDcm = 6 | |
43 | 43 | ||
44 | 44 | let idxPriceAssetDcm = 7 | |
45 | 45 | ||
46 | 46 | let idxIAmtAssetId = 8 | |
47 | 47 | ||
48 | 48 | let idxIPriceAssetId = 9 | |
49 | 49 | ||
50 | 50 | let idxLPAssetDcm = 10 | |
51 | 51 | ||
52 | 52 | let idxPoolAmtAssetAmt = 1 | |
53 | 53 | ||
54 | 54 | let idxPoolPriceAssetAmt = 2 | |
55 | 55 | ||
56 | 56 | let idxPoolLPAssetAmt = 3 | |
57 | 57 | ||
58 | 58 | let idxFactoryStakingContract = 1 | |
59 | 59 | ||
60 | 60 | let idxFactorySlippageContract = 7 | |
61 | 61 | ||
62 | 62 | func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) | |
63 | 63 | ||
64 | 64 | ||
65 | 65 | func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18)) | |
66 | 66 | ||
67 | 67 | ||
68 | - | func fromX18Round (val,resultScaleMult,round) = toInt(fraction(val, toBigInt(resultScaleMult), scale18, round)) | |
69 | - | ||
70 | - | ||
71 | 68 | func toScale (amt,resScale,curScale) = fraction(amt, resScale, curScale) | |
72 | 69 | ||
73 | 70 | ||
74 | 71 | func abs (val) = if ((0 > val)) | |
75 | 72 | then -(val) | |
76 | 73 | else val | |
77 | 74 | ||
78 | 75 | ||
79 | 76 | func absBigInt (val) = if ((zeroBigInt > val)) | |
80 | 77 | then -(val) | |
81 | 78 | else val | |
82 | 79 | ||
83 | 80 | ||
84 | 81 | func fc () = "%s__factoryContract" | |
85 | 82 | ||
86 | 83 | ||
87 | 84 | func mpk () = "%s__managerPublicKey" | |
88 | 85 | ||
89 | 86 | ||
90 | 87 | func pmpk () = "%s__pendingManagerPublicKey" | |
91 | 88 | ||
92 | 89 | ||
93 | 90 | func pl () = "%s%s__price__last" | |
94 | 91 | ||
95 | 92 | ||
96 | 93 | func ph (h,timestamp) = makeString(["%s%s%d%d__price__history", toString(h), toString(timestamp)], SEP) | |
97 | 94 | ||
98 | 95 | ||
99 | 96 | func pau (userAddress,txId) = ((("%s%s%s__P__" + userAddress) + "__") + txId) | |
100 | 97 | ||
101 | 98 | ||
102 | 99 | func gau (userAddress,txId) = ((("%s%s%s__G__" + userAddress) + "__") + txId) | |
103 | 100 | ||
104 | 101 | ||
105 | 102 | func aa () = "%s__amountAsset" | |
106 | 103 | ||
107 | 104 | ||
108 | 105 | func pa () = "%s__priceAsset" | |
109 | 106 | ||
110 | 107 | ||
111 | - | let keyFee = "%s__fee" | |
112 | - | ||
113 | - | let feeDefault = fraction(10, scale8, 10000) | |
114 | - | ||
115 | - | let fee = valueOrElse(getInteger(this, keyFee), feeDefault) | |
116 | - | ||
117 | - | let keyKLp = makeString(["%s", "kLp"], SEP) | |
118 | - | ||
119 | - | let keyKLpRefreshedHeight = makeString(["%s", "kLpRefreshedHeight"], SEP) | |
120 | - | ||
121 | - | let keyKLpRefreshDelay = makeString(["%s", "refreshKLpDelay"], SEP) | |
122 | - | ||
123 | - | let kLpRefreshDelayDefault = 30 | |
124 | - | ||
125 | - | let kLpRefreshDelay = valueOrElse(getInteger(this, keyKLpRefreshDelay), kLpRefreshDelayDefault) | |
126 | - | ||
127 | 108 | func keyFactoryConfig () = "%s__factoryConfig" | |
128 | 109 | ||
129 | 110 | ||
130 | 111 | func keyMatcherPub () = "%s%s__matcher__publicKey" | |
131 | 112 | ||
132 | 113 | ||
133 | 114 | func keyMappingPoolContractAddressToPoolAssets (poolContractAddress) = (("%s%s%s__" + poolContractAddress) + "__mappings__poolContract2LpAsset") | |
134 | 115 | ||
135 | 116 | ||
136 | 117 | func keyPoolConfig (iAmtAsset,iPriceAsset) = (((("%d%d%s__" + iAmtAsset) + "__") + iPriceAsset) + "__config") | |
137 | 118 | ||
138 | 119 | ||
139 | 120 | func keyMappingsBaseAsset2internalId (baseAssetStr) = ("%s%s%s__mappings__baseAsset2internalId__" + baseAssetStr) | |
140 | 121 | ||
141 | 122 | ||
142 | 123 | func keyAllPoolsShutdown () = "%s__shutdown" | |
143 | 124 | ||
144 | 125 | ||
145 | 126 | func keyPoolWeight (contractAddress) = ("%s%s__poolWeight__" + contractAddress) | |
146 | 127 | ||
147 | 128 | ||
148 | 129 | func keyAllowedLpScriptHash () = "%s__allowedLpScriptHash" | |
149 | 130 | ||
150 | 131 | ||
151 | 132 | let keyFeeCollectorAddress = "%s__feeCollectorAddress" | |
152 | 133 | ||
153 | 134 | func throwOrderError (orderValid,senderValid,matcherValid) = throw(((((("order validation failed: orderValid=" + toString(orderValid)) + " senderValid=") + toString(senderValid)) + " matcherValid=") + toString(matcherValid))) | |
154 | 135 | ||
155 | 136 | ||
156 | 137 | func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) | |
157 | 138 | ||
158 | 139 | ||
159 | 140 | func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) | |
160 | 141 | ||
161 | 142 | ||
162 | 143 | func throwErr (msg) = throw(makeString(["lp.ride:", msg], " ")) | |
163 | 144 | ||
164 | 145 | ||
165 | - | func fmtErr (msg) = makeString(["lp.ride:", msg], " ") | |
166 | - | ||
167 | - | ||
168 | 146 | let factoryContract = addressFromStringValue(getStringOrFail(this, fc())) | |
169 | 147 | ||
170 | 148 | let feeCollectorAddress = addressFromStringValue(getStringOrFail(factoryContract, keyFeeCollectorAddress)) | |
149 | + | ||
150 | + | let inFee = { | |
151 | + | let @ = invoke(factoryContract, "getInFeeREADONLY", [toString(this)], nil) | |
152 | + | if ($isInstanceOf(@, "Int")) | |
153 | + | then @ | |
154 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
155 | + | } | |
156 | + | ||
157 | + | let outFee = { | |
158 | + | let @ = invoke(factoryContract, "getOutFeeREADONLY", [toString(this)], nil) | |
159 | + | if ($isInstanceOf(@, "Int")) | |
160 | + | then @ | |
161 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
162 | + | } | |
171 | 163 | ||
172 | 164 | func isGlobalShutdown () = valueOrElse(getBoolean(factoryContract, keyAllPoolsShutdown()), false) | |
173 | 165 | ||
174 | 166 | ||
175 | 167 | func getMatcherPubOrFail () = fromBase58String(getStringOrFail(factoryContract, keyMatcherPub())) | |
176 | 168 | ||
177 | 169 | ||
178 | 170 | func getPoolConfig () = { | |
179 | 171 | let amtAsset = getStringOrFail(this, aa()) | |
180 | 172 | let priceAsset = getStringOrFail(this, pa()) | |
181 | 173 | let iPriceAsset = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(priceAsset)) | |
182 | 174 | let iAmtAsset = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(amtAsset)) | |
183 | 175 | split(getStringOrFail(factoryContract, keyPoolConfig(toString(iAmtAsset), toString(iPriceAsset))), SEP) | |
184 | 176 | } | |
185 | 177 | ||
186 | 178 | ||
187 | 179 | func parseAssetId (input) = if ((input == wavesString)) | |
188 | 180 | then unit | |
189 | 181 | else fromBase58String(input) | |
190 | 182 | ||
191 | 183 | ||
192 | 184 | func assetIdToString (input) = if ((input == unit)) | |
193 | 185 | then wavesString | |
194 | 186 | else toBase58String(value(input)) | |
195 | 187 | ||
196 | 188 | ||
197 | 189 | func parsePoolConfig (poolConfig) = $Tuple7(addressFromStringValue(poolConfig[idxPoolAddress]), parseIntValue(poolConfig[idxPoolStatus]), fromBase58String(poolConfig[idxPoolLPAssetId]), parseAssetId(poolConfig[idxAmtAssetId]), parseAssetId(poolConfig[idxPriceAssetId]), parseIntValue(poolConfig[idxAmtAssetDcm]), parseIntValue(poolConfig[idxPriceAssetDcm])) | |
198 | 190 | ||
199 | 191 | ||
200 | 192 | let poolConfigParsed = parsePoolConfig(getPoolConfig()) | |
201 | 193 | ||
202 | - | let $ | |
194 | + | let $t076017767 = poolConfigParsed | |
203 | 195 | ||
204 | - | let cfgPoolAddress = $ | |
196 | + | let cfgPoolAddress = $t076017767._1 | |
205 | 197 | ||
206 | - | let cfgPoolStatus = $ | |
198 | + | let cfgPoolStatus = $t076017767._2 | |
207 | 199 | ||
208 | - | let cfgLpAssetId = $ | |
200 | + | let cfgLpAssetId = $t076017767._3 | |
209 | 201 | ||
210 | - | let cfgAmountAssetId = $ | |
202 | + | let cfgAmountAssetId = $t076017767._4 | |
211 | 203 | ||
212 | - | let cfgPriceAssetId = $ | |
204 | + | let cfgPriceAssetId = $t076017767._5 | |
213 | 205 | ||
214 | - | let cfgAmountAssetDecimals = $ | |
206 | + | let cfgAmountAssetDecimals = $t076017767._6 | |
215 | 207 | ||
216 | - | let cfgPriceAssetDecimals = $ | |
208 | + | let cfgPriceAssetDecimals = $t076017767._7 | |
217 | 209 | ||
218 | 210 | func getFactoryConfig () = split(getStringOrFail(factoryContract, keyFactoryConfig()), SEP) | |
219 | 211 | ||
220 | 212 | ||
221 | 213 | let stakingContract = valueOrErrorMessage(addressFromString(getFactoryConfig()[idxFactoryStakingContract]), "incorrect staking address") | |
222 | 214 | ||
223 | 215 | let slippageContract = valueOrErrorMessage(addressFromString(getFactoryConfig()[idxFactorySlippageContract]), "incorrect staking address") | |
224 | 216 | ||
225 | 217 | func dataPutActionInfo (inAmtAssetAmt,inPriceAssetAmt,outLpAmt,price,slippageTolerancePassedByUser,slippageToleranceReal,txHeight,txTimestamp,slipageAmtAssetAmt,slipagePriceAssetAmt) = makeString(["%d%d%d%d%d%d%d%d%d%d", toString(inAmtAssetAmt), toString(inPriceAssetAmt), toString(outLpAmt), toString(price), toString(slippageTolerancePassedByUser), toString(slippageToleranceReal), toString(txHeight), toString(txTimestamp), toString(slipageAmtAssetAmt), toString(slipagePriceAssetAmt)], SEP) | |
226 | 218 | ||
227 | 219 | ||
228 | 220 | func dataGetActionInfo (outAmtAssetAmt,outPriceAssetAmt,inLpAmt,price,txHeight,txTimestamp) = makeString(["%d%d%d%d%d%d", toString(outAmtAssetAmt), toString(outPriceAssetAmt), toString(inLpAmt), toString(price), toString(txHeight), toString(txTimestamp)], SEP) | |
229 | 221 | ||
230 | 222 | ||
231 | 223 | func getAccBalance (assetId) = if ((assetId == "WAVES")) | |
232 | 224 | then wavesBalance(this).available | |
233 | 225 | else assetBalance(this, fromBase58String(assetId)) | |
234 | 226 | ||
235 | 227 | ||
236 | 228 | func calcPriceBigInt (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18) | |
237 | - | ||
238 | - | ||
239 | - | func calcPriceBigIntRound (prAmtX18,amAmtX18,round) = fraction(prAmtX18, scale18, amAmtX18, round) | |
240 | 229 | ||
241 | 230 | ||
242 | 231 | func privateCalcPrice (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
243 | 232 | let amtAssetAmtX18 = toX18(amAmt, amAssetDcm) | |
244 | 233 | let priceAssetAmtX18 = toX18(prAmt, prAssetDcm) | |
245 | 234 | calcPriceBigInt(priceAssetAmtX18, amtAssetAmtX18) | |
246 | 235 | } | |
247 | 236 | ||
248 | 237 | ||
249 | 238 | func calcPrices (amAmt,prAmt,lpAmt) = { | |
250 | 239 | let cfg = getPoolConfig() | |
251 | 240 | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
252 | 241 | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
253 | 242 | let priceX18 = privateCalcPrice(amtAssetDcm, priceAssetDcm, amAmt, prAmt) | |
254 | 243 | let amAmtX18 = toX18(amAmt, amtAssetDcm) | |
255 | 244 | let prAmtX18 = toX18(prAmt, priceAssetDcm) | |
256 | 245 | let lpAmtX18 = toX18(lpAmt, scale8) | |
257 | 246 | let lpPriceInAmAssetX18 = calcPriceBigInt(amAmtX18, lpAmtX18) | |
258 | 247 | let lpPriceInPrAssetX18 = calcPriceBigInt(prAmtX18, lpAmtX18) | |
259 | 248 | [priceX18, lpPriceInAmAssetX18, lpPriceInPrAssetX18] | |
260 | 249 | } | |
261 | 250 | ||
262 | 251 | ||
263 | 252 | func calculatePrices (amAmt,prAmt,lpAmt) = { | |
264 | 253 | let prices = calcPrices(amAmt, prAmt, lpAmt) | |
265 | 254 | [fromX18(prices[0], scale8), fromX18(prices[1], scale8), fromX18(prices[2], scale8)] | |
266 | 255 | } | |
267 | 256 | ||
268 | 257 | ||
269 | 258 | func estimateGetOperation (txId58,pmtAssetId,pmtLpAmt,userAddress) = { | |
270 | 259 | let cfg = getPoolConfig() | |
271 | 260 | let lpAssetId = cfg[idxPoolLPAssetId] | |
272 | 261 | let amAssetId = cfg[idxAmtAssetId] | |
273 | 262 | let prAssetId = cfg[idxPriceAssetId] | |
274 | 263 | let amAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
275 | 264 | let prAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
276 | 265 | let poolStatus = cfg[idxPoolStatus] | |
277 | 266 | let lpEmission = valueOrErrorMessage(assetInfo(fromBase58String(lpAssetId)), (("Asset " + lpAssetId) + " doesn't exist")).quantity | |
278 | 267 | if ((lpAssetId != pmtAssetId)) | |
279 | 268 | then throw("Invalid asset passed.") | |
280 | 269 | else { | |
281 | 270 | let amBalance = getAccBalance(amAssetId) | |
282 | 271 | let amBalanceX18 = toX18(amBalance, amAssetDcm) | |
283 | 272 | let prBalance = getAccBalance(prAssetId) | |
284 | 273 | let prBalanceX18 = toX18(prBalance, prAssetDcm) | |
285 | 274 | let curPriceX18 = calcPriceBigInt(prBalanceX18, amBalanceX18) | |
286 | 275 | let curPrice = fromX18(curPriceX18, scale8) | |
287 | 276 | let pmtLpAmtX18 = toX18(pmtLpAmt, scale8) | |
288 | 277 | let lpEmissionX18 = toX18(lpEmission, scale8) | |
289 | 278 | let outAmAmtX18 = fraction(amBalanceX18, pmtLpAmtX18, lpEmissionX18) | |
290 | 279 | let outPrAmtX18 = fraction(prBalanceX18, pmtLpAmtX18, lpEmissionX18) | |
291 | 280 | let outAmAmt = fromX18(outAmAmtX18, amAssetDcm) | |
292 | 281 | let outPrAmt = fromX18(outPrAmtX18, prAssetDcm) | |
293 | 282 | let state = if ((txId58 == "")) | |
294 | 283 | then nil | |
295 | 284 | else [ScriptTransfer(userAddress, outAmAmt, if ((amAssetId == "WAVES")) | |
296 | 285 | then unit | |
297 | 286 | else fromBase58String(amAssetId)), ScriptTransfer(userAddress, outPrAmt, if ((prAssetId == "WAVES")) | |
298 | 287 | then unit | |
299 | 288 | else fromBase58String(prAssetId)), StringEntry(gau(toString(userAddress), txId58), dataGetActionInfo(outAmAmt, outPrAmt, pmtLpAmt, curPrice, height, lastBlock.timestamp)), IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice)] | |
300 | 289 | $Tuple10(outAmAmt, outPrAmt, amAssetId, prAssetId, amBalance, prBalance, lpEmission, curPriceX18, poolStatus, state) | |
301 | 290 | } | |
302 | 291 | } | |
303 | 292 | ||
304 | 293 | ||
305 | 294 | func estimatePutOperation (txId58,slippageTolerance,inAmAssetAmt,inAmAssetId,inPrAssetAmt,inPrAssetId,userAddress,isEvaluate,emitLp) = { | |
306 | 295 | let cfg = getPoolConfig() | |
307 | 296 | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
308 | 297 | let amAssetIdStr = cfg[idxAmtAssetId] | |
309 | 298 | let prAssetIdStr = cfg[idxPriceAssetId] | |
310 | 299 | let iAmtAssetId = cfg[idxIAmtAssetId] | |
311 | 300 | let iPriceAssetId = cfg[idxIPriceAssetId] | |
312 | 301 | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
313 | 302 | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
314 | 303 | let poolStatus = cfg[idxPoolStatus] | |
315 | 304 | let lpEmission = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
316 | 305 | let inAmAssetIdStr = toBase58String(valueOrElse(inAmAssetId, fromBase58String("WAVES"))) | |
317 | 306 | let inPrAssetIdStr = toBase58String(valueOrElse(inPrAssetId, fromBase58String("WAVES"))) | |
318 | 307 | if (if ((amAssetIdStr != inAmAssetIdStr)) | |
319 | 308 | then true | |
320 | 309 | else (prAssetIdStr != inPrAssetIdStr)) | |
321 | 310 | then throw("Invalid amt or price asset passed.") | |
322 | 311 | else { | |
323 | 312 | let amBalance = if (isEvaluate) | |
324 | 313 | then getAccBalance(amAssetIdStr) | |
325 | 314 | else (getAccBalance(amAssetIdStr) - inAmAssetAmt) | |
326 | 315 | let prBalance = if (isEvaluate) | |
327 | 316 | then getAccBalance(prAssetIdStr) | |
328 | 317 | else (getAccBalance(prAssetIdStr) - inPrAssetAmt) | |
329 | 318 | let inAmAssetAmtX18 = toX18(inAmAssetAmt, amtAssetDcm) | |
330 | 319 | let inPrAssetAmtX18 = toX18(inPrAssetAmt, priceAssetDcm) | |
331 | 320 | let userPriceX18 = calcPriceBigInt(inPrAssetAmtX18, inAmAssetAmtX18) | |
332 | 321 | let amBalanceX18 = toX18(amBalance, amtAssetDcm) | |
333 | 322 | let prBalanceX18 = toX18(prBalance, priceAssetDcm) | |
334 | 323 | let res = if ((lpEmission == 0)) | |
335 | 324 | then { | |
336 | 325 | let curPriceX18 = zeroBigInt | |
337 | 326 | let slippageX18 = zeroBigInt | |
338 | 327 | let lpAmtX18 = pow((inAmAssetAmtX18 * inPrAssetAmtX18), 0, toBigInt(5), 1, 0, DOWN) | |
339 | 328 | $Tuple5(fromX18(lpAmtX18, scale8), fromX18(inAmAssetAmtX18, amtAssetDcm), fromX18(inPrAssetAmtX18, priceAssetDcm), calcPriceBigInt((prBalanceX18 + inPrAssetAmtX18), (amBalanceX18 + inAmAssetAmtX18)), slippageX18) | |
340 | 329 | } | |
341 | 330 | else { | |
342 | 331 | let curPriceX18 = calcPriceBigInt(prBalanceX18, amBalanceX18) | |
343 | 332 | let slippageX18 = fraction(absBigInt((curPriceX18 - userPriceX18)), scale18, curPriceX18) | |
344 | 333 | let slippageToleranceX18 = toX18(slippageTolerance, scale8) | |
345 | 334 | if (if ((curPriceX18 != zeroBigInt)) | |
346 | 335 | then (slippageX18 > slippageToleranceX18) | |
347 | 336 | else false) | |
348 | 337 | then throw(((("Price slippage " + toString(slippageX18)) + " exceeded the passed limit of ") + toString(slippageToleranceX18))) | |
349 | 338 | else { | |
350 | 339 | let lpEmissionX18 = toX18(lpEmission, scale8) | |
351 | - | let prViaAmX18 = fraction(inAmAssetAmtX18, | |
352 | - | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, | |
340 | + | let prViaAmX18 = fraction(inAmAssetAmtX18, curPriceX18, scale18) | |
341 | + | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, curPriceX18) | |
353 | 342 | let expectedAmts = if ((prViaAmX18 > inPrAssetAmtX18)) | |
354 | 343 | then $Tuple2(amViaPrX18, inPrAssetAmtX18) | |
355 | 344 | else $Tuple2(inAmAssetAmtX18, prViaAmX18) | |
356 | 345 | let expAmtAssetAmtX18 = expectedAmts._1 | |
357 | 346 | let expPriceAssetAmtX18 = expectedAmts._2 | |
358 | - | let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18 | |
359 | - | $Tuple5( | |
347 | + | let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18) | |
348 | + | $Tuple5(fromX18(lpAmtX18, scale8), fromX18(expAmtAssetAmtX18, amtAssetDcm), fromX18(expPriceAssetAmtX18, priceAssetDcm), curPriceX18, slippageX18) | |
360 | 349 | } | |
361 | 350 | } | |
362 | 351 | let calcLpAmt = res._1 | |
363 | 352 | let calcAmAssetPmt = res._2 | |
364 | 353 | let calcPrAssetPmt = res._3 | |
365 | 354 | let curPrice = fromX18(res._4, scale8) | |
366 | 355 | let slippageCalc = fromX18(res._5, scale8) | |
367 | 356 | if ((0 >= calcLpAmt)) | |
368 | 357 | then throw("Invalid calculations. LP calculated is less than zero.") | |
369 | 358 | else { | |
370 | 359 | let emitLpAmt = if (!(emitLp)) | |
371 | 360 | then 0 | |
372 | 361 | else calcLpAmt | |
373 | 362 | let amDiff = (inAmAssetAmt - calcAmAssetPmt) | |
374 | 363 | let prDiff = (inPrAssetAmt - calcPrAssetPmt) | |
375 | 364 | let commonState = [IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice), StringEntry(pau(userAddress, txId58), dataPutActionInfo(calcAmAssetPmt, calcPrAssetPmt, emitLpAmt, curPrice, slippageTolerance, slippageCalc, height, lastBlock.timestamp, amDiff, prDiff))] | |
376 | 365 | $Tuple13(calcLpAmt, emitLpAmt, curPrice, amBalance, prBalance, lpEmission, lpAssetId, poolStatus, commonState, amDiff, prDiff, inAmAssetId, inPrAssetId) | |
377 | 366 | } | |
378 | 367 | } | |
379 | 368 | } | |
380 | 369 | ||
381 | 370 | ||
382 | - | func calcKLp (amountBalance,priceBalance,lpEmission) = { | |
383 | - | let updatedKLp = fraction(pow((amountBalance * priceBalance), 0, toBigInt(5), 1, 18, DOWN), big1, lpEmission) | |
384 | - | if ((lpEmission == big0)) | |
385 | - | then big0 | |
386 | - | else updatedKLp | |
387 | - | } | |
388 | - | ||
389 | - | ||
390 | - | func calcCurrentKLp (amountAssetDelta,priceAssetDelta,lpAssetEmissionDelta) = { | |
391 | - | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amountAssetDelta) | |
392 | - | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - priceAssetDelta) | |
393 | - | let lpAssetEmission = (toBigInt(value(assetInfo(cfgLpAssetId)).quantity) - lpAssetEmissionDelta) | |
394 | - | let currentKLp = calcKLp(amountAssetBalance, priceAssetBalance, lpAssetEmission) | |
395 | - | currentKLp | |
396 | - | } | |
397 | - | ||
398 | - | ||
399 | - | func refreshKLpInternal (amountAssetBalanceDelta,priceAssetBalanceDelta,lpAssetEmissionDelta) = { | |
400 | - | let amountAssetBalance = (getAccBalance(assetIdToString(cfgAmountAssetId)) + amountAssetBalanceDelta) | |
401 | - | let priceAssetBalance = (getAccBalance(assetIdToString(cfgPriceAssetId)) + priceAssetBalanceDelta) | |
402 | - | let lpAssetEmission = (value(assetInfo(cfgLpAssetId)).quantity + lpAssetEmissionDelta) | |
403 | - | let updatedKLp = calcKLp(toBigInt(amountAssetBalance), toBigInt(priceAssetBalance), toBigInt(lpAssetEmission)) | |
404 | - | let actions = [IntegerEntry(keyKLpRefreshedHeight, height), StringEntry(keyKLp, toString(updatedKLp))] | |
405 | - | $Tuple2(actions, updatedKLp) | |
406 | - | } | |
407 | - | ||
408 | - | ||
409 | - | func validateUpdatedKLp (oldKLp,updatedKLp) = if ((updatedKLp >= oldKLp)) | |
410 | - | then true | |
411 | - | else throwErr(makeString(["updated KLp lower than current KLp", toString(oldKLp), toString(updatedKLp)], " ")) | |
412 | - | ||
413 | - | ||
414 | 371 | func validateMatcherOrderAllowed (order) = { | |
415 | - | let amountAssetAmount = order.amount | |
416 | - | let priceAssetAmount = fraction(order.amount, order.price, scale8, FLOOR) | |
417 | - | let $t02077720989 = if ((order.orderType == Buy)) | |
418 | - | then $Tuple2(amountAssetAmount, -(priceAssetAmount)) | |
419 | - | else $Tuple2(-(amountAssetAmount), priceAssetAmount) | |
420 | - | let amountAssetBalanceDelta = $t02077720989._1 | |
421 | - | let priceAssetBalanceDelta = $t02077720989._2 | |
372 | + | let cfg = getPoolConfig() | |
373 | + | let amtAssetId = cfg[idxAmtAssetId] | |
374 | + | let priceAssetId = cfg[idxPriceAssetId] | |
375 | + | let poolStatus = parseIntValue(cfg[idxPoolStatus]) | |
376 | + | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
377 | + | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
378 | + | let accAmtAssetBalance = getAccBalance(amtAssetId) | |
379 | + | let accPriceAssetBalance = getAccBalance(priceAssetId) | |
380 | + | let curPriceX18 = if ((order.orderType == Buy)) | |
381 | + | then privateCalcPrice(amtAssetDcm, priceAssetDcm, (accAmtAssetBalance + order.amount), accPriceAssetBalance) | |
382 | + | else privateCalcPrice(amtAssetDcm, priceAssetDcm, (accAmtAssetBalance - order.amount), accPriceAssetBalance) | |
383 | + | let curPrice = fromX18(curPriceX18, scale8) | |
422 | 384 | if (if (if (isGlobalShutdown()) | |
423 | 385 | then true | |
424 | - | else ( | |
386 | + | else (poolStatus == PoolMatcherDisabled)) | |
425 | 387 | then true | |
426 | - | else ( | |
388 | + | else (poolStatus == PoolShutdown)) | |
427 | 389 | then throw("Exchange operations disabled") | |
428 | - | else if (if ((order.assetPair.amountAsset != cfgAmountAssetId)) | |
429 | - | then true | |
430 | - | else (order.assetPair.priceAsset != cfgPriceAssetId)) | |
431 | - | then throw("Wrong order assets.") | |
432 | - | else { | |
433 | - | let kLp = valueOrErrorMessage(parseBigInt(valueOrErrorMessage(getString(this, keyKLp), fmtErr("kLp is required"))), fmtErr("invalid kLp")) | |
434 | - | let $t02146021560 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
435 | - | let unusedActions = $t02146021560._1 | |
436 | - | let kLpNew = $t02146021560._2 | |
437 | - | let isOrderValid = (kLpNew >= kLp) | |
438 | - | isOrderValid | |
439 | - | } | |
390 | + | else { | |
391 | + | let orderAmtAsset = order.assetPair.amountAsset | |
392 | + | let orderAmtAssetStr = if ((orderAmtAsset == unit)) | |
393 | + | then "WAVES" | |
394 | + | else toBase58String(value(orderAmtAsset)) | |
395 | + | let orderPriceAsset = order.assetPair.priceAsset | |
396 | + | let orderPriceAssetStr = if ((orderPriceAsset == unit)) | |
397 | + | then "WAVES" | |
398 | + | else toBase58String(value(orderPriceAsset)) | |
399 | + | if (if ((orderAmtAssetStr != amtAssetId)) | |
400 | + | then true | |
401 | + | else (orderPriceAssetStr != priceAssetId)) | |
402 | + | then throw("Wrong order assets.") | |
403 | + | else { | |
404 | + | let orderPrice = order.price | |
405 | + | let priceDcm = fraction(scale8, priceAssetDcm, amtAssetDcm) | |
406 | + | let castedOrderPrice = toScale(orderPrice, scale8, priceDcm) | |
407 | + | let isOrderPriceValid = if ((order.orderType == Buy)) | |
408 | + | then (curPrice >= castedOrderPrice) | |
409 | + | else (castedOrderPrice >= curPrice) | |
410 | + | true | |
411 | + | } | |
412 | + | } | |
440 | 413 | } | |
441 | 414 | ||
442 | 415 | ||
443 | 416 | func commonGet (i) = if ((size(i.payments) != 1)) | |
444 | 417 | then throw("exactly 1 payment is expected") | |
445 | 418 | else { | |
446 | 419 | let pmt = value(i.payments[0]) | |
447 | 420 | let pmtAssetId = value(pmt.assetId) | |
448 | 421 | let pmtAmt = pmt.amount | |
449 | 422 | let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(pmtAssetId), pmtAmt, i.caller) | |
450 | 423 | let outAmAmt = res._1 | |
451 | 424 | let outPrAmt = res._2 | |
452 | 425 | let poolStatus = parseIntValue(res._9) | |
453 | 426 | let state = res._10 | |
454 | 427 | if (if (isGlobalShutdown()) | |
455 | 428 | then true | |
456 | 429 | else (poolStatus == PoolShutdown)) | |
457 | 430 | then throw(("Get operation is blocked by admin. Status = " + toString(poolStatus))) | |
458 | 431 | else $Tuple5(outAmAmt, outPrAmt, pmtAmt, pmtAssetId, state) | |
459 | 432 | } | |
460 | 433 | ||
461 | 434 | ||
462 | 435 | func commonPut (i,slippageTolerance,emitLp) = if ((size(i.payments) != 2)) | |
463 | 436 | then throw("exactly 2 payments are expected") | |
464 | 437 | else { | |
465 | 438 | let amAssetPmt = value(i.payments[0]) | |
466 | 439 | let prAssetPmt = value(i.payments[1]) | |
467 | 440 | let estPut = estimatePutOperation(toBase58String(i.transactionId), slippageTolerance, amAssetPmt.amount, amAssetPmt.assetId, prAssetPmt.amount, prAssetPmt.assetId, toString(i.caller), false, emitLp) | |
468 | 441 | let poolStatus = parseIntValue(estPut._8) | |
469 | 442 | if (if (if (isGlobalShutdown()) | |
470 | 443 | then true | |
471 | 444 | else (poolStatus == PoolPutDisabled)) | |
472 | 445 | then true | |
473 | 446 | else (poolStatus == PoolShutdown)) | |
474 | 447 | then throw(("Put operation is blocked by admin. Status = " + toString(poolStatus))) | |
475 | 448 | else estPut | |
476 | 449 | } | |
477 | 450 | ||
478 | 451 | ||
479 | 452 | func emit (amount) = { | |
480 | 453 | let emitInv = invoke(factoryContract, "emit", [amount], nil) | |
481 | 454 | if ((emitInv == emitInv)) | |
482 | 455 | then { | |
483 | 456 | let emitInvLegacy = match emitInv { | |
484 | 457 | case legacyFactoryContract: Address => | |
485 | 458 | invoke(legacyFactoryContract, "emit", [amount], nil) | |
486 | 459 | case _ => | |
487 | 460 | unit | |
488 | 461 | } | |
489 | 462 | if ((emitInvLegacy == emitInvLegacy)) | |
490 | 463 | then amount | |
491 | 464 | else throw("Strict value is not equal to itself.") | |
492 | 465 | } | |
493 | 466 | else throw("Strict value is not equal to itself.") | |
494 | 467 | } | |
495 | 468 | ||
496 | 469 | ||
497 | - | func takeFee (amount) = { | |
498 | - | let feeAmount = fraction(amount, fee, scale8) | |
470 | + | func takeFee (amount,fee) = { | |
471 | + | let feeAmount = if ((fee == 0)) | |
472 | + | then 0 | |
473 | + | else fraction(amount, fee, scale8) | |
499 | 474 | $Tuple2((amount - feeAmount), feeAmount) | |
500 | 475 | } | |
501 | 476 | ||
502 | 477 | ||
503 | 478 | func calcPutOneToken (paymentAmountRaw,paymentAssetId,userAddress,txId) = { | |
504 | 479 | let isEval = (txId == unit) | |
505 | 480 | let amountBalanceRaw = getAccBalance(assetIdToString(cfgAmountAssetId)) | |
506 | 481 | let priceBalanceRaw = getAccBalance(assetIdToString(cfgPriceAssetId)) | |
507 | 482 | let paymentInAmountAsset = if ((paymentAssetId == cfgAmountAssetId)) | |
508 | 483 | then true | |
509 | 484 | else if ((paymentAssetId == cfgPriceAssetId)) | |
510 | 485 | then false | |
511 | 486 | else throwErr("invalid asset") | |
512 | - | let $ | |
487 | + | let $t02266422957 = if (isEval) | |
513 | 488 | then $Tuple2(amountBalanceRaw, priceBalanceRaw) | |
514 | 489 | else if (paymentInAmountAsset) | |
515 | 490 | then $Tuple2((amountBalanceRaw - paymentAmountRaw), priceBalanceRaw) | |
516 | 491 | else $Tuple2(amountBalanceRaw, (priceBalanceRaw - paymentAmountRaw)) | |
517 | - | let amountBalanceOld = $ | |
518 | - | let priceBalanceOld = $ | |
519 | - | let $ | |
492 | + | let amountBalanceOld = $t02266422957._1 | |
493 | + | let priceBalanceOld = $t02266422957._2 | |
494 | + | let $t02296123110 = if (paymentInAmountAsset) | |
520 | 495 | then $Tuple2(paymentAmountRaw, 0) | |
521 | 496 | else $Tuple2(0, paymentAmountRaw) | |
522 | - | let amountAssetAmountRaw = $ | |
523 | - | let priceAssetAmountRaw = $ | |
524 | - | let amountAssetAmount = takeFee(amountAssetAmountRaw)._1 | |
525 | - | let priceAssetAmount = takeFee(priceAssetAmountRaw)._1 | |
526 | - | let $ | |
527 | - | let paymentAmount = $ | |
528 | - | let feeAmount = $ | |
497 | + | let amountAssetAmountRaw = $t02296123110._1 | |
498 | + | let priceAssetAmountRaw = $t02296123110._2 | |
499 | + | let amountAssetAmount = takeFee(amountAssetAmountRaw, inFee)._1 | |
500 | + | let priceAssetAmount = takeFee(priceAssetAmountRaw, inFee)._1 | |
501 | + | let $t02324223306 = takeFee(paymentAmountRaw, inFee) | |
502 | + | let paymentAmount = $t02324223306._1 | |
503 | + | let feeAmount = $t02324223306._2 | |
529 | 504 | let amountBalanceNew = (amountBalanceOld + amountAssetAmount) | |
530 | 505 | let priceBalanceNew = (priceBalanceOld + priceAssetAmount) | |
531 | 506 | let priceNewX18 = calcPriceBigInt(toX18(priceBalanceNew, cfgPriceAssetDecimals), toX18(amountBalanceNew, cfgAmountAssetDecimals)) | |
532 | 507 | let priceNew = fromX18(priceNewX18, scale8) | |
533 | 508 | let paymentBalance = if (paymentInAmountAsset) | |
534 | 509 | then amountBalanceOld | |
535 | 510 | else priceBalanceOld | |
536 | 511 | let paymentBalanceBigInt = toBigInt(paymentBalance) | |
537 | 512 | let supplyBigInt = toBigInt(valueOrErrorMessage(assetInfo(cfgLpAssetId), (("asset " + toBase58String(cfgLpAssetId)) + " doesn't exist")).quantity) | |
538 | 513 | let chechSupply = if ((supplyBigInt > big0)) | |
539 | 514 | then true | |
540 | 515 | else throwErr("initial deposit requires all coins") | |
541 | 516 | if ((chechSupply == chechSupply)) | |
542 | 517 | then { | |
543 | 518 | let depositBigInt = toBigInt(paymentAmount) | |
544 | 519 | let issueAmount = max([0, toInt(((supplyBigInt * (sqrtBigInt((scale18 + ((depositBigInt * scale18) / paymentBalanceBigInt)), 18, 18, DOWN) - scale18)) / scale18))]) | |
545 | 520 | let commonState = if (isEval) | |
546 | 521 | then nil | |
547 | 522 | else [IntegerEntry(pl(), priceNew), IntegerEntry(ph(height, lastBlock.timestamp), priceNew), StringEntry(pau(toString(value(userAddress)), toBase58String(value(txId))), dataPutActionInfo(amountAssetAmountRaw, priceAssetAmountRaw, issueAmount, priceNew, 0, 0, height, lastBlock.timestamp, 0, 0))] | |
548 | 523 | let priceOldX18 = calcPriceBigInt(toX18(priceBalanceOld, cfgPriceAssetDecimals), toX18(amountBalanceOld, cfgAmountAssetDecimals)) | |
549 | 524 | let priceOld = fromX18(priceOldX18, scale8) | |
550 | 525 | let loss = { | |
551 | - | let $ | |
526 | + | let $t02478324950 = if (paymentInAmountAsset) | |
552 | 527 | then $Tuple2(amountAssetAmountRaw, amountBalanceOld) | |
553 | 528 | else $Tuple2(priceAssetAmountRaw, priceBalanceOld) | |
554 | - | let amount = $ | |
555 | - | let balance = $ | |
529 | + | let amount = $t02478324950._1 | |
530 | + | let balance = $t02478324950._2 | |
556 | 531 | let issueAmountBoth = toInt(fraction(supplyBigInt, toBigInt((amount / 2)), toBigInt(balance))) | |
557 | 532 | fraction((issueAmount - issueAmountBoth), scale8, issueAmountBoth) | |
558 | 533 | } | |
559 | - | $ | |
534 | + | $Tuple4(issueAmount, commonState, feeAmount, loss) | |
560 | 535 | } | |
561 | 536 | else throw("Strict value is not equal to itself.") | |
562 | 537 | } | |
563 | 538 | ||
564 | 539 | ||
565 | 540 | func calcGetOneToken (outAssetId,paymentAmount,paymentAssetId,userAddress,txId) = { | |
566 | 541 | let isEval = (txId == unit) | |
567 | 542 | let checks = [if ((paymentAssetId == cfgLpAssetId)) | |
568 | 543 | then true | |
569 | 544 | else throwErr("invalid lp asset")] | |
570 | 545 | if ((checks == checks)) | |
571 | 546 | then { | |
572 | 547 | let outInAmountAsset = if ((outAssetId == cfgAmountAssetId)) | |
573 | 548 | then true | |
574 | 549 | else if ((outAssetId == cfgPriceAssetId)) | |
575 | 550 | then false | |
576 | 551 | else throwErr("invalid asset") | |
577 | 552 | let balanceBigInt = if (outInAmountAsset) | |
578 | 553 | then toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) | |
579 | 554 | else toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) | |
580 | 555 | let amBalanceOld = getAccBalance(assetIdToString(cfgAmountAssetId)) | |
581 | 556 | let prBalanceOld = getAccBalance(assetIdToString(cfgPriceAssetId)) | |
582 | 557 | let outBalance = if (outInAmountAsset) | |
583 | 558 | then amBalanceOld | |
584 | 559 | else prBalanceOld | |
585 | 560 | let outBalanceBigInt = toBigInt(outBalance) | |
586 | 561 | let supplyBigInt = toBigInt(valueOrErrorMessage(assetInfo(cfgLpAssetId), (("asset " + toBase58String(cfgLpAssetId)) + " doesn't exist")).quantity) | |
587 | 562 | let redeemedBigInt = toBigInt(paymentAmount) | |
588 | 563 | let amountRaw = max([0, toInt(((balanceBigInt * (scale18 - pow((scale18 - ((redeemedBigInt * scale18) / supplyBigInt)), 18, big2, 0, 18, DOWN))) / scale18))]) | |
589 | - | let $ | |
590 | - | let totalAmount = $ | |
591 | - | let feeAmount = $ | |
592 | - | let $ | |
564 | + | let $t02653026586 = takeFee(amountRaw, outFee) | |
565 | + | let totalAmount = $t02653026586._1 | |
566 | + | let feeAmount = $t02653026586._2 | |
567 | + | let $t02659026816 = if (outInAmountAsset) | |
593 | 568 | then $Tuple4(totalAmount, 0, (amBalanceOld - amountRaw), prBalanceOld) | |
594 | 569 | else $Tuple4(0, totalAmount, amBalanceOld, (prBalanceOld - amountRaw)) | |
595 | - | let outAmAmount = $ | |
596 | - | let outPrAmount = $ | |
597 | - | let amBalanceNew = $ | |
598 | - | let prBalanceNew = $ | |
570 | + | let outAmAmount = $t02659026816._1 | |
571 | + | let outPrAmount = $t02659026816._2 | |
572 | + | let amBalanceNew = $t02659026816._3 | |
573 | + | let prBalanceNew = $t02659026816._4 | |
599 | 574 | let priceNewX18 = calcPriceBigInt(toX18(prBalanceNew, cfgPriceAssetDecimals), toX18(amBalanceNew, cfgAmountAssetDecimals)) | |
600 | 575 | let priceNew = fromX18(priceNewX18, scale8) | |
601 | 576 | let commonState = if (isEval) | |
602 | 577 | then nil | |
603 | 578 | else [StringEntry(gau(toString(value(userAddress)), toBase58String(value(txId))), dataGetActionInfo(outAmAmount, outPrAmount, paymentAmount, priceNew, height, lastBlock.timestamp)), IntegerEntry(pl(), priceNew), IntegerEntry(ph(height, lastBlock.timestamp), priceNew)] | |
604 | 579 | let priceOldX18 = calcPriceBigInt(toX18(prBalanceOld, cfgPriceAssetDecimals), toX18(amBalanceOld, cfgAmountAssetDecimals)) | |
605 | 580 | let priceOld = fromX18(priceOldX18, scale8) | |
606 | 581 | let loss = { | |
607 | 582 | let amountBothInPaymentAsset = (toInt(fraction(balanceBigInt, redeemedBigInt, supplyBigInt)) * 2) | |
608 | 583 | fraction((totalAmount - amountBothInPaymentAsset), scale8, amountBothInPaymentAsset) | |
609 | 584 | } | |
610 | - | $ | |
585 | + | $Tuple4(totalAmount, commonState, feeAmount, loss) | |
611 | 586 | } | |
612 | 587 | else throw("Strict value is not equal to itself.") | |
613 | 588 | } | |
614 | 589 | ||
615 | 590 | ||
616 | 591 | func managerPublicKeyOrUnit () = match getString(mpk()) { | |
617 | 592 | case s: String => | |
618 | 593 | fromBase58String(s) | |
619 | 594 | case _: Unit => | |
620 | 595 | unit | |
621 | 596 | case _ => | |
622 | 597 | throw("Match error") | |
623 | 598 | } | |
624 | 599 | ||
625 | 600 | ||
626 | 601 | func pendingManagerPublicKeyOrUnit () = match getString(pmpk()) { | |
627 | 602 | case s: String => | |
628 | 603 | fromBase58String(s) | |
629 | 604 | case _: Unit => | |
630 | 605 | unit | |
631 | 606 | case _ => | |
632 | 607 | throw("Match error") | |
633 | 608 | } | |
634 | 609 | ||
635 | 610 | ||
636 | 611 | func isManager (i) = match managerPublicKeyOrUnit() { | |
637 | 612 | case pk: ByteVector => | |
638 | 613 | (i.callerPublicKey == pk) | |
639 | 614 | case _: Unit => | |
640 | 615 | (i.caller == this) | |
641 | 616 | case _ => | |
642 | 617 | throw("Match error") | |
643 | 618 | } | |
644 | 619 | ||
645 | 620 | ||
646 | 621 | func mustManager (i) = { | |
647 | 622 | let pd = throw("Permission denied") | |
648 | 623 | match managerPublicKeyOrUnit() { | |
649 | 624 | case pk: ByteVector => | |
650 | 625 | if ((i.callerPublicKey == pk)) | |
651 | 626 | then true | |
652 | 627 | else pd | |
653 | 628 | case _: Unit => | |
654 | 629 | if ((i.caller == this)) | |
655 | 630 | then true | |
656 | 631 | else pd | |
657 | 632 | case _ => | |
658 | 633 | throw("Match error") | |
659 | 634 | } | |
660 | 635 | } | |
661 | 636 | ||
662 | 637 | ||
663 | 638 | @Callable(i) | |
664 | 639 | func setManager (pendingManagerPublicKey) = { | |
665 | 640 | let checkCaller = mustManager(i) | |
666 | 641 | if ((checkCaller == checkCaller)) | |
667 | 642 | then { | |
668 | 643 | let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey) | |
669 | 644 | if ((checkManagerPublicKey == checkManagerPublicKey)) | |
670 | 645 | then [StringEntry(pmpk(), pendingManagerPublicKey)] | |
671 | 646 | else throw("Strict value is not equal to itself.") | |
672 | 647 | } | |
673 | 648 | else throw("Strict value is not equal to itself.") | |
674 | 649 | } | |
675 | 650 | ||
676 | 651 | ||
677 | 652 | ||
678 | 653 | @Callable(i) | |
679 | 654 | func confirmManager () = { | |
680 | 655 | let pm = pendingManagerPublicKeyOrUnit() | |
681 | 656 | let hasPM = if (isDefined(pm)) | |
682 | 657 | then true | |
683 | 658 | else throw("No pending manager") | |
684 | 659 | if ((hasPM == hasPM)) | |
685 | 660 | then { | |
686 | 661 | let checkPM = if ((i.callerPublicKey == value(pm))) | |
687 | 662 | then true | |
688 | 663 | else throw("You are not pending manager") | |
689 | 664 | if ((checkPM == checkPM)) | |
690 | 665 | then [StringEntry(mpk(), toBase58String(value(pm))), DeleteEntry(pmpk())] | |
691 | 666 | else throw("Strict value is not equal to itself.") | |
692 | 667 | } | |
693 | 668 | else throw("Strict value is not equal to itself.") | |
694 | 669 | } | |
695 | 670 | ||
696 | 671 | ||
697 | 672 | ||
698 | 673 | @Callable(i) | |
699 | 674 | func put (slippageTolerance,shouldAutoStake) = if ((0 > slippageTolerance)) | |
700 | 675 | then throw("Invalid slippageTolerance passed") | |
701 | 676 | else { | |
702 | 677 | let estPut = commonPut(i, slippageTolerance, true) | |
703 | 678 | let emitLpAmt = estPut._2 | |
704 | 679 | let lpAssetId = estPut._7 | |
705 | 680 | let state = estPut._9 | |
706 | 681 | let amDiff = estPut._10 | |
707 | 682 | let prDiff = estPut._11 | |
708 | 683 | let amId = estPut._12 | |
709 | 684 | let prId = estPut._13 | |
710 | - | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
711 | - | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
712 | - | let currentKLp = calcCurrentKLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
713 | - | if ((currentKLp == currentKLp)) | |
685 | + | let emitInv = invoke(factoryContract, "emit", [emitLpAmt], nil) | |
686 | + | if ((emitInv == emitInv)) | |
714 | 687 | then { | |
715 | - | let emitInv = invoke(factoryContract, "emit", [emitLpAmt], nil) | |
716 | - | if ((emitInv == emitInv)) | |
688 | + | let emitInvLegacy = match emitInv { | |
689 | + | case legacyFactoryContract: Address => | |
690 | + | invoke(legacyFactoryContract, "emit", [emitLpAmt], nil) | |
691 | + | case _ => | |
692 | + | unit | |
693 | + | } | |
694 | + | if ((emitInvLegacy == emitInvLegacy)) | |
717 | 695 | then { | |
718 | - | let emitInvLegacy = match emitInv { | |
719 | - | case legacyFactoryContract: Address => | |
720 | - | invoke(legacyFactoryContract, "emit", [emitLpAmt], nil) | |
721 | - | case _ => | |
722 | - | unit | |
723 | - | } | |
724 | - | if ((emitInvLegacy == emitInvLegacy)) | |
696 | + | let slippageAInv = if ((amDiff > 0)) | |
697 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(amId, amDiff)]) | |
698 | + | else nil | |
699 | + | if ((slippageAInv == slippageAInv)) | |
725 | 700 | then { | |
726 | - | let | |
727 | - | then invoke(slippageContract, "put", nil, [AttachedPayment( | |
701 | + | let slippagePInv = if ((prDiff > 0)) | |
702 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(prId, prDiff)]) | |
728 | 703 | else nil | |
729 | - | if (( | |
704 | + | if ((slippagePInv == slippagePInv)) | |
730 | 705 | then { | |
731 | - | let slippagePInv = if ((prDiff > 0)) | |
732 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(prId, prDiff)]) | |
733 | - | else nil | |
734 | - | if ((slippagePInv == slippagePInv)) | |
706 | + | let lpTransfer = if (shouldAutoStake) | |
735 | 707 | then { | |
736 | - | let lpTransfer = if (shouldAutoStake) | |
737 | - | then { | |
738 | - | let slpStakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
739 | - | if ((slpStakeInv == slpStakeInv)) | |
740 | - | then nil | |
741 | - | else throw("Strict value is not equal to itself.") | |
742 | - | } | |
743 | - | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
744 | - | let $t03292633388 = refreshKLpInternal(0, 0, 0) | |
745 | - | if (($t03292633388 == $t03292633388)) | |
746 | - | then { | |
747 | - | let updatedKLp = $t03292633388._2 | |
748 | - | let refreshKLpActions = $t03292633388._1 | |
749 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
750 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
751 | - | then ((state ++ lpTransfer) ++ refreshKLpActions) | |
752 | - | else throw("Strict value is not equal to itself.") | |
753 | - | } | |
708 | + | let slpStakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
709 | + | if ((slpStakeInv == slpStakeInv)) | |
710 | + | then nil | |
754 | 711 | else throw("Strict value is not equal to itself.") | |
755 | 712 | } | |
756 | - | else throw("Strict value is not equal to itself.") | |
713 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
714 | + | (state ++ lpTransfer) | |
757 | 715 | } | |
758 | 716 | else throw("Strict value is not equal to itself.") | |
759 | 717 | } | |
760 | 718 | else throw("Strict value is not equal to itself.") | |
761 | 719 | } | |
762 | 720 | else throw("Strict value is not equal to itself.") | |
763 | 721 | } | |
764 | 722 | else throw("Strict value is not equal to itself.") | |
765 | 723 | } | |
766 | 724 | ||
767 | 725 | ||
768 | 726 | ||
769 | 727 | @Callable(i) | |
770 | 728 | func putForFree (maxSlippage) = if ((0 > maxSlippage)) | |
771 | 729 | then throw("Invalid value passed") | |
772 | 730 | else { | |
773 | 731 | let estPut = commonPut(i, maxSlippage, false) | |
774 | - | let state = estPut._9 | |
775 | - | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
776 | - | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
777 | - | let currentKLp = calcCurrentKLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
778 | - | if ((currentKLp == currentKLp)) | |
779 | - | then { | |
780 | - | let $t03395034015 = refreshKLpInternal(0, 0, 0) | |
781 | - | let refreshKLpActions = $t03395034015._1 | |
782 | - | let updatedKLp = $t03395034015._2 | |
783 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
784 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
785 | - | then (state ++ refreshKLpActions) | |
786 | - | else throw("Strict value is not equal to itself.") | |
787 | - | } | |
788 | - | else throw("Strict value is not equal to itself.") | |
732 | + | estPut._9 | |
789 | 733 | } | |
790 | 734 | ||
791 | 735 | ||
792 | 736 | ||
793 | 737 | @Callable(i) | |
794 | 738 | func putOneTkn (minOutAmount,autoStake) = { | |
795 | 739 | let isPoolOneTokenOperationsDisabled = { | |
796 | 740 | let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
797 | 741 | if ($isInstanceOf(@, "Boolean")) | |
798 | 742 | then @ | |
799 | 743 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
800 | 744 | } | |
801 | 745 | let isPutDisabled = if (if (if (isGlobalShutdown()) | |
802 | 746 | then true | |
803 | 747 | else (cfgPoolStatus == PoolPutDisabled)) | |
804 | 748 | then true | |
805 | 749 | else (cfgPoolStatus == PoolShutdown)) | |
806 | 750 | then true | |
807 | 751 | else isPoolOneTokenOperationsDisabled | |
808 | 752 | let checks = [if (if (!(isPutDisabled)) | |
809 | 753 | then true | |
810 | 754 | else isManager(i)) | |
811 | 755 | then true | |
812 | 756 | else throwErr("put operation is blocked by admin"), if ((size(i.payments) == 1)) | |
813 | 757 | then true | |
814 | 758 | else throwErr("exactly 1 payment are expected")] | |
815 | 759 | if ((checks == checks)) | |
816 | 760 | then { | |
817 | 761 | let payment = i.payments[0] | |
818 | 762 | let paymentAssetId = payment.assetId | |
819 | 763 | let paymentAmountRaw = payment.amount | |
820 | - | let currentKLp = if ((paymentAssetId == cfgAmountAssetId)) | |
821 | - | then calcCurrentKLp(toBigInt(paymentAmountRaw), toBigInt(0), toBigInt(0)) | |
822 | - | else if ((paymentAssetId == cfgPriceAssetId)) | |
823 | - | then calcCurrentKLp(toBigInt(0), toBigInt(paymentAmountRaw), toBigInt(0)) | |
824 | - | else throwErr("payment asset is not supported") | |
825 | 764 | let userAddress = i.caller | |
826 | 765 | let txId = i.transactionId | |
827 | - | let $ | |
828 | - | if (($ | |
766 | + | let $t03172331853 = calcPutOneToken(paymentAmountRaw, paymentAssetId, userAddress, txId) | |
767 | + | if (($t03172331853 == $t03172331853)) | |
829 | 768 | then { | |
830 | - | let paymentInAmountAsset = $t03520035352._5 | |
831 | - | let bonus = $t03520035352._4 | |
832 | - | let feeAmount = $t03520035352._3 | |
833 | - | let commonState = $t03520035352._2 | |
834 | - | let emitAmountEstimated = $t03520035352._1 | |
769 | + | let bonus = $t03172331853._4 | |
770 | + | let feeAmount = $t03172331853._3 | |
771 | + | let commonState = $t03172331853._2 | |
772 | + | let emitAmountEstimated = $t03172331853._1 | |
835 | 773 | let emitAmount = if (if ((minOutAmount > 0)) | |
836 | 774 | then (minOutAmount > emitAmountEstimated) | |
837 | 775 | else false) | |
838 | 776 | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
839 | 777 | else emitAmountEstimated | |
840 | 778 | let emitInv = emit(emitAmount) | |
841 | 779 | if ((emitInv == emitInv)) | |
842 | 780 | then { | |
843 | 781 | let lpTransfer = if (autoStake) | |
844 | 782 | then { | |
845 | 783 | let stakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(cfgLpAssetId, emitAmount)]) | |
846 | 784 | if ((stakeInv == stakeInv)) | |
847 | 785 | then nil | |
848 | 786 | else throw("Strict value is not equal to itself.") | |
849 | 787 | } | |
850 | 788 | else [ScriptTransfer(i.caller, emitAmount, cfgLpAssetId)] | |
851 | 789 | let sendFee = if ((feeAmount > 0)) | |
852 | 790 | then [ScriptTransfer(feeCollectorAddress, feeAmount, paymentAssetId)] | |
853 | 791 | else nil | |
854 | - | let $t03593836135 = if ((this == feeCollectorAddress)) | |
855 | - | then $Tuple2(0, 0) | |
856 | - | else if (paymentInAmountAsset) | |
857 | - | then $Tuple2(-(feeAmount), 0) | |
858 | - | else $Tuple2(0, -(feeAmount)) | |
859 | - | let amountAssetBalanceDelta = $t03593836135._1 | |
860 | - | let priceAssetBalanceDelta = $t03593836135._2 | |
861 | - | let $t03613836246 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
862 | - | let refreshKLpActions = $t03613836246._1 | |
863 | - | let updatedKLp = $t03613836246._2 | |
864 | - | let kLp = value(getString(keyKLp)) | |
865 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
866 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
867 | - | then $Tuple2((((commonState ++ lpTransfer) ++ sendFee) ++ refreshKLpActions), emitAmount) | |
868 | - | else throw("Strict value is not equal to itself.") | |
792 | + | $Tuple2(((commonState ++ lpTransfer) ++ sendFee), emitAmount) | |
869 | 793 | } | |
870 | 794 | else throw("Strict value is not equal to itself.") | |
871 | 795 | } | |
872 | 796 | else throw("Strict value is not equal to itself.") | |
873 | 797 | } | |
874 | 798 | else throw("Strict value is not equal to itself.") | |
875 | 799 | } | |
876 | 800 | ||
877 | 801 | ||
878 | 802 | ||
879 | 803 | @Callable(i) | |
880 | 804 | func putOneTknREADONLY (paymentAssetId,paymentAmountRaw) = { | |
881 | - | let $t03655236709 = calcPutOneToken(paymentAmountRaw, parseAssetId(paymentAssetId), unit, unit) | |
882 | - | let emitAmountEstimated = $t03655236709._1 | |
883 | - | let commonState = $t03655236709._2 | |
884 | - | let feeAmount = $t03655236709._3 | |
885 | - | let bonus = $t03655236709._4 | |
886 | - | let paymentInAmountAsset = $t03655236709._5 | |
805 | + | let $t03258232717 = calcPutOneToken(paymentAmountRaw, parseAssetId(paymentAssetId), unit, unit) | |
806 | + | let emitAmountEstimated = $t03258232717._1 | |
807 | + | let commonState = $t03258232717._2 | |
808 | + | let feeAmount = $t03258232717._3 | |
809 | + | let bonus = $t03258232717._4 | |
887 | 810 | $Tuple2(nil, $Tuple3(emitAmountEstimated, feeAmount, bonus)) | |
888 | 811 | } | |
889 | 812 | ||
890 | 813 | ||
891 | 814 | ||
892 | 815 | @Callable(i) | |
893 | 816 | func getOneTkn (outAssetIdStr,minOutAmount) = { | |
894 | 817 | let isPoolOneTokenOperationsDisabled = { | |
895 | 818 | let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
896 | 819 | if ($isInstanceOf(@, "Boolean")) | |
897 | 820 | then @ | |
898 | 821 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
899 | 822 | } | |
900 | 823 | let isGetDisabled = if (if (isGlobalShutdown()) | |
901 | 824 | then true | |
902 | 825 | else (cfgPoolStatus == PoolShutdown)) | |
903 | 826 | then true | |
904 | 827 | else isPoolOneTokenOperationsDisabled | |
905 | 828 | let checks = [if (if (!(isGetDisabled)) | |
906 | 829 | then true | |
907 | 830 | else isManager(i)) | |
908 | 831 | then true | |
909 | 832 | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 1)) | |
910 | 833 | then true | |
911 | 834 | else throwErr("exactly 1 payment are expected")] | |
912 | 835 | if ((checks == checks)) | |
913 | 836 | then { | |
914 | 837 | let outAssetId = parseAssetId(outAssetIdStr) | |
915 | 838 | let payment = i.payments[0] | |
916 | 839 | let paymentAssetId = payment.assetId | |
917 | 840 | let paymentAmount = payment.amount | |
918 | - | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(paymentAmount)) | |
919 | 841 | let userAddress = i.caller | |
920 | 842 | let txId = i.transactionId | |
921 | - | let $ | |
922 | - | if (($ | |
843 | + | let $t03352233657 = calcGetOneToken(outAssetId, paymentAmount, paymentAssetId, userAddress, txId) | |
844 | + | if (($t03352233657 == $t03352233657)) | |
923 | 845 | then { | |
924 | - | let outInAmountAsset = $t03760337756._5 | |
925 | - | let bonus = $t03760337756._4 | |
926 | - | let feeAmount = $t03760337756._3 | |
927 | - | let commonState = $t03760337756._2 | |
928 | - | let amountEstimated = $t03760337756._1 | |
846 | + | let bonus = $t03352233657._4 | |
847 | + | let feeAmount = $t03352233657._3 | |
848 | + | let commonState = $t03352233657._2 | |
849 | + | let amountEstimated = $t03352233657._1 | |
929 | 850 | let amount = if (if ((minOutAmount > 0)) | |
930 | 851 | then (minOutAmount > amountEstimated) | |
931 | 852 | else false) | |
932 | 853 | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
933 | 854 | else amountEstimated | |
934 | 855 | let burnInv = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)]) | |
935 | 856 | if ((burnInv == burnInv)) | |
936 | 857 | then { | |
937 | 858 | let assetTransfer = [ScriptTransfer(userAddress, amount, outAssetId)] | |
938 | 859 | let sendFee = if ((feeAmount > 0)) | |
939 | 860 | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)] | |
940 | 861 | else nil | |
941 | - | let $t03825638503 = { | |
942 | - | let feeAmountForCalc = if ((this == feeCollectorAddress)) | |
943 | - | then 0 | |
944 | - | else feeAmount | |
945 | - | if (outInAmountAsset) | |
946 | - | then $Tuple2(-((amount + feeAmountForCalc)), 0) | |
947 | - | else $Tuple2(0, -((amount + feeAmountForCalc))) | |
948 | - | } | |
949 | - | let amountAssetBalanceDelta = $t03825638503._1 | |
950 | - | let priceAssetBalanceDelta = $t03825638503._2 | |
951 | - | let $t03850638614 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
952 | - | let refreshKLpActions = $t03850638614._1 | |
953 | - | let updatedKLp = $t03850638614._2 | |
954 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
955 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
956 | - | then $Tuple2((((commonState ++ assetTransfer) ++ sendFee) ++ refreshKLpActions), amount) | |
957 | - | else throw("Strict value is not equal to itself.") | |
862 | + | $Tuple2(((commonState ++ assetTransfer) ++ sendFee), amount) | |
958 | 863 | } | |
959 | 864 | else throw("Strict value is not equal to itself.") | |
960 | 865 | } | |
961 | 866 | else throw("Strict value is not equal to itself.") | |
962 | 867 | } | |
963 | 868 | else throw("Strict value is not equal to itself.") | |
964 | 869 | } | |
965 | 870 | ||
966 | 871 | ||
967 | 872 | ||
968 | 873 | @Callable(i) | |
969 | 874 | func getOneTknREADONLY (outAssetId,paymentAmount) = { | |
970 | - | let $t03887139027 = calcGetOneToken(parseAssetId(outAssetId), paymentAmount, cfgLpAssetId, unit, unit) | |
971 | - | let amountEstimated = $t03887139027._1 | |
972 | - | let commonState = $t03887139027._2 | |
973 | - | let feeAmount = $t03887139027._3 | |
974 | - | let bonus = $t03887139027._4 | |
975 | - | let outInAmountAsset = $t03887139027._5 | |
875 | + | let $t03429234430 = calcGetOneToken(parseAssetId(outAssetId), paymentAmount, cfgLpAssetId, unit, unit) | |
876 | + | let amountEstimated = $t03429234430._1 | |
877 | + | let commonState = $t03429234430._2 | |
878 | + | let feeAmount = $t03429234430._3 | |
879 | + | let bonus = $t03429234430._4 | |
976 | 880 | $Tuple2(nil, $Tuple3(amountEstimated, feeAmount, bonus)) | |
977 | 881 | } | |
978 | 882 | ||
979 | 883 | ||
980 | 884 | ||
981 | 885 | @Callable(i) | |
982 | 886 | func unstakeAndGetOneTkn (unstakeAmount,outAssetIdStr,minOutAmount) = { | |
983 | 887 | let isPoolOneTokenOperationsDisabled = { | |
984 | 888 | let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
985 | 889 | if ($isInstanceOf(@, "Boolean")) | |
986 | 890 | then @ | |
987 | 891 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
988 | 892 | } | |
989 | 893 | let isGetDisabled = if (if (isGlobalShutdown()) | |
990 | 894 | then true | |
991 | 895 | else (cfgPoolStatus == PoolShutdown)) | |
992 | 896 | then true | |
993 | 897 | else isPoolOneTokenOperationsDisabled | |
994 | 898 | let checks = [if (if (!(isGetDisabled)) | |
995 | 899 | then true | |
996 | 900 | else isManager(i)) | |
997 | 901 | then true | |
998 | 902 | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
999 | 903 | then true | |
1000 | 904 | else throwErr("no payments are expected")] | |
1001 | 905 | if ((checks == checks)) | |
1002 | 906 | then { | |
1003 | 907 | let outAssetId = parseAssetId(outAssetIdStr) | |
1004 | 908 | let userAddress = i.caller | |
1005 | 909 | let txId = i.transactionId | |
1006 | - | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1007 | 910 | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1008 | 911 | if ((unstakeInv == unstakeInv)) | |
1009 | 912 | then { | |
1010 | - | let $ | |
1011 | - | if (($ | |
913 | + | let $t03525535388 = calcGetOneToken(outAssetId, unstakeAmount, cfgLpAssetId, userAddress, txId) | |
914 | + | if (($t03525535388 == $t03525535388)) | |
1012 | 915 | then { | |
1013 | - | let outInAmountAsset = $t03992940080._5 | |
1014 | - | let bonus = $t03992940080._4 | |
1015 | - | let feeAmount = $t03992940080._3 | |
1016 | - | let commonState = $t03992940080._2 | |
1017 | - | let amountEstimated = $t03992940080._1 | |
916 | + | let bonus = $t03525535388._4 | |
917 | + | let feeAmount = $t03525535388._3 | |
918 | + | let commonState = $t03525535388._2 | |
919 | + | let amountEstimated = $t03525535388._1 | |
1018 | 920 | let amount = if (if ((minOutAmount > 0)) | |
1019 | 921 | then (minOutAmount > amountEstimated) | |
1020 | 922 | else false) | |
1021 | 923 | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
1022 | 924 | else amountEstimated | |
1023 | 925 | let burnInv = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1024 | 926 | if ((burnInv == burnInv)) | |
1025 | 927 | then { | |
1026 | 928 | let assetTransfer = [ScriptTransfer(i.caller, amount, outAssetId)] | |
1027 | 929 | let sendFee = if ((feeAmount > 0)) | |
1028 | 930 | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)] | |
1029 | 931 | else nil | |
1030 | - | let $t04057540822 = { | |
1031 | - | let feeAmountForCalc = if ((this == feeCollectorAddress)) | |
1032 | - | then 0 | |
1033 | - | else feeAmount | |
1034 | - | if (outInAmountAsset) | |
1035 | - | then $Tuple2(-((amount + feeAmountForCalc)), 0) | |
1036 | - | else $Tuple2(0, -((amount + feeAmountForCalc))) | |
1037 | - | } | |
1038 | - | let amountAssetBalanceDelta = $t04057540822._1 | |
1039 | - | let priceAssetBalanceDelta = $t04057540822._2 | |
1040 | - | let $t04082540933 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1041 | - | let refreshKLpActions = $t04082540933._1 | |
1042 | - | let updatedKLp = $t04082540933._2 | |
1043 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1044 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1045 | - | then $Tuple2((((commonState ++ assetTransfer) ++ sendFee) ++ refreshKLpActions), amount) | |
1046 | - | else throw("Strict value is not equal to itself.") | |
932 | + | $Tuple2(((commonState ++ assetTransfer) ++ sendFee), amount) | |
1047 | 933 | } | |
1048 | 934 | else throw("Strict value is not equal to itself.") | |
1049 | 935 | } | |
1050 | 936 | else throw("Strict value is not equal to itself.") | |
1051 | 937 | } | |
1052 | 938 | else throw("Strict value is not equal to itself.") | |
1053 | 939 | } | |
1054 | 940 | else throw("Strict value is not equal to itself.") | |
1055 | 941 | } | |
1056 | 942 | ||
1057 | 943 | ||
1058 | 944 | ||
1059 | 945 | @Callable(i) | |
1060 | 946 | func get () = { | |
1061 | 947 | let res = commonGet(i) | |
1062 | 948 | let outAmtAmt = res._1 | |
1063 | 949 | let outPrAmt = res._2 | |
1064 | 950 | let pmtAmt = res._3 | |
1065 | 951 | let pmtAssetId = res._4 | |
1066 | 952 | let state = res._5 | |
1067 | - | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(pmtAmt)) | |
1068 | 953 | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1069 | 954 | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1070 | - | then { | |
1071 | - | let $t04188141963 = refreshKLpInternal(-(outAmtAmt), -(outPrAmt), 0) | |
1072 | - | let refreshKLpActions = $t04188141963._1 | |
1073 | - | let updatedKLp = $t04188141963._2 | |
1074 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1075 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1076 | - | then (state ++ refreshKLpActions) | |
1077 | - | else throw("Strict value is not equal to itself.") | |
1078 | - | } | |
955 | + | then state | |
1079 | 956 | else throw("Strict value is not equal to itself.") | |
1080 | 957 | } | |
1081 | 958 | ||
1082 | 959 | ||
1083 | 960 | ||
1084 | 961 | @Callable(i) | |
1085 | 962 | func getNoLess (noLessThenAmtAsset,noLessThenPriceAsset) = { | |
1086 | 963 | let res = commonGet(i) | |
1087 | 964 | let outAmAmt = res._1 | |
1088 | 965 | let outPrAmt = res._2 | |
1089 | 966 | let pmtAmt = res._3 | |
1090 | 967 | let pmtAssetId = res._4 | |
1091 | 968 | let state = res._5 | |
1092 | 969 | if ((noLessThenAmtAsset > outAmAmt)) | |
1093 | 970 | then throw(((("noLessThenAmtAsset failed: " + toString(outAmAmt)) + " < ") + toString(noLessThenAmtAsset))) | |
1094 | 971 | else if ((noLessThenPriceAsset > outPrAmt)) | |
1095 | 972 | then throw(((("noLessThenPriceAsset failed: " + toString(outPrAmt)) + " < ") + toString(noLessThenPriceAsset))) | |
1096 | 973 | else { | |
1097 | - | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(pmtAmt)) | |
1098 | 974 | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1099 | 975 | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1100 | - | then { | |
1101 | - | let $t04291442995 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1102 | - | let refreshKLpActions = $t04291442995._1 | |
1103 | - | let updatedKLp = $t04291442995._2 | |
1104 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1105 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1106 | - | then (state ++ refreshKLpActions) | |
1107 | - | else throw("Strict value is not equal to itself.") | |
1108 | - | } | |
976 | + | then state | |
1109 | 977 | else throw("Strict value is not equal to itself.") | |
1110 | 978 | } | |
1111 | 979 | } | |
1112 | 980 | ||
1113 | 981 | ||
1114 | 982 | ||
1115 | 983 | @Callable(i) | |
1116 | 984 | func unstakeAndGet (amount) = { | |
1117 | 985 | let checkPayments = if ((size(i.payments) != 0)) | |
1118 | 986 | then throw("No payments are expected") | |
1119 | 987 | else true | |
1120 | 988 | if ((checkPayments == checkPayments)) | |
1121 | 989 | then { | |
1122 | 990 | let cfg = getPoolConfig() | |
1123 | 991 | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
1124 | - | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1125 | 992 | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(lpAssetId), amount], nil) | |
1126 | 993 | if ((unstakeInv == unstakeInv)) | |
1127 | 994 | then { | |
1128 | 995 | let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
1129 | - | let outAmAmt = res._1 | |
1130 | - | let outPrAmt = res._2 | |
1131 | 996 | let poolStatus = parseIntValue(res._9) | |
1132 | 997 | let state = res._10 | |
1133 | 998 | let checkPoolStatus = if (if (isGlobalShutdown()) | |
1134 | 999 | then true | |
1135 | 1000 | else (poolStatus == PoolShutdown)) | |
1136 | 1001 | then throw(("Get operation is blocked by admin. Status = " + toString(poolStatus))) | |
1137 | 1002 | else true | |
1138 | 1003 | if ((checkPoolStatus == checkPoolStatus)) | |
1139 | 1004 | then { | |
1140 | 1005 | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1141 | 1006 | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1142 | - | then { | |
1143 | - | let $t04411844199 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1144 | - | let refreshKLpActions = $t04411844199._1 | |
1145 | - | let updatedKLp = $t04411844199._2 | |
1146 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1147 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1148 | - | then (state ++ refreshKLpActions) | |
1149 | - | else throw("Strict value is not equal to itself.") | |
1150 | - | } | |
1007 | + | then state | |
1151 | 1008 | else throw("Strict value is not equal to itself.") | |
1152 | 1009 | } | |
1153 | 1010 | else throw("Strict value is not equal to itself.") | |
1154 | 1011 | } | |
1155 | 1012 | else throw("Strict value is not equal to itself.") | |
1156 | 1013 | } | |
1157 | 1014 | else throw("Strict value is not equal to itself.") | |
1158 | 1015 | } | |
1159 | 1016 | ||
1160 | 1017 | ||
1161 | 1018 | ||
1162 | 1019 | @Callable(i) | |
1163 | 1020 | func unstakeAndGetNoLess (unstakeAmount,noLessThenAmountAsset,noLessThenPriceAsset) = { | |
1164 | 1021 | let isGetDisabled = if (isGlobalShutdown()) | |
1165 | 1022 | then true | |
1166 | 1023 | else (cfgPoolStatus == PoolShutdown) | |
1167 | 1024 | let checks = [if (!(isGetDisabled)) | |
1168 | 1025 | then true | |
1169 | 1026 | else throw("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1170 | 1027 | then true | |
1171 | 1028 | else throw("no payments are expected")] | |
1172 | 1029 | if ((checks == checks)) | |
1173 | 1030 | then { | |
1174 | - | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1175 | 1031 | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1176 | 1032 | if ((unstakeInv == unstakeInv)) | |
1177 | 1033 | then { | |
1178 | 1034 | let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller) | |
1179 | 1035 | let outAmAmt = res._1 | |
1180 | 1036 | let outPrAmt = res._2 | |
1181 | 1037 | let state = res._10 | |
1182 | 1038 | let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset)) | |
1183 | 1039 | then true | |
1184 | 1040 | else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset)) | |
1185 | 1041 | then true | |
1186 | 1042 | else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))] | |
1187 | 1043 | if ((checkAmounts == checkAmounts)) | |
1188 | 1044 | then { | |
1189 | 1045 | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1190 | 1046 | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1191 | - | then { | |
1192 | - | let $t04549145572 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1193 | - | let refreshKLpActions = $t04549145572._1 | |
1194 | - | let updatedKLp = $t04549145572._2 | |
1195 | - | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1196 | - | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1197 | - | then (state ++ refreshKLpActions) | |
1198 | - | else throw("Strict value is not equal to itself.") | |
1199 | - | } | |
1047 | + | then state | |
1200 | 1048 | else throw("Strict value is not equal to itself.") | |
1201 | 1049 | } | |
1202 | 1050 | else throw("Strict value is not equal to itself.") | |
1203 | 1051 | } | |
1204 | 1052 | else throw("Strict value is not equal to itself.") | |
1205 | 1053 | } | |
1206 | 1054 | else throw("Strict value is not equal to itself.") | |
1207 | 1055 | } | |
1208 | 1056 | ||
1209 | 1057 | ||
1210 | 1058 | ||
1211 | 1059 | @Callable(i) | |
1212 | 1060 | func activate (amtAssetStr,priceAssetStr) = if ((toString(i.caller) != toString(factoryContract))) | |
1213 | 1061 | then throw("permissions denied") | |
1214 | 1062 | else $Tuple2([StringEntry(aa(), amtAssetStr), StringEntry(pa(), priceAssetStr)], "success") | |
1215 | - | ||
1216 | - | ||
1217 | - | ||
1218 | - | @Callable(i) | |
1219 | - | func refreshKLp () = { | |
1220 | - | let lastRefreshedBlockHeight = valueOrElse(getInteger(keyKLpRefreshedHeight), 0) | |
1221 | - | let checkLastRefreshedBlockHeight = if (((height - lastRefreshedBlockHeight) >= kLpRefreshDelay)) | |
1222 | - | then unit | |
1223 | - | else throwErr(makeString([toString(kLpRefreshDelay), " blocks have not passed since the previous call"], "")) | |
1224 | - | if ((checkLastRefreshedBlockHeight == checkLastRefreshedBlockHeight)) | |
1225 | - | then { | |
1226 | - | let kLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyKLp), "0")), fmtErr("invalid kLp")) | |
1227 | - | let $t04675946823 = refreshKLpInternal(0, 0, 0) | |
1228 | - | let kLpUpdateActions = $t04675946823._1 | |
1229 | - | let updatedKLp = $t04675946823._2 | |
1230 | - | let actions = if ((kLp != updatedKLp)) | |
1231 | - | then kLpUpdateActions | |
1232 | - | else throwErr("nothing to refresh") | |
1233 | - | $Tuple2(actions, toString(updatedKLp)) | |
1234 | - | } | |
1235 | - | else throw("Strict value is not equal to itself.") | |
1236 | - | } | |
1237 | 1063 | ||
1238 | 1064 | ||
1239 | 1065 | ||
1240 | 1066 | @Callable(i) | |
1241 | 1067 | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, getPoolConfig()) | |
1242 | 1068 | ||
1243 | 1069 | ||
1244 | 1070 | ||
1245 | 1071 | @Callable(i) | |
1246 | 1072 | func getAccBalanceWrapperREADONLY (assetId) = $Tuple2(nil, getAccBalance(assetId)) | |
1247 | 1073 | ||
1248 | 1074 | ||
1249 | 1075 | ||
1250 | 1076 | @Callable(i) | |
1251 | 1077 | func calcPricesWrapperREADONLY (amAmt,prAmt,lpAmt) = { | |
1252 | 1078 | let prices = calcPrices(amAmt, prAmt, lpAmt) | |
1253 | 1079 | $Tuple2(nil, [toString(prices[0]), toString(prices[1]), toString(prices[2])]) | |
1254 | 1080 | } | |
1255 | 1081 | ||
1256 | 1082 | ||
1257 | 1083 | ||
1258 | 1084 | @Callable(i) | |
1259 | 1085 | func toX18WrapperREADONLY (origVal,origScaleMult) = $Tuple2(nil, toString(toX18(origVal, origScaleMult))) | |
1260 | 1086 | ||
1261 | 1087 | ||
1262 | 1088 | ||
1263 | 1089 | @Callable(i) | |
1264 | 1090 | func fromX18WrapperREADONLY (val,resultScaleMult) = $Tuple2(nil, fromX18(parseBigIntValue(val), resultScaleMult)) | |
1265 | 1091 | ||
1266 | 1092 | ||
1267 | 1093 | ||
1268 | 1094 | @Callable(i) | |
1269 | 1095 | func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString(calcPriceBigInt(parseBigIntValue(prAmtX18), parseBigIntValue(amAmtX18)))) | |
1270 | 1096 | ||
1271 | 1097 | ||
1272 | 1098 | ||
1273 | 1099 | @Callable(i) | |
1274 | 1100 | func estimatePutOperationWrapperREADONLY (txId58,slippageTolerance,inAmAssetAmt,inAmAssetId,inPrAssetAmt,inPrAssetId,userAddress,isEvaluate,emitLp) = $Tuple2(nil, estimatePutOperation(txId58, slippageTolerance, inAmAssetAmt, inAmAssetId, inPrAssetAmt, inPrAssetId, userAddress, isEvaluate, emitLp)) | |
1275 | 1101 | ||
1276 | 1102 | ||
1277 | 1103 | ||
1278 | 1104 | @Callable(i) | |
1279 | 1105 | func estimateGetOperationWrapperREADONLY (txId58,pmtAssetId,pmtLpAmt,userAddress) = { | |
1280 | 1106 | let res = estimateGetOperation(txId58, pmtAssetId, pmtLpAmt, addressFromStringValue(userAddress)) | |
1281 | 1107 | $Tuple2(nil, $Tuple10(res._1, res._2, res._3, res._4, res._5, res._6, res._7, toString(res._8), res._9, res._10)) | |
1282 | 1108 | } | |
1283 | 1109 | ||
1284 | 1110 | ||
1285 | 1111 | ||
1286 | 1112 | @Callable(i) | |
1287 | 1113 | func statsREADONLY () = { | |
1288 | 1114 | let cfg = getPoolConfig() | |
1289 | 1115 | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
1290 | 1116 | let amtAssetId = cfg[idxAmtAssetId] | |
1291 | 1117 | let priceAssetId = cfg[idxPriceAssetId] | |
1292 | 1118 | let iAmtAssetId = cfg[idxIAmtAssetId] | |
1293 | 1119 | let iPriceAssetId = cfg[idxIPriceAssetId] | |
1294 | 1120 | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
1295 | 1121 | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
1296 | 1122 | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
1297 | 1123 | let accAmtAssetBalance = getAccBalance(amtAssetId) | |
1298 | 1124 | let accPriceAssetBalance = getAccBalance(priceAssetId) | |
1299 | 1125 | let pricesList = if ((poolLPBalance == 0)) | |
1300 | 1126 | then [zeroBigInt, zeroBigInt, zeroBigInt] | |
1301 | 1127 | else calcPrices(accAmtAssetBalance, accPriceAssetBalance, poolLPBalance) | |
1302 | 1128 | let curPrice = 0 | |
1303 | 1129 | let lpAmtAssetShare = fromX18(pricesList[1], scale8) | |
1304 | 1130 | let lpPriceAssetShare = fromX18(pricesList[2], scale8) | |
1305 | 1131 | let poolWeight = value(getInteger(factoryContract, keyPoolWeight(toString(this)))) | |
1306 | 1132 | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d", toString(accAmtAssetBalance), toString(accPriceAssetBalance), toString(poolLPBalance), toString(curPrice), toString(lpAmtAssetShare), toString(lpPriceAssetShare), toString(poolWeight)], SEP)) | |
1307 | 1133 | } | |
1308 | 1134 | ||
1309 | 1135 | ||
1310 | 1136 | ||
1311 | 1137 | @Callable(i) | |
1312 | 1138 | func evaluatePutByAmountAssetREADONLY (inAmAssetAmt) = { | |
1313 | 1139 | let cfg = getPoolConfig() | |
1314 | 1140 | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
1315 | 1141 | let amAssetIdStr = cfg[idxAmtAssetId] | |
1316 | 1142 | let amAssetId = fromBase58String(amAssetIdStr) | |
1317 | 1143 | let prAssetIdStr = cfg[idxPriceAssetId] | |
1318 | 1144 | let prAssetId = fromBase58String(prAssetIdStr) | |
1319 | 1145 | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
1320 | 1146 | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
1321 | 1147 | let poolStatus = cfg[idxPoolStatus] | |
1322 | 1148 | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
1323 | 1149 | let accAmtAssetBalance = getAccBalance(amAssetIdStr) | |
1324 | 1150 | let accPriceAssetBalance = getAccBalance(prAssetIdStr) | |
1325 | 1151 | let amtAssetAmtX18 = toX18(accAmtAssetBalance, amtAssetDcm) | |
1326 | 1152 | let priceAssetAmtX18 = toX18(accPriceAssetBalance, priceAssetDcm) | |
1327 | 1153 | let curPriceX18 = if ((poolLPBalance == 0)) | |
1328 | 1154 | then zeroBigInt | |
1329 | 1155 | else calcPriceBigInt(priceAssetAmtX18, amtAssetAmtX18) | |
1330 | 1156 | let inAmAssetAmtX18 = toX18(inAmAssetAmt, amtAssetDcm) | |
1331 | 1157 | let inPrAssetAmtX18 = fraction(inAmAssetAmtX18, curPriceX18, scale18) | |
1332 | 1158 | let inPrAssetAmt = fromX18(inPrAssetAmtX18, priceAssetDcm) | |
1333 | 1159 | let estPut = estimatePutOperation("", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false) | |
1334 | 1160 | let calcLpAmt = estPut._1 | |
1335 | 1161 | let curPriceCalc = estPut._3 | |
1336 | 1162 | let amBalance = estPut._4 | |
1337 | 1163 | let prBalance = estPut._5 | |
1338 | 1164 | let lpEmission = estPut._6 | |
1339 | 1165 | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d%d", toString(calcLpAmt), toString(fromX18(curPriceX18, scale8)), toString(amBalance), toString(prBalance), toString(lpEmission), poolStatus, toString(inAmAssetAmt), toString(inPrAssetAmt)], SEP)) | |
1340 | 1166 | } | |
1341 | 1167 | ||
1342 | 1168 | ||
1343 | 1169 | ||
1344 | 1170 | @Callable(i) | |
1345 | 1171 | func evaluatePutByPriceAssetREADONLY (inPrAssetAmt) = { | |
1346 | 1172 | let cfg = getPoolConfig() | |
1347 | 1173 | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
1348 | 1174 | let amAssetIdStr = cfg[idxAmtAssetId] | |
1349 | 1175 | let amAssetId = fromBase58String(amAssetIdStr) | |
1350 | 1176 | let prAssetIdStr = cfg[idxPriceAssetId] | |
1351 | 1177 | let prAssetId = fromBase58String(prAssetIdStr) | |
1352 | 1178 | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
1353 | 1179 | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
1354 | 1180 | let poolStatus = cfg[idxPoolStatus] | |
1355 | 1181 | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
1356 | 1182 | let amBalanceRaw = getAccBalance(amAssetIdStr) | |
1357 | 1183 | let prBalanceRaw = getAccBalance(prAssetIdStr) | |
1358 | 1184 | let amBalanceRawX18 = toX18(amBalanceRaw, amtAssetDcm) | |
1359 | 1185 | let prBalanceRawX18 = toX18(prBalanceRaw, priceAssetDcm) | |
1360 | 1186 | let curPriceX18 = if ((poolLPBalance == 0)) | |
1361 | 1187 | then zeroBigInt | |
1362 | 1188 | else calcPriceBigInt(prBalanceRawX18, amBalanceRawX18) | |
1363 | 1189 | let inPrAssetAmtX18 = toX18(inPrAssetAmt, priceAssetDcm) | |
1364 | 1190 | let inAmAssetAmtX18 = fraction(inPrAssetAmtX18, scale18, curPriceX18) | |
1365 | 1191 | let inAmAssetAmt = fromX18(inAmAssetAmtX18, amtAssetDcm) | |
1366 | 1192 | let estPut = estimatePutOperation("", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false) | |
1367 | 1193 | let calcLpAmt = estPut._1 | |
1368 | 1194 | let curPriceCalc = estPut._3 | |
1369 | 1195 | let amBalance = estPut._4 | |
1370 | 1196 | let prBalance = estPut._5 | |
1371 | 1197 | let lpEmission = estPut._6 | |
1372 | 1198 | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d%d", toString(calcLpAmt), toString(fromX18(curPriceX18, scale8)), toString(amBalance), toString(prBalance), toString(lpEmission), poolStatus, toString(inAmAssetAmt), toString(inPrAssetAmt)], SEP)) | |
1373 | 1199 | } | |
1374 | 1200 | ||
1375 | 1201 | ||
1376 | 1202 | ||
1377 | 1203 | @Callable(i) | |
1378 | 1204 | func evaluateGetREADONLY (paymentLpAssetId,paymentLpAmt) = { | |
1379 | 1205 | let res = estimateGetOperation("", paymentLpAssetId, paymentLpAmt, this) | |
1380 | 1206 | let outAmAmt = res._1 | |
1381 | 1207 | let outPrAmt = res._2 | |
1382 | 1208 | let amBalance = res._5 | |
1383 | 1209 | let prBalance = res._6 | |
1384 | 1210 | let lpEmission = res._7 | |
1385 | 1211 | let curPrice = res._8 | |
1386 | 1212 | let poolStatus = parseIntValue(res._9) | |
1387 | 1213 | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d", toString(outAmAmt), toString(outPrAmt), toString(amBalance), toString(prBalance), toString(lpEmission), toString(curPrice), toString(poolStatus)], SEP)) | |
1388 | 1214 | } | |
1389 | 1215 | ||
1390 | 1216 | ||
1391 | 1217 | @Verifier(tx) | |
1392 | 1218 | func verify () = { | |
1393 | 1219 | let targetPublicKey = match managerPublicKeyOrUnit() { | |
1394 | 1220 | case pk: ByteVector => | |
1395 | 1221 | pk | |
1396 | 1222 | case _: Unit => | |
1397 | 1223 | tx.senderPublicKey | |
1398 | 1224 | case _ => | |
1399 | 1225 | throw("Match error") | |
1400 | 1226 | } | |
1401 | 1227 | match tx { | |
1402 | 1228 | case order: Order => | |
1403 | 1229 | let matcherPub = getMatcherPubOrFail() | |
1404 | 1230 | let orderValid = validateMatcherOrderAllowed(order) | |
1405 | 1231 | let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
1406 | 1232 | let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub) | |
1407 | 1233 | if (if (if (orderValid) | |
1408 | 1234 | then senderValid | |
1409 | 1235 | else false) | |
1410 | 1236 | then matcherValid | |
1411 | 1237 | else false) | |
1412 | 1238 | then true | |
1413 | 1239 | else throwOrderError(orderValid, senderValid, matcherValid) | |
1414 | 1240 | case s: SetScriptTransaction => | |
1415 | 1241 | let newHash = blake2b256(value(s.script)) | |
1416 | 1242 | let allowedHash = fromBase64String(value(getString(factoryContract, keyAllowedLpScriptHash()))) | |
1417 | 1243 | let currentHash = scriptHash(this) | |
1418 | 1244 | if (if ((allowedHash == newHash)) | |
1419 | 1245 | then (currentHash != newHash) | |
1420 | 1246 | else false) | |
1421 | 1247 | then true | |
1422 | 1248 | else sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1423 | 1249 | case _ => | |
1424 | 1250 | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1425 | 1251 | } | |
1426 | 1252 | } | |
1427 | 1253 |
github/deemru/w8io/026f985 167.58 ms ◑