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