tx · GeE4KG5d4Hrq1FxkHiryNNZkcTWzx7DUdmah2zzt8wNN 3NAefciWv6f9fWvEXdGgpHfanJFG8HqfjuT: -0.03900000 Waves 2023.02.09 12:51 [2441946] smart account 3NAefciWv6f9fWvEXdGgpHfanJFG8HqfjuT > SELF 0.00000000 Waves
{ "type": 13, "id": "GeE4KG5d4Hrq1FxkHiryNNZkcTWzx7DUdmah2zzt8wNN", "fee": 3900000, "feeAssetId": null, "timestamp": 1675936262002, "version": 2, "chainId": 84, "sender": "3NAefciWv6f9fWvEXdGgpHfanJFG8HqfjuT", "senderPublicKey": "D1BL65meykxFZTCuq7jq9HSGLLnWvQamQPUNrguW5w39", "proofs": [ "tA17RTegwngLv4CJmhz5hAfFB6sc67eLkk8p73CpLxHpGCytTnQLE1MUt9ynEyNZoyNBuoh5PUDgys7pZ21j2UL" ], "script": "base64:BgLYKggCEgQKAgEEEgYKBAEEAQgSAwoBCBIDCgEIEgASBAoCAQQSBAoCAQQSAwoBARIAEgQKAggBEgASBAoCCAESBAoCCAESBAoCAQESAwoBARIFCgMBAQESBQoDAQgBEgQKAgEIEgQKAgEIEgQKAggIEgQKAggIEgQKAggBEgASAwoBCBIFCgMBAQESBAoCCAESBAoCAQESBAoCCAgSCwoJCAEBAgECCAQEEgYKBAgIAQgiBnNjYWxlOCIMc2NhbGU4QmlnSW50IgdzY2FsZTE4Igp6ZXJvQmlnSW50IgRiaWcwIgRiaWcxIgRiaWcyIgRiaWczIgRiaWc0IgpzbGlwcGFnZTREIgt3YXZlc1N0cmluZyIFQW11bHQiBURjb252IgNTRVAiBUVNUFRZIgpQb29sQWN0aXZlIgpQb29sUHV0RGlzIg5Qb29sTWF0Y2hlckRpcyIMUG9vbFNodXRkb3duIg5pZHhQb29sQWRkcmVzcyIJaWR4UG9vbFN0IglpZHhMUEFzSWQiCWlkeEFtQXNJZCIJaWR4UHJBc0lkIgtpZHhBbXRBc0RjbSINaWR4UHJpY2VBc0RjbSILaWR4SUFtdEFzSWQiD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wMIBQJlWglib2R5Qnl0ZXMJAJEDAggFAmVaBnByb29mcwABBQJpagMDAwUCYUYFAmFIBwUCYUkHBgkBAmFFBAUCYUYFAmFHBQJhSAUCYUkDCQABAgUCZ2wCFFNldFNjcmlwdFRyYW5zYWN0aW9uBAJjQwUCZ2wDCQD0AwMIBQJpZwlib2R5Qnl0ZXMJAJEDAggFAmlnBnByb29mcwAABQJpaQYEAmlsCQD2AwEJAQV2YWx1ZQEIBQJjQwZzY3JpcHQEAmltCQDbBAEJAQV2YWx1ZQEJAJ0IAgUCYVEJAQJhQwAEAmluCQDxBwEFBHRoaXMDCQAAAgUCaW0FAmlsCQECIT0CBQJpbgUCaWwHCQD0AwMIBQJpZwlib2R5Qnl0ZXMJAJEDAggFAmlnBnByb29mcwAABQJpaV4cxMs=", "height": 2441946, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 7CLV6ivn8wgpx7bfYAuMh4ycvfpSikVdh6soTQ2fLCd8 Next: 84vGc8UaLAsvFNuz7VVRUTbGsSib6ifQjqANt5P4bRMC 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 | ||
813 | 902 | let c = (((((D * D) / (x * n)) * D) * aPrecision) / (ann * n)) | |
814 | 903 | let b = ((s + ((D * aPrecision) / ann)) - D) | |
815 | 904 | func calc (acc,cur) = { | |
816 | - | let $ | |
817 | - | let y = $ | |
818 | - | let found = $ | |
905 | + | let $t03431534335 = acc | |
906 | + | let y = $t03431534335._1 | |
907 | + | let found = $t03431534335._2 | |
819 | 908 | if ((found != unit)) | |
820 | 909 | then acc | |
821 | 910 | else { | |
828 | 917 | } | |
829 | 918 | ||
830 | 919 | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
831 | - | let $ | |
920 | + | let $t03466634713 = { | |
832 | 921 | let $l = arr | |
833 | 922 | let $s = size($l) | |
834 | 923 | let $acc0 = $Tuple2(D, unit) | |
842 | 931 | ||
843 | 932 | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
844 | 933 | } | |
845 | - | let y = $ | |
846 | - | let found = $ | |
934 | + | let y = $t03466634713._1 | |
935 | + | let found = $t03466634713._2 | |
847 | 936 | if ((found != unit)) | |
848 | 937 | then y | |
849 | 938 | else throw(("Y calculation error, Y = " + toString(y))) | |
852 | 941 | ||
853 | 942 | @Callable(i) | |
854 | 943 | func calculateAmountOutForSwapREADONLY (cleanAmountIn,isReverse) = { | |
855 | - | let $ | |
944 | + | let $t03493435358 = if ((isReverse == false)) | |
856 | 945 | then { | |
857 | 946 | let assetOut = strf(this, pa()) | |
858 | 947 | let poolAmountInBalance = (toBigInt(getAccBalance(strf(this, aa()))) + toBigInt(cleanAmountIn)) | |
863 | 952 | let poolAmountInBalance = (toBigInt(getAccBalance(strf(this, pa()))) + toBigInt(cleanAmountIn)) | |
864 | 953 | $Tuple2(assetOut, poolAmountInBalance) | |
865 | 954 | } | |
866 | - | let assetOut = $ | |
867 | - | let poolAmountInBalance = $ | |
955 | + | let assetOut = $t03493435358._1 | |
956 | + | let poolAmountInBalance = $t03493435358._2 | |
868 | 957 | let poolConfig = gpc() | |
869 | 958 | let amId = poolConfig[idxAmAsId] | |
870 | 959 | let prId = poolConfig[idxPrAsId] | |
889 | 978 | ||
890 | 979 | @Callable(i) | |
891 | 980 | func calculateAmountOutForSwapAndSendTokens (cleanAmountIn,isReverse,amountOutMin,addressTo) = { | |
981 | + | let swapContact = { | |
982 | + | let @ = invoke(addressFromStringValue(fc()), "getSwapContractREADONLY", nil, nil) | |
983 | + | if ($isInstanceOf(@, "String")) | |
984 | + | then @ | |
985 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
986 | + | } | |
892 | 987 | let checks = [if ((value(i.payments[0]).amount >= cleanAmountIn)) | |
893 | 988 | then true | |
894 | - | else throwErr("Wrong amount"), if ((i.caller == addressFromStringValue( | |
989 | + | else throwErr("Wrong amount"), if ((i.caller == addressFromStringValue(swapContact))) | |
895 | 990 | then true | |
896 | 991 | else throwErr("Permission denied")] | |
897 | 992 | if ((checks == checks)) | |
900 | 995 | let assetIn = if ((pmt.assetId == unit)) | |
901 | 996 | then toBase58String(toBytes("WAVES")) | |
902 | 997 | else toBase58String(value(pmt.assetId)) | |
903 | - | let $ | |
998 | + | let $t03682137215 = if ((isReverse == false)) | |
904 | 999 | then { | |
905 | 1000 | let assetOut = strf(this, pa()) | |
906 | 1001 | let poolAmountInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount) | |
911 | 1006 | let poolAmountInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount) | |
912 | 1007 | $Tuple2(assetOut, poolAmountInBalance) | |
913 | 1008 | } | |
914 | - | let assetOut = $ | |
915 | - | let poolAmountInBalance = $ | |
1009 | + | let assetOut = $t03682137215._1 | |
1010 | + | let poolAmountInBalance = $t03682137215._2 | |
916 | 1011 | let poolConfig = gpc() | |
917 | 1012 | let amId = poolConfig[idxAmAsId] | |
918 | 1013 | let prId = poolConfig[idxPrAsId] | |
1003 | 1098 | else if ((size(i.payments) != 2)) | |
1004 | 1099 | then throw("2 pmnts expd") | |
1005 | 1100 | 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)) | |
1101 | + | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1102 | + | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1103 | + | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amAssetPmt) | |
1104 | + | if ((amountAssetBalance == amountAssetBalance)) | |
1016 | 1105 | 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)) | |
1106 | + | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - prAssetPmt) | |
1107 | + | if ((priceAssetBalance == priceAssetBalance)) | |
1024 | 1108 | then { | |
1025 | - | let sa = if ((amDiff > 0)) | |
1026 | - | then invoke(slipCntr, "put", nil, [AttachedPayment(amId, amDiff)]) | |
1027 | - | else nil | |
1028 | - | if ((sa == sa)) | |
1109 | + | let lpAssetEmission = toBigInt(value(assetInfo(cfgLpAssetId)).quantity) | |
1110 | + | if ((lpAssetEmission == lpAssetEmission)) | |
1029 | 1111 | then { | |
1030 | - | let sp = if ((prDiff > 0)) | |
1031 | - | then invoke(slipCntr, "put", nil, [AttachedPayment(prId, prDiff)]) | |
1032 | - | else nil | |
1033 | - | if ((sp == sp)) | |
1112 | + | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1113 | + | if ((currentDLp == currentDLp)) | |
1034 | 1114 | then { | |
1035 | - | let lpTrnsfr = if (autoStake) | |
1115 | + | 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, "") | |
1116 | + | let emitLpAmt = e._2 | |
1117 | + | let lpAssetId = e._7 | |
1118 | + | let state = e._9 | |
1119 | + | let amDiff = e._10 | |
1120 | + | let prDiff = e._11 | |
1121 | + | let amId = e._12 | |
1122 | + | let prId = e._13 | |
1123 | + | let r = invoke(fca, "emit", [emitLpAmt], nil) | |
1124 | + | if ((r == r)) | |
1036 | 1125 | then { | |
1037 | - | let ss = invoke(stakingCntr, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
1038 | - | if ((ss == ss)) | |
1039 | - | then nil | |
1126 | + | let el = match r { | |
1127 | + | case legacy: Address => | |
1128 | + | invoke(legacy, "emit", [emitLpAmt], nil) | |
1129 | + | case _ => | |
1130 | + | unit | |
1131 | + | } | |
1132 | + | if ((el == el)) | |
1133 | + | then { | |
1134 | + | let sa = if ((amDiff > 0)) | |
1135 | + | then invoke(slipCntr, "put", nil, [AttachedPayment(amId, amDiff)]) | |
1136 | + | else nil | |
1137 | + | if ((sa == sa)) | |
1138 | + | then { | |
1139 | + | let sp = if ((prDiff > 0)) | |
1140 | + | then invoke(slipCntr, "put", nil, [AttachedPayment(prId, prDiff)]) | |
1141 | + | else nil | |
1142 | + | if ((sp == sp)) | |
1143 | + | then { | |
1144 | + | let lpTrnsfr = if (autoStake) | |
1145 | + | then { | |
1146 | + | let ss = invoke(stakingCntr, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
1147 | + | if ((ss == ss)) | |
1148 | + | then nil | |
1149 | + | else throw("Strict value is not equal to itself.") | |
1150 | + | } | |
1151 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
1152 | + | let $t04207642218 = refreshDLpInternal(0, 0, 0) | |
1153 | + | let refreshDLpActions = $t04207642218._1 | |
1154 | + | let updatedDLp = $t04207642218._2 | |
1155 | + | let check = if ((updatedDLp >= currentDLp)) | |
1156 | + | then true | |
1157 | + | else throwErr(makeString(["updated DLp lower than current DLp", toString(amountAssetBalance), toString(priceAssetBalance), toString(lpAssetEmission), toString(currentDLp), toString(updatedDLp), toString(amDiff), toString(prDiff)], " ")) | |
1158 | + | if ((check == check)) | |
1159 | + | then { | |
1160 | + | let lpAssetEmissionAfter = value(assetInfo(cfgLpAssetId)).quantity | |
1161 | + | if ((lpAssetEmissionAfter == lpAssetEmissionAfter)) | |
1162 | + | then ((state ++ lpTrnsfr) ++ refreshDLpActions) | |
1163 | + | else throw("Strict value is not equal to itself.") | |
1164 | + | } | |
1165 | + | else throw("Strict value is not equal to itself.") | |
1166 | + | } | |
1167 | + | else throw("Strict value is not equal to itself.") | |
1168 | + | } | |
1169 | + | else throw("Strict value is not equal to itself.") | |
1170 | + | } | |
1040 | 1171 | else throw("Strict value is not equal to itself.") | |
1041 | 1172 | } | |
1042 | - | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
1043 | - | (state ++ lpTrnsfr) | |
1173 | + | else throw("Strict value is not equal to itself.") | |
1044 | 1174 | } | |
1045 | 1175 | else throw("Strict value is not equal to itself.") | |
1046 | 1176 | } | |
1078 | 1208 | else throwErr("exactly 1 payment are expected")] | |
1079 | 1209 | if ((checks == checks)) | |
1080 | 1210 | 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]) | |
1211 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
1212 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
1213 | + | let lpId = cfgLpAssetId | |
1214 | + | let amDecimals = cfgAmountAssetDecimals | |
1215 | + | let prDecimals = cfgPriceAssetDecimals | |
1087 | 1216 | let userAddress = if ((i.caller == this)) | |
1088 | 1217 | then i.originCaller | |
1089 | 1218 | else i.caller | |
1090 | 1219 | let pmt = value(i.payments[0]) | |
1091 | 1220 | let pmtAssetId = toBase58String(value(pmt.assetId)) | |
1092 | 1221 | let pmtAmt = pmt.amount | |
1093 | - | let $t03879838956 = calcPutOneTkn(pmtAmt, pmtAssetId, toString(userAddress), toBase58String(i.transactionId), true) | |
1094 | - | if (($t03879838956 == $t03879838956)) | |
1222 | + | let currentDLp = if ((pmt.assetId == cfgAmountAssetId)) | |
1223 | + | then calcCurrentDLp(toBigInt(pmtAmt), toBigInt(0), toBigInt(0)) | |
1224 | + | else calcCurrentDLp(toBigInt(0), toBigInt(pmtAmt), toBigInt(0)) | |
1225 | + | if ((currentDLp == currentDLp)) | |
1095 | 1226 | 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)) | |
1227 | + | let $t04385944017 = calcPutOneTkn(pmtAmt, pmtAssetId, toString(userAddress), toBase58String(i.transactionId), true) | |
1228 | + | if (($t04385944017 == $t04385944017)) | |
1106 | 1229 | 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)) | |
1230 | + | let feeAmount = $t04385944017._3 | |
1231 | + | let state = $t04385944017._2 | |
1232 | + | let estimLP = $t04385944017._1 | |
1233 | + | let emitLpAmt = if (if ((minOutAmount > 0)) | |
1234 | + | then (minOutAmount > estimLP) | |
1235 | + | else false) | |
1236 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
1237 | + | else estimLP | |
1238 | + | let e = invoke(fca, "emit", [emitLpAmt], nil) | |
1239 | + | if ((e == e)) | |
1114 | 1240 | then { | |
1115 | - | let lpTrnsfr = if (autoStake) | |
1241 | + | let el = match e { | |
1242 | + | case legacy: Address => | |
1243 | + | invoke(legacy, "emit", [emitLpAmt], nil) | |
1244 | + | case _ => | |
1245 | + | unit | |
1246 | + | } | |
1247 | + | if ((el == el)) | |
1116 | 1248 | then { | |
1117 | - | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpId, emitLpAmt)]) | |
1118 | - | if ((ss == ss)) | |
1119 | - | then nil | |
1249 | + | let lpTrnsfr = if (autoStake) | |
1250 | + | then { | |
1251 | + | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpId, emitLpAmt)]) | |
1252 | + | if ((ss == ss)) | |
1253 | + | then nil | |
1254 | + | else throw("Strict value is not equal to itself.") | |
1255 | + | } | |
1256 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpId)] | |
1257 | + | let sendFeeToMatcher = if ((feeAmount > 0)) | |
1258 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, fromBase58String(pmtAssetId))] | |
1259 | + | else nil | |
1260 | + | let $t04483245181 = if ((this == feeCollectorAddress)) | |
1261 | + | then $Tuple2(0, 0) | |
1262 | + | else { | |
1263 | + | let paymentInAmountAsset = if ((pmt.assetId == cfgAmountAssetId)) | |
1264 | + | then true | |
1265 | + | else false | |
1266 | + | if (paymentInAmountAsset) | |
1267 | + | then $Tuple2(-(feeAmount), 0) | |
1268 | + | else $Tuple2(0, -(feeAmount)) | |
1269 | + | } | |
1270 | + | let amountAssetBalanceDelta = $t04483245181._1 | |
1271 | + | let priceAssetBalanceDelta = $t04483245181._2 | |
1272 | + | let $t04518445292 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1273 | + | let refreshDLpActions = $t04518445292._1 | |
1274 | + | let updatedDLp = $t04518445292._2 | |
1275 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1276 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1277 | + | then $Tuple2((((state ++ lpTrnsfr) ++ sendFeeToMatcher) ++ refreshDLpActions), emitLpAmt) | |
1120 | 1278 | else throw("Strict value is not equal to itself.") | |
1121 | 1279 | } | |
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) | |
1280 | + | else throw("Strict value is not equal to itself.") | |
1127 | 1281 | } | |
1128 | 1282 | else throw("Strict value is not equal to itself.") | |
1129 | 1283 | } | |
1143 | 1297 | then throw("2 pmnts expd") | |
1144 | 1298 | else { | |
1145 | 1299 | 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 | |
1300 | + | let state = estPut._9 | |
1301 | + | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1302 | + | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1303 | + | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1304 | + | if ((currentDLp == currentDLp)) | |
1305 | + | then { | |
1306 | + | let $t04632246387 = refreshDLpInternal(0, 0, 0) | |
1307 | + | let refreshDLpActions = $t04632246387._1 | |
1308 | + | let updatedDLp = $t04632246387._2 | |
1309 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1310 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1311 | + | then (state ++ refreshDLpActions) | |
1312 | + | else throw("Strict value is not equal to itself.") | |
1313 | + | } | |
1314 | + | else throw("Strict value is not equal to itself.") | |
1147 | 1315 | } | |
1148 | 1316 | ||
1149 | 1317 | ||
1150 | 1318 | ||
1151 | 1319 | @Callable(i) | |
1152 | 1320 | 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 | |
1321 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1322 | + | if ((currentDLp == currentDLp)) | |
1323 | + | then { | |
1324 | + | let r = cg(i) | |
1325 | + | let outAmtAmt = r._1 | |
1326 | + | let outPrAmt = r._2 | |
1327 | + | let pmtAmt = r._3 | |
1328 | + | let pmtAssetId = r._4 | |
1329 | + | let state = r._5 | |
1330 | + | let b = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1331 | + | if ((b == b)) | |
1332 | + | then { | |
1333 | + | let $t04756047642 = refreshDLpInternal(-(outAmtAmt), -(outPrAmt), 0) | |
1334 | + | let refreshDLpActions = $t04756047642._1 | |
1335 | + | let updatedDLp = $t04756047642._2 | |
1336 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1337 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1338 | + | then (state ++ refreshDLpActions) | |
1339 | + | else throw("Strict value is not equal to itself.") | |
1340 | + | } | |
1341 | + | else throw("Strict value is not equal to itself.") | |
1342 | + | } | |
1162 | 1343 | else throw("Strict value is not equal to itself.") | |
1163 | 1344 | } | |
1164 | 1345 | ||
1186 | 1367 | else throwErr("exactly 1 payment are expected")] | |
1187 | 1368 | if ((checks == checks)) | |
1188 | 1369 | then { | |
1189 | - | let $ | |
1190 | - | let state = $ | |
1191 | - | let totalAmount = $ | |
1370 | + | let $t04826048415 = getOneTknV2Internal(outAssetId, minOutAmount, i.payments, i.caller, i.originCaller, i.transactionId) | |
1371 | + | let state = $t04826048415._1 | |
1372 | + | let totalAmount = $t04826048415._2 | |
1192 | 1373 | $Tuple2(state, totalAmount) | |
1193 | 1374 | } | |
1194 | 1375 | else throw("Strict value is not equal to itself.") | |
1197 | 1378 | ||
1198 | 1379 | ||
1199 | 1380 | @Callable(i) | |
1381 | + | func refreshDLp () = { | |
1382 | + | let lastRefreshedBlockHeight = valueOrElse(getInteger(keyDLpRefreshedHeight), 0) | |
1383 | + | let checkLastRefreshedBlockHeight = if (((height - lastRefreshedBlockHeight) >= dLpRefreshDelay)) | |
1384 | + | then unit | |
1385 | + | else throwErr(makeString([toString(dLpRefreshDelay), " blocks have not passed since the previous call"], "")) | |
1386 | + | if ((checkLastRefreshedBlockHeight == checkLastRefreshedBlockHeight)) | |
1387 | + | then { | |
1388 | + | let dLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyDLp), "0")), fmtErr("invalid dLp")) | |
1389 | + | let $t04893949003 = refreshDLpInternal(0, 0, 0) | |
1390 | + | let dLpUpdateActions = $t04893949003._1 | |
1391 | + | let updatedDLp = $t04893949003._2 | |
1392 | + | let actions = if ((dLp != updatedDLp)) | |
1393 | + | then dLpUpdateActions | |
1394 | + | else throwErr("nothing to refresh") | |
1395 | + | $Tuple2(actions, toString(updatedDLp)) | |
1396 | + | } | |
1397 | + | else throw("Strict value is not equal to itself.") | |
1398 | + | } | |
1399 | + | ||
1400 | + | ||
1401 | + | ||
1402 | + | @Callable(i) | |
1200 | 1403 | func getOneTknV2READONLY (outAssetId,lpAssetAmount) = { | |
1201 | - | let poolConfig = gpc() | |
1202 | - | let amId = poolConfig[idxAmAsId] | |
1203 | - | let prId = poolConfig[idxPrAsId] | |
1204 | - | let lpId = poolConfig[idxLPAsId] | |
1404 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
1405 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
1406 | + | let lpId = toBase58String(value(cfgLpAssetId)) | |
1205 | 1407 | let xp = [toBigInt(getAccBalance(amId)), toBigInt(getAccBalance(prId))] | |
1206 | 1408 | let lpEmission = toBigInt(valueOrErrorMessage(assetInfo(fromBase58String(lpId)), "invalid lp asset").quantity) | |
1207 | 1409 | let D0 = getD(xp) | |
1214 | 1416 | let newY = getYD(xp, index, D1) | |
1215 | 1417 | let dy = (xp[index] - newY) | |
1216 | 1418 | let totalGetRaw = max([0, toInt((dy - big1))]) | |
1217 | - | let $ | |
1218 | - | let totalGet = $ | |
1219 | - | let feeAmount = $ | |
1419 | + | let $t05001350068 = takeFee(totalGetRaw, outFee) | |
1420 | + | let totalGet = $t05001350068._1 | |
1421 | + | let feeAmount = $t05001350068._2 | |
1220 | 1422 | $Tuple2(nil, $Tuple2(totalGet, feeAmount)) | |
1221 | 1423 | } | |
1222 | 1424 | ||
1224 | 1426 | ||
1225 | 1427 | @Callable(i) | |
1226 | 1428 | func getOneTknV2WithBonusREADONLY (outAssetId,lpAssetAmount) = { | |
1227 | - | let poolConfig = gpc() | |
1228 | - | let amId = poolConfig[idxAmAsId] | |
1229 | - | let prId = poolConfig[idxPrAsId] | |
1230 | - | let lpId = poolConfig[idxLPAsId] | |
1429 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
1430 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
1431 | + | let lpId = toBase58String(value(cfgLpAssetId)) | |
1231 | 1432 | let amBalance = getAccBalance(amId) | |
1232 | 1433 | let prBalance = getAccBalance(prId) | |
1233 | - | let $ | |
1434 | + | let $t05044350558 = { | |
1234 | 1435 | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, lpAssetAmount], nil) | |
1235 | 1436 | if ($isInstanceOf(@, "(Int, Int)")) | |
1236 | 1437 | then @ | |
1237 | 1438 | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
1238 | 1439 | } | |
1239 | - | let totalGet = $ | |
1240 | - | let feeAmount = $ | |
1440 | + | let totalGet = $t05044350558._1 | |
1441 | + | let feeAmount = $t05044350558._2 | |
1241 | 1442 | let r = ego("", lpId, lpAssetAmount, this) | |
1242 | 1443 | let outAmAmt = r._1 | |
1243 | 1444 | let outPrAmt = r._2 | |
1265 | 1466 | else if ((noLessThenPriceAsset > outPrAmt)) | |
1266 | 1467 | then throw(((("Failed: " + toString(outPrAmt)) + " < ") + toString(noLessThenPriceAsset))) | |
1267 | 1468 | else { | |
1268 | - | let burnLPAssetOnFactory = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1269 | - | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1270 | - | then state | |
1469 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1470 | + | if ((currentDLp == currentDLp)) | |
1471 | + | then { | |
1472 | + | let burnLPAssetOnFactory = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1473 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1474 | + | then { | |
1475 | + | let $t05172451805 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1476 | + | let refreshDLpActions = $t05172451805._1 | |
1477 | + | let updatedDLp = $t05172451805._2 | |
1478 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1479 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1480 | + | then (state ++ refreshDLpActions) | |
1481 | + | else throw("Strict value is not equal to itself.") | |
1482 | + | } | |
1483 | + | else throw("Strict value is not equal to itself.") | |
1484 | + | } | |
1271 | 1485 | else throw("Strict value is not equal to itself.") | |
1272 | 1486 | } | |
1273 | 1487 | } | |
1281 | 1495 | else true | |
1282 | 1496 | if ((checkPayments == checkPayments)) | |
1283 | 1497 | then { | |
1284 | - | let cfg = gpc() | |
1285 | 1498 | let factoryCfg = gfc() | |
1286 | - | let lpAssetId = | |
1499 | + | let lpAssetId = cfgLpAssetId | |
1287 | 1500 | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1288 | - | let | |
1289 | - | if (( | |
1501 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1502 | + | if ((currentDLp == currentDLp)) | |
1290 | 1503 | 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)) | |
1504 | + | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), amount], nil) | |
1505 | + | if ((unstakeInv == unstakeInv)) | |
1300 | 1506 | then { | |
1301 | - | let burnA = invoke(fca, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1302 | - | if ((burnA == burnA)) | |
1303 | - | then state | |
1507 | + | let r = ego(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
1508 | + | let outAmAmt = r._1 | |
1509 | + | let outPrAmt = r._2 | |
1510 | + | let sts = parseIntValue(r._9) | |
1511 | + | let state = r._10 | |
1512 | + | let v = if (if (igs()) | |
1513 | + | then true | |
1514 | + | else (sts == PoolShutdown)) | |
1515 | + | then throw(("Blocked: " + toString(sts))) | |
1516 | + | else true | |
1517 | + | if ((v == v)) | |
1518 | + | then { | |
1519 | + | let burnA = invoke(fca, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1520 | + | if ((burnA == burnA)) | |
1521 | + | then { | |
1522 | + | let $t05283252913 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1523 | + | let refreshDLpActions = $t05283252913._1 | |
1524 | + | let updatedDLp = $t05283252913._2 | |
1525 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1526 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1527 | + | then (state ++ refreshDLpActions) | |
1528 | + | else throw("Strict value is not equal to itself.") | |
1529 | + | } | |
1530 | + | else throw("Strict value is not equal to itself.") | |
1531 | + | } | |
1304 | 1532 | else throw("Strict value is not equal to itself.") | |
1305 | 1533 | } | |
1306 | 1534 | else throw("Strict value is not equal to itself.") | |
1324 | 1552 | else throw("no payments are expected")] | |
1325 | 1553 | if ((checks == checks)) | |
1326 | 1554 | then { | |
1327 | - | let | |
1328 | - | if (( | |
1555 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1556 | + | if ((currentDLp == currentDLp)) | |
1329 | 1557 | 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)) | |
1558 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1559 | + | if ((unstakeInv == unstakeInv)) | |
1340 | 1560 | then { | |
1341 | - | let burnLPAssetOnFactory = invoke(fca, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1342 | - | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1343 | - | then state | |
1561 | + | let res = ego(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller) | |
1562 | + | let outAmAmt = res._1 | |
1563 | + | let outPrAmt = res._2 | |
1564 | + | let state = res._10 | |
1565 | + | let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset)) | |
1566 | + | then true | |
1567 | + | else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset)) | |
1568 | + | then true | |
1569 | + | else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))] | |
1570 | + | if ((checkAmounts == checkAmounts)) | |
1571 | + | then { | |
1572 | + | let burnLPAssetOnFactory = invoke(fca, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1573 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1574 | + | then { | |
1575 | + | let $t05416454245 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1576 | + | let refreshDLpActions = $t05416454245._1 | |
1577 | + | let updatedDLp = $t05416454245._2 | |
1578 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1579 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1580 | + | then (state ++ refreshDLpActions) | |
1581 | + | else throw("Strict value is not equal to itself.") | |
1582 | + | } | |
1583 | + | else throw("Strict value is not equal to itself.") | |
1584 | + | } | |
1344 | 1585 | else throw("Strict value is not equal to itself.") | |
1345 | 1586 | } | |
1346 | 1587 | else throw("Strict value is not equal to itself.") | |
1374 | 1615 | else throwErr("no payments are expected")] | |
1375 | 1616 | if ((checks == checks)) | |
1376 | 1617 | then { | |
1377 | - | let cfg = gpc() | |
1378 | 1618 | let factoryCfg = gfc() | |
1379 | - | let lpAssetId = | |
1619 | + | let lpAssetId = cfgLpAssetId | |
1380 | 1620 | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1381 | 1621 | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), unstakeAmount], nil) | |
1382 | 1622 | if ((unstakeInv == unstakeInv)) | |
1383 | 1623 | then { | |
1384 | - | let $ | |
1385 | - | let state = $ | |
1386 | - | let totalAmount = $ | |
1624 | + | let $t05514055328 = getOneTknV2Internal(outAssetId, minOutAmount, [AttachedPayment(lpAssetId, unstakeAmount)], i.caller, i.originCaller, i.transactionId) | |
1625 | + | let state = $t05514055328._1 | |
1626 | + | let totalAmount = $t05514055328._2 | |
1387 | 1627 | $Tuple2(state, totalAmount) | |
1388 | 1628 | } | |
1389 | 1629 | else throw("Strict value is not equal to itself.") | |
1395 | 1635 | ||
1396 | 1636 | @Callable(i) | |
1397 | 1637 | 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 | |
1638 | + | let $t05545655559 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", true) | |
1639 | + | let lpAmount = $t05545655559._1 | |
1640 | + | let state = $t05545655559._2 | |
1641 | + | let feeAmount = $t05545655559._3 | |
1642 | + | let bonus = $t05545655559._4 | |
1407 | 1643 | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1408 | 1644 | } | |
1409 | 1645 | ||
1411 | 1647 | ||
1412 | 1648 | @Callable(i) | |
1413 | 1649 | 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 | |
1650 | + | let $t05570755811 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", false) | |
1651 | + | let lpAmount = $t05570755811._1 | |
1652 | + | let state = $t05570755811._2 | |
1653 | + | let feeAmount = $t05570755811._3 | |
1654 | + | let bonus = $t05570755811._4 | |
1423 | 1655 | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1424 | 1656 | } | |
1425 | 1657 | ||
1504 | 1736 | match tx { | |
1505 | 1737 | case order: Order => | |
1506 | 1738 | let matcherPub = mp() | |
1507 | - | let orderValid = moa(order) | |
1739 | + | let $t05860358672 = validateMatcherOrderAllowed(order) | |
1740 | + | let orderValid = $t05860358672._1 | |
1741 | + | let orderValidInfo = $t05860358672._2 | |
1508 | 1742 | let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
1509 | 1743 | let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub) | |
1510 | 1744 | if (if (if (orderValid) | |
1513 | 1747 | then matcherValid | |
1514 | 1748 | else false) | |
1515 | 1749 | then true | |
1516 | - | else | |
1750 | + | else throwOrderError(orderValid, orderValidInfo, senderValid, matcherValid) | |
1517 | 1751 | 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) | |
1752 | + | if (sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)) | |
1524 | 1753 | then true | |
1525 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1754 | + | else { | |
1755 | + | let newHash = blake2b256(value(s.script)) | |
1756 | + | let allowedHash = fromBase64String(value(getString(fca, keyAllowedLpStableScriptHash()))) | |
1757 | + | let currentHash = scriptHash(this) | |
1758 | + | if ((allowedHash == newHash)) | |
1759 | + | then (currentHash != newHash) | |
1760 | + | else false | |
1761 | + | } | |
1526 | 1762 | case _ => | |
1527 | 1763 | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1528 | 1764 | } |
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 | 887 | ||
799 | 888 | ||
800 | 889 | func getY (isReverse,D,poolAmountInBalance) = { | |
801 | 890 | let poolConfig = gpc() | |
802 | 891 | let amId = poolConfig[idxAmAsId] | |
803 | 892 | let prId = poolConfig[idxPrAsId] | |
804 | 893 | let n = big2 | |
805 | 894 | let aPrecision = parseBigIntValue(Amult) | |
806 | 895 | let a = (parseBigIntValue(A) * aPrecision) | |
807 | 896 | let xp = if ((isReverse == false)) | |
808 | 897 | then [(toBigInt(getAccBalance(amId)) + poolAmountInBalance), toBigInt(getAccBalance(prId))] | |
809 | 898 | else [(toBigInt(getAccBalance(prId)) + poolAmountInBalance), toBigInt(getAccBalance(amId))] | |
810 | 899 | let x = xp[0] | |
811 | 900 | let s = x | |
812 | 901 | let ann = (a * n) | |
813 | 902 | let c = (((((D * D) / (x * n)) * D) * aPrecision) / (ann * n)) | |
814 | 903 | let b = ((s + ((D * aPrecision) / ann)) - D) | |
815 | 904 | func calc (acc,cur) = { | |
816 | - | let $ | |
817 | - | let y = $ | |
818 | - | let found = $ | |
905 | + | let $t03431534335 = acc | |
906 | + | let y = $t03431534335._1 | |
907 | + | let found = $t03431534335._2 | |
819 | 908 | if ((found != unit)) | |
820 | 909 | then acc | |
821 | 910 | else { | |
822 | 911 | let yNext = (((y * y) + c) / ((big2 * y) + b)) | |
823 | 912 | let yDiff = absBigInt((yNext - value(y))) | |
824 | 913 | if ((big1 >= yDiff)) | |
825 | 914 | then $Tuple2(yNext, cur) | |
826 | 915 | else $Tuple2(yNext, unit) | |
827 | 916 | } | |
828 | 917 | } | |
829 | 918 | ||
830 | 919 | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
831 | - | let $ | |
920 | + | let $t03466634713 = { | |
832 | 921 | let $l = arr | |
833 | 922 | let $s = size($l) | |
834 | 923 | let $acc0 = $Tuple2(D, unit) | |
835 | 924 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
836 | 925 | then $a | |
837 | 926 | else calc($a, $l[$i]) | |
838 | 927 | ||
839 | 928 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
840 | 929 | then $a | |
841 | 930 | else throw("List size exceeds 15") | |
842 | 931 | ||
843 | 932 | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
844 | 933 | } | |
845 | - | let y = $ | |
846 | - | let found = $ | |
934 | + | let y = $t03466634713._1 | |
935 | + | let found = $t03466634713._2 | |
847 | 936 | if ((found != unit)) | |
848 | 937 | then y | |
849 | 938 | else throw(("Y calculation error, Y = " + toString(y))) | |
850 | 939 | } | |
851 | 940 | ||
852 | 941 | ||
853 | 942 | @Callable(i) | |
854 | 943 | func calculateAmountOutForSwapREADONLY (cleanAmountIn,isReverse) = { | |
855 | - | let $ | |
944 | + | let $t03493435358 = if ((isReverse == false)) | |
856 | 945 | then { | |
857 | 946 | let assetOut = strf(this, pa()) | |
858 | 947 | let poolAmountInBalance = (toBigInt(getAccBalance(strf(this, aa()))) + toBigInt(cleanAmountIn)) | |
859 | 948 | $Tuple2(assetOut, poolAmountInBalance) | |
860 | 949 | } | |
861 | 950 | else { | |
862 | 951 | let assetOut = strf(this, aa()) | |
863 | 952 | let poolAmountInBalance = (toBigInt(getAccBalance(strf(this, pa()))) + toBigInt(cleanAmountIn)) | |
864 | 953 | $Tuple2(assetOut, poolAmountInBalance) | |
865 | 954 | } | |
866 | - | let assetOut = $ | |
867 | - | let poolAmountInBalance = $ | |
955 | + | let assetOut = $t03493435358._1 | |
956 | + | let poolAmountInBalance = $t03493435358._2 | |
868 | 957 | let poolConfig = gpc() | |
869 | 958 | let amId = poolConfig[idxAmAsId] | |
870 | 959 | let prId = poolConfig[idxPrAsId] | |
871 | 960 | let xp = [toBigInt(getAccBalance(amId)), toBigInt(getAccBalance(prId))] | |
872 | 961 | let D = getD(xp) | |
873 | 962 | let y = getY(isReverse, D, toBigInt(cleanAmountIn)) | |
874 | 963 | let dy = ((toBigInt(getAccBalance(assetOut)) - y) - toBigInt(1)) | |
875 | 964 | let totalGetRaw = max([0, toInt(dy)]) | |
876 | 965 | let newXp = if ((isReverse == false)) | |
877 | 966 | then [(toBigInt(getAccBalance(amId)) + toBigInt(cleanAmountIn)), (toBigInt(getAccBalance(prId)) - dy)] | |
878 | 967 | else [(toBigInt(getAccBalance(amId)) - dy), (toBigInt(getAccBalance(prId)) + toBigInt(cleanAmountIn))] | |
879 | 968 | let newD = getD(newXp) | |
880 | 969 | let checkD = if ((newD >= D)) | |
881 | 970 | then true | |
882 | 971 | else throw(makeString(["new D is fewer error", toString(D), toString(newD)], "__")) | |
883 | 972 | if ((checkD == checkD)) | |
884 | 973 | then $Tuple2(nil, totalGetRaw) | |
885 | 974 | else throw("Strict value is not equal to itself.") | |
886 | 975 | } | |
887 | 976 | ||
888 | 977 | ||
889 | 978 | ||
890 | 979 | @Callable(i) | |
891 | 980 | func calculateAmountOutForSwapAndSendTokens (cleanAmountIn,isReverse,amountOutMin,addressTo) = { | |
981 | + | let swapContact = { | |
982 | + | let @ = invoke(addressFromStringValue(fc()), "getSwapContractREADONLY", nil, nil) | |
983 | + | if ($isInstanceOf(@, "String")) | |
984 | + | then @ | |
985 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
986 | + | } | |
892 | 987 | let checks = [if ((value(i.payments[0]).amount >= cleanAmountIn)) | |
893 | 988 | then true | |
894 | - | else throwErr("Wrong amount"), if ((i.caller == addressFromStringValue( | |
989 | + | else throwErr("Wrong amount"), if ((i.caller == addressFromStringValue(swapContact))) | |
895 | 990 | then true | |
896 | 991 | else throwErr("Permission denied")] | |
897 | 992 | if ((checks == checks)) | |
898 | 993 | then { | |
899 | 994 | let pmt = value(i.payments[0]) | |
900 | 995 | let assetIn = if ((pmt.assetId == unit)) | |
901 | 996 | then toBase58String(toBytes("WAVES")) | |
902 | 997 | else toBase58String(value(pmt.assetId)) | |
903 | - | let $ | |
998 | + | let $t03682137215 = if ((isReverse == false)) | |
904 | 999 | then { | |
905 | 1000 | let assetOut = strf(this, pa()) | |
906 | 1001 | let poolAmountInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount) | |
907 | 1002 | $Tuple2(assetOut, poolAmountInBalance) | |
908 | 1003 | } | |
909 | 1004 | else { | |
910 | 1005 | let assetOut = strf(this, aa()) | |
911 | 1006 | let poolAmountInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount) | |
912 | 1007 | $Tuple2(assetOut, poolAmountInBalance) | |
913 | 1008 | } | |
914 | - | let assetOut = $ | |
915 | - | let poolAmountInBalance = $ | |
1009 | + | let assetOut = $t03682137215._1 | |
1010 | + | let poolAmountInBalance = $t03682137215._2 | |
916 | 1011 | let poolConfig = gpc() | |
917 | 1012 | let amId = poolConfig[idxAmAsId] | |
918 | 1013 | let prId = poolConfig[idxPrAsId] | |
919 | 1014 | let xp = if ((isReverse == false)) | |
920 | 1015 | then [(toBigInt(getAccBalance(amId)) - toBigInt(value(i.payments[0]).amount)), toBigInt(getAccBalance(prId))] | |
921 | 1016 | else [toBigInt(getAccBalance(amId)), (toBigInt(getAccBalance(prId)) - toBigInt(value(i.payments[0]).amount))] | |
922 | 1017 | let D = getD(xp) | |
923 | 1018 | let y = getY(isReverse, D, toBigInt(0)) | |
924 | 1019 | let dy = ((toBigInt(getAccBalance(assetOut)) - y) - toBigInt(1)) | |
925 | 1020 | let totalGetRaw = max([0, toInt(dy)]) | |
926 | 1021 | let checkMin = if ((totalGetRaw >= amountOutMin)) | |
927 | 1022 | then true | |
928 | 1023 | else throw("Exchange result is fewer coins than expected") | |
929 | 1024 | if ((checkMin == checkMin)) | |
930 | 1025 | then { | |
931 | 1026 | let newXp = if ((isReverse == false)) | |
932 | 1027 | then [toBigInt(getAccBalance(amId)), (toBigInt(getAccBalance(prId)) - dy)] | |
933 | 1028 | else [(toBigInt(getAccBalance(amId)) - dy), toBigInt(getAccBalance(prId))] | |
934 | 1029 | let newD = getD(newXp) | |
935 | 1030 | let checkD = if ((newD >= D)) | |
936 | 1031 | then true | |
937 | 1032 | else throw("new D is fewer error") | |
938 | 1033 | if ((checkD == checkD)) | |
939 | 1034 | then [ScriptTransfer(addressFromStringValue(addressTo), totalGetRaw, if ((assetIn == "WAVES")) | |
940 | 1035 | then unit | |
941 | 1036 | else fromBase58String(assetOut))] | |
942 | 1037 | else throw("Strict value is not equal to itself.") | |
943 | 1038 | } | |
944 | 1039 | else throw("Strict value is not equal to itself.") | |
945 | 1040 | } | |
946 | 1041 | else throw("Strict value is not equal to itself.") | |
947 | 1042 | } | |
948 | 1043 | ||
949 | 1044 | ||
950 | 1045 | ||
951 | 1046 | @Callable(i) | |
952 | 1047 | func constructor (fc) = { | |
953 | 1048 | let c = mm(i) | |
954 | 1049 | if ((c == c)) | |
955 | 1050 | then [StringEntry(fc(), fc)] | |
956 | 1051 | else throw("Strict value is not equal to itself.") | |
957 | 1052 | } | |
958 | 1053 | ||
959 | 1054 | ||
960 | 1055 | ||
961 | 1056 | @Callable(i) | |
962 | 1057 | func setManager (pendingManagerPublicKey) = { | |
963 | 1058 | let c = mm(i) | |
964 | 1059 | if ((c == c)) | |
965 | 1060 | then { | |
966 | 1061 | let cm = fromBase58String(pendingManagerPublicKey) | |
967 | 1062 | if ((cm == cm)) | |
968 | 1063 | then [StringEntry(pmpk(), pendingManagerPublicKey)] | |
969 | 1064 | else throw("Strict value is not equal to itself.") | |
970 | 1065 | } | |
971 | 1066 | else throw("Strict value is not equal to itself.") | |
972 | 1067 | } | |
973 | 1068 | ||
974 | 1069 | ||
975 | 1070 | ||
976 | 1071 | @Callable(i) | |
977 | 1072 | func confirmManager () = { | |
978 | 1073 | let p = pm() | |
979 | 1074 | let hpm = if (isDefined(p)) | |
980 | 1075 | then true | |
981 | 1076 | else throw("No pending manager") | |
982 | 1077 | if ((hpm == hpm)) | |
983 | 1078 | then { | |
984 | 1079 | let cpm = if ((i.callerPublicKey == value(p))) | |
985 | 1080 | then true | |
986 | 1081 | else throw("You are not pending manager") | |
987 | 1082 | if ((cpm == cpm)) | |
988 | 1083 | then [StringEntry(mpk(), toBase58String(value(p))), DeleteEntry(pmpk())] | |
989 | 1084 | else throw("Strict value is not equal to itself.") | |
990 | 1085 | } | |
991 | 1086 | else throw("Strict value is not equal to itself.") | |
992 | 1087 | } | |
993 | 1088 | ||
994 | 1089 | ||
995 | 1090 | ||
996 | 1091 | @Callable(i) | |
997 | 1092 | func put (slip,autoStake) = { | |
998 | 1093 | let factCfg = gfc() | |
999 | 1094 | let stakingCntr = valueOrErrorMessage(addressFromString(factCfg[idxFactStakCntr]), "Wr st addr") | |
1000 | 1095 | let slipCntr = valueOrErrorMessage(addressFromString(factCfg[idxFactSlippCntr]), "Wr sl addr") | |
1001 | 1096 | if ((0 > slip)) | |
1002 | 1097 | then throw("Wrong slippage") | |
1003 | 1098 | else if ((size(i.payments) != 2)) | |
1004 | 1099 | then throw("2 pmnts expd") | |
1005 | 1100 | 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)) | |
1101 | + | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1102 | + | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1103 | + | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amAssetPmt) | |
1104 | + | if ((amountAssetBalance == amountAssetBalance)) | |
1016 | 1105 | 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)) | |
1106 | + | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - prAssetPmt) | |
1107 | + | if ((priceAssetBalance == priceAssetBalance)) | |
1024 | 1108 | then { | |
1025 | - | let sa = if ((amDiff > 0)) | |
1026 | - | then invoke(slipCntr, "put", nil, [AttachedPayment(amId, amDiff)]) | |
1027 | - | else nil | |
1028 | - | if ((sa == sa)) | |
1109 | + | let lpAssetEmission = toBigInt(value(assetInfo(cfgLpAssetId)).quantity) | |
1110 | + | if ((lpAssetEmission == lpAssetEmission)) | |
1029 | 1111 | then { | |
1030 | - | let sp = if ((prDiff > 0)) | |
1031 | - | then invoke(slipCntr, "put", nil, [AttachedPayment(prId, prDiff)]) | |
1032 | - | else nil | |
1033 | - | if ((sp == sp)) | |
1112 | + | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1113 | + | if ((currentDLp == currentDLp)) | |
1034 | 1114 | then { | |
1035 | - | let lpTrnsfr = if (autoStake) | |
1115 | + | 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, "") | |
1116 | + | let emitLpAmt = e._2 | |
1117 | + | let lpAssetId = e._7 | |
1118 | + | let state = e._9 | |
1119 | + | let amDiff = e._10 | |
1120 | + | let prDiff = e._11 | |
1121 | + | let amId = e._12 | |
1122 | + | let prId = e._13 | |
1123 | + | let r = invoke(fca, "emit", [emitLpAmt], nil) | |
1124 | + | if ((r == r)) | |
1036 | 1125 | then { | |
1037 | - | let ss = invoke(stakingCntr, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
1038 | - | if ((ss == ss)) | |
1039 | - | then nil | |
1126 | + | let el = match r { | |
1127 | + | case legacy: Address => | |
1128 | + | invoke(legacy, "emit", [emitLpAmt], nil) | |
1129 | + | case _ => | |
1130 | + | unit | |
1131 | + | } | |
1132 | + | if ((el == el)) | |
1133 | + | then { | |
1134 | + | let sa = if ((amDiff > 0)) | |
1135 | + | then invoke(slipCntr, "put", nil, [AttachedPayment(amId, amDiff)]) | |
1136 | + | else nil | |
1137 | + | if ((sa == sa)) | |
1138 | + | then { | |
1139 | + | let sp = if ((prDiff > 0)) | |
1140 | + | then invoke(slipCntr, "put", nil, [AttachedPayment(prId, prDiff)]) | |
1141 | + | else nil | |
1142 | + | if ((sp == sp)) | |
1143 | + | then { | |
1144 | + | let lpTrnsfr = if (autoStake) | |
1145 | + | then { | |
1146 | + | let ss = invoke(stakingCntr, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
1147 | + | if ((ss == ss)) | |
1148 | + | then nil | |
1149 | + | else throw("Strict value is not equal to itself.") | |
1150 | + | } | |
1151 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
1152 | + | let $t04207642218 = refreshDLpInternal(0, 0, 0) | |
1153 | + | let refreshDLpActions = $t04207642218._1 | |
1154 | + | let updatedDLp = $t04207642218._2 | |
1155 | + | let check = if ((updatedDLp >= currentDLp)) | |
1156 | + | then true | |
1157 | + | else throwErr(makeString(["updated DLp lower than current DLp", toString(amountAssetBalance), toString(priceAssetBalance), toString(lpAssetEmission), toString(currentDLp), toString(updatedDLp), toString(amDiff), toString(prDiff)], " ")) | |
1158 | + | if ((check == check)) | |
1159 | + | then { | |
1160 | + | let lpAssetEmissionAfter = value(assetInfo(cfgLpAssetId)).quantity | |
1161 | + | if ((lpAssetEmissionAfter == lpAssetEmissionAfter)) | |
1162 | + | then ((state ++ lpTrnsfr) ++ refreshDLpActions) | |
1163 | + | else throw("Strict value is not equal to itself.") | |
1164 | + | } | |
1165 | + | else throw("Strict value is not equal to itself.") | |
1166 | + | } | |
1167 | + | else throw("Strict value is not equal to itself.") | |
1168 | + | } | |
1169 | + | else throw("Strict value is not equal to itself.") | |
1170 | + | } | |
1040 | 1171 | else throw("Strict value is not equal to itself.") | |
1041 | 1172 | } | |
1042 | - | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
1043 | - | (state ++ lpTrnsfr) | |
1173 | + | else throw("Strict value is not equal to itself.") | |
1044 | 1174 | } | |
1045 | 1175 | else throw("Strict value is not equal to itself.") | |
1046 | 1176 | } | |
1047 | 1177 | else throw("Strict value is not equal to itself.") | |
1048 | 1178 | } | |
1049 | 1179 | else throw("Strict value is not equal to itself.") | |
1050 | 1180 | } | |
1051 | 1181 | else throw("Strict value is not equal to itself.") | |
1052 | 1182 | } | |
1053 | 1183 | } | |
1054 | 1184 | ||
1055 | 1185 | ||
1056 | 1186 | ||
1057 | 1187 | @Callable(i) | |
1058 | 1188 | func putOneTknV2 (minOutAmount,autoStake) = { | |
1059 | 1189 | let isPoolOneTokenOperationsDisabled = { | |
1060 | 1190 | let @ = invoke(fca, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1061 | 1191 | if ($isInstanceOf(@, "Boolean")) | |
1062 | 1192 | then @ | |
1063 | 1193 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1064 | 1194 | } | |
1065 | 1195 | let isPutDisabled = if (if (if (igs()) | |
1066 | 1196 | then true | |
1067 | 1197 | else (cfgPoolStatus == PoolPutDis)) | |
1068 | 1198 | then true | |
1069 | 1199 | else (cfgPoolStatus == PoolShutdown)) | |
1070 | 1200 | then true | |
1071 | 1201 | else isPoolOneTokenOperationsDisabled | |
1072 | 1202 | let checks = [if (if (!(isPutDisabled)) | |
1073 | 1203 | then true | |
1074 | 1204 | else isManager(i)) | |
1075 | 1205 | then true | |
1076 | 1206 | else throwErr("put operation is blocked by admin"), if ((size(i.payments) == 1)) | |
1077 | 1207 | then true | |
1078 | 1208 | else throwErr("exactly 1 payment are expected")] | |
1079 | 1209 | if ((checks == checks)) | |
1080 | 1210 | 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]) | |
1211 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
1212 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
1213 | + | let lpId = cfgLpAssetId | |
1214 | + | let amDecimals = cfgAmountAssetDecimals | |
1215 | + | let prDecimals = cfgPriceAssetDecimals | |
1087 | 1216 | let userAddress = if ((i.caller == this)) | |
1088 | 1217 | then i.originCaller | |
1089 | 1218 | else i.caller | |
1090 | 1219 | let pmt = value(i.payments[0]) | |
1091 | 1220 | let pmtAssetId = toBase58String(value(pmt.assetId)) | |
1092 | 1221 | let pmtAmt = pmt.amount | |
1093 | - | let $t03879838956 = calcPutOneTkn(pmtAmt, pmtAssetId, toString(userAddress), toBase58String(i.transactionId), true) | |
1094 | - | if (($t03879838956 == $t03879838956)) | |
1222 | + | let currentDLp = if ((pmt.assetId == cfgAmountAssetId)) | |
1223 | + | then calcCurrentDLp(toBigInt(pmtAmt), toBigInt(0), toBigInt(0)) | |
1224 | + | else calcCurrentDLp(toBigInt(0), toBigInt(pmtAmt), toBigInt(0)) | |
1225 | + | if ((currentDLp == currentDLp)) | |
1095 | 1226 | 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)) | |
1227 | + | let $t04385944017 = calcPutOneTkn(pmtAmt, pmtAssetId, toString(userAddress), toBase58String(i.transactionId), true) | |
1228 | + | if (($t04385944017 == $t04385944017)) | |
1106 | 1229 | 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)) | |
1230 | + | let feeAmount = $t04385944017._3 | |
1231 | + | let state = $t04385944017._2 | |
1232 | + | let estimLP = $t04385944017._1 | |
1233 | + | let emitLpAmt = if (if ((minOutAmount > 0)) | |
1234 | + | then (minOutAmount > estimLP) | |
1235 | + | else false) | |
1236 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
1237 | + | else estimLP | |
1238 | + | let e = invoke(fca, "emit", [emitLpAmt], nil) | |
1239 | + | if ((e == e)) | |
1114 | 1240 | then { | |
1115 | - | let lpTrnsfr = if (autoStake) | |
1241 | + | let el = match e { | |
1242 | + | case legacy: Address => | |
1243 | + | invoke(legacy, "emit", [emitLpAmt], nil) | |
1244 | + | case _ => | |
1245 | + | unit | |
1246 | + | } | |
1247 | + | if ((el == el)) | |
1116 | 1248 | then { | |
1117 | - | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpId, emitLpAmt)]) | |
1118 | - | if ((ss == ss)) | |
1119 | - | then nil | |
1249 | + | let lpTrnsfr = if (autoStake) | |
1250 | + | then { | |
1251 | + | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpId, emitLpAmt)]) | |
1252 | + | if ((ss == ss)) | |
1253 | + | then nil | |
1254 | + | else throw("Strict value is not equal to itself.") | |
1255 | + | } | |
1256 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpId)] | |
1257 | + | let sendFeeToMatcher = if ((feeAmount > 0)) | |
1258 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, fromBase58String(pmtAssetId))] | |
1259 | + | else nil | |
1260 | + | let $t04483245181 = if ((this == feeCollectorAddress)) | |
1261 | + | then $Tuple2(0, 0) | |
1262 | + | else { | |
1263 | + | let paymentInAmountAsset = if ((pmt.assetId == cfgAmountAssetId)) | |
1264 | + | then true | |
1265 | + | else false | |
1266 | + | if (paymentInAmountAsset) | |
1267 | + | then $Tuple2(-(feeAmount), 0) | |
1268 | + | else $Tuple2(0, -(feeAmount)) | |
1269 | + | } | |
1270 | + | let amountAssetBalanceDelta = $t04483245181._1 | |
1271 | + | let priceAssetBalanceDelta = $t04483245181._2 | |
1272 | + | let $t04518445292 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1273 | + | let refreshDLpActions = $t04518445292._1 | |
1274 | + | let updatedDLp = $t04518445292._2 | |
1275 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1276 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1277 | + | then $Tuple2((((state ++ lpTrnsfr) ++ sendFeeToMatcher) ++ refreshDLpActions), emitLpAmt) | |
1120 | 1278 | else throw("Strict value is not equal to itself.") | |
1121 | 1279 | } | |
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) | |
1280 | + | else throw("Strict value is not equal to itself.") | |
1127 | 1281 | } | |
1128 | 1282 | else throw("Strict value is not equal to itself.") | |
1129 | 1283 | } | |
1130 | 1284 | else throw("Strict value is not equal to itself.") | |
1131 | 1285 | } | |
1132 | 1286 | else throw("Strict value is not equal to itself.") | |
1133 | 1287 | } | |
1134 | 1288 | else throw("Strict value is not equal to itself.") | |
1135 | 1289 | } | |
1136 | 1290 | ||
1137 | 1291 | ||
1138 | 1292 | ||
1139 | 1293 | @Callable(i) | |
1140 | 1294 | func putForFree (maxSlpg) = if ((0 > maxSlpg)) | |
1141 | 1295 | then throw("Wrong slpg") | |
1142 | 1296 | else if ((size(i.payments) != 2)) | |
1143 | 1297 | then throw("2 pmnts expd") | |
1144 | 1298 | else { | |
1145 | 1299 | 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 | |
1300 | + | let state = estPut._9 | |
1301 | + | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1302 | + | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1303 | + | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1304 | + | if ((currentDLp == currentDLp)) | |
1305 | + | then { | |
1306 | + | let $t04632246387 = refreshDLpInternal(0, 0, 0) | |
1307 | + | let refreshDLpActions = $t04632246387._1 | |
1308 | + | let updatedDLp = $t04632246387._2 | |
1309 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1310 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1311 | + | then (state ++ refreshDLpActions) | |
1312 | + | else throw("Strict value is not equal to itself.") | |
1313 | + | } | |
1314 | + | else throw("Strict value is not equal to itself.") | |
1147 | 1315 | } | |
1148 | 1316 | ||
1149 | 1317 | ||
1150 | 1318 | ||
1151 | 1319 | @Callable(i) | |
1152 | 1320 | 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 | |
1321 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1322 | + | if ((currentDLp == currentDLp)) | |
1323 | + | then { | |
1324 | + | let r = cg(i) | |
1325 | + | let outAmtAmt = r._1 | |
1326 | + | let outPrAmt = r._2 | |
1327 | + | let pmtAmt = r._3 | |
1328 | + | let pmtAssetId = r._4 | |
1329 | + | let state = r._5 | |
1330 | + | let b = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1331 | + | if ((b == b)) | |
1332 | + | then { | |
1333 | + | let $t04756047642 = refreshDLpInternal(-(outAmtAmt), -(outPrAmt), 0) | |
1334 | + | let refreshDLpActions = $t04756047642._1 | |
1335 | + | let updatedDLp = $t04756047642._2 | |
1336 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1337 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1338 | + | then (state ++ refreshDLpActions) | |
1339 | + | else throw("Strict value is not equal to itself.") | |
1340 | + | } | |
1341 | + | else throw("Strict value is not equal to itself.") | |
1342 | + | } | |
1162 | 1343 | else throw("Strict value is not equal to itself.") | |
1163 | 1344 | } | |
1164 | 1345 | ||
1165 | 1346 | ||
1166 | 1347 | ||
1167 | 1348 | @Callable(i) | |
1168 | 1349 | func getOneTknV2 (outAssetId,minOutAmount) = { | |
1169 | 1350 | let isPoolOneTokenOperationsDisabled = { | |
1170 | 1351 | let @ = invoke(fca, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1171 | 1352 | if ($isInstanceOf(@, "Boolean")) | |
1172 | 1353 | then @ | |
1173 | 1354 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1174 | 1355 | } | |
1175 | 1356 | let isGetDisabled = if (if (igs()) | |
1176 | 1357 | then true | |
1177 | 1358 | else (cfgPoolStatus == PoolShutdown)) | |
1178 | 1359 | then true | |
1179 | 1360 | else isPoolOneTokenOperationsDisabled | |
1180 | 1361 | let checks = [if (if (!(isGetDisabled)) | |
1181 | 1362 | then true | |
1182 | 1363 | else isManager(i)) | |
1183 | 1364 | then true | |
1184 | 1365 | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 1)) | |
1185 | 1366 | then true | |
1186 | 1367 | else throwErr("exactly 1 payment are expected")] | |
1187 | 1368 | if ((checks == checks)) | |
1188 | 1369 | then { | |
1189 | - | let $ | |
1190 | - | let state = $ | |
1191 | - | let totalAmount = $ | |
1370 | + | let $t04826048415 = getOneTknV2Internal(outAssetId, minOutAmount, i.payments, i.caller, i.originCaller, i.transactionId) | |
1371 | + | let state = $t04826048415._1 | |
1372 | + | let totalAmount = $t04826048415._2 | |
1192 | 1373 | $Tuple2(state, totalAmount) | |
1193 | 1374 | } | |
1194 | 1375 | else throw("Strict value is not equal to itself.") | |
1195 | 1376 | } | |
1196 | 1377 | ||
1197 | 1378 | ||
1198 | 1379 | ||
1199 | 1380 | @Callable(i) | |
1381 | + | func refreshDLp () = { | |
1382 | + | let lastRefreshedBlockHeight = valueOrElse(getInteger(keyDLpRefreshedHeight), 0) | |
1383 | + | let checkLastRefreshedBlockHeight = if (((height - lastRefreshedBlockHeight) >= dLpRefreshDelay)) | |
1384 | + | then unit | |
1385 | + | else throwErr(makeString([toString(dLpRefreshDelay), " blocks have not passed since the previous call"], "")) | |
1386 | + | if ((checkLastRefreshedBlockHeight == checkLastRefreshedBlockHeight)) | |
1387 | + | then { | |
1388 | + | let dLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyDLp), "0")), fmtErr("invalid dLp")) | |
1389 | + | let $t04893949003 = refreshDLpInternal(0, 0, 0) | |
1390 | + | let dLpUpdateActions = $t04893949003._1 | |
1391 | + | let updatedDLp = $t04893949003._2 | |
1392 | + | let actions = if ((dLp != updatedDLp)) | |
1393 | + | then dLpUpdateActions | |
1394 | + | else throwErr("nothing to refresh") | |
1395 | + | $Tuple2(actions, toString(updatedDLp)) | |
1396 | + | } | |
1397 | + | else throw("Strict value is not equal to itself.") | |
1398 | + | } | |
1399 | + | ||
1400 | + | ||
1401 | + | ||
1402 | + | @Callable(i) | |
1200 | 1403 | func getOneTknV2READONLY (outAssetId,lpAssetAmount) = { | |
1201 | - | let poolConfig = gpc() | |
1202 | - | let amId = poolConfig[idxAmAsId] | |
1203 | - | let prId = poolConfig[idxPrAsId] | |
1204 | - | let lpId = poolConfig[idxLPAsId] | |
1404 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
1405 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
1406 | + | let lpId = toBase58String(value(cfgLpAssetId)) | |
1205 | 1407 | let xp = [toBigInt(getAccBalance(amId)), toBigInt(getAccBalance(prId))] | |
1206 | 1408 | let lpEmission = toBigInt(valueOrErrorMessage(assetInfo(fromBase58String(lpId)), "invalid lp asset").quantity) | |
1207 | 1409 | let D0 = getD(xp) | |
1208 | 1410 | let D1 = (D0 - fraction(toBigInt(lpAssetAmount), D0, lpEmission)) | |
1209 | 1411 | let index = if ((outAssetId == amId)) | |
1210 | 1412 | then 0 | |
1211 | 1413 | else if ((outAssetId == prId)) | |
1212 | 1414 | then 1 | |
1213 | 1415 | else throw("invalid out asset id") | |
1214 | 1416 | let newY = getYD(xp, index, D1) | |
1215 | 1417 | let dy = (xp[index] - newY) | |
1216 | 1418 | let totalGetRaw = max([0, toInt((dy - big1))]) | |
1217 | - | let $ | |
1218 | - | let totalGet = $ | |
1219 | - | let feeAmount = $ | |
1419 | + | let $t05001350068 = takeFee(totalGetRaw, outFee) | |
1420 | + | let totalGet = $t05001350068._1 | |
1421 | + | let feeAmount = $t05001350068._2 | |
1220 | 1422 | $Tuple2(nil, $Tuple2(totalGet, feeAmount)) | |
1221 | 1423 | } | |
1222 | 1424 | ||
1223 | 1425 | ||
1224 | 1426 | ||
1225 | 1427 | @Callable(i) | |
1226 | 1428 | func getOneTknV2WithBonusREADONLY (outAssetId,lpAssetAmount) = { | |
1227 | - | let poolConfig = gpc() | |
1228 | - | let amId = poolConfig[idxAmAsId] | |
1229 | - | let prId = poolConfig[idxPrAsId] | |
1230 | - | let lpId = poolConfig[idxLPAsId] | |
1429 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
1430 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
1431 | + | let lpId = toBase58String(value(cfgLpAssetId)) | |
1231 | 1432 | let amBalance = getAccBalance(amId) | |
1232 | 1433 | let prBalance = getAccBalance(prId) | |
1233 | - | let $ | |
1434 | + | let $t05044350558 = { | |
1234 | 1435 | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, lpAssetAmount], nil) | |
1235 | 1436 | if ($isInstanceOf(@, "(Int, Int)")) | |
1236 | 1437 | then @ | |
1237 | 1438 | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
1238 | 1439 | } | |
1239 | - | let totalGet = $ | |
1240 | - | let feeAmount = $ | |
1440 | + | let totalGet = $t05044350558._1 | |
1441 | + | let feeAmount = $t05044350558._2 | |
1241 | 1442 | let r = ego("", lpId, lpAssetAmount, this) | |
1242 | 1443 | let outAmAmt = r._1 | |
1243 | 1444 | let outPrAmt = r._2 | |
1244 | 1445 | let sumOfGetAssets = (outAmAmt + outPrAmt) | |
1245 | 1446 | let bonus = if ((sumOfGetAssets == 0)) | |
1246 | 1447 | then if ((totalGet == 0)) | |
1247 | 1448 | then 0 | |
1248 | 1449 | else throw("bonus calculation error") | |
1249 | 1450 | else fraction((totalGet - sumOfGetAssets), scale8, sumOfGetAssets) | |
1250 | 1451 | $Tuple2(nil, $Tuple3(totalGet, feeAmount, bonus)) | |
1251 | 1452 | } | |
1252 | 1453 | ||
1253 | 1454 | ||
1254 | 1455 | ||
1255 | 1456 | @Callable(i) | |
1256 | 1457 | func getNoLess (noLessThenAmtAsset,noLessThenPriceAsset) = { | |
1257 | 1458 | let r = cg(i) | |
1258 | 1459 | let outAmAmt = r._1 | |
1259 | 1460 | let outPrAmt = r._2 | |
1260 | 1461 | let pmtAmt = r._3 | |
1261 | 1462 | let pmtAssetId = r._4 | |
1262 | 1463 | let state = r._5 | |
1263 | 1464 | if ((noLessThenAmtAsset > outAmAmt)) | |
1264 | 1465 | then throw(((("Failed: " + toString(outAmAmt)) + " < ") + toString(noLessThenAmtAsset))) | |
1265 | 1466 | else if ((noLessThenPriceAsset > outPrAmt)) | |
1266 | 1467 | then throw(((("Failed: " + toString(outPrAmt)) + " < ") + toString(noLessThenPriceAsset))) | |
1267 | 1468 | else { | |
1268 | - | let burnLPAssetOnFactory = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1269 | - | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1270 | - | then state | |
1469 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1470 | + | if ((currentDLp == currentDLp)) | |
1471 | + | then { | |
1472 | + | let burnLPAssetOnFactory = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1473 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1474 | + | then { | |
1475 | + | let $t05172451805 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1476 | + | let refreshDLpActions = $t05172451805._1 | |
1477 | + | let updatedDLp = $t05172451805._2 | |
1478 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1479 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1480 | + | then (state ++ refreshDLpActions) | |
1481 | + | else throw("Strict value is not equal to itself.") | |
1482 | + | } | |
1483 | + | else throw("Strict value is not equal to itself.") | |
1484 | + | } | |
1271 | 1485 | else throw("Strict value is not equal to itself.") | |
1272 | 1486 | } | |
1273 | 1487 | } | |
1274 | 1488 | ||
1275 | 1489 | ||
1276 | 1490 | ||
1277 | 1491 | @Callable(i) | |
1278 | 1492 | func unstakeAndGet (amount) = { | |
1279 | 1493 | let checkPayments = if ((size(i.payments) != 0)) | |
1280 | 1494 | then throw("No pmnts expd") | |
1281 | 1495 | else true | |
1282 | 1496 | if ((checkPayments == checkPayments)) | |
1283 | 1497 | then { | |
1284 | - | let cfg = gpc() | |
1285 | 1498 | let factoryCfg = gfc() | |
1286 | - | let lpAssetId = | |
1499 | + | let lpAssetId = cfgLpAssetId | |
1287 | 1500 | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1288 | - | let | |
1289 | - | if (( | |
1501 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1502 | + | if ((currentDLp == currentDLp)) | |
1290 | 1503 | 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)) | |
1504 | + | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), amount], nil) | |
1505 | + | if ((unstakeInv == unstakeInv)) | |
1300 | 1506 | then { | |
1301 | - | let burnA = invoke(fca, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1302 | - | if ((burnA == burnA)) | |
1303 | - | then state | |
1507 | + | let r = ego(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
1508 | + | let outAmAmt = r._1 | |
1509 | + | let outPrAmt = r._2 | |
1510 | + | let sts = parseIntValue(r._9) | |
1511 | + | let state = r._10 | |
1512 | + | let v = if (if (igs()) | |
1513 | + | then true | |
1514 | + | else (sts == PoolShutdown)) | |
1515 | + | then throw(("Blocked: " + toString(sts))) | |
1516 | + | else true | |
1517 | + | if ((v == v)) | |
1518 | + | then { | |
1519 | + | let burnA = invoke(fca, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1520 | + | if ((burnA == burnA)) | |
1521 | + | then { | |
1522 | + | let $t05283252913 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1523 | + | let refreshDLpActions = $t05283252913._1 | |
1524 | + | let updatedDLp = $t05283252913._2 | |
1525 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1526 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1527 | + | then (state ++ refreshDLpActions) | |
1528 | + | else throw("Strict value is not equal to itself.") | |
1529 | + | } | |
1530 | + | else throw("Strict value is not equal to itself.") | |
1531 | + | } | |
1304 | 1532 | else throw("Strict value is not equal to itself.") | |
1305 | 1533 | } | |
1306 | 1534 | else throw("Strict value is not equal to itself.") | |
1307 | 1535 | } | |
1308 | 1536 | else throw("Strict value is not equal to itself.") | |
1309 | 1537 | } | |
1310 | 1538 | else throw("Strict value is not equal to itself.") | |
1311 | 1539 | } | |
1312 | 1540 | ||
1313 | 1541 | ||
1314 | 1542 | ||
1315 | 1543 | @Callable(i) | |
1316 | 1544 | func unstakeAndGetNoLess (unstakeAmount,noLessThenAmountAsset,noLessThenPriceAsset) = { | |
1317 | 1545 | let isGetDisabled = if (igs()) | |
1318 | 1546 | then true | |
1319 | 1547 | else (cfgPoolStatus == PoolShutdown) | |
1320 | 1548 | let checks = [if (!(isGetDisabled)) | |
1321 | 1549 | then true | |
1322 | 1550 | else throw("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1323 | 1551 | then true | |
1324 | 1552 | else throw("no payments are expected")] | |
1325 | 1553 | if ((checks == checks)) | |
1326 | 1554 | then { | |
1327 | - | let | |
1328 | - | if (( | |
1555 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1556 | + | if ((currentDLp == currentDLp)) | |
1329 | 1557 | 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)) | |
1558 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1559 | + | if ((unstakeInv == unstakeInv)) | |
1340 | 1560 | then { | |
1341 | - | let burnLPAssetOnFactory = invoke(fca, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1342 | - | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1343 | - | then state | |
1561 | + | let res = ego(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller) | |
1562 | + | let outAmAmt = res._1 | |
1563 | + | let outPrAmt = res._2 | |
1564 | + | let state = res._10 | |
1565 | + | let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset)) | |
1566 | + | then true | |
1567 | + | else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset)) | |
1568 | + | then true | |
1569 | + | else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))] | |
1570 | + | if ((checkAmounts == checkAmounts)) | |
1571 | + | then { | |
1572 | + | let burnLPAssetOnFactory = invoke(fca, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1573 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1574 | + | then { | |
1575 | + | let $t05416454245 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1576 | + | let refreshDLpActions = $t05416454245._1 | |
1577 | + | let updatedDLp = $t05416454245._2 | |
1578 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1579 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1580 | + | then (state ++ refreshDLpActions) | |
1581 | + | else throw("Strict value is not equal to itself.") | |
1582 | + | } | |
1583 | + | else throw("Strict value is not equal to itself.") | |
1584 | + | } | |
1344 | 1585 | else throw("Strict value is not equal to itself.") | |
1345 | 1586 | } | |
1346 | 1587 | else throw("Strict value is not equal to itself.") | |
1347 | 1588 | } | |
1348 | 1589 | else throw("Strict value is not equal to itself.") | |
1349 | 1590 | } | |
1350 | 1591 | else throw("Strict value is not equal to itself.") | |
1351 | 1592 | } | |
1352 | 1593 | ||
1353 | 1594 | ||
1354 | 1595 | ||
1355 | 1596 | @Callable(i) | |
1356 | 1597 | func unstakeAndGetOneTknV2 (unstakeAmount,outAssetId,minOutAmount) = { | |
1357 | 1598 | let isPoolOneTokenOperationsDisabled = { | |
1358 | 1599 | let @ = invoke(fca, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1359 | 1600 | if ($isInstanceOf(@, "Boolean")) | |
1360 | 1601 | then @ | |
1361 | 1602 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1362 | 1603 | } | |
1363 | 1604 | let isGetDisabled = if (if (igs()) | |
1364 | 1605 | then true | |
1365 | 1606 | else (cfgPoolStatus == PoolShutdown)) | |
1366 | 1607 | then true | |
1367 | 1608 | else isPoolOneTokenOperationsDisabled | |
1368 | 1609 | let checks = [if (if (!(isGetDisabled)) | |
1369 | 1610 | then true | |
1370 | 1611 | else isManager(i)) | |
1371 | 1612 | then true | |
1372 | 1613 | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1373 | 1614 | then true | |
1374 | 1615 | else throwErr("no payments are expected")] | |
1375 | 1616 | if ((checks == checks)) | |
1376 | 1617 | then { | |
1377 | - | let cfg = gpc() | |
1378 | 1618 | let factoryCfg = gfc() | |
1379 | - | let lpAssetId = | |
1619 | + | let lpAssetId = cfgLpAssetId | |
1380 | 1620 | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1381 | 1621 | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), unstakeAmount], nil) | |
1382 | 1622 | if ((unstakeInv == unstakeInv)) | |
1383 | 1623 | then { | |
1384 | - | let $ | |
1385 | - | let state = $ | |
1386 | - | let totalAmount = $ | |
1624 | + | let $t05514055328 = getOneTknV2Internal(outAssetId, minOutAmount, [AttachedPayment(lpAssetId, unstakeAmount)], i.caller, i.originCaller, i.transactionId) | |
1625 | + | let state = $t05514055328._1 | |
1626 | + | let totalAmount = $t05514055328._2 | |
1387 | 1627 | $Tuple2(state, totalAmount) | |
1388 | 1628 | } | |
1389 | 1629 | else throw("Strict value is not equal to itself.") | |
1390 | 1630 | } | |
1391 | 1631 | else throw("Strict value is not equal to itself.") | |
1392 | 1632 | } | |
1393 | 1633 | ||
1394 | 1634 | ||
1395 | 1635 | ||
1396 | 1636 | @Callable(i) | |
1397 | 1637 | 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 | |
1638 | + | let $t05545655559 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", true) | |
1639 | + | let lpAmount = $t05545655559._1 | |
1640 | + | let state = $t05545655559._2 | |
1641 | + | let feeAmount = $t05545655559._3 | |
1642 | + | let bonus = $t05545655559._4 | |
1407 | 1643 | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1408 | 1644 | } | |
1409 | 1645 | ||
1410 | 1646 | ||
1411 | 1647 | ||
1412 | 1648 | @Callable(i) | |
1413 | 1649 | 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 | |
1650 | + | let $t05570755811 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", false) | |
1651 | + | let lpAmount = $t05570755811._1 | |
1652 | + | let state = $t05570755811._2 | |
1653 | + | let feeAmount = $t05570755811._3 | |
1654 | + | let bonus = $t05570755811._4 | |
1423 | 1655 | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1424 | 1656 | } | |
1425 | 1657 | ||
1426 | 1658 | ||
1427 | 1659 | ||
1428 | 1660 | @Callable(i) | |
1429 | 1661 | func activate (amtAsStr,prAsStr) = if ((toString(i.caller) != toString(fca))) | |
1430 | 1662 | then throw("denied") | |
1431 | 1663 | else $Tuple2([StringEntry(aa(), amtAsStr), StringEntry(pa(), prAsStr)], "success") | |
1432 | 1664 | ||
1433 | 1665 | ||
1434 | 1666 | ||
1435 | 1667 | @Callable(i) | |
1436 | 1668 | func setS (k,v) = if ((toString(i.caller) != strf(this, ada()))) | |
1437 | 1669 | then pd | |
1438 | 1670 | else [StringEntry(k, v)] | |
1439 | 1671 | ||
1440 | 1672 | ||
1441 | 1673 | ||
1442 | 1674 | @Callable(i) | |
1443 | 1675 | func setI (k,v) = if ((toString(i.caller) != strf(this, ada()))) | |
1444 | 1676 | then pd | |
1445 | 1677 | else [IntegerEntry(k, v)] | |
1446 | 1678 | ||
1447 | 1679 | ||
1448 | 1680 | ||
1449 | 1681 | @Callable(i) | |
1450 | 1682 | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, gpc()) | |
1451 | 1683 | ||
1452 | 1684 | ||
1453 | 1685 | ||
1454 | 1686 | @Callable(i) | |
1455 | 1687 | func getAccBalanceWrapperREADONLY (assetId) = $Tuple2(nil, getAccBalance(assetId)) | |
1456 | 1688 | ||
1457 | 1689 | ||
1458 | 1690 | ||
1459 | 1691 | @Callable(i) | |
1460 | 1692 | func calcPricesWrapperREADONLY (amAmt,prAmt,lpAmt) = { | |
1461 | 1693 | let pr = calcPrices(amAmt, prAmt, lpAmt) | |
1462 | 1694 | $Tuple2(nil, [toString(pr[0]), toString(pr[1]), toString(pr[2])]) | |
1463 | 1695 | } | |
1464 | 1696 | ||
1465 | 1697 | ||
1466 | 1698 | ||
1467 | 1699 | @Callable(i) | |
1468 | 1700 | func fromX18WrapperREADONLY (val,resScaleMult) = $Tuple2(nil, f1(parseBigIntValue(val), resScaleMult)) | |
1469 | 1701 | ||
1470 | 1702 | ||
1471 | 1703 | ||
1472 | 1704 | @Callable(i) | |
1473 | 1705 | func toX18WrapperREADONLY (origVal,origScaleMult) = $Tuple2(nil, toString(t1(origVal, origScaleMult))) | |
1474 | 1706 | ||
1475 | 1707 | ||
1476 | 1708 | ||
1477 | 1709 | @Callable(i) | |
1478 | 1710 | func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString(cpbi(parseBigIntValue(prAmtX18), parseBigIntValue(amAmtX18)))) | |
1479 | 1711 | ||
1480 | 1712 | ||
1481 | 1713 | ||
1482 | 1714 | @Callable(i) | |
1483 | 1715 | 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 | 1716 | ||
1485 | 1717 | ||
1486 | 1718 | ||
1487 | 1719 | @Callable(i) | |
1488 | 1720 | func estimateGetOperationWrapperREADONLY (txId58,pmtAsId,pmtLpAmt,usrAddr) = { | |
1489 | 1721 | let r = ego(txId58, pmtAsId, pmtLpAmt, addressFromStringValue(usrAddr)) | |
1490 | 1722 | $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 | 1723 | } | |
1492 | 1724 | ||
1493 | 1725 | ||
1494 | 1726 | @Verifier(tx) | |
1495 | 1727 | func verify () = { | |
1496 | 1728 | let targetPublicKey = match m() { | |
1497 | 1729 | case pk: ByteVector => | |
1498 | 1730 | pk | |
1499 | 1731 | case _: Unit => | |
1500 | 1732 | tx.senderPublicKey | |
1501 | 1733 | case _ => | |
1502 | 1734 | throw("Match error") | |
1503 | 1735 | } | |
1504 | 1736 | match tx { | |
1505 | 1737 | case order: Order => | |
1506 | 1738 | let matcherPub = mp() | |
1507 | - | let orderValid = moa(order) | |
1739 | + | let $t05860358672 = validateMatcherOrderAllowed(order) | |
1740 | + | let orderValid = $t05860358672._1 | |
1741 | + | let orderValidInfo = $t05860358672._2 | |
1508 | 1742 | let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
1509 | 1743 | let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub) | |
1510 | 1744 | if (if (if (orderValid) | |
1511 | 1745 | then senderValid | |
1512 | 1746 | else false) | |
1513 | 1747 | then matcherValid | |
1514 | 1748 | else false) | |
1515 | 1749 | then true | |
1516 | - | else | |
1750 | + | else throwOrderError(orderValid, orderValidInfo, senderValid, matcherValid) | |
1517 | 1751 | 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) | |
1752 | + | if (sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)) | |
1524 | 1753 | then true | |
1525 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1754 | + | else { | |
1755 | + | let newHash = blake2b256(value(s.script)) | |
1756 | + | let allowedHash = fromBase64String(value(getString(fca, keyAllowedLpStableScriptHash()))) | |
1757 | + | let currentHash = scriptHash(this) | |
1758 | + | if ((allowedHash == newHash)) | |
1759 | + | then (currentHash != newHash) | |
1760 | + | else false | |
1761 | + | } | |
1526 | 1762 | case _ => | |
1527 | 1763 | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1528 | 1764 | } | |
1529 | 1765 | } | |
1530 | 1766 |
github/deemru/w8io/026f985 222.25 ms ◑