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