tx · 7Ke5qAXEXNEQRQdot1yCsaeaFN6kx6mt1KSCDuJj475D 3N7rPu8fJbSU4LaBm6xXpC6Q1mFMipUgcRQ: -0.04900000 Waves 2022.08.29 22:18 [2206149] smart account 3N7rPu8fJbSU4LaBm6xXpC6Q1mFMipUgcRQ > SELF 0.00000000 Waves
{ "type": 13, "id": "7Ke5qAXEXNEQRQdot1yCsaeaFN6kx6mt1KSCDuJj475D", "fee": 4900000, "feeAssetId": null, "timestamp": 1661800714796, "version": 2, "chainId": 84, "sender": "3N7rPu8fJbSU4LaBm6xXpC6Q1mFMipUgcRQ", "senderPublicKey": "9aasfTpGq8rpV4uUB9KaaHqqSrzvEw9t4pzXqv5N6BNr", "proofs": [ "3698F2JFngJzMJiupoeXPQhq9sxJC6FJkLhEbzRz4sNBo3oeqBuWjsY28pP8iN3t3yGXeWbsXgg6D1bNZPkEHEgq" ], "script": "base64:BgJiCAISABIAEgMKAQESAwoBARILCgkBAQEBAQEBAQESEAoOAQEBAQEBAQgICAEBAQESAwoBARIFCgMBAQESBQoDAQEBEgASAwoBARIAEgMKAQgSABIDCgEIEgMKAQgSBAoCCAF/AAlrX29yYV9rZXkCCWtfb3JhX2tleQAPa19vcmFfYmxvY2tfa2V5Ag9rX29yYV9ibG9ja19rZXkABWtfb3JhAgVrX29yYQAJa19iYWxhbmNlAglrX2JhbGFuY2UADmtfcG9zaXRpb25TaXplAg5rX3Bvc2l0aW9uU2l6ZQAQa19wb3NpdGlvbk1hcmdpbgIQa19wb3NpdGlvbk1hcmdpbgAWa19wb3NpdGlvbk9wZW5Ob3Rpb25hbAIWa19wb3NpdGlvbk9wZW5Ob3Rpb25hbAAua19wb3NpdGlvbkxhc3RVcGRhdGVkQ3VtdWxhdGl2ZVByZW1pdW1GcmFjdGlvbgISa19wb3NpdGlvbkZyYWN0aW9uAA1rX2luaXRpYWxpemVkAg1rX2luaXRpYWxpemVkAAhrX3BhdXNlZAIIa19wYXVzZWQABWtfZmVlAgVrX2ZlZQAP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Vuc3Rha2UJAPwHBAkBEXF1b3RlQXNzZXRTdGFraW5nAAIOdW5sb2NrTmV1dHJpbm8JAMwIAgUHX2Ftb3VudAkAzAgCCQDYBAEJAQpxdW90ZUFzc2V0AAUDbmlsBQNuaWwDCQAAAgUHdW5zdGFrZQUHdW5zdGFrZQkAzggCCQEId2l0aGRyYXcCCQERQGV4dHJOYXRpdmUoMTA2MikBBQdfdHJhZGVyBQdfYW1vdW50CQENdXBkYXRlQmFsYW5jZQEJAGUCCQEIY2JhbGFuY2UABQdfYW1vdW50CQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAQJ0eAEGdmVyaWZ5AAkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAkBDmFkbWluUHVibGljS2V5AMe2r1k=", "height": 2206149, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 5LBJHrHAkQY2P3EdAysM7dRKjEbDiFCgsCFCBs4AWAt5 Next: Emrnxf85FqHxe1TkbvntMWxmPcgemLyVMdYxYnLRP7az Diff:
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let k_ora_key = "k_ora_key" | |
5 | + | ||
6 | + | let k_ora_block_key = "k_ora_block_key" | |
5 | 7 | ||
6 | 8 | let k_ora = "k_ora" | |
7 | 9 | ||
29 | 31 | ||
30 | 32 | let k_liquidationFeeRatio = "k_liquidationFeeRatio" | |
31 | 33 | ||
34 | + | let k_partialLiquidationRatio = "k_partLiquidationRatio" | |
35 | + | ||
32 | 36 | let k_spreadLimit = "k_spreadLimit" | |
33 | 37 | ||
34 | 38 | let k_maxPriceImpact = "k_maxPriceImpact" | |
39 | + | ||
40 | + | let k_maxPriceSpread = "k_maxPriceSpread" | |
35 | 41 | ||
36 | 42 | let k_lastDataStr = "k_lastDataStr" | |
37 | 43 | ||
41 | 47 | ||
42 | 48 | let k_twapDataLastPrice = "k_twapDataLastPrice" | |
43 | 49 | ||
44 | - | let k_ | |
50 | + | let k_twapDataPreviousMinuteId = "k_twapDataPreviousMinuteId" | |
45 | 51 | ||
46 | 52 | let k_latestLongCumulativePremiumFraction = "k_latestLongPremiumFraction" | |
47 | 53 | ||
65 | 71 | ||
66 | 72 | let k_cumulativeNotional = "k_cumulativeNotional" | |
67 | 73 | ||
68 | - | let k_ | |
74 | + | let k_openInterestNotional = "k_openInterestNotional" | |
69 | 75 | ||
70 | 76 | let k_coordinatorAddress = "k_coordinatorAddress" | |
71 | 77 | ||
81 | 87 | ||
82 | 88 | let k_staking_address = "k_staking_address" | |
83 | 89 | ||
90 | + | let k_miner_address = "k_miner_address" | |
91 | + | ||
84 | 92 | func coordinator () = valueOrErrorMessage(addressFromString(getStringValue(this, k_coordinatorAddress)), "Coordinator not set") | |
85 | 93 | ||
86 | 94 | ||
93 | 101 | func quoteAsset () = fromBase58String(getStringValue(coordinator(), k_quote_asset)) | |
94 | 102 | ||
95 | 103 | ||
96 | - | func quoteAssetStaking () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_quote_staking)), "Quote | |
104 | + | func quoteAssetStaking () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_quote_staking)), "Quote asset staking not set") | |
97 | 105 | ||
98 | 106 | ||
99 | 107 | func stakingAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_staking_address)), "Insurance not set") | |
102 | 110 | func insuranceAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_insurance_address)), "Insurance not set") | |
103 | 111 | ||
104 | 112 | ||
113 | + | func minerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_miner_address)), "Insurance not set") | |
114 | + | ||
115 | + | ||
105 | 116 | let DIR_LONG = 1 | |
106 | 117 | ||
107 | 118 | let DIR_SHORT = 2 | |
108 | 119 | ||
109 | - | let | |
120 | + | let TWAP_INTERVAL = 15 | |
110 | 121 | ||
111 | - | let | |
122 | + | let ORACLE_INTERVAL = 15 | |
112 | 123 | ||
113 | 124 | let SECONDS = 1000 | |
114 | 125 | ||
136 | 147 | else -(_x) | |
137 | 148 | ||
138 | 149 | ||
150 | + | func vmax (_x,_y) = if ((_x >= _y)) | |
151 | + | then _x | |
152 | + | else _y | |
153 | + | ||
154 | + | ||
139 | 155 | func toCompositeKey (_key,_address) = ((_key + "_") + _address) | |
140 | 156 | ||
141 | 157 | ||
142 | - | func requireMoreMarginRatio (_marginRatio,_baseMarginRatio,_largerThanOrEqualTo) = { | |
143 | - | let remainingMarginRatio = (_marginRatio - _baseMarginRatio) | |
144 | - | if (if (_largerThanOrEqualTo) | |
145 | - | then (0 > remainingMarginRatio) | |
146 | - | else false) | |
147 | - | then throw("Invalid margin") | |
148 | - | else if (if (!(_largerThanOrEqualTo)) | |
149 | - | then (remainingMarginRatio >= 0) | |
150 | - | else false) | |
151 | - | then throw("Invalid margin") | |
152 | - | else true | |
158 | + | func listToStr (_list) = { | |
159 | + | func _join (accumulator,val) = ((accumulator + val) + ",") | |
160 | + | ||
161 | + | let newListStr = { | |
162 | + | let $l = _list | |
163 | + | let $s = size($l) | |
164 | + | let $acc0 = "" | |
165 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
166 | + | then $a | |
167 | + | else _join($a, $l[$i]) | |
168 | + | ||
169 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
170 | + | then $a | |
171 | + | else throw("List size exceeds 20") | |
172 | + | ||
173 | + | $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) | |
174 | + | } | |
175 | + | let newListStrU = dropRight(newListStr, 1) | |
176 | + | let newListStrR = if ((take(newListStrU, 1) == ",")) | |
177 | + | then drop(newListStrU, 1) | |
178 | + | else newListStrU | |
179 | + | newListStrR | |
153 | 180 | } | |
181 | + | ||
182 | + | ||
183 | + | func strToList (_str) = split(_str, ",") | |
184 | + | ||
185 | + | ||
186 | + | func pushToQueue (_list,_maxSize,_value) = if ((size(_list) > _maxSize)) | |
187 | + | then (removeByIndex(_list, 0) :+ _value) | |
188 | + | else (_list :+ _value) | |
154 | 189 | ||
155 | 190 | ||
156 | 191 | func int (k) = valueOrErrorMessage(getInteger(this, k), ("no value for " + k)) | |
177 | 212 | func cumulativeNotional () = int(k_cumulativeNotional) | |
178 | 213 | ||
179 | 214 | ||
180 | - | func | |
215 | + | func openInterestNotional () = int(k_openInterestNotional) | |
181 | 216 | ||
182 | 217 | ||
183 | 218 | func nextFundingBlockTimestamp () = int(k_nextFundingBlock) | |
192 | 227 | func fundingPeriodSeconds () = (fundingPeriodRaw() * SECONDS) | |
193 | 228 | ||
194 | 229 | ||
195 | - | func | |
230 | + | func maintenanceMarginRatio () = int(k_maintenanceMarginRatio) | |
196 | 231 | ||
197 | 232 | ||
198 | 233 | func liquidationFeeRatio () = int(k_liquidationFeeRatio) | |
234 | + | ||
235 | + | ||
236 | + | func partialLiquidationRatio () = int(k_partialLiquidationRatio) | |
199 | 237 | ||
200 | 238 | ||
201 | 239 | func spreadLimit () = int(k_spreadLimit) | |
202 | 240 | ||
203 | 241 | ||
204 | 242 | func maxPriceImpact () = int(k_maxPriceImpact) | |
243 | + | ||
244 | + | ||
245 | + | func maxPriceSpread () = int(k_maxPriceSpread) | |
205 | 246 | ||
206 | 247 | ||
207 | 248 | func latestLongCumulativePremiumFraction () = int(k_latestLongCumulativePremiumFraction) | |
216 | 257 | func totalLongPositionSize () = int(k_totalLongPositionSize) | |
217 | 258 | ||
218 | 259 | ||
219 | - | func latestCPF (_positionSize) = if ((_positionSize > 0)) | |
220 | - | then latestLongCumulativePremiumFraction() | |
221 | - | else latestShortCumulativePremiumFraction() | |
260 | + | func requireMoreMarginRatio (_marginRatio,_baseMarginRatio,_largerThanOrEqualTo) = { | |
261 | + | let remainingMarginRatio = (_marginRatio - _baseMarginRatio) | |
262 | + | if (if (_largerThanOrEqualTo) | |
263 | + | then (0 > remainingMarginRatio) | |
264 | + | else false) | |
265 | + | then throw("Invalid margin") | |
266 | + | else if (if (!(_largerThanOrEqualTo)) | |
267 | + | then (remainingMarginRatio >= 0) | |
268 | + | else false) | |
269 | + | then throw("Invalid margin") | |
270 | + | else true | |
271 | + | } | |
222 | 272 | ||
223 | 273 | ||
224 | - | func getPosition (invesor) = { | |
225 | - | let positionSizeOpt = getInteger(this, toCompositeKey(k_positionSize, invesor)) | |
274 | + | func latestCumulativePremiumFraction (_positionSize) = if ((_positionSize == 0)) | |
275 | + | then throw("Should not be called with _positionSize == 0") | |
276 | + | else if ((_positionSize > 0)) | |
277 | + | then latestLongCumulativePremiumFraction() | |
278 | + | else latestShortCumulativePremiumFraction() | |
279 | + | ||
280 | + | ||
281 | + | func getPosition (_trader) = { | |
282 | + | let positionSizeOpt = getInteger(this, toCompositeKey(k_positionSize, _trader)) | |
226 | 283 | match positionSizeOpt { | |
227 | 284 | case positionSize: Int => | |
228 | - | $Tuple4(positionSize, getIntegerValue(this, toCompositeKey(k_positionMargin, | |
285 | + | $Tuple4(positionSize, getIntegerValue(this, toCompositeKey(k_positionMargin, _trader)), getIntegerValue(this, toCompositeKey(k_positionOpenNotional, _trader)), getIntegerValue(this, toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _trader))) | |
229 | 286 | case _ => | |
230 | 287 | $Tuple4(0, 0, 0, 0) | |
231 | 288 | } | |
261 | 318 | func swapInput (_isAdd,_quoteAssetAmount) = { | |
262 | 319 | let _qtAstR = qtAstR() | |
263 | 320 | let _bsAstR = bsAstR() | |
264 | - | let priceBefore = divd(_qtAstR, _bsAstR) | |
265 | - | let amountBaseAssetBoughtWithoutPriceImpact = muld(_quoteAssetAmount, priceBefore) | |
266 | 321 | let k = muld(_qtAstR, _bsAstR) | |
267 | 322 | let quoteAssetReserveAfter = if (_isAdd) | |
268 | 323 | then (_qtAstR + _quoteAssetAmount) | |
272 | 327 | let amountBaseAssetBought = if (_isAdd) | |
273 | 328 | then amountBaseAssetBoughtAbs | |
274 | 329 | else -(amountBaseAssetBoughtAbs) | |
275 | - | let priceImpact = ((amountBaseAssetBoughtWithoutPriceImpact - amountBaseAssetBoughtAbs) / amountBaseAssetBoughtWithoutPriceImpact) | |
330 | + | let $t01217712370 = updateReserve(_isAdd, _quoteAssetAmount, amountBaseAssetBoughtAbs) | |
331 | + | let quoteAssetReserveAfter1 = $t01217712370._1 | |
332 | + | let baseAssetReserveAfter1 = $t01217712370._2 | |
333 | + | let totalPositionSizeAfter1 = $t01217712370._3 | |
334 | + | let cumulativeNotionalAfter1 = $t01217712370._4 | |
335 | + | let priceBefore = divd(_qtAstR, _bsAstR) | |
336 | + | let marketPrice = divd(_quoteAssetAmount, amountBaseAssetBoughtAbs) | |
337 | + | let priceDiff = abs((priceBefore - marketPrice)) | |
338 | + | let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff))) | |
276 | 339 | let maxPriceImpactValue = maxPriceImpact() | |
277 | 340 | if ((priceImpact > maxPriceImpactValue)) | |
278 | - | then throw(((("Price impact " + toString(priceImpact)) + " > max price impact ") + toString(maxPriceImpactValue))) | |
341 | + | 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))) | |
342 | + | else $Tuple5(amountBaseAssetBought, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, cumulativeNotionalAfter1) | |
343 | + | } | |
344 | + | ||
345 | + | ||
346 | + | func calcRemainMarginWithFundingPayment (_oldPositionSize,_oldPositionMargin,_oldPositionCumulativePremiumFraction,_marginDelta) = { | |
347 | + | let fundingPayment = if ((_oldPositionSize != 0)) | |
348 | + | then { | |
349 | + | let _latestCumulativePremiumFraction = latestCumulativePremiumFraction(_oldPositionSize) | |
350 | + | muld((_latestCumulativePremiumFraction - _oldPositionCumulativePremiumFraction), _oldPositionSize) | |
351 | + | } | |
352 | + | else 0 | |
353 | + | let signedMargin = ((_marginDelta - fundingPayment) + _oldPositionMargin) | |
354 | + | let $t01386113988 = if ((0 > signedMargin)) | |
355 | + | then $Tuple2(0, abs(signedMargin)) | |
356 | + | else $Tuple2(abs(signedMargin), 0) | |
357 | + | let remainMargin = $t01386113988._1 | |
358 | + | let badDebt = $t01386113988._2 | |
359 | + | $Tuple3(remainMargin, badDebt, fundingPayment) | |
360 | + | } | |
361 | + | ||
362 | + | ||
363 | + | func swapOutputWithReserves (_isAdd,_baseAssetAmount,_checkMaxPriceImpact,_quoteAssetReserve,_baseAssetReserve) = { | |
364 | + | let priceBefore = divd(_quoteAssetReserve, _baseAssetReserve) | |
365 | + | if ((_baseAssetAmount == 0)) | |
366 | + | then throw("Invalid base asset amount") | |
279 | 367 | else { | |
280 | - | let $t01037810581 = updateReserve(_isAdd, _quoteAssetAmount, amountBaseAssetBoughtAbs) | |
281 | - | let quoteAssetReserveAfter1 = $t01037810581._1 | |
282 | - | let baseAssetReserveAfter1 = $t01037810581._2 | |
283 | - | let totalPositionSizeAfter1 = $t01037810581._3 | |
284 | - | let cumulativeNotionalAfter1 = $t01037810581._4 | |
285 | - | $Tuple5(amountBaseAssetBought, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, cumulativeNotionalAfter1) | |
368 | + | let k = muld(_quoteAssetReserve, _baseAssetReserve) | |
369 | + | let baseAssetPoolAmountAfter = if (_isAdd) | |
370 | + | then (_baseAssetReserve + _baseAssetAmount) | |
371 | + | else (_baseAssetReserve - _baseAssetAmount) | |
372 | + | let quoteAssetAfter = divd(k, baseAssetPoolAmountAfter) | |
373 | + | let quoteAssetSold = abs((quoteAssetAfter - _quoteAssetReserve)) | |
374 | + | let maxPriceImpactValue = maxPriceImpact() | |
375 | + | let $t01496515158 = updateReserve(!(_isAdd), quoteAssetSold, _baseAssetAmount) | |
376 | + | let quoteAssetReserveAfter1 = $t01496515158._1 | |
377 | + | let baseAssetReserveAfter1 = $t01496515158._2 | |
378 | + | let totalPositionSizeAfter1 = $t01496515158._3 | |
379 | + | let cumulativeNotionalAfter1 = $t01496515158._4 | |
380 | + | let marketPrice = divd(quoteAssetSold, _baseAssetAmount) | |
381 | + | let priceDiff = abs((priceBefore - marketPrice)) | |
382 | + | let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff))) | |
383 | + | if (if ((priceImpact > maxPriceImpactValue)) | |
384 | + | then _checkMaxPriceImpact | |
385 | + | else false) | |
386 | + | 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))) | |
387 | + | else $Tuple8(quoteAssetSold, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, cumulativeNotionalAfter1, (totalLongPositionSize() - (if (_isAdd) | |
388 | + | then abs(_baseAssetAmount) | |
389 | + | else 0)), (totalShortPositionSize() - (if (!(_isAdd)) | |
390 | + | then abs(_baseAssetAmount) | |
391 | + | else 0)), priceImpact) | |
286 | 392 | } | |
287 | 393 | } | |
288 | 394 | ||
289 | 395 | ||
290 | - | func calcRemainMarginWithFundingPayment (_oldPositionSize,_oldPositionMargin,_oldPositionLstUpdCPF,_marginDelta) = { | |
291 | - | let _latestCPF = latestCPF(_oldPositionSize) | |
292 | - | let fundingPayment = if ((_oldPositionSize != 0)) | |
293 | - | then muld((_latestCPF - _oldPositionLstUpdCPF), _oldPositionSize) | |
294 | - | else 0 | |
295 | - | let signedMargin = ((_marginDelta - fundingPayment) + _oldPositionMargin) | |
296 | - | let $t01117011297 = if ((0 > signedMargin)) | |
297 | - | then $Tuple2(0, abs(signedMargin)) | |
298 | - | else $Tuple2(abs(signedMargin), 0) | |
299 | - | let remainMargin = $t01117011297._1 | |
300 | - | let badDebt = $t01117011297._2 | |
301 | - | $Tuple4(remainMargin, badDebt, fundingPayment, _latestCPF) | |
302 | - | } | |
303 | - | ||
304 | - | ||
305 | - | func swapOutput (_isAdd,_baseAssetAmount,_quoteAssetPoolAmount,_baseAssetPoolAmount) = if ((_baseAssetAmount == 0)) | |
306 | - | then throw("Invalid base asset amount") | |
307 | - | else { | |
308 | - | let k = muld(_quoteAssetPoolAmount, _baseAssetPoolAmount) | |
309 | - | let baseAssetPoolAmountAfter = if (_isAdd) | |
310 | - | then (_baseAssetPoolAmount + _baseAssetAmount) | |
311 | - | else (_baseAssetPoolAmount - _baseAssetAmount) | |
312 | - | let quoteAssetAfter = divd(k, baseAssetPoolAmountAfter) | |
313 | - | let quoteAssetSold = abs((quoteAssetAfter - _quoteAssetPoolAmount)) | |
314 | - | let $t01193412127 = updateReserve(!(_isAdd), quoteAssetSold, _baseAssetAmount) | |
315 | - | let quoteAssetReserveAfter1 = $t01193412127._1 | |
316 | - | let baseAssetReserveAfter1 = $t01193412127._2 | |
317 | - | let totalPositionSizeAfter1 = $t01193412127._3 | |
318 | - | let cumulativeNotionalAfter1 = $t01193412127._4 | |
319 | - | $Tuple7(quoteAssetSold, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, cumulativeNotionalAfter1, (totalLongPositionSize() - (if (_isAdd) | |
320 | - | then abs(_baseAssetAmount) | |
321 | - | else 0)), (totalShortPositionSize() - (if (!(_isAdd)) | |
322 | - | then abs(_baseAssetAmount) | |
323 | - | else 0))) | |
324 | - | } | |
396 | + | func swapOutput (_isAdd,_baseAssetAmount,_checkMaxPriceImpact) = swapOutputWithReserves(_isAdd, _baseAssetAmount, _checkMaxPriceImpact, qtAstR(), bsAstR()) | |
325 | 397 | ||
326 | 398 | ||
327 | 399 | func getOracleTwapPrice () = { | |
328 | 400 | let oracle = valueOrErrorMessage(addressFromString(getStringValue(this, k_ora)), "") | |
329 | 401 | let priceKey = getStringValue(this, k_ora_key) | |
330 | - | getIntegerValue(oracle, priceKey) | |
402 | + | let blockKey = getStringValue(this, k_ora_block_key) | |
403 | + | let lastValue = valueOrErrorMessage(getInteger(oracle, priceKey), ((("Can not get oracle price. Oracle: " + toString(oracle)) + " key: ") + priceKey)) | |
404 | + | lastValue | |
405 | + | } | |
406 | + | ||
407 | + | ||
408 | + | func requireNotOverSpreadLimit (_quoteAssetReserve,_baseAssetReserve) = { | |
409 | + | let oraclePrice = getOracleTwapPrice() | |
410 | + | let priceAfter = divd(_quoteAssetReserve, _baseAssetReserve) | |
411 | + | let averagePrice = divd((oraclePrice + priceAfter), (2 * DECIMAL_UNIT)) | |
412 | + | let absPriceDiff = divd(abs((oraclePrice - priceAfter)), averagePrice) | |
413 | + | if ((absPriceDiff > maxPriceSpread())) | |
414 | + | then throw(((("Price spread " + toString(absPriceDiff)) + " > max price spread ") + toString(maxPriceSpread()))) | |
415 | + | else true | |
331 | 416 | } | |
332 | 417 | ||
333 | 418 | ||
334 | 419 | func getSpotPrice () = { | |
335 | - | let _ | |
336 | - | let _ | |
337 | - | divd(_ | |
420 | + | let _quoteAssetReserve = qtAstR() | |
421 | + | let _baseAssetReserve = bsAstR() | |
422 | + | divd(_quoteAssetReserve, _baseAssetReserve) | |
338 | 423 | } | |
339 | 424 | ||
340 | 425 | ||
345 | 430 | } | |
346 | 431 | ||
347 | 432 | ||
433 | + | func getPositionAdjustedOpenNotional (_positionSize,_option,_quoteAssetReserve,_baseAssetReserve) = { | |
434 | + | let positionSizeAbs = abs(_positionSize) | |
435 | + | let isShort = (0 > _positionSize) | |
436 | + | let positionNotional = if ((_option == PNL_OPTION_SPOT)) | |
437 | + | then { | |
438 | + | let $t01837618547 = swapOutputWithReserves(!(isShort), positionSizeAbs, false, _quoteAssetReserve, _baseAssetReserve) | |
439 | + | let outPositionNotional = $t01837618547._1 | |
440 | + | let x1 = $t01837618547._2 | |
441 | + | let x2 = $t01837618547._3 | |
442 | + | let x3 = $t01837618547._4 | |
443 | + | outPositionNotional | |
444 | + | } | |
445 | + | else muld(positionSizeAbs, getOracleTwapPrice()) | |
446 | + | positionNotional | |
447 | + | } | |
448 | + | ||
449 | + | ||
348 | 450 | func getPositionNotionalAndUnrealizedPnl (_trader,_option) = { | |
349 | - | let $t01301913147 = getPosition(_trader) | |
350 | - | let positionSize = $t01301913147._1 | |
351 | - | let positionMargin = $t01301913147._2 | |
352 | - | let positionOpenNotional = $t01301913147._3 | |
353 | - | let positionLstUpdCPF = $t01301913147._4 | |
354 | - | let positionSizeAbs = abs(positionSize) | |
355 | - | if ((positionSizeAbs == 0)) | |
451 | + | let $t01894119069 = getPosition(_trader) | |
452 | + | let positionSize = $t01894119069._1 | |
453 | + | let positionMargin = $t01894119069._2 | |
454 | + | let positionOpenNotional = $t01894119069._3 | |
455 | + | let positionLstUpdCPF = $t01894119069._4 | |
456 | + | if ((positionSize == 0)) | |
356 | 457 | then throw("Invalid position size") | |
357 | 458 | else { | |
358 | 459 | let isShort = (0 > positionSize) | |
359 | - | let positionNotional = if ((_option == PNL_OPTION_SPOT)) | |
360 | - | then { | |
361 | - | let $t01339413541 = swapOutput(!(isShort), positionSizeAbs, qtAstR(), bsAstR()) | |
362 | - | let outPositionNotional = $t01339413541._1 | |
363 | - | let x1 = $t01339413541._2 | |
364 | - | let x2 = $t01339413541._3 | |
365 | - | let x3 = $t01339413541._4 | |
366 | - | outPositionNotional | |
367 | - | } | |
368 | - | else (positionSizeAbs * getOracleTwapPrice()) | |
460 | + | let positionNotional = getPositionAdjustedOpenNotional(positionSize, _option, qtAstR(), bsAstR()) | |
369 | 461 | let unrealizedPnl = if (isShort) | |
370 | 462 | then (positionOpenNotional - positionNotional) | |
371 | 463 | else (positionNotional - positionOpenNotional) | |
374 | 466 | } | |
375 | 467 | ||
376 | 468 | ||
469 | + | func calcMarginRatio (_remainMargin,_badDebt,_positionNotional) = divd((_remainMargin - _badDebt), _positionNotional) | |
470 | + | ||
471 | + | ||
377 | 472 | func getMarginRatioByOption (_trader,_option) = { | |
378 | - | func x () = 0 | |
379 | - | ||
380 | - | let $t01396514076 = getPosition(_trader) | |
381 | - | let positionSize = $t01396514076._1 | |
382 | - | let positionMargin = $t01396514076._2 | |
383 | - | let pon = $t01396514076._3 | |
384 | - | let positionLstUpdCPF = $t01396514076._4 | |
385 | - | let $t01408214175 = getPositionNotionalAndUnrealizedPnl(_trader, _option) | |
386 | - | let positionNotional = $t01408214175._1 | |
387 | - | let unrealizedPnl = $t01408214175._2 | |
388 | - | let $t01418014346 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
389 | - | let remainMargin = $t01418014346._1 | |
390 | - | let badDebt = $t01418014346._2 | |
391 | - | divd((remainMargin - badDebt), positionNotional) | |
473 | + | let $t01990220013 = getPosition(_trader) | |
474 | + | let positionSize = $t01990220013._1 | |
475 | + | let positionMargin = $t01990220013._2 | |
476 | + | let pon = $t01990220013._3 | |
477 | + | let positionLstUpdCPF = $t01990220013._4 | |
478 | + | let $t02001920112 = getPositionNotionalAndUnrealizedPnl(_trader, _option) | |
479 | + | let positionNotional = $t02001920112._1 | |
480 | + | let unrealizedPnl = $t02001920112._2 | |
481 | + | let $t02011720283 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
482 | + | let remainMargin = $t02011720283._1 | |
483 | + | let badDebt = $t02011720283._2 | |
484 | + | calcMarginRatio(remainMargin, badDebt, positionNotional) | |
392 | 485 | } | |
393 | 486 | ||
394 | 487 | ||
395 | 488 | func getMarginRatio (_trader) = getMarginRatioByOption(_trader, PNL_OPTION_SPOT) | |
396 | 489 | ||
397 | 490 | ||
398 | - | func internalClosePosition (_trader) = { | |
399 | - | let $t01454214653 = getPosition(_trader) | |
400 | - | let positionSize = $t01454214653._1 | |
401 | - | let positionMargin = $t01454214653._2 | |
402 | - | let pon = $t01454214653._3 | |
403 | - | let positionLstUpdCPF = $t01454214653._4 | |
404 | - | let $t01465914746 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
405 | - | let x1 = $t01465914746._1 | |
406 | - | let unrealizedPnl = $t01465914746._2 | |
407 | - | let $t01475114923 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
408 | - | let remainMargin = $t01475114923._1 | |
409 | - | let badDebt = $t01475114923._2 | |
410 | - | let x2 = $t01475114923._3 | |
491 | + | func getPartialLiquidationAmount (_trader,_positionSize) = { | |
492 | + | let maximumRatio = vmax(partialLiquidationRatio(), (DECIMAL_UNIT - divd(getMarginRatio(_trader), maintenanceMarginRatio()))) | |
493 | + | let maxExchangedPositionSize = muld(abs(_positionSize), maximumRatio) | |
494 | + | let swapResult = swapOutput((_positionSize > 0), maxExchangedPositionSize, false) | |
495 | + | let maxExchangedQuoteAssetAmount = swapResult._1 | |
496 | + | let priceImpact = swapResult._8 | |
497 | + | if ((maxPriceImpact() > priceImpact)) | |
498 | + | then maxExchangedQuoteAssetAmount | |
499 | + | else { | |
500 | + | let exchangedPositionSize = muld(abs(_positionSize), partialLiquidationRatio()) | |
501 | + | let exchangedQuoteAssetAmount = swapOutput((_positionSize > 0), exchangedPositionSize, false)._1 | |
502 | + | exchangedQuoteAssetAmount | |
503 | + | } | |
504 | + | } | |
505 | + | ||
506 | + | ||
507 | + | func internalClosePosition (_trader,_checkMaxPriceImpact) = { | |
508 | + | let $t02146521593 = getPosition(_trader) | |
509 | + | let positionSize = $t02146521593._1 | |
510 | + | let positionMargin = $t02146521593._2 | |
511 | + | let positionOpenNotional = $t02146521593._3 | |
512 | + | let positionLstUpdCPF = $t02146521593._4 | |
513 | + | let unrealizedPnl = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)._2 | |
514 | + | let $t02168821856 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
515 | + | let remainMargin = $t02168821856._1 | |
516 | + | let badDebt = $t02168821856._2 | |
411 | 517 | let exchangedPositionSize = -(positionSize) | |
412 | 518 | let realizedPnl = unrealizedPnl | |
413 | 519 | let marginToVault = -(remainMargin) | |
414 | - | let $ | |
415 | - | let exchangedQuoteAssetAmount = $ | |
416 | - | let quoteAssetReserveAfter = $ | |
417 | - | let baseAssetReserveAfter = $ | |
418 | - | let totalPositionSizeAfter = $ | |
419 | - | let cumulativeNotionalAfter = $ | |
420 | - | let totalLongAfter = $ | |
421 | - | let totalShortAfter = $ | |
422 | - | let | |
423 | - | $Tuple12(exchangedPositionSize, badDebt, realizedPnl, marginToVault, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, | |
520 | + | let $t02198322294 = swapOutput((positionSize > 0), abs(positionSize), _checkMaxPriceImpact) | |
521 | + | let exchangedQuoteAssetAmount = $t02198322294._1 | |
522 | + | let quoteAssetReserveAfter = $t02198322294._2 | |
523 | + | let baseAssetReserveAfter = $t02198322294._3 | |
524 | + | let totalPositionSizeAfter = $t02198322294._4 | |
525 | + | let cumulativeNotionalAfter = $t02198322294._5 | |
526 | + | let totalLongAfter = $t02198322294._6 | |
527 | + | let totalShortAfter = $t02198322294._7 | |
528 | + | let openInterestNotionalAfter = (openInterestNotional() - positionOpenNotional) | |
529 | + | $Tuple12(exchangedPositionSize, badDebt, realizedPnl, marginToVault, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, exchangedQuoteAssetAmount, totalLongAfter, totalShortAfter) | |
424 | 530 | } | |
425 | 531 | ||
426 | 532 | ||
429 | 535 | let startMinuteId = (minuteId - TWAP_INTERVAL) | |
430 | 536 | let listStr = valueOrElse(getString(this, k_lastDataStr), "") | |
431 | 537 | let list = split(listStr, ",") | |
432 | - | func filterFn ( | |
433 | - | then ( | |
434 | - | else | |
538 | + | func filterFn (accumulator,next) = if ((startMinuteId >= parseIntValue(next))) | |
539 | + | then (accumulator :+ parseIntValue(next)) | |
540 | + | else accumulator | |
435 | 541 | ||
436 | 542 | let listF = { | |
437 | 543 | let $l = list | |
453 | 559 | let lastMinuteId = valueOrElse(getInteger(this, k_lastMinuteId), 0) | |
454 | 560 | let endLastCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(lastMinuteId))), 0) | |
455 | 561 | let endLastPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(lastMinuteId))), 0) | |
456 | - | let | |
562 | + | let nowCumulativePrice = (endLastCumulativePrice + ((minuteId - lastMinuteId) * endLastPrice)) | |
457 | 563 | let startLastCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(maxIndex))), 0) | |
458 | 564 | let startLastPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(maxIndex))), 0) | |
459 | - | let | |
460 | - | (( | |
565 | + | let startCumulativePrice = (startLastCumulativePrice + ((startMinuteId - maxIndex) * startLastPrice)) | |
566 | + | ((nowCumulativePrice - startCumulativePrice) / TWAP_INTERVAL) | |
461 | 567 | } | |
462 | 568 | ||
463 | 569 | ||
464 | - | func updateSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact) = [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)] | |
570 | + | 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)] | |
465 | 571 | ||
466 | 572 | ||
467 | 573 | 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)] | |
468 | 574 | ||
469 | 575 | ||
470 | - | func updatePosition (_address,_size,_margin,_ | |
576 | + | 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)] | |
471 | 577 | ||
472 | 578 | ||
473 | 579 | func appendTwap (price) = { | |
479 | 585 | let lastMinuteId = if ((previousMinuteId == 0)) | |
480 | 586 | then minuteId | |
481 | 587 | else previousMinuteId | |
482 | - | let listStr = valueOrElse(getString(this, k_lastDataStr), "") | |
483 | - | let oldList = split(listStr, ",") | |
484 | - | let list = if ((size(oldList) > TWAP_INTERVAL)) | |
485 | - | then (removeByIndex(oldList, 0) :+ toString(minuteId)) | |
486 | - | else (oldList :+ toString(minuteId)) | |
487 | - | let prevCummulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(previousMinuteId))), 0) | |
488 | - | let prevPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(previousMinuteId))), price) | |
489 | - | let lastCummulativePrice = (prevCummulativePrice + ((minuteId - lastMinuteId) * prevPrice)) | |
490 | - | func join (accum,val) = ((accum + val) + ",") | |
491 | - | ||
492 | - | let newListStr = { | |
493 | - | let $l = list | |
494 | - | let $s = size($l) | |
495 | - | let $acc0 = "" | |
496 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
497 | - | then $a | |
498 | - | else join($a, $l[$i]) | |
499 | - | ||
500 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
501 | - | then $a | |
502 | - | else throw("List size exceeds 20") | |
503 | - | ||
504 | - | $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) | |
505 | - | } | |
506 | - | let newListStrU = dropRight(newListStr, 1) | |
507 | - | let newListStrR = if ((take(newListStrU, 1) == ",")) | |
508 | - | then drop(newListStrU, 1) | |
509 | - | else newListStrU | |
510 | - | [IntegerEntry(((k_twapDataLastCumulativePrice + "_") + toString(minuteId)), lastCummulativePrice), IntegerEntry(((k_twapDataLastPrice + "_") + toString(minuteId)), price), IntegerEntry(k_lastMinuteId, minuteId), StringEntry(k_lastDataStr, newListStrR)] | |
588 | + | if ((minuteId > previousMinuteId)) | |
589 | + | then { | |
590 | + | let prevCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(previousMinuteId))), 0) | |
591 | + | let prevPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(previousMinuteId))), price) | |
592 | + | let lastCumulativePrice = (prevCumulativePrice + ((minuteId - lastMinuteId) * prevPrice)) | |
593 | + | let list = pushToQueue(strToList(valueOrElse(getString(this, k_lastDataStr), "")), TWAP_INTERVAL, toString(minuteId)) | |
594 | + | [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))] | |
595 | + | } | |
596 | + | else { | |
597 | + | let twapDataPreviousMinuteId = valueOrElse(getInteger(this, toCompositeKey(k_twapDataPreviousMinuteId, toString(minuteId))), 0) | |
598 | + | let prevCumulativePrice = valueOrElse(getInteger(this, toCompositeKey(k_twapDataLastCumulativePrice, toString(twapDataPreviousMinuteId))), 0) | |
599 | + | let prevPrice = valueOrElse(getInteger(this, toCompositeKey(k_twapDataLastPrice, toString(twapDataPreviousMinuteId))), price) | |
600 | + | let lastCumulativePrice = (prevCumulativePrice + ((minuteId - twapDataPreviousMinuteId) * prevPrice)) | |
601 | + | [IntegerEntry(toCompositeKey(k_twapDataLastCumulativePrice, toString(minuteId)), lastCumulativePrice), IntegerEntry(toCompositeKey(k_twapDataLastPrice, toString(minuteId)), price)] | |
602 | + | } | |
511 | 603 | } | |
512 | 604 | } | |
513 | 605 | ||
514 | 606 | ||
515 | - | func updateAmm (_qtAstR,_bsAstR,_totalPositionSizeAfter,_cumulativeNotionalAfter,_openInteresetNotional,_totalLongPositionSize,_totalShortPositionSize) = if (((_totalLongPositionSize - _totalShortPositionSize) != _totalPositionSizeAfter)) | |
607 | + | func updateAmmReserves (_qtAstR,_bsAstR) = [IntegerEntry(k_quoteAssetReserve, _qtAstR), IntegerEntry(k_baseAssetReserve, _bsAstR)] | |
608 | + | ||
609 | + | ||
610 | + | func updateAmm (_qtAstR,_bsAstR,_totalPositionSizeAfter,_cumulativeNotionalAfter,_openInterestNotional,_totalLongPositionSize,_totalShortPositionSize) = if (((_totalLongPositionSize - _totalShortPositionSize) != _totalPositionSizeAfter)) | |
516 | 611 | then throw(((((("Invalid AMM state data: " + toString(_totalLongPositionSize)) + " + ") + toString(_totalShortPositionSize)) + " != ") + toString(_totalPositionSizeAfter))) | |
517 | - | else ( | |
612 | + | 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))) | |
518 | 613 | ||
519 | 614 | ||
520 | 615 | func deletePosition (_address) = [DeleteEntry(toCompositeKey(k_positionSize, _address)), DeleteEntry(toCompositeKey(k_positionMargin, _address)), DeleteEntry(toCompositeKey(k_positionOpenNotional, _address)), DeleteEntry(toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _address))] | |
551 | 646 | ||
552 | 647 | ||
553 | 648 | @Callable(i) | |
554 | - | func changeSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact) = if ((i.caller != adminAddress())) | |
555 | - | then throw("Invalid changeSettings params") | |
556 | - | else updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact) | |
649 | + | func addLiquidity (_quoteAssetAmount) = if (if ((i.caller != adminAddress())) | |
650 | + | then true | |
651 | + | else (0 >= _quoteAssetAmount)) | |
652 | + | then throw("Invalid addLiquidity params") | |
653 | + | else { | |
654 | + | let _qtAstR = qtAstR() | |
655 | + | let _bsAstR = bsAstR() | |
656 | + | let price = divd(_qtAstR, _bsAstR) | |
657 | + | let baseAssetAmountToAdd = divd(_quoteAssetAmount, price) | |
658 | + | let qtAstRAfter = (_qtAstR + _quoteAssetAmount) | |
659 | + | let bsAstRAfter = (_bsAstR + baseAssetAmountToAdd) | |
660 | + | updateAmmReserves(qtAstRAfter, bsAstRAfter) | |
661 | + | } | |
557 | 662 | ||
558 | 663 | ||
559 | 664 | ||
560 | 665 | @Callable(i) | |
561 | - | func initialize (_qtAstR,_bsAstR,_fundingPeriod,_initMarginRatio,_mmr,_liquidationFeeRatio,_fee,_oracle,_oracleKey,_coordinator,_spreadLimit,_maxPriceImpact) = if (if (if (if (if (if (if (if (if (if ((0 >= _qtAstR)) | |
666 | + | func removeLiquidity (_quoteAssetAmount) = if (if ((i.caller != adminAddress())) | |
667 | + | then true | |
668 | + | else (0 >= _quoteAssetAmount)) | |
669 | + | then throw("Invalid removeLiquidity params") | |
670 | + | else { | |
671 | + | let _qtAstR = qtAstR() | |
672 | + | let _bsAstR = bsAstR() | |
673 | + | let price = divd(_qtAstR, _bsAstR) | |
674 | + | let baseAssetAmountToRemove = divd(_quoteAssetAmount, price) | |
675 | + | let qtAstRAfter = (_qtAstR - _quoteAssetAmount) | |
676 | + | let bsAstRAfter = (_bsAstR - baseAssetAmountToRemove) | |
677 | + | updateAmmReserves(qtAstRAfter, bsAstRAfter) | |
678 | + | } | |
679 | + | ||
680 | + | ||
681 | + | ||
682 | + | @Callable(i) | |
683 | + | func changeSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread) = if ((i.caller != adminAddress())) | |
684 | + | then throw("Invalid changeSettings params") | |
685 | + | else updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread) | |
686 | + | ||
687 | + | ||
688 | + | ||
689 | + | @Callable(i) | |
690 | + | 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)) | |
562 | 691 | then true | |
563 | 692 | else (0 >= _bsAstR)) | |
564 | 693 | then true | |
576 | 705 | then true | |
577 | 706 | else (0 >= _maxPriceImpact)) | |
578 | 707 | then true | |
708 | + | else (0 >= _partialLiquidationRatio)) | |
709 | + | then true | |
710 | + | else (0 >= _maxPriceSpread)) | |
711 | + | then true | |
579 | 712 | else initialized()) | |
580 | 713 | then throw("Invalid initialize parameters") | |
581 | - | else ((((updateAmm(_qtAstR, _bsAstR, 0, 0, 0, 0, 0) ++ updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact)) ++ 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)]) | |
714 | + | 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)]) | |
582 | 715 | ||
583 | 716 | ||
584 | 717 | ||
585 | 718 | @Callable(i) | |
586 | - | func decreasePosition (_direction,_amount,_leverage,_minBaseAssetAmount) = if (if (if (if (if (if (if ((_direction != DIR_LONG)) | |
587 | - | then (_direction != DIR_SHORT) | |
588 | - | else false) | |
719 | + | func setInitMarginRatio (_initMarginRatio) = if (if ((0 >= _initMarginRatio)) | |
589 | 720 | then true | |
590 | - | else (0 >= _amount)) | |
591 | - | then true | |
592 | - | else if (((1 * DECIMAL_UNIT) > _leverage)) | |
593 | - | then true | |
594 | - | else (_leverage > (3 * DECIMAL_UNIT))) | |
721 | + | else !(initialized())) | |
722 | + | then throw("Invalid setInitMarginRatio parameters") | |
723 | + | else updateSettings(_initMarginRatio, maintenanceMarginRatio(), liquidationFeeRatio(), fundingPeriodRaw(), fee(), spreadLimit(), maxPriceImpact(), partialLiquidationRatio(), maxPriceSpread()) | |
724 | + | ||
725 | + | ||
726 | + | ||
727 | + | @Callable(i) | |
728 | + | func decreasePosition (_amount,_leverage,_minBaseAssetAmount) = if (if (if (if (if ((0 >= _amount)) | |
595 | 729 | then true | |
596 | 730 | else !(initialized())) | |
597 | 731 | then true | |
598 | 732 | else !(requireMoreMarginRatio(divd(DECIMAL_UNIT, _leverage), initMarginRatio(), true))) | |
599 | 733 | then true | |
734 | + | else !(requireOpenPosition(toString(i.caller)))) | |
735 | + | then true | |
600 | 736 | else paused()) | |
601 | 737 | then throw("Invalid decreasePosition parameters") | |
602 | 738 | else { | |
603 | - | let $t02461824770 = getPosition(toString(i.caller)) | |
604 | - | let oldPositionSize = $t02461824770._1 | |
605 | - | let oldPositionMargin = $t02461824770._2 | |
606 | - | let oldPositionOpenNotional = $t02461824770._3 | |
607 | - | let oldPositionLstUpdCPF = $t02461824770._4 | |
608 | - | let isNewPosition = (oldPositionSize == 0) | |
609 | - | let isSameDirection = if ((oldPositionSize > 0)) | |
610 | - | then (_direction == DIR_LONG) | |
611 | - | else (_direction == DIR_SHORT) | |
612 | - | let expandExisting = if (!(isNewPosition)) | |
613 | - | then isSameDirection | |
614 | - | else false | |
739 | + | let $t03418734339 = getPosition(toString(i.caller)) | |
740 | + | let oldPositionSize = $t03418734339._1 | |
741 | + | let oldPositionMargin = $t03418734339._2 | |
742 | + | let oldPositionOpenNotional = $t03418734339._3 | |
743 | + | let oldPositionLstUpdCPF = $t03418734339._4 | |
744 | + | let _direction = if ((oldPositionSize > 0)) | |
745 | + | then DIR_SHORT | |
746 | + | else DIR_LONG | |
615 | 747 | let isAdd = (_direction == DIR_LONG) | |
616 | - | let $t02505928078 = if (if (isNewPosition) | |
617 | - | then true | |
618 | - | else expandExisting) | |
619 | - | then throw("Use increasePosition to open new or increase position") | |
620 | - | else { | |
621 | - | let openNotional = muld(_amount, _leverage) | |
622 | - | let $t02556525681 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT) | |
623 | - | let oldPositionNotional = $t02556525681._1 | |
624 | - | let unrealizedPnl = $t02556525681._2 | |
625 | - | if ((oldPositionNotional > openNotional)) | |
626 | - | then { | |
627 | - | let $t02574325973 = swapInput(isAdd, openNotional) | |
628 | - | let exchangedPositionSize = $t02574325973._1 | |
629 | - | let quoteAssetReserveAfter = $t02574325973._2 | |
630 | - | let baseAssetReserveAfter = $t02574325973._3 | |
631 | - | let totalPositionSizeAfter = $t02574325973._4 | |
632 | - | let cumulativeNotionalAfter = $t02574325973._5 | |
633 | - | let exchangedPositionSizeAbs = abs(exchangedPositionSize) | |
634 | - | if (if ((_minBaseAssetAmount != 0)) | |
635 | - | then (_minBaseAssetAmount > exchangedPositionSizeAbs) | |
636 | - | else false) | |
637 | - | then throw(((("Too little basse asset exchanged, got " + toString(exchangedPositionSizeAbs)) + " expected ") + toString(_minBaseAssetAmount))) | |
638 | - | else { | |
639 | - | let realizedPnl = if ((oldPositionSize != 0)) | |
640 | - | then divd(muld(unrealizedPnl, exchangedPositionSizeAbs), oldPositionSize) | |
641 | - | else 0 | |
642 | - | let $t02651426785 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl) | |
643 | - | let remainMargin = $t02651426785._1 | |
644 | - | let badDebt = $t02651426785._2 | |
645 | - | let fundingPayment = $t02651426785._3 | |
646 | - | let oldLatestCPF = $t02651426785._4 | |
647 | - | let exchangedQuoteAssetAmount = openNotional | |
648 | - | let unrealizedPnlAfter = (unrealizedPnl - realizedPnl) | |
649 | - | let remainOpenNotional = if ((oldPositionSize > 0)) | |
650 | - | then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter) | |
651 | - | else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount) | |
652 | - | let newPositionSize = (oldPositionSize + exchangedPositionSize) | |
653 | - | $Tuple11(newPositionSize, remainMargin, abs(remainOpenNotional), oldLatestCPF, baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, (openInteresetNotional() - openNotional), (totalLongPositionSize() - (if ((newPositionSize > 0)) | |
654 | - | then abs(exchangedPositionSize) | |
655 | - | else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize)) | |
656 | - | then abs(exchangedPositionSize) | |
657 | - | else 0))) | |
658 | - | } | |
748 | + | let openNotional = muld(_amount, _leverage) | |
749 | + | let $t03451234628 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT) | |
750 | + | let oldPositionNotional = $t03451234628._1 | |
751 | + | let unrealizedPnl = $t03451234628._2 | |
752 | + | let $t03463437183 = if ((oldPositionNotional > openNotional)) | |
753 | + | then { | |
754 | + | let $t03501135230 = swapInput(isAdd, openNotional) | |
755 | + | let exchangedPositionSize = $t03501135230._1 | |
756 | + | let quoteAssetReserveAfter = $t03501135230._2 | |
757 | + | let baseAssetReserveAfter = $t03501135230._3 | |
758 | + | let totalPositionSizeAfter = $t03501135230._4 | |
759 | + | let cumulativeNotionalAfter = $t03501135230._5 | |
760 | + | let exchangedPositionSizeAbs = abs(exchangedPositionSize) | |
761 | + | if (if ((_minBaseAssetAmount != 0)) | |
762 | + | then (_minBaseAssetAmount > exchangedPositionSizeAbs) | |
763 | + | else false) | |
764 | + | then throw(((("Too little base asset exchanged, got " + toString(exchangedPositionSizeAbs)) + " expected ") + toString(_minBaseAssetAmount))) | |
765 | + | else { | |
766 | + | let realizedPnl = divd(muld(unrealizedPnl, exchangedPositionSizeAbs), abs(oldPositionSize)) | |
767 | + | let $t03566735912 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl) | |
768 | + | let remainMargin = $t03566735912._1 | |
769 | + | let badDebt = $t03566735912._2 | |
770 | + | let fundingPayment = $t03566735912._3 | |
771 | + | let exchangedQuoteAssetAmount = openNotional | |
772 | + | let unrealizedPnlAfter = (unrealizedPnl - realizedPnl) | |
773 | + | let remainOpenNotional = if ((oldPositionSize > 0)) | |
774 | + | then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter) | |
775 | + | else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount) | |
776 | + | let newPositionSize = (oldPositionSize + exchangedPositionSize) | |
777 | + | $Tuple11(newPositionSize, remainMargin, abs(remainOpenNotional), latestCumulativePremiumFraction(newPositionSize), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, (openInterestNotional() - openNotional), (totalLongPositionSize() - (if ((newPositionSize > 0)) | |
778 | + | then abs(exchangedPositionSize) | |
779 | + | else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize)) | |
780 | + | then abs(exchangedPositionSize) | |
781 | + | else 0))) | |
659 | 782 | } | |
660 | - | else throw("Close position first") | |
661 | 783 | } | |
662 | - | let newPositionSize = $t02505928078._1 | |
663 | - | let newPositionRemainMargin = $t02505928078._2 | |
664 | - | let newPosiionOpenNotional = $t02505928078._3 | |
665 | - | let newPositionLatestCPF = $t02505928078._4 | |
666 | - | let baseAssetReserveAfter = $t02505928078._5 | |
667 | - | let quoteAssetReserveAfter = $t02505928078._6 | |
668 | - | let totalPositionSizeAfter = $t02505928078._7 | |
669 | - | let cumulativeNotionalAfter = $t02505928078._8 | |
670 | - | let openInteresetNotionalAfter = $t02505928078._9 | |
671 | - | let totalLongAfter = $t02505928078._10 | |
672 | - | let totalShortAfter = $t02505928078._11 | |
673 | - | (updatePosition(toString(i.caller), newPositionSize, newPositionRemainMargin, newPosiionOpenNotional, newPositionLatestCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInteresetNotionalAfter, totalLongAfter, totalShortAfter)) | |
784 | + | else throw("Close position first") | |
785 | + | let newPositionSize = $t03463437183._1 | |
786 | + | let newPositionRemainMargin = $t03463437183._2 | |
787 | + | let newPositionOpenNotional = $t03463437183._3 | |
788 | + | let newPositionLatestCPF = $t03463437183._4 | |
789 | + | let baseAssetReserveAfter = $t03463437183._5 | |
790 | + | let quoteAssetReserveAfter = $t03463437183._6 | |
791 | + | let totalPositionSizeAfter = $t03463437183._7 | |
792 | + | let cumulativeNotionalAfter = $t03463437183._8 | |
793 | + | let openInterestNotionalAfter = $t03463437183._9 | |
794 | + | let totalLongAfter = $t03463437183._10 | |
795 | + | let totalShortAfter = $t03463437183._11 | |
796 | + | let notifyNotional = invoke(minerAddress(), "notifyNotional", [toString(i.caller), newPositionOpenNotional], nil) | |
797 | + | if ((notifyNotional == notifyNotional)) | |
798 | + | then (updatePosition(toString(i.caller), newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter)) | |
799 | + | else throw("Strict value is not equal to itself.") | |
674 | 800 | } | |
675 | 801 | ||
676 | 802 | ||
678 | 804 | @Callable(i) | |
679 | 805 | func increasePosition (_direction,_leverage,_minBaseAssetAmount) = { | |
680 | 806 | let _rawAmount = i.payments[0].amount | |
681 | - | | |
807 | + | if (if (if (if (if (if (if ((_direction != DIR_LONG)) | |
682 | 808 | then (_direction != DIR_SHORT) | |
683 | 809 | else false) | |
684 | 810 | then true | |
685 | 811 | else (0 >= _rawAmount)) | |
686 | - | then true | |
687 | - | else if (((1 * DECIMAL_UNIT) > _leverage)) | |
688 | - | then true | |
689 | - | else (_leverage > (3 * DECIMAL_UNIT))) | |
690 | 812 | then true | |
691 | 813 | else !(initialized())) | |
692 | 814 | then true | |
699 | 821 | else { | |
700 | 822 | let feeAmount = muld(_rawAmount, fee()) | |
701 | 823 | let _amount = (_rawAmount - feeAmount) | |
702 | - | let $ | |
703 | - | let oldPositionSize = $ | |
704 | - | let oldPositionMargin = $ | |
705 | - | let oldPositionOpenNotional = $ | |
706 | - | let oldPositionLstUpdCPF = $ | |
824 | + | let $t03830138453 = getPosition(toString(i.caller)) | |
825 | + | let oldPositionSize = $t03830138453._1 | |
826 | + | let oldPositionMargin = $t03830138453._2 | |
827 | + | let oldPositionOpenNotional = $t03830138453._3 | |
828 | + | let oldPositionLstUpdCPF = $t03830138453._4 | |
707 | 829 | let isNewPosition = (oldPositionSize == 0) | |
708 | 830 | let isSameDirection = if ((oldPositionSize > 0)) | |
709 | 831 | then (_direction == DIR_LONG) | |
712 | 834 | then isSameDirection | |
713 | 835 | else false | |
714 | 836 | let isAdd = (_direction == DIR_LONG) | |
715 | - | let $ | |
837 | + | let $t03874241310 = if (if (isNewPosition) | |
716 | 838 | then true | |
717 | 839 | else expandExisting) | |
718 | 840 | then { | |
719 | 841 | let openNotional = muld(_amount, _leverage) | |
720 | - | let $ | |
721 | - | let amountBaseAssetBought = $ | |
722 | - | let quoteAssetReserveAfter = $ | |
723 | - | let baseAssetReserveAfter = $ | |
724 | - | let totalPositionSizeAfter = $ | |
725 | - | let cumulativeNotionalAfter = $ | |
842 | + | let $t03916639372 = swapInput(isAdd, openNotional) | |
843 | + | let amountBaseAssetBought = $t03916639372._1 | |
844 | + | let quoteAssetReserveAfter = $t03916639372._2 | |
845 | + | let baseAssetReserveAfter = $t03916639372._3 | |
846 | + | let totalPositionSizeAfter = $t03916639372._4 | |
847 | + | let cumulativeNotionalAfter = $t03916639372._5 | |
726 | 848 | if (if ((_minBaseAssetAmount != 0)) | |
727 | 849 | then (_minBaseAssetAmount > abs(amountBaseAssetBought)) | |
728 | 850 | else false) | |
730 | 852 | else { | |
731 | 853 | let newPositionSize = (oldPositionSize + amountBaseAssetBought) | |
732 | 854 | let increaseMarginRequirement = divd(openNotional, _leverage) | |
733 | - | let $t03056630819 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, increaseMarginRequirement) | |
734 | - | let remainMargin = $t03056630819._1 | |
735 | - | let x1 = $t03056630819._2 | |
736 | - | let x2 = $t03056630819._3 | |
737 | - | let oldLatestCPF = $t03056630819._4 | |
738 | - | $Tuple11(newPositionSize, remainMargin, (oldPositionOpenNotional + openNotional), oldLatestCPF, baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, (openInteresetNotional() + openNotional), (totalLongPositionSize() + (if ((newPositionSize > 0)) | |
739 | - | then abs(amountBaseAssetBought) | |
740 | - | else 0)), (totalShortPositionSize() + (if ((0 > newPositionSize)) | |
741 | - | then abs(amountBaseAssetBought) | |
742 | - | else 0))) | |
855 | + | let $t03975339992 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, increaseMarginRequirement) | |
856 | + | let remainMargin = $t03975339992._1 | |
857 | + | let x1 = $t03975339992._2 | |
858 | + | let x2 = $t03975339992._3 | |
859 | + | if (!(requireNotOverSpreadLimit(quoteAssetReserveAfter, baseAssetReserveAfter))) | |
860 | + | then throw("Over max spread limit") | |
861 | + | else $Tuple11(newPositionSize, remainMargin, (oldPositionOpenNotional + openNotional), latestCumulativePremiumFraction(newPositionSize), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, (openInterestNotional() + openNotional), (totalLongPositionSize() + (if ((newPositionSize > 0)) | |
862 | + | then abs(amountBaseAssetBought) | |
863 | + | else 0)), (totalShortPositionSize() + (if ((0 > newPositionSize)) | |
864 | + | then abs(amountBaseAssetBought) | |
865 | + | else 0))) | |
743 | 866 | } | |
744 | 867 | } | |
745 | 868 | else { | |
746 | 869 | let openNotional = muld(_amount, _leverage) | |
747 | - | let $ | |
748 | - | let oldPositionNotional = $ | |
749 | - | let unrealizedPnl = $ | |
870 | + | let $t04100341119 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT) | |
871 | + | let oldPositionNotional = $t04100341119._1 | |
872 | + | let unrealizedPnl = $t04100341119._2 | |
750 | 873 | if ((oldPositionNotional > openNotional)) | |
751 | 874 | then throw("Use decreasePosition to decrease position size") | |
752 | 875 | else throw("Close position first") | |
753 | 876 | } | |
754 | - | let newPositionSize = $ | |
755 | - | let newPositionRemainMargin = $ | |
756 | - | let | |
757 | - | let newPositionLatestCPF = $ | |
758 | - | let baseAssetReserveAfter = $ | |
759 | - | let quoteAssetReserveAfter = $ | |
760 | - | let totalPositionSizeAfter = $ | |
761 | - | let cumulativeNotionalAfter = $ | |
762 | - | let | |
763 | - | let totalLongAfter = $ | |
764 | - | let totalShortAfter = $ | |
877 | + | let newPositionSize = $t03874241310._1 | |
878 | + | let newPositionRemainMargin = $t03874241310._2 | |
879 | + | let newPositionOpenNotional = $t03874241310._3 | |
880 | + | let newPositionLatestCPF = $t03874241310._4 | |
881 | + | let baseAssetReserveAfter = $t03874241310._5 | |
882 | + | let quoteAssetReserveAfter = $t03874241310._6 | |
883 | + | let totalPositionSizeAfter = $t03874241310._7 | |
884 | + | let cumulativeNotionalAfter = $t03874241310._8 | |
885 | + | let openInterestNotionalAfter = $t03874241310._9 | |
886 | + | let totalLongAfter = $t03874241310._10 | |
887 | + | let totalShortAfter = $t03874241310._11 | |
765 | 888 | let feeToStakers = (feeAmount / 2) | |
766 | 889 | let feeToInsurance = (feeAmount - feeToStakers) | |
767 | 890 | let stake = invoke(quoteAssetStaking(), "lockNeutrinoSP", [toString(stakingAddress()), ALL_FEES], [AttachedPayment(quoteAsset(), _amount)]) | |
769 | 892 | then { | |
770 | 893 | let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)]) | |
771 | 894 | if ((depositInsurance == depositInsurance)) | |
772 | - | then (((updatePosition(toString(i.caller), newPositionSize, newPositionRemainMargin, newPosiionOpenNotional, newPositionLatestCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInteresetNotionalAfter, totalLongAfter, totalShortAfter)) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) | |
895 | + | then { | |
896 | + | let notifyFee = invoke(minerAddress(), "notifyFees", [toString(i.caller), feeAmount], nil) | |
897 | + | if ((notifyFee == notifyFee)) | |
898 | + | then { | |
899 | + | let notifyNotional = invoke(minerAddress(), "notifyNotional", [toString(i.caller), newPositionOpenNotional], nil) | |
900 | + | if ((notifyNotional == notifyNotional)) | |
901 | + | then (((updatePosition(toString(i.caller), newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter)) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) | |
902 | + | else throw("Strict value is not equal to itself.") | |
903 | + | } | |
904 | + | else throw("Strict value is not equal to itself.") | |
905 | + | } | |
773 | 906 | else throw("Strict value is not equal to itself.") | |
774 | 907 | } | |
775 | 908 | else throw("Strict value is not equal to itself.") | |
792 | 925 | else { | |
793 | 926 | let feeAmount = muld(_rawAmount, fee()) | |
794 | 927 | let _amount = (_rawAmount - feeAmount) | |
795 | - | let $ | |
796 | - | let oldPositionSize = $ | |
797 | - | let oldPositionMargin = $ | |
798 | - | let oldPositionOpenNotional = $ | |
799 | - | let oldPositionLstUpdCPF = $ | |
928 | + | let $t04286643018 = getPosition(toString(i.caller)) | |
929 | + | let oldPositionSize = $t04286643018._1 | |
930 | + | let oldPositionMargin = $t04286643018._2 | |
931 | + | let oldPositionOpenNotional = $t04286643018._3 | |
932 | + | let oldPositionLstUpdCPF = $t04286643018._4 | |
800 | 933 | let feeToStakers = (feeAmount / 2) | |
801 | 934 | let feeToInsurance = (feeAmount - feeToStakers) | |
802 | 935 | let stake = invoke(quoteAssetStaking(), "lockNeutrinoSP", [toString(stakingAddress()), ALL_FEES], [AttachedPayment(quoteAsset(), _amount)]) | |
804 | 937 | then { | |
805 | 938 | let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)]) | |
806 | 939 | if ((depositInsurance == depositInsurance)) | |
807 | - | then ((updatePosition(toString(i.caller), oldPositionSize, (oldPositionMargin + _amount), oldPositionOpenNotional, oldPositionLstUpdCPF) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) | |
940 | + | then { | |
941 | + | let notifyFee = invoke(minerAddress(), "notifyFees", [toString(i.caller), feeAmount], nil) | |
942 | + | if ((notifyFee == notifyFee)) | |
943 | + | then ((updatePosition(toString(i.caller), oldPositionSize, (oldPositionMargin + _amount), oldPositionOpenNotional, oldPositionLstUpdCPF) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) | |
944 | + | else throw("Strict value is not equal to itself.") | |
945 | + | } | |
808 | 946 | else throw("Strict value is not equal to itself.") | |
809 | 947 | } | |
810 | 948 | else throw("Strict value is not equal to itself.") | |
823 | 961 | else paused()) | |
824 | 962 | then throw("Invalid removeMargin parameters") | |
825 | 963 | else { | |
826 | - | let $ | |
827 | - | let oldPositionSize = $ | |
828 | - | let oldPositionMargin = $ | |
829 | - | let oldPositionOpenNotional = $ | |
830 | - | let oldPositionLstUpdCPF = $ | |
964 | + | let $t04406744219 = getPosition(toString(i.caller)) | |
965 | + | let oldPositionSize = $t04406744219._1 | |
966 | + | let oldPositionMargin = $t04406744219._2 | |
967 | + | let oldPositionOpenNotional = $t04406744219._3 | |
968 | + | let oldPositionLstUpdCPF = $t04406744219._4 | |
831 | 969 | let marginDelta = -(_amount) | |
832 | - | let $t03446134656 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, marginDelta) | |
833 | - | let remainMargin = $t03446134656._1 | |
834 | - | let badDebt = $t03446134656._2 | |
835 | - | let x1 = $t03446134656._3 | |
836 | - | let latestCPF1 = $t03446134656._4 | |
970 | + | let $t04425644435 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, marginDelta) | |
971 | + | let remainMargin = $t04425644435._1 | |
972 | + | let badDebt = $t04425644435._2 | |
837 | 973 | if ((badDebt != 0)) | |
838 | - | then throw("Invalid | |
974 | + | then throw("Invalid removed margin amount") | |
839 | 975 | else { | |
840 | - | let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [_amount, toBase58String(quoteAsset())], nil) | |
841 | - | if ((unstake == unstake)) | |
842 | - | then ((updatePosition(toString(i.caller), oldPositionSize, remainMargin, oldPositionOpenNotional, latestCPF1) ++ withdraw(i.caller, _amount)) ++ updateBalance((cbalance() - _amount))) | |
843 | - | else throw("Strict value is not equal to itself.") | |
976 | + | let marginRatio = calcMarginRatio(remainMargin, badDebt, oldPositionOpenNotional) | |
977 | + | if (!(requireMoreMarginRatio(marginRatio, initMarginRatio(), true))) | |
978 | + | then throw(((("Too much margin removed: " + toString(marginRatio)) + " < ") + toString(initMarginRatio()))) | |
979 | + | else { | |
980 | + | let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [_amount, toBase58String(quoteAsset())], nil) | |
981 | + | if ((unstake == unstake)) | |
982 | + | then ((updatePosition(toString(i.caller), oldPositionSize, remainMargin, oldPositionOpenNotional, latestCumulativePremiumFraction(oldPositionSize)) ++ withdraw(i.caller, _amount)) ++ updateBalance((cbalance() - _amount))) | |
983 | + | else throw("Strict value is not equal to itself.") | |
984 | + | } | |
844 | 985 | } | |
845 | 986 | } | |
846 | 987 | ||
854 | 995 | else paused()) | |
855 | 996 | then throw("Invalid closePosition parameters") | |
856 | 997 | else { | |
857 | - | let $ | |
858 | - | let x1 = $ | |
859 | - | let positionBadDebt = $ | |
860 | - | let realizedPnl = $ | |
861 | - | let marginToVault = $ | |
862 | - | let quoteAssetReserveAfter = $ | |
863 | - | let baseAssetReserveAfter = $ | |
864 | - | let totalPositionSizeAfter = $ | |
865 | - | let cumulativeNotionalAfter = $ | |
866 | - | let | |
867 | - | let x2 = $ | |
868 | - | let totalLongAfter = $ | |
869 | - | let totalShortAfter = $ | |
998 | + | let $t04553145921 = internalClosePosition(toString(i.caller), true) | |
999 | + | let x1 = $t04553145921._1 | |
1000 | + | let positionBadDebt = $t04553145921._2 | |
1001 | + | let realizedPnl = $t04553145921._3 | |
1002 | + | let marginToVault = $t04553145921._4 | |
1003 | + | let quoteAssetReserveAfter = $t04553145921._5 | |
1004 | + | let baseAssetReserveAfter = $t04553145921._6 | |
1005 | + | let totalPositionSizeAfter = $t04553145921._7 | |
1006 | + | let cumulativeNotionalAfter = $t04553145921._8 | |
1007 | + | let openInterestNotionalAfter = $t04553145921._9 | |
1008 | + | let x2 = $t04553145921._10 | |
1009 | + | let totalLongAfter = $t04553145921._11 | |
1010 | + | let totalShortAfter = $t04553145921._12 | |
870 | 1011 | if ((positionBadDebt > 0)) | |
871 | 1012 | then throw("Unable to close position with bad debt") | |
872 | 1013 | else { | |
873 | 1014 | let withdrawAmount = abs(marginToVault) | |
874 | 1015 | let ammBalance = (cbalance() - withdrawAmount) | |
875 | - | let $ | |
1016 | + | let $t04613046272 = if ((0 > ammBalance)) | |
876 | 1017 | then $Tuple2(0, abs(ammBalance)) | |
877 | 1018 | else $Tuple2(ammBalance, 0) | |
878 | - | let ammNewBalance = $ | |
879 | - | let getFromInsurance = $ | |
1019 | + | let ammNewBalance = $t04613046272._1 | |
1020 | + | let getFromInsurance = $t04613046272._2 | |
880 | 1021 | let x = if ((getFromInsurance > 0)) | |
881 | 1022 | then { | |
882 | 1023 | let withdrawInsurance = invoke(insuranceAddress(), "withdraw", [getFromInsurance], nil) | |
889 | 1030 | then { | |
890 | 1031 | let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [(withdrawAmount - getFromInsurance), toBase58String(quoteAsset())], nil) | |
891 | 1032 | if ((unstake == unstake)) | |
892 | - | then (((deletePosition(toString(i.caller)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInteresetNotionalAfter, totalLongAfter, totalShortAfter)) ++ withdraw(i.caller, withdrawAmount)) ++ updateBalance(ammNewBalance)) | |
1033 | + | then { | |
1034 | + | let notifyNotional = invoke(minerAddress(), "notifyNotional", [toString(i.caller), 0], nil) | |
1035 | + | if ((notifyNotional == notifyNotional)) | |
1036 | + | then (((deletePosition(toString(i.caller)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter)) ++ withdraw(i.caller, withdrawAmount)) ++ updateBalance(ammNewBalance)) | |
1037 | + | else throw("Strict value is not equal to itself.") | |
1038 | + | } | |
893 | 1039 | else throw("Strict value is not equal to itself.") | |
894 | 1040 | } | |
895 | 1041 | else throw("Strict value is not equal to itself.") | |
900 | 1046 | ||
901 | 1047 | @Callable(i) | |
902 | 1048 | func liquidate (_trader) = { | |
1049 | + | let spotMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_SPOT) | |
903 | 1050 | let marginRatio = if (isOverFluctuationLimit()) | |
904 | - | then getMarginRatioByOption(_trader, PNL_OPTION_ORACLE) | |
905 | - | else getMarginRatioByOption(_trader, PNL_OPTION_SPOT) | |
906 | - | if (if (if (!(requireMoreMarginRatio(marginRatio, mmr(), false))) | |
1051 | + | then { | |
1052 | + | let oracleMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_ORACLE) | |
1053 | + | vmax(spotMarginRatio, oracleMarginRatio) | |
1054 | + | } | |
1055 | + | else spotMarginRatio | |
1056 | + | if (if (if (if (!(requireMoreMarginRatio(marginRatio, maintenanceMarginRatio(), false))) | |
1057 | + | then true | |
1058 | + | else !(requireOpenPosition(_trader))) | |
907 | 1059 | then true | |
908 | 1060 | else !(initialized())) | |
909 | 1061 | then true | |
910 | 1062 | else paused()) | |
911 | 1063 | then throw("Unable to liquidate") | |
912 | - | else { | |
913 | - | let $t03733337664 = internalClosePosition(_trader) | |
914 | - | let x1 = $t03733337664._1 | |
915 | - | let badDebt = $t03733337664._2 | |
916 | - | let x2 = $t03733337664._3 | |
917 | - | let marginToVault = $t03733337664._4 | |
918 | - | let quoteAssetReserveAfter = $t03733337664._5 | |
919 | - | let baseAssetReserveAfter = $t03733337664._6 | |
920 | - | let totalPositionSizeAfter = $t03733337664._7 | |
921 | - | let cumulativeNotionalAfter = $t03733337664._8 | |
922 | - | let openInteresetNotionalAfter = $t03733337664._9 | |
923 | - | let exchangedQuoteAssetAmount = $t03733337664._10 | |
924 | - | let totalLongAfter = $t03733337664._11 | |
925 | - | let totalShortAfter = $t03733337664._12 | |
926 | - | let feeToLiquidator = (muld(exchangedQuoteAssetAmount, liquidationFeeRatio()) / 2) | |
927 | - | let $t03775438158 = if ((feeToLiquidator > marginToVault)) | |
928 | - | then $Tuple3((feeToLiquidator - marginToVault), marginToVault, ((badDebt + feeToLiquidator) - marginToVault)) | |
929 | - | else $Tuple3(0, (marginToVault - feeToLiquidator), badDebt) | |
930 | - | let liquidationBadDebt = $t03775438158._1 | |
931 | - | let remainMargin = $t03775438158._2 | |
932 | - | let totalBadDebt = $t03775438158._3 | |
933 | - | let bd = (cbalance() - feeToLiquidator) | |
934 | - | let $t03820638294 = if ((0 > bd)) | |
935 | - | then $Tuple2(0, abs(bd)) | |
936 | - | else $Tuple2(bd, 0) | |
937 | - | let nb = $t03820638294._1 | |
938 | - | let fromi = $t03820638294._2 | |
939 | - | let x = if ((fromi > 0)) | |
940 | - | then { | |
941 | - | let withdrawInsurance = invoke(insuranceAddress(), "withdraw", [fromi], nil) | |
942 | - | if ((withdrawInsurance == withdrawInsurance)) | |
943 | - | then nil | |
944 | - | else throw("Strict value is not equal to itself.") | |
945 | - | } | |
946 | - | else nil | |
947 | - | if ((x == x)) | |
948 | - | then { | |
949 | - | let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [(feeToLiquidator - fromi), toBase58String(quoteAsset())], nil) | |
950 | - | if ((unstake == unstake)) | |
951 | - | then (((deletePosition(_trader) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInteresetNotionalAfter, totalLongAfter, totalShortAfter)) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(nb)) | |
952 | - | else throw("Strict value is not equal to itself.") | |
953 | - | } | |
954 | - | else throw("Strict value is not equal to itself.") | |
955 | - | } | |
1064 | + | else if (if (if ((spotMarginRatio > liquidationFeeRatio())) | |
1065 | + | then (partialLiquidationRatio() > 0) | |
1066 | + | else false) | |
1067 | + | then (DECIMAL_UNIT > partialLiquidationRatio()) | |
1068 | + | else false) | |
1069 | + | then { | |
1070 | + | let $t04837348523 = getPosition(_trader) | |
1071 | + | let oldPositionSize = $t04837348523._1 | |
1072 | + | let oldPositionMargin = $t04837348523._2 | |
1073 | + | let oldPositionOpenNotional = $t04837348523._3 | |
1074 | + | let oldPositionLstUpdCPF = $t04837348523._4 | |
1075 | + | let _direction = if ((oldPositionSize > 0)) | |
1076 | + | then DIR_SHORT | |
1077 | + | else DIR_LONG | |
1078 | + | let isAdd = (_direction == DIR_LONG) | |
1079 | + | let exchangedQuoteAssetAmount = getPartialLiquidationAmount(_trader, oldPositionSize) | |
1080 | + | let $t04874848852 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
1081 | + | let oldPositionNotional = $t04874848852._1 | |
1082 | + | let unrealizedPnl = $t04874848852._2 | |
1083 | + | let $t04886049150 = swapInput(isAdd, exchangedQuoteAssetAmount) | |
1084 | + | let exchangedPositionSize = $t04886049150._1 | |
1085 | + | let quoteAssetReserveAfter = $t04886049150._2 | |
1086 | + | let baseAssetReserveAfter = $t04886049150._3 | |
1087 | + | let totalPositionSizeAfter = $t04886049150._4 | |
1088 | + | let cumulativeNotionalAfter = $t04886049150._5 | |
1089 | + | let realizedPnl = divd(muld(unrealizedPnl, abs(exchangedPositionSize)), abs(oldPositionSize)) | |
1090 | + | let $t04925749490 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl) | |
1091 | + | let remainMargin = $t04925749490._1 | |
1092 | + | let badDebt = $t04925749490._2 | |
1093 | + | let fundingPayment = $t04925749490._3 | |
1094 | + | let unrealizedPnlAfter = (unrealizedPnl - realizedPnl) | |
1095 | + | let remainOpenNotional = if ((oldPositionSize > 0)) | |
1096 | + | then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter) | |
1097 | + | else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount) | |
1098 | + | let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio()) | |
1099 | + | let feeToLiquidator = (liquidationPenalty / 2) | |
1100 | + | let feeToInsurance = (liquidationPenalty - feeToLiquidator) | |
1101 | + | let newPositionMargin = (remainMargin - liquidationPenalty) | |
1102 | + | let newPositionSize = (oldPositionSize + exchangedPositionSize) | |
1103 | + | let newPositionOpenNotional = abs(remainOpenNotional) | |
1104 | + | let newPositionLstUpdCPF = latestCumulativePremiumFraction(newPositionSize) | |
1105 | + | let openInterestNotionalAfter = (openInterestNotional() - exchangedQuoteAssetAmount) | |
1106 | + | let ammBalance = (cbalance() - liquidationPenalty) | |
1107 | + | let $t05066350806 = if ((0 > ammBalance)) | |
1108 | + | then $Tuple2(0, abs(ammBalance)) | |
1109 | + | else $Tuple2(ammBalance, 0) | |
1110 | + | let newAmmBalance = $t05066350806._1 | |
1111 | + | let takeFromInsurance = $t05066350806._2 | |
1112 | + | let x = if ((takeFromInsurance > 0)) | |
1113 | + | then { | |
1114 | + | let withdrawInsurance = invoke(insuranceAddress(), "withdraw", [takeFromInsurance], nil) | |
1115 | + | if ((withdrawInsurance == withdrawInsurance)) | |
1116 | + | then nil | |
1117 | + | else throw("Strict value is not equal to itself.") | |
1118 | + | } | |
1119 | + | else nil | |
1120 | + | if ((x == x)) | |
1121 | + | then { | |
1122 | + | let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [(liquidationPenalty - takeFromInsurance), toBase58String(quoteAsset())], nil) | |
1123 | + | if ((unstake == unstake)) | |
1124 | + | then { | |
1125 | + | let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)]) | |
1126 | + | if ((depositInsurance == depositInsurance)) | |
1127 | + | then { | |
1128 | + | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil) | |
1129 | + | if ((notifyNotional == notifyNotional)) | |
1130 | + | then (((updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, (totalLongPositionSize() - (if ((newPositionSize > 0)) | |
1131 | + | then abs(exchangedPositionSize) | |
1132 | + | else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize)) | |
1133 | + | then abs(exchangedPositionSize) | |
1134 | + | else 0)))) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance)) | |
1135 | + | else throw("Strict value is not equal to itself.") | |
1136 | + | } | |
1137 | + | else throw("Strict value is not equal to itself.") | |
1138 | + | } | |
1139 | + | else throw("Strict value is not equal to itself.") | |
1140 | + | } | |
1141 | + | else throw("Strict value is not equal to itself.") | |
1142 | + | } | |
1143 | + | else { | |
1144 | + | let $t05226252717 = internalClosePosition(_trader, false) | |
1145 | + | let x1 = $t05226252717._1 | |
1146 | + | let badDebt = $t05226252717._2 | |
1147 | + | let x2 = $t05226252717._3 | |
1148 | + | let x3 = $t05226252717._4 | |
1149 | + | let quoteAssetReserveAfter = $t05226252717._5 | |
1150 | + | let baseAssetReserveAfter = $t05226252717._6 | |
1151 | + | let totalPositionSizeAfter = $t05226252717._7 | |
1152 | + | let cumulativeNotionalAfter = $t05226252717._8 | |
1153 | + | let openInterestNotionalAfter = $t05226252717._9 | |
1154 | + | let exchangedQuoteAssetAmount = $t05226252717._10 | |
1155 | + | let totalLongAfter = $t05226252717._11 | |
1156 | + | let totalShortAfter = $t05226252717._12 | |
1157 | + | let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio()) | |
1158 | + | let feeToLiquidator = (liquidationPenalty / 2) | |
1159 | + | let feeToInsurance = (liquidationPenalty - feeToLiquidator) | |
1160 | + | let ammBalance = (cbalance() - liquidationPenalty) | |
1161 | + | let $t05312953272 = if ((0 > ammBalance)) | |
1162 | + | then $Tuple2(0, abs(ammBalance)) | |
1163 | + | else $Tuple2(ammBalance, 0) | |
1164 | + | let newAmmBalance = $t05312953272._1 | |
1165 | + | let takeFromInsurance = $t05312953272._2 | |
1166 | + | let x = if ((takeFromInsurance > 0)) | |
1167 | + | then { | |
1168 | + | let withdrawInsurance = invoke(insuranceAddress(), "withdraw", [takeFromInsurance], nil) | |
1169 | + | if ((withdrawInsurance == withdrawInsurance)) | |
1170 | + | then nil | |
1171 | + | else throw("Strict value is not equal to itself.") | |
1172 | + | } | |
1173 | + | else nil | |
1174 | + | if ((x == x)) | |
1175 | + | then { | |
1176 | + | let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [(liquidationPenalty - takeFromInsurance), toBase58String(quoteAsset())], nil) | |
1177 | + | if ((unstake == unstake)) | |
1178 | + | then { | |
1179 | + | let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)]) | |
1180 | + | if ((depositInsurance == depositInsurance)) | |
1181 | + | then { | |
1182 | + | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, 0], nil) | |
1183 | + | if ((notifyNotional == notifyNotional)) | |
1184 | + | then (((deletePosition(_trader) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter)) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance)) | |
1185 | + | else throw("Strict value is not equal to itself.") | |
1186 | + | } | |
1187 | + | else throw("Strict value is not equal to itself.") | |
1188 | + | } | |
1189 | + | else throw("Strict value is not equal to itself.") | |
1190 | + | } | |
1191 | + | else throw("Strict value is not equal to itself.") | |
1192 | + | } | |
956 | 1193 | } | |
957 | 1194 | ||
958 | 1195 | ||
970 | 1207 | let underlyingPrice = getOracleTwapPrice() | |
971 | 1208 | let spotTwapPrice = getTwapSpotPrice() | |
972 | 1209 | let premium = (spotTwapPrice - underlyingPrice) | |
973 | - | let $ | |
1210 | + | let $t05486056195 = if (if ((totalShortPositionSize() == 0)) | |
974 | 1211 | then true | |
975 | 1212 | else (totalLongPositionSize() == 0)) | |
976 | 1213 | then $Tuple2(0, 0) | |
985 | 1222 | let shortPremiumFraction = divd(muld(longPremiumFraction, totalLongPositionSize()), totalShortPositionSize()) | |
986 | 1223 | $Tuple2(shortPremiumFraction, longPremiumFraction) | |
987 | 1224 | } | |
988 | - | let shortPremiumFraction = $ | |
989 | - | let longPremiumFraction = $ | |
1225 | + | let shortPremiumFraction = $t05486056195._1 | |
1226 | + | let longPremiumFraction = $t05486056195._2 | |
990 | 1227 | updateFunding((fundingBlockTimestamp + fundingPeriodSeconds()), (latestLongCumulativePremiumFraction() + longPremiumFraction), (latestShortCumulativePremiumFraction() + shortPremiumFraction), divd(longPremiumFraction, underlyingPrice), divd(shortPremiumFraction, underlyingPrice)) | |
991 | 1228 | } | |
992 | 1229 | } | |
995 | 1232 | ||
996 | 1233 | @Callable(i) | |
997 | 1234 | func v_get (_trader) = { | |
998 | - | let $ | |
999 | - | let x1 = $ | |
1000 | - | let x2 = $ | |
1001 | - | let x3 = $ | |
1002 | - | let x4 = $ | |
1235 | + | let $t05657056630 = internalClosePosition(_trader, false) | |
1236 | + | let x1 = $t05657056630._1 | |
1237 | + | let x2 = $t05657056630._2 | |
1238 | + | let x3 = $t05657056630._3 | |
1239 | + | let x4 = $t05657056630._4 | |
1003 | 1240 | throw((((s(x2) + s(x3)) + s(x4)) + s(getMarginRatio(_trader)))) | |
1004 | 1241 | } | |
1005 | 1242 | ||
1007 | 1244 | ||
1008 | 1245 | @Callable(i) | |
1009 | 1246 | func view_calcRemainMarginWithFundingPayment (_trader) = { | |
1010 | - | let $ | |
1011 | - | let positionSize = $ | |
1012 | - | let positionMargin = $ | |
1013 | - | let pon = $ | |
1014 | - | let positionLstUpdCPF = $ | |
1015 | - | let $ | |
1016 | - | let positionNotional = $ | |
1017 | - | let unrealizedPnl = $ | |
1018 | - | let $ | |
1019 | - | let remainMargin = $ | |
1020 | - | let badDebt = $ | |
1021 | - | let fundingPayment = $ | |
1022 | - | throw((s(remainMargin) + s(fundingPayment))) | |
1247 | + | let $t05677756888 = getPosition(_trader) | |
1248 | + | let positionSize = $t05677756888._1 | |
1249 | + | let positionMargin = $t05677756888._2 | |
1250 | + | let pon = $t05677756888._3 | |
1251 | + | let positionLstUpdCPF = $t05677756888._4 | |
1252 | + | let $t05689356994 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
1253 | + | let positionNotional = $t05689356994._1 | |
1254 | + | let unrealizedPnl = $t05689356994._2 | |
1255 | + | let $t05699957181 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
1256 | + | let remainMargin = $t05699957181._1 | |
1257 | + | let badDebt = $t05699957181._2 | |
1258 | + | let fundingPayment = $t05699957181._3 | |
1259 | + | throw((((((s(remainMargin) + s(fundingPayment)) + s(getMarginRatio(_trader))) + s(unrealizedPnl)) + s(badDebt)) + s(positionNotional))) | |
1023 | 1260 | } | |
1261 | + | ||
1262 | + | ||
1263 | + | ||
1264 | + | @Callable(i) | |
1265 | + | func forceMoveAsset (_trader,_amount) = if (if ((addressFromPublicKey(adminPublicKey()) != i.caller)) | |
1266 | + | then true | |
1267 | + | else (0 > _amount)) | |
1268 | + | then throw("Invalid forceMoveAsset parameters") | |
1269 | + | else { | |
1270 | + | let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [_amount, toBase58String(quoteAsset())], nil) | |
1271 | + | if ((unstake == unstake)) | |
1272 | + | then (withdraw(addressFromStringValue(_trader), _amount) ++ updateBalance((cbalance() - _amount))) | |
1273 | + | else throw("Strict value is not equal to itself.") | |
1274 | + | } | |
1024 | 1275 | ||
1025 | 1276 | ||
1026 | 1277 | @Verifier(tx) |
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let k_ora_key = "k_ora_key" | |
5 | + | ||
6 | + | let k_ora_block_key = "k_ora_block_key" | |
5 | 7 | ||
6 | 8 | let k_ora = "k_ora" | |
7 | 9 | ||
8 | 10 | let k_balance = "k_balance" | |
9 | 11 | ||
10 | 12 | let k_positionSize = "k_positionSize" | |
11 | 13 | ||
12 | 14 | let k_positionMargin = "k_positionMargin" | |
13 | 15 | ||
14 | 16 | let k_positionOpenNotional = "k_positionOpenNotional" | |
15 | 17 | ||
16 | 18 | let k_positionLastUpdatedCumulativePremiumFraction = "k_positionFraction" | |
17 | 19 | ||
18 | 20 | let k_initialized = "k_initialized" | |
19 | 21 | ||
20 | 22 | let k_paused = "k_paused" | |
21 | 23 | ||
22 | 24 | let k_fee = "k_fee" | |
23 | 25 | ||
24 | 26 | let k_fundingPeriod = "k_fundingPeriod" | |
25 | 27 | ||
26 | 28 | let k_initMarginRatio = "k_initMarginRatio" | |
27 | 29 | ||
28 | 30 | let k_maintenanceMarginRatio = "k_mmr" | |
29 | 31 | ||
30 | 32 | let k_liquidationFeeRatio = "k_liquidationFeeRatio" | |
31 | 33 | ||
34 | + | let k_partialLiquidationRatio = "k_partLiquidationRatio" | |
35 | + | ||
32 | 36 | let k_spreadLimit = "k_spreadLimit" | |
33 | 37 | ||
34 | 38 | let k_maxPriceImpact = "k_maxPriceImpact" | |
39 | + | ||
40 | + | let k_maxPriceSpread = "k_maxPriceSpread" | |
35 | 41 | ||
36 | 42 | let k_lastDataStr = "k_lastDataStr" | |
37 | 43 | ||
38 | 44 | let k_lastMinuteId = "k_lastMinuteId" | |
39 | 45 | ||
40 | 46 | let k_twapDataLastCumulativePrice = "k_twapDataLastCumulativePrice" | |
41 | 47 | ||
42 | 48 | let k_twapDataLastPrice = "k_twapDataLastPrice" | |
43 | 49 | ||
44 | - | let k_ | |
50 | + | let k_twapDataPreviousMinuteId = "k_twapDataPreviousMinuteId" | |
45 | 51 | ||
46 | 52 | let k_latestLongCumulativePremiumFraction = "k_latestLongPremiumFraction" | |
47 | 53 | ||
48 | 54 | let k_latestShortCumulativePremiumFraction = "k_latestShortPremiumFraction" | |
49 | 55 | ||
50 | 56 | let k_nextFundingBlock = "k_nextFundingBlockMinTimestamp" | |
51 | 57 | ||
52 | 58 | let k_longFundingRate = "k_longFundingRate" | |
53 | 59 | ||
54 | 60 | let k_shortFundingRate = "k_shortFundingRate" | |
55 | 61 | ||
56 | 62 | let k_quoteAssetReserve = "k_qtAstR" | |
57 | 63 | ||
58 | 64 | let k_baseAssetReserve = "k_bsAstR" | |
59 | 65 | ||
60 | 66 | let k_totalPositionSize = "k_totalPositionSize" | |
61 | 67 | ||
62 | 68 | let k_totalLongPositionSize = "k_totalLongPositionSize" | |
63 | 69 | ||
64 | 70 | let k_totalShortPositionSize = "k_totalShortPositionSize" | |
65 | 71 | ||
66 | 72 | let k_cumulativeNotional = "k_cumulativeNotional" | |
67 | 73 | ||
68 | - | let k_ | |
74 | + | let k_openInterestNotional = "k_openInterestNotional" | |
69 | 75 | ||
70 | 76 | let k_coordinatorAddress = "k_coordinatorAddress" | |
71 | 77 | ||
72 | 78 | let k_insurance_address = "k_insurance_address" | |
73 | 79 | ||
74 | 80 | let k_admin_address = "k_admin_address" | |
75 | 81 | ||
76 | 82 | let k_admin_public_key = "k_admin_public_key" | |
77 | 83 | ||
78 | 84 | let k_quote_asset = "k_quote_asset" | |
79 | 85 | ||
80 | 86 | let k_quote_staking = "k_quote_staking" | |
81 | 87 | ||
82 | 88 | let k_staking_address = "k_staking_address" | |
83 | 89 | ||
90 | + | let k_miner_address = "k_miner_address" | |
91 | + | ||
84 | 92 | func coordinator () = valueOrErrorMessage(addressFromString(getStringValue(this, k_coordinatorAddress)), "Coordinator not set") | |
85 | 93 | ||
86 | 94 | ||
87 | 95 | func adminAddress () = addressFromString(getStringValue(coordinator(), k_admin_address)) | |
88 | 96 | ||
89 | 97 | ||
90 | 98 | func adminPublicKey () = fromBase58String(getStringValue(coordinator(), k_admin_public_key)) | |
91 | 99 | ||
92 | 100 | ||
93 | 101 | func quoteAsset () = fromBase58String(getStringValue(coordinator(), k_quote_asset)) | |
94 | 102 | ||
95 | 103 | ||
96 | - | func quoteAssetStaking () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_quote_staking)), "Quote | |
104 | + | func quoteAssetStaking () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_quote_staking)), "Quote asset staking not set") | |
97 | 105 | ||
98 | 106 | ||
99 | 107 | func stakingAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_staking_address)), "Insurance not set") | |
100 | 108 | ||
101 | 109 | ||
102 | 110 | func insuranceAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_insurance_address)), "Insurance not set") | |
103 | 111 | ||
104 | 112 | ||
113 | + | func minerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_miner_address)), "Insurance not set") | |
114 | + | ||
115 | + | ||
105 | 116 | let DIR_LONG = 1 | |
106 | 117 | ||
107 | 118 | let DIR_SHORT = 2 | |
108 | 119 | ||
109 | - | let | |
120 | + | let TWAP_INTERVAL = 15 | |
110 | 121 | ||
111 | - | let | |
122 | + | let ORACLE_INTERVAL = 15 | |
112 | 123 | ||
113 | 124 | let SECONDS = 1000 | |
114 | 125 | ||
115 | 126 | let DECIMAL_UNIT = (1 * (((((10 * 10) * 10) * 10) * 10) * 10)) | |
116 | 127 | ||
117 | 128 | let ONE_DAY = (86400 * DECIMAL_UNIT) | |
118 | 129 | ||
119 | 130 | let ALL_FEES = 100 | |
120 | 131 | ||
121 | 132 | let PNL_OPTION_SPOT = 1 | |
122 | 133 | ||
123 | 134 | let PNL_OPTION_ORACLE = 2 | |
124 | 135 | ||
125 | 136 | func s (_x) = (toString(_x) + ",") | |
126 | 137 | ||
127 | 138 | ||
128 | 139 | func divd (_x,_y) = fraction(_x, DECIMAL_UNIT, _y, HALFEVEN) | |
129 | 140 | ||
130 | 141 | ||
131 | 142 | func muld (_x,_y) = fraction(_x, _y, DECIMAL_UNIT, HALFEVEN) | |
132 | 143 | ||
133 | 144 | ||
134 | 145 | func abs (_x) = if ((_x > 0)) | |
135 | 146 | then _x | |
136 | 147 | else -(_x) | |
137 | 148 | ||
138 | 149 | ||
150 | + | func vmax (_x,_y) = if ((_x >= _y)) | |
151 | + | then _x | |
152 | + | else _y | |
153 | + | ||
154 | + | ||
139 | 155 | func toCompositeKey (_key,_address) = ((_key + "_") + _address) | |
140 | 156 | ||
141 | 157 | ||
142 | - | func requireMoreMarginRatio (_marginRatio,_baseMarginRatio,_largerThanOrEqualTo) = { | |
143 | - | let remainingMarginRatio = (_marginRatio - _baseMarginRatio) | |
144 | - | if (if (_largerThanOrEqualTo) | |
145 | - | then (0 > remainingMarginRatio) | |
146 | - | else false) | |
147 | - | then throw("Invalid margin") | |
148 | - | else if (if (!(_largerThanOrEqualTo)) | |
149 | - | then (remainingMarginRatio >= 0) | |
150 | - | else false) | |
151 | - | then throw("Invalid margin") | |
152 | - | else true | |
158 | + | func listToStr (_list) = { | |
159 | + | func _join (accumulator,val) = ((accumulator + val) + ",") | |
160 | + | ||
161 | + | let newListStr = { | |
162 | + | let $l = _list | |
163 | + | let $s = size($l) | |
164 | + | let $acc0 = "" | |
165 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
166 | + | then $a | |
167 | + | else _join($a, $l[$i]) | |
168 | + | ||
169 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
170 | + | then $a | |
171 | + | else throw("List size exceeds 20") | |
172 | + | ||
173 | + | $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) | |
174 | + | } | |
175 | + | let newListStrU = dropRight(newListStr, 1) | |
176 | + | let newListStrR = if ((take(newListStrU, 1) == ",")) | |
177 | + | then drop(newListStrU, 1) | |
178 | + | else newListStrU | |
179 | + | newListStrR | |
153 | 180 | } | |
181 | + | ||
182 | + | ||
183 | + | func strToList (_str) = split(_str, ",") | |
184 | + | ||
185 | + | ||
186 | + | func pushToQueue (_list,_maxSize,_value) = if ((size(_list) > _maxSize)) | |
187 | + | then (removeByIndex(_list, 0) :+ _value) | |
188 | + | else (_list :+ _value) | |
154 | 189 | ||
155 | 190 | ||
156 | 191 | func int (k) = valueOrErrorMessage(getInteger(this, k), ("no value for " + k)) | |
157 | 192 | ||
158 | 193 | ||
159 | 194 | func cbalance () = int(k_balance) | |
160 | 195 | ||
161 | 196 | ||
162 | 197 | func fee () = int(k_fee) | |
163 | 198 | ||
164 | 199 | ||
165 | 200 | func initMarginRatio () = int(k_initMarginRatio) | |
166 | 201 | ||
167 | 202 | ||
168 | 203 | func qtAstR () = int(k_quoteAssetReserve) | |
169 | 204 | ||
170 | 205 | ||
171 | 206 | func bsAstR () = int(k_baseAssetReserve) | |
172 | 207 | ||
173 | 208 | ||
174 | 209 | func totalPositionSize () = int(k_totalPositionSize) | |
175 | 210 | ||
176 | 211 | ||
177 | 212 | func cumulativeNotional () = int(k_cumulativeNotional) | |
178 | 213 | ||
179 | 214 | ||
180 | - | func | |
215 | + | func openInterestNotional () = int(k_openInterestNotional) | |
181 | 216 | ||
182 | 217 | ||
183 | 218 | func nextFundingBlockTimestamp () = int(k_nextFundingBlock) | |
184 | 219 | ||
185 | 220 | ||
186 | 221 | func fundingPeriodRaw () = int(k_fundingPeriod) | |
187 | 222 | ||
188 | 223 | ||
189 | 224 | func fundingPeriodDecimal () = (fundingPeriodRaw() * DECIMAL_UNIT) | |
190 | 225 | ||
191 | 226 | ||
192 | 227 | func fundingPeriodSeconds () = (fundingPeriodRaw() * SECONDS) | |
193 | 228 | ||
194 | 229 | ||
195 | - | func | |
230 | + | func maintenanceMarginRatio () = int(k_maintenanceMarginRatio) | |
196 | 231 | ||
197 | 232 | ||
198 | 233 | func liquidationFeeRatio () = int(k_liquidationFeeRatio) | |
234 | + | ||
235 | + | ||
236 | + | func partialLiquidationRatio () = int(k_partialLiquidationRatio) | |
199 | 237 | ||
200 | 238 | ||
201 | 239 | func spreadLimit () = int(k_spreadLimit) | |
202 | 240 | ||
203 | 241 | ||
204 | 242 | func maxPriceImpact () = int(k_maxPriceImpact) | |
243 | + | ||
244 | + | ||
245 | + | func maxPriceSpread () = int(k_maxPriceSpread) | |
205 | 246 | ||
206 | 247 | ||
207 | 248 | func latestLongCumulativePremiumFraction () = int(k_latestLongCumulativePremiumFraction) | |
208 | 249 | ||
209 | 250 | ||
210 | 251 | func latestShortCumulativePremiumFraction () = int(k_latestShortCumulativePremiumFraction) | |
211 | 252 | ||
212 | 253 | ||
213 | 254 | func totalShortPositionSize () = int(k_totalShortPositionSize) | |
214 | 255 | ||
215 | 256 | ||
216 | 257 | func totalLongPositionSize () = int(k_totalLongPositionSize) | |
217 | 258 | ||
218 | 259 | ||
219 | - | func latestCPF (_positionSize) = if ((_positionSize > 0)) | |
220 | - | then latestLongCumulativePremiumFraction() | |
221 | - | else latestShortCumulativePremiumFraction() | |
260 | + | func requireMoreMarginRatio (_marginRatio,_baseMarginRatio,_largerThanOrEqualTo) = { | |
261 | + | let remainingMarginRatio = (_marginRatio - _baseMarginRatio) | |
262 | + | if (if (_largerThanOrEqualTo) | |
263 | + | then (0 > remainingMarginRatio) | |
264 | + | else false) | |
265 | + | then throw("Invalid margin") | |
266 | + | else if (if (!(_largerThanOrEqualTo)) | |
267 | + | then (remainingMarginRatio >= 0) | |
268 | + | else false) | |
269 | + | then throw("Invalid margin") | |
270 | + | else true | |
271 | + | } | |
222 | 272 | ||
223 | 273 | ||
224 | - | func getPosition (invesor) = { | |
225 | - | let positionSizeOpt = getInteger(this, toCompositeKey(k_positionSize, invesor)) | |
274 | + | func latestCumulativePremiumFraction (_positionSize) = if ((_positionSize == 0)) | |
275 | + | then throw("Should not be called with _positionSize == 0") | |
276 | + | else if ((_positionSize > 0)) | |
277 | + | then latestLongCumulativePremiumFraction() | |
278 | + | else latestShortCumulativePremiumFraction() | |
279 | + | ||
280 | + | ||
281 | + | func getPosition (_trader) = { | |
282 | + | let positionSizeOpt = getInteger(this, toCompositeKey(k_positionSize, _trader)) | |
226 | 283 | match positionSizeOpt { | |
227 | 284 | case positionSize: Int => | |
228 | - | $Tuple4(positionSize, getIntegerValue(this, toCompositeKey(k_positionMargin, | |
285 | + | $Tuple4(positionSize, getIntegerValue(this, toCompositeKey(k_positionMargin, _trader)), getIntegerValue(this, toCompositeKey(k_positionOpenNotional, _trader)), getIntegerValue(this, toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _trader))) | |
229 | 286 | case _ => | |
230 | 287 | $Tuple4(0, 0, 0, 0) | |
231 | 288 | } | |
232 | 289 | } | |
233 | 290 | ||
234 | 291 | ||
235 | 292 | func requireOpenPosition (_trader) = if ((getPosition(_trader)._1 == 0)) | |
236 | 293 | then throw("No open position") | |
237 | 294 | else true | |
238 | 295 | ||
239 | 296 | ||
240 | 297 | func initialized () = valueOrElse(getBoolean(this, k_initialized), false) | |
241 | 298 | ||
242 | 299 | ||
243 | 300 | func paused () = valueOrElse(getBoolean(this, k_paused), false) | |
244 | 301 | ||
245 | 302 | ||
246 | 303 | func updateReserve (_isAdd,_quoteAssetAmount,_baseAssetAmount) = if (_isAdd) | |
247 | 304 | then { | |
248 | 305 | let newBase = (bsAstR() - _baseAssetAmount) | |
249 | 306 | if ((0 >= newBase)) | |
250 | 307 | then throw("Tx lead to base asset reserve <= 0, revert") | |
251 | 308 | else $Tuple4((qtAstR() + _quoteAssetAmount), newBase, (totalPositionSize() + _baseAssetAmount), (cumulativeNotional() + _quoteAssetAmount)) | |
252 | 309 | } | |
253 | 310 | else { | |
254 | 311 | let newQuote = (qtAstR() - _quoteAssetAmount) | |
255 | 312 | if ((0 >= newQuote)) | |
256 | 313 | then throw("Tx lead to base quote reserve <= 0, revert") | |
257 | 314 | else $Tuple4(newQuote, (bsAstR() + _baseAssetAmount), (totalPositionSize() - _baseAssetAmount), (cumulativeNotional() - _quoteAssetAmount)) | |
258 | 315 | } | |
259 | 316 | ||
260 | 317 | ||
261 | 318 | func swapInput (_isAdd,_quoteAssetAmount) = { | |
262 | 319 | let _qtAstR = qtAstR() | |
263 | 320 | let _bsAstR = bsAstR() | |
264 | - | let priceBefore = divd(_qtAstR, _bsAstR) | |
265 | - | let amountBaseAssetBoughtWithoutPriceImpact = muld(_quoteAssetAmount, priceBefore) | |
266 | 321 | let k = muld(_qtAstR, _bsAstR) | |
267 | 322 | let quoteAssetReserveAfter = if (_isAdd) | |
268 | 323 | then (_qtAstR + _quoteAssetAmount) | |
269 | 324 | else (_qtAstR - _quoteAssetAmount) | |
270 | 325 | let baseAssetReserveAfter = divd(k, quoteAssetReserveAfter) | |
271 | 326 | let amountBaseAssetBoughtAbs = abs((baseAssetReserveAfter - _bsAstR)) | |
272 | 327 | let amountBaseAssetBought = if (_isAdd) | |
273 | 328 | then amountBaseAssetBoughtAbs | |
274 | 329 | else -(amountBaseAssetBoughtAbs) | |
275 | - | let priceImpact = ((amountBaseAssetBoughtWithoutPriceImpact - amountBaseAssetBoughtAbs) / amountBaseAssetBoughtWithoutPriceImpact) | |
330 | + | let $t01217712370 = updateReserve(_isAdd, _quoteAssetAmount, amountBaseAssetBoughtAbs) | |
331 | + | let quoteAssetReserveAfter1 = $t01217712370._1 | |
332 | + | let baseAssetReserveAfter1 = $t01217712370._2 | |
333 | + | let totalPositionSizeAfter1 = $t01217712370._3 | |
334 | + | let cumulativeNotionalAfter1 = $t01217712370._4 | |
335 | + | let priceBefore = divd(_qtAstR, _bsAstR) | |
336 | + | let marketPrice = divd(_quoteAssetAmount, amountBaseAssetBoughtAbs) | |
337 | + | let priceDiff = abs((priceBefore - marketPrice)) | |
338 | + | let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff))) | |
276 | 339 | let maxPriceImpactValue = maxPriceImpact() | |
277 | 340 | if ((priceImpact > maxPriceImpactValue)) | |
278 | - | then throw(((("Price impact " + toString(priceImpact)) + " > max price impact ") + toString(maxPriceImpactValue))) | |
341 | + | 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))) | |
342 | + | else $Tuple5(amountBaseAssetBought, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, cumulativeNotionalAfter1) | |
343 | + | } | |
344 | + | ||
345 | + | ||
346 | + | func calcRemainMarginWithFundingPayment (_oldPositionSize,_oldPositionMargin,_oldPositionCumulativePremiumFraction,_marginDelta) = { | |
347 | + | let fundingPayment = if ((_oldPositionSize != 0)) | |
348 | + | then { | |
349 | + | let _latestCumulativePremiumFraction = latestCumulativePremiumFraction(_oldPositionSize) | |
350 | + | muld((_latestCumulativePremiumFraction - _oldPositionCumulativePremiumFraction), _oldPositionSize) | |
351 | + | } | |
352 | + | else 0 | |
353 | + | let signedMargin = ((_marginDelta - fundingPayment) + _oldPositionMargin) | |
354 | + | let $t01386113988 = if ((0 > signedMargin)) | |
355 | + | then $Tuple2(0, abs(signedMargin)) | |
356 | + | else $Tuple2(abs(signedMargin), 0) | |
357 | + | let remainMargin = $t01386113988._1 | |
358 | + | let badDebt = $t01386113988._2 | |
359 | + | $Tuple3(remainMargin, badDebt, fundingPayment) | |
360 | + | } | |
361 | + | ||
362 | + | ||
363 | + | func swapOutputWithReserves (_isAdd,_baseAssetAmount,_checkMaxPriceImpact,_quoteAssetReserve,_baseAssetReserve) = { | |
364 | + | let priceBefore = divd(_quoteAssetReserve, _baseAssetReserve) | |
365 | + | if ((_baseAssetAmount == 0)) | |
366 | + | then throw("Invalid base asset amount") | |
279 | 367 | else { | |
280 | - | let $t01037810581 = updateReserve(_isAdd, _quoteAssetAmount, amountBaseAssetBoughtAbs) | |
281 | - | let quoteAssetReserveAfter1 = $t01037810581._1 | |
282 | - | let baseAssetReserveAfter1 = $t01037810581._2 | |
283 | - | let totalPositionSizeAfter1 = $t01037810581._3 | |
284 | - | let cumulativeNotionalAfter1 = $t01037810581._4 | |
285 | - | $Tuple5(amountBaseAssetBought, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, cumulativeNotionalAfter1) | |
368 | + | let k = muld(_quoteAssetReserve, _baseAssetReserve) | |
369 | + | let baseAssetPoolAmountAfter = if (_isAdd) | |
370 | + | then (_baseAssetReserve + _baseAssetAmount) | |
371 | + | else (_baseAssetReserve - _baseAssetAmount) | |
372 | + | let quoteAssetAfter = divd(k, baseAssetPoolAmountAfter) | |
373 | + | let quoteAssetSold = abs((quoteAssetAfter - _quoteAssetReserve)) | |
374 | + | let maxPriceImpactValue = maxPriceImpact() | |
375 | + | let $t01496515158 = updateReserve(!(_isAdd), quoteAssetSold, _baseAssetAmount) | |
376 | + | let quoteAssetReserveAfter1 = $t01496515158._1 | |
377 | + | let baseAssetReserveAfter1 = $t01496515158._2 | |
378 | + | let totalPositionSizeAfter1 = $t01496515158._3 | |
379 | + | let cumulativeNotionalAfter1 = $t01496515158._4 | |
380 | + | let marketPrice = divd(quoteAssetSold, _baseAssetAmount) | |
381 | + | let priceDiff = abs((priceBefore - marketPrice)) | |
382 | + | let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff))) | |
383 | + | if (if ((priceImpact > maxPriceImpactValue)) | |
384 | + | then _checkMaxPriceImpact | |
385 | + | else false) | |
386 | + | 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))) | |
387 | + | else $Tuple8(quoteAssetSold, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, cumulativeNotionalAfter1, (totalLongPositionSize() - (if (_isAdd) | |
388 | + | then abs(_baseAssetAmount) | |
389 | + | else 0)), (totalShortPositionSize() - (if (!(_isAdd)) | |
390 | + | then abs(_baseAssetAmount) | |
391 | + | else 0)), priceImpact) | |
286 | 392 | } | |
287 | 393 | } | |
288 | 394 | ||
289 | 395 | ||
290 | - | func calcRemainMarginWithFundingPayment (_oldPositionSize,_oldPositionMargin,_oldPositionLstUpdCPF,_marginDelta) = { | |
291 | - | let _latestCPF = latestCPF(_oldPositionSize) | |
292 | - | let fundingPayment = if ((_oldPositionSize != 0)) | |
293 | - | then muld((_latestCPF - _oldPositionLstUpdCPF), _oldPositionSize) | |
294 | - | else 0 | |
295 | - | let signedMargin = ((_marginDelta - fundingPayment) + _oldPositionMargin) | |
296 | - | let $t01117011297 = if ((0 > signedMargin)) | |
297 | - | then $Tuple2(0, abs(signedMargin)) | |
298 | - | else $Tuple2(abs(signedMargin), 0) | |
299 | - | let remainMargin = $t01117011297._1 | |
300 | - | let badDebt = $t01117011297._2 | |
301 | - | $Tuple4(remainMargin, badDebt, fundingPayment, _latestCPF) | |
302 | - | } | |
303 | - | ||
304 | - | ||
305 | - | func swapOutput (_isAdd,_baseAssetAmount,_quoteAssetPoolAmount,_baseAssetPoolAmount) = if ((_baseAssetAmount == 0)) | |
306 | - | then throw("Invalid base asset amount") | |
307 | - | else { | |
308 | - | let k = muld(_quoteAssetPoolAmount, _baseAssetPoolAmount) | |
309 | - | let baseAssetPoolAmountAfter = if (_isAdd) | |
310 | - | then (_baseAssetPoolAmount + _baseAssetAmount) | |
311 | - | else (_baseAssetPoolAmount - _baseAssetAmount) | |
312 | - | let quoteAssetAfter = divd(k, baseAssetPoolAmountAfter) | |
313 | - | let quoteAssetSold = abs((quoteAssetAfter - _quoteAssetPoolAmount)) | |
314 | - | let $t01193412127 = updateReserve(!(_isAdd), quoteAssetSold, _baseAssetAmount) | |
315 | - | let quoteAssetReserveAfter1 = $t01193412127._1 | |
316 | - | let baseAssetReserveAfter1 = $t01193412127._2 | |
317 | - | let totalPositionSizeAfter1 = $t01193412127._3 | |
318 | - | let cumulativeNotionalAfter1 = $t01193412127._4 | |
319 | - | $Tuple7(quoteAssetSold, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, cumulativeNotionalAfter1, (totalLongPositionSize() - (if (_isAdd) | |
320 | - | then abs(_baseAssetAmount) | |
321 | - | else 0)), (totalShortPositionSize() - (if (!(_isAdd)) | |
322 | - | then abs(_baseAssetAmount) | |
323 | - | else 0))) | |
324 | - | } | |
396 | + | func swapOutput (_isAdd,_baseAssetAmount,_checkMaxPriceImpact) = swapOutputWithReserves(_isAdd, _baseAssetAmount, _checkMaxPriceImpact, qtAstR(), bsAstR()) | |
325 | 397 | ||
326 | 398 | ||
327 | 399 | func getOracleTwapPrice () = { | |
328 | 400 | let oracle = valueOrErrorMessage(addressFromString(getStringValue(this, k_ora)), "") | |
329 | 401 | let priceKey = getStringValue(this, k_ora_key) | |
330 | - | getIntegerValue(oracle, priceKey) | |
402 | + | let blockKey = getStringValue(this, k_ora_block_key) | |
403 | + | let lastValue = valueOrErrorMessage(getInteger(oracle, priceKey), ((("Can not get oracle price. Oracle: " + toString(oracle)) + " key: ") + priceKey)) | |
404 | + | lastValue | |
405 | + | } | |
406 | + | ||
407 | + | ||
408 | + | func requireNotOverSpreadLimit (_quoteAssetReserve,_baseAssetReserve) = { | |
409 | + | let oraclePrice = getOracleTwapPrice() | |
410 | + | let priceAfter = divd(_quoteAssetReserve, _baseAssetReserve) | |
411 | + | let averagePrice = divd((oraclePrice + priceAfter), (2 * DECIMAL_UNIT)) | |
412 | + | let absPriceDiff = divd(abs((oraclePrice - priceAfter)), averagePrice) | |
413 | + | if ((absPriceDiff > maxPriceSpread())) | |
414 | + | then throw(((("Price spread " + toString(absPriceDiff)) + " > max price spread ") + toString(maxPriceSpread()))) | |
415 | + | else true | |
331 | 416 | } | |
332 | 417 | ||
333 | 418 | ||
334 | 419 | func getSpotPrice () = { | |
335 | - | let _ | |
336 | - | let _ | |
337 | - | divd(_ | |
420 | + | let _quoteAssetReserve = qtAstR() | |
421 | + | let _baseAssetReserve = bsAstR() | |
422 | + | divd(_quoteAssetReserve, _baseAssetReserve) | |
338 | 423 | } | |
339 | 424 | ||
340 | 425 | ||
341 | 426 | func isOverFluctuationLimit () = { | |
342 | 427 | let oraclePrice = getOracleTwapPrice() | |
343 | 428 | let currentPrice = getSpotPrice() | |
344 | 429 | (divd(abs((oraclePrice - currentPrice)), oraclePrice) > spreadLimit()) | |
345 | 430 | } | |
346 | 431 | ||
347 | 432 | ||
433 | + | func getPositionAdjustedOpenNotional (_positionSize,_option,_quoteAssetReserve,_baseAssetReserve) = { | |
434 | + | let positionSizeAbs = abs(_positionSize) | |
435 | + | let isShort = (0 > _positionSize) | |
436 | + | let positionNotional = if ((_option == PNL_OPTION_SPOT)) | |
437 | + | then { | |
438 | + | let $t01837618547 = swapOutputWithReserves(!(isShort), positionSizeAbs, false, _quoteAssetReserve, _baseAssetReserve) | |
439 | + | let outPositionNotional = $t01837618547._1 | |
440 | + | let x1 = $t01837618547._2 | |
441 | + | let x2 = $t01837618547._3 | |
442 | + | let x3 = $t01837618547._4 | |
443 | + | outPositionNotional | |
444 | + | } | |
445 | + | else muld(positionSizeAbs, getOracleTwapPrice()) | |
446 | + | positionNotional | |
447 | + | } | |
448 | + | ||
449 | + | ||
348 | 450 | func getPositionNotionalAndUnrealizedPnl (_trader,_option) = { | |
349 | - | let $t01301913147 = getPosition(_trader) | |
350 | - | let positionSize = $t01301913147._1 | |
351 | - | let positionMargin = $t01301913147._2 | |
352 | - | let positionOpenNotional = $t01301913147._3 | |
353 | - | let positionLstUpdCPF = $t01301913147._4 | |
354 | - | let positionSizeAbs = abs(positionSize) | |
355 | - | if ((positionSizeAbs == 0)) | |
451 | + | let $t01894119069 = getPosition(_trader) | |
452 | + | let positionSize = $t01894119069._1 | |
453 | + | let positionMargin = $t01894119069._2 | |
454 | + | let positionOpenNotional = $t01894119069._3 | |
455 | + | let positionLstUpdCPF = $t01894119069._4 | |
456 | + | if ((positionSize == 0)) | |
356 | 457 | then throw("Invalid position size") | |
357 | 458 | else { | |
358 | 459 | let isShort = (0 > positionSize) | |
359 | - | let positionNotional = if ((_option == PNL_OPTION_SPOT)) | |
360 | - | then { | |
361 | - | let $t01339413541 = swapOutput(!(isShort), positionSizeAbs, qtAstR(), bsAstR()) | |
362 | - | let outPositionNotional = $t01339413541._1 | |
363 | - | let x1 = $t01339413541._2 | |
364 | - | let x2 = $t01339413541._3 | |
365 | - | let x3 = $t01339413541._4 | |
366 | - | outPositionNotional | |
367 | - | } | |
368 | - | else (positionSizeAbs * getOracleTwapPrice()) | |
460 | + | let positionNotional = getPositionAdjustedOpenNotional(positionSize, _option, qtAstR(), bsAstR()) | |
369 | 461 | let unrealizedPnl = if (isShort) | |
370 | 462 | then (positionOpenNotional - positionNotional) | |
371 | 463 | else (positionNotional - positionOpenNotional) | |
372 | 464 | $Tuple2(positionNotional, unrealizedPnl) | |
373 | 465 | } | |
374 | 466 | } | |
375 | 467 | ||
376 | 468 | ||
469 | + | func calcMarginRatio (_remainMargin,_badDebt,_positionNotional) = divd((_remainMargin - _badDebt), _positionNotional) | |
470 | + | ||
471 | + | ||
377 | 472 | func getMarginRatioByOption (_trader,_option) = { | |
378 | - | func x () = 0 | |
379 | - | ||
380 | - | let $t01396514076 = getPosition(_trader) | |
381 | - | let positionSize = $t01396514076._1 | |
382 | - | let positionMargin = $t01396514076._2 | |
383 | - | let pon = $t01396514076._3 | |
384 | - | let positionLstUpdCPF = $t01396514076._4 | |
385 | - | let $t01408214175 = getPositionNotionalAndUnrealizedPnl(_trader, _option) | |
386 | - | let positionNotional = $t01408214175._1 | |
387 | - | let unrealizedPnl = $t01408214175._2 | |
388 | - | let $t01418014346 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
389 | - | let remainMargin = $t01418014346._1 | |
390 | - | let badDebt = $t01418014346._2 | |
391 | - | divd((remainMargin - badDebt), positionNotional) | |
473 | + | let $t01990220013 = getPosition(_trader) | |
474 | + | let positionSize = $t01990220013._1 | |
475 | + | let positionMargin = $t01990220013._2 | |
476 | + | let pon = $t01990220013._3 | |
477 | + | let positionLstUpdCPF = $t01990220013._4 | |
478 | + | let $t02001920112 = getPositionNotionalAndUnrealizedPnl(_trader, _option) | |
479 | + | let positionNotional = $t02001920112._1 | |
480 | + | let unrealizedPnl = $t02001920112._2 | |
481 | + | let $t02011720283 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
482 | + | let remainMargin = $t02011720283._1 | |
483 | + | let badDebt = $t02011720283._2 | |
484 | + | calcMarginRatio(remainMargin, badDebt, positionNotional) | |
392 | 485 | } | |
393 | 486 | ||
394 | 487 | ||
395 | 488 | func getMarginRatio (_trader) = getMarginRatioByOption(_trader, PNL_OPTION_SPOT) | |
396 | 489 | ||
397 | 490 | ||
398 | - | func internalClosePosition (_trader) = { | |
399 | - | let $t01454214653 = getPosition(_trader) | |
400 | - | let positionSize = $t01454214653._1 | |
401 | - | let positionMargin = $t01454214653._2 | |
402 | - | let pon = $t01454214653._3 | |
403 | - | let positionLstUpdCPF = $t01454214653._4 | |
404 | - | let $t01465914746 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
405 | - | let x1 = $t01465914746._1 | |
406 | - | let unrealizedPnl = $t01465914746._2 | |
407 | - | let $t01475114923 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
408 | - | let remainMargin = $t01475114923._1 | |
409 | - | let badDebt = $t01475114923._2 | |
410 | - | let x2 = $t01475114923._3 | |
491 | + | func getPartialLiquidationAmount (_trader,_positionSize) = { | |
492 | + | let maximumRatio = vmax(partialLiquidationRatio(), (DECIMAL_UNIT - divd(getMarginRatio(_trader), maintenanceMarginRatio()))) | |
493 | + | let maxExchangedPositionSize = muld(abs(_positionSize), maximumRatio) | |
494 | + | let swapResult = swapOutput((_positionSize > 0), maxExchangedPositionSize, false) | |
495 | + | let maxExchangedQuoteAssetAmount = swapResult._1 | |
496 | + | let priceImpact = swapResult._8 | |
497 | + | if ((maxPriceImpact() > priceImpact)) | |
498 | + | then maxExchangedQuoteAssetAmount | |
499 | + | else { | |
500 | + | let exchangedPositionSize = muld(abs(_positionSize), partialLiquidationRatio()) | |
501 | + | let exchangedQuoteAssetAmount = swapOutput((_positionSize > 0), exchangedPositionSize, false)._1 | |
502 | + | exchangedQuoteAssetAmount | |
503 | + | } | |
504 | + | } | |
505 | + | ||
506 | + | ||
507 | + | func internalClosePosition (_trader,_checkMaxPriceImpact) = { | |
508 | + | let $t02146521593 = getPosition(_trader) | |
509 | + | let positionSize = $t02146521593._1 | |
510 | + | let positionMargin = $t02146521593._2 | |
511 | + | let positionOpenNotional = $t02146521593._3 | |
512 | + | let positionLstUpdCPF = $t02146521593._4 | |
513 | + | let unrealizedPnl = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT)._2 | |
514 | + | let $t02168821856 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
515 | + | let remainMargin = $t02168821856._1 | |
516 | + | let badDebt = $t02168821856._2 | |
411 | 517 | let exchangedPositionSize = -(positionSize) | |
412 | 518 | let realizedPnl = unrealizedPnl | |
413 | 519 | let marginToVault = -(remainMargin) | |
414 | - | let $ | |
415 | - | let exchangedQuoteAssetAmount = $ | |
416 | - | let quoteAssetReserveAfter = $ | |
417 | - | let baseAssetReserveAfter = $ | |
418 | - | let totalPositionSizeAfter = $ | |
419 | - | let cumulativeNotionalAfter = $ | |
420 | - | let totalLongAfter = $ | |
421 | - | let totalShortAfter = $ | |
422 | - | let | |
423 | - | $Tuple12(exchangedPositionSize, badDebt, realizedPnl, marginToVault, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, | |
520 | + | let $t02198322294 = swapOutput((positionSize > 0), abs(positionSize), _checkMaxPriceImpact) | |
521 | + | let exchangedQuoteAssetAmount = $t02198322294._1 | |
522 | + | let quoteAssetReserveAfter = $t02198322294._2 | |
523 | + | let baseAssetReserveAfter = $t02198322294._3 | |
524 | + | let totalPositionSizeAfter = $t02198322294._4 | |
525 | + | let cumulativeNotionalAfter = $t02198322294._5 | |
526 | + | let totalLongAfter = $t02198322294._6 | |
527 | + | let totalShortAfter = $t02198322294._7 | |
528 | + | let openInterestNotionalAfter = (openInterestNotional() - positionOpenNotional) | |
529 | + | $Tuple12(exchangedPositionSize, badDebt, realizedPnl, marginToVault, quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, exchangedQuoteAssetAmount, totalLongAfter, totalShortAfter) | |
424 | 530 | } | |
425 | 531 | ||
426 | 532 | ||
427 | 533 | func getTwapSpotPrice () = { | |
428 | 534 | let minuteId = ((lastBlock.timestamp / 1000) / 60) | |
429 | 535 | let startMinuteId = (minuteId - TWAP_INTERVAL) | |
430 | 536 | let listStr = valueOrElse(getString(this, k_lastDataStr), "") | |
431 | 537 | let list = split(listStr, ",") | |
432 | - | func filterFn ( | |
433 | - | then ( | |
434 | - | else | |
538 | + | func filterFn (accumulator,next) = if ((startMinuteId >= parseIntValue(next))) | |
539 | + | then (accumulator :+ parseIntValue(next)) | |
540 | + | else accumulator | |
435 | 541 | ||
436 | 542 | let listF = { | |
437 | 543 | let $l = list | |
438 | 544 | let $s = size($l) | |
439 | 545 | let $acc0 = nil | |
440 | 546 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
441 | 547 | then $a | |
442 | 548 | else filterFn($a, $l[$i]) | |
443 | 549 | ||
444 | 550 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
445 | 551 | then $a | |
446 | 552 | else throw("List size exceeds 20") | |
447 | 553 | ||
448 | 554 | $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) | |
449 | 555 | } | |
450 | 556 | let maxIndex = if ((size(listF) > 0)) | |
451 | 557 | then max(listF) | |
452 | 558 | else parseIntValue(list[0]) | |
453 | 559 | let lastMinuteId = valueOrElse(getInteger(this, k_lastMinuteId), 0) | |
454 | 560 | let endLastCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(lastMinuteId))), 0) | |
455 | 561 | let endLastPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(lastMinuteId))), 0) | |
456 | - | let | |
562 | + | let nowCumulativePrice = (endLastCumulativePrice + ((minuteId - lastMinuteId) * endLastPrice)) | |
457 | 563 | let startLastCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(maxIndex))), 0) | |
458 | 564 | let startLastPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(maxIndex))), 0) | |
459 | - | let | |
460 | - | (( | |
565 | + | let startCumulativePrice = (startLastCumulativePrice + ((startMinuteId - maxIndex) * startLastPrice)) | |
566 | + | ((nowCumulativePrice - startCumulativePrice) / TWAP_INTERVAL) | |
461 | 567 | } | |
462 | 568 | ||
463 | 569 | ||
464 | - | func updateSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact) = [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)] | |
570 | + | 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)] | |
465 | 571 | ||
466 | 572 | ||
467 | 573 | 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)] | |
468 | 574 | ||
469 | 575 | ||
470 | - | func updatePosition (_address,_size,_margin,_ | |
576 | + | 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)] | |
471 | 577 | ||
472 | 578 | ||
473 | 579 | func appendTwap (price) = { | |
474 | 580 | let minuteId = ((lastBlock.timestamp / 1000) / 60) | |
475 | 581 | let previousMinuteId = valueOrElse(getInteger(this, k_lastMinuteId), 0) | |
476 | 582 | if ((previousMinuteId > minuteId)) | |
477 | 583 | then throw("TWAP out-of-order") | |
478 | 584 | else { | |
479 | 585 | let lastMinuteId = if ((previousMinuteId == 0)) | |
480 | 586 | then minuteId | |
481 | 587 | else previousMinuteId | |
482 | - | let listStr = valueOrElse(getString(this, k_lastDataStr), "") | |
483 | - | let oldList = split(listStr, ",") | |
484 | - | let list = if ((size(oldList) > TWAP_INTERVAL)) | |
485 | - | then (removeByIndex(oldList, 0) :+ toString(minuteId)) | |
486 | - | else (oldList :+ toString(minuteId)) | |
487 | - | let prevCummulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(previousMinuteId))), 0) | |
488 | - | let prevPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(previousMinuteId))), price) | |
489 | - | let lastCummulativePrice = (prevCummulativePrice + ((minuteId - lastMinuteId) * prevPrice)) | |
490 | - | func join (accum,val) = ((accum + val) + ",") | |
491 | - | ||
492 | - | let newListStr = { | |
493 | - | let $l = list | |
494 | - | let $s = size($l) | |
495 | - | let $acc0 = "" | |
496 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
497 | - | then $a | |
498 | - | else join($a, $l[$i]) | |
499 | - | ||
500 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
501 | - | then $a | |
502 | - | else throw("List size exceeds 20") | |
503 | - | ||
504 | - | $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) | |
505 | - | } | |
506 | - | let newListStrU = dropRight(newListStr, 1) | |
507 | - | let newListStrR = if ((take(newListStrU, 1) == ",")) | |
508 | - | then drop(newListStrU, 1) | |
509 | - | else newListStrU | |
510 | - | [IntegerEntry(((k_twapDataLastCumulativePrice + "_") + toString(minuteId)), lastCummulativePrice), IntegerEntry(((k_twapDataLastPrice + "_") + toString(minuteId)), price), IntegerEntry(k_lastMinuteId, minuteId), StringEntry(k_lastDataStr, newListStrR)] | |
588 | + | if ((minuteId > previousMinuteId)) | |
589 | + | then { | |
590 | + | let prevCumulativePrice = valueOrElse(getInteger(this, ((k_twapDataLastCumulativePrice + "_") + toString(previousMinuteId))), 0) | |
591 | + | let prevPrice = valueOrElse(getInteger(this, ((k_twapDataLastPrice + "_") + toString(previousMinuteId))), price) | |
592 | + | let lastCumulativePrice = (prevCumulativePrice + ((minuteId - lastMinuteId) * prevPrice)) | |
593 | + | let list = pushToQueue(strToList(valueOrElse(getString(this, k_lastDataStr), "")), TWAP_INTERVAL, toString(minuteId)) | |
594 | + | [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))] | |
595 | + | } | |
596 | + | else { | |
597 | + | let twapDataPreviousMinuteId = valueOrElse(getInteger(this, toCompositeKey(k_twapDataPreviousMinuteId, toString(minuteId))), 0) | |
598 | + | let prevCumulativePrice = valueOrElse(getInteger(this, toCompositeKey(k_twapDataLastCumulativePrice, toString(twapDataPreviousMinuteId))), 0) | |
599 | + | let prevPrice = valueOrElse(getInteger(this, toCompositeKey(k_twapDataLastPrice, toString(twapDataPreviousMinuteId))), price) | |
600 | + | let lastCumulativePrice = (prevCumulativePrice + ((minuteId - twapDataPreviousMinuteId) * prevPrice)) | |
601 | + | [IntegerEntry(toCompositeKey(k_twapDataLastCumulativePrice, toString(minuteId)), lastCumulativePrice), IntegerEntry(toCompositeKey(k_twapDataLastPrice, toString(minuteId)), price)] | |
602 | + | } | |
511 | 603 | } | |
512 | 604 | } | |
513 | 605 | ||
514 | 606 | ||
515 | - | func updateAmm (_qtAstR,_bsAstR,_totalPositionSizeAfter,_cumulativeNotionalAfter,_openInteresetNotional,_totalLongPositionSize,_totalShortPositionSize) = if (((_totalLongPositionSize - _totalShortPositionSize) != _totalPositionSizeAfter)) | |
607 | + | func updateAmmReserves (_qtAstR,_bsAstR) = [IntegerEntry(k_quoteAssetReserve, _qtAstR), IntegerEntry(k_baseAssetReserve, _bsAstR)] | |
608 | + | ||
609 | + | ||
610 | + | func updateAmm (_qtAstR,_bsAstR,_totalPositionSizeAfter,_cumulativeNotionalAfter,_openInterestNotional,_totalLongPositionSize,_totalShortPositionSize) = if (((_totalLongPositionSize - _totalShortPositionSize) != _totalPositionSizeAfter)) | |
516 | 611 | then throw(((((("Invalid AMM state data: " + toString(_totalLongPositionSize)) + " + ") + toString(_totalShortPositionSize)) + " != ") + toString(_totalPositionSizeAfter))) | |
517 | - | else ( | |
612 | + | 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))) | |
518 | 613 | ||
519 | 614 | ||
520 | 615 | func deletePosition (_address) = [DeleteEntry(toCompositeKey(k_positionSize, _address)), DeleteEntry(toCompositeKey(k_positionMargin, _address)), DeleteEntry(toCompositeKey(k_positionOpenNotional, _address)), DeleteEntry(toCompositeKey(k_positionLastUpdatedCumulativePremiumFraction, _address))] | |
521 | 616 | ||
522 | 617 | ||
523 | 618 | func withdraw (_address,_amount) = { | |
524 | 619 | let balance = assetBalance(this, quoteAsset()) | |
525 | 620 | if ((_amount > balance)) | |
526 | 621 | then throw(((("Unable to withdraw " + toString(_amount)) + " from contract balance ") + toString(balance))) | |
527 | 622 | else [ScriptTransfer(_address, _amount, quoteAsset())] | |
528 | 623 | } | |
529 | 624 | ||
530 | 625 | ||
531 | 626 | func updateBalance (i) = if ((0 > i)) | |
532 | 627 | then throw("Balance") | |
533 | 628 | else [IntegerEntry(k_balance, i)] | |
534 | 629 | ||
535 | 630 | ||
536 | 631 | func transferFee (i) = [ScriptTransfer(stakingAddress(), i, quoteAsset())] | |
537 | 632 | ||
538 | 633 | ||
539 | 634 | @Callable(i) | |
540 | 635 | func pause () = if ((i.caller != adminAddress())) | |
541 | 636 | then throw("Invalid togglePause params") | |
542 | 637 | else [BooleanEntry(k_paused, true)] | |
543 | 638 | ||
544 | 639 | ||
545 | 640 | ||
546 | 641 | @Callable(i) | |
547 | 642 | func unpause () = if ((i.caller != adminAddress())) | |
548 | 643 | then throw("Invalid togglePause params") | |
549 | 644 | else [BooleanEntry(k_paused, false)] | |
550 | 645 | ||
551 | 646 | ||
552 | 647 | ||
553 | 648 | @Callable(i) | |
554 | - | func changeSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact) = if ((i.caller != adminAddress())) | |
555 | - | then throw("Invalid changeSettings params") | |
556 | - | else updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact) | |
649 | + | func addLiquidity (_quoteAssetAmount) = if (if ((i.caller != adminAddress())) | |
650 | + | then true | |
651 | + | else (0 >= _quoteAssetAmount)) | |
652 | + | then throw("Invalid addLiquidity params") | |
653 | + | else { | |
654 | + | let _qtAstR = qtAstR() | |
655 | + | let _bsAstR = bsAstR() | |
656 | + | let price = divd(_qtAstR, _bsAstR) | |
657 | + | let baseAssetAmountToAdd = divd(_quoteAssetAmount, price) | |
658 | + | let qtAstRAfter = (_qtAstR + _quoteAssetAmount) | |
659 | + | let bsAstRAfter = (_bsAstR + baseAssetAmountToAdd) | |
660 | + | updateAmmReserves(qtAstRAfter, bsAstRAfter) | |
661 | + | } | |
557 | 662 | ||
558 | 663 | ||
559 | 664 | ||
560 | 665 | @Callable(i) | |
561 | - | func initialize (_qtAstR,_bsAstR,_fundingPeriod,_initMarginRatio,_mmr,_liquidationFeeRatio,_fee,_oracle,_oracleKey,_coordinator,_spreadLimit,_maxPriceImpact) = if (if (if (if (if (if (if (if (if (if ((0 >= _qtAstR)) | |
666 | + | func removeLiquidity (_quoteAssetAmount) = if (if ((i.caller != adminAddress())) | |
667 | + | then true | |
668 | + | else (0 >= _quoteAssetAmount)) | |
669 | + | then throw("Invalid removeLiquidity params") | |
670 | + | else { | |
671 | + | let _qtAstR = qtAstR() | |
672 | + | let _bsAstR = bsAstR() | |
673 | + | let price = divd(_qtAstR, _bsAstR) | |
674 | + | let baseAssetAmountToRemove = divd(_quoteAssetAmount, price) | |
675 | + | let qtAstRAfter = (_qtAstR - _quoteAssetAmount) | |
676 | + | let bsAstRAfter = (_bsAstR - baseAssetAmountToRemove) | |
677 | + | updateAmmReserves(qtAstRAfter, bsAstRAfter) | |
678 | + | } | |
679 | + | ||
680 | + | ||
681 | + | ||
682 | + | @Callable(i) | |
683 | + | func changeSettings (_initMarginRatio,_mmr,_liquidationFeeRatio,_fundingPeriod,_fee,_spreadLimit,_maxPriceImpact,_partialLiquidationRatio,_maxPriceSpread) = if ((i.caller != adminAddress())) | |
684 | + | then throw("Invalid changeSettings params") | |
685 | + | else updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact, _partialLiquidationRatio, _maxPriceSpread) | |
686 | + | ||
687 | + | ||
688 | + | ||
689 | + | @Callable(i) | |
690 | + | 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)) | |
562 | 691 | then true | |
563 | 692 | else (0 >= _bsAstR)) | |
564 | 693 | then true | |
565 | 694 | else (0 >= _fundingPeriod)) | |
566 | 695 | then true | |
567 | 696 | else (0 >= _initMarginRatio)) | |
568 | 697 | then true | |
569 | 698 | else (0 >= _mmr)) | |
570 | 699 | then true | |
571 | 700 | else (0 >= _liquidationFeeRatio)) | |
572 | 701 | then true | |
573 | 702 | else (0 >= _fee)) | |
574 | 703 | then true | |
575 | 704 | else (0 >= _spreadLimit)) | |
576 | 705 | then true | |
577 | 706 | else (0 >= _maxPriceImpact)) | |
578 | 707 | then true | |
708 | + | else (0 >= _partialLiquidationRatio)) | |
709 | + | then true | |
710 | + | else (0 >= _maxPriceSpread)) | |
711 | + | then true | |
579 | 712 | else initialized()) | |
580 | 713 | then throw("Invalid initialize parameters") | |
581 | - | else ((((updateAmm(_qtAstR, _bsAstR, 0, 0, 0, 0, 0) ++ updateSettings(_initMarginRatio, _mmr, _liquidationFeeRatio, _fundingPeriod, _fee, _spreadLimit, _maxPriceImpact)) ++ 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)]) | |
714 | + | 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)]) | |
582 | 715 | ||
583 | 716 | ||
584 | 717 | ||
585 | 718 | @Callable(i) | |
586 | - | func decreasePosition (_direction,_amount,_leverage,_minBaseAssetAmount) = if (if (if (if (if (if (if ((_direction != DIR_LONG)) | |
587 | - | then (_direction != DIR_SHORT) | |
588 | - | else false) | |
719 | + | func setInitMarginRatio (_initMarginRatio) = if (if ((0 >= _initMarginRatio)) | |
589 | 720 | then true | |
590 | - | else (0 >= _amount)) | |
591 | - | then true | |
592 | - | else if (((1 * DECIMAL_UNIT) > _leverage)) | |
593 | - | then true | |
594 | - | else (_leverage > (3 * DECIMAL_UNIT))) | |
721 | + | else !(initialized())) | |
722 | + | then throw("Invalid setInitMarginRatio parameters") | |
723 | + | else updateSettings(_initMarginRatio, maintenanceMarginRatio(), liquidationFeeRatio(), fundingPeriodRaw(), fee(), spreadLimit(), maxPriceImpact(), partialLiquidationRatio(), maxPriceSpread()) | |
724 | + | ||
725 | + | ||
726 | + | ||
727 | + | @Callable(i) | |
728 | + | func decreasePosition (_amount,_leverage,_minBaseAssetAmount) = if (if (if (if (if ((0 >= _amount)) | |
595 | 729 | then true | |
596 | 730 | else !(initialized())) | |
597 | 731 | then true | |
598 | 732 | else !(requireMoreMarginRatio(divd(DECIMAL_UNIT, _leverage), initMarginRatio(), true))) | |
599 | 733 | then true | |
734 | + | else !(requireOpenPosition(toString(i.caller)))) | |
735 | + | then true | |
600 | 736 | else paused()) | |
601 | 737 | then throw("Invalid decreasePosition parameters") | |
602 | 738 | else { | |
603 | - | let $t02461824770 = getPosition(toString(i.caller)) | |
604 | - | let oldPositionSize = $t02461824770._1 | |
605 | - | let oldPositionMargin = $t02461824770._2 | |
606 | - | let oldPositionOpenNotional = $t02461824770._3 | |
607 | - | let oldPositionLstUpdCPF = $t02461824770._4 | |
608 | - | let isNewPosition = (oldPositionSize == 0) | |
609 | - | let isSameDirection = if ((oldPositionSize > 0)) | |
610 | - | then (_direction == DIR_LONG) | |
611 | - | else (_direction == DIR_SHORT) | |
612 | - | let expandExisting = if (!(isNewPosition)) | |
613 | - | then isSameDirection | |
614 | - | else false | |
739 | + | let $t03418734339 = getPosition(toString(i.caller)) | |
740 | + | let oldPositionSize = $t03418734339._1 | |
741 | + | let oldPositionMargin = $t03418734339._2 | |
742 | + | let oldPositionOpenNotional = $t03418734339._3 | |
743 | + | let oldPositionLstUpdCPF = $t03418734339._4 | |
744 | + | let _direction = if ((oldPositionSize > 0)) | |
745 | + | then DIR_SHORT | |
746 | + | else DIR_LONG | |
615 | 747 | let isAdd = (_direction == DIR_LONG) | |
616 | - | let $t02505928078 = if (if (isNewPosition) | |
617 | - | then true | |
618 | - | else expandExisting) | |
619 | - | then throw("Use increasePosition to open new or increase position") | |
620 | - | else { | |
621 | - | let openNotional = muld(_amount, _leverage) | |
622 | - | let $t02556525681 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT) | |
623 | - | let oldPositionNotional = $t02556525681._1 | |
624 | - | let unrealizedPnl = $t02556525681._2 | |
625 | - | if ((oldPositionNotional > openNotional)) | |
626 | - | then { | |
627 | - | let $t02574325973 = swapInput(isAdd, openNotional) | |
628 | - | let exchangedPositionSize = $t02574325973._1 | |
629 | - | let quoteAssetReserveAfter = $t02574325973._2 | |
630 | - | let baseAssetReserveAfter = $t02574325973._3 | |
631 | - | let totalPositionSizeAfter = $t02574325973._4 | |
632 | - | let cumulativeNotionalAfter = $t02574325973._5 | |
633 | - | let exchangedPositionSizeAbs = abs(exchangedPositionSize) | |
634 | - | if (if ((_minBaseAssetAmount != 0)) | |
635 | - | then (_minBaseAssetAmount > exchangedPositionSizeAbs) | |
636 | - | else false) | |
637 | - | then throw(((("Too little basse asset exchanged, got " + toString(exchangedPositionSizeAbs)) + " expected ") + toString(_minBaseAssetAmount))) | |
638 | - | else { | |
639 | - | let realizedPnl = if ((oldPositionSize != 0)) | |
640 | - | then divd(muld(unrealizedPnl, exchangedPositionSizeAbs), oldPositionSize) | |
641 | - | else 0 | |
642 | - | let $t02651426785 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl) | |
643 | - | let remainMargin = $t02651426785._1 | |
644 | - | let badDebt = $t02651426785._2 | |
645 | - | let fundingPayment = $t02651426785._3 | |
646 | - | let oldLatestCPF = $t02651426785._4 | |
647 | - | let exchangedQuoteAssetAmount = openNotional | |
648 | - | let unrealizedPnlAfter = (unrealizedPnl - realizedPnl) | |
649 | - | let remainOpenNotional = if ((oldPositionSize > 0)) | |
650 | - | then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter) | |
651 | - | else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount) | |
652 | - | let newPositionSize = (oldPositionSize + exchangedPositionSize) | |
653 | - | $Tuple11(newPositionSize, remainMargin, abs(remainOpenNotional), oldLatestCPF, baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, (openInteresetNotional() - openNotional), (totalLongPositionSize() - (if ((newPositionSize > 0)) | |
654 | - | then abs(exchangedPositionSize) | |
655 | - | else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize)) | |
656 | - | then abs(exchangedPositionSize) | |
657 | - | else 0))) | |
658 | - | } | |
748 | + | let openNotional = muld(_amount, _leverage) | |
749 | + | let $t03451234628 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT) | |
750 | + | let oldPositionNotional = $t03451234628._1 | |
751 | + | let unrealizedPnl = $t03451234628._2 | |
752 | + | let $t03463437183 = if ((oldPositionNotional > openNotional)) | |
753 | + | then { | |
754 | + | let $t03501135230 = swapInput(isAdd, openNotional) | |
755 | + | let exchangedPositionSize = $t03501135230._1 | |
756 | + | let quoteAssetReserveAfter = $t03501135230._2 | |
757 | + | let baseAssetReserveAfter = $t03501135230._3 | |
758 | + | let totalPositionSizeAfter = $t03501135230._4 | |
759 | + | let cumulativeNotionalAfter = $t03501135230._5 | |
760 | + | let exchangedPositionSizeAbs = abs(exchangedPositionSize) | |
761 | + | if (if ((_minBaseAssetAmount != 0)) | |
762 | + | then (_minBaseAssetAmount > exchangedPositionSizeAbs) | |
763 | + | else false) | |
764 | + | then throw(((("Too little base asset exchanged, got " + toString(exchangedPositionSizeAbs)) + " expected ") + toString(_minBaseAssetAmount))) | |
765 | + | else { | |
766 | + | let realizedPnl = divd(muld(unrealizedPnl, exchangedPositionSizeAbs), abs(oldPositionSize)) | |
767 | + | let $t03566735912 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl) | |
768 | + | let remainMargin = $t03566735912._1 | |
769 | + | let badDebt = $t03566735912._2 | |
770 | + | let fundingPayment = $t03566735912._3 | |
771 | + | let exchangedQuoteAssetAmount = openNotional | |
772 | + | let unrealizedPnlAfter = (unrealizedPnl - realizedPnl) | |
773 | + | let remainOpenNotional = if ((oldPositionSize > 0)) | |
774 | + | then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter) | |
775 | + | else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount) | |
776 | + | let newPositionSize = (oldPositionSize + exchangedPositionSize) | |
777 | + | $Tuple11(newPositionSize, remainMargin, abs(remainOpenNotional), latestCumulativePremiumFraction(newPositionSize), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, (openInterestNotional() - openNotional), (totalLongPositionSize() - (if ((newPositionSize > 0)) | |
778 | + | then abs(exchangedPositionSize) | |
779 | + | else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize)) | |
780 | + | then abs(exchangedPositionSize) | |
781 | + | else 0))) | |
659 | 782 | } | |
660 | - | else throw("Close position first") | |
661 | 783 | } | |
662 | - | let newPositionSize = $t02505928078._1 | |
663 | - | let newPositionRemainMargin = $t02505928078._2 | |
664 | - | let newPosiionOpenNotional = $t02505928078._3 | |
665 | - | let newPositionLatestCPF = $t02505928078._4 | |
666 | - | let baseAssetReserveAfter = $t02505928078._5 | |
667 | - | let quoteAssetReserveAfter = $t02505928078._6 | |
668 | - | let totalPositionSizeAfter = $t02505928078._7 | |
669 | - | let cumulativeNotionalAfter = $t02505928078._8 | |
670 | - | let openInteresetNotionalAfter = $t02505928078._9 | |
671 | - | let totalLongAfter = $t02505928078._10 | |
672 | - | let totalShortAfter = $t02505928078._11 | |
673 | - | (updatePosition(toString(i.caller), newPositionSize, newPositionRemainMargin, newPosiionOpenNotional, newPositionLatestCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInteresetNotionalAfter, totalLongAfter, totalShortAfter)) | |
784 | + | else throw("Close position first") | |
785 | + | let newPositionSize = $t03463437183._1 | |
786 | + | let newPositionRemainMargin = $t03463437183._2 | |
787 | + | let newPositionOpenNotional = $t03463437183._3 | |
788 | + | let newPositionLatestCPF = $t03463437183._4 | |
789 | + | let baseAssetReserveAfter = $t03463437183._5 | |
790 | + | let quoteAssetReserveAfter = $t03463437183._6 | |
791 | + | let totalPositionSizeAfter = $t03463437183._7 | |
792 | + | let cumulativeNotionalAfter = $t03463437183._8 | |
793 | + | let openInterestNotionalAfter = $t03463437183._9 | |
794 | + | let totalLongAfter = $t03463437183._10 | |
795 | + | let totalShortAfter = $t03463437183._11 | |
796 | + | let notifyNotional = invoke(minerAddress(), "notifyNotional", [toString(i.caller), newPositionOpenNotional], nil) | |
797 | + | if ((notifyNotional == notifyNotional)) | |
798 | + | then (updatePosition(toString(i.caller), newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter)) | |
799 | + | else throw("Strict value is not equal to itself.") | |
674 | 800 | } | |
675 | 801 | ||
676 | 802 | ||
677 | 803 | ||
678 | 804 | @Callable(i) | |
679 | 805 | func increasePosition (_direction,_leverage,_minBaseAssetAmount) = { | |
680 | 806 | let _rawAmount = i.payments[0].amount | |
681 | - | | |
807 | + | if (if (if (if (if (if (if ((_direction != DIR_LONG)) | |
682 | 808 | then (_direction != DIR_SHORT) | |
683 | 809 | else false) | |
684 | 810 | then true | |
685 | 811 | else (0 >= _rawAmount)) | |
686 | - | then true | |
687 | - | else if (((1 * DECIMAL_UNIT) > _leverage)) | |
688 | - | then true | |
689 | - | else (_leverage > (3 * DECIMAL_UNIT))) | |
690 | 812 | then true | |
691 | 813 | else !(initialized())) | |
692 | 814 | then true | |
693 | 815 | else (i.payments[0].assetId != quoteAsset())) | |
694 | 816 | then true | |
695 | 817 | else !(requireMoreMarginRatio(divd(DECIMAL_UNIT, _leverage), initMarginRatio(), true))) | |
696 | 818 | then true | |
697 | 819 | else paused()) | |
698 | 820 | then throw("Invalid increasePosition parameters") | |
699 | 821 | else { | |
700 | 822 | let feeAmount = muld(_rawAmount, fee()) | |
701 | 823 | let _amount = (_rawAmount - feeAmount) | |
702 | - | let $ | |
703 | - | let oldPositionSize = $ | |
704 | - | let oldPositionMargin = $ | |
705 | - | let oldPositionOpenNotional = $ | |
706 | - | let oldPositionLstUpdCPF = $ | |
824 | + | let $t03830138453 = getPosition(toString(i.caller)) | |
825 | + | let oldPositionSize = $t03830138453._1 | |
826 | + | let oldPositionMargin = $t03830138453._2 | |
827 | + | let oldPositionOpenNotional = $t03830138453._3 | |
828 | + | let oldPositionLstUpdCPF = $t03830138453._4 | |
707 | 829 | let isNewPosition = (oldPositionSize == 0) | |
708 | 830 | let isSameDirection = if ((oldPositionSize > 0)) | |
709 | 831 | then (_direction == DIR_LONG) | |
710 | 832 | else (_direction == DIR_SHORT) | |
711 | 833 | let expandExisting = if (!(isNewPosition)) | |
712 | 834 | then isSameDirection | |
713 | 835 | else false | |
714 | 836 | let isAdd = (_direction == DIR_LONG) | |
715 | - | let $ | |
837 | + | let $t03874241310 = if (if (isNewPosition) | |
716 | 838 | then true | |
717 | 839 | else expandExisting) | |
718 | 840 | then { | |
719 | 841 | let openNotional = muld(_amount, _leverage) | |
720 | - | let $ | |
721 | - | let amountBaseAssetBought = $ | |
722 | - | let quoteAssetReserveAfter = $ | |
723 | - | let baseAssetReserveAfter = $ | |
724 | - | let totalPositionSizeAfter = $ | |
725 | - | let cumulativeNotionalAfter = $ | |
842 | + | let $t03916639372 = swapInput(isAdd, openNotional) | |
843 | + | let amountBaseAssetBought = $t03916639372._1 | |
844 | + | let quoteAssetReserveAfter = $t03916639372._2 | |
845 | + | let baseAssetReserveAfter = $t03916639372._3 | |
846 | + | let totalPositionSizeAfter = $t03916639372._4 | |
847 | + | let cumulativeNotionalAfter = $t03916639372._5 | |
726 | 848 | if (if ((_minBaseAssetAmount != 0)) | |
727 | 849 | then (_minBaseAssetAmount > abs(amountBaseAssetBought)) | |
728 | 850 | else false) | |
729 | 851 | then throw(((("Limit error: " + toString(abs(amountBaseAssetBought))) + " < ") + toString(_minBaseAssetAmount))) | |
730 | 852 | else { | |
731 | 853 | let newPositionSize = (oldPositionSize + amountBaseAssetBought) | |
732 | 854 | let increaseMarginRequirement = divd(openNotional, _leverage) | |
733 | - | let $t03056630819 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, increaseMarginRequirement) | |
734 | - | let remainMargin = $t03056630819._1 | |
735 | - | let x1 = $t03056630819._2 | |
736 | - | let x2 = $t03056630819._3 | |
737 | - | let oldLatestCPF = $t03056630819._4 | |
738 | - | $Tuple11(newPositionSize, remainMargin, (oldPositionOpenNotional + openNotional), oldLatestCPF, baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, (openInteresetNotional() + openNotional), (totalLongPositionSize() + (if ((newPositionSize > 0)) | |
739 | - | then abs(amountBaseAssetBought) | |
740 | - | else 0)), (totalShortPositionSize() + (if ((0 > newPositionSize)) | |
741 | - | then abs(amountBaseAssetBought) | |
742 | - | else 0))) | |
855 | + | let $t03975339992 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, increaseMarginRequirement) | |
856 | + | let remainMargin = $t03975339992._1 | |
857 | + | let x1 = $t03975339992._2 | |
858 | + | let x2 = $t03975339992._3 | |
859 | + | if (!(requireNotOverSpreadLimit(quoteAssetReserveAfter, baseAssetReserveAfter))) | |
860 | + | then throw("Over max spread limit") | |
861 | + | else $Tuple11(newPositionSize, remainMargin, (oldPositionOpenNotional + openNotional), latestCumulativePremiumFraction(newPositionSize), baseAssetReserveAfter, quoteAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, (openInterestNotional() + openNotional), (totalLongPositionSize() + (if ((newPositionSize > 0)) | |
862 | + | then abs(amountBaseAssetBought) | |
863 | + | else 0)), (totalShortPositionSize() + (if ((0 > newPositionSize)) | |
864 | + | then abs(amountBaseAssetBought) | |
865 | + | else 0))) | |
743 | 866 | } | |
744 | 867 | } | |
745 | 868 | else { | |
746 | 869 | let openNotional = muld(_amount, _leverage) | |
747 | - | let $ | |
748 | - | let oldPositionNotional = $ | |
749 | - | let unrealizedPnl = $ | |
870 | + | let $t04100341119 = getPositionNotionalAndUnrealizedPnl(toString(i.caller), PNL_OPTION_SPOT) | |
871 | + | let oldPositionNotional = $t04100341119._1 | |
872 | + | let unrealizedPnl = $t04100341119._2 | |
750 | 873 | if ((oldPositionNotional > openNotional)) | |
751 | 874 | then throw("Use decreasePosition to decrease position size") | |
752 | 875 | else throw("Close position first") | |
753 | 876 | } | |
754 | - | let newPositionSize = $ | |
755 | - | let newPositionRemainMargin = $ | |
756 | - | let | |
757 | - | let newPositionLatestCPF = $ | |
758 | - | let baseAssetReserveAfter = $ | |
759 | - | let quoteAssetReserveAfter = $ | |
760 | - | let totalPositionSizeAfter = $ | |
761 | - | let cumulativeNotionalAfter = $ | |
762 | - | let | |
763 | - | let totalLongAfter = $ | |
764 | - | let totalShortAfter = $ | |
877 | + | let newPositionSize = $t03874241310._1 | |
878 | + | let newPositionRemainMargin = $t03874241310._2 | |
879 | + | let newPositionOpenNotional = $t03874241310._3 | |
880 | + | let newPositionLatestCPF = $t03874241310._4 | |
881 | + | let baseAssetReserveAfter = $t03874241310._5 | |
882 | + | let quoteAssetReserveAfter = $t03874241310._6 | |
883 | + | let totalPositionSizeAfter = $t03874241310._7 | |
884 | + | let cumulativeNotionalAfter = $t03874241310._8 | |
885 | + | let openInterestNotionalAfter = $t03874241310._9 | |
886 | + | let totalLongAfter = $t03874241310._10 | |
887 | + | let totalShortAfter = $t03874241310._11 | |
765 | 888 | let feeToStakers = (feeAmount / 2) | |
766 | 889 | let feeToInsurance = (feeAmount - feeToStakers) | |
767 | 890 | let stake = invoke(quoteAssetStaking(), "lockNeutrinoSP", [toString(stakingAddress()), ALL_FEES], [AttachedPayment(quoteAsset(), _amount)]) | |
768 | 891 | if ((stake == stake)) | |
769 | 892 | then { | |
770 | 893 | let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)]) | |
771 | 894 | if ((depositInsurance == depositInsurance)) | |
772 | - | then (((updatePosition(toString(i.caller), newPositionSize, newPositionRemainMargin, newPosiionOpenNotional, newPositionLatestCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInteresetNotionalAfter, totalLongAfter, totalShortAfter)) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) | |
895 | + | then { | |
896 | + | let notifyFee = invoke(minerAddress(), "notifyFees", [toString(i.caller), feeAmount], nil) | |
897 | + | if ((notifyFee == notifyFee)) | |
898 | + | then { | |
899 | + | let notifyNotional = invoke(minerAddress(), "notifyNotional", [toString(i.caller), newPositionOpenNotional], nil) | |
900 | + | if ((notifyNotional == notifyNotional)) | |
901 | + | then (((updatePosition(toString(i.caller), newPositionSize, newPositionRemainMargin, newPositionOpenNotional, newPositionLatestCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter)) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) | |
902 | + | else throw("Strict value is not equal to itself.") | |
903 | + | } | |
904 | + | else throw("Strict value is not equal to itself.") | |
905 | + | } | |
773 | 906 | else throw("Strict value is not equal to itself.") | |
774 | 907 | } | |
775 | 908 | else throw("Strict value is not equal to itself.") | |
776 | 909 | } | |
777 | 910 | } | |
778 | 911 | ||
779 | 912 | ||
780 | 913 | ||
781 | 914 | @Callable(i) | |
782 | 915 | func addMargin () = { | |
783 | 916 | let _rawAmount = i.payments[0].amount | |
784 | 917 | if (if (if (if ((i.payments[0].assetId != quoteAsset())) | |
785 | 918 | then true | |
786 | 919 | else !(requireOpenPosition(toString(i.caller)))) | |
787 | 920 | then true | |
788 | 921 | else !(initialized())) | |
789 | 922 | then true | |
790 | 923 | else paused()) | |
791 | 924 | then throw("Invalid addMargin parameters") | |
792 | 925 | else { | |
793 | 926 | let feeAmount = muld(_rawAmount, fee()) | |
794 | 927 | let _amount = (_rawAmount - feeAmount) | |
795 | - | let $ | |
796 | - | let oldPositionSize = $ | |
797 | - | let oldPositionMargin = $ | |
798 | - | let oldPositionOpenNotional = $ | |
799 | - | let oldPositionLstUpdCPF = $ | |
928 | + | let $t04286643018 = getPosition(toString(i.caller)) | |
929 | + | let oldPositionSize = $t04286643018._1 | |
930 | + | let oldPositionMargin = $t04286643018._2 | |
931 | + | let oldPositionOpenNotional = $t04286643018._3 | |
932 | + | let oldPositionLstUpdCPF = $t04286643018._4 | |
800 | 933 | let feeToStakers = (feeAmount / 2) | |
801 | 934 | let feeToInsurance = (feeAmount - feeToStakers) | |
802 | 935 | let stake = invoke(quoteAssetStaking(), "lockNeutrinoSP", [toString(stakingAddress()), ALL_FEES], [AttachedPayment(quoteAsset(), _amount)]) | |
803 | 936 | if ((stake == stake)) | |
804 | 937 | then { | |
805 | 938 | let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)]) | |
806 | 939 | if ((depositInsurance == depositInsurance)) | |
807 | - | then ((updatePosition(toString(i.caller), oldPositionSize, (oldPositionMargin + _amount), oldPositionOpenNotional, oldPositionLstUpdCPF) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) | |
940 | + | then { | |
941 | + | let notifyFee = invoke(minerAddress(), "notifyFees", [toString(i.caller), feeAmount], nil) | |
942 | + | if ((notifyFee == notifyFee)) | |
943 | + | then ((updatePosition(toString(i.caller), oldPositionSize, (oldPositionMargin + _amount), oldPositionOpenNotional, oldPositionLstUpdCPF) ++ transferFee(feeToStakers)) ++ updateBalance((cbalance() + _amount))) | |
944 | + | else throw("Strict value is not equal to itself.") | |
945 | + | } | |
808 | 946 | else throw("Strict value is not equal to itself.") | |
809 | 947 | } | |
810 | 948 | else throw("Strict value is not equal to itself.") | |
811 | 949 | } | |
812 | 950 | } | |
813 | 951 | ||
814 | 952 | ||
815 | 953 | ||
816 | 954 | @Callable(i) | |
817 | 955 | func removeMargin (_amount) = if (if (if (if ((0 >= _amount)) | |
818 | 956 | then true | |
819 | 957 | else !(requireOpenPosition(toString(i.caller)))) | |
820 | 958 | then true | |
821 | 959 | else !(initialized())) | |
822 | 960 | then true | |
823 | 961 | else paused()) | |
824 | 962 | then throw("Invalid removeMargin parameters") | |
825 | 963 | else { | |
826 | - | let $ | |
827 | - | let oldPositionSize = $ | |
828 | - | let oldPositionMargin = $ | |
829 | - | let oldPositionOpenNotional = $ | |
830 | - | let oldPositionLstUpdCPF = $ | |
964 | + | let $t04406744219 = getPosition(toString(i.caller)) | |
965 | + | let oldPositionSize = $t04406744219._1 | |
966 | + | let oldPositionMargin = $t04406744219._2 | |
967 | + | let oldPositionOpenNotional = $t04406744219._3 | |
968 | + | let oldPositionLstUpdCPF = $t04406744219._4 | |
831 | 969 | let marginDelta = -(_amount) | |
832 | - | let $t03446134656 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, marginDelta) | |
833 | - | let remainMargin = $t03446134656._1 | |
834 | - | let badDebt = $t03446134656._2 | |
835 | - | let x1 = $t03446134656._3 | |
836 | - | let latestCPF1 = $t03446134656._4 | |
970 | + | let $t04425644435 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, marginDelta) | |
971 | + | let remainMargin = $t04425644435._1 | |
972 | + | let badDebt = $t04425644435._2 | |
837 | 973 | if ((badDebt != 0)) | |
838 | - | then throw("Invalid | |
974 | + | then throw("Invalid removed margin amount") | |
839 | 975 | else { | |
840 | - | let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [_amount, toBase58String(quoteAsset())], nil) | |
841 | - | if ((unstake == unstake)) | |
842 | - | then ((updatePosition(toString(i.caller), oldPositionSize, remainMargin, oldPositionOpenNotional, latestCPF1) ++ withdraw(i.caller, _amount)) ++ updateBalance((cbalance() - _amount))) | |
843 | - | else throw("Strict value is not equal to itself.") | |
976 | + | let marginRatio = calcMarginRatio(remainMargin, badDebt, oldPositionOpenNotional) | |
977 | + | if (!(requireMoreMarginRatio(marginRatio, initMarginRatio(), true))) | |
978 | + | then throw(((("Too much margin removed: " + toString(marginRatio)) + " < ") + toString(initMarginRatio()))) | |
979 | + | else { | |
980 | + | let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [_amount, toBase58String(quoteAsset())], nil) | |
981 | + | if ((unstake == unstake)) | |
982 | + | then ((updatePosition(toString(i.caller), oldPositionSize, remainMargin, oldPositionOpenNotional, latestCumulativePremiumFraction(oldPositionSize)) ++ withdraw(i.caller, _amount)) ++ updateBalance((cbalance() - _amount))) | |
983 | + | else throw("Strict value is not equal to itself.") | |
984 | + | } | |
844 | 985 | } | |
845 | 986 | } | |
846 | 987 | ||
847 | 988 | ||
848 | 989 | ||
849 | 990 | @Callable(i) | |
850 | 991 | func closePosition () = if (if (if (!(requireOpenPosition(toString(i.caller)))) | |
851 | 992 | then true | |
852 | 993 | else !(initialized())) | |
853 | 994 | then true | |
854 | 995 | else paused()) | |
855 | 996 | then throw("Invalid closePosition parameters") | |
856 | 997 | else { | |
857 | - | let $ | |
858 | - | let x1 = $ | |
859 | - | let positionBadDebt = $ | |
860 | - | let realizedPnl = $ | |
861 | - | let marginToVault = $ | |
862 | - | let quoteAssetReserveAfter = $ | |
863 | - | let baseAssetReserveAfter = $ | |
864 | - | let totalPositionSizeAfter = $ | |
865 | - | let cumulativeNotionalAfter = $ | |
866 | - | let | |
867 | - | let x2 = $ | |
868 | - | let totalLongAfter = $ | |
869 | - | let totalShortAfter = $ | |
998 | + | let $t04553145921 = internalClosePosition(toString(i.caller), true) | |
999 | + | let x1 = $t04553145921._1 | |
1000 | + | let positionBadDebt = $t04553145921._2 | |
1001 | + | let realizedPnl = $t04553145921._3 | |
1002 | + | let marginToVault = $t04553145921._4 | |
1003 | + | let quoteAssetReserveAfter = $t04553145921._5 | |
1004 | + | let baseAssetReserveAfter = $t04553145921._6 | |
1005 | + | let totalPositionSizeAfter = $t04553145921._7 | |
1006 | + | let cumulativeNotionalAfter = $t04553145921._8 | |
1007 | + | let openInterestNotionalAfter = $t04553145921._9 | |
1008 | + | let x2 = $t04553145921._10 | |
1009 | + | let totalLongAfter = $t04553145921._11 | |
1010 | + | let totalShortAfter = $t04553145921._12 | |
870 | 1011 | if ((positionBadDebt > 0)) | |
871 | 1012 | then throw("Unable to close position with bad debt") | |
872 | 1013 | else { | |
873 | 1014 | let withdrawAmount = abs(marginToVault) | |
874 | 1015 | let ammBalance = (cbalance() - withdrawAmount) | |
875 | - | let $ | |
1016 | + | let $t04613046272 = if ((0 > ammBalance)) | |
876 | 1017 | then $Tuple2(0, abs(ammBalance)) | |
877 | 1018 | else $Tuple2(ammBalance, 0) | |
878 | - | let ammNewBalance = $ | |
879 | - | let getFromInsurance = $ | |
1019 | + | let ammNewBalance = $t04613046272._1 | |
1020 | + | let getFromInsurance = $t04613046272._2 | |
880 | 1021 | let x = if ((getFromInsurance > 0)) | |
881 | 1022 | then { | |
882 | 1023 | let withdrawInsurance = invoke(insuranceAddress(), "withdraw", [getFromInsurance], nil) | |
883 | 1024 | if ((withdrawInsurance == withdrawInsurance)) | |
884 | 1025 | then nil | |
885 | 1026 | else throw("Strict value is not equal to itself.") | |
886 | 1027 | } | |
887 | 1028 | else nil | |
888 | 1029 | if ((x == x)) | |
889 | 1030 | then { | |
890 | 1031 | let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [(withdrawAmount - getFromInsurance), toBase58String(quoteAsset())], nil) | |
891 | 1032 | if ((unstake == unstake)) | |
892 | - | then (((deletePosition(toString(i.caller)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInteresetNotionalAfter, totalLongAfter, totalShortAfter)) ++ withdraw(i.caller, withdrawAmount)) ++ updateBalance(ammNewBalance)) | |
1033 | + | then { | |
1034 | + | let notifyNotional = invoke(minerAddress(), "notifyNotional", [toString(i.caller), 0], nil) | |
1035 | + | if ((notifyNotional == notifyNotional)) | |
1036 | + | then (((deletePosition(toString(i.caller)) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter)) ++ withdraw(i.caller, withdrawAmount)) ++ updateBalance(ammNewBalance)) | |
1037 | + | else throw("Strict value is not equal to itself.") | |
1038 | + | } | |
893 | 1039 | else throw("Strict value is not equal to itself.") | |
894 | 1040 | } | |
895 | 1041 | else throw("Strict value is not equal to itself.") | |
896 | 1042 | } | |
897 | 1043 | } | |
898 | 1044 | ||
899 | 1045 | ||
900 | 1046 | ||
901 | 1047 | @Callable(i) | |
902 | 1048 | func liquidate (_trader) = { | |
1049 | + | let spotMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_SPOT) | |
903 | 1050 | let marginRatio = if (isOverFluctuationLimit()) | |
904 | - | then getMarginRatioByOption(_trader, PNL_OPTION_ORACLE) | |
905 | - | else getMarginRatioByOption(_trader, PNL_OPTION_SPOT) | |
906 | - | if (if (if (!(requireMoreMarginRatio(marginRatio, mmr(), false))) | |
1051 | + | then { | |
1052 | + | let oracleMarginRatio = getMarginRatioByOption(_trader, PNL_OPTION_ORACLE) | |
1053 | + | vmax(spotMarginRatio, oracleMarginRatio) | |
1054 | + | } | |
1055 | + | else spotMarginRatio | |
1056 | + | if (if (if (if (!(requireMoreMarginRatio(marginRatio, maintenanceMarginRatio(), false))) | |
1057 | + | then true | |
1058 | + | else !(requireOpenPosition(_trader))) | |
907 | 1059 | then true | |
908 | 1060 | else !(initialized())) | |
909 | 1061 | then true | |
910 | 1062 | else paused()) | |
911 | 1063 | then throw("Unable to liquidate") | |
912 | - | else { | |
913 | - | let $t03733337664 = internalClosePosition(_trader) | |
914 | - | let x1 = $t03733337664._1 | |
915 | - | let badDebt = $t03733337664._2 | |
916 | - | let x2 = $t03733337664._3 | |
917 | - | let marginToVault = $t03733337664._4 | |
918 | - | let quoteAssetReserveAfter = $t03733337664._5 | |
919 | - | let baseAssetReserveAfter = $t03733337664._6 | |
920 | - | let totalPositionSizeAfter = $t03733337664._7 | |
921 | - | let cumulativeNotionalAfter = $t03733337664._8 | |
922 | - | let openInteresetNotionalAfter = $t03733337664._9 | |
923 | - | let exchangedQuoteAssetAmount = $t03733337664._10 | |
924 | - | let totalLongAfter = $t03733337664._11 | |
925 | - | let totalShortAfter = $t03733337664._12 | |
926 | - | let feeToLiquidator = (muld(exchangedQuoteAssetAmount, liquidationFeeRatio()) / 2) | |
927 | - | let $t03775438158 = if ((feeToLiquidator > marginToVault)) | |
928 | - | then $Tuple3((feeToLiquidator - marginToVault), marginToVault, ((badDebt + feeToLiquidator) - marginToVault)) | |
929 | - | else $Tuple3(0, (marginToVault - feeToLiquidator), badDebt) | |
930 | - | let liquidationBadDebt = $t03775438158._1 | |
931 | - | let remainMargin = $t03775438158._2 | |
932 | - | let totalBadDebt = $t03775438158._3 | |
933 | - | let bd = (cbalance() - feeToLiquidator) | |
934 | - | let $t03820638294 = if ((0 > bd)) | |
935 | - | then $Tuple2(0, abs(bd)) | |
936 | - | else $Tuple2(bd, 0) | |
937 | - | let nb = $t03820638294._1 | |
938 | - | let fromi = $t03820638294._2 | |
939 | - | let x = if ((fromi > 0)) | |
940 | - | then { | |
941 | - | let withdrawInsurance = invoke(insuranceAddress(), "withdraw", [fromi], nil) | |
942 | - | if ((withdrawInsurance == withdrawInsurance)) | |
943 | - | then nil | |
944 | - | else throw("Strict value is not equal to itself.") | |
945 | - | } | |
946 | - | else nil | |
947 | - | if ((x == x)) | |
948 | - | then { | |
949 | - | let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [(feeToLiquidator - fromi), toBase58String(quoteAsset())], nil) | |
950 | - | if ((unstake == unstake)) | |
951 | - | then (((deletePosition(_trader) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInteresetNotionalAfter, totalLongAfter, totalShortAfter)) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(nb)) | |
952 | - | else throw("Strict value is not equal to itself.") | |
953 | - | } | |
954 | - | else throw("Strict value is not equal to itself.") | |
955 | - | } | |
1064 | + | else if (if (if ((spotMarginRatio > liquidationFeeRatio())) | |
1065 | + | then (partialLiquidationRatio() > 0) | |
1066 | + | else false) | |
1067 | + | then (DECIMAL_UNIT > partialLiquidationRatio()) | |
1068 | + | else false) | |
1069 | + | then { | |
1070 | + | let $t04837348523 = getPosition(_trader) | |
1071 | + | let oldPositionSize = $t04837348523._1 | |
1072 | + | let oldPositionMargin = $t04837348523._2 | |
1073 | + | let oldPositionOpenNotional = $t04837348523._3 | |
1074 | + | let oldPositionLstUpdCPF = $t04837348523._4 | |
1075 | + | let _direction = if ((oldPositionSize > 0)) | |
1076 | + | then DIR_SHORT | |
1077 | + | else DIR_LONG | |
1078 | + | let isAdd = (_direction == DIR_LONG) | |
1079 | + | let exchangedQuoteAssetAmount = getPartialLiquidationAmount(_trader, oldPositionSize) | |
1080 | + | let $t04874848852 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
1081 | + | let oldPositionNotional = $t04874848852._1 | |
1082 | + | let unrealizedPnl = $t04874848852._2 | |
1083 | + | let $t04886049150 = swapInput(isAdd, exchangedQuoteAssetAmount) | |
1084 | + | let exchangedPositionSize = $t04886049150._1 | |
1085 | + | let quoteAssetReserveAfter = $t04886049150._2 | |
1086 | + | let baseAssetReserveAfter = $t04886049150._3 | |
1087 | + | let totalPositionSizeAfter = $t04886049150._4 | |
1088 | + | let cumulativeNotionalAfter = $t04886049150._5 | |
1089 | + | let realizedPnl = divd(muld(unrealizedPnl, abs(exchangedPositionSize)), abs(oldPositionSize)) | |
1090 | + | let $t04925749490 = calcRemainMarginWithFundingPayment(oldPositionSize, oldPositionMargin, oldPositionLstUpdCPF, realizedPnl) | |
1091 | + | let remainMargin = $t04925749490._1 | |
1092 | + | let badDebt = $t04925749490._2 | |
1093 | + | let fundingPayment = $t04925749490._3 | |
1094 | + | let unrealizedPnlAfter = (unrealizedPnl - realizedPnl) | |
1095 | + | let remainOpenNotional = if ((oldPositionSize > 0)) | |
1096 | + | then ((oldPositionNotional - exchangedQuoteAssetAmount) - unrealizedPnlAfter) | |
1097 | + | else ((unrealizedPnlAfter + oldPositionNotional) - exchangedQuoteAssetAmount) | |
1098 | + | let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio()) | |
1099 | + | let feeToLiquidator = (liquidationPenalty / 2) | |
1100 | + | let feeToInsurance = (liquidationPenalty - feeToLiquidator) | |
1101 | + | let newPositionMargin = (remainMargin - liquidationPenalty) | |
1102 | + | let newPositionSize = (oldPositionSize + exchangedPositionSize) | |
1103 | + | let newPositionOpenNotional = abs(remainOpenNotional) | |
1104 | + | let newPositionLstUpdCPF = latestCumulativePremiumFraction(newPositionSize) | |
1105 | + | let openInterestNotionalAfter = (openInterestNotional() - exchangedQuoteAssetAmount) | |
1106 | + | let ammBalance = (cbalance() - liquidationPenalty) | |
1107 | + | let $t05066350806 = if ((0 > ammBalance)) | |
1108 | + | then $Tuple2(0, abs(ammBalance)) | |
1109 | + | else $Tuple2(ammBalance, 0) | |
1110 | + | let newAmmBalance = $t05066350806._1 | |
1111 | + | let takeFromInsurance = $t05066350806._2 | |
1112 | + | let x = if ((takeFromInsurance > 0)) | |
1113 | + | then { | |
1114 | + | let withdrawInsurance = invoke(insuranceAddress(), "withdraw", [takeFromInsurance], nil) | |
1115 | + | if ((withdrawInsurance == withdrawInsurance)) | |
1116 | + | then nil | |
1117 | + | else throw("Strict value is not equal to itself.") | |
1118 | + | } | |
1119 | + | else nil | |
1120 | + | if ((x == x)) | |
1121 | + | then { | |
1122 | + | let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [(liquidationPenalty - takeFromInsurance), toBase58String(quoteAsset())], nil) | |
1123 | + | if ((unstake == unstake)) | |
1124 | + | then { | |
1125 | + | let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)]) | |
1126 | + | if ((depositInsurance == depositInsurance)) | |
1127 | + | then { | |
1128 | + | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, newPositionOpenNotional], nil) | |
1129 | + | if ((notifyNotional == notifyNotional)) | |
1130 | + | then (((updatePosition(_trader, newPositionSize, newPositionMargin, newPositionOpenNotional, newPositionLstUpdCPF) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, (totalLongPositionSize() - (if ((newPositionSize > 0)) | |
1131 | + | then abs(exchangedPositionSize) | |
1132 | + | else 0)), (totalShortPositionSize() - (if ((0 > newPositionSize)) | |
1133 | + | then abs(exchangedPositionSize) | |
1134 | + | else 0)))) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance)) | |
1135 | + | else throw("Strict value is not equal to itself.") | |
1136 | + | } | |
1137 | + | else throw("Strict value is not equal to itself.") | |
1138 | + | } | |
1139 | + | else throw("Strict value is not equal to itself.") | |
1140 | + | } | |
1141 | + | else throw("Strict value is not equal to itself.") | |
1142 | + | } | |
1143 | + | else { | |
1144 | + | let $t05226252717 = internalClosePosition(_trader, false) | |
1145 | + | let x1 = $t05226252717._1 | |
1146 | + | let badDebt = $t05226252717._2 | |
1147 | + | let x2 = $t05226252717._3 | |
1148 | + | let x3 = $t05226252717._4 | |
1149 | + | let quoteAssetReserveAfter = $t05226252717._5 | |
1150 | + | let baseAssetReserveAfter = $t05226252717._6 | |
1151 | + | let totalPositionSizeAfter = $t05226252717._7 | |
1152 | + | let cumulativeNotionalAfter = $t05226252717._8 | |
1153 | + | let openInterestNotionalAfter = $t05226252717._9 | |
1154 | + | let exchangedQuoteAssetAmount = $t05226252717._10 | |
1155 | + | let totalLongAfter = $t05226252717._11 | |
1156 | + | let totalShortAfter = $t05226252717._12 | |
1157 | + | let liquidationPenalty = muld(exchangedQuoteAssetAmount, liquidationFeeRatio()) | |
1158 | + | let feeToLiquidator = (liquidationPenalty / 2) | |
1159 | + | let feeToInsurance = (liquidationPenalty - feeToLiquidator) | |
1160 | + | let ammBalance = (cbalance() - liquidationPenalty) | |
1161 | + | let $t05312953272 = if ((0 > ammBalance)) | |
1162 | + | then $Tuple2(0, abs(ammBalance)) | |
1163 | + | else $Tuple2(ammBalance, 0) | |
1164 | + | let newAmmBalance = $t05312953272._1 | |
1165 | + | let takeFromInsurance = $t05312953272._2 | |
1166 | + | let x = if ((takeFromInsurance > 0)) | |
1167 | + | then { | |
1168 | + | let withdrawInsurance = invoke(insuranceAddress(), "withdraw", [takeFromInsurance], nil) | |
1169 | + | if ((withdrawInsurance == withdrawInsurance)) | |
1170 | + | then nil | |
1171 | + | else throw("Strict value is not equal to itself.") | |
1172 | + | } | |
1173 | + | else nil | |
1174 | + | if ((x == x)) | |
1175 | + | then { | |
1176 | + | let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [(liquidationPenalty - takeFromInsurance), toBase58String(quoteAsset())], nil) | |
1177 | + | if ((unstake == unstake)) | |
1178 | + | then { | |
1179 | + | let depositInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), feeToInsurance)]) | |
1180 | + | if ((depositInsurance == depositInsurance)) | |
1181 | + | then { | |
1182 | + | let notifyNotional = invoke(minerAddress(), "notifyNotional", [_trader, 0], nil) | |
1183 | + | if ((notifyNotional == notifyNotional)) | |
1184 | + | then (((deletePosition(_trader) ++ updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter, cumulativeNotionalAfter, openInterestNotionalAfter, totalLongAfter, totalShortAfter)) ++ withdraw(i.caller, feeToLiquidator)) ++ updateBalance(newAmmBalance)) | |
1185 | + | else throw("Strict value is not equal to itself.") | |
1186 | + | } | |
1187 | + | else throw("Strict value is not equal to itself.") | |
1188 | + | } | |
1189 | + | else throw("Strict value is not equal to itself.") | |
1190 | + | } | |
1191 | + | else throw("Strict value is not equal to itself.") | |
1192 | + | } | |
956 | 1193 | } | |
957 | 1194 | ||
958 | 1195 | ||
959 | 1196 | ||
960 | 1197 | @Callable(i) | |
961 | 1198 | func payFunding () = { | |
962 | 1199 | let fundingBlockTimestamp = nextFundingBlockTimestamp() | |
963 | 1200 | if (if (if ((fundingBlockTimestamp > lastBlock.timestamp)) | |
964 | 1201 | then true | |
965 | 1202 | else !(initialized())) | |
966 | 1203 | then true | |
967 | 1204 | else paused()) | |
968 | 1205 | then throw(((("Invalid funding block timestamp: " + toString(lastBlock.timestamp)) + " < ") + toString(fundingBlockTimestamp))) | |
969 | 1206 | else { | |
970 | 1207 | let underlyingPrice = getOracleTwapPrice() | |
971 | 1208 | let spotTwapPrice = getTwapSpotPrice() | |
972 | 1209 | let premium = (spotTwapPrice - underlyingPrice) | |
973 | - | let $ | |
1210 | + | let $t05486056195 = if (if ((totalShortPositionSize() == 0)) | |
974 | 1211 | then true | |
975 | 1212 | else (totalLongPositionSize() == 0)) | |
976 | 1213 | then $Tuple2(0, 0) | |
977 | 1214 | else if ((0 > premium)) | |
978 | 1215 | then { | |
979 | 1216 | let shortPremiumFraction = divd(muld(premium, fundingPeriodDecimal()), ONE_DAY) | |
980 | 1217 | let longPremiumFraction = divd(muld(shortPremiumFraction, totalShortPositionSize()), totalLongPositionSize()) | |
981 | 1218 | $Tuple2(shortPremiumFraction, longPremiumFraction) | |
982 | 1219 | } | |
983 | 1220 | else { | |
984 | 1221 | let longPremiumFraction = divd(muld(premium, fundingPeriodDecimal()), ONE_DAY) | |
985 | 1222 | let shortPremiumFraction = divd(muld(longPremiumFraction, totalLongPositionSize()), totalShortPositionSize()) | |
986 | 1223 | $Tuple2(shortPremiumFraction, longPremiumFraction) | |
987 | 1224 | } | |
988 | - | let shortPremiumFraction = $ | |
989 | - | let longPremiumFraction = $ | |
1225 | + | let shortPremiumFraction = $t05486056195._1 | |
1226 | + | let longPremiumFraction = $t05486056195._2 | |
990 | 1227 | updateFunding((fundingBlockTimestamp + fundingPeriodSeconds()), (latestLongCumulativePremiumFraction() + longPremiumFraction), (latestShortCumulativePremiumFraction() + shortPremiumFraction), divd(longPremiumFraction, underlyingPrice), divd(shortPremiumFraction, underlyingPrice)) | |
991 | 1228 | } | |
992 | 1229 | } | |
993 | 1230 | ||
994 | 1231 | ||
995 | 1232 | ||
996 | 1233 | @Callable(i) | |
997 | 1234 | func v_get (_trader) = { | |
998 | - | let $ | |
999 | - | let x1 = $ | |
1000 | - | let x2 = $ | |
1001 | - | let x3 = $ | |
1002 | - | let x4 = $ | |
1235 | + | let $t05657056630 = internalClosePosition(_trader, false) | |
1236 | + | let x1 = $t05657056630._1 | |
1237 | + | let x2 = $t05657056630._2 | |
1238 | + | let x3 = $t05657056630._3 | |
1239 | + | let x4 = $t05657056630._4 | |
1003 | 1240 | throw((((s(x2) + s(x3)) + s(x4)) + s(getMarginRatio(_trader)))) | |
1004 | 1241 | } | |
1005 | 1242 | ||
1006 | 1243 | ||
1007 | 1244 | ||
1008 | 1245 | @Callable(i) | |
1009 | 1246 | func view_calcRemainMarginWithFundingPayment (_trader) = { | |
1010 | - | let $ | |
1011 | - | let positionSize = $ | |
1012 | - | let positionMargin = $ | |
1013 | - | let pon = $ | |
1014 | - | let positionLstUpdCPF = $ | |
1015 | - | let $ | |
1016 | - | let positionNotional = $ | |
1017 | - | let unrealizedPnl = $ | |
1018 | - | let $ | |
1019 | - | let remainMargin = $ | |
1020 | - | let badDebt = $ | |
1021 | - | let fundingPayment = $ | |
1022 | - | throw((s(remainMargin) + s(fundingPayment))) | |
1247 | + | let $t05677756888 = getPosition(_trader) | |
1248 | + | let positionSize = $t05677756888._1 | |
1249 | + | let positionMargin = $t05677756888._2 | |
1250 | + | let pon = $t05677756888._3 | |
1251 | + | let positionLstUpdCPF = $t05677756888._4 | |
1252 | + | let $t05689356994 = getPositionNotionalAndUnrealizedPnl(_trader, PNL_OPTION_SPOT) | |
1253 | + | let positionNotional = $t05689356994._1 | |
1254 | + | let unrealizedPnl = $t05689356994._2 | |
1255 | + | let $t05699957181 = calcRemainMarginWithFundingPayment(positionSize, positionMargin, positionLstUpdCPF, unrealizedPnl) | |
1256 | + | let remainMargin = $t05699957181._1 | |
1257 | + | let badDebt = $t05699957181._2 | |
1258 | + | let fundingPayment = $t05699957181._3 | |
1259 | + | throw((((((s(remainMargin) + s(fundingPayment)) + s(getMarginRatio(_trader))) + s(unrealizedPnl)) + s(badDebt)) + s(positionNotional))) | |
1023 | 1260 | } | |
1261 | + | ||
1262 | + | ||
1263 | + | ||
1264 | + | @Callable(i) | |
1265 | + | func forceMoveAsset (_trader,_amount) = if (if ((addressFromPublicKey(adminPublicKey()) != i.caller)) | |
1266 | + | then true | |
1267 | + | else (0 > _amount)) | |
1268 | + | then throw("Invalid forceMoveAsset parameters") | |
1269 | + | else { | |
1270 | + | let unstake = invoke(quoteAssetStaking(), "unlockNeutrino", [_amount, toBase58String(quoteAsset())], nil) | |
1271 | + | if ((unstake == unstake)) | |
1272 | + | then (withdraw(addressFromStringValue(_trader), _amount) ++ updateBalance((cbalance() - _amount))) | |
1273 | + | else throw("Strict value is not equal to itself.") | |
1274 | + | } | |
1024 | 1275 | ||
1025 | 1276 | ||
1026 | 1277 | @Verifier(tx) | |
1027 | 1278 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], adminPublicKey()) | |
1028 | 1279 |
github/deemru/w8io/169f3d6 187.00 ms ◑