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:BgJyCAISABIAEgASABIDCgEBEgMKAQESDwoNAQEBAQEBAQEBAQEBARIUChIBAQEBAQEBCAgIAQEBAQEBAQESBgoEAQEBCBIAEgMKAQESBQoDAQEEEgMKAQgSABIAEgASAwoBCBIDCgEBEgASABIAEgQKAggIwgEADGtfYmFzZU9yYWNsZQIMa19iYXNlT3JhY2xlAA1rX3F1b3RlT3JhY2xlAg1rX3F1b3RlT3JhY2xlAAlrX2JhbGFuY2UCCWtfYmFsYW5jZQAKa19zZXF1ZW5jZQIKa19zZXF1ZW5jZQAOa19wb3NpdGlvblNpemUCDmtfcG9zaXRpb25TaXplABBrX3Bvc2l0aW9uTWFyZ2luAhBrX3Bvc2l0aW9uTWFyZ2luABZrX3Bvc2l0aW9uT3Blbk5vdGlvbmFsAhZrX3Bvc2l0aW9uT3Blbk5vdGlvbmFsAC5rX3Bvc2l0aW9uTGFzdFVwZGF0ZWRDdW11bGF0aXZlUHJlbWl1bUZyYWN0aW9uAhJrX3Bvc2l0aW9uRnJhY3Rpb24AEmtfcG9zaXRpb25TZXF1ZW5jZQISa19w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VyV2l0aEFydGlmYWN0AgUHX3RyYWRlcgULX2FydGlmYWN0SWQJAJQKAgUDbmlsBQZyZXN1bHQBAnR4AQZ2ZXJpZnkACQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAACQEOYWRtaW5QdWJsaWNLZXkAUYjcGQ==", "height": 2427371, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: GTwMSEdf7N6vNo2AxkDG5tGP6xLDJMzwj6wEsdZCu96J Next: 858z2JZZsF7GEpGKxhSwRxoJhjU3XzsbQmve6h1bZXd4 Diff:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let k_ora_key = "k_ora_key"
4+let k_baseOracle = "k_baseOracle"
55
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"
117
128 let k_balance = "k_balance"
139
2723
2824 let k_positionFee = "k_positionFee"
2925
26+let k_positionLastUpdatedTimestamp = "k_positionTimestamp"
27+
3028 let k_initialized = "k_initialized"
3129
3230 let k_paused = "k_paused"
3432 let k_closeOnly = "k_closeOnly"
3533
3634 let k_fee = "k_fee"
35+
36+let k_rolloverFee = "k_rollover_fee"
3737
3838 let k_fundingPeriod = "k_fundingPeriod"
3939
9797
9898 let k_openInterestLong = "k_openInterestLong"
9999
100+let k_lastTx = "k_lastTx"
101+
100102 let k_coordinatorAddress = "k_coordinatorAddress"
101103
102104 let k_vault_address = "k_vault_address"
117119
118120 let k_referral_address = "k_referral_address"
119121
120-let k_collateral_address = "k_collateral_address"
121-
122122 let k_exchange_address = "k_exchange_address"
123123
124124 let k_nft_manager_address = "k_nft_manager_address"
125-
126-let k_trader_market_asset_collateral = "k_trader_market_asset_collateral"
127125
128126 func toCompositeKey (_key,_address) = ((_key + "_") + _address)
129127
161159 func nftManagerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_nft_manager_address)), "NFT Manager not set")
162160
163161
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-
175162 let k_token_param = "k_token_param"
176163
177164 let k_token_type = "k_token_type"
184171
185172 let TWAP_INTERVAL = 15
186173
187-let ORACLE_INTERVAL = 15
188-
189174 let SECONDS = 1000
190175
191176 let DECIMAL_NUMBERS = 6
192177
193178 let DECIMAL_UNIT = (1 * (((((10 * 10) * 10) * 10) * 10) * 10))
194179
180+let MINUTES_IN_YEAR = (525600 * DECIMAL_UNIT)
181+
195182 let ONE_DAY = (86400 * DECIMAL_UNIT)
196-
197-let ALL_FEES = 100
198183
199184 let PNL_OPTION_SPOT = 1
200185
237222 else _y
238223
239224
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, ",")
263228
264229
265-func strToList (_str) = split(_str, ",")
230+func strToList (_str) = if ((_str == ""))
231+ then nil
232+ else split(_str, ",")
266233
267234
268235 func pushToQueue (_list,_maxSize,_value) = if ((size(_list) > _maxSize))
292259
293260
294261 func fee () = int(k_fee)
262+
263+
264+func rolloverFeeRate () = int(k_rolloverFee)
295265
296266
297267 func initMarginRatio () = int(k_initMarginRatio)
375345 func maxOracleDelay () = int(k_maxOracleDelay)
376346
377347
348+func lastTimestamp () = lastBlock.timestamp
349+
350+
378351 func getActualCaller (i) = valueOrElse(getString(ordersAddress(), "k_sender"), toString(i.caller))
379352
380353
403376 let positionSizeOpt = getInteger(this, toCompositeKey(k_positionSize, _trader))
404377 match positionSizeOpt {
405378 case positionSize: Int =>
406- $Tuple4(positionSize, getIntegerValue(this, toCompositeKey(k_positionMargin, _trader)), getIntegerValue(this, toCompositeKey(k_positionOpenNotional, _trader)), getIntegerValue(this, toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _trader)))
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)))
407380 case _ =>
408- $Tuple4(0, 0, 0, 0)
381+ $Tuple5(0, 0, 0, 0, 0)
409382 }
410383 }
411384
435408 func requireOpenPosition (_trader) = if ((getPosition(_trader)._1 == 0))
436409 then throw("No open position")
437410 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+ }
438428
439429
440430 func initialized () = valueOrElse(getBoolean(this, k_initialized), false)
483473 let amountBaseAssetBought = if (_isAdd)
484474 then amountBaseAssetBoughtAbs
485475 else -(amountBaseAssetBoughtAbs)
486- let $t01713817308 = updateReserve(_isAdd, quoteAssetAmountAdjusted, amountBaseAssetBoughtAbs)
487- let quoteAssetReserveAfter1 = $t01713817308._1
488- let baseAssetReserveAfter1 = $t01713817308._2
489- let totalPositionSizeAfter1 = $t01713817308._3
476+ let $t01725917429 = updateReserve(_isAdd, quoteAssetAmountAdjusted, amountBaseAssetBoughtAbs)
477+ let quoteAssetReserveAfter1 = $t01725917429._1
478+ let baseAssetReserveAfter1 = $t01725917429._2
479+ let totalPositionSizeAfter1 = $t01725917429._3
490480 let priceBefore = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW))
491481 let marketPrice = divd(_quoteAssetAmount, amountBaseAssetBoughtAbs)
492482 let priceDiff = abs((priceBefore - marketPrice))
498488 }
499489
500490
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) = {
502499 let fundingPayment = if ((_oldPositionSize != 0))
503500 then {
504501 let _latestCumulativePremiumFraction = latestCumulativePremiumFraction(_oldPositionSize)
505502 muld((_latestCumulativePremiumFraction - _oldPositionCumulativePremiumFraction), _oldPositionSize)
506503 }
507504 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))
510508 then $Tuple2(0, abs(signedMargin))
511509 else $Tuple2(abs(signedMargin), 0)
512- let remainMargin = $t01879518922._1
513- let badDebt = $t01879518922._2
514- $Tuple3(remainMargin, badDebt, fundingPayment)
510+ let remainMargin = $t01968419811._1
511+ let badDebt = $t01968419811._2
512+ $Tuple4(remainMargin, badDebt, fundingPayment, rolloverFee)
515513 }
516514
517515
528526 let quoteAssetDelta = abs((quoteAssetAfter - _quoteAssetReserve))
529527 let quoteAssetSold = muld(quoteAssetDelta, _quoteAssetWeight)
530528 let maxPriceImpactValue = maxPriceImpact()
531- let $t02009220254 = updateReserve(!(_isAdd), quoteAssetDelta, _baseAssetAmount)
532- let quoteAssetReserveAfter1 = $t02009220254._1
533- let baseAssetReserveAfter1 = $t02009220254._2
534- let totalPositionSizeAfter1 = $t02009220254._3
529+ let $t02107321235 = updateReserve(!(_isAdd), quoteAssetDelta, _baseAssetAmount)
530+ let quoteAssetReserveAfter1 = $t02107321235._1
531+ let baseAssetReserveAfter1 = $t02107321235._2
532+ let totalPositionSizeAfter1 = $t02107321235._3
535533 let marketPrice = divd(quoteAssetSold, _baseAssetAmount)
536534 let priceDiff = abs((priceBefore - marketPrice))
537535 let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff)))
551549 func swapOutput (_isAdd,_baseAssetAmount,_checkMaxPriceImpact) = swapOutputWithReserves(_isAdd, _baseAssetAmount, _checkMaxPriceImpact, qtAstR(), qtAstW(), bsAstR(), bsAstW())
552550
553551
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) = {
557553 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), "")
559554 if ((blockKey != ""))
560555 then {
561556 let currentBlock = lastBlock.height
568563 }
569564
570565
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+
571580 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
574584 if ((openKey != ""))
575585 then {
576586 let isOpen = valueOrErrorMessage(getBoolean(oracle, openKey), ((("Can not get oracle is open/closed. Oracle: " + toString(oracle)) + " key: ") + openKey))
633643 let isShort = (0 > _positionSize)
634644 let positionNotional = if ((_option == PNL_OPTION_SPOT))
635645 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
641647 outPositionNotional
642648 }
643649 else muld(positionSizeAbs, getOraclePrice())
658664
659665
660666 func getPositionNotionalAndUnrealizedPnl (_trader,_option) = {
661- let $t02684626974 = getPosition(_trader)
662- let positionSize = $t02684626974._1
663- let positionMargin = $t02684626974._2
664- let positionOpenNotional = $t02684626974._3
665- let positionLstUpdCPF = $t02684626974._4
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
666672 getPositionNotionalAndUnrealizedPnlByValues(positionSize, positionOpenNotional, qtAstR(), qtAstW(), bsAstR(), bsAstW(), _option)
667673 }
668674
671677
672678
673679 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
685692 calcMarginRatio(remainMargin, badDebt, positionNotional)
686693 }
687694
696703 let maxExchangedQuoteAssetAmount = swapResult._1
697704 let priceImpact = swapResult._7
698705 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())
705708 }
706709
707710
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")
734786 }
735787
736788
737789 func getTwapSpotPrice () = {
738- let minuteId = ((lastBlock.timestamp / 1000) / 60)
790+ let minuteId = ((lastTimestamp() / 1000) / 60)
739791 let startMinuteId = (minuteId - TWAP_INTERVAL)
740792 let listStr = valueOrElse(getString(this, k_lastDataStr), "")
741793 let list = split(listStr, ",")
742- func filterFn (accumulator,next) = if ((startMinuteId >= parseIntValue(next)))
794+ func filterFn (accumulator,next) = if ((startMinuteId >= valueOrErrorMessage(parseInt(next), ("getTwapSpotPrice: invalid int: " + listStr))))
743795 then (accumulator :+ parseIntValue(next))
744796 else accumulator
745797
759811 }
760812 let maxIndex = if ((size(listF) > 0))
761813 then max(listF)
762- else parseIntValue(list[0])
814+ else valueOrErrorMessage(parseInt(list[0]), ("getTwapSpotPrice: invalid int: " + listStr))
763815 let lastMinuteId = valueOrElse(getInteger(this, k_lastMinuteId), 0)
764816 let endLastCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(lastMinuteId))), 0)
765817 let endLastPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(lastMinuteId))), 0)
777829 then $Tuple2(qtAstR(), bsAstR())
778830 else {
779831 let direction = (_positionSize > 0)
780- let $t03202332202 = swapOutput(direction, abs(_positionSize), false)
781- let currentNetMarketValue = $t03202332202._1
782- let terminalQuoteAssetReserve = $t03202332202._2
783- let terminalBaseAssetReserve = $t03202332202._3
832+ let $t03956039739 = swapOutput(direction, abs(_positionSize), false)
833+ let currentNetMarketValue = $t03956039739._1
834+ let terminalQuoteAssetReserve = $t03956039739._2
835+ let terminalBaseAssetReserve = $t03956039739._3
784836 $Tuple2(terminalQuoteAssetReserve, terminalBaseAssetReserve)
785837 }
786838 }
845897 func getAdjustedFee (_artifactId,_baseFeeDiscount) = {
846898 let baseFeeRaw = fee()
847899 let baseFee = muld(baseFeeRaw, _baseFeeDiscount)
848- let $t03506335558 = if ((_artifactId != ""))
900+ let $t04260043095 = if ((_artifactId != ""))
849901 then {
850902 let artifactKind = strA(nftManagerAddress(), toCompositeKey(k_token_type, _artifactId))
851903 if ((artifactKind == FEE_REDUCTION_TOKEN_TYPE))
857909 else throw("Invalid attached artifact")
858910 }
859911 else $Tuple2(baseFee, false)
860- let adjustedFee = $t03506335558._1
861- let burnArtifact = $t03506335558._2
912+ let adjustedFee = $t04260043095._1
913+ let burnArtifact = $t04260043095._2
862914 $Tuple2(adjustedFee, burnArtifact)
863915 }
864916
874926 func isSameAsset (_trader,_assetId) = (getPositionAsset(_trader) == _assetId)
875927
876928
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-
892929 func getForTraderWithArtifact (_trader,_artifactId) = {
893930 let doGetFeeDiscount = invoke(minerAddress(), "computeFeeDiscount", [_trader], nil)
894931 if ((doGetFeeDiscount == doGetFeeDiscount))
899936 case _ =>
900937 throw("Invalid computeFeeDiscount result")
901938 }
902- let $t03678936863 = getAdjustedFee(_artifactId, feeDiscount)
903- let adjustedFee = $t03678936863._1
904- let burnArtifact = $t03678936863._2
939+ let $t04377543849 = getAdjustedFee(_artifactId, feeDiscount)
940+ let adjustedFee = $t04377543849._1
941+ let burnArtifact = $t04377543849._2
905942 $Tuple2(adjustedFee, burnArtifact)
906943 }
907944 else throw("Strict value is not equal to itself.")
923960 }
924961
925962
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)]
927964
928965
929966 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)]
933967
934968
935969 func incrementPositionSequenceNumber (_isNewPosition,_address) = if (_isNewPosition)
945979 else nil
946980
947981
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)]
949983
950984
951985 func appendTwap (_price) = {
952- let minuteId = ((lastBlock.timestamp / 1000) / 60)
986+ let minuteId = ((lastTimestamp() / 1000) / 60)
953987 let previousMinuteId = valueOrElse(getInteger(this, k_lastMinuteId), 0)
954988 if ((previousMinuteId > minuteId))
955989 then throw("TWAP out-of-order")
9911025 }
9921026
9931027
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))]
9951029
9961030
9971031 func withdraw (_address,_amount) = {
10571091 let qtAstRAfter = (_qtAstR + _quoteAssetAmount)
10581092 let baseAssetAmountToAdd = (divd(muld(qtAstRAfter, _qtAstW), price) - _bsAstR)
10591093 let bsAstRAfter = (_bsAstR + baseAssetAmountToAdd)
1060- let $t04610746258 = getSyncTerminalPrice(getOraclePrice(), qtAstRAfter, bsAstRAfter)
1061- let newQuoteAssetWeight = $t04610746258._1
1062- let newBaseAssetWeight = $t04610746258._2
1063- let marginToVault = $t04610746258._3
1094+ let $t05325653407 = getSyncTerminalPrice(getOraclePrice(), qtAstRAfter, bsAstRAfter)
1095+ let newQuoteAssetWeight = $t05325653407._1
1096+ let newBaseAssetWeight = $t05325653407._2
1097+ let marginToVault = $t05325653407._3
10641098 let doExchangePnL = if ((marginToVault != 0))
10651099 then {
10661100 let doExchangePnL = invoke(vaultAddress(), "exchangeFreeAndLocked", [marginToVault], nil)
10901124 let qtAstRAfter = (_qtAstR - _quoteAssetAmount)
10911125 let baseAssetAmountToRemove = abs((divd(muld(qtAstRAfter, _qtAstW), price) - _bsAstR))
10921126 let bsAstRAfter = (_bsAstR - baseAssetAmountToRemove)
1093- let $t04719047341 = getSyncTerminalPrice(getOraclePrice(), qtAstRAfter, bsAstRAfter)
1094- let newQuoteAssetWeight = $t04719047341._1
1095- let newBaseAssetWeight = $t04719047341._2
1096- let marginToVault = $t04719047341._3
1127+ let $t05433954490 = getSyncTerminalPrice(getOraclePrice(), qtAstRAfter, bsAstRAfter)
1128+ let newQuoteAssetWeight = $t05433954490._1
1129+ let newBaseAssetWeight = $t05433954490._2
1130+ let marginToVault = $t05433954490._3
10971131 let doExchangePnL = if ((marginToVault != 0))
10981132 then {
10991133 let doExchangePnL = invoke(vaultAddress(), "exchangeFreeAndLocked", [marginToVault], nil)
11101144
11111145
11121146 @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()))
11141148 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)
11161150
11171151
11181152
11191153 @Callable(i)
1120-func initialize (_qtAstR,_bsAstR,_fundingPeriod,_initMarginRatio,_mmr,_liquidationFeeRatio,_fee,_oracle,_oracleKey,_oracleBlockKey,_coordinator,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional,_feeToStakersPercent,_maxOracleDelay) = if (if (if (if (if (if (if (if (if (if (if (if (if (if (if (if ((0 >= _qtAstR))
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))
11211155 then true
11221156 else (0 >= _bsAstR))
11231157 then true
11471181 then true
11481182 else (0 >= _maxOracleDelay))
11491183 then true
1184+ else (0 >= _rolloverFee))
1185+ then true
11501186 else initialized())
11511187 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((lastBlock.timestamp + _fundingPeriod), 0, 0, 0, 0)) ++ updateBalance(0)) ++ [BooleanEntry(k_initialized, true), StringEntry(k_ora, _oracle), StringEntry(k_ora_key, _oracleKey), StringEntry(k_ora_block_key, _oracleBlockKey), StringEntry(k_coordinatorAddress, _coordinator)])
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)])
11531189
11541190
11551191
11581194 let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
11591195 if ((sync == sync))
11601196 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)
12251231 let referrerFeeAny = invoke(referralAddress(), "acceptPaymentWithLink", [_trader, _refLink], [AttachedPayment(quoteAsset(), distributeFeeAmount)])
12261232 if ((referrerFeeAny == referrerFeeAny))
12271233 then {
12321238 throw("Invalid referrerFee")
12331239 }
12341240 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
12401247 let isNewPosition = (oldPositionSize == 0)
12411248 let isSameDirection = if ((oldPositionSize > 0))
12421249 then (_direction == DIR_LONG)
12451252 then isSameDirection
12461253 else false
12471254 let isAdd = (_direction == DIR_LONG)
1248- let $t05292955891 = if (if (isNewPosition)
1255+ let $t05931162432 = if (if (isNewPosition)
12491256 then true
12501257 else expandExisting)
12511258 then {
12521259 let openNotional = muld(_amount, _leverage)
1253- let $t05339153564 = swapInput(isAdd, openNotional)
1254- let amountBaseAssetBought = $t05339153564._1
1255- let quoteAssetReserveAfter = $t05339153564._2
1256- let baseAssetReserveAfter = $t05339153564._3
1257- let totalPositionSizeAfter = $t05339153564._4
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
12581265 if (if ((_minBaseAssetAmount != 0))
12591266 then (_minBaseAssetAmount > abs(amountBaseAssetBought))
12601267 else false)
12671274 let totalShortOpenInterestAfter = (openInterestShort() + (if ((0 > newPositionSize))
12681275 then openNotional
12691276 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
12741282 if (!(requireNotOverSpreadLimit(quoteAssetReserveAfter, baseAssetReserveAfter)))
12751283 then throw("Over max spread limit")
12761284 else if (!(requireNotOverMaxOpenNotional(totalLongOpenInterestAfter, totalShortOpenInterestAfter)))
12771285 then throw("Over max open notional")
1278- else $Tuple12(newPositionSize, remainMargin, (oldPositionOpenNotional + openNotional), latestCumulativePremiumFraction(newPositionSize), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, (openInterestNotional() + openNotional), (totalLongPositionSize() + (if ((newPositionSize > 0))
1286+ else $Tuple14(newPositionSize, remainMargin, (oldPositionOpenNotional + openNotional), latestCumulativePremiumFraction(newPositionSize), lastTimestamp(), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, (openInterestNotional() + openNotional), (totalLongPositionSize() + (if ((newPositionSize > 0))
12791287 then abs(amountBaseAssetBought)
12801288 else 0)), (totalShortPositionSize() + (if ((0 > newPositionSize))
12811289 then abs(amountBaseAssetBought)
1282- else 0)), totalLongOpenInterestAfter, totalShortOpenInterestAfter)
1290+ else 0)), totalLongOpenInterestAfter, totalShortOpenInterestAfter, rolloverFee)
12831291 }
12841292 }
12851293 else {
12861294 let openNotional = muld(_amount, _leverage)
1287- let $t05559155707 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT)
1288- let oldPositionNotional = $t05559155707._1
1289- let unrealizedPnl = $t05559155707._2
1295+ let $t06213262248 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT)
1296+ let oldPositionNotional = $t06213262248._1
1297+ let unrealizedPnl = $t06213262248._2
12901298 if ((oldPositionNotional > openNotional))
12911299 then throw("Use decreasePosition to decrease position size")
12921300 else throw("Close position first")
12931301 }
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)
13171322 if ((stake == stake))
13181323 then {
13191324 let depositVault = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToVault)])
13241329 then {
13251330 let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil)
13261331 if ((notifyNotional == notifyNotional))
1327- then (((((((updatePosition(_trader, newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF) ++ incrementPositionSequenceNumber(isNewPosition, _trader)) ++ updatePositionFee(isNewPosition, _trader, adjustedFee)) ++ updatePositionAsset(_trader, _assetIdStr)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) ++ doBurnArtifact(burnArtifact, i))
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))
13281333 else throw("Strict value is not equal to itself.")
13291334 }
13301335 else throw("Strict value is not equal to itself.")
13311336 }
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))
13321661 else throw("Strict value is not equal to itself.")
13331662 }
13341663 else throw("Strict value is not equal to itself.")
13441673
13451674
13461675 @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)
19131676 func payFunding () = {
19141677 let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
19151678 if ((sync == sync))
19161679 then {
19171680 let fundingBlockTimestamp = nextFundingBlockTimestamp()
1918- if (if (if ((fundingBlockTimestamp > lastBlock.timestamp))
1681+ if (if (if ((fundingBlockTimestamp > lastTimestamp()))
19191682 then true
19201683 else !(initialized()))
19211684 then true
19221685 else paused())
1923- then throw(((("Invalid funding block timestamp: " + toString(lastBlock.timestamp)) + " < ") + toString(fundingBlockTimestamp)))
1686+ then throw(((("Invalid funding block timestamp: " + toString(lastTimestamp())) + " < ") + toString(fundingBlockTimestamp)))
19241687 else {
19251688 let underlyingPrice = getOraclePrice()
1926- let $t08088280944 = getFunding()
1927- let shortPremiumFraction = $t08088280944._1
1928- let longPremiumFraction = $t08088280944._2
1689+ let $t07530775369 = getFunding()
1690+ let shortPremiumFraction = $t07530775369._1
1691+ let longPremiumFraction = $t07530775369._2
19291692 updateFunding((fundingBlockTimestamp + fundingPeriodSeconds()), (latestLongCumulativePremiumFraction() + longPremiumFraction), (latestShortCumulativePremiumFraction() + shortPremiumFraction), divd(longPremiumFraction, underlyingPrice), divd(shortPremiumFraction, underlyingPrice))
19301693 }
19311694 }
19381701 func syncTerminalPriceToOracle () = {
19391702 let _qtAstR = qtAstR()
19401703 let _bsAstR = bsAstR()
1941- let $t08137681511 = getSyncTerminalPrice(getOraclePrice(), _qtAstR, _bsAstR)
1942- let newQuoteAssetWeight = $t08137681511._1
1943- let newBaseAssetWeight = $t08137681511._2
1944- let marginToVault = $t08137681511._3
1704+ let $t07580175936 = getSyncTerminalPrice(getOraclePrice(), _qtAstR, _bsAstR)
1705+ let newQuoteAssetWeight = $t07580175936._1
1706+ let newBaseAssetWeight = $t07580175936._2
1707+ let marginToVault = $t07580175936._3
19451708 let doExchangePnL = if ((marginToVault != 0))
19461709 then {
19471710 let doExchangePnL = invoke(vaultAddress(), "exchangeFreeAndLocked", [marginToVault], nil)
19511714 }
19521715 else nil
19531716 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))))
19551718 else throw("Strict value is not equal to itself.")
19561719 }
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+ }
19571732
19581733
19591734
19621737 let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
19631738 if ((sync == sync))
19641739 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)))
19781755 }
19791756 else throw("Strict value is not equal to itself.")
19801757 }
19931770
19941771 @Callable(i)
19951772 func view_getTerminalAmmPrice () = {
1996- let $t08287682957 = getTerminalAmmState()
1997- let terminalQuoteAssetReserve = $t08287682957._1
1998- let terminalBaseAssetReserve = $t08287682957._2
1773+ let $t07783277913 = getTerminalAmmState()
1774+ let terminalQuoteAssetReserve = $t07783277913._1
1775+ let terminalBaseAssetReserve = $t07783277913._2
19991776 let price = divd(muld(terminalQuoteAssetReserve, qtAstW()), muld(terminalBaseAssetReserve, bsAstW()))
20001777 throw(toString(price))
20011778 }
20051782 @Callable(i)
20061783 func view_getFunding () = {
20071784 let underlyingPrice = getOraclePrice()
2008- let $t08317283234 = getFunding()
2009- let shortPremiumFraction = $t08317283234._1
2010- let longPremiumFraction = $t08317283234._2
1785+ let $t07812878190 = getFunding()
1786+ let shortPremiumFraction = $t07812878190._1
1787+ let longPremiumFraction = $t07812878190._2
20111788 let longFunding = divd(longPremiumFraction, underlyingPrice)
20121789 let shortFunding = divd(shortPremiumFraction, underlyingPrice)
20131790 throw((((s(longFunding) + s(shortFunding)) + s(getTwapSpotPrice())) + s(getOraclePrice())))
20161793
20171794
20181795 @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)
20291796 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.")
20321804 }
20331805
20341806
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let k_ora_key = "k_ora_key"
4+let k_baseOracle = "k_baseOracle"
55
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"
117
128 let k_balance = "k_balance"
139
1410 let k_sequence = "k_sequence"
1511
1612 let k_positionSize = "k_positionSize"
1713
1814 let k_positionMargin = "k_positionMargin"
1915
2016 let k_positionOpenNotional = "k_positionOpenNotional"
2117
2218 let k_positionLastUpdatedCumulativePremiumFraction = "k_positionFraction"
2319
2420 let k_positionSequence = "k_positionSequence"
2521
2622 let k_positionAsset = "k_positionAsset"
2723
2824 let k_positionFee = "k_positionFee"
2925
26+let k_positionLastUpdatedTimestamp = "k_positionTimestamp"
27+
3028 let k_initialized = "k_initialized"
3129
3230 let k_paused = "k_paused"
3331
3432 let k_closeOnly = "k_closeOnly"
3533
3634 let k_fee = "k_fee"
35+
36+let k_rolloverFee = "k_rollover_fee"
3737
3838 let k_fundingPeriod = "k_fundingPeriod"
3939
4040 let k_initMarginRatio = "k_initMarginRatio"
4141
4242 let k_maintenanceMarginRatio = "k_mmr"
4343
4444 let k_liquidationFeeRatio = "k_liquidationFeeRatio"
4545
4646 let k_partialLiquidationRatio = "k_partLiquidationRatio"
4747
4848 let k_spreadLimit = "k_spreadLimit"
4949
5050 let k_maxPriceImpact = "k_maxPriceImpact"
5151
5252 let k_maxPriceSpread = "k_maxPriceSpread"
5353
5454 let k_maxOpenNotional = "k_maxOpenNotional"
5555
5656 let k_feeToStakersPercent = "k_feeToStakersPercent"
5757
5858 let k_maxOracleDelay = "k_maxOracleDelay"
5959
6060 let k_lastDataStr = "k_lastDataStr"
6161
6262 let k_lastMinuteId = "k_lastMinuteId"
6363
6464 let k_twapDataLastCumulativePrice = "k_twapDataLastCumulativePrice"
6565
6666 let k_twapDataLastPrice = "k_twapDataLastPrice"
6767
6868 let k_twapDataPreviousMinuteId = "k_twapDataPreviousMinuteId"
6969
7070 let k_latestLongCumulativePremiumFraction = "k_latestLongPremiumFraction"
7171
7272 let k_latestShortCumulativePremiumFraction = "k_latestShortPremiumFraction"
7373
7474 let k_nextFundingBlock = "k_nextFundingBlockMinTimestamp"
7575
7676 let k_longFundingRate = "k_longFundingRate"
7777
7878 let k_shortFundingRate = "k_shortFundingRate"
7979
8080 let k_quoteAssetReserve = "k_qtAstR"
8181
8282 let k_baseAssetReserve = "k_bsAstR"
8383
8484 let k_quoteAssetWeight = "k_qtAstW"
8585
8686 let k_baseAssetWeight = "k_bsAstW"
8787
8888 let k_totalPositionSize = "k_totalPositionSize"
8989
9090 let k_totalLongPositionSize = "k_totalLongPositionSize"
9191
9292 let k_totalShortPositionSize = "k_totalShortPositionSize"
9393
9494 let k_openInterestNotional = "k_openInterestNotional"
9595
9696 let k_openInterestShort = "k_openInterestShort"
9797
9898 let k_openInterestLong = "k_openInterestLong"
9999
100+let k_lastTx = "k_lastTx"
101+
100102 let k_coordinatorAddress = "k_coordinatorAddress"
101103
102104 let k_vault_address = "k_vault_address"
103105
104106 let k_admin_address = "k_admin_address"
105107
106108 let k_admin_public_key = "k_admin_public_key"
107109
108110 let k_quote_asset = "k_quote_asset"
109111
110112 let k_quote_staking = "k_quote_staking"
111113
112114 let k_staking_address = "k_staking_address"
113115
114116 let k_miner_address = "k_miner_address"
115117
116118 let k_orders_address = "k_orders_address"
117119
118120 let k_referral_address = "k_referral_address"
119121
120-let k_collateral_address = "k_collateral_address"
121-
122122 let k_exchange_address = "k_exchange_address"
123123
124124 let k_nft_manager_address = "k_nft_manager_address"
125-
126-let k_trader_market_asset_collateral = "k_trader_market_asset_collateral"
127125
128126 func toCompositeKey (_key,_address) = ((_key + "_") + _address)
129127
130128
131129 func coordinator () = valueOrErrorMessage(addressFromString(getStringValue(this, k_coordinatorAddress)), "Coordinator not set")
132130
133131
134132 func adminAddress () = addressFromString(getStringValue(coordinator(), k_admin_address))
135133
136134
137135 func adminPublicKey () = fromBase58String(getStringValue(coordinator(), k_admin_public_key))
138136
139137
140138 func quoteAsset () = fromBase58String(getStringValue(coordinator(), k_quote_asset))
141139
142140
143141 func quoteAssetStaking () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_quote_staking)), "Quote asset staking not set")
144142
145143
146144 func stakingAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_staking_address)), "Staking not set")
147145
148146
149147 func vaultAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_vault_address)), "Vault not set")
150148
151149
152150 func minerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_miner_address)), "Miner not set")
153151
154152
155153 func ordersAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_orders_address)), "Orders not set")
156154
157155
158156 func referralAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_referral_address)), "Referral not set")
159157
160158
161159 func nftManagerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_nft_manager_address)), "NFT Manager not set")
162160
163161
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-
175162 let k_token_param = "k_token_param"
176163
177164 let k_token_type = "k_token_type"
178165
179166 let FEE_REDUCTION_TOKEN_TYPE = "fee_reduction"
180167
181168 let DIR_LONG = 1
182169
183170 let DIR_SHORT = 2
184171
185172 let TWAP_INTERVAL = 15
186173
187-let ORACLE_INTERVAL = 15
188-
189174 let SECONDS = 1000
190175
191176 let DECIMAL_NUMBERS = 6
192177
193178 let DECIMAL_UNIT = (1 * (((((10 * 10) * 10) * 10) * 10) * 10))
194179
180+let MINUTES_IN_YEAR = (525600 * DECIMAL_UNIT)
181+
195182 let ONE_DAY = (86400 * DECIMAL_UNIT)
196-
197-let ALL_FEES = 100
198183
199184 let PNL_OPTION_SPOT = 1
200185
201186 let PNL_OPTION_ORACLE = 2
202187
203188 func s (_x) = (toString(_x) + ",")
204189
205190
206191 func divd (_x,_y) = fraction(_x, DECIMAL_UNIT, _y, HALFEVEN)
207192
208193
209194 func muld (_x,_y) = fraction(_x, _y, DECIMAL_UNIT, HALFEVEN)
210195
211196
212197 func sqrtd (_x) = sqrt(_x, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN)
213198
214199
215200 func powd (_x,_y) = pow(_x, DECIMAL_NUMBERS, _y, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN)
216201
217202
218203 func bdivd (_x,_y) = fraction(_x, toBigInt(DECIMAL_UNIT), _y, HALFEVEN)
219204
220205
221206 func bmuld (_x,_y) = fraction(_x, _y, toBigInt(DECIMAL_UNIT), HALFEVEN)
222207
223208
224209 func bsqrtd (_x) = sqrtBigInt(_x, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN)
225210
226211
227212 func bpowd (_x,_y) = pow(_x, DECIMAL_NUMBERS, _y, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN)
228213
229214
230215 func abs (_x) = if ((_x > 0))
231216 then _x
232217 else -(_x)
233218
234219
235220 func vmax (_x,_y) = if ((_x >= _y))
236221 then _x
237222 else _y
238223
239224
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, ",")
263228
264229
265-func strToList (_str) = split(_str, ",")
230+func strToList (_str) = if ((_str == ""))
231+ then nil
232+ else split(_str, ",")
266233
267234
268235 func pushToQueue (_list,_maxSize,_value) = if ((size(_list) > _maxSize))
269236 then (removeByIndex(_list, 0) :+ _value)
270237 else (_list :+ _value)
271238
272239
273240 func int (k) = valueOrErrorMessage(getInteger(this, k), ("no value for " + k))
274241
275242
276243 func intOr (k,def) = valueOrElse(getInteger(this, k), def)
277244
278245
279246 func strA (_address,_key) = {
280247 let val = valueOrErrorMessage(getString(_address, _key), ("No value for key " + _key))
281248 val
282249 }
283250
284251
285252 func intA (_address,_key) = {
286253 let val = valueOrErrorMessage(getInteger(_address, _key), ("No value for key " + _key))
287254 val
288255 }
289256
290257
291258 func cbalance () = int(k_balance)
292259
293260
294261 func fee () = int(k_fee)
262+
263+
264+func rolloverFeeRate () = int(k_rolloverFee)
295265
296266
297267 func initMarginRatio () = int(k_initMarginRatio)
298268
299269
300270 func qtAstR () = int(k_quoteAssetReserve)
301271
302272
303273 func bsAstR () = int(k_baseAssetReserve)
304274
305275
306276 func qtAstW () = intOr(k_quoteAssetWeight, DECIMAL_UNIT)
307277
308278
309279 func bsAstW () = intOr(k_baseAssetWeight, DECIMAL_UNIT)
310280
311281
312282 func totalPositionSize () = int(k_totalPositionSize)
313283
314284
315285 func openInterestNotional () = int(k_openInterestNotional)
316286
317287
318288 func openInterestShort () = int(k_openInterestShort)
319289
320290
321291 func openInterestLong () = int(k_openInterestLong)
322292
323293
324294 func nextFundingBlockTimestamp () = int(k_nextFundingBlock)
325295
326296
327297 func fundingPeriodRaw () = int(k_fundingPeriod)
328298
329299
330300 func fundingPeriodDecimal () = (fundingPeriodRaw() * DECIMAL_UNIT)
331301
332302
333303 func fundingPeriodSeconds () = (fundingPeriodRaw() * SECONDS)
334304
335305
336306 func maintenanceMarginRatio () = int(k_maintenanceMarginRatio)
337307
338308
339309 func liquidationFeeRatio () = int(k_liquidationFeeRatio)
340310
341311
342312 func partialLiquidationRatio () = int(k_partialLiquidationRatio)
343313
344314
345315 func spreadLimit () = int(k_spreadLimit)
346316
347317
348318 func maxPriceImpact () = int(k_maxPriceImpact)
349319
350320
351321 func maxPriceSpread () = int(k_maxPriceSpread)
352322
353323
354324 func maxOpenNotional () = int(k_maxOpenNotional)
355325
356326
357327 func latestLongCumulativePremiumFraction () = int(k_latestLongCumulativePremiumFraction)
358328
359329
360330 func latestShortCumulativePremiumFraction () = int(k_latestShortCumulativePremiumFraction)
361331
362332
363333 func totalShortPositionSize () = int(k_totalShortPositionSize)
364334
365335
366336 func totalLongPositionSize () = int(k_totalLongPositionSize)
367337
368338
369339 func lastSequence () = intOr(k_sequence, 0)
370340
371341
372342 func feeToStakersPercent () = int(k_feeToStakersPercent)
373343
374344
375345 func maxOracleDelay () = int(k_maxOracleDelay)
376346
377347
348+func lastTimestamp () = lastBlock.timestamp
349+
350+
378351 func getActualCaller (i) = valueOrElse(getString(ordersAddress(), "k_sender"), toString(i.caller))
379352
380353
381354 func requireMoreMarginRatio (_marginRatio,_baseMarginRatio,_largerThanOrEqualTo) = {
382355 let remainingMarginRatio = (_marginRatio - _baseMarginRatio)
383356 if (if (_largerThanOrEqualTo)
384357 then (0 > remainingMarginRatio)
385358 else false)
386359 then throw(((("Invalid margin: " + toString(_marginRatio)) + " < ") + toString(_baseMarginRatio)))
387360 else if (if (!(_largerThanOrEqualTo))
388361 then (remainingMarginRatio >= 0)
389362 else false)
390363 then throw(((("Invalid margin: " + toString(_marginRatio)) + " > ") + toString(_baseMarginRatio)))
391364 else true
392365 }
393366
394367
395368 func latestCumulativePremiumFraction (_positionSize) = if ((_positionSize == 0))
396369 then throw("Should not be called with _positionSize == 0")
397370 else if ((_positionSize > 0))
398371 then latestLongCumulativePremiumFraction()
399372 else latestShortCumulativePremiumFraction()
400373
401374
402375 func getPosition (_trader) = {
403376 let positionSizeOpt = getInteger(this, toCompositeKey(k_positionSize, _trader))
404377 match positionSizeOpt {
405378 case positionSize: Int =>
406- $Tuple4(positionSize, getIntegerValue(this, toCompositeKey(k_positionMargin, _trader)), getIntegerValue(this, toCompositeKey(k_positionOpenNotional, _trader)), getIntegerValue(this, toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _trader)))
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)))
407380 case _ =>
408- $Tuple4(0, 0, 0, 0)
381+ $Tuple5(0, 0, 0, 0, 0)
409382 }
410383 }
411384
412385
413386 func getPositionAsset (_trader) = {
414387 let positionAssetOpt = getString(this, toCompositeKey(k_positionAsset, _trader))
415388 match positionAssetOpt {
416389 case positionAsset: String =>
417390 positionAsset
418391 case _ =>
419392 toBase58String(quoteAsset())
420393 }
421394 }
422395
423396
424397 func getPositionFee (_trader) = {
425398 let positionFeeOpt = getInteger(this, toCompositeKey(k_positionFee, _trader))
426399 match positionFeeOpt {
427400 case positionFee: Int =>
428401 positionFee
429402 case _ =>
430403 fee()
431404 }
432405 }
433406
434407
435408 func requireOpenPosition (_trader) = if ((getPosition(_trader)._1 == 0))
436409 then throw("No open position")
437410 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+ }
438428
439429
440430 func initialized () = valueOrElse(getBoolean(this, k_initialized), false)
441431
442432
443433 func paused () = valueOrElse(getBoolean(this, k_paused), false)
444434
445435
446436 func closeOnly () = valueOrElse(getBoolean(this, k_closeOnly), false)
447437
448438
449439 func updateReserve (_isAdd,_quoteAssetAmount,_baseAssetAmount) = if (_isAdd)
450440 then {
451441 let newBase = (bsAstR() - _baseAssetAmount)
452442 if ((0 >= newBase))
453443 then throw("Tx lead to base asset reserve <= 0, revert")
454444 else $Tuple3((qtAstR() + _quoteAssetAmount), newBase, (totalPositionSize() + _baseAssetAmount))
455445 }
456446 else {
457447 let newQuote = (qtAstR() - _quoteAssetAmount)
458448 if ((0 >= newQuote))
459449 then throw("Tx lead to base quote reserve <= 0, revert")
460450 else $Tuple3(newQuote, (bsAstR() + _baseAssetAmount), (totalPositionSize() - _baseAssetAmount))
461451 }
462452
463453
464454 func calcInvariant (_qtAstR,_bsAstR) = {
465455 let bqtAstR = toBigInt(_qtAstR)
466456 let bbsAstR = toBigInt(_bsAstR)
467457 bmuld(bqtAstR, bbsAstR)
468458 }
469459
470460
471461 func swapInput (_isAdd,_quoteAssetAmount) = {
472462 let _qtAstR = qtAstR()
473463 let _bsAstR = bsAstR()
474464 let _qtAstW = qtAstW()
475465 let _bsAstW = bsAstW()
476466 let quoteAssetAmountAdjusted = divd(_quoteAssetAmount, _qtAstW)
477467 let k = calcInvariant(_qtAstR, _bsAstR)
478468 let quoteAssetReserveAfter = if (_isAdd)
479469 then (_qtAstR + quoteAssetAmountAdjusted)
480470 else (_qtAstR - quoteAssetAmountAdjusted)
481471 let baseAssetReserveAfter = toInt(bdivd(k, toBigInt(quoteAssetReserveAfter)))
482472 let amountBaseAssetBoughtAbs = abs((baseAssetReserveAfter - _bsAstR))
483473 let amountBaseAssetBought = if (_isAdd)
484474 then amountBaseAssetBoughtAbs
485475 else -(amountBaseAssetBoughtAbs)
486- let $t01713817308 = updateReserve(_isAdd, quoteAssetAmountAdjusted, amountBaseAssetBoughtAbs)
487- let quoteAssetReserveAfter1 = $t01713817308._1
488- let baseAssetReserveAfter1 = $t01713817308._2
489- let totalPositionSizeAfter1 = $t01713817308._3
476+ let $t01725917429 = updateReserve(_isAdd, quoteAssetAmountAdjusted, amountBaseAssetBoughtAbs)
477+ let quoteAssetReserveAfter1 = $t01725917429._1
478+ let baseAssetReserveAfter1 = $t01725917429._2
479+ let totalPositionSizeAfter1 = $t01725917429._3
490480 let priceBefore = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW))
491481 let marketPrice = divd(_quoteAssetAmount, amountBaseAssetBoughtAbs)
492482 let priceDiff = abs((priceBefore - marketPrice))
493483 let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff)))
494484 let maxPriceImpactValue = maxPriceImpact()
495485 if ((priceImpact > maxPriceImpactValue))
496486 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)))
497487 else $Tuple4(amountBaseAssetBought, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1)
498488 }
499489
500490
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) = {
502499 let fundingPayment = if ((_oldPositionSize != 0))
503500 then {
504501 let _latestCumulativePremiumFraction = latestCumulativePremiumFraction(_oldPositionSize)
505502 muld((_latestCumulativePremiumFraction - _oldPositionCumulativePremiumFraction), _oldPositionSize)
506503 }
507504 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))
510508 then $Tuple2(0, abs(signedMargin))
511509 else $Tuple2(abs(signedMargin), 0)
512- let remainMargin = $t01879518922._1
513- let badDebt = $t01879518922._2
514- $Tuple3(remainMargin, badDebt, fundingPayment)
510+ let remainMargin = $t01968419811._1
511+ let badDebt = $t01968419811._2
512+ $Tuple4(remainMargin, badDebt, fundingPayment, rolloverFee)
515513 }
516514
517515
518516 func swapOutputWithReserves (_isAdd,_baseAssetAmount,_checkMaxPriceImpact,_quoteAssetReserve,_quoteAssetWeight,_baseAssetReserve,_baseAssetWeight) = {
519517 let priceBefore = divd(muld(_quoteAssetReserve, _quoteAssetWeight), muld(_baseAssetReserve, _baseAssetWeight))
520518 if ((_baseAssetAmount == 0))
521519 then throw("Invalid base asset amount")
522520 else {
523521 let k = calcInvariant(_quoteAssetReserve, _baseAssetReserve)
524522 let baseAssetPoolAmountAfter = if (_isAdd)
525523 then (_baseAssetReserve + _baseAssetAmount)
526524 else (_baseAssetReserve - _baseAssetAmount)
527525 let quoteAssetAfter = toInt(bdivd(k, toBigInt(baseAssetPoolAmountAfter)))
528526 let quoteAssetDelta = abs((quoteAssetAfter - _quoteAssetReserve))
529527 let quoteAssetSold = muld(quoteAssetDelta, _quoteAssetWeight)
530528 let maxPriceImpactValue = maxPriceImpact()
531- let $t02009220254 = updateReserve(!(_isAdd), quoteAssetDelta, _baseAssetAmount)
532- let quoteAssetReserveAfter1 = $t02009220254._1
533- let baseAssetReserveAfter1 = $t02009220254._2
534- let totalPositionSizeAfter1 = $t02009220254._3
529+ let $t02107321235 = updateReserve(!(_isAdd), quoteAssetDelta, _baseAssetAmount)
530+ let quoteAssetReserveAfter1 = $t02107321235._1
531+ let baseAssetReserveAfter1 = $t02107321235._2
532+ let totalPositionSizeAfter1 = $t02107321235._3
535533 let marketPrice = divd(quoteAssetSold, _baseAssetAmount)
536534 let priceDiff = abs((priceBefore - marketPrice))
537535 let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff)))
538536 if (if ((priceImpact > maxPriceImpactValue))
539537 then _checkMaxPriceImpact
540538 else false)
541539 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)))
542540 else $Tuple7(quoteAssetSold, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, (totalLongPositionSize() - (if (_isAdd)
543541 then abs(_baseAssetAmount)
544542 else 0)), (totalShortPositionSize() - (if (!(_isAdd))
545543 then abs(_baseAssetAmount)
546544 else 0)), priceImpact)
547545 }
548546 }
549547
550548
551549 func swapOutput (_isAdd,_baseAssetAmount,_checkMaxPriceImpact) = swapOutputWithReserves(_isAdd, _baseAssetAmount, _checkMaxPriceImpact, qtAstR(), qtAstW(), bsAstR(), bsAstW())
552550
553551
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) = {
557553 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), "")
559554 if ((blockKey != ""))
560555 then {
561556 let currentBlock = lastBlock.height
562557 let lastOracleBlock = valueOrErrorMessage(getInteger(oracle, blockKey), ((("Can not get oracle block. Oracle: " + toString(oracle)) + " key: ") + blockKey))
563558 if (((currentBlock - lastOracleBlock) > maxOracleDelay()))
564559 then throw(((("Oracle stale data. Last oracle block: " + toString(lastOracleBlock)) + " current block: ") + toString(currentBlock)))
565560 else lastValue
566561 }
567562 else lastValue
568563 }
569564
570565
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+
571580 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
574584 if ((openKey != ""))
575585 then {
576586 let isOpen = valueOrErrorMessage(getBoolean(oracle, openKey), ((("Can not get oracle is open/closed. Oracle: " + toString(oracle)) + " key: ") + openKey))
577587 !(isOpen)
578588 }
579589 else false
580590 }
581591
582592
583593 func absPriceDiff (_oraclePrice,_quoteAssetReserve,_baseAssetReserve,_qtAstW,_bsAstW) = {
584594 let priceAfter = divd(muld(_quoteAssetReserve, _qtAstW), muld(_baseAssetReserve, _bsAstW))
585595 let averagePrice = divd((_oraclePrice + priceAfter), (2 * DECIMAL_UNIT))
586596 let absPriceDiff = divd(abs((_oraclePrice - priceAfter)), averagePrice)
587597 absPriceDiff
588598 }
589599
590600
591601 func requireNotOverSpreadLimit (_quoteAssetReserve,_baseAssetReserve) = {
592602 let oraclePrice = getOraclePrice()
593603 let _qtAstW = qtAstW()
594604 let _bsAstW = bsAstW()
595605 let absPriceDiffBefore = absPriceDiff(oraclePrice, qtAstR(), bsAstR(), _qtAstW, _bsAstW)
596606 let absPriceDiffAfter = absPriceDiff(oraclePrice, _quoteAssetReserve, _baseAssetReserve, _qtAstW, _bsAstW)
597607 if (if ((absPriceDiffAfter > maxPriceSpread()))
598608 then (absPriceDiffAfter > absPriceDiffBefore)
599609 else false)
600610 then throw(((("Price spread " + toString(absPriceDiffAfter)) + " > max price spread ") + toString(maxPriceSpread())))
601611 else true
602612 }
603613
604614
605615 func requireNotOverMaxOpenNotional (_longOpenNotional,_shortOpenNotional) = {
606616 let _maxOpenNotional = maxOpenNotional()
607617 if ((_longOpenNotional > _maxOpenNotional))
608618 then throw(((("Long open notional " + toString(_longOpenNotional)) + " > max open notional ") + toString(_maxOpenNotional)))
609619 else if ((_shortOpenNotional > _maxOpenNotional))
610620 then throw(((("Short open notional " + toString(_shortOpenNotional)) + " > max open notional ") + toString(_maxOpenNotional)))
611621 else true
612622 }
613623
614624
615625 func getSpotPrice () = {
616626 let _quoteAssetReserve = qtAstR()
617627 let _baseAssetReserve = bsAstR()
618628 let _qtAstW = qtAstW()
619629 let _bsAstW = bsAstW()
620630 divd(muld(_quoteAssetReserve, _qtAstW), muld(_baseAssetReserve, _bsAstW))
621631 }
622632
623633
624634 func isOverFluctuationLimit () = {
625635 let oraclePrice = getOraclePrice()
626636 let currentPrice = getSpotPrice()
627637 (divd(abs((oraclePrice - currentPrice)), oraclePrice) > spreadLimit())
628638 }
629639
630640
631641 func getPositionAdjustedOpenNotional (_positionSize,_option,_quoteAssetReserve,_quoteAssetWeight,_baseAssetReserve,_baseAssetWeight) = {
632642 let positionSizeAbs = abs(_positionSize)
633643 let isShort = (0 > _positionSize)
634644 let positionNotional = if ((_option == PNL_OPTION_SPOT))
635645 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
641647 outPositionNotional
642648 }
643649 else muld(positionSizeAbs, getOraclePrice())
644650 positionNotional
645651 }
646652
647653
648654 func getPositionNotionalAndUnrealizedPnlByValues (_positionSize,_positionOpenNotional,_quoteAssetReserve,_quoteAssetWeight,_baseAssetReserve,_baseAssetWeight,_option) = if ((_positionSize == 0))
649655 then throw("Invalid position size")
650656 else {
651657 let isShort = (0 > _positionSize)
652658 let positionNotional = getPositionAdjustedOpenNotional(_positionSize, _option, _quoteAssetReserve, _quoteAssetWeight, _baseAssetReserve, _baseAssetWeight)
653659 let unrealizedPnl = if (isShort)
654660 then (_positionOpenNotional - positionNotional)
655661 else (positionNotional - _positionOpenNotional)
656662 $Tuple2(positionNotional, unrealizedPnl)
657663 }
658664
659665
660666 func getPositionNotionalAndUnrealizedPnl (_trader,_option) = {
661- let $t02684626974 = getPosition(_trader)
662- let positionSize = $t02684626974._1
663- let positionMargin = $t02684626974._2
664- let positionOpenNotional = $t02684626974._3
665- let positionLstUpdCPF = $t02684626974._4
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
666672 getPositionNotionalAndUnrealizedPnlByValues(positionSize, positionOpenNotional, qtAstR(), qtAstW(), bsAstR(), bsAstW(), _option)
667673 }
668674
669675
670676 func calcMarginRatio (_remainMargin,_badDebt,_positionNotional) = divd((_remainMargin - _badDebt), _positionNotional)
671677
672678
673679 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
685692 calcMarginRatio(remainMargin, badDebt, positionNotional)
686693 }
687694
688695
689696 func getMarginRatio (_trader) = getMarginRatioByOption(_trader, PNL_OPTION_SPOT)
690697
691698
692699 func getPartialLiquidationAmount (_trader,_positionSize) = {
693700 let maximumRatio = vmax(partialLiquidationRatio(), (DECIMAL_UNIT - divd(getMarginRatio(_trader), maintenanceMarginRatio())))
694701 let maxExchangedPositionSize = muld(abs(_positionSize), maximumRatio)
695702 let swapResult = swapOutput((_positionSize > 0), maxExchangedPositionSize, false)
696703 let maxExchangedQuoteAssetAmount = swapResult._1
697704 let priceImpact = swapResult._7
698705 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())
705708 }
706709
707710
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")
734786 }
735787
736788
737789 func getTwapSpotPrice () = {
738- let minuteId = ((lastBlock.timestamp / 1000) / 60)
790+ let minuteId = ((lastTimestamp() / 1000) / 60)
739791 let startMinuteId = (minuteId - TWAP_INTERVAL)
740792 let listStr = valueOrElse(getString(this, k_lastDataStr), "")
741793 let list = split(listStr, ",")
742- func filterFn (accumulator,next) = if ((startMinuteId >= parseIntValue(next)))
794+ func filterFn (accumulator,next) = if ((startMinuteId >= valueOrErrorMessage(parseInt(next), ("getTwapSpotPrice: invalid int: " + listStr))))
743795 then (accumulator :+ parseIntValue(next))
744796 else accumulator
745797
746798 let listF = {
747799 let $l = list
748800 let $s = size($l)
749801 let $acc0 = nil
750802 func $f0_1 ($a,$i) = if (($i >= $s))
751803 then $a
752804 else filterFn($a, $l[$i])
753805
754806 func $f0_2 ($a,$i) = if (($i >= $s))
755807 then $a
756808 else throw("List size exceeds 20")
757809
758810 $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)
759811 }
760812 let maxIndex = if ((size(listF) > 0))
761813 then max(listF)
762- else parseIntValue(list[0])
814+ else valueOrErrorMessage(parseInt(list[0]), ("getTwapSpotPrice: invalid int: " + listStr))
763815 let lastMinuteId = valueOrElse(getInteger(this, k_lastMinuteId), 0)
764816 let endLastCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(lastMinuteId))), 0)
765817 let endLastPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(lastMinuteId))), 0)
766818 let nowCumulativePrice = (endLastCumulativePrice + ((minuteId - lastMinuteId) * endLastPrice))
767819 let startLastCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(maxIndex))), 0)
768820 let startLastPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(maxIndex))), 0)
769821 let startCumulativePrice = (startLastCumulativePrice + ((startMinuteId - maxIndex) * startLastPrice))
770822 ((nowCumulativePrice - startCumulativePrice) / TWAP_INTERVAL)
771823 }
772824
773825
774826 func getTerminalAmmState () = {
775827 let _positionSize = totalPositionSize()
776828 if ((_positionSize == 0))
777829 then $Tuple2(qtAstR(), bsAstR())
778830 else {
779831 let direction = (_positionSize > 0)
780- let $t03202332202 = swapOutput(direction, abs(_positionSize), false)
781- let currentNetMarketValue = $t03202332202._1
782- let terminalQuoteAssetReserve = $t03202332202._2
783- let terminalBaseAssetReserve = $t03202332202._3
832+ let $t03956039739 = swapOutput(direction, abs(_positionSize), false)
833+ let currentNetMarketValue = $t03956039739._1
834+ let terminalQuoteAssetReserve = $t03956039739._2
835+ let terminalBaseAssetReserve = $t03956039739._3
784836 $Tuple2(terminalQuoteAssetReserve, terminalBaseAssetReserve)
785837 }
786838 }
787839
788840
789841 func getQuoteAssetWeight (baseAssetReserve,totalPositionSize,quoteAssetReserve,targetPrice) = {
790842 let b = toBigInt(baseAssetReserve)
791843 let sz = toBigInt(totalPositionSize)
792844 let q = toBigInt(quoteAssetReserve)
793845 let p = toBigInt(targetPrice)
794846 let k = bmuld(q, b)
795847 let newB = (b + sz)
796848 let newQ = bdivd(k, newB)
797849 let z = bdivd(newQ, newB)
798850 let result = bdivd(p, z)
799851 toInt(result)
800852 }
801853
802854
803855 func getSyncTerminalPrice (_terminalPrice,_qtAstR,_bsAstR) = {
804856 let _positionSize = totalPositionSize()
805857 if ((_positionSize == 0))
806858 then {
807859 let newQtAstW = divd(muld(_terminalPrice, _bsAstR), _qtAstR)
808860 $Tuple3(newQtAstW, DECIMAL_UNIT, 0)
809861 }
810862 else {
811863 let direction = (_positionSize > 0)
812864 let currentNetMarketValue = swapOutput(direction, abs(_positionSize), false)._1
813865 let newQtAstW = getQuoteAssetWeight(_bsAstR, _positionSize, _qtAstR, _terminalPrice)
814866 let newBsAstW = DECIMAL_UNIT
815867 let marginToVault = getPositionNotionalAndUnrealizedPnlByValues(_positionSize, currentNetMarketValue, _qtAstR, newQtAstW, _bsAstR, newBsAstW, PNL_OPTION_SPOT)._2
816868 $Tuple3(newQtAstW, newBsAstW, marginToVault)
817869 }
818870 }
819871
820872
821873 func getFunding () = {
822874 let underlyingPrice = getOraclePrice()
823875 let spotTwapPrice = getTwapSpotPrice()
824876 let premium = (spotTwapPrice - underlyingPrice)
825877 if (if (if ((totalShortPositionSize() == 0))
826878 then true
827879 else (totalLongPositionSize() == 0))
828880 then true
829881 else isMarketClosed())
830882 then $Tuple2(0, 0)
831883 else if ((0 > premium))
832884 then {
833885 let shortPremiumFraction = divd(muld(premium, fundingPeriodDecimal()), ONE_DAY)
834886 let longPremiumFraction = divd(muld(shortPremiumFraction, totalShortPositionSize()), totalLongPositionSize())
835887 $Tuple2(shortPremiumFraction, longPremiumFraction)
836888 }
837889 else {
838890 let longPremiumFraction = divd(muld(premium, fundingPeriodDecimal()), ONE_DAY)
839891 let shortPremiumFraction = divd(muld(longPremiumFraction, totalLongPositionSize()), totalShortPositionSize())
840892 $Tuple2(shortPremiumFraction, longPremiumFraction)
841893 }
842894 }
843895
844896
845897 func getAdjustedFee (_artifactId,_baseFeeDiscount) = {
846898 let baseFeeRaw = fee()
847899 let baseFee = muld(baseFeeRaw, _baseFeeDiscount)
848- let $t03506335558 = if ((_artifactId != ""))
900+ let $t04260043095 = if ((_artifactId != ""))
849901 then {
850902 let artifactKind = strA(nftManagerAddress(), toCompositeKey(k_token_type, _artifactId))
851903 if ((artifactKind == FEE_REDUCTION_TOKEN_TYPE))
852904 then {
853905 let reduction = intA(nftManagerAddress(), toCompositeKey(k_token_param, _artifactId))
854906 let adjustedFee = muld(baseFee, reduction)
855907 $Tuple2(adjustedFee, true)
856908 }
857909 else throw("Invalid attached artifact")
858910 }
859911 else $Tuple2(baseFee, false)
860- let adjustedFee = $t03506335558._1
861- let burnArtifact = $t03506335558._2
912+ let adjustedFee = $t04260043095._1
913+ let burnArtifact = $t04260043095._2
862914 $Tuple2(adjustedFee, burnArtifact)
863915 }
864916
865917
866918 func isSameAssetOrNoPosition (_trader,_assetId) = {
867919 let oldPositionSize = getPosition(_trader)._1
868920 if ((oldPositionSize == 0))
869921 then true
870922 else (getPositionAsset(_trader) == _assetId)
871923 }
872924
873925
874926 func isSameAsset (_trader,_assetId) = (getPositionAsset(_trader) == _assetId)
875927
876928
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-
892929 func getForTraderWithArtifact (_trader,_artifactId) = {
893930 let doGetFeeDiscount = invoke(minerAddress(), "computeFeeDiscount", [_trader], nil)
894931 if ((doGetFeeDiscount == doGetFeeDiscount))
895932 then {
896933 let feeDiscount = match doGetFeeDiscount {
897934 case x: Int =>
898935 x
899936 case _ =>
900937 throw("Invalid computeFeeDiscount result")
901938 }
902- let $t03678936863 = getAdjustedFee(_artifactId, feeDiscount)
903- let adjustedFee = $t03678936863._1
904- let burnArtifact = $t03678936863._2
939+ let $t04377543849 = getAdjustedFee(_artifactId, feeDiscount)
940+ let adjustedFee = $t04377543849._1
941+ let burnArtifact = $t04377543849._2
905942 $Tuple2(adjustedFee, burnArtifact)
906943 }
907944 else throw("Strict value is not equal to itself.")
908945 }
909946
910947
911948 func getArtifactId (i) = {
912949 let artifactId = if ((size(i.payments) > 1))
913950 then toBase58String(valueOrErrorMessage(i.payments[1].assetId, "Invalid artifactId"))
914951 else ""
915952 artifactId
916953 }
917954
918955
919956 func distributeFee (_feeAmount) = {
920957 let feeToStakers = muld(_feeAmount, feeToStakersPercent())
921958 let feeToVault = (_feeAmount - feeToStakers)
922959 $Tuple2(feeToStakers, feeToVault)
923960 }
924961
925962
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)]
927964
928965
929966 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)]
933967
934968
935969 func incrementPositionSequenceNumber (_isNewPosition,_address) = if (_isNewPosition)
936970 then {
937971 let currentSequence = lastSequence()
938972 [IntegerEntry(toCompositeKey(k_positionSequence, _address), (currentSequence + 1)), IntegerEntry(k_sequence, (currentSequence + 1))]
939973 }
940974 else nil
941975
942976
943977 func updatePositionFee (_isNewPosition,_address,_fee) = if (_isNewPosition)
944978 then [IntegerEntry(toCompositeKey(k_positionFee, _address), _fee)]
945979 else nil
946980
947981
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)]
949983
950984
951985 func appendTwap (_price) = {
952- let minuteId = ((lastBlock.timestamp / 1000) / 60)
986+ let minuteId = ((lastTimestamp() / 1000) / 60)
953987 let previousMinuteId = valueOrElse(getInteger(this, k_lastMinuteId), 0)
954988 if ((previousMinuteId > minuteId))
955989 then throw("TWAP out-of-order")
956990 else {
957991 let lastMinuteId = if ((previousMinuteId == 0))
958992 then minuteId
959993 else previousMinuteId
960994 if ((minuteId > previousMinuteId))
961995 then {
962996 let prevCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(previousMinuteId))), 0)
963997 let prevPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(previousMinuteId))), _price)
964998 let lastCumulativePrice = (prevCumulativePrice + ((minuteId - lastMinuteId) * prevPrice))
965999 let list = pushToQueue(strToList(valueOrElse(getString(this, k_lastDataStr), "")), TWAP_INTERVAL, toString(minuteId))
9661000 [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))]
9671001 }
9681002 else {
9691003 let twapDataPreviousMinuteId = valueOrElse(getInteger(this, toCompositeKey(k_twapDataPreviousMinuteId, toString(minuteId))), 0)
9701004 let prevCumulativePrice = valueOrElse(getInteger(this, toCompositeKey(k_twapDataLastCumulativePrice, toString(twapDataPreviousMinuteId))), 0)
9711005 let prevPrice = valueOrElse(getInteger(this, toCompositeKey(k_twapDataLastPrice, toString(twapDataPreviousMinuteId))), _price)
9721006 let lastCumulativePrice = (prevCumulativePrice + ((minuteId - twapDataPreviousMinuteId) * prevPrice))
9731007 [IntegerEntry(toCompositeKey(k_twapDataLastCumulativePrice, toString(minuteId)), lastCumulativePrice), IntegerEntry(toCompositeKey(k_twapDataLastPrice, toString(minuteId)), _price)]
9741008 }
9751009 }
9761010 }
9771011
9781012
9791013 func updateAmmReserves (_qtAstR,_bsAstR) = [IntegerEntry(k_quoteAssetReserve, _qtAstR), IntegerEntry(k_baseAssetReserve, _bsAstR)]
9801014
9811015
9821016 func updateAmmWeights (_qtAstW,_bsAstW) = [IntegerEntry(k_quoteAssetWeight, _qtAstW), IntegerEntry(k_baseAssetWeight, _bsAstW)]
9831017
9841018
9851019 func updateAmm (_qtAstR,_bsAstR,_totalPositionSizeAfter,_openInterestNotional,_totalLongPositionSize,_totalShortPositionSize,_totalLongOpenNotional,_totalShortOpenNotional) = {
9861020 let _qtAstW = qtAstW()
9871021 let _bsAstW = bsAstW()
9881022 if (((_totalLongPositionSize - _totalShortPositionSize) != _totalPositionSizeAfter))
9891023 then throw(((((("Invalid AMM state data: " + toString(_totalLongPositionSize)) + " + ") + toString(_totalShortPositionSize)) + " != ") + toString(_totalPositionSizeAfter)))
9901024 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))))
9911025 }
9921026
9931027
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))]
9951029
9961030
9971031 func withdraw (_address,_amount) = {
9981032 let balance = assetBalance(this, quoteAsset())
9991033 if ((_amount > balance))
10001034 then throw(((("Unable to withdraw " + toString(_amount)) + " from contract balance ") + toString(balance)))
10011035 else [ScriptTransfer(_address, _amount, quoteAsset())]
10021036 }
10031037
10041038
10051039 func updateBalance (i) = if ((0 > i))
10061040 then throw("Balance")
10071041 else [IntegerEntry(k_balance, i)]
10081042
10091043
10101044 func transferFee (i) = [ScriptTransfer(stakingAddress(), i, quoteAsset())]
10111045
10121046
10131047 func doBurnArtifact (_burnArtifact,i) = if (_burnArtifact)
10141048 then [Burn(valueOrErrorMessage(i.payments[1].assetId, "Invalid artifact"), 1)]
10151049 else nil
10161050
10171051
10181052 @Callable(i)
10191053 func pause () = if ((i.caller != adminAddress()))
10201054 then throw("Invalid pause params")
10211055 else [BooleanEntry(k_paused, true)]
10221056
10231057
10241058
10251059 @Callable(i)
10261060 func unpause () = if ((i.caller != adminAddress()))
10271061 then throw("Invalid unpause params")
10281062 else [BooleanEntry(k_paused, false)]
10291063
10301064
10311065
10321066 @Callable(i)
10331067 func setCloseOnly () = if ((i.caller != adminAddress()))
10341068 then throw("Invalid setCloseOnly params")
10351069 else [BooleanEntry(k_closeOnly, true)]
10361070
10371071
10381072
10391073 @Callable(i)
10401074 func unsetCloseOnly () = if ((i.caller != adminAddress()))
10411075 then throw("Invalid unsetCloseOnly params")
10421076 else [BooleanEntry(k_closeOnly, false)]
10431077
10441078
10451079
10461080 @Callable(i)
10471081 func addLiquidity (_quoteAssetAmount) = if (if ((i.caller != adminAddress()))
10481082 then true
10491083 else (0 >= _quoteAssetAmount))
10501084 then throw("Invalid addLiquidity params")
10511085 else {
10521086 let _qtAstR = qtAstR()
10531087 let _bsAstR = bsAstR()
10541088 let _qtAstW = qtAstW()
10551089 let _bsAstW = bsAstW()
10561090 let price = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW))
10571091 let qtAstRAfter = (_qtAstR + _quoteAssetAmount)
10581092 let baseAssetAmountToAdd = (divd(muld(qtAstRAfter, _qtAstW), price) - _bsAstR)
10591093 let bsAstRAfter = (_bsAstR + baseAssetAmountToAdd)
1060- let $t04610746258 = getSyncTerminalPrice(getOraclePrice(), qtAstRAfter, bsAstRAfter)
1061- let newQuoteAssetWeight = $t04610746258._1
1062- let newBaseAssetWeight = $t04610746258._2
1063- let marginToVault = $t04610746258._3
1094+ let $t05325653407 = getSyncTerminalPrice(getOraclePrice(), qtAstRAfter, bsAstRAfter)
1095+ let newQuoteAssetWeight = $t05325653407._1
1096+ let newBaseAssetWeight = $t05325653407._2
1097+ let marginToVault = $t05325653407._3
10641098 let doExchangePnL = if ((marginToVault != 0))
10651099 then {
10661100 let doExchangePnL = invoke(vaultAddress(), "exchangeFreeAndLocked", [marginToVault], nil)
10671101 if ((doExchangePnL == doExchangePnL))
10681102 then nil
10691103 else throw("Strict value is not equal to itself.")
10701104 }
10711105 else nil
10721106 if ((doExchangePnL == doExchangePnL))
10731107 then (updateAmmReserves(qtAstRAfter, bsAstRAfter) ++ updateAmmWeights(newQuoteAssetWeight, newBaseAssetWeight))
10741108 else throw("Strict value is not equal to itself.")
10751109 }
10761110
10771111
10781112
10791113 @Callable(i)
10801114 func removeLiquidity (_quoteAssetAmount) = if (if ((i.caller != adminAddress()))
10811115 then true
10821116 else (_quoteAssetAmount >= 0))
10831117 then throw("Invalid removeLiquidity params")
10841118 else {
10851119 let _qtAstR = qtAstR()
10861120 let _bsAstR = bsAstR()
10871121 let _qtAstW = qtAstW()
10881122 let _bsAstW = bsAstW()
10891123 let price = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW))
10901124 let qtAstRAfter = (_qtAstR - _quoteAssetAmount)
10911125 let baseAssetAmountToRemove = abs((divd(muld(qtAstRAfter, _qtAstW), price) - _bsAstR))
10921126 let bsAstRAfter = (_bsAstR - baseAssetAmountToRemove)
1093- let $t04719047341 = getSyncTerminalPrice(getOraclePrice(), qtAstRAfter, bsAstRAfter)
1094- let newQuoteAssetWeight = $t04719047341._1
1095- let newBaseAssetWeight = $t04719047341._2
1096- let marginToVault = $t04719047341._3
1127+ let $t05433954490 = getSyncTerminalPrice(getOraclePrice(), qtAstRAfter, bsAstRAfter)
1128+ let newQuoteAssetWeight = $t05433954490._1
1129+ let newBaseAssetWeight = $t05433954490._2
1130+ let marginToVault = $t05433954490._3
10971131 let doExchangePnL = if ((marginToVault != 0))
10981132 then {
10991133 let doExchangePnL = invoke(vaultAddress(), "exchangeFreeAndLocked", [marginToVault], nil)
11001134 if ((doExchangePnL == doExchangePnL))
11011135 then nil
11021136 else throw("Strict value is not equal to itself.")
11031137 }
11041138 else nil
11051139 if ((doExchangePnL == doExchangePnL))
11061140 then (updateAmmReserves(qtAstRAfter, bsAstRAfter) ++ updateAmmWeights(newQuoteAssetWeight, newBaseAssetWeight))
11071141 else throw("Strict value is not equal to itself.")
11081142 }
11091143
11101144
11111145
11121146 @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()))
11141148 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)
11161150
11171151
11181152
11191153 @Callable(i)
1120-func initialize (_qtAstR,_bsAstR,_fundingPeriod,_initMarginRatio,_mmr,_liquidationFeeRatio,_fee,_oracle,_oracleKey,_oracleBlockKey,_coordinator,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional,_feeToStakersPercent,_maxOracleDelay) = if (if (if (if (if (if (if (if (if (if (if (if (if (if (if (if ((0 >= _qtAstR))
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))
11211155 then true
11221156 else (0 >= _bsAstR))
11231157 then true
11241158 else (0 >= _fundingPeriod))
11251159 then true
11261160 else (0 >= _initMarginRatio))
11271161 then true
11281162 else (0 >= _mmr))
11291163 then true
11301164 else (0 >= _liquidationFeeRatio))
11311165 then true
11321166 else (0 >= _fee))
11331167 then true
11341168 else (0 >= _spreadLimit))
11351169 then true
11361170 else (0 >= _maxPriceImpact))
11371171 then true
11381172 else (0 >= _partialLiquidationRatio))
11391173 then true
11401174 else (0 >= _maxPriceSpread))
11411175 then true
11421176 else (0 >= _maxOpenNotional))
11431177 then true
11441178 else (0 >= _feeToStakersPercent))
11451179 then true
11461180 else (_feeToStakersPercent > DECIMAL_UNIT))
11471181 then true
11481182 else (0 >= _maxOracleDelay))
11491183 then true
1184+ else (0 >= _rolloverFee))
1185+ then true
11501186 else initialized())
11511187 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((lastBlock.timestamp + _fundingPeriod), 0, 0, 0, 0)) ++ updateBalance(0)) ++ [BooleanEntry(k_initialized, true), StringEntry(k_ora, _oracle), StringEntry(k_ora_key, _oracleKey), StringEntry(k_ora_block_key, _oracleBlockKey), StringEntry(k_coordinatorAddress, _coordinator)])
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)])
11531189
11541190
11551191
11561192 @Callable(i)
11571193 func increasePosition (_direction,_leverage,_minBaseAssetAmount,_refLink) = {
11581194 let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
11591195 if ((sync == sync))
11601196 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)
12251231 let referrerFeeAny = invoke(referralAddress(), "acceptPaymentWithLink", [_trader, _refLink], [AttachedPayment(quoteAsset(), distributeFeeAmount)])
12261232 if ((referrerFeeAny == referrerFeeAny))
12271233 then {
12281234 let referrerFee = match referrerFeeAny {
12291235 case x: Int =>
12301236 x
12311237 case _ =>
12321238 throw("Invalid referrerFee")
12331239 }
12341240 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
12401247 let isNewPosition = (oldPositionSize == 0)
12411248 let isSameDirection = if ((oldPositionSize > 0))
12421249 then (_direction == DIR_LONG)
12431250 else (_direction == DIR_SHORT)
12441251 let expandExisting = if (!(isNewPosition))
12451252 then isSameDirection
12461253 else false
12471254 let isAdd = (_direction == DIR_LONG)
1248- let $t05292955891 = if (if (isNewPosition)
1255+ let $t05931162432 = if (if (isNewPosition)
12491256 then true
12501257 else expandExisting)
12511258 then {
12521259 let openNotional = muld(_amount, _leverage)
1253- let $t05339153564 = swapInput(isAdd, openNotional)
1254- let amountBaseAssetBought = $t05339153564._1
1255- let quoteAssetReserveAfter = $t05339153564._2
1256- let baseAssetReserveAfter = $t05339153564._3
1257- let totalPositionSizeAfter = $t05339153564._4
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
12581265 if (if ((_minBaseAssetAmount != 0))
12591266 then (_minBaseAssetAmount > abs(amountBaseAssetBought))
12601267 else false)
12611268 then throw(((("Limit error: " + toString(abs(amountBaseAssetBought))) + " < ") + toString(_minBaseAssetAmount)))
12621269 else {
12631270 let newPositionSize = (oldPositionSize + amountBaseAssetBought)
12641271 let totalLongOpenInterestAfter = (openInterestLong() + (if ((newPositionSize > 0))
12651272 then openNotional
12661273 else 0))
12671274 let totalShortOpenInterestAfter = (openInterestShort() + (if ((0 > newPositionSize))
12681275 then openNotional
12691276 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
12741282 if (!(requireNotOverSpreadLimit(quoteAssetReserveAfter, baseAssetReserveAfter)))
12751283 then throw("Over max spread limit")
12761284 else if (!(requireNotOverMaxOpenNotional(totalLongOpenInterestAfter, totalShortOpenInterestAfter)))
12771285 then throw("Over max open notional")
1278- else $Tuple12(newPositionSize, remainMargin, (oldPositionOpenNotional + openNotional), latestCumulativePremiumFraction(newPositionSize), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, (openInterestNotional() + openNotional), (totalLongPositionSize() + (if ((newPositionSize > 0))
1286+ else $Tuple14(newPositionSize, remainMargin, (oldPositionOpenNotional + openNotional), latestCumulativePremiumFraction(newPositionSize), lastTimestamp(), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, (openInterestNotional() + openNotional), (totalLongPositionSize() + (if ((newPositionSize > 0))
12791287 then abs(amountBaseAssetBought)
12801288 else 0)), (totalShortPositionSize() + (if ((0 > newPositionSize))
12811289 then abs(amountBaseAssetBought)
1282- else 0)), totalLongOpenInterestAfter, totalShortOpenInterestAfter)
1290+ else 0)), totalLongOpenInterestAfter, totalShortOpenInterestAfter, rolloverFee)
12831291 }
12841292 }
12851293 else {
12861294 let openNotional = muld(_amount, _leverage)
1287- let $t05559155707 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT)
1288- let oldPositionNotional = $t05559155707._1
1289- let unrealizedPnl = $t05559155707._2
1295+ let $t06213262248 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT)
1296+ let oldPositionNotional = $t06213262248._1
1297+ let unrealizedPnl = $t06213262248._2
12901298 if ((oldPositionNotional > openNotional))
12911299 then throw("Use decreasePosition to decrease position size")
12921300 else throw("Close position first")
12931301 }
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)
13171322 if ((stake == stake))
13181323 then {
13191324 let depositVault = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToVault)])
13201325 if ((depositVault == depositVault))
13211326 then {
13221327 let notifyFee = invoke(minerAddress(), "notifyFees", [_trader, feeAmount], nil)
13231328 if ((notifyFee == notifyFee))
13241329 then {
13251330 let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil)
13261331 if ((notifyNotional == notifyNotional))
1327- then (((((((updatePosition(_trader, newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF) ++ incrementPositionSequenceNumber(isNewPosition, _trader)) ++ updatePositionFee(isNewPosition, _trader, adjustedFee)) ++ updatePositionAsset(_trader, _assetIdStr)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) ++ doBurnArtifact(burnArtifact, i))
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))
13281333 else throw("Strict value is not equal to itself.")
13291334 }
13301335 else throw("Strict value is not equal to itself.")
13311336 }
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))
13321661 else throw("Strict value is not equal to itself.")
13331662 }
13341663 else throw("Strict value is not equal to itself.")
13351664 }
13361665 else throw("Strict value is not equal to itself.")
13371666 }
13381667 else throw("Strict value is not equal to itself.")
13391668 }
13401669 }
13411670 else throw("Strict value is not equal to itself.")
13421671 }
13431672
13441673
13451674
13461675 @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)
19131676 func payFunding () = {
19141677 let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
19151678 if ((sync == sync))
19161679 then {
19171680 let fundingBlockTimestamp = nextFundingBlockTimestamp()
1918- if (if (if ((fundingBlockTimestamp > lastBlock.timestamp))
1681+ if (if (if ((fundingBlockTimestamp > lastTimestamp()))
19191682 then true
19201683 else !(initialized()))
19211684 then true
19221685 else paused())
1923- then throw(((("Invalid funding block timestamp: " + toString(lastBlock.timestamp)) + " < ") + toString(fundingBlockTimestamp)))
1686+ then throw(((("Invalid funding block timestamp: " + toString(lastTimestamp())) + " < ") + toString(fundingBlockTimestamp)))
19241687 else {
19251688 let underlyingPrice = getOraclePrice()
1926- let $t08088280944 = getFunding()
1927- let shortPremiumFraction = $t08088280944._1
1928- let longPremiumFraction = $t08088280944._2
1689+ let $t07530775369 = getFunding()
1690+ let shortPremiumFraction = $t07530775369._1
1691+ let longPremiumFraction = $t07530775369._2
19291692 updateFunding((fundingBlockTimestamp + fundingPeriodSeconds()), (latestLongCumulativePremiumFraction() + longPremiumFraction), (latestShortCumulativePremiumFraction() + shortPremiumFraction), divd(longPremiumFraction, underlyingPrice), divd(shortPremiumFraction, underlyingPrice))
19301693 }
19311694 }
19321695 else throw("Strict value is not equal to itself.")
19331696 }
19341697
19351698
19361699
19371700 @Callable(i)
19381701 func syncTerminalPriceToOracle () = {
19391702 let _qtAstR = qtAstR()
19401703 let _bsAstR = bsAstR()
1941- let $t08137681511 = getSyncTerminalPrice(getOraclePrice(), _qtAstR, _bsAstR)
1942- let newQuoteAssetWeight = $t08137681511._1
1943- let newBaseAssetWeight = $t08137681511._2
1944- let marginToVault = $t08137681511._3
1704+ let $t07580175936 = getSyncTerminalPrice(getOraclePrice(), _qtAstR, _bsAstR)
1705+ let newQuoteAssetWeight = $t07580175936._1
1706+ let newBaseAssetWeight = $t07580175936._2
1707+ let marginToVault = $t07580175936._3
19451708 let doExchangePnL = if ((marginToVault != 0))
19461709 then {
19471710 let doExchangePnL = invoke(vaultAddress(), "exchangeFreeAndLocked", [marginToVault], nil)
19481711 if ((doExchangePnL == doExchangePnL))
19491712 then nil
19501713 else throw("Strict value is not equal to itself.")
19511714 }
19521715 else nil
19531716 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))))
19551718 else throw("Strict value is not equal to itself.")
19561719 }
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+ }
19571732
19581733
19591734
19601735 @Callable(i)
19611736 func view_calcRemainMarginWithFundingPayment (_trader) = {
19621737 let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
19631738 if ((sync == sync))
19641739 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)))
19781755 }
19791756 else throw("Strict value is not equal to itself.")
19801757 }
19811758
19821759
19831760
19841761 @Callable(i)
19851762 func view_getPegAdjustCost (_price) = {
19861763 let _qtAstR = qtAstR()
19871764 let _bsAstR = bsAstR()
19881765 let result = getSyncTerminalPrice(_price, _qtAstR, _bsAstR)
19891766 throw(toString(result._3))
19901767 }
19911768
19921769
19931770
19941771 @Callable(i)
19951772 func view_getTerminalAmmPrice () = {
1996- let $t08287682957 = getTerminalAmmState()
1997- let terminalQuoteAssetReserve = $t08287682957._1
1998- let terminalBaseAssetReserve = $t08287682957._2
1773+ let $t07783277913 = getTerminalAmmState()
1774+ let terminalQuoteAssetReserve = $t07783277913._1
1775+ let terminalBaseAssetReserve = $t07783277913._2
19991776 let price = divd(muld(terminalQuoteAssetReserve, qtAstW()), muld(terminalBaseAssetReserve, bsAstW()))
20001777 throw(toString(price))
20011778 }
20021779
20031780
20041781
20051782 @Callable(i)
20061783 func view_getFunding () = {
20071784 let underlyingPrice = getOraclePrice()
2008- let $t08317283234 = getFunding()
2009- let shortPremiumFraction = $t08317283234._1
2010- let longPremiumFraction = $t08317283234._2
1785+ let $t07812878190 = getFunding()
1786+ let shortPremiumFraction = $t07812878190._1
1787+ let longPremiumFraction = $t07812878190._2
20111788 let longFunding = divd(longPremiumFraction, underlyingPrice)
20121789 let shortFunding = divd(shortPremiumFraction, underlyingPrice)
20131790 throw((((s(longFunding) + s(shortFunding)) + s(getTwapSpotPrice())) + s(getOraclePrice())))
20141791 }
20151792
20161793
20171794
20181795 @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)
20291796 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.")
20321804 }
20331805
20341806
20351807
20361808 @Callable(i)
20371809 func computeFeeForTraderWithArtifact (_trader,_artifactId) = {
20381810 let result = getForTraderWithArtifact(_trader, _artifactId)
20391811 $Tuple2(nil, result)
20401812 }
20411813
20421814
20431815 @Verifier(tx)
20441816 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], adminPublicKey())
20451817

github/deemru/w8io/026f985 
262.89 ms