tx · 5DzdZyLEvuFS93qMgiWtNh14JFsBK3ukAkRrERxHQ3dG

3N7b3kPunHUXhZp1vMG9NhPMARNEprCMWxT:  -0.03100000 Waves

2023.02.27 12:40 [2467949] smart account 3N7b3kPunHUXhZp1vMG9NhPMARNEprCMWxT > SELF 0.00000000 Waves

{ "type": 13, "id": "5DzdZyLEvuFS93qMgiWtNh14JFsBK3ukAkRrERxHQ3dG", "fee": 3100000, "feeAssetId": null, "timestamp": 1677490953765, "version": 1, "sender": "3N7b3kPunHUXhZp1vMG9NhPMARNEprCMWxT", "senderPublicKey": "AYbpHveq7zviKTDV7SGTB1pZGFbkumgfq3jSwVv6BznT", "proofs": [ "2SFtaScEbGhQ8VLWAHsR9wdJWeg6kqQdPLsedJSHKgHpPg8UtFcEduUZebWrwFzedUA7oFAyHYFyUxPixjEtqieD" ], "script": "base64:BgK3JwgCEgMKAQgSABIECgIBBBIDCgEBEgQKAgEEEgQKAggBEgQKAggBEgQKAggBEgUKAwEIARIAEgQKAgEBEgMKAQESBQoDAQEBEgQKAggIEgASAwoBCBIFCgMBAQESBAoCAQESBAoCCAESBAoCCAgSCwoJCAEBAgECCAQEEgYKBAgIAQgSABIDCgEBEgMKAQESBAoCCAEiCmxQZGVjaW1hbHMiBnNjYWxlOCIMc2NhbGU4QmlnSW50IgdzY2FsZTE4Igp6ZXJvQmlnSW50IgRiaWcwIgRiaWcxIgRiaWcyIgt3YXZlc1N0cmluZyIDU0VQIgpQb29sQWN0aXZlIg9Qb29sUHV0RGlzYWJsZWQiE1Bvb2xNYXRjaGVyRGlzYWJsZWQiDFBvb2xTaHV0ZG93biIOaWR4UG9vbEFkZHJlc3MiDWlkeFBvb2xTdGF0dXMiEGlkeFBvb2xMUEFzc2V0SWQiDWlkeEFtdEFzc2V0SWQiD2lkeFByaWNlQXNzZXRJZCIOaWR4QW10QXNzZXREY20iEGlkeFByaWNlQXNzZXREY20iDmlkeElBbXRBc3NldElkIhBpZHhJUHJpY2VBc3NldElkIg1pZ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zCQCRAwIIBQJjUgZwcm9vZnMAAAgFAmNSD3NlbmRlclB1YmxpY0tleQQCYXQJAPQDAwgFAmNSCWJvZHlCeXRlcwkAkQMCCAUCY1IGcHJvb2ZzAAEFAmZMAwMDBQJhcgUCYXMHBQJhdAcGCQECYXEDBQJhcgUCYXMFAmF0AwkAAQIFAmRxAhRTZXRTY3JpcHRUcmFuc2FjdGlvbgQCZXcFAmRxBAJmTQkA9gMBCQEFdmFsdWUBCAUCZXcGc2NyaXB0BAJmTgkA2wQBCQEFdmFsdWUBCQCdCAIFAmFBCQECYW8ABAJmTwkA8QcBBQR0aGlzAwMJAAACBQJmTgUCZk0JAQIhPQIFAmZPBQJmTQcGCQD0AwMIBQJmSQlib2R5Qnl0ZXMJAJEDAggFAmZJBnByb29mcwAABQJmSwkA9AMDCAUCZkkJYm9keUJ5dGVzCQCRAwIIBQJmSQZwcm9vZnMAAAUCZkvBwFdz", "chainId": 84, "height": 2467949, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 24ur5xTDtKegEVmv88shnbugBou3imHU3jfa4rE5u9Vt Next: HxieAmcDMt8ZRJy8wx3FEnMrcyjbY9ZmPNttFEErgGhg Diff:
OldNewDifferences
6262 func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult))
6363
6464
65-func toX18BigInt (origVal,origScaleMult) = fraction(origVal, scale18, origScaleMult)
66-
67-
6865 func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18))
69-
70-
71-func fromX18Round (val,resultScaleMult,round) = toInt(fraction(val, toBigInt(resultScaleMult), scale18, round))
7266
7367
7468 func toScale (amt,resScale,curScale) = fraction(amt, resScale, curScale)
8276 func absBigInt (val) = if ((zeroBigInt > val))
8377 then -(val)
8478 else val
85-
86-
87-func swapContract () = "%s__swapContract"
8879
8980
9081 func fc () = "%s__factoryContract"
114105 func pa () = "%s__priceAsset"
115106
116107
117-let keyFee = "%s__fee"
118-
119-let feeDefault = fraction(10, scale8, 10000)
120-
121-let fee = valueOrElse(getInteger(this, keyFee), feeDefault)
122-
123-let keyKLp = makeString(["%s", "kLp"], SEP)
124-
125-let keyKLpRefreshedHeight = makeString(["%s", "kLpRefreshedHeight"], SEP)
126-
127-let keyKLpRefreshDelay = makeString(["%s", "refreshKLpDelay"], SEP)
128-
129-let kLpRefreshDelayDefault = 30
130-
131-let kLpRefreshDelay = valueOrElse(getInteger(this, keyKLpRefreshDelay), kLpRefreshDelayDefault)
132-
133108 func keyFactoryConfig () = "%s__factoryConfig"
134109
135110
156131
157132 let keyFeeCollectorAddress = "%s__feeCollectorAddress"
158133
159-func throwOrderError (orderValid,orderValidInfo,senderValid,matcherValid) = throw((((((((("order validation failed: orderValid=" + toString(orderValid)) + " (") + orderValidInfo) + ")") + " senderValid=") + toString(senderValid)) + " matcherValid=") + toString(matcherValid)))
134+func throwOrderError (orderValid,senderValid,matcherValid) = throw(((((("order validation failed: orderValid=" + toString(orderValid)) + " senderValid=") + toString(senderValid)) + " matcherValid=") + toString(matcherValid)))
160135
161136
162137 func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], ""))
166141
167142
168143 func throwErr (msg) = throw(makeString(["lp.ride:", msg], " "))
169-
170-
171-func fmtErr (msg) = makeString(["lp.ride:", msg], " ")
172144
173145
174146 let factoryContract = addressFromStringValue(getStringOrFail(this, fc()))
219191
220192 let poolConfigParsed = parsePoolConfig(getPoolConfig())
221193
222-let $t084698635 = poolConfigParsed
194+let $t076017767 = poolConfigParsed
223195
224-let cfgPoolAddress = $t084698635._1
196+let cfgPoolAddress = $t076017767._1
225197
226-let cfgPoolStatus = $t084698635._2
198+let cfgPoolStatus = $t076017767._2
227199
228-let cfgLpAssetId = $t084698635._3
200+let cfgLpAssetId = $t076017767._3
229201
230-let cfgAmountAssetId = $t084698635._4
202+let cfgAmountAssetId = $t076017767._4
231203
232-let cfgPriceAssetId = $t084698635._5
204+let cfgPriceAssetId = $t076017767._5
233205
234-let cfgAmountAssetDecimals = $t084698635._6
206+let cfgAmountAssetDecimals = $t076017767._6
235207
236-let cfgPriceAssetDecimals = $t084698635._7
208+let cfgPriceAssetDecimals = $t076017767._7
237209
238210 func getFactoryConfig () = split(getStringOrFail(factoryContract, keyFactoryConfig()), SEP)
239211
254226
255227
256228 func calcPriceBigInt (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18)
257-
258-
259-func calcPriceBigIntRound (prAmtX18,amAmtX18,round) = fraction(prAmtX18, scale18, amAmtX18, round)
260229
261230
262231 func privateCalcPrice (amAssetDcm,prAssetDcm,amAmt,prAmt) = {
308277 let lpEmissionX18 = toX18(lpEmission, scale8)
309278 let outAmAmtX18 = fraction(amBalanceX18, pmtLpAmtX18, lpEmissionX18)
310279 let outPrAmtX18 = fraction(prBalanceX18, pmtLpAmtX18, lpEmissionX18)
311- let outAmAmt = fromX18Round(outAmAmtX18, amAssetDcm, FLOOR)
312- let outPrAmt = fromX18Round(outPrAmtX18, prAssetDcm, FLOOR)
280+ let outAmAmt = fromX18(outAmAmtX18, amAssetDcm)
281+ let outPrAmt = fromX18(outPrAmtX18, prAssetDcm)
313282 let state = if ((txId58 == ""))
314283 then nil
315284 else [ScriptTransfer(userAddress, outAmAmt, if ((amAssetId == "WAVES"))
368337 then throw(((("Price slippage " + toString(slippageX18)) + " exceeded the passed limit of ") + toString(slippageToleranceX18)))
369338 else {
370339 let lpEmissionX18 = toX18(lpEmission, scale8)
371- let prViaAmX18 = fraction(inAmAssetAmtX18, calcPriceBigIntRound(prBalanceX18, amBalanceX18, CEILING), scale18, CEILING)
372- let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, calcPriceBigIntRound(prBalanceX18, amBalanceX18, FLOOR), CEILING)
340+ let prViaAmX18 = fraction(inAmAssetAmtX18, curPriceX18, scale18)
341+ let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, curPriceX18)
373342 let expectedAmts = if ((prViaAmX18 > inPrAssetAmtX18))
374343 then $Tuple2(amViaPrX18, inPrAssetAmtX18)
375344 else $Tuple2(inAmAssetAmtX18, prViaAmX18)
376345 let expAmtAssetAmtX18 = expectedAmts._1
377346 let expPriceAssetAmtX18 = expectedAmts._2
378- let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18, FLOOR)
379- $Tuple5(fromX18Round(lpAmtX18, scale8, FLOOR), fromX18Round(expAmtAssetAmtX18, amtAssetDcm, CEILING), fromX18Round(expPriceAssetAmtX18, priceAssetDcm, CEILING), curPriceX18, slippageX18)
347+ let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18)
348+ $Tuple5(fromX18(lpAmtX18, scale8), fromX18(expAmtAssetAmtX18, amtAssetDcm), fromX18(expPriceAssetAmtX18, priceAssetDcm), curPriceX18, slippageX18)
380349 }
381350 }
382351 let calcLpAmt = res._1
399368 }
400369
401370
402-func calcKLp (amountBalance,priceBalance,lpEmission) = {
403- let amountBalanceX18 = toX18BigInt(amountBalance, toBigInt(cfgAmountAssetDecimals))
404- let priceBalanceX18 = toX18BigInt(priceBalance, toBigInt(cfgPriceAssetDecimals))
405- let updatedKLp = fraction(pow((amountBalanceX18 * priceBalanceX18), 0, toBigInt(5), 1, 18, DOWN), big1, lpEmission)
406- if ((lpEmission == big0))
407- then big0
408- else updatedKLp
409- }
410-
411-
412-func calcCurrentKLp (amountAssetDelta,priceAssetDelta,lpAssetEmissionDelta) = {
413- let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amountAssetDelta)
414- let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - priceAssetDelta)
415- let lpAssetEmission = (toBigInt(value(assetInfo(cfgLpAssetId)).quantity) - lpAssetEmissionDelta)
416- let currentKLp = calcKLp(amountAssetBalance, priceAssetBalance, lpAssetEmission)
417- currentKLp
418- }
419-
420-
421-func refreshKLpInternal (amountAssetBalanceDelta,priceAssetBalanceDelta,lpAssetEmissionDelta) = {
422- let amountAssetBalance = (getAccBalance(assetIdToString(cfgAmountAssetId)) + amountAssetBalanceDelta)
423- let priceAssetBalance = (getAccBalance(assetIdToString(cfgPriceAssetId)) + priceAssetBalanceDelta)
424- let lpAssetEmission = (value(assetInfo(cfgLpAssetId)).quantity + lpAssetEmissionDelta)
425- let updatedKLp = calcKLp(toBigInt(amountAssetBalance), toBigInt(priceAssetBalance), toBigInt(lpAssetEmission))
426- let actions = [IntegerEntry(keyKLpRefreshedHeight, height), StringEntry(keyKLp, toString(updatedKLp))]
427- $Tuple2(actions, updatedKLp)
428- }
429-
430-
431-func validateUpdatedKLp (oldKLp,updatedKLp) = if ((updatedKLp >= oldKLp))
432- then true
433- else throwErr(makeString(["updated KLp lower than current KLp", toString(oldKLp), toString(updatedKLp)], " "))
434-
435-
436371 func validateMatcherOrderAllowed (order) = {
437- let amountAssetBalance = getAccBalance(assetIdToString(cfgAmountAssetId))
438- let priceAssetBalance = getAccBalance(assetIdToString(cfgPriceAssetId))
439- let amountAssetAmount = order.amount
440- let priceAssetAmount = fraction(order.amount, order.price, scale8, FLOOR)
441- let $t02154121753 = if ((order.orderType == Buy))
442- then $Tuple2(amountAssetAmount, -(priceAssetAmount))
443- else $Tuple2(-(amountAssetAmount), priceAssetAmount)
444- let amountAssetBalanceDelta = $t02154121753._1
445- let priceAssetBalanceDelta = $t02154121753._2
372+ let cfg = getPoolConfig()
373+ let amtAssetId = cfg[idxAmtAssetId]
374+ let priceAssetId = cfg[idxPriceAssetId]
375+ let poolStatus = parseIntValue(cfg[idxPoolStatus])
376+ let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm])
377+ let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm])
378+ let accAmtAssetBalance = getAccBalance(amtAssetId)
379+ let accPriceAssetBalance = getAccBalance(priceAssetId)
380+ let curPriceX18 = if ((order.orderType == Buy))
381+ then privateCalcPrice(amtAssetDcm, priceAssetDcm, (accAmtAssetBalance + order.amount), accPriceAssetBalance)
382+ else privateCalcPrice(amtAssetDcm, priceAssetDcm, (accAmtAssetBalance - order.amount), accPriceAssetBalance)
383+ let curPrice = fromX18(curPriceX18, scale8)
446384 if (if (if (isGlobalShutdown())
447385 then true
448- else (cfgPoolStatus == PoolMatcherDisabled))
386+ else (poolStatus == PoolMatcherDisabled))
449387 then true
450- else (cfgPoolStatus == PoolShutdown))
388+ else (poolStatus == PoolShutdown))
451389 then throw("Exchange operations disabled")
452- else if (if ((order.assetPair.amountAsset != cfgAmountAssetId))
453- then true
454- else (order.assetPair.priceAsset != cfgPriceAssetId))
455- then throw("Wrong order assets.")
456- else {
457- let kLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyKLp), "0")), fmtErr("invalid kLp"))
458- let $t02219322293 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0)
459- let unusedActions = $t02219322293._1
460- let kLpNew = $t02219322293._2
461- let isOrderValid = (kLpNew >= kLp)
462- let info = makeString(["kLp=", toString(kLp), " kLpNew=", toString(kLpNew), " amountAssetBalance=", toString(amountAssetBalance), " priceAssetBalance=", toString(priceAssetBalance), " amountAssetBalanceDelta=", toString(amountAssetBalanceDelta), " priceAssetBalanceDelta=", toString(priceAssetBalanceDelta), " height=", toString(height)], "")
463- $Tuple2(isOrderValid, info)
464- }
390+ else {
391+ let orderAmtAsset = order.assetPair.amountAsset
392+ let orderAmtAssetStr = if ((orderAmtAsset == unit))
393+ then "WAVES"
394+ else toBase58String(value(orderAmtAsset))
395+ let orderPriceAsset = order.assetPair.priceAsset
396+ let orderPriceAssetStr = if ((orderPriceAsset == unit))
397+ then "WAVES"
398+ else toBase58String(value(orderPriceAsset))
399+ if (if ((orderAmtAssetStr != amtAssetId))
400+ then true
401+ else (orderPriceAssetStr != priceAssetId))
402+ then throw("Wrong order assets.")
403+ else {
404+ let orderPrice = order.price
405+ let priceDcm = fraction(scale8, priceAssetDcm, amtAssetDcm)
406+ let castedOrderPrice = toScale(orderPrice, scale8, priceDcm)
407+ let isOrderPriceValid = if ((order.orderType == Buy))
408+ then (curPrice >= castedOrderPrice)
409+ else (castedOrderPrice >= curPrice)
410+ true
411+ }
412+ }
465413 }
466414
467415
536484 else if ((paymentAssetId == cfgPriceAssetId))
537485 then false
538486 else throwErr("invalid asset")
539- let $t02540625699 = if (isEval)
487+ let $t02266422957 = if (isEval)
540488 then $Tuple2(amountBalanceRaw, priceBalanceRaw)
541489 else if (paymentInAmountAsset)
542490 then $Tuple2((amountBalanceRaw - paymentAmountRaw), priceBalanceRaw)
543491 else $Tuple2(amountBalanceRaw, (priceBalanceRaw - paymentAmountRaw))
544- let amountBalanceOld = $t02540625699._1
545- let priceBalanceOld = $t02540625699._2
546- let $t02570325852 = if (paymentInAmountAsset)
492+ let amountBalanceOld = $t02266422957._1
493+ let priceBalanceOld = $t02266422957._2
494+ let $t02296123110 = if (paymentInAmountAsset)
547495 then $Tuple2(paymentAmountRaw, 0)
548496 else $Tuple2(0, paymentAmountRaw)
549- let amountAssetAmountRaw = $t02570325852._1
550- let priceAssetAmountRaw = $t02570325852._2
497+ let amountAssetAmountRaw = $t02296123110._1
498+ let priceAssetAmountRaw = $t02296123110._2
551499 let amountAssetAmount = takeFee(amountAssetAmountRaw, inFee)._1
552500 let priceAssetAmount = takeFee(priceAssetAmountRaw, inFee)._1
553- let $t02598426048 = takeFee(paymentAmountRaw, inFee)
554- let paymentAmount = $t02598426048._1
555- let feeAmount = $t02598426048._2
501+ let $t02324223306 = takeFee(paymentAmountRaw, inFee)
502+ let paymentAmount = $t02324223306._1
503+ let feeAmount = $t02324223306._2
556504 let amountBalanceNew = (amountBalanceOld + amountAssetAmount)
557505 let priceBalanceNew = (priceBalanceOld + priceAssetAmount)
558506 let priceNewX18 = calcPriceBigInt(toX18(priceBalanceNew, cfgPriceAssetDecimals), toX18(amountBalanceNew, cfgAmountAssetDecimals))
575523 let priceOldX18 = calcPriceBigInt(toX18(priceBalanceOld, cfgPriceAssetDecimals), toX18(amountBalanceOld, cfgAmountAssetDecimals))
576524 let priceOld = fromX18(priceOldX18, scale8)
577525 let loss = {
578- let $t02772927896 = if (paymentInAmountAsset)
526+ let $t02478324950 = if (paymentInAmountAsset)
579527 then $Tuple2(amountAssetAmountRaw, amountBalanceOld)
580528 else $Tuple2(priceAssetAmountRaw, priceBalanceOld)
581- let amount = $t02772927896._1
582- let balance = $t02772927896._2
529+ let amount = $t02478324950._1
530+ let balance = $t02478324950._2
583531 let issueAmountBoth = toInt(fraction(supplyBigInt, toBigInt((amount / 2)), toBigInt(balance)))
584532 fraction((issueAmount - issueAmountBoth), scale8, issueAmountBoth)
585533 }
586- $Tuple5(issueAmount, commonState, feeAmount, loss, paymentInAmountAsset)
534+ $Tuple4(issueAmount, commonState, feeAmount, loss)
587535 }
588536 else throw("Strict value is not equal to itself.")
589537 }
591539
592540 func calcGetOneToken (outAssetId,paymentAmount,paymentAssetId,userAddress,txId) = {
593541 let isEval = (txId == unit)
594- let cfg = getPoolConfig()
595- let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm])
596- let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm])
597542 let checks = [if ((paymentAssetId == cfgLpAssetId))
598543 then true
599544 else throwErr("invalid lp asset")]
607552 let balanceBigInt = if (outInAmountAsset)
608553 then toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId)))
609554 else toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId)))
610- let outInAmountAssetDecimals = if (outInAmountAsset)
611- then amtAssetDcm
612- else priceAssetDcm
613555 let amBalanceOld = getAccBalance(assetIdToString(cfgAmountAssetId))
614556 let prBalanceOld = getAccBalance(assetIdToString(cfgPriceAssetId))
615557 let outBalance = if (outInAmountAsset)
619561 let supplyBigInt = toBigInt(valueOrErrorMessage(assetInfo(cfgLpAssetId), (("asset " + toBase58String(cfgLpAssetId)) + " doesn't exist")).quantity)
620562 let redeemedBigInt = toBigInt(paymentAmount)
621563 let amountRaw = max([0, toInt(((balanceBigInt * (scale18 - pow((scale18 - ((redeemedBigInt * scale18) / supplyBigInt)), 18, big2, 0, 18, DOWN))) / scale18))])
622- let $t02997430030 = takeFee(amountRaw, outFee)
623- let totalAmount = $t02997430030._1
624- let feeAmount = $t02997430030._2
625- let $t03003430260 = if (outInAmountAsset)
564+ let $t02653026586 = takeFee(amountRaw, outFee)
565+ let totalAmount = $t02653026586._1
566+ let feeAmount = $t02653026586._2
567+ let $t02659026816 = if (outInAmountAsset)
626568 then $Tuple4(totalAmount, 0, (amBalanceOld - amountRaw), prBalanceOld)
627569 else $Tuple4(0, totalAmount, amBalanceOld, (prBalanceOld - amountRaw))
628- let outAmAmount = $t03003430260._1
629- let outPrAmount = $t03003430260._2
630- let amBalanceNew = $t03003430260._3
631- let prBalanceNew = $t03003430260._4
570+ let outAmAmount = $t02659026816._1
571+ let outPrAmount = $t02659026816._2
572+ let amBalanceNew = $t02659026816._3
573+ let prBalanceNew = $t02659026816._4
632574 let priceNewX18 = calcPriceBigInt(toX18(prBalanceNew, cfgPriceAssetDecimals), toX18(amBalanceNew, cfgAmountAssetDecimals))
633575 let priceNew = fromX18(priceNewX18, scale8)
634576 let commonState = if (isEval)
640582 let amountBothInPaymentAsset = (toInt(fraction(balanceBigInt, redeemedBigInt, supplyBigInt)) * 2)
641583 fraction((totalAmount - amountBothInPaymentAsset), scale8, amountBothInPaymentAsset)
642584 }
643- $Tuple5(totalAmount, commonState, feeAmount, loss, outInAmountAsset)
585+ $Tuple4(totalAmount, commonState, feeAmount, loss)
644586 }
645587 else throw("Strict value is not equal to itself.")
646588 }
694636
695637
696638 @Callable(i)
697-func calculateAmountOutForSwapREADONLY (cleanAmountIn,isReverse,feePoolAmount) = {
698- let $t03197732282 = if ((isReverse == false))
699- then {
700- let assetOut = getStringOrFail(this, pa())
701- let assetIn = getStringOrFail(this, aa())
702- $Tuple2(assetOut, assetIn)
703- }
704- else {
705- let assetOut = getStringOrFail(this, aa())
706- let assetIn = getStringOrFail(this, pa())
707- $Tuple2(assetOut, assetIn)
708- }
709- let assetOut = $t03197732282._1
710- let assetIn = $t03197732282._2
711- let poolAssetInBalance = getAccBalance(assetIn)
712- let poolAssetOutBalance = getAccBalance(assetOut)
713- let amountOut = fraction(poolAssetOutBalance, cleanAmountIn, (poolAssetInBalance + cleanAmountIn))
714- let oldK = (toBigInt(poolAssetInBalance) * toBigInt(poolAssetOutBalance))
715- let newK = (((toBigInt(getAccBalance(assetIn)) + toBigInt(cleanAmountIn)) + toBigInt(feePoolAmount)) * (toBigInt(getAccBalance(assetOut)) - toBigInt(amountOut)))
716- let checkK = if ((newK >= oldK))
717- then true
718- else throw("new K is fewer error")
719- if ((checkK == checkK))
720- then $Tuple2(nil, amountOut)
721- else throw("Strict value is not equal to itself.")
722- }
723-
724-
725-
726-@Callable(i)
727-func calculateAmountOutForSwapAndSendTokens (cleanAmountIn,isReverse,amountOutMin,addressTo,feePoolAmount) = {
728- let swapContact = {
729- let @ = invoke(factoryContract, "getSwapContractREADONLY", nil, nil)
730- if ($isInstanceOf(@, "String"))
731- then @
732- else throw(($getType(@) + " couldn't be cast to String"))
733- }
734- let checks = [if ((value(i.payments[0]).amount >= cleanAmountIn))
735- then true
736- else throwErr("Wrong amount"), if ((i.caller == addressFromStringValue(swapContact)))
737- then true
738- else throwErr("Permission denied")]
739- if ((checks == checks))
740- then {
741- let pmt = value(i.payments[0])
742- let assetIn = assetIdToString(pmt.assetId)
743- let assetOut = if ((isReverse == false))
744- then getStringOrFail(this, pa())
745- else getStringOrFail(this, aa())
746- let poolAssetInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount)
747- let poolAssetOutBalance = getAccBalance(assetOut)
748- let amountOut = fraction(poolAssetOutBalance, cleanAmountIn, (poolAssetInBalance + cleanAmountIn))
749- let oldK = (toBigInt(poolAssetInBalance) * toBigInt(poolAssetOutBalance))
750- let newK = ((toBigInt(getAccBalance(assetIn)) + toBigInt(feePoolAmount)) * (toBigInt(getAccBalance(assetOut)) - toBigInt(amountOut)))
751- let checkK = if ((newK >= oldK))
752- then true
753- else throw("new K is fewer error")
754- if ((checkK == checkK))
755- then {
756- let checkMin = if ((amountOut >= amountOutMin))
757- then true
758- else throw("Exchange result is fewer coins than expected")
759- if ((checkMin == checkMin))
760- then $Tuple2([ScriptTransfer(addressFromStringValue(addressTo), amountOut, parseAssetId(assetOut))], amountOut)
761- else throw("Strict value is not equal to itself.")
762- }
763- else throw("Strict value is not equal to itself.")
764- }
765- else throw("Strict value is not equal to itself.")
766- }
767-
768-
769-
770-@Callable(i)
771639 func setManager (pendingManagerPublicKey) = {
772640 let checkCaller = mustManager(i)
773641 if ((checkCaller == checkCaller))
814682 let prDiff = estPut._11
815683 let amId = estPut._12
816684 let prId = estPut._13
817- let amAssetPmt = toBigInt(value(i.payments[0]).amount)
818- let prAssetPmt = toBigInt(value(i.payments[1]).amount)
819- let currentKLp = calcCurrentKLp(amAssetPmt, prAssetPmt, toBigInt(0))
820- if ((currentKLp == currentKLp))
685+ let emitInv = invoke(factoryContract, "emit", [emitLpAmt], nil)
686+ if ((emitInv == emitInv))
821687 then {
822- let emitInv = invoke(factoryContract, "emit", [emitLpAmt], nil)
823- if ((emitInv == emitInv))
688+ let emitInvLegacy = match emitInv {
689+ case legacyFactoryContract: Address =>
690+ invoke(legacyFactoryContract, "emit", [emitLpAmt], nil)
691+ case _ =>
692+ unit
693+ }
694+ if ((emitInvLegacy == emitInvLegacy))
824695 then {
825- let emitInvLegacy = match emitInv {
826- case legacyFactoryContract: Address =>
827- invoke(legacyFactoryContract, "emit", [emitLpAmt], nil)
828- case _ =>
829- unit
830- }
831- if ((emitInvLegacy == emitInvLegacy))
696+ let slippageAInv = if ((amDiff > 0))
697+ then invoke(slippageContract, "put", nil, [AttachedPayment(amId, amDiff)])
698+ else nil
699+ if ((slippageAInv == slippageAInv))
832700 then {
833- let slippageAInv = if ((amDiff > 0))
834- then invoke(slippageContract, "put", nil, [AttachedPayment(amId, amDiff)])
701+ let slippagePInv = if ((prDiff > 0))
702+ then invoke(slippageContract, "put", nil, [AttachedPayment(prId, prDiff)])
835703 else nil
836- if ((slippageAInv == slippageAInv))
704+ if ((slippagePInv == slippagePInv))
837705 then {
838- let slippagePInv = if ((prDiff > 0))
839- then invoke(slippageContract, "put", nil, [AttachedPayment(prId, prDiff)])
840- else nil
841- if ((slippagePInv == slippagePInv))
706+ let lpTransfer = if (shouldAutoStake)
842707 then {
843- let lpTransfer = if (shouldAutoStake)
844- then {
845- let slpStakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)])
846- if ((slpStakeInv == slpStakeInv))
847- then nil
848- else throw("Strict value is not equal to itself.")
849- }
850- else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)]
851- let $t03716637628 = refreshKLpInternal(0, 0, 0)
852- if (($t03716637628 == $t03716637628))
853- then {
854- let updatedKLp = $t03716637628._2
855- let refreshKLpActions = $t03716637628._1
856- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
857- if ((isUpdatedKLpValid == isUpdatedKLpValid))
858- then ((state ++ lpTransfer) ++ refreshKLpActions)
859- else throw("Strict value is not equal to itself.")
860- }
708+ let slpStakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)])
709+ if ((slpStakeInv == slpStakeInv))
710+ then nil
861711 else throw("Strict value is not equal to itself.")
862712 }
863- else throw("Strict value is not equal to itself.")
713+ else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)]
714+ (state ++ lpTransfer)
864715 }
865716 else throw("Strict value is not equal to itself.")
866717 }
878729 then throw("Invalid value passed")
879730 else {
880731 let estPut = commonPut(i, maxSlippage, false)
881- let state = estPut._9
882- let amAssetPmt = toBigInt(value(i.payments[0]).amount)
883- let prAssetPmt = toBigInt(value(i.payments[1]).amount)
884- let currentKLp = calcCurrentKLp(amAssetPmt, prAssetPmt, toBigInt(0))
885- if ((currentKLp == currentKLp))
886- then {
887- let $t03819038255 = refreshKLpInternal(0, 0, 0)
888- let refreshKLpActions = $t03819038255._1
889- let updatedKLp = $t03819038255._2
890- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
891- if ((isUpdatedKLpValid == isUpdatedKLpValid))
892- then (state ++ refreshKLpActions)
893- else throw("Strict value is not equal to itself.")
894- }
895- else throw("Strict value is not equal to itself.")
732+ estPut._9
896733 }
897734
898735
924761 let payment = i.payments[0]
925762 let paymentAssetId = payment.assetId
926763 let paymentAmountRaw = payment.amount
927- let currentKLp = if ((paymentAssetId == cfgAmountAssetId))
928- then calcCurrentKLp(toBigInt(paymentAmountRaw), toBigInt(0), toBigInt(0))
929- else if ((paymentAssetId == cfgPriceAssetId))
930- then calcCurrentKLp(toBigInt(0), toBigInt(paymentAmountRaw), toBigInt(0))
931- else throwErr("payment asset is not supported")
932- if ((currentKLp == currentKLp))
764+ let userAddress = i.caller
765+ let txId = i.transactionId
766+ let $t03172331853 = calcPutOneToken(paymentAmountRaw, paymentAssetId, userAddress, txId)
767+ if (($t03172331853 == $t03172331853))
933768 then {
934- let userAddress = i.caller
935- let txId = i.transactionId
936- let $t03944339595 = calcPutOneToken(paymentAmountRaw, paymentAssetId, userAddress, txId)
937- if (($t03944339595 == $t03944339595))
769+ let bonus = $t03172331853._4
770+ let feeAmount = $t03172331853._3
771+ let commonState = $t03172331853._2
772+ let emitAmountEstimated = $t03172331853._1
773+ let emitAmount = if (if ((minOutAmount > 0))
774+ then (minOutAmount > emitAmountEstimated)
775+ else false)
776+ then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], ""))
777+ else emitAmountEstimated
778+ let emitInv = emit(emitAmount)
779+ if ((emitInv == emitInv))
938780 then {
939- let paymentInAmountAsset = $t03944339595._5
940- let bonus = $t03944339595._4
941- let feeAmount = $t03944339595._3
942- let commonState = $t03944339595._2
943- let emitAmountEstimated = $t03944339595._1
944- let emitAmount = if (if ((minOutAmount > 0))
945- then (minOutAmount > emitAmountEstimated)
946- else false)
947- then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], ""))
948- else emitAmountEstimated
949- let emitInv = emit(emitAmount)
950- if ((emitInv == emitInv))
781+ let lpTransfer = if (autoStake)
951782 then {
952- let lpTransfer = if (autoStake)
953- then {
954- let stakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(cfgLpAssetId, emitAmount)])
955- if ((stakeInv == stakeInv))
956- then nil
957- else throw("Strict value is not equal to itself.")
958- }
959- else [ScriptTransfer(i.caller, emitAmount, cfgLpAssetId)]
960- let sendFee = if ((feeAmount > 0))
961- then [ScriptTransfer(feeCollectorAddress, feeAmount, paymentAssetId)]
962- else nil
963- let $t04018140378 = if ((this == feeCollectorAddress))
964- then $Tuple2(0, 0)
965- else if (paymentInAmountAsset)
966- then $Tuple2(-(feeAmount), 0)
967- else $Tuple2(0, -(feeAmount))
968- let amountAssetBalanceDelta = $t04018140378._1
969- let priceAssetBalanceDelta = $t04018140378._2
970- let $t04038140489 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0)
971- let refreshKLpActions = $t04038140489._1
972- let updatedKLp = $t04038140489._2
973- let kLp = value(getString(keyKLp))
974- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
975- if ((isUpdatedKLpValid == isUpdatedKLpValid))
976- then $Tuple2((((commonState ++ lpTransfer) ++ sendFee) ++ refreshKLpActions), emitAmount)
783+ let stakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(cfgLpAssetId, emitAmount)])
784+ if ((stakeInv == stakeInv))
785+ then nil
977786 else throw("Strict value is not equal to itself.")
978787 }
979- else throw("Strict value is not equal to itself.")
788+ else [ScriptTransfer(i.caller, emitAmount, cfgLpAssetId)]
789+ let sendFee = if ((feeAmount > 0))
790+ then [ScriptTransfer(feeCollectorAddress, feeAmount, paymentAssetId)]
791+ else nil
792+ $Tuple2(((commonState ++ lpTransfer) ++ sendFee), emitAmount)
980793 }
981794 else throw("Strict value is not equal to itself.")
982795 }
989802
990803 @Callable(i)
991804 func putOneTknREADONLY (paymentAssetId,paymentAmountRaw) = {
992- let $t04079540952 = calcPutOneToken(paymentAmountRaw, parseAssetId(paymentAssetId), unit, unit)
993- let emitAmountEstimated = $t04079540952._1
994- let commonState = $t04079540952._2
995- let feeAmount = $t04079540952._3
996- let bonus = $t04079540952._4
997- let paymentInAmountAsset = $t04079540952._5
805+ let $t03258232717 = calcPutOneToken(paymentAmountRaw, parseAssetId(paymentAssetId), unit, unit)
806+ let emitAmountEstimated = $t03258232717._1
807+ let commonState = $t03258232717._2
808+ let feeAmount = $t03258232717._3
809+ let bonus = $t03258232717._4
998810 $Tuple2(nil, $Tuple3(emitAmountEstimated, feeAmount, bonus))
999811 }
1000812
1026838 let payment = i.payments[0]
1027839 let paymentAssetId = payment.assetId
1028840 let paymentAmount = payment.amount
1029- let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0))
1030- if ((currentKLp == currentKLp))
841+ let userAddress = i.caller
842+ let txId = i.transactionId
843+ let $t03352233657 = calcGetOneToken(outAssetId, paymentAmount, paymentAssetId, userAddress, txId)
844+ if (($t03352233657 == $t03352233657))
1031845 then {
1032- let userAddress = i.caller
1033- let txId = i.transactionId
1034- let $t04183741990 = calcGetOneToken(outAssetId, paymentAmount, paymentAssetId, userAddress, txId)
1035- if (($t04183741990 == $t04183741990))
846+ let bonus = $t03352233657._4
847+ let feeAmount = $t03352233657._3
848+ let commonState = $t03352233657._2
849+ let amountEstimated = $t03352233657._1
850+ let amount = if (if ((minOutAmount > 0))
851+ then (minOutAmount > amountEstimated)
852+ else false)
853+ then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], ""))
854+ else amountEstimated
855+ let burnInv = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)])
856+ if ((burnInv == burnInv))
1036857 then {
1037- let outInAmountAsset = $t04183741990._5
1038- let bonus = $t04183741990._4
1039- let feeAmount = $t04183741990._3
1040- let commonState = $t04183741990._2
1041- let amountEstimated = $t04183741990._1
1042- let amount = if (if ((minOutAmount > 0))
1043- then (minOutAmount > amountEstimated)
1044- else false)
1045- then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], ""))
1046- else amountEstimated
1047- let burnInv = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)])
1048- if ((burnInv == burnInv))
1049- then {
1050- let assetTransfer = [ScriptTransfer(userAddress, amount, outAssetId)]
1051- let sendFee = if ((feeAmount > 0))
1052- then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)]
1053- else nil
1054- let $t04249042737 = {
1055- let feeAmountForCalc = if ((this == feeCollectorAddress))
1056- then 0
1057- else feeAmount
1058- if (outInAmountAsset)
1059- then $Tuple2(-((amount + feeAmountForCalc)), 0)
1060- else $Tuple2(0, -((amount + feeAmountForCalc)))
1061- }
1062- let amountAssetBalanceDelta = $t04249042737._1
1063- let priceAssetBalanceDelta = $t04249042737._2
1064- let $t04274042848 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0)
1065- let refreshKLpActions = $t04274042848._1
1066- let updatedKLp = $t04274042848._2
1067- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
1068- if ((isUpdatedKLpValid == isUpdatedKLpValid))
1069- then $Tuple2((((commonState ++ assetTransfer) ++ sendFee) ++ refreshKLpActions), amount)
1070- else throw("Strict value is not equal to itself.")
1071- }
1072- else throw("Strict value is not equal to itself.")
858+ let assetTransfer = [ScriptTransfer(userAddress, amount, outAssetId)]
859+ let sendFee = if ((feeAmount > 0))
860+ then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)]
861+ else nil
862+ $Tuple2(((commonState ++ assetTransfer) ++ sendFee), amount)
1073863 }
1074864 else throw("Strict value is not equal to itself.")
1075865 }
1082872
1083873 @Callable(i)
1084874 func getOneTknREADONLY (outAssetId,paymentAmount) = {
1085- let $t04310543261 = calcGetOneToken(parseAssetId(outAssetId), paymentAmount, cfgLpAssetId, unit, unit)
1086- let amountEstimated = $t04310543261._1
1087- let commonState = $t04310543261._2
1088- let feeAmount = $t04310543261._3
1089- let bonus = $t04310543261._4
1090- let outInAmountAsset = $t04310543261._5
875+ let $t03429234430 = calcGetOneToken(parseAssetId(outAssetId), paymentAmount, cfgLpAssetId, unit, unit)
876+ let amountEstimated = $t03429234430._1
877+ let commonState = $t03429234430._2
878+ let feeAmount = $t03429234430._3
879+ let bonus = $t03429234430._4
1091880 $Tuple2(nil, $Tuple3(amountEstimated, feeAmount, bonus))
1092881 }
1093882
1118907 let outAssetId = parseAssetId(outAssetIdStr)
1119908 let userAddress = i.caller
1120909 let txId = i.transactionId
1121- let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0))
1122- if ((currentKLp == currentKLp))
910+ let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil)
911+ if ((unstakeInv == unstakeInv))
1123912 then {
1124- let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil)
1125- if ((unstakeInv == unstakeInv))
913+ let $t03525535388 = calcGetOneToken(outAssetId, unstakeAmount, cfgLpAssetId, userAddress, txId)
914+ if (($t03525535388 == $t03525535388))
1126915 then {
1127- let $t04416644317 = calcGetOneToken(outAssetId, unstakeAmount, cfgLpAssetId, userAddress, txId)
1128- if (($t04416644317 == $t04416644317))
916+ let bonus = $t03525535388._4
917+ let feeAmount = $t03525535388._3
918+ let commonState = $t03525535388._2
919+ let amountEstimated = $t03525535388._1
920+ let amount = if (if ((minOutAmount > 0))
921+ then (minOutAmount > amountEstimated)
922+ else false)
923+ then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], ""))
924+ else amountEstimated
925+ let burnInv = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)])
926+ if ((burnInv == burnInv))
1129927 then {
1130- let outInAmountAsset = $t04416644317._5
1131- let bonus = $t04416644317._4
1132- let feeAmount = $t04416644317._3
1133- let commonState = $t04416644317._2
1134- let amountEstimated = $t04416644317._1
1135- let amount = if (if ((minOutAmount > 0))
1136- then (minOutAmount > amountEstimated)
1137- else false)
1138- then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], ""))
1139- else amountEstimated
1140- let burnInv = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)])
1141- if ((burnInv == burnInv))
1142- then {
1143- let assetTransfer = [ScriptTransfer(i.caller, amount, outAssetId)]
1144- let sendFee = if ((feeAmount > 0))
1145- then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)]
1146- else nil
1147- let $t04481245059 = {
1148- let feeAmountForCalc = if ((this == feeCollectorAddress))
1149- then 0
1150- else feeAmount
1151- if (outInAmountAsset)
1152- then $Tuple2(-((amount + feeAmountForCalc)), 0)
1153- else $Tuple2(0, -((amount + feeAmountForCalc)))
1154- }
1155- let amountAssetBalanceDelta = $t04481245059._1
1156- let priceAssetBalanceDelta = $t04481245059._2
1157- let $t04506245170 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0)
1158- let refreshKLpActions = $t04506245170._1
1159- let updatedKLp = $t04506245170._2
1160- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
1161- if ((isUpdatedKLpValid == isUpdatedKLpValid))
1162- then $Tuple2((((commonState ++ assetTransfer) ++ sendFee) ++ refreshKLpActions), amount)
1163- else throw("Strict value is not equal to itself.")
1164- }
1165- else throw("Strict value is not equal to itself.")
928+ let assetTransfer = [ScriptTransfer(i.caller, amount, outAssetId)]
929+ let sendFee = if ((feeAmount > 0))
930+ then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)]
931+ else nil
932+ $Tuple2(((commonState ++ assetTransfer) ++ sendFee), amount)
1166933 }
1167934 else throw("Strict value is not equal to itself.")
1168935 }
1183950 let pmtAmt = res._3
1184951 let pmtAssetId = res._4
1185952 let state = res._5
1186- let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0))
1187- if ((currentKLp == currentKLp))
1188- then {
1189- let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)])
1190- if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
1191- then {
1192- let $t04611646198 = refreshKLpInternal(-(outAmtAmt), -(outPrAmt), 0)
1193- let refreshKLpActions = $t04611646198._1
1194- let updatedKLp = $t04611646198._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- }
1200- else throw("Strict value is not equal to itself.")
1201- }
953+ let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)])
954+ if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
955+ then state
1202956 else throw("Strict value is not equal to itself.")
1203957 }
1204958
1217971 else if ((noLessThenPriceAsset > outPrAmt))
1218972 then throw(((("noLessThenPriceAsset failed: " + toString(outPrAmt)) + " < ") + toString(noLessThenPriceAsset)))
1219973 else {
1220- let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0))
1221- if ((currentKLp == currentKLp))
1222- then {
1223- let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)])
1224- if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
1225- then {
1226- let $t04714747228 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0)
1227- let refreshKLpActions = $t04714747228._1
1228- let updatedKLp = $t04714747228._2
1229- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
1230- if ((isUpdatedKLpValid == isUpdatedKLpValid))
1231- then (state ++ refreshKLpActions)
1232- else throw("Strict value is not equal to itself.")
1233- }
1234- else throw("Strict value is not equal to itself.")
1235- }
974+ let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)])
975+ if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
976+ then state
1236977 else throw("Strict value is not equal to itself.")
1237978 }
1238979 }
1248989 then {
1249990 let cfg = getPoolConfig()
1250991 let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId])
1251- let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0))
1252- if ((currentKLp == currentKLp))
992+ let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(lpAssetId), amount], nil)
993+ if ((unstakeInv == unstakeInv))
1253994 then {
1254- let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(lpAssetId), amount], nil)
1255- if ((unstakeInv == unstakeInv))
995+ let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller)
996+ let poolStatus = parseIntValue(res._9)
997+ let state = res._10
998+ let checkPoolStatus = if (if (isGlobalShutdown())
999+ then true
1000+ else (poolStatus == PoolShutdown))
1001+ then throw(("Get operation is blocked by admin. Status = " + toString(poolStatus)))
1002+ else true
1003+ if ((checkPoolStatus == checkPoolStatus))
12561004 then {
1257- let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller)
1258- let outAmAmt = res._1
1259- let outPrAmt = res._2
1260- let poolStatus = parseIntValue(res._9)
1261- let state = res._10
1262- let checkPoolStatus = if (if (isGlobalShutdown())
1263- then true
1264- else (poolStatus == PoolShutdown))
1265- then throw(("Get operation is blocked by admin. Status = " + toString(poolStatus)))
1266- else true
1267- if ((checkPoolStatus == checkPoolStatus))
1268- then {
1269- let burnLPAssetOnFactory = invoke(factoryContract, "burn", [amount], [AttachedPayment(lpAssetId, amount)])
1270- if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
1271- then {
1272- let $t04835448435 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0)
1273- let refreshKLpActions = $t04835448435._1
1274- let updatedKLp = $t04835448435._2
1275- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
1276- if ((isUpdatedKLpValid == isUpdatedKLpValid))
1277- then (state ++ refreshKLpActions)
1278- else throw("Strict value is not equal to itself.")
1279- }
1280- else throw("Strict value is not equal to itself.")
1281- }
1005+ let burnLPAssetOnFactory = invoke(factoryContract, "burn", [amount], [AttachedPayment(lpAssetId, amount)])
1006+ if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
1007+ then state
12821008 else throw("Strict value is not equal to itself.")
12831009 }
12841010 else throw("Strict value is not equal to itself.")
13021028 else throw("no payments are expected")]
13031029 if ((checks == checks))
13041030 then {
1305- let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0))
1306- if ((currentKLp == currentKLp))
1031+ let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil)
1032+ if ((unstakeInv == unstakeInv))
13071033 then {
1308- let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil)
1309- if ((unstakeInv == unstakeInv))
1034+ let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller)
1035+ let outAmAmt = res._1
1036+ let outPrAmt = res._2
1037+ let state = res._10
1038+ let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset))
1039+ then true
1040+ else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset))
1041+ then true
1042+ else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))]
1043+ if ((checkAmounts == checkAmounts))
13101044 then {
1311- let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller)
1312- let outAmAmt = res._1
1313- let outPrAmt = res._2
1314- let state = res._10
1315- let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset))
1316- then true
1317- else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset))
1318- then true
1319- else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))]
1320- if ((checkAmounts == checkAmounts))
1321- then {
1322- let burnLPAssetOnFactory = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)])
1323- if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
1324- then {
1325- let $t04973049811 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0)
1326- let refreshKLpActions = $t04973049811._1
1327- let updatedKLp = $t04973049811._2
1328- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
1329- if ((isUpdatedKLpValid == isUpdatedKLpValid))
1330- then (state ++ refreshKLpActions)
1331- else throw("Strict value is not equal to itself.")
1332- }
1333- else throw("Strict value is not equal to itself.")
1334- }
1045+ let burnLPAssetOnFactory = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)])
1046+ if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
1047+ then state
13351048 else throw("Strict value is not equal to itself.")
13361049 }
13371050 else throw("Strict value is not equal to itself.")
13471060 func activate (amtAssetStr,priceAssetStr) = if ((toString(i.caller) != toString(factoryContract)))
13481061 then throw("permissions denied")
13491062 else $Tuple2([StringEntry(aa(), amtAssetStr), StringEntry(pa(), priceAssetStr)], "success")
1350-
1351-
1352-
1353-@Callable(i)
1354-func refreshKLp () = {
1355- let lastRefreshedBlockHeight = valueOrElse(getInteger(keyKLpRefreshedHeight), 0)
1356- let checkLastRefreshedBlockHeight = if (((height - lastRefreshedBlockHeight) >= kLpRefreshDelay))
1357- then unit
1358- else throwErr(makeString([toString(kLpRefreshDelay), " blocks have not passed since the previous call"], ""))
1359- if ((checkLastRefreshedBlockHeight == checkLastRefreshedBlockHeight))
1360- then {
1361- let kLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyKLp), "0")), fmtErr("invalid kLp"))
1362- let $t05099851062 = refreshKLpInternal(0, 0, 0)
1363- let kLpUpdateActions = $t05099851062._1
1364- let updatedKLp = $t05099851062._2
1365- let actions = if ((kLp != updatedKLp))
1366- then kLpUpdateActions
1367- else throwErr("nothing to refresh")
1368- $Tuple2(actions, toString(updatedKLp))
1369- }
1370- else throw("Strict value is not equal to itself.")
1371- }
13721063
13731064
13741065
15361227 match tx {
15371228 case order: Order =>
15381229 let matcherPub = getMatcherPubOrFail()
1539- let $t05972459793 = validateMatcherOrderAllowed(order)
1540- let orderValid = $t05972459793._1
1541- let orderValidInfo = $t05972459793._2
1230+ let orderValid = validateMatcherOrderAllowed(order)
15421231 let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey)
15431232 let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub)
15441233 if (if (if (orderValid)
15471236 then matcherValid
15481237 else false)
15491238 then true
1550- else throwOrderError(orderValid, orderValidInfo, senderValid, matcherValid)
1239+ else throwOrderError(orderValid, senderValid, matcherValid)
15511240 case s: SetScriptTransaction =>
1552- if (sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey))
1241+ let newHash = blake2b256(value(s.script))
1242+ let allowedHash = fromBase64String(value(getString(factoryContract, keyAllowedLpScriptHash())))
1243+ let currentHash = scriptHash(this)
1244+ if (if ((allowedHash == newHash))
1245+ then (currentHash != newHash)
1246+ else false)
15531247 then true
1554- else {
1555- let newHash = blake2b256(value(s.script))
1556- let allowedHash = fromBase64String(value(getString(factoryContract, keyAllowedLpScriptHash())))
1557- let currentHash = scriptHash(this)
1558- if ((allowedHash == newHash))
1559- then (currentHash != newHash)
1560- else false
1561- }
1248+ else sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
15621249 case _ =>
15631250 sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
15641251 }
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let lPdecimals = 8
55
66 let scale8 = 100000000
77
88 let scale8BigInt = toBigInt(100000000)
99
1010 let scale18 = toBigInt(1000000000000000000)
1111
1212 let zeroBigInt = toBigInt(0)
1313
1414 let big0 = toBigInt(0)
1515
1616 let big1 = toBigInt(1)
1717
1818 let big2 = toBigInt(2)
1919
2020 let wavesString = "WAVES"
2121
2222 let SEP = "__"
2323
2424 let PoolActive = 1
2525
2626 let PoolPutDisabled = 2
2727
2828 let PoolMatcherDisabled = 3
2929
3030 let PoolShutdown = 4
3131
3232 let idxPoolAddress = 1
3333
3434 let idxPoolStatus = 2
3535
3636 let idxPoolLPAssetId = 3
3737
3838 let idxAmtAssetId = 4
3939
4040 let idxPriceAssetId = 5
4141
4242 let idxAmtAssetDcm = 6
4343
4444 let idxPriceAssetDcm = 7
4545
4646 let idxIAmtAssetId = 8
4747
4848 let idxIPriceAssetId = 9
4949
5050 let idxLPAssetDcm = 10
5151
5252 let idxPoolAmtAssetAmt = 1
5353
5454 let idxPoolPriceAssetAmt = 2
5555
5656 let idxPoolLPAssetAmt = 3
5757
5858 let idxFactoryStakingContract = 1
5959
6060 let idxFactorySlippageContract = 7
6161
6262 func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult))
6363
6464
65-func toX18BigInt (origVal,origScaleMult) = fraction(origVal, scale18, origScaleMult)
66-
67-
6865 func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18))
69-
70-
71-func fromX18Round (val,resultScaleMult,round) = toInt(fraction(val, toBigInt(resultScaleMult), scale18, round))
7266
7367
7468 func toScale (amt,resScale,curScale) = fraction(amt, resScale, curScale)
7569
7670
7771 func abs (val) = if ((0 > val))
7872 then -(val)
7973 else val
8074
8175
8276 func absBigInt (val) = if ((zeroBigInt > val))
8377 then -(val)
8478 else val
85-
86-
87-func swapContract () = "%s__swapContract"
8879
8980
9081 func fc () = "%s__factoryContract"
9182
9283
9384 func mpk () = "%s__managerPublicKey"
9485
9586
9687 func pmpk () = "%s__pendingManagerPublicKey"
9788
9889
9990 func pl () = "%s%s__price__last"
10091
10192
10293 func ph (h,timestamp) = makeString(["%s%s%d%d__price__history", toString(h), toString(timestamp)], SEP)
10394
10495
10596 func pau (userAddress,txId) = ((("%s%s%s__P__" + userAddress) + "__") + txId)
10697
10798
10899 func gau (userAddress,txId) = ((("%s%s%s__G__" + userAddress) + "__") + txId)
109100
110101
111102 func aa () = "%s__amountAsset"
112103
113104
114105 func pa () = "%s__priceAsset"
115106
116107
117-let keyFee = "%s__fee"
118-
119-let feeDefault = fraction(10, scale8, 10000)
120-
121-let fee = valueOrElse(getInteger(this, keyFee), feeDefault)
122-
123-let keyKLp = makeString(["%s", "kLp"], SEP)
124-
125-let keyKLpRefreshedHeight = makeString(["%s", "kLpRefreshedHeight"], SEP)
126-
127-let keyKLpRefreshDelay = makeString(["%s", "refreshKLpDelay"], SEP)
128-
129-let kLpRefreshDelayDefault = 30
130-
131-let kLpRefreshDelay = valueOrElse(getInteger(this, keyKLpRefreshDelay), kLpRefreshDelayDefault)
132-
133108 func keyFactoryConfig () = "%s__factoryConfig"
134109
135110
136111 func keyMatcherPub () = "%s%s__matcher__publicKey"
137112
138113
139114 func keyMappingPoolContractAddressToPoolAssets (poolContractAddress) = (("%s%s%s__" + poolContractAddress) + "__mappings__poolContract2LpAsset")
140115
141116
142117 func keyPoolConfig (iAmtAsset,iPriceAsset) = (((("%d%d%s__" + iAmtAsset) + "__") + iPriceAsset) + "__config")
143118
144119
145120 func keyMappingsBaseAsset2internalId (baseAssetStr) = ("%s%s%s__mappings__baseAsset2internalId__" + baseAssetStr)
146121
147122
148123 func keyAllPoolsShutdown () = "%s__shutdown"
149124
150125
151126 func keyPoolWeight (contractAddress) = ("%s%s__poolWeight__" + contractAddress)
152127
153128
154129 func keyAllowedLpScriptHash () = "%s__allowedLpScriptHash"
155130
156131
157132 let keyFeeCollectorAddress = "%s__feeCollectorAddress"
158133
159-func throwOrderError (orderValid,orderValidInfo,senderValid,matcherValid) = throw((((((((("order validation failed: orderValid=" + toString(orderValid)) + " (") + orderValidInfo) + ")") + " senderValid=") + toString(senderValid)) + " matcherValid=") + toString(matcherValid)))
134+func throwOrderError (orderValid,senderValid,matcherValid) = throw(((((("order validation failed: orderValid=" + toString(orderValid)) + " senderValid=") + toString(senderValid)) + " matcherValid=") + toString(matcherValid)))
160135
161136
162137 func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], ""))
163138
164139
165140 func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], ""))
166141
167142
168143 func throwErr (msg) = throw(makeString(["lp.ride:", msg], " "))
169-
170-
171-func fmtErr (msg) = makeString(["lp.ride:", msg], " ")
172144
173145
174146 let factoryContract = addressFromStringValue(getStringOrFail(this, fc()))
175147
176148 let feeCollectorAddress = addressFromStringValue(getStringOrFail(factoryContract, keyFeeCollectorAddress))
177149
178150 let inFee = {
179151 let @ = invoke(factoryContract, "getInFeeREADONLY", [toString(this)], nil)
180152 if ($isInstanceOf(@, "Int"))
181153 then @
182154 else throw(($getType(@) + " couldn't be cast to Int"))
183155 }
184156
185157 let outFee = {
186158 let @ = invoke(factoryContract, "getOutFeeREADONLY", [toString(this)], nil)
187159 if ($isInstanceOf(@, "Int"))
188160 then @
189161 else throw(($getType(@) + " couldn't be cast to Int"))
190162 }
191163
192164 func isGlobalShutdown () = valueOrElse(getBoolean(factoryContract, keyAllPoolsShutdown()), false)
193165
194166
195167 func getMatcherPubOrFail () = fromBase58String(getStringOrFail(factoryContract, keyMatcherPub()))
196168
197169
198170 func getPoolConfig () = {
199171 let amtAsset = getStringOrFail(this, aa())
200172 let priceAsset = getStringOrFail(this, pa())
201173 let iPriceAsset = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(priceAsset))
202174 let iAmtAsset = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(amtAsset))
203175 split(getStringOrFail(factoryContract, keyPoolConfig(toString(iAmtAsset), toString(iPriceAsset))), SEP)
204176 }
205177
206178
207179 func parseAssetId (input) = if ((input == wavesString))
208180 then unit
209181 else fromBase58String(input)
210182
211183
212184 func assetIdToString (input) = if ((input == unit))
213185 then wavesString
214186 else toBase58String(value(input))
215187
216188
217189 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]))
218190
219191
220192 let poolConfigParsed = parsePoolConfig(getPoolConfig())
221193
222-let $t084698635 = poolConfigParsed
194+let $t076017767 = poolConfigParsed
223195
224-let cfgPoolAddress = $t084698635._1
196+let cfgPoolAddress = $t076017767._1
225197
226-let cfgPoolStatus = $t084698635._2
198+let cfgPoolStatus = $t076017767._2
227199
228-let cfgLpAssetId = $t084698635._3
200+let cfgLpAssetId = $t076017767._3
229201
230-let cfgAmountAssetId = $t084698635._4
202+let cfgAmountAssetId = $t076017767._4
231203
232-let cfgPriceAssetId = $t084698635._5
204+let cfgPriceAssetId = $t076017767._5
233205
234-let cfgAmountAssetDecimals = $t084698635._6
206+let cfgAmountAssetDecimals = $t076017767._6
235207
236-let cfgPriceAssetDecimals = $t084698635._7
208+let cfgPriceAssetDecimals = $t076017767._7
237209
238210 func getFactoryConfig () = split(getStringOrFail(factoryContract, keyFactoryConfig()), SEP)
239211
240212
241213 let stakingContract = valueOrErrorMessage(addressFromString(getFactoryConfig()[idxFactoryStakingContract]), "incorrect staking address")
242214
243215 let slippageContract = valueOrErrorMessage(addressFromString(getFactoryConfig()[idxFactorySlippageContract]), "incorrect staking address")
244216
245217 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)
246218
247219
248220 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)
249221
250222
251223 func getAccBalance (assetId) = if ((assetId == "WAVES"))
252224 then wavesBalance(this).available
253225 else assetBalance(this, fromBase58String(assetId))
254226
255227
256228 func calcPriceBigInt (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18)
257-
258-
259-func calcPriceBigIntRound (prAmtX18,amAmtX18,round) = fraction(prAmtX18, scale18, amAmtX18, round)
260229
261230
262231 func privateCalcPrice (amAssetDcm,prAssetDcm,amAmt,prAmt) = {
263232 let amtAssetAmtX18 = toX18(amAmt, amAssetDcm)
264233 let priceAssetAmtX18 = toX18(prAmt, prAssetDcm)
265234 calcPriceBigInt(priceAssetAmtX18, amtAssetAmtX18)
266235 }
267236
268237
269238 func calcPrices (amAmt,prAmt,lpAmt) = {
270239 let cfg = getPoolConfig()
271240 let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm])
272241 let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm])
273242 let priceX18 = privateCalcPrice(amtAssetDcm, priceAssetDcm, amAmt, prAmt)
274243 let amAmtX18 = toX18(amAmt, amtAssetDcm)
275244 let prAmtX18 = toX18(prAmt, priceAssetDcm)
276245 let lpAmtX18 = toX18(lpAmt, scale8)
277246 let lpPriceInAmAssetX18 = calcPriceBigInt(amAmtX18, lpAmtX18)
278247 let lpPriceInPrAssetX18 = calcPriceBigInt(prAmtX18, lpAmtX18)
279248 [priceX18, lpPriceInAmAssetX18, lpPriceInPrAssetX18]
280249 }
281250
282251
283252 func calculatePrices (amAmt,prAmt,lpAmt) = {
284253 let prices = calcPrices(amAmt, prAmt, lpAmt)
285254 [fromX18(prices[0], scale8), fromX18(prices[1], scale8), fromX18(prices[2], scale8)]
286255 }
287256
288257
289258 func estimateGetOperation (txId58,pmtAssetId,pmtLpAmt,userAddress) = {
290259 let cfg = getPoolConfig()
291260 let lpAssetId = cfg[idxPoolLPAssetId]
292261 let amAssetId = cfg[idxAmtAssetId]
293262 let prAssetId = cfg[idxPriceAssetId]
294263 let amAssetDcm = parseIntValue(cfg[idxAmtAssetDcm])
295264 let prAssetDcm = parseIntValue(cfg[idxPriceAssetDcm])
296265 let poolStatus = cfg[idxPoolStatus]
297266 let lpEmission = valueOrErrorMessage(assetInfo(fromBase58String(lpAssetId)), (("Asset " + lpAssetId) + " doesn't exist")).quantity
298267 if ((lpAssetId != pmtAssetId))
299268 then throw("Invalid asset passed.")
300269 else {
301270 let amBalance = getAccBalance(amAssetId)
302271 let amBalanceX18 = toX18(amBalance, amAssetDcm)
303272 let prBalance = getAccBalance(prAssetId)
304273 let prBalanceX18 = toX18(prBalance, prAssetDcm)
305274 let curPriceX18 = calcPriceBigInt(prBalanceX18, amBalanceX18)
306275 let curPrice = fromX18(curPriceX18, scale8)
307276 let pmtLpAmtX18 = toX18(pmtLpAmt, scale8)
308277 let lpEmissionX18 = toX18(lpEmission, scale8)
309278 let outAmAmtX18 = fraction(amBalanceX18, pmtLpAmtX18, lpEmissionX18)
310279 let outPrAmtX18 = fraction(prBalanceX18, pmtLpAmtX18, lpEmissionX18)
311- let outAmAmt = fromX18Round(outAmAmtX18, amAssetDcm, FLOOR)
312- let outPrAmt = fromX18Round(outPrAmtX18, prAssetDcm, FLOOR)
280+ let outAmAmt = fromX18(outAmAmtX18, amAssetDcm)
281+ let outPrAmt = fromX18(outPrAmtX18, prAssetDcm)
313282 let state = if ((txId58 == ""))
314283 then nil
315284 else [ScriptTransfer(userAddress, outAmAmt, if ((amAssetId == "WAVES"))
316285 then unit
317286 else fromBase58String(amAssetId)), ScriptTransfer(userAddress, outPrAmt, if ((prAssetId == "WAVES"))
318287 then unit
319288 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)]
320289 $Tuple10(outAmAmt, outPrAmt, amAssetId, prAssetId, amBalance, prBalance, lpEmission, curPriceX18, poolStatus, state)
321290 }
322291 }
323292
324293
325294 func estimatePutOperation (txId58,slippageTolerance,inAmAssetAmt,inAmAssetId,inPrAssetAmt,inPrAssetId,userAddress,isEvaluate,emitLp) = {
326295 let cfg = getPoolConfig()
327296 let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId])
328297 let amAssetIdStr = cfg[idxAmtAssetId]
329298 let prAssetIdStr = cfg[idxPriceAssetId]
330299 let iAmtAssetId = cfg[idxIAmtAssetId]
331300 let iPriceAssetId = cfg[idxIPriceAssetId]
332301 let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm])
333302 let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm])
334303 let poolStatus = cfg[idxPoolStatus]
335304 let lpEmission = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity
336305 let inAmAssetIdStr = toBase58String(valueOrElse(inAmAssetId, fromBase58String("WAVES")))
337306 let inPrAssetIdStr = toBase58String(valueOrElse(inPrAssetId, fromBase58String("WAVES")))
338307 if (if ((amAssetIdStr != inAmAssetIdStr))
339308 then true
340309 else (prAssetIdStr != inPrAssetIdStr))
341310 then throw("Invalid amt or price asset passed.")
342311 else {
343312 let amBalance = if (isEvaluate)
344313 then getAccBalance(amAssetIdStr)
345314 else (getAccBalance(amAssetIdStr) - inAmAssetAmt)
346315 let prBalance = if (isEvaluate)
347316 then getAccBalance(prAssetIdStr)
348317 else (getAccBalance(prAssetIdStr) - inPrAssetAmt)
349318 let inAmAssetAmtX18 = toX18(inAmAssetAmt, amtAssetDcm)
350319 let inPrAssetAmtX18 = toX18(inPrAssetAmt, priceAssetDcm)
351320 let userPriceX18 = calcPriceBigInt(inPrAssetAmtX18, inAmAssetAmtX18)
352321 let amBalanceX18 = toX18(amBalance, amtAssetDcm)
353322 let prBalanceX18 = toX18(prBalance, priceAssetDcm)
354323 let res = if ((lpEmission == 0))
355324 then {
356325 let curPriceX18 = zeroBigInt
357326 let slippageX18 = zeroBigInt
358327 let lpAmtX18 = pow((inAmAssetAmtX18 * inPrAssetAmtX18), 0, toBigInt(5), 1, 0, DOWN)
359328 $Tuple5(fromX18(lpAmtX18, scale8), fromX18(inAmAssetAmtX18, amtAssetDcm), fromX18(inPrAssetAmtX18, priceAssetDcm), calcPriceBigInt((prBalanceX18 + inPrAssetAmtX18), (amBalanceX18 + inAmAssetAmtX18)), slippageX18)
360329 }
361330 else {
362331 let curPriceX18 = calcPriceBigInt(prBalanceX18, amBalanceX18)
363332 let slippageX18 = fraction(absBigInt((curPriceX18 - userPriceX18)), scale18, curPriceX18)
364333 let slippageToleranceX18 = toX18(slippageTolerance, scale8)
365334 if (if ((curPriceX18 != zeroBigInt))
366335 then (slippageX18 > slippageToleranceX18)
367336 else false)
368337 then throw(((("Price slippage " + toString(slippageX18)) + " exceeded the passed limit of ") + toString(slippageToleranceX18)))
369338 else {
370339 let lpEmissionX18 = toX18(lpEmission, scale8)
371- let prViaAmX18 = fraction(inAmAssetAmtX18, calcPriceBigIntRound(prBalanceX18, amBalanceX18, CEILING), scale18, CEILING)
372- let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, calcPriceBigIntRound(prBalanceX18, amBalanceX18, FLOOR), CEILING)
340+ let prViaAmX18 = fraction(inAmAssetAmtX18, curPriceX18, scale18)
341+ let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, curPriceX18)
373342 let expectedAmts = if ((prViaAmX18 > inPrAssetAmtX18))
374343 then $Tuple2(amViaPrX18, inPrAssetAmtX18)
375344 else $Tuple2(inAmAssetAmtX18, prViaAmX18)
376345 let expAmtAssetAmtX18 = expectedAmts._1
377346 let expPriceAssetAmtX18 = expectedAmts._2
378- let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18, FLOOR)
379- $Tuple5(fromX18Round(lpAmtX18, scale8, FLOOR), fromX18Round(expAmtAssetAmtX18, amtAssetDcm, CEILING), fromX18Round(expPriceAssetAmtX18, priceAssetDcm, CEILING), curPriceX18, slippageX18)
347+ let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18)
348+ $Tuple5(fromX18(lpAmtX18, scale8), fromX18(expAmtAssetAmtX18, amtAssetDcm), fromX18(expPriceAssetAmtX18, priceAssetDcm), curPriceX18, slippageX18)
380349 }
381350 }
382351 let calcLpAmt = res._1
383352 let calcAmAssetPmt = res._2
384353 let calcPrAssetPmt = res._3
385354 let curPrice = fromX18(res._4, scale8)
386355 let slippageCalc = fromX18(res._5, scale8)
387356 if ((0 >= calcLpAmt))
388357 then throw("Invalid calculations. LP calculated is less than zero.")
389358 else {
390359 let emitLpAmt = if (!(emitLp))
391360 then 0
392361 else calcLpAmt
393362 let amDiff = (inAmAssetAmt - calcAmAssetPmt)
394363 let prDiff = (inPrAssetAmt - calcPrAssetPmt)
395364 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))]
396365 $Tuple13(calcLpAmt, emitLpAmt, curPrice, amBalance, prBalance, lpEmission, lpAssetId, poolStatus, commonState, amDiff, prDiff, inAmAssetId, inPrAssetId)
397366 }
398367 }
399368 }
400369
401370
402-func calcKLp (amountBalance,priceBalance,lpEmission) = {
403- let amountBalanceX18 = toX18BigInt(amountBalance, toBigInt(cfgAmountAssetDecimals))
404- let priceBalanceX18 = toX18BigInt(priceBalance, toBigInt(cfgPriceAssetDecimals))
405- let updatedKLp = fraction(pow((amountBalanceX18 * priceBalanceX18), 0, toBigInt(5), 1, 18, DOWN), big1, lpEmission)
406- if ((lpEmission == big0))
407- then big0
408- else updatedKLp
409- }
410-
411-
412-func calcCurrentKLp (amountAssetDelta,priceAssetDelta,lpAssetEmissionDelta) = {
413- let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amountAssetDelta)
414- let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - priceAssetDelta)
415- let lpAssetEmission = (toBigInt(value(assetInfo(cfgLpAssetId)).quantity) - lpAssetEmissionDelta)
416- let currentKLp = calcKLp(amountAssetBalance, priceAssetBalance, lpAssetEmission)
417- currentKLp
418- }
419-
420-
421-func refreshKLpInternal (amountAssetBalanceDelta,priceAssetBalanceDelta,lpAssetEmissionDelta) = {
422- let amountAssetBalance = (getAccBalance(assetIdToString(cfgAmountAssetId)) + amountAssetBalanceDelta)
423- let priceAssetBalance = (getAccBalance(assetIdToString(cfgPriceAssetId)) + priceAssetBalanceDelta)
424- let lpAssetEmission = (value(assetInfo(cfgLpAssetId)).quantity + lpAssetEmissionDelta)
425- let updatedKLp = calcKLp(toBigInt(amountAssetBalance), toBigInt(priceAssetBalance), toBigInt(lpAssetEmission))
426- let actions = [IntegerEntry(keyKLpRefreshedHeight, height), StringEntry(keyKLp, toString(updatedKLp))]
427- $Tuple2(actions, updatedKLp)
428- }
429-
430-
431-func validateUpdatedKLp (oldKLp,updatedKLp) = if ((updatedKLp >= oldKLp))
432- then true
433- else throwErr(makeString(["updated KLp lower than current KLp", toString(oldKLp), toString(updatedKLp)], " "))
434-
435-
436371 func validateMatcherOrderAllowed (order) = {
437- let amountAssetBalance = getAccBalance(assetIdToString(cfgAmountAssetId))
438- let priceAssetBalance = getAccBalance(assetIdToString(cfgPriceAssetId))
439- let amountAssetAmount = order.amount
440- let priceAssetAmount = fraction(order.amount, order.price, scale8, FLOOR)
441- let $t02154121753 = if ((order.orderType == Buy))
442- then $Tuple2(amountAssetAmount, -(priceAssetAmount))
443- else $Tuple2(-(amountAssetAmount), priceAssetAmount)
444- let amountAssetBalanceDelta = $t02154121753._1
445- let priceAssetBalanceDelta = $t02154121753._2
372+ let cfg = getPoolConfig()
373+ let amtAssetId = cfg[idxAmtAssetId]
374+ let priceAssetId = cfg[idxPriceAssetId]
375+ let poolStatus = parseIntValue(cfg[idxPoolStatus])
376+ let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm])
377+ let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm])
378+ let accAmtAssetBalance = getAccBalance(amtAssetId)
379+ let accPriceAssetBalance = getAccBalance(priceAssetId)
380+ let curPriceX18 = if ((order.orderType == Buy))
381+ then privateCalcPrice(amtAssetDcm, priceAssetDcm, (accAmtAssetBalance + order.amount), accPriceAssetBalance)
382+ else privateCalcPrice(amtAssetDcm, priceAssetDcm, (accAmtAssetBalance - order.amount), accPriceAssetBalance)
383+ let curPrice = fromX18(curPriceX18, scale8)
446384 if (if (if (isGlobalShutdown())
447385 then true
448- else (cfgPoolStatus == PoolMatcherDisabled))
386+ else (poolStatus == PoolMatcherDisabled))
449387 then true
450- else (cfgPoolStatus == PoolShutdown))
388+ else (poolStatus == PoolShutdown))
451389 then throw("Exchange operations disabled")
452- else if (if ((order.assetPair.amountAsset != cfgAmountAssetId))
453- then true
454- else (order.assetPair.priceAsset != cfgPriceAssetId))
455- then throw("Wrong order assets.")
456- else {
457- let kLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyKLp), "0")), fmtErr("invalid kLp"))
458- let $t02219322293 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0)
459- let unusedActions = $t02219322293._1
460- let kLpNew = $t02219322293._2
461- let isOrderValid = (kLpNew >= kLp)
462- let info = makeString(["kLp=", toString(kLp), " kLpNew=", toString(kLpNew), " amountAssetBalance=", toString(amountAssetBalance), " priceAssetBalance=", toString(priceAssetBalance), " amountAssetBalanceDelta=", toString(amountAssetBalanceDelta), " priceAssetBalanceDelta=", toString(priceAssetBalanceDelta), " height=", toString(height)], "")
463- $Tuple2(isOrderValid, info)
464- }
390+ else {
391+ let orderAmtAsset = order.assetPair.amountAsset
392+ let orderAmtAssetStr = if ((orderAmtAsset == unit))
393+ then "WAVES"
394+ else toBase58String(value(orderAmtAsset))
395+ let orderPriceAsset = order.assetPair.priceAsset
396+ let orderPriceAssetStr = if ((orderPriceAsset == unit))
397+ then "WAVES"
398+ else toBase58String(value(orderPriceAsset))
399+ if (if ((orderAmtAssetStr != amtAssetId))
400+ then true
401+ else (orderPriceAssetStr != priceAssetId))
402+ then throw("Wrong order assets.")
403+ else {
404+ let orderPrice = order.price
405+ let priceDcm = fraction(scale8, priceAssetDcm, amtAssetDcm)
406+ let castedOrderPrice = toScale(orderPrice, scale8, priceDcm)
407+ let isOrderPriceValid = if ((order.orderType == Buy))
408+ then (curPrice >= castedOrderPrice)
409+ else (castedOrderPrice >= curPrice)
410+ true
411+ }
412+ }
465413 }
466414
467415
468416 func commonGet (i) = if ((size(i.payments) != 1))
469417 then throw("exactly 1 payment is expected")
470418 else {
471419 let pmt = value(i.payments[0])
472420 let pmtAssetId = value(pmt.assetId)
473421 let pmtAmt = pmt.amount
474422 let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(pmtAssetId), pmtAmt, i.caller)
475423 let outAmAmt = res._1
476424 let outPrAmt = res._2
477425 let poolStatus = parseIntValue(res._9)
478426 let state = res._10
479427 if (if (isGlobalShutdown())
480428 then true
481429 else (poolStatus == PoolShutdown))
482430 then throw(("Get operation is blocked by admin. Status = " + toString(poolStatus)))
483431 else $Tuple5(outAmAmt, outPrAmt, pmtAmt, pmtAssetId, state)
484432 }
485433
486434
487435 func commonPut (i,slippageTolerance,emitLp) = if ((size(i.payments) != 2))
488436 then throw("exactly 2 payments are expected")
489437 else {
490438 let amAssetPmt = value(i.payments[0])
491439 let prAssetPmt = value(i.payments[1])
492440 let estPut = estimatePutOperation(toBase58String(i.transactionId), slippageTolerance, amAssetPmt.amount, amAssetPmt.assetId, prAssetPmt.amount, prAssetPmt.assetId, toString(i.caller), false, emitLp)
493441 let poolStatus = parseIntValue(estPut._8)
494442 if (if (if (isGlobalShutdown())
495443 then true
496444 else (poolStatus == PoolPutDisabled))
497445 then true
498446 else (poolStatus == PoolShutdown))
499447 then throw(("Put operation is blocked by admin. Status = " + toString(poolStatus)))
500448 else estPut
501449 }
502450
503451
504452 func emit (amount) = {
505453 let emitInv = invoke(factoryContract, "emit", [amount], nil)
506454 if ((emitInv == emitInv))
507455 then {
508456 let emitInvLegacy = match emitInv {
509457 case legacyFactoryContract: Address =>
510458 invoke(legacyFactoryContract, "emit", [amount], nil)
511459 case _ =>
512460 unit
513461 }
514462 if ((emitInvLegacy == emitInvLegacy))
515463 then amount
516464 else throw("Strict value is not equal to itself.")
517465 }
518466 else throw("Strict value is not equal to itself.")
519467 }
520468
521469
522470 func takeFee (amount,fee) = {
523471 let feeAmount = if ((fee == 0))
524472 then 0
525473 else fraction(amount, fee, scale8)
526474 $Tuple2((amount - feeAmount), feeAmount)
527475 }
528476
529477
530478 func calcPutOneToken (paymentAmountRaw,paymentAssetId,userAddress,txId) = {
531479 let isEval = (txId == unit)
532480 let amountBalanceRaw = getAccBalance(assetIdToString(cfgAmountAssetId))
533481 let priceBalanceRaw = getAccBalance(assetIdToString(cfgPriceAssetId))
534482 let paymentInAmountAsset = if ((paymentAssetId == cfgAmountAssetId))
535483 then true
536484 else if ((paymentAssetId == cfgPriceAssetId))
537485 then false
538486 else throwErr("invalid asset")
539- let $t02540625699 = if (isEval)
487+ let $t02266422957 = if (isEval)
540488 then $Tuple2(amountBalanceRaw, priceBalanceRaw)
541489 else if (paymentInAmountAsset)
542490 then $Tuple2((amountBalanceRaw - paymentAmountRaw), priceBalanceRaw)
543491 else $Tuple2(amountBalanceRaw, (priceBalanceRaw - paymentAmountRaw))
544- let amountBalanceOld = $t02540625699._1
545- let priceBalanceOld = $t02540625699._2
546- let $t02570325852 = if (paymentInAmountAsset)
492+ let amountBalanceOld = $t02266422957._1
493+ let priceBalanceOld = $t02266422957._2
494+ let $t02296123110 = if (paymentInAmountAsset)
547495 then $Tuple2(paymentAmountRaw, 0)
548496 else $Tuple2(0, paymentAmountRaw)
549- let amountAssetAmountRaw = $t02570325852._1
550- let priceAssetAmountRaw = $t02570325852._2
497+ let amountAssetAmountRaw = $t02296123110._1
498+ let priceAssetAmountRaw = $t02296123110._2
551499 let amountAssetAmount = takeFee(amountAssetAmountRaw, inFee)._1
552500 let priceAssetAmount = takeFee(priceAssetAmountRaw, inFee)._1
553- let $t02598426048 = takeFee(paymentAmountRaw, inFee)
554- let paymentAmount = $t02598426048._1
555- let feeAmount = $t02598426048._2
501+ let $t02324223306 = takeFee(paymentAmountRaw, inFee)
502+ let paymentAmount = $t02324223306._1
503+ let feeAmount = $t02324223306._2
556504 let amountBalanceNew = (amountBalanceOld + amountAssetAmount)
557505 let priceBalanceNew = (priceBalanceOld + priceAssetAmount)
558506 let priceNewX18 = calcPriceBigInt(toX18(priceBalanceNew, cfgPriceAssetDecimals), toX18(amountBalanceNew, cfgAmountAssetDecimals))
559507 let priceNew = fromX18(priceNewX18, scale8)
560508 let paymentBalance = if (paymentInAmountAsset)
561509 then amountBalanceOld
562510 else priceBalanceOld
563511 let paymentBalanceBigInt = toBigInt(paymentBalance)
564512 let supplyBigInt = toBigInt(valueOrErrorMessage(assetInfo(cfgLpAssetId), (("asset " + toBase58String(cfgLpAssetId)) + " doesn't exist")).quantity)
565513 let chechSupply = if ((supplyBigInt > big0))
566514 then true
567515 else throwErr("initial deposit requires all coins")
568516 if ((chechSupply == chechSupply))
569517 then {
570518 let depositBigInt = toBigInt(paymentAmount)
571519 let issueAmount = max([0, toInt(((supplyBigInt * (sqrtBigInt((scale18 + ((depositBigInt * scale18) / paymentBalanceBigInt)), 18, 18, DOWN) - scale18)) / scale18))])
572520 let commonState = if (isEval)
573521 then nil
574522 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))]
575523 let priceOldX18 = calcPriceBigInt(toX18(priceBalanceOld, cfgPriceAssetDecimals), toX18(amountBalanceOld, cfgAmountAssetDecimals))
576524 let priceOld = fromX18(priceOldX18, scale8)
577525 let loss = {
578- let $t02772927896 = if (paymentInAmountAsset)
526+ let $t02478324950 = if (paymentInAmountAsset)
579527 then $Tuple2(amountAssetAmountRaw, amountBalanceOld)
580528 else $Tuple2(priceAssetAmountRaw, priceBalanceOld)
581- let amount = $t02772927896._1
582- let balance = $t02772927896._2
529+ let amount = $t02478324950._1
530+ let balance = $t02478324950._2
583531 let issueAmountBoth = toInt(fraction(supplyBigInt, toBigInt((amount / 2)), toBigInt(balance)))
584532 fraction((issueAmount - issueAmountBoth), scale8, issueAmountBoth)
585533 }
586- $Tuple5(issueAmount, commonState, feeAmount, loss, paymentInAmountAsset)
534+ $Tuple4(issueAmount, commonState, feeAmount, loss)
587535 }
588536 else throw("Strict value is not equal to itself.")
589537 }
590538
591539
592540 func calcGetOneToken (outAssetId,paymentAmount,paymentAssetId,userAddress,txId) = {
593541 let isEval = (txId == unit)
594- let cfg = getPoolConfig()
595- let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm])
596- let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm])
597542 let checks = [if ((paymentAssetId == cfgLpAssetId))
598543 then true
599544 else throwErr("invalid lp asset")]
600545 if ((checks == checks))
601546 then {
602547 let outInAmountAsset = if ((outAssetId == cfgAmountAssetId))
603548 then true
604549 else if ((outAssetId == cfgPriceAssetId))
605550 then false
606551 else throwErr("invalid asset")
607552 let balanceBigInt = if (outInAmountAsset)
608553 then toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId)))
609554 else toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId)))
610- let outInAmountAssetDecimals = if (outInAmountAsset)
611- then amtAssetDcm
612- else priceAssetDcm
613555 let amBalanceOld = getAccBalance(assetIdToString(cfgAmountAssetId))
614556 let prBalanceOld = getAccBalance(assetIdToString(cfgPriceAssetId))
615557 let outBalance = if (outInAmountAsset)
616558 then amBalanceOld
617559 else prBalanceOld
618560 let outBalanceBigInt = toBigInt(outBalance)
619561 let supplyBigInt = toBigInt(valueOrErrorMessage(assetInfo(cfgLpAssetId), (("asset " + toBase58String(cfgLpAssetId)) + " doesn't exist")).quantity)
620562 let redeemedBigInt = toBigInt(paymentAmount)
621563 let amountRaw = max([0, toInt(((balanceBigInt * (scale18 - pow((scale18 - ((redeemedBigInt * scale18) / supplyBigInt)), 18, big2, 0, 18, DOWN))) / scale18))])
622- let $t02997430030 = takeFee(amountRaw, outFee)
623- let totalAmount = $t02997430030._1
624- let feeAmount = $t02997430030._2
625- let $t03003430260 = if (outInAmountAsset)
564+ let $t02653026586 = takeFee(amountRaw, outFee)
565+ let totalAmount = $t02653026586._1
566+ let feeAmount = $t02653026586._2
567+ let $t02659026816 = if (outInAmountAsset)
626568 then $Tuple4(totalAmount, 0, (amBalanceOld - amountRaw), prBalanceOld)
627569 else $Tuple4(0, totalAmount, amBalanceOld, (prBalanceOld - amountRaw))
628- let outAmAmount = $t03003430260._1
629- let outPrAmount = $t03003430260._2
630- let amBalanceNew = $t03003430260._3
631- let prBalanceNew = $t03003430260._4
570+ let outAmAmount = $t02659026816._1
571+ let outPrAmount = $t02659026816._2
572+ let amBalanceNew = $t02659026816._3
573+ let prBalanceNew = $t02659026816._4
632574 let priceNewX18 = calcPriceBigInt(toX18(prBalanceNew, cfgPriceAssetDecimals), toX18(amBalanceNew, cfgAmountAssetDecimals))
633575 let priceNew = fromX18(priceNewX18, scale8)
634576 let commonState = if (isEval)
635577 then nil
636578 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)]
637579 let priceOldX18 = calcPriceBigInt(toX18(prBalanceOld, cfgPriceAssetDecimals), toX18(amBalanceOld, cfgAmountAssetDecimals))
638580 let priceOld = fromX18(priceOldX18, scale8)
639581 let loss = {
640582 let amountBothInPaymentAsset = (toInt(fraction(balanceBigInt, redeemedBigInt, supplyBigInt)) * 2)
641583 fraction((totalAmount - amountBothInPaymentAsset), scale8, amountBothInPaymentAsset)
642584 }
643- $Tuple5(totalAmount, commonState, feeAmount, loss, outInAmountAsset)
585+ $Tuple4(totalAmount, commonState, feeAmount, loss)
644586 }
645587 else throw("Strict value is not equal to itself.")
646588 }
647589
648590
649591 func managerPublicKeyOrUnit () = match getString(mpk()) {
650592 case s: String =>
651593 fromBase58String(s)
652594 case _: Unit =>
653595 unit
654596 case _ =>
655597 throw("Match error")
656598 }
657599
658600
659601 func pendingManagerPublicKeyOrUnit () = match getString(pmpk()) {
660602 case s: String =>
661603 fromBase58String(s)
662604 case _: Unit =>
663605 unit
664606 case _ =>
665607 throw("Match error")
666608 }
667609
668610
669611 func isManager (i) = match managerPublicKeyOrUnit() {
670612 case pk: ByteVector =>
671613 (i.callerPublicKey == pk)
672614 case _: Unit =>
673615 (i.caller == this)
674616 case _ =>
675617 throw("Match error")
676618 }
677619
678620
679621 func mustManager (i) = {
680622 let pd = throw("Permission denied")
681623 match managerPublicKeyOrUnit() {
682624 case pk: ByteVector =>
683625 if ((i.callerPublicKey == pk))
684626 then true
685627 else pd
686628 case _: Unit =>
687629 if ((i.caller == this))
688630 then true
689631 else pd
690632 case _ =>
691633 throw("Match error")
692634 }
693635 }
694636
695637
696638 @Callable(i)
697-func calculateAmountOutForSwapREADONLY (cleanAmountIn,isReverse,feePoolAmount) = {
698- let $t03197732282 = if ((isReverse == false))
699- then {
700- let assetOut = getStringOrFail(this, pa())
701- let assetIn = getStringOrFail(this, aa())
702- $Tuple2(assetOut, assetIn)
703- }
704- else {
705- let assetOut = getStringOrFail(this, aa())
706- let assetIn = getStringOrFail(this, pa())
707- $Tuple2(assetOut, assetIn)
708- }
709- let assetOut = $t03197732282._1
710- let assetIn = $t03197732282._2
711- let poolAssetInBalance = getAccBalance(assetIn)
712- let poolAssetOutBalance = getAccBalance(assetOut)
713- let amountOut = fraction(poolAssetOutBalance, cleanAmountIn, (poolAssetInBalance + cleanAmountIn))
714- let oldK = (toBigInt(poolAssetInBalance) * toBigInt(poolAssetOutBalance))
715- let newK = (((toBigInt(getAccBalance(assetIn)) + toBigInt(cleanAmountIn)) + toBigInt(feePoolAmount)) * (toBigInt(getAccBalance(assetOut)) - toBigInt(amountOut)))
716- let checkK = if ((newK >= oldK))
717- then true
718- else throw("new K is fewer error")
719- if ((checkK == checkK))
720- then $Tuple2(nil, amountOut)
721- else throw("Strict value is not equal to itself.")
722- }
723-
724-
725-
726-@Callable(i)
727-func calculateAmountOutForSwapAndSendTokens (cleanAmountIn,isReverse,amountOutMin,addressTo,feePoolAmount) = {
728- let swapContact = {
729- let @ = invoke(factoryContract, "getSwapContractREADONLY", nil, nil)
730- if ($isInstanceOf(@, "String"))
731- then @
732- else throw(($getType(@) + " couldn't be cast to String"))
733- }
734- let checks = [if ((value(i.payments[0]).amount >= cleanAmountIn))
735- then true
736- else throwErr("Wrong amount"), if ((i.caller == addressFromStringValue(swapContact)))
737- then true
738- else throwErr("Permission denied")]
739- if ((checks == checks))
740- then {
741- let pmt = value(i.payments[0])
742- let assetIn = assetIdToString(pmt.assetId)
743- let assetOut = if ((isReverse == false))
744- then getStringOrFail(this, pa())
745- else getStringOrFail(this, aa())
746- let poolAssetInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount)
747- let poolAssetOutBalance = getAccBalance(assetOut)
748- let amountOut = fraction(poolAssetOutBalance, cleanAmountIn, (poolAssetInBalance + cleanAmountIn))
749- let oldK = (toBigInt(poolAssetInBalance) * toBigInt(poolAssetOutBalance))
750- let newK = ((toBigInt(getAccBalance(assetIn)) + toBigInt(feePoolAmount)) * (toBigInt(getAccBalance(assetOut)) - toBigInt(amountOut)))
751- let checkK = if ((newK >= oldK))
752- then true
753- else throw("new K is fewer error")
754- if ((checkK == checkK))
755- then {
756- let checkMin = if ((amountOut >= amountOutMin))
757- then true
758- else throw("Exchange result is fewer coins than expected")
759- if ((checkMin == checkMin))
760- then $Tuple2([ScriptTransfer(addressFromStringValue(addressTo), amountOut, parseAssetId(assetOut))], amountOut)
761- else throw("Strict value is not equal to itself.")
762- }
763- else throw("Strict value is not equal to itself.")
764- }
765- else throw("Strict value is not equal to itself.")
766- }
767-
768-
769-
770-@Callable(i)
771639 func setManager (pendingManagerPublicKey) = {
772640 let checkCaller = mustManager(i)
773641 if ((checkCaller == checkCaller))
774642 then {
775643 let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey)
776644 if ((checkManagerPublicKey == checkManagerPublicKey))
777645 then [StringEntry(pmpk(), pendingManagerPublicKey)]
778646 else throw("Strict value is not equal to itself.")
779647 }
780648 else throw("Strict value is not equal to itself.")
781649 }
782650
783651
784652
785653 @Callable(i)
786654 func confirmManager () = {
787655 let pm = pendingManagerPublicKeyOrUnit()
788656 let hasPM = if (isDefined(pm))
789657 then true
790658 else throw("No pending manager")
791659 if ((hasPM == hasPM))
792660 then {
793661 let checkPM = if ((i.callerPublicKey == value(pm)))
794662 then true
795663 else throw("You are not pending manager")
796664 if ((checkPM == checkPM))
797665 then [StringEntry(mpk(), toBase58String(value(pm))), DeleteEntry(pmpk())]
798666 else throw("Strict value is not equal to itself.")
799667 }
800668 else throw("Strict value is not equal to itself.")
801669 }
802670
803671
804672
805673 @Callable(i)
806674 func put (slippageTolerance,shouldAutoStake) = if ((0 > slippageTolerance))
807675 then throw("Invalid slippageTolerance passed")
808676 else {
809677 let estPut = commonPut(i, slippageTolerance, true)
810678 let emitLpAmt = estPut._2
811679 let lpAssetId = estPut._7
812680 let state = estPut._9
813681 let amDiff = estPut._10
814682 let prDiff = estPut._11
815683 let amId = estPut._12
816684 let prId = estPut._13
817- let amAssetPmt = toBigInt(value(i.payments[0]).amount)
818- let prAssetPmt = toBigInt(value(i.payments[1]).amount)
819- let currentKLp = calcCurrentKLp(amAssetPmt, prAssetPmt, toBigInt(0))
820- if ((currentKLp == currentKLp))
685+ let emitInv = invoke(factoryContract, "emit", [emitLpAmt], nil)
686+ if ((emitInv == emitInv))
821687 then {
822- let emitInv = invoke(factoryContract, "emit", [emitLpAmt], nil)
823- if ((emitInv == emitInv))
688+ let emitInvLegacy = match emitInv {
689+ case legacyFactoryContract: Address =>
690+ invoke(legacyFactoryContract, "emit", [emitLpAmt], nil)
691+ case _ =>
692+ unit
693+ }
694+ if ((emitInvLegacy == emitInvLegacy))
824695 then {
825- let emitInvLegacy = match emitInv {
826- case legacyFactoryContract: Address =>
827- invoke(legacyFactoryContract, "emit", [emitLpAmt], nil)
828- case _ =>
829- unit
830- }
831- if ((emitInvLegacy == emitInvLegacy))
696+ let slippageAInv = if ((amDiff > 0))
697+ then invoke(slippageContract, "put", nil, [AttachedPayment(amId, amDiff)])
698+ else nil
699+ if ((slippageAInv == slippageAInv))
832700 then {
833- let slippageAInv = if ((amDiff > 0))
834- then invoke(slippageContract, "put", nil, [AttachedPayment(amId, amDiff)])
701+ let slippagePInv = if ((prDiff > 0))
702+ then invoke(slippageContract, "put", nil, [AttachedPayment(prId, prDiff)])
835703 else nil
836- if ((slippageAInv == slippageAInv))
704+ if ((slippagePInv == slippagePInv))
837705 then {
838- let slippagePInv = if ((prDiff > 0))
839- then invoke(slippageContract, "put", nil, [AttachedPayment(prId, prDiff)])
840- else nil
841- if ((slippagePInv == slippagePInv))
706+ let lpTransfer = if (shouldAutoStake)
842707 then {
843- let lpTransfer = if (shouldAutoStake)
844- then {
845- let slpStakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)])
846- if ((slpStakeInv == slpStakeInv))
847- then nil
848- else throw("Strict value is not equal to itself.")
849- }
850- else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)]
851- let $t03716637628 = refreshKLpInternal(0, 0, 0)
852- if (($t03716637628 == $t03716637628))
853- then {
854- let updatedKLp = $t03716637628._2
855- let refreshKLpActions = $t03716637628._1
856- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
857- if ((isUpdatedKLpValid == isUpdatedKLpValid))
858- then ((state ++ lpTransfer) ++ refreshKLpActions)
859- else throw("Strict value is not equal to itself.")
860- }
708+ let slpStakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)])
709+ if ((slpStakeInv == slpStakeInv))
710+ then nil
861711 else throw("Strict value is not equal to itself.")
862712 }
863- else throw("Strict value is not equal to itself.")
713+ else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)]
714+ (state ++ lpTransfer)
864715 }
865716 else throw("Strict value is not equal to itself.")
866717 }
867718 else throw("Strict value is not equal to itself.")
868719 }
869720 else throw("Strict value is not equal to itself.")
870721 }
871722 else throw("Strict value is not equal to itself.")
872723 }
873724
874725
875726
876727 @Callable(i)
877728 func putForFree (maxSlippage) = if ((0 > maxSlippage))
878729 then throw("Invalid value passed")
879730 else {
880731 let estPut = commonPut(i, maxSlippage, false)
881- let state = estPut._9
882- let amAssetPmt = toBigInt(value(i.payments[0]).amount)
883- let prAssetPmt = toBigInt(value(i.payments[1]).amount)
884- let currentKLp = calcCurrentKLp(amAssetPmt, prAssetPmt, toBigInt(0))
885- if ((currentKLp == currentKLp))
886- then {
887- let $t03819038255 = refreshKLpInternal(0, 0, 0)
888- let refreshKLpActions = $t03819038255._1
889- let updatedKLp = $t03819038255._2
890- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
891- if ((isUpdatedKLpValid == isUpdatedKLpValid))
892- then (state ++ refreshKLpActions)
893- else throw("Strict value is not equal to itself.")
894- }
895- else throw("Strict value is not equal to itself.")
732+ estPut._9
896733 }
897734
898735
899736
900737 @Callable(i)
901738 func putOneTkn (minOutAmount,autoStake) = {
902739 let isPoolOneTokenOperationsDisabled = {
903740 let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil)
904741 if ($isInstanceOf(@, "Boolean"))
905742 then @
906743 else throw(($getType(@) + " couldn't be cast to Boolean"))
907744 }
908745 let isPutDisabled = if (if (if (isGlobalShutdown())
909746 then true
910747 else (cfgPoolStatus == PoolPutDisabled))
911748 then true
912749 else (cfgPoolStatus == PoolShutdown))
913750 then true
914751 else isPoolOneTokenOperationsDisabled
915752 let checks = [if (if (!(isPutDisabled))
916753 then true
917754 else isManager(i))
918755 then true
919756 else throwErr("put operation is blocked by admin"), if ((size(i.payments) == 1))
920757 then true
921758 else throwErr("exactly 1 payment are expected")]
922759 if ((checks == checks))
923760 then {
924761 let payment = i.payments[0]
925762 let paymentAssetId = payment.assetId
926763 let paymentAmountRaw = payment.amount
927- let currentKLp = if ((paymentAssetId == cfgAmountAssetId))
928- then calcCurrentKLp(toBigInt(paymentAmountRaw), toBigInt(0), toBigInt(0))
929- else if ((paymentAssetId == cfgPriceAssetId))
930- then calcCurrentKLp(toBigInt(0), toBigInt(paymentAmountRaw), toBigInt(0))
931- else throwErr("payment asset is not supported")
932- if ((currentKLp == currentKLp))
764+ let userAddress = i.caller
765+ let txId = i.transactionId
766+ let $t03172331853 = calcPutOneToken(paymentAmountRaw, paymentAssetId, userAddress, txId)
767+ if (($t03172331853 == $t03172331853))
933768 then {
934- let userAddress = i.caller
935- let txId = i.transactionId
936- let $t03944339595 = calcPutOneToken(paymentAmountRaw, paymentAssetId, userAddress, txId)
937- if (($t03944339595 == $t03944339595))
769+ let bonus = $t03172331853._4
770+ let feeAmount = $t03172331853._3
771+ let commonState = $t03172331853._2
772+ let emitAmountEstimated = $t03172331853._1
773+ let emitAmount = if (if ((minOutAmount > 0))
774+ then (minOutAmount > emitAmountEstimated)
775+ else false)
776+ then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], ""))
777+ else emitAmountEstimated
778+ let emitInv = emit(emitAmount)
779+ if ((emitInv == emitInv))
938780 then {
939- let paymentInAmountAsset = $t03944339595._5
940- let bonus = $t03944339595._4
941- let feeAmount = $t03944339595._3
942- let commonState = $t03944339595._2
943- let emitAmountEstimated = $t03944339595._1
944- let emitAmount = if (if ((minOutAmount > 0))
945- then (minOutAmount > emitAmountEstimated)
946- else false)
947- then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], ""))
948- else emitAmountEstimated
949- let emitInv = emit(emitAmount)
950- if ((emitInv == emitInv))
781+ let lpTransfer = if (autoStake)
951782 then {
952- let lpTransfer = if (autoStake)
953- then {
954- let stakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(cfgLpAssetId, emitAmount)])
955- if ((stakeInv == stakeInv))
956- then nil
957- else throw("Strict value is not equal to itself.")
958- }
959- else [ScriptTransfer(i.caller, emitAmount, cfgLpAssetId)]
960- let sendFee = if ((feeAmount > 0))
961- then [ScriptTransfer(feeCollectorAddress, feeAmount, paymentAssetId)]
962- else nil
963- let $t04018140378 = if ((this == feeCollectorAddress))
964- then $Tuple2(0, 0)
965- else if (paymentInAmountAsset)
966- then $Tuple2(-(feeAmount), 0)
967- else $Tuple2(0, -(feeAmount))
968- let amountAssetBalanceDelta = $t04018140378._1
969- let priceAssetBalanceDelta = $t04018140378._2
970- let $t04038140489 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0)
971- let refreshKLpActions = $t04038140489._1
972- let updatedKLp = $t04038140489._2
973- let kLp = value(getString(keyKLp))
974- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
975- if ((isUpdatedKLpValid == isUpdatedKLpValid))
976- then $Tuple2((((commonState ++ lpTransfer) ++ sendFee) ++ refreshKLpActions), emitAmount)
783+ let stakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(cfgLpAssetId, emitAmount)])
784+ if ((stakeInv == stakeInv))
785+ then nil
977786 else throw("Strict value is not equal to itself.")
978787 }
979- else throw("Strict value is not equal to itself.")
788+ else [ScriptTransfer(i.caller, emitAmount, cfgLpAssetId)]
789+ let sendFee = if ((feeAmount > 0))
790+ then [ScriptTransfer(feeCollectorAddress, feeAmount, paymentAssetId)]
791+ else nil
792+ $Tuple2(((commonState ++ lpTransfer) ++ sendFee), emitAmount)
980793 }
981794 else throw("Strict value is not equal to itself.")
982795 }
983796 else throw("Strict value is not equal to itself.")
984797 }
985798 else throw("Strict value is not equal to itself.")
986799 }
987800
988801
989802
990803 @Callable(i)
991804 func putOneTknREADONLY (paymentAssetId,paymentAmountRaw) = {
992- let $t04079540952 = calcPutOneToken(paymentAmountRaw, parseAssetId(paymentAssetId), unit, unit)
993- let emitAmountEstimated = $t04079540952._1
994- let commonState = $t04079540952._2
995- let feeAmount = $t04079540952._3
996- let bonus = $t04079540952._4
997- let paymentInAmountAsset = $t04079540952._5
805+ let $t03258232717 = calcPutOneToken(paymentAmountRaw, parseAssetId(paymentAssetId), unit, unit)
806+ let emitAmountEstimated = $t03258232717._1
807+ let commonState = $t03258232717._2
808+ let feeAmount = $t03258232717._3
809+ let bonus = $t03258232717._4
998810 $Tuple2(nil, $Tuple3(emitAmountEstimated, feeAmount, bonus))
999811 }
1000812
1001813
1002814
1003815 @Callable(i)
1004816 func getOneTkn (outAssetIdStr,minOutAmount) = {
1005817 let isPoolOneTokenOperationsDisabled = {
1006818 let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil)
1007819 if ($isInstanceOf(@, "Boolean"))
1008820 then @
1009821 else throw(($getType(@) + " couldn't be cast to Boolean"))
1010822 }
1011823 let isGetDisabled = if (if (isGlobalShutdown())
1012824 then true
1013825 else (cfgPoolStatus == PoolShutdown))
1014826 then true
1015827 else isPoolOneTokenOperationsDisabled
1016828 let checks = [if (if (!(isGetDisabled))
1017829 then true
1018830 else isManager(i))
1019831 then true
1020832 else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 1))
1021833 then true
1022834 else throwErr("exactly 1 payment are expected")]
1023835 if ((checks == checks))
1024836 then {
1025837 let outAssetId = parseAssetId(outAssetIdStr)
1026838 let payment = i.payments[0]
1027839 let paymentAssetId = payment.assetId
1028840 let paymentAmount = payment.amount
1029- let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0))
1030- if ((currentKLp == currentKLp))
841+ let userAddress = i.caller
842+ let txId = i.transactionId
843+ let $t03352233657 = calcGetOneToken(outAssetId, paymentAmount, paymentAssetId, userAddress, txId)
844+ if (($t03352233657 == $t03352233657))
1031845 then {
1032- let userAddress = i.caller
1033- let txId = i.transactionId
1034- let $t04183741990 = calcGetOneToken(outAssetId, paymentAmount, paymentAssetId, userAddress, txId)
1035- if (($t04183741990 == $t04183741990))
846+ let bonus = $t03352233657._4
847+ let feeAmount = $t03352233657._3
848+ let commonState = $t03352233657._2
849+ let amountEstimated = $t03352233657._1
850+ let amount = if (if ((minOutAmount > 0))
851+ then (minOutAmount > amountEstimated)
852+ else false)
853+ then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], ""))
854+ else amountEstimated
855+ let burnInv = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)])
856+ if ((burnInv == burnInv))
1036857 then {
1037- let outInAmountAsset = $t04183741990._5
1038- let bonus = $t04183741990._4
1039- let feeAmount = $t04183741990._3
1040- let commonState = $t04183741990._2
1041- let amountEstimated = $t04183741990._1
1042- let amount = if (if ((minOutAmount > 0))
1043- then (minOutAmount > amountEstimated)
1044- else false)
1045- then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], ""))
1046- else amountEstimated
1047- let burnInv = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)])
1048- if ((burnInv == burnInv))
1049- then {
1050- let assetTransfer = [ScriptTransfer(userAddress, amount, outAssetId)]
1051- let sendFee = if ((feeAmount > 0))
1052- then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)]
1053- else nil
1054- let $t04249042737 = {
1055- let feeAmountForCalc = if ((this == feeCollectorAddress))
1056- then 0
1057- else feeAmount
1058- if (outInAmountAsset)
1059- then $Tuple2(-((amount + feeAmountForCalc)), 0)
1060- else $Tuple2(0, -((amount + feeAmountForCalc)))
1061- }
1062- let amountAssetBalanceDelta = $t04249042737._1
1063- let priceAssetBalanceDelta = $t04249042737._2
1064- let $t04274042848 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0)
1065- let refreshKLpActions = $t04274042848._1
1066- let updatedKLp = $t04274042848._2
1067- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
1068- if ((isUpdatedKLpValid == isUpdatedKLpValid))
1069- then $Tuple2((((commonState ++ assetTransfer) ++ sendFee) ++ refreshKLpActions), amount)
1070- else throw("Strict value is not equal to itself.")
1071- }
1072- else throw("Strict value is not equal to itself.")
858+ let assetTransfer = [ScriptTransfer(userAddress, amount, outAssetId)]
859+ let sendFee = if ((feeAmount > 0))
860+ then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)]
861+ else nil
862+ $Tuple2(((commonState ++ assetTransfer) ++ sendFee), amount)
1073863 }
1074864 else throw("Strict value is not equal to itself.")
1075865 }
1076866 else throw("Strict value is not equal to itself.")
1077867 }
1078868 else throw("Strict value is not equal to itself.")
1079869 }
1080870
1081871
1082872
1083873 @Callable(i)
1084874 func getOneTknREADONLY (outAssetId,paymentAmount) = {
1085- let $t04310543261 = calcGetOneToken(parseAssetId(outAssetId), paymentAmount, cfgLpAssetId, unit, unit)
1086- let amountEstimated = $t04310543261._1
1087- let commonState = $t04310543261._2
1088- let feeAmount = $t04310543261._3
1089- let bonus = $t04310543261._4
1090- let outInAmountAsset = $t04310543261._5
875+ let $t03429234430 = calcGetOneToken(parseAssetId(outAssetId), paymentAmount, cfgLpAssetId, unit, unit)
876+ let amountEstimated = $t03429234430._1
877+ let commonState = $t03429234430._2
878+ let feeAmount = $t03429234430._3
879+ let bonus = $t03429234430._4
1091880 $Tuple2(nil, $Tuple3(amountEstimated, feeAmount, bonus))
1092881 }
1093882
1094883
1095884
1096885 @Callable(i)
1097886 func unstakeAndGetOneTkn (unstakeAmount,outAssetIdStr,minOutAmount) = {
1098887 let isPoolOneTokenOperationsDisabled = {
1099888 let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil)
1100889 if ($isInstanceOf(@, "Boolean"))
1101890 then @
1102891 else throw(($getType(@) + " couldn't be cast to Boolean"))
1103892 }
1104893 let isGetDisabled = if (if (isGlobalShutdown())
1105894 then true
1106895 else (cfgPoolStatus == PoolShutdown))
1107896 then true
1108897 else isPoolOneTokenOperationsDisabled
1109898 let checks = [if (if (!(isGetDisabled))
1110899 then true
1111900 else isManager(i))
1112901 then true
1113902 else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 0))
1114903 then true
1115904 else throwErr("no payments are expected")]
1116905 if ((checks == checks))
1117906 then {
1118907 let outAssetId = parseAssetId(outAssetIdStr)
1119908 let userAddress = i.caller
1120909 let txId = i.transactionId
1121- let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0))
1122- if ((currentKLp == currentKLp))
910+ let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil)
911+ if ((unstakeInv == unstakeInv))
1123912 then {
1124- let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil)
1125- if ((unstakeInv == unstakeInv))
913+ let $t03525535388 = calcGetOneToken(outAssetId, unstakeAmount, cfgLpAssetId, userAddress, txId)
914+ if (($t03525535388 == $t03525535388))
1126915 then {
1127- let $t04416644317 = calcGetOneToken(outAssetId, unstakeAmount, cfgLpAssetId, userAddress, txId)
1128- if (($t04416644317 == $t04416644317))
916+ let bonus = $t03525535388._4
917+ let feeAmount = $t03525535388._3
918+ let commonState = $t03525535388._2
919+ let amountEstimated = $t03525535388._1
920+ let amount = if (if ((minOutAmount > 0))
921+ then (minOutAmount > amountEstimated)
922+ else false)
923+ then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], ""))
924+ else amountEstimated
925+ let burnInv = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)])
926+ if ((burnInv == burnInv))
1129927 then {
1130- let outInAmountAsset = $t04416644317._5
1131- let bonus = $t04416644317._4
1132- let feeAmount = $t04416644317._3
1133- let commonState = $t04416644317._2
1134- let amountEstimated = $t04416644317._1
1135- let amount = if (if ((minOutAmount > 0))
1136- then (minOutAmount > amountEstimated)
1137- else false)
1138- then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], ""))
1139- else amountEstimated
1140- let burnInv = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)])
1141- if ((burnInv == burnInv))
1142- then {
1143- let assetTransfer = [ScriptTransfer(i.caller, amount, outAssetId)]
1144- let sendFee = if ((feeAmount > 0))
1145- then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)]
1146- else nil
1147- let $t04481245059 = {
1148- let feeAmountForCalc = if ((this == feeCollectorAddress))
1149- then 0
1150- else feeAmount
1151- if (outInAmountAsset)
1152- then $Tuple2(-((amount + feeAmountForCalc)), 0)
1153- else $Tuple2(0, -((amount + feeAmountForCalc)))
1154- }
1155- let amountAssetBalanceDelta = $t04481245059._1
1156- let priceAssetBalanceDelta = $t04481245059._2
1157- let $t04506245170 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0)
1158- let refreshKLpActions = $t04506245170._1
1159- let updatedKLp = $t04506245170._2
1160- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
1161- if ((isUpdatedKLpValid == isUpdatedKLpValid))
1162- then $Tuple2((((commonState ++ assetTransfer) ++ sendFee) ++ refreshKLpActions), amount)
1163- else throw("Strict value is not equal to itself.")
1164- }
1165- else throw("Strict value is not equal to itself.")
928+ let assetTransfer = [ScriptTransfer(i.caller, amount, outAssetId)]
929+ let sendFee = if ((feeAmount > 0))
930+ then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)]
931+ else nil
932+ $Tuple2(((commonState ++ assetTransfer) ++ sendFee), amount)
1166933 }
1167934 else throw("Strict value is not equal to itself.")
1168935 }
1169936 else throw("Strict value is not equal to itself.")
1170937 }
1171938 else throw("Strict value is not equal to itself.")
1172939 }
1173940 else throw("Strict value is not equal to itself.")
1174941 }
1175942
1176943
1177944
1178945 @Callable(i)
1179946 func get () = {
1180947 let res = commonGet(i)
1181948 let outAmtAmt = res._1
1182949 let outPrAmt = res._2
1183950 let pmtAmt = res._3
1184951 let pmtAssetId = res._4
1185952 let state = res._5
1186- let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0))
1187- if ((currentKLp == currentKLp))
1188- then {
1189- let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)])
1190- if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
1191- then {
1192- let $t04611646198 = refreshKLpInternal(-(outAmtAmt), -(outPrAmt), 0)
1193- let refreshKLpActions = $t04611646198._1
1194- let updatedKLp = $t04611646198._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- }
1200- else throw("Strict value is not equal to itself.")
1201- }
953+ let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)])
954+ if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
955+ then state
1202956 else throw("Strict value is not equal to itself.")
1203957 }
1204958
1205959
1206960
1207961 @Callable(i)
1208962 func getNoLess (noLessThenAmtAsset,noLessThenPriceAsset) = {
1209963 let res = commonGet(i)
1210964 let outAmAmt = res._1
1211965 let outPrAmt = res._2
1212966 let pmtAmt = res._3
1213967 let pmtAssetId = res._4
1214968 let state = res._5
1215969 if ((noLessThenAmtAsset > outAmAmt))
1216970 then throw(((("noLessThenAmtAsset failed: " + toString(outAmAmt)) + " < ") + toString(noLessThenAmtAsset)))
1217971 else if ((noLessThenPriceAsset > outPrAmt))
1218972 then throw(((("noLessThenPriceAsset failed: " + toString(outPrAmt)) + " < ") + toString(noLessThenPriceAsset)))
1219973 else {
1220- let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0))
1221- if ((currentKLp == currentKLp))
1222- then {
1223- let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)])
1224- if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
1225- then {
1226- let $t04714747228 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0)
1227- let refreshKLpActions = $t04714747228._1
1228- let updatedKLp = $t04714747228._2
1229- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
1230- if ((isUpdatedKLpValid == isUpdatedKLpValid))
1231- then (state ++ refreshKLpActions)
1232- else throw("Strict value is not equal to itself.")
1233- }
1234- else throw("Strict value is not equal to itself.")
1235- }
974+ let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)])
975+ if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
976+ then state
1236977 else throw("Strict value is not equal to itself.")
1237978 }
1238979 }
1239980
1240981
1241982
1242983 @Callable(i)
1243984 func unstakeAndGet (amount) = {
1244985 let checkPayments = if ((size(i.payments) != 0))
1245986 then throw("No payments are expected")
1246987 else true
1247988 if ((checkPayments == checkPayments))
1248989 then {
1249990 let cfg = getPoolConfig()
1250991 let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId])
1251- let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0))
1252- if ((currentKLp == currentKLp))
992+ let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(lpAssetId), amount], nil)
993+ if ((unstakeInv == unstakeInv))
1253994 then {
1254- let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(lpAssetId), amount], nil)
1255- if ((unstakeInv == unstakeInv))
995+ let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller)
996+ let poolStatus = parseIntValue(res._9)
997+ let state = res._10
998+ let checkPoolStatus = if (if (isGlobalShutdown())
999+ then true
1000+ else (poolStatus == PoolShutdown))
1001+ then throw(("Get operation is blocked by admin. Status = " + toString(poolStatus)))
1002+ else true
1003+ if ((checkPoolStatus == checkPoolStatus))
12561004 then {
1257- let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller)
1258- let outAmAmt = res._1
1259- let outPrAmt = res._2
1260- let poolStatus = parseIntValue(res._9)
1261- let state = res._10
1262- let checkPoolStatus = if (if (isGlobalShutdown())
1263- then true
1264- else (poolStatus == PoolShutdown))
1265- then throw(("Get operation is blocked by admin. Status = " + toString(poolStatus)))
1266- else true
1267- if ((checkPoolStatus == checkPoolStatus))
1268- then {
1269- let burnLPAssetOnFactory = invoke(factoryContract, "burn", [amount], [AttachedPayment(lpAssetId, amount)])
1270- if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
1271- then {
1272- let $t04835448435 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0)
1273- let refreshKLpActions = $t04835448435._1
1274- let updatedKLp = $t04835448435._2
1275- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
1276- if ((isUpdatedKLpValid == isUpdatedKLpValid))
1277- then (state ++ refreshKLpActions)
1278- else throw("Strict value is not equal to itself.")
1279- }
1280- else throw("Strict value is not equal to itself.")
1281- }
1005+ let burnLPAssetOnFactory = invoke(factoryContract, "burn", [amount], [AttachedPayment(lpAssetId, amount)])
1006+ if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
1007+ then state
12821008 else throw("Strict value is not equal to itself.")
12831009 }
12841010 else throw("Strict value is not equal to itself.")
12851011 }
12861012 else throw("Strict value is not equal to itself.")
12871013 }
12881014 else throw("Strict value is not equal to itself.")
12891015 }
12901016
12911017
12921018
12931019 @Callable(i)
12941020 func unstakeAndGetNoLess (unstakeAmount,noLessThenAmountAsset,noLessThenPriceAsset) = {
12951021 let isGetDisabled = if (isGlobalShutdown())
12961022 then true
12971023 else (cfgPoolStatus == PoolShutdown)
12981024 let checks = [if (!(isGetDisabled))
12991025 then true
13001026 else throw("get operation is blocked by admin"), if ((size(i.payments) == 0))
13011027 then true
13021028 else throw("no payments are expected")]
13031029 if ((checks == checks))
13041030 then {
1305- let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0))
1306- if ((currentKLp == currentKLp))
1031+ let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil)
1032+ if ((unstakeInv == unstakeInv))
13071033 then {
1308- let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil)
1309- if ((unstakeInv == unstakeInv))
1034+ let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller)
1035+ let outAmAmt = res._1
1036+ let outPrAmt = res._2
1037+ let state = res._10
1038+ let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset))
1039+ then true
1040+ else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset))
1041+ then true
1042+ else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))]
1043+ if ((checkAmounts == checkAmounts))
13101044 then {
1311- let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller)
1312- let outAmAmt = res._1
1313- let outPrAmt = res._2
1314- let state = res._10
1315- let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset))
1316- then true
1317- else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset))
1318- then true
1319- else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))]
1320- if ((checkAmounts == checkAmounts))
1321- then {
1322- let burnLPAssetOnFactory = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)])
1323- if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
1324- then {
1325- let $t04973049811 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0)
1326- let refreshKLpActions = $t04973049811._1
1327- let updatedKLp = $t04973049811._2
1328- let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp)
1329- if ((isUpdatedKLpValid == isUpdatedKLpValid))
1330- then (state ++ refreshKLpActions)
1331- else throw("Strict value is not equal to itself.")
1332- }
1333- else throw("Strict value is not equal to itself.")
1334- }
1045+ let burnLPAssetOnFactory = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)])
1046+ if ((burnLPAssetOnFactory == burnLPAssetOnFactory))
1047+ then state
13351048 else throw("Strict value is not equal to itself.")
13361049 }
13371050 else throw("Strict value is not equal to itself.")
13381051 }
13391052 else throw("Strict value is not equal to itself.")
13401053 }
13411054 else throw("Strict value is not equal to itself.")
13421055 }
13431056
13441057
13451058
13461059 @Callable(i)
13471060 func activate (amtAssetStr,priceAssetStr) = if ((toString(i.caller) != toString(factoryContract)))
13481061 then throw("permissions denied")
13491062 else $Tuple2([StringEntry(aa(), amtAssetStr), StringEntry(pa(), priceAssetStr)], "success")
1350-
1351-
1352-
1353-@Callable(i)
1354-func refreshKLp () = {
1355- let lastRefreshedBlockHeight = valueOrElse(getInteger(keyKLpRefreshedHeight), 0)
1356- let checkLastRefreshedBlockHeight = if (((height - lastRefreshedBlockHeight) >= kLpRefreshDelay))
1357- then unit
1358- else throwErr(makeString([toString(kLpRefreshDelay), " blocks have not passed since the previous call"], ""))
1359- if ((checkLastRefreshedBlockHeight == checkLastRefreshedBlockHeight))
1360- then {
1361- let kLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyKLp), "0")), fmtErr("invalid kLp"))
1362- let $t05099851062 = refreshKLpInternal(0, 0, 0)
1363- let kLpUpdateActions = $t05099851062._1
1364- let updatedKLp = $t05099851062._2
1365- let actions = if ((kLp != updatedKLp))
1366- then kLpUpdateActions
1367- else throwErr("nothing to refresh")
1368- $Tuple2(actions, toString(updatedKLp))
1369- }
1370- else throw("Strict value is not equal to itself.")
1371- }
13721063
13731064
13741065
13751066 @Callable(i)
13761067 func getPoolConfigWrapperREADONLY () = $Tuple2(nil, getPoolConfig())
13771068
13781069
13791070
13801071 @Callable(i)
13811072 func getAccBalanceWrapperREADONLY (assetId) = $Tuple2(nil, getAccBalance(assetId))
13821073
13831074
13841075
13851076 @Callable(i)
13861077 func calcPricesWrapperREADONLY (amAmt,prAmt,lpAmt) = {
13871078 let prices = calcPrices(amAmt, prAmt, lpAmt)
13881079 $Tuple2(nil, [toString(prices[0]), toString(prices[1]), toString(prices[2])])
13891080 }
13901081
13911082
13921083
13931084 @Callable(i)
13941085 func toX18WrapperREADONLY (origVal,origScaleMult) = $Tuple2(nil, toString(toX18(origVal, origScaleMult)))
13951086
13961087
13971088
13981089 @Callable(i)
13991090 func fromX18WrapperREADONLY (val,resultScaleMult) = $Tuple2(nil, fromX18(parseBigIntValue(val), resultScaleMult))
14001091
14011092
14021093
14031094 @Callable(i)
14041095 func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString(calcPriceBigInt(parseBigIntValue(prAmtX18), parseBigIntValue(amAmtX18))))
14051096
14061097
14071098
14081099 @Callable(i)
14091100 func estimatePutOperationWrapperREADONLY (txId58,slippageTolerance,inAmAssetAmt,inAmAssetId,inPrAssetAmt,inPrAssetId,userAddress,isEvaluate,emitLp) = $Tuple2(nil, estimatePutOperation(txId58, slippageTolerance, inAmAssetAmt, inAmAssetId, inPrAssetAmt, inPrAssetId, userAddress, isEvaluate, emitLp))
14101101
14111102
14121103
14131104 @Callable(i)
14141105 func estimateGetOperationWrapperREADONLY (txId58,pmtAssetId,pmtLpAmt,userAddress) = {
14151106 let res = estimateGetOperation(txId58, pmtAssetId, pmtLpAmt, addressFromStringValue(userAddress))
14161107 $Tuple2(nil, $Tuple10(res._1, res._2, res._3, res._4, res._5, res._6, res._7, toString(res._8), res._9, res._10))
14171108 }
14181109
14191110
14201111
14211112 @Callable(i)
14221113 func statsREADONLY () = {
14231114 let cfg = getPoolConfig()
14241115 let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId])
14251116 let amtAssetId = cfg[idxAmtAssetId]
14261117 let priceAssetId = cfg[idxPriceAssetId]
14271118 let iAmtAssetId = cfg[idxIAmtAssetId]
14281119 let iPriceAssetId = cfg[idxIPriceAssetId]
14291120 let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm])
14301121 let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm])
14311122 let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity
14321123 let accAmtAssetBalance = getAccBalance(amtAssetId)
14331124 let accPriceAssetBalance = getAccBalance(priceAssetId)
14341125 let pricesList = if ((poolLPBalance == 0))
14351126 then [zeroBigInt, zeroBigInt, zeroBigInt]
14361127 else calcPrices(accAmtAssetBalance, accPriceAssetBalance, poolLPBalance)
14371128 let curPrice = 0
14381129 let lpAmtAssetShare = fromX18(pricesList[1], scale8)
14391130 let lpPriceAssetShare = fromX18(pricesList[2], scale8)
14401131 let poolWeight = value(getInteger(factoryContract, keyPoolWeight(toString(this))))
14411132 $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))
14421133 }
14431134
14441135
14451136
14461137 @Callable(i)
14471138 func evaluatePutByAmountAssetREADONLY (inAmAssetAmt) = {
14481139 let cfg = getPoolConfig()
14491140 let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId])
14501141 let amAssetIdStr = cfg[idxAmtAssetId]
14511142 let amAssetId = fromBase58String(amAssetIdStr)
14521143 let prAssetIdStr = cfg[idxPriceAssetId]
14531144 let prAssetId = fromBase58String(prAssetIdStr)
14541145 let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm])
14551146 let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm])
14561147 let poolStatus = cfg[idxPoolStatus]
14571148 let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity
14581149 let accAmtAssetBalance = getAccBalance(amAssetIdStr)
14591150 let accPriceAssetBalance = getAccBalance(prAssetIdStr)
14601151 let amtAssetAmtX18 = toX18(accAmtAssetBalance, amtAssetDcm)
14611152 let priceAssetAmtX18 = toX18(accPriceAssetBalance, priceAssetDcm)
14621153 let curPriceX18 = if ((poolLPBalance == 0))
14631154 then zeroBigInt
14641155 else calcPriceBigInt(priceAssetAmtX18, amtAssetAmtX18)
14651156 let inAmAssetAmtX18 = toX18(inAmAssetAmt, amtAssetDcm)
14661157 let inPrAssetAmtX18 = fraction(inAmAssetAmtX18, curPriceX18, scale18)
14671158 let inPrAssetAmt = fromX18(inPrAssetAmtX18, priceAssetDcm)
14681159 let estPut = estimatePutOperation("", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false)
14691160 let calcLpAmt = estPut._1
14701161 let curPriceCalc = estPut._3
14711162 let amBalance = estPut._4
14721163 let prBalance = estPut._5
14731164 let lpEmission = estPut._6
14741165 $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))
14751166 }
14761167
14771168
14781169
14791170 @Callable(i)
14801171 func evaluatePutByPriceAssetREADONLY (inPrAssetAmt) = {
14811172 let cfg = getPoolConfig()
14821173 let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId])
14831174 let amAssetIdStr = cfg[idxAmtAssetId]
14841175 let amAssetId = fromBase58String(amAssetIdStr)
14851176 let prAssetIdStr = cfg[idxPriceAssetId]
14861177 let prAssetId = fromBase58String(prAssetIdStr)
14871178 let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm])
14881179 let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm])
14891180 let poolStatus = cfg[idxPoolStatus]
14901181 let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity
14911182 let amBalanceRaw = getAccBalance(amAssetIdStr)
14921183 let prBalanceRaw = getAccBalance(prAssetIdStr)
14931184 let amBalanceRawX18 = toX18(amBalanceRaw, amtAssetDcm)
14941185 let prBalanceRawX18 = toX18(prBalanceRaw, priceAssetDcm)
14951186 let curPriceX18 = if ((poolLPBalance == 0))
14961187 then zeroBigInt
14971188 else calcPriceBigInt(prBalanceRawX18, amBalanceRawX18)
14981189 let inPrAssetAmtX18 = toX18(inPrAssetAmt, priceAssetDcm)
14991190 let inAmAssetAmtX18 = fraction(inPrAssetAmtX18, scale18, curPriceX18)
15001191 let inAmAssetAmt = fromX18(inAmAssetAmtX18, amtAssetDcm)
15011192 let estPut = estimatePutOperation("", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false)
15021193 let calcLpAmt = estPut._1
15031194 let curPriceCalc = estPut._3
15041195 let amBalance = estPut._4
15051196 let prBalance = estPut._5
15061197 let lpEmission = estPut._6
15071198 $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))
15081199 }
15091200
15101201
15111202
15121203 @Callable(i)
15131204 func evaluateGetREADONLY (paymentLpAssetId,paymentLpAmt) = {
15141205 let res = estimateGetOperation("", paymentLpAssetId, paymentLpAmt, this)
15151206 let outAmAmt = res._1
15161207 let outPrAmt = res._2
15171208 let amBalance = res._5
15181209 let prBalance = res._6
15191210 let lpEmission = res._7
15201211 let curPrice = res._8
15211212 let poolStatus = parseIntValue(res._9)
15221213 $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))
15231214 }
15241215
15251216
15261217 @Verifier(tx)
15271218 func verify () = {
15281219 let targetPublicKey = match managerPublicKeyOrUnit() {
15291220 case pk: ByteVector =>
15301221 pk
15311222 case _: Unit =>
15321223 tx.senderPublicKey
15331224 case _ =>
15341225 throw("Match error")
15351226 }
15361227 match tx {
15371228 case order: Order =>
15381229 let matcherPub = getMatcherPubOrFail()
1539- let $t05972459793 = validateMatcherOrderAllowed(order)
1540- let orderValid = $t05972459793._1
1541- let orderValidInfo = $t05972459793._2
1230+ let orderValid = validateMatcherOrderAllowed(order)
15421231 let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey)
15431232 let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub)
15441233 if (if (if (orderValid)
15451234 then senderValid
15461235 else false)
15471236 then matcherValid
15481237 else false)
15491238 then true
1550- else throwOrderError(orderValid, orderValidInfo, senderValid, matcherValid)
1239+ else throwOrderError(orderValid, senderValid, matcherValid)
15511240 case s: SetScriptTransaction =>
1552- if (sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey))
1241+ let newHash = blake2b256(value(s.script))
1242+ let allowedHash = fromBase64String(value(getString(factoryContract, keyAllowedLpScriptHash())))
1243+ let currentHash = scriptHash(this)
1244+ if (if ((allowedHash == newHash))
1245+ then (currentHash != newHash)
1246+ else false)
15531247 then true
1554- else {
1555- let newHash = blake2b256(value(s.script))
1556- let allowedHash = fromBase64String(value(getString(factoryContract, keyAllowedLpScriptHash())))
1557- let currentHash = scriptHash(this)
1558- if ((allowedHash == newHash))
1559- then (currentHash != newHash)
1560- else false
1561- }
1248+ else sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
15621249 case _ =>
15631250 sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
15641251 }
15651252 }
15661253

github/deemru/w8io/026f985 
315.02 ms