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