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