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