tx · FCgGzRvw6fdH5SmPd5M5JNpfGPqa99GziSpQ8X6sGo1A 3NAefciWv6f9fWvEXdGgpHfanJFG8HqfjuT: -0.03200000 Waves 2023.02.27 12:42 [2467950] smart account 3NAefciWv6f9fWvEXdGgpHfanJFG8HqfjuT > SELF 0.00000000 Waves
{ "type": 13, "id": "FCgGzRvw6fdH5SmPd5M5JNpfGPqa99GziSpQ8X6sGo1A", "fee": 3200000, "feeAssetId": null, "timestamp": 1677490954751, "version": 1, "sender": "3NAefciWv6f9fWvEXdGgpHfanJFG8HqfjuT", "senderPublicKey": "D1BL65meykxFZTCuq7jq9HSGLLnWvQamQPUNrguW5w39", "proofs": [ "4VXRnbE8FJ1A6mb4pn6CtHagCGPFt3uXZgjcr1K8R1pHYRsm8fivvx5UHyK5EHGsvNFMvZfKivi9nqQxRe7V7TCt" ], "script": "base64:BgK/IggCEgMKAQgSAwoBCBIAEgQKAgEEEgQKAgEEEgMKAQESABIECgIIARIECgIIARIECgIIARIECgIBARIDCgEBEgUKAwEBARIFCgMBCAESBAoCAQgSBAoCAQgSBAoCCAgSBAoCCAgSBAoCCAESABIDCgEIEgUKAwEBARIECgIIARIECgIBARIECgIICBILCgkIAQECAQIIBAQSBgoECAgBCCIGc2NhbGU4IgxzY2FsZThCaWdJbnQiB3NjYWxlMTgiCnplcm9CaWdJbnQiBGJpZzAiBGJpZzEiBGJpZzIiCnNsaXBwYWdlNEQiC3dhdmVzU3RyaW5nIgVBbXVsdCIFRGNvbnYiA1NFUCIFRU1QVFkiClBvb2xBY3RpdmUiClBvb2xQdXREaXMiDlBvb2xNYXRjaGVyRGlzIgxQb29sU2h1dGRvd24iDmlkeFBvb2xBZGRyZXNzIglpZHhQb29sU3QiCWlkeExQQXNJZCIJaWR4QW1Bc0lkIglpZHhQckFzSWQiC2lkeEFtdEFzRGNtIg1pZHhQcmljZUFzRGNtIgtpZHhJQW10QXNJZCINaWR4SVByaWNlQXNJZCIPaWR4RmFjdFN0YWtDbnRyIhJpZ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saWNLZXkJAAIBAgtNYXRjaCBlcnJvcgQCYXYFAmdPAwkAAQIFAmF2AgVPcmRlcgQCZHoFAmF2BAJnUgkBAmFKAAQCZ1MJAQJkeQEFAmR6BAJnVAkA9AMDCAUCZHoJYm9keUJ5dGVzCQCRAwIIBQJkegZwcm9vZnMAAAgFAmR6D3NlbmRlclB1YmxpY0tleQQCZ1UJAPQDAwgFAmR6CWJvZHlCeXRlcwkAkQMCCAUCZHoGcHJvb2ZzAAEFAmdSAwMDBQJnUwUCZ1QHBQJnVQcGCQECYXEDBQJnUwUCZ1QFAmdVAwkAAQIFAmF2AhRTZXRTY3JpcHRUcmFuc2FjdGlvbgQCZFoFAmF2BAJnVgkA9gMBCQEFdmFsdWUBCAUCZFoGc2NyaXB0BAJnVwkA2wQBCQEFdmFsdWUBCQCdCAIFAmFECQECYW8ABAJnWAkA8QcBBQR0aGlzAwMJAAACBQJnVwUCZ1YJAQIhPQIFAmdYBQJnVgcGCQD0AwMIBQJnTwlib2R5Qnl0ZXMJAJEDAggFAmdPBnByb29mcwAABQJnUQkA9AMDCAUCZ08JYm9keUJ5dGVzCQCRAwIIBQJnTwZwcm9vZnMAAAUCZ1GEykE/", "chainId": 84, "height": 2467950, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 2vZHFhDbkCCjV4QTWnhMjjpBiGJjeB1Sqb7A2VcJShT1 Next: Gm59MEY78Hw4gwPA5rhY7dMdDAVeZw3BX9kVG1962tmP Diff:
Old | New | Differences | |
---|---|---|---|
14 | 14 | let big1 = toBigInt(1) | |
15 | 15 | ||
16 | 16 | let big2 = toBigInt(2) | |
17 | - | ||
18 | - | let big3 = toBigInt(3) | |
19 | - | ||
20 | - | let big4 = toBigInt(4) | |
21 | 17 | ||
22 | 18 | let slippage4D = toBigInt((scale8 - ((scale8 * 1) / scale8))) | |
23 | 19 | ||
70 | 66 | func t1 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) | |
71 | 67 | ||
72 | 68 | ||
73 | - | func t1BigInt (origVal,origScaleMult) = fraction(origVal, scale18, origScaleMult) | |
74 | - | ||
75 | - | ||
76 | 69 | func f1 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18)) | |
77 | - | ||
78 | - | ||
79 | - | func fromX18Round (val,resultScaleMult,round) = toInt(fraction(val, toBigInt(resultScaleMult), scale18, round)) | |
80 | - | ||
81 | - | ||
82 | - | func t2 (origVal,origScaleMult) = fraction(origVal, scale18, toBigInt(origScaleMult)) | |
83 | - | ||
84 | - | ||
85 | - | func f2 (val,resultScaleMult) = fraction(val, toBigInt(resultScaleMult), scale18) | |
86 | 70 | ||
87 | 71 | ||
88 | 72 | func ts (amt,resScale,curScale) = fraction(amt, resScale, curScale) | |
131 | 115 | func ada () = "%s__addonAddr" | |
132 | 116 | ||
133 | 117 | ||
134 | - | let keyFee = "%s__fee" | |
135 | - | ||
136 | - | let fee = valueOrElse(getInteger(this, keyFee), feeDefault) | |
137 | - | ||
138 | - | let keyDLp = makeString(["%s", "dLp"], SEP) | |
139 | - | ||
140 | - | let keyDLpRefreshedHeight = makeString(["%s", "dLpRefreshedHeight"], SEP) | |
141 | - | ||
142 | - | let keyDLpRefreshDelay = makeString(["%s", "refreshDLpDelay"], SEP) | |
143 | - | ||
144 | - | let dLpRefreshDelayDefault = 30 | |
145 | - | ||
146 | - | let dLpRefreshDelay = valueOrElse(getInteger(this, keyDLpRefreshDelay), dLpRefreshDelayDefault) | |
147 | - | ||
148 | 118 | func fcfg () = "%s__factoryConfig" | |
149 | 119 | ||
150 | 120 | ||
166 | 136 | func keyFeeCollectorAddress () = "%s__feeCollectorAddress" | |
167 | 137 | ||
168 | 138 | ||
169 | - | func throwOrderError (orderValid,orderValidInfo,senderValid,matcherValid) = throw((((((((("order validation failed: orderValid=" + toString(orderValid)) + " (") + orderValidInfo) + ")") + " senderValid=") + toString(senderValid)) + " matcherValid=") + toString(matcherValid))) | |
139 | + | func toe (orV,sendrV,matchV) = throw(((((("Failed: ordValid=" + toString(orV)) + " sndrValid=") + toString(sendrV)) + " mtchrValid=") + toString(matchV))) | |
140 | + | ||
141 | + | ||
142 | + | func str (val) = match val { | |
143 | + | case valStr: String => | |
144 | + | valStr | |
145 | + | case _ => | |
146 | + | throw("fail cast to String") | |
147 | + | } | |
170 | 148 | ||
171 | 149 | ||
172 | 150 | func strf (addr,key) = valueOrErrorMessage(getString(addr, key), makeString(["mandatory ", toString(addr), ".", key, " not defined"], "")) | |
176 | 154 | ||
177 | 155 | ||
178 | 156 | func throwErr (msg) = throw(makeString(["lp_stable.ride:", msg], " ")) | |
179 | - | ||
180 | - | ||
181 | - | func fmtErr (msg) = makeString(["lp_stable.ride:", msg], " ") | |
182 | 157 | ||
183 | 158 | ||
184 | 159 | let fca = addressFromStringValue(strf(this, fc())) | |
226 | 201 | else toBase58String(value(input)) | |
227 | 202 | ||
228 | 203 | ||
229 | - | func parsePoolConfig (poolConfig) = $ | |
204 | + | func parsePoolConfig (poolConfig) = $Tuple7(addressFromStringValue(poolConfig[idxPoolAddress]), parseIntValue(poolConfig[idxPoolSt]), fromBase58String(poolConfig[idxLPAsId]), parseAssetId(poolConfig[idxAmAsId]), parseAssetId(poolConfig[idxPrAsId]), parseIntValue(poolConfig[idxAmtAsDcm]), parseIntValue(poolConfig[idxPriceAsDcm])) | |
230 | 205 | ||
231 | 206 | ||
232 | 207 | let poolConfigParsed = parsePoolConfig(gpc()) | |
233 | 208 | ||
234 | - | let $ | |
209 | + | let $t069097095 = poolConfigParsed | |
235 | 210 | ||
236 | - | let cfgPoolAddress = $ | |
211 | + | let cfgPoolAddress = $t069097095._1 | |
237 | 212 | ||
238 | - | let cfgPoolStatus = $ | |
213 | + | let cfgPoolStatus = $t069097095._2 | |
239 | 214 | ||
240 | - | let cfgLpAssetId = $ | |
215 | + | let cfgLpAssetId = $t069097095._3 | |
241 | 216 | ||
242 | - | let cfgAmountAssetId = $ | |
217 | + | let cfgAmountAssetId = $t069097095._4 | |
243 | 218 | ||
244 | - | let cfgPriceAssetId = $ | |
219 | + | let cfgPriceAssetId = $t069097095._5 | |
245 | 220 | ||
246 | - | let cfgAmountAssetDecimals = $ | |
221 | + | let cfgAmountAssetDecimals = $t069097095._6 | |
247 | 222 | ||
248 | - | let cfgPriceAssetDecimals = $t079658194._7 | |
249 | - | ||
250 | - | let cfgInAmountAssedId = $t079658194._8 | |
251 | - | ||
252 | - | let cfgInPriceAssetId = $t079658194._9 | |
223 | + | let cfgPriceAssetDecimals = $t069097095._7 | |
253 | 224 | ||
254 | 225 | func gfc () = split(strf(fca, fcfg()), SEP) | |
255 | 226 | ||
276 | 247 | ||
277 | 248 | ||
278 | 249 | func cpbi (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18) | |
279 | - | ||
280 | - | ||
281 | - | func cpbir (prAmtX18,amAmtX18,round) = fraction(prAmtX18, scale18, amAmtX18, round) | |
282 | 250 | ||
283 | 251 | ||
284 | 252 | func vad (A1,A2,slippage) = { | |
309 | 277 | ||
310 | 278 | ||
311 | 279 | func calcPrices (amAmt,prAmt,lpAmt) = { | |
312 | - | let amtAsDcm = cfgAmountAssetDecimals | |
313 | - | let prAsDcm = cfgPriceAssetDecimals | |
280 | + | let cfg = gpc() | |
281 | + | let amtAsDcm = parseIntValue(cfg[idxAmtAsDcm]) | |
282 | + | let prAsDcm = parseIntValue(cfg[idxPriceAsDcm]) | |
314 | 283 | let priceX18 = pcp(amtAsDcm, prAsDcm, amAmt, prAmt) | |
315 | 284 | let amAmtX18 = t1(amAmt, amtAsDcm) | |
316 | 285 | let prAmtX18 = t1(prAmt, prAsDcm) | |
335 | 304 | } | |
336 | 305 | ||
337 | 306 | ||
338 | - | func getD (xp) = { | |
339 | - | let xp0 = xp[0] | |
340 | - | let xp1 = xp[1] | |
341 | - | let s = (xp0 + xp1) | |
342 | - | if ((s == big0)) | |
343 | - | then big0 | |
344 | - | else { | |
345 | - | let a = parseIntValue(A) | |
346 | - | let ann = (a * 2) | |
347 | - | let p = fraction(xp0, xp1, big1) | |
348 | - | let xp0_xp1_n_n = fraction(p, big4, big1) | |
349 | - | let ann_s = fraction(toBigInt(ann), s, big1) | |
350 | - | let ann_1 = toBigInt((ann - 1)) | |
351 | - | func calcDNext (d) = { | |
352 | - | let dd = fraction(d, d, big1) | |
353 | - | let ddd = fraction(dd, d, big1) | |
354 | - | let dp = fraction(ddd, big1, xp0_xp1_n_n) | |
355 | - | fraction((ann_s + fraction(dp, big2, big1)), d, (fraction(ann_1, d, big1) + fraction(big3, dp, big1))) | |
356 | - | } | |
357 | - | ||
358 | - | func calc (acc,i) = if (acc._2) | |
359 | - | then acc | |
360 | - | else { | |
361 | - | let d = acc._1 | |
362 | - | let dNext = calcDNext(d) | |
363 | - | let dDiffRaw = (dNext - value(d)) | |
364 | - | let dDiff = if ((big0 > dDiffRaw)) | |
365 | - | then -(dDiffRaw) | |
366 | - | else dDiffRaw | |
367 | - | if ((big1 >= dDiff)) | |
368 | - | then $Tuple2(dNext, true) | |
369 | - | else $Tuple2(dNext, false) | |
370 | - | } | |
371 | - | ||
372 | - | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] | |
373 | - | let $t01270312751 = { | |
374 | - | let $l = arr | |
375 | - | let $s = size($l) | |
376 | - | let $acc0 = $Tuple2(s, false) | |
377 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
378 | - | then $a | |
379 | - | else calc($a, $l[$i]) | |
380 | - | ||
381 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
382 | - | then $a | |
383 | - | else throw("List size exceeds 18") | |
384 | - | ||
385 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18) | |
386 | - | } | |
387 | - | let d = $t01270312751._1 | |
388 | - | let found = $t01270312751._2 | |
389 | - | if (found) | |
390 | - | then d | |
391 | - | else throw(("D calculation error, D = " + toString(d))) | |
392 | - | } | |
393 | - | } | |
394 | - | ||
395 | - | ||
396 | 307 | func ego (txId58,pmtAssetId,pmtLpAmt,userAddress) = { | |
397 | - | let lpId = cfgLpAssetId | |
398 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
399 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
400 | - | let amDcm = cfgAmountAssetDecimals | |
401 | - | let prDcm = cfgPriceAssetDecimals | |
402 | - | let sts = toString(cfgPoolStatus) | |
403 | - | let lpEmiss = valueOrErrorMessage(assetInfo(lpId), "Wrong LP id").quantity | |
404 | - | if ((toBase58String(lpId) != pmtAssetId)) | |
308 | + | let cfg = gpc() | |
309 | + | let lpId = cfg[idxLPAsId] | |
310 | + | let amId = cfg[idxAmAsId] | |
311 | + | let prId = cfg[idxPrAsId] | |
312 | + | let amDcm = parseIntValue(cfg[idxAmtAsDcm]) | |
313 | + | let prDcm = parseIntValue(cfg[idxPriceAsDcm]) | |
314 | + | let sts = cfg[idxPoolSt] | |
315 | + | let lpEmiss = valueOrErrorMessage(assetInfo(fromBase58String(lpId)), "Wrong LP id").quantity | |
316 | + | if ((lpId != pmtAssetId)) | |
405 | 317 | then throw("Wrong pmt asset") | |
406 | 318 | else { | |
407 | 319 | let amBalance = getAccBalance(amId) | |
414 | 326 | let lpEmissX18 = t1(lpEmiss, scale8) | |
415 | 327 | let outAmAmtX18 = fraction(amBalanceX18, pmtLpAmtX18, lpEmissX18) | |
416 | 328 | let outPrAmtX18 = fraction(prBalanceX18, pmtLpAmtX18, lpEmissX18) | |
417 | - | let outAmAmt = | |
418 | - | let outPrAmt = | |
329 | + | let outAmAmt = f1(outAmAmtX18, amDcm) | |
330 | + | let outPrAmt = f1(outPrAmtX18, prDcm) | |
419 | 331 | let state = if ((txId58 == "")) | |
420 | 332 | then nil | |
421 | 333 | else [ScriptTransfer(userAddress, outAmAmt, if ((amId == "WAVES")) | |
429 | 341 | ||
430 | 342 | ||
431 | 343 | func epo (txId58,slippage,inAmAmt,inAmId,inPrAmt,inPrId,userAddress,isEval,emitLp,isOneAsset,validateSlippage,pmtAmt,pmtId) = { | |
432 | - | let lpId = cfgLpAssetId | |
433 | - | let amIdStr = toBase58String(value(cfgAmountAssetId)) | |
434 | - | let prIdStr = toBase58String(value(cfgPriceAssetId)) | |
435 | - | let inAmIdStr = cfgInAmountAssedId | |
436 | - | let inPrIdStr = cfgInPriceAssetId | |
437 | - | let amtDcm = cfgAmountAssetDecimals | |
438 | - | let priceDcm = cfgPriceAssetDecimals | |
439 | - | let sts = toString(cfgPoolStatus) | |
344 | + | let cfg = gpc() | |
345 | + | let lpId = fromBase58String(cfg[idxLPAsId]) | |
346 | + | let amIdStr = cfg[idxAmAsId] | |
347 | + | let prIdStr = cfg[idxPrAsId] | |
348 | + | let inAmIdStr = cfg[idxIAmtAsId] | |
349 | + | let inPrIdStr = cfg[idxIPriceAsId] | |
350 | + | let amtDcm = parseIntValue(cfg[idxAmtAsDcm]) | |
351 | + | let priceDcm = parseIntValue(cfg[idxPriceAsDcm]) | |
352 | + | let sts = cfg[idxPoolSt] | |
440 | 353 | let lpEm = valueOrErrorMessage(assetInfo(lpId), "Wr lp as").quantity | |
441 | 354 | let amBalance = if (isEval) | |
442 | 355 | then getAccBalance(amIdStr) | |
461 | 374 | let userPriceX18 = cpbi(inPrAssetAmtX18, inAmAssetAmtX18) | |
462 | 375 | let amBalanceX18 = t1(amBalance, amtDcm) | |
463 | 376 | let prBalanceX18 = t1(prBalance, priceDcm) | |
464 | - | let D0 = getD([amBalanceX18, prBalanceX18]) | |
465 | 377 | let r = if ((lpEm == 0)) | |
466 | 378 | then { | |
467 | - | let D1 = getD([(amBalanceX18 + inAmAssetAmtX18), (prBalanceX18 + inPrAssetAmtX18)]) | |
468 | - | let checkD = if ((D1 > D0)) | |
469 | - | then true | |
470 | - | else throw("D1 should be greater than D0") | |
471 | - | if ((checkD == checkD)) | |
472 | - | then { | |
473 | - | let curPriceX18 = zeroBigInt | |
474 | - | let slippageX18 = zeroBigInt | |
475 | - | let lpAmtX18 = D1 | |
476 | - | $Tuple5(f1(lpAmtX18, scale8), f1(inAmAssetAmtX18, amtDcm), f1(inPrAssetAmtX18, priceDcm), cpbi((prBalanceX18 + inPrAssetAmtX18), (amBalanceX18 + inAmAssetAmtX18)), slippageX18) | |
477 | - | } | |
478 | - | else throw("Strict value is not equal to itself.") | |
379 | + | let curPriceX18 = zeroBigInt | |
380 | + | let slippageX18 = zeroBigInt | |
381 | + | let lpAmtX18 = pow((inAmAssetAmtX18 * inPrAssetAmtX18), 0, toBigInt(5), 1, 0, DOWN) | |
382 | + | $Tuple5(f1(lpAmtX18, scale8), f1(inAmAssetAmtX18, amtDcm), f1(inPrAssetAmtX18, priceDcm), cpbi((prBalanceX18 + inPrAssetAmtX18), (amBalanceX18 + inAmAssetAmtX18)), slippageX18) | |
479 | 383 | } | |
480 | 384 | else { | |
481 | 385 | let curPriceX18 = cpbi(prBalanceX18, amBalanceX18) | |
489 | 393 | then throw(((("Price slippage " + toString(slippageRealX18)) + " > ") + toString(slippageX18))) | |
490 | 394 | else { | |
491 | 395 | let lpEmissionX18 = t1(lpEm, scale8) | |
492 | - | let prViaAmX18 = fraction(inAmAssetAmtX18, | |
493 | - | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, | |
396 | + | let prViaAmX18 = fraction(inAmAssetAmtX18, curPriceX18, scale18) | |
397 | + | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, curPriceX18) | |
494 | 398 | let expectedAmts = if ((prViaAmX18 > inPrAssetAmtX18)) | |
495 | 399 | then $Tuple2(amViaPrX18, inPrAssetAmtX18) | |
496 | 400 | else $Tuple2(inAmAssetAmtX18, prViaAmX18) | |
497 | 401 | let expAmtAssetAmtX18 = expectedAmts._1 | |
498 | 402 | let expPriceAssetAmtX18 = expectedAmts._2 | |
499 | - | let D1 = getD([(amBalanceX18 + expAmtAssetAmtX18), (prBalanceX18 + expPriceAssetAmtX18)]) | |
500 | - | let checkD = if ((D1 > D0)) | |
501 | - | then true | |
502 | - | else throw("D1 should be greater than D0") | |
503 | - | if ((checkD == checkD)) | |
504 | - | then { | |
505 | - | let lpAmtX18 = fraction(lpEmissionX18, (D1 - D0), D0) | |
506 | - | $Tuple5(fromX18Round(lpAmtX18, scale8, FLOOR), fromX18Round(expAmtAssetAmtX18, amtDcm, CEILING), fromX18Round(expPriceAssetAmtX18, priceDcm, CEILING), curPriceX18, slippageX18) | |
507 | - | } | |
508 | - | else throw("Strict value is not equal to itself.") | |
403 | + | let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18) | |
404 | + | $Tuple5(f1(lpAmtX18, scale8), f1(expAmtAssetAmtX18, amtDcm), f1(expPriceAssetAmtX18, priceDcm), curPriceX18, slippageX18) | |
509 | 405 | } | |
510 | 406 | } | |
511 | 407 | let calcLpAmt = r._1 | |
521 | 417 | else calcLpAmt | |
522 | 418 | let amDiff = (inAmAmt - calcAmAssetPmt) | |
523 | 419 | let prDiff = (inPrAmt - calcPrAssetPmt) | |
524 | - | let $ | |
420 | + | let $t01756217907 = if (if (isOneAsset) | |
525 | 421 | then (pmtId == amIdStr) | |
526 | 422 | else false) | |
527 | 423 | then $Tuple2(pmtAmt, 0) | |
530 | 426 | else false) | |
531 | 427 | then $Tuple2(0, pmtAmt) | |
532 | 428 | else $Tuple2(calcAmAssetPmt, calcPrAssetPmt) | |
533 | - | let writeAmAmt = $ | |
534 | - | let writePrAmt = $ | |
429 | + | let writeAmAmt = $t01756217907._1 | |
430 | + | let writePrAmt = $t01756217907._2 | |
535 | 431 | let commonState = [IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice), StringEntry(pau(userAddress, txId58), dataPutActionInfo(writeAmAmt, writePrAmt, emitLpAmt, curPrice, slippage, slippageCalc, height, lastBlock.timestamp, amDiff, prDiff))] | |
536 | 432 | $Tuple13(calcLpAmt, emitLpAmt, curPrice, amBalance, prBalance, lpEm, lpId, sts, commonState, amDiff, prDiff, inAmId, inPrId) | |
537 | 433 | } | |
538 | 434 | } | |
539 | 435 | ||
540 | 436 | ||
541 | - | func getYD (xp,i,D) = { | |
542 | - | let n = big2 | |
543 | - | let x = xp[if ((i == 0)) | |
544 | - | then 1 | |
545 | - | else 0] | |
546 | - | let aPrecision = parseBigIntValue(Amult) | |
547 | - | let a = (parseBigIntValue(A) * aPrecision) | |
548 | - | let s = x | |
549 | - | let ann = (a * n) | |
550 | - | let c = (((((D * D) / (x * n)) * D) * aPrecision) / (ann * n)) | |
551 | - | let b = ((s + ((D * aPrecision) / ann)) - D) | |
552 | - | func calc (acc,cur) = { | |
553 | - | let $t02213022150 = acc | |
554 | - | let y = $t02213022150._1 | |
555 | - | let found = $t02213022150._2 | |
556 | - | if ((found != unit)) | |
557 | - | then acc | |
558 | - | else { | |
559 | - | let yNext = (((y * y) + c) / ((big2 * y) + b)) | |
560 | - | let yDiff = absBigInt((yNext - value(y))) | |
561 | - | if ((big1 >= yDiff)) | |
562 | - | then $Tuple2(yNext, cur) | |
563 | - | else $Tuple2(yNext, unit) | |
564 | - | } | |
565 | - | } | |
566 | - | ||
567 | - | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
568 | - | let $t02245722504 = { | |
569 | - | let $l = arr | |
570 | - | let $s = size($l) | |
571 | - | let $acc0 = $Tuple2(D, unit) | |
572 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
573 | - | then $a | |
574 | - | else calc($a, $l[$i]) | |
575 | - | ||
576 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
577 | - | then $a | |
578 | - | else throw("List size exceeds 15") | |
579 | - | ||
580 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
581 | - | } | |
582 | - | let y = $t02245722504._1 | |
583 | - | let found = $t02245722504._2 | |
584 | - | if ((found != unit)) | |
585 | - | then y | |
586 | - | else throw(("Y calculation error, Y = " + toString(y))) | |
587 | - | } | |
588 | - | ||
589 | - | ||
590 | - | func calcDLp (amountBalance,priceBalance,lpEmission) = { | |
591 | - | let updatedDLp = fraction(getD([t1BigInt(amountBalance, toBigInt(cfgAmountAssetDecimals)), t1BigInt(priceBalance, toBigInt(cfgPriceAssetDecimals))]), scale18, lpEmission) | |
592 | - | if ((lpEmission == big0)) | |
593 | - | then big0 | |
594 | - | else updatedDLp | |
595 | - | } | |
596 | - | ||
597 | - | ||
598 | - | func calcCurrentDLp (amountAssetDelta,priceAssetDelta,lpAssetEmissionDelta) = { | |
599 | - | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amountAssetDelta) | |
600 | - | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - priceAssetDelta) | |
601 | - | let lpAssetEmission = (toBigInt(value(assetInfo(cfgLpAssetId)).quantity) - lpAssetEmissionDelta) | |
602 | - | let currentDLp = calcDLp(amountAssetBalance, priceAssetBalance, lpAssetEmission) | |
603 | - | currentDLp | |
604 | - | } | |
605 | - | ||
606 | - | ||
607 | - | func refreshDLpInternal (amountAssetBalanceDelta,priceAssetBalanceDelta,lpAssetEmissionDelta) = { | |
608 | - | let amountAssetBalance = (getAccBalance(assetIdToString(cfgAmountAssetId)) + amountAssetBalanceDelta) | |
609 | - | let priceAssetBalance = (getAccBalance(assetIdToString(cfgPriceAssetId)) + priceAssetBalanceDelta) | |
610 | - | let lpAssetEmission = (value(assetInfo(cfgLpAssetId)).quantity + lpAssetEmissionDelta) | |
611 | - | let updatedDLp = calcDLp(toBigInt(amountAssetBalance), toBigInt(priceAssetBalance), toBigInt(lpAssetEmission)) | |
612 | - | let actions = [IntegerEntry(keyDLpRefreshedHeight, height), StringEntry(keyDLp, toString(updatedDLp))] | |
613 | - | $Tuple2(actions, updatedDLp) | |
614 | - | } | |
615 | - | ||
616 | - | ||
617 | - | func validateUpdatedDLp (oldDLp,updatedDLp) = if ((updatedDLp >= oldDLp)) | |
618 | - | then true | |
619 | - | else throwErr("updated DLp lower than current DLp") | |
620 | - | ||
621 | - | ||
622 | - | func validateMatcherOrderAllowed (order) = { | |
623 | - | let amountAssetBalance = getAccBalance(assetIdToString(cfgAmountAssetId)) | |
624 | - | let priceAssetBalance = getAccBalance(assetIdToString(cfgPriceAssetId)) | |
625 | - | let amountAssetAmount = order.amount | |
626 | - | let priceAssetAmount = fraction(order.amount, order.price, scale8, FLOOR) | |
627 | - | let $t02470224914 = if ((order.orderType == Buy)) | |
628 | - | then $Tuple2(amountAssetAmount, -(priceAssetAmount)) | |
629 | - | else $Tuple2(-(amountAssetAmount), priceAssetAmount) | |
630 | - | let amountAssetBalanceDelta = $t02470224914._1 | |
631 | - | let priceAssetBalanceDelta = $t02470224914._2 | |
437 | + | func moa (order) = { | |
438 | + | let cfg = gpc() | |
439 | + | let amtAsId = cfg[idxAmAsId] | |
440 | + | let prAsId = cfg[idxPrAsId] | |
441 | + | let sts = parseIntValue(cfg[idxPoolSt]) | |
442 | + | let amtAsDcm = parseIntValue(cfg[idxAmtAsDcm]) | |
443 | + | let prAsDcm = parseIntValue(cfg[idxPriceAsDcm]) | |
444 | + | let accAmtAsBalance = getAccBalance(amtAsId) | |
445 | + | let accPrAsBalance = getAccBalance(prAsId) | |
446 | + | let curPriceX18 = if ((order.orderType == Buy)) | |
447 | + | then pcp(amtAsDcm, prAsDcm, (accAmtAsBalance + order.amount), accPrAsBalance) | |
448 | + | else pcp(amtAsDcm, prAsDcm, (accAmtAsBalance - order.amount), accPrAsBalance) | |
449 | + | let curPrice = f1(curPriceX18, scale8) | |
632 | 450 | if (if (if (igs()) | |
633 | 451 | then true | |
634 | - | else ( | |
452 | + | else (sts == PoolMatcherDis)) | |
635 | 453 | then true | |
636 | - | else ( | |
454 | + | else (sts == PoolShutdown)) | |
637 | 455 | then throw("Admin blocked") | |
638 | - | else if (if ((order.assetPair.amountAsset != cfgAmountAssetId)) | |
639 | - | then true | |
640 | - | else (order.assetPair.priceAsset != cfgPriceAssetId)) | |
641 | - | then throw("Wr assets") | |
642 | - | else { | |
643 | - | let dLp = parseBigIntValue(valueOrElse(getString(this, keyDLp), "0")) | |
644 | - | let $t02525625356 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
645 | - | let unusedActions = $t02525625356._1 | |
646 | - | let dLpNew = $t02525625356._2 | |
647 | - | let isOrderValid = (dLpNew >= dLp) | |
648 | - | let info = makeString(["dLp=", toString(dLp), " dLpNew=", toString(dLpNew), " amountAssetBalance=", toString(amountAssetBalance), " priceAssetBalance=", toString(priceAssetBalance), " amountAssetBalanceDelta=", toString(amountAssetBalanceDelta), " priceAssetBalanceDelta=", toString(priceAssetBalanceDelta), " height=", toString(height)], "") | |
649 | - | $Tuple2(isOrderValid, info) | |
650 | - | } | |
456 | + | else { | |
457 | + | let orAmtAsset = order.assetPair.amountAsset | |
458 | + | let orAmtAsStr = if ((orAmtAsset == unit)) | |
459 | + | then "WAVES" | |
460 | + | else toBase58String(value(orAmtAsset)) | |
461 | + | let orPrAsset = order.assetPair.priceAsset | |
462 | + | let orPrAsStr = if ((orPrAsset == unit)) | |
463 | + | then "WAVES" | |
464 | + | else toBase58String(value(orPrAsset)) | |
465 | + | if (if ((orAmtAsStr != amtAsId)) | |
466 | + | then true | |
467 | + | else (orPrAsStr != prAsId)) | |
468 | + | then throw("Wr assets") | |
469 | + | else { | |
470 | + | let orderPrice = order.price | |
471 | + | let priceDcm = fraction(scale8, prAsDcm, amtAsDcm) | |
472 | + | let castOrderPrice = ts(orderPrice, scale8, priceDcm) | |
473 | + | let isOrderPriceValid = if ((order.orderType == Buy)) | |
474 | + | then (curPrice >= castOrderPrice) | |
475 | + | else (castOrderPrice >= curPrice) | |
476 | + | true | |
477 | + | } | |
478 | + | } | |
651 | 479 | } | |
652 | 480 | ||
653 | 481 | ||
683 | 511 | } | |
684 | 512 | ||
685 | 513 | ||
514 | + | func getD (xp) = { | |
515 | + | let n = big2 | |
516 | + | let xp0 = xp[0] | |
517 | + | let xp1 = xp[1] | |
518 | + | let aPrecision = parseBigIntValue(Amult) | |
519 | + | let a = (parseBigIntValue(A) * aPrecision) | |
520 | + | let s = (xp0 + xp1) | |
521 | + | if ((s == big0)) | |
522 | + | then big0 | |
523 | + | else { | |
524 | + | let ann = (a * n) | |
525 | + | let xp0_xp1_n_n = (((xp0 * xp1) * n) * n) | |
526 | + | let ann_s_aPrecision = ((ann * s) / aPrecision) | |
527 | + | let ann_aPrecision = (ann - aPrecision) | |
528 | + | let n1 = (n + big1) | |
529 | + | func calc (acc,cur) = { | |
530 | + | let $t02245922479 = acc | |
531 | + | let d = $t02245922479._1 | |
532 | + | let found = $t02245922479._2 | |
533 | + | if ((found != unit)) | |
534 | + | then acc | |
535 | + | else { | |
536 | + | let dp = (((d * d) * d) / xp0_xp1_n_n) | |
537 | + | let dNext = (((ann_s_aPrecision + (dp * n)) * d) / (((ann_aPrecision * d) / aPrecision) + (n1 * dp))) | |
538 | + | let dDiff = absBigInt((dNext - value(d))) | |
539 | + | if ((big1 >= dDiff)) | |
540 | + | then $Tuple2(dNext, cur) | |
541 | + | else $Tuple2(dNext, unit) | |
542 | + | } | |
543 | + | } | |
544 | + | ||
545 | + | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
546 | + | let $t02290022947 = { | |
547 | + | let $l = arr | |
548 | + | let $s = size($l) | |
549 | + | let $acc0 = $Tuple2(s, unit) | |
550 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
551 | + | then $a | |
552 | + | else calc($a, $l[$i]) | |
553 | + | ||
554 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
555 | + | then $a | |
556 | + | else throw("List size exceeds 15") | |
557 | + | ||
558 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
559 | + | } | |
560 | + | let d = $t02290022947._1 | |
561 | + | let found = $t02290022947._2 | |
562 | + | if ((found != unit)) | |
563 | + | then d | |
564 | + | else throw(("D calculation error, D = " + toString(d))) | |
565 | + | } | |
566 | + | } | |
567 | + | ||
568 | + | ||
569 | + | func getYD (xp,i,D) = { | |
570 | + | let n = big2 | |
571 | + | let x = xp[if ((i == 0)) | |
572 | + | then 1 | |
573 | + | else 0] | |
574 | + | let aPrecision = parseBigIntValue(Amult) | |
575 | + | let a = (parseBigIntValue(A) * aPrecision) | |
576 | + | let s = x | |
577 | + | let ann = (a * n) | |
578 | + | let c = (((((D * D) / (x * n)) * D) * aPrecision) / (ann * n)) | |
579 | + | let b = ((s + ((D * aPrecision) / ann)) - D) | |
580 | + | func calc (acc,cur) = { | |
581 | + | let $t02344723467 = acc | |
582 | + | let y = $t02344723467._1 | |
583 | + | let found = $t02344723467._2 | |
584 | + | if ((found != unit)) | |
585 | + | then acc | |
586 | + | else { | |
587 | + | let yNext = (((y * y) + c) / ((big2 * y) + b)) | |
588 | + | let yDiff = absBigInt((yNext - value(y))) | |
589 | + | if ((big1 >= yDiff)) | |
590 | + | then $Tuple2(yNext, cur) | |
591 | + | else $Tuple2(yNext, unit) | |
592 | + | } | |
593 | + | } | |
594 | + | ||
595 | + | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
596 | + | let $t02377423821 = { | |
597 | + | let $l = arr | |
598 | + | let $s = size($l) | |
599 | + | let $acc0 = $Tuple2(D, unit) | |
600 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
601 | + | then $a | |
602 | + | else calc($a, $l[$i]) | |
603 | + | ||
604 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
605 | + | then $a | |
606 | + | else throw("List size exceeds 15") | |
607 | + | ||
608 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
609 | + | } | |
610 | + | let y = $t02377423821._1 | |
611 | + | let found = $t02377423821._2 | |
612 | + | if ((found != unit)) | |
613 | + | then y | |
614 | + | else throw(("Y calculation error, Y = " + toString(y))) | |
615 | + | } | |
616 | + | ||
617 | + | ||
686 | 618 | func calcPutOneTkn (pmtAmtRaw,pmtAssetId,userAddress,txId,withTakeFee) = { | |
687 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
688 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
689 | - | let lpId = cfgLpAssetId | |
690 | - | let amtDcm = cfgAmountAssetDecimals | |
691 | - | let priceDcm = cfgPriceAssetDecimals | |
692 | - | let lpAssetEmission = toBigInt(valueOrErrorMessage(assetInfo(lpId), "invalid lp asset").quantity) | |
619 | + | let poolConfig = gpc() | |
620 | + | let amId = poolConfig[idxAmAsId] | |
621 | + | let prId = poolConfig[idxPrAsId] | |
622 | + | let lpId = poolConfig[idxLPAsId] | |
623 | + | let amtDcm = parseIntValue(poolConfig[idxAmtAsDcm]) | |
624 | + | let priceDcm = parseIntValue(poolConfig[idxPriceAsDcm]) | |
625 | + | let lpAssetEmission = toBigInt(valueOrErrorMessage(assetInfo(fromBase58String(lpId)), "invalid lp asset").quantity) | |
693 | 626 | let chechEmission = if ((lpAssetEmission > big0)) | |
694 | 627 | then true | |
695 | 628 | else throw("initial deposit requires all coins") | |
697 | 630 | then { | |
698 | 631 | let amBalance = getAccBalance(amId) | |
699 | 632 | let prBalance = getAccBalance(prId) | |
700 | - | let $ | |
633 | + | let $t02460425066 = if ((txId == "")) | |
701 | 634 | then $Tuple2(amBalance, prBalance) | |
702 | 635 | else if ((pmtAssetId == amId)) | |
703 | 636 | then if ((pmtAmtRaw > amBalance)) | |
708 | 641 | then throw("invalid payment amount") | |
709 | 642 | else $Tuple2(amBalance, (prBalance - pmtAmtRaw)) | |
710 | 643 | else throw("wrong pmtAssetId") | |
711 | - | let amBalanceOld = $ | |
712 | - | let prBalanceOld = $ | |
713 | - | let $ | |
644 | + | let amBalanceOld = $t02460425066._1 | |
645 | + | let prBalanceOld = $t02460425066._2 | |
646 | + | let $t02507225248 = if ((pmtAssetId == amId)) | |
714 | 647 | then $Tuple2(pmtAmtRaw, 0) | |
715 | 648 | else if ((pmtAssetId == prId)) | |
716 | 649 | then $Tuple2(0, pmtAmtRaw) | |
717 | 650 | else throw("invalid payment") | |
718 | - | let amAmountRaw = $ | |
719 | - | let prAmountRaw = $ | |
720 | - | let $ | |
651 | + | let amAmountRaw = $t02507225248._1 | |
652 | + | let prAmountRaw = $t02507225248._2 | |
653 | + | let $t02525225506 = if (withTakeFee) | |
721 | 654 | then $Tuple3(takeFee(amAmountRaw, inFee)._1, takeFee(prAmountRaw, inFee)._1, takeFee(pmtAmtRaw, inFee)._2) | |
722 | 655 | else $Tuple3(amAmountRaw, prAmountRaw, 0) | |
723 | - | let amAmount = $ | |
724 | - | let prAmount = $ | |
725 | - | let feeAmount = $ | |
656 | + | let amAmount = $t02525225506._1 | |
657 | + | let prAmount = $t02525225506._2 | |
658 | + | let feeAmount = $t02525225506._3 | |
726 | 659 | let amBalanceNew = (amBalanceOld + amAmount) | |
727 | 660 | let prBalanceNew = (prBalanceOld + prAmount) | |
728 | - | let D0 = getD([ | |
729 | - | let D1 = getD([ | |
661 | + | let D0 = getD([toBigInt(amBalanceOld), toBigInt(prBalanceOld)]) | |
662 | + | let D1 = getD([toBigInt(amBalanceNew), toBigInt(prBalanceNew)]) | |
730 | 663 | let checkD = if ((D1 > D0)) | |
731 | 664 | then true | |
732 | 665 | else throw() | |
733 | 666 | if ((checkD == checkD)) | |
734 | 667 | then { | |
735 | - | let lpAmount = fraction(lpAssetEmission, (D1 - D0), D0 | |
668 | + | let lpAmount = fraction(lpAssetEmission, (D1 - D0), D0) | |
736 | 669 | let curPrice = f1(cpbi(t1(prBalanceNew, priceDcm), t1(amBalanceNew, amtDcm)), scale8) | |
737 | 670 | let commonState = [IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice), StringEntry(pau(userAddress, txId), dataPutActionInfo(amAmountRaw, prAmountRaw, toInt(lpAmount), curPrice, 0, 0, height, lastBlock.timestamp, 0, 0))] | |
738 | 671 | let poolProportion = fraction(prBalanceOld, scale8, amBalanceOld) | |
749 | 682 | ||
750 | 683 | ||
751 | 684 | func getOneTknV2Internal (outAssetId,minOutAmount,payments,caller,originCaller,transactionId) = { | |
752 | - | let lpId = toBase58String(value(cfgLpAssetId)) | |
753 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
754 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
755 | - | let amDecimals = cfgAmountAssetDecimals | |
756 | - | let prDecimals = cfgPriceAssetDecimals | |
757 | - | let poolStatus = cfgPoolStatus | |
685 | + | let poolConfig = gpc() | |
686 | + | let lpId = poolConfig[idxLPAsId] | |
687 | + | let amId = poolConfig[idxAmAsId] | |
688 | + | let prId = poolConfig[idxPrAsId] | |
689 | + | let amDecimals = parseIntValue(poolConfig[idxAmtAsDcm]) | |
690 | + | let prDecimals = parseIntValue(poolConfig[idxPriceAsDcm]) | |
691 | + | let poolStatus = poolConfig[idxPoolSt] | |
758 | 692 | let userAddress = if ((caller == restContract)) | |
759 | 693 | then originCaller | |
760 | 694 | else caller | |
761 | 695 | let pmt = value(payments[0]) | |
762 | 696 | let pmtAssetId = value(pmt.assetId) | |
763 | 697 | let pmtAmt = pmt.amount | |
764 | - | let currentDLp = calcCurrentDLp(big0, big0, big0) | |
765 | - | if ((currentDLp == currentDLp)) | |
766 | - | then { | |
767 | - | let txId58 = toBase58String(transactionId) | |
768 | - | if ((lpId != toBase58String(pmtAssetId))) | |
769 | - | then throw("Wrong LP") | |
770 | - | else { | |
771 | - | let amBalance = getAccBalance(amId) | |
772 | - | let prBalance = getAccBalance(prId) | |
773 | - | let $t03102631137 = { | |
774 | - | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, pmtAmt], nil) | |
775 | - | if ($isInstanceOf(@, "(Int, Int)")) | |
776 | - | then @ | |
777 | - | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
778 | - | } | |
779 | - | if (($t03102631137 == $t03102631137)) | |
698 | + | let txId58 = toBase58String(transactionId) | |
699 | + | if ((lpId != toBase58String(pmtAssetId))) | |
700 | + | then throw("Wrong LP") | |
701 | + | else { | |
702 | + | let amBalance = getAccBalance(amId) | |
703 | + | let prBalance = getAccBalance(prId) | |
704 | + | let $t02750827619 = { | |
705 | + | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, pmtAmt], nil) | |
706 | + | if ($isInstanceOf(@, "(Int, Int)")) | |
707 | + | then @ | |
708 | + | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
709 | + | } | |
710 | + | if (($t02750827619 == $t02750827619)) | |
711 | + | then { | |
712 | + | let feeAmount = $t02750827619._2 | |
713 | + | let totalGet = $t02750827619._1 | |
714 | + | let totalAmount = if (if ((minOutAmount > 0)) | |
715 | + | then (minOutAmount > totalGet) | |
716 | + | else false) | |
717 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
718 | + | else totalGet | |
719 | + | let $t02780928116 = if ((outAssetId == amId)) | |
720 | + | then $Tuple4(totalAmount, 0, ((amBalance - totalAmount) - feeAmount), prBalance) | |
721 | + | else if ((outAssetId == prId)) | |
722 | + | then $Tuple4(0, totalAmount, amBalance, ((prBalance - totalAmount) - feeAmount)) | |
723 | + | else throw("invalid out asset id") | |
724 | + | let outAm = $t02780928116._1 | |
725 | + | let outPr = $t02780928116._2 | |
726 | + | let amBalanceNew = $t02780928116._3 | |
727 | + | let prBalanceNew = $t02780928116._4 | |
728 | + | let curPrX18 = cpbi(t1(prBalanceNew, prDecimals), t1(amBalanceNew, amDecimals)) | |
729 | + | let curPr = f1(curPrX18, scale8) | |
730 | + | let outAssetIdOrWaves = if ((outAssetId == "WAVES")) | |
731 | + | then unit | |
732 | + | else fromBase58String(outAssetId) | |
733 | + | let sendFeeToMatcher = if ((feeAmount > 0)) | |
734 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetIdOrWaves)] | |
735 | + | else nil | |
736 | + | let state = ([ScriptTransfer(userAddress, totalAmount, outAssetIdOrWaves), StringEntry(gau(toString(userAddress), txId58), dataGetActionInfo(outAm, outPr, pmtAmt, curPr, height, lastBlock.timestamp)), IntegerEntry(pl(), curPr), IntegerEntry(ph(height, lastBlock.timestamp), curPr)] ++ sendFeeToMatcher) | |
737 | + | if ((state == state)) | |
780 | 738 | then { | |
781 | - | let feeAmount = $t03102631137._2 | |
782 | - | let totalGet = $t03102631137._1 | |
783 | - | let totalAmount = if (if ((minOutAmount > 0)) | |
784 | - | then (minOutAmount > totalGet) | |
785 | - | else false) | |
786 | - | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
787 | - | else totalGet | |
788 | - | let $t03132731634 = if ((outAssetId == amId)) | |
789 | - | then $Tuple4(totalAmount, 0, ((amBalance - totalAmount) - feeAmount), prBalance) | |
790 | - | else if ((outAssetId == prId)) | |
791 | - | then $Tuple4(0, totalAmount, amBalance, ((prBalance - totalAmount) - feeAmount)) | |
792 | - | else throw("invalid out asset id") | |
793 | - | let outAm = $t03132731634._1 | |
794 | - | let outPr = $t03132731634._2 | |
795 | - | let amBalanceNew = $t03132731634._3 | |
796 | - | let prBalanceNew = $t03132731634._4 | |
797 | - | let curPrX18 = cpbi(t1(prBalanceNew, prDecimals), t1(amBalanceNew, amDecimals)) | |
798 | - | let curPr = f1(curPrX18, scale8) | |
799 | - | let outAssetIdOrWaves = if ((outAssetId == "WAVES")) | |
800 | - | then unit | |
801 | - | else fromBase58String(outAssetId) | |
802 | - | let sendFeeToMatcher = if ((feeAmount > 0)) | |
803 | - | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetIdOrWaves)] | |
804 | - | else nil | |
805 | - | let state = ([ScriptTransfer(userAddress, totalAmount, outAssetIdOrWaves), StringEntry(gau(toString(userAddress), txId58), dataGetActionInfo(outAm, outPr, pmtAmt, curPr, height, lastBlock.timestamp)), IntegerEntry(pl(), curPr), IntegerEntry(ph(height, lastBlock.timestamp), curPr)] ++ sendFeeToMatcher) | |
806 | - | if ((state == state)) | |
807 | - | then { | |
808 | - | let burn = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
809 | - | if ((burn == burn)) | |
810 | - | then { | |
811 | - | let $t03241932769 = { | |
812 | - | let feeAmountForCalc = if ((this == feeCollectorAddress)) | |
813 | - | then 0 | |
814 | - | else feeAmount | |
815 | - | let outInAmountAsset = if ((parseAssetId(outAssetId) == cfgAmountAssetId)) | |
816 | - | then true | |
817 | - | else false | |
818 | - | if (outInAmountAsset) | |
819 | - | then $Tuple2(-((totalGet + feeAmountForCalc)), 0) | |
820 | - | else $Tuple2(0, -((totalGet + feeAmountForCalc))) | |
821 | - | } | |
822 | - | let amountAssetBalanceDelta = $t03241932769._1 | |
823 | - | let priceAssetBalanceDelta = $t03241932769._2 | |
824 | - | let $t03277232880 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
825 | - | let refreshDLpActions = $t03277232880._1 | |
826 | - | let updatedDLp = $t03277232880._2 | |
827 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
828 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
829 | - | then $Tuple2((state ++ refreshDLpActions), totalAmount) | |
830 | - | else throw("Strict value is not equal to itself.") | |
831 | - | } | |
832 | - | else throw("Strict value is not equal to itself.") | |
833 | - | } | |
739 | + | let burn = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
740 | + | if ((burn == burn)) | |
741 | + | then $Tuple2(state, totalAmount) | |
834 | 742 | else throw("Strict value is not equal to itself.") | |
835 | 743 | } | |
836 | 744 | else throw("Strict value is not equal to itself.") | |
837 | 745 | } | |
746 | + | else throw("Strict value is not equal to itself.") | |
838 | 747 | } | |
839 | - | else throw("Strict value is not equal to itself.") | |
840 | 748 | } | |
841 | 749 | ||
842 | 750 | ||
884 | 792 | case _ => | |
885 | 793 | throw("Match error") | |
886 | 794 | } | |
887 | - | ||
888 | - | ||
889 | - | func getY (isReverse,D,poolAmountInBalance) = { | |
890 | - | let poolConfig = gpc() | |
891 | - | let amId = poolConfig[idxAmAsId] | |
892 | - | let prId = poolConfig[idxPrAsId] | |
893 | - | let n = big2 | |
894 | - | let aPrecision = parseBigIntValue(Amult) | |
895 | - | let a = (parseBigIntValue(A) * aPrecision) | |
896 | - | let xp = if ((isReverse == false)) | |
897 | - | then [(toBigInt(getAccBalance(amId)) + poolAmountInBalance), toBigInt(getAccBalance(prId))] | |
898 | - | else [(toBigInt(getAccBalance(prId)) + poolAmountInBalance), toBigInt(getAccBalance(amId))] | |
899 | - | let x = xp[0] | |
900 | - | let s = x | |
901 | - | let ann = (a * n) | |
902 | - | let c = (((((D * D) / (x * n)) * D) * aPrecision) / (ann * n)) | |
903 | - | let b = ((s + ((D * aPrecision) / ann)) - D) | |
904 | - | func calc (acc,cur) = { | |
905 | - | let $t03432734347 = acc | |
906 | - | let y = $t03432734347._1 | |
907 | - | let found = $t03432734347._2 | |
908 | - | if ((found != unit)) | |
909 | - | then acc | |
910 | - | else { | |
911 | - | let yNext = (((y * y) + c) / ((big2 * y) + b)) | |
912 | - | let yDiff = absBigInt((yNext - value(y))) | |
913 | - | if ((big1 >= yDiff)) | |
914 | - | then $Tuple2(yNext, cur) | |
915 | - | else $Tuple2(yNext, unit) | |
916 | - | } | |
917 | - | } | |
918 | - | ||
919 | - | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
920 | - | let $t03467834725 = { | |
921 | - | let $l = arr | |
922 | - | let $s = size($l) | |
923 | - | let $acc0 = $Tuple2(D, unit) | |
924 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
925 | - | then $a | |
926 | - | else calc($a, $l[$i]) | |
927 | - | ||
928 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
929 | - | then $a | |
930 | - | else throw("List size exceeds 15") | |
931 | - | ||
932 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
933 | - | } | |
934 | - | let y = $t03467834725._1 | |
935 | - | let found = $t03467834725._2 | |
936 | - | if ((found != unit)) | |
937 | - | then y | |
938 | - | else throw(("Y calculation error, Y = " + toString(y))) | |
939 | - | } | |
940 | - | ||
941 | - | ||
942 | - | @Callable(i) | |
943 | - | func calculateAmountOutForSwapREADONLY (cleanAmountIn,isReverse,feePoolAmount) = { | |
944 | - | let $t03496635390 = if ((isReverse == false)) | |
945 | - | then { | |
946 | - | let assetOut = strf(this, pa()) | |
947 | - | let poolAmountInBalance = (toBigInt(getAccBalance(strf(this, aa()))) + toBigInt(cleanAmountIn)) | |
948 | - | $Tuple2(assetOut, poolAmountInBalance) | |
949 | - | } | |
950 | - | else { | |
951 | - | let assetOut = strf(this, aa()) | |
952 | - | let poolAmountInBalance = (toBigInt(getAccBalance(strf(this, pa()))) + toBigInt(cleanAmountIn)) | |
953 | - | $Tuple2(assetOut, poolAmountInBalance) | |
954 | - | } | |
955 | - | let assetOut = $t03496635390._1 | |
956 | - | let poolAmountInBalance = $t03496635390._2 | |
957 | - | let poolConfig = gpc() | |
958 | - | let amId = poolConfig[idxAmAsId] | |
959 | - | let prId = poolConfig[idxPrAsId] | |
960 | - | let xp = [toBigInt(getAccBalance(amId)), toBigInt(getAccBalance(prId))] | |
961 | - | let D = getD(xp) | |
962 | - | let y = getY(isReverse, D, toBigInt(cleanAmountIn)) | |
963 | - | let dy = ((toBigInt(getAccBalance(assetOut)) - y) - toBigInt(1)) | |
964 | - | let totalGetRaw = max([0, toInt(dy)]) | |
965 | - | let newXp = if ((isReverse == false)) | |
966 | - | then [((toBigInt(getAccBalance(amId)) + toBigInt(cleanAmountIn)) + toBigInt(feePoolAmount)), (toBigInt(getAccBalance(prId)) - dy)] | |
967 | - | else [(toBigInt(getAccBalance(amId)) - dy), ((toBigInt(getAccBalance(prId)) + toBigInt(cleanAmountIn)) + toBigInt(feePoolAmount))] | |
968 | - | let newD = getD(newXp) | |
969 | - | let checkD = if ((newD >= D)) | |
970 | - | then true | |
971 | - | else throw(makeString(["new D is fewer error", toString(D), toString(newD)], "__")) | |
972 | - | if ((checkD == checkD)) | |
973 | - | then $Tuple2(nil, totalGetRaw) | |
974 | - | else throw("Strict value is not equal to itself.") | |
975 | - | } | |
976 | - | ||
977 | - | ||
978 | - | ||
979 | - | @Callable(i) | |
980 | - | func calculateAmountOutForSwapAndSendTokens (cleanAmountIn,isReverse,amountOutMin,addressTo,feePoolAmount) = { | |
981 | - | let swapContact = { | |
982 | - | let @ = invoke(fca, "getSwapContractREADONLY", nil, nil) | |
983 | - | if ($isInstanceOf(@, "String")) | |
984 | - | then @ | |
985 | - | else throw(($getType(@) + " couldn't be cast to String")) | |
986 | - | } | |
987 | - | let checks = [if ((value(i.payments[0]).amount >= cleanAmountIn)) | |
988 | - | then true | |
989 | - | else throwErr("Wrong amount"), if ((i.caller == addressFromStringValue(swapContact))) | |
990 | - | then true | |
991 | - | else throwErr("Permission denied")] | |
992 | - | if ((checks == checks)) | |
993 | - | then { | |
994 | - | let pmt = value(i.payments[0]) | |
995 | - | let assetIn = assetIdToString(pmt.assetId) | |
996 | - | let $t03682637220 = if ((isReverse == false)) | |
997 | - | then { | |
998 | - | let assetOut = strf(this, pa()) | |
999 | - | let poolAmountInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount) | |
1000 | - | $Tuple2(assetOut, poolAmountInBalance) | |
1001 | - | } | |
1002 | - | else { | |
1003 | - | let assetOut = strf(this, aa()) | |
1004 | - | let poolAmountInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount) | |
1005 | - | $Tuple2(assetOut, poolAmountInBalance) | |
1006 | - | } | |
1007 | - | let assetOut = $t03682637220._1 | |
1008 | - | let poolAmountInBalance = $t03682637220._2 | |
1009 | - | let poolConfig = gpc() | |
1010 | - | let amId = poolConfig[idxAmAsId] | |
1011 | - | let prId = poolConfig[idxPrAsId] | |
1012 | - | let xp = if ((isReverse == false)) | |
1013 | - | then [(toBigInt(getAccBalance(amId)) - toBigInt(value(i.payments[0]).amount)), toBigInt(getAccBalance(prId))] | |
1014 | - | else [toBigInt(getAccBalance(amId)), (toBigInt(getAccBalance(prId)) - toBigInt(value(i.payments[0]).amount))] | |
1015 | - | let D = getD(xp) | |
1016 | - | let y = getY(isReverse, D, toBigInt(0)) | |
1017 | - | let dy = ((toBigInt(getAccBalance(assetOut)) - y) - toBigInt(1)) | |
1018 | - | let totalGetRaw = max([0, toInt(dy)]) | |
1019 | - | let checkMin = if ((totalGetRaw >= amountOutMin)) | |
1020 | - | then true | |
1021 | - | else throw("Exchange result is fewer coins than expected") | |
1022 | - | if ((checkMin == checkMin)) | |
1023 | - | then { | |
1024 | - | let newXp = if ((isReverse == false)) | |
1025 | - | then [(toBigInt(getAccBalance(amId)) + toBigInt(feePoolAmount)), (toBigInt(getAccBalance(prId)) - dy)] | |
1026 | - | else [(toBigInt(getAccBalance(amId)) - dy), (toBigInt(getAccBalance(prId)) + toBigInt(feePoolAmount))] | |
1027 | - | let newD = getD(newXp) | |
1028 | - | let checkD = if ((newD >= D)) | |
1029 | - | then true | |
1030 | - | else throw("new D is fewer error") | |
1031 | - | if ((checkD == checkD)) | |
1032 | - | then $Tuple2([ScriptTransfer(addressFromStringValue(addressTo), totalGetRaw, parseAssetId(assetOut))], totalGetRaw) | |
1033 | - | else throw("Strict value is not equal to itself.") | |
1034 | - | } | |
1035 | - | else throw("Strict value is not equal to itself.") | |
1036 | - | } | |
1037 | - | else throw("Strict value is not equal to itself.") | |
1038 | - | } | |
1039 | - | ||
1040 | 795 | ||
1041 | 796 | ||
1042 | 797 | @Callable(i) | |
1094 | 849 | else if ((size(i.payments) != 2)) | |
1095 | 850 | then throw("2 pmnts expd") | |
1096 | 851 | else { | |
1097 | - | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1098 | - | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1099 | - | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amAssetPmt) | |
1100 | - | if ((amountAssetBalance == amountAssetBalance)) | |
852 | + | let e = cp(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], slip, true, false, true, 0, "") | |
853 | + | let emitLpAmt = e._2 | |
854 | + | let lpAssetId = e._7 | |
855 | + | let state = e._9 | |
856 | + | let amDiff = e._10 | |
857 | + | let prDiff = e._11 | |
858 | + | let amId = e._12 | |
859 | + | let prId = e._13 | |
860 | + | let r = invoke(fca, "emit", [emitLpAmt], nil) | |
861 | + | if ((r == r)) | |
1101 | 862 | then { | |
1102 | - | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - prAssetPmt) | |
1103 | - | if ((priceAssetBalance == priceAssetBalance)) | |
863 | + | let el = match r { | |
864 | + | case legacy: Address => | |
865 | + | invoke(legacy, "emit", [emitLpAmt], nil) | |
866 | + | case _ => | |
867 | + | unit | |
868 | + | } | |
869 | + | if ((el == el)) | |
1104 | 870 | then { | |
1105 | - | let lpAssetEmission = toBigInt(value(assetInfo(cfgLpAssetId)).quantity) | |
1106 | - | if ((lpAssetEmission == lpAssetEmission)) | |
871 | + | let sa = if ((amDiff > 0)) | |
872 | + | then invoke(slipCntr, "put", nil, [AttachedPayment(amId, amDiff)]) | |
873 | + | else nil | |
874 | + | if ((sa == sa)) | |
1107 | 875 | then { | |
1108 | - | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1109 | - | if ((currentDLp == currentDLp)) | |
876 | + | let sp = if ((prDiff > 0)) | |
877 | + | then invoke(slipCntr, "put", nil, [AttachedPayment(prId, prDiff)]) | |
878 | + | else nil | |
879 | + | if ((sp == sp)) | |
1110 | 880 | then { | |
1111 | - | let e = cp(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], slip, true, false, true, 0, "") | |
1112 | - | let emitLpAmt = e._2 | |
1113 | - | let lpAssetId = e._7 | |
1114 | - | let state = e._9 | |
1115 | - | let amDiff = e._10 | |
1116 | - | let prDiff = e._11 | |
1117 | - | let amId = e._12 | |
1118 | - | let prId = e._13 | |
1119 | - | let r = invoke(fca, "emit", [emitLpAmt], nil) | |
1120 | - | if ((r == r)) | |
881 | + | let lpTrnsfr = if (autoStake) | |
1121 | 882 | then { | |
1122 | - | let el = match r { | |
1123 | - | case legacy: Address => | |
1124 | - | invoke(legacy, "emit", [emitLpAmt], nil) | |
1125 | - | case _ => | |
1126 | - | unit | |
1127 | - | } | |
1128 | - | if ((el == el)) | |
1129 | - | then { | |
1130 | - | let sa = if ((amDiff > 0)) | |
1131 | - | then invoke(slipCntr, "put", nil, [AttachedPayment(amId, amDiff)]) | |
1132 | - | else nil | |
1133 | - | if ((sa == sa)) | |
1134 | - | then { | |
1135 | - | let sp = if ((prDiff > 0)) | |
1136 | - | then invoke(slipCntr, "put", nil, [AttachedPayment(prId, prDiff)]) | |
1137 | - | else nil | |
1138 | - | if ((sp == sp)) | |
1139 | - | then { | |
1140 | - | let lpTrnsfr = if (autoStake) | |
1141 | - | then { | |
1142 | - | let ss = invoke(stakingCntr, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
1143 | - | if ((ss == ss)) | |
1144 | - | then nil | |
1145 | - | else throw("Strict value is not equal to itself.") | |
1146 | - | } | |
1147 | - | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
1148 | - | let $t04183941981 = refreshDLpInternal(0, 0, 0) | |
1149 | - | let refreshDLpActions = $t04183941981._1 | |
1150 | - | let updatedDLp = $t04183941981._2 | |
1151 | - | let check = if ((updatedDLp >= currentDLp)) | |
1152 | - | then true | |
1153 | - | else throwErr(makeString(["updated DLp lower than current DLp", toString(amountAssetBalance), toString(priceAssetBalance), toString(lpAssetEmission), toString(currentDLp), toString(updatedDLp), toString(amDiff), toString(prDiff)], " ")) | |
1154 | - | if ((check == check)) | |
1155 | - | then { | |
1156 | - | let lpAssetEmissionAfter = value(assetInfo(cfgLpAssetId)).quantity | |
1157 | - | if ((lpAssetEmissionAfter == lpAssetEmissionAfter)) | |
1158 | - | then ((state ++ lpTrnsfr) ++ refreshDLpActions) | |
1159 | - | else throw("Strict value is not equal to itself.") | |
1160 | - | } | |
1161 | - | else throw("Strict value is not equal to itself.") | |
1162 | - | } | |
1163 | - | else throw("Strict value is not equal to itself.") | |
1164 | - | } | |
1165 | - | else throw("Strict value is not equal to itself.") | |
1166 | - | } | |
883 | + | let ss = invoke(stakingCntr, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
884 | + | if ((ss == ss)) | |
885 | + | then nil | |
1167 | 886 | else throw("Strict value is not equal to itself.") | |
1168 | 887 | } | |
1169 | - | else throw("Strict value is not equal to itself.") | |
888 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
889 | + | (state ++ lpTrnsfr) | |
1170 | 890 | } | |
1171 | 891 | else throw("Strict value is not equal to itself.") | |
1172 | 892 | } | |
1204 | 924 | else throwErr("exactly 1 payment are expected")] | |
1205 | 925 | if ((checks == checks)) | |
1206 | 926 | then { | |
1207 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
1208 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
1209 | - | let lpId = cfgLpAssetId | |
1210 | - | let amDecimals = cfgAmountAssetDecimals | |
1211 | - | let prDecimals = cfgPriceAssetDecimals | |
927 | + | let poolConfig = gpc() | |
928 | + | let amId = poolConfig[idxAmAsId] | |
929 | + | let prId = poolConfig[idxPrAsId] | |
930 | + | let lpId = fromBase58String(poolConfig[idxLPAsId]) | |
931 | + | let amDecimals = parseIntValue(poolConfig[idxAmtAsDcm]) | |
932 | + | let prDecimals = parseIntValue(poolConfig[idxPriceAsDcm]) | |
1212 | 933 | let userAddress = if ((i.caller == this)) | |
1213 | 934 | then i.originCaller | |
1214 | 935 | else i.caller | |
1215 | 936 | let pmt = value(i.payments[0]) | |
1216 | 937 | let pmtAssetId = toBase58String(value(pmt.assetId)) | |
1217 | 938 | let pmtAmt = pmt.amount | |
1218 | - | let currentDLp = if ((pmt.assetId == cfgAmountAssetId)) | |
1219 | - | then calcCurrentDLp(toBigInt(pmtAmt), toBigInt(0), toBigInt(0)) | |
1220 | - | else calcCurrentDLp(toBigInt(0), toBigInt(pmtAmt), toBigInt(0)) | |
1221 | - | if ((currentDLp == currentDLp)) | |
939 | + | let $t03347833636 = calcPutOneTkn(pmtAmt, pmtAssetId, toString(userAddress), toBase58String(i.transactionId), true) | |
940 | + | if (($t03347833636 == $t03347833636)) | |
1222 | 941 | then { | |
1223 | - | let $t04362243780 = calcPutOneTkn(pmtAmt, pmtAssetId, toString(userAddress), toBase58String(i.transactionId), true) | |
1224 | - | if (($t04362243780 == $t04362243780)) | |
942 | + | let feeAmount = $t03347833636._3 | |
943 | + | let state = $t03347833636._2 | |
944 | + | let estimLP = $t03347833636._1 | |
945 | + | let emitLpAmt = if (if ((minOutAmount > 0)) | |
946 | + | then (minOutAmount > estimLP) | |
947 | + | else false) | |
948 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
949 | + | else estimLP | |
950 | + | let e = invoke(fca, "emit", [emitLpAmt], nil) | |
951 | + | if ((e == e)) | |
1225 | 952 | then { | |
1226 | - | let feeAmount = $t04362243780._3 | |
1227 | - | let state = $t04362243780._2 | |
1228 | - | let estimLP = $t04362243780._1 | |
1229 | - | let emitLpAmt = if (if ((minOutAmount > 0)) | |
1230 | - | then (minOutAmount > estimLP) | |
1231 | - | else false) | |
1232 | - | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
1233 | - | else estimLP | |
1234 | - | let e = invoke(fca, "emit", [emitLpAmt], nil) | |
1235 | - | if ((e == e)) | |
953 | + | let el = match e { | |
954 | + | case legacy: Address => | |
955 | + | invoke(legacy, "emit", [emitLpAmt], nil) | |
956 | + | case _ => | |
957 | + | unit | |
958 | + | } | |
959 | + | if ((el == el)) | |
1236 | 960 | then { | |
1237 | - | let el = match e { | |
1238 | - | case legacy: Address => | |
1239 | - | invoke(legacy, "emit", [emitLpAmt], nil) | |
1240 | - | case _ => | |
1241 | - | unit | |
1242 | - | } | |
1243 | - | if ((el == el)) | |
961 | + | let lpTrnsfr = if (autoStake) | |
1244 | 962 | then { | |
1245 | - | let lpTrnsfr = if (autoStake) | |
1246 | - | then { | |
1247 | - | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpId, emitLpAmt)]) | |
1248 | - | if ((ss == ss)) | |
1249 | - | then nil | |
1250 | - | else throw("Strict value is not equal to itself.") | |
1251 | - | } | |
1252 | - | else [ScriptTransfer(i.caller, emitLpAmt, lpId)] | |
1253 | - | let sendFeeToMatcher = if ((feeAmount > 0)) | |
1254 | - | then [ScriptTransfer(feeCollectorAddress, feeAmount, fromBase58String(pmtAssetId))] | |
1255 | - | else nil | |
1256 | - | let $t04459544944 = if ((this == feeCollectorAddress)) | |
1257 | - | then $Tuple2(0, 0) | |
1258 | - | else { | |
1259 | - | let paymentInAmountAsset = if ((pmt.assetId == cfgAmountAssetId)) | |
1260 | - | then true | |
1261 | - | else false | |
1262 | - | if (paymentInAmountAsset) | |
1263 | - | then $Tuple2(-(feeAmount), 0) | |
1264 | - | else $Tuple2(0, -(feeAmount)) | |
1265 | - | } | |
1266 | - | let amountAssetBalanceDelta = $t04459544944._1 | |
1267 | - | let priceAssetBalanceDelta = $t04459544944._2 | |
1268 | - | let $t04494745055 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1269 | - | let refreshDLpActions = $t04494745055._1 | |
1270 | - | let updatedDLp = $t04494745055._2 | |
1271 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1272 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1273 | - | then $Tuple2((((state ++ lpTrnsfr) ++ sendFeeToMatcher) ++ refreshDLpActions), emitLpAmt) | |
963 | + | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpId, emitLpAmt)]) | |
964 | + | if ((ss == ss)) | |
965 | + | then nil | |
1274 | 966 | else throw("Strict value is not equal to itself.") | |
1275 | 967 | } | |
1276 | - | else throw("Strict value is not equal to itself.") | |
968 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpId)] | |
969 | + | let sendFeeToMatcher = if ((feeAmount > 0)) | |
970 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, fromBase58String(pmtAssetId))] | |
971 | + | else nil | |
972 | + | $Tuple2(((state ++ lpTrnsfr) ++ sendFeeToMatcher), emitLpAmt) | |
1277 | 973 | } | |
1278 | 974 | else throw("Strict value is not equal to itself.") | |
1279 | 975 | } | |
1293 | 989 | then throw("2 pmnts expd") | |
1294 | 990 | else { | |
1295 | 991 | let estPut = cp(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], maxSlpg, false, false, true, 0, "") | |
1296 | - | let state = estPut._9 | |
1297 | - | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1298 | - | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1299 | - | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1300 | - | if ((currentDLp == currentDLp)) | |
1301 | - | then { | |
1302 | - | let $t04608546150 = refreshDLpInternal(0, 0, 0) | |
1303 | - | let refreshDLpActions = $t04608546150._1 | |
1304 | - | let updatedDLp = $t04608546150._2 | |
1305 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1306 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1307 | - | then (state ++ refreshDLpActions) | |
1308 | - | else throw("Strict value is not equal to itself.") | |
1309 | - | } | |
1310 | - | else throw("Strict value is not equal to itself.") | |
992 | + | estPut._9 | |
1311 | 993 | } | |
1312 | 994 | ||
1313 | 995 | ||
1314 | 996 | ||
1315 | 997 | @Callable(i) | |
1316 | 998 | func get () = { | |
1317 | - | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1318 | - | if ((currentDLp == currentDLp)) | |
1319 | - | then { | |
1320 | - | let r = cg(i) | |
1321 | - | let outAmtAmt = r._1 | |
1322 | - | let outPrAmt = r._2 | |
1323 | - | let pmtAmt = r._3 | |
1324 | - | let pmtAssetId = r._4 | |
1325 | - | let state = r._5 | |
1326 | - | let b = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1327 | - | if ((b == b)) | |
1328 | - | then { | |
1329 | - | let $t04732347405 = refreshDLpInternal(-(outAmtAmt), -(outPrAmt), 0) | |
1330 | - | let refreshDLpActions = $t04732347405._1 | |
1331 | - | let updatedDLp = $t04732347405._2 | |
1332 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1333 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1334 | - | then (state ++ refreshDLpActions) | |
1335 | - | else throw("Strict value is not equal to itself.") | |
1336 | - | } | |
1337 | - | else throw("Strict value is not equal to itself.") | |
1338 | - | } | |
999 | + | let r = cg(i) | |
1000 | + | let outAmtAmt = r._1 | |
1001 | + | let outPrAmt = r._2 | |
1002 | + | let pmtAmt = r._3 | |
1003 | + | let pmtAssetId = r._4 | |
1004 | + | let state = r._5 | |
1005 | + | let b = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1006 | + | if ((b == b)) | |
1007 | + | then state | |
1339 | 1008 | else throw("Strict value is not equal to itself.") | |
1340 | 1009 | } | |
1341 | 1010 | ||
1363 | 1032 | else throwErr("exactly 1 payment are expected")] | |
1364 | 1033 | if ((checks == checks)) | |
1365 | 1034 | then { | |
1366 | - | let $ | |
1367 | - | let state = $ | |
1368 | - | let totalAmount = $ | |
1035 | + | let $t03625836413 = getOneTknV2Internal(outAssetId, minOutAmount, i.payments, i.caller, i.originCaller, i.transactionId) | |
1036 | + | let state = $t03625836413._1 | |
1037 | + | let totalAmount = $t03625836413._2 | |
1369 | 1038 | $Tuple2(state, totalAmount) | |
1370 | 1039 | } | |
1371 | 1040 | else throw("Strict value is not equal to itself.") | |
1374 | 1043 | ||
1375 | 1044 | ||
1376 | 1045 | @Callable(i) | |
1377 | - | func refreshDLp () = { | |
1378 | - | let lastRefreshedBlockHeight = valueOrElse(getInteger(keyDLpRefreshedHeight), 0) | |
1379 | - | let checkLastRefreshedBlockHeight = if (((height - lastRefreshedBlockHeight) >= dLpRefreshDelay)) | |
1380 | - | then unit | |
1381 | - | else throwErr(makeString([toString(dLpRefreshDelay), " blocks have not passed since the previous call"], "")) | |
1382 | - | if ((checkLastRefreshedBlockHeight == checkLastRefreshedBlockHeight)) | |
1383 | - | then { | |
1384 | - | let dLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyDLp), "0")), fmtErr("invalid dLp")) | |
1385 | - | let $t04870248766 = refreshDLpInternal(0, 0, 0) | |
1386 | - | let dLpUpdateActions = $t04870248766._1 | |
1387 | - | let updatedDLp = $t04870248766._2 | |
1388 | - | let actions = if ((dLp != updatedDLp)) | |
1389 | - | then dLpUpdateActions | |
1390 | - | else throwErr("nothing to refresh") | |
1391 | - | $Tuple2(actions, toString(updatedDLp)) | |
1392 | - | } | |
1393 | - | else throw("Strict value is not equal to itself.") | |
1394 | - | } | |
1395 | - | ||
1396 | - | ||
1397 | - | ||
1398 | - | @Callable(i) | |
1399 | 1046 | func getOneTknV2READONLY (outAssetId,lpAssetAmount) = { | |
1400 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
1401 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
1402 | - | let lpId = toBase58String(value(cfgLpAssetId)) | |
1047 | + | let poolConfig = gpc() | |
1048 | + | let amId = poolConfig[idxAmAsId] | |
1049 | + | let prId = poolConfig[idxPrAsId] | |
1050 | + | let lpId = poolConfig[idxLPAsId] | |
1403 | 1051 | let xp = [toBigInt(getAccBalance(amId)), toBigInt(getAccBalance(prId))] | |
1404 | 1052 | let lpEmission = toBigInt(valueOrErrorMessage(assetInfo(fromBase58String(lpId)), "invalid lp asset").quantity) | |
1405 | 1053 | let D0 = getD(xp) | |
1412 | 1060 | let newY = getYD(xp, index, D1) | |
1413 | 1061 | let dy = (xp[index] - newY) | |
1414 | 1062 | let totalGetRaw = max([0, toInt((dy - big1))]) | |
1415 | - | let $ | |
1416 | - | let totalGet = $ | |
1417 | - | let feeAmount = $ | |
1063 | + | let $t03720337258 = takeFee(totalGetRaw, outFee) | |
1064 | + | let totalGet = $t03720337258._1 | |
1065 | + | let feeAmount = $t03720337258._2 | |
1418 | 1066 | $Tuple2(nil, $Tuple2(totalGet, feeAmount)) | |
1419 | 1067 | } | |
1420 | 1068 | ||
1422 | 1070 | ||
1423 | 1071 | @Callable(i) | |
1424 | 1072 | func getOneTknV2WithBonusREADONLY (outAssetId,lpAssetAmount) = { | |
1425 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
1426 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
1427 | - | let lpId = toBase58String(value(cfgLpAssetId)) | |
1073 | + | let poolConfig = gpc() | |
1074 | + | let amId = poolConfig[idxAmAsId] | |
1075 | + | let prId = poolConfig[idxPrAsId] | |
1076 | + | let lpId = poolConfig[idxLPAsId] | |
1428 | 1077 | let amBalance = getAccBalance(amId) | |
1429 | 1078 | let prBalance = getAccBalance(prId) | |
1430 | - | let $ | |
1079 | + | let $t03760337718 = { | |
1431 | 1080 | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, lpAssetAmount], nil) | |
1432 | 1081 | if ($isInstanceOf(@, "(Int, Int)")) | |
1433 | 1082 | then @ | |
1434 | 1083 | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
1435 | 1084 | } | |
1436 | - | let totalGet = $ | |
1437 | - | let feeAmount = $ | |
1085 | + | let totalGet = $t03760337718._1 | |
1086 | + | let feeAmount = $t03760337718._2 | |
1438 | 1087 | let r = ego("", lpId, lpAssetAmount, this) | |
1439 | 1088 | let outAmAmt = r._1 | |
1440 | 1089 | let outPrAmt = r._2 | |
1462 | 1111 | else if ((noLessThenPriceAsset > outPrAmt)) | |
1463 | 1112 | then throw(((("Failed: " + toString(outPrAmt)) + " < ") + toString(noLessThenPriceAsset))) | |
1464 | 1113 | else { | |
1465 | - | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1466 | - | if ((currentDLp == currentDLp)) | |
1467 | - | then { | |
1468 | - | let burnLPAssetOnFactory = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1469 | - | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1470 | - | then { | |
1471 | - | let $t05148751568 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1472 | - | let refreshDLpActions = $t05148751568._1 | |
1473 | - | let updatedDLp = $t05148751568._2 | |
1474 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1475 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1476 | - | then (state ++ refreshDLpActions) | |
1477 | - | else throw("Strict value is not equal to itself.") | |
1478 | - | } | |
1479 | - | else throw("Strict value is not equal to itself.") | |
1480 | - | } | |
1114 | + | let burnLPAssetOnFactory = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1115 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1116 | + | then state | |
1481 | 1117 | else throw("Strict value is not equal to itself.") | |
1482 | 1118 | } | |
1483 | 1119 | } | |
1491 | 1127 | else true | |
1492 | 1128 | if ((checkPayments == checkPayments)) | |
1493 | 1129 | then { | |
1130 | + | let cfg = gpc() | |
1494 | 1131 | let factoryCfg = gfc() | |
1495 | - | let lpAssetId = | |
1132 | + | let lpAssetId = fromBase58String(cfg[idxLPAsId]) | |
1496 | 1133 | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1497 | - | let | |
1498 | - | if (( | |
1134 | + | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), amount], nil) | |
1135 | + | if ((unstakeInv == unstakeInv)) | |
1499 | 1136 | then { | |
1500 | - | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), amount], nil) | |
1501 | - | if ((unstakeInv == unstakeInv)) | |
1137 | + | let r = ego(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
1138 | + | let sts = parseIntValue(r._9) | |
1139 | + | let state = r._10 | |
1140 | + | let v = if (if (igs()) | |
1141 | + | then true | |
1142 | + | else (sts == PoolShutdown)) | |
1143 | + | then throw(("Blocked: " + toString(sts))) | |
1144 | + | else true | |
1145 | + | if ((v == v)) | |
1502 | 1146 | then { | |
1503 | - | let r = ego(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
1504 | - | let outAmAmt = r._1 | |
1505 | - | let outPrAmt = r._2 | |
1506 | - | let sts = parseIntValue(r._9) | |
1507 | - | let state = r._10 | |
1508 | - | let v = if (if (igs()) | |
1509 | - | then true | |
1510 | - | else (sts == PoolShutdown)) | |
1511 | - | then throw(("Blocked: " + toString(sts))) | |
1512 | - | else true | |
1513 | - | if ((v == v)) | |
1514 | - | then { | |
1515 | - | let burnA = invoke(fca, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1516 | - | if ((burnA == burnA)) | |
1517 | - | then { | |
1518 | - | let $t05259552676 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1519 | - | let refreshDLpActions = $t05259552676._1 | |
1520 | - | let updatedDLp = $t05259552676._2 | |
1521 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1522 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1523 | - | then (state ++ refreshDLpActions) | |
1524 | - | else throw("Strict value is not equal to itself.") | |
1525 | - | } | |
1526 | - | else throw("Strict value is not equal to itself.") | |
1527 | - | } | |
1147 | + | let burnA = invoke(fca, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1148 | + | if ((burnA == burnA)) | |
1149 | + | then state | |
1528 | 1150 | else throw("Strict value is not equal to itself.") | |
1529 | 1151 | } | |
1530 | 1152 | else throw("Strict value is not equal to itself.") | |
1548 | 1170 | else throw("no payments are expected")] | |
1549 | 1171 | if ((checks == checks)) | |
1550 | 1172 | then { | |
1551 | - | let | |
1552 | - | if (( | |
1173 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1174 | + | if ((unstakeInv == unstakeInv)) | |
1553 | 1175 | then { | |
1554 | - | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1555 | - | if ((unstakeInv == unstakeInv)) | |
1176 | + | let res = ego(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller) | |
1177 | + | let outAmAmt = res._1 | |
1178 | + | let outPrAmt = res._2 | |
1179 | + | let state = res._10 | |
1180 | + | let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset)) | |
1181 | + | then true | |
1182 | + | else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset)) | |
1183 | + | then true | |
1184 | + | else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))] | |
1185 | + | if ((checkAmounts == checkAmounts)) | |
1556 | 1186 | then { | |
1557 | - | let res = ego(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller) | |
1558 | - | let outAmAmt = res._1 | |
1559 | - | let outPrAmt = res._2 | |
1560 | - | let state = res._10 | |
1561 | - | let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset)) | |
1562 | - | then true | |
1563 | - | else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset)) | |
1564 | - | then true | |
1565 | - | else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))] | |
1566 | - | if ((checkAmounts == checkAmounts)) | |
1567 | - | then { | |
1568 | - | let burnLPAssetOnFactory = invoke(fca, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1569 | - | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1570 | - | then { | |
1571 | - | let $t05392754008 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1572 | - | let refreshDLpActions = $t05392754008._1 | |
1573 | - | let updatedDLp = $t05392754008._2 | |
1574 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1575 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1576 | - | then (state ++ refreshDLpActions) | |
1577 | - | else throw("Strict value is not equal to itself.") | |
1578 | - | } | |
1579 | - | else throw("Strict value is not equal to itself.") | |
1580 | - | } | |
1187 | + | let burnLPAssetOnFactory = invoke(fca, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1188 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1189 | + | then state | |
1581 | 1190 | else throw("Strict value is not equal to itself.") | |
1582 | 1191 | } | |
1583 | 1192 | else throw("Strict value is not equal to itself.") | |
1611 | 1220 | else throwErr("no payments are expected")] | |
1612 | 1221 | if ((checks == checks)) | |
1613 | 1222 | then { | |
1223 | + | let cfg = gpc() | |
1614 | 1224 | let factoryCfg = gfc() | |
1615 | - | let lpAssetId = | |
1225 | + | let lpAssetId = fromBase58String(cfg[idxLPAsId]) | |
1616 | 1226 | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1617 | - | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), unstakeAmount], nil) | |
1227 | + | let userAddress = i.caller | |
1228 | + | let lpAssetRecipientAddress = this | |
1229 | + | let unstakeInv = invoke(staking, "unstakeINTERNAL", [lpAssetId, unstakeAmount, userAddress.bytes, lpAssetRecipientAddress.bytes], nil) | |
1618 | 1230 | if ((unstakeInv == unstakeInv)) | |
1619 | 1231 | then { | |
1620 | - | let $ | |
1621 | - | let state = $ | |
1622 | - | let totalAmount = $ | |
1232 | + | let $t04168341871 = getOneTknV2Internal(outAssetId, minOutAmount, [AttachedPayment(lpAssetId, unstakeAmount)], i.caller, i.originCaller, i.transactionId) | |
1233 | + | let state = $t04168341871._1 | |
1234 | + | let totalAmount = $t04168341871._2 | |
1623 | 1235 | $Tuple2(state, totalAmount) | |
1624 | 1236 | } | |
1625 | 1237 | else throw("Strict value is not equal to itself.") | |
1631 | 1243 | ||
1632 | 1244 | @Callable(i) | |
1633 | 1245 | func putOneTknV2WithBonusREADONLY (paymentAmountRaw,paymentAssetId) = { | |
1634 | - | let $t05521955322 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", true) | |
1635 | - | let lpAmount = $t05521955322._1 | |
1636 | - | let state = $t05521955322._2 | |
1637 | - | let feeAmount = $t05521955322._3 | |
1638 | - | let bonus = $t05521955322._4 | |
1246 | + | let poolConfig = gpc() | |
1247 | + | let amId = poolConfig[idxAmAsId] | |
1248 | + | let prId = poolConfig[idxPrAsId] | |
1249 | + | let lpId = poolConfig[idxLPAsId] | |
1250 | + | let $t04213042233 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", true) | |
1251 | + | let lpAmount = $t04213042233._1 | |
1252 | + | let state = $t04213042233._2 | |
1253 | + | let feeAmount = $t04213042233._3 | |
1254 | + | let bonus = $t04213042233._4 | |
1639 | 1255 | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1640 | 1256 | } | |
1641 | 1257 | ||
1643 | 1259 | ||
1644 | 1260 | @Callable(i) | |
1645 | 1261 | func putOneTknV2WithoutTakeFeeREADONLY (paymentAmountRaw,paymentAssetId) = { | |
1646 | - | let $t05547055574 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", false) | |
1647 | - | let lpAmount = $t05547055574._1 | |
1648 | - | let state = $t05547055574._2 | |
1649 | - | let feeAmount = $t05547055574._3 | |
1650 | - | let bonus = $t05547055574._4 | |
1262 | + | let poolConfig = gpc() | |
1263 | + | let amId = poolConfig[idxAmAsId] | |
1264 | + | let prId = poolConfig[idxPrAsId] | |
1265 | + | let lpId = poolConfig[idxLPAsId] | |
1266 | + | let $t04251242616 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", false) | |
1267 | + | let lpAmount = $t04251242616._1 | |
1268 | + | let state = $t04251242616._2 | |
1269 | + | let feeAmount = $t04251242616._3 | |
1270 | + | let bonus = $t04251242616._4 | |
1651 | 1271 | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1652 | 1272 | } | |
1653 | 1273 | ||
1732 | 1352 | match tx { | |
1733 | 1353 | case order: Order => | |
1734 | 1354 | let matcherPub = mp() | |
1735 | - | let $t05836658435 = validateMatcherOrderAllowed(order) | |
1736 | - | let orderValid = $t05836658435._1 | |
1737 | - | let orderValidInfo = $t05836658435._2 | |
1355 | + | let orderValid = moa(order) | |
1738 | 1356 | let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
1739 | 1357 | let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub) | |
1740 | 1358 | if (if (if (orderValid) | |
1743 | 1361 | then matcherValid | |
1744 | 1362 | else false) | |
1745 | 1363 | then true | |
1746 | - | else | |
1364 | + | else toe(orderValid, senderValid, matcherValid) | |
1747 | 1365 | case s: SetScriptTransaction => | |
1748 | - | if (sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)) | |
1366 | + | let newHash = blake2b256(value(s.script)) | |
1367 | + | let allowedHash = fromBase64String(value(getString(fca, keyAllowedLpStableScriptHash()))) | |
1368 | + | let currentHash = scriptHash(this) | |
1369 | + | if (if ((allowedHash == newHash)) | |
1370 | + | then (currentHash != newHash) | |
1371 | + | else false) | |
1749 | 1372 | then true | |
1750 | - | else { | |
1751 | - | let newHash = blake2b256(value(s.script)) | |
1752 | - | let allowedHash = fromBase64String(value(getString(fca, keyAllowedLpStableScriptHash()))) | |
1753 | - | let currentHash = scriptHash(this) | |
1754 | - | if ((allowedHash == newHash)) | |
1755 | - | then (currentHash != newHash) | |
1756 | - | else false | |
1757 | - | } | |
1373 | + | else sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1758 | 1374 | case _ => | |
1759 | 1375 | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1760 | 1376 | } |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let scale8 = 100000000 | |
5 | 5 | ||
6 | 6 | let scale8BigInt = toBigInt(100000000) | |
7 | 7 | ||
8 | 8 | let scale18 = toBigInt(1000000000000000000) | |
9 | 9 | ||
10 | 10 | let zeroBigInt = toBigInt(0) | |
11 | 11 | ||
12 | 12 | let big0 = toBigInt(0) | |
13 | 13 | ||
14 | 14 | let big1 = toBigInt(1) | |
15 | 15 | ||
16 | 16 | let big2 = toBigInt(2) | |
17 | - | ||
18 | - | let big3 = toBigInt(3) | |
19 | - | ||
20 | - | let big4 = toBigInt(4) | |
21 | 17 | ||
22 | 18 | let slippage4D = toBigInt((scale8 - ((scale8 * 1) / scale8))) | |
23 | 19 | ||
24 | 20 | let wavesString = "WAVES" | |
25 | 21 | ||
26 | 22 | let Amult = "100" | |
27 | 23 | ||
28 | 24 | let Dconv = "1" | |
29 | 25 | ||
30 | 26 | let SEP = "__" | |
31 | 27 | ||
32 | 28 | let EMPTY = "" | |
33 | 29 | ||
34 | 30 | let PoolActive = 1 | |
35 | 31 | ||
36 | 32 | let PoolPutDis = 2 | |
37 | 33 | ||
38 | 34 | let PoolMatcherDis = 3 | |
39 | 35 | ||
40 | 36 | let PoolShutdown = 4 | |
41 | 37 | ||
42 | 38 | let idxPoolAddress = 1 | |
43 | 39 | ||
44 | 40 | let idxPoolSt = 2 | |
45 | 41 | ||
46 | 42 | let idxLPAsId = 3 | |
47 | 43 | ||
48 | 44 | let idxAmAsId = 4 | |
49 | 45 | ||
50 | 46 | let idxPrAsId = 5 | |
51 | 47 | ||
52 | 48 | let idxAmtAsDcm = 6 | |
53 | 49 | ||
54 | 50 | let idxPriceAsDcm = 7 | |
55 | 51 | ||
56 | 52 | let idxIAmtAsId = 8 | |
57 | 53 | ||
58 | 54 | let idxIPriceAsId = 9 | |
59 | 55 | ||
60 | 56 | let idxFactStakCntr = 1 | |
61 | 57 | ||
62 | 58 | let idxFactoryRestCntr = 6 | |
63 | 59 | ||
64 | 60 | let idxFactSlippCntr = 7 | |
65 | 61 | ||
66 | 62 | let idxFactGwxRewCntr = 10 | |
67 | 63 | ||
68 | 64 | let feeDefault = fraction(10, scale8, 10000) | |
69 | 65 | ||
70 | 66 | func t1 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) | |
71 | 67 | ||
72 | 68 | ||
73 | - | func t1BigInt (origVal,origScaleMult) = fraction(origVal, scale18, origScaleMult) | |
74 | - | ||
75 | - | ||
76 | 69 | func f1 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18)) | |
77 | - | ||
78 | - | ||
79 | - | func fromX18Round (val,resultScaleMult,round) = toInt(fraction(val, toBigInt(resultScaleMult), scale18, round)) | |
80 | - | ||
81 | - | ||
82 | - | func t2 (origVal,origScaleMult) = fraction(origVal, scale18, toBigInt(origScaleMult)) | |
83 | - | ||
84 | - | ||
85 | - | func f2 (val,resultScaleMult) = fraction(val, toBigInt(resultScaleMult), scale18) | |
86 | 70 | ||
87 | 71 | ||
88 | 72 | func ts (amt,resScale,curScale) = fraction(amt, resScale, curScale) | |
89 | 73 | ||
90 | 74 | ||
91 | 75 | func abs (val) = if ((zeroBigInt > val)) | |
92 | 76 | then -(val) | |
93 | 77 | else val | |
94 | 78 | ||
95 | 79 | ||
96 | 80 | func absBigInt (val) = if ((zeroBigInt > val)) | |
97 | 81 | then -(val) | |
98 | 82 | else val | |
99 | 83 | ||
100 | 84 | ||
101 | 85 | func fc () = "%s__factoryContract" | |
102 | 86 | ||
103 | 87 | ||
104 | 88 | func mpk () = "%s__managerPublicKey" | |
105 | 89 | ||
106 | 90 | ||
107 | 91 | func pmpk () = "%s__pendingManagerPublicKey" | |
108 | 92 | ||
109 | 93 | ||
110 | 94 | func pl () = "%s%s__price__last" | |
111 | 95 | ||
112 | 96 | ||
113 | 97 | func ph (h,t) = makeString(["%s%s%d%d__price__history", toString(h), toString(t)], SEP) | |
114 | 98 | ||
115 | 99 | ||
116 | 100 | func pau (ua,txId) = ((("%s%s%s__P__" + ua) + "__") + txId) | |
117 | 101 | ||
118 | 102 | ||
119 | 103 | func gau (ua,txId) = ((("%s%s%s__G__" + ua) + "__") + txId) | |
120 | 104 | ||
121 | 105 | ||
122 | 106 | func aa () = "%s__amountAsset" | |
123 | 107 | ||
124 | 108 | ||
125 | 109 | func pa () = "%s__priceAsset" | |
126 | 110 | ||
127 | 111 | ||
128 | 112 | func amp () = "%s__amp" | |
129 | 113 | ||
130 | 114 | ||
131 | 115 | func ada () = "%s__addonAddr" | |
132 | 116 | ||
133 | 117 | ||
134 | - | let keyFee = "%s__fee" | |
135 | - | ||
136 | - | let fee = valueOrElse(getInteger(this, keyFee), feeDefault) | |
137 | - | ||
138 | - | let keyDLp = makeString(["%s", "dLp"], SEP) | |
139 | - | ||
140 | - | let keyDLpRefreshedHeight = makeString(["%s", "dLpRefreshedHeight"], SEP) | |
141 | - | ||
142 | - | let keyDLpRefreshDelay = makeString(["%s", "refreshDLpDelay"], SEP) | |
143 | - | ||
144 | - | let dLpRefreshDelayDefault = 30 | |
145 | - | ||
146 | - | let dLpRefreshDelay = valueOrElse(getInteger(this, keyDLpRefreshDelay), dLpRefreshDelayDefault) | |
147 | - | ||
148 | 118 | func fcfg () = "%s__factoryConfig" | |
149 | 119 | ||
150 | 120 | ||
151 | 121 | func mtpk () = "%s%s__matcher__publicKey" | |
152 | 122 | ||
153 | 123 | ||
154 | 124 | func pc (iAmtAs,iPrAs) = (((("%d%d%s__" + iAmtAs) + "__") + iPrAs) + "__config") | |
155 | 125 | ||
156 | 126 | ||
157 | 127 | func mba (bAStr) = ("%s%s%s__mappings__baseAsset2internalId__" + bAStr) | |
158 | 128 | ||
159 | 129 | ||
160 | 130 | func aps () = "%s__shutdown" | |
161 | 131 | ||
162 | 132 | ||
163 | 133 | func keyAllowedLpStableScriptHash () = "%s__allowedLpStableScriptHash" | |
164 | 134 | ||
165 | 135 | ||
166 | 136 | func keyFeeCollectorAddress () = "%s__feeCollectorAddress" | |
167 | 137 | ||
168 | 138 | ||
169 | - | func throwOrderError (orderValid,orderValidInfo,senderValid,matcherValid) = throw((((((((("order validation failed: orderValid=" + toString(orderValid)) + " (") + orderValidInfo) + ")") + " senderValid=") + toString(senderValid)) + " matcherValid=") + toString(matcherValid))) | |
139 | + | func toe (orV,sendrV,matchV) = throw(((((("Failed: ordValid=" + toString(orV)) + " sndrValid=") + toString(sendrV)) + " mtchrValid=") + toString(matchV))) | |
140 | + | ||
141 | + | ||
142 | + | func str (val) = match val { | |
143 | + | case valStr: String => | |
144 | + | valStr | |
145 | + | case _ => | |
146 | + | throw("fail cast to String") | |
147 | + | } | |
170 | 148 | ||
171 | 149 | ||
172 | 150 | func strf (addr,key) = valueOrErrorMessage(getString(addr, key), makeString(["mandatory ", toString(addr), ".", key, " not defined"], "")) | |
173 | 151 | ||
174 | 152 | ||
175 | 153 | func intf (addr,key) = valueOrErrorMessage(getInteger(addr, key), makeString(["mandatory ", toString(addr), ".", key, " not defined"], "")) | |
176 | 154 | ||
177 | 155 | ||
178 | 156 | func throwErr (msg) = throw(makeString(["lp_stable.ride:", msg], " ")) | |
179 | - | ||
180 | - | ||
181 | - | func fmtErr (msg) = makeString(["lp_stable.ride:", msg], " ") | |
182 | 157 | ||
183 | 158 | ||
184 | 159 | let fca = addressFromStringValue(strf(this, fc())) | |
185 | 160 | ||
186 | 161 | let inFee = { | |
187 | 162 | let @ = invoke(fca, "getInFeeREADONLY", [toString(this)], nil) | |
188 | 163 | if ($isInstanceOf(@, "Int")) | |
189 | 164 | then @ | |
190 | 165 | else throw(($getType(@) + " couldn't be cast to Int")) | |
191 | 166 | } | |
192 | 167 | ||
193 | 168 | let outFee = { | |
194 | 169 | let @ = invoke(fca, "getOutFeeREADONLY", [toString(this)], nil) | |
195 | 170 | if ($isInstanceOf(@, "Int")) | |
196 | 171 | then @ | |
197 | 172 | else throw(($getType(@) + " couldn't be cast to Int")) | |
198 | 173 | } | |
199 | 174 | ||
200 | 175 | let A = strf(this, amp()) | |
201 | 176 | ||
202 | 177 | func igs () = valueOrElse(getBoolean(fca, aps()), false) | |
203 | 178 | ||
204 | 179 | ||
205 | 180 | func mp () = fromBase58String(strf(fca, mtpk())) | |
206 | 181 | ||
207 | 182 | ||
208 | 183 | let feeCollectorAddress = addressFromStringValue(strf(fca, keyFeeCollectorAddress())) | |
209 | 184 | ||
210 | 185 | func gpc () = { | |
211 | 186 | let amtAs = strf(this, aa()) | |
212 | 187 | let priceAs = strf(this, pa()) | |
213 | 188 | let iPriceAs = intf(fca, mba(priceAs)) | |
214 | 189 | let iAmtAs = intf(fca, mba(amtAs)) | |
215 | 190 | split(strf(fca, pc(toString(iAmtAs), toString(iPriceAs))), SEP) | |
216 | 191 | } | |
217 | 192 | ||
218 | 193 | ||
219 | 194 | func parseAssetId (input) = if ((input == wavesString)) | |
220 | 195 | then unit | |
221 | 196 | else fromBase58String(input) | |
222 | 197 | ||
223 | 198 | ||
224 | 199 | func assetIdToString (input) = if ((input == unit)) | |
225 | 200 | then wavesString | |
226 | 201 | else toBase58String(value(input)) | |
227 | 202 | ||
228 | 203 | ||
229 | - | func parsePoolConfig (poolConfig) = $ | |
204 | + | func parsePoolConfig (poolConfig) = $Tuple7(addressFromStringValue(poolConfig[idxPoolAddress]), parseIntValue(poolConfig[idxPoolSt]), fromBase58String(poolConfig[idxLPAsId]), parseAssetId(poolConfig[idxAmAsId]), parseAssetId(poolConfig[idxPrAsId]), parseIntValue(poolConfig[idxAmtAsDcm]), parseIntValue(poolConfig[idxPriceAsDcm])) | |
230 | 205 | ||
231 | 206 | ||
232 | 207 | let poolConfigParsed = parsePoolConfig(gpc()) | |
233 | 208 | ||
234 | - | let $ | |
209 | + | let $t069097095 = poolConfigParsed | |
235 | 210 | ||
236 | - | let cfgPoolAddress = $ | |
211 | + | let cfgPoolAddress = $t069097095._1 | |
237 | 212 | ||
238 | - | let cfgPoolStatus = $ | |
213 | + | let cfgPoolStatus = $t069097095._2 | |
239 | 214 | ||
240 | - | let cfgLpAssetId = $ | |
215 | + | let cfgLpAssetId = $t069097095._3 | |
241 | 216 | ||
242 | - | let cfgAmountAssetId = $ | |
217 | + | let cfgAmountAssetId = $t069097095._4 | |
243 | 218 | ||
244 | - | let cfgPriceAssetId = $ | |
219 | + | let cfgPriceAssetId = $t069097095._5 | |
245 | 220 | ||
246 | - | let cfgAmountAssetDecimals = $ | |
221 | + | let cfgAmountAssetDecimals = $t069097095._6 | |
247 | 222 | ||
248 | - | let cfgPriceAssetDecimals = $t079658194._7 | |
249 | - | ||
250 | - | let cfgInAmountAssedId = $t079658194._8 | |
251 | - | ||
252 | - | let cfgInPriceAssetId = $t079658194._9 | |
223 | + | let cfgPriceAssetDecimals = $t069097095._7 | |
253 | 224 | ||
254 | 225 | func gfc () = split(strf(fca, fcfg()), SEP) | |
255 | 226 | ||
256 | 227 | ||
257 | 228 | let factoryConfig = gfc() | |
258 | 229 | ||
259 | 230 | let stakingContract = valueOrErrorMessage(addressFromString(factoryConfig[idxFactStakCntr]), "Invalid staking contract address") | |
260 | 231 | ||
261 | 232 | let slipageContract = valueOrErrorMessage(addressFromString(factoryConfig[idxFactSlippCntr]), "Invalid slipage contract address") | |
262 | 233 | ||
263 | 234 | let gwxContract = valueOrErrorMessage(addressFromString(factoryConfig[idxFactGwxRewCntr]), "Invalid gwx contract address") | |
264 | 235 | ||
265 | 236 | let restContract = valueOrErrorMessage(addressFromString(factoryConfig[idxFactoryRestCntr]), "Invalid gwx contract address") | |
266 | 237 | ||
267 | 238 | func dataPutActionInfo (inAmtAssetAmt,inPriceAssetAmt,outLpAmt,price,slipByUser,slippageReal,txHeight,txTimestamp,slipageAmAmt,slipagePrAmt) = makeString(["%d%d%d%d%d%d%d%d%d%d", toString(inAmtAssetAmt), toString(inPriceAssetAmt), toString(outLpAmt), toString(price), toString(slipByUser), toString(slippageReal), toString(txHeight), toString(txTimestamp), toString(slipageAmAmt), toString(slipagePrAmt)], SEP) | |
268 | 239 | ||
269 | 240 | ||
270 | 241 | 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) | |
271 | 242 | ||
272 | 243 | ||
273 | 244 | func getAccBalance (assetId) = if ((assetId == "WAVES")) | |
274 | 245 | then wavesBalance(this).available | |
275 | 246 | else assetBalance(this, fromBase58String(assetId)) | |
276 | 247 | ||
277 | 248 | ||
278 | 249 | func cpbi (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18) | |
279 | - | ||
280 | - | ||
281 | - | func cpbir (prAmtX18,amAmtX18,round) = fraction(prAmtX18, scale18, amAmtX18, round) | |
282 | 250 | ||
283 | 251 | ||
284 | 252 | func vad (A1,A2,slippage) = { | |
285 | 253 | let diff = fraction((A1 - A2), scale8BigInt, A2) | |
286 | 254 | let pass = ((slippage - abs(diff)) > zeroBigInt) | |
287 | 255 | if (!(pass)) | |
288 | 256 | then throw(("Big slpg: " + toString(diff))) | |
289 | 257 | else $Tuple2(pass, min([A1, A2])) | |
290 | 258 | } | |
291 | 259 | ||
292 | 260 | ||
293 | 261 | func vd (D1,D0,slpg) = { | |
294 | 262 | let diff = fraction(D0, scale8BigInt, D1) | |
295 | 263 | let fail = (slpg > diff) | |
296 | 264 | if (if (fail) | |
297 | 265 | then true | |
298 | 266 | else (D0 > D1)) | |
299 | 267 | then throw(((((((toString(D0) + " ") + toString(D1)) + " ") + toString(diff)) + " ") + toString(slpg))) | |
300 | 268 | else fail | |
301 | 269 | } | |
302 | 270 | ||
303 | 271 | ||
304 | 272 | func pcp (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
305 | 273 | let amtAsAmtX18 = t1(amAmt, amAssetDcm) | |
306 | 274 | let prAsAmtX18 = t1(prAmt, prAssetDcm) | |
307 | 275 | cpbi(prAsAmtX18, amtAsAmtX18) | |
308 | 276 | } | |
309 | 277 | ||
310 | 278 | ||
311 | 279 | func calcPrices (amAmt,prAmt,lpAmt) = { | |
312 | - | let amtAsDcm = cfgAmountAssetDecimals | |
313 | - | let prAsDcm = cfgPriceAssetDecimals | |
280 | + | let cfg = gpc() | |
281 | + | let amtAsDcm = parseIntValue(cfg[idxAmtAsDcm]) | |
282 | + | let prAsDcm = parseIntValue(cfg[idxPriceAsDcm]) | |
314 | 283 | let priceX18 = pcp(amtAsDcm, prAsDcm, amAmt, prAmt) | |
315 | 284 | let amAmtX18 = t1(amAmt, amtAsDcm) | |
316 | 285 | let prAmtX18 = t1(prAmt, prAsDcm) | |
317 | 286 | let lpAmtX18 = t1(lpAmt, scale8) | |
318 | 287 | let lpPrInAmAsX18 = cpbi(amAmtX18, lpAmtX18) | |
319 | 288 | let lpPrInPrAsX18 = cpbi(prAmtX18, lpAmtX18) | |
320 | 289 | [priceX18, lpPrInAmAsX18, lpPrInPrAsX18] | |
321 | 290 | } | |
322 | 291 | ||
323 | 292 | ||
324 | 293 | func calculatePrices (amAmt,prAmt,lpAmt) = { | |
325 | 294 | let p = calcPrices(amAmt, prAmt, lpAmt) | |
326 | 295 | [f1(p[0], scale8), f1(p[1], scale8), f1(p[2], scale8)] | |
327 | 296 | } | |
328 | 297 | ||
329 | 298 | ||
330 | 299 | func takeFee (amount,fee) = { | |
331 | 300 | let feeAmount = if ((fee == 0)) | |
332 | 301 | then 0 | |
333 | 302 | else fraction(amount, fee, scale8) | |
334 | 303 | $Tuple2((amount - feeAmount), feeAmount) | |
335 | 304 | } | |
336 | 305 | ||
337 | 306 | ||
338 | - | func getD (xp) = { | |
339 | - | let xp0 = xp[0] | |
340 | - | let xp1 = xp[1] | |
341 | - | let s = (xp0 + xp1) | |
342 | - | if ((s == big0)) | |
343 | - | then big0 | |
344 | - | else { | |
345 | - | let a = parseIntValue(A) | |
346 | - | let ann = (a * 2) | |
347 | - | let p = fraction(xp0, xp1, big1) | |
348 | - | let xp0_xp1_n_n = fraction(p, big4, big1) | |
349 | - | let ann_s = fraction(toBigInt(ann), s, big1) | |
350 | - | let ann_1 = toBigInt((ann - 1)) | |
351 | - | func calcDNext (d) = { | |
352 | - | let dd = fraction(d, d, big1) | |
353 | - | let ddd = fraction(dd, d, big1) | |
354 | - | let dp = fraction(ddd, big1, xp0_xp1_n_n) | |
355 | - | fraction((ann_s + fraction(dp, big2, big1)), d, (fraction(ann_1, d, big1) + fraction(big3, dp, big1))) | |
356 | - | } | |
357 | - | ||
358 | - | func calc (acc,i) = if (acc._2) | |
359 | - | then acc | |
360 | - | else { | |
361 | - | let d = acc._1 | |
362 | - | let dNext = calcDNext(d) | |
363 | - | let dDiffRaw = (dNext - value(d)) | |
364 | - | let dDiff = if ((big0 > dDiffRaw)) | |
365 | - | then -(dDiffRaw) | |
366 | - | else dDiffRaw | |
367 | - | if ((big1 >= dDiff)) | |
368 | - | then $Tuple2(dNext, true) | |
369 | - | else $Tuple2(dNext, false) | |
370 | - | } | |
371 | - | ||
372 | - | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] | |
373 | - | let $t01270312751 = { | |
374 | - | let $l = arr | |
375 | - | let $s = size($l) | |
376 | - | let $acc0 = $Tuple2(s, false) | |
377 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
378 | - | then $a | |
379 | - | else calc($a, $l[$i]) | |
380 | - | ||
381 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
382 | - | then $a | |
383 | - | else throw("List size exceeds 18") | |
384 | - | ||
385 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18) | |
386 | - | } | |
387 | - | let d = $t01270312751._1 | |
388 | - | let found = $t01270312751._2 | |
389 | - | if (found) | |
390 | - | then d | |
391 | - | else throw(("D calculation error, D = " + toString(d))) | |
392 | - | } | |
393 | - | } | |
394 | - | ||
395 | - | ||
396 | 307 | func ego (txId58,pmtAssetId,pmtLpAmt,userAddress) = { | |
397 | - | let lpId = cfgLpAssetId | |
398 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
399 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
400 | - | let amDcm = cfgAmountAssetDecimals | |
401 | - | let prDcm = cfgPriceAssetDecimals | |
402 | - | let sts = toString(cfgPoolStatus) | |
403 | - | let lpEmiss = valueOrErrorMessage(assetInfo(lpId), "Wrong LP id").quantity | |
404 | - | if ((toBase58String(lpId) != pmtAssetId)) | |
308 | + | let cfg = gpc() | |
309 | + | let lpId = cfg[idxLPAsId] | |
310 | + | let amId = cfg[idxAmAsId] | |
311 | + | let prId = cfg[idxPrAsId] | |
312 | + | let amDcm = parseIntValue(cfg[idxAmtAsDcm]) | |
313 | + | let prDcm = parseIntValue(cfg[idxPriceAsDcm]) | |
314 | + | let sts = cfg[idxPoolSt] | |
315 | + | let lpEmiss = valueOrErrorMessage(assetInfo(fromBase58String(lpId)), "Wrong LP id").quantity | |
316 | + | if ((lpId != pmtAssetId)) | |
405 | 317 | then throw("Wrong pmt asset") | |
406 | 318 | else { | |
407 | 319 | let amBalance = getAccBalance(amId) | |
408 | 320 | let amBalanceX18 = t1(amBalance, amDcm) | |
409 | 321 | let prBalance = getAccBalance(prId) | |
410 | 322 | let prBalanceX18 = t1(prBalance, prDcm) | |
411 | 323 | let curPriceX18 = cpbi(prBalanceX18, amBalanceX18) | |
412 | 324 | let curPrice = f1(curPriceX18, scale8) | |
413 | 325 | let pmtLpAmtX18 = t1(pmtLpAmt, scale8) | |
414 | 326 | let lpEmissX18 = t1(lpEmiss, scale8) | |
415 | 327 | let outAmAmtX18 = fraction(amBalanceX18, pmtLpAmtX18, lpEmissX18) | |
416 | 328 | let outPrAmtX18 = fraction(prBalanceX18, pmtLpAmtX18, lpEmissX18) | |
417 | - | let outAmAmt = | |
418 | - | let outPrAmt = | |
329 | + | let outAmAmt = f1(outAmAmtX18, amDcm) | |
330 | + | let outPrAmt = f1(outPrAmtX18, prDcm) | |
419 | 331 | let state = if ((txId58 == "")) | |
420 | 332 | then nil | |
421 | 333 | else [ScriptTransfer(userAddress, outAmAmt, if ((amId == "WAVES")) | |
422 | 334 | then unit | |
423 | 335 | else fromBase58String(amId)), ScriptTransfer(userAddress, outPrAmt, if ((prId == "WAVES")) | |
424 | 336 | then unit | |
425 | 337 | else fromBase58String(prId)), StringEntry(gau(toString(userAddress), txId58), dataGetActionInfo(outAmAmt, outPrAmt, pmtLpAmt, curPrice, height, lastBlock.timestamp)), IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice)] | |
426 | 338 | $Tuple10(outAmAmt, outPrAmt, amId, prId, amBalance, prBalance, lpEmiss, curPriceX18, sts, state) | |
427 | 339 | } | |
428 | 340 | } | |
429 | 341 | ||
430 | 342 | ||
431 | 343 | func epo (txId58,slippage,inAmAmt,inAmId,inPrAmt,inPrId,userAddress,isEval,emitLp,isOneAsset,validateSlippage,pmtAmt,pmtId) = { | |
432 | - | let lpId = cfgLpAssetId | |
433 | - | let amIdStr = toBase58String(value(cfgAmountAssetId)) | |
434 | - | let prIdStr = toBase58String(value(cfgPriceAssetId)) | |
435 | - | let inAmIdStr = cfgInAmountAssedId | |
436 | - | let inPrIdStr = cfgInPriceAssetId | |
437 | - | let amtDcm = cfgAmountAssetDecimals | |
438 | - | let priceDcm = cfgPriceAssetDecimals | |
439 | - | let sts = toString(cfgPoolStatus) | |
344 | + | let cfg = gpc() | |
345 | + | let lpId = fromBase58String(cfg[idxLPAsId]) | |
346 | + | let amIdStr = cfg[idxAmAsId] | |
347 | + | let prIdStr = cfg[idxPrAsId] | |
348 | + | let inAmIdStr = cfg[idxIAmtAsId] | |
349 | + | let inPrIdStr = cfg[idxIPriceAsId] | |
350 | + | let amtDcm = parseIntValue(cfg[idxAmtAsDcm]) | |
351 | + | let priceDcm = parseIntValue(cfg[idxPriceAsDcm]) | |
352 | + | let sts = cfg[idxPoolSt] | |
440 | 353 | let lpEm = valueOrErrorMessage(assetInfo(lpId), "Wr lp as").quantity | |
441 | 354 | let amBalance = if (isEval) | |
442 | 355 | then getAccBalance(amIdStr) | |
443 | 356 | else if (if (isOneAsset) | |
444 | 357 | then (pmtId == amIdStr) | |
445 | 358 | else false) | |
446 | 359 | then (getAccBalance(amIdStr) - pmtAmt) | |
447 | 360 | else if (isOneAsset) | |
448 | 361 | then getAccBalance(amIdStr) | |
449 | 362 | else (getAccBalance(amIdStr) - inAmAmt) | |
450 | 363 | let prBalance = if (isEval) | |
451 | 364 | then getAccBalance(prIdStr) | |
452 | 365 | else if (if (isOneAsset) | |
453 | 366 | then (pmtId == prIdStr) | |
454 | 367 | else false) | |
455 | 368 | then (getAccBalance(prIdStr) - pmtAmt) | |
456 | 369 | else if (isOneAsset) | |
457 | 370 | then getAccBalance(prIdStr) | |
458 | 371 | else (getAccBalance(prIdStr) - inPrAmt) | |
459 | 372 | let inAmAssetAmtX18 = t1(inAmAmt, amtDcm) | |
460 | 373 | let inPrAssetAmtX18 = t1(inPrAmt, priceDcm) | |
461 | 374 | let userPriceX18 = cpbi(inPrAssetAmtX18, inAmAssetAmtX18) | |
462 | 375 | let amBalanceX18 = t1(amBalance, amtDcm) | |
463 | 376 | let prBalanceX18 = t1(prBalance, priceDcm) | |
464 | - | let D0 = getD([amBalanceX18, prBalanceX18]) | |
465 | 377 | let r = if ((lpEm == 0)) | |
466 | 378 | then { | |
467 | - | let D1 = getD([(amBalanceX18 + inAmAssetAmtX18), (prBalanceX18 + inPrAssetAmtX18)]) | |
468 | - | let checkD = if ((D1 > D0)) | |
469 | - | then true | |
470 | - | else throw("D1 should be greater than D0") | |
471 | - | if ((checkD == checkD)) | |
472 | - | then { | |
473 | - | let curPriceX18 = zeroBigInt | |
474 | - | let slippageX18 = zeroBigInt | |
475 | - | let lpAmtX18 = D1 | |
476 | - | $Tuple5(f1(lpAmtX18, scale8), f1(inAmAssetAmtX18, amtDcm), f1(inPrAssetAmtX18, priceDcm), cpbi((prBalanceX18 + inPrAssetAmtX18), (amBalanceX18 + inAmAssetAmtX18)), slippageX18) | |
477 | - | } | |
478 | - | else throw("Strict value is not equal to itself.") | |
379 | + | let curPriceX18 = zeroBigInt | |
380 | + | let slippageX18 = zeroBigInt | |
381 | + | let lpAmtX18 = pow((inAmAssetAmtX18 * inPrAssetAmtX18), 0, toBigInt(5), 1, 0, DOWN) | |
382 | + | $Tuple5(f1(lpAmtX18, scale8), f1(inAmAssetAmtX18, amtDcm), f1(inPrAssetAmtX18, priceDcm), cpbi((prBalanceX18 + inPrAssetAmtX18), (amBalanceX18 + inAmAssetAmtX18)), slippageX18) | |
479 | 383 | } | |
480 | 384 | else { | |
481 | 385 | let curPriceX18 = cpbi(prBalanceX18, amBalanceX18) | |
482 | 386 | let slippageRealX18 = fraction(abs((curPriceX18 - userPriceX18)), scale18, curPriceX18) | |
483 | 387 | let slippageX18 = t1(slippage, scale8) | |
484 | 388 | if (if (if (validateSlippage) | |
485 | 389 | then (curPriceX18 != zeroBigInt) | |
486 | 390 | else false) | |
487 | 391 | then (slippageRealX18 > slippageX18) | |
488 | 392 | else false) | |
489 | 393 | then throw(((("Price slippage " + toString(slippageRealX18)) + " > ") + toString(slippageX18))) | |
490 | 394 | else { | |
491 | 395 | let lpEmissionX18 = t1(lpEm, scale8) | |
492 | - | let prViaAmX18 = fraction(inAmAssetAmtX18, | |
493 | - | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, | |
396 | + | let prViaAmX18 = fraction(inAmAssetAmtX18, curPriceX18, scale18) | |
397 | + | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, curPriceX18) | |
494 | 398 | let expectedAmts = if ((prViaAmX18 > inPrAssetAmtX18)) | |
495 | 399 | then $Tuple2(amViaPrX18, inPrAssetAmtX18) | |
496 | 400 | else $Tuple2(inAmAssetAmtX18, prViaAmX18) | |
497 | 401 | let expAmtAssetAmtX18 = expectedAmts._1 | |
498 | 402 | let expPriceAssetAmtX18 = expectedAmts._2 | |
499 | - | let D1 = getD([(amBalanceX18 + expAmtAssetAmtX18), (prBalanceX18 + expPriceAssetAmtX18)]) | |
500 | - | let checkD = if ((D1 > D0)) | |
501 | - | then true | |
502 | - | else throw("D1 should be greater than D0") | |
503 | - | if ((checkD == checkD)) | |
504 | - | then { | |
505 | - | let lpAmtX18 = fraction(lpEmissionX18, (D1 - D0), D0) | |
506 | - | $Tuple5(fromX18Round(lpAmtX18, scale8, FLOOR), fromX18Round(expAmtAssetAmtX18, amtDcm, CEILING), fromX18Round(expPriceAssetAmtX18, priceDcm, CEILING), curPriceX18, slippageX18) | |
507 | - | } | |
508 | - | else throw("Strict value is not equal to itself.") | |
403 | + | let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18) | |
404 | + | $Tuple5(f1(lpAmtX18, scale8), f1(expAmtAssetAmtX18, amtDcm), f1(expPriceAssetAmtX18, priceDcm), curPriceX18, slippageX18) | |
509 | 405 | } | |
510 | 406 | } | |
511 | 407 | let calcLpAmt = r._1 | |
512 | 408 | let calcAmAssetPmt = r._2 | |
513 | 409 | let calcPrAssetPmt = r._3 | |
514 | 410 | let curPrice = f1(r._4, scale8) | |
515 | 411 | let slippageCalc = f1(r._5, scale8) | |
516 | 412 | if ((0 >= calcLpAmt)) | |
517 | 413 | then throw("LP <= 0") | |
518 | 414 | else { | |
519 | 415 | let emitLpAmt = if (!(emitLp)) | |
520 | 416 | then 0 | |
521 | 417 | else calcLpAmt | |
522 | 418 | let amDiff = (inAmAmt - calcAmAssetPmt) | |
523 | 419 | let prDiff = (inPrAmt - calcPrAssetPmt) | |
524 | - | let $ | |
420 | + | let $t01756217907 = if (if (isOneAsset) | |
525 | 421 | then (pmtId == amIdStr) | |
526 | 422 | else false) | |
527 | 423 | then $Tuple2(pmtAmt, 0) | |
528 | 424 | else if (if (isOneAsset) | |
529 | 425 | then (pmtId == prIdStr) | |
530 | 426 | else false) | |
531 | 427 | then $Tuple2(0, pmtAmt) | |
532 | 428 | else $Tuple2(calcAmAssetPmt, calcPrAssetPmt) | |
533 | - | let writeAmAmt = $ | |
534 | - | let writePrAmt = $ | |
429 | + | let writeAmAmt = $t01756217907._1 | |
430 | + | let writePrAmt = $t01756217907._2 | |
535 | 431 | let commonState = [IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice), StringEntry(pau(userAddress, txId58), dataPutActionInfo(writeAmAmt, writePrAmt, emitLpAmt, curPrice, slippage, slippageCalc, height, lastBlock.timestamp, amDiff, prDiff))] | |
536 | 432 | $Tuple13(calcLpAmt, emitLpAmt, curPrice, amBalance, prBalance, lpEm, lpId, sts, commonState, amDiff, prDiff, inAmId, inPrId) | |
537 | 433 | } | |
538 | 434 | } | |
539 | 435 | ||
540 | 436 | ||
541 | - | func getYD (xp,i,D) = { | |
542 | - | let n = big2 | |
543 | - | let x = xp[if ((i == 0)) | |
544 | - | then 1 | |
545 | - | else 0] | |
546 | - | let aPrecision = parseBigIntValue(Amult) | |
547 | - | let a = (parseBigIntValue(A) * aPrecision) | |
548 | - | let s = x | |
549 | - | let ann = (a * n) | |
550 | - | let c = (((((D * D) / (x * n)) * D) * aPrecision) / (ann * n)) | |
551 | - | let b = ((s + ((D * aPrecision) / ann)) - D) | |
552 | - | func calc (acc,cur) = { | |
553 | - | let $t02213022150 = acc | |
554 | - | let y = $t02213022150._1 | |
555 | - | let found = $t02213022150._2 | |
556 | - | if ((found != unit)) | |
557 | - | then acc | |
558 | - | else { | |
559 | - | let yNext = (((y * y) + c) / ((big2 * y) + b)) | |
560 | - | let yDiff = absBigInt((yNext - value(y))) | |
561 | - | if ((big1 >= yDiff)) | |
562 | - | then $Tuple2(yNext, cur) | |
563 | - | else $Tuple2(yNext, unit) | |
564 | - | } | |
565 | - | } | |
566 | - | ||
567 | - | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
568 | - | let $t02245722504 = { | |
569 | - | let $l = arr | |
570 | - | let $s = size($l) | |
571 | - | let $acc0 = $Tuple2(D, unit) | |
572 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
573 | - | then $a | |
574 | - | else calc($a, $l[$i]) | |
575 | - | ||
576 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
577 | - | then $a | |
578 | - | else throw("List size exceeds 15") | |
579 | - | ||
580 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
581 | - | } | |
582 | - | let y = $t02245722504._1 | |
583 | - | let found = $t02245722504._2 | |
584 | - | if ((found != unit)) | |
585 | - | then y | |
586 | - | else throw(("Y calculation error, Y = " + toString(y))) | |
587 | - | } | |
588 | - | ||
589 | - | ||
590 | - | func calcDLp (amountBalance,priceBalance,lpEmission) = { | |
591 | - | let updatedDLp = fraction(getD([t1BigInt(amountBalance, toBigInt(cfgAmountAssetDecimals)), t1BigInt(priceBalance, toBigInt(cfgPriceAssetDecimals))]), scale18, lpEmission) | |
592 | - | if ((lpEmission == big0)) | |
593 | - | then big0 | |
594 | - | else updatedDLp | |
595 | - | } | |
596 | - | ||
597 | - | ||
598 | - | func calcCurrentDLp (amountAssetDelta,priceAssetDelta,lpAssetEmissionDelta) = { | |
599 | - | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amountAssetDelta) | |
600 | - | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - priceAssetDelta) | |
601 | - | let lpAssetEmission = (toBigInt(value(assetInfo(cfgLpAssetId)).quantity) - lpAssetEmissionDelta) | |
602 | - | let currentDLp = calcDLp(amountAssetBalance, priceAssetBalance, lpAssetEmission) | |
603 | - | currentDLp | |
604 | - | } | |
605 | - | ||
606 | - | ||
607 | - | func refreshDLpInternal (amountAssetBalanceDelta,priceAssetBalanceDelta,lpAssetEmissionDelta) = { | |
608 | - | let amountAssetBalance = (getAccBalance(assetIdToString(cfgAmountAssetId)) + amountAssetBalanceDelta) | |
609 | - | let priceAssetBalance = (getAccBalance(assetIdToString(cfgPriceAssetId)) + priceAssetBalanceDelta) | |
610 | - | let lpAssetEmission = (value(assetInfo(cfgLpAssetId)).quantity + lpAssetEmissionDelta) | |
611 | - | let updatedDLp = calcDLp(toBigInt(amountAssetBalance), toBigInt(priceAssetBalance), toBigInt(lpAssetEmission)) | |
612 | - | let actions = [IntegerEntry(keyDLpRefreshedHeight, height), StringEntry(keyDLp, toString(updatedDLp))] | |
613 | - | $Tuple2(actions, updatedDLp) | |
614 | - | } | |
615 | - | ||
616 | - | ||
617 | - | func validateUpdatedDLp (oldDLp,updatedDLp) = if ((updatedDLp >= oldDLp)) | |
618 | - | then true | |
619 | - | else throwErr("updated DLp lower than current DLp") | |
620 | - | ||
621 | - | ||
622 | - | func validateMatcherOrderAllowed (order) = { | |
623 | - | let amountAssetBalance = getAccBalance(assetIdToString(cfgAmountAssetId)) | |
624 | - | let priceAssetBalance = getAccBalance(assetIdToString(cfgPriceAssetId)) | |
625 | - | let amountAssetAmount = order.amount | |
626 | - | let priceAssetAmount = fraction(order.amount, order.price, scale8, FLOOR) | |
627 | - | let $t02470224914 = if ((order.orderType == Buy)) | |
628 | - | then $Tuple2(amountAssetAmount, -(priceAssetAmount)) | |
629 | - | else $Tuple2(-(amountAssetAmount), priceAssetAmount) | |
630 | - | let amountAssetBalanceDelta = $t02470224914._1 | |
631 | - | let priceAssetBalanceDelta = $t02470224914._2 | |
437 | + | func moa (order) = { | |
438 | + | let cfg = gpc() | |
439 | + | let amtAsId = cfg[idxAmAsId] | |
440 | + | let prAsId = cfg[idxPrAsId] | |
441 | + | let sts = parseIntValue(cfg[idxPoolSt]) | |
442 | + | let amtAsDcm = parseIntValue(cfg[idxAmtAsDcm]) | |
443 | + | let prAsDcm = parseIntValue(cfg[idxPriceAsDcm]) | |
444 | + | let accAmtAsBalance = getAccBalance(amtAsId) | |
445 | + | let accPrAsBalance = getAccBalance(prAsId) | |
446 | + | let curPriceX18 = if ((order.orderType == Buy)) | |
447 | + | then pcp(amtAsDcm, prAsDcm, (accAmtAsBalance + order.amount), accPrAsBalance) | |
448 | + | else pcp(amtAsDcm, prAsDcm, (accAmtAsBalance - order.amount), accPrAsBalance) | |
449 | + | let curPrice = f1(curPriceX18, scale8) | |
632 | 450 | if (if (if (igs()) | |
633 | 451 | then true | |
634 | - | else ( | |
452 | + | else (sts == PoolMatcherDis)) | |
635 | 453 | then true | |
636 | - | else ( | |
454 | + | else (sts == PoolShutdown)) | |
637 | 455 | then throw("Admin blocked") | |
638 | - | else if (if ((order.assetPair.amountAsset != cfgAmountAssetId)) | |
639 | - | then true | |
640 | - | else (order.assetPair.priceAsset != cfgPriceAssetId)) | |
641 | - | then throw("Wr assets") | |
642 | - | else { | |
643 | - | let dLp = parseBigIntValue(valueOrElse(getString(this, keyDLp), "0")) | |
644 | - | let $t02525625356 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
645 | - | let unusedActions = $t02525625356._1 | |
646 | - | let dLpNew = $t02525625356._2 | |
647 | - | let isOrderValid = (dLpNew >= dLp) | |
648 | - | let info = makeString(["dLp=", toString(dLp), " dLpNew=", toString(dLpNew), " amountAssetBalance=", toString(amountAssetBalance), " priceAssetBalance=", toString(priceAssetBalance), " amountAssetBalanceDelta=", toString(amountAssetBalanceDelta), " priceAssetBalanceDelta=", toString(priceAssetBalanceDelta), " height=", toString(height)], "") | |
649 | - | $Tuple2(isOrderValid, info) | |
650 | - | } | |
456 | + | else { | |
457 | + | let orAmtAsset = order.assetPair.amountAsset | |
458 | + | let orAmtAsStr = if ((orAmtAsset == unit)) | |
459 | + | then "WAVES" | |
460 | + | else toBase58String(value(orAmtAsset)) | |
461 | + | let orPrAsset = order.assetPair.priceAsset | |
462 | + | let orPrAsStr = if ((orPrAsset == unit)) | |
463 | + | then "WAVES" | |
464 | + | else toBase58String(value(orPrAsset)) | |
465 | + | if (if ((orAmtAsStr != amtAsId)) | |
466 | + | then true | |
467 | + | else (orPrAsStr != prAsId)) | |
468 | + | then throw("Wr assets") | |
469 | + | else { | |
470 | + | let orderPrice = order.price | |
471 | + | let priceDcm = fraction(scale8, prAsDcm, amtAsDcm) | |
472 | + | let castOrderPrice = ts(orderPrice, scale8, priceDcm) | |
473 | + | let isOrderPriceValid = if ((order.orderType == Buy)) | |
474 | + | then (curPrice >= castOrderPrice) | |
475 | + | else (castOrderPrice >= curPrice) | |
476 | + | true | |
477 | + | } | |
478 | + | } | |
651 | 479 | } | |
652 | 480 | ||
653 | 481 | ||
654 | 482 | func cg (i) = if ((size(i.payments) != 1)) | |
655 | 483 | then throw("1 pmnt exp") | |
656 | 484 | else { | |
657 | 485 | let pmt = value(i.payments[0]) | |
658 | 486 | let pmtAssetId = value(pmt.assetId) | |
659 | 487 | let pmtAmt = pmt.amount | |
660 | 488 | let r = ego(toBase58String(i.transactionId), toBase58String(pmtAssetId), pmtAmt, i.caller) | |
661 | 489 | let outAmAmt = r._1 | |
662 | 490 | let outPrAmt = r._2 | |
663 | 491 | let sts = parseIntValue(r._9) | |
664 | 492 | let state = r._10 | |
665 | 493 | if (if (igs()) | |
666 | 494 | then true | |
667 | 495 | else (sts == PoolShutdown)) | |
668 | 496 | then throw(("Admin blocked: " + toString(sts))) | |
669 | 497 | else $Tuple5(outAmAmt, outPrAmt, pmtAmt, pmtAssetId, state) | |
670 | 498 | } | |
671 | 499 | ||
672 | 500 | ||
673 | 501 | func cp (caller,txId,amAsPmt,prAsPmt,slippage,emitLp,isOneAsset,validateSlippage,pmtAmt,pmtId) = { | |
674 | 502 | let r = epo(txId, slippage, value(amAsPmt).amount, value(amAsPmt).assetId, value(prAsPmt).amount, value(prAsPmt).assetId, caller, (txId == ""), emitLp, isOneAsset, validateSlippage, pmtAmt, pmtId) | |
675 | 503 | let sts = parseIntValue(r._8) | |
676 | 504 | if (if (if (igs()) | |
677 | 505 | then true | |
678 | 506 | else (sts == PoolPutDis)) | |
679 | 507 | then true | |
680 | 508 | else (sts == PoolShutdown)) | |
681 | 509 | then throw(("Blocked:" + toString(sts))) | |
682 | 510 | else r | |
683 | 511 | } | |
684 | 512 | ||
685 | 513 | ||
514 | + | func getD (xp) = { | |
515 | + | let n = big2 | |
516 | + | let xp0 = xp[0] | |
517 | + | let xp1 = xp[1] | |
518 | + | let aPrecision = parseBigIntValue(Amult) | |
519 | + | let a = (parseBigIntValue(A) * aPrecision) | |
520 | + | let s = (xp0 + xp1) | |
521 | + | if ((s == big0)) | |
522 | + | then big0 | |
523 | + | else { | |
524 | + | let ann = (a * n) | |
525 | + | let xp0_xp1_n_n = (((xp0 * xp1) * n) * n) | |
526 | + | let ann_s_aPrecision = ((ann * s) / aPrecision) | |
527 | + | let ann_aPrecision = (ann - aPrecision) | |
528 | + | let n1 = (n + big1) | |
529 | + | func calc (acc,cur) = { | |
530 | + | let $t02245922479 = acc | |
531 | + | let d = $t02245922479._1 | |
532 | + | let found = $t02245922479._2 | |
533 | + | if ((found != unit)) | |
534 | + | then acc | |
535 | + | else { | |
536 | + | let dp = (((d * d) * d) / xp0_xp1_n_n) | |
537 | + | let dNext = (((ann_s_aPrecision + (dp * n)) * d) / (((ann_aPrecision * d) / aPrecision) + (n1 * dp))) | |
538 | + | let dDiff = absBigInt((dNext - value(d))) | |
539 | + | if ((big1 >= dDiff)) | |
540 | + | then $Tuple2(dNext, cur) | |
541 | + | else $Tuple2(dNext, unit) | |
542 | + | } | |
543 | + | } | |
544 | + | ||
545 | + | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
546 | + | let $t02290022947 = { | |
547 | + | let $l = arr | |
548 | + | let $s = size($l) | |
549 | + | let $acc0 = $Tuple2(s, unit) | |
550 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
551 | + | then $a | |
552 | + | else calc($a, $l[$i]) | |
553 | + | ||
554 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
555 | + | then $a | |
556 | + | else throw("List size exceeds 15") | |
557 | + | ||
558 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
559 | + | } | |
560 | + | let d = $t02290022947._1 | |
561 | + | let found = $t02290022947._2 | |
562 | + | if ((found != unit)) | |
563 | + | then d | |
564 | + | else throw(("D calculation error, D = " + toString(d))) | |
565 | + | } | |
566 | + | } | |
567 | + | ||
568 | + | ||
569 | + | func getYD (xp,i,D) = { | |
570 | + | let n = big2 | |
571 | + | let x = xp[if ((i == 0)) | |
572 | + | then 1 | |
573 | + | else 0] | |
574 | + | let aPrecision = parseBigIntValue(Amult) | |
575 | + | let a = (parseBigIntValue(A) * aPrecision) | |
576 | + | let s = x | |
577 | + | let ann = (a * n) | |
578 | + | let c = (((((D * D) / (x * n)) * D) * aPrecision) / (ann * n)) | |
579 | + | let b = ((s + ((D * aPrecision) / ann)) - D) | |
580 | + | func calc (acc,cur) = { | |
581 | + | let $t02344723467 = acc | |
582 | + | let y = $t02344723467._1 | |
583 | + | let found = $t02344723467._2 | |
584 | + | if ((found != unit)) | |
585 | + | then acc | |
586 | + | else { | |
587 | + | let yNext = (((y * y) + c) / ((big2 * y) + b)) | |
588 | + | let yDiff = absBigInt((yNext - value(y))) | |
589 | + | if ((big1 >= yDiff)) | |
590 | + | then $Tuple2(yNext, cur) | |
591 | + | else $Tuple2(yNext, unit) | |
592 | + | } | |
593 | + | } | |
594 | + | ||
595 | + | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
596 | + | let $t02377423821 = { | |
597 | + | let $l = arr | |
598 | + | let $s = size($l) | |
599 | + | let $acc0 = $Tuple2(D, unit) | |
600 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
601 | + | then $a | |
602 | + | else calc($a, $l[$i]) | |
603 | + | ||
604 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
605 | + | then $a | |
606 | + | else throw("List size exceeds 15") | |
607 | + | ||
608 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
609 | + | } | |
610 | + | let y = $t02377423821._1 | |
611 | + | let found = $t02377423821._2 | |
612 | + | if ((found != unit)) | |
613 | + | then y | |
614 | + | else throw(("Y calculation error, Y = " + toString(y))) | |
615 | + | } | |
616 | + | ||
617 | + | ||
686 | 618 | func calcPutOneTkn (pmtAmtRaw,pmtAssetId,userAddress,txId,withTakeFee) = { | |
687 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
688 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
689 | - | let lpId = cfgLpAssetId | |
690 | - | let amtDcm = cfgAmountAssetDecimals | |
691 | - | let priceDcm = cfgPriceAssetDecimals | |
692 | - | let lpAssetEmission = toBigInt(valueOrErrorMessage(assetInfo(lpId), "invalid lp asset").quantity) | |
619 | + | let poolConfig = gpc() | |
620 | + | let amId = poolConfig[idxAmAsId] | |
621 | + | let prId = poolConfig[idxPrAsId] | |
622 | + | let lpId = poolConfig[idxLPAsId] | |
623 | + | let amtDcm = parseIntValue(poolConfig[idxAmtAsDcm]) | |
624 | + | let priceDcm = parseIntValue(poolConfig[idxPriceAsDcm]) | |
625 | + | let lpAssetEmission = toBigInt(valueOrErrorMessage(assetInfo(fromBase58String(lpId)), "invalid lp asset").quantity) | |
693 | 626 | let chechEmission = if ((lpAssetEmission > big0)) | |
694 | 627 | then true | |
695 | 628 | else throw("initial deposit requires all coins") | |
696 | 629 | if ((chechEmission == chechEmission)) | |
697 | 630 | then { | |
698 | 631 | let amBalance = getAccBalance(amId) | |
699 | 632 | let prBalance = getAccBalance(prId) | |
700 | - | let $ | |
633 | + | let $t02460425066 = if ((txId == "")) | |
701 | 634 | then $Tuple2(amBalance, prBalance) | |
702 | 635 | else if ((pmtAssetId == amId)) | |
703 | 636 | then if ((pmtAmtRaw > amBalance)) | |
704 | 637 | then throw("invalid payment amount") | |
705 | 638 | else $Tuple2((amBalance - pmtAmtRaw), prBalance) | |
706 | 639 | else if ((pmtAssetId == prId)) | |
707 | 640 | then if ((pmtAmtRaw > prBalance)) | |
708 | 641 | then throw("invalid payment amount") | |
709 | 642 | else $Tuple2(amBalance, (prBalance - pmtAmtRaw)) | |
710 | 643 | else throw("wrong pmtAssetId") | |
711 | - | let amBalanceOld = $ | |
712 | - | let prBalanceOld = $ | |
713 | - | let $ | |
644 | + | let amBalanceOld = $t02460425066._1 | |
645 | + | let prBalanceOld = $t02460425066._2 | |
646 | + | let $t02507225248 = if ((pmtAssetId == amId)) | |
714 | 647 | then $Tuple2(pmtAmtRaw, 0) | |
715 | 648 | else if ((pmtAssetId == prId)) | |
716 | 649 | then $Tuple2(0, pmtAmtRaw) | |
717 | 650 | else throw("invalid payment") | |
718 | - | let amAmountRaw = $ | |
719 | - | let prAmountRaw = $ | |
720 | - | let $ | |
651 | + | let amAmountRaw = $t02507225248._1 | |
652 | + | let prAmountRaw = $t02507225248._2 | |
653 | + | let $t02525225506 = if (withTakeFee) | |
721 | 654 | then $Tuple3(takeFee(amAmountRaw, inFee)._1, takeFee(prAmountRaw, inFee)._1, takeFee(pmtAmtRaw, inFee)._2) | |
722 | 655 | else $Tuple3(amAmountRaw, prAmountRaw, 0) | |
723 | - | let amAmount = $ | |
724 | - | let prAmount = $ | |
725 | - | let feeAmount = $ | |
656 | + | let amAmount = $t02525225506._1 | |
657 | + | let prAmount = $t02525225506._2 | |
658 | + | let feeAmount = $t02525225506._3 | |
726 | 659 | let amBalanceNew = (amBalanceOld + amAmount) | |
727 | 660 | let prBalanceNew = (prBalanceOld + prAmount) | |
728 | - | let D0 = getD([ | |
729 | - | let D1 = getD([ | |
661 | + | let D0 = getD([toBigInt(amBalanceOld), toBigInt(prBalanceOld)]) | |
662 | + | let D1 = getD([toBigInt(amBalanceNew), toBigInt(prBalanceNew)]) | |
730 | 663 | let checkD = if ((D1 > D0)) | |
731 | 664 | then true | |
732 | 665 | else throw() | |
733 | 666 | if ((checkD == checkD)) | |
734 | 667 | then { | |
735 | - | let lpAmount = fraction(lpAssetEmission, (D1 - D0), D0 | |
668 | + | let lpAmount = fraction(lpAssetEmission, (D1 - D0), D0) | |
736 | 669 | let curPrice = f1(cpbi(t1(prBalanceNew, priceDcm), t1(amBalanceNew, amtDcm)), scale8) | |
737 | 670 | let commonState = [IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice), StringEntry(pau(userAddress, txId), dataPutActionInfo(amAmountRaw, prAmountRaw, toInt(lpAmount), curPrice, 0, 0, height, lastBlock.timestamp, 0, 0))] | |
738 | 671 | let poolProportion = fraction(prBalanceOld, scale8, amBalanceOld) | |
739 | 672 | let amountAssetPart = fraction(pmtAmtRaw, scale8, (poolProportion + scale8)) | |
740 | 673 | let priceAssetPart = (pmtAmtRaw - amountAssetPart) | |
741 | 674 | let lpAmtBoth = fraction(lpAssetEmission, toBigInt(priceAssetPart), toBigInt(prBalanceOld)) | |
742 | 675 | let bonus = toInt(fraction((lpAmount - lpAmtBoth), scale8BigInt, lpAmtBoth)) | |
743 | 676 | $Tuple4(toInt(lpAmount), commonState, feeAmount, bonus) | |
744 | 677 | } | |
745 | 678 | else throw("Strict value is not equal to itself.") | |
746 | 679 | } | |
747 | 680 | else throw("Strict value is not equal to itself.") | |
748 | 681 | } | |
749 | 682 | ||
750 | 683 | ||
751 | 684 | func getOneTknV2Internal (outAssetId,minOutAmount,payments,caller,originCaller,transactionId) = { | |
752 | - | let lpId = toBase58String(value(cfgLpAssetId)) | |
753 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
754 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
755 | - | let amDecimals = cfgAmountAssetDecimals | |
756 | - | let prDecimals = cfgPriceAssetDecimals | |
757 | - | let poolStatus = cfgPoolStatus | |
685 | + | let poolConfig = gpc() | |
686 | + | let lpId = poolConfig[idxLPAsId] | |
687 | + | let amId = poolConfig[idxAmAsId] | |
688 | + | let prId = poolConfig[idxPrAsId] | |
689 | + | let amDecimals = parseIntValue(poolConfig[idxAmtAsDcm]) | |
690 | + | let prDecimals = parseIntValue(poolConfig[idxPriceAsDcm]) | |
691 | + | let poolStatus = poolConfig[idxPoolSt] | |
758 | 692 | let userAddress = if ((caller == restContract)) | |
759 | 693 | then originCaller | |
760 | 694 | else caller | |
761 | 695 | let pmt = value(payments[0]) | |
762 | 696 | let pmtAssetId = value(pmt.assetId) | |
763 | 697 | let pmtAmt = pmt.amount | |
764 | - | let currentDLp = calcCurrentDLp(big0, big0, big0) | |
765 | - | if ((currentDLp == currentDLp)) | |
766 | - | then { | |
767 | - | let txId58 = toBase58String(transactionId) | |
768 | - | if ((lpId != toBase58String(pmtAssetId))) | |
769 | - | then throw("Wrong LP") | |
770 | - | else { | |
771 | - | let amBalance = getAccBalance(amId) | |
772 | - | let prBalance = getAccBalance(prId) | |
773 | - | let $t03102631137 = { | |
774 | - | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, pmtAmt], nil) | |
775 | - | if ($isInstanceOf(@, "(Int, Int)")) | |
776 | - | then @ | |
777 | - | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
778 | - | } | |
779 | - | if (($t03102631137 == $t03102631137)) | |
698 | + | let txId58 = toBase58String(transactionId) | |
699 | + | if ((lpId != toBase58String(pmtAssetId))) | |
700 | + | then throw("Wrong LP") | |
701 | + | else { | |
702 | + | let amBalance = getAccBalance(amId) | |
703 | + | let prBalance = getAccBalance(prId) | |
704 | + | let $t02750827619 = { | |
705 | + | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, pmtAmt], nil) | |
706 | + | if ($isInstanceOf(@, "(Int, Int)")) | |
707 | + | then @ | |
708 | + | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
709 | + | } | |
710 | + | if (($t02750827619 == $t02750827619)) | |
711 | + | then { | |
712 | + | let feeAmount = $t02750827619._2 | |
713 | + | let totalGet = $t02750827619._1 | |
714 | + | let totalAmount = if (if ((minOutAmount > 0)) | |
715 | + | then (minOutAmount > totalGet) | |
716 | + | else false) | |
717 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
718 | + | else totalGet | |
719 | + | let $t02780928116 = if ((outAssetId == amId)) | |
720 | + | then $Tuple4(totalAmount, 0, ((amBalance - totalAmount) - feeAmount), prBalance) | |
721 | + | else if ((outAssetId == prId)) | |
722 | + | then $Tuple4(0, totalAmount, amBalance, ((prBalance - totalAmount) - feeAmount)) | |
723 | + | else throw("invalid out asset id") | |
724 | + | let outAm = $t02780928116._1 | |
725 | + | let outPr = $t02780928116._2 | |
726 | + | let amBalanceNew = $t02780928116._3 | |
727 | + | let prBalanceNew = $t02780928116._4 | |
728 | + | let curPrX18 = cpbi(t1(prBalanceNew, prDecimals), t1(amBalanceNew, amDecimals)) | |
729 | + | let curPr = f1(curPrX18, scale8) | |
730 | + | let outAssetIdOrWaves = if ((outAssetId == "WAVES")) | |
731 | + | then unit | |
732 | + | else fromBase58String(outAssetId) | |
733 | + | let sendFeeToMatcher = if ((feeAmount > 0)) | |
734 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetIdOrWaves)] | |
735 | + | else nil | |
736 | + | let state = ([ScriptTransfer(userAddress, totalAmount, outAssetIdOrWaves), StringEntry(gau(toString(userAddress), txId58), dataGetActionInfo(outAm, outPr, pmtAmt, curPr, height, lastBlock.timestamp)), IntegerEntry(pl(), curPr), IntegerEntry(ph(height, lastBlock.timestamp), curPr)] ++ sendFeeToMatcher) | |
737 | + | if ((state == state)) | |
780 | 738 | then { | |
781 | - | let feeAmount = $t03102631137._2 | |
782 | - | let totalGet = $t03102631137._1 | |
783 | - | let totalAmount = if (if ((minOutAmount > 0)) | |
784 | - | then (minOutAmount > totalGet) | |
785 | - | else false) | |
786 | - | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
787 | - | else totalGet | |
788 | - | let $t03132731634 = if ((outAssetId == amId)) | |
789 | - | then $Tuple4(totalAmount, 0, ((amBalance - totalAmount) - feeAmount), prBalance) | |
790 | - | else if ((outAssetId == prId)) | |
791 | - | then $Tuple4(0, totalAmount, amBalance, ((prBalance - totalAmount) - feeAmount)) | |
792 | - | else throw("invalid out asset id") | |
793 | - | let outAm = $t03132731634._1 | |
794 | - | let outPr = $t03132731634._2 | |
795 | - | let amBalanceNew = $t03132731634._3 | |
796 | - | let prBalanceNew = $t03132731634._4 | |
797 | - | let curPrX18 = cpbi(t1(prBalanceNew, prDecimals), t1(amBalanceNew, amDecimals)) | |
798 | - | let curPr = f1(curPrX18, scale8) | |
799 | - | let outAssetIdOrWaves = if ((outAssetId == "WAVES")) | |
800 | - | then unit | |
801 | - | else fromBase58String(outAssetId) | |
802 | - | let sendFeeToMatcher = if ((feeAmount > 0)) | |
803 | - | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetIdOrWaves)] | |
804 | - | else nil | |
805 | - | let state = ([ScriptTransfer(userAddress, totalAmount, outAssetIdOrWaves), StringEntry(gau(toString(userAddress), txId58), dataGetActionInfo(outAm, outPr, pmtAmt, curPr, height, lastBlock.timestamp)), IntegerEntry(pl(), curPr), IntegerEntry(ph(height, lastBlock.timestamp), curPr)] ++ sendFeeToMatcher) | |
806 | - | if ((state == state)) | |
807 | - | then { | |
808 | - | let burn = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
809 | - | if ((burn == burn)) | |
810 | - | then { | |
811 | - | let $t03241932769 = { | |
812 | - | let feeAmountForCalc = if ((this == feeCollectorAddress)) | |
813 | - | then 0 | |
814 | - | else feeAmount | |
815 | - | let outInAmountAsset = if ((parseAssetId(outAssetId) == cfgAmountAssetId)) | |
816 | - | then true | |
817 | - | else false | |
818 | - | if (outInAmountAsset) | |
819 | - | then $Tuple2(-((totalGet + feeAmountForCalc)), 0) | |
820 | - | else $Tuple2(0, -((totalGet + feeAmountForCalc))) | |
821 | - | } | |
822 | - | let amountAssetBalanceDelta = $t03241932769._1 | |
823 | - | let priceAssetBalanceDelta = $t03241932769._2 | |
824 | - | let $t03277232880 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
825 | - | let refreshDLpActions = $t03277232880._1 | |
826 | - | let updatedDLp = $t03277232880._2 | |
827 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
828 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
829 | - | then $Tuple2((state ++ refreshDLpActions), totalAmount) | |
830 | - | else throw("Strict value is not equal to itself.") | |
831 | - | } | |
832 | - | else throw("Strict value is not equal to itself.") | |
833 | - | } | |
739 | + | let burn = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
740 | + | if ((burn == burn)) | |
741 | + | then $Tuple2(state, totalAmount) | |
834 | 742 | else throw("Strict value is not equal to itself.") | |
835 | 743 | } | |
836 | 744 | else throw("Strict value is not equal to itself.") | |
837 | 745 | } | |
746 | + | else throw("Strict value is not equal to itself.") | |
838 | 747 | } | |
839 | - | else throw("Strict value is not equal to itself.") | |
840 | 748 | } | |
841 | 749 | ||
842 | 750 | ||
843 | 751 | func m () = match getString(mpk()) { | |
844 | 752 | case s: String => | |
845 | 753 | fromBase58String(s) | |
846 | 754 | case _: Unit => | |
847 | 755 | unit | |
848 | 756 | case _ => | |
849 | 757 | throw("Match error") | |
850 | 758 | } | |
851 | 759 | ||
852 | 760 | ||
853 | 761 | func pm () = match getString(pmpk()) { | |
854 | 762 | case s: String => | |
855 | 763 | fromBase58String(s) | |
856 | 764 | case _: Unit => | |
857 | 765 | unit | |
858 | 766 | case _ => | |
859 | 767 | throw("Match error") | |
860 | 768 | } | |
861 | 769 | ||
862 | 770 | ||
863 | 771 | let pd = throw("Permission denied") | |
864 | 772 | ||
865 | 773 | func isManager (i) = match m() { | |
866 | 774 | case pk: ByteVector => | |
867 | 775 | (i.callerPublicKey == pk) | |
868 | 776 | case _: Unit => | |
869 | 777 | (i.caller == this) | |
870 | 778 | case _ => | |
871 | 779 | throw("Match error") | |
872 | 780 | } | |
873 | 781 | ||
874 | 782 | ||
875 | 783 | func mm (i) = match m() { | |
876 | 784 | case pk: ByteVector => | |
877 | 785 | if ((i.callerPublicKey == pk)) | |
878 | 786 | then true | |
879 | 787 | else pd | |
880 | 788 | case _: Unit => | |
881 | 789 | if ((i.caller == this)) | |
882 | 790 | then true | |
883 | 791 | else pd | |
884 | 792 | case _ => | |
885 | 793 | throw("Match error") | |
886 | 794 | } | |
887 | - | ||
888 | - | ||
889 | - | func getY (isReverse,D,poolAmountInBalance) = { | |
890 | - | let poolConfig = gpc() | |
891 | - | let amId = poolConfig[idxAmAsId] | |
892 | - | let prId = poolConfig[idxPrAsId] | |
893 | - | let n = big2 | |
894 | - | let aPrecision = parseBigIntValue(Amult) | |
895 | - | let a = (parseBigIntValue(A) * aPrecision) | |
896 | - | let xp = if ((isReverse == false)) | |
897 | - | then [(toBigInt(getAccBalance(amId)) + poolAmountInBalance), toBigInt(getAccBalance(prId))] | |
898 | - | else [(toBigInt(getAccBalance(prId)) + poolAmountInBalance), toBigInt(getAccBalance(amId))] | |
899 | - | let x = xp[0] | |
900 | - | let s = x | |
901 | - | let ann = (a * n) | |
902 | - | let c = (((((D * D) / (x * n)) * D) * aPrecision) / (ann * n)) | |
903 | - | let b = ((s + ((D * aPrecision) / ann)) - D) | |
904 | - | func calc (acc,cur) = { | |
905 | - | let $t03432734347 = acc | |
906 | - | let y = $t03432734347._1 | |
907 | - | let found = $t03432734347._2 | |
908 | - | if ((found != unit)) | |
909 | - | then acc | |
910 | - | else { | |
911 | - | let yNext = (((y * y) + c) / ((big2 * y) + b)) | |
912 | - | let yDiff = absBigInt((yNext - value(y))) | |
913 | - | if ((big1 >= yDiff)) | |
914 | - | then $Tuple2(yNext, cur) | |
915 | - | else $Tuple2(yNext, unit) | |
916 | - | } | |
917 | - | } | |
918 | - | ||
919 | - | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
920 | - | let $t03467834725 = { | |
921 | - | let $l = arr | |
922 | - | let $s = size($l) | |
923 | - | let $acc0 = $Tuple2(D, unit) | |
924 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
925 | - | then $a | |
926 | - | else calc($a, $l[$i]) | |
927 | - | ||
928 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
929 | - | then $a | |
930 | - | else throw("List size exceeds 15") | |
931 | - | ||
932 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
933 | - | } | |
934 | - | let y = $t03467834725._1 | |
935 | - | let found = $t03467834725._2 | |
936 | - | if ((found != unit)) | |
937 | - | then y | |
938 | - | else throw(("Y calculation error, Y = " + toString(y))) | |
939 | - | } | |
940 | - | ||
941 | - | ||
942 | - | @Callable(i) | |
943 | - | func calculateAmountOutForSwapREADONLY (cleanAmountIn,isReverse,feePoolAmount) = { | |
944 | - | let $t03496635390 = if ((isReverse == false)) | |
945 | - | then { | |
946 | - | let assetOut = strf(this, pa()) | |
947 | - | let poolAmountInBalance = (toBigInt(getAccBalance(strf(this, aa()))) + toBigInt(cleanAmountIn)) | |
948 | - | $Tuple2(assetOut, poolAmountInBalance) | |
949 | - | } | |
950 | - | else { | |
951 | - | let assetOut = strf(this, aa()) | |
952 | - | let poolAmountInBalance = (toBigInt(getAccBalance(strf(this, pa()))) + toBigInt(cleanAmountIn)) | |
953 | - | $Tuple2(assetOut, poolAmountInBalance) | |
954 | - | } | |
955 | - | let assetOut = $t03496635390._1 | |
956 | - | let poolAmountInBalance = $t03496635390._2 | |
957 | - | let poolConfig = gpc() | |
958 | - | let amId = poolConfig[idxAmAsId] | |
959 | - | let prId = poolConfig[idxPrAsId] | |
960 | - | let xp = [toBigInt(getAccBalance(amId)), toBigInt(getAccBalance(prId))] | |
961 | - | let D = getD(xp) | |
962 | - | let y = getY(isReverse, D, toBigInt(cleanAmountIn)) | |
963 | - | let dy = ((toBigInt(getAccBalance(assetOut)) - y) - toBigInt(1)) | |
964 | - | let totalGetRaw = max([0, toInt(dy)]) | |
965 | - | let newXp = if ((isReverse == false)) | |
966 | - | then [((toBigInt(getAccBalance(amId)) + toBigInt(cleanAmountIn)) + toBigInt(feePoolAmount)), (toBigInt(getAccBalance(prId)) - dy)] | |
967 | - | else [(toBigInt(getAccBalance(amId)) - dy), ((toBigInt(getAccBalance(prId)) + toBigInt(cleanAmountIn)) + toBigInt(feePoolAmount))] | |
968 | - | let newD = getD(newXp) | |
969 | - | let checkD = if ((newD >= D)) | |
970 | - | then true | |
971 | - | else throw(makeString(["new D is fewer error", toString(D), toString(newD)], "__")) | |
972 | - | if ((checkD == checkD)) | |
973 | - | then $Tuple2(nil, totalGetRaw) | |
974 | - | else throw("Strict value is not equal to itself.") | |
975 | - | } | |
976 | - | ||
977 | - | ||
978 | - | ||
979 | - | @Callable(i) | |
980 | - | func calculateAmountOutForSwapAndSendTokens (cleanAmountIn,isReverse,amountOutMin,addressTo,feePoolAmount) = { | |
981 | - | let swapContact = { | |
982 | - | let @ = invoke(fca, "getSwapContractREADONLY", nil, nil) | |
983 | - | if ($isInstanceOf(@, "String")) | |
984 | - | then @ | |
985 | - | else throw(($getType(@) + " couldn't be cast to String")) | |
986 | - | } | |
987 | - | let checks = [if ((value(i.payments[0]).amount >= cleanAmountIn)) | |
988 | - | then true | |
989 | - | else throwErr("Wrong amount"), if ((i.caller == addressFromStringValue(swapContact))) | |
990 | - | then true | |
991 | - | else throwErr("Permission denied")] | |
992 | - | if ((checks == checks)) | |
993 | - | then { | |
994 | - | let pmt = value(i.payments[0]) | |
995 | - | let assetIn = assetIdToString(pmt.assetId) | |
996 | - | let $t03682637220 = if ((isReverse == false)) | |
997 | - | then { | |
998 | - | let assetOut = strf(this, pa()) | |
999 | - | let poolAmountInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount) | |
1000 | - | $Tuple2(assetOut, poolAmountInBalance) | |
1001 | - | } | |
1002 | - | else { | |
1003 | - | let assetOut = strf(this, aa()) | |
1004 | - | let poolAmountInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount) | |
1005 | - | $Tuple2(assetOut, poolAmountInBalance) | |
1006 | - | } | |
1007 | - | let assetOut = $t03682637220._1 | |
1008 | - | let poolAmountInBalance = $t03682637220._2 | |
1009 | - | let poolConfig = gpc() | |
1010 | - | let amId = poolConfig[idxAmAsId] | |
1011 | - | let prId = poolConfig[idxPrAsId] | |
1012 | - | let xp = if ((isReverse == false)) | |
1013 | - | then [(toBigInt(getAccBalance(amId)) - toBigInt(value(i.payments[0]).amount)), toBigInt(getAccBalance(prId))] | |
1014 | - | else [toBigInt(getAccBalance(amId)), (toBigInt(getAccBalance(prId)) - toBigInt(value(i.payments[0]).amount))] | |
1015 | - | let D = getD(xp) | |
1016 | - | let y = getY(isReverse, D, toBigInt(0)) | |
1017 | - | let dy = ((toBigInt(getAccBalance(assetOut)) - y) - toBigInt(1)) | |
1018 | - | let totalGetRaw = max([0, toInt(dy)]) | |
1019 | - | let checkMin = if ((totalGetRaw >= amountOutMin)) | |
1020 | - | then true | |
1021 | - | else throw("Exchange result is fewer coins than expected") | |
1022 | - | if ((checkMin == checkMin)) | |
1023 | - | then { | |
1024 | - | let newXp = if ((isReverse == false)) | |
1025 | - | then [(toBigInt(getAccBalance(amId)) + toBigInt(feePoolAmount)), (toBigInt(getAccBalance(prId)) - dy)] | |
1026 | - | else [(toBigInt(getAccBalance(amId)) - dy), (toBigInt(getAccBalance(prId)) + toBigInt(feePoolAmount))] | |
1027 | - | let newD = getD(newXp) | |
1028 | - | let checkD = if ((newD >= D)) | |
1029 | - | then true | |
1030 | - | else throw("new D is fewer error") | |
1031 | - | if ((checkD == checkD)) | |
1032 | - | then $Tuple2([ScriptTransfer(addressFromStringValue(addressTo), totalGetRaw, parseAssetId(assetOut))], totalGetRaw) | |
1033 | - | else throw("Strict value is not equal to itself.") | |
1034 | - | } | |
1035 | - | else throw("Strict value is not equal to itself.") | |
1036 | - | } | |
1037 | - | else throw("Strict value is not equal to itself.") | |
1038 | - | } | |
1039 | - | ||
1040 | 795 | ||
1041 | 796 | ||
1042 | 797 | @Callable(i) | |
1043 | 798 | func constructor (fc) = { | |
1044 | 799 | let c = mm(i) | |
1045 | 800 | if ((c == c)) | |
1046 | 801 | then [StringEntry(fc(), fc)] | |
1047 | 802 | else throw("Strict value is not equal to itself.") | |
1048 | 803 | } | |
1049 | 804 | ||
1050 | 805 | ||
1051 | 806 | ||
1052 | 807 | @Callable(i) | |
1053 | 808 | func setManager (pendingManagerPublicKey) = { | |
1054 | 809 | let c = mm(i) | |
1055 | 810 | if ((c == c)) | |
1056 | 811 | then { | |
1057 | 812 | let cm = fromBase58String(pendingManagerPublicKey) | |
1058 | 813 | if ((cm == cm)) | |
1059 | 814 | then [StringEntry(pmpk(), pendingManagerPublicKey)] | |
1060 | 815 | else throw("Strict value is not equal to itself.") | |
1061 | 816 | } | |
1062 | 817 | else throw("Strict value is not equal to itself.") | |
1063 | 818 | } | |
1064 | 819 | ||
1065 | 820 | ||
1066 | 821 | ||
1067 | 822 | @Callable(i) | |
1068 | 823 | func confirmManager () = { | |
1069 | 824 | let p = pm() | |
1070 | 825 | let hpm = if (isDefined(p)) | |
1071 | 826 | then true | |
1072 | 827 | else throw("No pending manager") | |
1073 | 828 | if ((hpm == hpm)) | |
1074 | 829 | then { | |
1075 | 830 | let cpm = if ((i.callerPublicKey == value(p))) | |
1076 | 831 | then true | |
1077 | 832 | else throw("You are not pending manager") | |
1078 | 833 | if ((cpm == cpm)) | |
1079 | 834 | then [StringEntry(mpk(), toBase58String(value(p))), DeleteEntry(pmpk())] | |
1080 | 835 | else throw("Strict value is not equal to itself.") | |
1081 | 836 | } | |
1082 | 837 | else throw("Strict value is not equal to itself.") | |
1083 | 838 | } | |
1084 | 839 | ||
1085 | 840 | ||
1086 | 841 | ||
1087 | 842 | @Callable(i) | |
1088 | 843 | func put (slip,autoStake) = { | |
1089 | 844 | let factCfg = gfc() | |
1090 | 845 | let stakingCntr = valueOrErrorMessage(addressFromString(factCfg[idxFactStakCntr]), "Wr st addr") | |
1091 | 846 | let slipCntr = valueOrErrorMessage(addressFromString(factCfg[idxFactSlippCntr]), "Wr sl addr") | |
1092 | 847 | if ((0 > slip)) | |
1093 | 848 | then throw("Wrong slippage") | |
1094 | 849 | else if ((size(i.payments) != 2)) | |
1095 | 850 | then throw("2 pmnts expd") | |
1096 | 851 | else { | |
1097 | - | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1098 | - | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1099 | - | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amAssetPmt) | |
1100 | - | if ((amountAssetBalance == amountAssetBalance)) | |
852 | + | let e = cp(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], slip, true, false, true, 0, "") | |
853 | + | let emitLpAmt = e._2 | |
854 | + | let lpAssetId = e._7 | |
855 | + | let state = e._9 | |
856 | + | let amDiff = e._10 | |
857 | + | let prDiff = e._11 | |
858 | + | let amId = e._12 | |
859 | + | let prId = e._13 | |
860 | + | let r = invoke(fca, "emit", [emitLpAmt], nil) | |
861 | + | if ((r == r)) | |
1101 | 862 | then { | |
1102 | - | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - prAssetPmt) | |
1103 | - | if ((priceAssetBalance == priceAssetBalance)) | |
863 | + | let el = match r { | |
864 | + | case legacy: Address => | |
865 | + | invoke(legacy, "emit", [emitLpAmt], nil) | |
866 | + | case _ => | |
867 | + | unit | |
868 | + | } | |
869 | + | if ((el == el)) | |
1104 | 870 | then { | |
1105 | - | let lpAssetEmission = toBigInt(value(assetInfo(cfgLpAssetId)).quantity) | |
1106 | - | if ((lpAssetEmission == lpAssetEmission)) | |
871 | + | let sa = if ((amDiff > 0)) | |
872 | + | then invoke(slipCntr, "put", nil, [AttachedPayment(amId, amDiff)]) | |
873 | + | else nil | |
874 | + | if ((sa == sa)) | |
1107 | 875 | then { | |
1108 | - | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1109 | - | if ((currentDLp == currentDLp)) | |
876 | + | let sp = if ((prDiff > 0)) | |
877 | + | then invoke(slipCntr, "put", nil, [AttachedPayment(prId, prDiff)]) | |
878 | + | else nil | |
879 | + | if ((sp == sp)) | |
1110 | 880 | then { | |
1111 | - | let e = cp(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], slip, true, false, true, 0, "") | |
1112 | - | let emitLpAmt = e._2 | |
1113 | - | let lpAssetId = e._7 | |
1114 | - | let state = e._9 | |
1115 | - | let amDiff = e._10 | |
1116 | - | let prDiff = e._11 | |
1117 | - | let amId = e._12 | |
1118 | - | let prId = e._13 | |
1119 | - | let r = invoke(fca, "emit", [emitLpAmt], nil) | |
1120 | - | if ((r == r)) | |
881 | + | let lpTrnsfr = if (autoStake) | |
1121 | 882 | then { | |
1122 | - | let el = match r { | |
1123 | - | case legacy: Address => | |
1124 | - | invoke(legacy, "emit", [emitLpAmt], nil) | |
1125 | - | case _ => | |
1126 | - | unit | |
1127 | - | } | |
1128 | - | if ((el == el)) | |
1129 | - | then { | |
1130 | - | let sa = if ((amDiff > 0)) | |
1131 | - | then invoke(slipCntr, "put", nil, [AttachedPayment(amId, amDiff)]) | |
1132 | - | else nil | |
1133 | - | if ((sa == sa)) | |
1134 | - | then { | |
1135 | - | let sp = if ((prDiff > 0)) | |
1136 | - | then invoke(slipCntr, "put", nil, [AttachedPayment(prId, prDiff)]) | |
1137 | - | else nil | |
1138 | - | if ((sp == sp)) | |
1139 | - | then { | |
1140 | - | let lpTrnsfr = if (autoStake) | |
1141 | - | then { | |
1142 | - | let ss = invoke(stakingCntr, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
1143 | - | if ((ss == ss)) | |
1144 | - | then nil | |
1145 | - | else throw("Strict value is not equal to itself.") | |
1146 | - | } | |
1147 | - | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
1148 | - | let $t04183941981 = refreshDLpInternal(0, 0, 0) | |
1149 | - | let refreshDLpActions = $t04183941981._1 | |
1150 | - | let updatedDLp = $t04183941981._2 | |
1151 | - | let check = if ((updatedDLp >= currentDLp)) | |
1152 | - | then true | |
1153 | - | else throwErr(makeString(["updated DLp lower than current DLp", toString(amountAssetBalance), toString(priceAssetBalance), toString(lpAssetEmission), toString(currentDLp), toString(updatedDLp), toString(amDiff), toString(prDiff)], " ")) | |
1154 | - | if ((check == check)) | |
1155 | - | then { | |
1156 | - | let lpAssetEmissionAfter = value(assetInfo(cfgLpAssetId)).quantity | |
1157 | - | if ((lpAssetEmissionAfter == lpAssetEmissionAfter)) | |
1158 | - | then ((state ++ lpTrnsfr) ++ refreshDLpActions) | |
1159 | - | else throw("Strict value is not equal to itself.") | |
1160 | - | } | |
1161 | - | else throw("Strict value is not equal to itself.") | |
1162 | - | } | |
1163 | - | else throw("Strict value is not equal to itself.") | |
1164 | - | } | |
1165 | - | else throw("Strict value is not equal to itself.") | |
1166 | - | } | |
883 | + | let ss = invoke(stakingCntr, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
884 | + | if ((ss == ss)) | |
885 | + | then nil | |
1167 | 886 | else throw("Strict value is not equal to itself.") | |
1168 | 887 | } | |
1169 | - | else throw("Strict value is not equal to itself.") | |
888 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
889 | + | (state ++ lpTrnsfr) | |
1170 | 890 | } | |
1171 | 891 | else throw("Strict value is not equal to itself.") | |
1172 | 892 | } | |
1173 | 893 | else throw("Strict value is not equal to itself.") | |
1174 | 894 | } | |
1175 | 895 | else throw("Strict value is not equal to itself.") | |
1176 | 896 | } | |
1177 | 897 | else throw("Strict value is not equal to itself.") | |
1178 | 898 | } | |
1179 | 899 | } | |
1180 | 900 | ||
1181 | 901 | ||
1182 | 902 | ||
1183 | 903 | @Callable(i) | |
1184 | 904 | func putOneTknV2 (minOutAmount,autoStake) = { | |
1185 | 905 | let isPoolOneTokenOperationsDisabled = { | |
1186 | 906 | let @ = invoke(fca, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1187 | 907 | if ($isInstanceOf(@, "Boolean")) | |
1188 | 908 | then @ | |
1189 | 909 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1190 | 910 | } | |
1191 | 911 | let isPutDisabled = if (if (if (igs()) | |
1192 | 912 | then true | |
1193 | 913 | else (cfgPoolStatus == PoolPutDis)) | |
1194 | 914 | then true | |
1195 | 915 | else (cfgPoolStatus == PoolShutdown)) | |
1196 | 916 | then true | |
1197 | 917 | else isPoolOneTokenOperationsDisabled | |
1198 | 918 | let checks = [if (if (!(isPutDisabled)) | |
1199 | 919 | then true | |
1200 | 920 | else isManager(i)) | |
1201 | 921 | then true | |
1202 | 922 | else throwErr("put operation is blocked by admin"), if ((size(i.payments) == 1)) | |
1203 | 923 | then true | |
1204 | 924 | else throwErr("exactly 1 payment are expected")] | |
1205 | 925 | if ((checks == checks)) | |
1206 | 926 | then { | |
1207 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
1208 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
1209 | - | let lpId = cfgLpAssetId | |
1210 | - | let amDecimals = cfgAmountAssetDecimals | |
1211 | - | let prDecimals = cfgPriceAssetDecimals | |
927 | + | let poolConfig = gpc() | |
928 | + | let amId = poolConfig[idxAmAsId] | |
929 | + | let prId = poolConfig[idxPrAsId] | |
930 | + | let lpId = fromBase58String(poolConfig[idxLPAsId]) | |
931 | + | let amDecimals = parseIntValue(poolConfig[idxAmtAsDcm]) | |
932 | + | let prDecimals = parseIntValue(poolConfig[idxPriceAsDcm]) | |
1212 | 933 | let userAddress = if ((i.caller == this)) | |
1213 | 934 | then i.originCaller | |
1214 | 935 | else i.caller | |
1215 | 936 | let pmt = value(i.payments[0]) | |
1216 | 937 | let pmtAssetId = toBase58String(value(pmt.assetId)) | |
1217 | 938 | let pmtAmt = pmt.amount | |
1218 | - | let currentDLp = if ((pmt.assetId == cfgAmountAssetId)) | |
1219 | - | then calcCurrentDLp(toBigInt(pmtAmt), toBigInt(0), toBigInt(0)) | |
1220 | - | else calcCurrentDLp(toBigInt(0), toBigInt(pmtAmt), toBigInt(0)) | |
1221 | - | if ((currentDLp == currentDLp)) | |
939 | + | let $t03347833636 = calcPutOneTkn(pmtAmt, pmtAssetId, toString(userAddress), toBase58String(i.transactionId), true) | |
940 | + | if (($t03347833636 == $t03347833636)) | |
1222 | 941 | then { | |
1223 | - | let $t04362243780 = calcPutOneTkn(pmtAmt, pmtAssetId, toString(userAddress), toBase58String(i.transactionId), true) | |
1224 | - | if (($t04362243780 == $t04362243780)) | |
942 | + | let feeAmount = $t03347833636._3 | |
943 | + | let state = $t03347833636._2 | |
944 | + | let estimLP = $t03347833636._1 | |
945 | + | let emitLpAmt = if (if ((minOutAmount > 0)) | |
946 | + | then (minOutAmount > estimLP) | |
947 | + | else false) | |
948 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
949 | + | else estimLP | |
950 | + | let e = invoke(fca, "emit", [emitLpAmt], nil) | |
951 | + | if ((e == e)) | |
1225 | 952 | then { | |
1226 | - | let feeAmount = $t04362243780._3 | |
1227 | - | let state = $t04362243780._2 | |
1228 | - | let estimLP = $t04362243780._1 | |
1229 | - | let emitLpAmt = if (if ((minOutAmount > 0)) | |
1230 | - | then (minOutAmount > estimLP) | |
1231 | - | else false) | |
1232 | - | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
1233 | - | else estimLP | |
1234 | - | let e = invoke(fca, "emit", [emitLpAmt], nil) | |
1235 | - | if ((e == e)) | |
953 | + | let el = match e { | |
954 | + | case legacy: Address => | |
955 | + | invoke(legacy, "emit", [emitLpAmt], nil) | |
956 | + | case _ => | |
957 | + | unit | |
958 | + | } | |
959 | + | if ((el == el)) | |
1236 | 960 | then { | |
1237 | - | let el = match e { | |
1238 | - | case legacy: Address => | |
1239 | - | invoke(legacy, "emit", [emitLpAmt], nil) | |
1240 | - | case _ => | |
1241 | - | unit | |
1242 | - | } | |
1243 | - | if ((el == el)) | |
961 | + | let lpTrnsfr = if (autoStake) | |
1244 | 962 | then { | |
1245 | - | let lpTrnsfr = if (autoStake) | |
1246 | - | then { | |
1247 | - | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpId, emitLpAmt)]) | |
1248 | - | if ((ss == ss)) | |
1249 | - | then nil | |
1250 | - | else throw("Strict value is not equal to itself.") | |
1251 | - | } | |
1252 | - | else [ScriptTransfer(i.caller, emitLpAmt, lpId)] | |
1253 | - | let sendFeeToMatcher = if ((feeAmount > 0)) | |
1254 | - | then [ScriptTransfer(feeCollectorAddress, feeAmount, fromBase58String(pmtAssetId))] | |
1255 | - | else nil | |
1256 | - | let $t04459544944 = if ((this == feeCollectorAddress)) | |
1257 | - | then $Tuple2(0, 0) | |
1258 | - | else { | |
1259 | - | let paymentInAmountAsset = if ((pmt.assetId == cfgAmountAssetId)) | |
1260 | - | then true | |
1261 | - | else false | |
1262 | - | if (paymentInAmountAsset) | |
1263 | - | then $Tuple2(-(feeAmount), 0) | |
1264 | - | else $Tuple2(0, -(feeAmount)) | |
1265 | - | } | |
1266 | - | let amountAssetBalanceDelta = $t04459544944._1 | |
1267 | - | let priceAssetBalanceDelta = $t04459544944._2 | |
1268 | - | let $t04494745055 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1269 | - | let refreshDLpActions = $t04494745055._1 | |
1270 | - | let updatedDLp = $t04494745055._2 | |
1271 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1272 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1273 | - | then $Tuple2((((state ++ lpTrnsfr) ++ sendFeeToMatcher) ++ refreshDLpActions), emitLpAmt) | |
963 | + | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpId, emitLpAmt)]) | |
964 | + | if ((ss == ss)) | |
965 | + | then nil | |
1274 | 966 | else throw("Strict value is not equal to itself.") | |
1275 | 967 | } | |
1276 | - | else throw("Strict value is not equal to itself.") | |
968 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpId)] | |
969 | + | let sendFeeToMatcher = if ((feeAmount > 0)) | |
970 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, fromBase58String(pmtAssetId))] | |
971 | + | else nil | |
972 | + | $Tuple2(((state ++ lpTrnsfr) ++ sendFeeToMatcher), emitLpAmt) | |
1277 | 973 | } | |
1278 | 974 | else throw("Strict value is not equal to itself.") | |
1279 | 975 | } | |
1280 | 976 | else throw("Strict value is not equal to itself.") | |
1281 | 977 | } | |
1282 | 978 | else throw("Strict value is not equal to itself.") | |
1283 | 979 | } | |
1284 | 980 | else throw("Strict value is not equal to itself.") | |
1285 | 981 | } | |
1286 | 982 | ||
1287 | 983 | ||
1288 | 984 | ||
1289 | 985 | @Callable(i) | |
1290 | 986 | func putForFree (maxSlpg) = if ((0 > maxSlpg)) | |
1291 | 987 | then throw("Wrong slpg") | |
1292 | 988 | else if ((size(i.payments) != 2)) | |
1293 | 989 | then throw("2 pmnts expd") | |
1294 | 990 | else { | |
1295 | 991 | let estPut = cp(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], maxSlpg, false, false, true, 0, "") | |
1296 | - | let state = estPut._9 | |
1297 | - | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1298 | - | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1299 | - | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1300 | - | if ((currentDLp == currentDLp)) | |
1301 | - | then { | |
1302 | - | let $t04608546150 = refreshDLpInternal(0, 0, 0) | |
1303 | - | let refreshDLpActions = $t04608546150._1 | |
1304 | - | let updatedDLp = $t04608546150._2 | |
1305 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1306 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1307 | - | then (state ++ refreshDLpActions) | |
1308 | - | else throw("Strict value is not equal to itself.") | |
1309 | - | } | |
1310 | - | else throw("Strict value is not equal to itself.") | |
992 | + | estPut._9 | |
1311 | 993 | } | |
1312 | 994 | ||
1313 | 995 | ||
1314 | 996 | ||
1315 | 997 | @Callable(i) | |
1316 | 998 | func get () = { | |
1317 | - | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1318 | - | if ((currentDLp == currentDLp)) | |
1319 | - | then { | |
1320 | - | let r = cg(i) | |
1321 | - | let outAmtAmt = r._1 | |
1322 | - | let outPrAmt = r._2 | |
1323 | - | let pmtAmt = r._3 | |
1324 | - | let pmtAssetId = r._4 | |
1325 | - | let state = r._5 | |
1326 | - | let b = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1327 | - | if ((b == b)) | |
1328 | - | then { | |
1329 | - | let $t04732347405 = refreshDLpInternal(-(outAmtAmt), -(outPrAmt), 0) | |
1330 | - | let refreshDLpActions = $t04732347405._1 | |
1331 | - | let updatedDLp = $t04732347405._2 | |
1332 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1333 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1334 | - | then (state ++ refreshDLpActions) | |
1335 | - | else throw("Strict value is not equal to itself.") | |
1336 | - | } | |
1337 | - | else throw("Strict value is not equal to itself.") | |
1338 | - | } | |
999 | + | let r = cg(i) | |
1000 | + | let outAmtAmt = r._1 | |
1001 | + | let outPrAmt = r._2 | |
1002 | + | let pmtAmt = r._3 | |
1003 | + | let pmtAssetId = r._4 | |
1004 | + | let state = r._5 | |
1005 | + | let b = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1006 | + | if ((b == b)) | |
1007 | + | then state | |
1339 | 1008 | else throw("Strict value is not equal to itself.") | |
1340 | 1009 | } | |
1341 | 1010 | ||
1342 | 1011 | ||
1343 | 1012 | ||
1344 | 1013 | @Callable(i) | |
1345 | 1014 | func getOneTknV2 (outAssetId,minOutAmount) = { | |
1346 | 1015 | let isPoolOneTokenOperationsDisabled = { | |
1347 | 1016 | let @ = invoke(fca, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1348 | 1017 | if ($isInstanceOf(@, "Boolean")) | |
1349 | 1018 | then @ | |
1350 | 1019 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1351 | 1020 | } | |
1352 | 1021 | let isGetDisabled = if (if (igs()) | |
1353 | 1022 | then true | |
1354 | 1023 | else (cfgPoolStatus == PoolShutdown)) | |
1355 | 1024 | then true | |
1356 | 1025 | else isPoolOneTokenOperationsDisabled | |
1357 | 1026 | let checks = [if (if (!(isGetDisabled)) | |
1358 | 1027 | then true | |
1359 | 1028 | else isManager(i)) | |
1360 | 1029 | then true | |
1361 | 1030 | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 1)) | |
1362 | 1031 | then true | |
1363 | 1032 | else throwErr("exactly 1 payment are expected")] | |
1364 | 1033 | if ((checks == checks)) | |
1365 | 1034 | then { | |
1366 | - | let $ | |
1367 | - | let state = $ | |
1368 | - | let totalAmount = $ | |
1035 | + | let $t03625836413 = getOneTknV2Internal(outAssetId, minOutAmount, i.payments, i.caller, i.originCaller, i.transactionId) | |
1036 | + | let state = $t03625836413._1 | |
1037 | + | let totalAmount = $t03625836413._2 | |
1369 | 1038 | $Tuple2(state, totalAmount) | |
1370 | 1039 | } | |
1371 | 1040 | else throw("Strict value is not equal to itself.") | |
1372 | 1041 | } | |
1373 | 1042 | ||
1374 | 1043 | ||
1375 | 1044 | ||
1376 | 1045 | @Callable(i) | |
1377 | - | func refreshDLp () = { | |
1378 | - | let lastRefreshedBlockHeight = valueOrElse(getInteger(keyDLpRefreshedHeight), 0) | |
1379 | - | let checkLastRefreshedBlockHeight = if (((height - lastRefreshedBlockHeight) >= dLpRefreshDelay)) | |
1380 | - | then unit | |
1381 | - | else throwErr(makeString([toString(dLpRefreshDelay), " blocks have not passed since the previous call"], "")) | |
1382 | - | if ((checkLastRefreshedBlockHeight == checkLastRefreshedBlockHeight)) | |
1383 | - | then { | |
1384 | - | let dLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyDLp), "0")), fmtErr("invalid dLp")) | |
1385 | - | let $t04870248766 = refreshDLpInternal(0, 0, 0) | |
1386 | - | let dLpUpdateActions = $t04870248766._1 | |
1387 | - | let updatedDLp = $t04870248766._2 | |
1388 | - | let actions = if ((dLp != updatedDLp)) | |
1389 | - | then dLpUpdateActions | |
1390 | - | else throwErr("nothing to refresh") | |
1391 | - | $Tuple2(actions, toString(updatedDLp)) | |
1392 | - | } | |
1393 | - | else throw("Strict value is not equal to itself.") | |
1394 | - | } | |
1395 | - | ||
1396 | - | ||
1397 | - | ||
1398 | - | @Callable(i) | |
1399 | 1046 | func getOneTknV2READONLY (outAssetId,lpAssetAmount) = { | |
1400 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
1401 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
1402 | - | let lpId = toBase58String(value(cfgLpAssetId)) | |
1047 | + | let poolConfig = gpc() | |
1048 | + | let amId = poolConfig[idxAmAsId] | |
1049 | + | let prId = poolConfig[idxPrAsId] | |
1050 | + | let lpId = poolConfig[idxLPAsId] | |
1403 | 1051 | let xp = [toBigInt(getAccBalance(amId)), toBigInt(getAccBalance(prId))] | |
1404 | 1052 | let lpEmission = toBigInt(valueOrErrorMessage(assetInfo(fromBase58String(lpId)), "invalid lp asset").quantity) | |
1405 | 1053 | let D0 = getD(xp) | |
1406 | 1054 | let D1 = (D0 - fraction(toBigInt(lpAssetAmount), D0, lpEmission)) | |
1407 | 1055 | let index = if ((outAssetId == amId)) | |
1408 | 1056 | then 0 | |
1409 | 1057 | else if ((outAssetId == prId)) | |
1410 | 1058 | then 1 | |
1411 | 1059 | else throw("invalid out asset id") | |
1412 | 1060 | let newY = getYD(xp, index, D1) | |
1413 | 1061 | let dy = (xp[index] - newY) | |
1414 | 1062 | let totalGetRaw = max([0, toInt((dy - big1))]) | |
1415 | - | let $ | |
1416 | - | let totalGet = $ | |
1417 | - | let feeAmount = $ | |
1063 | + | let $t03720337258 = takeFee(totalGetRaw, outFee) | |
1064 | + | let totalGet = $t03720337258._1 | |
1065 | + | let feeAmount = $t03720337258._2 | |
1418 | 1066 | $Tuple2(nil, $Tuple2(totalGet, feeAmount)) | |
1419 | 1067 | } | |
1420 | 1068 | ||
1421 | 1069 | ||
1422 | 1070 | ||
1423 | 1071 | @Callable(i) | |
1424 | 1072 | func getOneTknV2WithBonusREADONLY (outAssetId,lpAssetAmount) = { | |
1425 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
1426 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
1427 | - | let lpId = toBase58String(value(cfgLpAssetId)) | |
1073 | + | let poolConfig = gpc() | |
1074 | + | let amId = poolConfig[idxAmAsId] | |
1075 | + | let prId = poolConfig[idxPrAsId] | |
1076 | + | let lpId = poolConfig[idxLPAsId] | |
1428 | 1077 | let amBalance = getAccBalance(amId) | |
1429 | 1078 | let prBalance = getAccBalance(prId) | |
1430 | - | let $ | |
1079 | + | let $t03760337718 = { | |
1431 | 1080 | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, lpAssetAmount], nil) | |
1432 | 1081 | if ($isInstanceOf(@, "(Int, Int)")) | |
1433 | 1082 | then @ | |
1434 | 1083 | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
1435 | 1084 | } | |
1436 | - | let totalGet = $ | |
1437 | - | let feeAmount = $ | |
1085 | + | let totalGet = $t03760337718._1 | |
1086 | + | let feeAmount = $t03760337718._2 | |
1438 | 1087 | let r = ego("", lpId, lpAssetAmount, this) | |
1439 | 1088 | let outAmAmt = r._1 | |
1440 | 1089 | let outPrAmt = r._2 | |
1441 | 1090 | let sumOfGetAssets = (outAmAmt + outPrAmt) | |
1442 | 1091 | let bonus = if ((sumOfGetAssets == 0)) | |
1443 | 1092 | then if ((totalGet == 0)) | |
1444 | 1093 | then 0 | |
1445 | 1094 | else throw("bonus calculation error") | |
1446 | 1095 | else fraction((totalGet - sumOfGetAssets), scale8, sumOfGetAssets) | |
1447 | 1096 | $Tuple2(nil, $Tuple3(totalGet, feeAmount, bonus)) | |
1448 | 1097 | } | |
1449 | 1098 | ||
1450 | 1099 | ||
1451 | 1100 | ||
1452 | 1101 | @Callable(i) | |
1453 | 1102 | func getNoLess (noLessThenAmtAsset,noLessThenPriceAsset) = { | |
1454 | 1103 | let r = cg(i) | |
1455 | 1104 | let outAmAmt = r._1 | |
1456 | 1105 | let outPrAmt = r._2 | |
1457 | 1106 | let pmtAmt = r._3 | |
1458 | 1107 | let pmtAssetId = r._4 | |
1459 | 1108 | let state = r._5 | |
1460 | 1109 | if ((noLessThenAmtAsset > outAmAmt)) | |
1461 | 1110 | then throw(((("Failed: " + toString(outAmAmt)) + " < ") + toString(noLessThenAmtAsset))) | |
1462 | 1111 | else if ((noLessThenPriceAsset > outPrAmt)) | |
1463 | 1112 | then throw(((("Failed: " + toString(outPrAmt)) + " < ") + toString(noLessThenPriceAsset))) | |
1464 | 1113 | else { | |
1465 | - | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1466 | - | if ((currentDLp == currentDLp)) | |
1467 | - | then { | |
1468 | - | let burnLPAssetOnFactory = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1469 | - | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1470 | - | then { | |
1471 | - | let $t05148751568 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1472 | - | let refreshDLpActions = $t05148751568._1 | |
1473 | - | let updatedDLp = $t05148751568._2 | |
1474 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1475 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1476 | - | then (state ++ refreshDLpActions) | |
1477 | - | else throw("Strict value is not equal to itself.") | |
1478 | - | } | |
1479 | - | else throw("Strict value is not equal to itself.") | |
1480 | - | } | |
1114 | + | let burnLPAssetOnFactory = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1115 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1116 | + | then state | |
1481 | 1117 | else throw("Strict value is not equal to itself.") | |
1482 | 1118 | } | |
1483 | 1119 | } | |
1484 | 1120 | ||
1485 | 1121 | ||
1486 | 1122 | ||
1487 | 1123 | @Callable(i) | |
1488 | 1124 | func unstakeAndGet (amount) = { | |
1489 | 1125 | let checkPayments = if ((size(i.payments) != 0)) | |
1490 | 1126 | then throw("No pmnts expd") | |
1491 | 1127 | else true | |
1492 | 1128 | if ((checkPayments == checkPayments)) | |
1493 | 1129 | then { | |
1130 | + | let cfg = gpc() | |
1494 | 1131 | let factoryCfg = gfc() | |
1495 | - | let lpAssetId = | |
1132 | + | let lpAssetId = fromBase58String(cfg[idxLPAsId]) | |
1496 | 1133 | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1497 | - | let | |
1498 | - | if (( | |
1134 | + | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), amount], nil) | |
1135 | + | if ((unstakeInv == unstakeInv)) | |
1499 | 1136 | then { | |
1500 | - | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), amount], nil) | |
1501 | - | if ((unstakeInv == unstakeInv)) | |
1137 | + | let r = ego(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
1138 | + | let sts = parseIntValue(r._9) | |
1139 | + | let state = r._10 | |
1140 | + | let v = if (if (igs()) | |
1141 | + | then true | |
1142 | + | else (sts == PoolShutdown)) | |
1143 | + | then throw(("Blocked: " + toString(sts))) | |
1144 | + | else true | |
1145 | + | if ((v == v)) | |
1502 | 1146 | then { | |
1503 | - | let r = ego(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
1504 | - | let outAmAmt = r._1 | |
1505 | - | let outPrAmt = r._2 | |
1506 | - | let sts = parseIntValue(r._9) | |
1507 | - | let state = r._10 | |
1508 | - | let v = if (if (igs()) | |
1509 | - | then true | |
1510 | - | else (sts == PoolShutdown)) | |
1511 | - | then throw(("Blocked: " + toString(sts))) | |
1512 | - | else true | |
1513 | - | if ((v == v)) | |
1514 | - | then { | |
1515 | - | let burnA = invoke(fca, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1516 | - | if ((burnA == burnA)) | |
1517 | - | then { | |
1518 | - | let $t05259552676 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1519 | - | let refreshDLpActions = $t05259552676._1 | |
1520 | - | let updatedDLp = $t05259552676._2 | |
1521 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1522 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1523 | - | then (state ++ refreshDLpActions) | |
1524 | - | else throw("Strict value is not equal to itself.") | |
1525 | - | } | |
1526 | - | else throw("Strict value is not equal to itself.") | |
1527 | - | } | |
1147 | + | let burnA = invoke(fca, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1148 | + | if ((burnA == burnA)) | |
1149 | + | then state | |
1528 | 1150 | else throw("Strict value is not equal to itself.") | |
1529 | 1151 | } | |
1530 | 1152 | else throw("Strict value is not equal to itself.") | |
1531 | 1153 | } | |
1532 | 1154 | else throw("Strict value is not equal to itself.") | |
1533 | 1155 | } | |
1534 | 1156 | else throw("Strict value is not equal to itself.") | |
1535 | 1157 | } | |
1536 | 1158 | ||
1537 | 1159 | ||
1538 | 1160 | ||
1539 | 1161 | @Callable(i) | |
1540 | 1162 | func unstakeAndGetNoLess (unstakeAmount,noLessThenAmountAsset,noLessThenPriceAsset) = { | |
1541 | 1163 | let isGetDisabled = if (igs()) | |
1542 | 1164 | then true | |
1543 | 1165 | else (cfgPoolStatus == PoolShutdown) | |
1544 | 1166 | let checks = [if (!(isGetDisabled)) | |
1545 | 1167 | then true | |
1546 | 1168 | else throw("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1547 | 1169 | then true | |
1548 | 1170 | else throw("no payments are expected")] | |
1549 | 1171 | if ((checks == checks)) | |
1550 | 1172 | then { | |
1551 | - | let | |
1552 | - | if (( | |
1173 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1174 | + | if ((unstakeInv == unstakeInv)) | |
1553 | 1175 | then { | |
1554 | - | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1555 | - | if ((unstakeInv == unstakeInv)) | |
1176 | + | let res = ego(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller) | |
1177 | + | let outAmAmt = res._1 | |
1178 | + | let outPrAmt = res._2 | |
1179 | + | let state = res._10 | |
1180 | + | let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset)) | |
1181 | + | then true | |
1182 | + | else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset)) | |
1183 | + | then true | |
1184 | + | else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))] | |
1185 | + | if ((checkAmounts == checkAmounts)) | |
1556 | 1186 | then { | |
1557 | - | let res = ego(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller) | |
1558 | - | let outAmAmt = res._1 | |
1559 | - | let outPrAmt = res._2 | |
1560 | - | let state = res._10 | |
1561 | - | let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset)) | |
1562 | - | then true | |
1563 | - | else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset)) | |
1564 | - | then true | |
1565 | - | else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))] | |
1566 | - | if ((checkAmounts == checkAmounts)) | |
1567 | - | then { | |
1568 | - | let burnLPAssetOnFactory = invoke(fca, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1569 | - | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1570 | - | then { | |
1571 | - | let $t05392754008 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1572 | - | let refreshDLpActions = $t05392754008._1 | |
1573 | - | let updatedDLp = $t05392754008._2 | |
1574 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1575 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1576 | - | then (state ++ refreshDLpActions) | |
1577 | - | else throw("Strict value is not equal to itself.") | |
1578 | - | } | |
1579 | - | else throw("Strict value is not equal to itself.") | |
1580 | - | } | |
1187 | + | let burnLPAssetOnFactory = invoke(fca, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1188 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1189 | + | then state | |
1581 | 1190 | else throw("Strict value is not equal to itself.") | |
1582 | 1191 | } | |
1583 | 1192 | else throw("Strict value is not equal to itself.") | |
1584 | 1193 | } | |
1585 | 1194 | else throw("Strict value is not equal to itself.") | |
1586 | 1195 | } | |
1587 | 1196 | else throw("Strict value is not equal to itself.") | |
1588 | 1197 | } | |
1589 | 1198 | ||
1590 | 1199 | ||
1591 | 1200 | ||
1592 | 1201 | @Callable(i) | |
1593 | 1202 | func unstakeAndGetOneTknV2 (unstakeAmount,outAssetId,minOutAmount) = { | |
1594 | 1203 | let isPoolOneTokenOperationsDisabled = { | |
1595 | 1204 | let @ = invoke(fca, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1596 | 1205 | if ($isInstanceOf(@, "Boolean")) | |
1597 | 1206 | then @ | |
1598 | 1207 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1599 | 1208 | } | |
1600 | 1209 | let isGetDisabled = if (if (igs()) | |
1601 | 1210 | then true | |
1602 | 1211 | else (cfgPoolStatus == PoolShutdown)) | |
1603 | 1212 | then true | |
1604 | 1213 | else isPoolOneTokenOperationsDisabled | |
1605 | 1214 | let checks = [if (if (!(isGetDisabled)) | |
1606 | 1215 | then true | |
1607 | 1216 | else isManager(i)) | |
1608 | 1217 | then true | |
1609 | 1218 | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1610 | 1219 | then true | |
1611 | 1220 | else throwErr("no payments are expected")] | |
1612 | 1221 | if ((checks == checks)) | |
1613 | 1222 | then { | |
1223 | + | let cfg = gpc() | |
1614 | 1224 | let factoryCfg = gfc() | |
1615 | - | let lpAssetId = | |
1225 | + | let lpAssetId = fromBase58String(cfg[idxLPAsId]) | |
1616 | 1226 | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1617 | - | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), unstakeAmount], nil) | |
1227 | + | let userAddress = i.caller | |
1228 | + | let lpAssetRecipientAddress = this | |
1229 | + | let unstakeInv = invoke(staking, "unstakeINTERNAL", [lpAssetId, unstakeAmount, userAddress.bytes, lpAssetRecipientAddress.bytes], nil) | |
1618 | 1230 | if ((unstakeInv == unstakeInv)) | |
1619 | 1231 | then { | |
1620 | - | let $ | |
1621 | - | let state = $ | |
1622 | - | let totalAmount = $ | |
1232 | + | let $t04168341871 = getOneTknV2Internal(outAssetId, minOutAmount, [AttachedPayment(lpAssetId, unstakeAmount)], i.caller, i.originCaller, i.transactionId) | |
1233 | + | let state = $t04168341871._1 | |
1234 | + | let totalAmount = $t04168341871._2 | |
1623 | 1235 | $Tuple2(state, totalAmount) | |
1624 | 1236 | } | |
1625 | 1237 | else throw("Strict value is not equal to itself.") | |
1626 | 1238 | } | |
1627 | 1239 | else throw("Strict value is not equal to itself.") | |
1628 | 1240 | } | |
1629 | 1241 | ||
1630 | 1242 | ||
1631 | 1243 | ||
1632 | 1244 | @Callable(i) | |
1633 | 1245 | func putOneTknV2WithBonusREADONLY (paymentAmountRaw,paymentAssetId) = { | |
1634 | - | let $t05521955322 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", true) | |
1635 | - | let lpAmount = $t05521955322._1 | |
1636 | - | let state = $t05521955322._2 | |
1637 | - | let feeAmount = $t05521955322._3 | |
1638 | - | let bonus = $t05521955322._4 | |
1246 | + | let poolConfig = gpc() | |
1247 | + | let amId = poolConfig[idxAmAsId] | |
1248 | + | let prId = poolConfig[idxPrAsId] | |
1249 | + | let lpId = poolConfig[idxLPAsId] | |
1250 | + | let $t04213042233 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", true) | |
1251 | + | let lpAmount = $t04213042233._1 | |
1252 | + | let state = $t04213042233._2 | |
1253 | + | let feeAmount = $t04213042233._3 | |
1254 | + | let bonus = $t04213042233._4 | |
1639 | 1255 | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1640 | 1256 | } | |
1641 | 1257 | ||
1642 | 1258 | ||
1643 | 1259 | ||
1644 | 1260 | @Callable(i) | |
1645 | 1261 | func putOneTknV2WithoutTakeFeeREADONLY (paymentAmountRaw,paymentAssetId) = { | |
1646 | - | let $t05547055574 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", false) | |
1647 | - | let lpAmount = $t05547055574._1 | |
1648 | - | let state = $t05547055574._2 | |
1649 | - | let feeAmount = $t05547055574._3 | |
1650 | - | let bonus = $t05547055574._4 | |
1262 | + | let poolConfig = gpc() | |
1263 | + | let amId = poolConfig[idxAmAsId] | |
1264 | + | let prId = poolConfig[idxPrAsId] | |
1265 | + | let lpId = poolConfig[idxLPAsId] | |
1266 | + | let $t04251242616 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", false) | |
1267 | + | let lpAmount = $t04251242616._1 | |
1268 | + | let state = $t04251242616._2 | |
1269 | + | let feeAmount = $t04251242616._3 | |
1270 | + | let bonus = $t04251242616._4 | |
1651 | 1271 | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1652 | 1272 | } | |
1653 | 1273 | ||
1654 | 1274 | ||
1655 | 1275 | ||
1656 | 1276 | @Callable(i) | |
1657 | 1277 | func activate (amtAsStr,prAsStr) = if ((toString(i.caller) != toString(fca))) | |
1658 | 1278 | then throw("denied") | |
1659 | 1279 | else $Tuple2([StringEntry(aa(), amtAsStr), StringEntry(pa(), prAsStr)], "success") | |
1660 | 1280 | ||
1661 | 1281 | ||
1662 | 1282 | ||
1663 | 1283 | @Callable(i) | |
1664 | 1284 | func setS (k,v) = if ((toString(i.caller) != strf(this, ada()))) | |
1665 | 1285 | then pd | |
1666 | 1286 | else [StringEntry(k, v)] | |
1667 | 1287 | ||
1668 | 1288 | ||
1669 | 1289 | ||
1670 | 1290 | @Callable(i) | |
1671 | 1291 | func setI (k,v) = if ((toString(i.caller) != strf(this, ada()))) | |
1672 | 1292 | then pd | |
1673 | 1293 | else [IntegerEntry(k, v)] | |
1674 | 1294 | ||
1675 | 1295 | ||
1676 | 1296 | ||
1677 | 1297 | @Callable(i) | |
1678 | 1298 | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, gpc()) | |
1679 | 1299 | ||
1680 | 1300 | ||
1681 | 1301 | ||
1682 | 1302 | @Callable(i) | |
1683 | 1303 | func getAccBalanceWrapperREADONLY (assetId) = $Tuple2(nil, getAccBalance(assetId)) | |
1684 | 1304 | ||
1685 | 1305 | ||
1686 | 1306 | ||
1687 | 1307 | @Callable(i) | |
1688 | 1308 | func calcPricesWrapperREADONLY (amAmt,prAmt,lpAmt) = { | |
1689 | 1309 | let pr = calcPrices(amAmt, prAmt, lpAmt) | |
1690 | 1310 | $Tuple2(nil, [toString(pr[0]), toString(pr[1]), toString(pr[2])]) | |
1691 | 1311 | } | |
1692 | 1312 | ||
1693 | 1313 | ||
1694 | 1314 | ||
1695 | 1315 | @Callable(i) | |
1696 | 1316 | func fromX18WrapperREADONLY (val,resScaleMult) = $Tuple2(nil, f1(parseBigIntValue(val), resScaleMult)) | |
1697 | 1317 | ||
1698 | 1318 | ||
1699 | 1319 | ||
1700 | 1320 | @Callable(i) | |
1701 | 1321 | func toX18WrapperREADONLY (origVal,origScaleMult) = $Tuple2(nil, toString(t1(origVal, origScaleMult))) | |
1702 | 1322 | ||
1703 | 1323 | ||
1704 | 1324 | ||
1705 | 1325 | @Callable(i) | |
1706 | 1326 | func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString(cpbi(parseBigIntValue(prAmtX18), parseBigIntValue(amAmtX18)))) | |
1707 | 1327 | ||
1708 | 1328 | ||
1709 | 1329 | ||
1710 | 1330 | @Callable(i) | |
1711 | 1331 | func estimatePutOperationWrapperREADONLY (txId58,slippage,inAmAmt,inAmId,inPrAmt,inPrId,usrAddr,isEval,emitLp) = $Tuple2(nil, epo(txId58, slippage, inAmAmt, inAmId, inPrAmt, inPrId, usrAddr, isEval, emitLp, true, false, 0, "")) | |
1712 | 1332 | ||
1713 | 1333 | ||
1714 | 1334 | ||
1715 | 1335 | @Callable(i) | |
1716 | 1336 | func estimateGetOperationWrapperREADONLY (txId58,pmtAsId,pmtLpAmt,usrAddr) = { | |
1717 | 1337 | let r = ego(txId58, pmtAsId, pmtLpAmt, addressFromStringValue(usrAddr)) | |
1718 | 1338 | $Tuple2(nil, $Tuple10(r._1, r._2, r._3, r._4, r._5, r._6, r._7, toString(r._8), r._9, r._10)) | |
1719 | 1339 | } | |
1720 | 1340 | ||
1721 | 1341 | ||
1722 | 1342 | @Verifier(tx) | |
1723 | 1343 | func verify () = { | |
1724 | 1344 | let targetPublicKey = match m() { | |
1725 | 1345 | case pk: ByteVector => | |
1726 | 1346 | pk | |
1727 | 1347 | case _: Unit => | |
1728 | 1348 | tx.senderPublicKey | |
1729 | 1349 | case _ => | |
1730 | 1350 | throw("Match error") | |
1731 | 1351 | } | |
1732 | 1352 | match tx { | |
1733 | 1353 | case order: Order => | |
1734 | 1354 | let matcherPub = mp() | |
1735 | - | let $t05836658435 = validateMatcherOrderAllowed(order) | |
1736 | - | let orderValid = $t05836658435._1 | |
1737 | - | let orderValidInfo = $t05836658435._2 | |
1355 | + | let orderValid = moa(order) | |
1738 | 1356 | let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
1739 | 1357 | let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub) | |
1740 | 1358 | if (if (if (orderValid) | |
1741 | 1359 | then senderValid | |
1742 | 1360 | else false) | |
1743 | 1361 | then matcherValid | |
1744 | 1362 | else false) | |
1745 | 1363 | then true | |
1746 | - | else | |
1364 | + | else toe(orderValid, senderValid, matcherValid) | |
1747 | 1365 | case s: SetScriptTransaction => | |
1748 | - | if (sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)) | |
1366 | + | let newHash = blake2b256(value(s.script)) | |
1367 | + | let allowedHash = fromBase64String(value(getString(fca, keyAllowedLpStableScriptHash()))) | |
1368 | + | let currentHash = scriptHash(this) | |
1369 | + | if (if ((allowedHash == newHash)) | |
1370 | + | then (currentHash != newHash) | |
1371 | + | else false) | |
1749 | 1372 | then true | |
1750 | - | else { | |
1751 | - | let newHash = blake2b256(value(s.script)) | |
1752 | - | let allowedHash = fromBase64String(value(getString(fca, keyAllowedLpStableScriptHash()))) | |
1753 | - | let currentHash = scriptHash(this) | |
1754 | - | if ((allowedHash == newHash)) | |
1755 | - | then (currentHash != newHash) | |
1756 | - | else false | |
1757 | - | } | |
1373 | + | else sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1758 | 1374 | case _ => | |
1759 | 1375 | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1760 | 1376 | } | |
1761 | 1377 | } | |
1762 | 1378 |
github/deemru/w8io/026f985 201.99 ms ◑