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