tx · HPfwiPJ9w9SUK82yV952ZqAcGjpZKUQydNo7dqCpudPB 3Mp3uUKsY4LnTo3j4N7dJAfqRfMJ6Rgr35Q: -0.07500000 Waves 2023.01.30 10:00 [2427371] smart account 3Mp3uUKsY4LnTo3j4N7dJAfqRfMJ6Rgr35Q > SELF 0.00000000 Waves
{ "type": 13, "id": "HPfwiPJ9w9SUK82yV952ZqAcGjpZKUQydNo7dqCpudPB", "fee": 7500000, "feeAssetId": null, "timestamp": 1675062145348, "version": 2, "chainId": 84, "sender": "3Mp3uUKsY4LnTo3j4N7dJAfqRfMJ6Rgr35Q", "senderPublicKey": "EiYReiiFX6CXEuz35wibBnvZ8LjJHZrgFwR73fomjgzy", "proofs": [ "QQzq3QKUNB2v1ypjmbAqjvXLL6LjwX4ugAo1T7X1qzLyQqkyGJ7B13TiiZm1u3RkBxWT6enwuStMj9v2CoxoVc5" ], "script": "base64:BgJyCAISABIAEgASABIDCgEBEgMKAQESDwoNAQEBAQEBAQEBAQEBARIUChIBAQEBAQEBCAgIAQEBAQEBAQESBgoEAQEBCBIAEgMKAQESBQoDAQEEEgMKAQgSABIAEgASAwoBCBIDCgEBEgASABIAEgQKAggIwgEADGtfYmFzZU9yYWNsZQIMa19iYXNlT3JhY2xlAA1rX3F1b3RlT3JhY2xlAg1rX3F1b3RlT3JhY2xlAAlrX2JhbGFuY2UCCWtfYmFsYW5jZQAKa19zZXF1ZW5jZQIKa19zZXF1ZW5jZQAOa19wb3NpdGlvblNpemUCDmtfcG9zaXRpb25TaXplABBrX3Bvc2l0aW9uTWFyZ2luAhBrX3Bvc2l0aW9uTWFyZ2luABZrX3Bvc2l0aW9uT3Blbk5vdGlvbmFsAhZrX3Bvc2l0aW9uT3Blbk5vdGlvbmFsAC5rX3Bvc2l0aW9uTGFzdFVwZGF0ZWRDdW11bGF0aXZlUHJlbWl1bUZyYWN0aW9uAhJrX3Bvc2l0aW9uRnJhY3Rpb24AEmtfcG9zaXRpb25TZXF1ZW5jZQISa19wb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yV2l0aEFydGlmYWN0AgUHX3RyYWRlcgULX2FydGlmYWN0SWQJAJQKAgUDbmlsBQZyZXN1bHQBAnR4AQZ2ZXJpZnkACQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAACQEOYWRtaW5QdWJsaWNLZXkAUYjcGQ==", "height": 2427371, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: GTwMSEdf7N6vNo2AxkDG5tGP6xLDJMzwj6wEsdZCu96J Next: 858z2JZZsF7GEpGKxhSwRxoJhjU3XzsbQmve6h1bZXd4 Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let k_ | |
4 | + | let k_baseOracle = "k_baseOracle" | |
5 | 5 | ||
6 | - | let k_ora_block_key = "k_ora_block_key" | |
7 | - | ||
8 | - | let k_ora_open_key = "k_ora_open_key" | |
9 | - | ||
10 | - | let k_ora = "k_ora" | |
6 | + | let k_quoteOracle = "k_quoteOracle" | |
11 | 7 | ||
12 | 8 | let k_balance = "k_balance" | |
13 | 9 | ||
27 | 23 | ||
28 | 24 | let k_positionFee = "k_positionFee" | |
29 | 25 | ||
26 | + | let k_positionLastUpdatedTimestamp = "k_positionTimestamp" | |
27 | + | ||
30 | 28 | let k_initialized = "k_initialized" | |
31 | 29 | ||
32 | 30 | let k_paused = "k_paused" | |
34 | 32 | let k_closeOnly = "k_closeOnly" | |
35 | 33 | ||
36 | 34 | let k_fee = "k_fee" | |
35 | + | ||
36 | + | let k_rolloverFee = "k_rollover_fee" | |
37 | 37 | ||
38 | 38 | let k_fundingPeriod = "k_fundingPeriod" | |
39 | 39 | ||
97 | 97 | ||
98 | 98 | let k_openInterestLong = "k_openInterestLong" | |
99 | 99 | ||
100 | + | let k_lastTx = "k_lastTx" | |
101 | + | ||
100 | 102 | let k_coordinatorAddress = "k_coordinatorAddress" | |
101 | 103 | ||
102 | 104 | let k_vault_address = "k_vault_address" | |
117 | 119 | ||
118 | 120 | let k_referral_address = "k_referral_address" | |
119 | 121 | ||
120 | - | let k_collateral_address = "k_collateral_address" | |
121 | - | ||
122 | 122 | let k_exchange_address = "k_exchange_address" | |
123 | 123 | ||
124 | 124 | let k_nft_manager_address = "k_nft_manager_address" | |
125 | - | ||
126 | - | let k_trader_market_asset_collateral = "k_trader_market_asset_collateral" | |
127 | 125 | ||
128 | 126 | func toCompositeKey (_key,_address) = ((_key + "_") + _address) | |
129 | 127 | ||
161 | 159 | func nftManagerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_nft_manager_address)), "NFT Manager not set") | |
162 | 160 | ||
163 | 161 | ||
164 | - | func collateralAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_collateral_address)), "Collateral Manager not set") | |
165 | - | ||
166 | - | ||
167 | - | func swapAddress () = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(coordinator(), k_exchange_address), "No swap address")), "Invalid swap address") | |
168 | - | ||
169 | - | ||
170 | - | let k_whitelist_asset = "k_whitelist_asset" | |
171 | - | ||
172 | - | func isWhitelistAsset (_assetId) = valueOrElse(getBoolean(collateralAddress(), toCompositeKey(k_whitelist_asset, _assetId)), false) | |
173 | - | ||
174 | - | ||
175 | 162 | let k_token_param = "k_token_param" | |
176 | 163 | ||
177 | 164 | let k_token_type = "k_token_type" | |
184 | 171 | ||
185 | 172 | let TWAP_INTERVAL = 15 | |
186 | 173 | ||
187 | - | let ORACLE_INTERVAL = 15 | |
188 | - | ||
189 | 174 | let SECONDS = 1000 | |
190 | 175 | ||
191 | 176 | let DECIMAL_NUMBERS = 6 | |
192 | 177 | ||
193 | 178 | let DECIMAL_UNIT = (1 * (((((10 * 10) * 10) * 10) * 10) * 10)) | |
194 | 179 | ||
180 | + | let MINUTES_IN_YEAR = (525600 * DECIMAL_UNIT) | |
181 | + | ||
195 | 182 | let ONE_DAY = (86400 * DECIMAL_UNIT) | |
196 | - | ||
197 | - | let ALL_FEES = 100 | |
198 | 183 | ||
199 | 184 | let PNL_OPTION_SPOT = 1 | |
200 | 185 | ||
237 | 222 | else _y | |
238 | 223 | ||
239 | 224 | ||
240 | - | func listToStr (_list) = { | |
241 | - | func _join (accumulator,val) = ((accumulator + val) + ",") | |
242 | - | ||
243 | - | let newListStr = { | |
244 | - | let $l = _list | |
245 | - | let $s = size($l) | |
246 | - | let $acc0 = "" | |
247 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
248 | - | then $a | |
249 | - | else _join($a, $l[$i]) | |
250 | - | ||
251 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
252 | - | then $a | |
253 | - | else throw("List size exceeds 20") | |
254 | - | ||
255 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20) | |
256 | - | } | |
257 | - | let newListStrU = dropRight(newListStr, 1) | |
258 | - | let newListStrR = if ((take(newListStrU, 1) == ",")) | |
259 | - | then drop(newListStrU, 1) | |
260 | - | else newListStrU | |
261 | - | newListStrR | |
262 | - | } | |
225 | + | func listToStr (_list) = if ((size(_list) == 0)) | |
226 | + | then "" | |
227 | + | else makeString(_list, ",") | |
263 | 228 | ||
264 | 229 | ||
265 | - | func strToList (_str) = split(_str, ",") | |
230 | + | func strToList (_str) = if ((_str == "")) | |
231 | + | then nil | |
232 | + | else split(_str, ",") | |
266 | 233 | ||
267 | 234 | ||
268 | 235 | func pushToQueue (_list,_maxSize,_value) = if ((size(_list) > _maxSize)) | |
292 | 259 | ||
293 | 260 | ||
294 | 261 | func fee () = int(k_fee) | |
262 | + | ||
263 | + | ||
264 | + | func rolloverFeeRate () = int(k_rolloverFee) | |
295 | 265 | ||
296 | 266 | ||
297 | 267 | func initMarginRatio () = int(k_initMarginRatio) | |
375 | 345 | func maxOracleDelay () = int(k_maxOracleDelay) | |
376 | 346 | ||
377 | 347 | ||
348 | + | func lastTimestamp () = lastBlock.timestamp | |
349 | + | ||
350 | + | ||
378 | 351 | func getActualCaller (i) = valueOrElse(getString(ordersAddress(), "k_sender"), toString(i.caller)) | |
379 | 352 | ||
380 | 353 | ||
403 | 376 | let positionSizeOpt = getInteger(this, toCompositeKey(k_positionSize, _trader)) | |
404 | 377 | match positionSizeOpt { | |
405 | 378 | case positionSize: Int => | |
406 | - | $ | |
379 | + | $Tuple5(positionSize, getIntegerValue(this, toCompositeKey(k_positionMargin, _trader)), getIntegerValue(this, toCompositeKey(k_positionOpenNotional, _trader)), getIntegerValue(this, toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _trader)), getIntegerValue(this, toCompositeKey(k_positionLastUpdatedTimestamp, _trader))) | |
407 | 380 | case _ => | |
408 | - | $ | |
381 | + | $Tuple5(0, 0, 0, 0, 0) | |
409 | 382 | } | |
410 | 383 | } | |
411 | 384 | ||
435 | 408 | func requireOpenPosition (_trader) = if ((getPosition(_trader)._1 == 0)) | |
436 | 409 | then throw("No open position") | |
437 | 410 | else true | |
411 | + | ||
412 | + | ||
413 | + | func getOracleData (key) = { | |
414 | + | let oracleDataStr = getString(this, key) | |
415 | + | if (if (isDefined(oracleDataStr)) | |
416 | + | then (value(oracleDataStr) != "") | |
417 | + | else false) | |
418 | + | then { | |
419 | + | let oracleData = split(value(oracleDataStr), ",") | |
420 | + | let oracleAddress = valueOrErrorMessage(addressFromString(oracleData[0]), ("Invalid oracle address in: " + value(oracleDataStr))) | |
421 | + | let priceKey = oracleData[1] | |
422 | + | let blockKey = oracleData[2] | |
423 | + | let openKey = oracleData[3] | |
424 | + | $Tuple4(oracleAddress, priceKey, blockKey, openKey) | |
425 | + | } | |
426 | + | else unit | |
427 | + | } | |
438 | 428 | ||
439 | 429 | ||
440 | 430 | func initialized () = valueOrElse(getBoolean(this, k_initialized), false) | |
483 | 473 | let amountBaseAssetBought = if (_isAdd) | |
484 | 474 | then amountBaseAssetBoughtAbs | |
485 | 475 | else -(amountBaseAssetBoughtAbs) | |
486 | - | let $ | |
487 | - | let quoteAssetReserveAfter1 = $ | |
488 | - | let baseAssetReserveAfter1 = $ | |
489 | - | let totalPositionSizeAfter1 = $ | |
476 | + | let $t01725917429 = updateReserve(_isAdd, quoteAssetAmountAdjusted, amountBaseAssetBoughtAbs) | |
477 | + | let quoteAssetReserveAfter1 = $t01725917429._1 | |
478 | + | let baseAssetReserveAfter1 = $t01725917429._2 | |
479 | + | let totalPositionSizeAfter1 = $t01725917429._3 | |
490 | 480 | let priceBefore = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW)) | |
491 | 481 | let marketPrice = divd(_quoteAssetAmount, amountBaseAssetBoughtAbs) | |
492 | 482 | let priceDiff = abs((priceBefore - marketPrice)) | |
498 | 488 | } | |
499 | 489 | ||
500 | 490 | ||
501 | - | func calcRemainMarginWithFundingPayment (_oldPositionSize,_oldPositionMargin,_oldPositionCumulativePremiumFraction,_marginDelta) = { | |
491 | + | func calcRolloverFee (_oldPositionMargin,_oldPositionLastUpdatedTimestamp) = { | |
492 | + | let positionMinutes = ((((lastTimestamp() - _oldPositionLastUpdatedTimestamp) / 1000) / 60) * DECIMAL_UNIT) | |
493 | + | let rolloverFee = divd(muld(muld(_oldPositionMargin, positionMinutes), rolloverFeeRate()), MINUTES_IN_YEAR) | |
494 | + | rolloverFee | |
495 | + | } | |
496 | + | ||
497 | + | ||
498 | + | func calcRemainMarginWithFundingPaymentAndRolloverFee (_oldPositionSize,_oldPositionMargin,_oldPositionCumulativePremiumFraction,_oldPositionLastUpdatedTimestamp,_marginDelta) = { | |
502 | 499 | let fundingPayment = if ((_oldPositionSize != 0)) | |
503 | 500 | then { | |
504 | 501 | let _latestCumulativePremiumFraction = latestCumulativePremiumFraction(_oldPositionSize) | |
505 | 502 | muld((_latestCumulativePremiumFraction - _oldPositionCumulativePremiumFraction), _oldPositionSize) | |
506 | 503 | } | |
507 | 504 | else 0 | |
508 | - | let signedMargin = ((_marginDelta - fundingPayment) + _oldPositionMargin) | |
509 | - | let $t01879518922 = if ((0 > signedMargin)) | |
505 | + | let rolloverFee = calcRolloverFee(_oldPositionMargin, _oldPositionLastUpdatedTimestamp) | |
506 | + | let signedMargin = (((_marginDelta - rolloverFee) - fundingPayment) + _oldPositionMargin) | |
507 | + | let $t01968419811 = if ((0 > signedMargin)) | |
510 | 508 | then $Tuple2(0, abs(signedMargin)) | |
511 | 509 | else $Tuple2(abs(signedMargin), 0) | |
512 | - | let remainMargin = $ | |
513 | - | let badDebt = $ | |
514 | - | $ | |
510 | + | let remainMargin = $t01968419811._1 | |
511 | + | let badDebt = $t01968419811._2 | |
512 | + | $Tuple4(remainMargin, badDebt, fundingPayment, rolloverFee) | |
515 | 513 | } | |
516 | 514 | ||
517 | 515 | ||
528 | 526 | let quoteAssetDelta = abs((quoteAssetAfter - _quoteAssetReserve)) | |
529 | 527 | let quoteAssetSold = muld(quoteAssetDelta, _quoteAssetWeight) | |
530 | 528 | let maxPriceImpactValue = maxPriceImpact() | |
531 | - | let $ | |
532 | - | let quoteAssetReserveAfter1 = $ | |
533 | - | let baseAssetReserveAfter1 = $ | |
534 | - | let totalPositionSizeAfter1 = $ | |
529 | + | let $t02107321235 = updateReserve(!(_isAdd), quoteAssetDelta, _baseAssetAmount) | |
530 | + | let quoteAssetReserveAfter1 = $t02107321235._1 | |
531 | + | let baseAssetReserveAfter1 = $t02107321235._2 | |
532 | + | let totalPositionSizeAfter1 = $t02107321235._3 | |
535 | 533 | let marketPrice = divd(quoteAssetSold, _baseAssetAmount) | |
536 | 534 | let priceDiff = abs((priceBefore - marketPrice)) | |
537 | 535 | let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff))) | |
551 | 549 | func swapOutput (_isAdd,_baseAssetAmount,_checkMaxPriceImpact) = swapOutputWithReserves(_isAdd, _baseAssetAmount, _checkMaxPriceImpact, qtAstR(), qtAstW(), bsAstR(), bsAstW()) | |
552 | 550 | ||
553 | 551 | ||
554 | - | func getOraclePrice () = { | |
555 | - | let oracle = valueOrErrorMessage(addressFromString(getStringValue(this, k_ora)), "") | |
556 | - | let priceKey = getStringValue(this, k_ora_key) | |
552 | + | func getOraclePriceValue (oracle,priceKey,blockKey) = { | |
557 | 553 | let lastValue = valueOrErrorMessage(getInteger(oracle, priceKey), ((("Can not get oracle price. Oracle: " + toString(oracle)) + " key: ") + priceKey)) | |
558 | - | let blockKey = valueOrElse(getString(this, k_ora_block_key), "") | |
559 | 554 | if ((blockKey != "")) | |
560 | 555 | then { | |
561 | 556 | let currentBlock = lastBlock.height | |
568 | 563 | } | |
569 | 564 | ||
570 | 565 | ||
566 | + | func getOraclePrice () = { | |
567 | + | let baseOracle = valueOrErrorMessage(getOracleData(k_baseOracle), "No base asset oracle data") | |
568 | + | let baseOraclePrice = getOraclePriceValue(baseOracle._1, baseOracle._2, baseOracle._3) | |
569 | + | let quoteOracle = getOracleData(k_quoteOracle) | |
570 | + | let quoteOraclePrice = if (isDefined(quoteOracle)) | |
571 | + | then { | |
572 | + | let quoteOracleV = value(quoteOracle) | |
573 | + | getOraclePriceValue(quoteOracleV._1, quoteOracleV._2, quoteOracleV._3) | |
574 | + | } | |
575 | + | else DECIMAL_UNIT | |
576 | + | divd(baseOraclePrice, quoteOraclePrice) | |
577 | + | } | |
578 | + | ||
579 | + | ||
571 | 580 | func isMarketClosed () = { | |
572 | - | let oracle = valueOrErrorMessage(addressFromString(getStringValue(this, k_ora)), "") | |
573 | - | let openKey = valueOrElse(getString(this, k_ora_open_key), "") | |
581 | + | let baseOracle = valueOrErrorMessage(getOracleData(k_baseOracle), "No base asset oracle data") | |
582 | + | let oracle = baseOracle._1 | |
583 | + | let openKey = baseOracle._4 | |
574 | 584 | if ((openKey != "")) | |
575 | 585 | then { | |
576 | 586 | let isOpen = valueOrErrorMessage(getBoolean(oracle, openKey), ((("Can not get oracle is open/closed. Oracle: " + toString(oracle)) + " key: ") + openKey)) | |
633 | 643 | let isShort = (0 > _positionSize) | |
634 | 644 | let positionNotional = if ((_option == PNL_OPTION_SPOT)) | |
635 | 645 | then { | |
636 | - | let $t02520525425 = swapOutputWithReserves(!(isShort), positionSizeAbs, false, _quoteAssetReserve, _quoteAssetWeight, _baseAssetReserve, _baseAssetWeight) | |
637 | - | let outPositionNotional = $t02520525425._1 | |
638 | - | let x1 = $t02520525425._2 | |
639 | - | let x2 = $t02520525425._3 | |
640 | - | let x3 = $t02520525425._4 | |
646 | + | let outPositionNotional = swapOutputWithReserves(!(isShort), positionSizeAbs, false, _quoteAssetReserve, _quoteAssetWeight, _baseAssetReserve, _baseAssetWeight)._1 | |
641 | 647 | outPositionNotional | |
642 | 648 | } | |
643 | 649 | else muld(positionSizeAbs, getOraclePrice()) | |
658 | 664 | ||
659 | 665 | ||
660 | 666 | func getPositionNotionalAndUnrealizedPnl (_trader,_option) = { | |
661 | - | let $ | |
662 | - | let positionSize = $ | |
663 | - | let positionMargin = $ | |
664 | - | let positionOpenNotional = $ | |
665 | - | let positionLstUpdCPF = $ | |
667 | + | let $t02911329241 = getPosition(_trader) | |
668 | + | let positionSize = $t02911329241._1 | |
669 | + | let positionMargin = $t02911329241._2 | |
670 | + | let positionOpenNotional = $t02911329241._3 | |
671 | + | let positionLstUpdCPF = $t02911329241._4 | |
666 | 672 | getPositionNotionalAndUnrealizedPnlByValues(positionSize, positionOpenNotional, qtAstR(), qtAstW(), bsAstR(), bsAstW(), _option) | |
667 | 673 | } | |
668 | 674 | ||
671 | 677 | ||
672 | 678 | ||
673 | 679 | func getMarginRatioByOption (_trader,_option) = { | |
674 | - | let $t02748727598 = getPosition(_trader) | |
675 | - | let positionSize = $t02748727598._1 | |
676 | - | let positionMargin = $t02748727598._2 | |
677 | - | let pon = $t02748727598._3 | |
678 | - | let positionLstUpdCPF = $t02748727598._4 | |
679 | - | let $t02760427697 = getPositionNotionalAndUnrealizedPnl(_trader, _option) | |
680 | - | let positionNotional = $t02760427697._1 | |
681 | - | let unrealizedPnl = $t02760427697._2 | |
682 | - | let $t02770227868 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
683 | - | let remainMargin = $t02770227868._1 | |
684 | - | let badDebt = $t02770227868._2 | |
680 | + | let $t02975629897 = getPosition(_trader) | |
681 | + | let positionSize = $t02975629897._1 | |
682 | + | let positionMargin = $t02975629897._2 | |
683 | + | let pon = $t02975629897._3 | |
684 | + | let positionLastUpdatedCPF = $t02975629897._4 | |
685 | + | let positionTimestamp = $t02975629897._5 | |
686 | + | let $t02990329996 = getPositionNotionalAndUnrealizedPnl(_trader, _option) | |
687 | + | let positionNotional = $t02990329996._1 | |
688 | + | let unrealizedPnl = $t02990329996._2 | |
689 | + | let $t03000130213 = calcRemainMarginWithFundingPaymentAndRolloverFee(positionSize, positionMargin, positionLastUpdatedCPF, positionTimestamp, unrealizedPnl) | |
690 | + | let remainMargin = $t03000130213._1 | |
691 | + | let badDebt = $t03000130213._2 | |
685 | 692 | calcMarginRatio(remainMargin, badDebt, positionNotional) | |
686 | 693 | } | |
687 | 694 | ||
696 | 703 | let maxExchangedQuoteAssetAmount = swapResult._1 | |
697 | 704 | let priceImpact = swapResult._7 | |
698 | 705 | if ((maxPriceImpact() > priceImpact)) | |
699 | - | then maxExchangedQuoteAssetAmount | |
700 | - | else { | |
701 | - | let exchangedPositionSize = muld(abs(_positionSize), partialLiquidationRatio()) | |
702 | - | let exchangedQuoteAssetAmount = swapOutput((_positionSize > 0), exchangedPositionSize, false)._1 | |
703 | - | exchangedQuoteAssetAmount | |
704 | - | } | |
706 | + | then maxExchangedPositionSize | |
707 | + | else muld(abs(_positionSize), partialLiquidationRatio()) | |
705 | 708 | } | |
706 | 709 | ||
707 | 710 | ||
708 | - | func internalClosePosition (_trader,_checkMaxPriceImpact) = { | |
709 | - | let $t02910829236 = getPosition(_trader) | |
710 | - | let positionSize = $t02910829236._1 | |
711 | - | let positionMargin = $t02910829236._2 | |
712 | - | let positionOpenNotional = $t02910829236._3 | |
713 | - | let positionLstUpdCPF = $t02910829236._4 | |
714 | - | let unrealizedPnl = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)._2 | |
715 | - | let $t02933129499 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
716 | - | let remainMargin = $t02933129499._1 | |
717 | - | let badDebt = $t02933129499._2 | |
718 | - | let exchangedPositionSize = -(positionSize) | |
719 | - | let realizedPnl = unrealizedPnl | |
720 | - | let marginToVault = -(remainMargin) | |
721 | - | let $t02962629900 = swapOutput((positionSize > 0), abs(positionSize), _checkMaxPriceImpact) | |
722 | - | let exchangedQuoteAssetAmount = $t02962629900._1 | |
723 | - | let quoteAssetReserveAfter = $t02962629900._2 | |
724 | - | let baseAssetReserveAfter = $t02962629900._3 | |
725 | - | let totalPositionSizeAfter = $t02962629900._4 | |
726 | - | let totalLongAfter = $t02962629900._5 | |
727 | - | let totalShortAfter = $t02962629900._6 | |
728 | - | let openInterestNotionalAfter = (openInterestNotional() - positionOpenNotional) | |
729 | - | $Tuple13(exchangedPositionSize, badDebt, realizedPnl, marginToVault, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, exchangedQuoteAssetAmount, totalLongAfter, totalShortAfter, (openInterestLong() - (if ((positionSize > 0)) | |
730 | - | then positionOpenNotional | |
731 | - | else 0)), (openInterestShort() - (if ((0 > positionSize)) | |
732 | - | then positionOpenNotional | |
733 | - | else 0))) | |
711 | + | func internalClosePosition (_trader,_size,_fee,_minQuoteAssetAmount,_addToMargin,_checkMaxPriceImpact) = { | |
712 | + | let $t03125731413 = getPosition(_trader) | |
713 | + | let oldPositionSize = $t03125731413._1 | |
714 | + | let oldPositionMargin = $t03125731413._2 | |
715 | + | let oldPositionOpenNotional = $t03125731413._3 | |
716 | + | let oldPositionLstUpdCPF = $t03125731413._4 | |
717 | + | let oldPositionTimestamp = $t03125731413._5 | |
718 | + | let isLongPosition = (oldPositionSize > 0) | |
719 | + | let absOldPositionSize = abs(oldPositionSize) | |
720 | + | if (if ((absOldPositionSize >= _size)) | |
721 | + | then (_size > 0) | |
722 | + | else false) | |
723 | + | then { | |
724 | + | let isPartialClose = (absOldPositionSize > _size) | |
725 | + | let $t03170532156 = swapOutput((oldPositionSize > 0), _size, _checkMaxPriceImpact) | |
726 | + | let exchangedQuoteAssetAmount = $t03170532156._1 | |
727 | + | let quoteAssetReserveAfter = $t03170532156._2 | |
728 | + | let baseAssetReserveAfter = $t03170532156._3 | |
729 | + | let totalPositionSizeAfter = $t03170532156._4 | |
730 | + | let exchangedPositionSize = if ((oldPositionSize > 0)) | |
731 | + | then -(_size) | |
732 | + | else _size | |
733 | + | let $t03237132578 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
734 | + | let oldPositionNotional = $t03237132578._1 | |
735 | + | let unrealizedPnl = $t03237132578._2 | |
736 | + | let realizedRatio = divd(abs(exchangedPositionSize), absOldPositionSize) | |
737 | + | let realizedPnl = muld(unrealizedPnl, realizedRatio) | |
738 | + | let $t03291933165 = calcRemainMarginWithFundingPaymentAndRolloverFee(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, oldPositionTimestamp, unrealizedPnl) | |
739 | + | let remainMarginBefore = $t03291933165._1 | |
740 | + | let x1 = $t03291933165._2 | |
741 | + | let x2 = $t03291933165._3 | |
742 | + | let rolloverFee = $t03291933165._4 | |
743 | + | let positionBadDebt = calcRemainMarginWithFundingPaymentAndRolloverFee(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, oldPositionTimestamp, realizedPnl)._2 | |
744 | + | let realizedCloseFee = muld(muld(oldPositionNotional, realizedRatio), _fee) | |
745 | + | let unrealizedPnlAfter = (unrealizedPnl - realizedPnl) | |
746 | + | let remainOpenNotional = if ((oldPositionSize > 0)) | |
747 | + | then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter) | |
748 | + | else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount) | |
749 | + | let newPositionSize = (oldPositionSize + exchangedPositionSize) | |
750 | + | let $t03457134957 = if ((newPositionSize == 0)) | |
751 | + | then $Tuple2(0, 0) | |
752 | + | else $Tuple2(abs(remainOpenNotional), latestCumulativePremiumFraction(newPositionSize)) | |
753 | + | let newPositionOpenNotional = $t03457134957._1 | |
754 | + | let newPositionLstUpdCPF = $t03457134957._2 | |
755 | + | let openNotionalDelta = (oldPositionOpenNotional - newPositionOpenNotional) | |
756 | + | let marginRatio = getMarginRatioByOption(_trader, PNL_OPTION_SPOT) | |
757 | + | let newPositionMarginWithSameRatio = if ((oldPositionSize > 0)) | |
758 | + | then (muld((newPositionOpenNotional + unrealizedPnlAfter), marginRatio) - unrealizedPnlAfter) | |
759 | + | else (muld((newPositionOpenNotional - unrealizedPnlAfter), marginRatio) - unrealizedPnlAfter) | |
760 | + | let marginToTraderRaw = ((remainMarginBefore - (newPositionMarginWithSameRatio + unrealizedPnlAfter)) - realizedCloseFee) | |
761 | + | let marginToTrader = if ((0 > marginToTraderRaw)) | |
762 | + | then throw("Invalid internalClosePosition params: unable to pay fee") | |
763 | + | else marginToTraderRaw | |
764 | + | let newPositionMargin = if (_addToMargin) | |
765 | + | then (newPositionMarginWithSameRatio + marginToTrader) | |
766 | + | else newPositionMarginWithSameRatio | |
767 | + | if (if ((_minQuoteAssetAmount != 0)) | |
768 | + | then (_minQuoteAssetAmount > exchangedQuoteAssetAmount) | |
769 | + | else false) | |
770 | + | then throw(((("Limit error: " + toString(exchangedQuoteAssetAmount)) + " < ") + toString(_minQuoteAssetAmount))) | |
771 | + | else $Tuple17(newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF, positionBadDebt, realizedPnl, if (if (_addToMargin) | |
772 | + | then isPartialClose | |
773 | + | else false) | |
774 | + | then 0 | |
775 | + | else marginToTrader, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, (openInterestNotional() - openNotionalDelta), (totalLongPositionSize() - (if (isLongPosition) | |
776 | + | then abs(exchangedPositionSize) | |
777 | + | else 0)), (totalShortPositionSize() - (if (!(isLongPosition)) | |
778 | + | then abs(exchangedPositionSize) | |
779 | + | else 0)), (openInterestLong() - (if (isLongPosition) | |
780 | + | then openNotionalDelta | |
781 | + | else 0)), (openInterestShort() - (if (!(isLongPosition)) | |
782 | + | then openNotionalDelta | |
783 | + | else 0)), (realizedCloseFee + rolloverFee), exchangedQuoteAssetAmount) | |
784 | + | } | |
785 | + | else throw("Invalid internalClosePosition params: invalid position size") | |
734 | 786 | } | |
735 | 787 | ||
736 | 788 | ||
737 | 789 | func getTwapSpotPrice () = { | |
738 | - | let minuteId = (( | |
790 | + | let minuteId = ((lastTimestamp() / 1000) / 60) | |
739 | 791 | let startMinuteId = (minuteId - TWAP_INTERVAL) | |
740 | 792 | let listStr = valueOrElse(getString(this, k_lastDataStr), "") | |
741 | 793 | let list = split(listStr, ",") | |
742 | - | func filterFn (accumulator,next) = if ((startMinuteId >= | |
794 | + | func filterFn (accumulator,next) = if ((startMinuteId >= valueOrErrorMessage(parseInt(next), ("getTwapSpotPrice: invalid int: " + listStr)))) | |
743 | 795 | then (accumulator :+ parseIntValue(next)) | |
744 | 796 | else accumulator | |
745 | 797 | ||
759 | 811 | } | |
760 | 812 | let maxIndex = if ((size(listF) > 0)) | |
761 | 813 | then max(listF) | |
762 | - | else | |
814 | + | else valueOrErrorMessage(parseInt(list[0]), ("getTwapSpotPrice: invalid int: " + listStr)) | |
763 | 815 | let lastMinuteId = valueOrElse(getInteger(this, k_lastMinuteId), 0) | |
764 | 816 | let endLastCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(lastMinuteId))), 0) | |
765 | 817 | let endLastPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(lastMinuteId))), 0) | |
777 | 829 | then $Tuple2(qtAstR(), bsAstR()) | |
778 | 830 | else { | |
779 | 831 | let direction = (_positionSize > 0) | |
780 | - | let $ | |
781 | - | let currentNetMarketValue = $ | |
782 | - | let terminalQuoteAssetReserve = $ | |
783 | - | let terminalBaseAssetReserve = $ | |
832 | + | let $t03956039739 = swapOutput(direction, abs(_positionSize), false) | |
833 | + | let currentNetMarketValue = $t03956039739._1 | |
834 | + | let terminalQuoteAssetReserve = $t03956039739._2 | |
835 | + | let terminalBaseAssetReserve = $t03956039739._3 | |
784 | 836 | $Tuple2(terminalQuoteAssetReserve, terminalBaseAssetReserve) | |
785 | 837 | } | |
786 | 838 | } | |
845 | 897 | func getAdjustedFee (_artifactId,_baseFeeDiscount) = { | |
846 | 898 | let baseFeeRaw = fee() | |
847 | 899 | let baseFee = muld(baseFeeRaw, _baseFeeDiscount) | |
848 | - | let $ | |
900 | + | let $t04260043095 = if ((_artifactId != "")) | |
849 | 901 | then { | |
850 | 902 | let artifactKind = strA(nftManagerAddress(), toCompositeKey(k_token_type, _artifactId)) | |
851 | 903 | if ((artifactKind == FEE_REDUCTION_TOKEN_TYPE)) | |
857 | 909 | else throw("Invalid attached artifact") | |
858 | 910 | } | |
859 | 911 | else $Tuple2(baseFee, false) | |
860 | - | let adjustedFee = $ | |
861 | - | let burnArtifact = $ | |
912 | + | let adjustedFee = $t04260043095._1 | |
913 | + | let burnArtifact = $t04260043095._2 | |
862 | 914 | $Tuple2(adjustedFee, burnArtifact) | |
863 | 915 | } | |
864 | 916 | ||
874 | 926 | func isSameAsset (_trader,_assetId) = (getPositionAsset(_trader) == _assetId) | |
875 | 927 | ||
876 | 928 | ||
877 | - | func getBorrowedByTraderInMarketKey (_amm,_assetId,_trader) = ((((((k_trader_market_asset_collateral + "_") + _amm) + "_") + _assetId) + "_") + _trader) | |
878 | - | ||
879 | - | ||
880 | - | func getBorrowedByTrader (_trader) = { | |
881 | - | let positionAsset = getPositionAsset(_trader) | |
882 | - | if ((positionAsset == toBase58String(quoteAsset()))) | |
883 | - | then $Tuple2(0, positionAsset) | |
884 | - | else { | |
885 | - | let key = getBorrowedByTraderInMarketKey(toString(this), positionAsset, _trader) | |
886 | - | let borrow = valueOrElse(getInteger(collateralAddress(), key), 0) | |
887 | - | $Tuple2(borrow, positionAsset) | |
888 | - | } | |
889 | - | } | |
890 | - | ||
891 | - | ||
892 | 929 | func getForTraderWithArtifact (_trader,_artifactId) = { | |
893 | 930 | let doGetFeeDiscount = invoke(minerAddress(), "computeFeeDiscount", [_trader], nil) | |
894 | 931 | if ((doGetFeeDiscount == doGetFeeDiscount)) | |
899 | 936 | case _ => | |
900 | 937 | throw("Invalid computeFeeDiscount result") | |
901 | 938 | } | |
902 | - | let $ | |
903 | - | let adjustedFee = $ | |
904 | - | let burnArtifact = $ | |
939 | + | let $t04377543849 = getAdjustedFee(_artifactId, feeDiscount) | |
940 | + | let adjustedFee = $t04377543849._1 | |
941 | + | let burnArtifact = $t04377543849._2 | |
905 | 942 | $Tuple2(adjustedFee, burnArtifact) | |
906 | 943 | } | |
907 | 944 | else throw("Strict value is not equal to itself.") | |
923 | 960 | } | |
924 | 961 | ||
925 | 962 | ||
926 | - | func updateSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional,_feeToStakersPercent,_maxOracleDelay) = [IntegerEntry(k_initMarginRatio, _initMarginRatio), IntegerEntry(k_maintenanceMarginRatio, _mmr), IntegerEntry(k_liquidationFeeRatio, _liquidationFeeRatio), IntegerEntry(k_fundingPeriod, _fundingPeriod), IntegerEntry(k_fee, _fee), IntegerEntry(k_spreadLimit, _spreadLimit), IntegerEntry(k_maxPriceImpact, _maxPriceImpact), IntegerEntry(k_partialLiquidationRatio, _partialLiquidationRatio), IntegerEntry(k_maxPriceSpread, _maxPriceSpread), IntegerEntry(k_maxOpenNotional, _maxOpenNotional), IntegerEntry(k_feeToStakersPercent, _feeToStakersPercent), IntegerEntry(k_maxOracleDelay, _feeToStakersPercent)] | |
963 | + | func updateSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional,_feeToStakersPercent,_maxOracleDelay,_rolloverFee) = [IntegerEntry(k_initMarginRatio, _initMarginRatio), IntegerEntry(k_maintenanceMarginRatio, _mmr), IntegerEntry(k_liquidationFeeRatio, _liquidationFeeRatio), IntegerEntry(k_fundingPeriod, _fundingPeriod), IntegerEntry(k_fee, _fee), IntegerEntry(k_spreadLimit, _spreadLimit), IntegerEntry(k_maxPriceImpact, _maxPriceImpact), IntegerEntry(k_partialLiquidationRatio, _partialLiquidationRatio), IntegerEntry(k_maxPriceSpread, _maxPriceSpread), IntegerEntry(k_maxOpenNotional, _maxOpenNotional), IntegerEntry(k_feeToStakersPercent, _feeToStakersPercent), IntegerEntry(k_maxOracleDelay, _feeToStakersPercent), IntegerEntry(k_rolloverFee, _rolloverFee)] | |
927 | 964 | ||
928 | 965 | ||
929 | 966 | func updateFunding (_nextFundingBlock,_latestLongCumulativePremiumFraction,_latestShortCumulativePremiumFraction,_longFundingRate,_shortFundingRate) = [IntegerEntry(k_nextFundingBlock, _nextFundingBlock), IntegerEntry(k_latestLongCumulativePremiumFraction, _latestLongCumulativePremiumFraction), IntegerEntry(k_latestShortCumulativePremiumFraction, _latestShortCumulativePremiumFraction), IntegerEntry(k_longFundingRate, _longFundingRate), IntegerEntry(k_shortFundingRate, _shortFundingRate)] | |
930 | - | ||
931 | - | ||
932 | - | func updatePositionAsset (_address,_assetId) = [StringEntry(toCompositeKey(k_positionAsset, _address), _assetId)] | |
933 | 967 | ||
934 | 968 | ||
935 | 969 | func incrementPositionSequenceNumber (_isNewPosition,_address) = if (_isNewPosition) | |
945 | 979 | else nil | |
946 | 980 | ||
947 | 981 | ||
948 | - | func updatePosition (_address,_size,_margin,_openNotional,_latestCumulativePremiumFraction) = [IntegerEntry(toCompositeKey(k_positionSize, _address), _size), IntegerEntry(toCompositeKey(k_positionMargin, _address), _margin), IntegerEntry(toCompositeKey(k_positionOpenNotional, _address), _openNotional), IntegerEntry(toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _address), _latestCumulativePremiumFraction)] | |
982 | + | func updatePosition (_address,_size,_margin,_openNotional,_latestCumulativePremiumFraction,_latestTimestamp) = [IntegerEntry(toCompositeKey(k_positionSize, _address), _size), IntegerEntry(toCompositeKey(k_positionMargin, _address), _margin), IntegerEntry(toCompositeKey(k_positionOpenNotional, _address), _openNotional), IntegerEntry(toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _address), _latestCumulativePremiumFraction), IntegerEntry(toCompositeKey(k_positionLastUpdatedTimestamp, _address), _latestTimestamp)] | |
949 | 983 | ||
950 | 984 | ||
951 | 985 | func appendTwap (_price) = { | |
952 | - | let minuteId = (( | |
986 | + | let minuteId = ((lastTimestamp() / 1000) / 60) | |
953 | 987 | let previousMinuteId = valueOrElse(getInteger(this, k_lastMinuteId), 0) | |
954 | 988 | if ((previousMinuteId > minuteId)) | |
955 | 989 | then throw("TWAP out-of-order") | |
991 | 1025 | } | |
992 | 1026 | ||
993 | 1027 | ||
994 | - | func deletePosition (_address) = [DeleteEntry(toCompositeKey(k_positionSize, _address)), DeleteEntry(toCompositeKey(k_positionMargin, _address)), DeleteEntry(toCompositeKey(k_positionOpenNotional, _address)), DeleteEntry(toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _address)), DeleteEntry(toCompositeKey(k_positionAsset, _address))] | |
1028 | + | func deletePosition (_address) = [DeleteEntry(toCompositeKey(k_positionSize, _address)), DeleteEntry(toCompositeKey(k_positionMargin, _address)), DeleteEntry(toCompositeKey(k_positionOpenNotional, _address)), DeleteEntry(toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _address)), DeleteEntry(toCompositeKey(k_positionAsset, _address)), DeleteEntry(toCompositeKey(k_positionFee, _address)), DeleteEntry(toCompositeKey(k_positionLastUpdatedTimestamp, _address))] | |
995 | 1029 | ||
996 | 1030 | ||
997 | 1031 | func withdraw (_address,_amount) = { | |
1057 | 1091 | let qtAstRAfter = (_qtAstR + _quoteAssetAmount) | |
1058 | 1092 | let baseAssetAmountToAdd = (divd(muld(qtAstRAfter, _qtAstW), price) - _bsAstR) | |
1059 | 1093 | let bsAstRAfter = (_bsAstR + baseAssetAmountToAdd) | |
1060 | - | let $ | |
1061 | - | let newQuoteAssetWeight = $ | |
1062 | - | let newBaseAssetWeight = $ | |
1063 | - | let marginToVault = $ | |
1094 | + | let $t05325653407 = getSyncTerminalPrice(getOraclePrice(), qtAstRAfter, bsAstRAfter) | |
1095 | + | let newQuoteAssetWeight = $t05325653407._1 | |
1096 | + | let newBaseAssetWeight = $t05325653407._2 | |
1097 | + | let marginToVault = $t05325653407._3 | |
1064 | 1098 | let doExchangePnL = if ((marginToVault != 0)) | |
1065 | 1099 | then { | |
1066 | 1100 | let doExchangePnL = invoke(vaultAddress(), "exchangeFreeAndLocked", [marginToVault], nil) | |
1090 | 1124 | let qtAstRAfter = (_qtAstR - _quoteAssetAmount) | |
1091 | 1125 | let baseAssetAmountToRemove = abs((divd(muld(qtAstRAfter, _qtAstW), price) - _bsAstR)) | |
1092 | 1126 | let bsAstRAfter = (_bsAstR - baseAssetAmountToRemove) | |
1093 | - | let $ | |
1094 | - | let newQuoteAssetWeight = $ | |
1095 | - | let newBaseAssetWeight = $ | |
1096 | - | let marginToVault = $ | |
1127 | + | let $t05433954490 = getSyncTerminalPrice(getOraclePrice(), qtAstRAfter, bsAstRAfter) | |
1128 | + | let newQuoteAssetWeight = $t05433954490._1 | |
1129 | + | let newBaseAssetWeight = $t05433954490._2 | |
1130 | + | let marginToVault = $t05433954490._3 | |
1097 | 1131 | let doExchangePnL = if ((marginToVault != 0)) | |
1098 | 1132 | then { | |
1099 | 1133 | let doExchangePnL = invoke(vaultAddress(), "exchangeFreeAndLocked", [marginToVault], nil) | |
1110 | 1144 | ||
1111 | 1145 | ||
1112 | 1146 | @Callable(i) | |
1113 | - | func changeSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional,_feeToStakersPercent,_maxOracleDelay) = if ((i.caller != adminAddress())) | |
1147 | + | func changeSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional,_feeToStakersPercent,_maxOracleDelay,_rolloverFee) = if ((i.caller != adminAddress())) | |
1114 | 1148 | then throw("Invalid changeSettings params") | |
1115 | - | else updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread, _maxOpenNotional, _feeToStakersPercent, _maxOracleDelay) | |
1149 | + | else updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread, _maxOpenNotional, _feeToStakersPercent, _maxOracleDelay, _rolloverFee) | |
1116 | 1150 | ||
1117 | 1151 | ||
1118 | 1152 | ||
1119 | 1153 | @Callable(i) | |
1120 | - | func initialize (_qtAstR,_bsAstR,_fundingPeriod,_initMarginRatio,_mmr,_liquidationFeeRatio,_fee,_ | |
1154 | + | func initialize (_qtAstR,_bsAstR,_fundingPeriod,_initMarginRatio,_mmr,_liquidationFeeRatio,_fee,_baseOracleData,_quoteOracleData,_coordinator,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional,_feeToStakersPercent,_maxOracleDelay,_rolloverFee) = if (if (if (if (if (if (if (if (if (if (if (if (if (if (if (if (if ((0 >= _qtAstR)) | |
1121 | 1155 | then true | |
1122 | 1156 | else (0 >= _bsAstR)) | |
1123 | 1157 | then true | |
1147 | 1181 | then true | |
1148 | 1182 | else (0 >= _maxOracleDelay)) | |
1149 | 1183 | then true | |
1184 | + | else (0 >= _rolloverFee)) | |
1185 | + | then true | |
1150 | 1186 | else initialized()) | |
1151 | 1187 | then throw("Invalid initialize parameters") | |
1152 | - | else ((((updateAmm(_qtAstR, _bsAstR, 0, 0, 0, 0, 0, 0) ++ updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread, _maxOpenNotional, _feeToStakersPercent, _maxOracleDelay)) ++ updateFunding(( | |
1188 | + | else ((((updateAmm(_qtAstR, _bsAstR, 0, 0, 0, 0, 0, 0) ++ updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread, _maxOpenNotional, _feeToStakersPercent, _maxOracleDelay, _rolloverFee)) ++ updateFunding((lastTimestamp() + _fundingPeriod), 0, 0, 0, 0)) ++ updateBalance(0)) ++ [BooleanEntry(k_initialized, true), StringEntry(k_baseOracle, _baseOracleData), StringEntry(k_quoteOracle, _quoteOracleData), StringEntry(k_coordinatorAddress, _coordinator)]) | |
1153 | 1189 | ||
1154 | 1190 | ||
1155 | 1191 | ||
1158 | 1194 | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1159 | 1195 | if ((sync == sync)) | |
1160 | 1196 | then { | |
1161 | - | let _trader = getActualCaller(i) | |
1162 | - | let _rawAmount = i.payments[0].amount | |
1163 | - | let _assetId = i.payments[0].assetId | |
1164 | - | let _assetIdStr = toBase58String(value(_assetId)) | |
1165 | - | let isQuoteAsset = (_assetId == quoteAsset()) | |
1166 | - | let isCollateralAsset = isWhitelistAsset(_assetIdStr) | |
1167 | - | if (if (if (if (if (if (if (if (if (if ((_direction != DIR_LONG)) | |
1168 | - | then (_direction != DIR_SHORT) | |
1169 | - | else false) | |
1170 | - | then true | |
1171 | - | else (0 >= _rawAmount)) | |
1172 | - | then true | |
1173 | - | else !(initialized())) | |
1174 | - | then true | |
1175 | - | else if (!(isQuoteAsset)) | |
1176 | - | then !(isCollateralAsset) | |
1177 | - | else false) | |
1178 | - | then true | |
1179 | - | else !(isSameAssetOrNoPosition(_trader, _assetIdStr))) | |
1180 | - | then true | |
1181 | - | else !(requireMoreMarginRatio(divd(DECIMAL_UNIT, _leverage), initMarginRatio(), true))) | |
1182 | - | then true | |
1183 | - | else paused()) | |
1184 | - | then true | |
1185 | - | else closeOnly()) | |
1186 | - | then true | |
1187 | - | else isMarketClosed()) | |
1188 | - | then throw("Invalid increasePosition parameters") | |
1189 | - | else { | |
1190 | - | let $t05100951158 = getForTraderWithArtifact(_trader, getArtifactId(i)) | |
1191 | - | let adjustedFee = $t05100951158._1 | |
1192 | - | let burnArtifact = $t05100951158._2 | |
1193 | - | let _amount = divd(_rawAmount, (muld(adjustedFee, _leverage) + DECIMAL_UNIT)) | |
1194 | - | let rawFeeAmount = (_rawAmount - _amount) | |
1195 | - | let distributeFeeAmount = if (isCollateralAsset) | |
1196 | - | then { | |
1197 | - | let doBorrow = invoke(collateralAddress(), "borrow", [_trader], [AttachedPayment(_assetId, _amount)]) | |
1198 | - | if ((doBorrow == doBorrow)) | |
1199 | - | then { | |
1200 | - | let balanceBefore = assetBalance(this, quoteAsset()) | |
1201 | - | if ((balanceBefore == balanceBefore)) | |
1202 | - | then { | |
1203 | - | let doSwap = invoke(swapAddress(), "swap", [toBase58String(quoteAsset()), 0], [AttachedPayment(_assetId, rawFeeAmount)]) | |
1204 | - | if ((doSwap == doSwap)) | |
1205 | - | then { | |
1206 | - | let balanceAfter = assetBalance(this, quoteAsset()) | |
1207 | - | if ((balanceAfter == balanceAfter)) | |
1208 | - | then { | |
1209 | - | let exchangedAmount = (balanceAfter - balanceBefore) | |
1210 | - | if ((exchangedAmount == exchangedAmount)) | |
1211 | - | then exchangedAmount | |
1212 | - | else throw("Strict value is not equal to itself.") | |
1213 | - | } | |
1214 | - | else throw("Strict value is not equal to itself.") | |
1215 | - | } | |
1216 | - | else throw("Strict value is not equal to itself.") | |
1217 | - | } | |
1218 | - | else throw("Strict value is not equal to itself.") | |
1219 | - | } | |
1220 | - | else throw("Strict value is not equal to itself.") | |
1221 | - | } | |
1222 | - | else rawFeeAmount | |
1223 | - | if ((distributeFeeAmount == distributeFeeAmount)) | |
1224 | - | then { | |
1197 | + | let ensureCalledOnce = invoke(this, "ensureCalledOnce", nil, nil) | |
1198 | + | if ((ensureCalledOnce == ensureCalledOnce)) | |
1199 | + | then { | |
1200 | + | let _trader = getActualCaller(i) | |
1201 | + | let _rawAmount = i.payments[0].amount | |
1202 | + | let _assetId = i.payments[0].assetId | |
1203 | + | let _assetIdStr = toBase58String(value(_assetId)) | |
1204 | + | let isQuoteAsset = (_assetId == quoteAsset()) | |
1205 | + | if (if (if (if (if (if (if (if (if (if ((_direction != DIR_LONG)) | |
1206 | + | then (_direction != DIR_SHORT) | |
1207 | + | else false) | |
1208 | + | then true | |
1209 | + | else (0 >= _rawAmount)) | |
1210 | + | then true | |
1211 | + | else !(initialized())) | |
1212 | + | then true | |
1213 | + | else !(isQuoteAsset)) | |
1214 | + | then true | |
1215 | + | else !(isSameAssetOrNoPosition(_trader, _assetIdStr))) | |
1216 | + | then true | |
1217 | + | else !(requireMoreMarginRatio(divd(DECIMAL_UNIT, _leverage), initMarginRatio(), true))) | |
1218 | + | then true | |
1219 | + | else paused()) | |
1220 | + | then true | |
1221 | + | else closeOnly()) | |
1222 | + | then true | |
1223 | + | else isMarketClosed()) | |
1224 | + | then throw("Invalid increasePosition parameters") | |
1225 | + | else { | |
1226 | + | let $t05820958358 = getForTraderWithArtifact(_trader, getArtifactId(i)) | |
1227 | + | let adjustedFee = $t05820958358._1 | |
1228 | + | let burnArtifact = $t05820958358._2 | |
1229 | + | let _amount = divd(_rawAmount, (muld(adjustedFee, _leverage) + DECIMAL_UNIT)) | |
1230 | + | let distributeFeeAmount = (_rawAmount - _amount) | |
1225 | 1231 | let referrerFeeAny = invoke(referralAddress(), "acceptPaymentWithLink", [_trader, _refLink], [AttachedPayment(quoteAsset(), distributeFeeAmount)]) | |
1226 | 1232 | if ((referrerFeeAny == referrerFeeAny)) | |
1227 | 1233 | then { | |
1232 | 1238 | throw("Invalid referrerFee") | |
1233 | 1239 | } | |
1234 | 1240 | let feeAmount = (distributeFeeAmount - referrerFee) | |
1235 | - | let $t05250052640 = getPosition(_trader) | |
1236 | - | let oldPositionSize = $t05250052640._1 | |
1237 | - | let oldPositionMargin = $t05250052640._2 | |
1238 | - | let oldPositionOpenNotional = $t05250052640._3 | |
1239 | - | let oldPositionLstUpdCPF = $t05250052640._4 | |
1241 | + | let $t05885459022 = getPosition(_trader) | |
1242 | + | let oldPositionSize = $t05885459022._1 | |
1243 | + | let oldPositionMargin = $t05885459022._2 | |
1244 | + | let oldPositionOpenNotional = $t05885459022._3 | |
1245 | + | let oldPositionLstUpdCPF = $t05885459022._4 | |
1246 | + | let oldPositionTimestamp = $t05885459022._5 | |
1240 | 1247 | let isNewPosition = (oldPositionSize == 0) | |
1241 | 1248 | let isSameDirection = if ((oldPositionSize > 0)) | |
1242 | 1249 | then (_direction == DIR_LONG) | |
1245 | 1252 | then isSameDirection | |
1246 | 1253 | else false | |
1247 | 1254 | let isAdd = (_direction == DIR_LONG) | |
1248 | - | let $ | |
1255 | + | let $t05931162432 = if (if (isNewPosition) | |
1249 | 1256 | then true | |
1250 | 1257 | else expandExisting) | |
1251 | 1258 | then { | |
1252 | 1259 | let openNotional = muld(_amount, _leverage) | |
1253 | - | let $ | |
1254 | - | let amountBaseAssetBought = $ | |
1255 | - | let quoteAssetReserveAfter = $ | |
1256 | - | let baseAssetReserveAfter = $ | |
1257 | - | let totalPositionSizeAfter = $ | |
1260 | + | let $t05982059993 = swapInput(isAdd, openNotional) | |
1261 | + | let amountBaseAssetBought = $t05982059993._1 | |
1262 | + | let quoteAssetReserveAfter = $t05982059993._2 | |
1263 | + | let baseAssetReserveAfter = $t05982059993._3 | |
1264 | + | let totalPositionSizeAfter = $t05982059993._4 | |
1258 | 1265 | if (if ((_minBaseAssetAmount != 0)) | |
1259 | 1266 | then (_minBaseAssetAmount > abs(amountBaseAssetBought)) | |
1260 | 1267 | else false) | |
1267 | 1274 | let totalShortOpenInterestAfter = (openInterestShort() + (if ((0 > newPositionSize)) | |
1268 | 1275 | then openNotional | |
1269 | 1276 | else 0)) | |
1270 | - | let $t05411054331 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, _amount) | |
1271 | - | let remainMargin = $t05411054331._1 | |
1272 | - | let x1 = $t05411054331._2 | |
1273 | - | let x2 = $t05411054331._3 | |
1277 | + | let $t06053960814 = calcRemainMarginWithFundingPaymentAndRolloverFee(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, oldPositionTimestamp, _amount) | |
1278 | + | let remainMargin = $t06053960814._1 | |
1279 | + | let x1 = $t06053960814._2 | |
1280 | + | let x2 = $t06053960814._3 | |
1281 | + | let rolloverFee = $t06053960814._4 | |
1274 | 1282 | if (!(requireNotOverSpreadLimit(quoteAssetReserveAfter, baseAssetReserveAfter))) | |
1275 | 1283 | then throw("Over max spread limit") | |
1276 | 1284 | else if (!(requireNotOverMaxOpenNotional(totalLongOpenInterestAfter, totalShortOpenInterestAfter))) | |
1277 | 1285 | then throw("Over max open notional") | |
1278 | - | else $ | |
1286 | + | else $Tuple14(newPositionSize, remainMargin, (oldPositionOpenNotional + openNotional), latestCumulativePremiumFraction(newPositionSize), lastTimestamp(), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, (openInterestNotional() + openNotional), (totalLongPositionSize() + (if ((newPositionSize > 0)) | |
1279 | 1287 | then abs(amountBaseAssetBought) | |
1280 | 1288 | else 0)), (totalShortPositionSize() + (if ((0 > newPositionSize)) | |
1281 | 1289 | then abs(amountBaseAssetBought) | |
1282 | - | else 0)), totalLongOpenInterestAfter, totalShortOpenInterestAfter) | |
1290 | + | else 0)), totalLongOpenInterestAfter, totalShortOpenInterestAfter, rolloverFee) | |
1283 | 1291 | } | |
1284 | 1292 | } | |
1285 | 1293 | else { | |
1286 | 1294 | let openNotional = muld(_amount, _leverage) | |
1287 | - | let $ | |
1288 | - | let oldPositionNotional = $ | |
1289 | - | let unrealizedPnl = $ | |
1295 | + | let $t06213262248 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT) | |
1296 | + | let oldPositionNotional = $t06213262248._1 | |
1297 | + | let unrealizedPnl = $t06213262248._2 | |
1290 | 1298 | if ((oldPositionNotional > openNotional)) | |
1291 | 1299 | then throw("Use decreasePosition to decrease position size") | |
1292 | 1300 | else throw("Close position first") | |
1293 | 1301 | } | |
1294 | - | let newPositionSize = $t05292955891._1 | |
1295 | - | let newPositionRemainMargin = $t05292955891._2 | |
1296 | - | let newPositionOpenNotional = $t05292955891._3 | |
1297 | - | let newPositionLatestCPF = $t05292955891._4 | |
1298 | - | let baseAssetReserveAfter = $t05292955891._5 | |
1299 | - | let quoteAssetReserveAfter = $t05292955891._6 | |
1300 | - | let totalPositionSizeAfter = $t05292955891._7 | |
1301 | - | let openInterestNotionalAfter = $t05292955891._8 | |
1302 | - | let totalLongAfter = $t05292955891._9 | |
1303 | - | let totalShortAfter = $t05292955891._10 | |
1304 | - | let totalLongOpenInterestAfter = $t05292955891._11 | |
1305 | - | let totalShortOpenInterestAfter = $t05292955891._12 | |
1306 | - | let $t05589755954 = distributeFee(feeAmount) | |
1307 | - | let feeToStakers = $t05589755954._1 | |
1308 | - | let feeToVault = $t05589755954._2 | |
1309 | - | let stake = if (isQuoteAsset) | |
1310 | - | then { | |
1311 | - | let stake = invoke(vaultAddress(), "addLocked", [false], [AttachedPayment(quoteAsset(), _amount)]) | |
1312 | - | if ((stake == stake)) | |
1313 | - | then nil | |
1314 | - | else throw("Strict value is not equal to itself.") | |
1315 | - | } | |
1316 | - | else nil | |
1302 | + | let newPositionSize = $t05931162432._1 | |
1303 | + | let newPositionRemainMargin = $t05931162432._2 | |
1304 | + | let newPositionOpenNotional = $t05931162432._3 | |
1305 | + | let newPositionLatestCPF = $t05931162432._4 | |
1306 | + | let newPositionTimestamp = $t05931162432._5 | |
1307 | + | let baseAssetReserveAfter = $t05931162432._6 | |
1308 | + | let quoteAssetReserveAfter = $t05931162432._7 | |
1309 | + | let totalPositionSizeAfter = $t05931162432._8 | |
1310 | + | let openInterestNotionalAfter = $t05931162432._9 | |
1311 | + | let totalLongAfter = $t05931162432._10 | |
1312 | + | let totalShortAfter = $t05931162432._11 | |
1313 | + | let totalLongOpenInterestAfter = $t05931162432._12 | |
1314 | + | let totalShortOpenInterestAfter = $t05931162432._13 | |
1315 | + | let rolloverFee = $t05931162432._14 | |
1316 | + | let $t06243862509 = distributeFee((feeAmount + rolloverFee)) | |
1317 | + | let feeToStakers = $t06243862509._1 | |
1318 | + | let feeToVault = $t06243862509._2 | |
1319 | + | let stake = if ((_amount >= rolloverFee)) | |
1320 | + | then invoke(vaultAddress(), "addLocked", nil, [AttachedPayment(quoteAsset(), (_amount - rolloverFee))]) | |
1321 | + | else invoke(vaultAddress(), "withdrawLocked", [(rolloverFee - _amount)], nil) | |
1317 | 1322 | if ((stake == stake)) | |
1318 | 1323 | then { | |
1319 | 1324 | let depositVault = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToVault)]) | |
1324 | 1329 | then { | |
1325 | 1330 | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil) | |
1326 | 1331 | if ((notifyNotional == notifyNotional)) | |
1327 | - | then (((((( | |
1332 | + | then ((((((updatePosition(_trader, newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF, newPositionTimestamp) ++ incrementPositionSequenceNumber(isNewPosition, _trader)) ++ updatePositionFee(isNewPosition, _trader, adjustedFee)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ transferFee(feeToStakers)) ++ updateBalance(((cbalance() + _amount) - rolloverFee))) ++ doBurnArtifact(burnArtifact, i)) | |
1328 | 1333 | else throw("Strict value is not equal to itself.") | |
1329 | 1334 | } | |
1330 | 1335 | else throw("Strict value is not equal to itself.") | |
1331 | 1336 | } | |
1337 | + | else throw("Strict value is not equal to itself.") | |
1338 | + | } | |
1339 | + | else throw("Strict value is not equal to itself.") | |
1340 | + | } | |
1341 | + | else throw("Strict value is not equal to itself.") | |
1342 | + | } | |
1343 | + | } | |
1344 | + | else throw("Strict value is not equal to itself.") | |
1345 | + | } | |
1346 | + | else throw("Strict value is not equal to itself.") | |
1347 | + | } | |
1348 | + | ||
1349 | + | ||
1350 | + | ||
1351 | + | @Callable(i) | |
1352 | + | func addMargin () = { | |
1353 | + | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1354 | + | if ((sync == sync)) | |
1355 | + | then { | |
1356 | + | let ensureCalledOnce = invoke(this, "ensureCalledOnce", nil, nil) | |
1357 | + | if ((ensureCalledOnce == ensureCalledOnce)) | |
1358 | + | then { | |
1359 | + | let _trader = toString(i.caller) | |
1360 | + | let _amount = i.payments[0].amount | |
1361 | + | let _assetId = i.payments[0].assetId | |
1362 | + | let _assetIdStr = toBase58String(value(_assetId)) | |
1363 | + | let isQuoteAsset = (_assetId == quoteAsset()) | |
1364 | + | if (if (if (if (if (if (if (!(isQuoteAsset)) | |
1365 | + | then true | |
1366 | + | else !(requireOpenPosition(toString(i.caller)))) | |
1367 | + | then true | |
1368 | + | else !(isSameAsset(_trader, _assetIdStr))) | |
1369 | + | then true | |
1370 | + | else !(initialized())) | |
1371 | + | then true | |
1372 | + | else paused()) | |
1373 | + | then true | |
1374 | + | else closeOnly()) | |
1375 | + | then true | |
1376 | + | else isMarketClosed()) | |
1377 | + | then throw("Invalid addMargin parameters") | |
1378 | + | else { | |
1379 | + | let $t06462064788 = getPosition(_trader) | |
1380 | + | let oldPositionSize = $t06462064788._1 | |
1381 | + | let oldPositionMargin = $t06462064788._2 | |
1382 | + | let oldPositionOpenNotional = $t06462064788._3 | |
1383 | + | let oldPositionLstUpdCPF = $t06462064788._4 | |
1384 | + | let oldPositionTimestamp = $t06462064788._5 | |
1385 | + | let stake = invoke(vaultAddress(), "addLocked", nil, [AttachedPayment(quoteAsset(), _amount)]) | |
1386 | + | if ((stake == stake)) | |
1387 | + | then { | |
1388 | + | let rolloverFee = calcRolloverFee(oldPositionMargin, oldPositionTimestamp) | |
1389 | + | let doTransferFeeToStakers = if ((rolloverFee > 0)) | |
1390 | + | then { | |
1391 | + | let $t06507365132 = distributeFee(rolloverFee) | |
1392 | + | let feeToStakers = $t06507365132._1 | |
1393 | + | let feeToVault = $t06507365132._2 | |
1394 | + | let unstake = invoke(vaultAddress(), "withdrawLocked", [feeToStakers], nil) | |
1395 | + | if ((unstake == unstake)) | |
1396 | + | then { | |
1397 | + | let lockBadDebt = invoke(vaultAddress(), "exchangeFreeAndLocked", [-(feeToVault)], nil) | |
1398 | + | if ((lockBadDebt == lockBadDebt)) | |
1399 | + | then transferFee(feeToStakers) | |
1400 | + | else throw("Strict value is not equal to itself.") | |
1401 | + | } | |
1402 | + | else throw("Strict value is not equal to itself.") | |
1403 | + | } | |
1404 | + | else nil | |
1405 | + | if ((doTransferFeeToStakers == doTransferFeeToStakers)) | |
1406 | + | then ((updatePosition(_trader, oldPositionSize, ((oldPositionMargin - rolloverFee) + _amount), oldPositionOpenNotional, oldPositionLstUpdCPF, lastTimestamp()) ++ updateBalance(((cbalance() + _amount) - rolloverFee))) ++ doTransferFeeToStakers) | |
1407 | + | else throw("Strict value is not equal to itself.") | |
1408 | + | } | |
1409 | + | else throw("Strict value is not equal to itself.") | |
1410 | + | } | |
1411 | + | } | |
1412 | + | else throw("Strict value is not equal to itself.") | |
1413 | + | } | |
1414 | + | else throw("Strict value is not equal to itself.") | |
1415 | + | } | |
1416 | + | ||
1417 | + | ||
1418 | + | ||
1419 | + | @Callable(i) | |
1420 | + | func removeMargin (_amount) = { | |
1421 | + | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1422 | + | if ((sync == sync)) | |
1423 | + | then { | |
1424 | + | let ensureCalledOnce = invoke(this, "ensureCalledOnce", nil, nil) | |
1425 | + | if ((ensureCalledOnce == ensureCalledOnce)) | |
1426 | + | then { | |
1427 | + | let _trader = toString(i.caller) | |
1428 | + | if (if (if (if (if ((0 >= _amount)) | |
1429 | + | then true | |
1430 | + | else !(requireOpenPosition(_trader))) | |
1431 | + | then true | |
1432 | + | else !(initialized())) | |
1433 | + | then true | |
1434 | + | else paused()) | |
1435 | + | then true | |
1436 | + | else isMarketClosed()) | |
1437 | + | then throw("Invalid removeMargin parameters") | |
1438 | + | else { | |
1439 | + | let $t06624466412 = getPosition(_trader) | |
1440 | + | let oldPositionSize = $t06624466412._1 | |
1441 | + | let oldPositionMargin = $t06624466412._2 | |
1442 | + | let oldPositionOpenNotional = $t06624466412._3 | |
1443 | + | let oldPositionLstUpdCPF = $t06624466412._4 | |
1444 | + | let oldPositionTimestamp = $t06624466412._5 | |
1445 | + | let $t06641866667 = calcRemainMarginWithFundingPaymentAndRolloverFee(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, oldPositionTimestamp, -(_amount)) | |
1446 | + | let remainMargin = $t06641866667._1 | |
1447 | + | let badDebt = $t06641866667._2 | |
1448 | + | let fundingPayment = $t06641866667._3 | |
1449 | + | let rolloverFee = $t06641866667._4 | |
1450 | + | if ((badDebt != 0)) | |
1451 | + | then throw("Invalid removed margin amount") | |
1452 | + | else { | |
1453 | + | let marginRatio = calcMarginRatio(remainMargin, badDebt, oldPositionOpenNotional) | |
1454 | + | if (!(requireMoreMarginRatio(marginRatio, initMarginRatio(), true))) | |
1455 | + | then throw(((("Too much margin removed: " + toString(marginRatio)) + " < ") + toString(initMarginRatio()))) | |
1456 | + | else { | |
1457 | + | let $t06705367112 = distributeFee(rolloverFee) | |
1458 | + | let feeToStakers = $t06705367112._1 | |
1459 | + | let feeToVault = $t06705367112._2 | |
1460 | + | let doTransferFeeToStakers = if ((rolloverFee > 0)) | |
1461 | + | then { | |
1462 | + | let lockBadDebt = invoke(vaultAddress(), "exchangeFreeAndLocked", [-(feeToVault)], nil) | |
1463 | + | if ((lockBadDebt == lockBadDebt)) | |
1464 | + | then transferFee(feeToStakers) | |
1465 | + | else throw("Strict value is not equal to itself.") | |
1466 | + | } | |
1467 | + | else nil | |
1468 | + | if ((doTransferFeeToStakers == doTransferFeeToStakers)) | |
1469 | + | then { | |
1470 | + | let unstake = invoke(vaultAddress(), "withdrawLocked", [(_amount + feeToStakers)], nil) | |
1471 | + | if ((unstake == unstake)) | |
1472 | + | then (((updatePosition(_trader, oldPositionSize, remainMargin, oldPositionOpenNotional, latestCumulativePremiumFraction(oldPositionSize), lastTimestamp()) ++ withdraw(i.caller, _amount)) ++ updateBalance(((cbalance() - _amount) - rolloverFee))) ++ doTransferFeeToStakers) | |
1473 | + | else throw("Strict value is not equal to itself.") | |
1474 | + | } | |
1475 | + | else throw("Strict value is not equal to itself.") | |
1476 | + | } | |
1477 | + | } | |
1478 | + | } | |
1479 | + | } | |
1480 | + | else throw("Strict value is not equal to itself.") | |
1481 | + | } | |
1482 | + | else throw("Strict value is not equal to itself.") | |
1483 | + | } | |
1484 | + | ||
1485 | + | ||
1486 | + | ||
1487 | + | @Callable(i) | |
1488 | + | func closePosition (_size,_minQuoteAssetAmount,_addToMargin) = { | |
1489 | + | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1490 | + | if ((sync == sync)) | |
1491 | + | then { | |
1492 | + | let ensureCalledOnce = invoke(this, "ensureCalledOnce", nil, nil) | |
1493 | + | if ((ensureCalledOnce == ensureCalledOnce)) | |
1494 | + | then { | |
1495 | + | let _trader = getActualCaller(i) | |
1496 | + | let _traderAddress = valueOrErrorMessage(addressFromString(_trader), "Invalid caller") | |
1497 | + | let positionFee = getPositionFee(_trader) | |
1498 | + | if (if (if (if (if (if (!(requireOpenPosition(_trader))) | |
1499 | + | then true | |
1500 | + | else !(initialized())) | |
1501 | + | then true | |
1502 | + | else paused()) | |
1503 | + | then true | |
1504 | + | else (0 >= _size)) | |
1505 | + | then true | |
1506 | + | else (0 > _minQuoteAssetAmount)) | |
1507 | + | then true | |
1508 | + | else isMarketClosed()) | |
1509 | + | then throw("Invalid closePosition parameters") | |
1510 | + | else { | |
1511 | + | let oldPositionTimestamp = getPosition(_trader)._5 | |
1512 | + | let $t06876969342 = internalClosePosition(_trader, _size, positionFee, _minQuoteAssetAmount, _addToMargin, true) | |
1513 | + | let newPositionSize = $t06876969342._1 | |
1514 | + | let newPositionMargin = $t06876969342._2 | |
1515 | + | let newPositionOpenNotional = $t06876969342._3 | |
1516 | + | let newPositionLstUpdCPF = $t06876969342._4 | |
1517 | + | let positionBadDebt = $t06876969342._5 | |
1518 | + | let realizedPnl = $t06876969342._6 | |
1519 | + | let marginToTrader = $t06876969342._7 | |
1520 | + | let quoteAssetReserveAfter = $t06876969342._8 | |
1521 | + | let baseAssetReserveAfter = $t06876969342._9 | |
1522 | + | let totalPositionSizeAfter = $t06876969342._10 | |
1523 | + | let openInterestNotionalAfter = $t06876969342._11 | |
1524 | + | let totalLongAfter = $t06876969342._12 | |
1525 | + | let totalShortAfter = $t06876969342._13 | |
1526 | + | let totalLongOpenInterestAfter = $t06876969342._14 | |
1527 | + | let totalShortOpenInterestAfter = $t06876969342._15 | |
1528 | + | let realizedFee = $t06876969342._16 | |
1529 | + | if ((positionBadDebt > 0)) | |
1530 | + | then throw("Invalid closePosition parameters: bad debt") | |
1531 | + | else if ((oldPositionTimestamp >= lastTimestamp())) | |
1532 | + | then throw("Invalid closePosition parameters: wait at least 1 block before closing the position") | |
1533 | + | else { | |
1534 | + | let isPartialClose = (newPositionSize != 0) | |
1535 | + | let withdrawAmount = (marginToTrader + realizedFee) | |
1536 | + | let ammBalance = (cbalance() - withdrawAmount) | |
1537 | + | let ammNewBalance = if ((0 > ammBalance)) | |
1538 | + | then 0 | |
1539 | + | else ammBalance | |
1540 | + | let unstake = invoke(vaultAddress(), "withdrawLocked", [withdrawAmount], nil) | |
1541 | + | if ((unstake == unstake)) | |
1542 | + | then { | |
1543 | + | let $t07001470073 = distributeFee(realizedFee) | |
1544 | + | let feeToStakers = $t07001470073._1 | |
1545 | + | let feeToVault = $t07001470073._2 | |
1546 | + | let depositVault = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToVault)]) | |
1547 | + | if ((depositVault == depositVault)) | |
1548 | + | then { | |
1549 | + | let notifyFee = invoke(minerAddress(), "notifyFees", [_trader, realizedFee], nil) | |
1550 | + | if ((notifyFee == notifyFee)) | |
1551 | + | then { | |
1552 | + | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil) | |
1553 | + | if ((notifyNotional == notifyNotional)) | |
1554 | + | then (((((if (isPartialClose) | |
1555 | + | then updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF, lastTimestamp()) | |
1556 | + | else deletePosition(_trader)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ (if ((marginToTrader > 0)) | |
1557 | + | then withdraw(_traderAddress, marginToTrader) | |
1558 | + | else nil)) ++ updateBalance(ammNewBalance)) ++ transferFee(feeToStakers)) | |
1559 | + | else throw("Strict value is not equal to itself.") | |
1560 | + | } | |
1561 | + | else throw("Strict value is not equal to itself.") | |
1562 | + | } | |
1563 | + | else throw("Strict value is not equal to itself.") | |
1564 | + | } | |
1565 | + | else throw("Strict value is not equal to itself.") | |
1566 | + | } | |
1567 | + | } | |
1568 | + | } | |
1569 | + | else throw("Strict value is not equal to itself.") | |
1570 | + | } | |
1571 | + | else throw("Strict value is not equal to itself.") | |
1572 | + | } | |
1573 | + | ||
1574 | + | ||
1575 | + | ||
1576 | + | @Callable(i) | |
1577 | + | func liquidate (_trader) = { | |
1578 | + | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1579 | + | if ((sync == sync)) | |
1580 | + | then { | |
1581 | + | let spotMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_SPOT) | |
1582 | + | let liquidationMarginRatio = if (isOverFluctuationLimit()) | |
1583 | + | then { | |
1584 | + | let oracleMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_ORACLE) | |
1585 | + | vmax(spotMarginRatio, oracleMarginRatio) | |
1586 | + | } | |
1587 | + | else spotMarginRatio | |
1588 | + | if (if (if (if (if (!(requireMoreMarginRatio(liquidationMarginRatio, maintenanceMarginRatio(), false))) | |
1589 | + | then true | |
1590 | + | else !(requireOpenPosition(_trader))) | |
1591 | + | then true | |
1592 | + | else !(initialized())) | |
1593 | + | then true | |
1594 | + | else paused()) | |
1595 | + | then true | |
1596 | + | else isMarketClosed()) | |
1597 | + | then throw("Unable to liquidate") | |
1598 | + | else { | |
1599 | + | let isPartialLiquidation = if (if ((spotMarginRatio > liquidationFeeRatio())) | |
1600 | + | then true | |
1601 | + | else (partialLiquidationRatio() > 0)) | |
1602 | + | then true | |
1603 | + | else (DECIMAL_UNIT > partialLiquidationRatio()) | |
1604 | + | let oldPositionSize = getPosition(_trader)._1 | |
1605 | + | let positionSizeAbs = abs(oldPositionSize) | |
1606 | + | let $t07238672709 = if (isPartialLiquidation) | |
1607 | + | then { | |
1608 | + | let liquidationSize = getPartialLiquidationAmount(_trader, oldPositionSize) | |
1609 | + | let liquidationRatio = divd(abs(liquidationSize), positionSizeAbs) | |
1610 | + | $Tuple2(liquidationRatio, abs(liquidationSize)) | |
1611 | + | } | |
1612 | + | else $Tuple2(0, positionSizeAbs) | |
1613 | + | let liquidationRatio = $t07238672709._1 | |
1614 | + | let liquidationSize = $t07238672709._2 | |
1615 | + | let $t07271573341 = internalClosePosition(_trader, if (isPartialLiquidation) | |
1616 | + | then liquidationSize | |
1617 | + | else positionSizeAbs, liquidationFeeRatio(), 0, true, false) | |
1618 | + | let newPositionSize = $t07271573341._1 | |
1619 | + | let newPositionMargin = $t07271573341._2 | |
1620 | + | let newPositionOpenNotional = $t07271573341._3 | |
1621 | + | let newPositionLstUpdCPF = $t07271573341._4 | |
1622 | + | let positionBadDebt = $t07271573341._5 | |
1623 | + | let realizedPnl = $t07271573341._6 | |
1624 | + | let marginToTrader = $t07271573341._7 | |
1625 | + | let quoteAssetReserveAfter = $t07271573341._8 | |
1626 | + | let baseAssetReserveAfter = $t07271573341._9 | |
1627 | + | let totalPositionSizeAfter = $t07271573341._10 | |
1628 | + | let openInterestNotionalAfter = $t07271573341._11 | |
1629 | + | let totalLongAfter = $t07271573341._12 | |
1630 | + | let totalShortAfter = $t07271573341._13 | |
1631 | + | let totalLongOpenInterestAfter = $t07271573341._14 | |
1632 | + | let totalShortOpenInterestAfter = $t07271573341._15 | |
1633 | + | let liquidationPenalty = $t07271573341._16 | |
1634 | + | let feeToLiquidator = (liquidationPenalty / 2) | |
1635 | + | let feeToVault = (liquidationPenalty - feeToLiquidator) | |
1636 | + | let ammBalance = (cbalance() - liquidationPenalty) | |
1637 | + | let newAmmBalance = if ((0 > ammBalance)) | |
1638 | + | then 0 | |
1639 | + | else ammBalance | |
1640 | + | let lockBadDebt = if ((positionBadDebt > 0)) | |
1641 | + | then { | |
1642 | + | let lockBadDebt = invoke(vaultAddress(), "exchangeFreeAndLocked", [positionBadDebt], nil) | |
1643 | + | if ((lockBadDebt == lockBadDebt)) | |
1644 | + | then nil | |
1645 | + | else throw("Strict value is not equal to itself.") | |
1646 | + | } | |
1647 | + | else nil | |
1648 | + | if ((lockBadDebt == lockBadDebt)) | |
1649 | + | then { | |
1650 | + | let unstake = invoke(vaultAddress(), "withdrawLocked", [liquidationPenalty], nil) | |
1651 | + | if ((unstake == unstake)) | |
1652 | + | then { | |
1653 | + | let depositInsurance = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToVault)]) | |
1654 | + | if ((depositInsurance == depositInsurance)) | |
1655 | + | then { | |
1656 | + | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil) | |
1657 | + | if ((notifyNotional == notifyNotional)) | |
1658 | + | then ((((if (isPartialLiquidation) | |
1659 | + | then updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF, lastTimestamp()) | |
1660 | + | else deletePosition(_trader)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance)) | |
1332 | 1661 | else throw("Strict value is not equal to itself.") | |
1333 | 1662 | } | |
1334 | 1663 | else throw("Strict value is not equal to itself.") | |
1344 | 1673 | ||
1345 | 1674 | ||
1346 | 1675 | @Callable(i) | |
1347 | - | func addMargin () = { | |
1348 | - | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1349 | - | if ((sync == sync)) | |
1350 | - | then { | |
1351 | - | let _trader = toString(i.caller) | |
1352 | - | let _amount = i.payments[0].amount | |
1353 | - | let _assetId = i.payments[0].assetId | |
1354 | - | let _assetIdStr = toBase58String(value(_assetId)) | |
1355 | - | let isQuoteAsset = (_assetId == quoteAsset()) | |
1356 | - | let isCollateralAsset = isWhitelistAsset(_assetIdStr) | |
1357 | - | if (if (if (if (if (if (if (if (!(isQuoteAsset)) | |
1358 | - | then !(isCollateralAsset) | |
1359 | - | else false) | |
1360 | - | then true | |
1361 | - | else !(requireOpenPosition(toString(i.caller)))) | |
1362 | - | then true | |
1363 | - | else !(isSameAsset(_trader, _assetIdStr))) | |
1364 | - | then true | |
1365 | - | else !(initialized())) | |
1366 | - | then true | |
1367 | - | else paused()) | |
1368 | - | then true | |
1369 | - | else closeOnly()) | |
1370 | - | then true | |
1371 | - | else isMarketClosed()) | |
1372 | - | then throw("Invalid addMargin parameters") | |
1373 | - | else { | |
1374 | - | let $t05798558125 = getPosition(_trader) | |
1375 | - | let oldPositionSize = $t05798558125._1 | |
1376 | - | let oldPositionMargin = $t05798558125._2 | |
1377 | - | let oldPositionOpenNotional = $t05798558125._3 | |
1378 | - | let oldPositionLstUpdCPF = $t05798558125._4 | |
1379 | - | let stake = if (isQuoteAsset) | |
1380 | - | then { | |
1381 | - | let stake = invoke(vaultAddress(), "addLocked", [false], [AttachedPayment(quoteAsset(), _amount)]) | |
1382 | - | if ((stake == stake)) | |
1383 | - | then nil | |
1384 | - | else throw("Strict value is not equal to itself.") | |
1385 | - | } | |
1386 | - | else nil | |
1387 | - | if ((stake == stake)) | |
1388 | - | then (updatePosition(_trader, oldPositionSize, (oldPositionMargin + _amount), oldPositionOpenNotional, oldPositionLstUpdCPF) ++ updateBalance((cbalance() + _amount))) | |
1389 | - | else throw("Strict value is not equal to itself.") | |
1390 | - | } | |
1391 | - | } | |
1392 | - | else throw("Strict value is not equal to itself.") | |
1393 | - | } | |
1394 | - | ||
1395 | - | ||
1396 | - | ||
1397 | - | @Callable(i) | |
1398 | - | func removeMargin (_amount) = { | |
1399 | - | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1400 | - | if ((sync == sync)) | |
1401 | - | then { | |
1402 | - | let _trader = toString(i.caller) | |
1403 | - | if (if (if (if (if ((0 >= _amount)) | |
1404 | - | then true | |
1405 | - | else !(requireOpenPosition(_trader))) | |
1406 | - | then true | |
1407 | - | else !(initialized())) | |
1408 | - | then true | |
1409 | - | else paused()) | |
1410 | - | then true | |
1411 | - | else isMarketClosed()) | |
1412 | - | then throw("Invalid removeMargin parameters") | |
1413 | - | else { | |
1414 | - | let $t05892059060 = getPosition(_trader) | |
1415 | - | let oldPositionSize = $t05892059060._1 | |
1416 | - | let oldPositionMargin = $t05892059060._2 | |
1417 | - | let oldPositionOpenNotional = $t05892059060._3 | |
1418 | - | let oldPositionLstUpdCPF = $t05892059060._4 | |
1419 | - | let marginDelta = -(_amount) | |
1420 | - | let $t05909759276 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, marginDelta) | |
1421 | - | let remainMargin = $t05909759276._1 | |
1422 | - | let badDebt = $t05909759276._2 | |
1423 | - | if ((badDebt != 0)) | |
1424 | - | then throw("Invalid removed margin amount") | |
1425 | - | else { | |
1426 | - | let marginRatio = calcMarginRatio(remainMargin, badDebt, oldPositionOpenNotional) | |
1427 | - | if (!(requireMoreMarginRatio(marginRatio, initMarginRatio(), true))) | |
1428 | - | then throw(((("Too much margin removed: " + toString(marginRatio)) + " < ") + toString(initMarginRatio()))) | |
1429 | - | else { | |
1430 | - | let quoteAssetStr = toBase58String(quoteAsset()) | |
1431 | - | let $t05972059774 = getBorrowedByTrader(_trader) | |
1432 | - | let borrowed = $t05972059774._1 | |
1433 | - | let assetId = $t05972059774._2 | |
1434 | - | let toRepay = if ((_amount > borrowed)) | |
1435 | - | then borrowed | |
1436 | - | else _amount | |
1437 | - | let toWithdraw = if ((borrowed > _amount)) | |
1438 | - | then 0 | |
1439 | - | else (_amount - borrowed) | |
1440 | - | let finalBorrow = (borrowed - toRepay) | |
1441 | - | let switchPositionToQuote = if ((finalBorrow > 0)) | |
1442 | - | then nil | |
1443 | - | else updatePositionAsset(_trader, quoteAssetStr) | |
1444 | - | let doSanityCheck = if (((toRepay + toWithdraw) != _amount)) | |
1445 | - | then throw(((((("toRepay=" + toString(toRepay)) + " + toWithdraw=") + toString(toWithdraw)) + " != ") + toString(_amount))) | |
1446 | - | else nil | |
1447 | - | if ((doSanityCheck == doSanityCheck)) | |
1448 | - | then { | |
1449 | - | let doUnstake = if ((toWithdraw > 0)) | |
1450 | - | then { | |
1451 | - | let doUnstake = invoke(vaultAddress(), "withdrawLocked", [toWithdraw], nil) | |
1452 | - | if ((doUnstake == doUnstake)) | |
1453 | - | then nil | |
1454 | - | else throw("Strict value is not equal to itself.") | |
1455 | - | } | |
1456 | - | else nil | |
1457 | - | if ((doUnstake == doUnstake)) | |
1458 | - | then { | |
1459 | - | let returnCollateralAction = if ((toRepay > 0)) | |
1460 | - | then { | |
1461 | - | let doRepay = invoke(collateralAddress(), "repay", [_trader, toRepay, assetId], nil) | |
1462 | - | if ((doRepay == doRepay)) | |
1463 | - | then [ScriptTransfer(i.caller, toRepay, fromBase58String(assetId))] | |
1464 | - | else throw("Strict value is not equal to itself.") | |
1465 | - | } | |
1466 | - | else nil | |
1467 | - | if ((returnCollateralAction == returnCollateralAction)) | |
1468 | - | then ((((updatePosition(_trader, oldPositionSize, remainMargin, oldPositionOpenNotional, latestCumulativePremiumFraction(oldPositionSize)) ++ (if ((toWithdraw > 0)) | |
1469 | - | then withdraw(i.caller, toWithdraw) | |
1470 | - | else nil)) ++ updateBalance((cbalance() - _amount))) ++ switchPositionToQuote) ++ returnCollateralAction) | |
1471 | - | else throw("Strict value is not equal to itself.") | |
1472 | - | } | |
1473 | - | else throw("Strict value is not equal to itself.") | |
1474 | - | } | |
1475 | - | else throw("Strict value is not equal to itself.") | |
1476 | - | } | |
1477 | - | } | |
1478 | - | } | |
1479 | - | } | |
1480 | - | else throw("Strict value is not equal to itself.") | |
1481 | - | } | |
1482 | - | ||
1483 | - | ||
1484 | - | ||
1485 | - | @Callable(i) | |
1486 | - | func closePosition (_size,_minQuoteAssetAmount,_addToMargin) = { | |
1487 | - | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1488 | - | if ((sync == sync)) | |
1489 | - | then { | |
1490 | - | let _trader = getActualCaller(i) | |
1491 | - | let _traderAddress = valueOrErrorMessage(addressFromString(_trader), "Invalid caller") | |
1492 | - | let positionFee = getPositionFee(_trader) | |
1493 | - | if (if (if (if (if (if (!(requireOpenPosition(_trader))) | |
1494 | - | then true | |
1495 | - | else !(initialized())) | |
1496 | - | then true | |
1497 | - | else paused()) | |
1498 | - | then true | |
1499 | - | else (0 >= _size)) | |
1500 | - | then true | |
1501 | - | else (0 > _minQuoteAssetAmount)) | |
1502 | - | then true | |
1503 | - | else isMarketClosed()) | |
1504 | - | then throw("Invalid closePosition parameters") | |
1505 | - | else { | |
1506 | - | let $t06201162151 = getPosition(_trader) | |
1507 | - | let oldPositionSize = $t06201162151._1 | |
1508 | - | let oldPositionMargin = $t06201162151._2 | |
1509 | - | let oldPositionOpenNotional = $t06201162151._3 | |
1510 | - | let oldPositionLstUpdCPF = $t06201162151._4 | |
1511 | - | let $t06215768035 = if ((abs(oldPositionSize) > _size)) | |
1512 | - | then { | |
1513 | - | let _direction = if ((oldPositionSize > 0)) | |
1514 | - | then DIR_SHORT | |
1515 | - | else DIR_LONG | |
1516 | - | let isAdd = (_direction == DIR_LONG) | |
1517 | - | let $t06276862990 = swapOutput((oldPositionSize > 0), _size, true) | |
1518 | - | let exchangedQuoteAssetAmount = $t06276862990._1 | |
1519 | - | let quoteAssetReserveAfter = $t06276862990._2 | |
1520 | - | let baseAssetReserveAfter = $t06276862990._3 | |
1521 | - | let totalPositionSizeAfter = $t06276862990._4 | |
1522 | - | let exchangedPositionSize = if ((oldPositionSize > 0)) | |
1523 | - | then -(_size) | |
1524 | - | else _size | |
1525 | - | let $t06308163235 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
1526 | - | let oldPositionNotional = $t06308163235._1 | |
1527 | - | let unrealizedPnl = $t06308163235._2 | |
1528 | - | let mr = getMarginRatioByOption(_trader, PNL_OPTION_SPOT) | |
1529 | - | let realizedRatio = divd(abs(exchangedPositionSize), abs(oldPositionSize)) | |
1530 | - | let realizedPnl = muld(unrealizedPnl, realizedRatio) | |
1531 | - | let realizedFee = muld(muld(oldPositionNotional, realizedRatio), positionFee) | |
1532 | - | let remainMarginBefore = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, unrealizedPnl)._1 | |
1533 | - | let positionBadDebt = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl)._2 | |
1534 | - | let unrealizedPnlAfter = (unrealizedPnl - realizedPnl) | |
1535 | - | let remainOpenNotional = if ((oldPositionSize > 0)) | |
1536 | - | then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter) | |
1537 | - | else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount) | |
1538 | - | let newPositionOpenNotional = abs(remainOpenNotional) | |
1539 | - | let newPositionSize = (oldPositionSize + exchangedPositionSize) | |
1540 | - | let newPositionLstUpdCPF = latestCumulativePremiumFraction(newPositionSize) | |
1541 | - | let openNotionalDelta = (oldPositionOpenNotional - newPositionOpenNotional) | |
1542 | - | let openInterestNotionalAfter = (openInterestNotional() - openNotionalDelta) | |
1543 | - | let newPositionMargin = if ((oldPositionSize > 0)) | |
1544 | - | then (muld((newPositionOpenNotional + unrealizedPnlAfter), mr) - unrealizedPnlAfter) | |
1545 | - | else (muld((newPositionOpenNotional - unrealizedPnlAfter), mr) - unrealizedPnlAfter) | |
1546 | - | let marginToTraderRaw = ((remainMarginBefore - (newPositionMargin + unrealizedPnlAfter)) - realizedFee) | |
1547 | - | let marginToTrader = if ((0 > marginToTraderRaw)) | |
1548 | - | then throw("Margin error: unable to pay close fee") | |
1549 | - | else marginToTraderRaw | |
1550 | - | if (if ((_minQuoteAssetAmount != 0)) | |
1551 | - | then (_minQuoteAssetAmount > exchangedQuoteAssetAmount) | |
1552 | - | else false) | |
1553 | - | then throw(((("Limit error: " + toString(exchangedQuoteAssetAmount)) + " < ") + toString(_minQuoteAssetAmount))) | |
1554 | - | else $Tuple16(newPositionSize, if (_addToMargin) | |
1555 | - | then (newPositionMargin + marginToTrader) | |
1556 | - | else newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF, positionBadDebt, realizedPnl, if (_addToMargin) | |
1557 | - | then 0 | |
1558 | - | else marginToTrader, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, (totalLongPositionSize() - (if ((newPositionSize > 0)) | |
1559 | - | then abs(exchangedPositionSize) | |
1560 | - | else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize)) | |
1561 | - | then abs(exchangedPositionSize) | |
1562 | - | else 0)), (openInterestLong() - (if ((newPositionSize > 0)) | |
1563 | - | then openNotionalDelta | |
1564 | - | else 0)), (openInterestShort() - (if ((0 > newPositionSize)) | |
1565 | - | then openNotionalDelta | |
1566 | - | else 0)), realizedFee) | |
1567 | - | } | |
1568 | - | else if ((_size > abs(oldPositionSize))) | |
1569 | - | then throw("Invalid closePosition parameters") | |
1570 | - | else { | |
1571 | - | let $t06645466884 = internalClosePosition(_trader, true) | |
1572 | - | let x2 = $t06645466884._1 | |
1573 | - | let positionBadDebt = $t06645466884._2 | |
1574 | - | let realizedPnl = $t06645466884._3 | |
1575 | - | let marginToTraderWithoutFee = $t06645466884._4 | |
1576 | - | let quoteAssetReserveAfter = $t06645466884._5 | |
1577 | - | let baseAssetReserveAfter = $t06645466884._6 | |
1578 | - | let totalPositionSizeAfter = $t06645466884._7 | |
1579 | - | let openInterestNotionalAfter = $t06645466884._8 | |
1580 | - | let exchangedQuoteAssetAmount = $t06645466884._9 | |
1581 | - | let totalLongAfter = $t06645466884._10 | |
1582 | - | let totalShortAfter = $t06645466884._11 | |
1583 | - | let totalLongOpenInterestAfter = $t06645466884._12 | |
1584 | - | let totalShortOpenInterestAfter = $t06645466884._13 | |
1585 | - | let realizedFee = muld(exchangedQuoteAssetAmount, positionFee) | |
1586 | - | let marginToTraderRaw = (abs(marginToTraderWithoutFee) - realizedFee) | |
1587 | - | let marginToTrader = if ((0 > marginToTraderRaw)) | |
1588 | - | then throw(((((((("Margin error: unable to pay close fee: " + toString(realizedFee)) + " margin: ") + toString(marginToTraderWithoutFee)) + " fee percent: ") + toString(positionFee)) + " notional: ") + toString(exchangedQuoteAssetAmount))) | |
1589 | - | else marginToTraderRaw | |
1590 | - | if (if ((_minQuoteAssetAmount != 0)) | |
1591 | - | then (_minQuoteAssetAmount > exchangedQuoteAssetAmount) | |
1592 | - | else false) | |
1593 | - | then throw(((("Limit error: " + toString(exchangedQuoteAssetAmount)) + " < ") + toString(_minQuoteAssetAmount))) | |
1594 | - | else $Tuple16(0, 0, 0, 0, positionBadDebt, realizedPnl, marginToTrader, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter, realizedFee) | |
1595 | - | } | |
1596 | - | let newPositionSize = $t06215768035._1 | |
1597 | - | let newPositionMargin = $t06215768035._2 | |
1598 | - | let newPositionOpenNotional = $t06215768035._3 | |
1599 | - | let newPositionLstUpdCPF = $t06215768035._4 | |
1600 | - | let positionBadDebt = $t06215768035._5 | |
1601 | - | let realizedPnl = $t06215768035._6 | |
1602 | - | let marginToTrader = $t06215768035._7 | |
1603 | - | let quoteAssetReserveAfter = $t06215768035._8 | |
1604 | - | let baseAssetReserveAfter = $t06215768035._9 | |
1605 | - | let totalPositionSizeAfter = $t06215768035._10 | |
1606 | - | let openInterestNotionalAfter = $t06215768035._11 | |
1607 | - | let totalLongAfter = $t06215768035._12 | |
1608 | - | let totalShortAfter = $t06215768035._13 | |
1609 | - | let totalLongOpenInterestAfter = $t06215768035._14 | |
1610 | - | let totalShortOpenInterestAfter = $t06215768035._15 | |
1611 | - | let realizedFee = $t06215768035._16 | |
1612 | - | if ((positionBadDebt > 0)) | |
1613 | - | then throw("Unable to close position with bad debt") | |
1614 | - | else { | |
1615 | - | let isPartialClose = (newPositionSize != 0) | |
1616 | - | let withdrawAmount = (marginToTrader + realizedFee) | |
1617 | - | let ammBalance = (cbalance() - withdrawAmount) | |
1618 | - | let $t06830268509 = if ((0 > ammBalance)) | |
1619 | - | then $Tuple2(0, abs(ammBalance)) | |
1620 | - | else $Tuple2(ammBalance, 0) | |
1621 | - | let ammNewBalance = $t06830268509._1 | |
1622 | - | let x11 = $t06830268509._2 | |
1623 | - | let $t06851668570 = getBorrowedByTrader(_trader) | |
1624 | - | let borrowed = $t06851668570._1 | |
1625 | - | let assetId = $t06851668570._2 | |
1626 | - | let $t06857869438 = if ((borrowed > 0)) | |
1627 | - | then if ((withdrawAmount >= borrowed)) | |
1628 | - | then { | |
1629 | - | let doRepay = invoke(collateralAddress(), "repay", [_trader, borrowed, assetId], nil) | |
1630 | - | if ((doRepay == doRepay)) | |
1631 | - | then $Tuple3(borrowed, (withdrawAmount - borrowed), isPartialClose) | |
1632 | - | else throw("Strict value is not equal to itself.") | |
1633 | - | } | |
1634 | - | else { | |
1635 | - | let realizeAndClose = invoke(collateralAddress(), if (isPartialClose) | |
1636 | - | then "repay" | |
1637 | - | else "realizePartiallyAndClose", [_trader, withdrawAmount, assetId], nil) | |
1638 | - | if ((realizeAndClose == realizeAndClose)) | |
1639 | - | then $Tuple3(withdrawAmount, 0, false) | |
1640 | - | else throw("Strict value is not equal to itself.") | |
1641 | - | } | |
1642 | - | else $Tuple3(0, withdrawAmount, false) | |
1643 | - | if (($t06857869438 == $t06857869438)) | |
1644 | - | then { | |
1645 | - | let switchToQuote = $t06857869438._3 | |
1646 | - | let quoteWithdrawAmountBeforeFee = $t06857869438._2 | |
1647 | - | let assetWithdrawAmountBeforeFee = $t06857869438._1 | |
1648 | - | let $t06944670513 = if ((quoteWithdrawAmountBeforeFee >= realizedFee)) | |
1649 | - | then $Tuple3(assetWithdrawAmountBeforeFee, (quoteWithdrawAmountBeforeFee - realizedFee), realizedFee) | |
1650 | - | else { | |
1651 | - | let feeLeftToWithdrawFromAsset = (realizedFee - quoteWithdrawAmountBeforeFee) | |
1652 | - | let assetWithdrawAmountAfterFee = (assetWithdrawAmountBeforeFee - feeLeftToWithdrawFromAsset) | |
1653 | - | let balanceBefore = assetBalance(this, quoteAsset()) | |
1654 | - | if ((balanceBefore == balanceBefore)) | |
1655 | - | then { | |
1656 | - | let doSwap = invoke(swapAddress(), "swap", [toBase58String(quoteAsset()), 0], [AttachedPayment(fromBase58String(assetId), feeLeftToWithdrawFromAsset)]) | |
1657 | - | if ((doSwap == doSwap)) | |
1658 | - | then { | |
1659 | - | let balanceAfter = assetBalance(this, quoteAsset()) | |
1660 | - | if ((balanceAfter == balanceAfter)) | |
1661 | - | then { | |
1662 | - | let exchangedAmount = (balanceAfter - balanceBefore) | |
1663 | - | if ((exchangedAmount == exchangedAmount)) | |
1664 | - | then $Tuple3(assetWithdrawAmountAfterFee, 0, (quoteWithdrawAmountBeforeFee + exchangedAmount)) | |
1665 | - | else throw("Strict value is not equal to itself.") | |
1666 | - | } | |
1667 | - | else throw("Strict value is not equal to itself.") | |
1668 | - | } | |
1669 | - | else throw("Strict value is not equal to itself.") | |
1670 | - | } | |
1671 | - | else throw("Strict value is not equal to itself.") | |
1672 | - | } | |
1673 | - | if (($t06944670513 == $t06944670513)) | |
1674 | - | then { | |
1675 | - | let actualFeeInQuoteAsset = $t06944670513._3 | |
1676 | - | let quoteWithdrawAmountAfterFee = $t06944670513._2 | |
1677 | - | let assetWithdrawAmountAfterFee = $t06944670513._1 | |
1678 | - | let unstake = if ((quoteWithdrawAmountBeforeFee > 0)) | |
1679 | - | then { | |
1680 | - | let unstake = invoke(vaultAddress(), "withdrawLocked", [quoteWithdrawAmountBeforeFee], nil) | |
1681 | - | if ((unstake == unstake)) | |
1682 | - | then nil | |
1683 | - | else throw("Strict value is not equal to itself.") | |
1684 | - | } | |
1685 | - | else nil | |
1686 | - | if ((unstake == unstake)) | |
1687 | - | then { | |
1688 | - | let $t07078770856 = distributeFee(actualFeeInQuoteAsset) | |
1689 | - | let feeToStakers = $t07078770856._1 | |
1690 | - | let feeToVault = $t07078770856._2 | |
1691 | - | let depositVault = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToVault)]) | |
1692 | - | if ((depositVault == depositVault)) | |
1693 | - | then { | |
1694 | - | let notifyFee = invoke(minerAddress(), "notifyFees", [_trader, realizedFee], nil) | |
1695 | - | if ((notifyFee == notifyFee)) | |
1696 | - | then { | |
1697 | - | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil) | |
1698 | - | if ((notifyNotional == notifyNotional)) | |
1699 | - | then (((((((if (isPartialClose) | |
1700 | - | then updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF) | |
1701 | - | else deletePosition(_trader)) ++ (if (switchToQuote) | |
1702 | - | then { | |
1703 | - | let quoteAssetStr = toBase58String(quoteAsset()) | |
1704 | - | updatePositionAsset(_trader, quoteAssetStr) | |
1705 | - | } | |
1706 | - | else nil)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ transferFee(feeToStakers)) ++ (if ((quoteWithdrawAmountAfterFee > 0)) | |
1707 | - | then withdraw(_traderAddress, quoteWithdrawAmountAfterFee) | |
1708 | - | else nil)) ++ updateBalance(ammNewBalance)) ++ (if ((assetWithdrawAmountAfterFee > 0)) | |
1709 | - | then [ScriptTransfer(_traderAddress, assetWithdrawAmountAfterFee, fromBase58String(assetId))] | |
1710 | - | else nil)) | |
1711 | - | else throw("Strict value is not equal to itself.") | |
1712 | - | } | |
1713 | - | else throw("Strict value is not equal to itself.") | |
1714 | - | } | |
1715 | - | else throw("Strict value is not equal to itself.") | |
1716 | - | } | |
1717 | - | else throw("Strict value is not equal to itself.") | |
1718 | - | } | |
1719 | - | else throw("Strict value is not equal to itself.") | |
1720 | - | } | |
1721 | - | else throw("Strict value is not equal to itself.") | |
1722 | - | } | |
1723 | - | } | |
1724 | - | } | |
1725 | - | else throw("Strict value is not equal to itself.") | |
1726 | - | } | |
1727 | - | ||
1728 | - | ||
1729 | - | ||
1730 | - | @Callable(i) | |
1731 | - | func liquidate (_trader) = { | |
1732 | - | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1733 | - | if ((sync == sync)) | |
1734 | - | then { | |
1735 | - | let spotMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_SPOT) | |
1736 | - | let marginRatio = if (isOverFluctuationLimit()) | |
1737 | - | then { | |
1738 | - | let oracleMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_ORACLE) | |
1739 | - | vmax(spotMarginRatio, oracleMarginRatio) | |
1740 | - | } | |
1741 | - | else spotMarginRatio | |
1742 | - | if (if (if (if (if (!(requireMoreMarginRatio(marginRatio, maintenanceMarginRatio(), false))) | |
1743 | - | then true | |
1744 | - | else !(requireOpenPosition(_trader))) | |
1745 | - | then true | |
1746 | - | else !(initialized())) | |
1747 | - | then true | |
1748 | - | else paused()) | |
1749 | - | then true | |
1750 | - | else isMarketClosed()) | |
1751 | - | then throw("Unable to liquidate") | |
1752 | - | else if (if (if ((spotMarginRatio > liquidationFeeRatio())) | |
1753 | - | then (partialLiquidationRatio() > 0) | |
1754 | - | else false) | |
1755 | - | then (DECIMAL_UNIT > partialLiquidationRatio()) | |
1756 | - | else false) | |
1757 | - | then { | |
1758 | - | let $t07360973759 = getPosition(_trader) | |
1759 | - | let oldPositionSize = $t07360973759._1 | |
1760 | - | let oldPositionMargin = $t07360973759._2 | |
1761 | - | let oldPositionOpenNotional = $t07360973759._3 | |
1762 | - | let oldPositionLstUpdCPF = $t07360973759._4 | |
1763 | - | let _direction = if ((oldPositionSize > 0)) | |
1764 | - | then DIR_SHORT | |
1765 | - | else DIR_LONG | |
1766 | - | let isAdd = (_direction == DIR_LONG) | |
1767 | - | let exchangedQuoteAssetAmount = getPartialLiquidationAmount(_trader, oldPositionSize) | |
1768 | - | let $t07398474088 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
1769 | - | let oldPositionNotional = $t07398474088._1 | |
1770 | - | let unrealizedPnl = $t07398474088._2 | |
1771 | - | let $t07409674283 = swapInput(isAdd, exchangedQuoteAssetAmount) | |
1772 | - | let exchangedPositionSize = $t07409674283._1 | |
1773 | - | let quoteAssetReserveAfter = $t07409674283._2 | |
1774 | - | let baseAssetReserveAfter = $t07409674283._3 | |
1775 | - | let totalPositionSizeAfter = $t07409674283._4 | |
1776 | - | let liquidationRatio = divd(abs(exchangedPositionSize), abs(oldPositionSize)) | |
1777 | - | let realizedPnl = muld(unrealizedPnl, liquidationRatio) | |
1778 | - | let $t07457274805 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl) | |
1779 | - | let remainMargin = $t07457274805._1 | |
1780 | - | let badDebt = $t07457274805._2 | |
1781 | - | let fundingPayment = $t07457274805._3 | |
1782 | - | let unrealizedPnlAfter = (unrealizedPnl - realizedPnl) | |
1783 | - | let remainOpenNotional = if ((oldPositionSize > 0)) | |
1784 | - | then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter) | |
1785 | - | else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount) | |
1786 | - | let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio()) | |
1787 | - | let feeToLiquidator = (liquidationPenalty / 2) | |
1788 | - | let feeToVault = (liquidationPenalty - feeToLiquidator) | |
1789 | - | let newPositionMargin = (remainMargin - liquidationPenalty) | |
1790 | - | let newPositionSize = (oldPositionSize + exchangedPositionSize) | |
1791 | - | let newPositionOpenNotional = abs(remainOpenNotional) | |
1792 | - | let openNotionalDelta = (oldPositionOpenNotional - newPositionOpenNotional) | |
1793 | - | let newPositionLstUpdCPF = latestCumulativePremiumFraction(newPositionSize) | |
1794 | - | let openInterestNotionalAfter = (openInterestNotional() - openNotionalDelta) | |
1795 | - | let ammBalance = (cbalance() - liquidationPenalty) | |
1796 | - | let $t07604676175 = if ((0 > ammBalance)) | |
1797 | - | then $Tuple2(0, abs(ammBalance)) | |
1798 | - | else $Tuple2(ammBalance, 0) | |
1799 | - | let newAmmBalance = $t07604676175._1 | |
1800 | - | let x11 = $t07604676175._2 | |
1801 | - | let $t07618376237 = getBorrowedByTrader(_trader) | |
1802 | - | let borrowed = $t07618376237._1 | |
1803 | - | let assetId = $t07618376237._2 | |
1804 | - | let doLiquidateCollateral = if ((borrowed > 0)) | |
1805 | - | then { | |
1806 | - | let collateralToSell = muld(borrowed, liquidationRatio) | |
1807 | - | let realizeAndClose = invoke(collateralAddress(), "realizePartially", [_trader, assetId, collateralToSell], nil) | |
1808 | - | if ((realizeAndClose == realizeAndClose)) | |
1809 | - | then nil | |
1810 | - | else throw("Strict value is not equal to itself.") | |
1811 | - | } | |
1812 | - | else nil | |
1813 | - | if ((doLiquidateCollateral == doLiquidateCollateral)) | |
1814 | - | then { | |
1815 | - | let unstake = invoke(vaultAddress(), "withdrawLocked", [liquidationPenalty], nil) | |
1816 | - | if ((unstake == unstake)) | |
1817 | - | then { | |
1818 | - | let depositInsurance = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToVault)]) | |
1819 | - | if ((depositInsurance == depositInsurance)) | |
1820 | - | then { | |
1821 | - | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil) | |
1822 | - | if ((notifyNotional == notifyNotional)) | |
1823 | - | then (((updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, (totalLongPositionSize() - (if ((newPositionSize > 0)) | |
1824 | - | then abs(exchangedPositionSize) | |
1825 | - | else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize)) | |
1826 | - | then abs(exchangedPositionSize) | |
1827 | - | else 0)), (openInterestLong() - (if ((newPositionSize > 0)) | |
1828 | - | then openNotionalDelta | |
1829 | - | else 0)), (openInterestShort() - (if ((0 > newPositionSize)) | |
1830 | - | then openNotionalDelta | |
1831 | - | else 0)))) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance)) | |
1832 | - | else throw("Strict value is not equal to itself.") | |
1833 | - | } | |
1834 | - | else throw("Strict value is not equal to itself.") | |
1835 | - | } | |
1836 | - | else throw("Strict value is not equal to itself.") | |
1837 | - | } | |
1838 | - | else throw("Strict value is not equal to itself.") | |
1839 | - | } | |
1840 | - | else { | |
1841 | - | let $t07791678411 = internalClosePosition(_trader, false) | |
1842 | - | let x1 = $t07791678411._1 | |
1843 | - | let badDebt = $t07791678411._2 | |
1844 | - | let x2 = $t07791678411._3 | |
1845 | - | let x3 = $t07791678411._4 | |
1846 | - | let quoteAssetReserveAfter = $t07791678411._5 | |
1847 | - | let baseAssetReserveAfter = $t07791678411._6 | |
1848 | - | let totalPositionSizeAfter = $t07791678411._7 | |
1849 | - | let openInterestNotionalAfter = $t07791678411._8 | |
1850 | - | let exchangedQuoteAssetAmount = $t07791678411._9 | |
1851 | - | let totalLongAfter = $t07791678411._10 | |
1852 | - | let totalShortAfter = $t07791678411._11 | |
1853 | - | let totalLongOpenInterestAfter = $t07791678411._12 | |
1854 | - | let totalShortOpenInterestAfter = $t07791678411._13 | |
1855 | - | let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio()) | |
1856 | - | let feeToLiquidator = (liquidationPenalty / 2) | |
1857 | - | let feeToVault = (liquidationPenalty - feeToLiquidator) | |
1858 | - | let ammBalance = (cbalance() - liquidationPenalty) | |
1859 | - | let $t07881978948 = if ((0 > ammBalance)) | |
1860 | - | then $Tuple2(0, abs(ammBalance)) | |
1861 | - | else $Tuple2(ammBalance, 0) | |
1862 | - | let newAmmBalance = $t07881978948._1 | |
1863 | - | let x11 = $t07881978948._2 | |
1864 | - | let $t07895679010 = getBorrowedByTrader(_trader) | |
1865 | - | let borrowed = $t07895679010._1 | |
1866 | - | let assetId = $t07895679010._2 | |
1867 | - | let doLiquidateCollateral = if ((borrowed > 0)) | |
1868 | - | then { | |
1869 | - | let realizeAndClose = invoke(collateralAddress(), "realizePartiallyAndClose", [_trader, 0, assetId], nil) | |
1870 | - | if ((realizeAndClose == realizeAndClose)) | |
1871 | - | then nil | |
1872 | - | else throw("Strict value is not equal to itself.") | |
1873 | - | } | |
1874 | - | else nil | |
1875 | - | if ((doLiquidateCollateral == doLiquidateCollateral)) | |
1876 | - | then { | |
1877 | - | let x = if ((badDebt > 0)) | |
1878 | - | then { | |
1879 | - | let lockBadDebt = invoke(vaultAddress(), "exchangeFreeAndLocked", [badDebt], nil) | |
1880 | - | if ((lockBadDebt == lockBadDebt)) | |
1881 | - | then nil | |
1882 | - | else throw("Strict value is not equal to itself.") | |
1883 | - | } | |
1884 | - | else nil | |
1885 | - | if ((x == x)) | |
1886 | - | then { | |
1887 | - | let unstake = invoke(vaultAddress(), "withdrawLocked", [liquidationPenalty], nil) | |
1888 | - | if ((unstake == unstake)) | |
1889 | - | then { | |
1890 | - | let depositInsurance = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToVault)]) | |
1891 | - | if ((depositInsurance == depositInsurance)) | |
1892 | - | then { | |
1893 | - | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, 0], nil) | |
1894 | - | if ((notifyNotional == notifyNotional)) | |
1895 | - | then (((deletePosition(_trader) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance)) | |
1896 | - | else throw("Strict value is not equal to itself.") | |
1897 | - | } | |
1898 | - | else throw("Strict value is not equal to itself.") | |
1899 | - | } | |
1900 | - | else throw("Strict value is not equal to itself.") | |
1901 | - | } | |
1902 | - | else throw("Strict value is not equal to itself.") | |
1903 | - | } | |
1904 | - | else throw("Strict value is not equal to itself.") | |
1905 | - | } | |
1906 | - | } | |
1907 | - | else throw("Strict value is not equal to itself.") | |
1908 | - | } | |
1909 | - | ||
1910 | - | ||
1911 | - | ||
1912 | - | @Callable(i) | |
1913 | 1676 | func payFunding () = { | |
1914 | 1677 | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1915 | 1678 | if ((sync == sync)) | |
1916 | 1679 | then { | |
1917 | 1680 | let fundingBlockTimestamp = nextFundingBlockTimestamp() | |
1918 | - | if (if (if ((fundingBlockTimestamp > | |
1681 | + | if (if (if ((fundingBlockTimestamp > lastTimestamp())) | |
1919 | 1682 | then true | |
1920 | 1683 | else !(initialized())) | |
1921 | 1684 | then true | |
1922 | 1685 | else paused()) | |
1923 | - | then throw(((("Invalid funding block timestamp: " + toString( | |
1686 | + | then throw(((("Invalid funding block timestamp: " + toString(lastTimestamp())) + " < ") + toString(fundingBlockTimestamp))) | |
1924 | 1687 | else { | |
1925 | 1688 | let underlyingPrice = getOraclePrice() | |
1926 | - | let $ | |
1927 | - | let shortPremiumFraction = $ | |
1928 | - | let longPremiumFraction = $ | |
1689 | + | let $t07530775369 = getFunding() | |
1690 | + | let shortPremiumFraction = $t07530775369._1 | |
1691 | + | let longPremiumFraction = $t07530775369._2 | |
1929 | 1692 | updateFunding((fundingBlockTimestamp + fundingPeriodSeconds()), (latestLongCumulativePremiumFraction() + longPremiumFraction), (latestShortCumulativePremiumFraction() + shortPremiumFraction), divd(longPremiumFraction, underlyingPrice), divd(shortPremiumFraction, underlyingPrice)) | |
1930 | 1693 | } | |
1931 | 1694 | } | |
1938 | 1701 | func syncTerminalPriceToOracle () = { | |
1939 | 1702 | let _qtAstR = qtAstR() | |
1940 | 1703 | let _bsAstR = bsAstR() | |
1941 | - | let $ | |
1942 | - | let newQuoteAssetWeight = $ | |
1943 | - | let newBaseAssetWeight = $ | |
1944 | - | let marginToVault = $ | |
1704 | + | let $t07580175936 = getSyncTerminalPrice(getOraclePrice(), _qtAstR, _bsAstR) | |
1705 | + | let newQuoteAssetWeight = $t07580175936._1 | |
1706 | + | let newBaseAssetWeight = $t07580175936._2 | |
1707 | + | let marginToVault = $t07580175936._3 | |
1945 | 1708 | let doExchangePnL = if ((marginToVault != 0)) | |
1946 | 1709 | then { | |
1947 | 1710 | let doExchangePnL = invoke(vaultAddress(), "exchangeFreeAndLocked", [marginToVault], nil) | |
1951 | 1714 | } | |
1952 | 1715 | else nil | |
1953 | 1716 | if ((doExchangePnL == doExchangePnL)) | |
1954 | - | then (updateAmmWeights(newQuoteAssetWeight, newBaseAssetWeight) ++ appendTwap(divd(muld(_qtAstR, newQuoteAssetWeight), muld(_bsAstR, newBaseAssetWeight)))) | |
1717 | + | then ((updateBalance((cbalance() + marginToVault)) ++ updateAmmWeights(newQuoteAssetWeight, newBaseAssetWeight)) ++ appendTwap(divd(muld(_qtAstR, newQuoteAssetWeight), muld(_bsAstR, newBaseAssetWeight)))) | |
1955 | 1718 | else throw("Strict value is not equal to itself.") | |
1956 | 1719 | } | |
1720 | + | ||
1721 | + | ||
1722 | + | ||
1723 | + | @Callable(i) | |
1724 | + | func ensureCalledOnce () = if ((i.caller != this)) | |
1725 | + | then throw("Invalid saveCurrentTxId parameters") | |
1726 | + | else { | |
1727 | + | let lastTx = valueOrElse(getString(this, k_lastTx), "") | |
1728 | + | if ((lastTx != toBase58String(i.transactionId))) | |
1729 | + | then [StringEntry(k_lastTx, lastTx)] | |
1730 | + | else throw("Can not call vAMM methods twice in one tx") | |
1731 | + | } | |
1957 | 1732 | ||
1958 | 1733 | ||
1959 | 1734 | ||
1962 | 1737 | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1963 | 1738 | if ((sync == sync)) | |
1964 | 1739 | then { | |
1965 | - | let $t08208082181 = getPosition(_trader) | |
1966 | - | let positionSize = $t08208082181._1 | |
1967 | - | let positionMargin = $t08208082181._2 | |
1968 | - | let pon = $t08208082181._3 | |
1969 | - | let positionLstUpdCPF = $t08208082181._4 | |
1970 | - | let $t08218482285 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
1971 | - | let positionNotional = $t08218482285._1 | |
1972 | - | let unrealizedPnl = $t08218482285._2 | |
1973 | - | let $t08228882460 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
1974 | - | let remainMargin = $t08228882460._1 | |
1975 | - | let badDebt = $t08228882460._2 | |
1976 | - | let fundingPayment = $t08228882460._3 | |
1977 | - | throw((((((s(remainMargin) + s(fundingPayment)) + s(getMarginRatio(_trader))) + s(unrealizedPnl)) + s(badDebt)) + s(positionNotional))) | |
1740 | + | let $t07694177065 = getPosition(_trader) | |
1741 | + | let positionSize = $t07694177065._1 | |
1742 | + | let positionMargin = $t07694177065._2 | |
1743 | + | let pon = $t07694177065._3 | |
1744 | + | let positionLstUpdCPF = $t07694177065._4 | |
1745 | + | let positionTimestamp = $t07694177065._5 | |
1746 | + | let $t07706877169 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
1747 | + | let positionNotional = $t07706877169._1 | |
1748 | + | let unrealizedPnl = $t07706877169._2 | |
1749 | + | let $t07717277396 = calcRemainMarginWithFundingPaymentAndRolloverFee(positionSize, positionMargin, positionLstUpdCPF, positionTimestamp, unrealizedPnl) | |
1750 | + | let remainMargin = $t07717277396._1 | |
1751 | + | let badDebt = $t07717277396._2 | |
1752 | + | let fundingPayment = $t07717277396._3 | |
1753 | + | let rolloverFee = $t07717277396._4 | |
1754 | + | throw(((((((s(remainMargin) + s(fundingPayment)) + s(getMarginRatio(_trader))) + s(unrealizedPnl)) + s(badDebt)) + s(positionNotional)) + s(rolloverFee))) | |
1978 | 1755 | } | |
1979 | 1756 | else throw("Strict value is not equal to itself.") | |
1980 | 1757 | } | |
1993 | 1770 | ||
1994 | 1771 | @Callable(i) | |
1995 | 1772 | func view_getTerminalAmmPrice () = { | |
1996 | - | let $ | |
1997 | - | let terminalQuoteAssetReserve = $ | |
1998 | - | let terminalBaseAssetReserve = $ | |
1773 | + | let $t07783277913 = getTerminalAmmState() | |
1774 | + | let terminalQuoteAssetReserve = $t07783277913._1 | |
1775 | + | let terminalBaseAssetReserve = $t07783277913._2 | |
1999 | 1776 | let price = divd(muld(terminalQuoteAssetReserve, qtAstW()), muld(terminalBaseAssetReserve, bsAstW())) | |
2000 | 1777 | throw(toString(price)) | |
2001 | 1778 | } | |
2005 | 1782 | @Callable(i) | |
2006 | 1783 | func view_getFunding () = { | |
2007 | 1784 | let underlyingPrice = getOraclePrice() | |
2008 | - | let $ | |
2009 | - | let shortPremiumFraction = $ | |
2010 | - | let longPremiumFraction = $ | |
1785 | + | let $t07812878190 = getFunding() | |
1786 | + | let shortPremiumFraction = $t07812878190._1 | |
1787 | + | let longPremiumFraction = $t07812878190._2 | |
2011 | 1788 | let longFunding = divd(longPremiumFraction, underlyingPrice) | |
2012 | 1789 | let shortFunding = divd(shortPremiumFraction, underlyingPrice) | |
2013 | 1790 | throw((((s(longFunding) + s(shortFunding)) + s(getTwapSpotPrice())) + s(getOraclePrice()))) | |
2016 | 1793 | ||
2017 | 1794 | ||
2018 | 1795 | @Callable(i) | |
2019 | - | func view_getBorrowedByTrader (_trader) = { | |
2020 | - | let $t08352083574 = getBorrowedByTrader(_trader) | |
2021 | - | let borrowed = $t08352083574._1 | |
2022 | - | let assetId = $t08352083574._2 | |
2023 | - | throw((s(borrowed) + assetId)) | |
2024 | - | } | |
2025 | - | ||
2026 | - | ||
2027 | - | ||
2028 | - | @Callable(i) | |
2029 | 1796 | func computeSpotPrice () = { | |
2030 | - | let result = getSpotPrice() | |
2031 | - | $Tuple2(nil, result) | |
1797 | + | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1798 | + | if ((sync == sync)) | |
1799 | + | then { | |
1800 | + | let result = getSpotPrice() | |
1801 | + | $Tuple2(nil, result) | |
1802 | + | } | |
1803 | + | else throw("Strict value is not equal to itself.") | |
2032 | 1804 | } | |
2033 | 1805 | ||
2034 | 1806 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let k_ | |
4 | + | let k_baseOracle = "k_baseOracle" | |
5 | 5 | ||
6 | - | let k_ora_block_key = "k_ora_block_key" | |
7 | - | ||
8 | - | let k_ora_open_key = "k_ora_open_key" | |
9 | - | ||
10 | - | let k_ora = "k_ora" | |
6 | + | let k_quoteOracle = "k_quoteOracle" | |
11 | 7 | ||
12 | 8 | let k_balance = "k_balance" | |
13 | 9 | ||
14 | 10 | let k_sequence = "k_sequence" | |
15 | 11 | ||
16 | 12 | let k_positionSize = "k_positionSize" | |
17 | 13 | ||
18 | 14 | let k_positionMargin = "k_positionMargin" | |
19 | 15 | ||
20 | 16 | let k_positionOpenNotional = "k_positionOpenNotional" | |
21 | 17 | ||
22 | 18 | let k_positionLastUpdatedCumulativePremiumFraction = "k_positionFraction" | |
23 | 19 | ||
24 | 20 | let k_positionSequence = "k_positionSequence" | |
25 | 21 | ||
26 | 22 | let k_positionAsset = "k_positionAsset" | |
27 | 23 | ||
28 | 24 | let k_positionFee = "k_positionFee" | |
29 | 25 | ||
26 | + | let k_positionLastUpdatedTimestamp = "k_positionTimestamp" | |
27 | + | ||
30 | 28 | let k_initialized = "k_initialized" | |
31 | 29 | ||
32 | 30 | let k_paused = "k_paused" | |
33 | 31 | ||
34 | 32 | let k_closeOnly = "k_closeOnly" | |
35 | 33 | ||
36 | 34 | let k_fee = "k_fee" | |
35 | + | ||
36 | + | let k_rolloverFee = "k_rollover_fee" | |
37 | 37 | ||
38 | 38 | let k_fundingPeriod = "k_fundingPeriod" | |
39 | 39 | ||
40 | 40 | let k_initMarginRatio = "k_initMarginRatio" | |
41 | 41 | ||
42 | 42 | let k_maintenanceMarginRatio = "k_mmr" | |
43 | 43 | ||
44 | 44 | let k_liquidationFeeRatio = "k_liquidationFeeRatio" | |
45 | 45 | ||
46 | 46 | let k_partialLiquidationRatio = "k_partLiquidationRatio" | |
47 | 47 | ||
48 | 48 | let k_spreadLimit = "k_spreadLimit" | |
49 | 49 | ||
50 | 50 | let k_maxPriceImpact = "k_maxPriceImpact" | |
51 | 51 | ||
52 | 52 | let k_maxPriceSpread = "k_maxPriceSpread" | |
53 | 53 | ||
54 | 54 | let k_maxOpenNotional = "k_maxOpenNotional" | |
55 | 55 | ||
56 | 56 | let k_feeToStakersPercent = "k_feeToStakersPercent" | |
57 | 57 | ||
58 | 58 | let k_maxOracleDelay = "k_maxOracleDelay" | |
59 | 59 | ||
60 | 60 | let k_lastDataStr = "k_lastDataStr" | |
61 | 61 | ||
62 | 62 | let k_lastMinuteId = "k_lastMinuteId" | |
63 | 63 | ||
64 | 64 | let k_twapDataLastCumulativePrice = "k_twapDataLastCumulativePrice" | |
65 | 65 | ||
66 | 66 | let k_twapDataLastPrice = "k_twapDataLastPrice" | |
67 | 67 | ||
68 | 68 | let k_twapDataPreviousMinuteId = "k_twapDataPreviousMinuteId" | |
69 | 69 | ||
70 | 70 | let k_latestLongCumulativePremiumFraction = "k_latestLongPremiumFraction" | |
71 | 71 | ||
72 | 72 | let k_latestShortCumulativePremiumFraction = "k_latestShortPremiumFraction" | |
73 | 73 | ||
74 | 74 | let k_nextFundingBlock = "k_nextFundingBlockMinTimestamp" | |
75 | 75 | ||
76 | 76 | let k_longFundingRate = "k_longFundingRate" | |
77 | 77 | ||
78 | 78 | let k_shortFundingRate = "k_shortFundingRate" | |
79 | 79 | ||
80 | 80 | let k_quoteAssetReserve = "k_qtAstR" | |
81 | 81 | ||
82 | 82 | let k_baseAssetReserve = "k_bsAstR" | |
83 | 83 | ||
84 | 84 | let k_quoteAssetWeight = "k_qtAstW" | |
85 | 85 | ||
86 | 86 | let k_baseAssetWeight = "k_bsAstW" | |
87 | 87 | ||
88 | 88 | let k_totalPositionSize = "k_totalPositionSize" | |
89 | 89 | ||
90 | 90 | let k_totalLongPositionSize = "k_totalLongPositionSize" | |
91 | 91 | ||
92 | 92 | let k_totalShortPositionSize = "k_totalShortPositionSize" | |
93 | 93 | ||
94 | 94 | let k_openInterestNotional = "k_openInterestNotional" | |
95 | 95 | ||
96 | 96 | let k_openInterestShort = "k_openInterestShort" | |
97 | 97 | ||
98 | 98 | let k_openInterestLong = "k_openInterestLong" | |
99 | 99 | ||
100 | + | let k_lastTx = "k_lastTx" | |
101 | + | ||
100 | 102 | let k_coordinatorAddress = "k_coordinatorAddress" | |
101 | 103 | ||
102 | 104 | let k_vault_address = "k_vault_address" | |
103 | 105 | ||
104 | 106 | let k_admin_address = "k_admin_address" | |
105 | 107 | ||
106 | 108 | let k_admin_public_key = "k_admin_public_key" | |
107 | 109 | ||
108 | 110 | let k_quote_asset = "k_quote_asset" | |
109 | 111 | ||
110 | 112 | let k_quote_staking = "k_quote_staking" | |
111 | 113 | ||
112 | 114 | let k_staking_address = "k_staking_address" | |
113 | 115 | ||
114 | 116 | let k_miner_address = "k_miner_address" | |
115 | 117 | ||
116 | 118 | let k_orders_address = "k_orders_address" | |
117 | 119 | ||
118 | 120 | let k_referral_address = "k_referral_address" | |
119 | 121 | ||
120 | - | let k_collateral_address = "k_collateral_address" | |
121 | - | ||
122 | 122 | let k_exchange_address = "k_exchange_address" | |
123 | 123 | ||
124 | 124 | let k_nft_manager_address = "k_nft_manager_address" | |
125 | - | ||
126 | - | let k_trader_market_asset_collateral = "k_trader_market_asset_collateral" | |
127 | 125 | ||
128 | 126 | func toCompositeKey (_key,_address) = ((_key + "_") + _address) | |
129 | 127 | ||
130 | 128 | ||
131 | 129 | func coordinator () = valueOrErrorMessage(addressFromString(getStringValue(this, k_coordinatorAddress)), "Coordinator not set") | |
132 | 130 | ||
133 | 131 | ||
134 | 132 | func adminAddress () = addressFromString(getStringValue(coordinator(), k_admin_address)) | |
135 | 133 | ||
136 | 134 | ||
137 | 135 | func adminPublicKey () = fromBase58String(getStringValue(coordinator(), k_admin_public_key)) | |
138 | 136 | ||
139 | 137 | ||
140 | 138 | func quoteAsset () = fromBase58String(getStringValue(coordinator(), k_quote_asset)) | |
141 | 139 | ||
142 | 140 | ||
143 | 141 | func quoteAssetStaking () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_quote_staking)), "Quote asset staking not set") | |
144 | 142 | ||
145 | 143 | ||
146 | 144 | func stakingAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_staking_address)), "Staking not set") | |
147 | 145 | ||
148 | 146 | ||
149 | 147 | func vaultAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_vault_address)), "Vault not set") | |
150 | 148 | ||
151 | 149 | ||
152 | 150 | func minerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_miner_address)), "Miner not set") | |
153 | 151 | ||
154 | 152 | ||
155 | 153 | func ordersAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_orders_address)), "Orders not set") | |
156 | 154 | ||
157 | 155 | ||
158 | 156 | func referralAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_referral_address)), "Referral not set") | |
159 | 157 | ||
160 | 158 | ||
161 | 159 | func nftManagerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_nft_manager_address)), "NFT Manager not set") | |
162 | 160 | ||
163 | 161 | ||
164 | - | func collateralAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_collateral_address)), "Collateral Manager not set") | |
165 | - | ||
166 | - | ||
167 | - | func swapAddress () = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(coordinator(), k_exchange_address), "No swap address")), "Invalid swap address") | |
168 | - | ||
169 | - | ||
170 | - | let k_whitelist_asset = "k_whitelist_asset" | |
171 | - | ||
172 | - | func isWhitelistAsset (_assetId) = valueOrElse(getBoolean(collateralAddress(), toCompositeKey(k_whitelist_asset, _assetId)), false) | |
173 | - | ||
174 | - | ||
175 | 162 | let k_token_param = "k_token_param" | |
176 | 163 | ||
177 | 164 | let k_token_type = "k_token_type" | |
178 | 165 | ||
179 | 166 | let FEE_REDUCTION_TOKEN_TYPE = "fee_reduction" | |
180 | 167 | ||
181 | 168 | let DIR_LONG = 1 | |
182 | 169 | ||
183 | 170 | let DIR_SHORT = 2 | |
184 | 171 | ||
185 | 172 | let TWAP_INTERVAL = 15 | |
186 | 173 | ||
187 | - | let ORACLE_INTERVAL = 15 | |
188 | - | ||
189 | 174 | let SECONDS = 1000 | |
190 | 175 | ||
191 | 176 | let DECIMAL_NUMBERS = 6 | |
192 | 177 | ||
193 | 178 | let DECIMAL_UNIT = (1 * (((((10 * 10) * 10) * 10) * 10) * 10)) | |
194 | 179 | ||
180 | + | let MINUTES_IN_YEAR = (525600 * DECIMAL_UNIT) | |
181 | + | ||
195 | 182 | let ONE_DAY = (86400 * DECIMAL_UNIT) | |
196 | - | ||
197 | - | let ALL_FEES = 100 | |
198 | 183 | ||
199 | 184 | let PNL_OPTION_SPOT = 1 | |
200 | 185 | ||
201 | 186 | let PNL_OPTION_ORACLE = 2 | |
202 | 187 | ||
203 | 188 | func s (_x) = (toString(_x) + ",") | |
204 | 189 | ||
205 | 190 | ||
206 | 191 | func divd (_x,_y) = fraction(_x, DECIMAL_UNIT, _y, HALFEVEN) | |
207 | 192 | ||
208 | 193 | ||
209 | 194 | func muld (_x,_y) = fraction(_x, _y, DECIMAL_UNIT, HALFEVEN) | |
210 | 195 | ||
211 | 196 | ||
212 | 197 | func sqrtd (_x) = sqrt(_x, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN) | |
213 | 198 | ||
214 | 199 | ||
215 | 200 | func powd (_x,_y) = pow(_x, DECIMAL_NUMBERS, _y, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN) | |
216 | 201 | ||
217 | 202 | ||
218 | 203 | func bdivd (_x,_y) = fraction(_x, toBigInt(DECIMAL_UNIT), _y, HALFEVEN) | |
219 | 204 | ||
220 | 205 | ||
221 | 206 | func bmuld (_x,_y) = fraction(_x, _y, toBigInt(DECIMAL_UNIT), HALFEVEN) | |
222 | 207 | ||
223 | 208 | ||
224 | 209 | func bsqrtd (_x) = sqrtBigInt(_x, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN) | |
225 | 210 | ||
226 | 211 | ||
227 | 212 | func bpowd (_x,_y) = pow(_x, DECIMAL_NUMBERS, _y, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN) | |
228 | 213 | ||
229 | 214 | ||
230 | 215 | func abs (_x) = if ((_x > 0)) | |
231 | 216 | then _x | |
232 | 217 | else -(_x) | |
233 | 218 | ||
234 | 219 | ||
235 | 220 | func vmax (_x,_y) = if ((_x >= _y)) | |
236 | 221 | then _x | |
237 | 222 | else _y | |
238 | 223 | ||
239 | 224 | ||
240 | - | func listToStr (_list) = { | |
241 | - | func _join (accumulator,val) = ((accumulator + val) + ",") | |
242 | - | ||
243 | - | let newListStr = { | |
244 | - | let $l = _list | |
245 | - | let $s = size($l) | |
246 | - | let $acc0 = "" | |
247 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
248 | - | then $a | |
249 | - | else _join($a, $l[$i]) | |
250 | - | ||
251 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
252 | - | then $a | |
253 | - | else throw("List size exceeds 20") | |
254 | - | ||
255 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20) | |
256 | - | } | |
257 | - | let newListStrU = dropRight(newListStr, 1) | |
258 | - | let newListStrR = if ((take(newListStrU, 1) == ",")) | |
259 | - | then drop(newListStrU, 1) | |
260 | - | else newListStrU | |
261 | - | newListStrR | |
262 | - | } | |
225 | + | func listToStr (_list) = if ((size(_list) == 0)) | |
226 | + | then "" | |
227 | + | else makeString(_list, ",") | |
263 | 228 | ||
264 | 229 | ||
265 | - | func strToList (_str) = split(_str, ",") | |
230 | + | func strToList (_str) = if ((_str == "")) | |
231 | + | then nil | |
232 | + | else split(_str, ",") | |
266 | 233 | ||
267 | 234 | ||
268 | 235 | func pushToQueue (_list,_maxSize,_value) = if ((size(_list) > _maxSize)) | |
269 | 236 | then (removeByIndex(_list, 0) :+ _value) | |
270 | 237 | else (_list :+ _value) | |
271 | 238 | ||
272 | 239 | ||
273 | 240 | func int (k) = valueOrErrorMessage(getInteger(this, k), ("no value for " + k)) | |
274 | 241 | ||
275 | 242 | ||
276 | 243 | func intOr (k,def) = valueOrElse(getInteger(this, k), def) | |
277 | 244 | ||
278 | 245 | ||
279 | 246 | func strA (_address,_key) = { | |
280 | 247 | let val = valueOrErrorMessage(getString(_address, _key), ("No value for key " + _key)) | |
281 | 248 | val | |
282 | 249 | } | |
283 | 250 | ||
284 | 251 | ||
285 | 252 | func intA (_address,_key) = { | |
286 | 253 | let val = valueOrErrorMessage(getInteger(_address, _key), ("No value for key " + _key)) | |
287 | 254 | val | |
288 | 255 | } | |
289 | 256 | ||
290 | 257 | ||
291 | 258 | func cbalance () = int(k_balance) | |
292 | 259 | ||
293 | 260 | ||
294 | 261 | func fee () = int(k_fee) | |
262 | + | ||
263 | + | ||
264 | + | func rolloverFeeRate () = int(k_rolloverFee) | |
295 | 265 | ||
296 | 266 | ||
297 | 267 | func initMarginRatio () = int(k_initMarginRatio) | |
298 | 268 | ||
299 | 269 | ||
300 | 270 | func qtAstR () = int(k_quoteAssetReserve) | |
301 | 271 | ||
302 | 272 | ||
303 | 273 | func bsAstR () = int(k_baseAssetReserve) | |
304 | 274 | ||
305 | 275 | ||
306 | 276 | func qtAstW () = intOr(k_quoteAssetWeight, DECIMAL_UNIT) | |
307 | 277 | ||
308 | 278 | ||
309 | 279 | func bsAstW () = intOr(k_baseAssetWeight, DECIMAL_UNIT) | |
310 | 280 | ||
311 | 281 | ||
312 | 282 | func totalPositionSize () = int(k_totalPositionSize) | |
313 | 283 | ||
314 | 284 | ||
315 | 285 | func openInterestNotional () = int(k_openInterestNotional) | |
316 | 286 | ||
317 | 287 | ||
318 | 288 | func openInterestShort () = int(k_openInterestShort) | |
319 | 289 | ||
320 | 290 | ||
321 | 291 | func openInterestLong () = int(k_openInterestLong) | |
322 | 292 | ||
323 | 293 | ||
324 | 294 | func nextFundingBlockTimestamp () = int(k_nextFundingBlock) | |
325 | 295 | ||
326 | 296 | ||
327 | 297 | func fundingPeriodRaw () = int(k_fundingPeriod) | |
328 | 298 | ||
329 | 299 | ||
330 | 300 | func fundingPeriodDecimal () = (fundingPeriodRaw() * DECIMAL_UNIT) | |
331 | 301 | ||
332 | 302 | ||
333 | 303 | func fundingPeriodSeconds () = (fundingPeriodRaw() * SECONDS) | |
334 | 304 | ||
335 | 305 | ||
336 | 306 | func maintenanceMarginRatio () = int(k_maintenanceMarginRatio) | |
337 | 307 | ||
338 | 308 | ||
339 | 309 | func liquidationFeeRatio () = int(k_liquidationFeeRatio) | |
340 | 310 | ||
341 | 311 | ||
342 | 312 | func partialLiquidationRatio () = int(k_partialLiquidationRatio) | |
343 | 313 | ||
344 | 314 | ||
345 | 315 | func spreadLimit () = int(k_spreadLimit) | |
346 | 316 | ||
347 | 317 | ||
348 | 318 | func maxPriceImpact () = int(k_maxPriceImpact) | |
349 | 319 | ||
350 | 320 | ||
351 | 321 | func maxPriceSpread () = int(k_maxPriceSpread) | |
352 | 322 | ||
353 | 323 | ||
354 | 324 | func maxOpenNotional () = int(k_maxOpenNotional) | |
355 | 325 | ||
356 | 326 | ||
357 | 327 | func latestLongCumulativePremiumFraction () = int(k_latestLongCumulativePremiumFraction) | |
358 | 328 | ||
359 | 329 | ||
360 | 330 | func latestShortCumulativePremiumFraction () = int(k_latestShortCumulativePremiumFraction) | |
361 | 331 | ||
362 | 332 | ||
363 | 333 | func totalShortPositionSize () = int(k_totalShortPositionSize) | |
364 | 334 | ||
365 | 335 | ||
366 | 336 | func totalLongPositionSize () = int(k_totalLongPositionSize) | |
367 | 337 | ||
368 | 338 | ||
369 | 339 | func lastSequence () = intOr(k_sequence, 0) | |
370 | 340 | ||
371 | 341 | ||
372 | 342 | func feeToStakersPercent () = int(k_feeToStakersPercent) | |
373 | 343 | ||
374 | 344 | ||
375 | 345 | func maxOracleDelay () = int(k_maxOracleDelay) | |
376 | 346 | ||
377 | 347 | ||
348 | + | func lastTimestamp () = lastBlock.timestamp | |
349 | + | ||
350 | + | ||
378 | 351 | func getActualCaller (i) = valueOrElse(getString(ordersAddress(), "k_sender"), toString(i.caller)) | |
379 | 352 | ||
380 | 353 | ||
381 | 354 | func requireMoreMarginRatio (_marginRatio,_baseMarginRatio,_largerThanOrEqualTo) = { | |
382 | 355 | let remainingMarginRatio = (_marginRatio - _baseMarginRatio) | |
383 | 356 | if (if (_largerThanOrEqualTo) | |
384 | 357 | then (0 > remainingMarginRatio) | |
385 | 358 | else false) | |
386 | 359 | then throw(((("Invalid margin: " + toString(_marginRatio)) + " < ") + toString(_baseMarginRatio))) | |
387 | 360 | else if (if (!(_largerThanOrEqualTo)) | |
388 | 361 | then (remainingMarginRatio >= 0) | |
389 | 362 | else false) | |
390 | 363 | then throw(((("Invalid margin: " + toString(_marginRatio)) + " > ") + toString(_baseMarginRatio))) | |
391 | 364 | else true | |
392 | 365 | } | |
393 | 366 | ||
394 | 367 | ||
395 | 368 | func latestCumulativePremiumFraction (_positionSize) = if ((_positionSize == 0)) | |
396 | 369 | then throw("Should not be called with _positionSize == 0") | |
397 | 370 | else if ((_positionSize > 0)) | |
398 | 371 | then latestLongCumulativePremiumFraction() | |
399 | 372 | else latestShortCumulativePremiumFraction() | |
400 | 373 | ||
401 | 374 | ||
402 | 375 | func getPosition (_trader) = { | |
403 | 376 | let positionSizeOpt = getInteger(this, toCompositeKey(k_positionSize, _trader)) | |
404 | 377 | match positionSizeOpt { | |
405 | 378 | case positionSize: Int => | |
406 | - | $ | |
379 | + | $Tuple5(positionSize, getIntegerValue(this, toCompositeKey(k_positionMargin, _trader)), getIntegerValue(this, toCompositeKey(k_positionOpenNotional, _trader)), getIntegerValue(this, toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _trader)), getIntegerValue(this, toCompositeKey(k_positionLastUpdatedTimestamp, _trader))) | |
407 | 380 | case _ => | |
408 | - | $ | |
381 | + | $Tuple5(0, 0, 0, 0, 0) | |
409 | 382 | } | |
410 | 383 | } | |
411 | 384 | ||
412 | 385 | ||
413 | 386 | func getPositionAsset (_trader) = { | |
414 | 387 | let positionAssetOpt = getString(this, toCompositeKey(k_positionAsset, _trader)) | |
415 | 388 | match positionAssetOpt { | |
416 | 389 | case positionAsset: String => | |
417 | 390 | positionAsset | |
418 | 391 | case _ => | |
419 | 392 | toBase58String(quoteAsset()) | |
420 | 393 | } | |
421 | 394 | } | |
422 | 395 | ||
423 | 396 | ||
424 | 397 | func getPositionFee (_trader) = { | |
425 | 398 | let positionFeeOpt = getInteger(this, toCompositeKey(k_positionFee, _trader)) | |
426 | 399 | match positionFeeOpt { | |
427 | 400 | case positionFee: Int => | |
428 | 401 | positionFee | |
429 | 402 | case _ => | |
430 | 403 | fee() | |
431 | 404 | } | |
432 | 405 | } | |
433 | 406 | ||
434 | 407 | ||
435 | 408 | func requireOpenPosition (_trader) = if ((getPosition(_trader)._1 == 0)) | |
436 | 409 | then throw("No open position") | |
437 | 410 | else true | |
411 | + | ||
412 | + | ||
413 | + | func getOracleData (key) = { | |
414 | + | let oracleDataStr = getString(this, key) | |
415 | + | if (if (isDefined(oracleDataStr)) | |
416 | + | then (value(oracleDataStr) != "") | |
417 | + | else false) | |
418 | + | then { | |
419 | + | let oracleData = split(value(oracleDataStr), ",") | |
420 | + | let oracleAddress = valueOrErrorMessage(addressFromString(oracleData[0]), ("Invalid oracle address in: " + value(oracleDataStr))) | |
421 | + | let priceKey = oracleData[1] | |
422 | + | let blockKey = oracleData[2] | |
423 | + | let openKey = oracleData[3] | |
424 | + | $Tuple4(oracleAddress, priceKey, blockKey, openKey) | |
425 | + | } | |
426 | + | else unit | |
427 | + | } | |
438 | 428 | ||
439 | 429 | ||
440 | 430 | func initialized () = valueOrElse(getBoolean(this, k_initialized), false) | |
441 | 431 | ||
442 | 432 | ||
443 | 433 | func paused () = valueOrElse(getBoolean(this, k_paused), false) | |
444 | 434 | ||
445 | 435 | ||
446 | 436 | func closeOnly () = valueOrElse(getBoolean(this, k_closeOnly), false) | |
447 | 437 | ||
448 | 438 | ||
449 | 439 | func updateReserve (_isAdd,_quoteAssetAmount,_baseAssetAmount) = if (_isAdd) | |
450 | 440 | then { | |
451 | 441 | let newBase = (bsAstR() - _baseAssetAmount) | |
452 | 442 | if ((0 >= newBase)) | |
453 | 443 | then throw("Tx lead to base asset reserve <= 0, revert") | |
454 | 444 | else $Tuple3((qtAstR() + _quoteAssetAmount), newBase, (totalPositionSize() + _baseAssetAmount)) | |
455 | 445 | } | |
456 | 446 | else { | |
457 | 447 | let newQuote = (qtAstR() - _quoteAssetAmount) | |
458 | 448 | if ((0 >= newQuote)) | |
459 | 449 | then throw("Tx lead to base quote reserve <= 0, revert") | |
460 | 450 | else $Tuple3(newQuote, (bsAstR() + _baseAssetAmount), (totalPositionSize() - _baseAssetAmount)) | |
461 | 451 | } | |
462 | 452 | ||
463 | 453 | ||
464 | 454 | func calcInvariant (_qtAstR,_bsAstR) = { | |
465 | 455 | let bqtAstR = toBigInt(_qtAstR) | |
466 | 456 | let bbsAstR = toBigInt(_bsAstR) | |
467 | 457 | bmuld(bqtAstR, bbsAstR) | |
468 | 458 | } | |
469 | 459 | ||
470 | 460 | ||
471 | 461 | func swapInput (_isAdd,_quoteAssetAmount) = { | |
472 | 462 | let _qtAstR = qtAstR() | |
473 | 463 | let _bsAstR = bsAstR() | |
474 | 464 | let _qtAstW = qtAstW() | |
475 | 465 | let _bsAstW = bsAstW() | |
476 | 466 | let quoteAssetAmountAdjusted = divd(_quoteAssetAmount, _qtAstW) | |
477 | 467 | let k = calcInvariant(_qtAstR, _bsAstR) | |
478 | 468 | let quoteAssetReserveAfter = if (_isAdd) | |
479 | 469 | then (_qtAstR + quoteAssetAmountAdjusted) | |
480 | 470 | else (_qtAstR - quoteAssetAmountAdjusted) | |
481 | 471 | let baseAssetReserveAfter = toInt(bdivd(k, toBigInt(quoteAssetReserveAfter))) | |
482 | 472 | let amountBaseAssetBoughtAbs = abs((baseAssetReserveAfter - _bsAstR)) | |
483 | 473 | let amountBaseAssetBought = if (_isAdd) | |
484 | 474 | then amountBaseAssetBoughtAbs | |
485 | 475 | else -(amountBaseAssetBoughtAbs) | |
486 | - | let $ | |
487 | - | let quoteAssetReserveAfter1 = $ | |
488 | - | let baseAssetReserveAfter1 = $ | |
489 | - | let totalPositionSizeAfter1 = $ | |
476 | + | let $t01725917429 = updateReserve(_isAdd, quoteAssetAmountAdjusted, amountBaseAssetBoughtAbs) | |
477 | + | let quoteAssetReserveAfter1 = $t01725917429._1 | |
478 | + | let baseAssetReserveAfter1 = $t01725917429._2 | |
479 | + | let totalPositionSizeAfter1 = $t01725917429._3 | |
490 | 480 | let priceBefore = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW)) | |
491 | 481 | let marketPrice = divd(_quoteAssetAmount, amountBaseAssetBoughtAbs) | |
492 | 482 | let priceDiff = abs((priceBefore - marketPrice)) | |
493 | 483 | let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff))) | |
494 | 484 | let maxPriceImpactValue = maxPriceImpact() | |
495 | 485 | if ((priceImpact > maxPriceImpactValue)) | |
496 | 486 | then throw(((((((((((((("Price impact " + toString(priceImpact)) + " > max price impact ") + toString(maxPriceImpactValue)) + " before quote asset: ") + toString(_qtAstR)) + " before base asset: ") + toString(_bsAstR)) + " quote asset amount to exchange: ") + toString(_quoteAssetAmount)) + " price before: ") + toString(priceBefore)) + " marketPrice: ") + toString(marketPrice))) | |
497 | 487 | else $Tuple4(amountBaseAssetBought, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1) | |
498 | 488 | } | |
499 | 489 | ||
500 | 490 | ||
501 | - | func calcRemainMarginWithFundingPayment (_oldPositionSize,_oldPositionMargin,_oldPositionCumulativePremiumFraction,_marginDelta) = { | |
491 | + | func calcRolloverFee (_oldPositionMargin,_oldPositionLastUpdatedTimestamp) = { | |
492 | + | let positionMinutes = ((((lastTimestamp() - _oldPositionLastUpdatedTimestamp) / 1000) / 60) * DECIMAL_UNIT) | |
493 | + | let rolloverFee = divd(muld(muld(_oldPositionMargin, positionMinutes), rolloverFeeRate()), MINUTES_IN_YEAR) | |
494 | + | rolloverFee | |
495 | + | } | |
496 | + | ||
497 | + | ||
498 | + | func calcRemainMarginWithFundingPaymentAndRolloverFee (_oldPositionSize,_oldPositionMargin,_oldPositionCumulativePremiumFraction,_oldPositionLastUpdatedTimestamp,_marginDelta) = { | |
502 | 499 | let fundingPayment = if ((_oldPositionSize != 0)) | |
503 | 500 | then { | |
504 | 501 | let _latestCumulativePremiumFraction = latestCumulativePremiumFraction(_oldPositionSize) | |
505 | 502 | muld((_latestCumulativePremiumFraction - _oldPositionCumulativePremiumFraction), _oldPositionSize) | |
506 | 503 | } | |
507 | 504 | else 0 | |
508 | - | let signedMargin = ((_marginDelta - fundingPayment) + _oldPositionMargin) | |
509 | - | let $t01879518922 = if ((0 > signedMargin)) | |
505 | + | let rolloverFee = calcRolloverFee(_oldPositionMargin, _oldPositionLastUpdatedTimestamp) | |
506 | + | let signedMargin = (((_marginDelta - rolloverFee) - fundingPayment) + _oldPositionMargin) | |
507 | + | let $t01968419811 = if ((0 > signedMargin)) | |
510 | 508 | then $Tuple2(0, abs(signedMargin)) | |
511 | 509 | else $Tuple2(abs(signedMargin), 0) | |
512 | - | let remainMargin = $ | |
513 | - | let badDebt = $ | |
514 | - | $ | |
510 | + | let remainMargin = $t01968419811._1 | |
511 | + | let badDebt = $t01968419811._2 | |
512 | + | $Tuple4(remainMargin, badDebt, fundingPayment, rolloverFee) | |
515 | 513 | } | |
516 | 514 | ||
517 | 515 | ||
518 | 516 | func swapOutputWithReserves (_isAdd,_baseAssetAmount,_checkMaxPriceImpact,_quoteAssetReserve,_quoteAssetWeight,_baseAssetReserve,_baseAssetWeight) = { | |
519 | 517 | let priceBefore = divd(muld(_quoteAssetReserve, _quoteAssetWeight), muld(_baseAssetReserve, _baseAssetWeight)) | |
520 | 518 | if ((_baseAssetAmount == 0)) | |
521 | 519 | then throw("Invalid base asset amount") | |
522 | 520 | else { | |
523 | 521 | let k = calcInvariant(_quoteAssetReserve, _baseAssetReserve) | |
524 | 522 | let baseAssetPoolAmountAfter = if (_isAdd) | |
525 | 523 | then (_baseAssetReserve + _baseAssetAmount) | |
526 | 524 | else (_baseAssetReserve - _baseAssetAmount) | |
527 | 525 | let quoteAssetAfter = toInt(bdivd(k, toBigInt(baseAssetPoolAmountAfter))) | |
528 | 526 | let quoteAssetDelta = abs((quoteAssetAfter - _quoteAssetReserve)) | |
529 | 527 | let quoteAssetSold = muld(quoteAssetDelta, _quoteAssetWeight) | |
530 | 528 | let maxPriceImpactValue = maxPriceImpact() | |
531 | - | let $ | |
532 | - | let quoteAssetReserveAfter1 = $ | |
533 | - | let baseAssetReserveAfter1 = $ | |
534 | - | let totalPositionSizeAfter1 = $ | |
529 | + | let $t02107321235 = updateReserve(!(_isAdd), quoteAssetDelta, _baseAssetAmount) | |
530 | + | let quoteAssetReserveAfter1 = $t02107321235._1 | |
531 | + | let baseAssetReserveAfter1 = $t02107321235._2 | |
532 | + | let totalPositionSizeAfter1 = $t02107321235._3 | |
535 | 533 | let marketPrice = divd(quoteAssetSold, _baseAssetAmount) | |
536 | 534 | let priceDiff = abs((priceBefore - marketPrice)) | |
537 | 535 | let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff))) | |
538 | 536 | if (if ((priceImpact > maxPriceImpactValue)) | |
539 | 537 | then _checkMaxPriceImpact | |
540 | 538 | else false) | |
541 | 539 | then throw(((((((((((((("Price impact " + toString(priceImpact)) + " > max price impact ") + toString(maxPriceImpactValue)) + " before quote asset: ") + toString(_quoteAssetReserve)) + " before base asset: ") + toString(_baseAssetReserve)) + " base asset amount to exchange: ") + toString(_baseAssetAmount)) + " price before: ") + toString(priceBefore)) + " market price: ") + toString(marketPrice))) | |
542 | 540 | else $Tuple7(quoteAssetSold, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, (totalLongPositionSize() - (if (_isAdd) | |
543 | 541 | then abs(_baseAssetAmount) | |
544 | 542 | else 0)), (totalShortPositionSize() - (if (!(_isAdd)) | |
545 | 543 | then abs(_baseAssetAmount) | |
546 | 544 | else 0)), priceImpact) | |
547 | 545 | } | |
548 | 546 | } | |
549 | 547 | ||
550 | 548 | ||
551 | 549 | func swapOutput (_isAdd,_baseAssetAmount,_checkMaxPriceImpact) = swapOutputWithReserves(_isAdd, _baseAssetAmount, _checkMaxPriceImpact, qtAstR(), qtAstW(), bsAstR(), bsAstW()) | |
552 | 550 | ||
553 | 551 | ||
554 | - | func getOraclePrice () = { | |
555 | - | let oracle = valueOrErrorMessage(addressFromString(getStringValue(this, k_ora)), "") | |
556 | - | let priceKey = getStringValue(this, k_ora_key) | |
552 | + | func getOraclePriceValue (oracle,priceKey,blockKey) = { | |
557 | 553 | let lastValue = valueOrErrorMessage(getInteger(oracle, priceKey), ((("Can not get oracle price. Oracle: " + toString(oracle)) + " key: ") + priceKey)) | |
558 | - | let blockKey = valueOrElse(getString(this, k_ora_block_key), "") | |
559 | 554 | if ((blockKey != "")) | |
560 | 555 | then { | |
561 | 556 | let currentBlock = lastBlock.height | |
562 | 557 | let lastOracleBlock = valueOrErrorMessage(getInteger(oracle, blockKey), ((("Can not get oracle block. Oracle: " + toString(oracle)) + " key: ") + blockKey)) | |
563 | 558 | if (((currentBlock - lastOracleBlock) > maxOracleDelay())) | |
564 | 559 | then throw(((("Oracle stale data. Last oracle block: " + toString(lastOracleBlock)) + " current block: ") + toString(currentBlock))) | |
565 | 560 | else lastValue | |
566 | 561 | } | |
567 | 562 | else lastValue | |
568 | 563 | } | |
569 | 564 | ||
570 | 565 | ||
566 | + | func getOraclePrice () = { | |
567 | + | let baseOracle = valueOrErrorMessage(getOracleData(k_baseOracle), "No base asset oracle data") | |
568 | + | let baseOraclePrice = getOraclePriceValue(baseOracle._1, baseOracle._2, baseOracle._3) | |
569 | + | let quoteOracle = getOracleData(k_quoteOracle) | |
570 | + | let quoteOraclePrice = if (isDefined(quoteOracle)) | |
571 | + | then { | |
572 | + | let quoteOracleV = value(quoteOracle) | |
573 | + | getOraclePriceValue(quoteOracleV._1, quoteOracleV._2, quoteOracleV._3) | |
574 | + | } | |
575 | + | else DECIMAL_UNIT | |
576 | + | divd(baseOraclePrice, quoteOraclePrice) | |
577 | + | } | |
578 | + | ||
579 | + | ||
571 | 580 | func isMarketClosed () = { | |
572 | - | let oracle = valueOrErrorMessage(addressFromString(getStringValue(this, k_ora)), "") | |
573 | - | let openKey = valueOrElse(getString(this, k_ora_open_key), "") | |
581 | + | let baseOracle = valueOrErrorMessage(getOracleData(k_baseOracle), "No base asset oracle data") | |
582 | + | let oracle = baseOracle._1 | |
583 | + | let openKey = baseOracle._4 | |
574 | 584 | if ((openKey != "")) | |
575 | 585 | then { | |
576 | 586 | let isOpen = valueOrErrorMessage(getBoolean(oracle, openKey), ((("Can not get oracle is open/closed. Oracle: " + toString(oracle)) + " key: ") + openKey)) | |
577 | 587 | !(isOpen) | |
578 | 588 | } | |
579 | 589 | else false | |
580 | 590 | } | |
581 | 591 | ||
582 | 592 | ||
583 | 593 | func absPriceDiff (_oraclePrice,_quoteAssetReserve,_baseAssetReserve,_qtAstW,_bsAstW) = { | |
584 | 594 | let priceAfter = divd(muld(_quoteAssetReserve, _qtAstW), muld(_baseAssetReserve, _bsAstW)) | |
585 | 595 | let averagePrice = divd((_oraclePrice + priceAfter), (2 * DECIMAL_UNIT)) | |
586 | 596 | let absPriceDiff = divd(abs((_oraclePrice - priceAfter)), averagePrice) | |
587 | 597 | absPriceDiff | |
588 | 598 | } | |
589 | 599 | ||
590 | 600 | ||
591 | 601 | func requireNotOverSpreadLimit (_quoteAssetReserve,_baseAssetReserve) = { | |
592 | 602 | let oraclePrice = getOraclePrice() | |
593 | 603 | let _qtAstW = qtAstW() | |
594 | 604 | let _bsAstW = bsAstW() | |
595 | 605 | let absPriceDiffBefore = absPriceDiff(oraclePrice, qtAstR(), bsAstR(), _qtAstW, _bsAstW) | |
596 | 606 | let absPriceDiffAfter = absPriceDiff(oraclePrice, _quoteAssetReserve, _baseAssetReserve, _qtAstW, _bsAstW) | |
597 | 607 | if (if ((absPriceDiffAfter > maxPriceSpread())) | |
598 | 608 | then (absPriceDiffAfter > absPriceDiffBefore) | |
599 | 609 | else false) | |
600 | 610 | then throw(((("Price spread " + toString(absPriceDiffAfter)) + " > max price spread ") + toString(maxPriceSpread()))) | |
601 | 611 | else true | |
602 | 612 | } | |
603 | 613 | ||
604 | 614 | ||
605 | 615 | func requireNotOverMaxOpenNotional (_longOpenNotional,_shortOpenNotional) = { | |
606 | 616 | let _maxOpenNotional = maxOpenNotional() | |
607 | 617 | if ((_longOpenNotional > _maxOpenNotional)) | |
608 | 618 | then throw(((("Long open notional " + toString(_longOpenNotional)) + " > max open notional ") + toString(_maxOpenNotional))) | |
609 | 619 | else if ((_shortOpenNotional > _maxOpenNotional)) | |
610 | 620 | then throw(((("Short open notional " + toString(_shortOpenNotional)) + " > max open notional ") + toString(_maxOpenNotional))) | |
611 | 621 | else true | |
612 | 622 | } | |
613 | 623 | ||
614 | 624 | ||
615 | 625 | func getSpotPrice () = { | |
616 | 626 | let _quoteAssetReserve = qtAstR() | |
617 | 627 | let _baseAssetReserve = bsAstR() | |
618 | 628 | let _qtAstW = qtAstW() | |
619 | 629 | let _bsAstW = bsAstW() | |
620 | 630 | divd(muld(_quoteAssetReserve, _qtAstW), muld(_baseAssetReserve, _bsAstW)) | |
621 | 631 | } | |
622 | 632 | ||
623 | 633 | ||
624 | 634 | func isOverFluctuationLimit () = { | |
625 | 635 | let oraclePrice = getOraclePrice() | |
626 | 636 | let currentPrice = getSpotPrice() | |
627 | 637 | (divd(abs((oraclePrice - currentPrice)), oraclePrice) > spreadLimit()) | |
628 | 638 | } | |
629 | 639 | ||
630 | 640 | ||
631 | 641 | func getPositionAdjustedOpenNotional (_positionSize,_option,_quoteAssetReserve,_quoteAssetWeight,_baseAssetReserve,_baseAssetWeight) = { | |
632 | 642 | let positionSizeAbs = abs(_positionSize) | |
633 | 643 | let isShort = (0 > _positionSize) | |
634 | 644 | let positionNotional = if ((_option == PNL_OPTION_SPOT)) | |
635 | 645 | then { | |
636 | - | let $t02520525425 = swapOutputWithReserves(!(isShort), positionSizeAbs, false, _quoteAssetReserve, _quoteAssetWeight, _baseAssetReserve, _baseAssetWeight) | |
637 | - | let outPositionNotional = $t02520525425._1 | |
638 | - | let x1 = $t02520525425._2 | |
639 | - | let x2 = $t02520525425._3 | |
640 | - | let x3 = $t02520525425._4 | |
646 | + | let outPositionNotional = swapOutputWithReserves(!(isShort), positionSizeAbs, false, _quoteAssetReserve, _quoteAssetWeight, _baseAssetReserve, _baseAssetWeight)._1 | |
641 | 647 | outPositionNotional | |
642 | 648 | } | |
643 | 649 | else muld(positionSizeAbs, getOraclePrice()) | |
644 | 650 | positionNotional | |
645 | 651 | } | |
646 | 652 | ||
647 | 653 | ||
648 | 654 | func getPositionNotionalAndUnrealizedPnlByValues (_positionSize,_positionOpenNotional,_quoteAssetReserve,_quoteAssetWeight,_baseAssetReserve,_baseAssetWeight,_option) = if ((_positionSize == 0)) | |
649 | 655 | then throw("Invalid position size") | |
650 | 656 | else { | |
651 | 657 | let isShort = (0 > _positionSize) | |
652 | 658 | let positionNotional = getPositionAdjustedOpenNotional(_positionSize, _option, _quoteAssetReserve, _quoteAssetWeight, _baseAssetReserve, _baseAssetWeight) | |
653 | 659 | let unrealizedPnl = if (isShort) | |
654 | 660 | then (_positionOpenNotional - positionNotional) | |
655 | 661 | else (positionNotional - _positionOpenNotional) | |
656 | 662 | $Tuple2(positionNotional, unrealizedPnl) | |
657 | 663 | } | |
658 | 664 | ||
659 | 665 | ||
660 | 666 | func getPositionNotionalAndUnrealizedPnl (_trader,_option) = { | |
661 | - | let $ | |
662 | - | let positionSize = $ | |
663 | - | let positionMargin = $ | |
664 | - | let positionOpenNotional = $ | |
665 | - | let positionLstUpdCPF = $ | |
667 | + | let $t02911329241 = getPosition(_trader) | |
668 | + | let positionSize = $t02911329241._1 | |
669 | + | let positionMargin = $t02911329241._2 | |
670 | + | let positionOpenNotional = $t02911329241._3 | |
671 | + | let positionLstUpdCPF = $t02911329241._4 | |
666 | 672 | getPositionNotionalAndUnrealizedPnlByValues(positionSize, positionOpenNotional, qtAstR(), qtAstW(), bsAstR(), bsAstW(), _option) | |
667 | 673 | } | |
668 | 674 | ||
669 | 675 | ||
670 | 676 | func calcMarginRatio (_remainMargin,_badDebt,_positionNotional) = divd((_remainMargin - _badDebt), _positionNotional) | |
671 | 677 | ||
672 | 678 | ||
673 | 679 | func getMarginRatioByOption (_trader,_option) = { | |
674 | - | let $t02748727598 = getPosition(_trader) | |
675 | - | let positionSize = $t02748727598._1 | |
676 | - | let positionMargin = $t02748727598._2 | |
677 | - | let pon = $t02748727598._3 | |
678 | - | let positionLstUpdCPF = $t02748727598._4 | |
679 | - | let $t02760427697 = getPositionNotionalAndUnrealizedPnl(_trader, _option) | |
680 | - | let positionNotional = $t02760427697._1 | |
681 | - | let unrealizedPnl = $t02760427697._2 | |
682 | - | let $t02770227868 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
683 | - | let remainMargin = $t02770227868._1 | |
684 | - | let badDebt = $t02770227868._2 | |
680 | + | let $t02975629897 = getPosition(_trader) | |
681 | + | let positionSize = $t02975629897._1 | |
682 | + | let positionMargin = $t02975629897._2 | |
683 | + | let pon = $t02975629897._3 | |
684 | + | let positionLastUpdatedCPF = $t02975629897._4 | |
685 | + | let positionTimestamp = $t02975629897._5 | |
686 | + | let $t02990329996 = getPositionNotionalAndUnrealizedPnl(_trader, _option) | |
687 | + | let positionNotional = $t02990329996._1 | |
688 | + | let unrealizedPnl = $t02990329996._2 | |
689 | + | let $t03000130213 = calcRemainMarginWithFundingPaymentAndRolloverFee(positionSize, positionMargin, positionLastUpdatedCPF, positionTimestamp, unrealizedPnl) | |
690 | + | let remainMargin = $t03000130213._1 | |
691 | + | let badDebt = $t03000130213._2 | |
685 | 692 | calcMarginRatio(remainMargin, badDebt, positionNotional) | |
686 | 693 | } | |
687 | 694 | ||
688 | 695 | ||
689 | 696 | func getMarginRatio (_trader) = getMarginRatioByOption(_trader, PNL_OPTION_SPOT) | |
690 | 697 | ||
691 | 698 | ||
692 | 699 | func getPartialLiquidationAmount (_trader,_positionSize) = { | |
693 | 700 | let maximumRatio = vmax(partialLiquidationRatio(), (DECIMAL_UNIT - divd(getMarginRatio(_trader), maintenanceMarginRatio()))) | |
694 | 701 | let maxExchangedPositionSize = muld(abs(_positionSize), maximumRatio) | |
695 | 702 | let swapResult = swapOutput((_positionSize > 0), maxExchangedPositionSize, false) | |
696 | 703 | let maxExchangedQuoteAssetAmount = swapResult._1 | |
697 | 704 | let priceImpact = swapResult._7 | |
698 | 705 | if ((maxPriceImpact() > priceImpact)) | |
699 | - | then maxExchangedQuoteAssetAmount | |
700 | - | else { | |
701 | - | let exchangedPositionSize = muld(abs(_positionSize), partialLiquidationRatio()) | |
702 | - | let exchangedQuoteAssetAmount = swapOutput((_positionSize > 0), exchangedPositionSize, false)._1 | |
703 | - | exchangedQuoteAssetAmount | |
704 | - | } | |
706 | + | then maxExchangedPositionSize | |
707 | + | else muld(abs(_positionSize), partialLiquidationRatio()) | |
705 | 708 | } | |
706 | 709 | ||
707 | 710 | ||
708 | - | func internalClosePosition (_trader,_checkMaxPriceImpact) = { | |
709 | - | let $t02910829236 = getPosition(_trader) | |
710 | - | let positionSize = $t02910829236._1 | |
711 | - | let positionMargin = $t02910829236._2 | |
712 | - | let positionOpenNotional = $t02910829236._3 | |
713 | - | let positionLstUpdCPF = $t02910829236._4 | |
714 | - | let unrealizedPnl = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)._2 | |
715 | - | let $t02933129499 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
716 | - | let remainMargin = $t02933129499._1 | |
717 | - | let badDebt = $t02933129499._2 | |
718 | - | let exchangedPositionSize = -(positionSize) | |
719 | - | let realizedPnl = unrealizedPnl | |
720 | - | let marginToVault = -(remainMargin) | |
721 | - | let $t02962629900 = swapOutput((positionSize > 0), abs(positionSize), _checkMaxPriceImpact) | |
722 | - | let exchangedQuoteAssetAmount = $t02962629900._1 | |
723 | - | let quoteAssetReserveAfter = $t02962629900._2 | |
724 | - | let baseAssetReserveAfter = $t02962629900._3 | |
725 | - | let totalPositionSizeAfter = $t02962629900._4 | |
726 | - | let totalLongAfter = $t02962629900._5 | |
727 | - | let totalShortAfter = $t02962629900._6 | |
728 | - | let openInterestNotionalAfter = (openInterestNotional() - positionOpenNotional) | |
729 | - | $Tuple13(exchangedPositionSize, badDebt, realizedPnl, marginToVault, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, exchangedQuoteAssetAmount, totalLongAfter, totalShortAfter, (openInterestLong() - (if ((positionSize > 0)) | |
730 | - | then positionOpenNotional | |
731 | - | else 0)), (openInterestShort() - (if ((0 > positionSize)) | |
732 | - | then positionOpenNotional | |
733 | - | else 0))) | |
711 | + | func internalClosePosition (_trader,_size,_fee,_minQuoteAssetAmount,_addToMargin,_checkMaxPriceImpact) = { | |
712 | + | let $t03125731413 = getPosition(_trader) | |
713 | + | let oldPositionSize = $t03125731413._1 | |
714 | + | let oldPositionMargin = $t03125731413._2 | |
715 | + | let oldPositionOpenNotional = $t03125731413._3 | |
716 | + | let oldPositionLstUpdCPF = $t03125731413._4 | |
717 | + | let oldPositionTimestamp = $t03125731413._5 | |
718 | + | let isLongPosition = (oldPositionSize > 0) | |
719 | + | let absOldPositionSize = abs(oldPositionSize) | |
720 | + | if (if ((absOldPositionSize >= _size)) | |
721 | + | then (_size > 0) | |
722 | + | else false) | |
723 | + | then { | |
724 | + | let isPartialClose = (absOldPositionSize > _size) | |
725 | + | let $t03170532156 = swapOutput((oldPositionSize > 0), _size, _checkMaxPriceImpact) | |
726 | + | let exchangedQuoteAssetAmount = $t03170532156._1 | |
727 | + | let quoteAssetReserveAfter = $t03170532156._2 | |
728 | + | let baseAssetReserveAfter = $t03170532156._3 | |
729 | + | let totalPositionSizeAfter = $t03170532156._4 | |
730 | + | let exchangedPositionSize = if ((oldPositionSize > 0)) | |
731 | + | then -(_size) | |
732 | + | else _size | |
733 | + | let $t03237132578 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
734 | + | let oldPositionNotional = $t03237132578._1 | |
735 | + | let unrealizedPnl = $t03237132578._2 | |
736 | + | let realizedRatio = divd(abs(exchangedPositionSize), absOldPositionSize) | |
737 | + | let realizedPnl = muld(unrealizedPnl, realizedRatio) | |
738 | + | let $t03291933165 = calcRemainMarginWithFundingPaymentAndRolloverFee(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, oldPositionTimestamp, unrealizedPnl) | |
739 | + | let remainMarginBefore = $t03291933165._1 | |
740 | + | let x1 = $t03291933165._2 | |
741 | + | let x2 = $t03291933165._3 | |
742 | + | let rolloverFee = $t03291933165._4 | |
743 | + | let positionBadDebt = calcRemainMarginWithFundingPaymentAndRolloverFee(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, oldPositionTimestamp, realizedPnl)._2 | |
744 | + | let realizedCloseFee = muld(muld(oldPositionNotional, realizedRatio), _fee) | |
745 | + | let unrealizedPnlAfter = (unrealizedPnl - realizedPnl) | |
746 | + | let remainOpenNotional = if ((oldPositionSize > 0)) | |
747 | + | then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter) | |
748 | + | else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount) | |
749 | + | let newPositionSize = (oldPositionSize + exchangedPositionSize) | |
750 | + | let $t03457134957 = if ((newPositionSize == 0)) | |
751 | + | then $Tuple2(0, 0) | |
752 | + | else $Tuple2(abs(remainOpenNotional), latestCumulativePremiumFraction(newPositionSize)) | |
753 | + | let newPositionOpenNotional = $t03457134957._1 | |
754 | + | let newPositionLstUpdCPF = $t03457134957._2 | |
755 | + | let openNotionalDelta = (oldPositionOpenNotional - newPositionOpenNotional) | |
756 | + | let marginRatio = getMarginRatioByOption(_trader, PNL_OPTION_SPOT) | |
757 | + | let newPositionMarginWithSameRatio = if ((oldPositionSize > 0)) | |
758 | + | then (muld((newPositionOpenNotional + unrealizedPnlAfter), marginRatio) - unrealizedPnlAfter) | |
759 | + | else (muld((newPositionOpenNotional - unrealizedPnlAfter), marginRatio) - unrealizedPnlAfter) | |
760 | + | let marginToTraderRaw = ((remainMarginBefore - (newPositionMarginWithSameRatio + unrealizedPnlAfter)) - realizedCloseFee) | |
761 | + | let marginToTrader = if ((0 > marginToTraderRaw)) | |
762 | + | then throw("Invalid internalClosePosition params: unable to pay fee") | |
763 | + | else marginToTraderRaw | |
764 | + | let newPositionMargin = if (_addToMargin) | |
765 | + | then (newPositionMarginWithSameRatio + marginToTrader) | |
766 | + | else newPositionMarginWithSameRatio | |
767 | + | if (if ((_minQuoteAssetAmount != 0)) | |
768 | + | then (_minQuoteAssetAmount > exchangedQuoteAssetAmount) | |
769 | + | else false) | |
770 | + | then throw(((("Limit error: " + toString(exchangedQuoteAssetAmount)) + " < ") + toString(_minQuoteAssetAmount))) | |
771 | + | else $Tuple17(newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF, positionBadDebt, realizedPnl, if (if (_addToMargin) | |
772 | + | then isPartialClose | |
773 | + | else false) | |
774 | + | then 0 | |
775 | + | else marginToTrader, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, (openInterestNotional() - openNotionalDelta), (totalLongPositionSize() - (if (isLongPosition) | |
776 | + | then abs(exchangedPositionSize) | |
777 | + | else 0)), (totalShortPositionSize() - (if (!(isLongPosition)) | |
778 | + | then abs(exchangedPositionSize) | |
779 | + | else 0)), (openInterestLong() - (if (isLongPosition) | |
780 | + | then openNotionalDelta | |
781 | + | else 0)), (openInterestShort() - (if (!(isLongPosition)) | |
782 | + | then openNotionalDelta | |
783 | + | else 0)), (realizedCloseFee + rolloverFee), exchangedQuoteAssetAmount) | |
784 | + | } | |
785 | + | else throw("Invalid internalClosePosition params: invalid position size") | |
734 | 786 | } | |
735 | 787 | ||
736 | 788 | ||
737 | 789 | func getTwapSpotPrice () = { | |
738 | - | let minuteId = (( | |
790 | + | let minuteId = ((lastTimestamp() / 1000) / 60) | |
739 | 791 | let startMinuteId = (minuteId - TWAP_INTERVAL) | |
740 | 792 | let listStr = valueOrElse(getString(this, k_lastDataStr), "") | |
741 | 793 | let list = split(listStr, ",") | |
742 | - | func filterFn (accumulator,next) = if ((startMinuteId >= | |
794 | + | func filterFn (accumulator,next) = if ((startMinuteId >= valueOrErrorMessage(parseInt(next), ("getTwapSpotPrice: invalid int: " + listStr)))) | |
743 | 795 | then (accumulator :+ parseIntValue(next)) | |
744 | 796 | else accumulator | |
745 | 797 | ||
746 | 798 | let listF = { | |
747 | 799 | let $l = list | |
748 | 800 | let $s = size($l) | |
749 | 801 | let $acc0 = nil | |
750 | 802 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
751 | 803 | then $a | |
752 | 804 | else filterFn($a, $l[$i]) | |
753 | 805 | ||
754 | 806 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
755 | 807 | then $a | |
756 | 808 | else throw("List size exceeds 20") | |
757 | 809 | ||
758 | 810 | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20) | |
759 | 811 | } | |
760 | 812 | let maxIndex = if ((size(listF) > 0)) | |
761 | 813 | then max(listF) | |
762 | - | else | |
814 | + | else valueOrErrorMessage(parseInt(list[0]), ("getTwapSpotPrice: invalid int: " + listStr)) | |
763 | 815 | let lastMinuteId = valueOrElse(getInteger(this, k_lastMinuteId), 0) | |
764 | 816 | let endLastCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(lastMinuteId))), 0) | |
765 | 817 | let endLastPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(lastMinuteId))), 0) | |
766 | 818 | let nowCumulativePrice = (endLastCumulativePrice + ((minuteId - lastMinuteId) * endLastPrice)) | |
767 | 819 | let startLastCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(maxIndex))), 0) | |
768 | 820 | let startLastPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(maxIndex))), 0) | |
769 | 821 | let startCumulativePrice = (startLastCumulativePrice + ((startMinuteId - maxIndex) * startLastPrice)) | |
770 | 822 | ((nowCumulativePrice - startCumulativePrice) / TWAP_INTERVAL) | |
771 | 823 | } | |
772 | 824 | ||
773 | 825 | ||
774 | 826 | func getTerminalAmmState () = { | |
775 | 827 | let _positionSize = totalPositionSize() | |
776 | 828 | if ((_positionSize == 0)) | |
777 | 829 | then $Tuple2(qtAstR(), bsAstR()) | |
778 | 830 | else { | |
779 | 831 | let direction = (_positionSize > 0) | |
780 | - | let $ | |
781 | - | let currentNetMarketValue = $ | |
782 | - | let terminalQuoteAssetReserve = $ | |
783 | - | let terminalBaseAssetReserve = $ | |
832 | + | let $t03956039739 = swapOutput(direction, abs(_positionSize), false) | |
833 | + | let currentNetMarketValue = $t03956039739._1 | |
834 | + | let terminalQuoteAssetReserve = $t03956039739._2 | |
835 | + | let terminalBaseAssetReserve = $t03956039739._3 | |
784 | 836 | $Tuple2(terminalQuoteAssetReserve, terminalBaseAssetReserve) | |
785 | 837 | } | |
786 | 838 | } | |
787 | 839 | ||
788 | 840 | ||
789 | 841 | func getQuoteAssetWeight (baseAssetReserve,totalPositionSize,quoteAssetReserve,targetPrice) = { | |
790 | 842 | let b = toBigInt(baseAssetReserve) | |
791 | 843 | let sz = toBigInt(totalPositionSize) | |
792 | 844 | let q = toBigInt(quoteAssetReserve) | |
793 | 845 | let p = toBigInt(targetPrice) | |
794 | 846 | let k = bmuld(q, b) | |
795 | 847 | let newB = (b + sz) | |
796 | 848 | let newQ = bdivd(k, newB) | |
797 | 849 | let z = bdivd(newQ, newB) | |
798 | 850 | let result = bdivd(p, z) | |
799 | 851 | toInt(result) | |
800 | 852 | } | |
801 | 853 | ||
802 | 854 | ||
803 | 855 | func getSyncTerminalPrice (_terminalPrice,_qtAstR,_bsAstR) = { | |
804 | 856 | let _positionSize = totalPositionSize() | |
805 | 857 | if ((_positionSize == 0)) | |
806 | 858 | then { | |
807 | 859 | let newQtAstW = divd(muld(_terminalPrice, _bsAstR), _qtAstR) | |
808 | 860 | $Tuple3(newQtAstW, DECIMAL_UNIT, 0) | |
809 | 861 | } | |
810 | 862 | else { | |
811 | 863 | let direction = (_positionSize > 0) | |
812 | 864 | let currentNetMarketValue = swapOutput(direction, abs(_positionSize), false)._1 | |
813 | 865 | let newQtAstW = getQuoteAssetWeight(_bsAstR, _positionSize, _qtAstR, _terminalPrice) | |
814 | 866 | let newBsAstW = DECIMAL_UNIT | |
815 | 867 | let marginToVault = getPositionNotionalAndUnrealizedPnlByValues(_positionSize, currentNetMarketValue, _qtAstR, newQtAstW, _bsAstR, newBsAstW, PNL_OPTION_SPOT)._2 | |
816 | 868 | $Tuple3(newQtAstW, newBsAstW, marginToVault) | |
817 | 869 | } | |
818 | 870 | } | |
819 | 871 | ||
820 | 872 | ||
821 | 873 | func getFunding () = { | |
822 | 874 | let underlyingPrice = getOraclePrice() | |
823 | 875 | let spotTwapPrice = getTwapSpotPrice() | |
824 | 876 | let premium = (spotTwapPrice - underlyingPrice) | |
825 | 877 | if (if (if ((totalShortPositionSize() == 0)) | |
826 | 878 | then true | |
827 | 879 | else (totalLongPositionSize() == 0)) | |
828 | 880 | then true | |
829 | 881 | else isMarketClosed()) | |
830 | 882 | then $Tuple2(0, 0) | |
831 | 883 | else if ((0 > premium)) | |
832 | 884 | then { | |
833 | 885 | let shortPremiumFraction = divd(muld(premium, fundingPeriodDecimal()), ONE_DAY) | |
834 | 886 | let longPremiumFraction = divd(muld(shortPremiumFraction, totalShortPositionSize()), totalLongPositionSize()) | |
835 | 887 | $Tuple2(shortPremiumFraction, longPremiumFraction) | |
836 | 888 | } | |
837 | 889 | else { | |
838 | 890 | let longPremiumFraction = divd(muld(premium, fundingPeriodDecimal()), ONE_DAY) | |
839 | 891 | let shortPremiumFraction = divd(muld(longPremiumFraction, totalLongPositionSize()), totalShortPositionSize()) | |
840 | 892 | $Tuple2(shortPremiumFraction, longPremiumFraction) | |
841 | 893 | } | |
842 | 894 | } | |
843 | 895 | ||
844 | 896 | ||
845 | 897 | func getAdjustedFee (_artifactId,_baseFeeDiscount) = { | |
846 | 898 | let baseFeeRaw = fee() | |
847 | 899 | let baseFee = muld(baseFeeRaw, _baseFeeDiscount) | |
848 | - | let $ | |
900 | + | let $t04260043095 = if ((_artifactId != "")) | |
849 | 901 | then { | |
850 | 902 | let artifactKind = strA(nftManagerAddress(), toCompositeKey(k_token_type, _artifactId)) | |
851 | 903 | if ((artifactKind == FEE_REDUCTION_TOKEN_TYPE)) | |
852 | 904 | then { | |
853 | 905 | let reduction = intA(nftManagerAddress(), toCompositeKey(k_token_param, _artifactId)) | |
854 | 906 | let adjustedFee = muld(baseFee, reduction) | |
855 | 907 | $Tuple2(adjustedFee, true) | |
856 | 908 | } | |
857 | 909 | else throw("Invalid attached artifact") | |
858 | 910 | } | |
859 | 911 | else $Tuple2(baseFee, false) | |
860 | - | let adjustedFee = $ | |
861 | - | let burnArtifact = $ | |
912 | + | let adjustedFee = $t04260043095._1 | |
913 | + | let burnArtifact = $t04260043095._2 | |
862 | 914 | $Tuple2(adjustedFee, burnArtifact) | |
863 | 915 | } | |
864 | 916 | ||
865 | 917 | ||
866 | 918 | func isSameAssetOrNoPosition (_trader,_assetId) = { | |
867 | 919 | let oldPositionSize = getPosition(_trader)._1 | |
868 | 920 | if ((oldPositionSize == 0)) | |
869 | 921 | then true | |
870 | 922 | else (getPositionAsset(_trader) == _assetId) | |
871 | 923 | } | |
872 | 924 | ||
873 | 925 | ||
874 | 926 | func isSameAsset (_trader,_assetId) = (getPositionAsset(_trader) == _assetId) | |
875 | 927 | ||
876 | 928 | ||
877 | - | func getBorrowedByTraderInMarketKey (_amm,_assetId,_trader) = ((((((k_trader_market_asset_collateral + "_") + _amm) + "_") + _assetId) + "_") + _trader) | |
878 | - | ||
879 | - | ||
880 | - | func getBorrowedByTrader (_trader) = { | |
881 | - | let positionAsset = getPositionAsset(_trader) | |
882 | - | if ((positionAsset == toBase58String(quoteAsset()))) | |
883 | - | then $Tuple2(0, positionAsset) | |
884 | - | else { | |
885 | - | let key = getBorrowedByTraderInMarketKey(toString(this), positionAsset, _trader) | |
886 | - | let borrow = valueOrElse(getInteger(collateralAddress(), key), 0) | |
887 | - | $Tuple2(borrow, positionAsset) | |
888 | - | } | |
889 | - | } | |
890 | - | ||
891 | - | ||
892 | 929 | func getForTraderWithArtifact (_trader,_artifactId) = { | |
893 | 930 | let doGetFeeDiscount = invoke(minerAddress(), "computeFeeDiscount", [_trader], nil) | |
894 | 931 | if ((doGetFeeDiscount == doGetFeeDiscount)) | |
895 | 932 | then { | |
896 | 933 | let feeDiscount = match doGetFeeDiscount { | |
897 | 934 | case x: Int => | |
898 | 935 | x | |
899 | 936 | case _ => | |
900 | 937 | throw("Invalid computeFeeDiscount result") | |
901 | 938 | } | |
902 | - | let $ | |
903 | - | let adjustedFee = $ | |
904 | - | let burnArtifact = $ | |
939 | + | let $t04377543849 = getAdjustedFee(_artifactId, feeDiscount) | |
940 | + | let adjustedFee = $t04377543849._1 | |
941 | + | let burnArtifact = $t04377543849._2 | |
905 | 942 | $Tuple2(adjustedFee, burnArtifact) | |
906 | 943 | } | |
907 | 944 | else throw("Strict value is not equal to itself.") | |
908 | 945 | } | |
909 | 946 | ||
910 | 947 | ||
911 | 948 | func getArtifactId (i) = { | |
912 | 949 | let artifactId = if ((size(i.payments) > 1)) | |
913 | 950 | then toBase58String(valueOrErrorMessage(i.payments[1].assetId, "Invalid artifactId")) | |
914 | 951 | else "" | |
915 | 952 | artifactId | |
916 | 953 | } | |
917 | 954 | ||
918 | 955 | ||
919 | 956 | func distributeFee (_feeAmount) = { | |
920 | 957 | let feeToStakers = muld(_feeAmount, feeToStakersPercent()) | |
921 | 958 | let feeToVault = (_feeAmount - feeToStakers) | |
922 | 959 | $Tuple2(feeToStakers, feeToVault) | |
923 | 960 | } | |
924 | 961 | ||
925 | 962 | ||
926 | - | func updateSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional,_feeToStakersPercent,_maxOracleDelay) = [IntegerEntry(k_initMarginRatio, _initMarginRatio), IntegerEntry(k_maintenanceMarginRatio, _mmr), IntegerEntry(k_liquidationFeeRatio, _liquidationFeeRatio), IntegerEntry(k_fundingPeriod, _fundingPeriod), IntegerEntry(k_fee, _fee), IntegerEntry(k_spreadLimit, _spreadLimit), IntegerEntry(k_maxPriceImpact, _maxPriceImpact), IntegerEntry(k_partialLiquidationRatio, _partialLiquidationRatio), IntegerEntry(k_maxPriceSpread, _maxPriceSpread), IntegerEntry(k_maxOpenNotional, _maxOpenNotional), IntegerEntry(k_feeToStakersPercent, _feeToStakersPercent), IntegerEntry(k_maxOracleDelay, _feeToStakersPercent)] | |
963 | + | func updateSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional,_feeToStakersPercent,_maxOracleDelay,_rolloverFee) = [IntegerEntry(k_initMarginRatio, _initMarginRatio), IntegerEntry(k_maintenanceMarginRatio, _mmr), IntegerEntry(k_liquidationFeeRatio, _liquidationFeeRatio), IntegerEntry(k_fundingPeriod, _fundingPeriod), IntegerEntry(k_fee, _fee), IntegerEntry(k_spreadLimit, _spreadLimit), IntegerEntry(k_maxPriceImpact, _maxPriceImpact), IntegerEntry(k_partialLiquidationRatio, _partialLiquidationRatio), IntegerEntry(k_maxPriceSpread, _maxPriceSpread), IntegerEntry(k_maxOpenNotional, _maxOpenNotional), IntegerEntry(k_feeToStakersPercent, _feeToStakersPercent), IntegerEntry(k_maxOracleDelay, _feeToStakersPercent), IntegerEntry(k_rolloverFee, _rolloverFee)] | |
927 | 964 | ||
928 | 965 | ||
929 | 966 | func updateFunding (_nextFundingBlock,_latestLongCumulativePremiumFraction,_latestShortCumulativePremiumFraction,_longFundingRate,_shortFundingRate) = [IntegerEntry(k_nextFundingBlock, _nextFundingBlock), IntegerEntry(k_latestLongCumulativePremiumFraction, _latestLongCumulativePremiumFraction), IntegerEntry(k_latestShortCumulativePremiumFraction, _latestShortCumulativePremiumFraction), IntegerEntry(k_longFundingRate, _longFundingRate), IntegerEntry(k_shortFundingRate, _shortFundingRate)] | |
930 | - | ||
931 | - | ||
932 | - | func updatePositionAsset (_address,_assetId) = [StringEntry(toCompositeKey(k_positionAsset, _address), _assetId)] | |
933 | 967 | ||
934 | 968 | ||
935 | 969 | func incrementPositionSequenceNumber (_isNewPosition,_address) = if (_isNewPosition) | |
936 | 970 | then { | |
937 | 971 | let currentSequence = lastSequence() | |
938 | 972 | [IntegerEntry(toCompositeKey(k_positionSequence, _address), (currentSequence + 1)), IntegerEntry(k_sequence, (currentSequence + 1))] | |
939 | 973 | } | |
940 | 974 | else nil | |
941 | 975 | ||
942 | 976 | ||
943 | 977 | func updatePositionFee (_isNewPosition,_address,_fee) = if (_isNewPosition) | |
944 | 978 | then [IntegerEntry(toCompositeKey(k_positionFee, _address), _fee)] | |
945 | 979 | else nil | |
946 | 980 | ||
947 | 981 | ||
948 | - | func updatePosition (_address,_size,_margin,_openNotional,_latestCumulativePremiumFraction) = [IntegerEntry(toCompositeKey(k_positionSize, _address), _size), IntegerEntry(toCompositeKey(k_positionMargin, _address), _margin), IntegerEntry(toCompositeKey(k_positionOpenNotional, _address), _openNotional), IntegerEntry(toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _address), _latestCumulativePremiumFraction)] | |
982 | + | func updatePosition (_address,_size,_margin,_openNotional,_latestCumulativePremiumFraction,_latestTimestamp) = [IntegerEntry(toCompositeKey(k_positionSize, _address), _size), IntegerEntry(toCompositeKey(k_positionMargin, _address), _margin), IntegerEntry(toCompositeKey(k_positionOpenNotional, _address), _openNotional), IntegerEntry(toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _address), _latestCumulativePremiumFraction), IntegerEntry(toCompositeKey(k_positionLastUpdatedTimestamp, _address), _latestTimestamp)] | |
949 | 983 | ||
950 | 984 | ||
951 | 985 | func appendTwap (_price) = { | |
952 | - | let minuteId = (( | |
986 | + | let minuteId = ((lastTimestamp() / 1000) / 60) | |
953 | 987 | let previousMinuteId = valueOrElse(getInteger(this, k_lastMinuteId), 0) | |
954 | 988 | if ((previousMinuteId > minuteId)) | |
955 | 989 | then throw("TWAP out-of-order") | |
956 | 990 | else { | |
957 | 991 | let lastMinuteId = if ((previousMinuteId == 0)) | |
958 | 992 | then minuteId | |
959 | 993 | else previousMinuteId | |
960 | 994 | if ((minuteId > previousMinuteId)) | |
961 | 995 | then { | |
962 | 996 | let prevCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(previousMinuteId))), 0) | |
963 | 997 | let prevPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(previousMinuteId))), _price) | |
964 | 998 | let lastCumulativePrice = (prevCumulativePrice + ((minuteId - lastMinuteId) * prevPrice)) | |
965 | 999 | let list = pushToQueue(strToList(valueOrElse(getString(this, k_lastDataStr), "")), TWAP_INTERVAL, toString(minuteId)) | |
966 | 1000 | [IntegerEntry(toCompositeKey(k_twapDataLastCumulativePrice, toString(minuteId)), lastCumulativePrice), IntegerEntry(toCompositeKey(k_twapDataLastPrice, toString(minuteId)), _price), IntegerEntry(toCompositeKey(k_twapDataPreviousMinuteId, toString(minuteId)), previousMinuteId), IntegerEntry(k_lastMinuteId, minuteId), StringEntry(k_lastDataStr, listToStr(list))] | |
967 | 1001 | } | |
968 | 1002 | else { | |
969 | 1003 | let twapDataPreviousMinuteId = valueOrElse(getInteger(this, toCompositeKey(k_twapDataPreviousMinuteId, toString(minuteId))), 0) | |
970 | 1004 | let prevCumulativePrice = valueOrElse(getInteger(this, toCompositeKey(k_twapDataLastCumulativePrice, toString(twapDataPreviousMinuteId))), 0) | |
971 | 1005 | let prevPrice = valueOrElse(getInteger(this, toCompositeKey(k_twapDataLastPrice, toString(twapDataPreviousMinuteId))), _price) | |
972 | 1006 | let lastCumulativePrice = (prevCumulativePrice + ((minuteId - twapDataPreviousMinuteId) * prevPrice)) | |
973 | 1007 | [IntegerEntry(toCompositeKey(k_twapDataLastCumulativePrice, toString(minuteId)), lastCumulativePrice), IntegerEntry(toCompositeKey(k_twapDataLastPrice, toString(minuteId)), _price)] | |
974 | 1008 | } | |
975 | 1009 | } | |
976 | 1010 | } | |
977 | 1011 | ||
978 | 1012 | ||
979 | 1013 | func updateAmmReserves (_qtAstR,_bsAstR) = [IntegerEntry(k_quoteAssetReserve, _qtAstR), IntegerEntry(k_baseAssetReserve, _bsAstR)] | |
980 | 1014 | ||
981 | 1015 | ||
982 | 1016 | func updateAmmWeights (_qtAstW,_bsAstW) = [IntegerEntry(k_quoteAssetWeight, _qtAstW), IntegerEntry(k_baseAssetWeight, _bsAstW)] | |
983 | 1017 | ||
984 | 1018 | ||
985 | 1019 | func updateAmm (_qtAstR,_bsAstR,_totalPositionSizeAfter,_openInterestNotional,_totalLongPositionSize,_totalShortPositionSize,_totalLongOpenNotional,_totalShortOpenNotional) = { | |
986 | 1020 | let _qtAstW = qtAstW() | |
987 | 1021 | let _bsAstW = bsAstW() | |
988 | 1022 | if (((_totalLongPositionSize - _totalShortPositionSize) != _totalPositionSizeAfter)) | |
989 | 1023 | then throw(((((("Invalid AMM state data: " + toString(_totalLongPositionSize)) + " + ") + toString(_totalShortPositionSize)) + " != ") + toString(_totalPositionSizeAfter))) | |
990 | 1024 | else ((updateAmmReserves(_qtAstR, _bsAstR) ++ [IntegerEntry(k_totalPositionSize, _totalPositionSizeAfter), IntegerEntry(k_openInterestNotional, _openInterestNotional), IntegerEntry(k_totalLongPositionSize, _totalLongPositionSize), IntegerEntry(k_totalShortPositionSize, _totalShortPositionSize), IntegerEntry(k_openInterestLong, _totalLongOpenNotional), IntegerEntry(k_openInterestShort, _totalShortOpenNotional)]) ++ appendTwap(divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW)))) | |
991 | 1025 | } | |
992 | 1026 | ||
993 | 1027 | ||
994 | - | func deletePosition (_address) = [DeleteEntry(toCompositeKey(k_positionSize, _address)), DeleteEntry(toCompositeKey(k_positionMargin, _address)), DeleteEntry(toCompositeKey(k_positionOpenNotional, _address)), DeleteEntry(toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _address)), DeleteEntry(toCompositeKey(k_positionAsset, _address))] | |
1028 | + | func deletePosition (_address) = [DeleteEntry(toCompositeKey(k_positionSize, _address)), DeleteEntry(toCompositeKey(k_positionMargin, _address)), DeleteEntry(toCompositeKey(k_positionOpenNotional, _address)), DeleteEntry(toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _address)), DeleteEntry(toCompositeKey(k_positionAsset, _address)), DeleteEntry(toCompositeKey(k_positionFee, _address)), DeleteEntry(toCompositeKey(k_positionLastUpdatedTimestamp, _address))] | |
995 | 1029 | ||
996 | 1030 | ||
997 | 1031 | func withdraw (_address,_amount) = { | |
998 | 1032 | let balance = assetBalance(this, quoteAsset()) | |
999 | 1033 | if ((_amount > balance)) | |
1000 | 1034 | then throw(((("Unable to withdraw " + toString(_amount)) + " from contract balance ") + toString(balance))) | |
1001 | 1035 | else [ScriptTransfer(_address, _amount, quoteAsset())] | |
1002 | 1036 | } | |
1003 | 1037 | ||
1004 | 1038 | ||
1005 | 1039 | func updateBalance (i) = if ((0 > i)) | |
1006 | 1040 | then throw("Balance") | |
1007 | 1041 | else [IntegerEntry(k_balance, i)] | |
1008 | 1042 | ||
1009 | 1043 | ||
1010 | 1044 | func transferFee (i) = [ScriptTransfer(stakingAddress(), i, quoteAsset())] | |
1011 | 1045 | ||
1012 | 1046 | ||
1013 | 1047 | func doBurnArtifact (_burnArtifact,i) = if (_burnArtifact) | |
1014 | 1048 | then [Burn(valueOrErrorMessage(i.payments[1].assetId, "Invalid artifact"), 1)] | |
1015 | 1049 | else nil | |
1016 | 1050 | ||
1017 | 1051 | ||
1018 | 1052 | @Callable(i) | |
1019 | 1053 | func pause () = if ((i.caller != adminAddress())) | |
1020 | 1054 | then throw("Invalid pause params") | |
1021 | 1055 | else [BooleanEntry(k_paused, true)] | |
1022 | 1056 | ||
1023 | 1057 | ||
1024 | 1058 | ||
1025 | 1059 | @Callable(i) | |
1026 | 1060 | func unpause () = if ((i.caller != adminAddress())) | |
1027 | 1061 | then throw("Invalid unpause params") | |
1028 | 1062 | else [BooleanEntry(k_paused, false)] | |
1029 | 1063 | ||
1030 | 1064 | ||
1031 | 1065 | ||
1032 | 1066 | @Callable(i) | |
1033 | 1067 | func setCloseOnly () = if ((i.caller != adminAddress())) | |
1034 | 1068 | then throw("Invalid setCloseOnly params") | |
1035 | 1069 | else [BooleanEntry(k_closeOnly, true)] | |
1036 | 1070 | ||
1037 | 1071 | ||
1038 | 1072 | ||
1039 | 1073 | @Callable(i) | |
1040 | 1074 | func unsetCloseOnly () = if ((i.caller != adminAddress())) | |
1041 | 1075 | then throw("Invalid unsetCloseOnly params") | |
1042 | 1076 | else [BooleanEntry(k_closeOnly, false)] | |
1043 | 1077 | ||
1044 | 1078 | ||
1045 | 1079 | ||
1046 | 1080 | @Callable(i) | |
1047 | 1081 | func addLiquidity (_quoteAssetAmount) = if (if ((i.caller != adminAddress())) | |
1048 | 1082 | then true | |
1049 | 1083 | else (0 >= _quoteAssetAmount)) | |
1050 | 1084 | then throw("Invalid addLiquidity params") | |
1051 | 1085 | else { | |
1052 | 1086 | let _qtAstR = qtAstR() | |
1053 | 1087 | let _bsAstR = bsAstR() | |
1054 | 1088 | let _qtAstW = qtAstW() | |
1055 | 1089 | let _bsAstW = bsAstW() | |
1056 | 1090 | let price = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW)) | |
1057 | 1091 | let qtAstRAfter = (_qtAstR + _quoteAssetAmount) | |
1058 | 1092 | let baseAssetAmountToAdd = (divd(muld(qtAstRAfter, _qtAstW), price) - _bsAstR) | |
1059 | 1093 | let bsAstRAfter = (_bsAstR + baseAssetAmountToAdd) | |
1060 | - | let $ | |
1061 | - | let newQuoteAssetWeight = $ | |
1062 | - | let newBaseAssetWeight = $ | |
1063 | - | let marginToVault = $ | |
1094 | + | let $t05325653407 = getSyncTerminalPrice(getOraclePrice(), qtAstRAfter, bsAstRAfter) | |
1095 | + | let newQuoteAssetWeight = $t05325653407._1 | |
1096 | + | let newBaseAssetWeight = $t05325653407._2 | |
1097 | + | let marginToVault = $t05325653407._3 | |
1064 | 1098 | let doExchangePnL = if ((marginToVault != 0)) | |
1065 | 1099 | then { | |
1066 | 1100 | let doExchangePnL = invoke(vaultAddress(), "exchangeFreeAndLocked", [marginToVault], nil) | |
1067 | 1101 | if ((doExchangePnL == doExchangePnL)) | |
1068 | 1102 | then nil | |
1069 | 1103 | else throw("Strict value is not equal to itself.") | |
1070 | 1104 | } | |
1071 | 1105 | else nil | |
1072 | 1106 | if ((doExchangePnL == doExchangePnL)) | |
1073 | 1107 | then (updateAmmReserves(qtAstRAfter, bsAstRAfter) ++ updateAmmWeights(newQuoteAssetWeight, newBaseAssetWeight)) | |
1074 | 1108 | else throw("Strict value is not equal to itself.") | |
1075 | 1109 | } | |
1076 | 1110 | ||
1077 | 1111 | ||
1078 | 1112 | ||
1079 | 1113 | @Callable(i) | |
1080 | 1114 | func removeLiquidity (_quoteAssetAmount) = if (if ((i.caller != adminAddress())) | |
1081 | 1115 | then true | |
1082 | 1116 | else (_quoteAssetAmount >= 0)) | |
1083 | 1117 | then throw("Invalid removeLiquidity params") | |
1084 | 1118 | else { | |
1085 | 1119 | let _qtAstR = qtAstR() | |
1086 | 1120 | let _bsAstR = bsAstR() | |
1087 | 1121 | let _qtAstW = qtAstW() | |
1088 | 1122 | let _bsAstW = bsAstW() | |
1089 | 1123 | let price = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW)) | |
1090 | 1124 | let qtAstRAfter = (_qtAstR - _quoteAssetAmount) | |
1091 | 1125 | let baseAssetAmountToRemove = abs((divd(muld(qtAstRAfter, _qtAstW), price) - _bsAstR)) | |
1092 | 1126 | let bsAstRAfter = (_bsAstR - baseAssetAmountToRemove) | |
1093 | - | let $ | |
1094 | - | let newQuoteAssetWeight = $ | |
1095 | - | let newBaseAssetWeight = $ | |
1096 | - | let marginToVault = $ | |
1127 | + | let $t05433954490 = getSyncTerminalPrice(getOraclePrice(), qtAstRAfter, bsAstRAfter) | |
1128 | + | let newQuoteAssetWeight = $t05433954490._1 | |
1129 | + | let newBaseAssetWeight = $t05433954490._2 | |
1130 | + | let marginToVault = $t05433954490._3 | |
1097 | 1131 | let doExchangePnL = if ((marginToVault != 0)) | |
1098 | 1132 | then { | |
1099 | 1133 | let doExchangePnL = invoke(vaultAddress(), "exchangeFreeAndLocked", [marginToVault], nil) | |
1100 | 1134 | if ((doExchangePnL == doExchangePnL)) | |
1101 | 1135 | then nil | |
1102 | 1136 | else throw("Strict value is not equal to itself.") | |
1103 | 1137 | } | |
1104 | 1138 | else nil | |
1105 | 1139 | if ((doExchangePnL == doExchangePnL)) | |
1106 | 1140 | then (updateAmmReserves(qtAstRAfter, bsAstRAfter) ++ updateAmmWeights(newQuoteAssetWeight, newBaseAssetWeight)) | |
1107 | 1141 | else throw("Strict value is not equal to itself.") | |
1108 | 1142 | } | |
1109 | 1143 | ||
1110 | 1144 | ||
1111 | 1145 | ||
1112 | 1146 | @Callable(i) | |
1113 | - | func changeSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional,_feeToStakersPercent,_maxOracleDelay) = if ((i.caller != adminAddress())) | |
1147 | + | func changeSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional,_feeToStakersPercent,_maxOracleDelay,_rolloverFee) = if ((i.caller != adminAddress())) | |
1114 | 1148 | then throw("Invalid changeSettings params") | |
1115 | - | else updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread, _maxOpenNotional, _feeToStakersPercent, _maxOracleDelay) | |
1149 | + | else updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread, _maxOpenNotional, _feeToStakersPercent, _maxOracleDelay, _rolloverFee) | |
1116 | 1150 | ||
1117 | 1151 | ||
1118 | 1152 | ||
1119 | 1153 | @Callable(i) | |
1120 | - | func initialize (_qtAstR,_bsAstR,_fundingPeriod,_initMarginRatio,_mmr,_liquidationFeeRatio,_fee,_ | |
1154 | + | func initialize (_qtAstR,_bsAstR,_fundingPeriod,_initMarginRatio,_mmr,_liquidationFeeRatio,_fee,_baseOracleData,_quoteOracleData,_coordinator,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional,_feeToStakersPercent,_maxOracleDelay,_rolloverFee) = if (if (if (if (if (if (if (if (if (if (if (if (if (if (if (if (if ((0 >= _qtAstR)) | |
1121 | 1155 | then true | |
1122 | 1156 | else (0 >= _bsAstR)) | |
1123 | 1157 | then true | |
1124 | 1158 | else (0 >= _fundingPeriod)) | |
1125 | 1159 | then true | |
1126 | 1160 | else (0 >= _initMarginRatio)) | |
1127 | 1161 | then true | |
1128 | 1162 | else (0 >= _mmr)) | |
1129 | 1163 | then true | |
1130 | 1164 | else (0 >= _liquidationFeeRatio)) | |
1131 | 1165 | then true | |
1132 | 1166 | else (0 >= _fee)) | |
1133 | 1167 | then true | |
1134 | 1168 | else (0 >= _spreadLimit)) | |
1135 | 1169 | then true | |
1136 | 1170 | else (0 >= _maxPriceImpact)) | |
1137 | 1171 | then true | |
1138 | 1172 | else (0 >= _partialLiquidationRatio)) | |
1139 | 1173 | then true | |
1140 | 1174 | else (0 >= _maxPriceSpread)) | |
1141 | 1175 | then true | |
1142 | 1176 | else (0 >= _maxOpenNotional)) | |
1143 | 1177 | then true | |
1144 | 1178 | else (0 >= _feeToStakersPercent)) | |
1145 | 1179 | then true | |
1146 | 1180 | else (_feeToStakersPercent > DECIMAL_UNIT)) | |
1147 | 1181 | then true | |
1148 | 1182 | else (0 >= _maxOracleDelay)) | |
1149 | 1183 | then true | |
1184 | + | else (0 >= _rolloverFee)) | |
1185 | + | then true | |
1150 | 1186 | else initialized()) | |
1151 | 1187 | then throw("Invalid initialize parameters") | |
1152 | - | else ((((updateAmm(_qtAstR, _bsAstR, 0, 0, 0, 0, 0, 0) ++ updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread, _maxOpenNotional, _feeToStakersPercent, _maxOracleDelay)) ++ updateFunding(( | |
1188 | + | else ((((updateAmm(_qtAstR, _bsAstR, 0, 0, 0, 0, 0, 0) ++ updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread, _maxOpenNotional, _feeToStakersPercent, _maxOracleDelay, _rolloverFee)) ++ updateFunding((lastTimestamp() + _fundingPeriod), 0, 0, 0, 0)) ++ updateBalance(0)) ++ [BooleanEntry(k_initialized, true), StringEntry(k_baseOracle, _baseOracleData), StringEntry(k_quoteOracle, _quoteOracleData), StringEntry(k_coordinatorAddress, _coordinator)]) | |
1153 | 1189 | ||
1154 | 1190 | ||
1155 | 1191 | ||
1156 | 1192 | @Callable(i) | |
1157 | 1193 | func increasePosition (_direction,_leverage,_minBaseAssetAmount,_refLink) = { | |
1158 | 1194 | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1159 | 1195 | if ((sync == sync)) | |
1160 | 1196 | then { | |
1161 | - | let _trader = getActualCaller(i) | |
1162 | - | let _rawAmount = i.payments[0].amount | |
1163 | - | let _assetId = i.payments[0].assetId | |
1164 | - | let _assetIdStr = toBase58String(value(_assetId)) | |
1165 | - | let isQuoteAsset = (_assetId == quoteAsset()) | |
1166 | - | let isCollateralAsset = isWhitelistAsset(_assetIdStr) | |
1167 | - | if (if (if (if (if (if (if (if (if (if ((_direction != DIR_LONG)) | |
1168 | - | then (_direction != DIR_SHORT) | |
1169 | - | else false) | |
1170 | - | then true | |
1171 | - | else (0 >= _rawAmount)) | |
1172 | - | then true | |
1173 | - | else !(initialized())) | |
1174 | - | then true | |
1175 | - | else if (!(isQuoteAsset)) | |
1176 | - | then !(isCollateralAsset) | |
1177 | - | else false) | |
1178 | - | then true | |
1179 | - | else !(isSameAssetOrNoPosition(_trader, _assetIdStr))) | |
1180 | - | then true | |
1181 | - | else !(requireMoreMarginRatio(divd(DECIMAL_UNIT, _leverage), initMarginRatio(), true))) | |
1182 | - | then true | |
1183 | - | else paused()) | |
1184 | - | then true | |
1185 | - | else closeOnly()) | |
1186 | - | then true | |
1187 | - | else isMarketClosed()) | |
1188 | - | then throw("Invalid increasePosition parameters") | |
1189 | - | else { | |
1190 | - | let $t05100951158 = getForTraderWithArtifact(_trader, getArtifactId(i)) | |
1191 | - | let adjustedFee = $t05100951158._1 | |
1192 | - | let burnArtifact = $t05100951158._2 | |
1193 | - | let _amount = divd(_rawAmount, (muld(adjustedFee, _leverage) + DECIMAL_UNIT)) | |
1194 | - | let rawFeeAmount = (_rawAmount - _amount) | |
1195 | - | let distributeFeeAmount = if (isCollateralAsset) | |
1196 | - | then { | |
1197 | - | let doBorrow = invoke(collateralAddress(), "borrow", [_trader], [AttachedPayment(_assetId, _amount)]) | |
1198 | - | if ((doBorrow == doBorrow)) | |
1199 | - | then { | |
1200 | - | let balanceBefore = assetBalance(this, quoteAsset()) | |
1201 | - | if ((balanceBefore == balanceBefore)) | |
1202 | - | then { | |
1203 | - | let doSwap = invoke(swapAddress(), "swap", [toBase58String(quoteAsset()), 0], [AttachedPayment(_assetId, rawFeeAmount)]) | |
1204 | - | if ((doSwap == doSwap)) | |
1205 | - | then { | |
1206 | - | let balanceAfter = assetBalance(this, quoteAsset()) | |
1207 | - | if ((balanceAfter == balanceAfter)) | |
1208 | - | then { | |
1209 | - | let exchangedAmount = (balanceAfter - balanceBefore) | |
1210 | - | if ((exchangedAmount == exchangedAmount)) | |
1211 | - | then exchangedAmount | |
1212 | - | else throw("Strict value is not equal to itself.") | |
1213 | - | } | |
1214 | - | else throw("Strict value is not equal to itself.") | |
1215 | - | } | |
1216 | - | else throw("Strict value is not equal to itself.") | |
1217 | - | } | |
1218 | - | else throw("Strict value is not equal to itself.") | |
1219 | - | } | |
1220 | - | else throw("Strict value is not equal to itself.") | |
1221 | - | } | |
1222 | - | else rawFeeAmount | |
1223 | - | if ((distributeFeeAmount == distributeFeeAmount)) | |
1224 | - | then { | |
1197 | + | let ensureCalledOnce = invoke(this, "ensureCalledOnce", nil, nil) | |
1198 | + | if ((ensureCalledOnce == ensureCalledOnce)) | |
1199 | + | then { | |
1200 | + | let _trader = getActualCaller(i) | |
1201 | + | let _rawAmount = i.payments[0].amount | |
1202 | + | let _assetId = i.payments[0].assetId | |
1203 | + | let _assetIdStr = toBase58String(value(_assetId)) | |
1204 | + | let isQuoteAsset = (_assetId == quoteAsset()) | |
1205 | + | if (if (if (if (if (if (if (if (if (if ((_direction != DIR_LONG)) | |
1206 | + | then (_direction != DIR_SHORT) | |
1207 | + | else false) | |
1208 | + | then true | |
1209 | + | else (0 >= _rawAmount)) | |
1210 | + | then true | |
1211 | + | else !(initialized())) | |
1212 | + | then true | |
1213 | + | else !(isQuoteAsset)) | |
1214 | + | then true | |
1215 | + | else !(isSameAssetOrNoPosition(_trader, _assetIdStr))) | |
1216 | + | then true | |
1217 | + | else !(requireMoreMarginRatio(divd(DECIMAL_UNIT, _leverage), initMarginRatio(), true))) | |
1218 | + | then true | |
1219 | + | else paused()) | |
1220 | + | then true | |
1221 | + | else closeOnly()) | |
1222 | + | then true | |
1223 | + | else isMarketClosed()) | |
1224 | + | then throw("Invalid increasePosition parameters") | |
1225 | + | else { | |
1226 | + | let $t05820958358 = getForTraderWithArtifact(_trader, getArtifactId(i)) | |
1227 | + | let adjustedFee = $t05820958358._1 | |
1228 | + | let burnArtifact = $t05820958358._2 | |
1229 | + | let _amount = divd(_rawAmount, (muld(adjustedFee, _leverage) + DECIMAL_UNIT)) | |
1230 | + | let distributeFeeAmount = (_rawAmount - _amount) | |
1225 | 1231 | let referrerFeeAny = invoke(referralAddress(), "acceptPaymentWithLink", [_trader, _refLink], [AttachedPayment(quoteAsset(), distributeFeeAmount)]) | |
1226 | 1232 | if ((referrerFeeAny == referrerFeeAny)) | |
1227 | 1233 | then { | |
1228 | 1234 | let referrerFee = match referrerFeeAny { | |
1229 | 1235 | case x: Int => | |
1230 | 1236 | x | |
1231 | 1237 | case _ => | |
1232 | 1238 | throw("Invalid referrerFee") | |
1233 | 1239 | } | |
1234 | 1240 | let feeAmount = (distributeFeeAmount - referrerFee) | |
1235 | - | let $t05250052640 = getPosition(_trader) | |
1236 | - | let oldPositionSize = $t05250052640._1 | |
1237 | - | let oldPositionMargin = $t05250052640._2 | |
1238 | - | let oldPositionOpenNotional = $t05250052640._3 | |
1239 | - | let oldPositionLstUpdCPF = $t05250052640._4 | |
1241 | + | let $t05885459022 = getPosition(_trader) | |
1242 | + | let oldPositionSize = $t05885459022._1 | |
1243 | + | let oldPositionMargin = $t05885459022._2 | |
1244 | + | let oldPositionOpenNotional = $t05885459022._3 | |
1245 | + | let oldPositionLstUpdCPF = $t05885459022._4 | |
1246 | + | let oldPositionTimestamp = $t05885459022._5 | |
1240 | 1247 | let isNewPosition = (oldPositionSize == 0) | |
1241 | 1248 | let isSameDirection = if ((oldPositionSize > 0)) | |
1242 | 1249 | then (_direction == DIR_LONG) | |
1243 | 1250 | else (_direction == DIR_SHORT) | |
1244 | 1251 | let expandExisting = if (!(isNewPosition)) | |
1245 | 1252 | then isSameDirection | |
1246 | 1253 | else false | |
1247 | 1254 | let isAdd = (_direction == DIR_LONG) | |
1248 | - | let $ | |
1255 | + | let $t05931162432 = if (if (isNewPosition) | |
1249 | 1256 | then true | |
1250 | 1257 | else expandExisting) | |
1251 | 1258 | then { | |
1252 | 1259 | let openNotional = muld(_amount, _leverage) | |
1253 | - | let $ | |
1254 | - | let amountBaseAssetBought = $ | |
1255 | - | let quoteAssetReserveAfter = $ | |
1256 | - | let baseAssetReserveAfter = $ | |
1257 | - | let totalPositionSizeAfter = $ | |
1260 | + | let $t05982059993 = swapInput(isAdd, openNotional) | |
1261 | + | let amountBaseAssetBought = $t05982059993._1 | |
1262 | + | let quoteAssetReserveAfter = $t05982059993._2 | |
1263 | + | let baseAssetReserveAfter = $t05982059993._3 | |
1264 | + | let totalPositionSizeAfter = $t05982059993._4 | |
1258 | 1265 | if (if ((_minBaseAssetAmount != 0)) | |
1259 | 1266 | then (_minBaseAssetAmount > abs(amountBaseAssetBought)) | |
1260 | 1267 | else false) | |
1261 | 1268 | then throw(((("Limit error: " + toString(abs(amountBaseAssetBought))) + " < ") + toString(_minBaseAssetAmount))) | |
1262 | 1269 | else { | |
1263 | 1270 | let newPositionSize = (oldPositionSize + amountBaseAssetBought) | |
1264 | 1271 | let totalLongOpenInterestAfter = (openInterestLong() + (if ((newPositionSize > 0)) | |
1265 | 1272 | then openNotional | |
1266 | 1273 | else 0)) | |
1267 | 1274 | let totalShortOpenInterestAfter = (openInterestShort() + (if ((0 > newPositionSize)) | |
1268 | 1275 | then openNotional | |
1269 | 1276 | else 0)) | |
1270 | - | let $t05411054331 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, _amount) | |
1271 | - | let remainMargin = $t05411054331._1 | |
1272 | - | let x1 = $t05411054331._2 | |
1273 | - | let x2 = $t05411054331._3 | |
1277 | + | let $t06053960814 = calcRemainMarginWithFundingPaymentAndRolloverFee(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, oldPositionTimestamp, _amount) | |
1278 | + | let remainMargin = $t06053960814._1 | |
1279 | + | let x1 = $t06053960814._2 | |
1280 | + | let x2 = $t06053960814._3 | |
1281 | + | let rolloverFee = $t06053960814._4 | |
1274 | 1282 | if (!(requireNotOverSpreadLimit(quoteAssetReserveAfter, baseAssetReserveAfter))) | |
1275 | 1283 | then throw("Over max spread limit") | |
1276 | 1284 | else if (!(requireNotOverMaxOpenNotional(totalLongOpenInterestAfter, totalShortOpenInterestAfter))) | |
1277 | 1285 | then throw("Over max open notional") | |
1278 | - | else $ | |
1286 | + | else $Tuple14(newPositionSize, remainMargin, (oldPositionOpenNotional + openNotional), latestCumulativePremiumFraction(newPositionSize), lastTimestamp(), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, (openInterestNotional() + openNotional), (totalLongPositionSize() + (if ((newPositionSize > 0)) | |
1279 | 1287 | then abs(amountBaseAssetBought) | |
1280 | 1288 | else 0)), (totalShortPositionSize() + (if ((0 > newPositionSize)) | |
1281 | 1289 | then abs(amountBaseAssetBought) | |
1282 | - | else 0)), totalLongOpenInterestAfter, totalShortOpenInterestAfter) | |
1290 | + | else 0)), totalLongOpenInterestAfter, totalShortOpenInterestAfter, rolloverFee) | |
1283 | 1291 | } | |
1284 | 1292 | } | |
1285 | 1293 | else { | |
1286 | 1294 | let openNotional = muld(_amount, _leverage) | |
1287 | - | let $ | |
1288 | - | let oldPositionNotional = $ | |
1289 | - | let unrealizedPnl = $ | |
1295 | + | let $t06213262248 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT) | |
1296 | + | let oldPositionNotional = $t06213262248._1 | |
1297 | + | let unrealizedPnl = $t06213262248._2 | |
1290 | 1298 | if ((oldPositionNotional > openNotional)) | |
1291 | 1299 | then throw("Use decreasePosition to decrease position size") | |
1292 | 1300 | else throw("Close position first") | |
1293 | 1301 | } | |
1294 | - | let newPositionSize = $t05292955891._1 | |
1295 | - | let newPositionRemainMargin = $t05292955891._2 | |
1296 | - | let newPositionOpenNotional = $t05292955891._3 | |
1297 | - | let newPositionLatestCPF = $t05292955891._4 | |
1298 | - | let baseAssetReserveAfter = $t05292955891._5 | |
1299 | - | let quoteAssetReserveAfter = $t05292955891._6 | |
1300 | - | let totalPositionSizeAfter = $t05292955891._7 | |
1301 | - | let openInterestNotionalAfter = $t05292955891._8 | |
1302 | - | let totalLongAfter = $t05292955891._9 | |
1303 | - | let totalShortAfter = $t05292955891._10 | |
1304 | - | let totalLongOpenInterestAfter = $t05292955891._11 | |
1305 | - | let totalShortOpenInterestAfter = $t05292955891._12 | |
1306 | - | let $t05589755954 = distributeFee(feeAmount) | |
1307 | - | let feeToStakers = $t05589755954._1 | |
1308 | - | let feeToVault = $t05589755954._2 | |
1309 | - | let stake = if (isQuoteAsset) | |
1310 | - | then { | |
1311 | - | let stake = invoke(vaultAddress(), "addLocked", [false], [AttachedPayment(quoteAsset(), _amount)]) | |
1312 | - | if ((stake == stake)) | |
1313 | - | then nil | |
1314 | - | else throw("Strict value is not equal to itself.") | |
1315 | - | } | |
1316 | - | else nil | |
1302 | + | let newPositionSize = $t05931162432._1 | |
1303 | + | let newPositionRemainMargin = $t05931162432._2 | |
1304 | + | let newPositionOpenNotional = $t05931162432._3 | |
1305 | + | let newPositionLatestCPF = $t05931162432._4 | |
1306 | + | let newPositionTimestamp = $t05931162432._5 | |
1307 | + | let baseAssetReserveAfter = $t05931162432._6 | |
1308 | + | let quoteAssetReserveAfter = $t05931162432._7 | |
1309 | + | let totalPositionSizeAfter = $t05931162432._8 | |
1310 | + | let openInterestNotionalAfter = $t05931162432._9 | |
1311 | + | let totalLongAfter = $t05931162432._10 | |
1312 | + | let totalShortAfter = $t05931162432._11 | |
1313 | + | let totalLongOpenInterestAfter = $t05931162432._12 | |
1314 | + | let totalShortOpenInterestAfter = $t05931162432._13 | |
1315 | + | let rolloverFee = $t05931162432._14 | |
1316 | + | let $t06243862509 = distributeFee((feeAmount + rolloverFee)) | |
1317 | + | let feeToStakers = $t06243862509._1 | |
1318 | + | let feeToVault = $t06243862509._2 | |
1319 | + | let stake = if ((_amount >= rolloverFee)) | |
1320 | + | then invoke(vaultAddress(), "addLocked", nil, [AttachedPayment(quoteAsset(), (_amount - rolloverFee))]) | |
1321 | + | else invoke(vaultAddress(), "withdrawLocked", [(rolloverFee - _amount)], nil) | |
1317 | 1322 | if ((stake == stake)) | |
1318 | 1323 | then { | |
1319 | 1324 | let depositVault = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToVault)]) | |
1320 | 1325 | if ((depositVault == depositVault)) | |
1321 | 1326 | then { | |
1322 | 1327 | let notifyFee = invoke(minerAddress(), "notifyFees", [_trader, feeAmount], nil) | |
1323 | 1328 | if ((notifyFee == notifyFee)) | |
1324 | 1329 | then { | |
1325 | 1330 | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil) | |
1326 | 1331 | if ((notifyNotional == notifyNotional)) | |
1327 | - | then (((((( | |
1332 | + | then ((((((updatePosition(_trader, newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF, newPositionTimestamp) ++ incrementPositionSequenceNumber(isNewPosition, _trader)) ++ updatePositionFee(isNewPosition, _trader, adjustedFee)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ transferFee(feeToStakers)) ++ updateBalance(((cbalance() + _amount) - rolloverFee))) ++ doBurnArtifact(burnArtifact, i)) | |
1328 | 1333 | else throw("Strict value is not equal to itself.") | |
1329 | 1334 | } | |
1330 | 1335 | else throw("Strict value is not equal to itself.") | |
1331 | 1336 | } | |
1337 | + | else throw("Strict value is not equal to itself.") | |
1338 | + | } | |
1339 | + | else throw("Strict value is not equal to itself.") | |
1340 | + | } | |
1341 | + | else throw("Strict value is not equal to itself.") | |
1342 | + | } | |
1343 | + | } | |
1344 | + | else throw("Strict value is not equal to itself.") | |
1345 | + | } | |
1346 | + | else throw("Strict value is not equal to itself.") | |
1347 | + | } | |
1348 | + | ||
1349 | + | ||
1350 | + | ||
1351 | + | @Callable(i) | |
1352 | + | func addMargin () = { | |
1353 | + | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1354 | + | if ((sync == sync)) | |
1355 | + | then { | |
1356 | + | let ensureCalledOnce = invoke(this, "ensureCalledOnce", nil, nil) | |
1357 | + | if ((ensureCalledOnce == ensureCalledOnce)) | |
1358 | + | then { | |
1359 | + | let _trader = toString(i.caller) | |
1360 | + | let _amount = i.payments[0].amount | |
1361 | + | let _assetId = i.payments[0].assetId | |
1362 | + | let _assetIdStr = toBase58String(value(_assetId)) | |
1363 | + | let isQuoteAsset = (_assetId == quoteAsset()) | |
1364 | + | if (if (if (if (if (if (if (!(isQuoteAsset)) | |
1365 | + | then true | |
1366 | + | else !(requireOpenPosition(toString(i.caller)))) | |
1367 | + | then true | |
1368 | + | else !(isSameAsset(_trader, _assetIdStr))) | |
1369 | + | then true | |
1370 | + | else !(initialized())) | |
1371 | + | then true | |
1372 | + | else paused()) | |
1373 | + | then true | |
1374 | + | else closeOnly()) | |
1375 | + | then true | |
1376 | + | else isMarketClosed()) | |
1377 | + | then throw("Invalid addMargin parameters") | |
1378 | + | else { | |
1379 | + | let $t06462064788 = getPosition(_trader) | |
1380 | + | let oldPositionSize = $t06462064788._1 | |
1381 | + | let oldPositionMargin = $t06462064788._2 | |
1382 | + | let oldPositionOpenNotional = $t06462064788._3 | |
1383 | + | let oldPositionLstUpdCPF = $t06462064788._4 | |
1384 | + | let oldPositionTimestamp = $t06462064788._5 | |
1385 | + | let stake = invoke(vaultAddress(), "addLocked", nil, [AttachedPayment(quoteAsset(), _amount)]) | |
1386 | + | if ((stake == stake)) | |
1387 | + | then { | |
1388 | + | let rolloverFee = calcRolloverFee(oldPositionMargin, oldPositionTimestamp) | |
1389 | + | let doTransferFeeToStakers = if ((rolloverFee > 0)) | |
1390 | + | then { | |
1391 | + | let $t06507365132 = distributeFee(rolloverFee) | |
1392 | + | let feeToStakers = $t06507365132._1 | |
1393 | + | let feeToVault = $t06507365132._2 | |
1394 | + | let unstake = invoke(vaultAddress(), "withdrawLocked", [feeToStakers], nil) | |
1395 | + | if ((unstake == unstake)) | |
1396 | + | then { | |
1397 | + | let lockBadDebt = invoke(vaultAddress(), "exchangeFreeAndLocked", [-(feeToVault)], nil) | |
1398 | + | if ((lockBadDebt == lockBadDebt)) | |
1399 | + | then transferFee(feeToStakers) | |
1400 | + | else throw("Strict value is not equal to itself.") | |
1401 | + | } | |
1402 | + | else throw("Strict value is not equal to itself.") | |
1403 | + | } | |
1404 | + | else nil | |
1405 | + | if ((doTransferFeeToStakers == doTransferFeeToStakers)) | |
1406 | + | then ((updatePosition(_trader, oldPositionSize, ((oldPositionMargin - rolloverFee) + _amount), oldPositionOpenNotional, oldPositionLstUpdCPF, lastTimestamp()) ++ updateBalance(((cbalance() + _amount) - rolloverFee))) ++ doTransferFeeToStakers) | |
1407 | + | else throw("Strict value is not equal to itself.") | |
1408 | + | } | |
1409 | + | else throw("Strict value is not equal to itself.") | |
1410 | + | } | |
1411 | + | } | |
1412 | + | else throw("Strict value is not equal to itself.") | |
1413 | + | } | |
1414 | + | else throw("Strict value is not equal to itself.") | |
1415 | + | } | |
1416 | + | ||
1417 | + | ||
1418 | + | ||
1419 | + | @Callable(i) | |
1420 | + | func removeMargin (_amount) = { | |
1421 | + | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1422 | + | if ((sync == sync)) | |
1423 | + | then { | |
1424 | + | let ensureCalledOnce = invoke(this, "ensureCalledOnce", nil, nil) | |
1425 | + | if ((ensureCalledOnce == ensureCalledOnce)) | |
1426 | + | then { | |
1427 | + | let _trader = toString(i.caller) | |
1428 | + | if (if (if (if (if ((0 >= _amount)) | |
1429 | + | then true | |
1430 | + | else !(requireOpenPosition(_trader))) | |
1431 | + | then true | |
1432 | + | else !(initialized())) | |
1433 | + | then true | |
1434 | + | else paused()) | |
1435 | + | then true | |
1436 | + | else isMarketClosed()) | |
1437 | + | then throw("Invalid removeMargin parameters") | |
1438 | + | else { | |
1439 | + | let $t06624466412 = getPosition(_trader) | |
1440 | + | let oldPositionSize = $t06624466412._1 | |
1441 | + | let oldPositionMargin = $t06624466412._2 | |
1442 | + | let oldPositionOpenNotional = $t06624466412._3 | |
1443 | + | let oldPositionLstUpdCPF = $t06624466412._4 | |
1444 | + | let oldPositionTimestamp = $t06624466412._5 | |
1445 | + | let $t06641866667 = calcRemainMarginWithFundingPaymentAndRolloverFee(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, oldPositionTimestamp, -(_amount)) | |
1446 | + | let remainMargin = $t06641866667._1 | |
1447 | + | let badDebt = $t06641866667._2 | |
1448 | + | let fundingPayment = $t06641866667._3 | |
1449 | + | let rolloverFee = $t06641866667._4 | |
1450 | + | if ((badDebt != 0)) | |
1451 | + | then throw("Invalid removed margin amount") | |
1452 | + | else { | |
1453 | + | let marginRatio = calcMarginRatio(remainMargin, badDebt, oldPositionOpenNotional) | |
1454 | + | if (!(requireMoreMarginRatio(marginRatio, initMarginRatio(), true))) | |
1455 | + | then throw(((("Too much margin removed: " + toString(marginRatio)) + " < ") + toString(initMarginRatio()))) | |
1456 | + | else { | |
1457 | + | let $t06705367112 = distributeFee(rolloverFee) | |
1458 | + | let feeToStakers = $t06705367112._1 | |
1459 | + | let feeToVault = $t06705367112._2 | |
1460 | + | let doTransferFeeToStakers = if ((rolloverFee > 0)) | |
1461 | + | then { | |
1462 | + | let lockBadDebt = invoke(vaultAddress(), "exchangeFreeAndLocked", [-(feeToVault)], nil) | |
1463 | + | if ((lockBadDebt == lockBadDebt)) | |
1464 | + | then transferFee(feeToStakers) | |
1465 | + | else throw("Strict value is not equal to itself.") | |
1466 | + | } | |
1467 | + | else nil | |
1468 | + | if ((doTransferFeeToStakers == doTransferFeeToStakers)) | |
1469 | + | then { | |
1470 | + | let unstake = invoke(vaultAddress(), "withdrawLocked", [(_amount + feeToStakers)], nil) | |
1471 | + | if ((unstake == unstake)) | |
1472 | + | then (((updatePosition(_trader, oldPositionSize, remainMargin, oldPositionOpenNotional, latestCumulativePremiumFraction(oldPositionSize), lastTimestamp()) ++ withdraw(i.caller, _amount)) ++ updateBalance(((cbalance() - _amount) - rolloverFee))) ++ doTransferFeeToStakers) | |
1473 | + | else throw("Strict value is not equal to itself.") | |
1474 | + | } | |
1475 | + | else throw("Strict value is not equal to itself.") | |
1476 | + | } | |
1477 | + | } | |
1478 | + | } | |
1479 | + | } | |
1480 | + | else throw("Strict value is not equal to itself.") | |
1481 | + | } | |
1482 | + | else throw("Strict value is not equal to itself.") | |
1483 | + | } | |
1484 | + | ||
1485 | + | ||
1486 | + | ||
1487 | + | @Callable(i) | |
1488 | + | func closePosition (_size,_minQuoteAssetAmount,_addToMargin) = { | |
1489 | + | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1490 | + | if ((sync == sync)) | |
1491 | + | then { | |
1492 | + | let ensureCalledOnce = invoke(this, "ensureCalledOnce", nil, nil) | |
1493 | + | if ((ensureCalledOnce == ensureCalledOnce)) | |
1494 | + | then { | |
1495 | + | let _trader = getActualCaller(i) | |
1496 | + | let _traderAddress = valueOrErrorMessage(addressFromString(_trader), "Invalid caller") | |
1497 | + | let positionFee = getPositionFee(_trader) | |
1498 | + | if (if (if (if (if (if (!(requireOpenPosition(_trader))) | |
1499 | + | then true | |
1500 | + | else !(initialized())) | |
1501 | + | then true | |
1502 | + | else paused()) | |
1503 | + | then true | |
1504 | + | else (0 >= _size)) | |
1505 | + | then true | |
1506 | + | else (0 > _minQuoteAssetAmount)) | |
1507 | + | then true | |
1508 | + | else isMarketClosed()) | |
1509 | + | then throw("Invalid closePosition parameters") | |
1510 | + | else { | |
1511 | + | let oldPositionTimestamp = getPosition(_trader)._5 | |
1512 | + | let $t06876969342 = internalClosePosition(_trader, _size, positionFee, _minQuoteAssetAmount, _addToMargin, true) | |
1513 | + | let newPositionSize = $t06876969342._1 | |
1514 | + | let newPositionMargin = $t06876969342._2 | |
1515 | + | let newPositionOpenNotional = $t06876969342._3 | |
1516 | + | let newPositionLstUpdCPF = $t06876969342._4 | |
1517 | + | let positionBadDebt = $t06876969342._5 | |
1518 | + | let realizedPnl = $t06876969342._6 | |
1519 | + | let marginToTrader = $t06876969342._7 | |
1520 | + | let quoteAssetReserveAfter = $t06876969342._8 | |
1521 | + | let baseAssetReserveAfter = $t06876969342._9 | |
1522 | + | let totalPositionSizeAfter = $t06876969342._10 | |
1523 | + | let openInterestNotionalAfter = $t06876969342._11 | |
1524 | + | let totalLongAfter = $t06876969342._12 | |
1525 | + | let totalShortAfter = $t06876969342._13 | |
1526 | + | let totalLongOpenInterestAfter = $t06876969342._14 | |
1527 | + | let totalShortOpenInterestAfter = $t06876969342._15 | |
1528 | + | let realizedFee = $t06876969342._16 | |
1529 | + | if ((positionBadDebt > 0)) | |
1530 | + | then throw("Invalid closePosition parameters: bad debt") | |
1531 | + | else if ((oldPositionTimestamp >= lastTimestamp())) | |
1532 | + | then throw("Invalid closePosition parameters: wait at least 1 block before closing the position") | |
1533 | + | else { | |
1534 | + | let isPartialClose = (newPositionSize != 0) | |
1535 | + | let withdrawAmount = (marginToTrader + realizedFee) | |
1536 | + | let ammBalance = (cbalance() - withdrawAmount) | |
1537 | + | let ammNewBalance = if ((0 > ammBalance)) | |
1538 | + | then 0 | |
1539 | + | else ammBalance | |
1540 | + | let unstake = invoke(vaultAddress(), "withdrawLocked", [withdrawAmount], nil) | |
1541 | + | if ((unstake == unstake)) | |
1542 | + | then { | |
1543 | + | let $t07001470073 = distributeFee(realizedFee) | |
1544 | + | let feeToStakers = $t07001470073._1 | |
1545 | + | let feeToVault = $t07001470073._2 | |
1546 | + | let depositVault = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToVault)]) | |
1547 | + | if ((depositVault == depositVault)) | |
1548 | + | then { | |
1549 | + | let notifyFee = invoke(minerAddress(), "notifyFees", [_trader, realizedFee], nil) | |
1550 | + | if ((notifyFee == notifyFee)) | |
1551 | + | then { | |
1552 | + | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil) | |
1553 | + | if ((notifyNotional == notifyNotional)) | |
1554 | + | then (((((if (isPartialClose) | |
1555 | + | then updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF, lastTimestamp()) | |
1556 | + | else deletePosition(_trader)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ (if ((marginToTrader > 0)) | |
1557 | + | then withdraw(_traderAddress, marginToTrader) | |
1558 | + | else nil)) ++ updateBalance(ammNewBalance)) ++ transferFee(feeToStakers)) | |
1559 | + | else throw("Strict value is not equal to itself.") | |
1560 | + | } | |
1561 | + | else throw("Strict value is not equal to itself.") | |
1562 | + | } | |
1563 | + | else throw("Strict value is not equal to itself.") | |
1564 | + | } | |
1565 | + | else throw("Strict value is not equal to itself.") | |
1566 | + | } | |
1567 | + | } | |
1568 | + | } | |
1569 | + | else throw("Strict value is not equal to itself.") | |
1570 | + | } | |
1571 | + | else throw("Strict value is not equal to itself.") | |
1572 | + | } | |
1573 | + | ||
1574 | + | ||
1575 | + | ||
1576 | + | @Callable(i) | |
1577 | + | func liquidate (_trader) = { | |
1578 | + | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1579 | + | if ((sync == sync)) | |
1580 | + | then { | |
1581 | + | let spotMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_SPOT) | |
1582 | + | let liquidationMarginRatio = if (isOverFluctuationLimit()) | |
1583 | + | then { | |
1584 | + | let oracleMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_ORACLE) | |
1585 | + | vmax(spotMarginRatio, oracleMarginRatio) | |
1586 | + | } | |
1587 | + | else spotMarginRatio | |
1588 | + | if (if (if (if (if (!(requireMoreMarginRatio(liquidationMarginRatio, maintenanceMarginRatio(), false))) | |
1589 | + | then true | |
1590 | + | else !(requireOpenPosition(_trader))) | |
1591 | + | then true | |
1592 | + | else !(initialized())) | |
1593 | + | then true | |
1594 | + | else paused()) | |
1595 | + | then true | |
1596 | + | else isMarketClosed()) | |
1597 | + | then throw("Unable to liquidate") | |
1598 | + | else { | |
1599 | + | let isPartialLiquidation = if (if ((spotMarginRatio > liquidationFeeRatio())) | |
1600 | + | then true | |
1601 | + | else (partialLiquidationRatio() > 0)) | |
1602 | + | then true | |
1603 | + | else (DECIMAL_UNIT > partialLiquidationRatio()) | |
1604 | + | let oldPositionSize = getPosition(_trader)._1 | |
1605 | + | let positionSizeAbs = abs(oldPositionSize) | |
1606 | + | let $t07238672709 = if (isPartialLiquidation) | |
1607 | + | then { | |
1608 | + | let liquidationSize = getPartialLiquidationAmount(_trader, oldPositionSize) | |
1609 | + | let liquidationRatio = divd(abs(liquidationSize), positionSizeAbs) | |
1610 | + | $Tuple2(liquidationRatio, abs(liquidationSize)) | |
1611 | + | } | |
1612 | + | else $Tuple2(0, positionSizeAbs) | |
1613 | + | let liquidationRatio = $t07238672709._1 | |
1614 | + | let liquidationSize = $t07238672709._2 | |
1615 | + | let $t07271573341 = internalClosePosition(_trader, if (isPartialLiquidation) | |
1616 | + | then liquidationSize | |
1617 | + | else positionSizeAbs, liquidationFeeRatio(), 0, true, false) | |
1618 | + | let newPositionSize = $t07271573341._1 | |
1619 | + | let newPositionMargin = $t07271573341._2 | |
1620 | + | let newPositionOpenNotional = $t07271573341._3 | |
1621 | + | let newPositionLstUpdCPF = $t07271573341._4 | |
1622 | + | let positionBadDebt = $t07271573341._5 | |
1623 | + | let realizedPnl = $t07271573341._6 | |
1624 | + | let marginToTrader = $t07271573341._7 | |
1625 | + | let quoteAssetReserveAfter = $t07271573341._8 | |
1626 | + | let baseAssetReserveAfter = $t07271573341._9 | |
1627 | + | let totalPositionSizeAfter = $t07271573341._10 | |
1628 | + | let openInterestNotionalAfter = $t07271573341._11 | |
1629 | + | let totalLongAfter = $t07271573341._12 | |
1630 | + | let totalShortAfter = $t07271573341._13 | |
1631 | + | let totalLongOpenInterestAfter = $t07271573341._14 | |
1632 | + | let totalShortOpenInterestAfter = $t07271573341._15 | |
1633 | + | let liquidationPenalty = $t07271573341._16 | |
1634 | + | let feeToLiquidator = (liquidationPenalty / 2) | |
1635 | + | let feeToVault = (liquidationPenalty - feeToLiquidator) | |
1636 | + | let ammBalance = (cbalance() - liquidationPenalty) | |
1637 | + | let newAmmBalance = if ((0 > ammBalance)) | |
1638 | + | then 0 | |
1639 | + | else ammBalance | |
1640 | + | let lockBadDebt = if ((positionBadDebt > 0)) | |
1641 | + | then { | |
1642 | + | let lockBadDebt = invoke(vaultAddress(), "exchangeFreeAndLocked", [positionBadDebt], nil) | |
1643 | + | if ((lockBadDebt == lockBadDebt)) | |
1644 | + | then nil | |
1645 | + | else throw("Strict value is not equal to itself.") | |
1646 | + | } | |
1647 | + | else nil | |
1648 | + | if ((lockBadDebt == lockBadDebt)) | |
1649 | + | then { | |
1650 | + | let unstake = invoke(vaultAddress(), "withdrawLocked", [liquidationPenalty], nil) | |
1651 | + | if ((unstake == unstake)) | |
1652 | + | then { | |
1653 | + | let depositInsurance = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToVault)]) | |
1654 | + | if ((depositInsurance == depositInsurance)) | |
1655 | + | then { | |
1656 | + | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil) | |
1657 | + | if ((notifyNotional == notifyNotional)) | |
1658 | + | then ((((if (isPartialLiquidation) | |
1659 | + | then updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF, lastTimestamp()) | |
1660 | + | else deletePosition(_trader)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance)) | |
1332 | 1661 | else throw("Strict value is not equal to itself.") | |
1333 | 1662 | } | |
1334 | 1663 | else throw("Strict value is not equal to itself.") | |
1335 | 1664 | } | |
1336 | 1665 | else throw("Strict value is not equal to itself.") | |
1337 | 1666 | } | |
1338 | 1667 | else throw("Strict value is not equal to itself.") | |
1339 | 1668 | } | |
1340 | 1669 | } | |
1341 | 1670 | else throw("Strict value is not equal to itself.") | |
1342 | 1671 | } | |
1343 | 1672 | ||
1344 | 1673 | ||
1345 | 1674 | ||
1346 | 1675 | @Callable(i) | |
1347 | - | func addMargin () = { | |
1348 | - | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1349 | - | if ((sync == sync)) | |
1350 | - | then { | |
1351 | - | let _trader = toString(i.caller) | |
1352 | - | let _amount = i.payments[0].amount | |
1353 | - | let _assetId = i.payments[0].assetId | |
1354 | - | let _assetIdStr = toBase58String(value(_assetId)) | |
1355 | - | let isQuoteAsset = (_assetId == quoteAsset()) | |
1356 | - | let isCollateralAsset = isWhitelistAsset(_assetIdStr) | |
1357 | - | if (if (if (if (if (if (if (if (!(isQuoteAsset)) | |
1358 | - | then !(isCollateralAsset) | |
1359 | - | else false) | |
1360 | - | then true | |
1361 | - | else !(requireOpenPosition(toString(i.caller)))) | |
1362 | - | then true | |
1363 | - | else !(isSameAsset(_trader, _assetIdStr))) | |
1364 | - | then true | |
1365 | - | else !(initialized())) | |
1366 | - | then true | |
1367 | - | else paused()) | |
1368 | - | then true | |
1369 | - | else closeOnly()) | |
1370 | - | then true | |
1371 | - | else isMarketClosed()) | |
1372 | - | then throw("Invalid addMargin parameters") | |
1373 | - | else { | |
1374 | - | let $t05798558125 = getPosition(_trader) | |
1375 | - | let oldPositionSize = $t05798558125._1 | |
1376 | - | let oldPositionMargin = $t05798558125._2 | |
1377 | - | let oldPositionOpenNotional = $t05798558125._3 | |
1378 | - | let oldPositionLstUpdCPF = $t05798558125._4 | |
1379 | - | let stake = if (isQuoteAsset) | |
1380 | - | then { | |
1381 | - | let stake = invoke(vaultAddress(), "addLocked", [false], [AttachedPayment(quoteAsset(), _amount)]) | |
1382 | - | if ((stake == stake)) | |
1383 | - | then nil | |
1384 | - | else throw("Strict value is not equal to itself.") | |
1385 | - | } | |
1386 | - | else nil | |
1387 | - | if ((stake == stake)) | |
1388 | - | then (updatePosition(_trader, oldPositionSize, (oldPositionMargin + _amount), oldPositionOpenNotional, oldPositionLstUpdCPF) ++ updateBalance((cbalance() + _amount))) | |
1389 | - | else throw("Strict value is not equal to itself.") | |
1390 | - | } | |
1391 | - | } | |
1392 | - | else throw("Strict value is not equal to itself.") | |
1393 | - | } | |
1394 | - | ||
1395 | - | ||
1396 | - | ||
1397 | - | @Callable(i) | |
1398 | - | func removeMargin (_amount) = { | |
1399 | - | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1400 | - | if ((sync == sync)) | |
1401 | - | then { | |
1402 | - | let _trader = toString(i.caller) | |
1403 | - | if (if (if (if (if ((0 >= _amount)) | |
1404 | - | then true | |
1405 | - | else !(requireOpenPosition(_trader))) | |
1406 | - | then true | |
1407 | - | else !(initialized())) | |
1408 | - | then true | |
1409 | - | else paused()) | |
1410 | - | then true | |
1411 | - | else isMarketClosed()) | |
1412 | - | then throw("Invalid removeMargin parameters") | |
1413 | - | else { | |
1414 | - | let $t05892059060 = getPosition(_trader) | |
1415 | - | let oldPositionSize = $t05892059060._1 | |
1416 | - | let oldPositionMargin = $t05892059060._2 | |
1417 | - | let oldPositionOpenNotional = $t05892059060._3 | |
1418 | - | let oldPositionLstUpdCPF = $t05892059060._4 | |
1419 | - | let marginDelta = -(_amount) | |
1420 | - | let $t05909759276 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, marginDelta) | |
1421 | - | let remainMargin = $t05909759276._1 | |
1422 | - | let badDebt = $t05909759276._2 | |
1423 | - | if ((badDebt != 0)) | |
1424 | - | then throw("Invalid removed margin amount") | |
1425 | - | else { | |
1426 | - | let marginRatio = calcMarginRatio(remainMargin, badDebt, oldPositionOpenNotional) | |
1427 | - | if (!(requireMoreMarginRatio(marginRatio, initMarginRatio(), true))) | |
1428 | - | then throw(((("Too much margin removed: " + toString(marginRatio)) + " < ") + toString(initMarginRatio()))) | |
1429 | - | else { | |
1430 | - | let quoteAssetStr = toBase58String(quoteAsset()) | |
1431 | - | let $t05972059774 = getBorrowedByTrader(_trader) | |
1432 | - | let borrowed = $t05972059774._1 | |
1433 | - | let assetId = $t05972059774._2 | |
1434 | - | let toRepay = if ((_amount > borrowed)) | |
1435 | - | then borrowed | |
1436 | - | else _amount | |
1437 | - | let toWithdraw = if ((borrowed > _amount)) | |
1438 | - | then 0 | |
1439 | - | else (_amount - borrowed) | |
1440 | - | let finalBorrow = (borrowed - toRepay) | |
1441 | - | let switchPositionToQuote = if ((finalBorrow > 0)) | |
1442 | - | then nil | |
1443 | - | else updatePositionAsset(_trader, quoteAssetStr) | |
1444 | - | let doSanityCheck = if (((toRepay + toWithdraw) != _amount)) | |
1445 | - | then throw(((((("toRepay=" + toString(toRepay)) + " + toWithdraw=") + toString(toWithdraw)) + " != ") + toString(_amount))) | |
1446 | - | else nil | |
1447 | - | if ((doSanityCheck == doSanityCheck)) | |
1448 | - | then { | |
1449 | - | let doUnstake = if ((toWithdraw > 0)) | |
1450 | - | then { | |
1451 | - | let doUnstake = invoke(vaultAddress(), "withdrawLocked", [toWithdraw], nil) | |
1452 | - | if ((doUnstake == doUnstake)) | |
1453 | - | then nil | |
1454 | - | else throw("Strict value is not equal to itself.") | |
1455 | - | } | |
1456 | - | else nil | |
1457 | - | if ((doUnstake == doUnstake)) | |
1458 | - | then { | |
1459 | - | let returnCollateralAction = if ((toRepay > 0)) | |
1460 | - | then { | |
1461 | - | let doRepay = invoke(collateralAddress(), "repay", [_trader, toRepay, assetId], nil) | |
1462 | - | if ((doRepay == doRepay)) | |
1463 | - | then [ScriptTransfer(i.caller, toRepay, fromBase58String(assetId))] | |
1464 | - | else throw("Strict value is not equal to itself.") | |
1465 | - | } | |
1466 | - | else nil | |
1467 | - | if ((returnCollateralAction == returnCollateralAction)) | |
1468 | - | then ((((updatePosition(_trader, oldPositionSize, remainMargin, oldPositionOpenNotional, latestCumulativePremiumFraction(oldPositionSize)) ++ (if ((toWithdraw > 0)) | |
1469 | - | then withdraw(i.caller, toWithdraw) | |
1470 | - | else nil)) ++ updateBalance((cbalance() - _amount))) ++ switchPositionToQuote) ++ returnCollateralAction) | |
1471 | - | else throw("Strict value is not equal to itself.") | |
1472 | - | } | |
1473 | - | else throw("Strict value is not equal to itself.") | |
1474 | - | } | |
1475 | - | else throw("Strict value is not equal to itself.") | |
1476 | - | } | |
1477 | - | } | |
1478 | - | } | |
1479 | - | } | |
1480 | - | else throw("Strict value is not equal to itself.") | |
1481 | - | } | |
1482 | - | ||
1483 | - | ||
1484 | - | ||
1485 | - | @Callable(i) | |
1486 | - | func closePosition (_size,_minQuoteAssetAmount,_addToMargin) = { | |
1487 | - | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1488 | - | if ((sync == sync)) | |
1489 | - | then { | |
1490 | - | let _trader = getActualCaller(i) | |
1491 | - | let _traderAddress = valueOrErrorMessage(addressFromString(_trader), "Invalid caller") | |
1492 | - | let positionFee = getPositionFee(_trader) | |
1493 | - | if (if (if (if (if (if (!(requireOpenPosition(_trader))) | |
1494 | - | then true | |
1495 | - | else !(initialized())) | |
1496 | - | then true | |
1497 | - | else paused()) | |
1498 | - | then true | |
1499 | - | else (0 >= _size)) | |
1500 | - | then true | |
1501 | - | else (0 > _minQuoteAssetAmount)) | |
1502 | - | then true | |
1503 | - | else isMarketClosed()) | |
1504 | - | then throw("Invalid closePosition parameters") | |
1505 | - | else { | |
1506 | - | let $t06201162151 = getPosition(_trader) | |
1507 | - | let oldPositionSize = $t06201162151._1 | |
1508 | - | let oldPositionMargin = $t06201162151._2 | |
1509 | - | let oldPositionOpenNotional = $t06201162151._3 | |
1510 | - | let oldPositionLstUpdCPF = $t06201162151._4 | |
1511 | - | let $t06215768035 = if ((abs(oldPositionSize) > _size)) | |
1512 | - | then { | |
1513 | - | let _direction = if ((oldPositionSize > 0)) | |
1514 | - | then DIR_SHORT | |
1515 | - | else DIR_LONG | |
1516 | - | let isAdd = (_direction == DIR_LONG) | |
1517 | - | let $t06276862990 = swapOutput((oldPositionSize > 0), _size, true) | |
1518 | - | let exchangedQuoteAssetAmount = $t06276862990._1 | |
1519 | - | let quoteAssetReserveAfter = $t06276862990._2 | |
1520 | - | let baseAssetReserveAfter = $t06276862990._3 | |
1521 | - | let totalPositionSizeAfter = $t06276862990._4 | |
1522 | - | let exchangedPositionSize = if ((oldPositionSize > 0)) | |
1523 | - | then -(_size) | |
1524 | - | else _size | |
1525 | - | let $t06308163235 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
1526 | - | let oldPositionNotional = $t06308163235._1 | |
1527 | - | let unrealizedPnl = $t06308163235._2 | |
1528 | - | let mr = getMarginRatioByOption(_trader, PNL_OPTION_SPOT) | |
1529 | - | let realizedRatio = divd(abs(exchangedPositionSize), abs(oldPositionSize)) | |
1530 | - | let realizedPnl = muld(unrealizedPnl, realizedRatio) | |
1531 | - | let realizedFee = muld(muld(oldPositionNotional, realizedRatio), positionFee) | |
1532 | - | let remainMarginBefore = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, unrealizedPnl)._1 | |
1533 | - | let positionBadDebt = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl)._2 | |
1534 | - | let unrealizedPnlAfter = (unrealizedPnl - realizedPnl) | |
1535 | - | let remainOpenNotional = if ((oldPositionSize > 0)) | |
1536 | - | then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter) | |
1537 | - | else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount) | |
1538 | - | let newPositionOpenNotional = abs(remainOpenNotional) | |
1539 | - | let newPositionSize = (oldPositionSize + exchangedPositionSize) | |
1540 | - | let newPositionLstUpdCPF = latestCumulativePremiumFraction(newPositionSize) | |
1541 | - | let openNotionalDelta = (oldPositionOpenNotional - newPositionOpenNotional) | |
1542 | - | let openInterestNotionalAfter = (openInterestNotional() - openNotionalDelta) | |
1543 | - | let newPositionMargin = if ((oldPositionSize > 0)) | |
1544 | - | then (muld((newPositionOpenNotional + unrealizedPnlAfter), mr) - unrealizedPnlAfter) | |
1545 | - | else (muld((newPositionOpenNotional - unrealizedPnlAfter), mr) - unrealizedPnlAfter) | |
1546 | - | let marginToTraderRaw = ((remainMarginBefore - (newPositionMargin + unrealizedPnlAfter)) - realizedFee) | |
1547 | - | let marginToTrader = if ((0 > marginToTraderRaw)) | |
1548 | - | then throw("Margin error: unable to pay close fee") | |
1549 | - | else marginToTraderRaw | |
1550 | - | if (if ((_minQuoteAssetAmount != 0)) | |
1551 | - | then (_minQuoteAssetAmount > exchangedQuoteAssetAmount) | |
1552 | - | else false) | |
1553 | - | then throw(((("Limit error: " + toString(exchangedQuoteAssetAmount)) + " < ") + toString(_minQuoteAssetAmount))) | |
1554 | - | else $Tuple16(newPositionSize, if (_addToMargin) | |
1555 | - | then (newPositionMargin + marginToTrader) | |
1556 | - | else newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF, positionBadDebt, realizedPnl, if (_addToMargin) | |
1557 | - | then 0 | |
1558 | - | else marginToTrader, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, (totalLongPositionSize() - (if ((newPositionSize > 0)) | |
1559 | - | then abs(exchangedPositionSize) | |
1560 | - | else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize)) | |
1561 | - | then abs(exchangedPositionSize) | |
1562 | - | else 0)), (openInterestLong() - (if ((newPositionSize > 0)) | |
1563 | - | then openNotionalDelta | |
1564 | - | else 0)), (openInterestShort() - (if ((0 > newPositionSize)) | |
1565 | - | then openNotionalDelta | |
1566 | - | else 0)), realizedFee) | |
1567 | - | } | |
1568 | - | else if ((_size > abs(oldPositionSize))) | |
1569 | - | then throw("Invalid closePosition parameters") | |
1570 | - | else { | |
1571 | - | let $t06645466884 = internalClosePosition(_trader, true) | |
1572 | - | let x2 = $t06645466884._1 | |
1573 | - | let positionBadDebt = $t06645466884._2 | |
1574 | - | let realizedPnl = $t06645466884._3 | |
1575 | - | let marginToTraderWithoutFee = $t06645466884._4 | |
1576 | - | let quoteAssetReserveAfter = $t06645466884._5 | |
1577 | - | let baseAssetReserveAfter = $t06645466884._6 | |
1578 | - | let totalPositionSizeAfter = $t06645466884._7 | |
1579 | - | let openInterestNotionalAfter = $t06645466884._8 | |
1580 | - | let exchangedQuoteAssetAmount = $t06645466884._9 | |
1581 | - | let totalLongAfter = $t06645466884._10 | |
1582 | - | let totalShortAfter = $t06645466884._11 | |
1583 | - | let totalLongOpenInterestAfter = $t06645466884._12 | |
1584 | - | let totalShortOpenInterestAfter = $t06645466884._13 | |
1585 | - | let realizedFee = muld(exchangedQuoteAssetAmount, positionFee) | |
1586 | - | let marginToTraderRaw = (abs(marginToTraderWithoutFee) - realizedFee) | |
1587 | - | let marginToTrader = if ((0 > marginToTraderRaw)) | |
1588 | - | then throw(((((((("Margin error: unable to pay close fee: " + toString(realizedFee)) + " margin: ") + toString(marginToTraderWithoutFee)) + " fee percent: ") + toString(positionFee)) + " notional: ") + toString(exchangedQuoteAssetAmount))) | |
1589 | - | else marginToTraderRaw | |
1590 | - | if (if ((_minQuoteAssetAmount != 0)) | |
1591 | - | then (_minQuoteAssetAmount > exchangedQuoteAssetAmount) | |
1592 | - | else false) | |
1593 | - | then throw(((("Limit error: " + toString(exchangedQuoteAssetAmount)) + " < ") + toString(_minQuoteAssetAmount))) | |
1594 | - | else $Tuple16(0, 0, 0, 0, positionBadDebt, realizedPnl, marginToTrader, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter, realizedFee) | |
1595 | - | } | |
1596 | - | let newPositionSize = $t06215768035._1 | |
1597 | - | let newPositionMargin = $t06215768035._2 | |
1598 | - | let newPositionOpenNotional = $t06215768035._3 | |
1599 | - | let newPositionLstUpdCPF = $t06215768035._4 | |
1600 | - | let positionBadDebt = $t06215768035._5 | |
1601 | - | let realizedPnl = $t06215768035._6 | |
1602 | - | let marginToTrader = $t06215768035._7 | |
1603 | - | let quoteAssetReserveAfter = $t06215768035._8 | |
1604 | - | let baseAssetReserveAfter = $t06215768035._9 | |
1605 | - | let totalPositionSizeAfter = $t06215768035._10 | |
1606 | - | let openInterestNotionalAfter = $t06215768035._11 | |
1607 | - | let totalLongAfter = $t06215768035._12 | |
1608 | - | let totalShortAfter = $t06215768035._13 | |
1609 | - | let totalLongOpenInterestAfter = $t06215768035._14 | |
1610 | - | let totalShortOpenInterestAfter = $t06215768035._15 | |
1611 | - | let realizedFee = $t06215768035._16 | |
1612 | - | if ((positionBadDebt > 0)) | |
1613 | - | then throw("Unable to close position with bad debt") | |
1614 | - | else { | |
1615 | - | let isPartialClose = (newPositionSize != 0) | |
1616 | - | let withdrawAmount = (marginToTrader + realizedFee) | |
1617 | - | let ammBalance = (cbalance() - withdrawAmount) | |
1618 | - | let $t06830268509 = if ((0 > ammBalance)) | |
1619 | - | then $Tuple2(0, abs(ammBalance)) | |
1620 | - | else $Tuple2(ammBalance, 0) | |
1621 | - | let ammNewBalance = $t06830268509._1 | |
1622 | - | let x11 = $t06830268509._2 | |
1623 | - | let $t06851668570 = getBorrowedByTrader(_trader) | |
1624 | - | let borrowed = $t06851668570._1 | |
1625 | - | let assetId = $t06851668570._2 | |
1626 | - | let $t06857869438 = if ((borrowed > 0)) | |
1627 | - | then if ((withdrawAmount >= borrowed)) | |
1628 | - | then { | |
1629 | - | let doRepay = invoke(collateralAddress(), "repay", [_trader, borrowed, assetId], nil) | |
1630 | - | if ((doRepay == doRepay)) | |
1631 | - | then $Tuple3(borrowed, (withdrawAmount - borrowed), isPartialClose) | |
1632 | - | else throw("Strict value is not equal to itself.") | |
1633 | - | } | |
1634 | - | else { | |
1635 | - | let realizeAndClose = invoke(collateralAddress(), if (isPartialClose) | |
1636 | - | then "repay" | |
1637 | - | else "realizePartiallyAndClose", [_trader, withdrawAmount, assetId], nil) | |
1638 | - | if ((realizeAndClose == realizeAndClose)) | |
1639 | - | then $Tuple3(withdrawAmount, 0, false) | |
1640 | - | else throw("Strict value is not equal to itself.") | |
1641 | - | } | |
1642 | - | else $Tuple3(0, withdrawAmount, false) | |
1643 | - | if (($t06857869438 == $t06857869438)) | |
1644 | - | then { | |
1645 | - | let switchToQuote = $t06857869438._3 | |
1646 | - | let quoteWithdrawAmountBeforeFee = $t06857869438._2 | |
1647 | - | let assetWithdrawAmountBeforeFee = $t06857869438._1 | |
1648 | - | let $t06944670513 = if ((quoteWithdrawAmountBeforeFee >= realizedFee)) | |
1649 | - | then $Tuple3(assetWithdrawAmountBeforeFee, (quoteWithdrawAmountBeforeFee - realizedFee), realizedFee) | |
1650 | - | else { | |
1651 | - | let feeLeftToWithdrawFromAsset = (realizedFee - quoteWithdrawAmountBeforeFee) | |
1652 | - | let assetWithdrawAmountAfterFee = (assetWithdrawAmountBeforeFee - feeLeftToWithdrawFromAsset) | |
1653 | - | let balanceBefore = assetBalance(this, quoteAsset()) | |
1654 | - | if ((balanceBefore == balanceBefore)) | |
1655 | - | then { | |
1656 | - | let doSwap = invoke(swapAddress(), "swap", [toBase58String(quoteAsset()), 0], [AttachedPayment(fromBase58String(assetId), feeLeftToWithdrawFromAsset)]) | |
1657 | - | if ((doSwap == doSwap)) | |
1658 | - | then { | |
1659 | - | let balanceAfter = assetBalance(this, quoteAsset()) | |
1660 | - | if ((balanceAfter == balanceAfter)) | |
1661 | - | then { | |
1662 | - | let exchangedAmount = (balanceAfter - balanceBefore) | |
1663 | - | if ((exchangedAmount == exchangedAmount)) | |
1664 | - | then $Tuple3(assetWithdrawAmountAfterFee, 0, (quoteWithdrawAmountBeforeFee + exchangedAmount)) | |
1665 | - | else throw("Strict value is not equal to itself.") | |
1666 | - | } | |
1667 | - | else throw("Strict value is not equal to itself.") | |
1668 | - | } | |
1669 | - | else throw("Strict value is not equal to itself.") | |
1670 | - | } | |
1671 | - | else throw("Strict value is not equal to itself.") | |
1672 | - | } | |
1673 | - | if (($t06944670513 == $t06944670513)) | |
1674 | - | then { | |
1675 | - | let actualFeeInQuoteAsset = $t06944670513._3 | |
1676 | - | let quoteWithdrawAmountAfterFee = $t06944670513._2 | |
1677 | - | let assetWithdrawAmountAfterFee = $t06944670513._1 | |
1678 | - | let unstake = if ((quoteWithdrawAmountBeforeFee > 0)) | |
1679 | - | then { | |
1680 | - | let unstake = invoke(vaultAddress(), "withdrawLocked", [quoteWithdrawAmountBeforeFee], nil) | |
1681 | - | if ((unstake == unstake)) | |
1682 | - | then nil | |
1683 | - | else throw("Strict value is not equal to itself.") | |
1684 | - | } | |
1685 | - | else nil | |
1686 | - | if ((unstake == unstake)) | |
1687 | - | then { | |
1688 | - | let $t07078770856 = distributeFee(actualFeeInQuoteAsset) | |
1689 | - | let feeToStakers = $t07078770856._1 | |
1690 | - | let feeToVault = $t07078770856._2 | |
1691 | - | let depositVault = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToVault)]) | |
1692 | - | if ((depositVault == depositVault)) | |
1693 | - | then { | |
1694 | - | let notifyFee = invoke(minerAddress(), "notifyFees", [_trader, realizedFee], nil) | |
1695 | - | if ((notifyFee == notifyFee)) | |
1696 | - | then { | |
1697 | - | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil) | |
1698 | - | if ((notifyNotional == notifyNotional)) | |
1699 | - | then (((((((if (isPartialClose) | |
1700 | - | then updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF) | |
1701 | - | else deletePosition(_trader)) ++ (if (switchToQuote) | |
1702 | - | then { | |
1703 | - | let quoteAssetStr = toBase58String(quoteAsset()) | |
1704 | - | updatePositionAsset(_trader, quoteAssetStr) | |
1705 | - | } | |
1706 | - | else nil)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ transferFee(feeToStakers)) ++ (if ((quoteWithdrawAmountAfterFee > 0)) | |
1707 | - | then withdraw(_traderAddress, quoteWithdrawAmountAfterFee) | |
1708 | - | else nil)) ++ updateBalance(ammNewBalance)) ++ (if ((assetWithdrawAmountAfterFee > 0)) | |
1709 | - | then [ScriptTransfer(_traderAddress, assetWithdrawAmountAfterFee, fromBase58String(assetId))] | |
1710 | - | else nil)) | |
1711 | - | else throw("Strict value is not equal to itself.") | |
1712 | - | } | |
1713 | - | else throw("Strict value is not equal to itself.") | |
1714 | - | } | |
1715 | - | else throw("Strict value is not equal to itself.") | |
1716 | - | } | |
1717 | - | else throw("Strict value is not equal to itself.") | |
1718 | - | } | |
1719 | - | else throw("Strict value is not equal to itself.") | |
1720 | - | } | |
1721 | - | else throw("Strict value is not equal to itself.") | |
1722 | - | } | |
1723 | - | } | |
1724 | - | } | |
1725 | - | else throw("Strict value is not equal to itself.") | |
1726 | - | } | |
1727 | - | ||
1728 | - | ||
1729 | - | ||
1730 | - | @Callable(i) | |
1731 | - | func liquidate (_trader) = { | |
1732 | - | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1733 | - | if ((sync == sync)) | |
1734 | - | then { | |
1735 | - | let spotMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_SPOT) | |
1736 | - | let marginRatio = if (isOverFluctuationLimit()) | |
1737 | - | then { | |
1738 | - | let oracleMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_ORACLE) | |
1739 | - | vmax(spotMarginRatio, oracleMarginRatio) | |
1740 | - | } | |
1741 | - | else spotMarginRatio | |
1742 | - | if (if (if (if (if (!(requireMoreMarginRatio(marginRatio, maintenanceMarginRatio(), false))) | |
1743 | - | then true | |
1744 | - | else !(requireOpenPosition(_trader))) | |
1745 | - | then true | |
1746 | - | else !(initialized())) | |
1747 | - | then true | |
1748 | - | else paused()) | |
1749 | - | then true | |
1750 | - | else isMarketClosed()) | |
1751 | - | then throw("Unable to liquidate") | |
1752 | - | else if (if (if ((spotMarginRatio > liquidationFeeRatio())) | |
1753 | - | then (partialLiquidationRatio() > 0) | |
1754 | - | else false) | |
1755 | - | then (DECIMAL_UNIT > partialLiquidationRatio()) | |
1756 | - | else false) | |
1757 | - | then { | |
1758 | - | let $t07360973759 = getPosition(_trader) | |
1759 | - | let oldPositionSize = $t07360973759._1 | |
1760 | - | let oldPositionMargin = $t07360973759._2 | |
1761 | - | let oldPositionOpenNotional = $t07360973759._3 | |
1762 | - | let oldPositionLstUpdCPF = $t07360973759._4 | |
1763 | - | let _direction = if ((oldPositionSize > 0)) | |
1764 | - | then DIR_SHORT | |
1765 | - | else DIR_LONG | |
1766 | - | let isAdd = (_direction == DIR_LONG) | |
1767 | - | let exchangedQuoteAssetAmount = getPartialLiquidationAmount(_trader, oldPositionSize) | |
1768 | - | let $t07398474088 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
1769 | - | let oldPositionNotional = $t07398474088._1 | |
1770 | - | let unrealizedPnl = $t07398474088._2 | |
1771 | - | let $t07409674283 = swapInput(isAdd, exchangedQuoteAssetAmount) | |
1772 | - | let exchangedPositionSize = $t07409674283._1 | |
1773 | - | let quoteAssetReserveAfter = $t07409674283._2 | |
1774 | - | let baseAssetReserveAfter = $t07409674283._3 | |
1775 | - | let totalPositionSizeAfter = $t07409674283._4 | |
1776 | - | let liquidationRatio = divd(abs(exchangedPositionSize), abs(oldPositionSize)) | |
1777 | - | let realizedPnl = muld(unrealizedPnl, liquidationRatio) | |
1778 | - | let $t07457274805 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl) | |
1779 | - | let remainMargin = $t07457274805._1 | |
1780 | - | let badDebt = $t07457274805._2 | |
1781 | - | let fundingPayment = $t07457274805._3 | |
1782 | - | let unrealizedPnlAfter = (unrealizedPnl - realizedPnl) | |
1783 | - | let remainOpenNotional = if ((oldPositionSize > 0)) | |
1784 | - | then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter) | |
1785 | - | else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount) | |
1786 | - | let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio()) | |
1787 | - | let feeToLiquidator = (liquidationPenalty / 2) | |
1788 | - | let feeToVault = (liquidationPenalty - feeToLiquidator) | |
1789 | - | let newPositionMargin = (remainMargin - liquidationPenalty) | |
1790 | - | let newPositionSize = (oldPositionSize + exchangedPositionSize) | |
1791 | - | let newPositionOpenNotional = abs(remainOpenNotional) | |
1792 | - | let openNotionalDelta = (oldPositionOpenNotional - newPositionOpenNotional) | |
1793 | - | let newPositionLstUpdCPF = latestCumulativePremiumFraction(newPositionSize) | |
1794 | - | let openInterestNotionalAfter = (openInterestNotional() - openNotionalDelta) | |
1795 | - | let ammBalance = (cbalance() - liquidationPenalty) | |
1796 | - | let $t07604676175 = if ((0 > ammBalance)) | |
1797 | - | then $Tuple2(0, abs(ammBalance)) | |
1798 | - | else $Tuple2(ammBalance, 0) | |
1799 | - | let newAmmBalance = $t07604676175._1 | |
1800 | - | let x11 = $t07604676175._2 | |
1801 | - | let $t07618376237 = getBorrowedByTrader(_trader) | |
1802 | - | let borrowed = $t07618376237._1 | |
1803 | - | let assetId = $t07618376237._2 | |
1804 | - | let doLiquidateCollateral = if ((borrowed > 0)) | |
1805 | - | then { | |
1806 | - | let collateralToSell = muld(borrowed, liquidationRatio) | |
1807 | - | let realizeAndClose = invoke(collateralAddress(), "realizePartially", [_trader, assetId, collateralToSell], nil) | |
1808 | - | if ((realizeAndClose == realizeAndClose)) | |
1809 | - | then nil | |
1810 | - | else throw("Strict value is not equal to itself.") | |
1811 | - | } | |
1812 | - | else nil | |
1813 | - | if ((doLiquidateCollateral == doLiquidateCollateral)) | |
1814 | - | then { | |
1815 | - | let unstake = invoke(vaultAddress(), "withdrawLocked", [liquidationPenalty], nil) | |
1816 | - | if ((unstake == unstake)) | |
1817 | - | then { | |
1818 | - | let depositInsurance = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToVault)]) | |
1819 | - | if ((depositInsurance == depositInsurance)) | |
1820 | - | then { | |
1821 | - | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil) | |
1822 | - | if ((notifyNotional == notifyNotional)) | |
1823 | - | then (((updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, (totalLongPositionSize() - (if ((newPositionSize > 0)) | |
1824 | - | then abs(exchangedPositionSize) | |
1825 | - | else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize)) | |
1826 | - | then abs(exchangedPositionSize) | |
1827 | - | else 0)), (openInterestLong() - (if ((newPositionSize > 0)) | |
1828 | - | then openNotionalDelta | |
1829 | - | else 0)), (openInterestShort() - (if ((0 > newPositionSize)) | |
1830 | - | then openNotionalDelta | |
1831 | - | else 0)))) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance)) | |
1832 | - | else throw("Strict value is not equal to itself.") | |
1833 | - | } | |
1834 | - | else throw("Strict value is not equal to itself.") | |
1835 | - | } | |
1836 | - | else throw("Strict value is not equal to itself.") | |
1837 | - | } | |
1838 | - | else throw("Strict value is not equal to itself.") | |
1839 | - | } | |
1840 | - | else { | |
1841 | - | let $t07791678411 = internalClosePosition(_trader, false) | |
1842 | - | let x1 = $t07791678411._1 | |
1843 | - | let badDebt = $t07791678411._2 | |
1844 | - | let x2 = $t07791678411._3 | |
1845 | - | let x3 = $t07791678411._4 | |
1846 | - | let quoteAssetReserveAfter = $t07791678411._5 | |
1847 | - | let baseAssetReserveAfter = $t07791678411._6 | |
1848 | - | let totalPositionSizeAfter = $t07791678411._7 | |
1849 | - | let openInterestNotionalAfter = $t07791678411._8 | |
1850 | - | let exchangedQuoteAssetAmount = $t07791678411._9 | |
1851 | - | let totalLongAfter = $t07791678411._10 | |
1852 | - | let totalShortAfter = $t07791678411._11 | |
1853 | - | let totalLongOpenInterestAfter = $t07791678411._12 | |
1854 | - | let totalShortOpenInterestAfter = $t07791678411._13 | |
1855 | - | let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio()) | |
1856 | - | let feeToLiquidator = (liquidationPenalty / 2) | |
1857 | - | let feeToVault = (liquidationPenalty - feeToLiquidator) | |
1858 | - | let ammBalance = (cbalance() - liquidationPenalty) | |
1859 | - | let $t07881978948 = if ((0 > ammBalance)) | |
1860 | - | then $Tuple2(0, abs(ammBalance)) | |
1861 | - | else $Tuple2(ammBalance, 0) | |
1862 | - | let newAmmBalance = $t07881978948._1 | |
1863 | - | let x11 = $t07881978948._2 | |
1864 | - | let $t07895679010 = getBorrowedByTrader(_trader) | |
1865 | - | let borrowed = $t07895679010._1 | |
1866 | - | let assetId = $t07895679010._2 | |
1867 | - | let doLiquidateCollateral = if ((borrowed > 0)) | |
1868 | - | then { | |
1869 | - | let realizeAndClose = invoke(collateralAddress(), "realizePartiallyAndClose", [_trader, 0, assetId], nil) | |
1870 | - | if ((realizeAndClose == realizeAndClose)) | |
1871 | - | then nil | |
1872 | - | else throw("Strict value is not equal to itself.") | |
1873 | - | } | |
1874 | - | else nil | |
1875 | - | if ((doLiquidateCollateral == doLiquidateCollateral)) | |
1876 | - | then { | |
1877 | - | let x = if ((badDebt > 0)) | |
1878 | - | then { | |
1879 | - | let lockBadDebt = invoke(vaultAddress(), "exchangeFreeAndLocked", [badDebt], nil) | |
1880 | - | if ((lockBadDebt == lockBadDebt)) | |
1881 | - | then nil | |
1882 | - | else throw("Strict value is not equal to itself.") | |
1883 | - | } | |
1884 | - | else nil | |
1885 | - | if ((x == x)) | |
1886 | - | then { | |
1887 | - | let unstake = invoke(vaultAddress(), "withdrawLocked", [liquidationPenalty], nil) | |
1888 | - | if ((unstake == unstake)) | |
1889 | - | then { | |
1890 | - | let depositInsurance = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToVault)]) | |
1891 | - | if ((depositInsurance == depositInsurance)) | |
1892 | - | then { | |
1893 | - | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, 0], nil) | |
1894 | - | if ((notifyNotional == notifyNotional)) | |
1895 | - | then (((deletePosition(_trader) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance)) | |
1896 | - | else throw("Strict value is not equal to itself.") | |
1897 | - | } | |
1898 | - | else throw("Strict value is not equal to itself.") | |
1899 | - | } | |
1900 | - | else throw("Strict value is not equal to itself.") | |
1901 | - | } | |
1902 | - | else throw("Strict value is not equal to itself.") | |
1903 | - | } | |
1904 | - | else throw("Strict value is not equal to itself.") | |
1905 | - | } | |
1906 | - | } | |
1907 | - | else throw("Strict value is not equal to itself.") | |
1908 | - | } | |
1909 | - | ||
1910 | - | ||
1911 | - | ||
1912 | - | @Callable(i) | |
1913 | 1676 | func payFunding () = { | |
1914 | 1677 | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1915 | 1678 | if ((sync == sync)) | |
1916 | 1679 | then { | |
1917 | 1680 | let fundingBlockTimestamp = nextFundingBlockTimestamp() | |
1918 | - | if (if (if ((fundingBlockTimestamp > | |
1681 | + | if (if (if ((fundingBlockTimestamp > lastTimestamp())) | |
1919 | 1682 | then true | |
1920 | 1683 | else !(initialized())) | |
1921 | 1684 | then true | |
1922 | 1685 | else paused()) | |
1923 | - | then throw(((("Invalid funding block timestamp: " + toString( | |
1686 | + | then throw(((("Invalid funding block timestamp: " + toString(lastTimestamp())) + " < ") + toString(fundingBlockTimestamp))) | |
1924 | 1687 | else { | |
1925 | 1688 | let underlyingPrice = getOraclePrice() | |
1926 | - | let $ | |
1927 | - | let shortPremiumFraction = $ | |
1928 | - | let longPremiumFraction = $ | |
1689 | + | let $t07530775369 = getFunding() | |
1690 | + | let shortPremiumFraction = $t07530775369._1 | |
1691 | + | let longPremiumFraction = $t07530775369._2 | |
1929 | 1692 | updateFunding((fundingBlockTimestamp + fundingPeriodSeconds()), (latestLongCumulativePremiumFraction() + longPremiumFraction), (latestShortCumulativePremiumFraction() + shortPremiumFraction), divd(longPremiumFraction, underlyingPrice), divd(shortPremiumFraction, underlyingPrice)) | |
1930 | 1693 | } | |
1931 | 1694 | } | |
1932 | 1695 | else throw("Strict value is not equal to itself.") | |
1933 | 1696 | } | |
1934 | 1697 | ||
1935 | 1698 | ||
1936 | 1699 | ||
1937 | 1700 | @Callable(i) | |
1938 | 1701 | func syncTerminalPriceToOracle () = { | |
1939 | 1702 | let _qtAstR = qtAstR() | |
1940 | 1703 | let _bsAstR = bsAstR() | |
1941 | - | let $ | |
1942 | - | let newQuoteAssetWeight = $ | |
1943 | - | let newBaseAssetWeight = $ | |
1944 | - | let marginToVault = $ | |
1704 | + | let $t07580175936 = getSyncTerminalPrice(getOraclePrice(), _qtAstR, _bsAstR) | |
1705 | + | let newQuoteAssetWeight = $t07580175936._1 | |
1706 | + | let newBaseAssetWeight = $t07580175936._2 | |
1707 | + | let marginToVault = $t07580175936._3 | |
1945 | 1708 | let doExchangePnL = if ((marginToVault != 0)) | |
1946 | 1709 | then { | |
1947 | 1710 | let doExchangePnL = invoke(vaultAddress(), "exchangeFreeAndLocked", [marginToVault], nil) | |
1948 | 1711 | if ((doExchangePnL == doExchangePnL)) | |
1949 | 1712 | then nil | |
1950 | 1713 | else throw("Strict value is not equal to itself.") | |
1951 | 1714 | } | |
1952 | 1715 | else nil | |
1953 | 1716 | if ((doExchangePnL == doExchangePnL)) | |
1954 | - | then (updateAmmWeights(newQuoteAssetWeight, newBaseAssetWeight) ++ appendTwap(divd(muld(_qtAstR, newQuoteAssetWeight), muld(_bsAstR, newBaseAssetWeight)))) | |
1717 | + | then ((updateBalance((cbalance() + marginToVault)) ++ updateAmmWeights(newQuoteAssetWeight, newBaseAssetWeight)) ++ appendTwap(divd(muld(_qtAstR, newQuoteAssetWeight), muld(_bsAstR, newBaseAssetWeight)))) | |
1955 | 1718 | else throw("Strict value is not equal to itself.") | |
1956 | 1719 | } | |
1720 | + | ||
1721 | + | ||
1722 | + | ||
1723 | + | @Callable(i) | |
1724 | + | func ensureCalledOnce () = if ((i.caller != this)) | |
1725 | + | then throw("Invalid saveCurrentTxId parameters") | |
1726 | + | else { | |
1727 | + | let lastTx = valueOrElse(getString(this, k_lastTx), "") | |
1728 | + | if ((lastTx != toBase58String(i.transactionId))) | |
1729 | + | then [StringEntry(k_lastTx, lastTx)] | |
1730 | + | else throw("Can not call vAMM methods twice in one tx") | |
1731 | + | } | |
1957 | 1732 | ||
1958 | 1733 | ||
1959 | 1734 | ||
1960 | 1735 | @Callable(i) | |
1961 | 1736 | func view_calcRemainMarginWithFundingPayment (_trader) = { | |
1962 | 1737 | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1963 | 1738 | if ((sync == sync)) | |
1964 | 1739 | then { | |
1965 | - | let $t08208082181 = getPosition(_trader) | |
1966 | - | let positionSize = $t08208082181._1 | |
1967 | - | let positionMargin = $t08208082181._2 | |
1968 | - | let pon = $t08208082181._3 | |
1969 | - | let positionLstUpdCPF = $t08208082181._4 | |
1970 | - | let $t08218482285 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
1971 | - | let positionNotional = $t08218482285._1 | |
1972 | - | let unrealizedPnl = $t08218482285._2 | |
1973 | - | let $t08228882460 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
1974 | - | let remainMargin = $t08228882460._1 | |
1975 | - | let badDebt = $t08228882460._2 | |
1976 | - | let fundingPayment = $t08228882460._3 | |
1977 | - | throw((((((s(remainMargin) + s(fundingPayment)) + s(getMarginRatio(_trader))) + s(unrealizedPnl)) + s(badDebt)) + s(positionNotional))) | |
1740 | + | let $t07694177065 = getPosition(_trader) | |
1741 | + | let positionSize = $t07694177065._1 | |
1742 | + | let positionMargin = $t07694177065._2 | |
1743 | + | let pon = $t07694177065._3 | |
1744 | + | let positionLstUpdCPF = $t07694177065._4 | |
1745 | + | let positionTimestamp = $t07694177065._5 | |
1746 | + | let $t07706877169 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
1747 | + | let positionNotional = $t07706877169._1 | |
1748 | + | let unrealizedPnl = $t07706877169._2 | |
1749 | + | let $t07717277396 = calcRemainMarginWithFundingPaymentAndRolloverFee(positionSize, positionMargin, positionLstUpdCPF, positionTimestamp, unrealizedPnl) | |
1750 | + | let remainMargin = $t07717277396._1 | |
1751 | + | let badDebt = $t07717277396._2 | |
1752 | + | let fundingPayment = $t07717277396._3 | |
1753 | + | let rolloverFee = $t07717277396._4 | |
1754 | + | throw(((((((s(remainMargin) + s(fundingPayment)) + s(getMarginRatio(_trader))) + s(unrealizedPnl)) + s(badDebt)) + s(positionNotional)) + s(rolloverFee))) | |
1978 | 1755 | } | |
1979 | 1756 | else throw("Strict value is not equal to itself.") | |
1980 | 1757 | } | |
1981 | 1758 | ||
1982 | 1759 | ||
1983 | 1760 | ||
1984 | 1761 | @Callable(i) | |
1985 | 1762 | func view_getPegAdjustCost (_price) = { | |
1986 | 1763 | let _qtAstR = qtAstR() | |
1987 | 1764 | let _bsAstR = bsAstR() | |
1988 | 1765 | let result = getSyncTerminalPrice(_price, _qtAstR, _bsAstR) | |
1989 | 1766 | throw(toString(result._3)) | |
1990 | 1767 | } | |
1991 | 1768 | ||
1992 | 1769 | ||
1993 | 1770 | ||
1994 | 1771 | @Callable(i) | |
1995 | 1772 | func view_getTerminalAmmPrice () = { | |
1996 | - | let $ | |
1997 | - | let terminalQuoteAssetReserve = $ | |
1998 | - | let terminalBaseAssetReserve = $ | |
1773 | + | let $t07783277913 = getTerminalAmmState() | |
1774 | + | let terminalQuoteAssetReserve = $t07783277913._1 | |
1775 | + | let terminalBaseAssetReserve = $t07783277913._2 | |
1999 | 1776 | let price = divd(muld(terminalQuoteAssetReserve, qtAstW()), muld(terminalBaseAssetReserve, bsAstW())) | |
2000 | 1777 | throw(toString(price)) | |
2001 | 1778 | } | |
2002 | 1779 | ||
2003 | 1780 | ||
2004 | 1781 | ||
2005 | 1782 | @Callable(i) | |
2006 | 1783 | func view_getFunding () = { | |
2007 | 1784 | let underlyingPrice = getOraclePrice() | |
2008 | - | let $ | |
2009 | - | let shortPremiumFraction = $ | |
2010 | - | let longPremiumFraction = $ | |
1785 | + | let $t07812878190 = getFunding() | |
1786 | + | let shortPremiumFraction = $t07812878190._1 | |
1787 | + | let longPremiumFraction = $t07812878190._2 | |
2011 | 1788 | let longFunding = divd(longPremiumFraction, underlyingPrice) | |
2012 | 1789 | let shortFunding = divd(shortPremiumFraction, underlyingPrice) | |
2013 | 1790 | throw((((s(longFunding) + s(shortFunding)) + s(getTwapSpotPrice())) + s(getOraclePrice()))) | |
2014 | 1791 | } | |
2015 | 1792 | ||
2016 | 1793 | ||
2017 | 1794 | ||
2018 | 1795 | @Callable(i) | |
2019 | - | func view_getBorrowedByTrader (_trader) = { | |
2020 | - | let $t08352083574 = getBorrowedByTrader(_trader) | |
2021 | - | let borrowed = $t08352083574._1 | |
2022 | - | let assetId = $t08352083574._2 | |
2023 | - | throw((s(borrowed) + assetId)) | |
2024 | - | } | |
2025 | - | ||
2026 | - | ||
2027 | - | ||
2028 | - | @Callable(i) | |
2029 | 1796 | func computeSpotPrice () = { | |
2030 | - | let result = getSpotPrice() | |
2031 | - | $Tuple2(nil, result) | |
1797 | + | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
1798 | + | if ((sync == sync)) | |
1799 | + | then { | |
1800 | + | let result = getSpotPrice() | |
1801 | + | $Tuple2(nil, result) | |
1802 | + | } | |
1803 | + | else throw("Strict value is not equal to itself.") | |
2032 | 1804 | } | |
2033 | 1805 | ||
2034 | 1806 | ||
2035 | 1807 | ||
2036 | 1808 | @Callable(i) | |
2037 | 1809 | func computeFeeForTraderWithArtifact (_trader,_artifactId) = { | |
2038 | 1810 | let result = getForTraderWithArtifact(_trader, _artifactId) | |
2039 | 1811 | $Tuple2(nil, result) | |
2040 | 1812 | } | |
2041 | 1813 | ||
2042 | 1814 | ||
2043 | 1815 | @Verifier(tx) | |
2044 | 1816 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], adminPublicKey()) | |
2045 | 1817 |
github/deemru/w8io/026f985 262.89 ms ◑