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