tx · F3UGMSQFKnv1otcpC9jNZzmhXGnToxQPjEm6beCFwih6

3N8G95pEaYEhZ4U3m3UrzpEzwBFn5vvXsZH:  -0.07000000 Waves

2022.12.08 11:42 [2351140] smart account 3N8G95pEaYEhZ4U3m3UrzpEzwBFn5vvXsZH > SELF 0.00000000 Waves

{ "type": 13, "id": "F3UGMSQFKnv1otcpC9jNZzmhXGnToxQPjEm6beCFwih6", "fee": 7000000, "feeAssetId": null, "timestamp": 1670488924669, "version": 2, "chainId": 84, "sender": "3N8G95pEaYEhZ4U3m3UrzpEzwBFn5vvXsZH", "senderPublicKey": "Hj6oyH6As5UWo8fZ1K4hPsEY7nxH3MvhBqDD6axiwjXs", "proofs": [ "5xNbSYM7xZLT4UR9ceb42bdLr3v2y382px5KTiVHHWoCe5JS4F9ja7sY2Q6SngmhT4r1fNRNYW26HCM5A5QA4jjm" ], "script": "base64:BgJ1CAISABIAEgASABIDCgEBEgMKAQESDAoKAQEBAQEBAQEBARIRCg8BAQEBAQEBCAgIAQEBAQESBQoDAQEBEgYKBAEBAQgSABIDCgEBEgQKAgEBEgMKAQgSABIAEgMKAQgSAwoBARIAEgASAwoBCBIAEgQKAggIuwEACWtfb3JhX2tleQIJa19vcmFfa2V5AA9rX29yYV9ibG9ja19rZXkCD2tfb3JhX2Jsb2NrX2tleQAFa19vcmECBWtfb3JhAAlrX2JhbGFuY2UCCWtfYmFsYW5jZQAKa19zZXF1ZW5jZQIKa19zZXF1ZW5jZQAOa19wb3NpdGlvblNpemUCDmtfcG9zaXRpb25TaXplABBrX3Bvc2l0aW9uTWFyZ2luAhBrX3Bvc2l0aW9uTWFyZ2luABZrX3Bvc2l0aW9uT3Blbk5vdGlvbmFsAhZrX3Bvc2l0aW9uT3Blbk5vdGlvbmFsAC5rX3Bvc2l0aW9uTGFzdFVwZGF0ZWRDdW11bGF0aXZlUHJlbWl1bUZyYWN0aW9uAhJrX3Bvc2l0aW9uRnJhY3Rpb24AEmtfcG9zaXRpb25TZXF1Z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XBTcG90UHJpY2UACQEBcwEJARJnZXRPcmFjbGVUd2FwUHJpY2UAAWkBGHZpZXdfZ2V0Qm9ycm93ZWRCeVRyYWRlcgEHX3RyYWRlcgQNJHQwODE4ODE4MTkzNQkBE2dldEJvcnJvd2VkQnlUcmFkZXIBBQdfdHJhZGVyBAhib3Jyb3dlZAgFDSR0MDgxODgxODE5MzUCXzEEB2Fzc2V0SWQIBQ0kdDA4MTg4MTgxOTM1Al8yCQACAQkArAICCQEBcwEFCGJvcnJvd2VkBQdhc3NldElkAWkBEGNvbXB1dGVTcG90UHJpY2UABAZyZXN1bHQJAQxnZXRTcG90UHJpY2UACQCUCgIFA25pbAUGcmVzdWx0AWkBH2NvbXB1dGVGZWVGb3JUcmFkZXJXaXRoQXJ0aWZhY3QCB190cmFkZXILX2FydGlmYWN0SWQEBnJlc3VsdAkBGGdldEZvclRyYWRlcldpdGhBcnRpZmFjdAIFB190cmFkZXIFC19hcnRpZmFjdElkCQCUCgIFA25pbAUGcmVzdWx0AQJ0eAEGdmVyaWZ5AAkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAkBDmFkbWluUHVibGljS2V5AEfFPW0=", "height": 2351140, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 7fdsf7EVU5bmorExRwuSifrekRHkDh25t9iX9biFML3m Next: none Diff:
OldNewDifferences
99
1010 let k_balance = "k_balance"
1111
12+let k_sequence = "k_sequence"
13+
1214 let k_positionSize = "k_positionSize"
1315
1416 let k_positionMargin = "k_positionMargin"
1719
1820 let k_positionLastUpdatedCumulativePremiumFraction = "k_positionFraction"
1921
20-let k_positionClosedDate = "k_positionClosedDate"
22+let k_positionSequence = "k_positionSequence"
2123
2224 let k_positionAsset = "k_positionAsset"
2325
2426 let k_initialized = "k_initialized"
2527
2628 let k_paused = "k_paused"
29+
30+let k_closeOnly = "k_closeOnly"
2731
2832 let k_fee = "k_fee"
2933
4246 let k_maxPriceImpact = "k_maxPriceImpact"
4347
4448 let k_maxPriceSpread = "k_maxPriceSpread"
49+
50+let k_maxOpenNotional = "k_maxOpenNotional"
4551
4652 let k_lastDataStr = "k_lastDataStr"
4753
6773
6874 let k_baseAssetReserve = "k_bsAstR"
6975
76+let k_quoteAssetWeight = "k_qtAstW"
77+
78+let k_baseAssetWeight = "k_bsAstW"
79+
7080 let k_totalPositionSize = "k_totalPositionSize"
7181
7282 let k_totalLongPositionSize = "k_totalLongPositionSize"
7383
7484 let k_totalShortPositionSize = "k_totalShortPositionSize"
7585
76-let k_cumulativeNotional = "k_cumulativeNotional"
86+let k_openInterestNotional = "k_openInterestNotional"
7787
78-let k_openInterestNotional = "k_openInterestNotional"
88+let k_openInterestShort = "k_openInterestShort"
89+
90+let k_openInterestLong = "k_openInterestLong"
7991
8092 let k_coordinatorAddress = "k_coordinatorAddress"
8193
82-let k_insurance_address = "k_insurance_address"
94+let k_vault_address = "k_vault_address"
8395
8496 let k_admin_address = "k_admin_address"
8597
96108 let k_orders_address = "k_orders_address"
97109
98110 let k_referral_address = "k_referral_address"
99-
100-let k_manager_address = "k_manager_address"
101111
102112 let k_collateral_address = "k_collateral_address"
103113
128138 func stakingAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_staking_address)), "Staking not set")
129139
130140
131-func insuranceAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_insurance_address)), "Insurance not set")
141+func vaultAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_vault_address)), "Vault not set")
132142
133143
134144 func minerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_miner_address)), "Miner not set")
138148
139149
140150 func referralAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_referral_address)), "Referral not set")
141-
142-
143-func managerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_manager_address)), "Manager not set")
144151
145152
146153 func nftManagerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_nft_manager_address)), "NFT Manager not set")
173180
174181 let SECONDS = 1000
175182
183+let DECIMAL_NUMBERS = 6
184+
176185 let DECIMAL_UNIT = (1 * (((((10 * 10) * 10) * 10) * 10) * 10))
177186
178187 let ONE_DAY = (86400 * DECIMAL_UNIT)
190199
191200
192201 func muld (_x,_y) = fraction(_x, _y, DECIMAL_UNIT, HALFEVEN)
202+
203+
204+func sqrtd (_x) = sqrt(_x, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN)
205+
206+
207+func powd (_x,_y) = pow(_x, DECIMAL_NUMBERS, _y, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN)
208+
209+
210+func bdivd (_x,_y) = fraction(_x, toBigInt(DECIMAL_UNIT), _y, HALFEVEN)
211+
212+
213+func bmuld (_x,_y) = fraction(_x, _y, toBigInt(DECIMAL_UNIT), HALFEVEN)
214+
215+
216+func bsqrtd (_x) = sqrtBigInt(_x, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN)
217+
218+
219+func bpowd (_x,_y) = pow(_x, DECIMAL_NUMBERS, _y, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN)
193220
194221
195222 func abs (_x) = if ((_x > 0))
238265 func int (k) = valueOrErrorMessage(getInteger(this, k), ("no value for " + k))
239266
240267
268+func intOr (k,def) = valueOrElse(getInteger(this, k), def)
269+
270+
241271 func strA (_address,_key) = {
242272 let val = valueOrErrorMessage(getString(_address, _key), ("No value for key " + _key))
243273 val
265295 func bsAstR () = int(k_baseAssetReserve)
266296
267297
298+func qtAstW () = intOr(k_quoteAssetWeight, DECIMAL_UNIT)
299+
300+
301+func bsAstW () = intOr(k_baseAssetWeight, DECIMAL_UNIT)
302+
303+
268304 func totalPositionSize () = int(k_totalPositionSize)
269305
270306
271-func cumulativeNotional () = int(k_cumulativeNotional)
307+func openInterestNotional () = int(k_openInterestNotional)
272308
273309
274-func openInterestNotional () = int(k_openInterestNotional)
310+func openInterestShort () = int(k_openInterestShort)
311+
312+
313+func openInterestLong () = int(k_openInterestLong)
275314
276315
277316 func nextFundingBlockTimestamp () = int(k_nextFundingBlock)
304343 func maxPriceSpread () = int(k_maxPriceSpread)
305344
306345
346+func maxOpenNotional () = int(k_maxOpenNotional)
347+
348+
307349 func latestLongCumulativePremiumFraction () = int(k_latestLongCumulativePremiumFraction)
308350
309351
314356
315357
316358 func totalLongPositionSize () = int(k_totalLongPositionSize)
359+
360+
361+func lastSequence () = intOr(k_sequence, 0)
317362
318363
319364 func getActualCaller (i) = valueOrElse(getString(ordersAddress(), "k_sender"), toString(i.caller))
373418 func paused () = valueOrElse(getBoolean(this, k_paused), false)
374419
375420
421+func closeOnly () = valueOrElse(getBoolean(this, k_closeOnly), false)
422+
423+
376424 func updateReserve (_isAdd,_quoteAssetAmount,_baseAssetAmount) = if (_isAdd)
377425 then {
378426 let newBase = (bsAstR() - _baseAssetAmount)
379427 if ((0 >= newBase))
380428 then throw("Tx lead to base asset reserve <= 0, revert")
381- else $Tuple4((qtAstR() + _quoteAssetAmount), newBase, (totalPositionSize() + _baseAssetAmount), (cumulativeNotional() + _quoteAssetAmount))
429+ else $Tuple3((qtAstR() + _quoteAssetAmount), newBase, (totalPositionSize() + _baseAssetAmount))
382430 }
383431 else {
384432 let newQuote = (qtAstR() - _quoteAssetAmount)
385433 if ((0 >= newQuote))
386434 then throw("Tx lead to base quote reserve <= 0, revert")
387- else $Tuple4(newQuote, (bsAstR() + _baseAssetAmount), (totalPositionSize() - _baseAssetAmount), (cumulativeNotional() - _quoteAssetAmount))
435+ else $Tuple3(newQuote, (bsAstR() + _baseAssetAmount), (totalPositionSize() - _baseAssetAmount))
388436 }
437+
438+
439+func calcInvariant (_qtAstR,_qtAstW,_bsAstR,_bsAstW) = {
440+ let bqtAstR = toBigInt(_qtAstR)
441+ let bqtAstW = toBigInt(_qtAstW)
442+ let bbsAstR = toBigInt(_bsAstR)
443+ let bbsAstW = toBigInt(_bsAstW)
444+ bmuld(bmuld(bqtAstR, bqtAstW), bmuld(bbsAstR, bbsAstW))
445+ }
389446
390447
391448 func swapInput (_isAdd,_quoteAssetAmount) = {
392449 let _qtAstR = qtAstR()
393450 let _bsAstR = bsAstR()
394- let k = muld(_qtAstR, _bsAstR)
451+ let _qtAstW = qtAstW()
452+ let _bsAstW = bsAstW()
453+ let k = calcInvariant(_qtAstR, _qtAstW, _bsAstR, _bsAstW)
395454 let quoteAssetReserveAfter = if (_isAdd)
396455 then (_qtAstR + _quoteAssetAmount)
397456 else (_qtAstR - _quoteAssetAmount)
398- let baseAssetReserveAfter = divd(k, quoteAssetReserveAfter)
399- let amountBaseAssetBoughtAbs = abs((baseAssetReserveAfter - _bsAstR))
457+ let baseAssetReserveAfter = toInt(bdivd(k, toBigInt(muld(quoteAssetReserveAfter, _qtAstW))))
458+ let amountBaseAssetBoughtAbs = divd(abs((baseAssetReserveAfter - _bsAstR)), _qtAstW)
400459 let amountBaseAssetBought = if (_isAdd)
401460 then amountBaseAssetBoughtAbs
402461 else -(amountBaseAssetBoughtAbs)
403- let $t01497415167 = updateReserve(_isAdd, _quoteAssetAmount, amountBaseAssetBoughtAbs)
404- let quoteAssetReserveAfter1 = $t01497415167._1
405- let baseAssetReserveAfter1 = $t01497415167._2
406- let totalPositionSizeAfter1 = $t01497415167._3
407- let cumulativeNotionalAfter1 = $t01497415167._4
408- let priceBefore = divd(_qtAstR, _bsAstR)
462+ let $t01665516818 = updateReserve(_isAdd, _quoteAssetAmount, amountBaseAssetBoughtAbs)
463+ let quoteAssetReserveAfter1 = $t01665516818._1
464+ let baseAssetReserveAfter1 = $t01665516818._2
465+ let totalPositionSizeAfter1 = $t01665516818._3
466+ let priceBefore = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW))
409467 let marketPrice = divd(_quoteAssetAmount, amountBaseAssetBoughtAbs)
410468 let priceDiff = abs((priceBefore - marketPrice))
411469 let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff)))
412470 let maxPriceImpactValue = maxPriceImpact()
413471 if ((priceImpact > maxPriceImpactValue))
414472 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)))
415- else $Tuple5(amountBaseAssetBought, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, cumulativeNotionalAfter1)
473+ else $Tuple4(amountBaseAssetBought, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1)
416474 }
417475
418476
424482 }
425483 else 0
426484 let signedMargin = ((_marginDelta - fundingPayment) + _oldPositionMargin)
427- let $t01665816785 = if ((0 > signedMargin))
485+ let $t01830518432 = if ((0 > signedMargin))
428486 then $Tuple2(0, abs(signedMargin))
429487 else $Tuple2(abs(signedMargin), 0)
430- let remainMargin = $t01665816785._1
431- let badDebt = $t01665816785._2
488+ let remainMargin = $t01830518432._1
489+ let badDebt = $t01830518432._2
432490 $Tuple3(remainMargin, badDebt, fundingPayment)
433491 }
434492
435493
436-func swapOutputWithReserves (_isAdd,_baseAssetAmount,_checkMaxPriceImpact,_quoteAssetReserve,_baseAssetReserve) = {
437- let priceBefore = divd(_quoteAssetReserve, _baseAssetReserve)
494+func swapOutputWithReserves (_isAdd,_baseAssetAmount,_checkMaxPriceImpact,_quoteAssetReserve,_quoteAssetWeight,_baseAssetReserve,_baseAssetWeight) = {
495+ let priceBefore = divd(muld(_quoteAssetReserve, _quoteAssetWeight), muld(_baseAssetReserve, _baseAssetWeight))
438496 if ((_baseAssetAmount == 0))
439497 then throw("Invalid base asset amount")
440498 else {
441- let k = muld(_quoteAssetReserve, _baseAssetReserve)
499+ let k = calcInvariant(_quoteAssetReserve, _quoteAssetWeight, _baseAssetReserve, _baseAssetWeight)
442500 let baseAssetPoolAmountAfter = if (_isAdd)
443501 then (_baseAssetReserve + _baseAssetAmount)
444502 else (_baseAssetReserve - _baseAssetAmount)
445- let quoteAssetAfter = divd(k, baseAssetPoolAmountAfter)
446- let quoteAssetSold = abs((quoteAssetAfter - _quoteAssetReserve))
503+ let quoteAssetAfter = toInt(bdivd(k, toBigInt(muld(baseAssetPoolAmountAfter, _baseAssetWeight))))
504+ let quoteAssetSold = abs((quoteAssetAfter - muld(_quoteAssetReserve, _quoteAssetWeight)))
447505 let maxPriceImpactValue = maxPriceImpact()
448- let $t01776217955 = updateReserve(!(_isAdd), quoteAssetSold, _baseAssetAmount)
449- let quoteAssetReserveAfter1 = $t01776217955._1
450- let baseAssetReserveAfter1 = $t01776217955._2
451- let totalPositionSizeAfter1 = $t01776217955._3
452- let cumulativeNotionalAfter1 = $t01776217955._4
506+ let $t01962019781 = updateReserve(!(_isAdd), quoteAssetSold, _baseAssetAmount)
507+ let quoteAssetReserveAfter1 = $t01962019781._1
508+ let baseAssetReserveAfter1 = $t01962019781._2
509+ let totalPositionSizeAfter1 = $t01962019781._3
453510 let marketPrice = divd(quoteAssetSold, _baseAssetAmount)
454511 let priceDiff = abs((priceBefore - marketPrice))
455512 let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff)))
457514 then _checkMaxPriceImpact
458515 else false)
459516 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)))
460- else $Tuple8(quoteAssetSold, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, cumulativeNotionalAfter1, (totalLongPositionSize() - (if (_isAdd)
517+ else $Tuple7(quoteAssetSold, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, (totalLongPositionSize() - (if (_isAdd)
461518 then abs(_baseAssetAmount)
462519 else 0)), (totalShortPositionSize() - (if (!(_isAdd))
463520 then abs(_baseAssetAmount)
466523 }
467524
468525
469-func swapOutput (_isAdd,_baseAssetAmount,_checkMaxPriceImpact) = swapOutputWithReserves(_isAdd, _baseAssetAmount, _checkMaxPriceImpact, qtAstR(), bsAstR())
526+func swapOutput (_isAdd,_baseAssetAmount,_checkMaxPriceImpact) = swapOutputWithReserves(_isAdd, _baseAssetAmount, _checkMaxPriceImpact, qtAstR(), qtAstW(), bsAstR(), bsAstW())
470527
471528
472529 func getOracleTwapPrice () = {
489546 }
490547
491548
549+func requireNotOverMaxOpenNotional (_longOpenNotional,_shortOpenNotional) = {
550+ let _maxOpenNotional = maxOpenNotional()
551+ if ((_longOpenNotional > _maxOpenNotional))
552+ then throw(((("Long open notional " + toString(_longOpenNotional)) + " > max open notional ") + toString(_maxOpenNotional)))
553+ else if ((_shortOpenNotional > _maxOpenNotional))
554+ then throw(((("Short open notional " + toString(_shortOpenNotional)) + " > max open notional ") + toString(_maxOpenNotional)))
555+ else true
556+ }
557+
558+
492559 func getSpotPrice () = {
493560 let _quoteAssetReserve = qtAstR()
494561 let _baseAssetReserve = bsAstR()
495- divd(_quoteAssetReserve, _baseAssetReserve)
562+ let _qtAstW = qtAstW()
563+ let _bsAstW = bsAstW()
564+ divd(muld(_quoteAssetReserve, _qtAstW), muld(_baseAssetReserve, _bsAstW))
496565 }
497566
498567
503572 }
504573
505574
506-func getPositionAdjustedOpenNotional (_positionSize,_option,_quoteAssetReserve,_baseAssetReserve) = {
575+func getPositionAdjustedOpenNotional (_positionSize,_option,_quoteAssetReserve,_quoteAssetWeight,_baseAssetReserve,_baseAssetWeight) = {
507576 let positionSizeAbs = abs(_positionSize)
508577 let isShort = (0 > _positionSize)
509578 let positionNotional = if ((_option == PNL_OPTION_SPOT))
510579 then {
511- let $t02117321344 = swapOutputWithReserves(!(isShort), positionSizeAbs, false, _quoteAssetReserve, _baseAssetReserve)
512- let outPositionNotional = $t02117321344._1
513- let x1 = $t02117321344._2
514- let x2 = $t02117321344._3
515- let x3 = $t02117321344._4
580+ let $t02365523875 = swapOutputWithReserves(!(isShort), positionSizeAbs, false, _quoteAssetReserve, _quoteAssetWeight, _baseAssetReserve, _baseAssetWeight)
581+ let outPositionNotional = $t02365523875._1
582+ let x1 = $t02365523875._2
583+ let x2 = $t02365523875._3
584+ let x3 = $t02365523875._4
516585 outPositionNotional
517586 }
518587 else muld(positionSizeAbs, getOracleTwapPrice())
520589 }
521590
522591
523-func getPositionNotionalAndUnrealizedPnlByValues (_positionSize,_positionOpenNotional,_quoteAssetReserve,_baseAssetReserve,_option) = if ((_positionSize == 0))
592+func getPositionNotionalAndUnrealizedPnlByValues (_positionSize,_positionOpenNotional,_quoteAssetReserve,_quoteAssetWeight,_baseAssetReserve,_baseAssetWeight,_option) = if ((_positionSize == 0))
524593 then throw("Invalid position size")
525594 else {
526595 let isShort = (0 > _positionSize)
527- let positionNotional = getPositionAdjustedOpenNotional(_positionSize, _option, _quoteAssetReserve, _baseAssetReserve)
596+ let positionNotional = getPositionAdjustedOpenNotional(_positionSize, _option, _quoteAssetReserve, _quoteAssetWeight, _baseAssetReserve, _baseAssetWeight)
528597 let unrealizedPnl = if (isShort)
529598 then (_positionOpenNotional - positionNotional)
530599 else (positionNotional - _positionOpenNotional)
533602
534603
535604 func getPositionNotionalAndUnrealizedPnl (_trader,_option) = {
536- let $t02266122789 = getPosition(_trader)
537- let positionSize = $t02266122789._1
538- let positionMargin = $t02266122789._2
539- let positionOpenNotional = $t02266122789._3
540- let positionLstUpdCPF = $t02266122789._4
541- getPositionNotionalAndUnrealizedPnlByValues(positionSize, positionOpenNotional, qtAstR(), bsAstR(), _option)
605+ let $t02530025428 = getPosition(_trader)
606+ let positionSize = $t02530025428._1
607+ let positionMargin = $t02530025428._2
608+ let positionOpenNotional = $t02530025428._3
609+ let positionLstUpdCPF = $t02530025428._4
610+ getPositionNotionalAndUnrealizedPnlByValues(positionSize, positionOpenNotional, qtAstR(), qtAstW(), bsAstR(), bsAstW(), _option)
542611 }
543612
544613
546615
547616
548617 func getMarginRatioByOption (_trader,_option) = {
549- let $t02327023381 = getPosition(_trader)
550- let positionSize = $t02327023381._1
551- let positionMargin = $t02327023381._2
552- let pon = $t02327023381._3
553- let positionLstUpdCPF = $t02327023381._4
554- let $t02338723480 = getPositionNotionalAndUnrealizedPnl(_trader, _option)
555- let positionNotional = $t02338723480._1
556- let unrealizedPnl = $t02338723480._2
557- let $t02348523651 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl)
558- let remainMargin = $t02348523651._1
559- let badDebt = $t02348523651._2
618+ let $t02594126052 = getPosition(_trader)
619+ let positionSize = $t02594126052._1
620+ let positionMargin = $t02594126052._2
621+ let pon = $t02594126052._3
622+ let positionLstUpdCPF = $t02594126052._4
623+ let $t02605826151 = getPositionNotionalAndUnrealizedPnl(_trader, _option)
624+ let positionNotional = $t02605826151._1
625+ let unrealizedPnl = $t02605826151._2
626+ let $t02615626322 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl)
627+ let remainMargin = $t02615626322._1
628+ let badDebt = $t02615626322._2
560629 calcMarginRatio(remainMargin, badDebt, positionNotional)
561630 }
562631
569638 let maxExchangedPositionSize = muld(abs(_positionSize), maximumRatio)
570639 let swapResult = swapOutput((_positionSize > 0), maxExchangedPositionSize, false)
571640 let maxExchangedQuoteAssetAmount = swapResult._1
572- let priceImpact = swapResult._8
641+ let priceImpact = swapResult._7
573642 if ((maxPriceImpact() > priceImpact))
574643 then maxExchangedQuoteAssetAmount
575644 else {
581650
582651
583652 func internalClosePosition (_trader,_checkMaxPriceImpact) = {
584- let $t02488425012 = getPosition(_trader)
585- let positionSize = $t02488425012._1
586- let positionMargin = $t02488425012._2
587- let positionOpenNotional = $t02488425012._3
588- let positionLstUpdCPF = $t02488425012._4
653+ let $t02756227690 = getPosition(_trader)
654+ let positionSize = $t02756227690._1
655+ let positionMargin = $t02756227690._2
656+ let positionOpenNotional = $t02756227690._3
657+ let positionLstUpdCPF = $t02756227690._4
589658 let unrealizedPnl = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)._2
590- let $t02510725275 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl)
591- let remainMargin = $t02510725275._1
592- let badDebt = $t02510725275._2
659+ let $t02778527953 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl)
660+ let remainMargin = $t02778527953._1
661+ let badDebt = $t02778527953._2
593662 let exchangedPositionSize = -(positionSize)
594663 let realizedPnl = unrealizedPnl
595664 let marginToVault = -(remainMargin)
596- let $t02540225713 = swapOutput((positionSize > 0), abs(positionSize), _checkMaxPriceImpact)
597- let exchangedQuoteAssetAmount = $t02540225713._1
598- let quoteAssetReserveAfter = $t02540225713._2
599- let baseAssetReserveAfter = $t02540225713._3
600- let totalPositionSizeAfter = $t02540225713._4
601- let cumulativeNotionalAfter = $t02540225713._5
602- let totalLongAfter = $t02540225713._6
603- let totalShortAfter = $t02540225713._7
665+ let $t02808028354 = swapOutput((positionSize > 0), abs(positionSize), _checkMaxPriceImpact)
666+ let exchangedQuoteAssetAmount = $t02808028354._1
667+ let quoteAssetReserveAfter = $t02808028354._2
668+ let baseAssetReserveAfter = $t02808028354._3
669+ let totalPositionSizeAfter = $t02808028354._4
670+ let totalLongAfter = $t02808028354._5
671+ let totalShortAfter = $t02808028354._6
604672 let openInterestNotionalAfter = (openInterestNotional() - positionOpenNotional)
605- $Tuple12(exchangedPositionSize, badDebt, realizedPnl, marginToVault, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, exchangedQuoteAssetAmount, totalLongAfter, totalShortAfter)
673+ $Tuple13(exchangedPositionSize, badDebt, realizedPnl, marginToVault, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, exchangedQuoteAssetAmount, totalLongAfter, totalShortAfter, (openInterestLong() - (if ((positionSize > 0))
674+ then positionOpenNotional
675+ else 0)), (openInterestShort() - (if ((0 > positionSize))
676+ then positionOpenNotional
677+ else 0)))
606678 }
607679
608680
643715 }
644716
645717
646-func getPegAdjustCost (_price) = {
718+func getTerminalAmmState () = {
647719 let _positionSize = totalPositionSize()
648- let direction = (_positionSize > 0)
649- let currentNetMarketValue = swapOutput(direction, abs(_positionSize), false)._1
650- let baseAssetReserve = bsAstR()
651- let newQuoteAssetReserve = muld(baseAssetReserve, _price)
652- let cost = getPositionNotionalAndUnrealizedPnlByValues(_positionSize, currentNetMarketValue, newQuoteAssetReserve, baseAssetReserve, PNL_OPTION_SPOT)._2
653- $Tuple2(newQuoteAssetReserve, cost)
720+ if ((_positionSize == 0))
721+ then $Tuple2(qtAstR(), bsAstR())
722+ else {
723+ let direction = (_positionSize > 0)
724+ let $t03047730656 = swapOutput(direction, abs(_positionSize), false)
725+ let currentNetMarketValue = $t03047730656._1
726+ let terminalQuoteAssetReserve = $t03047730656._2
727+ let terminalBaseAssetReserve = $t03047730656._3
728+ $Tuple2(terminalQuoteAssetReserve, terminalBaseAssetReserve)
729+ }
730+ }
731+
732+
733+func getQuoteAssetWeight (baseAssetReserve,totalPositionSize,quoteAssetReserve,targetPrice) = {
734+ let b = toBigInt(baseAssetReserve)
735+ let sz = toBigInt(totalPositionSize)
736+ let q = toBigInt(quoteAssetReserve)
737+ let p = toBigInt(targetPrice)
738+ let bs2 = bpowd((b + sz), toBigInt((2 * DECIMAL_UNIT)))
739+ let qbs2 = bmuld(q, bs2)
740+ let ps4 = (toBigInt(4) * bmuld(p, sz))
741+ let sqr = bsqrtd(bmuld(qbs2, (q - ps4)))
742+ let bq = bmuld(b, q)
743+ let qs = bmuld(q, sz)
744+ let top = ((-(sqr) + bq) + qs)
745+ let bot = (toBigInt(2) * bmuld(q, sz))
746+ let result = bdivd(top, bot)
747+ toInt(result)
748+ }
749+
750+
751+func getSyncTerminalPrice (_terminalPrice) = {
752+ let _positionSize = totalPositionSize()
753+ if ((_positionSize == 0))
754+ then {
755+ let _qtAstR = qtAstR()
756+ let _bsAstR = bsAstR()
757+ let newQtAstW = divd(muld(_terminalPrice, _bsAstR), _qtAstR)
758+ $Tuple3(newQtAstW, DECIMAL_UNIT, 0)
759+ }
760+ else {
761+ let direction = (_positionSize > 0)
762+ let currentNetMarketValue = swapOutput(direction, abs(_positionSize), false)._1
763+ let _qtAstR = qtAstR()
764+ let _bsAstR = bsAstR()
765+ let newQtAstW = getQuoteAssetWeight(_bsAstR, _positionSize, _qtAstR, _terminalPrice)
766+ let newBsAstW = DECIMAL_UNIT
767+ let marginToVault = getPositionNotionalAndUnrealizedPnlByValues(_positionSize, currentNetMarketValue, _qtAstR, newQtAstW, _bsAstR, newBsAstW, PNL_OPTION_SPOT)._2
768+ $Tuple3(newQtAstW, newBsAstW, marginToVault)
769+ }
654770 }
655771
656772
676792 }
677793
678794
679-func getAdjustedFee (i) = {
680- let baseFee = fee()
681- let $t02937629984 = if ((size(i.payments) > 1))
795+func getAdjustedFee (_artifactId,_baseFeeDiscount) = {
796+ let baseFeeRaw = fee()
797+ let baseFee = muld(baseFeeRaw, _baseFeeDiscount)
798+ let $t03375534250 = if ((_artifactId != ""))
682799 then {
683- let artifactId = toBase58String(valueOrErrorMessage(i.payments[1].assetId, "Invalid attached artifact"))
684- let artifactKind = strA(nftManagerAddress(), toCompositeKey(k_token_type, artifactId))
800+ let artifactKind = strA(nftManagerAddress(), toCompositeKey(k_token_type, _artifactId))
685801 if ((artifactKind == FEE_REDUCTION_TOKEN_TYPE))
686802 then {
687- let reduction = intA(nftManagerAddress(), toCompositeKey(k_token_param, artifactId))
803+ let reduction = intA(nftManagerAddress(), toCompositeKey(k_token_param, _artifactId))
688804 let adjustedFee = muld(baseFee, reduction)
689805 $Tuple2(adjustedFee, true)
690806 }
691807 else throw("Invalid attached artifact")
692808 }
693809 else $Tuple2(baseFee, false)
694- let adjustedFee = $t02937629984._1
695- let burnArtifact = $t02937629984._2
810+ let adjustedFee = $t03375534250._1
811+ let burnArtifact = $t03375534250._2
696812 $Tuple2(adjustedFee, burnArtifact)
697813 }
698814
699815
700-func updateSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread) = [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)]
816+func updateSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional) = [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)]
701817
702818
703819 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)]
704820
705821
706822 func updatePositionAsset (_address,_assetId) = [StringEntry(toCompositeKey(k_positionAsset, _address), _assetId)]
823+
824+
825+func incrementPositionSequenceNumber (isNewPosition,_address) = if (isNewPosition)
826+ then {
827+ let currentSequence = lastSequence()
828+[IntegerEntry(toCompositeKey(k_positionSequence, _address), (currentSequence + 1)), IntegerEntry(k_sequence, (currentSequence + 1))]
829+ }
830+ else nil
707831
708832
709833 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)]
740864 func updateAmmReserves (_qtAstR,_bsAstR) = [IntegerEntry(k_quoteAssetReserve, _qtAstR), IntegerEntry(k_baseAssetReserve, _bsAstR)]
741865
742866
743-func updateAmm (_qtAstR,_bsAstR,_totalPositionSizeAfter,_cumulativeNotionalAfter,_openInterestNotional,_totalLongPositionSize,_totalShortPositionSize) = if (((_totalLongPositionSize - _totalShortPositionSize) != _totalPositionSizeAfter))
744- then throw(((((("Invalid AMM state data: " + toString(_totalLongPositionSize)) + " + ") + toString(_totalShortPositionSize)) + " != ") + toString(_totalPositionSizeAfter)))
745- else ((updateAmmReserves(_qtAstR, _bsAstR) ++ [IntegerEntry(k_totalPositionSize, _totalPositionSizeAfter), IntegerEntry(k_cumulativeNotional, _cumulativeNotionalAfter), IntegerEntry(k_openInterestNotional, _openInterestNotional), IntegerEntry(k_totalLongPositionSize, _totalLongPositionSize), IntegerEntry(k_totalShortPositionSize, _totalShortPositionSize)]) ++ appendTwap(divd(_qtAstR, _bsAstR)))
867+func updateAmmWeights (_qtAstW,_bsAstW) = [IntegerEntry(k_quoteAssetWeight, _qtAstW), IntegerEntry(k_baseAssetWeight, _bsAstW)]
746868
747869
748-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)), IntegerEntry(toCompositeKey(k_positionClosedDate, _address), lastBlock.timestamp)]
870+func updateAmm (_qtAstR,_bsAstR,_totalPositionSizeAfter,_openInterestNotional,_totalLongPositionSize,_totalShortPositionSize,_totalLongOpenNotional,_totalShortOpenNotional) = {
871+ let _qtAstW = qtAstW()
872+ let _bsAstW = bsAstW()
873+ if (((_totalLongPositionSize - _totalShortPositionSize) != _totalPositionSizeAfter))
874+ then throw(((((("Invalid AMM state data: " + toString(_totalLongPositionSize)) + " + ") + toString(_totalShortPositionSize)) + " != ") + toString(_totalPositionSizeAfter)))
875+ 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))))
876+ }
877+
878+
879+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))]
749880
750881
751882 func withdraw (_address,_amount) = {
795926 }
796927
797928
929+func getForTraderWithArtifact (_trader,_artifactId) = {
930+ let doGetFeeDiscount = invoke(minerAddress(), "computeFeeDiscount", [_trader], nil)
931+ if ((doGetFeeDiscount == doGetFeeDiscount))
932+ then {
933+ let feeDiscount = match doGetFeeDiscount {
934+ case x: Int =>
935+ x
936+ case _ =>
937+ throw("Invalid computeFeeDiscount result")
938+ }
939+ let $t04258342657 = getAdjustedFee(_artifactId, feeDiscount)
940+ let adjustedFee = $t04258342657._1
941+ let burnArtifact = $t04258342657._2
942+ $Tuple2(adjustedFee, burnArtifact)
943+ }
944+ else throw("Strict value is not equal to itself.")
945+ }
946+
947+
948+func getArtifactId (i) = {
949+ let artifactId = if ((size(i.payments) > 1))
950+ then toBase58String(valueOrErrorMessage(i.payments[1].assetId, "Invalid artifactId"))
951+ else ""
952+ artifactId
953+ }
954+
955+
798956 @Callable(i)
799957 func pause () = if ((i.caller != adminAddress()))
800- then throw("Invalid togglePause params")
958+ then throw("Invalid pause params")
801959 else [BooleanEntry(k_paused, true)]
802960
803961
804962
805963 @Callable(i)
806964 func unpause () = if ((i.caller != adminAddress()))
807- then throw("Invalid togglePause params")
965+ then throw("Invalid unpause params")
808966 else [BooleanEntry(k_paused, false)]
967+
968+
969+
970+@Callable(i)
971+func setCloseOnly () = if ((i.caller != adminAddress()))
972+ then throw("Invalid setCloseOnly params")
973+ else [BooleanEntry(k_closeOnly, true)]
974+
975+
976+
977+@Callable(i)
978+func unsetCloseOnly () = if ((i.caller != adminAddress()))
979+ then throw("Invalid unsetCloseOnly params")
980+ else [BooleanEntry(k_closeOnly, false)]
809981
810982
811983
817989 else {
818990 let _qtAstR = qtAstR()
819991 let _bsAstR = bsAstR()
820- let price = divd(_qtAstR, _bsAstR)
992+ let _qtAstW = qtAstW()
993+ let _bsAstW = bsAstW()
994+ let price = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW))
821995 let baseAssetAmountToAdd = divd(_quoteAssetAmount, price)
822996 let qtAstRAfter = (_qtAstR + _quoteAssetAmount)
823997 let bsAstRAfter = (_bsAstR + baseAssetAmountToAdd)
8341008 else {
8351009 let _qtAstR = qtAstR()
8361010 let _bsAstR = bsAstR()
837- let price = divd(_qtAstR, _bsAstR)
1011+ let _qtAstW = qtAstW()
1012+ let _bsAstW = bsAstW()
1013+ let price = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW))
8381014 let baseAssetAmountToRemove = divd(_quoteAssetAmount, price)
8391015 let qtAstRAfter = (_qtAstR - _quoteAssetAmount)
8401016 let bsAstRAfter = (_bsAstR - baseAssetAmountToRemove)
8441020
8451021
8461022 @Callable(i)
847-func changeSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread) = if ((i.caller != adminAddress()))
1023+func changeSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional) = if ((i.caller != adminAddress()))
8481024 then throw("Invalid changeSettings params")
849- else updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread)
1025+ else updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread, _maxOpenNotional)
8501026
8511027
8521028
8531029 @Callable(i)
854-func initialize (_qtAstR,_bsAstR,_fundingPeriod,_initMarginRatio,_mmr,_liquidationFeeRatio,_fee,_oracle,_oracleKey,_coordinator,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread) = if (if (if (if (if (if (if (if (if (if (if (if ((0 >= _qtAstR))
1030+func initialize (_qtAstR,_bsAstR,_fundingPeriod,_initMarginRatio,_mmr,_liquidationFeeRatio,_fee,_oracle,_oracleKey,_coordinator,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional) = if (if (if (if (if (if (if (if (if (if (if (if (if ((0 >= _qtAstR))
8551031 then true
8561032 else (0 >= _bsAstR))
8571033 then true
8731049 then true
8741050 else (0 >= _maxPriceSpread))
8751051 then true
1052+ else (0 >= _maxOpenNotional))
1053+ then true
8761054 else initialized())
8771055 then throw("Invalid initialize parameters")
878- else ((((updateAmm(_qtAstR, _bsAstR, 0, 0, 0, 0, 0) ++ updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread)) ++ 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_coordinatorAddress, _coordinator)])
1056+ else ((((updateAmm(_qtAstR, _bsAstR, 0, 0, 0, 0, 0, 0) ++ updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread, _maxOpenNotional)) ++ 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_coordinatorAddress, _coordinator)])
8791057
8801058
8811059
8821060 @Callable(i)
883-func setInitMarginRatio (_initMarginRatio) = if (if ((0 >= _initMarginRatio))
884- then true
885- else !(initialized()))
886- then throw("Invalid setInitMarginRatio parameters")
887- else updateSettings(_initMarginRatio, maintenanceMarginRatio(), liquidationFeeRatio(), fundingPeriodRaw(), fee(), spreadLimit(), maxPriceImpact(), partialLiquidationRatio(), maxPriceSpread())
888-
889-
890-
891-@Callable(i)
892-func decreasePosition (_amount,_leverage,_minBaseAssetAmount) = if (if (if (if (if ((0 >= _amount))
893- then true
894- else !(initialized()))
895- then true
896- else !(requireMoreMarginRatio(divd(DECIMAL_UNIT, _leverage), initMarginRatio(), true)))
897- then true
898- else !(requireOpenPosition(toString(i.caller))))
899- then true
900- else paused())
901- then throw("Invalid decreasePosition parameters")
902- else {
903- let $t04149241644 = getPosition(toString(i.caller))
904- let oldPositionSize = $t04149241644._1
905- let oldPositionMargin = $t04149241644._2
906- let oldPositionOpenNotional = $t04149241644._3
907- let oldPositionLstUpdCPF = $t04149241644._4
908- let _direction = if ((oldPositionSize > 0))
909- then DIR_SHORT
910- else DIR_LONG
911- let isAdd = (_direction == DIR_LONG)
912- let openNotional = muld(_amount, _leverage)
913- let $t04181741933 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT)
914- let oldPositionNotional = $t04181741933._1
915- let unrealizedPnl = $t04181741933._2
916- let $t04193944488 = if ((oldPositionNotional > openNotional))
917- then {
918- let $t04231642535 = swapInput(isAdd, openNotional)
919- let exchangedPositionSize = $t04231642535._1
920- let quoteAssetReserveAfter = $t04231642535._2
921- let baseAssetReserveAfter = $t04231642535._3
922- let totalPositionSizeAfter = $t04231642535._4
923- let cumulativeNotionalAfter = $t04231642535._5
924- let exchangedPositionSizeAbs = abs(exchangedPositionSize)
925- if (if ((_minBaseAssetAmount != 0))
926- then (_minBaseAssetAmount > exchangedPositionSizeAbs)
927- else false)
928- then throw(((("Too little base asset exchanged, got " + toString(exchangedPositionSizeAbs)) + " expected ") + toString(_minBaseAssetAmount)))
929- else {
930- let realizedPnl = divd(muld(unrealizedPnl, exchangedPositionSizeAbs), abs(oldPositionSize))
931- let $t04297243217 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl)
932- let remainMargin = $t04297243217._1
933- let badDebt = $t04297243217._2
934- let fundingPayment = $t04297243217._3
935- let exchangedQuoteAssetAmount = openNotional
936- let unrealizedPnlAfter = (unrealizedPnl - realizedPnl)
937- let remainOpenNotional = if ((oldPositionSize > 0))
938- then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter)
939- else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount)
940- let newPositionSize = (oldPositionSize + exchangedPositionSize)
941- $Tuple11(newPositionSize, remainMargin, abs(remainOpenNotional), latestCumulativePremiumFraction(newPositionSize), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, (openInterestNotional() - openNotional), (totalLongPositionSize() - (if ((newPositionSize > 0))
942- then abs(exchangedPositionSize)
943- else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize))
944- then abs(exchangedPositionSize)
945- else 0)))
946- }
947- }
948- else throw("Close position first")
949- let newPositionSize = $t04193944488._1
950- let newPositionRemainMargin = $t04193944488._2
951- let newPositionOpenNotional = $t04193944488._3
952- let newPositionLatestCPF = $t04193944488._4
953- let baseAssetReserveAfter = $t04193944488._5
954- let quoteAssetReserveAfter = $t04193944488._6
955- let totalPositionSizeAfter = $t04193944488._7
956- let cumulativeNotionalAfter = $t04193944488._8
957- let openInterestNotionalAfter = $t04193944488._9
958- let totalLongAfter = $t04193944488._10
959- let totalShortAfter = $t04193944488._11
960- let notifyNotional = invoke(minerAddress(), "notifyNotional", [toString(i.caller), newPositionOpenNotional], nil)
961- if ((notifyNotional == notifyNotional))
962- then (updatePosition(toString(i.caller), newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter))
963- else throw("Strict value is not equal to itself.")
964- }
1061+func decreasePosition (_amount,_leverage,_minBaseAssetAmount) = {
1062+ let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
1063+ if ((sync == sync))
1064+ then {
1065+ let _trader = getActualCaller(i)
1066+ if (if (if (if (if ((0 >= _amount))
1067+ then true
1068+ else !(initialized()))
1069+ then true
1070+ else !(requireMoreMarginRatio(divd(DECIMAL_UNIT, _leverage), initMarginRatio(), true)))
1071+ then true
1072+ else !(requireOpenPosition(_trader)))
1073+ then true
1074+ else paused())
1075+ then throw("Invalid decreasePosition parameters")
1076+ else {
1077+ let $t04734747487 = getPosition(_trader)
1078+ let oldPositionSize = $t04734747487._1
1079+ let oldPositionMargin = $t04734747487._2
1080+ let oldPositionOpenNotional = $t04734747487._3
1081+ let oldPositionLstUpdCPF = $t04734747487._4
1082+ let _direction = if ((oldPositionSize > 0))
1083+ then DIR_SHORT
1084+ else DIR_LONG
1085+ let isAdd = (_direction == DIR_LONG)
1086+ let openNotional = muld(_amount, _leverage)
1087+ let $t04766047764 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)
1088+ let oldPositionNotional = $t04766047764._1
1089+ let unrealizedPnl = $t04766047764._2
1090+ let $t04777050428 = if ((oldPositionNotional > openNotional))
1091+ then {
1092+ let $t04818548369 = swapInput(isAdd, openNotional)
1093+ let exchangedPositionSize = $t04818548369._1
1094+ let quoteAssetReserveAfter = $t04818548369._2
1095+ let baseAssetReserveAfter = $t04818548369._3
1096+ let totalPositionSizeAfter = $t04818548369._4
1097+ let exchangedPositionSizeAbs = abs(exchangedPositionSize)
1098+ if (if ((_minBaseAssetAmount != 0))
1099+ then (_minBaseAssetAmount > exchangedPositionSizeAbs)
1100+ else false)
1101+ then throw(((("Too little base asset exchanged, got " + toString(exchangedPositionSizeAbs)) + " expected ") + toString(_minBaseAssetAmount)))
1102+ else {
1103+ let realizedPnl = divd(muld(unrealizedPnl, exchangedPositionSizeAbs), abs(oldPositionSize))
1104+ let $t04880649051 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl)
1105+ let remainMargin = $t04880649051._1
1106+ let badDebt = $t04880649051._2
1107+ let fundingPayment = $t04880649051._3
1108+ let exchangedQuoteAssetAmount = openNotional
1109+ let unrealizedPnlAfter = (unrealizedPnl - realizedPnl)
1110+ let remainOpenNotional = if ((oldPositionSize > 0))
1111+ then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter)
1112+ else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount)
1113+ let newPositionSize = (oldPositionSize + exchangedPositionSize)
1114+ $Tuple12(newPositionSize, remainMargin, abs(remainOpenNotional), latestCumulativePremiumFraction(newPositionSize), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, (openInterestNotional() - openNotional), (totalLongPositionSize() - (if ((newPositionSize > 0))
1115+ then abs(exchangedPositionSize)
1116+ else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize))
1117+ then abs(exchangedPositionSize)
1118+ else 0)), (openInterestLong() - (if ((newPositionSize > 0))
1119+ then openNotional
1120+ else 0)), (openInterestShort() - (if ((0 > newPositionSize))
1121+ then openNotional
1122+ else 0)))
1123+ }
1124+ }
1125+ else throw("Close position first")
1126+ let newPositionSize = $t04777050428._1
1127+ let newPositionRemainMargin = $t04777050428._2
1128+ let newPositionOpenNotional = $t04777050428._3
1129+ let newPositionLatestCPF = $t04777050428._4
1130+ let baseAssetReserveAfter = $t04777050428._5
1131+ let quoteAssetReserveAfter = $t04777050428._6
1132+ let totalPositionSizeAfter = $t04777050428._7
1133+ let openInterestNotionalAfter = $t04777050428._8
1134+ let totalLongAfter = $t04777050428._9
1135+ let totalShortAfter = $t04777050428._10
1136+ let totalLongOpenInterestAfter = $t04777050428._11
1137+ let totalShortOpenInterestAfter = $t04777050428._12
1138+ let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil)
1139+ if ((notifyNotional == notifyNotional))
1140+ then (updatePosition(_trader, newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter))
1141+ else throw("Strict value is not equal to itself.")
1142+ }
1143+ }
1144+ else throw("Strict value is not equal to itself.")
1145+ }
9651146
9661147
9671148
9681149 @Callable(i)
9691150 func increasePosition (_direction,_leverage,_minBaseAssetAmount,_refLink) = {
970- let _trader = toString(i.caller)
971- let _rawAmount = i.payments[0].amount
972- let _assetId = i.payments[0].assetId
973- let _assetIdStr = toBase58String(value(_assetId))
974- let isQuoteAsset = (_assetId == quoteAsset())
975- let isCollateralAsset = isWhitelistAsset(_assetIdStr)
976- if (if (if (if (if (if (if (if ((_direction != DIR_LONG))
977- then (_direction != DIR_SHORT)
978- else false)
979- then true
980- else (0 >= _rawAmount))
981- then true
982- else !(initialized()))
983- then true
984- else if (!(isQuoteAsset))
985- then !(isCollateralAsset)
986- else false)
987- then true
988- else !(isSameAssetOrNoPosition(_trader, _assetIdStr)))
989- then true
990- else !(requireMoreMarginRatio(divd(DECIMAL_UNIT, _leverage), initMarginRatio(), true)))
991- then true
992- else paused())
993- then throw("Invalid increasePosition parameters")
994- else {
995- let baseFee = fee()
996- let $t04585045901 = getAdjustedFee(i)
997- let adjustedFee = $t04585045901._1
998- let burnArtifact = $t04585045901._2
999- let rawFeeAmount = muld(_rawAmount, adjustedFee)
1000- let _amount = (_rawAmount - rawFeeAmount)
1001- let distributeFeeAmount = if (isCollateralAsset)
1002- then {
1003- let doBorrow = invoke(collateralAddress(), "borrow", [_trader], [AttachedPayment(_assetId, _amount)])
1004- if ((doBorrow == doBorrow))
1151+ let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
1152+ if ((sync == sync))
1153+ then {
1154+ let _trader = getActualCaller(i)
1155+ let _rawAmount = i.payments[0].amount
1156+ let _assetId = i.payments[0].assetId
1157+ let _assetIdStr = toBase58String(value(_assetId))
1158+ let isQuoteAsset = (_assetId == quoteAsset())
1159+ let isCollateralAsset = isWhitelistAsset(_assetIdStr)
1160+ if (if (if (if (if (if (if (if (if ((_direction != DIR_LONG))
1161+ then (_direction != DIR_SHORT)
1162+ else false)
1163+ then true
1164+ else (0 >= _rawAmount))
1165+ then true
1166+ else !(initialized()))
1167+ then true
1168+ else if (!(isQuoteAsset))
1169+ then !(isCollateralAsset)
1170+ else false)
1171+ then true
1172+ else !(isSameAssetOrNoPosition(_trader, _assetIdStr)))
1173+ then true
1174+ else !(requireMoreMarginRatio(divd(DECIMAL_UNIT, _leverage), initMarginRatio(), true)))
1175+ then true
1176+ else paused())
1177+ then true
1178+ else closeOnly())
1179+ then throw("Invalid increasePosition parameters")
1180+ else {
1181+ let $t05186651951 = getForTraderWithArtifact(_trader, getArtifactId(i))
1182+ let adjustedFee = $t05186651951._1
1183+ let burnArtifact = $t05186651951._2
1184+ let rawFeeAmount = muld(_rawAmount, adjustedFee)
1185+ let _amount = (_rawAmount - rawFeeAmount)
1186+ let distributeFeeAmount = if (isCollateralAsset)
10051187 then {
1006- let balanceBefore = assetBalance(this, quoteAsset())
1007- if ((balanceBefore == balanceBefore))
1188+ let doBorrow = invoke(collateralAddress(), "borrow", [_trader], [AttachedPayment(_assetId, _amount)])
1189+ if ((doBorrow == doBorrow))
10081190 then {
1009- let doSwap = invoke(swapAddress(), "swap", [toBase58String(quoteAsset()), 0], [AttachedPayment(_assetId, rawFeeAmount)])
1010- if ((doSwap == doSwap))
1191+ let balanceBefore = assetBalance(this, quoteAsset())
1192+ if ((balanceBefore == balanceBefore))
10111193 then {
1012- let balanceAfter = assetBalance(this, quoteAsset())
1013- if ((balanceAfter == balanceAfter))
1194+ let doSwap = invoke(swapAddress(), "swap", [toBase58String(quoteAsset()), 0], [AttachedPayment(_assetId, rawFeeAmount)])
1195+ if ((doSwap == doSwap))
10141196 then {
1015- let exchangedAmount = (balanceAfter - balanceBefore)
1016- if ((exchangedAmount == exchangedAmount))
1017- then exchangedAmount
1197+ let balanceAfter = assetBalance(this, quoteAsset())
1198+ if ((balanceAfter == balanceAfter))
1199+ then {
1200+ let exchangedAmount = (balanceAfter - balanceBefore)
1201+ if ((exchangedAmount == exchangedAmount))
1202+ then exchangedAmount
1203+ else throw("Strict value is not equal to itself.")
1204+ }
1205+ else throw("Strict value is not equal to itself.")
1206+ }
1207+ else throw("Strict value is not equal to itself.")
1208+ }
1209+ else throw("Strict value is not equal to itself.")
1210+ }
1211+ else throw("Strict value is not equal to itself.")
1212+ }
1213+ else rawFeeAmount
1214+ if ((distributeFeeAmount == distributeFeeAmount))
1215+ then {
1216+ let referrerFeeAny = invoke(referralAddress(), "acceptPaymentWithLink", [_trader, _refLink], [AttachedPayment(quoteAsset(), distributeFeeAmount)])
1217+ if ((referrerFeeAny == referrerFeeAny))
1218+ then {
1219+ let referrerFee = match referrerFeeAny {
1220+ case x: Int =>
1221+ x
1222+ case _ =>
1223+ throw("Invalid referrerFee")
1224+ }
1225+ let feeAmount = (distributeFeeAmount - referrerFee)
1226+ let $t05326753407 = getPosition(_trader)
1227+ let oldPositionSize = $t05326753407._1
1228+ let oldPositionMargin = $t05326753407._2
1229+ let oldPositionOpenNotional = $t05326753407._3
1230+ let oldPositionLstUpdCPF = $t05326753407._4
1231+ let isNewPosition = (oldPositionSize == 0)
1232+ let isSameDirection = if ((oldPositionSize > 0))
1233+ then (_direction == DIR_LONG)
1234+ else (_direction == DIR_SHORT)
1235+ let expandExisting = if (!(isNewPosition))
1236+ then isSameDirection
1237+ else false
1238+ let isAdd = (_direction == DIR_LONG)
1239+ let $t05369656737 = if (if (isNewPosition)
1240+ then true
1241+ else expandExisting)
1242+ then {
1243+ let openNotional = muld(_amount, _leverage)
1244+ let $t05415854331 = swapInput(isAdd, openNotional)
1245+ let amountBaseAssetBought = $t05415854331._1
1246+ let quoteAssetReserveAfter = $t05415854331._2
1247+ let baseAssetReserveAfter = $t05415854331._3
1248+ let totalPositionSizeAfter = $t05415854331._4
1249+ if (if ((_minBaseAssetAmount != 0))
1250+ then (_minBaseAssetAmount > abs(amountBaseAssetBought))
1251+ else false)
1252+ then throw(((("Limit error: " + toString(abs(amountBaseAssetBought))) + " < ") + toString(_minBaseAssetAmount)))
1253+ else {
1254+ let newPositionSize = (oldPositionSize + amountBaseAssetBought)
1255+ let totalLongOpenInterestAfter = (openInterestLong() + (if ((newPositionSize > 0))
1256+ then openNotional
1257+ else 0))
1258+ let totalShortOpenInterestAfter = (openInterestShort() + (if ((0 > newPositionSize))
1259+ then openNotional
1260+ else 0))
1261+ let increaseMarginRequirement = divd(openNotional, _leverage)
1262+ let $t05493955178 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, increaseMarginRequirement)
1263+ let remainMargin = $t05493955178._1
1264+ let x1 = $t05493955178._2
1265+ let x2 = $t05493955178._3
1266+ if (!(requireNotOverSpreadLimit(quoteAssetReserveAfter, baseAssetReserveAfter)))
1267+ then throw("Over max spread limit")
1268+ else if (!(requireNotOverMaxOpenNotional(totalLongOpenInterestAfter, totalShortOpenInterestAfter)))
1269+ then throw("Over max open notional")
1270+ else $Tuple12(newPositionSize, remainMargin, (oldPositionOpenNotional + openNotional), latestCumulativePremiumFraction(newPositionSize), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, (openInterestNotional() + openNotional), (totalLongPositionSize() + (if ((newPositionSize > 0))
1271+ then abs(amountBaseAssetBought)
1272+ else 0)), (totalShortPositionSize() + (if ((0 > newPositionSize))
1273+ then abs(amountBaseAssetBought)
1274+ else 0)), totalLongOpenInterestAfter, totalShortOpenInterestAfter)
1275+ }
1276+ }
1277+ else {
1278+ let openNotional = muld(_amount, _leverage)
1279+ let $t05643756553 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT)
1280+ let oldPositionNotional = $t05643756553._1
1281+ let unrealizedPnl = $t05643756553._2
1282+ if ((oldPositionNotional > openNotional))
1283+ then throw("Use decreasePosition to decrease position size")
1284+ else throw("Close position first")
1285+ }
1286+ let newPositionSize = $t05369656737._1
1287+ let newPositionRemainMargin = $t05369656737._2
1288+ let newPositionOpenNotional = $t05369656737._3
1289+ let newPositionLatestCPF = $t05369656737._4
1290+ let baseAssetReserveAfter = $t05369656737._5
1291+ let quoteAssetReserveAfter = $t05369656737._6
1292+ let totalPositionSizeAfter = $t05369656737._7
1293+ let openInterestNotionalAfter = $t05369656737._8
1294+ let totalLongAfter = $t05369656737._9
1295+ let totalShortAfter = $t05369656737._10
1296+ let totalLongOpenInterestAfter = $t05369656737._11
1297+ let totalShortOpenInterestAfter = $t05369656737._12
1298+ let feeToStakers = (feeAmount / 2)
1299+ let feeToInsurance = (feeAmount - feeToStakers)
1300+ let stake = invoke(vaultAddress(), "addLocked", nil, [AttachedPayment(quoteAsset(), _amount)])
1301+ if ((stake == stake))
1302+ then {
1303+ let depositInsurance = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
1304+ if ((depositInsurance == depositInsurance))
1305+ then {
1306+ let notifyFee = invoke(minerAddress(), "notifyFees", [_trader, feeAmount], nil)
1307+ if ((notifyFee == notifyFee))
1308+ then {
1309+ let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil)
1310+ if ((notifyNotional == notifyNotional))
1311+ then ((((((updatePosition(_trader, newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF) ++ incrementPositionSequenceNumber(isNewPosition, _trader)) ++ updatePositionAsset(_trader, _assetIdStr)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) ++ doBurnArtifact(burnArtifact, i))
1312+ else throw("Strict value is not equal to itself.")
1313+ }
10181314 else throw("Strict value is not equal to itself.")
10191315 }
10201316 else throw("Strict value is not equal to itself.")
10251321 }
10261322 else throw("Strict value is not equal to itself.")
10271323 }
1028- else rawFeeAmount
1029- if ((distributeFeeAmount == distributeFeeAmount))
1030- then {
1031- let referrerFeeAny = invoke(referralAddress(), "acceptPaymentWithLink", [_trader, _refLink], [AttachedPayment(quoteAsset(), distributeFeeAmount)])
1032- if ((referrerFeeAny == referrerFeeAny))
1324+ }
1325+ else throw("Strict value is not equal to itself.")
1326+ }
1327+
1328+
1329+
1330+@Callable(i)
1331+func addMargin () = {
1332+ let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
1333+ if ((sync == sync))
1334+ then {
1335+ let _trader = toString(i.caller)
1336+ let _rawAmount = i.payments[0].amount
1337+ let _assetId = i.payments[0].assetId
1338+ let _assetIdStr = toBase58String(value(_assetId))
1339+ let isQuoteAsset = (_assetId == quoteAsset())
1340+ let isCollateralAsset = isWhitelistAsset(_assetIdStr)
1341+ if (if (if (if (if (if (if (!(isQuoteAsset))
1342+ then !(isCollateralAsset)
1343+ else false)
1344+ then true
1345+ else !(requireOpenPosition(toString(i.caller))))
1346+ then true
1347+ else !(isSameAsset(_trader, _assetIdStr)))
1348+ then true
1349+ else !(initialized()))
1350+ then true
1351+ else paused())
1352+ then true
1353+ else closeOnly())
1354+ then throw("Invalid addMargin parameters")
1355+ else {
1356+ let $t05867958764 = getForTraderWithArtifact(_trader, getArtifactId(i))
1357+ let adjustedFee = $t05867958764._1
1358+ let burnArtifact = $t05867958764._2
1359+ let rawFeeAmount = muld(_rawAmount, adjustedFee)
1360+ let _amount = (_rawAmount - rawFeeAmount)
1361+ let distributeFeeAmount = if (isCollateralAsset)
10331362 then {
1034- let referrerFee = match referrerFeeAny {
1035- case x: Int =>
1036- x
1037- case _ =>
1038- throw("Invalid referrerFee")
1363+ let doBorrow = invoke(collateralAddress(), "borrow", [_trader], [AttachedPayment(_assetId, _amount)])
1364+ if ((doBorrow == doBorrow))
1365+ then {
1366+ let balanceBefore = assetBalance(this, quoteAsset())
1367+ if ((balanceBefore == balanceBefore))
1368+ then {
1369+ let doSwap = invoke(swapAddress(), "swap", [toBase58String(quoteAsset()), 0], [AttachedPayment(_assetId, rawFeeAmount)])
1370+ if ((doSwap == doSwap))
1371+ then {
1372+ let balanceAfter = assetBalance(this, quoteAsset())
1373+ if ((balanceAfter == balanceAfter))
1374+ then {
1375+ let exchangedAmount = (balanceAfter - balanceBefore)
1376+ if ((exchangedAmount == exchangedAmount))
1377+ then exchangedAmount
1378+ else throw("Strict value is not equal to itself.")
1379+ }
1380+ else throw("Strict value is not equal to itself.")
1381+ }
1382+ else throw("Strict value is not equal to itself.")
1383+ }
1384+ else throw("Strict value is not equal to itself.")
1385+ }
1386+ else throw("Strict value is not equal to itself.")
10391387 }
1040- let feeAmount = (distributeFeeAmount - referrerFee)
1041- let $t04721747357 = getPosition(_trader)
1042- let oldPositionSize = $t04721747357._1
1043- let oldPositionMargin = $t04721747357._2
1044- let oldPositionOpenNotional = $t04721747357._3
1045- let oldPositionLstUpdCPF = $t04721747357._4
1046- let isNewPosition = (oldPositionSize == 0)
1047- let isSameDirection = if ((oldPositionSize > 0))
1048- then (_direction == DIR_LONG)
1049- else (_direction == DIR_SHORT)
1050- let expandExisting = if (!(isNewPosition))
1051- then isSameDirection
1052- else false
1053- let isAdd = (_direction == DIR_LONG)
1054- let $t04764650231 = if (if (isNewPosition)
1055- then true
1056- else expandExisting)
1388+ else rawFeeAmount
1389+ if ((distributeFeeAmount == distributeFeeAmount))
1390+ then {
1391+ let referrerFeeAny = invoke(referralAddress(), "acceptPayment", [_trader], [AttachedPayment(quoteAsset(), distributeFeeAmount)])
1392+ if ((referrerFeeAny == referrerFeeAny))
10571393 then {
1058- let openNotional = muld(_amount, _leverage)
1059- let $t04807048276 = swapInput(isAdd, openNotional)
1060- let amountBaseAssetBought = $t04807048276._1
1061- let quoteAssetReserveAfter = $t04807048276._2
1062- let baseAssetReserveAfter = $t04807048276._3
1063- let totalPositionSizeAfter = $t04807048276._4
1064- let cumulativeNotionalAfter = $t04807048276._5
1065- if (if ((_minBaseAssetAmount != 0))
1066- then (_minBaseAssetAmount > abs(amountBaseAssetBought))
1067- else false)
1068- then throw(((("Limit error: " + toString(abs(amountBaseAssetBought))) + " < ") + toString(_minBaseAssetAmount)))
1069- else {
1070- let newPositionSize = (oldPositionSize + amountBaseAssetBought)
1071- let increaseMarginRequirement = divd(openNotional, _leverage)
1072- let $t04865748896 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, increaseMarginRequirement)
1073- let remainMargin = $t04865748896._1
1074- let x1 = $t04865748896._2
1075- let x2 = $t04865748896._3
1076- if (!(requireNotOverSpreadLimit(quoteAssetReserveAfter, baseAssetReserveAfter)))
1077- then throw("Over max spread limit")
1078- else $Tuple11(newPositionSize, remainMargin, (oldPositionOpenNotional + openNotional), latestCumulativePremiumFraction(newPositionSize), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, (openInterestNotional() + openNotional), (totalLongPositionSize() + (if ((newPositionSize > 0))
1079- then abs(amountBaseAssetBought)
1080- else 0)), (totalShortPositionSize() + (if ((0 > newPositionSize))
1081- then abs(amountBaseAssetBought)
1082- else 0)))
1083- }
1394+ let referrerFee = match referrerFeeAny {
1395+ case x: Int =>
1396+ x
1397+ case _ =>
1398+ throw("Invalid referrerFee")
10841399 }
1085- else {
1086- let openNotional = muld(_amount, _leverage)
1087- let $t04992450040 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT)
1088- let oldPositionNotional = $t04992450040._1
1089- let unrealizedPnl = $t04992450040._2
1090- if ((oldPositionNotional > openNotional))
1091- then throw("Use decreasePosition to decrease position size")
1092- else throw("Close position first")
1093- }
1094- let newPositionSize = $t04764650231._1
1095- let newPositionRemainMargin = $t04764650231._2
1096- let newPositionOpenNotional = $t04764650231._3
1097- let newPositionLatestCPF = $t04764650231._4
1098- let baseAssetReserveAfter = $t04764650231._5
1099- let quoteAssetReserveAfter = $t04764650231._6
1100- let totalPositionSizeAfter = $t04764650231._7
1101- let cumulativeNotionalAfter = $t04764650231._8
1102- let openInterestNotionalAfter = $t04764650231._9
1103- let totalLongAfter = $t04764650231._10
1104- let totalShortAfter = $t04764650231._11
1105- let feeToStakers = (feeAmount / 2)
1106- let feeToInsurance = (feeAmount - feeToStakers)
1107- let stake = invoke(managerAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), _amount)])
1108- if ((stake == stake))
1109- then {
1110- let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
1111- if ((depositInsurance == depositInsurance))
1400+ let feeAmount = (distributeFeeAmount - referrerFee)
1401+ let $t06006360203 = getPosition(_trader)
1402+ let oldPositionSize = $t06006360203._1
1403+ let oldPositionMargin = $t06006360203._2
1404+ let oldPositionOpenNotional = $t06006360203._3
1405+ let oldPositionLstUpdCPF = $t06006360203._4
1406+ let feeToStakers = (feeAmount / 2)
1407+ let feeToInsurance = (feeAmount - feeToStakers)
1408+ let stake = invoke(vaultAddress(), "addLocked", nil, [AttachedPayment(quoteAsset(), _amount)])
1409+ if ((stake == stake))
11121410 then {
1113- let notifyFee = invoke(minerAddress(), "notifyFees", [_trader, feeAmount], nil)
1114- if ((notifyFee == notifyFee))
1411+ let depositInsurance = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
1412+ if ((depositInsurance == depositInsurance))
11151413 then {
1116- let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil)
1117- if ((notifyNotional == notifyNotional))
1118- then (((((updatePosition(_trader, newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF) ++ updatePositionAsset(_trader, _assetIdStr)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter)) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) ++ doBurnArtifact(burnArtifact, i))
1414+ let notifyFee = invoke(minerAddress(), "notifyFees", [_trader, feeAmount], nil)
1415+ if ((notifyFee == notifyFee))
1416+ then (((updatePosition(_trader, oldPositionSize, (oldPositionMargin + _amount), oldPositionOpenNotional, oldPositionLstUpdCPF) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) ++ doBurnArtifact(burnArtifact, i))
11191417 else throw("Strict value is not equal to itself.")
11201418 }
11211419 else throw("Strict value is not equal to itself.")
11261424 }
11271425 else throw("Strict value is not equal to itself.")
11281426 }
1129- else throw("Strict value is not equal to itself.")
11301427 }
1428+ else throw("Strict value is not equal to itself.")
11311429 }
11321430
11331431
11341432
11351433 @Callable(i)
1136-func addMargin () = {
1137- let _trader = toString(i.caller)
1138- let _rawAmount = i.payments[0].amount
1139- let _assetId = i.payments[0].assetId
1140- let _assetIdStr = toBase58String(value(_assetId))
1141- let isQuoteAsset = (_assetId == quoteAsset())
1142- let isCollateralAsset = isWhitelistAsset(_assetIdStr)
1143- if (if (if (if (if (if (!(isQuoteAsset))
1144- then !(isCollateralAsset)
1145- else false)
1146- then true
1147- else !(requireOpenPosition(toString(i.caller))))
1148- then true
1149- else !(isSameAsset(_trader, _assetIdStr)))
1150- then true
1151- else !(initialized()))
1152- then true
1153- else paused())
1154- then throw("Invalid addMargin parameters")
1155- else {
1156- let $t05198752038 = getAdjustedFee(i)
1157- let adjustedFee = $t05198752038._1
1158- let burnArtifact = $t05198752038._2
1159- let rawFeeAmount = muld(_rawAmount, adjustedFee)
1160- let _amount = (_rawAmount - rawFeeAmount)
1161- let distributeFeeAmount = if (isCollateralAsset)
1162- then {
1163- let doBorrow = invoke(collateralAddress(), "borrow", [_trader], [AttachedPayment(_assetId, _amount)])
1164- if ((doBorrow == doBorrow))
1165- then {
1166- let balanceBefore = assetBalance(this, quoteAsset())
1167- if ((balanceBefore == balanceBefore))
1168- then {
1169- let doSwap = invoke(swapAddress(), "swap", [toBase58String(quoteAsset()), 0], [AttachedPayment(_assetId, rawFeeAmount)])
1170- if ((doSwap == doSwap))
1434+func removeMargin (_amount) = {
1435+ let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
1436+ if ((sync == sync))
1437+ then {
1438+ let _trader = toString(i.caller)
1439+ if (if (if (if ((0 >= _amount))
1440+ then true
1441+ else !(requireOpenPosition(_trader)))
1442+ then true
1443+ else !(initialized()))
1444+ then true
1445+ else paused())
1446+ then throw("Invalid removeMargin parameters")
1447+ else {
1448+ let $t06130961449 = getPosition(_trader)
1449+ let oldPositionSize = $t06130961449._1
1450+ let oldPositionMargin = $t06130961449._2
1451+ let oldPositionOpenNotional = $t06130961449._3
1452+ let oldPositionLstUpdCPF = $t06130961449._4
1453+ let marginDelta = -(_amount)
1454+ let $t06148661665 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, marginDelta)
1455+ let remainMargin = $t06148661665._1
1456+ let badDebt = $t06148661665._2
1457+ if ((badDebt != 0))
1458+ then throw("Invalid removed margin amount")
1459+ else {
1460+ let marginRatio = calcMarginRatio(remainMargin, badDebt, oldPositionOpenNotional)
1461+ if (!(requireMoreMarginRatio(marginRatio, initMarginRatio(), true)))
1462+ then throw(((("Too much margin removed: " + toString(marginRatio)) + " < ") + toString(initMarginRatio())))
1463+ else {
1464+ let quoteAssetStr = toBase58String(quoteAsset())
1465+ let $t06210962163 = getBorrowedByTrader(_trader)
1466+ let borrowed = $t06210962163._1
1467+ let assetId = $t06210962163._2
1468+ let toRepay = if ((_amount > borrowed))
1469+ then borrowed
1470+ else _amount
1471+ let toWithdraw = if ((borrowed > _amount))
1472+ then 0
1473+ else (_amount - borrowed)
1474+ let finalBorrow = (borrowed - toRepay)
1475+ let switchPositionToQuote = if ((finalBorrow > 0))
1476+ then nil
1477+ else updatePositionAsset(_trader, quoteAssetStr)
1478+ let doSanityCheck = if (((toRepay + toWithdraw) != _amount))
1479+ then throw(((((("toRepay=" + toString(toRepay)) + " + toWithdraw=") + toString(toWithdraw)) + " != ") + toString(_amount)))
1480+ else nil
1481+ if ((doSanityCheck == doSanityCheck))
11711482 then {
1172- let balanceAfter = assetBalance(this, quoteAsset())
1173- if ((balanceAfter == balanceAfter))
1483+ let doUnstake = invoke(vaultAddress(), "withdrawLocked", [_amount], nil)
1484+ if ((doUnstake == doUnstake))
11741485 then {
1175- let exchangedAmount = (balanceAfter - balanceBefore)
1176- if ((exchangedAmount == exchangedAmount))
1177- then exchangedAmount
1486+ let returnCollateralAction = if ((toRepay > 0))
1487+ then {
1488+ let doRepay = invoke(collateralAddress(), "repay", [_trader, assetId], [AttachedPayment(quoteAsset(), toRepay)])
1489+ if ((doRepay == doRepay))
1490+ then [ScriptTransfer(i.caller, toRepay, fromBase58String(assetId))]
1491+ else throw("Strict value is not equal to itself.")
1492+ }
1493+ else nil
1494+ if ((returnCollateralAction == returnCollateralAction))
1495+ then ((((updatePosition(_trader, oldPositionSize, remainMargin, oldPositionOpenNotional, latestCumulativePremiumFraction(oldPositionSize)) ++ (if ((toWithdraw > 0))
1496+ then withdraw(i.caller, toWithdraw)
1497+ else nil)) ++ updateBalance((cbalance() - _amount))) ++ switchPositionToQuote) ++ returnCollateralAction)
11781498 else throw("Strict value is not equal to itself.")
11791499 }
11801500 else throw("Strict value is not equal to itself.")
11811501 }
11821502 else throw("Strict value is not equal to itself.")
11831503 }
1184- else throw("Strict value is not equal to itself.")
11851504 }
1186- else throw("Strict value is not equal to itself.")
11871505 }
1188- else rawFeeAmount
1189- if ((distributeFeeAmount == distributeFeeAmount))
1190- then {
1191- let referrerFeeAny = invoke(referralAddress(), "acceptPayment", [_trader], [AttachedPayment(quoteAsset(), distributeFeeAmount)])
1192- if ((referrerFeeAny == referrerFeeAny))
1193- then {
1194- let referrerFee = match referrerFeeAny {
1195- case x: Int =>
1196- x
1197- case _ =>
1198- throw("Invalid referrerFee")
1199- }
1200- let feeAmount = (distributeFeeAmount - referrerFee)
1201- let $t05333753477 = getPosition(_trader)
1202- let oldPositionSize = $t05333753477._1
1203- let oldPositionMargin = $t05333753477._2
1204- let oldPositionOpenNotional = $t05333753477._3
1205- let oldPositionLstUpdCPF = $t05333753477._4
1206- let feeToStakers = (feeAmount / 2)
1207- let feeToInsurance = (feeAmount - feeToStakers)
1208- let stake = invoke(managerAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), _amount)])
1209- if ((stake == stake))
1210- then {
1211- let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
1212- if ((depositInsurance == depositInsurance))
1213- then {
1214- let notifyFee = invoke(minerAddress(), "notifyFees", [_trader, feeAmount], nil)
1215- if ((notifyFee == notifyFee))
1216- then (((updatePosition(_trader, oldPositionSize, (oldPositionMargin + _amount), oldPositionOpenNotional, oldPositionLstUpdCPF) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) ++ doBurnArtifact(burnArtifact, i))
1217- else throw("Strict value is not equal to itself.")
1218- }
1219- else throw("Strict value is not equal to itself.")
1220- }
1221- else throw("Strict value is not equal to itself.")
1222- }
1223- else throw("Strict value is not equal to itself.")
1224- }
1225- else throw("Strict value is not equal to itself.")
12261506 }
1507+ else throw("Strict value is not equal to itself.")
12271508 }
12281509
12291510
12301511
12311512 @Callable(i)
1232-func removeMargin (_amount) = {
1233- let _trader = toString(i.caller)
1234- if (if (if (if ((0 >= _amount))
1235- then true
1236- else !(requireOpenPosition(_trader)))
1237- then true
1238- else !(initialized()))
1239- then true
1240- else paused())
1241- then throw("Invalid removeMargin parameters")
1242- else {
1243- let $t05452054660 = getPosition(_trader)
1244- let oldPositionSize = $t05452054660._1
1245- let oldPositionMargin = $t05452054660._2
1246- let oldPositionOpenNotional = $t05452054660._3
1247- let oldPositionLstUpdCPF = $t05452054660._4
1248- let marginDelta = -(_amount)
1249- let $t05469754876 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, marginDelta)
1250- let remainMargin = $t05469754876._1
1251- let badDebt = $t05469754876._2
1252- if ((badDebt != 0))
1253- then throw("Invalid removed margin amount")
1513+func closePosition (_size,_minQuoteAssetAmount) = {
1514+ let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
1515+ if ((sync == sync))
1516+ then {
1517+ let _trader = getActualCaller(i)
1518+ let _traderAddress = valueOrErrorMessage(addressFromString(_trader), "Invalid caller")
1519+ if (if (if (if (if (!(requireOpenPosition(_trader)))
1520+ then true
1521+ else !(initialized()))
1522+ then true
1523+ else paused())
1524+ then true
1525+ else (0 >= _size))
1526+ then true
1527+ else (0 > _minQuoteAssetAmount))
1528+ then throw("Invalid closePosition parameters")
12541529 else {
1255- let marginRatio = calcMarginRatio(remainMargin, badDebt, oldPositionOpenNotional)
1256- if (!(requireMoreMarginRatio(marginRatio, initMarginRatio(), true)))
1257- then throw(((("Too much margin removed: " + toString(marginRatio)) + " < ") + toString(initMarginRatio())))
1530+ let $t06429364433 = getPosition(_trader)
1531+ let oldPositionSize = $t06429364433._1
1532+ let oldPositionMargin = $t06429364433._2
1533+ let oldPositionOpenNotional = $t06429364433._3
1534+ let oldPositionLstUpdCPF = $t06429364433._4
1535+ let $t06443968811 = if ((abs(oldPositionSize) > _size))
1536+ then {
1537+ let _direction = if ((oldPositionSize > 0))
1538+ then DIR_SHORT
1539+ else DIR_LONG
1540+ let isAdd = (_direction == DIR_LONG)
1541+ let $t06503065252 = swapOutput((oldPositionSize > 0), _size, true)
1542+ let exchangedQuoteAssetAmount = $t06503065252._1
1543+ let quoteAssetReserveAfter = $t06503065252._2
1544+ let baseAssetReserveAfter = $t06503065252._3
1545+ let totalPositionSizeAfter = $t06503065252._4
1546+ let exchangedPositionSize = if ((oldPositionSize > 0))
1547+ then -(_size)
1548+ else _size
1549+ let $t06534365497 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)
1550+ let oldPositionNotional = $t06534365497._1
1551+ let unrealizedPnl = $t06534365497._2
1552+ let realizedRatio = divd(abs(exchangedPositionSize), abs(oldPositionSize))
1553+ let realizedPnl = muld(unrealizedPnl, realizedRatio)
1554+ let $t06571165949 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl)
1555+ let remainMargin = $t06571165949._1
1556+ let positionBadDebt = $t06571165949._2
1557+ let fundingPayment = $t06571165949._3
1558+ let unrealizedPnlAfter = (unrealizedPnl - realizedPnl)
1559+ let remainOpenNotional = if ((oldPositionSize > 0))
1560+ then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter)
1561+ else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount)
1562+ let newPositionMargin = muld(remainMargin, realizedRatio)
1563+ let newPositionSize = (oldPositionSize + exchangedPositionSize)
1564+ let newPositionOpenNotional = abs(remainOpenNotional)
1565+ let newPositionLstUpdCPF = latestCumulativePremiumFraction(newPositionSize)
1566+ let openInterestNotionalAfter = (openInterestNotional() - exchangedQuoteAssetAmount)
1567+ if (if ((_minQuoteAssetAmount != 0))
1568+ then (_minQuoteAssetAmount > exchangedQuoteAssetAmount)
1569+ else false)
1570+ then throw(((("Limit error: " + toString(exchangedQuoteAssetAmount)) + " < ") + toString(_minQuoteAssetAmount)))
1571+ else $Tuple15(newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF, positionBadDebt, realizedPnl, (abs((remainMargin - newPositionMargin)) + realizedPnl), quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, (totalLongPositionSize() - (if ((newPositionSize > 0))
1572+ then abs(exchangedPositionSize)
1573+ else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize))
1574+ then abs(exchangedPositionSize)
1575+ else 0)), (openInterestLong() - (if ((newPositionSize > 0))
1576+ then exchangedQuoteAssetAmount
1577+ else 0)), (openInterestShort() - (if ((0 > newPositionSize))
1578+ then exchangedQuoteAssetAmount
1579+ else 0)))
1580+ }
1581+ else if ((_size > abs(oldPositionSize)))
1582+ then throw("Invalid closePosition parameters")
1583+ else {
1584+ let $t06775268171 = internalClosePosition(_trader, true)
1585+ let exchangedQuoteAssetAmount = $t06775268171._1
1586+ let positionBadDebt = $t06775268171._2
1587+ let realizedPnl = $t06775268171._3
1588+ let marginToVault = $t06775268171._4
1589+ let quoteAssetReserveAfter = $t06775268171._5
1590+ let baseAssetReserveAfter = $t06775268171._6
1591+ let totalPositionSizeAfter = $t06775268171._7
1592+ let openInterestNotionalAfter = $t06775268171._8
1593+ let x2 = $t06775268171._9
1594+ let totalLongAfter = $t06775268171._10
1595+ let totalShortAfter = $t06775268171._11
1596+ let totalLongOpenInterestAfter = $t06775268171._12
1597+ let totalShortOpenInterestAfter = $t06775268171._13
1598+ if (if ((_minQuoteAssetAmount != 0))
1599+ then (_minQuoteAssetAmount > exchangedQuoteAssetAmount)
1600+ else false)
1601+ then throw(((("Limit error: " + toString(exchangedQuoteAssetAmount)) + " < ") + toString(_minQuoteAssetAmount)))
1602+ else $Tuple15(0, 0, 0, 0, positionBadDebt, realizedPnl, marginToVault, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)
1603+ }
1604+ let newPositionSize = $t06443968811._1
1605+ let newPositionMargin = $t06443968811._2
1606+ let newPositionOpenNotional = $t06443968811._3
1607+ let newPositionLstUpdCPF = $t06443968811._4
1608+ let positionBadDebt = $t06443968811._5
1609+ let realizedPnl = $t06443968811._6
1610+ let marginToVault = $t06443968811._7
1611+ let quoteAssetReserveAfter = $t06443968811._8
1612+ let baseAssetReserveAfter = $t06443968811._9
1613+ let totalPositionSizeAfter = $t06443968811._10
1614+ let openInterestNotionalAfter = $t06443968811._11
1615+ let totalLongAfter = $t06443968811._12
1616+ let totalShortAfter = $t06443968811._13
1617+ let totalLongOpenInterestAfter = $t06443968811._14
1618+ let totalShortOpenInterestAfter = $t06443968811._15
1619+ if ((positionBadDebt > 0))
1620+ then throw("Unable to close position with bad debt")
12581621 else {
1259- let quoteAssetStr = toBase58String(quoteAsset())
1260- let $t05532055374 = getBorrowedByTrader(_trader)
1261- let borrowed = $t05532055374._1
1262- let assetId = $t05532055374._2
1263- let toRepay = if ((_amount > borrowed))
1264- then borrowed
1265- else _amount
1266- let toWithdraw = if ((borrowed > _amount))
1267- then 0
1268- else (_amount - borrowed)
1269- let finalBorrow = (borrowed - toRepay)
1270- let switchPositionToQuote = if ((finalBorrow > 0))
1271- then nil
1272- else updatePositionAsset(_trader, quoteAssetStr)
1273- let doSanityCheck = if (((toRepay + toWithdraw) != _amount))
1274- then throw(((((("toRepay=" + toString(toRepay)) + " + toWithdraw=") + toString(toWithdraw)) + " != ") + toString(_amount)))
1275- else nil
1276- if ((doSanityCheck == doSanityCheck))
1277- then {
1278- let doUnstake = invoke(managerAddress(), "withdraw", [quoteAssetStr, _amount], nil)
1279- if ((doUnstake == doUnstake))
1280- then {
1281- let returnCollateralAction = if ((toRepay > 0))
1282- then {
1283- let doRepay = invoke(collateralAddress(), "repay", [_trader, assetId], [AttachedPayment(quoteAsset(), toRepay)])
1284- if ((doRepay == doRepay))
1285- then [ScriptTransfer(i.caller, toRepay, fromBase58String(assetId))]
1286- else throw("Strict value is not equal to itself.")
1287- }
1288- else nil
1289- if ((returnCollateralAction == returnCollateralAction))
1290- then (updatePosition(_trader, oldPositionSize, remainMargin, oldPositionOpenNotional, latestCumulativePremiumFraction(oldPositionSize)) ++ (if ((toWithdraw > 0))
1291- then withdraw(i.caller, toWithdraw)
1292- else (((nil ++ updateBalance((cbalance() - _amount))) ++ switchPositionToQuote) ++ returnCollateralAction)))
1293- else throw("Strict value is not equal to itself.")
1294- }
1295- else throw("Strict value is not equal to itself.")
1296- }
1297- else throw("Strict value is not equal to itself.")
1298- }
1299- }
1300- }
1301- }
1302-
1303-
1304-
1305-@Callable(i)
1306-func closePosition () = {
1307- let _trader = getActualCaller(i)
1308- let _traderAddress = valueOrErrorMessage(addressFromString(_trader), "Invalid caller")
1309- if (if (if (!(requireOpenPosition(_trader)))
1310- then true
1311- else !(initialized()))
1312- then true
1313- else paused())
1314- then throw("Invalid closePosition parameters")
1315- else {
1316- let $t05756657944 = internalClosePosition(_trader, true)
1317- let x1 = $t05756657944._1
1318- let positionBadDebt = $t05756657944._2
1319- let realizedPnl = $t05756657944._3
1320- let marginToVault = $t05756657944._4
1321- let quoteAssetReserveAfter = $t05756657944._5
1322- let baseAssetReserveAfter = $t05756657944._6
1323- let totalPositionSizeAfter = $t05756657944._7
1324- let cumulativeNotionalAfter = $t05756657944._8
1325- let openInterestNotionalAfter = $t05756657944._9
1326- let x2 = $t05756657944._10
1327- let totalLongAfter = $t05756657944._11
1328- let totalShortAfter = $t05756657944._12
1329- if ((positionBadDebt > 0))
1330- then throw("Unable to close position with bad debt")
1331- else {
1332- let withdrawAmount = abs(marginToVault)
1333- let ammBalance = (cbalance() - withdrawAmount)
1334- let $t05815358295 = if ((0 > ammBalance))
1335- then $Tuple2(0, abs(ammBalance))
1336- else $Tuple2(ammBalance, 0)
1337- let ammNewBalance = $t05815358295._1
1338- let getFromInsurance = $t05815358295._2
1339- let x = if ((getFromInsurance > 0))
1340- then {
1341- let withdrawInsurance = invoke(insuranceAddress(), "withdraw", [getFromInsurance], nil)
1342- if ((withdrawInsurance == withdrawInsurance))
1343- then nil
1344- else throw("Strict value is not equal to itself.")
1345- }
1346- else nil
1347- if ((x == x))
1348- then {
1349- let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), (withdrawAmount - getFromInsurance)], nil)
1622+ let withdrawAmount = abs(marginToVault)
1623+ let ammBalance = (cbalance() - withdrawAmount)
1624+ let $t06902069149 = if ((0 > ammBalance))
1625+ then $Tuple2(0, abs(ammBalance))
1626+ else $Tuple2(ammBalance, 0)
1627+ let ammNewBalance = $t06902069149._1
1628+ let x11 = $t06902069149._2
1629+ let unstake = invoke(vaultAddress(), "withdrawLocked", [withdrawAmount], nil)
13501630 if ((unstake == unstake))
13511631 then {
1352- let $t05879758851 = getBorrowedByTrader(_trader)
1353- let borrowed = $t05879758851._1
1354- let assetId = $t05879758851._2
1355- let $t05886659783 = if ((borrowed > 0))
1632+ let $t06936169415 = getBorrowedByTrader(_trader)
1633+ let borrowed = $t06936169415._1
1634+ let assetId = $t06936169415._2
1635+ let $t06943070347 = if ((borrowed > 0))
13561636 then if ((withdrawAmount >= borrowed))
13571637 then {
13581638 let doRepay = invoke(collateralAddress(), "repay", [_trader, assetId], [AttachedPayment(quoteAsset(), borrowed)])
13671647 else throw("Strict value is not equal to itself.")
13681648 }
13691649 else $Tuple2(nil, withdrawAmount)
1370- if (($t05886659783 == $t05886659783))
1650+ if (($t06943070347 == $t06943070347))
13711651 then {
1372- let quoteWithdrawAmount = $t05886659783._2
1373- let sendCollateralAction = $t05886659783._1
1652+ let quoteWithdrawAmount = $t06943070347._2
1653+ let sendCollateralAction = $t06943070347._1
13741654 let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, 0], nil)
13751655 if ((notifyNotional == notifyNotional))
1376- then ((deletePosition(_trader) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter)) ++ (if ((quoteWithdrawAmount > 0))
1656+ then (((((if ((newPositionSize == 0))
1657+ then deletePosition(_trader)
1658+ else updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ (if ((quoteWithdrawAmount > 0))
13771659 then withdraw(_traderAddress, quoteWithdrawAmount)
1378- else ((nil ++ updateBalance(ammNewBalance)) ++ sendCollateralAction)))
1660+ else nil)) ++ updateBalance(ammNewBalance)) ++ sendCollateralAction)
13791661 else throw("Strict value is not equal to itself.")
13801662 }
13811663 else throw("Strict value is not equal to itself.")
13821664 }
13831665 else throw("Strict value is not equal to itself.")
13841666 }
1385- else throw("Strict value is not equal to itself.")
13861667 }
13871668 }
1669+ else throw("Strict value is not equal to itself.")
13881670 }
13891671
13901672
13911673
13921674 @Callable(i)
13931675 func liquidate (_trader) = {
1394- let spotMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_SPOT)
1395- let marginRatio = if (isOverFluctuationLimit())
1676+ let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
1677+ if ((sync == sync))
13961678 then {
1397- let oracleMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_ORACLE)
1398- vmax(spotMarginRatio, oracleMarginRatio)
1399- }
1400- else spotMarginRatio
1401- if (if (if (if (!(requireMoreMarginRatio(marginRatio, maintenanceMarginRatio(), false)))
1402- then true
1403- else !(requireOpenPosition(_trader)))
1404- then true
1405- else !(initialized()))
1406- then true
1407- else paused())
1408- then throw("Unable to liquidate")
1409- else if (if (if ((spotMarginRatio > liquidationFeeRatio()))
1410- then (partialLiquidationRatio() > 0)
1411- else false)
1412- then (DECIMAL_UNIT > partialLiquidationRatio())
1413- else false)
1414- then {
1415- let $t06148361633 = getPosition(_trader)
1416- let oldPositionSize = $t06148361633._1
1417- let oldPositionMargin = $t06148361633._2
1418- let oldPositionOpenNotional = $t06148361633._3
1419- let oldPositionLstUpdCPF = $t06148361633._4
1420- let _direction = if ((oldPositionSize > 0))
1421- then DIR_SHORT
1422- else DIR_LONG
1423- let isAdd = (_direction == DIR_LONG)
1424- let exchangedQuoteAssetAmount = getPartialLiquidationAmount(_trader, oldPositionSize)
1425- let $t06185861962 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)
1426- let oldPositionNotional = $t06185861962._1
1427- let unrealizedPnl = $t06185861962._2
1428- let $t06197062202 = swapInput(isAdd, exchangedQuoteAssetAmount)
1429- let exchangedPositionSize = $t06197062202._1
1430- let quoteAssetReserveAfter = $t06197062202._2
1431- let baseAssetReserveAfter = $t06197062202._3
1432- let totalPositionSizeAfter = $t06197062202._4
1433- let cumulativeNotionalAfter = $t06197062202._5
1434- let liquidationRatio = divd(abs(exchangedPositionSize), abs(oldPositionSize))
1435- let realizedPnl = muld(unrealizedPnl, liquidationRatio)
1436- let $t06241362646 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl)
1437- let remainMargin = $t06241362646._1
1438- let badDebt = $t06241362646._2
1439- let fundingPayment = $t06241362646._3
1440- let unrealizedPnlAfter = (unrealizedPnl - realizedPnl)
1441- let remainOpenNotional = if ((oldPositionSize > 0))
1442- then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter)
1443- else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount)
1444- let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio())
1445- let feeToLiquidator = (liquidationPenalty / 2)
1446- let feeToInsurance = (liquidationPenalty - feeToLiquidator)
1447- let newPositionMargin = (remainMargin - liquidationPenalty)
1448- let newPositionSize = (oldPositionSize + exchangedPositionSize)
1449- let newPositionOpenNotional = abs(remainOpenNotional)
1450- let newPositionLstUpdCPF = latestCumulativePremiumFraction(newPositionSize)
1451- let openInterestNotionalAfter = (openInterestNotional() - exchangedQuoteAssetAmount)
1452- let ammBalance = (cbalance() - liquidationPenalty)
1453- let $t06381963962 = if ((0 > ammBalance))
1454- then $Tuple2(0, abs(ammBalance))
1455- else $Tuple2(ammBalance, 0)
1456- let newAmmBalance = $t06381963962._1
1457- let takeFromInsurance = $t06381963962._2
1458- let $t06397064024 = getBorrowedByTrader(_trader)
1459- let borrowed = $t06397064024._1
1460- let assetId = $t06397064024._2
1461- let doLiquidateCollateral = if ((borrowed > 0))
1679+ let spotMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_SPOT)
1680+ let marginRatio = if (isOverFluctuationLimit())
1681+ then {
1682+ let oracleMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_ORACLE)
1683+ vmax(spotMarginRatio, oracleMarginRatio)
1684+ }
1685+ else spotMarginRatio
1686+ if (if (if (if (!(requireMoreMarginRatio(marginRatio, maintenanceMarginRatio(), false)))
1687+ then true
1688+ else !(requireOpenPosition(_trader)))
1689+ then true
1690+ else !(initialized()))
1691+ then true
1692+ else paused())
1693+ then throw("Unable to liquidate")
1694+ else if (if (if ((spotMarginRatio > liquidationFeeRatio()))
1695+ then (partialLiquidationRatio() > 0)
1696+ else false)
1697+ then (DECIMAL_UNIT > partialLiquidationRatio())
1698+ else false)
14621699 then {
1463- let collateralToSell = muld(borrowed, liquidationRatio)
1464- let realizeAndClose = invoke(collateralAddress(), "realizePartially", [_trader, assetId, collateralToSell], nil)
1465- if ((realizeAndClose == realizeAndClose))
1466- then nil
1467- else throw("Strict value is not equal to itself.")
1468- }
1469- else nil
1470- if ((doLiquidateCollateral == doLiquidateCollateral))
1471- then {
1472- let x = if ((takeFromInsurance > 0))
1700+ let $t07239672546 = getPosition(_trader)
1701+ let oldPositionSize = $t07239672546._1
1702+ let oldPositionMargin = $t07239672546._2
1703+ let oldPositionOpenNotional = $t07239672546._3
1704+ let oldPositionLstUpdCPF = $t07239672546._4
1705+ let _direction = if ((oldPositionSize > 0))
1706+ then DIR_SHORT
1707+ else DIR_LONG
1708+ let isAdd = (_direction == DIR_LONG)
1709+ let exchangedQuoteAssetAmount = getPartialLiquidationAmount(_trader, oldPositionSize)
1710+ let $t07277172875 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)
1711+ let oldPositionNotional = $t07277172875._1
1712+ let unrealizedPnl = $t07277172875._2
1713+ let $t07288373070 = swapInput(isAdd, exchangedQuoteAssetAmount)
1714+ let exchangedPositionSize = $t07288373070._1
1715+ let quoteAssetReserveAfter = $t07288373070._2
1716+ let baseAssetReserveAfter = $t07288373070._3
1717+ let totalPositionSizeAfter = $t07288373070._4
1718+ let liquidationRatio = divd(abs(exchangedPositionSize), abs(oldPositionSize))
1719+ let realizedPnl = muld(unrealizedPnl, liquidationRatio)
1720+ let $t07335973592 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl)
1721+ let remainMargin = $t07335973592._1
1722+ let badDebt = $t07335973592._2
1723+ let fundingPayment = $t07335973592._3
1724+ let unrealizedPnlAfter = (unrealizedPnl - realizedPnl)
1725+ let remainOpenNotional = if ((oldPositionSize > 0))
1726+ then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter)
1727+ else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount)
1728+ let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio())
1729+ let feeToLiquidator = (liquidationPenalty / 2)
1730+ let feeToInsurance = (liquidationPenalty - feeToLiquidator)
1731+ let newPositionMargin = (remainMargin - liquidationPenalty)
1732+ let newPositionSize = (oldPositionSize + exchangedPositionSize)
1733+ let newPositionOpenNotional = abs(remainOpenNotional)
1734+ let newPositionLstUpdCPF = latestCumulativePremiumFraction(newPositionSize)
1735+ let openInterestNotionalAfter = (openInterestNotional() - exchangedQuoteAssetAmount)
1736+ let ammBalance = (cbalance() - liquidationPenalty)
1737+ let $t07476574894 = if ((0 > ammBalance))
1738+ then $Tuple2(0, abs(ammBalance))
1739+ else $Tuple2(ammBalance, 0)
1740+ let newAmmBalance = $t07476574894._1
1741+ let x11 = $t07476574894._2
1742+ let $t07490274956 = getBorrowedByTrader(_trader)
1743+ let borrowed = $t07490274956._1
1744+ let assetId = $t07490274956._2
1745+ let doLiquidateCollateral = if ((borrowed > 0))
14731746 then {
1474- let withdrawInsurance = invoke(insuranceAddress(), "withdraw", [takeFromInsurance], nil)
1475- if ((withdrawInsurance == withdrawInsurance))
1747+ let collateralToSell = muld(borrowed, liquidationRatio)
1748+ let realizeAndClose = invoke(collateralAddress(), "realizePartially", [_trader, assetId, collateralToSell], nil)
1749+ if ((realizeAndClose == realizeAndClose))
14761750 then nil
14771751 else throw("Strict value is not equal to itself.")
14781752 }
14791753 else nil
1480- if ((x == x))
1754+ if ((doLiquidateCollateral == doLiquidateCollateral))
14811755 then {
1482- let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), (liquidationPenalty - takeFromInsurance)], nil)
1756+ let unstake = invoke(vaultAddress(), "withdrawLocked", [liquidationPenalty], nil)
14831757 if ((unstake == unstake))
14841758 then {
1485- let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
1759+ let depositInsurance = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
14861760 if ((depositInsurance == depositInsurance))
14871761 then {
14881762 let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil)
14891763 if ((notifyNotional == notifyNotional))
1490- then (((updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, (totalLongPositionSize() - (if ((newPositionSize > 0))
1764+ then (((updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, (totalLongPositionSize() - (if ((newPositionSize > 0))
14911765 then abs(exchangedPositionSize)
14921766 else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize))
14931767 then abs(exchangedPositionSize)
1768+ else 0)), (openInterestLong() - (if ((newPositionSize > 0))
1769+ then exchangedQuoteAssetAmount
1770+ else 0)), (openInterestShort() - (if ((0 > newPositionSize))
1771+ then exchangedQuoteAssetAmount
14941772 else 0)))) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance))
14951773 else throw("Strict value is not equal to itself.")
14961774 }
15001778 }
15011779 else throw("Strict value is not equal to itself.")
15021780 }
1503- else throw("Strict value is not equal to itself.")
1504- }
1505- else {
1506- let $t06586666321 = internalClosePosition(_trader, false)
1507- let x1 = $t06586666321._1
1508- let badDebt = $t06586666321._2
1509- let x2 = $t06586666321._3
1510- let x3 = $t06586666321._4
1511- let quoteAssetReserveAfter = $t06586666321._5
1512- let baseAssetReserveAfter = $t06586666321._6
1513- let totalPositionSizeAfter = $t06586666321._7
1514- let cumulativeNotionalAfter = $t06586666321._8
1515- let openInterestNotionalAfter = $t06586666321._9
1516- let exchangedQuoteAssetAmount = $t06586666321._10
1517- let totalLongAfter = $t06586666321._11
1518- let totalShortAfter = $t06586666321._12
1519- let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio())
1520- let feeToLiquidator = (liquidationPenalty / 2)
1521- let feeToInsurance = (liquidationPenalty - feeToLiquidator)
1522- let ammBalance = (cbalance() - liquidationPenalty)
1523- let $t06673366876 = if ((0 > ammBalance))
1524- then $Tuple2(0, abs(ammBalance))
1525- else $Tuple2(ammBalance, 0)
1526- let newAmmBalance = $t06673366876._1
1527- let takeFromInsurance = $t06673366876._2
1528- let $t06688466938 = getBorrowedByTrader(_trader)
1529- let borrowed = $t06688466938._1
1530- let assetId = $t06688466938._2
1531- let doLiquidateCollateral = if ((borrowed > 0))
1532- then {
1533- let realizeAndClose = invoke(collateralAddress(), "realizePartiallyAndClose", [_trader, assetId], nil)
1534- if ((realizeAndClose == realizeAndClose))
1535- then nil
1536- else throw("Strict value is not equal to itself.")
1537- }
1538- else nil
1539- if ((doLiquidateCollateral == doLiquidateCollateral))
1540- then {
1541- let x = if ((takeFromInsurance > 0))
1781+ else {
1782+ let $t07665577150 = internalClosePosition(_trader, false)
1783+ let x1 = $t07665577150._1
1784+ let badDebt = $t07665577150._2
1785+ let x2 = $t07665577150._3
1786+ let x3 = $t07665577150._4
1787+ let quoteAssetReserveAfter = $t07665577150._5
1788+ let baseAssetReserveAfter = $t07665577150._6
1789+ let totalPositionSizeAfter = $t07665577150._7
1790+ let openInterestNotionalAfter = $t07665577150._8
1791+ let exchangedQuoteAssetAmount = $t07665577150._9
1792+ let totalLongAfter = $t07665577150._10
1793+ let totalShortAfter = $t07665577150._11
1794+ let totalLongOpenInterestAfter = $t07665577150._12
1795+ let totalShortOpenInterestAfter = $t07665577150._13
1796+ let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio())
1797+ let feeToLiquidator = (liquidationPenalty / 2)
1798+ let feeToInsurance = (liquidationPenalty - feeToLiquidator)
1799+ let ammBalance = (cbalance() - liquidationPenalty)
1800+ let $t07756277691 = if ((0 > ammBalance))
1801+ then $Tuple2(0, abs(ammBalance))
1802+ else $Tuple2(ammBalance, 0)
1803+ let newAmmBalance = $t07756277691._1
1804+ let x11 = $t07756277691._2
1805+ let $t07769977753 = getBorrowedByTrader(_trader)
1806+ let borrowed = $t07769977753._1
1807+ let assetId = $t07769977753._2
1808+ let doLiquidateCollateral = if ((borrowed > 0))
15421809 then {
1543- let withdrawInsurance = invoke(insuranceAddress(), "withdraw", [takeFromInsurance], nil)
1544- if ((withdrawInsurance == withdrawInsurance))
1810+ let realizeAndClose = invoke(collateralAddress(), "realizePartiallyAndClose", [_trader, assetId], nil)
1811+ if ((realizeAndClose == realizeAndClose))
15451812 then nil
15461813 else throw("Strict value is not equal to itself.")
15471814 }
15481815 else nil
1549- if ((x == x))
1816+ if ((doLiquidateCollateral == doLiquidateCollateral))
15501817 then {
1551- let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), (liquidationPenalty - takeFromInsurance)], nil)
1552- if ((unstake == unstake))
1818+ let x = if ((badDebt > 0))
15531819 then {
1554- let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
1555- if ((depositInsurance == depositInsurance))
1820+ let lockBadDebt = invoke(vaultAddress(), "exchangeFreeAndLocked", [badDebt], nil)
1821+ if ((lockBadDebt == lockBadDebt))
1822+ then nil
1823+ else throw("Strict value is not equal to itself.")
1824+ }
1825+ else nil
1826+ if ((x == x))
1827+ then {
1828+ let unstake = invoke(vaultAddress(), "withdrawLocked", [liquidationPenalty], nil)
1829+ if ((unstake == unstake))
15561830 then {
1557- let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, 0], nil)
1558- if ((notifyNotional == notifyNotional))
1559- then (((deletePosition(_trader) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter)) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance))
1831+ let depositInsurance = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
1832+ if ((depositInsurance == depositInsurance))
1833+ then {
1834+ let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, 0], nil)
1835+ if ((notifyNotional == notifyNotional))
1836+ then (((deletePosition(_trader) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance))
1837+ else throw("Strict value is not equal to itself.")
1838+ }
15601839 else throw("Strict value is not equal to itself.")
15611840 }
15621841 else throw("Strict value is not equal to itself.")
15651844 }
15661845 else throw("Strict value is not equal to itself.")
15671846 }
1568- else throw("Strict value is not equal to itself.")
1569- }
1847+ }
1848+ else throw("Strict value is not equal to itself.")
15701849 }
15711850
15721851
15821861 then throw(((("Invalid funding block timestamp: " + toString(lastBlock.timestamp)) + " < ") + toString(fundingBlockTimestamp)))
15831862 else {
15841863 let underlyingPrice = getOracleTwapPrice()
1585- let $t06873668798 = getFunding()
1586- let shortPremiumFraction = $t06873668798._1
1587- let longPremiumFraction = $t06873668798._2
1864+ let $t07956079622 = getFunding()
1865+ let shortPremiumFraction = $t07956079622._1
1866+ let longPremiumFraction = $t07956079622._2
15881867 updateFunding((fundingBlockTimestamp + fundingPeriodSeconds()), (latestLongCumulativePremiumFraction() + longPremiumFraction), (latestShortCumulativePremiumFraction() + shortPremiumFraction), divd(longPremiumFraction, underlyingPrice), divd(shortPremiumFraction, underlyingPrice))
15891868 }
15901869 }
15921871
15931872
15941873 @Callable(i)
1595-func forceMoveAsset (_trader,_amount) = if (if ((addressFromPublicKey(adminPublicKey()) != i.caller))
1596- then true
1597- else (0 > _amount))
1598- then throw("Invalid forceMoveAsset parameters")
1599- else {
1600- let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), _amount], nil)
1601- if ((unstake == unstake))
1602- then (withdraw(addressFromStringValue(_trader), _amount) ++ updateBalance((cbalance() - _amount)))
1603- else throw("Strict value is not equal to itself.")
1604- }
1605-
1606-
1607-
1608-@Callable(i)
1609-func adjustPeg (_price) = if (if ((addressFromPublicKey(adminPublicKey()) != i.caller))
1610- then true
1611- else (0 > _price))
1612- then throw("Invalid adjustPeg parameters")
1613- else {
1614- let $t06978969875 = getPegAdjustCost(_price)
1615- let newQuoteAssetReserve = $t06978969875._1
1616- let pegChangeCost = $t06978969875._2
1617- if ((pegChangeCost == 0))
1618- then throw("Nothing to adjust")
1619- else if ((pegChangeCost > 0))
1620- then updateAmmReserves(newQuoteAssetReserve, bsAstR())
1621- else {
1622- let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), abs(pegChangeCost)], nil)
1623- if ((unstake == unstake))
1624- then {
1625- let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), abs(pegChangeCost))])
1626- if ((depositInsurance == depositInsurance))
1627- then (updateBalance((cbalance() - abs(pegChangeCost))) ++ updateAmmReserves(newQuoteAssetReserve, bsAstR()))
1628- else throw("Strict value is not equal to itself.")
1629- }
1630- else throw("Strict value is not equal to itself.")
1631- }
1632- }
1633-
1634-
1635-
1636-@Callable(i)
1637-func migrateLiquidity () = {
1638- let amount = cbalance()
1639- if ((amount > 0))
1640- then {
1641- let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [amount, toBase58String(quoteAsset())], nil)
1642- if ((unstake == unstake))
1643- then {
1644- let stake = invoke(managerAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), amount)])
1645- if ((stake == stake))
1646- then nil
1647- else throw("Strict value is not equal to itself.")
1648- }
1649- else throw("Strict value is not equal to itself.")
1650- }
1651- else nil
1652- }
1653-
1654-
1655-
1656-@Callable(i)
1657-func v_get (_trader) = {
1658- let $t07151671576 = internalClosePosition(_trader, false)
1659- let x1 = $t07151671576._1
1660- let x2 = $t07151671576._2
1661- let x3 = $t07151671576._3
1662- let x4 = $t07151671576._4
1663- throw((((s(x2) + s(x3)) + s(x4)) + s(getMarginRatio(_trader))))
1874+func syncTerminalPriceToOracle () = {
1875+ let $t08000480125 = getSyncTerminalPrice(getOracleTwapPrice())
1876+ let newQuoteAssetWeight = $t08000480125._1
1877+ let newBaseAssetWeight = $t08000480125._2
1878+ let marginToVault = $t08000480125._3
1879+ let lockBadDebt = invoke(vaultAddress(), "exchangeFreeAndLocked", [marginToVault], nil)
1880+ if ((lockBadDebt == lockBadDebt))
1881+ then updateAmmWeights(newQuoteAssetWeight, newBaseAssetWeight)
1882+ else throw("Strict value is not equal to itself.")
16641883 }
16651884
16661885
16671886
16681887 @Callable(i)
16691888 func view_calcRemainMarginWithFundingPayment (_trader) = {
1670- let $t07172371834 = getPosition(_trader)
1671- let positionSize = $t07172371834._1
1672- let positionMargin = $t07172371834._2
1673- let pon = $t07172371834._3
1674- let positionLstUpdCPF = $t07172371834._4
1675- let $t07183971940 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)
1676- let positionNotional = $t07183971940._1
1677- let unrealizedPnl = $t07183971940._2
1678- let $t07194572127 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl)
1679- let remainMargin = $t07194572127._1
1680- let badDebt = $t07194572127._2
1681- let fundingPayment = $t07194572127._3
1682- throw((((((s(remainMargin) + s(fundingPayment)) + s(getMarginRatio(_trader))) + s(unrealizedPnl)) + s(badDebt)) + s(positionNotional)))
1889+ let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
1890+ if ((sync == sync))
1891+ then {
1892+ let $t08050280603 = getPosition(_trader)
1893+ let positionSize = $t08050280603._1
1894+ let positionMargin = $t08050280603._2
1895+ let pon = $t08050280603._3
1896+ let positionLstUpdCPF = $t08050280603._4
1897+ let $t08060680707 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)
1898+ let positionNotional = $t08060680707._1
1899+ let unrealizedPnl = $t08060680707._2
1900+ let $t08071080882 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl)
1901+ let remainMargin = $t08071080882._1
1902+ let badDebt = $t08071080882._2
1903+ let fundingPayment = $t08071080882._3
1904+ throw((((((s(remainMargin) + s(fundingPayment)) + s(getMarginRatio(_trader))) + s(unrealizedPnl)) + s(badDebt)) + s(positionNotional)))
1905+ }
1906+ else throw("Strict value is not equal to itself.")
16831907 }
16841908
16851909
16861910
16871911 @Callable(i)
16881912 func view_getPegAdjustCost (_price) = {
1689- let cost = getPegAdjustCost(_price)
1690- throw(toString(cost._2))
1913+ let result = getSyncTerminalPrice(_price)
1914+ throw(toString(result._3))
1915+ }
1916+
1917+
1918+
1919+@Callable(i)
1920+func view_getTerminalAmmPrice () = {
1921+ let $t08122981310 = getTerminalAmmState()
1922+ let terminalQuoteAssetReserve = $t08122981310._1
1923+ let terminalBaseAssetReserve = $t08122981310._2
1924+ let price = divd(muld(terminalQuoteAssetReserve, qtAstW()), muld(terminalBaseAssetReserve, bsAstW()))
1925+ throw(toString(price))
16911926 }
16921927
16931928
16951930 @Callable(i)
16961931 func view_getFunding () = {
16971932 let underlyingPrice = getOracleTwapPrice()
1698- let $t07251872580 = getFunding()
1699- let shortPremiumFraction = $t07251872580._1
1700- let longPremiumFraction = $t07251872580._2
1933+ let $t08152981591 = getFunding()
1934+ let shortPremiumFraction = $t08152981591._1
1935+ let longPremiumFraction = $t08152981591._2
17011936 let longFunding = divd(longPremiumFraction, underlyingPrice)
17021937 let shortFunding = divd(shortPremiumFraction, underlyingPrice)
17031938 throw((((s(longFunding) + s(shortFunding)) + s(getTwapSpotPrice())) + s(getOracleTwapPrice())))
17071942
17081943 @Callable(i)
17091944 func view_getBorrowedByTrader (_trader) = {
1710- let $t07287072924 = getBorrowedByTrader(_trader)
1711- let borrowed = $t07287072924._1
1712- let assetId = $t07287072924._2
1945+ let $t08188181935 = getBorrowedByTrader(_trader)
1946+ let borrowed = $t08188181935._1
1947+ let assetId = $t08188181935._2
17131948 throw((s(borrowed) + assetId))
1949+ }
1950+
1951+
1952+
1953+@Callable(i)
1954+func computeSpotPrice () = {
1955+ let result = getSpotPrice()
1956+ $Tuple2(nil, result)
1957+ }
1958+
1959+
1960+
1961+@Callable(i)
1962+func computeFeeForTraderWithArtifact (_trader,_artifactId) = {
1963+ let result = getForTraderWithArtifact(_trader, _artifactId)
1964+ $Tuple2(nil, result)
17141965 }
17151966
17161967
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let k_ora_key = "k_ora_key"
55
66 let k_ora_block_key = "k_ora_block_key"
77
88 let k_ora = "k_ora"
99
1010 let k_balance = "k_balance"
1111
12+let k_sequence = "k_sequence"
13+
1214 let k_positionSize = "k_positionSize"
1315
1416 let k_positionMargin = "k_positionMargin"
1517
1618 let k_positionOpenNotional = "k_positionOpenNotional"
1719
1820 let k_positionLastUpdatedCumulativePremiumFraction = "k_positionFraction"
1921
20-let k_positionClosedDate = "k_positionClosedDate"
22+let k_positionSequence = "k_positionSequence"
2123
2224 let k_positionAsset = "k_positionAsset"
2325
2426 let k_initialized = "k_initialized"
2527
2628 let k_paused = "k_paused"
29+
30+let k_closeOnly = "k_closeOnly"
2731
2832 let k_fee = "k_fee"
2933
3034 let k_fundingPeriod = "k_fundingPeriod"
3135
3236 let k_initMarginRatio = "k_initMarginRatio"
3337
3438 let k_maintenanceMarginRatio = "k_mmr"
3539
3640 let k_liquidationFeeRatio = "k_liquidationFeeRatio"
3741
3842 let k_partialLiquidationRatio = "k_partLiquidationRatio"
3943
4044 let k_spreadLimit = "k_spreadLimit"
4145
4246 let k_maxPriceImpact = "k_maxPriceImpact"
4347
4448 let k_maxPriceSpread = "k_maxPriceSpread"
49+
50+let k_maxOpenNotional = "k_maxOpenNotional"
4551
4652 let k_lastDataStr = "k_lastDataStr"
4753
4854 let k_lastMinuteId = "k_lastMinuteId"
4955
5056 let k_twapDataLastCumulativePrice = "k_twapDataLastCumulativePrice"
5157
5258 let k_twapDataLastPrice = "k_twapDataLastPrice"
5359
5460 let k_twapDataPreviousMinuteId = "k_twapDataPreviousMinuteId"
5561
5662 let k_latestLongCumulativePremiumFraction = "k_latestLongPremiumFraction"
5763
5864 let k_latestShortCumulativePremiumFraction = "k_latestShortPremiumFraction"
5965
6066 let k_nextFundingBlock = "k_nextFundingBlockMinTimestamp"
6167
6268 let k_longFundingRate = "k_longFundingRate"
6369
6470 let k_shortFundingRate = "k_shortFundingRate"
6571
6672 let k_quoteAssetReserve = "k_qtAstR"
6773
6874 let k_baseAssetReserve = "k_bsAstR"
6975
76+let k_quoteAssetWeight = "k_qtAstW"
77+
78+let k_baseAssetWeight = "k_bsAstW"
79+
7080 let k_totalPositionSize = "k_totalPositionSize"
7181
7282 let k_totalLongPositionSize = "k_totalLongPositionSize"
7383
7484 let k_totalShortPositionSize = "k_totalShortPositionSize"
7585
76-let k_cumulativeNotional = "k_cumulativeNotional"
86+let k_openInterestNotional = "k_openInterestNotional"
7787
78-let k_openInterestNotional = "k_openInterestNotional"
88+let k_openInterestShort = "k_openInterestShort"
89+
90+let k_openInterestLong = "k_openInterestLong"
7991
8092 let k_coordinatorAddress = "k_coordinatorAddress"
8193
82-let k_insurance_address = "k_insurance_address"
94+let k_vault_address = "k_vault_address"
8395
8496 let k_admin_address = "k_admin_address"
8597
8698 let k_admin_public_key = "k_admin_public_key"
8799
88100 let k_quote_asset = "k_quote_asset"
89101
90102 let k_quote_staking = "k_quote_staking"
91103
92104 let k_staking_address = "k_staking_address"
93105
94106 let k_miner_address = "k_miner_address"
95107
96108 let k_orders_address = "k_orders_address"
97109
98110 let k_referral_address = "k_referral_address"
99-
100-let k_manager_address = "k_manager_address"
101111
102112 let k_collateral_address = "k_collateral_address"
103113
104114 let k_exchange_address = "k_exchange_address"
105115
106116 let k_nft_manager_address = "k_nft_manager_address"
107117
108118 let k_trader_market_asset_collateral = "k_trader_market_asset_collateral"
109119
110120 func toCompositeKey (_key,_address) = ((_key + "_") + _address)
111121
112122
113123 func coordinator () = valueOrErrorMessage(addressFromString(getStringValue(this, k_coordinatorAddress)), "Coordinator not set")
114124
115125
116126 func adminAddress () = addressFromString(getStringValue(coordinator(), k_admin_address))
117127
118128
119129 func adminPublicKey () = fromBase58String(getStringValue(coordinator(), k_admin_public_key))
120130
121131
122132 func quoteAsset () = fromBase58String(getStringValue(coordinator(), k_quote_asset))
123133
124134
125135 func quoteAssetStaking () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_quote_staking)), "Quote asset staking not set")
126136
127137
128138 func stakingAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_staking_address)), "Staking not set")
129139
130140
131-func insuranceAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_insurance_address)), "Insurance not set")
141+func vaultAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_vault_address)), "Vault not set")
132142
133143
134144 func minerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_miner_address)), "Miner not set")
135145
136146
137147 func ordersAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_orders_address)), "Orders not set")
138148
139149
140150 func referralAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_referral_address)), "Referral not set")
141-
142-
143-func managerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_manager_address)), "Manager not set")
144151
145152
146153 func nftManagerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_nft_manager_address)), "NFT Manager not set")
147154
148155
149156 func collateralAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_collateral_address)), "Collateral Manager not set")
150157
151158
152159 func swapAddress () = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(coordinator(), k_exchange_address), "No swap address")), "Invalid swap address")
153160
154161
155162 let k_whitelist_asset = "k_whitelist_asset"
156163
157164 func isWhitelistAsset (_assetId) = valueOrElse(getBoolean(collateralAddress(), toCompositeKey(k_whitelist_asset, _assetId)), false)
158165
159166
160167 let k_token_param = "k_token_param"
161168
162169 let k_token_type = "k_token_type"
163170
164171 let FEE_REDUCTION_TOKEN_TYPE = "fee_reduction"
165172
166173 let DIR_LONG = 1
167174
168175 let DIR_SHORT = 2
169176
170177 let TWAP_INTERVAL = 15
171178
172179 let ORACLE_INTERVAL = 15
173180
174181 let SECONDS = 1000
175182
183+let DECIMAL_NUMBERS = 6
184+
176185 let DECIMAL_UNIT = (1 * (((((10 * 10) * 10) * 10) * 10) * 10))
177186
178187 let ONE_DAY = (86400 * DECIMAL_UNIT)
179188
180189 let ALL_FEES = 100
181190
182191 let PNL_OPTION_SPOT = 1
183192
184193 let PNL_OPTION_ORACLE = 2
185194
186195 func s (_x) = (toString(_x) + ",")
187196
188197
189198 func divd (_x,_y) = fraction(_x, DECIMAL_UNIT, _y, HALFEVEN)
190199
191200
192201 func muld (_x,_y) = fraction(_x, _y, DECIMAL_UNIT, HALFEVEN)
202+
203+
204+func sqrtd (_x) = sqrt(_x, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN)
205+
206+
207+func powd (_x,_y) = pow(_x, DECIMAL_NUMBERS, _y, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN)
208+
209+
210+func bdivd (_x,_y) = fraction(_x, toBigInt(DECIMAL_UNIT), _y, HALFEVEN)
211+
212+
213+func bmuld (_x,_y) = fraction(_x, _y, toBigInt(DECIMAL_UNIT), HALFEVEN)
214+
215+
216+func bsqrtd (_x) = sqrtBigInt(_x, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN)
217+
218+
219+func bpowd (_x,_y) = pow(_x, DECIMAL_NUMBERS, _y, DECIMAL_NUMBERS, DECIMAL_NUMBERS, HALFEVEN)
193220
194221
195222 func abs (_x) = if ((_x > 0))
196223 then _x
197224 else -(_x)
198225
199226
200227 func vmax (_x,_y) = if ((_x >= _y))
201228 then _x
202229 else _y
203230
204231
205232 func listToStr (_list) = {
206233 func _join (accumulator,val) = ((accumulator + val) + ",")
207234
208235 let newListStr = {
209236 let $l = _list
210237 let $s = size($l)
211238 let $acc0 = ""
212239 func $f0_1 ($a,$i) = if (($i >= $s))
213240 then $a
214241 else _join($a, $l[$i])
215242
216243 func $f0_2 ($a,$i) = if (($i >= $s))
217244 then $a
218245 else throw("List size exceeds 20")
219246
220247 $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)
221248 }
222249 let newListStrU = dropRight(newListStr, 1)
223250 let newListStrR = if ((take(newListStrU, 1) == ","))
224251 then drop(newListStrU, 1)
225252 else newListStrU
226253 newListStrR
227254 }
228255
229256
230257 func strToList (_str) = split(_str, ",")
231258
232259
233260 func pushToQueue (_list,_maxSize,_value) = if ((size(_list) > _maxSize))
234261 then (removeByIndex(_list, 0) :+ _value)
235262 else (_list :+ _value)
236263
237264
238265 func int (k) = valueOrErrorMessage(getInteger(this, k), ("no value for " + k))
239266
240267
268+func intOr (k,def) = valueOrElse(getInteger(this, k), def)
269+
270+
241271 func strA (_address,_key) = {
242272 let val = valueOrErrorMessage(getString(_address, _key), ("No value for key " + _key))
243273 val
244274 }
245275
246276
247277 func intA (_address,_key) = {
248278 let val = valueOrErrorMessage(getInteger(_address, _key), ("No value for key " + _key))
249279 val
250280 }
251281
252282
253283 func cbalance () = int(k_balance)
254284
255285
256286 func fee () = int(k_fee)
257287
258288
259289 func initMarginRatio () = int(k_initMarginRatio)
260290
261291
262292 func qtAstR () = int(k_quoteAssetReserve)
263293
264294
265295 func bsAstR () = int(k_baseAssetReserve)
266296
267297
298+func qtAstW () = intOr(k_quoteAssetWeight, DECIMAL_UNIT)
299+
300+
301+func bsAstW () = intOr(k_baseAssetWeight, DECIMAL_UNIT)
302+
303+
268304 func totalPositionSize () = int(k_totalPositionSize)
269305
270306
271-func cumulativeNotional () = int(k_cumulativeNotional)
307+func openInterestNotional () = int(k_openInterestNotional)
272308
273309
274-func openInterestNotional () = int(k_openInterestNotional)
310+func openInterestShort () = int(k_openInterestShort)
311+
312+
313+func openInterestLong () = int(k_openInterestLong)
275314
276315
277316 func nextFundingBlockTimestamp () = int(k_nextFundingBlock)
278317
279318
280319 func fundingPeriodRaw () = int(k_fundingPeriod)
281320
282321
283322 func fundingPeriodDecimal () = (fundingPeriodRaw() * DECIMAL_UNIT)
284323
285324
286325 func fundingPeriodSeconds () = (fundingPeriodRaw() * SECONDS)
287326
288327
289328 func maintenanceMarginRatio () = int(k_maintenanceMarginRatio)
290329
291330
292331 func liquidationFeeRatio () = int(k_liquidationFeeRatio)
293332
294333
295334 func partialLiquidationRatio () = int(k_partialLiquidationRatio)
296335
297336
298337 func spreadLimit () = int(k_spreadLimit)
299338
300339
301340 func maxPriceImpact () = int(k_maxPriceImpact)
302341
303342
304343 func maxPriceSpread () = int(k_maxPriceSpread)
305344
306345
346+func maxOpenNotional () = int(k_maxOpenNotional)
347+
348+
307349 func latestLongCumulativePremiumFraction () = int(k_latestLongCumulativePremiumFraction)
308350
309351
310352 func latestShortCumulativePremiumFraction () = int(k_latestShortCumulativePremiumFraction)
311353
312354
313355 func totalShortPositionSize () = int(k_totalShortPositionSize)
314356
315357
316358 func totalLongPositionSize () = int(k_totalLongPositionSize)
359+
360+
361+func lastSequence () = intOr(k_sequence, 0)
317362
318363
319364 func getActualCaller (i) = valueOrElse(getString(ordersAddress(), "k_sender"), toString(i.caller))
320365
321366
322367 func requireMoreMarginRatio (_marginRatio,_baseMarginRatio,_largerThanOrEqualTo) = {
323368 let remainingMarginRatio = (_marginRatio - _baseMarginRatio)
324369 if (if (_largerThanOrEqualTo)
325370 then (0 > remainingMarginRatio)
326371 else false)
327372 then throw("Invalid margin")
328373 else if (if (!(_largerThanOrEqualTo))
329374 then (remainingMarginRatio >= 0)
330375 else false)
331376 then throw("Invalid margin")
332377 else true
333378 }
334379
335380
336381 func latestCumulativePremiumFraction (_positionSize) = if ((_positionSize == 0))
337382 then throw("Should not be called with _positionSize == 0")
338383 else if ((_positionSize > 0))
339384 then latestLongCumulativePremiumFraction()
340385 else latestShortCumulativePremiumFraction()
341386
342387
343388 func getPosition (_trader) = {
344389 let positionSizeOpt = getInteger(this, toCompositeKey(k_positionSize, _trader))
345390 match positionSizeOpt {
346391 case positionSize: Int =>
347392 $Tuple4(positionSize, getIntegerValue(this, toCompositeKey(k_positionMargin, _trader)), getIntegerValue(this, toCompositeKey(k_positionOpenNotional, _trader)), getIntegerValue(this, toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _trader)))
348393 case _ =>
349394 $Tuple4(0, 0, 0, 0)
350395 }
351396 }
352397
353398
354399 func getPositionAsset (_trader) = {
355400 let positionAssetOpt = getString(this, toCompositeKey(k_positionAsset, _trader))
356401 match positionAssetOpt {
357402 case positionAsset: String =>
358403 positionAsset
359404 case _ =>
360405 toBase58String(quoteAsset())
361406 }
362407 }
363408
364409
365410 func requireOpenPosition (_trader) = if ((getPosition(_trader)._1 == 0))
366411 then throw("No open position")
367412 else true
368413
369414
370415 func initialized () = valueOrElse(getBoolean(this, k_initialized), false)
371416
372417
373418 func paused () = valueOrElse(getBoolean(this, k_paused), false)
374419
375420
421+func closeOnly () = valueOrElse(getBoolean(this, k_closeOnly), false)
422+
423+
376424 func updateReserve (_isAdd,_quoteAssetAmount,_baseAssetAmount) = if (_isAdd)
377425 then {
378426 let newBase = (bsAstR() - _baseAssetAmount)
379427 if ((0 >= newBase))
380428 then throw("Tx lead to base asset reserve <= 0, revert")
381- else $Tuple4((qtAstR() + _quoteAssetAmount), newBase, (totalPositionSize() + _baseAssetAmount), (cumulativeNotional() + _quoteAssetAmount))
429+ else $Tuple3((qtAstR() + _quoteAssetAmount), newBase, (totalPositionSize() + _baseAssetAmount))
382430 }
383431 else {
384432 let newQuote = (qtAstR() - _quoteAssetAmount)
385433 if ((0 >= newQuote))
386434 then throw("Tx lead to base quote reserve <= 0, revert")
387- else $Tuple4(newQuote, (bsAstR() + _baseAssetAmount), (totalPositionSize() - _baseAssetAmount), (cumulativeNotional() - _quoteAssetAmount))
435+ else $Tuple3(newQuote, (bsAstR() + _baseAssetAmount), (totalPositionSize() - _baseAssetAmount))
388436 }
437+
438+
439+func calcInvariant (_qtAstR,_qtAstW,_bsAstR,_bsAstW) = {
440+ let bqtAstR = toBigInt(_qtAstR)
441+ let bqtAstW = toBigInt(_qtAstW)
442+ let bbsAstR = toBigInt(_bsAstR)
443+ let bbsAstW = toBigInt(_bsAstW)
444+ bmuld(bmuld(bqtAstR, bqtAstW), bmuld(bbsAstR, bbsAstW))
445+ }
389446
390447
391448 func swapInput (_isAdd,_quoteAssetAmount) = {
392449 let _qtAstR = qtAstR()
393450 let _bsAstR = bsAstR()
394- let k = muld(_qtAstR, _bsAstR)
451+ let _qtAstW = qtAstW()
452+ let _bsAstW = bsAstW()
453+ let k = calcInvariant(_qtAstR, _qtAstW, _bsAstR, _bsAstW)
395454 let quoteAssetReserveAfter = if (_isAdd)
396455 then (_qtAstR + _quoteAssetAmount)
397456 else (_qtAstR - _quoteAssetAmount)
398- let baseAssetReserveAfter = divd(k, quoteAssetReserveAfter)
399- let amountBaseAssetBoughtAbs = abs((baseAssetReserveAfter - _bsAstR))
457+ let baseAssetReserveAfter = toInt(bdivd(k, toBigInt(muld(quoteAssetReserveAfter, _qtAstW))))
458+ let amountBaseAssetBoughtAbs = divd(abs((baseAssetReserveAfter - _bsAstR)), _qtAstW)
400459 let amountBaseAssetBought = if (_isAdd)
401460 then amountBaseAssetBoughtAbs
402461 else -(amountBaseAssetBoughtAbs)
403- let $t01497415167 = updateReserve(_isAdd, _quoteAssetAmount, amountBaseAssetBoughtAbs)
404- let quoteAssetReserveAfter1 = $t01497415167._1
405- let baseAssetReserveAfter1 = $t01497415167._2
406- let totalPositionSizeAfter1 = $t01497415167._3
407- let cumulativeNotionalAfter1 = $t01497415167._4
408- let priceBefore = divd(_qtAstR, _bsAstR)
462+ let $t01665516818 = updateReserve(_isAdd, _quoteAssetAmount, amountBaseAssetBoughtAbs)
463+ let quoteAssetReserveAfter1 = $t01665516818._1
464+ let baseAssetReserveAfter1 = $t01665516818._2
465+ let totalPositionSizeAfter1 = $t01665516818._3
466+ let priceBefore = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW))
409467 let marketPrice = divd(_quoteAssetAmount, amountBaseAssetBoughtAbs)
410468 let priceDiff = abs((priceBefore - marketPrice))
411469 let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff)))
412470 let maxPriceImpactValue = maxPriceImpact()
413471 if ((priceImpact > maxPriceImpactValue))
414472 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)))
415- else $Tuple5(amountBaseAssetBought, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, cumulativeNotionalAfter1)
473+ else $Tuple4(amountBaseAssetBought, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1)
416474 }
417475
418476
419477 func calcRemainMarginWithFundingPayment (_oldPositionSize,_oldPositionMargin,_oldPositionCumulativePremiumFraction,_marginDelta) = {
420478 let fundingPayment = if ((_oldPositionSize != 0))
421479 then {
422480 let _latestCumulativePremiumFraction = latestCumulativePremiumFraction(_oldPositionSize)
423481 muld((_latestCumulativePremiumFraction - _oldPositionCumulativePremiumFraction), _oldPositionSize)
424482 }
425483 else 0
426484 let signedMargin = ((_marginDelta - fundingPayment) + _oldPositionMargin)
427- let $t01665816785 = if ((0 > signedMargin))
485+ let $t01830518432 = if ((0 > signedMargin))
428486 then $Tuple2(0, abs(signedMargin))
429487 else $Tuple2(abs(signedMargin), 0)
430- let remainMargin = $t01665816785._1
431- let badDebt = $t01665816785._2
488+ let remainMargin = $t01830518432._1
489+ let badDebt = $t01830518432._2
432490 $Tuple3(remainMargin, badDebt, fundingPayment)
433491 }
434492
435493
436-func swapOutputWithReserves (_isAdd,_baseAssetAmount,_checkMaxPriceImpact,_quoteAssetReserve,_baseAssetReserve) = {
437- let priceBefore = divd(_quoteAssetReserve, _baseAssetReserve)
494+func swapOutputWithReserves (_isAdd,_baseAssetAmount,_checkMaxPriceImpact,_quoteAssetReserve,_quoteAssetWeight,_baseAssetReserve,_baseAssetWeight) = {
495+ let priceBefore = divd(muld(_quoteAssetReserve, _quoteAssetWeight), muld(_baseAssetReserve, _baseAssetWeight))
438496 if ((_baseAssetAmount == 0))
439497 then throw("Invalid base asset amount")
440498 else {
441- let k = muld(_quoteAssetReserve, _baseAssetReserve)
499+ let k = calcInvariant(_quoteAssetReserve, _quoteAssetWeight, _baseAssetReserve, _baseAssetWeight)
442500 let baseAssetPoolAmountAfter = if (_isAdd)
443501 then (_baseAssetReserve + _baseAssetAmount)
444502 else (_baseAssetReserve - _baseAssetAmount)
445- let quoteAssetAfter = divd(k, baseAssetPoolAmountAfter)
446- let quoteAssetSold = abs((quoteAssetAfter - _quoteAssetReserve))
503+ let quoteAssetAfter = toInt(bdivd(k, toBigInt(muld(baseAssetPoolAmountAfter, _baseAssetWeight))))
504+ let quoteAssetSold = abs((quoteAssetAfter - muld(_quoteAssetReserve, _quoteAssetWeight)))
447505 let maxPriceImpactValue = maxPriceImpact()
448- let $t01776217955 = updateReserve(!(_isAdd), quoteAssetSold, _baseAssetAmount)
449- let quoteAssetReserveAfter1 = $t01776217955._1
450- let baseAssetReserveAfter1 = $t01776217955._2
451- let totalPositionSizeAfter1 = $t01776217955._3
452- let cumulativeNotionalAfter1 = $t01776217955._4
506+ let $t01962019781 = updateReserve(!(_isAdd), quoteAssetSold, _baseAssetAmount)
507+ let quoteAssetReserveAfter1 = $t01962019781._1
508+ let baseAssetReserveAfter1 = $t01962019781._2
509+ let totalPositionSizeAfter1 = $t01962019781._3
453510 let marketPrice = divd(quoteAssetSold, _baseAssetAmount)
454511 let priceDiff = abs((priceBefore - marketPrice))
455512 let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff)))
456513 if (if ((priceImpact > maxPriceImpactValue))
457514 then _checkMaxPriceImpact
458515 else false)
459516 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)))
460- else $Tuple8(quoteAssetSold, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, cumulativeNotionalAfter1, (totalLongPositionSize() - (if (_isAdd)
517+ else $Tuple7(quoteAssetSold, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, (totalLongPositionSize() - (if (_isAdd)
461518 then abs(_baseAssetAmount)
462519 else 0)), (totalShortPositionSize() - (if (!(_isAdd))
463520 then abs(_baseAssetAmount)
464521 else 0)), priceImpact)
465522 }
466523 }
467524
468525
469-func swapOutput (_isAdd,_baseAssetAmount,_checkMaxPriceImpact) = swapOutputWithReserves(_isAdd, _baseAssetAmount, _checkMaxPriceImpact, qtAstR(), bsAstR())
526+func swapOutput (_isAdd,_baseAssetAmount,_checkMaxPriceImpact) = swapOutputWithReserves(_isAdd, _baseAssetAmount, _checkMaxPriceImpact, qtAstR(), qtAstW(), bsAstR(), bsAstW())
470527
471528
472529 func getOracleTwapPrice () = {
473530 let oracle = valueOrErrorMessage(addressFromString(getStringValue(this, k_ora)), "")
474531 let priceKey = getStringValue(this, k_ora_key)
475532 let blockKey = getStringValue(this, k_ora_block_key)
476533 let lastValue = valueOrErrorMessage(getInteger(oracle, priceKey), ((("Can not get oracle price. Oracle: " + toString(oracle)) + " key: ") + priceKey))
477534 lastValue
478535 }
479536
480537
481538 func requireNotOverSpreadLimit (_quoteAssetReserve,_baseAssetReserve) = {
482539 let oraclePrice = getOracleTwapPrice()
483540 let priceAfter = divd(_quoteAssetReserve, _baseAssetReserve)
484541 let averagePrice = divd((oraclePrice + priceAfter), (2 * DECIMAL_UNIT))
485542 let absPriceDiff = divd(abs((oraclePrice - priceAfter)), averagePrice)
486543 if ((absPriceDiff > maxPriceSpread()))
487544 then throw(((("Price spread " + toString(absPriceDiff)) + " > max price spread ") + toString(maxPriceSpread())))
488545 else true
489546 }
490547
491548
549+func requireNotOverMaxOpenNotional (_longOpenNotional,_shortOpenNotional) = {
550+ let _maxOpenNotional = maxOpenNotional()
551+ if ((_longOpenNotional > _maxOpenNotional))
552+ then throw(((("Long open notional " + toString(_longOpenNotional)) + " > max open notional ") + toString(_maxOpenNotional)))
553+ else if ((_shortOpenNotional > _maxOpenNotional))
554+ then throw(((("Short open notional " + toString(_shortOpenNotional)) + " > max open notional ") + toString(_maxOpenNotional)))
555+ else true
556+ }
557+
558+
492559 func getSpotPrice () = {
493560 let _quoteAssetReserve = qtAstR()
494561 let _baseAssetReserve = bsAstR()
495- divd(_quoteAssetReserve, _baseAssetReserve)
562+ let _qtAstW = qtAstW()
563+ let _bsAstW = bsAstW()
564+ divd(muld(_quoteAssetReserve, _qtAstW), muld(_baseAssetReserve, _bsAstW))
496565 }
497566
498567
499568 func isOverFluctuationLimit () = {
500569 let oraclePrice = getOracleTwapPrice()
501570 let currentPrice = getSpotPrice()
502571 (divd(abs((oraclePrice - currentPrice)), oraclePrice) > spreadLimit())
503572 }
504573
505574
506-func getPositionAdjustedOpenNotional (_positionSize,_option,_quoteAssetReserve,_baseAssetReserve) = {
575+func getPositionAdjustedOpenNotional (_positionSize,_option,_quoteAssetReserve,_quoteAssetWeight,_baseAssetReserve,_baseAssetWeight) = {
507576 let positionSizeAbs = abs(_positionSize)
508577 let isShort = (0 > _positionSize)
509578 let positionNotional = if ((_option == PNL_OPTION_SPOT))
510579 then {
511- let $t02117321344 = swapOutputWithReserves(!(isShort), positionSizeAbs, false, _quoteAssetReserve, _baseAssetReserve)
512- let outPositionNotional = $t02117321344._1
513- let x1 = $t02117321344._2
514- let x2 = $t02117321344._3
515- let x3 = $t02117321344._4
580+ let $t02365523875 = swapOutputWithReserves(!(isShort), positionSizeAbs, false, _quoteAssetReserve, _quoteAssetWeight, _baseAssetReserve, _baseAssetWeight)
581+ let outPositionNotional = $t02365523875._1
582+ let x1 = $t02365523875._2
583+ let x2 = $t02365523875._3
584+ let x3 = $t02365523875._4
516585 outPositionNotional
517586 }
518587 else muld(positionSizeAbs, getOracleTwapPrice())
519588 positionNotional
520589 }
521590
522591
523-func getPositionNotionalAndUnrealizedPnlByValues (_positionSize,_positionOpenNotional,_quoteAssetReserve,_baseAssetReserve,_option) = if ((_positionSize == 0))
592+func getPositionNotionalAndUnrealizedPnlByValues (_positionSize,_positionOpenNotional,_quoteAssetReserve,_quoteAssetWeight,_baseAssetReserve,_baseAssetWeight,_option) = if ((_positionSize == 0))
524593 then throw("Invalid position size")
525594 else {
526595 let isShort = (0 > _positionSize)
527- let positionNotional = getPositionAdjustedOpenNotional(_positionSize, _option, _quoteAssetReserve, _baseAssetReserve)
596+ let positionNotional = getPositionAdjustedOpenNotional(_positionSize, _option, _quoteAssetReserve, _quoteAssetWeight, _baseAssetReserve, _baseAssetWeight)
528597 let unrealizedPnl = if (isShort)
529598 then (_positionOpenNotional - positionNotional)
530599 else (positionNotional - _positionOpenNotional)
531600 $Tuple2(positionNotional, unrealizedPnl)
532601 }
533602
534603
535604 func getPositionNotionalAndUnrealizedPnl (_trader,_option) = {
536- let $t02266122789 = getPosition(_trader)
537- let positionSize = $t02266122789._1
538- let positionMargin = $t02266122789._2
539- let positionOpenNotional = $t02266122789._3
540- let positionLstUpdCPF = $t02266122789._4
541- getPositionNotionalAndUnrealizedPnlByValues(positionSize, positionOpenNotional, qtAstR(), bsAstR(), _option)
605+ let $t02530025428 = getPosition(_trader)
606+ let positionSize = $t02530025428._1
607+ let positionMargin = $t02530025428._2
608+ let positionOpenNotional = $t02530025428._3
609+ let positionLstUpdCPF = $t02530025428._4
610+ getPositionNotionalAndUnrealizedPnlByValues(positionSize, positionOpenNotional, qtAstR(), qtAstW(), bsAstR(), bsAstW(), _option)
542611 }
543612
544613
545614 func calcMarginRatio (_remainMargin,_badDebt,_positionNotional) = divd((_remainMargin - _badDebt), _positionNotional)
546615
547616
548617 func getMarginRatioByOption (_trader,_option) = {
549- let $t02327023381 = getPosition(_trader)
550- let positionSize = $t02327023381._1
551- let positionMargin = $t02327023381._2
552- let pon = $t02327023381._3
553- let positionLstUpdCPF = $t02327023381._4
554- let $t02338723480 = getPositionNotionalAndUnrealizedPnl(_trader, _option)
555- let positionNotional = $t02338723480._1
556- let unrealizedPnl = $t02338723480._2
557- let $t02348523651 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl)
558- let remainMargin = $t02348523651._1
559- let badDebt = $t02348523651._2
618+ let $t02594126052 = getPosition(_trader)
619+ let positionSize = $t02594126052._1
620+ let positionMargin = $t02594126052._2
621+ let pon = $t02594126052._3
622+ let positionLstUpdCPF = $t02594126052._4
623+ let $t02605826151 = getPositionNotionalAndUnrealizedPnl(_trader, _option)
624+ let positionNotional = $t02605826151._1
625+ let unrealizedPnl = $t02605826151._2
626+ let $t02615626322 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl)
627+ let remainMargin = $t02615626322._1
628+ let badDebt = $t02615626322._2
560629 calcMarginRatio(remainMargin, badDebt, positionNotional)
561630 }
562631
563632
564633 func getMarginRatio (_trader) = getMarginRatioByOption(_trader, PNL_OPTION_SPOT)
565634
566635
567636 func getPartialLiquidationAmount (_trader,_positionSize) = {
568637 let maximumRatio = vmax(partialLiquidationRatio(), (DECIMAL_UNIT - divd(getMarginRatio(_trader), maintenanceMarginRatio())))
569638 let maxExchangedPositionSize = muld(abs(_positionSize), maximumRatio)
570639 let swapResult = swapOutput((_positionSize > 0), maxExchangedPositionSize, false)
571640 let maxExchangedQuoteAssetAmount = swapResult._1
572- let priceImpact = swapResult._8
641+ let priceImpact = swapResult._7
573642 if ((maxPriceImpact() > priceImpact))
574643 then maxExchangedQuoteAssetAmount
575644 else {
576645 let exchangedPositionSize = muld(abs(_positionSize), partialLiquidationRatio())
577646 let exchangedQuoteAssetAmount = swapOutput((_positionSize > 0), exchangedPositionSize, false)._1
578647 exchangedQuoteAssetAmount
579648 }
580649 }
581650
582651
583652 func internalClosePosition (_trader,_checkMaxPriceImpact) = {
584- let $t02488425012 = getPosition(_trader)
585- let positionSize = $t02488425012._1
586- let positionMargin = $t02488425012._2
587- let positionOpenNotional = $t02488425012._3
588- let positionLstUpdCPF = $t02488425012._4
653+ let $t02756227690 = getPosition(_trader)
654+ let positionSize = $t02756227690._1
655+ let positionMargin = $t02756227690._2
656+ let positionOpenNotional = $t02756227690._3
657+ let positionLstUpdCPF = $t02756227690._4
589658 let unrealizedPnl = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)._2
590- let $t02510725275 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl)
591- let remainMargin = $t02510725275._1
592- let badDebt = $t02510725275._2
659+ let $t02778527953 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl)
660+ let remainMargin = $t02778527953._1
661+ let badDebt = $t02778527953._2
593662 let exchangedPositionSize = -(positionSize)
594663 let realizedPnl = unrealizedPnl
595664 let marginToVault = -(remainMargin)
596- let $t02540225713 = swapOutput((positionSize > 0), abs(positionSize), _checkMaxPriceImpact)
597- let exchangedQuoteAssetAmount = $t02540225713._1
598- let quoteAssetReserveAfter = $t02540225713._2
599- let baseAssetReserveAfter = $t02540225713._3
600- let totalPositionSizeAfter = $t02540225713._4
601- let cumulativeNotionalAfter = $t02540225713._5
602- let totalLongAfter = $t02540225713._6
603- let totalShortAfter = $t02540225713._7
665+ let $t02808028354 = swapOutput((positionSize > 0), abs(positionSize), _checkMaxPriceImpact)
666+ let exchangedQuoteAssetAmount = $t02808028354._1
667+ let quoteAssetReserveAfter = $t02808028354._2
668+ let baseAssetReserveAfter = $t02808028354._3
669+ let totalPositionSizeAfter = $t02808028354._4
670+ let totalLongAfter = $t02808028354._5
671+ let totalShortAfter = $t02808028354._6
604672 let openInterestNotionalAfter = (openInterestNotional() - positionOpenNotional)
605- $Tuple12(exchangedPositionSize, badDebt, realizedPnl, marginToVault, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, exchangedQuoteAssetAmount, totalLongAfter, totalShortAfter)
673+ $Tuple13(exchangedPositionSize, badDebt, realizedPnl, marginToVault, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, exchangedQuoteAssetAmount, totalLongAfter, totalShortAfter, (openInterestLong() - (if ((positionSize > 0))
674+ then positionOpenNotional
675+ else 0)), (openInterestShort() - (if ((0 > positionSize))
676+ then positionOpenNotional
677+ else 0)))
606678 }
607679
608680
609681 func getTwapSpotPrice () = {
610682 let minuteId = ((lastBlock.timestamp / 1000) / 60)
611683 let startMinuteId = (minuteId - TWAP_INTERVAL)
612684 let listStr = valueOrElse(getString(this, k_lastDataStr), "")
613685 let list = split(listStr, ",")
614686 func filterFn (accumulator,next) = if ((startMinuteId >= parseIntValue(next)))
615687 then (accumulator :+ parseIntValue(next))
616688 else accumulator
617689
618690 let listF = {
619691 let $l = list
620692 let $s = size($l)
621693 let $acc0 = nil
622694 func $f0_1 ($a,$i) = if (($i >= $s))
623695 then $a
624696 else filterFn($a, $l[$i])
625697
626698 func $f0_2 ($a,$i) = if (($i >= $s))
627699 then $a
628700 else throw("List size exceeds 20")
629701
630702 $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)
631703 }
632704 let maxIndex = if ((size(listF) > 0))
633705 then max(listF)
634706 else parseIntValue(list[0])
635707 let lastMinuteId = valueOrElse(getInteger(this, k_lastMinuteId), 0)
636708 let endLastCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(lastMinuteId))), 0)
637709 let endLastPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(lastMinuteId))), 0)
638710 let nowCumulativePrice = (endLastCumulativePrice + ((minuteId - lastMinuteId) * endLastPrice))
639711 let startLastCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(maxIndex))), 0)
640712 let startLastPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(maxIndex))), 0)
641713 let startCumulativePrice = (startLastCumulativePrice + ((startMinuteId - maxIndex) * startLastPrice))
642714 ((nowCumulativePrice - startCumulativePrice) / TWAP_INTERVAL)
643715 }
644716
645717
646-func getPegAdjustCost (_price) = {
718+func getTerminalAmmState () = {
647719 let _positionSize = totalPositionSize()
648- let direction = (_positionSize > 0)
649- let currentNetMarketValue = swapOutput(direction, abs(_positionSize), false)._1
650- let baseAssetReserve = bsAstR()
651- let newQuoteAssetReserve = muld(baseAssetReserve, _price)
652- let cost = getPositionNotionalAndUnrealizedPnlByValues(_positionSize, currentNetMarketValue, newQuoteAssetReserve, baseAssetReserve, PNL_OPTION_SPOT)._2
653- $Tuple2(newQuoteAssetReserve, cost)
720+ if ((_positionSize == 0))
721+ then $Tuple2(qtAstR(), bsAstR())
722+ else {
723+ let direction = (_positionSize > 0)
724+ let $t03047730656 = swapOutput(direction, abs(_positionSize), false)
725+ let currentNetMarketValue = $t03047730656._1
726+ let terminalQuoteAssetReserve = $t03047730656._2
727+ let terminalBaseAssetReserve = $t03047730656._3
728+ $Tuple2(terminalQuoteAssetReserve, terminalBaseAssetReserve)
729+ }
730+ }
731+
732+
733+func getQuoteAssetWeight (baseAssetReserve,totalPositionSize,quoteAssetReserve,targetPrice) = {
734+ let b = toBigInt(baseAssetReserve)
735+ let sz = toBigInt(totalPositionSize)
736+ let q = toBigInt(quoteAssetReserve)
737+ let p = toBigInt(targetPrice)
738+ let bs2 = bpowd((b + sz), toBigInt((2 * DECIMAL_UNIT)))
739+ let qbs2 = bmuld(q, bs2)
740+ let ps4 = (toBigInt(4) * bmuld(p, sz))
741+ let sqr = bsqrtd(bmuld(qbs2, (q - ps4)))
742+ let bq = bmuld(b, q)
743+ let qs = bmuld(q, sz)
744+ let top = ((-(sqr) + bq) + qs)
745+ let bot = (toBigInt(2) * bmuld(q, sz))
746+ let result = bdivd(top, bot)
747+ toInt(result)
748+ }
749+
750+
751+func getSyncTerminalPrice (_terminalPrice) = {
752+ let _positionSize = totalPositionSize()
753+ if ((_positionSize == 0))
754+ then {
755+ let _qtAstR = qtAstR()
756+ let _bsAstR = bsAstR()
757+ let newQtAstW = divd(muld(_terminalPrice, _bsAstR), _qtAstR)
758+ $Tuple3(newQtAstW, DECIMAL_UNIT, 0)
759+ }
760+ else {
761+ let direction = (_positionSize > 0)
762+ let currentNetMarketValue = swapOutput(direction, abs(_positionSize), false)._1
763+ let _qtAstR = qtAstR()
764+ let _bsAstR = bsAstR()
765+ let newQtAstW = getQuoteAssetWeight(_bsAstR, _positionSize, _qtAstR, _terminalPrice)
766+ let newBsAstW = DECIMAL_UNIT
767+ let marginToVault = getPositionNotionalAndUnrealizedPnlByValues(_positionSize, currentNetMarketValue, _qtAstR, newQtAstW, _bsAstR, newBsAstW, PNL_OPTION_SPOT)._2
768+ $Tuple3(newQtAstW, newBsAstW, marginToVault)
769+ }
654770 }
655771
656772
657773 func getFunding () = {
658774 let underlyingPrice = getOracleTwapPrice()
659775 let spotTwapPrice = getTwapSpotPrice()
660776 let premium = (spotTwapPrice - underlyingPrice)
661777 if (if ((totalShortPositionSize() == 0))
662778 then true
663779 else (totalLongPositionSize() == 0))
664780 then $Tuple2(0, 0)
665781 else if ((0 > premium))
666782 then {
667783 let shortPremiumFraction = divd(muld(premium, fundingPeriodDecimal()), ONE_DAY)
668784 let longPremiumFraction = divd(muld(shortPremiumFraction, totalShortPositionSize()), totalLongPositionSize())
669785 $Tuple2(shortPremiumFraction, longPremiumFraction)
670786 }
671787 else {
672788 let longPremiumFraction = divd(muld(premium, fundingPeriodDecimal()), ONE_DAY)
673789 let shortPremiumFraction = divd(muld(longPremiumFraction, totalLongPositionSize()), totalShortPositionSize())
674790 $Tuple2(shortPremiumFraction, longPremiumFraction)
675791 }
676792 }
677793
678794
679-func getAdjustedFee (i) = {
680- let baseFee = fee()
681- let $t02937629984 = if ((size(i.payments) > 1))
795+func getAdjustedFee (_artifactId,_baseFeeDiscount) = {
796+ let baseFeeRaw = fee()
797+ let baseFee = muld(baseFeeRaw, _baseFeeDiscount)
798+ let $t03375534250 = if ((_artifactId != ""))
682799 then {
683- let artifactId = toBase58String(valueOrErrorMessage(i.payments[1].assetId, "Invalid attached artifact"))
684- let artifactKind = strA(nftManagerAddress(), toCompositeKey(k_token_type, artifactId))
800+ let artifactKind = strA(nftManagerAddress(), toCompositeKey(k_token_type, _artifactId))
685801 if ((artifactKind == FEE_REDUCTION_TOKEN_TYPE))
686802 then {
687- let reduction = intA(nftManagerAddress(), toCompositeKey(k_token_param, artifactId))
803+ let reduction = intA(nftManagerAddress(), toCompositeKey(k_token_param, _artifactId))
688804 let adjustedFee = muld(baseFee, reduction)
689805 $Tuple2(adjustedFee, true)
690806 }
691807 else throw("Invalid attached artifact")
692808 }
693809 else $Tuple2(baseFee, false)
694- let adjustedFee = $t02937629984._1
695- let burnArtifact = $t02937629984._2
810+ let adjustedFee = $t03375534250._1
811+ let burnArtifact = $t03375534250._2
696812 $Tuple2(adjustedFee, burnArtifact)
697813 }
698814
699815
700-func updateSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread) = [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)]
816+func updateSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional) = [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)]
701817
702818
703819 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)]
704820
705821
706822 func updatePositionAsset (_address,_assetId) = [StringEntry(toCompositeKey(k_positionAsset, _address), _assetId)]
823+
824+
825+func incrementPositionSequenceNumber (isNewPosition,_address) = if (isNewPosition)
826+ then {
827+ let currentSequence = lastSequence()
828+[IntegerEntry(toCompositeKey(k_positionSequence, _address), (currentSequence + 1)), IntegerEntry(k_sequence, (currentSequence + 1))]
829+ }
830+ else nil
707831
708832
709833 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)]
710834
711835
712836 func appendTwap (price) = {
713837 let minuteId = ((lastBlock.timestamp / 1000) / 60)
714838 let previousMinuteId = valueOrElse(getInteger(this, k_lastMinuteId), 0)
715839 if ((previousMinuteId > minuteId))
716840 then throw("TWAP out-of-order")
717841 else {
718842 let lastMinuteId = if ((previousMinuteId == 0))
719843 then minuteId
720844 else previousMinuteId
721845 if ((minuteId > previousMinuteId))
722846 then {
723847 let prevCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(previousMinuteId))), 0)
724848 let prevPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(previousMinuteId))), price)
725849 let lastCumulativePrice = (prevCumulativePrice + ((minuteId - lastMinuteId) * prevPrice))
726850 let list = pushToQueue(strToList(valueOrElse(getString(this, k_lastDataStr), "")), TWAP_INTERVAL, toString(minuteId))
727851 [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))]
728852 }
729853 else {
730854 let twapDataPreviousMinuteId = valueOrElse(getInteger(this, toCompositeKey(k_twapDataPreviousMinuteId, toString(minuteId))), 0)
731855 let prevCumulativePrice = valueOrElse(getInteger(this, toCompositeKey(k_twapDataLastCumulativePrice, toString(twapDataPreviousMinuteId))), 0)
732856 let prevPrice = valueOrElse(getInteger(this, toCompositeKey(k_twapDataLastPrice, toString(twapDataPreviousMinuteId))), price)
733857 let lastCumulativePrice = (prevCumulativePrice + ((minuteId - twapDataPreviousMinuteId) * prevPrice))
734858 [IntegerEntry(toCompositeKey(k_twapDataLastCumulativePrice, toString(minuteId)), lastCumulativePrice), IntegerEntry(toCompositeKey(k_twapDataLastPrice, toString(minuteId)), price)]
735859 }
736860 }
737861 }
738862
739863
740864 func updateAmmReserves (_qtAstR,_bsAstR) = [IntegerEntry(k_quoteAssetReserve, _qtAstR), IntegerEntry(k_baseAssetReserve, _bsAstR)]
741865
742866
743-func updateAmm (_qtAstR,_bsAstR,_totalPositionSizeAfter,_cumulativeNotionalAfter,_openInterestNotional,_totalLongPositionSize,_totalShortPositionSize) = if (((_totalLongPositionSize - _totalShortPositionSize) != _totalPositionSizeAfter))
744- then throw(((((("Invalid AMM state data: " + toString(_totalLongPositionSize)) + " + ") + toString(_totalShortPositionSize)) + " != ") + toString(_totalPositionSizeAfter)))
745- else ((updateAmmReserves(_qtAstR, _bsAstR) ++ [IntegerEntry(k_totalPositionSize, _totalPositionSizeAfter), IntegerEntry(k_cumulativeNotional, _cumulativeNotionalAfter), IntegerEntry(k_openInterestNotional, _openInterestNotional), IntegerEntry(k_totalLongPositionSize, _totalLongPositionSize), IntegerEntry(k_totalShortPositionSize, _totalShortPositionSize)]) ++ appendTwap(divd(_qtAstR, _bsAstR)))
867+func updateAmmWeights (_qtAstW,_bsAstW) = [IntegerEntry(k_quoteAssetWeight, _qtAstW), IntegerEntry(k_baseAssetWeight, _bsAstW)]
746868
747869
748-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)), IntegerEntry(toCompositeKey(k_positionClosedDate, _address), lastBlock.timestamp)]
870+func updateAmm (_qtAstR,_bsAstR,_totalPositionSizeAfter,_openInterestNotional,_totalLongPositionSize,_totalShortPositionSize,_totalLongOpenNotional,_totalShortOpenNotional) = {
871+ let _qtAstW = qtAstW()
872+ let _bsAstW = bsAstW()
873+ if (((_totalLongPositionSize - _totalShortPositionSize) != _totalPositionSizeAfter))
874+ then throw(((((("Invalid AMM state data: " + toString(_totalLongPositionSize)) + " + ") + toString(_totalShortPositionSize)) + " != ") + toString(_totalPositionSizeAfter)))
875+ 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))))
876+ }
877+
878+
879+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))]
749880
750881
751882 func withdraw (_address,_amount) = {
752883 let balance = assetBalance(this, quoteAsset())
753884 if ((_amount > balance))
754885 then throw(((("Unable to withdraw " + toString(_amount)) + " from contract balance ") + toString(balance)))
755886 else [ScriptTransfer(_address, _amount, quoteAsset())]
756887 }
757888
758889
759890 func updateBalance (i) = if ((0 > i))
760891 then throw("Balance")
761892 else [IntegerEntry(k_balance, i)]
762893
763894
764895 func transferFee (i) = [ScriptTransfer(stakingAddress(), i, quoteAsset())]
765896
766897
767898 func doBurnArtifact (_burnArtifact,i) = if (_burnArtifact)
768899 then [Burn(valueOrErrorMessage(i.payments[1].assetId, "Invalid artifact"), 1)]
769900 else nil
770901
771902
772903 func isSameAssetOrNoPosition (_trader,_assetId) = {
773904 let oldPositionSize = getPosition(_trader)._1
774905 if ((oldPositionSize == 0))
775906 then true
776907 else (getPositionAsset(_trader) == _assetId)
777908 }
778909
779910
780911 func isSameAsset (_trader,_assetId) = (getPositionAsset(_trader) == _assetId)
781912
782913
783914 func getBorrowedByTraderInMarketKey (_amm,_assetId,_trader) = ((((((k_trader_market_asset_collateral + "_") + _amm) + "_") + _assetId) + "_") + _trader)
784915
785916
786917 func getBorrowedByTrader (_trader) = {
787918 let positionAsset = getPositionAsset(_trader)
788919 if ((positionAsset == toBase58String(quoteAsset())))
789920 then $Tuple2(0, positionAsset)
790921 else {
791922 let key = getBorrowedByTraderInMarketKey(toString(this), positionAsset, _trader)
792923 let borrow = valueOrElse(getInteger(collateralAddress(), key), 0)
793924 $Tuple2(borrow, positionAsset)
794925 }
795926 }
796927
797928
929+func getForTraderWithArtifact (_trader,_artifactId) = {
930+ let doGetFeeDiscount = invoke(minerAddress(), "computeFeeDiscount", [_trader], nil)
931+ if ((doGetFeeDiscount == doGetFeeDiscount))
932+ then {
933+ let feeDiscount = match doGetFeeDiscount {
934+ case x: Int =>
935+ x
936+ case _ =>
937+ throw("Invalid computeFeeDiscount result")
938+ }
939+ let $t04258342657 = getAdjustedFee(_artifactId, feeDiscount)
940+ let adjustedFee = $t04258342657._1
941+ let burnArtifact = $t04258342657._2
942+ $Tuple2(adjustedFee, burnArtifact)
943+ }
944+ else throw("Strict value is not equal to itself.")
945+ }
946+
947+
948+func getArtifactId (i) = {
949+ let artifactId = if ((size(i.payments) > 1))
950+ then toBase58String(valueOrErrorMessage(i.payments[1].assetId, "Invalid artifactId"))
951+ else ""
952+ artifactId
953+ }
954+
955+
798956 @Callable(i)
799957 func pause () = if ((i.caller != adminAddress()))
800- then throw("Invalid togglePause params")
958+ then throw("Invalid pause params")
801959 else [BooleanEntry(k_paused, true)]
802960
803961
804962
805963 @Callable(i)
806964 func unpause () = if ((i.caller != adminAddress()))
807- then throw("Invalid togglePause params")
965+ then throw("Invalid unpause params")
808966 else [BooleanEntry(k_paused, false)]
967+
968+
969+
970+@Callable(i)
971+func setCloseOnly () = if ((i.caller != adminAddress()))
972+ then throw("Invalid setCloseOnly params")
973+ else [BooleanEntry(k_closeOnly, true)]
974+
975+
976+
977+@Callable(i)
978+func unsetCloseOnly () = if ((i.caller != adminAddress()))
979+ then throw("Invalid unsetCloseOnly params")
980+ else [BooleanEntry(k_closeOnly, false)]
809981
810982
811983
812984 @Callable(i)
813985 func addLiquidity (_quoteAssetAmount) = if (if ((i.caller != adminAddress()))
814986 then true
815987 else (0 >= _quoteAssetAmount))
816988 then throw("Invalid addLiquidity params")
817989 else {
818990 let _qtAstR = qtAstR()
819991 let _bsAstR = bsAstR()
820- let price = divd(_qtAstR, _bsAstR)
992+ let _qtAstW = qtAstW()
993+ let _bsAstW = bsAstW()
994+ let price = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW))
821995 let baseAssetAmountToAdd = divd(_quoteAssetAmount, price)
822996 let qtAstRAfter = (_qtAstR + _quoteAssetAmount)
823997 let bsAstRAfter = (_bsAstR + baseAssetAmountToAdd)
824998 updateAmmReserves(qtAstRAfter, bsAstRAfter)
825999 }
8261000
8271001
8281002
8291003 @Callable(i)
8301004 func removeLiquidity (_quoteAssetAmount) = if (if ((i.caller != adminAddress()))
8311005 then true
8321006 else (0 >= _quoteAssetAmount))
8331007 then throw("Invalid removeLiquidity params")
8341008 else {
8351009 let _qtAstR = qtAstR()
8361010 let _bsAstR = bsAstR()
837- let price = divd(_qtAstR, _bsAstR)
1011+ let _qtAstW = qtAstW()
1012+ let _bsAstW = bsAstW()
1013+ let price = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW))
8381014 let baseAssetAmountToRemove = divd(_quoteAssetAmount, price)
8391015 let qtAstRAfter = (_qtAstR - _quoteAssetAmount)
8401016 let bsAstRAfter = (_bsAstR - baseAssetAmountToRemove)
8411017 updateAmmReserves(qtAstRAfter, bsAstRAfter)
8421018 }
8431019
8441020
8451021
8461022 @Callable(i)
847-func changeSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread) = if ((i.caller != adminAddress()))
1023+func changeSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional) = if ((i.caller != adminAddress()))
8481024 then throw("Invalid changeSettings params")
849- else updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread)
1025+ else updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread, _maxOpenNotional)
8501026
8511027
8521028
8531029 @Callable(i)
854-func initialize (_qtAstR,_bsAstR,_fundingPeriod,_initMarginRatio,_mmr,_liquidationFeeRatio,_fee,_oracle,_oracleKey,_coordinator,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread) = if (if (if (if (if (if (if (if (if (if (if (if ((0 >= _qtAstR))
1030+func initialize (_qtAstR,_bsAstR,_fundingPeriod,_initMarginRatio,_mmr,_liquidationFeeRatio,_fee,_oracle,_oracleKey,_coordinator,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread,_maxOpenNotional) = if (if (if (if (if (if (if (if (if (if (if (if (if ((0 >= _qtAstR))
8551031 then true
8561032 else (0 >= _bsAstR))
8571033 then true
8581034 else (0 >= _fundingPeriod))
8591035 then true
8601036 else (0 >= _initMarginRatio))
8611037 then true
8621038 else (0 >= _mmr))
8631039 then true
8641040 else (0 >= _liquidationFeeRatio))
8651041 then true
8661042 else (0 >= _fee))
8671043 then true
8681044 else (0 >= _spreadLimit))
8691045 then true
8701046 else (0 >= _maxPriceImpact))
8711047 then true
8721048 else (0 >= _partialLiquidationRatio))
8731049 then true
8741050 else (0 >= _maxPriceSpread))
8751051 then true
1052+ else (0 >= _maxOpenNotional))
1053+ then true
8761054 else initialized())
8771055 then throw("Invalid initialize parameters")
878- else ((((updateAmm(_qtAstR, _bsAstR, 0, 0, 0, 0, 0) ++ updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread)) ++ 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_coordinatorAddress, _coordinator)])
1056+ else ((((updateAmm(_qtAstR, _bsAstR, 0, 0, 0, 0, 0, 0) ++ updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread, _maxOpenNotional)) ++ 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_coordinatorAddress, _coordinator)])
8791057
8801058
8811059
8821060 @Callable(i)
883-func setInitMarginRatio (_initMarginRatio) = if (if ((0 >= _initMarginRatio))
884- then true
885- else !(initialized()))
886- then throw("Invalid setInitMarginRatio parameters")
887- else updateSettings(_initMarginRatio, maintenanceMarginRatio(), liquidationFeeRatio(), fundingPeriodRaw(), fee(), spreadLimit(), maxPriceImpact(), partialLiquidationRatio(), maxPriceSpread())
888-
889-
890-
891-@Callable(i)
892-func decreasePosition (_amount,_leverage,_minBaseAssetAmount) = if (if (if (if (if ((0 >= _amount))
893- then true
894- else !(initialized()))
895- then true
896- else !(requireMoreMarginRatio(divd(DECIMAL_UNIT, _leverage), initMarginRatio(), true)))
897- then true
898- else !(requireOpenPosition(toString(i.caller))))
899- then true
900- else paused())
901- then throw("Invalid decreasePosition parameters")
902- else {
903- let $t04149241644 = getPosition(toString(i.caller))
904- let oldPositionSize = $t04149241644._1
905- let oldPositionMargin = $t04149241644._2
906- let oldPositionOpenNotional = $t04149241644._3
907- let oldPositionLstUpdCPF = $t04149241644._4
908- let _direction = if ((oldPositionSize > 0))
909- then DIR_SHORT
910- else DIR_LONG
911- let isAdd = (_direction == DIR_LONG)
912- let openNotional = muld(_amount, _leverage)
913- let $t04181741933 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT)
914- let oldPositionNotional = $t04181741933._1
915- let unrealizedPnl = $t04181741933._2
916- let $t04193944488 = if ((oldPositionNotional > openNotional))
917- then {
918- let $t04231642535 = swapInput(isAdd, openNotional)
919- let exchangedPositionSize = $t04231642535._1
920- let quoteAssetReserveAfter = $t04231642535._2
921- let baseAssetReserveAfter = $t04231642535._3
922- let totalPositionSizeAfter = $t04231642535._4
923- let cumulativeNotionalAfter = $t04231642535._5
924- let exchangedPositionSizeAbs = abs(exchangedPositionSize)
925- if (if ((_minBaseAssetAmount != 0))
926- then (_minBaseAssetAmount > exchangedPositionSizeAbs)
927- else false)
928- then throw(((("Too little base asset exchanged, got " + toString(exchangedPositionSizeAbs)) + " expected ") + toString(_minBaseAssetAmount)))
929- else {
930- let realizedPnl = divd(muld(unrealizedPnl, exchangedPositionSizeAbs), abs(oldPositionSize))
931- let $t04297243217 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl)
932- let remainMargin = $t04297243217._1
933- let badDebt = $t04297243217._2
934- let fundingPayment = $t04297243217._3
935- let exchangedQuoteAssetAmount = openNotional
936- let unrealizedPnlAfter = (unrealizedPnl - realizedPnl)
937- let remainOpenNotional = if ((oldPositionSize > 0))
938- then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter)
939- else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount)
940- let newPositionSize = (oldPositionSize + exchangedPositionSize)
941- $Tuple11(newPositionSize, remainMargin, abs(remainOpenNotional), latestCumulativePremiumFraction(newPositionSize), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, (openInterestNotional() - openNotional), (totalLongPositionSize() - (if ((newPositionSize > 0))
942- then abs(exchangedPositionSize)
943- else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize))
944- then abs(exchangedPositionSize)
945- else 0)))
946- }
947- }
948- else throw("Close position first")
949- let newPositionSize = $t04193944488._1
950- let newPositionRemainMargin = $t04193944488._2
951- let newPositionOpenNotional = $t04193944488._3
952- let newPositionLatestCPF = $t04193944488._4
953- let baseAssetReserveAfter = $t04193944488._5
954- let quoteAssetReserveAfter = $t04193944488._6
955- let totalPositionSizeAfter = $t04193944488._7
956- let cumulativeNotionalAfter = $t04193944488._8
957- let openInterestNotionalAfter = $t04193944488._9
958- let totalLongAfter = $t04193944488._10
959- let totalShortAfter = $t04193944488._11
960- let notifyNotional = invoke(minerAddress(), "notifyNotional", [toString(i.caller), newPositionOpenNotional], nil)
961- if ((notifyNotional == notifyNotional))
962- then (updatePosition(toString(i.caller), newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter))
963- else throw("Strict value is not equal to itself.")
964- }
1061+func decreasePosition (_amount,_leverage,_minBaseAssetAmount) = {
1062+ let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
1063+ if ((sync == sync))
1064+ then {
1065+ let _trader = getActualCaller(i)
1066+ if (if (if (if (if ((0 >= _amount))
1067+ then true
1068+ else !(initialized()))
1069+ then true
1070+ else !(requireMoreMarginRatio(divd(DECIMAL_UNIT, _leverage), initMarginRatio(), true)))
1071+ then true
1072+ else !(requireOpenPosition(_trader)))
1073+ then true
1074+ else paused())
1075+ then throw("Invalid decreasePosition parameters")
1076+ else {
1077+ let $t04734747487 = getPosition(_trader)
1078+ let oldPositionSize = $t04734747487._1
1079+ let oldPositionMargin = $t04734747487._2
1080+ let oldPositionOpenNotional = $t04734747487._3
1081+ let oldPositionLstUpdCPF = $t04734747487._4
1082+ let _direction = if ((oldPositionSize > 0))
1083+ then DIR_SHORT
1084+ else DIR_LONG
1085+ let isAdd = (_direction == DIR_LONG)
1086+ let openNotional = muld(_amount, _leverage)
1087+ let $t04766047764 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)
1088+ let oldPositionNotional = $t04766047764._1
1089+ let unrealizedPnl = $t04766047764._2
1090+ let $t04777050428 = if ((oldPositionNotional > openNotional))
1091+ then {
1092+ let $t04818548369 = swapInput(isAdd, openNotional)
1093+ let exchangedPositionSize = $t04818548369._1
1094+ let quoteAssetReserveAfter = $t04818548369._2
1095+ let baseAssetReserveAfter = $t04818548369._3
1096+ let totalPositionSizeAfter = $t04818548369._4
1097+ let exchangedPositionSizeAbs = abs(exchangedPositionSize)
1098+ if (if ((_minBaseAssetAmount != 0))
1099+ then (_minBaseAssetAmount > exchangedPositionSizeAbs)
1100+ else false)
1101+ then throw(((("Too little base asset exchanged, got " + toString(exchangedPositionSizeAbs)) + " expected ") + toString(_minBaseAssetAmount)))
1102+ else {
1103+ let realizedPnl = divd(muld(unrealizedPnl, exchangedPositionSizeAbs), abs(oldPositionSize))
1104+ let $t04880649051 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl)
1105+ let remainMargin = $t04880649051._1
1106+ let badDebt = $t04880649051._2
1107+ let fundingPayment = $t04880649051._3
1108+ let exchangedQuoteAssetAmount = openNotional
1109+ let unrealizedPnlAfter = (unrealizedPnl - realizedPnl)
1110+ let remainOpenNotional = if ((oldPositionSize > 0))
1111+ then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter)
1112+ else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount)
1113+ let newPositionSize = (oldPositionSize + exchangedPositionSize)
1114+ $Tuple12(newPositionSize, remainMargin, abs(remainOpenNotional), latestCumulativePremiumFraction(newPositionSize), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, (openInterestNotional() - openNotional), (totalLongPositionSize() - (if ((newPositionSize > 0))
1115+ then abs(exchangedPositionSize)
1116+ else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize))
1117+ then abs(exchangedPositionSize)
1118+ else 0)), (openInterestLong() - (if ((newPositionSize > 0))
1119+ then openNotional
1120+ else 0)), (openInterestShort() - (if ((0 > newPositionSize))
1121+ then openNotional
1122+ else 0)))
1123+ }
1124+ }
1125+ else throw("Close position first")
1126+ let newPositionSize = $t04777050428._1
1127+ let newPositionRemainMargin = $t04777050428._2
1128+ let newPositionOpenNotional = $t04777050428._3
1129+ let newPositionLatestCPF = $t04777050428._4
1130+ let baseAssetReserveAfter = $t04777050428._5
1131+ let quoteAssetReserveAfter = $t04777050428._6
1132+ let totalPositionSizeAfter = $t04777050428._7
1133+ let openInterestNotionalAfter = $t04777050428._8
1134+ let totalLongAfter = $t04777050428._9
1135+ let totalShortAfter = $t04777050428._10
1136+ let totalLongOpenInterestAfter = $t04777050428._11
1137+ let totalShortOpenInterestAfter = $t04777050428._12
1138+ let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil)
1139+ if ((notifyNotional == notifyNotional))
1140+ then (updatePosition(_trader, newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter))
1141+ else throw("Strict value is not equal to itself.")
1142+ }
1143+ }
1144+ else throw("Strict value is not equal to itself.")
1145+ }
9651146
9661147
9671148
9681149 @Callable(i)
9691150 func increasePosition (_direction,_leverage,_minBaseAssetAmount,_refLink) = {
970- let _trader = toString(i.caller)
971- let _rawAmount = i.payments[0].amount
972- let _assetId = i.payments[0].assetId
973- let _assetIdStr = toBase58String(value(_assetId))
974- let isQuoteAsset = (_assetId == quoteAsset())
975- let isCollateralAsset = isWhitelistAsset(_assetIdStr)
976- if (if (if (if (if (if (if (if ((_direction != DIR_LONG))
977- then (_direction != DIR_SHORT)
978- else false)
979- then true
980- else (0 >= _rawAmount))
981- then true
982- else !(initialized()))
983- then true
984- else if (!(isQuoteAsset))
985- then !(isCollateralAsset)
986- else false)
987- then true
988- else !(isSameAssetOrNoPosition(_trader, _assetIdStr)))
989- then true
990- else !(requireMoreMarginRatio(divd(DECIMAL_UNIT, _leverage), initMarginRatio(), true)))
991- then true
992- else paused())
993- then throw("Invalid increasePosition parameters")
994- else {
995- let baseFee = fee()
996- let $t04585045901 = getAdjustedFee(i)
997- let adjustedFee = $t04585045901._1
998- let burnArtifact = $t04585045901._2
999- let rawFeeAmount = muld(_rawAmount, adjustedFee)
1000- let _amount = (_rawAmount - rawFeeAmount)
1001- let distributeFeeAmount = if (isCollateralAsset)
1002- then {
1003- let doBorrow = invoke(collateralAddress(), "borrow", [_trader], [AttachedPayment(_assetId, _amount)])
1004- if ((doBorrow == doBorrow))
1151+ let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
1152+ if ((sync == sync))
1153+ then {
1154+ let _trader = getActualCaller(i)
1155+ let _rawAmount = i.payments[0].amount
1156+ let _assetId = i.payments[0].assetId
1157+ let _assetIdStr = toBase58String(value(_assetId))
1158+ let isQuoteAsset = (_assetId == quoteAsset())
1159+ let isCollateralAsset = isWhitelistAsset(_assetIdStr)
1160+ if (if (if (if (if (if (if (if (if ((_direction != DIR_LONG))
1161+ then (_direction != DIR_SHORT)
1162+ else false)
1163+ then true
1164+ else (0 >= _rawAmount))
1165+ then true
1166+ else !(initialized()))
1167+ then true
1168+ else if (!(isQuoteAsset))
1169+ then !(isCollateralAsset)
1170+ else false)
1171+ then true
1172+ else !(isSameAssetOrNoPosition(_trader, _assetIdStr)))
1173+ then true
1174+ else !(requireMoreMarginRatio(divd(DECIMAL_UNIT, _leverage), initMarginRatio(), true)))
1175+ then true
1176+ else paused())
1177+ then true
1178+ else closeOnly())
1179+ then throw("Invalid increasePosition parameters")
1180+ else {
1181+ let $t05186651951 = getForTraderWithArtifact(_trader, getArtifactId(i))
1182+ let adjustedFee = $t05186651951._1
1183+ let burnArtifact = $t05186651951._2
1184+ let rawFeeAmount = muld(_rawAmount, adjustedFee)
1185+ let _amount = (_rawAmount - rawFeeAmount)
1186+ let distributeFeeAmount = if (isCollateralAsset)
10051187 then {
1006- let balanceBefore = assetBalance(this, quoteAsset())
1007- if ((balanceBefore == balanceBefore))
1188+ let doBorrow = invoke(collateralAddress(), "borrow", [_trader], [AttachedPayment(_assetId, _amount)])
1189+ if ((doBorrow == doBorrow))
10081190 then {
1009- let doSwap = invoke(swapAddress(), "swap", [toBase58String(quoteAsset()), 0], [AttachedPayment(_assetId, rawFeeAmount)])
1010- if ((doSwap == doSwap))
1191+ let balanceBefore = assetBalance(this, quoteAsset())
1192+ if ((balanceBefore == balanceBefore))
10111193 then {
1012- let balanceAfter = assetBalance(this, quoteAsset())
1013- if ((balanceAfter == balanceAfter))
1194+ let doSwap = invoke(swapAddress(), "swap", [toBase58String(quoteAsset()), 0], [AttachedPayment(_assetId, rawFeeAmount)])
1195+ if ((doSwap == doSwap))
10141196 then {
1015- let exchangedAmount = (balanceAfter - balanceBefore)
1016- if ((exchangedAmount == exchangedAmount))
1017- then exchangedAmount
1197+ let balanceAfter = assetBalance(this, quoteAsset())
1198+ if ((balanceAfter == balanceAfter))
1199+ then {
1200+ let exchangedAmount = (balanceAfter - balanceBefore)
1201+ if ((exchangedAmount == exchangedAmount))
1202+ then exchangedAmount
1203+ else throw("Strict value is not equal to itself.")
1204+ }
1205+ else throw("Strict value is not equal to itself.")
1206+ }
1207+ else throw("Strict value is not equal to itself.")
1208+ }
1209+ else throw("Strict value is not equal to itself.")
1210+ }
1211+ else throw("Strict value is not equal to itself.")
1212+ }
1213+ else rawFeeAmount
1214+ if ((distributeFeeAmount == distributeFeeAmount))
1215+ then {
1216+ let referrerFeeAny = invoke(referralAddress(), "acceptPaymentWithLink", [_trader, _refLink], [AttachedPayment(quoteAsset(), distributeFeeAmount)])
1217+ if ((referrerFeeAny == referrerFeeAny))
1218+ then {
1219+ let referrerFee = match referrerFeeAny {
1220+ case x: Int =>
1221+ x
1222+ case _ =>
1223+ throw("Invalid referrerFee")
1224+ }
1225+ let feeAmount = (distributeFeeAmount - referrerFee)
1226+ let $t05326753407 = getPosition(_trader)
1227+ let oldPositionSize = $t05326753407._1
1228+ let oldPositionMargin = $t05326753407._2
1229+ let oldPositionOpenNotional = $t05326753407._3
1230+ let oldPositionLstUpdCPF = $t05326753407._4
1231+ let isNewPosition = (oldPositionSize == 0)
1232+ let isSameDirection = if ((oldPositionSize > 0))
1233+ then (_direction == DIR_LONG)
1234+ else (_direction == DIR_SHORT)
1235+ let expandExisting = if (!(isNewPosition))
1236+ then isSameDirection
1237+ else false
1238+ let isAdd = (_direction == DIR_LONG)
1239+ let $t05369656737 = if (if (isNewPosition)
1240+ then true
1241+ else expandExisting)
1242+ then {
1243+ let openNotional = muld(_amount, _leverage)
1244+ let $t05415854331 = swapInput(isAdd, openNotional)
1245+ let amountBaseAssetBought = $t05415854331._1
1246+ let quoteAssetReserveAfter = $t05415854331._2
1247+ let baseAssetReserveAfter = $t05415854331._3
1248+ let totalPositionSizeAfter = $t05415854331._4
1249+ if (if ((_minBaseAssetAmount != 0))
1250+ then (_minBaseAssetAmount > abs(amountBaseAssetBought))
1251+ else false)
1252+ then throw(((("Limit error: " + toString(abs(amountBaseAssetBought))) + " < ") + toString(_minBaseAssetAmount)))
1253+ else {
1254+ let newPositionSize = (oldPositionSize + amountBaseAssetBought)
1255+ let totalLongOpenInterestAfter = (openInterestLong() + (if ((newPositionSize > 0))
1256+ then openNotional
1257+ else 0))
1258+ let totalShortOpenInterestAfter = (openInterestShort() + (if ((0 > newPositionSize))
1259+ then openNotional
1260+ else 0))
1261+ let increaseMarginRequirement = divd(openNotional, _leverage)
1262+ let $t05493955178 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, increaseMarginRequirement)
1263+ let remainMargin = $t05493955178._1
1264+ let x1 = $t05493955178._2
1265+ let x2 = $t05493955178._3
1266+ if (!(requireNotOverSpreadLimit(quoteAssetReserveAfter, baseAssetReserveAfter)))
1267+ then throw("Over max spread limit")
1268+ else if (!(requireNotOverMaxOpenNotional(totalLongOpenInterestAfter, totalShortOpenInterestAfter)))
1269+ then throw("Over max open notional")
1270+ else $Tuple12(newPositionSize, remainMargin, (oldPositionOpenNotional + openNotional), latestCumulativePremiumFraction(newPositionSize), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, (openInterestNotional() + openNotional), (totalLongPositionSize() + (if ((newPositionSize > 0))
1271+ then abs(amountBaseAssetBought)
1272+ else 0)), (totalShortPositionSize() + (if ((0 > newPositionSize))
1273+ then abs(amountBaseAssetBought)
1274+ else 0)), totalLongOpenInterestAfter, totalShortOpenInterestAfter)
1275+ }
1276+ }
1277+ else {
1278+ let openNotional = muld(_amount, _leverage)
1279+ let $t05643756553 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT)
1280+ let oldPositionNotional = $t05643756553._1
1281+ let unrealizedPnl = $t05643756553._2
1282+ if ((oldPositionNotional > openNotional))
1283+ then throw("Use decreasePosition to decrease position size")
1284+ else throw("Close position first")
1285+ }
1286+ let newPositionSize = $t05369656737._1
1287+ let newPositionRemainMargin = $t05369656737._2
1288+ let newPositionOpenNotional = $t05369656737._3
1289+ let newPositionLatestCPF = $t05369656737._4
1290+ let baseAssetReserveAfter = $t05369656737._5
1291+ let quoteAssetReserveAfter = $t05369656737._6
1292+ let totalPositionSizeAfter = $t05369656737._7
1293+ let openInterestNotionalAfter = $t05369656737._8
1294+ let totalLongAfter = $t05369656737._9
1295+ let totalShortAfter = $t05369656737._10
1296+ let totalLongOpenInterestAfter = $t05369656737._11
1297+ let totalShortOpenInterestAfter = $t05369656737._12
1298+ let feeToStakers = (feeAmount / 2)
1299+ let feeToInsurance = (feeAmount - feeToStakers)
1300+ let stake = invoke(vaultAddress(), "addLocked", nil, [AttachedPayment(quoteAsset(), _amount)])
1301+ if ((stake == stake))
1302+ then {
1303+ let depositInsurance = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
1304+ if ((depositInsurance == depositInsurance))
1305+ then {
1306+ let notifyFee = invoke(minerAddress(), "notifyFees", [_trader, feeAmount], nil)
1307+ if ((notifyFee == notifyFee))
1308+ then {
1309+ let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil)
1310+ if ((notifyNotional == notifyNotional))
1311+ then ((((((updatePosition(_trader, newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF) ++ incrementPositionSequenceNumber(isNewPosition, _trader)) ++ updatePositionAsset(_trader, _assetIdStr)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) ++ doBurnArtifact(burnArtifact, i))
1312+ else throw("Strict value is not equal to itself.")
1313+ }
10181314 else throw("Strict value is not equal to itself.")
10191315 }
10201316 else throw("Strict value is not equal to itself.")
10211317 }
10221318 else throw("Strict value is not equal to itself.")
10231319 }
10241320 else throw("Strict value is not equal to itself.")
10251321 }
10261322 else throw("Strict value is not equal to itself.")
10271323 }
1028- else rawFeeAmount
1029- if ((distributeFeeAmount == distributeFeeAmount))
1030- then {
1031- let referrerFeeAny = invoke(referralAddress(), "acceptPaymentWithLink", [_trader, _refLink], [AttachedPayment(quoteAsset(), distributeFeeAmount)])
1032- if ((referrerFeeAny == referrerFeeAny))
1324+ }
1325+ else throw("Strict value is not equal to itself.")
1326+ }
1327+
1328+
1329+
1330+@Callable(i)
1331+func addMargin () = {
1332+ let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
1333+ if ((sync == sync))
1334+ then {
1335+ let _trader = toString(i.caller)
1336+ let _rawAmount = i.payments[0].amount
1337+ let _assetId = i.payments[0].assetId
1338+ let _assetIdStr = toBase58String(value(_assetId))
1339+ let isQuoteAsset = (_assetId == quoteAsset())
1340+ let isCollateralAsset = isWhitelistAsset(_assetIdStr)
1341+ if (if (if (if (if (if (if (!(isQuoteAsset))
1342+ then !(isCollateralAsset)
1343+ else false)
1344+ then true
1345+ else !(requireOpenPosition(toString(i.caller))))
1346+ then true
1347+ else !(isSameAsset(_trader, _assetIdStr)))
1348+ then true
1349+ else !(initialized()))
1350+ then true
1351+ else paused())
1352+ then true
1353+ else closeOnly())
1354+ then throw("Invalid addMargin parameters")
1355+ else {
1356+ let $t05867958764 = getForTraderWithArtifact(_trader, getArtifactId(i))
1357+ let adjustedFee = $t05867958764._1
1358+ let burnArtifact = $t05867958764._2
1359+ let rawFeeAmount = muld(_rawAmount, adjustedFee)
1360+ let _amount = (_rawAmount - rawFeeAmount)
1361+ let distributeFeeAmount = if (isCollateralAsset)
10331362 then {
1034- let referrerFee = match referrerFeeAny {
1035- case x: Int =>
1036- x
1037- case _ =>
1038- throw("Invalid referrerFee")
1363+ let doBorrow = invoke(collateralAddress(), "borrow", [_trader], [AttachedPayment(_assetId, _amount)])
1364+ if ((doBorrow == doBorrow))
1365+ then {
1366+ let balanceBefore = assetBalance(this, quoteAsset())
1367+ if ((balanceBefore == balanceBefore))
1368+ then {
1369+ let doSwap = invoke(swapAddress(), "swap", [toBase58String(quoteAsset()), 0], [AttachedPayment(_assetId, rawFeeAmount)])
1370+ if ((doSwap == doSwap))
1371+ then {
1372+ let balanceAfter = assetBalance(this, quoteAsset())
1373+ if ((balanceAfter == balanceAfter))
1374+ then {
1375+ let exchangedAmount = (balanceAfter - balanceBefore)
1376+ if ((exchangedAmount == exchangedAmount))
1377+ then exchangedAmount
1378+ else throw("Strict value is not equal to itself.")
1379+ }
1380+ else throw("Strict value is not equal to itself.")
1381+ }
1382+ else throw("Strict value is not equal to itself.")
1383+ }
1384+ else throw("Strict value is not equal to itself.")
1385+ }
1386+ else throw("Strict value is not equal to itself.")
10391387 }
1040- let feeAmount = (distributeFeeAmount - referrerFee)
1041- let $t04721747357 = getPosition(_trader)
1042- let oldPositionSize = $t04721747357._1
1043- let oldPositionMargin = $t04721747357._2
1044- let oldPositionOpenNotional = $t04721747357._3
1045- let oldPositionLstUpdCPF = $t04721747357._4
1046- let isNewPosition = (oldPositionSize == 0)
1047- let isSameDirection = if ((oldPositionSize > 0))
1048- then (_direction == DIR_LONG)
1049- else (_direction == DIR_SHORT)
1050- let expandExisting = if (!(isNewPosition))
1051- then isSameDirection
1052- else false
1053- let isAdd = (_direction == DIR_LONG)
1054- let $t04764650231 = if (if (isNewPosition)
1055- then true
1056- else expandExisting)
1388+ else rawFeeAmount
1389+ if ((distributeFeeAmount == distributeFeeAmount))
1390+ then {
1391+ let referrerFeeAny = invoke(referralAddress(), "acceptPayment", [_trader], [AttachedPayment(quoteAsset(), distributeFeeAmount)])
1392+ if ((referrerFeeAny == referrerFeeAny))
10571393 then {
1058- let openNotional = muld(_amount, _leverage)
1059- let $t04807048276 = swapInput(isAdd, openNotional)
1060- let amountBaseAssetBought = $t04807048276._1
1061- let quoteAssetReserveAfter = $t04807048276._2
1062- let baseAssetReserveAfter = $t04807048276._3
1063- let totalPositionSizeAfter = $t04807048276._4
1064- let cumulativeNotionalAfter = $t04807048276._5
1065- if (if ((_minBaseAssetAmount != 0))
1066- then (_minBaseAssetAmount > abs(amountBaseAssetBought))
1067- else false)
1068- then throw(((("Limit error: " + toString(abs(amountBaseAssetBought))) + " < ") + toString(_minBaseAssetAmount)))
1069- else {
1070- let newPositionSize = (oldPositionSize + amountBaseAssetBought)
1071- let increaseMarginRequirement = divd(openNotional, _leverage)
1072- let $t04865748896 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, increaseMarginRequirement)
1073- let remainMargin = $t04865748896._1
1074- let x1 = $t04865748896._2
1075- let x2 = $t04865748896._3
1076- if (!(requireNotOverSpreadLimit(quoteAssetReserveAfter, baseAssetReserveAfter)))
1077- then throw("Over max spread limit")
1078- else $Tuple11(newPositionSize, remainMargin, (oldPositionOpenNotional + openNotional), latestCumulativePremiumFraction(newPositionSize), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, (openInterestNotional() + openNotional), (totalLongPositionSize() + (if ((newPositionSize > 0))
1079- then abs(amountBaseAssetBought)
1080- else 0)), (totalShortPositionSize() + (if ((0 > newPositionSize))
1081- then abs(amountBaseAssetBought)
1082- else 0)))
1083- }
1394+ let referrerFee = match referrerFeeAny {
1395+ case x: Int =>
1396+ x
1397+ case _ =>
1398+ throw("Invalid referrerFee")
10841399 }
1085- else {
1086- let openNotional = muld(_amount, _leverage)
1087- let $t04992450040 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT)
1088- let oldPositionNotional = $t04992450040._1
1089- let unrealizedPnl = $t04992450040._2
1090- if ((oldPositionNotional > openNotional))
1091- then throw("Use decreasePosition to decrease position size")
1092- else throw("Close position first")
1093- }
1094- let newPositionSize = $t04764650231._1
1095- let newPositionRemainMargin = $t04764650231._2
1096- let newPositionOpenNotional = $t04764650231._3
1097- let newPositionLatestCPF = $t04764650231._4
1098- let baseAssetReserveAfter = $t04764650231._5
1099- let quoteAssetReserveAfter = $t04764650231._6
1100- let totalPositionSizeAfter = $t04764650231._7
1101- let cumulativeNotionalAfter = $t04764650231._8
1102- let openInterestNotionalAfter = $t04764650231._9
1103- let totalLongAfter = $t04764650231._10
1104- let totalShortAfter = $t04764650231._11
1105- let feeToStakers = (feeAmount / 2)
1106- let feeToInsurance = (feeAmount - feeToStakers)
1107- let stake = invoke(managerAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), _amount)])
1108- if ((stake == stake))
1109- then {
1110- let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
1111- if ((depositInsurance == depositInsurance))
1400+ let feeAmount = (distributeFeeAmount - referrerFee)
1401+ let $t06006360203 = getPosition(_trader)
1402+ let oldPositionSize = $t06006360203._1
1403+ let oldPositionMargin = $t06006360203._2
1404+ let oldPositionOpenNotional = $t06006360203._3
1405+ let oldPositionLstUpdCPF = $t06006360203._4
1406+ let feeToStakers = (feeAmount / 2)
1407+ let feeToInsurance = (feeAmount - feeToStakers)
1408+ let stake = invoke(vaultAddress(), "addLocked", nil, [AttachedPayment(quoteAsset(), _amount)])
1409+ if ((stake == stake))
11121410 then {
1113- let notifyFee = invoke(minerAddress(), "notifyFees", [_trader, feeAmount], nil)
1114- if ((notifyFee == notifyFee))
1411+ let depositInsurance = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
1412+ if ((depositInsurance == depositInsurance))
11151413 then {
1116- let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil)
1117- if ((notifyNotional == notifyNotional))
1118- then (((((updatePosition(_trader, newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF) ++ updatePositionAsset(_trader, _assetIdStr)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter)) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) ++ doBurnArtifact(burnArtifact, i))
1414+ let notifyFee = invoke(minerAddress(), "notifyFees", [_trader, feeAmount], nil)
1415+ if ((notifyFee == notifyFee))
1416+ then (((updatePosition(_trader, oldPositionSize, (oldPositionMargin + _amount), oldPositionOpenNotional, oldPositionLstUpdCPF) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) ++ doBurnArtifact(burnArtifact, i))
11191417 else throw("Strict value is not equal to itself.")
11201418 }
11211419 else throw("Strict value is not equal to itself.")
11221420 }
11231421 else throw("Strict value is not equal to itself.")
11241422 }
11251423 else throw("Strict value is not equal to itself.")
11261424 }
11271425 else throw("Strict value is not equal to itself.")
11281426 }
1129- else throw("Strict value is not equal to itself.")
11301427 }
1428+ else throw("Strict value is not equal to itself.")
11311429 }
11321430
11331431
11341432
11351433 @Callable(i)
1136-func addMargin () = {
1137- let _trader = toString(i.caller)
1138- let _rawAmount = i.payments[0].amount
1139- let _assetId = i.payments[0].assetId
1140- let _assetIdStr = toBase58String(value(_assetId))
1141- let isQuoteAsset = (_assetId == quoteAsset())
1142- let isCollateralAsset = isWhitelistAsset(_assetIdStr)
1143- if (if (if (if (if (if (!(isQuoteAsset))
1144- then !(isCollateralAsset)
1145- else false)
1146- then true
1147- else !(requireOpenPosition(toString(i.caller))))
1148- then true
1149- else !(isSameAsset(_trader, _assetIdStr)))
1150- then true
1151- else !(initialized()))
1152- then true
1153- else paused())
1154- then throw("Invalid addMargin parameters")
1155- else {
1156- let $t05198752038 = getAdjustedFee(i)
1157- let adjustedFee = $t05198752038._1
1158- let burnArtifact = $t05198752038._2
1159- let rawFeeAmount = muld(_rawAmount, adjustedFee)
1160- let _amount = (_rawAmount - rawFeeAmount)
1161- let distributeFeeAmount = if (isCollateralAsset)
1162- then {
1163- let doBorrow = invoke(collateralAddress(), "borrow", [_trader], [AttachedPayment(_assetId, _amount)])
1164- if ((doBorrow == doBorrow))
1165- then {
1166- let balanceBefore = assetBalance(this, quoteAsset())
1167- if ((balanceBefore == balanceBefore))
1168- then {
1169- let doSwap = invoke(swapAddress(), "swap", [toBase58String(quoteAsset()), 0], [AttachedPayment(_assetId, rawFeeAmount)])
1170- if ((doSwap == doSwap))
1434+func removeMargin (_amount) = {
1435+ let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
1436+ if ((sync == sync))
1437+ then {
1438+ let _trader = toString(i.caller)
1439+ if (if (if (if ((0 >= _amount))
1440+ then true
1441+ else !(requireOpenPosition(_trader)))
1442+ then true
1443+ else !(initialized()))
1444+ then true
1445+ else paused())
1446+ then throw("Invalid removeMargin parameters")
1447+ else {
1448+ let $t06130961449 = getPosition(_trader)
1449+ let oldPositionSize = $t06130961449._1
1450+ let oldPositionMargin = $t06130961449._2
1451+ let oldPositionOpenNotional = $t06130961449._3
1452+ let oldPositionLstUpdCPF = $t06130961449._4
1453+ let marginDelta = -(_amount)
1454+ let $t06148661665 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, marginDelta)
1455+ let remainMargin = $t06148661665._1
1456+ let badDebt = $t06148661665._2
1457+ if ((badDebt != 0))
1458+ then throw("Invalid removed margin amount")
1459+ else {
1460+ let marginRatio = calcMarginRatio(remainMargin, badDebt, oldPositionOpenNotional)
1461+ if (!(requireMoreMarginRatio(marginRatio, initMarginRatio(), true)))
1462+ then throw(((("Too much margin removed: " + toString(marginRatio)) + " < ") + toString(initMarginRatio())))
1463+ else {
1464+ let quoteAssetStr = toBase58String(quoteAsset())
1465+ let $t06210962163 = getBorrowedByTrader(_trader)
1466+ let borrowed = $t06210962163._1
1467+ let assetId = $t06210962163._2
1468+ let toRepay = if ((_amount > borrowed))
1469+ then borrowed
1470+ else _amount
1471+ let toWithdraw = if ((borrowed > _amount))
1472+ then 0
1473+ else (_amount - borrowed)
1474+ let finalBorrow = (borrowed - toRepay)
1475+ let switchPositionToQuote = if ((finalBorrow > 0))
1476+ then nil
1477+ else updatePositionAsset(_trader, quoteAssetStr)
1478+ let doSanityCheck = if (((toRepay + toWithdraw) != _amount))
1479+ then throw(((((("toRepay=" + toString(toRepay)) + " + toWithdraw=") + toString(toWithdraw)) + " != ") + toString(_amount)))
1480+ else nil
1481+ if ((doSanityCheck == doSanityCheck))
11711482 then {
1172- let balanceAfter = assetBalance(this, quoteAsset())
1173- if ((balanceAfter == balanceAfter))
1483+ let doUnstake = invoke(vaultAddress(), "withdrawLocked", [_amount], nil)
1484+ if ((doUnstake == doUnstake))
11741485 then {
1175- let exchangedAmount = (balanceAfter - balanceBefore)
1176- if ((exchangedAmount == exchangedAmount))
1177- then exchangedAmount
1486+ let returnCollateralAction = if ((toRepay > 0))
1487+ then {
1488+ let doRepay = invoke(collateralAddress(), "repay", [_trader, assetId], [AttachedPayment(quoteAsset(), toRepay)])
1489+ if ((doRepay == doRepay))
1490+ then [ScriptTransfer(i.caller, toRepay, fromBase58String(assetId))]
1491+ else throw("Strict value is not equal to itself.")
1492+ }
1493+ else nil
1494+ if ((returnCollateralAction == returnCollateralAction))
1495+ then ((((updatePosition(_trader, oldPositionSize, remainMargin, oldPositionOpenNotional, latestCumulativePremiumFraction(oldPositionSize)) ++ (if ((toWithdraw > 0))
1496+ then withdraw(i.caller, toWithdraw)
1497+ else nil)) ++ updateBalance((cbalance() - _amount))) ++ switchPositionToQuote) ++ returnCollateralAction)
11781498 else throw("Strict value is not equal to itself.")
11791499 }
11801500 else throw("Strict value is not equal to itself.")
11811501 }
11821502 else throw("Strict value is not equal to itself.")
11831503 }
1184- else throw("Strict value is not equal to itself.")
11851504 }
1186- else throw("Strict value is not equal to itself.")
11871505 }
1188- else rawFeeAmount
1189- if ((distributeFeeAmount == distributeFeeAmount))
1190- then {
1191- let referrerFeeAny = invoke(referralAddress(), "acceptPayment", [_trader], [AttachedPayment(quoteAsset(), distributeFeeAmount)])
1192- if ((referrerFeeAny == referrerFeeAny))
1193- then {
1194- let referrerFee = match referrerFeeAny {
1195- case x: Int =>
1196- x
1197- case _ =>
1198- throw("Invalid referrerFee")
1199- }
1200- let feeAmount = (distributeFeeAmount - referrerFee)
1201- let $t05333753477 = getPosition(_trader)
1202- let oldPositionSize = $t05333753477._1
1203- let oldPositionMargin = $t05333753477._2
1204- let oldPositionOpenNotional = $t05333753477._3
1205- let oldPositionLstUpdCPF = $t05333753477._4
1206- let feeToStakers = (feeAmount / 2)
1207- let feeToInsurance = (feeAmount - feeToStakers)
1208- let stake = invoke(managerAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), _amount)])
1209- if ((stake == stake))
1210- then {
1211- let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
1212- if ((depositInsurance == depositInsurance))
1213- then {
1214- let notifyFee = invoke(minerAddress(), "notifyFees", [_trader, feeAmount], nil)
1215- if ((notifyFee == notifyFee))
1216- then (((updatePosition(_trader, oldPositionSize, (oldPositionMargin + _amount), oldPositionOpenNotional, oldPositionLstUpdCPF) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) ++ doBurnArtifact(burnArtifact, i))
1217- else throw("Strict value is not equal to itself.")
1218- }
1219- else throw("Strict value is not equal to itself.")
1220- }
1221- else throw("Strict value is not equal to itself.")
1222- }
1223- else throw("Strict value is not equal to itself.")
1224- }
1225- else throw("Strict value is not equal to itself.")
12261506 }
1507+ else throw("Strict value is not equal to itself.")
12271508 }
12281509
12291510
12301511
12311512 @Callable(i)
1232-func removeMargin (_amount) = {
1233- let _trader = toString(i.caller)
1234- if (if (if (if ((0 >= _amount))
1235- then true
1236- else !(requireOpenPosition(_trader)))
1237- then true
1238- else !(initialized()))
1239- then true
1240- else paused())
1241- then throw("Invalid removeMargin parameters")
1242- else {
1243- let $t05452054660 = getPosition(_trader)
1244- let oldPositionSize = $t05452054660._1
1245- let oldPositionMargin = $t05452054660._2
1246- let oldPositionOpenNotional = $t05452054660._3
1247- let oldPositionLstUpdCPF = $t05452054660._4
1248- let marginDelta = -(_amount)
1249- let $t05469754876 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, marginDelta)
1250- let remainMargin = $t05469754876._1
1251- let badDebt = $t05469754876._2
1252- if ((badDebt != 0))
1253- then throw("Invalid removed margin amount")
1513+func closePosition (_size,_minQuoteAssetAmount) = {
1514+ let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
1515+ if ((sync == sync))
1516+ then {
1517+ let _trader = getActualCaller(i)
1518+ let _traderAddress = valueOrErrorMessage(addressFromString(_trader), "Invalid caller")
1519+ if (if (if (if (if (!(requireOpenPosition(_trader)))
1520+ then true
1521+ else !(initialized()))
1522+ then true
1523+ else paused())
1524+ then true
1525+ else (0 >= _size))
1526+ then true
1527+ else (0 > _minQuoteAssetAmount))
1528+ then throw("Invalid closePosition parameters")
12541529 else {
1255- let marginRatio = calcMarginRatio(remainMargin, badDebt, oldPositionOpenNotional)
1256- if (!(requireMoreMarginRatio(marginRatio, initMarginRatio(), true)))
1257- then throw(((("Too much margin removed: " + toString(marginRatio)) + " < ") + toString(initMarginRatio())))
1530+ let $t06429364433 = getPosition(_trader)
1531+ let oldPositionSize = $t06429364433._1
1532+ let oldPositionMargin = $t06429364433._2
1533+ let oldPositionOpenNotional = $t06429364433._3
1534+ let oldPositionLstUpdCPF = $t06429364433._4
1535+ let $t06443968811 = if ((abs(oldPositionSize) > _size))
1536+ then {
1537+ let _direction = if ((oldPositionSize > 0))
1538+ then DIR_SHORT
1539+ else DIR_LONG
1540+ let isAdd = (_direction == DIR_LONG)
1541+ let $t06503065252 = swapOutput((oldPositionSize > 0), _size, true)
1542+ let exchangedQuoteAssetAmount = $t06503065252._1
1543+ let quoteAssetReserveAfter = $t06503065252._2
1544+ let baseAssetReserveAfter = $t06503065252._3
1545+ let totalPositionSizeAfter = $t06503065252._4
1546+ let exchangedPositionSize = if ((oldPositionSize > 0))
1547+ then -(_size)
1548+ else _size
1549+ let $t06534365497 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)
1550+ let oldPositionNotional = $t06534365497._1
1551+ let unrealizedPnl = $t06534365497._2
1552+ let realizedRatio = divd(abs(exchangedPositionSize), abs(oldPositionSize))
1553+ let realizedPnl = muld(unrealizedPnl, realizedRatio)
1554+ let $t06571165949 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl)
1555+ let remainMargin = $t06571165949._1
1556+ let positionBadDebt = $t06571165949._2
1557+ let fundingPayment = $t06571165949._3
1558+ let unrealizedPnlAfter = (unrealizedPnl - realizedPnl)
1559+ let remainOpenNotional = if ((oldPositionSize > 0))
1560+ then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter)
1561+ else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount)
1562+ let newPositionMargin = muld(remainMargin, realizedRatio)
1563+ let newPositionSize = (oldPositionSize + exchangedPositionSize)
1564+ let newPositionOpenNotional = abs(remainOpenNotional)
1565+ let newPositionLstUpdCPF = latestCumulativePremiumFraction(newPositionSize)
1566+ let openInterestNotionalAfter = (openInterestNotional() - exchangedQuoteAssetAmount)
1567+ if (if ((_minQuoteAssetAmount != 0))
1568+ then (_minQuoteAssetAmount > exchangedQuoteAssetAmount)
1569+ else false)
1570+ then throw(((("Limit error: " + toString(exchangedQuoteAssetAmount)) + " < ") + toString(_minQuoteAssetAmount)))
1571+ else $Tuple15(newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF, positionBadDebt, realizedPnl, (abs((remainMargin - newPositionMargin)) + realizedPnl), quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, (totalLongPositionSize() - (if ((newPositionSize > 0))
1572+ then abs(exchangedPositionSize)
1573+ else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize))
1574+ then abs(exchangedPositionSize)
1575+ else 0)), (openInterestLong() - (if ((newPositionSize > 0))
1576+ then exchangedQuoteAssetAmount
1577+ else 0)), (openInterestShort() - (if ((0 > newPositionSize))
1578+ then exchangedQuoteAssetAmount
1579+ else 0)))
1580+ }
1581+ else if ((_size > abs(oldPositionSize)))
1582+ then throw("Invalid closePosition parameters")
1583+ else {
1584+ let $t06775268171 = internalClosePosition(_trader, true)
1585+ let exchangedQuoteAssetAmount = $t06775268171._1
1586+ let positionBadDebt = $t06775268171._2
1587+ let realizedPnl = $t06775268171._3
1588+ let marginToVault = $t06775268171._4
1589+ let quoteAssetReserveAfter = $t06775268171._5
1590+ let baseAssetReserveAfter = $t06775268171._6
1591+ let totalPositionSizeAfter = $t06775268171._7
1592+ let openInterestNotionalAfter = $t06775268171._8
1593+ let x2 = $t06775268171._9
1594+ let totalLongAfter = $t06775268171._10
1595+ let totalShortAfter = $t06775268171._11
1596+ let totalLongOpenInterestAfter = $t06775268171._12
1597+ let totalShortOpenInterestAfter = $t06775268171._13
1598+ if (if ((_minQuoteAssetAmount != 0))
1599+ then (_minQuoteAssetAmount > exchangedQuoteAssetAmount)
1600+ else false)
1601+ then throw(((("Limit error: " + toString(exchangedQuoteAssetAmount)) + " < ") + toString(_minQuoteAssetAmount)))
1602+ else $Tuple15(0, 0, 0, 0, positionBadDebt, realizedPnl, marginToVault, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)
1603+ }
1604+ let newPositionSize = $t06443968811._1
1605+ let newPositionMargin = $t06443968811._2
1606+ let newPositionOpenNotional = $t06443968811._3
1607+ let newPositionLstUpdCPF = $t06443968811._4
1608+ let positionBadDebt = $t06443968811._5
1609+ let realizedPnl = $t06443968811._6
1610+ let marginToVault = $t06443968811._7
1611+ let quoteAssetReserveAfter = $t06443968811._8
1612+ let baseAssetReserveAfter = $t06443968811._9
1613+ let totalPositionSizeAfter = $t06443968811._10
1614+ let openInterestNotionalAfter = $t06443968811._11
1615+ let totalLongAfter = $t06443968811._12
1616+ let totalShortAfter = $t06443968811._13
1617+ let totalLongOpenInterestAfter = $t06443968811._14
1618+ let totalShortOpenInterestAfter = $t06443968811._15
1619+ if ((positionBadDebt > 0))
1620+ then throw("Unable to close position with bad debt")
12581621 else {
1259- let quoteAssetStr = toBase58String(quoteAsset())
1260- let $t05532055374 = getBorrowedByTrader(_trader)
1261- let borrowed = $t05532055374._1
1262- let assetId = $t05532055374._2
1263- let toRepay = if ((_amount > borrowed))
1264- then borrowed
1265- else _amount
1266- let toWithdraw = if ((borrowed > _amount))
1267- then 0
1268- else (_amount - borrowed)
1269- let finalBorrow = (borrowed - toRepay)
1270- let switchPositionToQuote = if ((finalBorrow > 0))
1271- then nil
1272- else updatePositionAsset(_trader, quoteAssetStr)
1273- let doSanityCheck = if (((toRepay + toWithdraw) != _amount))
1274- then throw(((((("toRepay=" + toString(toRepay)) + " + toWithdraw=") + toString(toWithdraw)) + " != ") + toString(_amount)))
1275- else nil
1276- if ((doSanityCheck == doSanityCheck))
1277- then {
1278- let doUnstake = invoke(managerAddress(), "withdraw", [quoteAssetStr, _amount], nil)
1279- if ((doUnstake == doUnstake))
1280- then {
1281- let returnCollateralAction = if ((toRepay > 0))
1282- then {
1283- let doRepay = invoke(collateralAddress(), "repay", [_trader, assetId], [AttachedPayment(quoteAsset(), toRepay)])
1284- if ((doRepay == doRepay))
1285- then [ScriptTransfer(i.caller, toRepay, fromBase58String(assetId))]
1286- else throw("Strict value is not equal to itself.")
1287- }
1288- else nil
1289- if ((returnCollateralAction == returnCollateralAction))
1290- then (updatePosition(_trader, oldPositionSize, remainMargin, oldPositionOpenNotional, latestCumulativePremiumFraction(oldPositionSize)) ++ (if ((toWithdraw > 0))
1291- then withdraw(i.caller, toWithdraw)
1292- else (((nil ++ updateBalance((cbalance() - _amount))) ++ switchPositionToQuote) ++ returnCollateralAction)))
1293- else throw("Strict value is not equal to itself.")
1294- }
1295- else throw("Strict value is not equal to itself.")
1296- }
1297- else throw("Strict value is not equal to itself.")
1298- }
1299- }
1300- }
1301- }
1302-
1303-
1304-
1305-@Callable(i)
1306-func closePosition () = {
1307- let _trader = getActualCaller(i)
1308- let _traderAddress = valueOrErrorMessage(addressFromString(_trader), "Invalid caller")
1309- if (if (if (!(requireOpenPosition(_trader)))
1310- then true
1311- else !(initialized()))
1312- then true
1313- else paused())
1314- then throw("Invalid closePosition parameters")
1315- else {
1316- let $t05756657944 = internalClosePosition(_trader, true)
1317- let x1 = $t05756657944._1
1318- let positionBadDebt = $t05756657944._2
1319- let realizedPnl = $t05756657944._3
1320- let marginToVault = $t05756657944._4
1321- let quoteAssetReserveAfter = $t05756657944._5
1322- let baseAssetReserveAfter = $t05756657944._6
1323- let totalPositionSizeAfter = $t05756657944._7
1324- let cumulativeNotionalAfter = $t05756657944._8
1325- let openInterestNotionalAfter = $t05756657944._9
1326- let x2 = $t05756657944._10
1327- let totalLongAfter = $t05756657944._11
1328- let totalShortAfter = $t05756657944._12
1329- if ((positionBadDebt > 0))
1330- then throw("Unable to close position with bad debt")
1331- else {
1332- let withdrawAmount = abs(marginToVault)
1333- let ammBalance = (cbalance() - withdrawAmount)
1334- let $t05815358295 = if ((0 > ammBalance))
1335- then $Tuple2(0, abs(ammBalance))
1336- else $Tuple2(ammBalance, 0)
1337- let ammNewBalance = $t05815358295._1
1338- let getFromInsurance = $t05815358295._2
1339- let x = if ((getFromInsurance > 0))
1340- then {
1341- let withdrawInsurance = invoke(insuranceAddress(), "withdraw", [getFromInsurance], nil)
1342- if ((withdrawInsurance == withdrawInsurance))
1343- then nil
1344- else throw("Strict value is not equal to itself.")
1345- }
1346- else nil
1347- if ((x == x))
1348- then {
1349- let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), (withdrawAmount - getFromInsurance)], nil)
1622+ let withdrawAmount = abs(marginToVault)
1623+ let ammBalance = (cbalance() - withdrawAmount)
1624+ let $t06902069149 = if ((0 > ammBalance))
1625+ then $Tuple2(0, abs(ammBalance))
1626+ else $Tuple2(ammBalance, 0)
1627+ let ammNewBalance = $t06902069149._1
1628+ let x11 = $t06902069149._2
1629+ let unstake = invoke(vaultAddress(), "withdrawLocked", [withdrawAmount], nil)
13501630 if ((unstake == unstake))
13511631 then {
1352- let $t05879758851 = getBorrowedByTrader(_trader)
1353- let borrowed = $t05879758851._1
1354- let assetId = $t05879758851._2
1355- let $t05886659783 = if ((borrowed > 0))
1632+ let $t06936169415 = getBorrowedByTrader(_trader)
1633+ let borrowed = $t06936169415._1
1634+ let assetId = $t06936169415._2
1635+ let $t06943070347 = if ((borrowed > 0))
13561636 then if ((withdrawAmount >= borrowed))
13571637 then {
13581638 let doRepay = invoke(collateralAddress(), "repay", [_trader, assetId], [AttachedPayment(quoteAsset(), borrowed)])
13591639 if ((doRepay == doRepay))
13601640 then $Tuple2([ScriptTransfer(_traderAddress, borrowed, fromBase58String(assetId))], (withdrawAmount - borrowed))
13611641 else throw("Strict value is not equal to itself.")
13621642 }
13631643 else {
13641644 let realizeAndClose = invoke(collateralAddress(), "realizePartiallyAndClose", [_trader, assetId], [AttachedPayment(quoteAsset(), withdrawAmount)])
13651645 if ((realizeAndClose == realizeAndClose))
13661646 then $Tuple2([ScriptTransfer(_traderAddress, withdrawAmount, fromBase58String(assetId))], 0)
13671647 else throw("Strict value is not equal to itself.")
13681648 }
13691649 else $Tuple2(nil, withdrawAmount)
1370- if (($t05886659783 == $t05886659783))
1650+ if (($t06943070347 == $t06943070347))
13711651 then {
1372- let quoteWithdrawAmount = $t05886659783._2
1373- let sendCollateralAction = $t05886659783._1
1652+ let quoteWithdrawAmount = $t06943070347._2
1653+ let sendCollateralAction = $t06943070347._1
13741654 let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, 0], nil)
13751655 if ((notifyNotional == notifyNotional))
1376- then ((deletePosition(_trader) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter)) ++ (if ((quoteWithdrawAmount > 0))
1656+ then (((((if ((newPositionSize == 0))
1657+ then deletePosition(_trader)
1658+ else updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ (if ((quoteWithdrawAmount > 0))
13771659 then withdraw(_traderAddress, quoteWithdrawAmount)
1378- else ((nil ++ updateBalance(ammNewBalance)) ++ sendCollateralAction)))
1660+ else nil)) ++ updateBalance(ammNewBalance)) ++ sendCollateralAction)
13791661 else throw("Strict value is not equal to itself.")
13801662 }
13811663 else throw("Strict value is not equal to itself.")
13821664 }
13831665 else throw("Strict value is not equal to itself.")
13841666 }
1385- else throw("Strict value is not equal to itself.")
13861667 }
13871668 }
1669+ else throw("Strict value is not equal to itself.")
13881670 }
13891671
13901672
13911673
13921674 @Callable(i)
13931675 func liquidate (_trader) = {
1394- let spotMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_SPOT)
1395- let marginRatio = if (isOverFluctuationLimit())
1676+ let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
1677+ if ((sync == sync))
13961678 then {
1397- let oracleMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_ORACLE)
1398- vmax(spotMarginRatio, oracleMarginRatio)
1399- }
1400- else spotMarginRatio
1401- if (if (if (if (!(requireMoreMarginRatio(marginRatio, maintenanceMarginRatio(), false)))
1402- then true
1403- else !(requireOpenPosition(_trader)))
1404- then true
1405- else !(initialized()))
1406- then true
1407- else paused())
1408- then throw("Unable to liquidate")
1409- else if (if (if ((spotMarginRatio > liquidationFeeRatio()))
1410- then (partialLiquidationRatio() > 0)
1411- else false)
1412- then (DECIMAL_UNIT > partialLiquidationRatio())
1413- else false)
1414- then {
1415- let $t06148361633 = getPosition(_trader)
1416- let oldPositionSize = $t06148361633._1
1417- let oldPositionMargin = $t06148361633._2
1418- let oldPositionOpenNotional = $t06148361633._3
1419- let oldPositionLstUpdCPF = $t06148361633._4
1420- let _direction = if ((oldPositionSize > 0))
1421- then DIR_SHORT
1422- else DIR_LONG
1423- let isAdd = (_direction == DIR_LONG)
1424- let exchangedQuoteAssetAmount = getPartialLiquidationAmount(_trader, oldPositionSize)
1425- let $t06185861962 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)
1426- let oldPositionNotional = $t06185861962._1
1427- let unrealizedPnl = $t06185861962._2
1428- let $t06197062202 = swapInput(isAdd, exchangedQuoteAssetAmount)
1429- let exchangedPositionSize = $t06197062202._1
1430- let quoteAssetReserveAfter = $t06197062202._2
1431- let baseAssetReserveAfter = $t06197062202._3
1432- let totalPositionSizeAfter = $t06197062202._4
1433- let cumulativeNotionalAfter = $t06197062202._5
1434- let liquidationRatio = divd(abs(exchangedPositionSize), abs(oldPositionSize))
1435- let realizedPnl = muld(unrealizedPnl, liquidationRatio)
1436- let $t06241362646 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl)
1437- let remainMargin = $t06241362646._1
1438- let badDebt = $t06241362646._2
1439- let fundingPayment = $t06241362646._3
1440- let unrealizedPnlAfter = (unrealizedPnl - realizedPnl)
1441- let remainOpenNotional = if ((oldPositionSize > 0))
1442- then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter)
1443- else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount)
1444- let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio())
1445- let feeToLiquidator = (liquidationPenalty / 2)
1446- let feeToInsurance = (liquidationPenalty - feeToLiquidator)
1447- let newPositionMargin = (remainMargin - liquidationPenalty)
1448- let newPositionSize = (oldPositionSize + exchangedPositionSize)
1449- let newPositionOpenNotional = abs(remainOpenNotional)
1450- let newPositionLstUpdCPF = latestCumulativePremiumFraction(newPositionSize)
1451- let openInterestNotionalAfter = (openInterestNotional() - exchangedQuoteAssetAmount)
1452- let ammBalance = (cbalance() - liquidationPenalty)
1453- let $t06381963962 = if ((0 > ammBalance))
1454- then $Tuple2(0, abs(ammBalance))
1455- else $Tuple2(ammBalance, 0)
1456- let newAmmBalance = $t06381963962._1
1457- let takeFromInsurance = $t06381963962._2
1458- let $t06397064024 = getBorrowedByTrader(_trader)
1459- let borrowed = $t06397064024._1
1460- let assetId = $t06397064024._2
1461- let doLiquidateCollateral = if ((borrowed > 0))
1679+ let spotMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_SPOT)
1680+ let marginRatio = if (isOverFluctuationLimit())
1681+ then {
1682+ let oracleMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_ORACLE)
1683+ vmax(spotMarginRatio, oracleMarginRatio)
1684+ }
1685+ else spotMarginRatio
1686+ if (if (if (if (!(requireMoreMarginRatio(marginRatio, maintenanceMarginRatio(), false)))
1687+ then true
1688+ else !(requireOpenPosition(_trader)))
1689+ then true
1690+ else !(initialized()))
1691+ then true
1692+ else paused())
1693+ then throw("Unable to liquidate")
1694+ else if (if (if ((spotMarginRatio > liquidationFeeRatio()))
1695+ then (partialLiquidationRatio() > 0)
1696+ else false)
1697+ then (DECIMAL_UNIT > partialLiquidationRatio())
1698+ else false)
14621699 then {
1463- let collateralToSell = muld(borrowed, liquidationRatio)
1464- let realizeAndClose = invoke(collateralAddress(), "realizePartially", [_trader, assetId, collateralToSell], nil)
1465- if ((realizeAndClose == realizeAndClose))
1466- then nil
1467- else throw("Strict value is not equal to itself.")
1468- }
1469- else nil
1470- if ((doLiquidateCollateral == doLiquidateCollateral))
1471- then {
1472- let x = if ((takeFromInsurance > 0))
1700+ let $t07239672546 = getPosition(_trader)
1701+ let oldPositionSize = $t07239672546._1
1702+ let oldPositionMargin = $t07239672546._2
1703+ let oldPositionOpenNotional = $t07239672546._3
1704+ let oldPositionLstUpdCPF = $t07239672546._4
1705+ let _direction = if ((oldPositionSize > 0))
1706+ then DIR_SHORT
1707+ else DIR_LONG
1708+ let isAdd = (_direction == DIR_LONG)
1709+ let exchangedQuoteAssetAmount = getPartialLiquidationAmount(_trader, oldPositionSize)
1710+ let $t07277172875 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)
1711+ let oldPositionNotional = $t07277172875._1
1712+ let unrealizedPnl = $t07277172875._2
1713+ let $t07288373070 = swapInput(isAdd, exchangedQuoteAssetAmount)
1714+ let exchangedPositionSize = $t07288373070._1
1715+ let quoteAssetReserveAfter = $t07288373070._2
1716+ let baseAssetReserveAfter = $t07288373070._3
1717+ let totalPositionSizeAfter = $t07288373070._4
1718+ let liquidationRatio = divd(abs(exchangedPositionSize), abs(oldPositionSize))
1719+ let realizedPnl = muld(unrealizedPnl, liquidationRatio)
1720+ let $t07335973592 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl)
1721+ let remainMargin = $t07335973592._1
1722+ let badDebt = $t07335973592._2
1723+ let fundingPayment = $t07335973592._3
1724+ let unrealizedPnlAfter = (unrealizedPnl - realizedPnl)
1725+ let remainOpenNotional = if ((oldPositionSize > 0))
1726+ then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter)
1727+ else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount)
1728+ let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio())
1729+ let feeToLiquidator = (liquidationPenalty / 2)
1730+ let feeToInsurance = (liquidationPenalty - feeToLiquidator)
1731+ let newPositionMargin = (remainMargin - liquidationPenalty)
1732+ let newPositionSize = (oldPositionSize + exchangedPositionSize)
1733+ let newPositionOpenNotional = abs(remainOpenNotional)
1734+ let newPositionLstUpdCPF = latestCumulativePremiumFraction(newPositionSize)
1735+ let openInterestNotionalAfter = (openInterestNotional() - exchangedQuoteAssetAmount)
1736+ let ammBalance = (cbalance() - liquidationPenalty)
1737+ let $t07476574894 = if ((0 > ammBalance))
1738+ then $Tuple2(0, abs(ammBalance))
1739+ else $Tuple2(ammBalance, 0)
1740+ let newAmmBalance = $t07476574894._1
1741+ let x11 = $t07476574894._2
1742+ let $t07490274956 = getBorrowedByTrader(_trader)
1743+ let borrowed = $t07490274956._1
1744+ let assetId = $t07490274956._2
1745+ let doLiquidateCollateral = if ((borrowed > 0))
14731746 then {
1474- let withdrawInsurance = invoke(insuranceAddress(), "withdraw", [takeFromInsurance], nil)
1475- if ((withdrawInsurance == withdrawInsurance))
1747+ let collateralToSell = muld(borrowed, liquidationRatio)
1748+ let realizeAndClose = invoke(collateralAddress(), "realizePartially", [_trader, assetId, collateralToSell], nil)
1749+ if ((realizeAndClose == realizeAndClose))
14761750 then nil
14771751 else throw("Strict value is not equal to itself.")
14781752 }
14791753 else nil
1480- if ((x == x))
1754+ if ((doLiquidateCollateral == doLiquidateCollateral))
14811755 then {
1482- let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), (liquidationPenalty - takeFromInsurance)], nil)
1756+ let unstake = invoke(vaultAddress(), "withdrawLocked", [liquidationPenalty], nil)
14831757 if ((unstake == unstake))
14841758 then {
1485- let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
1759+ let depositInsurance = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
14861760 if ((depositInsurance == depositInsurance))
14871761 then {
14881762 let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil)
14891763 if ((notifyNotional == notifyNotional))
1490- then (((updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, (totalLongPositionSize() - (if ((newPositionSize > 0))
1764+ then (((updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, (totalLongPositionSize() - (if ((newPositionSize > 0))
14911765 then abs(exchangedPositionSize)
14921766 else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize))
14931767 then abs(exchangedPositionSize)
1768+ else 0)), (openInterestLong() - (if ((newPositionSize > 0))
1769+ then exchangedQuoteAssetAmount
1770+ else 0)), (openInterestShort() - (if ((0 > newPositionSize))
1771+ then exchangedQuoteAssetAmount
14941772 else 0)))) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance))
14951773 else throw("Strict value is not equal to itself.")
14961774 }
14971775 else throw("Strict value is not equal to itself.")
14981776 }
14991777 else throw("Strict value is not equal to itself.")
15001778 }
15011779 else throw("Strict value is not equal to itself.")
15021780 }
1503- else throw("Strict value is not equal to itself.")
1504- }
1505- else {
1506- let $t06586666321 = internalClosePosition(_trader, false)
1507- let x1 = $t06586666321._1
1508- let badDebt = $t06586666321._2
1509- let x2 = $t06586666321._3
1510- let x3 = $t06586666321._4
1511- let quoteAssetReserveAfter = $t06586666321._5
1512- let baseAssetReserveAfter = $t06586666321._6
1513- let totalPositionSizeAfter = $t06586666321._7
1514- let cumulativeNotionalAfter = $t06586666321._8
1515- let openInterestNotionalAfter = $t06586666321._9
1516- let exchangedQuoteAssetAmount = $t06586666321._10
1517- let totalLongAfter = $t06586666321._11
1518- let totalShortAfter = $t06586666321._12
1519- let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio())
1520- let feeToLiquidator = (liquidationPenalty / 2)
1521- let feeToInsurance = (liquidationPenalty - feeToLiquidator)
1522- let ammBalance = (cbalance() - liquidationPenalty)
1523- let $t06673366876 = if ((0 > ammBalance))
1524- then $Tuple2(0, abs(ammBalance))
1525- else $Tuple2(ammBalance, 0)
1526- let newAmmBalance = $t06673366876._1
1527- let takeFromInsurance = $t06673366876._2
1528- let $t06688466938 = getBorrowedByTrader(_trader)
1529- let borrowed = $t06688466938._1
1530- let assetId = $t06688466938._2
1531- let doLiquidateCollateral = if ((borrowed > 0))
1532- then {
1533- let realizeAndClose = invoke(collateralAddress(), "realizePartiallyAndClose", [_trader, assetId], nil)
1534- if ((realizeAndClose == realizeAndClose))
1535- then nil
1536- else throw("Strict value is not equal to itself.")
1537- }
1538- else nil
1539- if ((doLiquidateCollateral == doLiquidateCollateral))
1540- then {
1541- let x = if ((takeFromInsurance > 0))
1781+ else {
1782+ let $t07665577150 = internalClosePosition(_trader, false)
1783+ let x1 = $t07665577150._1
1784+ let badDebt = $t07665577150._2
1785+ let x2 = $t07665577150._3
1786+ let x3 = $t07665577150._4
1787+ let quoteAssetReserveAfter = $t07665577150._5
1788+ let baseAssetReserveAfter = $t07665577150._6
1789+ let totalPositionSizeAfter = $t07665577150._7
1790+ let openInterestNotionalAfter = $t07665577150._8
1791+ let exchangedQuoteAssetAmount = $t07665577150._9
1792+ let totalLongAfter = $t07665577150._10
1793+ let totalShortAfter = $t07665577150._11
1794+ let totalLongOpenInterestAfter = $t07665577150._12
1795+ let totalShortOpenInterestAfter = $t07665577150._13
1796+ let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio())
1797+ let feeToLiquidator = (liquidationPenalty / 2)
1798+ let feeToInsurance = (liquidationPenalty - feeToLiquidator)
1799+ let ammBalance = (cbalance() - liquidationPenalty)
1800+ let $t07756277691 = if ((0 > ammBalance))
1801+ then $Tuple2(0, abs(ammBalance))
1802+ else $Tuple2(ammBalance, 0)
1803+ let newAmmBalance = $t07756277691._1
1804+ let x11 = $t07756277691._2
1805+ let $t07769977753 = getBorrowedByTrader(_trader)
1806+ let borrowed = $t07769977753._1
1807+ let assetId = $t07769977753._2
1808+ let doLiquidateCollateral = if ((borrowed > 0))
15421809 then {
1543- let withdrawInsurance = invoke(insuranceAddress(), "withdraw", [takeFromInsurance], nil)
1544- if ((withdrawInsurance == withdrawInsurance))
1810+ let realizeAndClose = invoke(collateralAddress(), "realizePartiallyAndClose", [_trader, assetId], nil)
1811+ if ((realizeAndClose == realizeAndClose))
15451812 then nil
15461813 else throw("Strict value is not equal to itself.")
15471814 }
15481815 else nil
1549- if ((x == x))
1816+ if ((doLiquidateCollateral == doLiquidateCollateral))
15501817 then {
1551- let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), (liquidationPenalty - takeFromInsurance)], nil)
1552- if ((unstake == unstake))
1818+ let x = if ((badDebt > 0))
15531819 then {
1554- let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
1555- if ((depositInsurance == depositInsurance))
1820+ let lockBadDebt = invoke(vaultAddress(), "exchangeFreeAndLocked", [badDebt], nil)
1821+ if ((lockBadDebt == lockBadDebt))
1822+ then nil
1823+ else throw("Strict value is not equal to itself.")
1824+ }
1825+ else nil
1826+ if ((x == x))
1827+ then {
1828+ let unstake = invoke(vaultAddress(), "withdrawLocked", [liquidationPenalty], nil)
1829+ if ((unstake == unstake))
15561830 then {
1557- let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, 0], nil)
1558- if ((notifyNotional == notifyNotional))
1559- then (((deletePosition(_trader) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter)) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance))
1831+ let depositInsurance = invoke(vaultAddress(), "addFree", nil, [AttachedPayment(quoteAsset(), feeToInsurance)])
1832+ if ((depositInsurance == depositInsurance))
1833+ then {
1834+ let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, 0], nil)
1835+ if ((notifyNotional == notifyNotional))
1836+ then (((deletePosition(_trader) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter, totalLongOpenInterestAfter, totalShortOpenInterestAfter)) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance))
1837+ else throw("Strict value is not equal to itself.")
1838+ }
15601839 else throw("Strict value is not equal to itself.")
15611840 }
15621841 else throw("Strict value is not equal to itself.")
15631842 }
15641843 else throw("Strict value is not equal to itself.")
15651844 }
15661845 else throw("Strict value is not equal to itself.")
15671846 }
1568- else throw("Strict value is not equal to itself.")
1569- }
1847+ }
1848+ else throw("Strict value is not equal to itself.")
15701849 }
15711850
15721851
15731852
15741853 @Callable(i)
15751854 func payFunding () = {
15761855 let fundingBlockTimestamp = nextFundingBlockTimestamp()
15771856 if (if (if ((fundingBlockTimestamp > lastBlock.timestamp))
15781857 then true
15791858 else !(initialized()))
15801859 then true
15811860 else paused())
15821861 then throw(((("Invalid funding block timestamp: " + toString(lastBlock.timestamp)) + " < ") + toString(fundingBlockTimestamp)))
15831862 else {
15841863 let underlyingPrice = getOracleTwapPrice()
1585- let $t06873668798 = getFunding()
1586- let shortPremiumFraction = $t06873668798._1
1587- let longPremiumFraction = $t06873668798._2
1864+ let $t07956079622 = getFunding()
1865+ let shortPremiumFraction = $t07956079622._1
1866+ let longPremiumFraction = $t07956079622._2
15881867 updateFunding((fundingBlockTimestamp + fundingPeriodSeconds()), (latestLongCumulativePremiumFraction() + longPremiumFraction), (latestShortCumulativePremiumFraction() + shortPremiumFraction), divd(longPremiumFraction, underlyingPrice), divd(shortPremiumFraction, underlyingPrice))
15891868 }
15901869 }
15911870
15921871
15931872
15941873 @Callable(i)
1595-func forceMoveAsset (_trader,_amount) = if (if ((addressFromPublicKey(adminPublicKey()) != i.caller))
1596- then true
1597- else (0 > _amount))
1598- then throw("Invalid forceMoveAsset parameters")
1599- else {
1600- let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), _amount], nil)
1601- if ((unstake == unstake))
1602- then (withdraw(addressFromStringValue(_trader), _amount) ++ updateBalance((cbalance() - _amount)))
1603- else throw("Strict value is not equal to itself.")
1604- }
1605-
1606-
1607-
1608-@Callable(i)
1609-func adjustPeg (_price) = if (if ((addressFromPublicKey(adminPublicKey()) != i.caller))
1610- then true
1611- else (0 > _price))
1612- then throw("Invalid adjustPeg parameters")
1613- else {
1614- let $t06978969875 = getPegAdjustCost(_price)
1615- let newQuoteAssetReserve = $t06978969875._1
1616- let pegChangeCost = $t06978969875._2
1617- if ((pegChangeCost == 0))
1618- then throw("Nothing to adjust")
1619- else if ((pegChangeCost > 0))
1620- then updateAmmReserves(newQuoteAssetReserve, bsAstR())
1621- else {
1622- let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), abs(pegChangeCost)], nil)
1623- if ((unstake == unstake))
1624- then {
1625- let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), abs(pegChangeCost))])
1626- if ((depositInsurance == depositInsurance))
1627- then (updateBalance((cbalance() - abs(pegChangeCost))) ++ updateAmmReserves(newQuoteAssetReserve, bsAstR()))
1628- else throw("Strict value is not equal to itself.")
1629- }
1630- else throw("Strict value is not equal to itself.")
1631- }
1632- }
1633-
1634-
1635-
1636-@Callable(i)
1637-func migrateLiquidity () = {
1638- let amount = cbalance()
1639- if ((amount > 0))
1640- then {
1641- let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [amount, toBase58String(quoteAsset())], nil)
1642- if ((unstake == unstake))
1643- then {
1644- let stake = invoke(managerAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), amount)])
1645- if ((stake == stake))
1646- then nil
1647- else throw("Strict value is not equal to itself.")
1648- }
1649- else throw("Strict value is not equal to itself.")
1650- }
1651- else nil
1652- }
1653-
1654-
1655-
1656-@Callable(i)
1657-func v_get (_trader) = {
1658- let $t07151671576 = internalClosePosition(_trader, false)
1659- let x1 = $t07151671576._1
1660- let x2 = $t07151671576._2
1661- let x3 = $t07151671576._3
1662- let x4 = $t07151671576._4
1663- throw((((s(x2) + s(x3)) + s(x4)) + s(getMarginRatio(_trader))))
1874+func syncTerminalPriceToOracle () = {
1875+ let $t08000480125 = getSyncTerminalPrice(getOracleTwapPrice())
1876+ let newQuoteAssetWeight = $t08000480125._1
1877+ let newBaseAssetWeight = $t08000480125._2
1878+ let marginToVault = $t08000480125._3
1879+ let lockBadDebt = invoke(vaultAddress(), "exchangeFreeAndLocked", [marginToVault], nil)
1880+ if ((lockBadDebt == lockBadDebt))
1881+ then updateAmmWeights(newQuoteAssetWeight, newBaseAssetWeight)
1882+ else throw("Strict value is not equal to itself.")
16641883 }
16651884
16661885
16671886
16681887 @Callable(i)
16691888 func view_calcRemainMarginWithFundingPayment (_trader) = {
1670- let $t07172371834 = getPosition(_trader)
1671- let positionSize = $t07172371834._1
1672- let positionMargin = $t07172371834._2
1673- let pon = $t07172371834._3
1674- let positionLstUpdCPF = $t07172371834._4
1675- let $t07183971940 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)
1676- let positionNotional = $t07183971940._1
1677- let unrealizedPnl = $t07183971940._2
1678- let $t07194572127 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl)
1679- let remainMargin = $t07194572127._1
1680- let badDebt = $t07194572127._2
1681- let fundingPayment = $t07194572127._3
1682- throw((((((s(remainMargin) + s(fundingPayment)) + s(getMarginRatio(_trader))) + s(unrealizedPnl)) + s(badDebt)) + s(positionNotional)))
1889+ let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil)
1890+ if ((sync == sync))
1891+ then {
1892+ let $t08050280603 = getPosition(_trader)
1893+ let positionSize = $t08050280603._1
1894+ let positionMargin = $t08050280603._2
1895+ let pon = $t08050280603._3
1896+ let positionLstUpdCPF = $t08050280603._4
1897+ let $t08060680707 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)
1898+ let positionNotional = $t08060680707._1
1899+ let unrealizedPnl = $t08060680707._2
1900+ let $t08071080882 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl)
1901+ let remainMargin = $t08071080882._1
1902+ let badDebt = $t08071080882._2
1903+ let fundingPayment = $t08071080882._3
1904+ throw((((((s(remainMargin) + s(fundingPayment)) + s(getMarginRatio(_trader))) + s(unrealizedPnl)) + s(badDebt)) + s(positionNotional)))
1905+ }
1906+ else throw("Strict value is not equal to itself.")
16831907 }
16841908
16851909
16861910
16871911 @Callable(i)
16881912 func view_getPegAdjustCost (_price) = {
1689- let cost = getPegAdjustCost(_price)
1690- throw(toString(cost._2))
1913+ let result = getSyncTerminalPrice(_price)
1914+ throw(toString(result._3))
1915+ }
1916+
1917+
1918+
1919+@Callable(i)
1920+func view_getTerminalAmmPrice () = {
1921+ let $t08122981310 = getTerminalAmmState()
1922+ let terminalQuoteAssetReserve = $t08122981310._1
1923+ let terminalBaseAssetReserve = $t08122981310._2
1924+ let price = divd(muld(terminalQuoteAssetReserve, qtAstW()), muld(terminalBaseAssetReserve, bsAstW()))
1925+ throw(toString(price))
16911926 }
16921927
16931928
16941929
16951930 @Callable(i)
16961931 func view_getFunding () = {
16971932 let underlyingPrice = getOracleTwapPrice()
1698- let $t07251872580 = getFunding()
1699- let shortPremiumFraction = $t07251872580._1
1700- let longPremiumFraction = $t07251872580._2
1933+ let $t08152981591 = getFunding()
1934+ let shortPremiumFraction = $t08152981591._1
1935+ let longPremiumFraction = $t08152981591._2
17011936 let longFunding = divd(longPremiumFraction, underlyingPrice)
17021937 let shortFunding = divd(shortPremiumFraction, underlyingPrice)
17031938 throw((((s(longFunding) + s(shortFunding)) + s(getTwapSpotPrice())) + s(getOracleTwapPrice())))
17041939 }
17051940
17061941
17071942
17081943 @Callable(i)
17091944 func view_getBorrowedByTrader (_trader) = {
1710- let $t07287072924 = getBorrowedByTrader(_trader)
1711- let borrowed = $t07287072924._1
1712- let assetId = $t07287072924._2
1945+ let $t08188181935 = getBorrowedByTrader(_trader)
1946+ let borrowed = $t08188181935._1
1947+ let assetId = $t08188181935._2
17131948 throw((s(borrowed) + assetId))
1949+ }
1950+
1951+
1952+
1953+@Callable(i)
1954+func computeSpotPrice () = {
1955+ let result = getSpotPrice()
1956+ $Tuple2(nil, result)
1957+ }
1958+
1959+
1960+
1961+@Callable(i)
1962+func computeFeeForTraderWithArtifact (_trader,_artifactId) = {
1963+ let result = getForTraderWithArtifact(_trader, _artifactId)
1964+ $Tuple2(nil, result)
17141965 }
17151966
17161967
17171968 @Verifier(tx)
17181969 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], adminPublicKey())
17191970

github/deemru/w8io/026f985 
265.53 ms