tx · HR2Q5DwnggXfAGj8yBJQd9cMbup894NUTJy5nXqSmv1W 3N9kbR6BQEQV7pwBfDFzprJtNofgi6fSJ6Y: -0.03700000 Waves 2023.06.23 12:17 [2635101] smart account 3N9kbR6BQEQV7pwBfDFzprJtNofgi6fSJ6Y > SELF 0.00000000 Waves
{ "type": 13, "id": "HR2Q5DwnggXfAGj8yBJQd9cMbup894NUTJy5nXqSmv1W", "fee": 3700000, "feeAssetId": null, "timestamp": 1687511941224, "version": 2, "chainId": 84, "sender": "3N9kbR6BQEQV7pwBfDFzprJtNofgi6fSJ6Y", "senderPublicKey": "EajGg1J8duApPELWPw9gVkPwAKFC9hujhvCcne4FunUa", "proofs": [ "3qyf5gakpEcQ3WNtxoNrdAYrsWjtYvs8wEJ2uicq2z3fdcRumyPNS1ViAbq8yXGXTMF6HkSD4vCwJLuH9q692YZa" ], "script": "base64:BgJsCAISBAoCCAgSAwoBCBIAEgQKAggBEgMKAQESEAoOCAEBAQEBAQgBAQEBAQgSDAoKCAEBAQgBAQEBCBIFCgMICAESCAoGCAgBAQEBEg4KDAgIAQEBAQEBCAgBARIDCgEBEgQKAgEIEgQKAgEIRAAUa19jb29yZGluYXRvckFkZHJlc3MCFGtfY29vcmRpbmF0b3JBZGRyZXNzAA9rX2FkbWluX2FkZHJlc3MCD2tfYWRtaW5fYWRkcmVzcwANa19xdW90ZV9hc3NldAINa19xdW90ZV9hc3NldAAFa19hbW0CBWtfYW1tABFrX21hbmFnZXJfYWRkcmVzcwIRa19tYW5hZ2VyX2FkZHJlc3MAEmtfcG9zaXRpb25TZXF1ZW5jZQISa19wb3NpdGlvblNlcXVlbmNlAA5rX3Bvc2l0aW9uU2l6ZQIOa19wb3NpdGlvblNpemUAEGtfZXhlY3V0ZWRPcmRlcnMCEGtfZXhlY3V0ZWRPcmRlcnMAEGtfY2FuY2VsZWRPcmRlcnMCEGtfY2FuY2VsZWRPcmRlcnMAB2tfb3JkZXICB2tfb3JkZXIADmtfb3JkZXJSZXF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 } View: original | compacted Prev: 4GQDLn3cqjDQdPnmxAgefpTZtysBmz9vGVUCv99MyqAk Next: none Diff:
Old | New | Differences | |
---|---|---|---|
29 | 29 | ||
30 | 30 | let k_traderOrderIds = "k_traderOrderIds" | |
31 | 31 | ||
32 | + | let k_spreadLimit = "k_spreadLimit" | |
33 | + | ||
32 | 34 | let k_sender = "k_sender" | |
33 | 35 | ||
34 | 36 | let k_initialized = "k_initialized" | |
52 | 54 | let TIME = lastBlock.timestamp | |
53 | 55 | ||
54 | 56 | let DECIMAL_UNIT = (1 * (((((10 * 10) * 10) * 10) * 10) * 10)) | |
55 | - | ||
56 | - | let SPREAD_LIMIT = (DECIMAL_UNIT / 200) | |
57 | 57 | ||
58 | 58 | func abs (_x) = if ((_x > 0)) | |
59 | 59 | then _x | |
95 | 95 | func coordinator () = valueOrErrorMessage(addressFromString(getStringValue(this, k_coordinatorAddress)), "Coordinator not set") | |
96 | 96 | ||
97 | 97 | ||
98 | + | func adminAddress () = addressFromString(getStringValue(coordinator(), k_admin_address)) | |
99 | + | ||
100 | + | ||
98 | 101 | func quoteAsset () = fromBase58String(getStringValue(coordinator(), k_quote_asset)) | |
99 | 102 | ||
100 | 103 | ||
112 | 115 | else if (valueOrElse(getBoolean(this, canceledOrderKey(_orderId)), false)) | |
113 | 116 | then throw(("Order already cancelled: " + toString(_orderId))) | |
114 | 117 | else true | |
118 | + | ||
119 | + | ||
120 | + | func getSpreadLimit () = valueOrErrorMessage(getInteger(this, k_spreadLimit), "Spread limit not set") | |
115 | 121 | ||
116 | 122 | ||
117 | 123 | func currentOrderId () = valueOrElse(getInteger(this, k_lastOrderId), 0) | |
166 | 172 | let refLink = orderPartList[8] | |
167 | 173 | let positionId = valueOrErrorMessage(parseInt(orderPartList[9]), "Invalid positionId") | |
168 | 174 | let limitPrice = valueOrErrorMessage(parseInt(orderPartList[10]), "Invalid limitPrice") | |
169 | - | $Tuple11(amm, trader, amountIn, leverage, type, triggerPrice, paymentUsdn, side, refLink, positionId, limitPrice) | |
175 | + | let expiration = if ((size(orderPartList) > 11)) | |
176 | + | then valueOrErrorMessage(parseInt(orderPartList[11]), "Invalid expiration") | |
177 | + | else 0 | |
178 | + | let marketPrice = if ((size(orderPartList) > 12)) | |
179 | + | then valueOrErrorMessage(parseInt(orderPartList[12]), "Invalid orderMarketPrice") | |
180 | + | else 0 | |
181 | + | $Tuple13(amm, trader, amountIn, leverage, type, triggerPrice, paymentUsdn, side, refLink, positionId, limitPrice, expiration, marketPrice) | |
170 | 182 | } | |
171 | 183 | ||
172 | 184 | ||
227 | 239 | } | |
228 | 240 | ||
229 | 241 | ||
230 | - | func getSpread (_price) = muld(_price, | |
242 | + | func getSpread (_price) = muld(_price, getSpreadLimit()) | |
231 | 243 | ||
232 | 244 | ||
233 | - | func saveOrder (_orderId,_amm,_trader,_amountIn,_leverage,_type,_triggerPrice,_paymentUsdn,_side,_refLink,_positionId,_limitPrice) = { | |
234 | - | let orderStr = makeString([_amm, _trader, toString(_amountIn), toString(_leverage), toString(_type), toString(_triggerPrice), toString(_paymentUsdn), toString(_side), _refLink, toString(_positionId), toString(_limitPrice)], ",") | |
245 | + | func saveOrder (_orderId,_amm,_trader,_amountIn,_leverage,_type,_triggerPrice,_paymentUsdn,_side,_refLink,_positionId,_limitPrice,_expiration,_orderMarketPrice) = { | |
246 | + | let orderStr = makeString([_amm, _trader, toString(_amountIn), toString(_leverage), toString(_type), toString(_triggerPrice), toString(_paymentUsdn), toString(_side), _refLink, toString(_positionId), toString(_limitPrice), toString(_expiration), toString(_orderMarketPrice)], ",") | |
235 | 247 | [StringEntry(orderKey(_orderId), orderStr)] | |
236 | 248 | } | |
237 | 249 | ||
294 | 306 | let positionIds = getPositionIds(_amm, _trader) | |
295 | 307 | func cleanUpOne (_acc,_orderId) = { | |
296 | 308 | let orderIdInt = valueOrErrorMessage(parseInt(_orderId), "Invalid order id") | |
297 | - | let $t01115611351 = getOrder(orderIdInt) | |
298 | - | let _x1 = $t01115611351._1 | |
299 | - | let _x2 = $t01115611351._2 | |
300 | - | let _x3 = $t01115611351._3 | |
301 | - | let _x4 = $t01115611351._4 | |
302 | - | let _type = $t01115611351._5 | |
303 | - | let _x5 = $t01115611351._6 | |
304 | - | let _x6 = $t01115611351._7 | |
305 | - | let _x7 = $t01115611351._8 | |
306 | - | let _x8 = $t01115611351._9 | |
307 | - | let _positionId = $t01115611351._10 | |
308 | - | let _x9 = $t01115611351._11 | |
309 | - | if (if (if (if ((_type == STOP)) | |
309 | + | let $t01176611982 = getOrder(orderIdInt) | |
310 | + | let _x1 = $t01176611982._1 | |
311 | + | let _x2 = $t01176611982._2 | |
312 | + | let _x3 = $t01176611982._3 | |
313 | + | let _x4 = $t01176611982._4 | |
314 | + | let _type = $t01176611982._5 | |
315 | + | let _x5 = $t01176611982._6 | |
316 | + | let _x6 = $t01176611982._7 | |
317 | + | let _x7 = $t01176611982._8 | |
318 | + | let _x8 = $t01176611982._9 | |
319 | + | let _positionId = $t01176611982._10 | |
320 | + | let _x9 = $t01176611982._11 | |
321 | + | let _expiration = $t01176611982._12 | |
322 | + | let cancelTakeStopOfNoPosition = if (if (if ((_type == STOP)) | |
310 | 323 | then true | |
311 | 324 | else (_type == TAKE)) | |
312 | 325 | then (positionIds[0] != _positionId) | |
313 | 326 | else false) | |
314 | 327 | then (positionIds[1] != _positionId) | |
315 | - | else false) | |
328 | + | else false | |
329 | + | let cancelLimitIfExpired = if ((_type == LIMIT)) | |
330 | + | then (lastBlock.timestamp >= _expiration) | |
331 | + | else false | |
332 | + | if (if (cancelTakeStopOfNoPosition) | |
333 | + | then true | |
334 | + | else cancelLimitIfExpired) | |
316 | 335 | then { | |
317 | 336 | let change = markCancelOrder(orderIdInt) | |
318 | 337 | let newOrderList = addRemoveOrderIdList(_acc._1, orderIdInt, _amm, _trader, false) | |
321 | 340 | else _acc | |
322 | 341 | } | |
323 | 342 | ||
324 | - | let $ | |
343 | + | let $t01251412589 = { | |
325 | 344 | let $l = orders | |
326 | 345 | let $s = size($l) | |
327 | 346 | let $acc0 = $Tuple2(orders, nil) | |
335 | 354 | ||
336 | 355 | $f0_2($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) | |
337 | 356 | } | |
338 | - | let newOrders = $ | |
339 | - | let cancelActions = $ | |
357 | + | let newOrders = $t01251412589._1 | |
358 | + | let cancelActions = $t01251412589._2 | |
340 | 359 | ((cancelActions ++ updateTraderOrderCount(_amm, _trader, size(newOrders))) ++ updateOrderIdStr(makeString(newOrders, ","), _amm, _trader)) | |
341 | 360 | } | |
342 | 361 | ||
357 | 376 | ||
358 | 377 | ||
359 | 378 | @Callable(i) | |
360 | - | func initialize (_coordinator) = if (if (initialized()) | |
379 | + | func initialize (_coordinator,_spreadLimit) = if (if (if (initialized()) | |
380 | + | then true | |
381 | + | else if ((0 > _spreadLimit)) | |
382 | + | then true | |
383 | + | else (_spreadLimit > (DECIMAL_UNIT / 10))) | |
361 | 384 | then true | |
362 | 385 | else (i.caller != this)) | |
363 | 386 | then throw("Unable to initialize") | |
364 | - | else [StringEntry(k_coordinatorAddress, toString(addressFromStringValue(_coordinator))), BooleanEntry(k_initialized, true)] | |
387 | + | else [StringEntry(k_coordinatorAddress, toString(addressFromStringValue(_coordinator))), IntegerEntry(k_spreadLimit, _spreadLimit), BooleanEntry(k_initialized, true)] | |
365 | 388 | ||
366 | 389 | ||
367 | 390 | ||
368 | 391 | @Callable(i) | |
369 | - | func createOrder (_amm,_type,_triggerPrice,_limitPrice,_amountIn,_leverage,_side,_refLink,_stopTriggerPrice,_stopLimitPrice,_takeTriggerPrice,_takeLimitPrice) = { | |
392 | + | func changeSettings (_spreadLimit) = if (if ((i.caller != adminAddress())) | |
393 | + | then true | |
394 | + | else if ((0 > _spreadLimit)) | |
395 | + | then true | |
396 | + | else (_spreadLimit > (DECIMAL_UNIT / 10))) | |
397 | + | then throw("Invalid changeSettings params") | |
398 | + | else [IntegerEntry(k_spreadLimit, _spreadLimit)] | |
399 | + | ||
400 | + | ||
401 | + | ||
402 | + | @Callable(i) | |
403 | + | func createOrder (_amm,_type,_triggerPrice,_limitPrice,_amountIn,_leverage,_side,_refLink,_stopTriggerPrice,_stopLimitPrice,_takeTriggerPrice,_takeLimitPrice,_expiration,_priceData) = { | |
370 | 404 | let _trader = toString(i.caller) | |
371 | - | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
372 | - | if ((cleanUp == cleanUp)) | |
373 | - | then if ((size(i.payments) > 1)) | |
374 | - | then throw("Invalid createOrder parameters: invalid payment count") | |
375 | - | else { | |
376 | - | let $t01427514527 = if ((size(i.payments) == 1)) | |
377 | - | then $Tuple2(toBase58String(valueOrErrorMessage(i.payments[0].assetId, "Invalid asset id")), i.payments[0].amount) | |
378 | - | else $Tuple2("", 0) | |
379 | - | let paymentAssetId = $t01427514527._1 | |
380 | - | let paymentAmount = $t01427514527._2 | |
381 | - | let doCall = invoke(this, "internalCreateOrder", [_trader, _amm, _type, _triggerPrice, _limitPrice, _amountIn, _leverage, _side, _refLink, paymentAssetId, paymentAmount], nil) | |
382 | - | if ((doCall == doCall)) | |
383 | - | then { | |
384 | - | let orderId = match doCall { | |
385 | - | case t: Int => | |
386 | - | t | |
387 | - | case _ => | |
388 | - | throw("Invalid ID of created order") | |
389 | - | } | |
390 | - | if ((_type == LIMIT)) | |
405 | + | let updatePrice = invoke(addressFromStringValue(_amm), "updateOracle", [_priceData], nil) | |
406 | + | if ((updatePrice == updatePrice)) | |
407 | + | then { | |
408 | + | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
409 | + | if ((cleanUp == cleanUp)) | |
410 | + | then if ((size(i.payments) > 1)) | |
411 | + | then throw("Invalid createOrder parameters: invalid payment count") | |
412 | + | else { | |
413 | + | let $t01570315955 = if ((size(i.payments) == 1)) | |
414 | + | then $Tuple2(toBase58String(valueOrErrorMessage(i.payments[0].assetId, "Invalid asset id")), i.payments[0].amount) | |
415 | + | else $Tuple2("", 0) | |
416 | + | let paymentAssetId = $t01570315955._1 | |
417 | + | let paymentAmount = $t01570315955._2 | |
418 | + | let doCall = invoke(this, "internalCreateOrder", [_trader, _amm, _type, _triggerPrice, _limitPrice, _amountIn, _leverage, _side, _refLink, paymentAssetId, paymentAmount, _expiration], nil) | |
419 | + | if ((doCall == doCall)) | |
391 | 420 | then { | |
392 | - | let makeStop = if ((_stopTriggerPrice > 0)) | |
421 | + | let orderId = match doCall { | |
422 | + | case t: Int => | |
423 | + | t | |
424 | + | case _ => | |
425 | + | throw("Invalid ID of created order") | |
426 | + | } | |
427 | + | if ((_type == LIMIT)) | |
393 | 428 | then { | |
394 | - | let doMakeStop = invoke(this, "internalCreateOrderRequest", [_trader, _amm, orderId, STOP, _stopTriggerPrice, _stopLimitPrice], nil) | |
395 | - | if ((doMakeStop == doMakeStop)) | |
396 | - | then nil | |
397 | - | else throw("Strict value is not equal to itself.") | |
429 | + | let makeStop = if ((_stopTriggerPrice > 0)) | |
430 | + | then { | |
431 | + | let doMakeStop = invoke(this, "internalCreateOrderRequest", [_trader, _amm, orderId, STOP, _stopTriggerPrice, _stopLimitPrice], nil) | |
432 | + | if ((doMakeStop == doMakeStop)) | |
433 | + | then nil | |
434 | + | else throw("Strict value is not equal to itself.") | |
435 | + | } | |
436 | + | else nil | |
437 | + | let makeTake = if ((_takeTriggerPrice > 0)) | |
438 | + | then { | |
439 | + | let doMakeTake = invoke(this, "internalCreateOrderRequest", [_trader, _amm, orderId, TAKE, _takeTriggerPrice, _takeLimitPrice], nil) | |
440 | + | if ((doMakeTake == doMakeTake)) | |
441 | + | then nil | |
442 | + | else throw("Strict value is not equal to itself.") | |
443 | + | } | |
444 | + | else nil | |
445 | + | (makeStop ++ makeTake) | |
398 | 446 | } | |
399 | 447 | else nil | |
400 | - | let makeTake = if ((_takeTriggerPrice > 0)) | |
401 | - | then { | |
402 | - | let doMakeTake = invoke(this, "internalCreateOrderRequest", [_trader, _amm, orderId, TAKE, _takeTriggerPrice, _takeLimitPrice], nil) | |
403 | - | if ((doMakeTake == doMakeTake)) | |
404 | - | then nil | |
405 | - | else throw("Strict value is not equal to itself.") | |
406 | - | } | |
407 | - | else nil | |
408 | - | (makeStop ++ makeTake) | |
409 | 448 | } | |
410 | - | else | |
449 | + | else throw("Strict value is not equal to itself.") | |
411 | 450 | } | |
412 | - | ||
413 | - | ||
451 | + | else throw("Strict value is not equal to itself.") | |
452 | + | } | |
414 | 453 | else throw("Strict value is not equal to itself.") | |
415 | 454 | } | |
416 | 455 | ||
417 | 456 | ||
418 | 457 | ||
419 | 458 | @Callable(i) | |
420 | - | func increasePositionWithStopLoss (_amm,_direction,_leverage,_minBaseAssetAmount,_refLink,_stopTriggerPrice,_stopLimitPrice,_takeTriggerPrice,_takeLimitPrice) = { | |
459 | + | func increasePositionWithStopLoss (_amm,_direction,_leverage,_minBaseAssetAmount,_refLink,_stopTriggerPrice,_stopLimitPrice,_takeTriggerPrice,_takeLimitPrice,_priceData) = { | |
421 | 460 | let _trader = toString(i.caller) | |
422 | 461 | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
423 | 462 | if ((cleanUp == cleanUp)) | |
433 | 472 | let doSetContext = invoke(this, "setContext", [_trader], nil) | |
434 | 473 | if ((doSetContext == doSetContext)) | |
435 | 474 | then { | |
436 | - | let | |
437 | - | if (( | |
475 | + | let doOpenPosition = invoke(addressFromStringValue(_amm), "increasePosition", [_direction, _leverage, _minBaseAssetAmount, _refLink, _priceData], i.payments) | |
476 | + | if ((doOpenPosition == doOpenPosition)) | |
438 | 477 | then { | |
439 | 478 | let doResetContext = invoke(this, "resetContext", nil, nil) | |
440 | 479 | if ((doResetContext == doResetContext)) | |
443 | 482 | if ((openedPositionSize == openedPositionSize)) | |
444 | 483 | then { | |
445 | 484 | let amountIn = abs(openedPositionSize) | |
446 | - | let stopLossSide = if ((0 > openedPositionSize)) | |
447 | - | then LONG | |
448 | - | else SHORT | |
449 | - | let doCreateStopOrder = if ((_stopTriggerPrice > 0)) | |
485 | + | if ((amountIn == amountIn)) | |
450 | 486 | then { | |
451 | - | let doCreateStopOrder = invoke(this, "internalCreateOrder", [_trader, _amm, STOP, _stopTriggerPrice, _stopLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0], nil) | |
452 | - | if ((doCreateStopOrder == doCreateStopOrder)) | |
453 | - | then nil | |
454 | - | else throw("Strict value is not equal to itself.") | |
455 | - | } | |
456 | - | else nil | |
457 | - | if ((doCreateStopOrder == doCreateStopOrder)) | |
458 | - | then { | |
459 | - | let doCreateTakeOrder = if ((_takeTriggerPrice > 0)) | |
487 | + | let stopLossSide = if ((0 > openedPositionSize)) | |
488 | + | then LONG | |
489 | + | else SHORT | |
490 | + | let checkAmountIn = if ((0 >= amountIn)) | |
460 | 491 | then { | |
461 | - | let doCreateTakeOrder = invoke(this, "internalCreateOrder", [_trader, _amm, TAKE, _takeTriggerPrice, _takeLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0], nil) | |
462 | - | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
463 | - | then nil | |
492 | + | let data = makeString([_amm, _trader, toString(_direction), toString(_leverage), toString(_minBaseAssetAmount), _refLink, _priceData], ",") | |
493 | + | throw(((("Invalid amountIn=" + toString(amountIn)) + " after success increasePosition: ") + data)) | |
494 | + | } | |
495 | + | else 0 | |
496 | + | if ((checkAmountIn == checkAmountIn)) | |
497 | + | then { | |
498 | + | let doCreateStopOrder = if ((_stopTriggerPrice > 0)) | |
499 | + | then { | |
500 | + | let doCreateStopOrder = invoke(this, "internalCreateOrder", [_trader, _amm, STOP, _stopTriggerPrice, _stopLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0, 0], nil) | |
501 | + | if ((doCreateStopOrder == doCreateStopOrder)) | |
502 | + | then nil | |
503 | + | else throw("Strict value is not equal to itself.") | |
504 | + | } | |
505 | + | else nil | |
506 | + | if ((doCreateStopOrder == doCreateStopOrder)) | |
507 | + | then { | |
508 | + | let doCreateTakeOrder = if ((_takeTriggerPrice > 0)) | |
509 | + | then { | |
510 | + | let doCreateTakeOrder = invoke(this, "internalCreateOrder", [_trader, _amm, TAKE, _takeTriggerPrice, _takeLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0, 0], nil) | |
511 | + | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
512 | + | then nil | |
513 | + | else throw("Strict value is not equal to itself.") | |
514 | + | } | |
515 | + | else nil | |
516 | + | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
517 | + | then nil | |
518 | + | else throw("Strict value is not equal to itself.") | |
519 | + | } | |
464 | 520 | else throw("Strict value is not equal to itself.") | |
465 | 521 | } | |
466 | - | else nil | |
467 | - | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
468 | - | then nil | |
469 | 522 | else throw("Strict value is not equal to itself.") | |
470 | 523 | } | |
471 | 524 | else throw("Strict value is not equal to itself.") | |
514 | 567 | ||
515 | 568 | ||
516 | 569 | @Callable(i) | |
517 | - | func internalCreateOrder (_trader,_amm,_type,_triggerPrice,_limitPrice,_amountIn,_leverage,_side,_refLink,_paymentAssetId,_paymentAmount) = { | |
518 | - | let x1 = toString(!(initialized())) | |
519 | - | let x2 = toString(!(isWhitelist(_amm))) | |
520 | - | let x3 = toString((0 >= _triggerPrice)) | |
521 | - | let x4 = toString((0 > _limitPrice)) | |
522 | - | let x5 = toString((0 >= _amountIn)) | |
523 | - | let x6 = toString((0 > _leverage)) | |
524 | - | let x7 = toString(!(if ((_side == LONG)) | |
570 | + | func internalCreateOrder (_trader,_amm,_type,_triggerPrice,_limitPrice,_amountIn,_leverage,_side,_refLink,_paymentAssetId,_paymentAmount,_expiration) = if (if (if (if (if (if (if (if (if (if (!(initialized())) | |
571 | + | then true | |
572 | + | else !(isWhitelist(_amm))) | |
573 | + | then true | |
574 | + | else (0 >= _triggerPrice)) | |
575 | + | then true | |
576 | + | else (0 > _limitPrice)) | |
577 | + | then true | |
578 | + | else (0 >= _amountIn)) | |
579 | + | then true | |
580 | + | else (0 > _leverage)) | |
581 | + | then true | |
582 | + | else !(if ((_side == LONG)) | |
525 | 583 | then true | |
526 | 584 | else (_side == SHORT))) | |
527 | - | let x8 = toString(!(if (if ((_type == STOP)) | |
585 | + | then true | |
586 | + | else !(if (if ((_type == STOP)) | |
528 | 587 | then true | |
529 | 588 | else (_type == TAKE)) | |
530 | 589 | then true | |
531 | 590 | else (_type == LIMIT))) | |
532 | - | let x9 = toString(!((i.caller == this))) | |
533 | - | let all = makeString([x1, x2, x3, x4, x5, x6, x7, x8, x9], ",") | |
534 | - | if (if (if (if (if (if (if (if (if (!(initialized())) | |
535 | - | then true | |
536 | - | else !(isWhitelist(_amm))) | |
537 | - | then true | |
538 | - | else (0 >= _triggerPrice)) | |
539 | - | then true | |
540 | - | else (0 > _limitPrice)) | |
541 | - | then true | |
542 | - | else (0 >= _amountIn)) | |
543 | - | then true | |
544 | - | else (0 > _leverage)) | |
545 | - | then true | |
546 | - | else !(if ((_side == LONG)) | |
591 | + | then true | |
592 | + | else !((i.caller == this))) | |
593 | + | then true | |
594 | + | else (0 > _expiration)) | |
595 | + | then throw("Invalid internalCreateOrder parameters") | |
596 | + | else { | |
597 | + | let orderId = (currentOrderId() + 1) | |
598 | + | let positionDirection = getPositionDirection(_side, _type) | |
599 | + | let newTraderOrderCount = (getTraderOrderCount(_amm, _trader) + 1) | |
600 | + | let positionSize = getPositionSize(_amm, _trader, positionDirection) | |
601 | + | let orderMarketPrice = getMarketPrice(_amm) | |
602 | + | let _direction = if (if (if ((positionSize == 0)) | |
547 | 603 | then true | |
548 | - | else ( | |
549 | - | then | |
550 | - | else | |
604 | + | else if ((positionSize > 0)) | |
605 | + | then (_side == LONG) | |
606 | + | else false) | |
551 | 607 | then true | |
552 | - | else (_type == TAKE)) | |
553 | - | then true | |
554 | - | else (_type == LIMIT))) | |
555 | - | then true | |
556 | - | else !((i.caller == this))) | |
557 | - | then throw(("Invalid internalCreateOrder parameters " + all)) | |
558 | - | else { | |
559 | - | let orderId = (currentOrderId() + 1) | |
560 | - | let positionDirection = getPositionDirection(_side, _type) | |
561 | - | let newTraderOrderCount = (getTraderOrderCount(_amm, _trader) + 1) | |
562 | - | let positionSize = getPositionSize(_amm, _trader, positionDirection) | |
563 | - | let _direction = if (if (if ((positionSize == 0)) | |
608 | + | else if ((0 > positionSize)) | |
609 | + | then (_side == SHORT) | |
610 | + | else false) | |
611 | + | then INCREASE | |
612 | + | else DECREASE | |
613 | + | if (if ((positionSize == 0)) | |
614 | + | then if ((_type == STOP)) | |
564 | 615 | then true | |
565 | - | else if ((positionSize > 0)) | |
566 | - | then (_side == LONG) | |
567 | - | else false) | |
568 | - | then true | |
569 | - | else if ((0 > positionSize)) | |
570 | - | then (_side == SHORT) | |
571 | - | else false) | |
572 | - | then INCREASE | |
573 | - | else DECREASE | |
574 | - | if (if ((positionSize == 0)) | |
575 | - | then if ((_type == STOP)) | |
576 | - | then true | |
577 | - | else (_type == TAKE) | |
578 | - | else false) | |
579 | - | then throw("Can not create STOP/TAKE order: no position") | |
580 | - | else { | |
581 | - | let usdnPayment = if ((_direction == INCREASE)) | |
582 | - | then if (if ((_paymentAssetId != toBase58String(quoteAsset()))) | |
616 | + | else (_type == TAKE) | |
617 | + | else false) | |
618 | + | then throw("Can not create STOP/TAKE order: no position") | |
619 | + | else { | |
620 | + | let usdnPayment = if ((_direction == INCREASE)) | |
621 | + | then if (if ((_paymentAssetId != toBase58String(quoteAsset()))) | |
622 | + | then true | |
623 | + | else (_paymentAmount != _amountIn)) | |
624 | + | then throw("Invalid createLimitOrder parameters: invalid payment") | |
625 | + | else { | |
626 | + | let stake = invoke(managerAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), _paymentAmount)]) | |
627 | + | if ((stake == stake)) | |
628 | + | then _paymentAmount | |
629 | + | else throw("Strict value is not equal to itself.") | |
630 | + | } | |
631 | + | else 0 | |
632 | + | if ((usdnPayment == usdnPayment)) | |
633 | + | then { | |
634 | + | let positionId = if ((positionSize != 0)) | |
635 | + | then getPositionId(_amm, _trader, positionDirection) | |
636 | + | else 0 | |
637 | + | if (if (if ((_type == STOP)) | |
583 | 638 | then true | |
584 | - | else (_paymentAmount != _amountIn)) | |
585 | - | then throw("Invalid createLimitOrder parameters: invalid payment") | |
586 | - | else { | |
587 | - | let stake = invoke(managerAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), _paymentAmount)]) | |
588 | - | if ((stake == stake)) | |
589 | - | then _paymentAmount | |
590 | - | else throw("Strict value is not equal to itself.") | |
591 | - | } | |
592 | - | else 0 | |
593 | - | if ((usdnPayment == usdnPayment)) | |
594 | - | then { | |
595 | - | let positionId = if ((positionSize != 0)) | |
596 | - | then getPositionId(_amm, _trader, positionDirection) | |
597 | - | else 0 | |
598 | - | if (if (if ((_type == STOP)) | |
599 | - | then true | |
600 | - | else (_type == TAKE)) | |
601 | - | then (positionId == 0) | |
602 | - | else false) | |
603 | - | then throw("STOP and TAKE order should be assigned to position with id != 0") | |
604 | - | else if ((newTraderOrderCount > MAX_TRADER_ORDERS_PER_AMM)) | |
605 | - | then throw("Invalid createLimitOrder parameters: order count") | |
606 | - | else { | |
607 | - | let changeSet = (((saveOrder(orderId, _amm, _trader, _amountIn, _leverage, _type, _triggerPrice, usdnPayment, _side, _refLink, positionId, _limitPrice) ++ addRemoveOrderId(orderId, _amm, _trader, true)) ++ updateTraderOrderCount(_amm, _trader, newTraderOrderCount)) ++ updateLastOrderId(orderId)) | |
608 | - | $Tuple2(changeSet, orderId) | |
609 | - | } | |
610 | - | } | |
611 | - | else throw("Strict value is not equal to itself.") | |
612 | - | } | |
613 | - | } | |
614 | - | } | |
639 | + | else (_type == TAKE)) | |
640 | + | then (positionId == 0) | |
641 | + | else false) | |
642 | + | then throw("STOP and TAKE order should be assigned to position with id != 0") | |
643 | + | else if ((newTraderOrderCount > MAX_TRADER_ORDERS_PER_AMM)) | |
644 | + | then throw("Invalid createLimitOrder parameters: order count") | |
645 | + | else { | |
646 | + | let changeSet = (((saveOrder(orderId, _amm, _trader, _amountIn, _leverage, _type, _triggerPrice, usdnPayment, _side, _refLink, positionId, _limitPrice, _expiration, orderMarketPrice) ++ addRemoveOrderId(orderId, _amm, _trader, true)) ++ updateTraderOrderCount(_amm, _trader, newTraderOrderCount)) ++ updateLastOrderId(orderId)) | |
647 | + | $Tuple2(changeSet, orderId) | |
648 | + | } | |
649 | + | } | |
650 | + | else throw("Strict value is not equal to itself.") | |
651 | + | } | |
652 | + | } | |
615 | 653 | ||
616 | 654 | ||
617 | 655 | ||
618 | 656 | @Callable(i) | |
619 | 657 | func cancelOrder (_orderId) = { | |
620 | - | let $t02378624005 = getOrder(_orderId) | |
621 | - | let _amm = $t02378624005._1 | |
622 | - | let _trader = $t02378624005._2 | |
623 | - | let _amountIn = $t02378624005._3 | |
624 | - | let _leverage = $t02378624005._4 | |
625 | - | let _type = $t02378624005._5 | |
626 | - | let _triggerPrice = $t02378624005._6 | |
627 | - | let _amountUsdn = $t02378624005._7 | |
628 | - | let _side = $t02378624005._8 | |
629 | - | let _refLink = $t02378624005._9 | |
630 | - | let _positionId = $t02378624005._10 | |
631 | - | let _limitPrice = $t02378624005._11 | |
658 | + | let $t02559125741 = getOrder(_orderId) | |
659 | + | let _amm = $t02559125741._1 | |
660 | + | let _trader = $t02559125741._2 | |
661 | + | let _amountIn = $t02559125741._3 | |
662 | + | let _leverage = $t02559125741._4 | |
663 | + | let _type = $t02559125741._5 | |
664 | + | let _triggerPrice = $t02559125741._6 | |
665 | + | let _amountUsdn = $t02559125741._7 | |
632 | 666 | if (if (if (!(initialized())) | |
633 | 667 | then true | |
634 | 668 | else !(isValid(_orderId))) | |
661 | 695 | ||
662 | 696 | ||
663 | 697 | @Callable(i) | |
664 | - | func executeOrder (_orderId) = { | |
665 | - | let $t02520325422 = getOrder(_orderId) | |
666 | - | let _amm = $t02520325422._1 | |
667 | - | let _trader = $t02520325422._2 | |
668 | - | let _amountIn = $t02520325422._3 | |
669 | - | let _leverage = $t02520325422._4 | |
670 | - | let _type = $t02520325422._5 | |
671 | - | let _triggerPrice = $t02520325422._6 | |
672 | - | let _amountUsdn = $t02520325422._7 | |
673 | - | let _side = $t02520325422._8 | |
674 | - | let _refLink = $t02520325422._9 | |
675 | - | let _positionId = $t02520325422._10 | |
676 | - | let _limitPrice = $t02520325422._11 | |
677 | - | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
678 | - | if ((cleanUp == cleanUp)) | |
698 | + | func executeOrder (_orderId,_priceData) = { | |
699 | + | let $t02695927221 = getOrder(_orderId) | |
700 | + | let _amm = $t02695927221._1 | |
701 | + | let _trader = $t02695927221._2 | |
702 | + | let _amountIn = $t02695927221._3 | |
703 | + | let _leverage = $t02695927221._4 | |
704 | + | let _type = $t02695927221._5 | |
705 | + | let _triggerPrice = $t02695927221._6 | |
706 | + | let _amountUsdn = $t02695927221._7 | |
707 | + | let _side = $t02695927221._8 | |
708 | + | let _refLink = $t02695927221._9 | |
709 | + | let _positionId = $t02695927221._10 | |
710 | + | let _limitPrice = $t02695927221._11 | |
711 | + | let _timestamp = $t02695927221._12 | |
712 | + | let _orderMarketPrice = $t02695927221._13 | |
713 | + | let updatePrice = invoke(addressFromStringValue(_amm), "updateOracle", [_priceData], nil) | |
714 | + | if ((updatePrice == updatePrice)) | |
679 | 715 | then { | |
680 | - | let positionDirection = getPositionDirection(_side, _type) | |
681 | - | if (if (!(initialized())) | |
682 | - | then true | |
683 | - | else !(isValid(_orderId))) | |
684 | - | then throw("Invalid executeOrder parameters") | |
685 | - | else { | |
686 | - | let positionSize = getPositionSize(_amm, _trader, positionDirection) | |
687 | - | if ((positionSize == positionSize)) | |
688 | - | then { | |
689 | - | let currentPositionId = if ((positionSize != 0)) | |
690 | - | then getPositionId(_amm, _trader, positionDirection) | |
691 | - | else 0 | |
692 | - | let $t02592929307 = if ((_type == STOP)) | |
716 | + | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
717 | + | if ((cleanUp == cleanUp)) | |
718 | + | then { | |
719 | + | let positionDirection = getPositionDirection(_side, _type) | |
720 | + | if (if (!(initialized())) | |
721 | + | then true | |
722 | + | else !(isValid(_orderId))) | |
723 | + | then throw("Invalid executeOrder parameters") | |
724 | + | else { | |
725 | + | let positionSize = getPositionSize(_amm, _trader, positionDirection) | |
726 | + | if ((positionSize == positionSize)) | |
693 | 727 | then { | |
694 | - | let _positionDirection = if ((positionSize > 0)) | |
695 | - | then LONG | |
696 | - | else if ((0 > positionSize)) | |
697 | - | then SHORT | |
698 | - | else throw("Can not execute STOP order: no open position") | |
699 | - | let marketPrice = getMarketPrice(_amm) | |
700 | - | let isExecutable = if ((_side == _positionDirection)) | |
701 | - | then throw("Can not execute STOP order: reduce only") | |
702 | - | else if ((currentPositionId != _positionId)) | |
703 | - | then throw("Can not execute STOP order: position closed") | |
704 | - | else if ((_positionDirection == LONG)) | |
705 | - | then (_triggerPrice >= marketPrice) | |
706 | - | else (marketPrice >= _triggerPrice) | |
707 | - | if (isExecutable) | |
708 | - | then $Tuple3("closePosition", [minv(_amountIn, abs(positionSize)), positionDirection, muld(_limitPrice, abs(positionSize)), false], nil) | |
709 | - | else throw("Can not execute STOP order: triggerPrice mismatch") | |
710 | - | } | |
711 | - | else if ((_type == TAKE)) | |
712 | - | then { | |
713 | - | let _positionDirection = if ((positionSize > 0)) | |
714 | - | then LONG | |
715 | - | else if ((0 > positionSize)) | |
716 | - | then SHORT | |
717 | - | else throw("Can not execute STOP order: no open position") | |
718 | - | let marketPrice = getMarketPrice(_amm) | |
719 | - | let isExecutable = if ((_side == _positionDirection)) | |
720 | - | then throw("Can not execute TAKE order: reduce only") | |
721 | - | else if ((currentPositionId != _positionId)) | |
722 | - | then throw(((("Can not execute TAKE order: position closed " + toString(currentPositionId)) + "!=") + toString(_positionId))) | |
723 | - | else if ((_positionDirection == LONG)) | |
724 | - | then (marketPrice >= _triggerPrice) | |
725 | - | else (_triggerPrice >= marketPrice) | |
726 | - | if (isExecutable) | |
727 | - | then $Tuple3("closePosition", [minv(_amountIn, abs(positionSize)), positionDirection, muld(_limitPrice, abs(positionSize)), false], nil) | |
728 | - | else throw("Can not execute TAKE order: triggerPrice mismatch") | |
729 | - | } | |
730 | - | else if ((_type == LIMIT)) | |
728 | + | let currentPositionId = if ((positionSize != 0)) | |
729 | + | then getPositionId(_amm, _trader, positionDirection) | |
730 | + | else 0 | |
731 | + | let $t02783031791 = if ((_type == STOP)) | |
731 | 732 | then { | |
733 | + | let _positionDirection = if ((positionSize > 0)) | |
734 | + | then LONG | |
735 | + | else if ((0 > positionSize)) | |
736 | + | then SHORT | |
737 | + | else throw("Can not execute STOP order: no open position") | |
732 | 738 | let marketPrice = getMarketPrice(_amm) | |
733 | - | let spread = if ((_limitPrice == 0)) | |
734 | - | then getSpread(_triggerPrice) | |
735 | - | else abs((_triggerPrice - _limitPrice)) | |
736 | - | let isExecutable = if ((marketPrice >= (_triggerPrice - spread))) | |
737 | - | then ((_triggerPrice + spread) >= marketPrice) | |
738 | - | else false | |
739 | + | let isExecutable = if ((_side == _positionDirection)) | |
740 | + | then throw("Can not execute STOP order: reduce only") | |
741 | + | else if ((currentPositionId != _positionId)) | |
742 | + | then throw("Can not execute STOP order: position closed") | |
743 | + | else if ((_positionDirection == LONG)) | |
744 | + | then (_triggerPrice >= marketPrice) | |
745 | + | else (marketPrice >= _triggerPrice) | |
739 | 746 | if (isExecutable) | |
747 | + | then $Tuple3("closePosition", [minv(_amountIn, abs(positionSize)), positionDirection, muld(_limitPrice, abs(positionSize)), false, _priceData], nil) | |
748 | + | else throw("Can not execute STOP order: triggerPrice mismatch") | |
749 | + | } | |
750 | + | else if ((_type == TAKE)) | |
751 | + | then { | |
752 | + | let _positionDirection = if ((positionSize > 0)) | |
753 | + | then LONG | |
754 | + | else if ((0 > positionSize)) | |
755 | + | then SHORT | |
756 | + | else throw("Can not execute STOP order: no open position") | |
757 | + | let marketPrice = getMarketPrice(_amm) | |
758 | + | let isExecutable = if ((_side == _positionDirection)) | |
759 | + | then throw("Can not execute TAKE order: reduce only") | |
760 | + | else if ((currentPositionId != _positionId)) | |
761 | + | then throw(((("Can not execute TAKE order: position closed " + toString(currentPositionId)) + "!=") + toString(_positionId))) | |
762 | + | else if ((_positionDirection == LONG)) | |
763 | + | then (marketPrice >= _triggerPrice) | |
764 | + | else (_triggerPrice >= marketPrice) | |
765 | + | if (isExecutable) | |
766 | + | then $Tuple3("closePosition", [minv(_amountIn, abs(positionSize)), positionDirection, muld(_limitPrice, abs(positionSize)), false, _priceData], nil) | |
767 | + | else throw("Can not execute TAKE order: triggerPrice mismatch") | |
768 | + | } | |
769 | + | else if ((_type == LIMIT)) | |
740 | 770 | then { | |
741 | - | let amountInWithFee = (_amountUsdn - muld(_amountUsdn, getFee(_amm, _trader))) | |
742 | - | $Tuple3("increasePosition", [_side, _leverage, if ((_limitPrice == 0)) | |
743 | - | then 0 | |
744 | - | else divd(amountInWithFee, _limitPrice), _refLink], [AttachedPayment(quoteAsset(), _amountUsdn)]) | |
771 | + | let marketPrice = getMarketPrice(_amm) | |
772 | + | let isExecutableByStop = if ((_limitPrice == 0)) | |
773 | + | then true | |
774 | + | else if ((_limitPrice > _orderMarketPrice)) | |
775 | + | then (marketPrice >= _limitPrice) | |
776 | + | else (_limitPrice >= marketPrice) | |
777 | + | let isExecutableForTriggerPrice = if ((_side == LONG)) | |
778 | + | then (_triggerPrice >= marketPrice) | |
779 | + | else (marketPrice >= _triggerPrice) | |
780 | + | let isExecutable = if (isExecutableByStop) | |
781 | + | then isExecutableForTriggerPrice | |
782 | + | else false | |
783 | + | if (isExecutable) | |
784 | + | then { | |
785 | + | let marginAmount = divd(_amountUsdn, (muld(getFee(_amm, _trader), _leverage) + DECIMAL_UNIT)) | |
786 | + | let openNotional = muld(marginAmount, _leverage) | |
787 | + | let idealMinBaseAssetAmount = divd(openNotional, _triggerPrice) | |
788 | + | let minBaseAssetAmount = (idealMinBaseAssetAmount - muld(idealMinBaseAssetAmount, getSpreadLimit())) | |
789 | + | $Tuple3("increasePosition", [_side, _leverage, minBaseAssetAmount, _refLink, _priceData], [AttachedPayment(quoteAsset(), _amountUsdn)]) | |
790 | + | } | |
791 | + | else throw("Can not execute LIMIT order: triggerPrice mismatch") | |
745 | 792 | } | |
746 | - | else throw("Can not execute LIMIT order: triggerPrice mismatch") | |
793 | + | else throw(("Invalid order type: " + toString(_type))) | |
794 | + | let method = $t02783031791._1 | |
795 | + | let args = $t02783031791._2 | |
796 | + | let payments = $t02783031791._3 | |
797 | + | let withdraw = if ((size(payments) == 1)) | |
798 | + | then { | |
799 | + | let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), payments[0].amount], nil) | |
800 | + | if ((unstake == unstake)) | |
801 | + | then nil | |
802 | + | else throw("Strict value is not equal to itself.") | |
747 | 803 | } | |
748 | - | else throw(("Invalid order type: " + toString(_type))) | |
749 | - | let method = $t02592929307._1 | |
750 | - | let args = $t02592929307._2 | |
751 | - | let payments = $t02592929307._3 | |
752 | - | let withdraw = if ((size(payments) == 1)) | |
753 | - | then { | |
754 | - | let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), payments[0].amount], nil) | |
755 | - | if ((unstake == unstake)) | |
756 | - | then nil | |
757 | - | else throw("Strict value is not equal to itself.") | |
758 | - | } | |
759 | - | else nil | |
760 | - | if ((withdraw == withdraw)) | |
761 | - | then { | |
762 | - | let doSetContext = invoke(this, "setContext", [_trader], nil) | |
763 | - | if ((doSetContext == doSetContext)) | |
804 | + | else nil | |
805 | + | if ((withdraw == withdraw)) | |
764 | 806 | then { | |
765 | - | let | |
766 | - | if (( | |
807 | + | let doSetContext = invoke(this, "setContext", [_trader], nil) | |
808 | + | if ((doSetContext == doSetContext)) | |
767 | 809 | then { | |
768 | - | let | |
769 | - | if (( | |
810 | + | let doClosePosition = invoke(addressFromStringValue(_amm), method, args, payments) | |
811 | + | if ((doClosePosition == doClosePosition)) | |
770 | 812 | then { | |
771 | - | let executeOrderRequest = if ((_type == LIMIT)) | |
813 | + | let doResetContext = invoke(this, "resetContext", nil, nil) | |
814 | + | if ((doResetContext == doResetContext)) | |
772 | 815 | then { | |
773 | - | let newPositionSize = getPositionSize(_amm, _trader, positionDirection) | |
774 | - | if ((newPositionSize == newPositionSize)) | |
816 | + | let executeOrderRequest = if ((_type == LIMIT)) | |
775 | 817 | then { | |
776 | - | let | |
777 | - | if (( | |
818 | + | let newPositionSize = getPositionSize(_amm, _trader, positionDirection) | |
819 | + | if ((newPositionSize == newPositionSize)) | |
778 | 820 | then { | |
779 | - | let positionSizeDelta = (newPositionSize - positionSize) | |
780 | - | let closeOrderSide = if ((newPositionSize > 0)) | |
781 | - | then SHORT | |
782 | - | else LONG | |
783 | - | let makeTakeOrder = if (haveOrderRequest(_orderId, TAKE)) | |
821 | + | let newPositionId = getPositionId(_amm, _trader, positionDirection) | |
822 | + | if ((newPositionId == newPositionId)) | |
784 | 823 | then { | |
785 | - | let $t03026930468 = getOrderRequest(_orderId, TAKE) | |
786 | - | let newOrderId = $t03026930468._1 | |
787 | - | let newAmm = $t03026930468._2 | |
788 | - | let newTrader = $t03026930468._3 | |
789 | - | let newType = $t03026930468._4 | |
790 | - | let newTriggerPrice = $t03026930468._5 | |
791 | - | let newLimitPrice = $t03026930468._6 | |
792 | - | let doCall = invoke(this, "internalCreateOrder", [newTrader, newAmm, newType, newTriggerPrice, newLimitPrice, positionSizeDelta, 0, closeOrderSide, "", "", 0], nil) | |
793 | - | if ((doCall == doCall)) | |
794 | - | then nil | |
795 | - | else throw("Strict value is not equal to itself.") | |
796 | - | } | |
797 | - | else nil | |
798 | - | if ((makeTakeOrder == makeTakeOrder)) | |
799 | - | then { | |
800 | - | let makeStopOrder = if (haveOrderRequest(_orderId, STOP)) | |
824 | + | let positionSizeDelta = (newPositionSize - positionSize) | |
825 | + | let closeOrderSide = if ((newPositionSize > 0)) | |
826 | + | then SHORT | |
827 | + | else LONG | |
828 | + | let makeTakeOrder = if (haveOrderRequest(_orderId, TAKE)) | |
801 | 829 | then { | |
802 | - | let $ | |
803 | - | let newOrderId = $ | |
804 | - | let newAmm = $ | |
805 | - | let newTrader = $ | |
806 | - | let newType = $ | |
807 | - | let newTriggerPrice = $ | |
808 | - | let newLimitPrice = $ | |
809 | - | let doCall = invoke(this, "internalCreateOrder", [newTrader, newAmm, newType, newTriggerPrice, newLimitPrice, positionSizeDelta, 0, closeOrderSide, "", "", 0], nil) | |
830 | + | let $t03275332952 = getOrderRequest(_orderId, TAKE) | |
831 | + | let newOrderId = $t03275332952._1 | |
832 | + | let newAmm = $t03275332952._2 | |
833 | + | let newTrader = $t03275332952._3 | |
834 | + | let newType = $t03275332952._4 | |
835 | + | let newTriggerPrice = $t03275332952._5 | |
836 | + | let newLimitPrice = $t03275332952._6 | |
837 | + | let doCall = invoke(this, "internalCreateOrder", [newTrader, newAmm, newType, newTriggerPrice, newLimitPrice, positionSizeDelta, 0, closeOrderSide, "", "", 0, 0], nil) | |
810 | 838 | if ((doCall == doCall)) | |
811 | 839 | then nil | |
812 | 840 | else throw("Strict value is not equal to itself.") | |
813 | 841 | } | |
814 | 842 | else nil | |
815 | - | if ((makeStopOrder == makeStopOrder)) | |
816 | - | then (makeTakeOrder ++ makeStopOrder) | |
843 | + | if ((makeTakeOrder == makeTakeOrder)) | |
844 | + | then { | |
845 | + | let makeStopOrder = if (haveOrderRequest(_orderId, STOP)) | |
846 | + | then { | |
847 | + | let $t03352533724 = getOrderRequest(_orderId, STOP) | |
848 | + | let newOrderId = $t03352533724._1 | |
849 | + | let newAmm = $t03352533724._2 | |
850 | + | let newTrader = $t03352533724._3 | |
851 | + | let newType = $t03352533724._4 | |
852 | + | let newTriggerPrice = $t03352533724._5 | |
853 | + | let newLimitPrice = $t03352533724._6 | |
854 | + | let doCall = invoke(this, "internalCreateOrder", [newTrader, newAmm, newType, newTriggerPrice, newLimitPrice, positionSizeDelta, 0, closeOrderSide, "", "", 0, 0], nil) | |
855 | + | if ((doCall == doCall)) | |
856 | + | then nil | |
857 | + | else throw("Strict value is not equal to itself.") | |
858 | + | } | |
859 | + | else nil | |
860 | + | if ((makeStopOrder == makeStopOrder)) | |
861 | + | then (makeTakeOrder ++ makeStopOrder) | |
862 | + | else throw("Strict value is not equal to itself.") | |
863 | + | } | |
817 | 864 | else throw("Strict value is not equal to itself.") | |
818 | 865 | } | |
819 | 866 | else throw("Strict value is not equal to itself.") | |
820 | 867 | } | |
821 | 868 | else throw("Strict value is not equal to itself.") | |
822 | 869 | } | |
823 | - | else | |
824 | - | | |
825 | - | | |
826 | - | | |
827 | - | | |
828 | - | | |
829 | - | | |
830 | - | | |
870 | + | else nil | |
871 | + | if ((executeOrderRequest == executeOrderRequest)) | |
872 | + | then { | |
873 | + | let doMarkOrderExecuted = invoke(this, "internalMarkOrderExecuted", [_amm, _trader, _orderId], nil) | |
874 | + | if ((doMarkOrderExecuted == doMarkOrderExecuted)) | |
875 | + | then nil | |
876 | + | else throw("Strict value is not equal to itself.") | |
877 | + | } | |
831 | 878 | else throw("Strict value is not equal to itself.") | |
832 | 879 | } | |
833 | 880 | else throw("Strict value is not equal to itself.") | |
840 | 887 | } | |
841 | 888 | else throw("Strict value is not equal to itself.") | |
842 | 889 | } | |
843 | - | else throw("Strict value is not equal to itself.") | |
844 | 890 | } | |
891 | + | else throw("Strict value is not equal to itself.") | |
845 | 892 | } | |
846 | 893 | else throw("Strict value is not equal to itself.") | |
847 | 894 | } | |
849 | 896 | ||
850 | 897 | ||
851 | 898 | @Callable(i) | |
852 | - | func view_canExecuteOrder (_orderId) = { | |
853 | - | let s = invoke(this, "executeOrder", [_orderId], nil) | |
899 | + | func view_canExecuteOrder (_orderId,_priceData) = { | |
900 | + | let s = invoke(this, "executeOrder", [_orderId, _priceData], nil) | |
854 | 901 | if ((s == s)) | |
855 | 902 | then throw("Success") | |
856 | 903 | else throw("Strict value is not equal to itself.") |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let k_coordinatorAddress = "k_coordinatorAddress" | |
5 | 5 | ||
6 | 6 | let k_admin_address = "k_admin_address" | |
7 | 7 | ||
8 | 8 | let k_quote_asset = "k_quote_asset" | |
9 | 9 | ||
10 | 10 | let k_amm = "k_amm" | |
11 | 11 | ||
12 | 12 | let k_manager_address = "k_manager_address" | |
13 | 13 | ||
14 | 14 | let k_positionSequence = "k_positionSequence" | |
15 | 15 | ||
16 | 16 | let k_positionSize = "k_positionSize" | |
17 | 17 | ||
18 | 18 | let k_executedOrders = "k_executedOrders" | |
19 | 19 | ||
20 | 20 | let k_canceledOrders = "k_canceledOrders" | |
21 | 21 | ||
22 | 22 | let k_order = "k_order" | |
23 | 23 | ||
24 | 24 | let k_orderRequest = "k_orderReq" | |
25 | 25 | ||
26 | 26 | let k_lastOrderId = "k_lastOrderId" | |
27 | 27 | ||
28 | 28 | let k_traderOrderCnt = "k_traderOrderCnt" | |
29 | 29 | ||
30 | 30 | let k_traderOrderIds = "k_traderOrderIds" | |
31 | 31 | ||
32 | + | let k_spreadLimit = "k_spreadLimit" | |
33 | + | ||
32 | 34 | let k_sender = "k_sender" | |
33 | 35 | ||
34 | 36 | let k_initialized = "k_initialized" | |
35 | 37 | ||
36 | 38 | let STOP = 1 | |
37 | 39 | ||
38 | 40 | let TAKE = 2 | |
39 | 41 | ||
40 | 42 | let LIMIT = 3 | |
41 | 43 | ||
42 | 44 | let LONG = 1 | |
43 | 45 | ||
44 | 46 | let SHORT = 2 | |
45 | 47 | ||
46 | 48 | let INCREASE = 1 | |
47 | 49 | ||
48 | 50 | let DECREASE = 2 | |
49 | 51 | ||
50 | 52 | let MAX_TRADER_ORDERS_PER_AMM = 10 | |
51 | 53 | ||
52 | 54 | let TIME = lastBlock.timestamp | |
53 | 55 | ||
54 | 56 | let DECIMAL_UNIT = (1 * (((((10 * 10) * 10) * 10) * 10) * 10)) | |
55 | - | ||
56 | - | let SPREAD_LIMIT = (DECIMAL_UNIT / 200) | |
57 | 57 | ||
58 | 58 | func abs (_x) = if ((_x > 0)) | |
59 | 59 | then _x | |
60 | 60 | else -(_x) | |
61 | 61 | ||
62 | 62 | ||
63 | 63 | func divd (_x,_y) = fraction(_x, DECIMAL_UNIT, _y, HALFEVEN) | |
64 | 64 | ||
65 | 65 | ||
66 | 66 | func muld (_x,_y) = fraction(_x, _y, DECIMAL_UNIT, HALFEVEN) | |
67 | 67 | ||
68 | 68 | ||
69 | 69 | func minv (_x,_y) = if ((_x > _y)) | |
70 | 70 | then _y | |
71 | 71 | else _x | |
72 | 72 | ||
73 | 73 | ||
74 | 74 | func toCompositeKey (_key,_address) = ((_key + "_") + _address) | |
75 | 75 | ||
76 | 76 | ||
77 | 77 | func executedOrderKey (_orderId) = ((k_executedOrders + "_") + toString(_orderId)) | |
78 | 78 | ||
79 | 79 | ||
80 | 80 | func canceledOrderKey (_orderId) = ((k_canceledOrders + "_") + toString(_orderId)) | |
81 | 81 | ||
82 | 82 | ||
83 | 83 | func orderKey (_orderId) = toCompositeKey(k_order, toString(_orderId)) | |
84 | 84 | ||
85 | 85 | ||
86 | 86 | func orderRequestKey (_orderId,_type) = ((((k_orderRequest + "_") + toString(_orderId)) + "_") + toString(_type)) | |
87 | 87 | ||
88 | 88 | ||
89 | 89 | func traderOrderCountKey (_amm,_trader) = ((((k_traderOrderCnt + "_") + _amm) + "_") + _trader) | |
90 | 90 | ||
91 | 91 | ||
92 | 92 | func traderOrderIdsKey (_amm,_trader) = ((((k_traderOrderIds + "_") + _amm) + "_") + _trader) | |
93 | 93 | ||
94 | 94 | ||
95 | 95 | func coordinator () = valueOrErrorMessage(addressFromString(getStringValue(this, k_coordinatorAddress)), "Coordinator not set") | |
96 | 96 | ||
97 | 97 | ||
98 | + | func adminAddress () = addressFromString(getStringValue(coordinator(), k_admin_address)) | |
99 | + | ||
100 | + | ||
98 | 101 | func quoteAsset () = fromBase58String(getStringValue(coordinator(), k_quote_asset)) | |
99 | 102 | ||
100 | 103 | ||
101 | 104 | func managerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_manager_address)), "Manager not set") | |
102 | 105 | ||
103 | 106 | ||
104 | 107 | func isWhitelist (_address) = valueOrElse(getBoolean(coordinator(), toCompositeKey(k_amm, _address)), false) | |
105 | 108 | ||
106 | 109 | ||
107 | 110 | func initialized () = valueOrElse(getBoolean(this, k_initialized), false) | |
108 | 111 | ||
109 | 112 | ||
110 | 113 | func isValid (_orderId) = if (valueOrElse(getBoolean(this, executedOrderKey(_orderId)), false)) | |
111 | 114 | then throw(("Order already executed: " + toString(_orderId))) | |
112 | 115 | else if (valueOrElse(getBoolean(this, canceledOrderKey(_orderId)), false)) | |
113 | 116 | then throw(("Order already cancelled: " + toString(_orderId))) | |
114 | 117 | else true | |
118 | + | ||
119 | + | ||
120 | + | func getSpreadLimit () = valueOrErrorMessage(getInteger(this, k_spreadLimit), "Spread limit not set") | |
115 | 121 | ||
116 | 122 | ||
117 | 123 | func currentOrderId () = valueOrElse(getInteger(this, k_lastOrderId), 0) | |
118 | 124 | ||
119 | 125 | ||
120 | 126 | func getTraderOrderCount (_amm,_trader) = { | |
121 | 127 | let key = traderOrderCountKey(_amm, _trader) | |
122 | 128 | valueOrElse(getInteger(this, key), 0) | |
123 | 129 | } | |
124 | 130 | ||
125 | 131 | ||
126 | 132 | func traderAmmOrdersIds (_amm,_trader) = { | |
127 | 133 | let key = traderOrderIdsKey(_amm, _trader) | |
128 | 134 | let val = valueOrElse(getString(this, key), "") | |
129 | 135 | if ((val == "")) | |
130 | 136 | then nil | |
131 | 137 | else split(val, ",") | |
132 | 138 | } | |
133 | 139 | ||
134 | 140 | ||
135 | 141 | func haveOrderRequest (_orderId,_type) = { | |
136 | 142 | let key = orderRequestKey(_orderId, _type) | |
137 | 143 | isDefined(getString(this, key)) | |
138 | 144 | } | |
139 | 145 | ||
140 | 146 | ||
141 | 147 | func getOrderRequest (_orderId,_type) = { | |
142 | 148 | let key = orderRequestKey(_orderId, _type) | |
143 | 149 | let orderRequestStr = valueOrErrorMessage(getString(this, key), ("Not order request for key: " + key)) | |
144 | 150 | let orderRequestPartList = split(orderRequestStr, ",") | |
145 | 151 | let orderId = valueOrErrorMessage(parseInt(orderRequestPartList[0]), "Invalid orderId") | |
146 | 152 | let amm = orderRequestPartList[1] | |
147 | 153 | let trader = orderRequestPartList[2] | |
148 | 154 | let type = valueOrErrorMessage(parseInt(orderRequestPartList[3]), "Invalid type") | |
149 | 155 | let triggerPrice = valueOrErrorMessage(parseInt(orderRequestPartList[4]), "Invalid triggerPrice") | |
150 | 156 | let limitPrice = valueOrErrorMessage(parseInt(orderRequestPartList[5]), "Invalid limitPrice") | |
151 | 157 | $Tuple6(orderId, amm, trader, type, triggerPrice, limitPrice) | |
152 | 158 | } | |
153 | 159 | ||
154 | 160 | ||
155 | 161 | func getOrder (_orderId) = { | |
156 | 162 | let orderStr = valueOrErrorMessage(getString(this, orderKey(_orderId)), ("Invalid order id: " + toString(_orderId))) | |
157 | 163 | let orderPartList = split(orderStr, ",") | |
158 | 164 | let amm = orderPartList[0] | |
159 | 165 | let trader = orderPartList[1] | |
160 | 166 | let amountIn = valueOrErrorMessage(parseInt(orderPartList[2]), "Invalid amountIn") | |
161 | 167 | let leverage = valueOrErrorMessage(parseInt(orderPartList[3]), "Invalid leverage") | |
162 | 168 | let type = valueOrErrorMessage(parseInt(orderPartList[4]), "Invalid type") | |
163 | 169 | let triggerPrice = valueOrErrorMessage(parseInt(orderPartList[5]), "Invalid triggerPrice") | |
164 | 170 | let paymentUsdn = valueOrErrorMessage(parseInt(orderPartList[6]), "Invalid paymentUsdn") | |
165 | 171 | let side = valueOrErrorMessage(parseInt(orderPartList[7]), "Invalid side") | |
166 | 172 | let refLink = orderPartList[8] | |
167 | 173 | let positionId = valueOrErrorMessage(parseInt(orderPartList[9]), "Invalid positionId") | |
168 | 174 | let limitPrice = valueOrErrorMessage(parseInt(orderPartList[10]), "Invalid limitPrice") | |
169 | - | $Tuple11(amm, trader, amountIn, leverage, type, triggerPrice, paymentUsdn, side, refLink, positionId, limitPrice) | |
175 | + | let expiration = if ((size(orderPartList) > 11)) | |
176 | + | then valueOrErrorMessage(parseInt(orderPartList[11]), "Invalid expiration") | |
177 | + | else 0 | |
178 | + | let marketPrice = if ((size(orderPartList) > 12)) | |
179 | + | then valueOrErrorMessage(parseInt(orderPartList[12]), "Invalid orderMarketPrice") | |
180 | + | else 0 | |
181 | + | $Tuple13(amm, trader, amountIn, leverage, type, triggerPrice, paymentUsdn, side, refLink, positionId, limitPrice, expiration, marketPrice) | |
170 | 182 | } | |
171 | 183 | ||
172 | 184 | ||
173 | 185 | func getMarketPrice (_amm) = { | |
174 | 186 | let s = invoke(addressFromStringValue(_amm), "computeSpotPrice", nil, nil) | |
175 | 187 | if ((s == s)) | |
176 | 188 | then { | |
177 | 189 | let res = match s { | |
178 | 190 | case t: Int => | |
179 | 191 | t | |
180 | 192 | case _ => | |
181 | 193 | throw("Invalid computeSpotPrice result") | |
182 | 194 | } | |
183 | 195 | value(res) | |
184 | 196 | } | |
185 | 197 | else throw("Strict value is not equal to itself.") | |
186 | 198 | } | |
187 | 199 | ||
188 | 200 | ||
189 | 201 | func getFee (_amm,_trader) = { | |
190 | 202 | let s = invoke(addressFromStringValue(_amm), "computeFeeForTraderWithArtifact", [_trader, ""], nil) | |
191 | 203 | if ((s == s)) | |
192 | 204 | then { | |
193 | 205 | let res = match s { | |
194 | 206 | case t: (Int, Boolean) => | |
195 | 207 | t._1 | |
196 | 208 | case _ => | |
197 | 209 | throw("Invalid computeFeeForTraderWithArtifact result") | |
198 | 210 | } | |
199 | 211 | value(res) | |
200 | 212 | } | |
201 | 213 | else throw("Strict value is not equal to itself.") | |
202 | 214 | } | |
203 | 215 | ||
204 | 216 | ||
205 | 217 | func getPositionDirection (_orderSide,_orderType) = if (if ((_orderType == TAKE)) | |
206 | 218 | then true | |
207 | 219 | else (_orderType == STOP)) | |
208 | 220 | then if ((_orderSide == LONG)) | |
209 | 221 | then SHORT | |
210 | 222 | else LONG | |
211 | 223 | else _orderSide | |
212 | 224 | ||
213 | 225 | ||
214 | 226 | func getPositionSize (_amm,_trader,_direction) = { | |
215 | 227 | let amm = addressFromStringValue(_amm) | |
216 | 228 | let positionKey = ((_trader + "_") + toString(_direction)) | |
217 | 229 | let sizeKey = toCompositeKey(k_positionSize, positionKey) | |
218 | 230 | valueOrElse(getInteger(amm, sizeKey), 0) | |
219 | 231 | } | |
220 | 232 | ||
221 | 233 | ||
222 | 234 | func getPositionId (_amm,_trader,_direction) = { | |
223 | 235 | let amm = addressFromStringValue(_amm) | |
224 | 236 | let positionKey = ((_trader + "_") + toString(_direction)) | |
225 | 237 | let seqKey = toCompositeKey(k_positionSequence, positionKey) | |
226 | 238 | valueOrElse(getInteger(amm, seqKey), 0) | |
227 | 239 | } | |
228 | 240 | ||
229 | 241 | ||
230 | - | func getSpread (_price) = muld(_price, | |
242 | + | func getSpread (_price) = muld(_price, getSpreadLimit()) | |
231 | 243 | ||
232 | 244 | ||
233 | - | func saveOrder (_orderId,_amm,_trader,_amountIn,_leverage,_type,_triggerPrice,_paymentUsdn,_side,_refLink,_positionId,_limitPrice) = { | |
234 | - | let orderStr = makeString([_amm, _trader, toString(_amountIn), toString(_leverage), toString(_type), toString(_triggerPrice), toString(_paymentUsdn), toString(_side), _refLink, toString(_positionId), toString(_limitPrice)], ",") | |
245 | + | func saveOrder (_orderId,_amm,_trader,_amountIn,_leverage,_type,_triggerPrice,_paymentUsdn,_side,_refLink,_positionId,_limitPrice,_expiration,_orderMarketPrice) = { | |
246 | + | let orderStr = makeString([_amm, _trader, toString(_amountIn), toString(_leverage), toString(_type), toString(_triggerPrice), toString(_paymentUsdn), toString(_side), _refLink, toString(_positionId), toString(_limitPrice), toString(_expiration), toString(_orderMarketPrice)], ",") | |
235 | 247 | [StringEntry(orderKey(_orderId), orderStr)] | |
236 | 248 | } | |
237 | 249 | ||
238 | 250 | ||
239 | 251 | func saveOrderRequest (_orderId,_amm,_trader,_type,_triggerPrice,_limitPrice) = { | |
240 | 252 | let orderReqStr = makeString([toString(_orderId), _amm, _trader, toString(_type), toString(_triggerPrice), toString(_limitPrice)], ",") | |
241 | 253 | [StringEntry(orderRequestKey(_orderId, _type), orderReqStr)] | |
242 | 254 | } | |
243 | 255 | ||
244 | 256 | ||
245 | 257 | func updateOrderIdStr (_orderIdsNewStr,_amm,_trader) = [StringEntry(traderOrderIdsKey(_amm, _trader), _orderIdsNewStr)] | |
246 | 258 | ||
247 | 259 | ||
248 | 260 | func addRemoveOrderIdList (_orderIds,_orderId,_amm,_trader,_add) = { | |
249 | 261 | let orderIdsNew = if (_add) | |
250 | 262 | then (_orderIds :+ toString(_orderId)) | |
251 | 263 | else removeByIndex(_orderIds, valueOrErrorMessage(indexOf(_orderIds, toString(_orderId)), ("No order with id: " + toString(_orderId)))) | |
252 | 264 | orderIdsNew | |
253 | 265 | } | |
254 | 266 | ||
255 | 267 | ||
256 | 268 | func addRemoveOrderId (_orderId,_amm,_trader,_add) = { | |
257 | 269 | let orderIds = traderAmmOrdersIds(_amm, _trader) | |
258 | 270 | let orderIdsNew = addRemoveOrderIdList(orderIds, _orderId, _amm, _trader, _add) | |
259 | 271 | let orderIdsNewStr = makeString(orderIdsNew, ",") | |
260 | 272 | updateOrderIdStr(orderIdsNewStr, _amm, _trader) | |
261 | 273 | } | |
262 | 274 | ||
263 | 275 | ||
264 | 276 | func updateTraderOrderCount (_amm,_trader,_count) = if ((0 > _count)) | |
265 | 277 | then throw(("Invalid order count: " + toString(_count))) | |
266 | 278 | else [IntegerEntry(traderOrderCountKey(_amm, _trader), _count)] | |
267 | 279 | ||
268 | 280 | ||
269 | 281 | func updateLastOrderId (_lastOrderId) = [IntegerEntry(k_lastOrderId, _lastOrderId)] | |
270 | 282 | ||
271 | 283 | ||
272 | 284 | func markExecuteOrder (_orderId) = [BooleanEntry(toCompositeKey(k_executedOrders, toString(_orderId)), true)] | |
273 | 285 | ||
274 | 286 | ||
275 | 287 | func markCancelOrder (_orderId) = [BooleanEntry(toCompositeKey(k_canceledOrders, toString(_orderId)), true)] | |
276 | 288 | ||
277 | 289 | ||
278 | 290 | func getPositionIds (_amm,_trader) = { | |
279 | 291 | let longPositionSize = getPositionSize(_amm, _trader, LONG) | |
280 | 292 | let currentLongPositionId = if ((longPositionSize != 0)) | |
281 | 293 | then getPositionId(_amm, _trader, LONG) | |
282 | 294 | else 0 | |
283 | 295 | let shortPositionSize = getPositionSize(_amm, _trader, SHORT) | |
284 | 296 | let currentShortPositionId = if ((shortPositionSize != 0)) | |
285 | 297 | then getPositionId(_amm, _trader, SHORT) | |
286 | 298 | else 0 | |
287 | 299 | [currentLongPositionId, currentShortPositionId] | |
288 | 300 | } | |
289 | 301 | ||
290 | 302 | ||
291 | 303 | @Callable(i) | |
292 | 304 | func cleanUpStaleOrders (_amm,_trader) = { | |
293 | 305 | let orders = traderAmmOrdersIds(_amm, _trader) | |
294 | 306 | let positionIds = getPositionIds(_amm, _trader) | |
295 | 307 | func cleanUpOne (_acc,_orderId) = { | |
296 | 308 | let orderIdInt = valueOrErrorMessage(parseInt(_orderId), "Invalid order id") | |
297 | - | let $t01115611351 = getOrder(orderIdInt) | |
298 | - | let _x1 = $t01115611351._1 | |
299 | - | let _x2 = $t01115611351._2 | |
300 | - | let _x3 = $t01115611351._3 | |
301 | - | let _x4 = $t01115611351._4 | |
302 | - | let _type = $t01115611351._5 | |
303 | - | let _x5 = $t01115611351._6 | |
304 | - | let _x6 = $t01115611351._7 | |
305 | - | let _x7 = $t01115611351._8 | |
306 | - | let _x8 = $t01115611351._9 | |
307 | - | let _positionId = $t01115611351._10 | |
308 | - | let _x9 = $t01115611351._11 | |
309 | - | if (if (if (if ((_type == STOP)) | |
309 | + | let $t01176611982 = getOrder(orderIdInt) | |
310 | + | let _x1 = $t01176611982._1 | |
311 | + | let _x2 = $t01176611982._2 | |
312 | + | let _x3 = $t01176611982._3 | |
313 | + | let _x4 = $t01176611982._4 | |
314 | + | let _type = $t01176611982._5 | |
315 | + | let _x5 = $t01176611982._6 | |
316 | + | let _x6 = $t01176611982._7 | |
317 | + | let _x7 = $t01176611982._8 | |
318 | + | let _x8 = $t01176611982._9 | |
319 | + | let _positionId = $t01176611982._10 | |
320 | + | let _x9 = $t01176611982._11 | |
321 | + | let _expiration = $t01176611982._12 | |
322 | + | let cancelTakeStopOfNoPosition = if (if (if ((_type == STOP)) | |
310 | 323 | then true | |
311 | 324 | else (_type == TAKE)) | |
312 | 325 | then (positionIds[0] != _positionId) | |
313 | 326 | else false) | |
314 | 327 | then (positionIds[1] != _positionId) | |
315 | - | else false) | |
328 | + | else false | |
329 | + | let cancelLimitIfExpired = if ((_type == LIMIT)) | |
330 | + | then (lastBlock.timestamp >= _expiration) | |
331 | + | else false | |
332 | + | if (if (cancelTakeStopOfNoPosition) | |
333 | + | then true | |
334 | + | else cancelLimitIfExpired) | |
316 | 335 | then { | |
317 | 336 | let change = markCancelOrder(orderIdInt) | |
318 | 337 | let newOrderList = addRemoveOrderIdList(_acc._1, orderIdInt, _amm, _trader, false) | |
319 | 338 | $Tuple2(newOrderList, (_acc._2 ++ change)) | |
320 | 339 | } | |
321 | 340 | else _acc | |
322 | 341 | } | |
323 | 342 | ||
324 | - | let $ | |
343 | + | let $t01251412589 = { | |
325 | 344 | let $l = orders | |
326 | 345 | let $s = size($l) | |
327 | 346 | let $acc0 = $Tuple2(orders, nil) | |
328 | 347 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
329 | 348 | then $a | |
330 | 349 | else cleanUpOne($a, $l[$i]) | |
331 | 350 | ||
332 | 351 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
333 | 352 | then $a | |
334 | 353 | else throw("List size exceeds 10") | |
335 | 354 | ||
336 | 355 | $f0_2($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) | |
337 | 356 | } | |
338 | - | let newOrders = $ | |
339 | - | let cancelActions = $ | |
357 | + | let newOrders = $t01251412589._1 | |
358 | + | let cancelActions = $t01251412589._2 | |
340 | 359 | ((cancelActions ++ updateTraderOrderCount(_amm, _trader, size(newOrders))) ++ updateOrderIdStr(makeString(newOrders, ","), _amm, _trader)) | |
341 | 360 | } | |
342 | 361 | ||
343 | 362 | ||
344 | 363 | ||
345 | 364 | @Callable(i) | |
346 | 365 | func setContext (_sender) = if ((i.caller != this)) | |
347 | 366 | then throw("Only self-call") | |
348 | 367 | else [StringEntry(k_sender, _sender)] | |
349 | 368 | ||
350 | 369 | ||
351 | 370 | ||
352 | 371 | @Callable(i) | |
353 | 372 | func resetContext () = if ((i.caller != this)) | |
354 | 373 | then throw("Only self-call") | |
355 | 374 | else [DeleteEntry(k_sender)] | |
356 | 375 | ||
357 | 376 | ||
358 | 377 | ||
359 | 378 | @Callable(i) | |
360 | - | func initialize (_coordinator) = if (if (initialized()) | |
379 | + | func initialize (_coordinator,_spreadLimit) = if (if (if (initialized()) | |
380 | + | then true | |
381 | + | else if ((0 > _spreadLimit)) | |
382 | + | then true | |
383 | + | else (_spreadLimit > (DECIMAL_UNIT / 10))) | |
361 | 384 | then true | |
362 | 385 | else (i.caller != this)) | |
363 | 386 | then throw("Unable to initialize") | |
364 | - | else [StringEntry(k_coordinatorAddress, toString(addressFromStringValue(_coordinator))), BooleanEntry(k_initialized, true)] | |
387 | + | else [StringEntry(k_coordinatorAddress, toString(addressFromStringValue(_coordinator))), IntegerEntry(k_spreadLimit, _spreadLimit), BooleanEntry(k_initialized, true)] | |
365 | 388 | ||
366 | 389 | ||
367 | 390 | ||
368 | 391 | @Callable(i) | |
369 | - | func createOrder (_amm,_type,_triggerPrice,_limitPrice,_amountIn,_leverage,_side,_refLink,_stopTriggerPrice,_stopLimitPrice,_takeTriggerPrice,_takeLimitPrice) = { | |
392 | + | func changeSettings (_spreadLimit) = if (if ((i.caller != adminAddress())) | |
393 | + | then true | |
394 | + | else if ((0 > _spreadLimit)) | |
395 | + | then true | |
396 | + | else (_spreadLimit > (DECIMAL_UNIT / 10))) | |
397 | + | then throw("Invalid changeSettings params") | |
398 | + | else [IntegerEntry(k_spreadLimit, _spreadLimit)] | |
399 | + | ||
400 | + | ||
401 | + | ||
402 | + | @Callable(i) | |
403 | + | func createOrder (_amm,_type,_triggerPrice,_limitPrice,_amountIn,_leverage,_side,_refLink,_stopTriggerPrice,_stopLimitPrice,_takeTriggerPrice,_takeLimitPrice,_expiration,_priceData) = { | |
370 | 404 | let _trader = toString(i.caller) | |
371 | - | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
372 | - | if ((cleanUp == cleanUp)) | |
373 | - | then if ((size(i.payments) > 1)) | |
374 | - | then throw("Invalid createOrder parameters: invalid payment count") | |
375 | - | else { | |
376 | - | let $t01427514527 = if ((size(i.payments) == 1)) | |
377 | - | then $Tuple2(toBase58String(valueOrErrorMessage(i.payments[0].assetId, "Invalid asset id")), i.payments[0].amount) | |
378 | - | else $Tuple2("", 0) | |
379 | - | let paymentAssetId = $t01427514527._1 | |
380 | - | let paymentAmount = $t01427514527._2 | |
381 | - | let doCall = invoke(this, "internalCreateOrder", [_trader, _amm, _type, _triggerPrice, _limitPrice, _amountIn, _leverage, _side, _refLink, paymentAssetId, paymentAmount], nil) | |
382 | - | if ((doCall == doCall)) | |
383 | - | then { | |
384 | - | let orderId = match doCall { | |
385 | - | case t: Int => | |
386 | - | t | |
387 | - | case _ => | |
388 | - | throw("Invalid ID of created order") | |
389 | - | } | |
390 | - | if ((_type == LIMIT)) | |
405 | + | let updatePrice = invoke(addressFromStringValue(_amm), "updateOracle", [_priceData], nil) | |
406 | + | if ((updatePrice == updatePrice)) | |
407 | + | then { | |
408 | + | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
409 | + | if ((cleanUp == cleanUp)) | |
410 | + | then if ((size(i.payments) > 1)) | |
411 | + | then throw("Invalid createOrder parameters: invalid payment count") | |
412 | + | else { | |
413 | + | let $t01570315955 = if ((size(i.payments) == 1)) | |
414 | + | then $Tuple2(toBase58String(valueOrErrorMessage(i.payments[0].assetId, "Invalid asset id")), i.payments[0].amount) | |
415 | + | else $Tuple2("", 0) | |
416 | + | let paymentAssetId = $t01570315955._1 | |
417 | + | let paymentAmount = $t01570315955._2 | |
418 | + | let doCall = invoke(this, "internalCreateOrder", [_trader, _amm, _type, _triggerPrice, _limitPrice, _amountIn, _leverage, _side, _refLink, paymentAssetId, paymentAmount, _expiration], nil) | |
419 | + | if ((doCall == doCall)) | |
391 | 420 | then { | |
392 | - | let makeStop = if ((_stopTriggerPrice > 0)) | |
421 | + | let orderId = match doCall { | |
422 | + | case t: Int => | |
423 | + | t | |
424 | + | case _ => | |
425 | + | throw("Invalid ID of created order") | |
426 | + | } | |
427 | + | if ((_type == LIMIT)) | |
393 | 428 | then { | |
394 | - | let doMakeStop = invoke(this, "internalCreateOrderRequest", [_trader, _amm, orderId, STOP, _stopTriggerPrice, _stopLimitPrice], nil) | |
395 | - | if ((doMakeStop == doMakeStop)) | |
396 | - | then nil | |
397 | - | else throw("Strict value is not equal to itself.") | |
429 | + | let makeStop = if ((_stopTriggerPrice > 0)) | |
430 | + | then { | |
431 | + | let doMakeStop = invoke(this, "internalCreateOrderRequest", [_trader, _amm, orderId, STOP, _stopTriggerPrice, _stopLimitPrice], nil) | |
432 | + | if ((doMakeStop == doMakeStop)) | |
433 | + | then nil | |
434 | + | else throw("Strict value is not equal to itself.") | |
435 | + | } | |
436 | + | else nil | |
437 | + | let makeTake = if ((_takeTriggerPrice > 0)) | |
438 | + | then { | |
439 | + | let doMakeTake = invoke(this, "internalCreateOrderRequest", [_trader, _amm, orderId, TAKE, _takeTriggerPrice, _takeLimitPrice], nil) | |
440 | + | if ((doMakeTake == doMakeTake)) | |
441 | + | then nil | |
442 | + | else throw("Strict value is not equal to itself.") | |
443 | + | } | |
444 | + | else nil | |
445 | + | (makeStop ++ makeTake) | |
398 | 446 | } | |
399 | 447 | else nil | |
400 | - | let makeTake = if ((_takeTriggerPrice > 0)) | |
401 | - | then { | |
402 | - | let doMakeTake = invoke(this, "internalCreateOrderRequest", [_trader, _amm, orderId, TAKE, _takeTriggerPrice, _takeLimitPrice], nil) | |
403 | - | if ((doMakeTake == doMakeTake)) | |
404 | - | then nil | |
405 | - | else throw("Strict value is not equal to itself.") | |
406 | - | } | |
407 | - | else nil | |
408 | - | (makeStop ++ makeTake) | |
409 | 448 | } | |
410 | - | else | |
449 | + | else throw("Strict value is not equal to itself.") | |
411 | 450 | } | |
412 | - | ||
413 | - | ||
451 | + | else throw("Strict value is not equal to itself.") | |
452 | + | } | |
414 | 453 | else throw("Strict value is not equal to itself.") | |
415 | 454 | } | |
416 | 455 | ||
417 | 456 | ||
418 | 457 | ||
419 | 458 | @Callable(i) | |
420 | - | func increasePositionWithStopLoss (_amm,_direction,_leverage,_minBaseAssetAmount,_refLink,_stopTriggerPrice,_stopLimitPrice,_takeTriggerPrice,_takeLimitPrice) = { | |
459 | + | func increasePositionWithStopLoss (_amm,_direction,_leverage,_minBaseAssetAmount,_refLink,_stopTriggerPrice,_stopLimitPrice,_takeTriggerPrice,_takeLimitPrice,_priceData) = { | |
421 | 460 | let _trader = toString(i.caller) | |
422 | 461 | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
423 | 462 | if ((cleanUp == cleanUp)) | |
424 | 463 | then if (if (!(initialized())) | |
425 | 464 | then true | |
426 | 465 | else !(isWhitelist(_amm))) | |
427 | 466 | then throw("Invalid increasePositionWithStopLoss parameters") | |
428 | 467 | else { | |
429 | 468 | let positionSize = getPositionSize(_amm, _trader, _direction) | |
430 | 469 | if ((positionSize != 0)) | |
431 | 470 | then throw("Invalid increasePositionWithStopLoss parameters: only new position") | |
432 | 471 | else { | |
433 | 472 | let doSetContext = invoke(this, "setContext", [_trader], nil) | |
434 | 473 | if ((doSetContext == doSetContext)) | |
435 | 474 | then { | |
436 | - | let | |
437 | - | if (( | |
475 | + | let doOpenPosition = invoke(addressFromStringValue(_amm), "increasePosition", [_direction, _leverage, _minBaseAssetAmount, _refLink, _priceData], i.payments) | |
476 | + | if ((doOpenPosition == doOpenPosition)) | |
438 | 477 | then { | |
439 | 478 | let doResetContext = invoke(this, "resetContext", nil, nil) | |
440 | 479 | if ((doResetContext == doResetContext)) | |
441 | 480 | then { | |
442 | 481 | let openedPositionSize = getPositionSize(_amm, _trader, _direction) | |
443 | 482 | if ((openedPositionSize == openedPositionSize)) | |
444 | 483 | then { | |
445 | 484 | let amountIn = abs(openedPositionSize) | |
446 | - | let stopLossSide = if ((0 > openedPositionSize)) | |
447 | - | then LONG | |
448 | - | else SHORT | |
449 | - | let doCreateStopOrder = if ((_stopTriggerPrice > 0)) | |
485 | + | if ((amountIn == amountIn)) | |
450 | 486 | then { | |
451 | - | let doCreateStopOrder = invoke(this, "internalCreateOrder", [_trader, _amm, STOP, _stopTriggerPrice, _stopLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0], nil) | |
452 | - | if ((doCreateStopOrder == doCreateStopOrder)) | |
453 | - | then nil | |
454 | - | else throw("Strict value is not equal to itself.") | |
455 | - | } | |
456 | - | else nil | |
457 | - | if ((doCreateStopOrder == doCreateStopOrder)) | |
458 | - | then { | |
459 | - | let doCreateTakeOrder = if ((_takeTriggerPrice > 0)) | |
487 | + | let stopLossSide = if ((0 > openedPositionSize)) | |
488 | + | then LONG | |
489 | + | else SHORT | |
490 | + | let checkAmountIn = if ((0 >= amountIn)) | |
460 | 491 | then { | |
461 | - | let doCreateTakeOrder = invoke(this, "internalCreateOrder", [_trader, _amm, TAKE, _takeTriggerPrice, _takeLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0], nil) | |
462 | - | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
463 | - | then nil | |
492 | + | let data = makeString([_amm, _trader, toString(_direction), toString(_leverage), toString(_minBaseAssetAmount), _refLink, _priceData], ",") | |
493 | + | throw(((("Invalid amountIn=" + toString(amountIn)) + " after success increasePosition: ") + data)) | |
494 | + | } | |
495 | + | else 0 | |
496 | + | if ((checkAmountIn == checkAmountIn)) | |
497 | + | then { | |
498 | + | let doCreateStopOrder = if ((_stopTriggerPrice > 0)) | |
499 | + | then { | |
500 | + | let doCreateStopOrder = invoke(this, "internalCreateOrder", [_trader, _amm, STOP, _stopTriggerPrice, _stopLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0, 0], nil) | |
501 | + | if ((doCreateStopOrder == doCreateStopOrder)) | |
502 | + | then nil | |
503 | + | else throw("Strict value is not equal to itself.") | |
504 | + | } | |
505 | + | else nil | |
506 | + | if ((doCreateStopOrder == doCreateStopOrder)) | |
507 | + | then { | |
508 | + | let doCreateTakeOrder = if ((_takeTriggerPrice > 0)) | |
509 | + | then { | |
510 | + | let doCreateTakeOrder = invoke(this, "internalCreateOrder", [_trader, _amm, TAKE, _takeTriggerPrice, _takeLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0, 0], nil) | |
511 | + | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
512 | + | then nil | |
513 | + | else throw("Strict value is not equal to itself.") | |
514 | + | } | |
515 | + | else nil | |
516 | + | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
517 | + | then nil | |
518 | + | else throw("Strict value is not equal to itself.") | |
519 | + | } | |
464 | 520 | else throw("Strict value is not equal to itself.") | |
465 | 521 | } | |
466 | - | else nil | |
467 | - | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
468 | - | then nil | |
469 | 522 | else throw("Strict value is not equal to itself.") | |
470 | 523 | } | |
471 | 524 | else throw("Strict value is not equal to itself.") | |
472 | 525 | } | |
473 | 526 | else throw("Strict value is not equal to itself.") | |
474 | 527 | } | |
475 | 528 | else throw("Strict value is not equal to itself.") | |
476 | 529 | } | |
477 | 530 | else throw("Strict value is not equal to itself.") | |
478 | 531 | } | |
479 | 532 | else throw("Strict value is not equal to itself.") | |
480 | 533 | } | |
481 | 534 | } | |
482 | 535 | else throw("Strict value is not equal to itself.") | |
483 | 536 | } | |
484 | 537 | ||
485 | 538 | ||
486 | 539 | ||
487 | 540 | @Callable(i) | |
488 | 541 | func internalMarkOrderExecuted (_amm,_trader,_orderId) = if (if (if (!(initialized())) | |
489 | 542 | then true | |
490 | 543 | else !(isWhitelist(_amm))) | |
491 | 544 | then true | |
492 | 545 | else !((i.caller == this))) | |
493 | 546 | then throw("Invalid internalMarkOrderExecuted parameters") | |
494 | 547 | else { | |
495 | 548 | let newTraderOrderCount = (getTraderOrderCount(_amm, _trader) - 1) | |
496 | 549 | ((updateTraderOrderCount(_amm, _trader, newTraderOrderCount) ++ addRemoveOrderId(_orderId, _amm, _trader, false)) ++ markExecuteOrder(_orderId)) | |
497 | 550 | } | |
498 | 551 | ||
499 | 552 | ||
500 | 553 | ||
501 | 554 | @Callable(i) | |
502 | 555 | func internalCreateOrderRequest (_trader,_amm,_orderId,_type,_triggerPrice,_limitPrice) = if (if (if (if (if (!(initialized())) | |
503 | 556 | then true | |
504 | 557 | else !(isWhitelist(_amm))) | |
505 | 558 | then true | |
506 | 559 | else (0 >= _triggerPrice)) | |
507 | 560 | then true | |
508 | 561 | else (0 > _limitPrice)) | |
509 | 562 | then true | |
510 | 563 | else !((i.caller == this))) | |
511 | 564 | then throw("Invalid internalCreateOrderRequest parameters") | |
512 | 565 | else saveOrderRequest(_orderId, _amm, _trader, _type, _triggerPrice, _limitPrice) | |
513 | 566 | ||
514 | 567 | ||
515 | 568 | ||
516 | 569 | @Callable(i) | |
517 | - | func internalCreateOrder (_trader,_amm,_type,_triggerPrice,_limitPrice,_amountIn,_leverage,_side,_refLink,_paymentAssetId,_paymentAmount) = { | |
518 | - | let x1 = toString(!(initialized())) | |
519 | - | let x2 = toString(!(isWhitelist(_amm))) | |
520 | - | let x3 = toString((0 >= _triggerPrice)) | |
521 | - | let x4 = toString((0 > _limitPrice)) | |
522 | - | let x5 = toString((0 >= _amountIn)) | |
523 | - | let x6 = toString((0 > _leverage)) | |
524 | - | let x7 = toString(!(if ((_side == LONG)) | |
570 | + | func internalCreateOrder (_trader,_amm,_type,_triggerPrice,_limitPrice,_amountIn,_leverage,_side,_refLink,_paymentAssetId,_paymentAmount,_expiration) = if (if (if (if (if (if (if (if (if (if (!(initialized())) | |
571 | + | then true | |
572 | + | else !(isWhitelist(_amm))) | |
573 | + | then true | |
574 | + | else (0 >= _triggerPrice)) | |
575 | + | then true | |
576 | + | else (0 > _limitPrice)) | |
577 | + | then true | |
578 | + | else (0 >= _amountIn)) | |
579 | + | then true | |
580 | + | else (0 > _leverage)) | |
581 | + | then true | |
582 | + | else !(if ((_side == LONG)) | |
525 | 583 | then true | |
526 | 584 | else (_side == SHORT))) | |
527 | - | let x8 = toString(!(if (if ((_type == STOP)) | |
585 | + | then true | |
586 | + | else !(if (if ((_type == STOP)) | |
528 | 587 | then true | |
529 | 588 | else (_type == TAKE)) | |
530 | 589 | then true | |
531 | 590 | else (_type == LIMIT))) | |
532 | - | let x9 = toString(!((i.caller == this))) | |
533 | - | let all = makeString([x1, x2, x3, x4, x5, x6, x7, x8, x9], ",") | |
534 | - | if (if (if (if (if (if (if (if (if (!(initialized())) | |
535 | - | then true | |
536 | - | else !(isWhitelist(_amm))) | |
537 | - | then true | |
538 | - | else (0 >= _triggerPrice)) | |
539 | - | then true | |
540 | - | else (0 > _limitPrice)) | |
541 | - | then true | |
542 | - | else (0 >= _amountIn)) | |
543 | - | then true | |
544 | - | else (0 > _leverage)) | |
545 | - | then true | |
546 | - | else !(if ((_side == LONG)) | |
591 | + | then true | |
592 | + | else !((i.caller == this))) | |
593 | + | then true | |
594 | + | else (0 > _expiration)) | |
595 | + | then throw("Invalid internalCreateOrder parameters") | |
596 | + | else { | |
597 | + | let orderId = (currentOrderId() + 1) | |
598 | + | let positionDirection = getPositionDirection(_side, _type) | |
599 | + | let newTraderOrderCount = (getTraderOrderCount(_amm, _trader) + 1) | |
600 | + | let positionSize = getPositionSize(_amm, _trader, positionDirection) | |
601 | + | let orderMarketPrice = getMarketPrice(_amm) | |
602 | + | let _direction = if (if (if ((positionSize == 0)) | |
547 | 603 | then true | |
548 | - | else ( | |
549 | - | then | |
550 | - | else | |
604 | + | else if ((positionSize > 0)) | |
605 | + | then (_side == LONG) | |
606 | + | else false) | |
551 | 607 | then true | |
552 | - | else (_type == TAKE)) | |
553 | - | then true | |
554 | - | else (_type == LIMIT))) | |
555 | - | then true | |
556 | - | else !((i.caller == this))) | |
557 | - | then throw(("Invalid internalCreateOrder parameters " + all)) | |
558 | - | else { | |
559 | - | let orderId = (currentOrderId() + 1) | |
560 | - | let positionDirection = getPositionDirection(_side, _type) | |
561 | - | let newTraderOrderCount = (getTraderOrderCount(_amm, _trader) + 1) | |
562 | - | let positionSize = getPositionSize(_amm, _trader, positionDirection) | |
563 | - | let _direction = if (if (if ((positionSize == 0)) | |
608 | + | else if ((0 > positionSize)) | |
609 | + | then (_side == SHORT) | |
610 | + | else false) | |
611 | + | then INCREASE | |
612 | + | else DECREASE | |
613 | + | if (if ((positionSize == 0)) | |
614 | + | then if ((_type == STOP)) | |
564 | 615 | then true | |
565 | - | else if ((positionSize > 0)) | |
566 | - | then (_side == LONG) | |
567 | - | else false) | |
568 | - | then true | |
569 | - | else if ((0 > positionSize)) | |
570 | - | then (_side == SHORT) | |
571 | - | else false) | |
572 | - | then INCREASE | |
573 | - | else DECREASE | |
574 | - | if (if ((positionSize == 0)) | |
575 | - | then if ((_type == STOP)) | |
576 | - | then true | |
577 | - | else (_type == TAKE) | |
578 | - | else false) | |
579 | - | then throw("Can not create STOP/TAKE order: no position") | |
580 | - | else { | |
581 | - | let usdnPayment = if ((_direction == INCREASE)) | |
582 | - | then if (if ((_paymentAssetId != toBase58String(quoteAsset()))) | |
616 | + | else (_type == TAKE) | |
617 | + | else false) | |
618 | + | then throw("Can not create STOP/TAKE order: no position") | |
619 | + | else { | |
620 | + | let usdnPayment = if ((_direction == INCREASE)) | |
621 | + | then if (if ((_paymentAssetId != toBase58String(quoteAsset()))) | |
622 | + | then true | |
623 | + | else (_paymentAmount != _amountIn)) | |
624 | + | then throw("Invalid createLimitOrder parameters: invalid payment") | |
625 | + | else { | |
626 | + | let stake = invoke(managerAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), _paymentAmount)]) | |
627 | + | if ((stake == stake)) | |
628 | + | then _paymentAmount | |
629 | + | else throw("Strict value is not equal to itself.") | |
630 | + | } | |
631 | + | else 0 | |
632 | + | if ((usdnPayment == usdnPayment)) | |
633 | + | then { | |
634 | + | let positionId = if ((positionSize != 0)) | |
635 | + | then getPositionId(_amm, _trader, positionDirection) | |
636 | + | else 0 | |
637 | + | if (if (if ((_type == STOP)) | |
583 | 638 | then true | |
584 | - | else (_paymentAmount != _amountIn)) | |
585 | - | then throw("Invalid createLimitOrder parameters: invalid payment") | |
586 | - | else { | |
587 | - | let stake = invoke(managerAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), _paymentAmount)]) | |
588 | - | if ((stake == stake)) | |
589 | - | then _paymentAmount | |
590 | - | else throw("Strict value is not equal to itself.") | |
591 | - | } | |
592 | - | else 0 | |
593 | - | if ((usdnPayment == usdnPayment)) | |
594 | - | then { | |
595 | - | let positionId = if ((positionSize != 0)) | |
596 | - | then getPositionId(_amm, _trader, positionDirection) | |
597 | - | else 0 | |
598 | - | if (if (if ((_type == STOP)) | |
599 | - | then true | |
600 | - | else (_type == TAKE)) | |
601 | - | then (positionId == 0) | |
602 | - | else false) | |
603 | - | then throw("STOP and TAKE order should be assigned to position with id != 0") | |
604 | - | else if ((newTraderOrderCount > MAX_TRADER_ORDERS_PER_AMM)) | |
605 | - | then throw("Invalid createLimitOrder parameters: order count") | |
606 | - | else { | |
607 | - | let changeSet = (((saveOrder(orderId, _amm, _trader, _amountIn, _leverage, _type, _triggerPrice, usdnPayment, _side, _refLink, positionId, _limitPrice) ++ addRemoveOrderId(orderId, _amm, _trader, true)) ++ updateTraderOrderCount(_amm, _trader, newTraderOrderCount)) ++ updateLastOrderId(orderId)) | |
608 | - | $Tuple2(changeSet, orderId) | |
609 | - | } | |
610 | - | } | |
611 | - | else throw("Strict value is not equal to itself.") | |
612 | - | } | |
613 | - | } | |
614 | - | } | |
639 | + | else (_type == TAKE)) | |
640 | + | then (positionId == 0) | |
641 | + | else false) | |
642 | + | then throw("STOP and TAKE order should be assigned to position with id != 0") | |
643 | + | else if ((newTraderOrderCount > MAX_TRADER_ORDERS_PER_AMM)) | |
644 | + | then throw("Invalid createLimitOrder parameters: order count") | |
645 | + | else { | |
646 | + | let changeSet = (((saveOrder(orderId, _amm, _trader, _amountIn, _leverage, _type, _triggerPrice, usdnPayment, _side, _refLink, positionId, _limitPrice, _expiration, orderMarketPrice) ++ addRemoveOrderId(orderId, _amm, _trader, true)) ++ updateTraderOrderCount(_amm, _trader, newTraderOrderCount)) ++ updateLastOrderId(orderId)) | |
647 | + | $Tuple2(changeSet, orderId) | |
648 | + | } | |
649 | + | } | |
650 | + | else throw("Strict value is not equal to itself.") | |
651 | + | } | |
652 | + | } | |
615 | 653 | ||
616 | 654 | ||
617 | 655 | ||
618 | 656 | @Callable(i) | |
619 | 657 | func cancelOrder (_orderId) = { | |
620 | - | let $t02378624005 = getOrder(_orderId) | |
621 | - | let _amm = $t02378624005._1 | |
622 | - | let _trader = $t02378624005._2 | |
623 | - | let _amountIn = $t02378624005._3 | |
624 | - | let _leverage = $t02378624005._4 | |
625 | - | let _type = $t02378624005._5 | |
626 | - | let _triggerPrice = $t02378624005._6 | |
627 | - | let _amountUsdn = $t02378624005._7 | |
628 | - | let _side = $t02378624005._8 | |
629 | - | let _refLink = $t02378624005._9 | |
630 | - | let _positionId = $t02378624005._10 | |
631 | - | let _limitPrice = $t02378624005._11 | |
658 | + | let $t02559125741 = getOrder(_orderId) | |
659 | + | let _amm = $t02559125741._1 | |
660 | + | let _trader = $t02559125741._2 | |
661 | + | let _amountIn = $t02559125741._3 | |
662 | + | let _leverage = $t02559125741._4 | |
663 | + | let _type = $t02559125741._5 | |
664 | + | let _triggerPrice = $t02559125741._6 | |
665 | + | let _amountUsdn = $t02559125741._7 | |
632 | 666 | if (if (if (!(initialized())) | |
633 | 667 | then true | |
634 | 668 | else !(isValid(_orderId))) | |
635 | 669 | then true | |
636 | 670 | else !((toString(i.caller) == _trader))) | |
637 | 671 | then throw("Invalid cancelOrder parameters") | |
638 | 672 | else { | |
639 | 673 | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
640 | 674 | if ((cleanUp == cleanUp)) | |
641 | 675 | then { | |
642 | 676 | let newTraderOrderCount = (getTraderOrderCount(_amm, _trader) - 1) | |
643 | 677 | let withdraw = if ((_amountUsdn > 0)) | |
644 | 678 | then { | |
645 | 679 | let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), _amountUsdn], nil) | |
646 | 680 | if ((unstake == unstake)) | |
647 | 681 | then nil | |
648 | 682 | else throw("Strict value is not equal to itself.") | |
649 | 683 | } | |
650 | 684 | else nil | |
651 | 685 | if ((withdraw == withdraw)) | |
652 | 686 | then (((markCancelOrder(_orderId) ++ addRemoveOrderId(_orderId, _amm, _trader, false)) ++ updateTraderOrderCount(_amm, _trader, newTraderOrderCount)) ++ (if ((_amountUsdn > 0)) | |
653 | 687 | then [ScriptTransfer(i.caller, _amountUsdn, quoteAsset())] | |
654 | 688 | else nil)) | |
655 | 689 | else throw("Strict value is not equal to itself.") | |
656 | 690 | } | |
657 | 691 | else throw("Strict value is not equal to itself.") | |
658 | 692 | } | |
659 | 693 | } | |
660 | 694 | ||
661 | 695 | ||
662 | 696 | ||
663 | 697 | @Callable(i) | |
664 | - | func executeOrder (_orderId) = { | |
665 | - | let $t02520325422 = getOrder(_orderId) | |
666 | - | let _amm = $t02520325422._1 | |
667 | - | let _trader = $t02520325422._2 | |
668 | - | let _amountIn = $t02520325422._3 | |
669 | - | let _leverage = $t02520325422._4 | |
670 | - | let _type = $t02520325422._5 | |
671 | - | let _triggerPrice = $t02520325422._6 | |
672 | - | let _amountUsdn = $t02520325422._7 | |
673 | - | let _side = $t02520325422._8 | |
674 | - | let _refLink = $t02520325422._9 | |
675 | - | let _positionId = $t02520325422._10 | |
676 | - | let _limitPrice = $t02520325422._11 | |
677 | - | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
678 | - | if ((cleanUp == cleanUp)) | |
698 | + | func executeOrder (_orderId,_priceData) = { | |
699 | + | let $t02695927221 = getOrder(_orderId) | |
700 | + | let _amm = $t02695927221._1 | |
701 | + | let _trader = $t02695927221._2 | |
702 | + | let _amountIn = $t02695927221._3 | |
703 | + | let _leverage = $t02695927221._4 | |
704 | + | let _type = $t02695927221._5 | |
705 | + | let _triggerPrice = $t02695927221._6 | |
706 | + | let _amountUsdn = $t02695927221._7 | |
707 | + | let _side = $t02695927221._8 | |
708 | + | let _refLink = $t02695927221._9 | |
709 | + | let _positionId = $t02695927221._10 | |
710 | + | let _limitPrice = $t02695927221._11 | |
711 | + | let _timestamp = $t02695927221._12 | |
712 | + | let _orderMarketPrice = $t02695927221._13 | |
713 | + | let updatePrice = invoke(addressFromStringValue(_amm), "updateOracle", [_priceData], nil) | |
714 | + | if ((updatePrice == updatePrice)) | |
679 | 715 | then { | |
680 | - | let positionDirection = getPositionDirection(_side, _type) | |
681 | - | if (if (!(initialized())) | |
682 | - | then true | |
683 | - | else !(isValid(_orderId))) | |
684 | - | then throw("Invalid executeOrder parameters") | |
685 | - | else { | |
686 | - | let positionSize = getPositionSize(_amm, _trader, positionDirection) | |
687 | - | if ((positionSize == positionSize)) | |
688 | - | then { | |
689 | - | let currentPositionId = if ((positionSize != 0)) | |
690 | - | then getPositionId(_amm, _trader, positionDirection) | |
691 | - | else 0 | |
692 | - | let $t02592929307 = if ((_type == STOP)) | |
716 | + | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
717 | + | if ((cleanUp == cleanUp)) | |
718 | + | then { | |
719 | + | let positionDirection = getPositionDirection(_side, _type) | |
720 | + | if (if (!(initialized())) | |
721 | + | then true | |
722 | + | else !(isValid(_orderId))) | |
723 | + | then throw("Invalid executeOrder parameters") | |
724 | + | else { | |
725 | + | let positionSize = getPositionSize(_amm, _trader, positionDirection) | |
726 | + | if ((positionSize == positionSize)) | |
693 | 727 | then { | |
694 | - | let _positionDirection = if ((positionSize > 0)) | |
695 | - | then LONG | |
696 | - | else if ((0 > positionSize)) | |
697 | - | then SHORT | |
698 | - | else throw("Can not execute STOP order: no open position") | |
699 | - | let marketPrice = getMarketPrice(_amm) | |
700 | - | let isExecutable = if ((_side == _positionDirection)) | |
701 | - | then throw("Can not execute STOP order: reduce only") | |
702 | - | else if ((currentPositionId != _positionId)) | |
703 | - | then throw("Can not execute STOP order: position closed") | |
704 | - | else if ((_positionDirection == LONG)) | |
705 | - | then (_triggerPrice >= marketPrice) | |
706 | - | else (marketPrice >= _triggerPrice) | |
707 | - | if (isExecutable) | |
708 | - | then $Tuple3("closePosition", [minv(_amountIn, abs(positionSize)), positionDirection, muld(_limitPrice, abs(positionSize)), false], nil) | |
709 | - | else throw("Can not execute STOP order: triggerPrice mismatch") | |
710 | - | } | |
711 | - | else if ((_type == TAKE)) | |
712 | - | then { | |
713 | - | let _positionDirection = if ((positionSize > 0)) | |
714 | - | then LONG | |
715 | - | else if ((0 > positionSize)) | |
716 | - | then SHORT | |
717 | - | else throw("Can not execute STOP order: no open position") | |
718 | - | let marketPrice = getMarketPrice(_amm) | |
719 | - | let isExecutable = if ((_side == _positionDirection)) | |
720 | - | then throw("Can not execute TAKE order: reduce only") | |
721 | - | else if ((currentPositionId != _positionId)) | |
722 | - | then throw(((("Can not execute TAKE order: position closed " + toString(currentPositionId)) + "!=") + toString(_positionId))) | |
723 | - | else if ((_positionDirection == LONG)) | |
724 | - | then (marketPrice >= _triggerPrice) | |
725 | - | else (_triggerPrice >= marketPrice) | |
726 | - | if (isExecutable) | |
727 | - | then $Tuple3("closePosition", [minv(_amountIn, abs(positionSize)), positionDirection, muld(_limitPrice, abs(positionSize)), false], nil) | |
728 | - | else throw("Can not execute TAKE order: triggerPrice mismatch") | |
729 | - | } | |
730 | - | else if ((_type == LIMIT)) | |
728 | + | let currentPositionId = if ((positionSize != 0)) | |
729 | + | then getPositionId(_amm, _trader, positionDirection) | |
730 | + | else 0 | |
731 | + | let $t02783031791 = if ((_type == STOP)) | |
731 | 732 | then { | |
733 | + | let _positionDirection = if ((positionSize > 0)) | |
734 | + | then LONG | |
735 | + | else if ((0 > positionSize)) | |
736 | + | then SHORT | |
737 | + | else throw("Can not execute STOP order: no open position") | |
732 | 738 | let marketPrice = getMarketPrice(_amm) | |
733 | - | let spread = if ((_limitPrice == 0)) | |
734 | - | then getSpread(_triggerPrice) | |
735 | - | else abs((_triggerPrice - _limitPrice)) | |
736 | - | let isExecutable = if ((marketPrice >= (_triggerPrice - spread))) | |
737 | - | then ((_triggerPrice + spread) >= marketPrice) | |
738 | - | else false | |
739 | + | let isExecutable = if ((_side == _positionDirection)) | |
740 | + | then throw("Can not execute STOP order: reduce only") | |
741 | + | else if ((currentPositionId != _positionId)) | |
742 | + | then throw("Can not execute STOP order: position closed") | |
743 | + | else if ((_positionDirection == LONG)) | |
744 | + | then (_triggerPrice >= marketPrice) | |
745 | + | else (marketPrice >= _triggerPrice) | |
739 | 746 | if (isExecutable) | |
747 | + | then $Tuple3("closePosition", [minv(_amountIn, abs(positionSize)), positionDirection, muld(_limitPrice, abs(positionSize)), false, _priceData], nil) | |
748 | + | else throw("Can not execute STOP order: triggerPrice mismatch") | |
749 | + | } | |
750 | + | else if ((_type == TAKE)) | |
751 | + | then { | |
752 | + | let _positionDirection = if ((positionSize > 0)) | |
753 | + | then LONG | |
754 | + | else if ((0 > positionSize)) | |
755 | + | then SHORT | |
756 | + | else throw("Can not execute STOP order: no open position") | |
757 | + | let marketPrice = getMarketPrice(_amm) | |
758 | + | let isExecutable = if ((_side == _positionDirection)) | |
759 | + | then throw("Can not execute TAKE order: reduce only") | |
760 | + | else if ((currentPositionId != _positionId)) | |
761 | + | then throw(((("Can not execute TAKE order: position closed " + toString(currentPositionId)) + "!=") + toString(_positionId))) | |
762 | + | else if ((_positionDirection == LONG)) | |
763 | + | then (marketPrice >= _triggerPrice) | |
764 | + | else (_triggerPrice >= marketPrice) | |
765 | + | if (isExecutable) | |
766 | + | then $Tuple3("closePosition", [minv(_amountIn, abs(positionSize)), positionDirection, muld(_limitPrice, abs(positionSize)), false, _priceData], nil) | |
767 | + | else throw("Can not execute TAKE order: triggerPrice mismatch") | |
768 | + | } | |
769 | + | else if ((_type == LIMIT)) | |
740 | 770 | then { | |
741 | - | let amountInWithFee = (_amountUsdn - muld(_amountUsdn, getFee(_amm, _trader))) | |
742 | - | $Tuple3("increasePosition", [_side, _leverage, if ((_limitPrice == 0)) | |
743 | - | then 0 | |
744 | - | else divd(amountInWithFee, _limitPrice), _refLink], [AttachedPayment(quoteAsset(), _amountUsdn)]) | |
771 | + | let marketPrice = getMarketPrice(_amm) | |
772 | + | let isExecutableByStop = if ((_limitPrice == 0)) | |
773 | + | then true | |
774 | + | else if ((_limitPrice > _orderMarketPrice)) | |
775 | + | then (marketPrice >= _limitPrice) | |
776 | + | else (_limitPrice >= marketPrice) | |
777 | + | let isExecutableForTriggerPrice = if ((_side == LONG)) | |
778 | + | then (_triggerPrice >= marketPrice) | |
779 | + | else (marketPrice >= _triggerPrice) | |
780 | + | let isExecutable = if (isExecutableByStop) | |
781 | + | then isExecutableForTriggerPrice | |
782 | + | else false | |
783 | + | if (isExecutable) | |
784 | + | then { | |
785 | + | let marginAmount = divd(_amountUsdn, (muld(getFee(_amm, _trader), _leverage) + DECIMAL_UNIT)) | |
786 | + | let openNotional = muld(marginAmount, _leverage) | |
787 | + | let idealMinBaseAssetAmount = divd(openNotional, _triggerPrice) | |
788 | + | let minBaseAssetAmount = (idealMinBaseAssetAmount - muld(idealMinBaseAssetAmount, getSpreadLimit())) | |
789 | + | $Tuple3("increasePosition", [_side, _leverage, minBaseAssetAmount, _refLink, _priceData], [AttachedPayment(quoteAsset(), _amountUsdn)]) | |
790 | + | } | |
791 | + | else throw("Can not execute LIMIT order: triggerPrice mismatch") | |
745 | 792 | } | |
746 | - | else throw("Can not execute LIMIT order: triggerPrice mismatch") | |
793 | + | else throw(("Invalid order type: " + toString(_type))) | |
794 | + | let method = $t02783031791._1 | |
795 | + | let args = $t02783031791._2 | |
796 | + | let payments = $t02783031791._3 | |
797 | + | let withdraw = if ((size(payments) == 1)) | |
798 | + | then { | |
799 | + | let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), payments[0].amount], nil) | |
800 | + | if ((unstake == unstake)) | |
801 | + | then nil | |
802 | + | else throw("Strict value is not equal to itself.") | |
747 | 803 | } | |
748 | - | else throw(("Invalid order type: " + toString(_type))) | |
749 | - | let method = $t02592929307._1 | |
750 | - | let args = $t02592929307._2 | |
751 | - | let payments = $t02592929307._3 | |
752 | - | let withdraw = if ((size(payments) == 1)) | |
753 | - | then { | |
754 | - | let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), payments[0].amount], nil) | |
755 | - | if ((unstake == unstake)) | |
756 | - | then nil | |
757 | - | else throw("Strict value is not equal to itself.") | |
758 | - | } | |
759 | - | else nil | |
760 | - | if ((withdraw == withdraw)) | |
761 | - | then { | |
762 | - | let doSetContext = invoke(this, "setContext", [_trader], nil) | |
763 | - | if ((doSetContext == doSetContext)) | |
804 | + | else nil | |
805 | + | if ((withdraw == withdraw)) | |
764 | 806 | then { | |
765 | - | let | |
766 | - | if (( | |
807 | + | let doSetContext = invoke(this, "setContext", [_trader], nil) | |
808 | + | if ((doSetContext == doSetContext)) | |
767 | 809 | then { | |
768 | - | let | |
769 | - | if (( | |
810 | + | let doClosePosition = invoke(addressFromStringValue(_amm), method, args, payments) | |
811 | + | if ((doClosePosition == doClosePosition)) | |
770 | 812 | then { | |
771 | - | let executeOrderRequest = if ((_type == LIMIT)) | |
813 | + | let doResetContext = invoke(this, "resetContext", nil, nil) | |
814 | + | if ((doResetContext == doResetContext)) | |
772 | 815 | then { | |
773 | - | let newPositionSize = getPositionSize(_amm, _trader, positionDirection) | |
774 | - | if ((newPositionSize == newPositionSize)) | |
816 | + | let executeOrderRequest = if ((_type == LIMIT)) | |
775 | 817 | then { | |
776 | - | let | |
777 | - | if (( | |
818 | + | let newPositionSize = getPositionSize(_amm, _trader, positionDirection) | |
819 | + | if ((newPositionSize == newPositionSize)) | |
778 | 820 | then { | |
779 | - | let positionSizeDelta = (newPositionSize - positionSize) | |
780 | - | let closeOrderSide = if ((newPositionSize > 0)) | |
781 | - | then SHORT | |
782 | - | else LONG | |
783 | - | let makeTakeOrder = if (haveOrderRequest(_orderId, TAKE)) | |
821 | + | let newPositionId = getPositionId(_amm, _trader, positionDirection) | |
822 | + | if ((newPositionId == newPositionId)) | |
784 | 823 | then { | |
785 | - | let $t03026930468 = getOrderRequest(_orderId, TAKE) | |
786 | - | let newOrderId = $t03026930468._1 | |
787 | - | let newAmm = $t03026930468._2 | |
788 | - | let newTrader = $t03026930468._3 | |
789 | - | let newType = $t03026930468._4 | |
790 | - | let newTriggerPrice = $t03026930468._5 | |
791 | - | let newLimitPrice = $t03026930468._6 | |
792 | - | let doCall = invoke(this, "internalCreateOrder", [newTrader, newAmm, newType, newTriggerPrice, newLimitPrice, positionSizeDelta, 0, closeOrderSide, "", "", 0], nil) | |
793 | - | if ((doCall == doCall)) | |
794 | - | then nil | |
795 | - | else throw("Strict value is not equal to itself.") | |
796 | - | } | |
797 | - | else nil | |
798 | - | if ((makeTakeOrder == makeTakeOrder)) | |
799 | - | then { | |
800 | - | let makeStopOrder = if (haveOrderRequest(_orderId, STOP)) | |
824 | + | let positionSizeDelta = (newPositionSize - positionSize) | |
825 | + | let closeOrderSide = if ((newPositionSize > 0)) | |
826 | + | then SHORT | |
827 | + | else LONG | |
828 | + | let makeTakeOrder = if (haveOrderRequest(_orderId, TAKE)) | |
801 | 829 | then { | |
802 | - | let $ | |
803 | - | let newOrderId = $ | |
804 | - | let newAmm = $ | |
805 | - | let newTrader = $ | |
806 | - | let newType = $ | |
807 | - | let newTriggerPrice = $ | |
808 | - | let newLimitPrice = $ | |
809 | - | let doCall = invoke(this, "internalCreateOrder", [newTrader, newAmm, newType, newTriggerPrice, newLimitPrice, positionSizeDelta, 0, closeOrderSide, "", "", 0], nil) | |
830 | + | let $t03275332952 = getOrderRequest(_orderId, TAKE) | |
831 | + | let newOrderId = $t03275332952._1 | |
832 | + | let newAmm = $t03275332952._2 | |
833 | + | let newTrader = $t03275332952._3 | |
834 | + | let newType = $t03275332952._4 | |
835 | + | let newTriggerPrice = $t03275332952._5 | |
836 | + | let newLimitPrice = $t03275332952._6 | |
837 | + | let doCall = invoke(this, "internalCreateOrder", [newTrader, newAmm, newType, newTriggerPrice, newLimitPrice, positionSizeDelta, 0, closeOrderSide, "", "", 0, 0], nil) | |
810 | 838 | if ((doCall == doCall)) | |
811 | 839 | then nil | |
812 | 840 | else throw("Strict value is not equal to itself.") | |
813 | 841 | } | |
814 | 842 | else nil | |
815 | - | if ((makeStopOrder == makeStopOrder)) | |
816 | - | then (makeTakeOrder ++ makeStopOrder) | |
843 | + | if ((makeTakeOrder == makeTakeOrder)) | |
844 | + | then { | |
845 | + | let makeStopOrder = if (haveOrderRequest(_orderId, STOP)) | |
846 | + | then { | |
847 | + | let $t03352533724 = getOrderRequest(_orderId, STOP) | |
848 | + | let newOrderId = $t03352533724._1 | |
849 | + | let newAmm = $t03352533724._2 | |
850 | + | let newTrader = $t03352533724._3 | |
851 | + | let newType = $t03352533724._4 | |
852 | + | let newTriggerPrice = $t03352533724._5 | |
853 | + | let newLimitPrice = $t03352533724._6 | |
854 | + | let doCall = invoke(this, "internalCreateOrder", [newTrader, newAmm, newType, newTriggerPrice, newLimitPrice, positionSizeDelta, 0, closeOrderSide, "", "", 0, 0], nil) | |
855 | + | if ((doCall == doCall)) | |
856 | + | then nil | |
857 | + | else throw("Strict value is not equal to itself.") | |
858 | + | } | |
859 | + | else nil | |
860 | + | if ((makeStopOrder == makeStopOrder)) | |
861 | + | then (makeTakeOrder ++ makeStopOrder) | |
862 | + | else throw("Strict value is not equal to itself.") | |
863 | + | } | |
817 | 864 | else throw("Strict value is not equal to itself.") | |
818 | 865 | } | |
819 | 866 | else throw("Strict value is not equal to itself.") | |
820 | 867 | } | |
821 | 868 | else throw("Strict value is not equal to itself.") | |
822 | 869 | } | |
823 | - | else | |
824 | - | | |
825 | - | | |
826 | - | | |
827 | - | | |
828 | - | | |
829 | - | | |
830 | - | | |
870 | + | else nil | |
871 | + | if ((executeOrderRequest == executeOrderRequest)) | |
872 | + | then { | |
873 | + | let doMarkOrderExecuted = invoke(this, "internalMarkOrderExecuted", [_amm, _trader, _orderId], nil) | |
874 | + | if ((doMarkOrderExecuted == doMarkOrderExecuted)) | |
875 | + | then nil | |
876 | + | else throw("Strict value is not equal to itself.") | |
877 | + | } | |
831 | 878 | else throw("Strict value is not equal to itself.") | |
832 | 879 | } | |
833 | 880 | else throw("Strict value is not equal to itself.") | |
834 | 881 | } | |
835 | 882 | else throw("Strict value is not equal to itself.") | |
836 | 883 | } | |
837 | 884 | else throw("Strict value is not equal to itself.") | |
838 | 885 | } | |
839 | 886 | else throw("Strict value is not equal to itself.") | |
840 | 887 | } | |
841 | 888 | else throw("Strict value is not equal to itself.") | |
842 | 889 | } | |
843 | - | else throw("Strict value is not equal to itself.") | |
844 | 890 | } | |
891 | + | else throw("Strict value is not equal to itself.") | |
845 | 892 | } | |
846 | 893 | else throw("Strict value is not equal to itself.") | |
847 | 894 | } | |
848 | 895 | ||
849 | 896 | ||
850 | 897 | ||
851 | 898 | @Callable(i) | |
852 | - | func view_canExecuteOrder (_orderId) = { | |
853 | - | let s = invoke(this, "executeOrder", [_orderId], nil) | |
899 | + | func view_canExecuteOrder (_orderId,_priceData) = { | |
900 | + | let s = invoke(this, "executeOrder", [_orderId, _priceData], nil) | |
854 | 901 | if ((s == s)) | |
855 | 902 | then throw("Success") | |
856 | 903 | else throw("Strict value is not equal to itself.") | |
857 | 904 | } | |
858 | 905 | ||
859 | 906 | ||
860 | 907 | @Verifier(tx) | |
861 | 908 | func verify () = { | |
862 | 909 | let coordinatorStr = getString(this, k_coordinatorAddress) | |
863 | 910 | if (isDefined(coordinatorStr)) | |
864 | 911 | then { | |
865 | 912 | let admin = getString(addressFromStringValue(value(coordinatorStr)), k_admin_address) | |
866 | 913 | if (isDefined(admin)) | |
867 | 914 | then valueOrElse(getBoolean(addressFromStringValue(value(admin)), ((("status_" + toString(this)) + "_") + toBase58String(tx.id))), false) | |
868 | 915 | else throw("unable to verify: admin not set in coordinator") | |
869 | 916 | } | |
870 | 917 | else sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
871 | 918 | } | |
872 | 919 |
github/deemru/w8io/169f3d6 185.35 ms ◑