tx · 7TWuUDmGmaHU9G5CzN24GHdhCC47BJSULNmFnTyEkjjf 3MzKSdTH2jFbypLsoNfrH7QgkzSbx3EYwCA: -0.02600000 Waves 2022.08.15 17:50 [2185721] smart account 3MzKSdTH2jFbypLsoNfrH7QgkzSbx3EYwCA > SELF 0.00000000 Waves
{ "type": 13, "id": "7TWuUDmGmaHU9G5CzN24GHdhCC47BJSULNmFnTyEkjjf", "fee": 2600000, "feeAssetId": null, "timestamp": 1660575010319, "version": 1, "sender": "3MzKSdTH2jFbypLsoNfrH7QgkzSbx3EYwCA", "senderPublicKey": "35yd3qw1gxKDxKwGAykHN9fANbXNWwseaUwbWDj24o3x", "proofs": [ "4eFYMrEWe4Equ6vU71eipVXHFuS3JpwAauwzTmEPvZajaaG8nx1r4c41oXni7YEdzqhM7Trrhdj2VLXyDHjdmpzV" ], "script": "base64:BgL+HwgCEgMKAQgSAwoBCBIAEgQKAgEEEgcKBQEBAQEEEgMKAQESABIHCgUBAQEIARIECgIBARIDCgEBEgQKAggIEgQKAggIEgQKAggBEgASAwoBCBIFCgMBAQESBAoCCAESBAoCAQESBAoCCAgSCwoJCAEBAgECCAQEEgYKBAgIAQgiBnNjYWxlOCIMc2NhbGU4QmlnSW50IgdzY2FsZTE4Igh0aG91c2FuZCIKemVyb0JpZ0ludCIJb25lQmlnSW50IgpzbGlwcGFnZTREIgVBbXVsdCIFRGNvbnYiA1NFUCIFRU1QVFkiClBvb2xBY3RpdmUiClBvb2xQdXREaXMiDlBvb2xNYXRjaGVyRGlzIgxQb29sU2h1dGRvd24iDmlkeFBvb2xBZGRyZXNzIglpZHhQb29sU3QiCWlkeExQQXNJZCIJaWR4QW1Bc0lkIglpZHhQckFzSWQiC2lkeEFtdEFzRGNtIg1pZHhQcmljZUFzRGNtIgtpZHhJQW10QXNJZCINaWR4SVByaWNlQXNJZCIPaWR4RmFjdFN0YWtDbnRyIhBpZHhGYWN0U2xpcHBDbnRyIhFpZHhGYWN0R3d4UmV3Q250ciISZmV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hdGVQdXRPcGVyYXRpb25XcmFwcGVyUkVBRE9OTFkJAmJHAmJnAmNpAmVWAmNrAmVXAmVYAmNtAmNuCQCUCgIFA25pbAkBAmNnDAUCYkcFAmJnBQJjaQUCZVYFAmNrBQJlVwUCZVgFAmNtBQJjbgcAAAIAAmRpASNlc3RpbWF0ZUdldE9wZXJhdGlvbldyYXBwZXJSRUFET05MWQQCYkcCZVkCYkkCZVgEAmN5CQECYkYEBQJiRwUCZVkFAmJJCQERQGV4dHJOYXRpdmUoMTA2MikBBQJlWAkAlAoCBQNuaWwJAJwKCggFAmN5Al8xCAUCY3kCXzIIBQJjeQJfMwgFAmN5Al80CAUCY3kCXzUIBQJjeQJfNggFAmN5Al83CQCmAwEIBQJjeQJfOAgFAmN5Al85CAUCY3kDXzEwAQJlWgECZmEABAJhdAUCZVoDCQABAgUCYXQCBU9yZGVyBAJjVgUCYXQEAmZiCQECYUMABAJhcAkBAmNVAQUCY1YEAmZjCQD0AwMIBQJjVglib2R5Qnl0ZXMJAJEDAggFAmNWBnByb29mcwAACAUCY1YPc2VuZGVyUHVibGljS2V5BAJmZAkA9AMDCAUCY1YJYm9keUJ5dGVzCQCRAwIIBQJjVgZwcm9vZnMAAQUCZmIDAwMFAmFwBQJmYwcFAmZkBwYJAQJhbwMFAmFwBQJmYwUCZmQEAmZlBAJmZgkBAmRzAAMJAAECBQJmZgIKQnl0ZVZlY3RvcgQCZHgFAmZmBQJkeAMJAAECBQJmZgIEVW5pdAgFAmVaD3NlbmRlclB1YmxpY0tleQkAAgECC01hdGNoIGVycm9yCQD0AwMIBQJlWglib2R5Qnl0ZXMJAJEDAggFAmVaBnByb29mcwAABQJmZd18zmc=", "chainId": 84, "height": 2185721, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 57oomHZowvc4bbyAq6vCSay5jsR46pp9aAPxKRFFQKy4 Next: FHFuEo3f5gS9dkWkpYJUAm5ft2KwiFXorwrhz6WGbojB Diff:
Old | New | Differences | |
---|---|---|---|
6 | 6 | let scale8BigInt = toBigInt(100000000) | |
7 | 7 | ||
8 | 8 | let scale18 = toBigInt(1000000000000000000) | |
9 | + | ||
10 | + | let thousand = 1000 | |
9 | 11 | ||
10 | 12 | let zeroBigInt = toBigInt(0) | |
11 | 13 | ||
53 | 55 | ||
54 | 56 | let idxFactGwxRewCntr = 10 | |
55 | 57 | ||
56 | - | let | |
58 | + | let feePermilleDefault = 0 | |
57 | 59 | ||
58 | 60 | func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) | |
59 | 61 | ||
102 | 104 | func keyAddonAddress () = "%s__addonAddr" | |
103 | 105 | ||
104 | 106 | ||
105 | - | ||
107 | + | let keyFeePermille = "%s__feePermille" | |
106 | 108 | ||
107 | - | ||
108 | - | func lsotc (caller) = makeString(["%s%s__lastPutOneTknCall", caller], SEP) | |
109 | - | ||
109 | + | let feePermille = valueOrElse(getInteger(this, keyFeePermille), feePermilleDefault) | |
110 | 110 | ||
111 | 111 | func fcfg () = "%s__factoryConfig" | |
112 | 112 | ||
152 | 152 | ||
153 | 153 | func getMatcherPubOrFail () = fromBase58String(getStringOrFail(factoryContract, mtpk())) | |
154 | 154 | ||
155 | + | ||
156 | + | let matcherAddress = addressFromPublicKey(getMatcherPubOrFail()) | |
155 | 157 | ||
156 | 158 | func getPoolConfig () = { | |
157 | 159 | let amtAs = getStringOrFail(this, keyAmountAsset()) | |
322 | 324 | let currentPriceX18 = calcPriceBigInt(priceBalanceX18, amountBalanceX18) | |
323 | 325 | let slippageRealX18 = fraction(abs((currentPriceX18 - userPriceX18)), scale18, currentPriceX18) | |
324 | 326 | let slippageX18 = toX18(slippageTolerance, scale8) | |
325 | - | | |
327 | + | if (if ((currentPriceX18 != zeroBigInt)) | |
326 | 328 | then (slippageRealX18 > slippageX18) | |
327 | - | else false) == false)) | |
328 | - | then true | |
329 | - | else throwErr(((("Price slippage " + toString(slippageRealX18)) + " > ") + toString(slippageX18))) | |
330 | - | if ((validateSlippage == validateSlippage)) | |
331 | - | then { | |
329 | + | else false) | |
330 | + | then throwErr(((("Price slippage " + toString(slippageRealX18)) + " > ") + toString(slippageX18))) | |
331 | + | else { | |
332 | 332 | let lpEmissionX18 = toX18(lpEmission, scale8) | |
333 | 333 | let prViaAmX18 = fraction(inAmountAssetAmountX18, currentPriceX18, scale18) | |
334 | 334 | let amViaPrX18 = fraction(inPriceAssetAmountX18, scale18, currentPriceX18) | |
340 | 340 | let lpAmountX18 = fraction(lpEmissionX18, expectedPriceAssetAmountX18, priceBalanceX18) | |
341 | 341 | $Tuple5(fromX18(lpAmountX18, scale8), fromX18(expectedAmountAssetAmountX18, decimals), fromX18(expectedPriceAssetAmountX18, decimals), currentPriceX18, slippageX18) | |
342 | 342 | } | |
343 | - | else throw("Strict value is not equal to itself.") | |
344 | 343 | } | |
345 | 344 | let calculateLpAmount = r._1 | |
346 | 345 | let calculateAmountAssetPayment = r._2 | |
357 | 356 | else calculateLpAmount | |
358 | 357 | let amountDiff = (inAmountAssetAmount - calculateAmountAssetPayment) | |
359 | 358 | let priceDiff = (inPriceAssetAmount - calculatePriceAssetPayment) | |
360 | - | let $ | |
359 | + | let $t01618916448 = if (if (isOneAsset) | |
361 | 360 | then (paymentId == amountIdStr) | |
362 | 361 | else false) | |
363 | 362 | then $Tuple2(paymentAmount, 0) | |
366 | 365 | else false) | |
367 | 366 | then $Tuple2(0, paymentAmount) | |
368 | 367 | else $Tuple2(calculateAmountAssetPayment, calculatePriceAssetPayment) | |
369 | - | let writeAmAmt = $ | |
370 | - | let writePrAmt = $ | |
368 | + | let writeAmAmt = $t01618916448._1 | |
369 | + | let writePrAmt = $t01618916448._2 | |
371 | 370 | let commonState = [IntegerEntry(keyPriceLast(), currentPrice), IntegerEntry(keyPriceHistory(height, lastBlock.timestamp), currentPrice), StringEntry(keyPutActionByUser(userAddress, txId58), dataPutActionInfo(writeAmAmt, writePrAmt, emitLpAmount, currentPrice, slippageTolerance, slippageCalculate, height, lastBlock.timestamp, amountDiff, priceDiff))] | |
372 | 371 | $Tuple13(calculateLpAmount, emitLpAmount, currentPrice, amountBalance, priceBalance, lpEmission, lpAssetId, sts, commonState, amountDiff, priceDiff, inAmountAssetId, inPriceAssetId) | |
373 | 372 | } | |
456 | 455 | else (sts == PoolShutdown)) | |
457 | 456 | then throwErr(("Blocked:" + toString(sts))) | |
458 | 457 | else r | |
458 | + | } | |
459 | + | ||
460 | + | ||
461 | + | func takeFee (amount) = { | |
462 | + | let fee = fraction(amount, feePermille, thousand) | |
463 | + | $Tuple2((amount - fee), fee) | |
459 | 464 | } | |
460 | 465 | ||
461 | 466 | ||
624 | 629 | let userAddress = if ((addon == toString(i.caller))) | |
625 | 630 | then i.originCaller | |
626 | 631 | else i.caller | |
627 | - | let addonContract = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(keyAddonAddress()), "no addons")), "addon address in not valid") | |
628 | - | let check = reentrantInvoke(addonContract, "ensureCanPutOneTkn", [toString(userAddress)], nil) | |
629 | - | if ((check == check)) | |
630 | - | then if (if (if (if ((0 >= slippage)) | |
631 | - | then true | |
632 | - | else (0 >= amountAssetPart)) | |
633 | - | then true | |
634 | - | else (0 >= priceAssetPart)) | |
635 | - | then true | |
636 | - | else (0 >= outLp)) | |
637 | - | then throwErr("Wrong params") | |
638 | - | else if ((size(i.payments) != 1)) | |
639 | - | then throwErr("1 payment expected") | |
640 | - | else { | |
641 | - | let payment = value(i.payments[0]) | |
642 | - | let paymentAssetId = toBase58String(value(payment.assetId)) | |
643 | - | let paymentAmount = payment.amount | |
644 | - | if (if (if ((amountAssetPart > paymentAmount)) | |
645 | - | then true | |
646 | - | else (priceAssetPart > paymentAmount)) | |
647 | - | then true | |
648 | - | else (10000000 > paymentAmount)) | |
649 | - | then throwErr("wrong payment amount") | |
650 | - | else { | |
651 | - | let amountBalance = getAccBalance(amountId) | |
652 | - | let priceBalance = getAccBalance(priceId) | |
653 | - | let $t02607126526 = if ((paymentAssetId == amountId)) | |
654 | - | then $Tuple6((amountBalance - paymentAmount), priceBalance, (paymentAmount - amountAssetPart), priceAssetPart, 0, 0) | |
655 | - | else if ((paymentAssetId == priceId)) | |
656 | - | then $Tuple6(amountBalance, (priceBalance - paymentAmount), 0, 0, (paymentAmount - priceAssetPart), amountAssetPart) | |
657 | - | else throwErr("wrong paymentAssetId") | |
658 | - | let amountBalanceNow = $t02607126526._1 | |
659 | - | let priceBalanceNow = $t02607126526._2 | |
660 | - | let virtSwapInAm = $t02607126526._3 | |
661 | - | let virtSwapOutPr = $t02607126526._4 | |
662 | - | let virtSwapInPr = $t02607126526._5 | |
663 | - | let virtSwapOutAm = $t02607126526._6 | |
664 | - | let D0 = invoke(gwxRewardContract, "calcD", [toString(amountBalanceNow), toString(priceBalanceNow), amplificator, Amult, Dconv], nil) | |
665 | - | let D1 = invoke(gwxRewardContract, "calcD", [toString(toBigInt(((amountBalanceNow + virtSwapInAm) - virtSwapOutAm))), toString(toBigInt(((priceBalanceNow + virtSwapInPr) - virtSwapOutPr))), amplificator, Amult, Dconv], nil) | |
666 | - | let D0vsD1 = validateD(parseBigIntValue(str(D1)), parseBigIntValue(str(D0)), slippage4D) | |
667 | - | if ((D0vsD1 == D0vsD1)) | |
668 | - | then { | |
669 | - | let estimatePut = commonPut(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(fromBase58String(amountId), amountAssetPart), AttachedPayment(fromBase58String(priceId), priceAssetPart), slippage, true, true, paymentAmount, paymentAssetId) | |
670 | - | let estimateLP = estimatePut._2 | |
671 | - | let lpAssetId = estimatePut._7 | |
672 | - | let state = estimatePut._9 | |
673 | - | let amountDiff = estimatePut._10 | |
674 | - | let priceDiff = estimatePut._11 | |
675 | - | let lpCalcRes = validateAbsDiff(toBigInt(estimateLP), toBigInt(outLp), toBigInt(slippage)) | |
676 | - | let emitLpAmount = toInt(lpCalcRes._2) | |
677 | - | let e = invoke(factoryContract, "emit", [emitLpAmount], nil) | |
678 | - | if ((e == e)) | |
679 | - | then { | |
680 | - | let el = match e { | |
681 | - | case legacy: Address => | |
682 | - | invoke(legacy, "emit", [emitLpAmount], nil) | |
683 | - | case _ => | |
684 | - | unit | |
685 | - | } | |
686 | - | if ((el == el)) | |
687 | - | then { | |
688 | - | let sa = if ((amountDiff > 0)) | |
689 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(fromBase58String(amountId), amountDiff)]) | |
690 | - | else nil | |
691 | - | if ((sa == sa)) | |
692 | - | then { | |
693 | - | let sp = if ((priceDiff > 0)) | |
694 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(fromBase58String(priceId), priceDiff)]) | |
695 | - | else nil | |
696 | - | if ((sp == sp)) | |
697 | - | then { | |
698 | - | let lpTrasfer = if (autoStake) | |
699 | - | then { | |
700 | - | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmount)]) | |
701 | - | if ((ss == ss)) | |
702 | - | then nil | |
703 | - | else throw("Strict value is not equal to itself.") | |
704 | - | } | |
705 | - | else [ScriptTransfer(i.caller, emitLpAmount, lpAssetId)] | |
706 | - | (state ++ lpTrasfer) | |
707 | - | } | |
708 | - | else throw("Strict value is not equal to itself.") | |
709 | - | } | |
710 | - | else throw("Strict value is not equal to itself.") | |
711 | - | } | |
712 | - | else throw("Strict value is not equal to itself.") | |
713 | - | } | |
714 | - | else throw("Strict value is not equal to itself.") | |
715 | - | } | |
716 | - | else throw("Strict value is not equal to itself.") | |
717 | - | } | |
718 | - | } | |
719 | - | else throw("Strict value is not equal to itself.") | |
632 | + | if (if (if (if ((0 >= slippage)) | |
633 | + | then true | |
634 | + | else (0 >= amountAssetPart)) | |
635 | + | then true | |
636 | + | else (0 >= priceAssetPart)) | |
637 | + | then true | |
638 | + | else (0 >= outLp)) | |
639 | + | then throwErr("Wrong params") | |
640 | + | else if ((size(i.payments) != 1)) | |
641 | + | then throwErr("1 payment expected") | |
642 | + | else { | |
643 | + | let payment = value(i.payments[0]) | |
644 | + | let paymentAssetId = toBase58String(value(payment.assetId)) | |
645 | + | let paymentAmountRaw = payment.amount | |
646 | + | let $t02561725676 = takeFee(paymentAmountRaw) | |
647 | + | let paymentAmount = $t02561725676._1 | |
648 | + | let feeAmount = $t02561725676._2 | |
649 | + | if (if (if ((amountAssetPart > paymentAmount)) | |
650 | + | then true | |
651 | + | else (priceAssetPart > paymentAmount)) | |
652 | + | then true | |
653 | + | else (10000000 > paymentAmount)) | |
654 | + | then throwErr("wrong payment amount") | |
655 | + | else { | |
656 | + | let amountBalance = getAccBalance(amountId) | |
657 | + | let priceBalance = getAccBalance(priceId) | |
658 | + | let $t02594026395 = if ((paymentAssetId == amountId)) | |
659 | + | then $Tuple6((amountBalance - paymentAmount), priceBalance, (paymentAmount - amountAssetPart), priceAssetPart, 0, 0) | |
660 | + | else if ((paymentAssetId == priceId)) | |
661 | + | then $Tuple6(amountBalance, (priceBalance - paymentAmount), 0, 0, (paymentAmount - priceAssetPart), amountAssetPart) | |
662 | + | else throwErr("wrong paymentAssetId") | |
663 | + | let amountBalanceNow = $t02594026395._1 | |
664 | + | let priceBalanceNow = $t02594026395._2 | |
665 | + | let virtSwapInAm = $t02594026395._3 | |
666 | + | let virtSwapOutPr = $t02594026395._4 | |
667 | + | let virtSwapInPr = $t02594026395._5 | |
668 | + | let virtSwapOutAm = $t02594026395._6 | |
669 | + | let D0 = invoke(gwxRewardContract, "calcD", [toString(amountBalanceNow), toString(priceBalanceNow), amplificator, Amult, Dconv], nil) | |
670 | + | let D1 = invoke(gwxRewardContract, "calcD", [toString(toBigInt(((amountBalanceNow + virtSwapInAm) - virtSwapOutAm))), toString(toBigInt(((priceBalanceNow + virtSwapInPr) - virtSwapOutPr))), amplificator, Amult, Dconv], nil) | |
671 | + | let D0vsD1 = validateD(parseBigIntValue(str(D1)), parseBigIntValue(str(D0)), slippage4D) | |
672 | + | if ((D0vsD1 == D0vsD1)) | |
673 | + | then { | |
674 | + | let estimatePut = commonPut(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(fromBase58String(amountId), amountAssetPart), AttachedPayment(fromBase58String(priceId), priceAssetPart), slippage, true, true, paymentAmount, paymentAssetId) | |
675 | + | let estimateLP = estimatePut._2 | |
676 | + | let lpAssetId = estimatePut._7 | |
677 | + | let state = estimatePut._9 | |
678 | + | let amountDiff = estimatePut._10 | |
679 | + | let priceDiff = estimatePut._11 | |
680 | + | let lpCalcRes = validateAbsDiff(toBigInt(estimateLP), toBigInt(outLp), toBigInt(slippage)) | |
681 | + | let emitLpAmount = toInt(lpCalcRes._2) | |
682 | + | let e = invoke(factoryContract, "emit", [emitLpAmount], nil) | |
683 | + | if ((e == e)) | |
684 | + | then { | |
685 | + | let el = match e { | |
686 | + | case legacy: Address => | |
687 | + | invoke(legacy, "emit", [emitLpAmount], nil) | |
688 | + | case _ => | |
689 | + | unit | |
690 | + | } | |
691 | + | if ((el == el)) | |
692 | + | then { | |
693 | + | let sa = if ((amountDiff > 0)) | |
694 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(fromBase58String(amountId), amountDiff)]) | |
695 | + | else nil | |
696 | + | if ((sa == sa)) | |
697 | + | then { | |
698 | + | let sp = if ((priceDiff > 0)) | |
699 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(fromBase58String(priceId), priceDiff)]) | |
700 | + | else nil | |
701 | + | if ((sp == sp)) | |
702 | + | then { | |
703 | + | let lpTrasfer = if (autoStake) | |
704 | + | then { | |
705 | + | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmount)]) | |
706 | + | if ((ss == ss)) | |
707 | + | then nil | |
708 | + | else throw("Strict value is not equal to itself.") | |
709 | + | } | |
710 | + | else [ScriptTransfer(i.caller, emitLpAmount, lpAssetId)] | |
711 | + | let sendFeeToMatcher = if ((feeAmount > 0)) | |
712 | + | then [ScriptTransfer(matcherAddress, feeAmount, fromBase58String(paymentAssetId))] | |
713 | + | else nil | |
714 | + | ((state ++ lpTrasfer) ++ sendFeeToMatcher) | |
715 | + | } | |
716 | + | else throw("Strict value is not equal to itself.") | |
717 | + | } | |
718 | + | else throw("Strict value is not equal to itself.") | |
719 | + | } | |
720 | + | else throw("Strict value is not equal to itself.") | |
721 | + | } | |
722 | + | else throw("Strict value is not equal to itself.") | |
723 | + | } | |
724 | + | else throw("Strict value is not equal to itself.") | |
725 | + | } | |
726 | + | } | |
720 | 727 | } | |
721 | 728 | ||
722 | 729 | ||
770 | 777 | let txId58 = toBase58String(i.transactionId) | |
771 | 778 | let paymentAssetId = value(payment.assetId) | |
772 | 779 | let paymentAmount = payment.amount | |
773 | - | let addonContract = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(keyAddonAddress()), "no addons")), "addon address in not valid") | |
774 | - | let check = reentrantInvoke(addonContract, "ensureCanGetOneTkn", [toString(userAddress)], nil) | |
775 | - | if ((check == check)) | |
776 | - | then if ((1000000000 > paymentAmount)) | |
777 | - | then throwErr("Min payment 10 LP") | |
778 | - | else if (if (if ((0 > slippage)) | |
779 | - | then true | |
780 | - | else (0 > exchResult)) | |
781 | - | then true | |
782 | - | else (0 > outAmount)) | |
783 | - | then throwErr("Wrong params") | |
784 | - | else if ((lpAssetId != toBase58String(paymentAssetId))) | |
785 | - | then throwErr("Wrong LP") | |
786 | - | else { | |
787 | - | let r = estimateGetOperation(toBase58String(i.transactionId), toBase58String(paymentAssetId), paymentAmount, i.caller) | |
788 | - | let estimAmAmt = r._1 | |
789 | - | let estimPrAmt = r._2 | |
790 | - | let amountBalance = getAccBalance(amountId) | |
791 | - | let priceBalance = getAccBalance(priceId) | |
792 | - | let $t03176632234 = if ((outAssetId == amountId)) | |
793 | - | then $Tuple7((amountBalance - estimAmAmt), (priceBalance - estimPrAmt), exchResult, estimPrAmt, 0, 0, (estimAmAmt + exchResult)) | |
794 | - | else if ((outAssetId == priceId)) | |
795 | - | then $Tuple7((amountBalance - estimAmAmt), (priceBalance - estimPrAmt), 0, 0, exchResult, estimAmAmt, (estimPrAmt + exchResult)) | |
796 | - | else throwErr("wrong outAssetId") | |
797 | - | let amountBalanceNow = $t03176632234._1 | |
798 | - | let priceBalanceNow = $t03176632234._2 | |
799 | - | let virtSwapInAm = $t03176632234._3 | |
800 | - | let virtSwapOutPr = $t03176632234._4 | |
801 | - | let virtSwapInPr = $t03176632234._5 | |
802 | - | let virtSwapOutAm = $t03176632234._6 | |
803 | - | let totalGet = $t03176632234._7 | |
804 | - | if (if ((0 > virtSwapInAm)) | |
805 | - | then true | |
806 | - | else (0 > virtSwapInPr)) | |
807 | - | then throwErr("Wrong calc") | |
808 | - | else { | |
809 | - | let D0 = invoke(gwxRewardContract, "calcD", [toString(amountBalanceNow), toString(priceBalanceNow), amplificator, Amult, Dconv], nil) | |
810 | - | let D1 = invoke(gwxRewardContract, "calcD", [toString(((amountBalanceNow - virtSwapInAm) + virtSwapOutAm)), toString(((priceBalanceNow + virtSwapOutPr) - virtSwapInPr)), amplificator, Amult, Dconv], nil) | |
811 | - | let D0vsD1 = validateD(parseBigIntValue(str(D1)), parseBigIntValue(str(D0)), slippage4D) | |
812 | - | if ((D0vsD1 == D0vsD1)) | |
813 | - | then { | |
814 | - | let finalRes = validateAbsDiff(toBigInt(totalGet), toBigInt(outAmount), toBigInt(slippage)) | |
815 | - | if ((finalRes == finalRes)) | |
816 | - | then { | |
817 | - | let $t03290333011 = if ((outAssetId == amountId)) | |
818 | - | then $Tuple2(toInt(finalRes._2), 0) | |
819 | - | else $Tuple2(0, toInt(finalRes._2)) | |
820 | - | let outAm = $t03290333011._1 | |
821 | - | let outPr = $t03290333011._2 | |
822 | - | let decimals = if ((amountDecimals >= priceDecimals)) | |
823 | - | then amountDecimals | |
824 | - | else priceDecimals | |
825 | - | if ((decimals == decimals)) | |
826 | - | then { | |
827 | - | let curPrX18 = calcPriceBigInt(toX18(priceBalance, decimals), toX18(amountBalance, decimals)) | |
828 | - | let curPr = fromX18(curPrX18, scale8) | |
829 | - | let state = [ScriptTransfer(userAddress, (outAm + outPr), if ((outAssetId == "WAVES")) | |
830 | - | then unit | |
831 | - | else fromBase58String(outAssetId)), StringEntry(keyGetActionByUser(toString(userAddress), txId58), dataGetActionInfo(outAm, outPr, paymentAmount, curPr, height, lastBlock.timestamp)), IntegerEntry(keyPriceLast(), curPr), IntegerEntry(keyPriceHistory(height, lastBlock.timestamp), curPr)] | |
832 | - | if ((state == state)) | |
833 | - | then { | |
834 | - | let burn = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)]) | |
835 | - | if ((burn == burn)) | |
836 | - | then state | |
837 | - | else throw("Strict value is not equal to itself.") | |
838 | - | } | |
839 | - | else throw("Strict value is not equal to itself.") | |
840 | - | } | |
841 | - | else throw("Strict value is not equal to itself.") | |
842 | - | } | |
843 | - | else throw("Strict value is not equal to itself.") | |
844 | - | } | |
845 | - | else throw("Strict value is not equal to itself.") | |
846 | - | } | |
847 | - | } | |
848 | - | else throw("Strict value is not equal to itself.") | |
780 | + | if ((1000000000 > paymentAmount)) | |
781 | + | then throwErr("Min payment 10 LP") | |
782 | + | else if (if (if ((0 > slippage)) | |
783 | + | then true | |
784 | + | else (0 > exchResult)) | |
785 | + | then true | |
786 | + | else (0 > outAmount)) | |
787 | + | then throwErr("Wrong params") | |
788 | + | else if ((lpAssetId != toBase58String(paymentAssetId))) | |
789 | + | then throwErr("Wrong LP") | |
790 | + | else { | |
791 | + | let r = estimateGetOperation(toBase58String(i.transactionId), toBase58String(paymentAssetId), paymentAmount, i.caller) | |
792 | + | let estimAmAmt = r._1 | |
793 | + | let estimPrAmt = r._2 | |
794 | + | let amountBalance = getAccBalance(amountId) | |
795 | + | let priceBalance = getAccBalance(priceId) | |
796 | + | let $t03153432002 = if ((outAssetId == amountId)) | |
797 | + | then $Tuple7((amountBalance - estimAmAmt), (priceBalance - estimPrAmt), exchResult, estimPrAmt, 0, 0, (estimAmAmt + exchResult)) | |
798 | + | else if ((outAssetId == priceId)) | |
799 | + | then $Tuple7((amountBalance - estimAmAmt), (priceBalance - estimPrAmt), 0, 0, exchResult, estimAmAmt, (estimPrAmt + exchResult)) | |
800 | + | else throwErr("wrong outAssetId") | |
801 | + | let amountBalanceNow = $t03153432002._1 | |
802 | + | let priceBalanceNow = $t03153432002._2 | |
803 | + | let virtSwapInAm = $t03153432002._3 | |
804 | + | let virtSwapOutPr = $t03153432002._4 | |
805 | + | let virtSwapInPr = $t03153432002._5 | |
806 | + | let virtSwapOutAm = $t03153432002._6 | |
807 | + | let totalGet = $t03153432002._7 | |
808 | + | if (if ((0 > virtSwapInAm)) | |
809 | + | then true | |
810 | + | else (0 > virtSwapInPr)) | |
811 | + | then throwErr("Wrong calc") | |
812 | + | else { | |
813 | + | let D0 = invoke(gwxRewardContract, "calcD", [toString(amountBalanceNow), toString(priceBalanceNow), amplificator, Amult, Dconv], nil) | |
814 | + | let D1 = invoke(gwxRewardContract, "calcD", [toString(((amountBalanceNow - virtSwapInAm) + virtSwapOutAm)), toString(((priceBalanceNow + virtSwapOutPr) - virtSwapInPr)), amplificator, Amult, Dconv], nil) | |
815 | + | let D0vsD1 = validateD(parseBigIntValue(str(D1)), parseBigIntValue(str(D0)), slippage4D) | |
816 | + | if ((D0vsD1 == D0vsD1)) | |
817 | + | then { | |
818 | + | let finalRes = validateAbsDiff(toBigInt(totalGet), toBigInt(outAmount), toBigInt(slippage)) | |
819 | + | if ((finalRes == finalRes)) | |
820 | + | then { | |
821 | + | let $t03267132779 = if ((outAssetId == amountId)) | |
822 | + | then $Tuple2(toInt(finalRes._2), 0) | |
823 | + | else $Tuple2(0, toInt(finalRes._2)) | |
824 | + | let outAm = $t03267132779._1 | |
825 | + | let outPr = $t03267132779._2 | |
826 | + | let totalAmountRaw = (outAm + outPr) | |
827 | + | let $t03281932874 = takeFee(totalAmountRaw) | |
828 | + | let totalAmount = $t03281932874._1 | |
829 | + | let feeAmount = $t03281932874._2 | |
830 | + | let outAssetIdOrWaves = if ((outAssetId == "WAVES")) | |
831 | + | then unit | |
832 | + | else fromBase58String(outAssetId) | |
833 | + | let sendFeeToMatcher = if ((feeAmount > 0)) | |
834 | + | then [ScriptTransfer(matcherAddress, feeAmount, outAssetIdOrWaves)] | |
835 | + | else nil | |
836 | + | let decimals = if ((amountDecimals >= priceDecimals)) | |
837 | + | then amountDecimals | |
838 | + | else priceDecimals | |
839 | + | if ((decimals == decimals)) | |
840 | + | then { | |
841 | + | let curPrX18 = calcPriceBigInt(toX18(priceBalance, decimals), toX18(amountBalance, decimals)) | |
842 | + | let curPr = fromX18(curPrX18, scale8) | |
843 | + | let state = [ScriptTransfer(userAddress, totalAmount, outAssetIdOrWaves), StringEntry(keyGetActionByUser(toString(userAddress), txId58), dataGetActionInfo(outAm, outPr, paymentAmount, curPr, height, lastBlock.timestamp)), IntegerEntry(keyPriceLast(), curPr), IntegerEntry(keyPriceHistory(height, lastBlock.timestamp), curPr)] | |
844 | + | if ((state == state)) | |
845 | + | then { | |
846 | + | let burn = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)]) | |
847 | + | if ((burn == burn)) | |
848 | + | then (state ++ sendFeeToMatcher) | |
849 | + | else throw("Strict value is not equal to itself.") | |
850 | + | } | |
851 | + | else throw("Strict value is not equal to itself.") | |
852 | + | } | |
853 | + | else throw("Strict value is not equal to itself.") | |
854 | + | } | |
855 | + | else throw("Strict value is not equal to itself.") | |
856 | + | } | |
857 | + | else throw("Strict value is not equal to itself.") | |
858 | + | } | |
859 | + | } | |
849 | 860 | } | |
850 | 861 | ||
851 | 862 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let scale8 = 100000000 | |
5 | 5 | ||
6 | 6 | let scale8BigInt = toBigInt(100000000) | |
7 | 7 | ||
8 | 8 | let scale18 = toBigInt(1000000000000000000) | |
9 | + | ||
10 | + | let thousand = 1000 | |
9 | 11 | ||
10 | 12 | let zeroBigInt = toBigInt(0) | |
11 | 13 | ||
12 | 14 | let oneBigInt = toBigInt(1) | |
13 | 15 | ||
14 | 16 | let slippage4D = toBigInt((scale8 - ((scale8 * 1) / scale8))) | |
15 | 17 | ||
16 | 18 | let Amult = "100" | |
17 | 19 | ||
18 | 20 | let Dconv = "1" | |
19 | 21 | ||
20 | 22 | let SEP = "__" | |
21 | 23 | ||
22 | 24 | let EMPTY = "" | |
23 | 25 | ||
24 | 26 | let PoolActive = 1 | |
25 | 27 | ||
26 | 28 | let PoolPutDis = 2 | |
27 | 29 | ||
28 | 30 | let PoolMatcherDis = 3 | |
29 | 31 | ||
30 | 32 | let PoolShutdown = 4 | |
31 | 33 | ||
32 | 34 | let idxPoolAddress = 1 | |
33 | 35 | ||
34 | 36 | let idxPoolSt = 2 | |
35 | 37 | ||
36 | 38 | let idxLPAsId = 3 | |
37 | 39 | ||
38 | 40 | let idxAmAsId = 4 | |
39 | 41 | ||
40 | 42 | let idxPrAsId = 5 | |
41 | 43 | ||
42 | 44 | let idxAmtAsDcm = 6 | |
43 | 45 | ||
44 | 46 | let idxPriceAsDcm = 7 | |
45 | 47 | ||
46 | 48 | let idxIAmtAsId = 8 | |
47 | 49 | ||
48 | 50 | let idxIPriceAsId = 9 | |
49 | 51 | ||
50 | 52 | let idxFactStakCntr = 1 | |
51 | 53 | ||
52 | 54 | let idxFactSlippCntr = 7 | |
53 | 55 | ||
54 | 56 | let idxFactGwxRewCntr = 10 | |
55 | 57 | ||
56 | - | let | |
58 | + | let feePermilleDefault = 0 | |
57 | 59 | ||
58 | 60 | func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) | |
59 | 61 | ||
60 | 62 | ||
61 | 63 | func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18)) | |
62 | 64 | ||
63 | 65 | ||
64 | 66 | func ts (amt,resScale,curScale) = fraction(amt, resScale, curScale) | |
65 | 67 | ||
66 | 68 | ||
67 | 69 | func abs (val) = if ((zeroBigInt > val)) | |
68 | 70 | then -(val) | |
69 | 71 | else val | |
70 | 72 | ||
71 | 73 | ||
72 | 74 | func keyFactoryContact () = "%s__factoryContract" | |
73 | 75 | ||
74 | 76 | ||
75 | 77 | func keyManagerPublicKey () = "%s__managerPublicKey" | |
76 | 78 | ||
77 | 79 | ||
78 | 80 | func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey" | |
79 | 81 | ||
80 | 82 | ||
81 | 83 | func keyPriceLast () = "%s%s__price__last" | |
82 | 84 | ||
83 | 85 | ||
84 | 86 | func keyPriceHistory (h,t) = makeString(["%s%s%d%d__price__history", toString(h), toString(t)], SEP) | |
85 | 87 | ||
86 | 88 | ||
87 | 89 | func keyPutActionByUser (ua,txId) = ((("%s%s%s__P__" + ua) + "__") + txId) | |
88 | 90 | ||
89 | 91 | ||
90 | 92 | func keyGetActionByUser (ua,txId) = ((("%s%s%s__G__" + ua) + "__") + txId) | |
91 | 93 | ||
92 | 94 | ||
93 | 95 | func keyAmountAsset () = "%s__amountAsset" | |
94 | 96 | ||
95 | 97 | ||
96 | 98 | func keyPriceAsset () = "%s__priceAsset" | |
97 | 99 | ||
98 | 100 | ||
99 | 101 | func keyAmplificator () = "%s__amp" | |
100 | 102 | ||
101 | 103 | ||
102 | 104 | func keyAddonAddress () = "%s__addonAddr" | |
103 | 105 | ||
104 | 106 | ||
105 | - | ||
107 | + | let keyFeePermille = "%s__feePermille" | |
106 | 108 | ||
107 | - | ||
108 | - | func lsotc (caller) = makeString(["%s%s__lastPutOneTknCall", caller], SEP) | |
109 | - | ||
109 | + | let feePermille = valueOrElse(getInteger(this, keyFeePermille), feePermilleDefault) | |
110 | 110 | ||
111 | 111 | func fcfg () = "%s__factoryConfig" | |
112 | 112 | ||
113 | 113 | ||
114 | 114 | func mtpk () = "%s%s__matcher__publicKey" | |
115 | 115 | ||
116 | 116 | ||
117 | 117 | func pc (iAmtAs,iPrAs) = (((("%d%d%s__" + iAmtAs) + "__") + iPrAs) + "__config") | |
118 | 118 | ||
119 | 119 | ||
120 | 120 | func mba (bAStr) = ("%s%s%s__mappings__baseAsset2internalId__" + bAStr) | |
121 | 121 | ||
122 | 122 | ||
123 | 123 | func aps () = "%s__shutdown" | |
124 | 124 | ||
125 | 125 | ||
126 | 126 | func throwErr (msg) = throw(makeString(["lp_stable.ride:", msg], " ")) | |
127 | 127 | ||
128 | 128 | ||
129 | 129 | func throwOrderError (orV,sendrV,matchV) = throwErr(((((("Failed: ordValid=" + toString(orV)) + " sndrValid=") + toString(sendrV)) + " mtchrValid=") + toString(matchV))) | |
130 | 130 | ||
131 | 131 | ||
132 | 132 | func str (val) = match val { | |
133 | 133 | case valStr: String => | |
134 | 134 | valStr | |
135 | 135 | case _ => | |
136 | 136 | throwErr("fail cast to String") | |
137 | 137 | } | |
138 | 138 | ||
139 | 139 | ||
140 | 140 | func getStringOrFail (addr,key) = valueOrErrorMessage(getString(addr, key), makeString(["mandatory ", toString(addr), ".", key, " not defined"], "")) | |
141 | 141 | ||
142 | 142 | ||
143 | 143 | func getIntOrFail (addr,key) = valueOrErrorMessage(getInteger(addr, key), makeString(["mandatory ", toString(addr), ".", key, " not defined"], "")) | |
144 | 144 | ||
145 | 145 | ||
146 | 146 | let factoryContract = addressFromStringValue(getStringOrFail(this, keyFactoryContact())) | |
147 | 147 | ||
148 | 148 | let amplificator = getStringOrFail(this, keyAmplificator()) | |
149 | 149 | ||
150 | 150 | func isGlobalShutdown () = valueOrElse(getBoolean(factoryContract, aps()), false) | |
151 | 151 | ||
152 | 152 | ||
153 | 153 | func getMatcherPubOrFail () = fromBase58String(getStringOrFail(factoryContract, mtpk())) | |
154 | 154 | ||
155 | + | ||
156 | + | let matcherAddress = addressFromPublicKey(getMatcherPubOrFail()) | |
155 | 157 | ||
156 | 158 | func getPoolConfig () = { | |
157 | 159 | let amtAs = getStringOrFail(this, keyAmountAsset()) | |
158 | 160 | let priceAs = getStringOrFail(this, keyPriceAsset()) | |
159 | 161 | let iPriceAs = getIntOrFail(factoryContract, mba(priceAs)) | |
160 | 162 | let iAmtAs = getIntOrFail(factoryContract, mba(amtAs)) | |
161 | 163 | split(getStringOrFail(factoryContract, pc(toString(iAmtAs), toString(iPriceAs))), SEP) | |
162 | 164 | } | |
163 | 165 | ||
164 | 166 | ||
165 | 167 | func getFactoryConfig () = split(getStringOrFail(factoryContract, fcfg()), SEP) | |
166 | 168 | ||
167 | 169 | ||
168 | 170 | func dataPutActionInfo (inAmtAssetAmt,inPriceAssetAmt,outLpAmt,price,slipByUser,slippageReal,txHeight,txTimestamp,slipageAmAmt,slipagePrAmt) = makeString(["%d%d%d%d%d%d%d%d%d%d", toString(inAmtAssetAmt), toString(inPriceAssetAmt), toString(outLpAmt), toString(price), toString(slipByUser), toString(slippageReal), toString(txHeight), toString(txTimestamp), toString(slipageAmAmt), toString(slipagePrAmt)], SEP) | |
169 | 171 | ||
170 | 172 | ||
171 | 173 | 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) | |
172 | 174 | ||
173 | 175 | ||
174 | 176 | func getAccBalance (assetId) = if ((assetId == "WAVES")) | |
175 | 177 | then wavesBalance(this).available | |
176 | 178 | else assetBalance(this, fromBase58String(assetId)) | |
177 | 179 | ||
178 | 180 | ||
179 | 181 | func calcPriceBigInt (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18) | |
180 | 182 | ||
181 | 183 | ||
182 | 184 | func validateAbsDiff (estimateLP,outLp,slippage) = { | |
183 | 185 | let diff = fraction((estimateLP - outLp), scale8BigInt, outLp) | |
184 | 186 | let pass = ((slippage - abs(diff)) > zeroBigInt) | |
185 | 187 | if (!(pass)) | |
186 | 188 | then throwErr(("Big slippage: " + toString(diff))) | |
187 | 189 | else $Tuple2(pass, min([estimateLP, outLp])) | |
188 | 190 | } | |
189 | 191 | ||
190 | 192 | ||
191 | 193 | func validateD (D1,D0,slippage) = { | |
192 | 194 | let diff = fraction(D0, scale8BigInt, D1) | |
193 | 195 | let fail = (slippage > diff) | |
194 | 196 | if (if (fail) | |
195 | 197 | then true | |
196 | 198 | else (D0 > D1)) | |
197 | 199 | then throwErr(((((((toString(D0) + " ") + toString(D1)) + " ") + toString(diff)) + " ") + toString(slippage))) | |
198 | 200 | else fail | |
199 | 201 | } | |
200 | 202 | ||
201 | 203 | ||
202 | 204 | func privateCalcPrice (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
203 | 205 | let amtAsAmtX18 = toX18(amAmt, amAssetDcm) | |
204 | 206 | let prAsAmtX18 = toX18(prAmt, prAssetDcm) | |
205 | 207 | calcPriceBigInt(prAsAmtX18, amtAsAmtX18) | |
206 | 208 | } | |
207 | 209 | ||
208 | 210 | ||
209 | 211 | func calcPrices (amAmt,prAmt,lpAmt) = { | |
210 | 212 | let cfg = getPoolConfig() | |
211 | 213 | let amtAsDcm = parseIntValue(cfg[idxAmtAsDcm]) | |
212 | 214 | let prAsDcm = parseIntValue(cfg[idxPriceAsDcm]) | |
213 | 215 | let priceX18 = privateCalcPrice(amtAsDcm, prAsDcm, amAmt, prAmt) | |
214 | 216 | let amAmtX18 = toX18(amAmt, amtAsDcm) | |
215 | 217 | let prAmtX18 = toX18(prAmt, prAsDcm) | |
216 | 218 | let lpAmtX18 = toX18(lpAmt, scale8) | |
217 | 219 | let lpPrInAmAsX18 = calcPriceBigInt(amAmtX18, lpAmtX18) | |
218 | 220 | let lpPrInPrAsX18 = calcPriceBigInt(prAmtX18, lpAmtX18) | |
219 | 221 | [priceX18, lpPrInAmAsX18, lpPrInPrAsX18] | |
220 | 222 | } | |
221 | 223 | ||
222 | 224 | ||
223 | 225 | func calculatePrices (amAmt,prAmt,lpAmt) = { | |
224 | 226 | let p = calcPrices(amAmt, prAmt, lpAmt) | |
225 | 227 | [fromX18(p[0], scale8), fromX18(p[1], scale8), fromX18(p[2], scale8)] | |
226 | 228 | } | |
227 | 229 | ||
228 | 230 | ||
229 | 231 | func estimateGetOperation (txId58,paymentAssetId,paymentLpAmount,userAddress) = { | |
230 | 232 | let cfg = getPoolConfig() | |
231 | 233 | let lpAssetId = cfg[idxLPAsId] | |
232 | 234 | let amountId = cfg[idxAmAsId] | |
233 | 235 | let priceId = cfg[idxPrAsId] | |
234 | 236 | let amountDecimals = parseIntValue(cfg[idxAmtAsDcm]) | |
235 | 237 | let priceDecimals = parseIntValue(cfg[idxPriceAsDcm]) | |
236 | 238 | let sts = cfg[idxPoolSt] | |
237 | 239 | let lpEmission = valueOrErrorMessage(assetInfo(fromBase58String(lpAssetId)), "Wrong LP id").quantity | |
238 | 240 | let validationBlock = if ((lpAssetId == paymentAssetId)) | |
239 | 241 | then true | |
240 | 242 | else throwErr("Wrong payment asset") | |
241 | 243 | if ((validationBlock == validationBlock)) | |
242 | 244 | then { | |
243 | 245 | let decimals = if ((amountDecimals >= priceDecimals)) | |
244 | 246 | then amountDecimals | |
245 | 247 | else priceDecimals | |
246 | 248 | if ((decimals == decimals)) | |
247 | 249 | then { | |
248 | 250 | let amountBalance = getAccBalance(amountId) | |
249 | 251 | let amountBalanceX18 = toX18(amountBalance, decimals) | |
250 | 252 | let priceBalance = getAccBalance(priceId) | |
251 | 253 | let priceBalanceX18 = toX18(priceBalance, decimals) | |
252 | 254 | let currentPriceX18 = calcPriceBigInt(priceBalanceX18, amountBalanceX18) | |
253 | 255 | let curPrice = fromX18(currentPriceX18, scale8) | |
254 | 256 | let paymentLpAmountX18 = toX18(paymentLpAmount, scale8) | |
255 | 257 | let lpEmissionX18 = toX18(lpEmission, scale8) | |
256 | 258 | let outAmountAmountX18 = fraction(amountBalanceX18, paymentLpAmountX18, lpEmissionX18) | |
257 | 259 | let outPriceAmountX18 = fraction(priceBalanceX18, paymentLpAmountX18, lpEmissionX18) | |
258 | 260 | let outAmountAmount = fromX18(outAmountAmountX18, decimals) | |
259 | 261 | let outPriceAmount = fromX18(outPriceAmountX18, decimals) | |
260 | 262 | let state = if ((txId58 == "")) | |
261 | 263 | then nil | |
262 | 264 | else [ScriptTransfer(userAddress, outAmountAmount, if ((amountId == "WAVES")) | |
263 | 265 | then unit | |
264 | 266 | else fromBase58String(amountId)), ScriptTransfer(userAddress, outPriceAmount, if ((priceId == "WAVES")) | |
265 | 267 | then unit | |
266 | 268 | else fromBase58String(priceId)), StringEntry(keyGetActionByUser(toString(userAddress), txId58), dataGetActionInfo(outAmountAmount, outPriceAmount, paymentLpAmount, curPrice, height, lastBlock.timestamp)), IntegerEntry(keyPriceLast(), curPrice), IntegerEntry(keyPriceHistory(height, lastBlock.timestamp), curPrice)] | |
267 | 269 | $Tuple10(outAmountAmount, outPriceAmount, amountId, priceId, amountBalance, priceBalance, lpEmission, currentPriceX18, sts, state) | |
268 | 270 | } | |
269 | 271 | else throw("Strict value is not equal to itself.") | |
270 | 272 | } | |
271 | 273 | else throw("Strict value is not equal to itself.") | |
272 | 274 | } | |
273 | 275 | ||
274 | 276 | ||
275 | 277 | func estimatePutOperation (txId58,slippageTolerance,inAmountAssetAmount,inAmountAssetId,inPriceAssetAmount,inPriceAssetId,userAddress,isEvaluate,emitLp,isOneAsset,paymentAmount,paymentId) = { | |
276 | 278 | let cfg = getPoolConfig() | |
277 | 279 | let lpAssetId = fromBase58String(cfg[idxLPAsId]) | |
278 | 280 | let amountIdStr = cfg[idxAmAsId] | |
279 | 281 | let priceIdStr = cfg[idxPrAsId] | |
280 | 282 | let inAmountIdStr = cfg[idxIAmtAsId] | |
281 | 283 | let inPriceIdStr = cfg[idxIPriceAsId] | |
282 | 284 | let amountDecimals = parseIntValue(cfg[idxAmtAsDcm]) | |
283 | 285 | let priceDecimals = parseIntValue(cfg[idxPriceAsDcm]) | |
284 | 286 | let sts = cfg[idxPoolSt] | |
285 | 287 | let lpEmission = valueOrErrorMessage(assetInfo(lpAssetId), "Wrong lp asset").quantity | |
286 | 288 | let amountBalance = if (isEvaluate) | |
287 | 289 | then getAccBalance(amountIdStr) | |
288 | 290 | else if (if (isOneAsset) | |
289 | 291 | then (paymentId == amountIdStr) | |
290 | 292 | else false) | |
291 | 293 | then (getAccBalance(amountIdStr) - paymentAmount) | |
292 | 294 | else if (isOneAsset) | |
293 | 295 | then getAccBalance(amountIdStr) | |
294 | 296 | else (getAccBalance(amountIdStr) - inAmountAssetAmount) | |
295 | 297 | let priceBalance = if (isEvaluate) | |
296 | 298 | then getAccBalance(priceIdStr) | |
297 | 299 | else if (if (isOneAsset) | |
298 | 300 | then (paymentId == priceIdStr) | |
299 | 301 | else false) | |
300 | 302 | then (getAccBalance(priceIdStr) - paymentAmount) | |
301 | 303 | else if (isOneAsset) | |
302 | 304 | then getAccBalance(priceIdStr) | |
303 | 305 | else (getAccBalance(priceIdStr) - inPriceAssetAmount) | |
304 | 306 | let decimals = if ((amountDecimals >= priceDecimals)) | |
305 | 307 | then amountDecimals | |
306 | 308 | else priceDecimals | |
307 | 309 | if ((decimals == decimals)) | |
308 | 310 | then { | |
309 | 311 | let inAmountAssetAmountX18 = toX18(inAmountAssetAmount, decimals) | |
310 | 312 | let inPriceAssetAmountX18 = toX18(inPriceAssetAmount, decimals) | |
311 | 313 | let userPriceX18 = calcPriceBigInt(inPriceAssetAmountX18, inAmountAssetAmountX18) | |
312 | 314 | let amountBalanceX18 = toX18(amountBalance, decimals) | |
313 | 315 | let priceBalanceX18 = toX18(priceBalance, decimals) | |
314 | 316 | let r = if ((lpEmission == 0)) | |
315 | 317 | then { | |
316 | 318 | let currentPriceX18 = zeroBigInt | |
317 | 319 | let slippageX18 = zeroBigInt | |
318 | 320 | let lpAmountX18 = pow((inAmountAssetAmountX18 * inPriceAssetAmountX18), 0, toBigInt(5), 1, 0, DOWN) | |
319 | 321 | $Tuple5(fromX18(lpAmountX18, scale8), fromX18(inAmountAssetAmountX18, decimals), fromX18(inPriceAssetAmountX18, decimals), calcPriceBigInt((priceBalanceX18 + inPriceAssetAmountX18), (amountBalanceX18 + inAmountAssetAmountX18)), slippageX18) | |
320 | 322 | } | |
321 | 323 | else { | |
322 | 324 | let currentPriceX18 = calcPriceBigInt(priceBalanceX18, amountBalanceX18) | |
323 | 325 | let slippageRealX18 = fraction(abs((currentPriceX18 - userPriceX18)), scale18, currentPriceX18) | |
324 | 326 | let slippageX18 = toX18(slippageTolerance, scale8) | |
325 | - | | |
327 | + | if (if ((currentPriceX18 != zeroBigInt)) | |
326 | 328 | then (slippageRealX18 > slippageX18) | |
327 | - | else false) == false)) | |
328 | - | then true | |
329 | - | else throwErr(((("Price slippage " + toString(slippageRealX18)) + " > ") + toString(slippageX18))) | |
330 | - | if ((validateSlippage == validateSlippage)) | |
331 | - | then { | |
329 | + | else false) | |
330 | + | then throwErr(((("Price slippage " + toString(slippageRealX18)) + " > ") + toString(slippageX18))) | |
331 | + | else { | |
332 | 332 | let lpEmissionX18 = toX18(lpEmission, scale8) | |
333 | 333 | let prViaAmX18 = fraction(inAmountAssetAmountX18, currentPriceX18, scale18) | |
334 | 334 | let amViaPrX18 = fraction(inPriceAssetAmountX18, scale18, currentPriceX18) | |
335 | 335 | let expectedAmounts = if ((prViaAmX18 > inPriceAssetAmountX18)) | |
336 | 336 | then $Tuple2(amViaPrX18, inAmountAssetAmountX18) | |
337 | 337 | else $Tuple2(inAmountAssetAmountX18, prViaAmX18) | |
338 | 338 | let expectedAmountAssetAmountX18 = expectedAmounts._1 | |
339 | 339 | let expectedPriceAssetAmountX18 = expectedAmounts._2 | |
340 | 340 | let lpAmountX18 = fraction(lpEmissionX18, expectedPriceAssetAmountX18, priceBalanceX18) | |
341 | 341 | $Tuple5(fromX18(lpAmountX18, scale8), fromX18(expectedAmountAssetAmountX18, decimals), fromX18(expectedPriceAssetAmountX18, decimals), currentPriceX18, slippageX18) | |
342 | 342 | } | |
343 | - | else throw("Strict value is not equal to itself.") | |
344 | 343 | } | |
345 | 344 | let calculateLpAmount = r._1 | |
346 | 345 | let calculateAmountAssetPayment = r._2 | |
347 | 346 | let calculatePriceAssetPayment = r._3 | |
348 | 347 | let currentPrice = fromX18(r._4, scale8) | |
349 | 348 | let slippageCalculate = fromX18(r._5, scale8) | |
350 | 349 | let checkCalcLpAmount = if ((calculateLpAmount > 0)) | |
351 | 350 | then true | |
352 | 351 | else throwErr("LP <= 0") | |
353 | 352 | if ((checkCalcLpAmount == checkCalcLpAmount)) | |
354 | 353 | then { | |
355 | 354 | let emitLpAmount = if (!(emitLp)) | |
356 | 355 | then 0 | |
357 | 356 | else calculateLpAmount | |
358 | 357 | let amountDiff = (inAmountAssetAmount - calculateAmountAssetPayment) | |
359 | 358 | let priceDiff = (inPriceAssetAmount - calculatePriceAssetPayment) | |
360 | - | let $ | |
359 | + | let $t01618916448 = if (if (isOneAsset) | |
361 | 360 | then (paymentId == amountIdStr) | |
362 | 361 | else false) | |
363 | 362 | then $Tuple2(paymentAmount, 0) | |
364 | 363 | else if (if (isOneAsset) | |
365 | 364 | then (paymentId == priceIdStr) | |
366 | 365 | else false) | |
367 | 366 | then $Tuple2(0, paymentAmount) | |
368 | 367 | else $Tuple2(calculateAmountAssetPayment, calculatePriceAssetPayment) | |
369 | - | let writeAmAmt = $ | |
370 | - | let writePrAmt = $ | |
368 | + | let writeAmAmt = $t01618916448._1 | |
369 | + | let writePrAmt = $t01618916448._2 | |
371 | 370 | let commonState = [IntegerEntry(keyPriceLast(), currentPrice), IntegerEntry(keyPriceHistory(height, lastBlock.timestamp), currentPrice), StringEntry(keyPutActionByUser(userAddress, txId58), dataPutActionInfo(writeAmAmt, writePrAmt, emitLpAmount, currentPrice, slippageTolerance, slippageCalculate, height, lastBlock.timestamp, amountDiff, priceDiff))] | |
372 | 371 | $Tuple13(calculateLpAmount, emitLpAmount, currentPrice, amountBalance, priceBalance, lpEmission, lpAssetId, sts, commonState, amountDiff, priceDiff, inAmountAssetId, inPriceAssetId) | |
373 | 372 | } | |
374 | 373 | else throw("Strict value is not equal to itself.") | |
375 | 374 | } | |
376 | 375 | else throw("Strict value is not equal to itself.") | |
377 | 376 | } | |
378 | 377 | ||
379 | 378 | ||
380 | 379 | func validateMatcherOrderAllowed (order) = { | |
381 | 380 | let cfg = getPoolConfig() | |
382 | 381 | let amtAsId = cfg[idxAmAsId] | |
383 | 382 | let prAsId = cfg[idxPrAsId] | |
384 | 383 | let sts = parseIntValue(cfg[idxPoolSt]) | |
385 | 384 | let amtAsDcm = parseIntValue(cfg[idxAmtAsDcm]) | |
386 | 385 | let prAsDcm = parseIntValue(cfg[idxPriceAsDcm]) | |
387 | 386 | let accAmtAsBalance = getAccBalance(amtAsId) | |
388 | 387 | let accPrAsBalance = getAccBalance(prAsId) | |
389 | 388 | let currentPriceX18 = if ((order.orderType == Buy)) | |
390 | 389 | then privateCalcPrice(amtAsDcm, prAsDcm, (accAmtAsBalance + order.amount), accPrAsBalance) | |
391 | 390 | else privateCalcPrice(amtAsDcm, prAsDcm, (accAmtAsBalance - order.amount), accPrAsBalance) | |
392 | 391 | let curPrice = fromX18(currentPriceX18, scale8) | |
393 | 392 | if (if (if (isGlobalShutdown()) | |
394 | 393 | then true | |
395 | 394 | else (sts == PoolMatcherDis)) | |
396 | 395 | then true | |
397 | 396 | else (sts == PoolShutdown)) | |
398 | 397 | then throwErr("Admin blocked") | |
399 | 398 | else { | |
400 | 399 | let orAmtAsset = order.assetPair.amountAsset | |
401 | 400 | let orAmtAsStr = if ((orAmtAsset == unit)) | |
402 | 401 | then "WAVES" | |
403 | 402 | else toBase58String(value(orAmtAsset)) | |
404 | 403 | let orPrAsset = order.assetPair.priceAsset | |
405 | 404 | let orPrAsStr = if ((orPrAsset == unit)) | |
406 | 405 | then "WAVES" | |
407 | 406 | else toBase58String(value(orPrAsset)) | |
408 | 407 | if (if ((orAmtAsStr != amtAsId)) | |
409 | 408 | then true | |
410 | 409 | else (orPrAsStr != prAsId)) | |
411 | 410 | then throwErr("Wr assets") | |
412 | 411 | else { | |
413 | 412 | let orderPrice = order.price | |
414 | 413 | let priceDecimals = fraction(scale8, prAsDcm, amtAsDcm) | |
415 | 414 | let castOrderPrice = ts(orderPrice, scale8, priceDecimals) | |
416 | 415 | let isOrderPriceValid = if ((order.orderType == Buy)) | |
417 | 416 | then (curPrice >= castOrderPrice) | |
418 | 417 | else (castOrderPrice >= curPrice) | |
419 | 418 | true | |
420 | 419 | } | |
421 | 420 | } | |
422 | 421 | } | |
423 | 422 | ||
424 | 423 | ||
425 | 424 | func commonGet (i) = { | |
426 | 425 | let checkPayments = if ((size(i.payments) == 1)) | |
427 | 426 | then true | |
428 | 427 | else throwErr("1 payment expected") | |
429 | 428 | if ((checkPayments == checkPayments)) | |
430 | 429 | then { | |
431 | 430 | let payment = value(i.payments[0]) | |
432 | 431 | let paymentAssetId = value(payment.assetId) | |
433 | 432 | let paymentAmount = payment.amount | |
434 | 433 | let r = estimateGetOperation(toBase58String(i.transactionId), toBase58String(paymentAssetId), paymentAmount, i.caller) | |
435 | 434 | let outAmountAmount = r._1 | |
436 | 435 | let outPriceAmount = r._2 | |
437 | 436 | let sts = parseIntValue(r._9) | |
438 | 437 | let state = r._10 | |
439 | 438 | if (if (isGlobalShutdown()) | |
440 | 439 | then true | |
441 | 440 | else (sts == PoolShutdown)) | |
442 | 441 | then throwErr(("Admin blocked: " + toString(sts))) | |
443 | 442 | else $Tuple5(outAmountAmount, outPriceAmount, paymentAmount, paymentAssetId, state) | |
444 | 443 | } | |
445 | 444 | else throw("Strict value is not equal to itself.") | |
446 | 445 | } | |
447 | 446 | ||
448 | 447 | ||
449 | 448 | func commonPut (caller,txId,amountAssetPayment,priceAssetPayment,slippage,emitLp,isOneAsset,paymentAmount,paymentId) = { | |
450 | 449 | let r = estimatePutOperation(txId, slippage, value(amountAssetPayment).amount, value(amountAssetPayment).assetId, value(priceAssetPayment).amount, value(priceAssetPayment).assetId, caller, false, emitLp, isOneAsset, paymentAmount, paymentId) | |
451 | 450 | let sts = parseIntValue(r._8) | |
452 | 451 | if (if (if (isGlobalShutdown()) | |
453 | 452 | then true | |
454 | 453 | else (sts == PoolPutDis)) | |
455 | 454 | then true | |
456 | 455 | else (sts == PoolShutdown)) | |
457 | 456 | then throwErr(("Blocked:" + toString(sts))) | |
458 | 457 | else r | |
458 | + | } | |
459 | + | ||
460 | + | ||
461 | + | func takeFee (amount) = { | |
462 | + | let fee = fraction(amount, feePermille, thousand) | |
463 | + | $Tuple2((amount - fee), fee) | |
459 | 464 | } | |
460 | 465 | ||
461 | 466 | ||
462 | 467 | func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) { | |
463 | 468 | case s: String => | |
464 | 469 | fromBase58String(s) | |
465 | 470 | case _: Unit => | |
466 | 471 | unit | |
467 | 472 | case _ => | |
468 | 473 | throw("Match error") | |
469 | 474 | } | |
470 | 475 | ||
471 | 476 | ||
472 | 477 | func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) { | |
473 | 478 | case s: String => | |
474 | 479 | fromBase58String(s) | |
475 | 480 | case _: Unit => | |
476 | 481 | unit | |
477 | 482 | case _ => | |
478 | 483 | throw("Match error") | |
479 | 484 | } | |
480 | 485 | ||
481 | 486 | ||
482 | 487 | let pd = throwErr("Permission denied") | |
483 | 488 | ||
484 | 489 | func mustManager (i) = match managerPublicKeyOrUnit() { | |
485 | 490 | case pk: ByteVector => | |
486 | 491 | if ((i.callerPublicKey == pk)) | |
487 | 492 | then true | |
488 | 493 | else pd | |
489 | 494 | case _: Unit => | |
490 | 495 | if ((i.caller == this)) | |
491 | 496 | then true | |
492 | 497 | else pd | |
493 | 498 | case _ => | |
494 | 499 | throw("Match error") | |
495 | 500 | } | |
496 | 501 | ||
497 | 502 | ||
498 | 503 | @Callable(i) | |
499 | 504 | func constructor (factoryContract) = { | |
500 | 505 | let checkCaller = mustManager(i) | |
501 | 506 | if ((checkCaller == checkCaller)) | |
502 | 507 | then [StringEntry(keyFactoryContact(), factoryContract)] | |
503 | 508 | else throw("Strict value is not equal to itself.") | |
504 | 509 | } | |
505 | 510 | ||
506 | 511 | ||
507 | 512 | ||
508 | 513 | @Callable(i) | |
509 | 514 | func setManager (pendingManagerPublicKey) = { | |
510 | 515 | let checkCaller = mustManager(i) | |
511 | 516 | if ((checkCaller == checkCaller)) | |
512 | 517 | then { | |
513 | 518 | let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey) | |
514 | 519 | if ((checkManagerPublicKey == checkManagerPublicKey)) | |
515 | 520 | then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)] | |
516 | 521 | else throw("Strict value is not equal to itself.") | |
517 | 522 | } | |
518 | 523 | else throw("Strict value is not equal to itself.") | |
519 | 524 | } | |
520 | 525 | ||
521 | 526 | ||
522 | 527 | ||
523 | 528 | @Callable(i) | |
524 | 529 | func confirmManager () = { | |
525 | 530 | let pm = pendingManagerPublicKeyOrUnit() | |
526 | 531 | let hasPM = if (isDefined(pm)) | |
527 | 532 | then true | |
528 | 533 | else throwErr("No pending manager") | |
529 | 534 | if ((hasPM == hasPM)) | |
530 | 535 | then { | |
531 | 536 | let checkPM = if ((i.callerPublicKey == value(pm))) | |
532 | 537 | then true | |
533 | 538 | else throwErr("You are not pending manager") | |
534 | 539 | if ((checkPM == checkPM)) | |
535 | 540 | then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())] | |
536 | 541 | else throw("Strict value is not equal to itself.") | |
537 | 542 | } | |
538 | 543 | else throw("Strict value is not equal to itself.") | |
539 | 544 | } | |
540 | 545 | ||
541 | 546 | ||
542 | 547 | ||
543 | 548 | @Callable(i) | |
544 | 549 | func put (slippage,autoStake) = { | |
545 | 550 | let factCfg = getFactoryConfig() | |
546 | 551 | let stakingContract = valueOrErrorMessage(addressFromString(factCfg[idxFactStakCntr]), "Wrong staking contract") | |
547 | 552 | let slippageContract = valueOrErrorMessage(addressFromString(factCfg[idxFactSlippCntr]), "Wrogn slippage contract") | |
548 | 553 | let slippageCheck = if ((slippage >= 0)) | |
549 | 554 | then true | |
550 | 555 | else throwErr("wrong slippage") | |
551 | 556 | if ((slippageCheck == slippageCheck)) | |
552 | 557 | then { | |
553 | 558 | let paymentsCheck = if ((size(i.payments) == 2)) | |
554 | 559 | then true | |
555 | 560 | else throwErr("2 payments expected") | |
556 | 561 | if ((paymentsCheck == paymentsCheck)) | |
557 | 562 | then { | |
558 | 563 | let estimatePut = commonPut(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], slippage, true, false, 0, "") | |
559 | 564 | let emitLpAmount = estimatePut._2 | |
560 | 565 | let lpAssetId = estimatePut._7 | |
561 | 566 | let state = estimatePut._9 | |
562 | 567 | let amountDiff = estimatePut._10 | |
563 | 568 | let priceDiff = estimatePut._11 | |
564 | 569 | let amountId = estimatePut._12 | |
565 | 570 | let priceId = estimatePut._13 | |
566 | 571 | let r = invoke(factoryContract, "emit", [emitLpAmount], nil) | |
567 | 572 | if ((r == r)) | |
568 | 573 | then { | |
569 | 574 | let el = match r { | |
570 | 575 | case legacy: Address => | |
571 | 576 | invoke(legacy, "emit", [emitLpAmount], nil) | |
572 | 577 | case _ => | |
573 | 578 | unit | |
574 | 579 | } | |
575 | 580 | if ((el == el)) | |
576 | 581 | then { | |
577 | 582 | let sa = if ((amountDiff > 0)) | |
578 | 583 | then invoke(slippageContract, "put", nil, [AttachedPayment(amountId, amountDiff)]) | |
579 | 584 | else nil | |
580 | 585 | if ((sa == sa)) | |
581 | 586 | then { | |
582 | 587 | let sp = if ((priceDiff > 0)) | |
583 | 588 | then invoke(slippageContract, "put", nil, [AttachedPayment(priceId, priceDiff)]) | |
584 | 589 | else nil | |
585 | 590 | if ((sp == sp)) | |
586 | 591 | then { | |
587 | 592 | let lpTrasfer = if (autoStake) | |
588 | 593 | then { | |
589 | 594 | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmount)]) | |
590 | 595 | if ((ss == ss)) | |
591 | 596 | then nil | |
592 | 597 | else throw("Strict value is not equal to itself.") | |
593 | 598 | } | |
594 | 599 | else [ScriptTransfer(i.caller, emitLpAmount, lpAssetId)] | |
595 | 600 | (state ++ lpTrasfer) | |
596 | 601 | } | |
597 | 602 | else throw("Strict value is not equal to itself.") | |
598 | 603 | } | |
599 | 604 | else throw("Strict value is not equal to itself.") | |
600 | 605 | } | |
601 | 606 | else throw("Strict value is not equal to itself.") | |
602 | 607 | } | |
603 | 608 | else throw("Strict value is not equal to itself.") | |
604 | 609 | } | |
605 | 610 | else throw("Strict value is not equal to itself.") | |
606 | 611 | } | |
607 | 612 | else throw("Strict value is not equal to itself.") | |
608 | 613 | } | |
609 | 614 | ||
610 | 615 | ||
611 | 616 | ||
612 | 617 | @Callable(i) | |
613 | 618 | func putOneTkn (amountAssetPart,priceAssetPart,outLp,slippage,autoStake) = { | |
614 | 619 | let cfg = getFactoryConfig() | |
615 | 620 | let stakingContract = valueOrErrorMessage(addressFromString(cfg[idxFactStakCntr]), "Wrong staking contract") | |
616 | 621 | let slippageContract = valueOrErrorMessage(addressFromString(cfg[idxFactSlippCntr]), "Wrong slippage contract") | |
617 | 622 | let gwxRewardContract = valueOrErrorMessage(addressFromString(cfg[idxFactGwxRewCntr]), "Wrong gwx reward contract") | |
618 | 623 | let poolCfg = getPoolConfig() | |
619 | 624 | let amountId = poolCfg[idxAmAsId] | |
620 | 625 | let priceId = poolCfg[idxPrAsId] | |
621 | 626 | let amountDecimals = parseIntValue(poolCfg[idxAmtAsDcm]) | |
622 | 627 | let priceDecimals = parseIntValue(poolCfg[idxPriceAsDcm]) | |
623 | 628 | let addon = valueOrElse(getString(this, keyAddonAddress()), "") | |
624 | 629 | let userAddress = if ((addon == toString(i.caller))) | |
625 | 630 | then i.originCaller | |
626 | 631 | else i.caller | |
627 | - | let addonContract = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(keyAddonAddress()), "no addons")), "addon address in not valid") | |
628 | - | let check = reentrantInvoke(addonContract, "ensureCanPutOneTkn", [toString(userAddress)], nil) | |
629 | - | if ((check == check)) | |
630 | - | then if (if (if (if ((0 >= slippage)) | |
631 | - | then true | |
632 | - | else (0 >= amountAssetPart)) | |
633 | - | then true | |
634 | - | else (0 >= priceAssetPart)) | |
635 | - | then true | |
636 | - | else (0 >= outLp)) | |
637 | - | then throwErr("Wrong params") | |
638 | - | else if ((size(i.payments) != 1)) | |
639 | - | then throwErr("1 payment expected") | |
640 | - | else { | |
641 | - | let payment = value(i.payments[0]) | |
642 | - | let paymentAssetId = toBase58String(value(payment.assetId)) | |
643 | - | let paymentAmount = payment.amount | |
644 | - | if (if (if ((amountAssetPart > paymentAmount)) | |
645 | - | then true | |
646 | - | else (priceAssetPart > paymentAmount)) | |
647 | - | then true | |
648 | - | else (10000000 > paymentAmount)) | |
649 | - | then throwErr("wrong payment amount") | |
650 | - | else { | |
651 | - | let amountBalance = getAccBalance(amountId) | |
652 | - | let priceBalance = getAccBalance(priceId) | |
653 | - | let $t02607126526 = if ((paymentAssetId == amountId)) | |
654 | - | then $Tuple6((amountBalance - paymentAmount), priceBalance, (paymentAmount - amountAssetPart), priceAssetPart, 0, 0) | |
655 | - | else if ((paymentAssetId == priceId)) | |
656 | - | then $Tuple6(amountBalance, (priceBalance - paymentAmount), 0, 0, (paymentAmount - priceAssetPart), amountAssetPart) | |
657 | - | else throwErr("wrong paymentAssetId") | |
658 | - | let amountBalanceNow = $t02607126526._1 | |
659 | - | let priceBalanceNow = $t02607126526._2 | |
660 | - | let virtSwapInAm = $t02607126526._3 | |
661 | - | let virtSwapOutPr = $t02607126526._4 | |
662 | - | let virtSwapInPr = $t02607126526._5 | |
663 | - | let virtSwapOutAm = $t02607126526._6 | |
664 | - | let D0 = invoke(gwxRewardContract, "calcD", [toString(amountBalanceNow), toString(priceBalanceNow), amplificator, Amult, Dconv], nil) | |
665 | - | let D1 = invoke(gwxRewardContract, "calcD", [toString(toBigInt(((amountBalanceNow + virtSwapInAm) - virtSwapOutAm))), toString(toBigInt(((priceBalanceNow + virtSwapInPr) - virtSwapOutPr))), amplificator, Amult, Dconv], nil) | |
666 | - | let D0vsD1 = validateD(parseBigIntValue(str(D1)), parseBigIntValue(str(D0)), slippage4D) | |
667 | - | if ((D0vsD1 == D0vsD1)) | |
668 | - | then { | |
669 | - | let estimatePut = commonPut(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(fromBase58String(amountId), amountAssetPart), AttachedPayment(fromBase58String(priceId), priceAssetPart), slippage, true, true, paymentAmount, paymentAssetId) | |
670 | - | let estimateLP = estimatePut._2 | |
671 | - | let lpAssetId = estimatePut._7 | |
672 | - | let state = estimatePut._9 | |
673 | - | let amountDiff = estimatePut._10 | |
674 | - | let priceDiff = estimatePut._11 | |
675 | - | let lpCalcRes = validateAbsDiff(toBigInt(estimateLP), toBigInt(outLp), toBigInt(slippage)) | |
676 | - | let emitLpAmount = toInt(lpCalcRes._2) | |
677 | - | let e = invoke(factoryContract, "emit", [emitLpAmount], nil) | |
678 | - | if ((e == e)) | |
679 | - | then { | |
680 | - | let el = match e { | |
681 | - | case legacy: Address => | |
682 | - | invoke(legacy, "emit", [emitLpAmount], nil) | |
683 | - | case _ => | |
684 | - | unit | |
685 | - | } | |
686 | - | if ((el == el)) | |
687 | - | then { | |
688 | - | let sa = if ((amountDiff > 0)) | |
689 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(fromBase58String(amountId), amountDiff)]) | |
690 | - | else nil | |
691 | - | if ((sa == sa)) | |
692 | - | then { | |
693 | - | let sp = if ((priceDiff > 0)) | |
694 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(fromBase58String(priceId), priceDiff)]) | |
695 | - | else nil | |
696 | - | if ((sp == sp)) | |
697 | - | then { | |
698 | - | let lpTrasfer = if (autoStake) | |
699 | - | then { | |
700 | - | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmount)]) | |
701 | - | if ((ss == ss)) | |
702 | - | then nil | |
703 | - | else throw("Strict value is not equal to itself.") | |
704 | - | } | |
705 | - | else [ScriptTransfer(i.caller, emitLpAmount, lpAssetId)] | |
706 | - | (state ++ lpTrasfer) | |
707 | - | } | |
708 | - | else throw("Strict value is not equal to itself.") | |
709 | - | } | |
710 | - | else throw("Strict value is not equal to itself.") | |
711 | - | } | |
712 | - | else throw("Strict value is not equal to itself.") | |
713 | - | } | |
714 | - | else throw("Strict value is not equal to itself.") | |
715 | - | } | |
716 | - | else throw("Strict value is not equal to itself.") | |
717 | - | } | |
718 | - | } | |
719 | - | else throw("Strict value is not equal to itself.") | |
632 | + | if (if (if (if ((0 >= slippage)) | |
633 | + | then true | |
634 | + | else (0 >= amountAssetPart)) | |
635 | + | then true | |
636 | + | else (0 >= priceAssetPart)) | |
637 | + | then true | |
638 | + | else (0 >= outLp)) | |
639 | + | then throwErr("Wrong params") | |
640 | + | else if ((size(i.payments) != 1)) | |
641 | + | then throwErr("1 payment expected") | |
642 | + | else { | |
643 | + | let payment = value(i.payments[0]) | |
644 | + | let paymentAssetId = toBase58String(value(payment.assetId)) | |
645 | + | let paymentAmountRaw = payment.amount | |
646 | + | let $t02561725676 = takeFee(paymentAmountRaw) | |
647 | + | let paymentAmount = $t02561725676._1 | |
648 | + | let feeAmount = $t02561725676._2 | |
649 | + | if (if (if ((amountAssetPart > paymentAmount)) | |
650 | + | then true | |
651 | + | else (priceAssetPart > paymentAmount)) | |
652 | + | then true | |
653 | + | else (10000000 > paymentAmount)) | |
654 | + | then throwErr("wrong payment amount") | |
655 | + | else { | |
656 | + | let amountBalance = getAccBalance(amountId) | |
657 | + | let priceBalance = getAccBalance(priceId) | |
658 | + | let $t02594026395 = if ((paymentAssetId == amountId)) | |
659 | + | then $Tuple6((amountBalance - paymentAmount), priceBalance, (paymentAmount - amountAssetPart), priceAssetPart, 0, 0) | |
660 | + | else if ((paymentAssetId == priceId)) | |
661 | + | then $Tuple6(amountBalance, (priceBalance - paymentAmount), 0, 0, (paymentAmount - priceAssetPart), amountAssetPart) | |
662 | + | else throwErr("wrong paymentAssetId") | |
663 | + | let amountBalanceNow = $t02594026395._1 | |
664 | + | let priceBalanceNow = $t02594026395._2 | |
665 | + | let virtSwapInAm = $t02594026395._3 | |
666 | + | let virtSwapOutPr = $t02594026395._4 | |
667 | + | let virtSwapInPr = $t02594026395._5 | |
668 | + | let virtSwapOutAm = $t02594026395._6 | |
669 | + | let D0 = invoke(gwxRewardContract, "calcD", [toString(amountBalanceNow), toString(priceBalanceNow), amplificator, Amult, Dconv], nil) | |
670 | + | let D1 = invoke(gwxRewardContract, "calcD", [toString(toBigInt(((amountBalanceNow + virtSwapInAm) - virtSwapOutAm))), toString(toBigInt(((priceBalanceNow + virtSwapInPr) - virtSwapOutPr))), amplificator, Amult, Dconv], nil) | |
671 | + | let D0vsD1 = validateD(parseBigIntValue(str(D1)), parseBigIntValue(str(D0)), slippage4D) | |
672 | + | if ((D0vsD1 == D0vsD1)) | |
673 | + | then { | |
674 | + | let estimatePut = commonPut(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(fromBase58String(amountId), amountAssetPart), AttachedPayment(fromBase58String(priceId), priceAssetPart), slippage, true, true, paymentAmount, paymentAssetId) | |
675 | + | let estimateLP = estimatePut._2 | |
676 | + | let lpAssetId = estimatePut._7 | |
677 | + | let state = estimatePut._9 | |
678 | + | let amountDiff = estimatePut._10 | |
679 | + | let priceDiff = estimatePut._11 | |
680 | + | let lpCalcRes = validateAbsDiff(toBigInt(estimateLP), toBigInt(outLp), toBigInt(slippage)) | |
681 | + | let emitLpAmount = toInt(lpCalcRes._2) | |
682 | + | let e = invoke(factoryContract, "emit", [emitLpAmount], nil) | |
683 | + | if ((e == e)) | |
684 | + | then { | |
685 | + | let el = match e { | |
686 | + | case legacy: Address => | |
687 | + | invoke(legacy, "emit", [emitLpAmount], nil) | |
688 | + | case _ => | |
689 | + | unit | |
690 | + | } | |
691 | + | if ((el == el)) | |
692 | + | then { | |
693 | + | let sa = if ((amountDiff > 0)) | |
694 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(fromBase58String(amountId), amountDiff)]) | |
695 | + | else nil | |
696 | + | if ((sa == sa)) | |
697 | + | then { | |
698 | + | let sp = if ((priceDiff > 0)) | |
699 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(fromBase58String(priceId), priceDiff)]) | |
700 | + | else nil | |
701 | + | if ((sp == sp)) | |
702 | + | then { | |
703 | + | let lpTrasfer = if (autoStake) | |
704 | + | then { | |
705 | + | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmount)]) | |
706 | + | if ((ss == ss)) | |
707 | + | then nil | |
708 | + | else throw("Strict value is not equal to itself.") | |
709 | + | } | |
710 | + | else [ScriptTransfer(i.caller, emitLpAmount, lpAssetId)] | |
711 | + | let sendFeeToMatcher = if ((feeAmount > 0)) | |
712 | + | then [ScriptTransfer(matcherAddress, feeAmount, fromBase58String(paymentAssetId))] | |
713 | + | else nil | |
714 | + | ((state ++ lpTrasfer) ++ sendFeeToMatcher) | |
715 | + | } | |
716 | + | else throw("Strict value is not equal to itself.") | |
717 | + | } | |
718 | + | else throw("Strict value is not equal to itself.") | |
719 | + | } | |
720 | + | else throw("Strict value is not equal to itself.") | |
721 | + | } | |
722 | + | else throw("Strict value is not equal to itself.") | |
723 | + | } | |
724 | + | else throw("Strict value is not equal to itself.") | |
725 | + | } | |
726 | + | } | |
720 | 727 | } | |
721 | 728 | ||
722 | 729 | ||
723 | 730 | ||
724 | 731 | @Callable(i) | |
725 | 732 | func putForFree (maxslippage) = if ((0 > maxslippage)) | |
726 | 733 | then throwErr("wrong slippage") | |
727 | 734 | else if ((size(i.payments) != 2)) | |
728 | 735 | then throwErr("2 payments expected") | |
729 | 736 | else { | |
730 | 737 | let estimatePut = commonPut(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], maxslippage, false, false, 0, "") | |
731 | 738 | estimatePut._9 | |
732 | 739 | } | |
733 | 740 | ||
734 | 741 | ||
735 | 742 | ||
736 | 743 | @Callable(i) | |
737 | 744 | func get () = { | |
738 | 745 | let r = commonGet(i) | |
739 | 746 | let outAmtAmt = r._1 | |
740 | 747 | let outPriceAmount = r._2 | |
741 | 748 | let paymentAmount = r._3 | |
742 | 749 | let paymentAssetId = r._4 | |
743 | 750 | let state = r._5 | |
744 | 751 | let b = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)]) | |
745 | 752 | if ((b == b)) | |
746 | 753 | then state | |
747 | 754 | else throw("Strict value is not equal to itself.") | |
748 | 755 | } | |
749 | 756 | ||
750 | 757 | ||
751 | 758 | ||
752 | 759 | @Callable(i) | |
753 | 760 | func getOneTkn (exchResult,notUsed,outAmount,outAssetId,slippage) = if ((size(i.payments) != 1)) | |
754 | 761 | then throwErr("1 payment expected") | |
755 | 762 | else { | |
756 | 763 | let cfg = getPoolConfig() | |
757 | 764 | let lpAssetId = cfg[idxLPAsId] | |
758 | 765 | let amountId = cfg[idxAmAsId] | |
759 | 766 | let priceId = cfg[idxPrAsId] | |
760 | 767 | let amountDecimals = parseIntValue(cfg[idxAmtAsDcm]) | |
761 | 768 | let priceDecimals = parseIntValue(cfg[idxPriceAsDcm]) | |
762 | 769 | let sts = cfg[idxPoolSt] | |
763 | 770 | let factCfg = getFactoryConfig() | |
764 | 771 | let gwxRewardContract = valueOrErrorMessage(addressFromString(factCfg[idxFactGwxRewCntr]), "Wrong gwxRewardContract address") | |
765 | 772 | let payment = value(i.payments[0]) | |
766 | 773 | let addon = valueOrElse(getString(this, keyAddonAddress()), "") | |
767 | 774 | let userAddress = if ((addon == toString(i.caller))) | |
768 | 775 | then i.originCaller | |
769 | 776 | else i.caller | |
770 | 777 | let txId58 = toBase58String(i.transactionId) | |
771 | 778 | let paymentAssetId = value(payment.assetId) | |
772 | 779 | let paymentAmount = payment.amount | |
773 | - | let addonContract = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(keyAddonAddress()), "no addons")), "addon address in not valid") | |
774 | - | let check = reentrantInvoke(addonContract, "ensureCanGetOneTkn", [toString(userAddress)], nil) | |
775 | - | if ((check == check)) | |
776 | - | then if ((1000000000 > paymentAmount)) | |
777 | - | then throwErr("Min payment 10 LP") | |
778 | - | else if (if (if ((0 > slippage)) | |
779 | - | then true | |
780 | - | else (0 > exchResult)) | |
781 | - | then true | |
782 | - | else (0 > outAmount)) | |
783 | - | then throwErr("Wrong params") | |
784 | - | else if ((lpAssetId != toBase58String(paymentAssetId))) | |
785 | - | then throwErr("Wrong LP") | |
786 | - | else { | |
787 | - | let r = estimateGetOperation(toBase58String(i.transactionId), toBase58String(paymentAssetId), paymentAmount, i.caller) | |
788 | - | let estimAmAmt = r._1 | |
789 | - | let estimPrAmt = r._2 | |
790 | - | let amountBalance = getAccBalance(amountId) | |
791 | - | let priceBalance = getAccBalance(priceId) | |
792 | - | let $t03176632234 = if ((outAssetId == amountId)) | |
793 | - | then $Tuple7((amountBalance - estimAmAmt), (priceBalance - estimPrAmt), exchResult, estimPrAmt, 0, 0, (estimAmAmt + exchResult)) | |
794 | - | else if ((outAssetId == priceId)) | |
795 | - | then $Tuple7((amountBalance - estimAmAmt), (priceBalance - estimPrAmt), 0, 0, exchResult, estimAmAmt, (estimPrAmt + exchResult)) | |
796 | - | else throwErr("wrong outAssetId") | |
797 | - | let amountBalanceNow = $t03176632234._1 | |
798 | - | let priceBalanceNow = $t03176632234._2 | |
799 | - | let virtSwapInAm = $t03176632234._3 | |
800 | - | let virtSwapOutPr = $t03176632234._4 | |
801 | - | let virtSwapInPr = $t03176632234._5 | |
802 | - | let virtSwapOutAm = $t03176632234._6 | |
803 | - | let totalGet = $t03176632234._7 | |
804 | - | if (if ((0 > virtSwapInAm)) | |
805 | - | then true | |
806 | - | else (0 > virtSwapInPr)) | |
807 | - | then throwErr("Wrong calc") | |
808 | - | else { | |
809 | - | let D0 = invoke(gwxRewardContract, "calcD", [toString(amountBalanceNow), toString(priceBalanceNow), amplificator, Amult, Dconv], nil) | |
810 | - | let D1 = invoke(gwxRewardContract, "calcD", [toString(((amountBalanceNow - virtSwapInAm) + virtSwapOutAm)), toString(((priceBalanceNow + virtSwapOutPr) - virtSwapInPr)), amplificator, Amult, Dconv], nil) | |
811 | - | let D0vsD1 = validateD(parseBigIntValue(str(D1)), parseBigIntValue(str(D0)), slippage4D) | |
812 | - | if ((D0vsD1 == D0vsD1)) | |
813 | - | then { | |
814 | - | let finalRes = validateAbsDiff(toBigInt(totalGet), toBigInt(outAmount), toBigInt(slippage)) | |
815 | - | if ((finalRes == finalRes)) | |
816 | - | then { | |
817 | - | let $t03290333011 = if ((outAssetId == amountId)) | |
818 | - | then $Tuple2(toInt(finalRes._2), 0) | |
819 | - | else $Tuple2(0, toInt(finalRes._2)) | |
820 | - | let outAm = $t03290333011._1 | |
821 | - | let outPr = $t03290333011._2 | |
822 | - | let decimals = if ((amountDecimals >= priceDecimals)) | |
823 | - | then amountDecimals | |
824 | - | else priceDecimals | |
825 | - | if ((decimals == decimals)) | |
826 | - | then { | |
827 | - | let curPrX18 = calcPriceBigInt(toX18(priceBalance, decimals), toX18(amountBalance, decimals)) | |
828 | - | let curPr = fromX18(curPrX18, scale8) | |
829 | - | let state = [ScriptTransfer(userAddress, (outAm + outPr), if ((outAssetId == "WAVES")) | |
830 | - | then unit | |
831 | - | else fromBase58String(outAssetId)), StringEntry(keyGetActionByUser(toString(userAddress), txId58), dataGetActionInfo(outAm, outPr, paymentAmount, curPr, height, lastBlock.timestamp)), IntegerEntry(keyPriceLast(), curPr), IntegerEntry(keyPriceHistory(height, lastBlock.timestamp), curPr)] | |
832 | - | if ((state == state)) | |
833 | - | then { | |
834 | - | let burn = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)]) | |
835 | - | if ((burn == burn)) | |
836 | - | then state | |
837 | - | else throw("Strict value is not equal to itself.") | |
838 | - | } | |
839 | - | else throw("Strict value is not equal to itself.") | |
840 | - | } | |
841 | - | else throw("Strict value is not equal to itself.") | |
842 | - | } | |
843 | - | else throw("Strict value is not equal to itself.") | |
844 | - | } | |
845 | - | else throw("Strict value is not equal to itself.") | |
846 | - | } | |
847 | - | } | |
848 | - | else throw("Strict value is not equal to itself.") | |
780 | + | if ((1000000000 > paymentAmount)) | |
781 | + | then throwErr("Min payment 10 LP") | |
782 | + | else if (if (if ((0 > slippage)) | |
783 | + | then true | |
784 | + | else (0 > exchResult)) | |
785 | + | then true | |
786 | + | else (0 > outAmount)) | |
787 | + | then throwErr("Wrong params") | |
788 | + | else if ((lpAssetId != toBase58String(paymentAssetId))) | |
789 | + | then throwErr("Wrong LP") | |
790 | + | else { | |
791 | + | let r = estimateGetOperation(toBase58String(i.transactionId), toBase58String(paymentAssetId), paymentAmount, i.caller) | |
792 | + | let estimAmAmt = r._1 | |
793 | + | let estimPrAmt = r._2 | |
794 | + | let amountBalance = getAccBalance(amountId) | |
795 | + | let priceBalance = getAccBalance(priceId) | |
796 | + | let $t03153432002 = if ((outAssetId == amountId)) | |
797 | + | then $Tuple7((amountBalance - estimAmAmt), (priceBalance - estimPrAmt), exchResult, estimPrAmt, 0, 0, (estimAmAmt + exchResult)) | |
798 | + | else if ((outAssetId == priceId)) | |
799 | + | then $Tuple7((amountBalance - estimAmAmt), (priceBalance - estimPrAmt), 0, 0, exchResult, estimAmAmt, (estimPrAmt + exchResult)) | |
800 | + | else throwErr("wrong outAssetId") | |
801 | + | let amountBalanceNow = $t03153432002._1 | |
802 | + | let priceBalanceNow = $t03153432002._2 | |
803 | + | let virtSwapInAm = $t03153432002._3 | |
804 | + | let virtSwapOutPr = $t03153432002._4 | |
805 | + | let virtSwapInPr = $t03153432002._5 | |
806 | + | let virtSwapOutAm = $t03153432002._6 | |
807 | + | let totalGet = $t03153432002._7 | |
808 | + | if (if ((0 > virtSwapInAm)) | |
809 | + | then true | |
810 | + | else (0 > virtSwapInPr)) | |
811 | + | then throwErr("Wrong calc") | |
812 | + | else { | |
813 | + | let D0 = invoke(gwxRewardContract, "calcD", [toString(amountBalanceNow), toString(priceBalanceNow), amplificator, Amult, Dconv], nil) | |
814 | + | let D1 = invoke(gwxRewardContract, "calcD", [toString(((amountBalanceNow - virtSwapInAm) + virtSwapOutAm)), toString(((priceBalanceNow + virtSwapOutPr) - virtSwapInPr)), amplificator, Amult, Dconv], nil) | |
815 | + | let D0vsD1 = validateD(parseBigIntValue(str(D1)), parseBigIntValue(str(D0)), slippage4D) | |
816 | + | if ((D0vsD1 == D0vsD1)) | |
817 | + | then { | |
818 | + | let finalRes = validateAbsDiff(toBigInt(totalGet), toBigInt(outAmount), toBigInt(slippage)) | |
819 | + | if ((finalRes == finalRes)) | |
820 | + | then { | |
821 | + | let $t03267132779 = if ((outAssetId == amountId)) | |
822 | + | then $Tuple2(toInt(finalRes._2), 0) | |
823 | + | else $Tuple2(0, toInt(finalRes._2)) | |
824 | + | let outAm = $t03267132779._1 | |
825 | + | let outPr = $t03267132779._2 | |
826 | + | let totalAmountRaw = (outAm + outPr) | |
827 | + | let $t03281932874 = takeFee(totalAmountRaw) | |
828 | + | let totalAmount = $t03281932874._1 | |
829 | + | let feeAmount = $t03281932874._2 | |
830 | + | let outAssetIdOrWaves = if ((outAssetId == "WAVES")) | |
831 | + | then unit | |
832 | + | else fromBase58String(outAssetId) | |
833 | + | let sendFeeToMatcher = if ((feeAmount > 0)) | |
834 | + | then [ScriptTransfer(matcherAddress, feeAmount, outAssetIdOrWaves)] | |
835 | + | else nil | |
836 | + | let decimals = if ((amountDecimals >= priceDecimals)) | |
837 | + | then amountDecimals | |
838 | + | else priceDecimals | |
839 | + | if ((decimals == decimals)) | |
840 | + | then { | |
841 | + | let curPrX18 = calcPriceBigInt(toX18(priceBalance, decimals), toX18(amountBalance, decimals)) | |
842 | + | let curPr = fromX18(curPrX18, scale8) | |
843 | + | let state = [ScriptTransfer(userAddress, totalAmount, outAssetIdOrWaves), StringEntry(keyGetActionByUser(toString(userAddress), txId58), dataGetActionInfo(outAm, outPr, paymentAmount, curPr, height, lastBlock.timestamp)), IntegerEntry(keyPriceLast(), curPr), IntegerEntry(keyPriceHistory(height, lastBlock.timestamp), curPr)] | |
844 | + | if ((state == state)) | |
845 | + | then { | |
846 | + | let burn = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)]) | |
847 | + | if ((burn == burn)) | |
848 | + | then (state ++ sendFeeToMatcher) | |
849 | + | else throw("Strict value is not equal to itself.") | |
850 | + | } | |
851 | + | else throw("Strict value is not equal to itself.") | |
852 | + | } | |
853 | + | else throw("Strict value is not equal to itself.") | |
854 | + | } | |
855 | + | else throw("Strict value is not equal to itself.") | |
856 | + | } | |
857 | + | else throw("Strict value is not equal to itself.") | |
858 | + | } | |
859 | + | } | |
849 | 860 | } | |
850 | 861 | ||
851 | 862 | ||
852 | 863 | ||
853 | 864 | @Callable(i) | |
854 | 865 | func getNoLess (noLessThenAmtAsset,noLessThenPriceAsset) = { | |
855 | 866 | let r = commonGet(i) | |
856 | 867 | let outAmountAmount = r._1 | |
857 | 868 | let outPriceAmount = r._2 | |
858 | 869 | let paymentAmount = r._3 | |
859 | 870 | let paymentAssetId = r._4 | |
860 | 871 | let state = r._5 | |
861 | 872 | let checkOutAmountAmount = if ((outAmountAmount >= noLessThenAmtAsset)) | |
862 | 873 | then true | |
863 | 874 | else throwErr(((("Failed: " + toString(outAmountAmount)) + " < ") + toString(noLessThenAmtAsset))) | |
864 | 875 | if ((checkOutAmountAmount == checkOutAmountAmount)) | |
865 | 876 | then { | |
866 | 877 | let checkOutPriceAmount = if ((outPriceAmount >= noLessThenPriceAsset)) | |
867 | 878 | then true | |
868 | 879 | else throwErr(((("Failed: " + toString(outPriceAmount)) + " < ") + toString(noLessThenPriceAsset))) | |
869 | 880 | if ((checkOutPriceAmount == checkOutPriceAmount)) | |
870 | 881 | then { | |
871 | 882 | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)]) | |
872 | 883 | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
873 | 884 | then state | |
874 | 885 | else throw("Strict value is not equal to itself.") | |
875 | 886 | } | |
876 | 887 | else throw("Strict value is not equal to itself.") | |
877 | 888 | } | |
878 | 889 | else throw("Strict value is not equal to itself.") | |
879 | 890 | } | |
880 | 891 | ||
881 | 892 | ||
882 | 893 | ||
883 | 894 | @Callable(i) | |
884 | 895 | func unstakeAndGet (amount) = { | |
885 | 896 | let checkPayments = if ((size(i.payments) != 0)) | |
886 | 897 | then throwErr("no payments expected") | |
887 | 898 | else true | |
888 | 899 | if ((checkPayments == checkPayments)) | |
889 | 900 | then { | |
890 | 901 | let cfg = getPoolConfig() | |
891 | 902 | let factoryCfg = getFactoryConfig() | |
892 | 903 | let lpAssetId = fromBase58String(cfg[idxLPAsId]) | |
893 | 904 | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "wrong") | |
894 | 905 | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), amount], nil) | |
895 | 906 | if ((unstakeInv == unstakeInv)) | |
896 | 907 | then { | |
897 | 908 | let r = estimateGetOperation(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
898 | 909 | let sts = parseIntValue(r._9) | |
899 | 910 | let state = r._10 | |
900 | 911 | let v = if (if (isGlobalShutdown()) | |
901 | 912 | then true | |
902 | 913 | else (sts == PoolShutdown)) | |
903 | 914 | then throwErr(("Blocked: " + toString(sts))) | |
904 | 915 | else true | |
905 | 916 | if ((v == v)) | |
906 | 917 | then { | |
907 | 918 | let burnA = invoke(factoryContract, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
908 | 919 | if ((burnA == burnA)) | |
909 | 920 | then state | |
910 | 921 | else throw("Strict value is not equal to itself.") | |
911 | 922 | } | |
912 | 923 | else throw("Strict value is not equal to itself.") | |
913 | 924 | } | |
914 | 925 | else throw("Strict value is not equal to itself.") | |
915 | 926 | } | |
916 | 927 | else throw("Strict value is not equal to itself.") | |
917 | 928 | } | |
918 | 929 | ||
919 | 930 | ||
920 | 931 | ||
921 | 932 | @Callable(i) | |
922 | 933 | func activate (amtAsStr,prAsStr) = if ((toString(i.caller) != toString(factoryContract))) | |
923 | 934 | then throwErr("denied") | |
924 | 935 | else $Tuple2([StringEntry(keyAmountAsset(), amtAsStr), StringEntry(keyPriceAsset(), prAsStr)], "success") | |
925 | 936 | ||
926 | 937 | ||
927 | 938 | ||
928 | 939 | @Callable(i) | |
929 | 940 | func setS (k,v) = if ((toString(i.caller) != getStringOrFail(this, keyAddonAddress()))) | |
930 | 941 | then pd | |
931 | 942 | else [StringEntry(k, v)] | |
932 | 943 | ||
933 | 944 | ||
934 | 945 | ||
935 | 946 | @Callable(i) | |
936 | 947 | func setI (k,v) = if ((toString(i.caller) != getStringOrFail(this, keyAddonAddress()))) | |
937 | 948 | then pd | |
938 | 949 | else [IntegerEntry(k, v)] | |
939 | 950 | ||
940 | 951 | ||
941 | 952 | ||
942 | 953 | @Callable(i) | |
943 | 954 | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, getPoolConfig()) | |
944 | 955 | ||
945 | 956 | ||
946 | 957 | ||
947 | 958 | @Callable(i) | |
948 | 959 | func getAccBalanceWrapperREADONLY (assetId) = $Tuple2(nil, getAccBalance(assetId)) | |
949 | 960 | ||
950 | 961 | ||
951 | 962 | ||
952 | 963 | @Callable(i) | |
953 | 964 | func calcPricesWrapperREADONLY (amAmt,prAmt,lpAmt) = { | |
954 | 965 | let pr = calcPrices(amAmt, prAmt, lpAmt) | |
955 | 966 | $Tuple2(nil, [toString(pr[0]), toString(pr[1]), toString(pr[2])]) | |
956 | 967 | } | |
957 | 968 | ||
958 | 969 | ||
959 | 970 | ||
960 | 971 | @Callable(i) | |
961 | 972 | func fromX18WrapperREADONLY (val,resScaleMult) = $Tuple2(nil, fromX18(parseBigIntValue(val), resScaleMult)) | |
962 | 973 | ||
963 | 974 | ||
964 | 975 | ||
965 | 976 | @Callable(i) | |
966 | 977 | func toX18WrapperREADONLY (origVal,origScaleMult) = $Tuple2(nil, toString(toX18(origVal, origScaleMult))) | |
967 | 978 | ||
968 | 979 | ||
969 | 980 | ||
970 | 981 | @Callable(i) | |
971 | 982 | func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString(calcPriceBigInt(parseBigIntValue(prAmtX18), parseBigIntValue(amAmtX18)))) | |
972 | 983 | ||
973 | 984 | ||
974 | 985 | ||
975 | 986 | @Callable(i) | |
976 | 987 | func estimatePutOperationWrapperREADONLY (txId58,slippage,inAmountAssetAmount,inAmId,inPriceAssetAmount,inPrId,usrAddr,isEvaluate,emitLp) = $Tuple2(nil, estimatePutOperation(txId58, slippage, inAmountAssetAmount, inAmId, inPriceAssetAmount, inPrId, usrAddr, isEvaluate, emitLp, false, 0, "")) | |
977 | 988 | ||
978 | 989 | ||
979 | 990 | ||
980 | 991 | @Callable(i) | |
981 | 992 | func estimateGetOperationWrapperREADONLY (txId58,paymentAsId,paymentLpAmount,usrAddr) = { | |
982 | 993 | let r = estimateGetOperation(txId58, paymentAsId, paymentLpAmount, addressFromStringValue(usrAddr)) | |
983 | 994 | $Tuple2(nil, $Tuple10(r._1, r._2, r._3, r._4, r._5, r._6, r._7, toString(r._8), r._9, r._10)) | |
984 | 995 | } | |
985 | 996 | ||
986 | 997 | ||
987 | 998 | @Verifier(tx) | |
988 | 999 | func verify () = match tx { | |
989 | 1000 | case order: Order => | |
990 | 1001 | let mtchPub = getMatcherPubOrFail() | |
991 | 1002 | let orV = validateMatcherOrderAllowed(order) | |
992 | 1003 | let sndrV = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
993 | 1004 | let mtchV = sigVerify(order.bodyBytes, order.proofs[1], mtchPub) | |
994 | 1005 | if (if (if (orV) | |
995 | 1006 | then sndrV | |
996 | 1007 | else false) | |
997 | 1008 | then mtchV | |
998 | 1009 | else false) | |
999 | 1010 | then true | |
1000 | 1011 | else throwOrderError(orV, sndrV, mtchV) | |
1001 | 1012 | case _ => | |
1002 | 1013 | let targetPublicKey = match managerPublicKeyOrUnit() { | |
1003 | 1014 | case pk: ByteVector => | |
1004 | 1015 | pk | |
1005 | 1016 | case _: Unit => | |
1006 | 1017 | tx.senderPublicKey | |
1007 | 1018 | case _ => | |
1008 | 1019 | throw("Match error") | |
1009 | 1020 | } | |
1010 | 1021 | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1011 | 1022 | } | |
1012 | 1023 |
github/deemru/w8io/026f985 111.86 ms ◑