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