tx · Fj8LyeAxMh3HyxXSCJcfdzuxbkP34QExpoCxpuGYvYrU 3N9kbR6BQEQV7pwBfDFzprJtNofgi6fSJ6Y: -0.03700000 Waves 2022.12.21 20:40 [2370372] smart account 3N9kbR6BQEQV7pwBfDFzprJtNofgi6fSJ6Y > SELF 0.00000000 Waves
{ "type": 13, "id": "Fj8LyeAxMh3HyxXSCJcfdzuxbkP34QExpoCxpuGYvYrU", "fee": 3700000, "feeAssetId": null, "timestamp": 1671644440005, "version": 2, "chainId": 84, "sender": "3N9kbR6BQEQV7pwBfDFzprJtNofgi6fSJ6Y", "senderPublicKey": "EajGg1J8duApPELWPw9gVkPwAKFC9hujhvCcne4FunUa", "proofs": [ "2b1ioECWLgjEpbDacsYGNQMb1VGcPKqNumL1NbfzChW8bP7NYMHrfzYp5GKAyB566iZTV6PWV9PYHjxoVNwkjDog" ], "script": "base64:BgJLCAISBAoCCAgSAwoBCBIAEgMKAQgSCgoICAEBAQEBAQgSCwoJCAEBAQgBAQEBEg0KCwgIAQEBAQEBCAgBEgMKAQESAwoBARIDCgEBOwAUa19jb29yZGluYXRvckFkZHJlc3MCFGtfY29vcmRpbmF0b3JBZGRyZXNzABJrX2FkbWluX3B1YmxpY19rZXkCEmtfYWRtaW5fcHVibGljX2tleQANa19xdW90ZV9hc3NldAINa19xdW90ZV9hc3NldAAFa19hbW0CBWtfYW1tABFrX21hbmFnZXJfYWRkcmVzcwIRa19tYW5hZ2VyX2FkZHJlc3MAEmtfcG9zaXRpb25TZXF1ZW5jZQISa19wb3NpdGlvblNlcXVlbmNlAA5rX3Bvc2l0aW9uU2l6ZQIOa19wb3NpdGlvblNpemUABWtfZmVlAgVrX2ZlZQAQa19leGVjdXRlZE9yZGVycwIQa19leGVjdXRlZE9yZGVycwAQa19jYW5jZWxlZE9yZGVycwIQa19jYW5jZWxlZE9yZGVycwAHa19vcmRlcgIHa19vcmRlcgANa19sYXN0T3JkZXJJZAINa19sYXN0T3JkZXJJZAAQa190cmFkZXJP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1Jlc2V0Q29udGV4dAQTbmV3VHJhZGVyT3JkZXJDb3VudAkAZQIJARNnZXRUcmFkZXJPcmRlckNvdW50AgUEX2FtbQUHX3RyYWRlcgABCQDOCAIJAM4IAgkBFnVwZGF0ZVRyYWRlck9yZGVyQ291bnQDBQRfYW1tBQdfdHJhZGVyBRNuZXdUcmFkZXJPcmRlckNvdW50CQEQYWRkUmVtb3ZlT3JkZXJJZAQFCF9vcmRlcklkBQRfYW1tBQdfdHJhZGVyBwkBEG1hcmtFeGVjdXRlT3JkZXIBBQhfb3JkZXJJZAkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgFpARR2aWV3X2NhbkV4ZWN1dGVPcmRlcgEIX29yZGVySWQEAXMJAPwHBAUEdGhpcwIMZXhlY3V0ZU9yZGVyCQDMCAIFCF9vcmRlcklkBQNuaWwFA25pbAMJAAACBQFzBQFzCQACAQIHU3VjY2VzcwkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgECdHgBBnZlcmlmeQAJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAAJAQ5hZG1pblB1YmxpY0tleQC8ceGo", "height": 2370372, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 9HEMv6NzTacEfbxV2S5MSzaPbbvk6qzzx3MmD4UrEe71 Next: G7FXZm7SAJJt3w4FYMYKa97zdrFBQqRBG961NkLTHbhM Diff:
Old | New | Differences | |
---|---|---|---|
26 | 26 | let k_lastOrderId = "k_lastOrderId" | |
27 | 27 | ||
28 | 28 | let k_traderOrderCnt = "k_traderOrderCnt" | |
29 | + | ||
30 | + | let k_traderOrderIds = "k_traderOrderIds" | |
29 | 31 | ||
30 | 32 | let k_sender = "k_sender" | |
31 | 33 | ||
84 | 86 | func traderOrderCountKey (_amm,_trader) = ((((k_traderOrderCnt + "_") + _amm) + "_") + _trader) | |
85 | 87 | ||
86 | 88 | ||
89 | + | func traderOrderIdsKey (_amm,_trader) = ((((k_traderOrderIds + "_") + _amm) + "_") + _trader) | |
90 | + | ||
91 | + | ||
87 | 92 | func coordinator () = valueOrErrorMessage(addressFromString(getStringValue(this, k_coordinatorAddress)), "Coordinator not set") | |
88 | 93 | ||
89 | 94 | ||
115 | 120 | func getTraderOrderCount (_amm,_trader) = { | |
116 | 121 | let key = traderOrderCountKey(_amm, _trader) | |
117 | 122 | valueOrElse(getInteger(this, key), 0) | |
123 | + | } | |
124 | + | ||
125 | + | ||
126 | + | func traderAmmOrdersIds (_amm,_trader) = { | |
127 | + | let key = traderOrderIdsKey(_amm, _trader) | |
128 | + | let val = valueOrElse(getString(this, key), "") | |
129 | + | if ((val == "")) | |
130 | + | then nil | |
131 | + | else split(val, ",") | |
118 | 132 | } | |
119 | 133 | ||
120 | 134 | ||
191 | 205 | } | |
192 | 206 | ||
193 | 207 | ||
208 | + | func addRemoveOrderId (_orderId,_amm,_trader,_add) = { | |
209 | + | let orderIds = traderAmmOrdersIds(_amm, _trader) | |
210 | + | let orderIdsNew = if (_add) | |
211 | + | then (orderIds :+ toString(_orderId)) | |
212 | + | else removeByIndex(orderIds, valueOrErrorMessage(indexOf(orderIds, toString(_orderId)), ("No order with id: " + toString(_orderId)))) | |
213 | + | let orderIdsNewStr = makeString(orderIdsNew, ",") | |
214 | + | [StringEntry(traderOrderIdsKey(_amm, _trader), orderIdsNewStr)] | |
215 | + | } | |
216 | + | ||
217 | + | ||
194 | 218 | func updateTraderOrderCount (_amm,_trader,_count) = [IntegerEntry(traderOrderCountKey(_amm, _trader), _count)] | |
195 | 219 | ||
196 | 220 | ||
201 | 225 | ||
202 | 226 | ||
203 | 227 | func markCancelOrder (_orderId) = [BooleanEntry(toCompositeKey(k_canceledOrders, toString(_orderId)), true)] | |
228 | + | ||
229 | + | ||
230 | + | @Callable(i) | |
231 | + | func cleanUpStaleOrders (_amm,_trader) = { | |
232 | + | let orders = traderAmmOrdersIds(_amm, _trader) | |
233 | + | func cleanUpOne (_acc,_orderId) = { | |
234 | + | let orderIdInt = valueOrErrorMessage(parseInt(_orderId), "Invalid order id") | |
235 | + | let $t083208515 = getOrder(orderIdInt) | |
236 | + | let _x1 = $t083208515._1 | |
237 | + | let _x2 = $t083208515._2 | |
238 | + | let _x3 = $t083208515._3 | |
239 | + | let _x4 = $t083208515._4 | |
240 | + | let _type = $t083208515._5 | |
241 | + | let _x5 = $t083208515._6 | |
242 | + | let _x6 = $t083208515._7 | |
243 | + | let _x7 = $t083208515._8 | |
244 | + | let _x8 = $t083208515._9 | |
245 | + | let _positionId = $t083208515._10 | |
246 | + | let _x9 = $t083208515._11 | |
247 | + | let positionSize = getPositionSize(_amm, _trader) | |
248 | + | let currentPositionId = if ((positionSize != 0)) | |
249 | + | then getPositionId(_amm, _trader) | |
250 | + | else 0 | |
251 | + | if (if (if ((_type == STOP)) | |
252 | + | then true | |
253 | + | else (_type == TAKE)) | |
254 | + | then (currentPositionId != _positionId) | |
255 | + | else false) | |
256 | + | then { | |
257 | + | let change = (markCancelOrder(orderIdInt) ++ addRemoveOrderId(orderIdInt, _amm, _trader, false)) | |
258 | + | (_acc ++ change) | |
259 | + | } | |
260 | + | else _acc | |
261 | + | } | |
262 | + | ||
263 | + | let $l = orders | |
264 | + | let $s = size($l) | |
265 | + | let $acc0 = nil | |
266 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
267 | + | then $a | |
268 | + | else cleanUpOne($a, $l[$i]) | |
269 | + | ||
270 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
271 | + | then $a | |
272 | + | else throw("List size exceeds 5") | |
273 | + | ||
274 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5) | |
275 | + | } | |
276 | + | ||
204 | 277 | ||
205 | 278 | ||
206 | 279 | @Callable(i) | |
225 | 298 | ||
226 | 299 | ||
227 | 300 | @Callable(i) | |
228 | - | func createOrder (_amm,_type,_triggerPrice,_limitPrice,_amountIn,_leverage,_side,_refLink) = if ((size(i.payments) > 1)) | |
229 | - | then throw("Invalid createOrder parameters: invalid payment count") | |
230 | - | else { | |
231 | - | let $t080238275 = if ((size(i.payments) == 1)) | |
232 | - | then $Tuple2(toBase58String(valueOrErrorMessage(i.payments[0].assetId, "Invalid asset id")), i.payments[0].amount) | |
233 | - | else $Tuple2("", 0) | |
234 | - | let paymentAssetId = $t080238275._1 | |
235 | - | let paymentAmount = $t080238275._2 | |
236 | - | let doCall = invoke(this, "internalCreateOrder", [toString(i.caller), _amm, _type, _triggerPrice, _limitPrice, _amountIn, _leverage, _side, _refLink, paymentAssetId, paymentAmount], nil) | |
237 | - | if ((doCall == doCall)) | |
238 | - | then nil | |
239 | - | else throw("Strict value is not equal to itself.") | |
240 | - | } | |
301 | + | func createOrder (_amm,_type,_triggerPrice,_limitPrice,_amountIn,_leverage,_side,_refLink) = { | |
302 | + | let _trader = toString(i.caller) | |
303 | + | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
304 | + | if ((cleanUp == cleanUp)) | |
305 | + | then if ((size(i.payments) > 1)) | |
306 | + | then throw("Invalid createOrder parameters: invalid payment count") | |
307 | + | else { | |
308 | + | let $t01010010352 = if ((size(i.payments) == 1)) | |
309 | + | then $Tuple2(toBase58String(valueOrErrorMessage(i.payments[0].assetId, "Invalid asset id")), i.payments[0].amount) | |
310 | + | else $Tuple2("", 0) | |
311 | + | let paymentAssetId = $t01010010352._1 | |
312 | + | let paymentAmount = $t01010010352._2 | |
313 | + | let doCall = invoke(this, "internalCreateOrder", [_trader, _amm, _type, _triggerPrice, _limitPrice, _amountIn, _leverage, _side, _refLink, paymentAssetId, paymentAmount], nil) | |
314 | + | if ((doCall == doCall)) | |
315 | + | then nil | |
316 | + | else throw("Strict value is not equal to itself.") | |
317 | + | } | |
318 | + | else throw("Strict value is not equal to itself.") | |
319 | + | } | |
241 | 320 | ||
242 | 321 | ||
243 | 322 | ||
244 | 323 | @Callable(i) | |
245 | 324 | func increasePositionWithStopLoss (_amm,_direction,_leverage,_minBaseAssetAmount,_refLink,_stopTriggerPrice,_stopLimitPrice,_takeTriggerPrice,_takeLimitPrice) = { | |
246 | 325 | let _trader = toString(i.caller) | |
247 | - | if (if (!(initialized())) | |
248 | - | then true | |
249 | - | else !(isWhitelist(_amm))) | |
250 | - | then throw("Invalid increasePositionWithStopLoss parameters") | |
251 | - | else { | |
252 | - | let positionSize = getPositionSize(_amm, _trader) | |
253 | - | if ((positionSize != 0)) | |
254 | - | then throw("Invalid increasePositionWithStopLoss parameters: only new position") | |
255 | - | else { | |
256 | - | let doSetContext = invoke(this, "setContext", [_trader], nil) | |
257 | - | if ((doSetContext == doSetContext)) | |
258 | - | then { | |
259 | - | let doClosePosition = invoke(addressFromStringValue(_amm), "increasePosition", [_direction, _leverage, _minBaseAssetAmount, _refLink], i.payments) | |
260 | - | if ((doClosePosition == doClosePosition)) | |
261 | - | then { | |
262 | - | let doResetContext = invoke(this, "resetContext", nil, nil) | |
263 | - | if ((doResetContext == doResetContext)) | |
264 | - | then { | |
265 | - | let openedPositionSize = getPositionSize(_amm, _trader) | |
266 | - | if ((openedPositionSize == openedPositionSize)) | |
267 | - | then { | |
268 | - | let amountIn = abs(openedPositionSize) | |
269 | - | let stopLossSide = if ((0 > openedPositionSize)) | |
270 | - | then LONG | |
271 | - | else SHORT | |
272 | - | let doCreateStopOrder = if ((_stopTriggerPrice > 0)) | |
273 | - | then { | |
274 | - | let doCreateStopOrder = invoke(this, "internalCreateOrder", [_trader, _amm, STOP, _stopTriggerPrice, _stopLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0], nil) | |
275 | - | if ((doCreateStopOrder == doCreateStopOrder)) | |
276 | - | then nil | |
277 | - | else throw("Strict value is not equal to itself.") | |
278 | - | } | |
279 | - | else nil | |
280 | - | if ((doCreateStopOrder == doCreateStopOrder)) | |
281 | - | then { | |
282 | - | let doCreateTakeOrder = if ((_takeTriggerPrice > 0)) | |
283 | - | then { | |
284 | - | let doCreateTakeOrder = invoke(this, "internalCreateOrder", [_trader, _amm, TAKE, _takeTriggerPrice, _takeLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0], nil) | |
285 | - | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
286 | - | then nil | |
287 | - | else throw("Strict value is not equal to itself.") | |
288 | - | } | |
289 | - | else nil | |
290 | - | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
291 | - | then nil | |
292 | - | else throw("Strict value is not equal to itself.") | |
293 | - | } | |
294 | - | else throw("Strict value is not equal to itself.") | |
295 | - | } | |
296 | - | else throw("Strict value is not equal to itself.") | |
297 | - | } | |
298 | - | else throw("Strict value is not equal to itself.") | |
299 | - | } | |
300 | - | else throw("Strict value is not equal to itself.") | |
301 | - | } | |
302 | - | else throw("Strict value is not equal to itself.") | |
303 | - | } | |
304 | - | } | |
326 | + | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
327 | + | if ((cleanUp == cleanUp)) | |
328 | + | then if (if (!(initialized())) | |
329 | + | then true | |
330 | + | else !(isWhitelist(_amm))) | |
331 | + | then throw("Invalid increasePositionWithStopLoss parameters") | |
332 | + | else { | |
333 | + | let positionSize = getPositionSize(_amm, _trader) | |
334 | + | if ((positionSize != 0)) | |
335 | + | then throw("Invalid increasePositionWithStopLoss parameters: only new position") | |
336 | + | else { | |
337 | + | let doSetContext = invoke(this, "setContext", [_trader], nil) | |
338 | + | if ((doSetContext == doSetContext)) | |
339 | + | then { | |
340 | + | let doClosePosition = invoke(addressFromStringValue(_amm), "increasePosition", [_direction, _leverage, _minBaseAssetAmount, _refLink], i.payments) | |
341 | + | if ((doClosePosition == doClosePosition)) | |
342 | + | then { | |
343 | + | let doResetContext = invoke(this, "resetContext", nil, nil) | |
344 | + | if ((doResetContext == doResetContext)) | |
345 | + | then { | |
346 | + | let openedPositionSize = getPositionSize(_amm, _trader) | |
347 | + | if ((openedPositionSize == openedPositionSize)) | |
348 | + | then { | |
349 | + | let amountIn = abs(openedPositionSize) | |
350 | + | let stopLossSide = if ((0 > openedPositionSize)) | |
351 | + | then LONG | |
352 | + | else SHORT | |
353 | + | let doCreateStopOrder = if ((_stopTriggerPrice > 0)) | |
354 | + | then { | |
355 | + | let doCreateStopOrder = invoke(this, "internalCreateOrder", [_trader, _amm, STOP, _stopTriggerPrice, _stopLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0], nil) | |
356 | + | if ((doCreateStopOrder == doCreateStopOrder)) | |
357 | + | then nil | |
358 | + | else throw("Strict value is not equal to itself.") | |
359 | + | } | |
360 | + | else nil | |
361 | + | if ((doCreateStopOrder == doCreateStopOrder)) | |
362 | + | then { | |
363 | + | let doCreateTakeOrder = if ((_takeTriggerPrice > 0)) | |
364 | + | then { | |
365 | + | let doCreateTakeOrder = invoke(this, "internalCreateOrder", [_trader, _amm, TAKE, _takeTriggerPrice, _takeLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0], nil) | |
366 | + | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
367 | + | then nil | |
368 | + | else throw("Strict value is not equal to itself.") | |
369 | + | } | |
370 | + | else nil | |
371 | + | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
372 | + | then nil | |
373 | + | else throw("Strict value is not equal to itself.") | |
374 | + | } | |
375 | + | else throw("Strict value is not equal to itself.") | |
376 | + | } | |
377 | + | else throw("Strict value is not equal to itself.") | |
378 | + | } | |
379 | + | else throw("Strict value is not equal to itself.") | |
380 | + | } | |
381 | + | else throw("Strict value is not equal to itself.") | |
382 | + | } | |
383 | + | else throw("Strict value is not equal to itself.") | |
384 | + | } | |
385 | + | } | |
386 | + | else throw("Strict value is not equal to itself.") | |
305 | 387 | } | |
306 | 388 | ||
307 | 389 | ||
372 | 454 | else 0 | |
373 | 455 | if ((newTraderOrderCount > MAX_TRADER_ORDERS_PER_AMM)) | |
374 | 456 | then throw("Invalid createLimitOrder parameters: order count") | |
375 | - | else ((saveOrder(orderId, _amm, _trader, _amountIn, _leverage, _type, _triggerPrice, usdnPayment, _side, _refLink, positionId, _limitPrice) ++ updateTraderOrderCount(_amm, _trader, newTraderOrderCount)) ++ updateLastOrderId(orderId)) | |
457 | + | else (((saveOrder(orderId, _amm, _trader, _amountIn, _leverage, _type, _triggerPrice, usdnPayment, _side, _refLink, positionId, _limitPrice) ++ addRemoveOrderId(orderId, _amm, _trader, true)) ++ updateTraderOrderCount(_amm, _trader, newTraderOrderCount)) ++ updateLastOrderId(orderId)) | |
376 | 458 | } | |
377 | 459 | else throw("Strict value is not equal to itself.") | |
378 | 460 | } | |
382 | 464 | ||
383 | 465 | @Callable(i) | |
384 | 466 | func cancelOrder (_orderId) = { | |
385 | - | let $ | |
386 | - | let _amm = $ | |
387 | - | let _trader = $ | |
388 | - | let _amountIn = $ | |
389 | - | let _leverage = $ | |
390 | - | let _type = $ | |
391 | - | let _triggerPrice = $ | |
392 | - | let _amountUsdn = $ | |
393 | - | let _side = $ | |
394 | - | let _refLink = $ | |
395 | - | let _positionId = $ | |
396 | - | let _limitPrice = $ | |
467 | + | let $t01572115940 = getOrder(_orderId) | |
468 | + | let _amm = $t01572115940._1 | |
469 | + | let _trader = $t01572115940._2 | |
470 | + | let _amountIn = $t01572115940._3 | |
471 | + | let _leverage = $t01572115940._4 | |
472 | + | let _type = $t01572115940._5 | |
473 | + | let _triggerPrice = $t01572115940._6 | |
474 | + | let _amountUsdn = $t01572115940._7 | |
475 | + | let _side = $t01572115940._8 | |
476 | + | let _refLink = $t01572115940._9 | |
477 | + | let _positionId = $t01572115940._10 | |
478 | + | let _limitPrice = $t01572115940._11 | |
397 | 479 | if (if (if (!(initialized())) | |
398 | 480 | then true | |
399 | 481 | else !(isValid(_orderId))) | |
401 | 483 | else !((toString(i.caller) == _trader))) | |
402 | 484 | then throw("Invalid cancelOrder parameters") | |
403 | 485 | else { | |
404 | - | let | |
405 | - | | |
486 | + | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
487 | + | if ((cleanUp == cleanUp)) | |
406 | 488 | then { | |
407 | - | let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), _amountUsdn], nil) | |
408 | - | if ((unstake == unstake)) | |
409 | - | then nil | |
489 | + | let newTraderOrderCount = (getTraderOrderCount(_amm, _trader) - 1) | |
490 | + | let withdraw = if ((_amountUsdn > 0)) | |
491 | + | then { | |
492 | + | let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), _amountUsdn], nil) | |
493 | + | if ((unstake == unstake)) | |
494 | + | then nil | |
495 | + | else throw("Strict value is not equal to itself.") | |
496 | + | } | |
497 | + | else nil | |
498 | + | if ((withdraw == withdraw)) | |
499 | + | then (((markCancelOrder(_orderId) ++ addRemoveOrderId(_orderId, _amm, _trader, false)) ++ updateTraderOrderCount(_amm, _trader, newTraderOrderCount)) ++ (if ((_amountUsdn > 0)) | |
500 | + | then [ScriptTransfer(i.caller, _amountUsdn, quoteAsset())] | |
501 | + | else nil)) | |
410 | 502 | else throw("Strict value is not equal to itself.") | |
411 | 503 | } | |
412 | - | else nil | |
413 | - | if ((withdraw == withdraw)) | |
414 | - | then ((markCancelOrder(_orderId) ++ updateTraderOrderCount(_amm, _trader, newTraderOrderCount)) ++ (if ((_amountUsdn > 0)) | |
415 | - | then [ScriptTransfer(i.caller, _amountUsdn, quoteAsset())] | |
416 | - | else nil)) | |
417 | 504 | else throw("Strict value is not equal to itself.") | |
418 | 505 | } | |
419 | 506 | } | |
422 | 509 | ||
423 | 510 | @Callable(i) | |
424 | 511 | func executeOrder (_orderId) = { | |
425 | - | let $t01456014779 = getOrder(_orderId) | |
426 | - | let _amm = $t01456014779._1 | |
427 | - | let _trader = $t01456014779._2 | |
428 | - | let _amountIn = $t01456014779._3 | |
429 | - | let _leverage = $t01456014779._4 | |
430 | - | let _type = $t01456014779._5 | |
431 | - | let _triggerPrice = $t01456014779._6 | |
432 | - | let _amountUsdn = $t01456014779._7 | |
433 | - | let _side = $t01456014779._8 | |
434 | - | let _refLink = $t01456014779._9 | |
435 | - | let _positionId = $t01456014779._10 | |
436 | - | let _limitPrice = $t01456014779._11 | |
437 | - | if (if (!(initialized())) | |
438 | - | then true | |
439 | - | else !(isValid(_orderId))) | |
440 | - | then throw("Invalid executeOrder parameters") | |
441 | - | else { | |
442 | - | let positionSize = getPositionSize(_amm, _trader) | |
443 | - | let currentPositionId = if ((positionSize != 0)) | |
444 | - | then getPositionId(_amm, _trader) | |
445 | - | else 0 | |
446 | - | let $t01510518926 = if ((_type == STOP)) | |
447 | - | then { | |
448 | - | let _positionDirection = if ((positionSize > 0)) | |
449 | - | then LONG | |
450 | - | else if ((0 > positionSize)) | |
451 | - | then SHORT | |
452 | - | else throw("Can not execute STOP order: no open position") | |
453 | - | let marketPrice = getMarketPrice(_amm) | |
454 | - | let isExecutable = if ((_side == _positionDirection)) | |
455 | - | then throw("Can not execute STOP order: reduce only") | |
456 | - | else if ((currentPositionId != _positionId)) | |
457 | - | then throw("Can not execute STOP order: position closed") | |
458 | - | else if ((_positionDirection == LONG)) | |
459 | - | then (_triggerPrice >= marketPrice) | |
460 | - | else (marketPrice >= _triggerPrice) | |
461 | - | if (isExecutable) | |
462 | - | then $Tuple3("closePosition", [minv(_amountIn, abs(positionSize)), muld(_limitPrice, abs(positionSize))], nil) | |
463 | - | else throw("Can not execute STOP order: triggerPrice mismatch") | |
464 | - | } | |
465 | - | else if ((_type == TAKE)) | |
512 | + | let $t01691117130 = getOrder(_orderId) | |
513 | + | let _amm = $t01691117130._1 | |
514 | + | let _trader = $t01691117130._2 | |
515 | + | let _amountIn = $t01691117130._3 | |
516 | + | let _leverage = $t01691117130._4 | |
517 | + | let _type = $t01691117130._5 | |
518 | + | let _triggerPrice = $t01691117130._6 | |
519 | + | let _amountUsdn = $t01691117130._7 | |
520 | + | let _side = $t01691117130._8 | |
521 | + | let _refLink = $t01691117130._9 | |
522 | + | let _positionId = $t01691117130._10 | |
523 | + | let _limitPrice = $t01691117130._11 | |
524 | + | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
525 | + | if ((cleanUp == cleanUp)) | |
526 | + | then if (if (!(initialized())) | |
527 | + | then true | |
528 | + | else !(isValid(_orderId))) | |
529 | + | then throw("Invalid executeOrder parameters") | |
530 | + | else { | |
531 | + | let positionSize = getPositionSize(_amm, _trader) | |
532 | + | let currentPositionId = if ((positionSize != 0)) | |
533 | + | then getPositionId(_amm, _trader) | |
534 | + | else 0 | |
535 | + | let $t01753821359 = if ((_type == STOP)) | |
466 | 536 | then { | |
467 | 537 | let _positionDirection = if ((positionSize > 0)) | |
468 | 538 | then LONG | |
471 | 541 | else throw("Can not execute STOP order: no open position") | |
472 | 542 | let marketPrice = getMarketPrice(_amm) | |
473 | 543 | let isExecutable = if ((_side == _positionDirection)) | |
474 | - | then throw("Can not execute | |
544 | + | then throw("Can not execute STOP order: reduce only") | |
475 | 545 | else if ((currentPositionId != _positionId)) | |
476 | - | then throw( | |
546 | + | then throw("Can not execute STOP order: position closed") | |
477 | 547 | else if ((_positionDirection == LONG)) | |
478 | - | then ( | |
479 | - | else ( | |
548 | + | then (_triggerPrice >= marketPrice) | |
549 | + | else (marketPrice >= _triggerPrice) | |
480 | 550 | if (isExecutable) | |
481 | 551 | then $Tuple3("closePosition", [minv(_amountIn, abs(positionSize)), muld(_limitPrice, abs(positionSize))], nil) | |
482 | - | else throw("Can not execute | |
552 | + | else throw("Can not execute STOP order: triggerPrice mismatch") | |
483 | 553 | } | |
484 | - | else if ((_type == | |
554 | + | else if ((_type == TAKE)) | |
485 | 555 | then { | |
556 | + | let _positionDirection = if ((positionSize > 0)) | |
557 | + | then LONG | |
558 | + | else if ((0 > positionSize)) | |
559 | + | then SHORT | |
560 | + | else throw("Can not execute STOP order: no open position") | |
486 | 561 | let marketPrice = getMarketPrice(_amm) | |
487 | - | let spread = if ((_limitPrice == 0)) | |
488 | - | then getSpread(_triggerPrice) | |
489 | - | else abs((_triggerPrice - _limitPrice)) | |
490 | - | let isExecutable = if ((marketPrice >= (_triggerPrice - spread))) | |
491 | - | then ((_triggerPrice + spread) >= marketPrice) | |
492 | - | else false | |
562 | + | let isExecutable = if ((_side == _positionDirection)) | |
563 | + | then throw("Can not execute TAKE order: reduce only") | |
564 | + | else if ((currentPositionId != _positionId)) | |
565 | + | then throw(((("Can not execute TAKE order: position closed " + toString(currentPositionId)) + "!=") + toString(_positionId))) | |
566 | + | else if ((_positionDirection == LONG)) | |
567 | + | then (marketPrice >= _triggerPrice) | |
568 | + | else (_triggerPrice >= marketPrice) | |
493 | 569 | if (isExecutable) | |
494 | - | then { | |
495 | - | let _positionDirection = if ((positionSize > 0)) | |
496 | - | then LONG | |
497 | - | else if ((0 > positionSize)) | |
498 | - | then SHORT | |
499 | - | else -1 | |
500 | - | let direction = if ((positionSize == 0)) | |
501 | - | then INCREASE | |
502 | - | else if ((_positionDirection == _side)) | |
570 | + | then $Tuple3("closePosition", [minv(_amountIn, abs(positionSize)), muld(_limitPrice, abs(positionSize))], nil) | |
571 | + | else throw("Can not execute TAKE order: triggerPrice mismatch") | |
572 | + | } | |
573 | + | else if ((_type == LIMIT)) | |
574 | + | then { | |
575 | + | let marketPrice = getMarketPrice(_amm) | |
576 | + | let spread = if ((_limitPrice == 0)) | |
577 | + | then getSpread(_triggerPrice) | |
578 | + | else abs((_triggerPrice - _limitPrice)) | |
579 | + | let isExecutable = if ((marketPrice >= (_triggerPrice - spread))) | |
580 | + | then ((_triggerPrice + spread) >= marketPrice) | |
581 | + | else false | |
582 | + | if (isExecutable) | |
583 | + | then { | |
584 | + | let _positionDirection = if ((positionSize > 0)) | |
585 | + | then LONG | |
586 | + | else if ((0 > positionSize)) | |
587 | + | then SHORT | |
588 | + | else -1 | |
589 | + | let direction = if ((positionSize == 0)) | |
503 | 590 | then INCREASE | |
504 | - | else DECREASE | |
505 | - | if ((direction == INCREASE)) | |
506 | - | then { | |
507 | - | let amountInWithFee = (_amountUsdn - muld(_amountUsdn, getFee(_amm, _trader))) | |
508 | - | $Tuple3("increasePosition", [_side, _leverage, if ((_limitPrice == 0)) | |
509 | - | then 0 | |
510 | - | else divd(amountInWithFee, _limitPrice), _refLink], [AttachedPayment(quoteAsset(), _amountUsdn)]) | |
511 | - | } | |
512 | - | else $Tuple3("closePosition", [_amountIn, muld(_amountIn, _limitPrice)], nil) | |
513 | - | } | |
514 | - | else throw("Can not execute LIMIT order: triggerPrice mismatch") | |
515 | - | } | |
516 | - | else throw(("Invalid order type: " + toString(_type))) | |
517 | - | let method = $t01510518926._1 | |
518 | - | let args = $t01510518926._2 | |
519 | - | let payments = $t01510518926._3 | |
520 | - | let withdraw = if ((size(payments) == 1)) | |
521 | - | then { | |
522 | - | let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), payments[0].amount], nil) | |
523 | - | if ((unstake == unstake)) | |
524 | - | then nil | |
525 | - | else throw("Strict value is not equal to itself.") | |
526 | - | } | |
527 | - | else nil | |
528 | - | if ((withdraw == withdraw)) | |
529 | - | then { | |
530 | - | let doSetContext = invoke(this, "setContext", [_trader], nil) | |
531 | - | if ((doSetContext == doSetContext)) | |
532 | - | then { | |
533 | - | let doClosePosition = invoke(addressFromStringValue(_amm), method, args, payments) | |
534 | - | if ((doClosePosition == doClosePosition)) | |
535 | - | then { | |
536 | - | let doResetContext = invoke(this, "resetContext", nil, nil) | |
537 | - | if ((doResetContext == doResetContext)) | |
538 | - | then markExecuteOrder(_orderId) | |
539 | - | else throw("Strict value is not equal to itself.") | |
540 | - | } | |
541 | - | else throw("Strict value is not equal to itself.") | |
542 | - | } | |
543 | - | else throw("Strict value is not equal to itself.") | |
544 | - | } | |
545 | - | else throw("Strict value is not equal to itself.") | |
546 | - | } | |
591 | + | else if ((_positionDirection == _side)) | |
592 | + | then INCREASE | |
593 | + | else DECREASE | |
594 | + | if ((direction == INCREASE)) | |
595 | + | then { | |
596 | + | let amountInWithFee = (_amountUsdn - muld(_amountUsdn, getFee(_amm, _trader))) | |
597 | + | $Tuple3("increasePosition", [_side, _leverage, if ((_limitPrice == 0)) | |
598 | + | then 0 | |
599 | + | else divd(amountInWithFee, _limitPrice), _refLink], [AttachedPayment(quoteAsset(), _amountUsdn)]) | |
600 | + | } | |
601 | + | else $Tuple3("closePosition", [_amountIn, muld(_amountIn, _limitPrice)], nil) | |
602 | + | } | |
603 | + | else throw("Can not execute LIMIT order: triggerPrice mismatch") | |
604 | + | } | |
605 | + | else throw(("Invalid order type: " + toString(_type))) | |
606 | + | let method = $t01753821359._1 | |
607 | + | let args = $t01753821359._2 | |
608 | + | let payments = $t01753821359._3 | |
609 | + | let withdraw = if ((size(payments) == 1)) | |
610 | + | then { | |
611 | + | let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), payments[0].amount], nil) | |
612 | + | if ((unstake == unstake)) | |
613 | + | then nil | |
614 | + | else throw("Strict value is not equal to itself.") | |
615 | + | } | |
616 | + | else nil | |
617 | + | if ((withdraw == withdraw)) | |
618 | + | then { | |
619 | + | let doSetContext = invoke(this, "setContext", [_trader], nil) | |
620 | + | if ((doSetContext == doSetContext)) | |
621 | + | then { | |
622 | + | let doClosePosition = invoke(addressFromStringValue(_amm), method, args, payments) | |
623 | + | if ((doClosePosition == doClosePosition)) | |
624 | + | then { | |
625 | + | let doResetContext = invoke(this, "resetContext", nil, nil) | |
626 | + | if ((doResetContext == doResetContext)) | |
627 | + | then { | |
628 | + | let newTraderOrderCount = (getTraderOrderCount(_amm, _trader) - 1) | |
629 | + | ((updateTraderOrderCount(_amm, _trader, newTraderOrderCount) ++ addRemoveOrderId(_orderId, _amm, _trader, false)) ++ markExecuteOrder(_orderId)) | |
630 | + | } | |
631 | + | else throw("Strict value is not equal to itself.") | |
632 | + | } | |
633 | + | else throw("Strict value is not equal to itself.") | |
634 | + | } | |
635 | + | else throw("Strict value is not equal to itself.") | |
636 | + | } | |
637 | + | else throw("Strict value is not equal to itself.") | |
638 | + | } | |
639 | + | else throw("Strict value is not equal to itself.") | |
547 | 640 | } | |
548 | 641 | ||
549 | 642 |
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_public_key = "k_admin_public_key" | |
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_fee = "k_fee" | |
19 | 19 | ||
20 | 20 | let k_executedOrders = "k_executedOrders" | |
21 | 21 | ||
22 | 22 | let k_canceledOrders = "k_canceledOrders" | |
23 | 23 | ||
24 | 24 | let k_order = "k_order" | |
25 | 25 | ||
26 | 26 | let k_lastOrderId = "k_lastOrderId" | |
27 | 27 | ||
28 | 28 | let k_traderOrderCnt = "k_traderOrderCnt" | |
29 | + | ||
30 | + | let k_traderOrderIds = "k_traderOrderIds" | |
29 | 31 | ||
30 | 32 | let k_sender = "k_sender" | |
31 | 33 | ||
32 | 34 | let k_initialized = "k_initialized" | |
33 | 35 | ||
34 | 36 | let STOP = 1 | |
35 | 37 | ||
36 | 38 | let TAKE = 2 | |
37 | 39 | ||
38 | 40 | let LIMIT = 3 | |
39 | 41 | ||
40 | 42 | let LONG = 1 | |
41 | 43 | ||
42 | 44 | let SHORT = 2 | |
43 | 45 | ||
44 | 46 | let INCREASE = 1 | |
45 | 47 | ||
46 | 48 | let DECREASE = 2 | |
47 | 49 | ||
48 | 50 | let MAX_TRADER_ORDERS_PER_AMM = 5 | |
49 | 51 | ||
50 | 52 | let TIME = lastBlock.timestamp | |
51 | 53 | ||
52 | 54 | let DECIMAL_UNIT = (1 * (((((10 * 10) * 10) * 10) * 10) * 10)) | |
53 | 55 | ||
54 | 56 | let SPREAD_LIMIT = (DECIMAL_UNIT / 200) | |
55 | 57 | ||
56 | 58 | func abs (_x) = if ((_x > 0)) | |
57 | 59 | then _x | |
58 | 60 | else -(_x) | |
59 | 61 | ||
60 | 62 | ||
61 | 63 | func divd (_x,_y) = fraction(_x, DECIMAL_UNIT, _y, HALFEVEN) | |
62 | 64 | ||
63 | 65 | ||
64 | 66 | func muld (_x,_y) = fraction(_x, _y, DECIMAL_UNIT, HALFEVEN) | |
65 | 67 | ||
66 | 68 | ||
67 | 69 | func minv (_x,_y) = if ((_x > _y)) | |
68 | 70 | then _y | |
69 | 71 | else _x | |
70 | 72 | ||
71 | 73 | ||
72 | 74 | func toCompositeKey (_key,_address) = ((_key + "_") + _address) | |
73 | 75 | ||
74 | 76 | ||
75 | 77 | func executedOrderKey (_orderId) = ((k_executedOrders + "_") + toString(_orderId)) | |
76 | 78 | ||
77 | 79 | ||
78 | 80 | func canceledOrderKey (_orderId) = ((k_canceledOrders + "_") + toString(_orderId)) | |
79 | 81 | ||
80 | 82 | ||
81 | 83 | func orderKey (_orderId) = toCompositeKey(k_order, toString(_orderId)) | |
82 | 84 | ||
83 | 85 | ||
84 | 86 | func traderOrderCountKey (_amm,_trader) = ((((k_traderOrderCnt + "_") + _amm) + "_") + _trader) | |
85 | 87 | ||
86 | 88 | ||
89 | + | func traderOrderIdsKey (_amm,_trader) = ((((k_traderOrderIds + "_") + _amm) + "_") + _trader) | |
90 | + | ||
91 | + | ||
87 | 92 | func coordinator () = valueOrErrorMessage(addressFromString(getStringValue(this, k_coordinatorAddress)), "Coordinator not set") | |
88 | 93 | ||
89 | 94 | ||
90 | 95 | func quoteAsset () = fromBase58String(getStringValue(coordinator(), k_quote_asset)) | |
91 | 96 | ||
92 | 97 | ||
93 | 98 | func managerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_manager_address)), "Manager not set") | |
94 | 99 | ||
95 | 100 | ||
96 | 101 | func isWhitelist (_address) = valueOrElse(getBoolean(coordinator(), toCompositeKey(k_amm, _address)), false) | |
97 | 102 | ||
98 | 103 | ||
99 | 104 | func adminPublicKey () = fromBase58String(getStringValue(coordinator(), k_admin_public_key)) | |
100 | 105 | ||
101 | 106 | ||
102 | 107 | func initialized () = valueOrElse(getBoolean(this, k_initialized), false) | |
103 | 108 | ||
104 | 109 | ||
105 | 110 | func isValid (_orderId) = if (valueOrElse(getBoolean(this, executedOrderKey(_orderId)), false)) | |
106 | 111 | then throw(("Order already executed: " + toString(_orderId))) | |
107 | 112 | else if (valueOrElse(getBoolean(this, canceledOrderKey(_orderId)), false)) | |
108 | 113 | then throw(("Order already cancelled: " + toString(_orderId))) | |
109 | 114 | else true | |
110 | 115 | ||
111 | 116 | ||
112 | 117 | func currentOrderId () = valueOrElse(getInteger(this, k_lastOrderId), 0) | |
113 | 118 | ||
114 | 119 | ||
115 | 120 | func getTraderOrderCount (_amm,_trader) = { | |
116 | 121 | let key = traderOrderCountKey(_amm, _trader) | |
117 | 122 | valueOrElse(getInteger(this, key), 0) | |
123 | + | } | |
124 | + | ||
125 | + | ||
126 | + | func traderAmmOrdersIds (_amm,_trader) = { | |
127 | + | let key = traderOrderIdsKey(_amm, _trader) | |
128 | + | let val = valueOrElse(getString(this, key), "") | |
129 | + | if ((val == "")) | |
130 | + | then nil | |
131 | + | else split(val, ",") | |
118 | 132 | } | |
119 | 133 | ||
120 | 134 | ||
121 | 135 | func getOrder (_orderId) = { | |
122 | 136 | let orderStr = valueOrErrorMessage(getString(this, orderKey(_orderId)), ("Invalid order id: " + toString(_orderId))) | |
123 | 137 | let orderPartList = split(orderStr, ",") | |
124 | 138 | let amm = orderPartList[0] | |
125 | 139 | let trader = orderPartList[1] | |
126 | 140 | let amountIn = valueOrErrorMessage(parseInt(orderPartList[2]), "Invalid amountIn") | |
127 | 141 | let leverage = valueOrErrorMessage(parseInt(orderPartList[3]), "Invalid leverage") | |
128 | 142 | let type = valueOrErrorMessage(parseInt(orderPartList[4]), "Invalid type") | |
129 | 143 | let triggerPrice = valueOrErrorMessage(parseInt(orderPartList[5]), "Invalid triggerPrice") | |
130 | 144 | let paymentUsdn = valueOrErrorMessage(parseInt(orderPartList[6]), "Invalid paymentUsdn") | |
131 | 145 | let side = valueOrErrorMessage(parseInt(orderPartList[7]), "Invalid side") | |
132 | 146 | let refLink = orderPartList[8] | |
133 | 147 | let positionId = valueOrErrorMessage(parseInt(orderPartList[9]), "Invalid positionId") | |
134 | 148 | let limitPrice = valueOrErrorMessage(parseInt(orderPartList[10]), "Invalid limitPrice") | |
135 | 149 | $Tuple11(amm, trader, amountIn, leverage, type, triggerPrice, paymentUsdn, side, refLink, positionId, limitPrice) | |
136 | 150 | } | |
137 | 151 | ||
138 | 152 | ||
139 | 153 | func getMarketPrice (_amm) = { | |
140 | 154 | let s = invoke(addressFromStringValue(_amm), "computeSpotPrice", nil, nil) | |
141 | 155 | if ((s == s)) | |
142 | 156 | then { | |
143 | 157 | let res = match s { | |
144 | 158 | case t: Int => | |
145 | 159 | t | |
146 | 160 | case _ => | |
147 | 161 | throw("Invalid computeSpotPrice result") | |
148 | 162 | } | |
149 | 163 | value(res) | |
150 | 164 | } | |
151 | 165 | else throw("Strict value is not equal to itself.") | |
152 | 166 | } | |
153 | 167 | ||
154 | 168 | ||
155 | 169 | func getFee (_amm,_trader) = { | |
156 | 170 | let s = invoke(addressFromStringValue(_amm), "computeFeeForTraderWithArtifact", [_trader, ""], nil) | |
157 | 171 | if ((s == s)) | |
158 | 172 | then { | |
159 | 173 | let res = match s { | |
160 | 174 | case t: (Int, Boolean) => | |
161 | 175 | t._1 | |
162 | 176 | case _ => | |
163 | 177 | throw("Invalid computeFeeForTraderWithArtifact result") | |
164 | 178 | } | |
165 | 179 | value(res) | |
166 | 180 | } | |
167 | 181 | else throw("Strict value is not equal to itself.") | |
168 | 182 | } | |
169 | 183 | ||
170 | 184 | ||
171 | 185 | func getPositionSize (_amm,_trader) = { | |
172 | 186 | let amm = addressFromStringValue(_amm) | |
173 | 187 | let sizeKey = toCompositeKey(k_positionSize, _trader) | |
174 | 188 | valueOrElse(getInteger(amm, sizeKey), 0) | |
175 | 189 | } | |
176 | 190 | ||
177 | 191 | ||
178 | 192 | func getPositionId (_amm,_trader) = { | |
179 | 193 | let amm = addressFromStringValue(_amm) | |
180 | 194 | let seqKey = toCompositeKey(k_positionSequence, _trader) | |
181 | 195 | valueOrElse(getInteger(amm, seqKey), 0) | |
182 | 196 | } | |
183 | 197 | ||
184 | 198 | ||
185 | 199 | func getSpread (_price) = muld(_price, SPREAD_LIMIT) | |
186 | 200 | ||
187 | 201 | ||
188 | 202 | func saveOrder (_orderId,_amm,_trader,_amountIn,_leverage,_type,_triggerPrice,_paymentUsdn,_side,_refLink,_positionId,_limitPrice) = { | |
189 | 203 | let orderStr = makeString([_amm, _trader, toString(_amountIn), toString(_leverage), toString(_type), toString(_triggerPrice), toString(_paymentUsdn), toString(_side), _refLink, toString(_positionId), toString(_limitPrice)], ",") | |
190 | 204 | [StringEntry(orderKey(_orderId), orderStr)] | |
191 | 205 | } | |
192 | 206 | ||
193 | 207 | ||
208 | + | func addRemoveOrderId (_orderId,_amm,_trader,_add) = { | |
209 | + | let orderIds = traderAmmOrdersIds(_amm, _trader) | |
210 | + | let orderIdsNew = if (_add) | |
211 | + | then (orderIds :+ toString(_orderId)) | |
212 | + | else removeByIndex(orderIds, valueOrErrorMessage(indexOf(orderIds, toString(_orderId)), ("No order with id: " + toString(_orderId)))) | |
213 | + | let orderIdsNewStr = makeString(orderIdsNew, ",") | |
214 | + | [StringEntry(traderOrderIdsKey(_amm, _trader), orderIdsNewStr)] | |
215 | + | } | |
216 | + | ||
217 | + | ||
194 | 218 | func updateTraderOrderCount (_amm,_trader,_count) = [IntegerEntry(traderOrderCountKey(_amm, _trader), _count)] | |
195 | 219 | ||
196 | 220 | ||
197 | 221 | func updateLastOrderId (_lastOrderId) = [IntegerEntry(k_lastOrderId, _lastOrderId)] | |
198 | 222 | ||
199 | 223 | ||
200 | 224 | func markExecuteOrder (_orderId) = [BooleanEntry(toCompositeKey(k_executedOrders, toString(_orderId)), true)] | |
201 | 225 | ||
202 | 226 | ||
203 | 227 | func markCancelOrder (_orderId) = [BooleanEntry(toCompositeKey(k_canceledOrders, toString(_orderId)), true)] | |
228 | + | ||
229 | + | ||
230 | + | @Callable(i) | |
231 | + | func cleanUpStaleOrders (_amm,_trader) = { | |
232 | + | let orders = traderAmmOrdersIds(_amm, _trader) | |
233 | + | func cleanUpOne (_acc,_orderId) = { | |
234 | + | let orderIdInt = valueOrErrorMessage(parseInt(_orderId), "Invalid order id") | |
235 | + | let $t083208515 = getOrder(orderIdInt) | |
236 | + | let _x1 = $t083208515._1 | |
237 | + | let _x2 = $t083208515._2 | |
238 | + | let _x3 = $t083208515._3 | |
239 | + | let _x4 = $t083208515._4 | |
240 | + | let _type = $t083208515._5 | |
241 | + | let _x5 = $t083208515._6 | |
242 | + | let _x6 = $t083208515._7 | |
243 | + | let _x7 = $t083208515._8 | |
244 | + | let _x8 = $t083208515._9 | |
245 | + | let _positionId = $t083208515._10 | |
246 | + | let _x9 = $t083208515._11 | |
247 | + | let positionSize = getPositionSize(_amm, _trader) | |
248 | + | let currentPositionId = if ((positionSize != 0)) | |
249 | + | then getPositionId(_amm, _trader) | |
250 | + | else 0 | |
251 | + | if (if (if ((_type == STOP)) | |
252 | + | then true | |
253 | + | else (_type == TAKE)) | |
254 | + | then (currentPositionId != _positionId) | |
255 | + | else false) | |
256 | + | then { | |
257 | + | let change = (markCancelOrder(orderIdInt) ++ addRemoveOrderId(orderIdInt, _amm, _trader, false)) | |
258 | + | (_acc ++ change) | |
259 | + | } | |
260 | + | else _acc | |
261 | + | } | |
262 | + | ||
263 | + | let $l = orders | |
264 | + | let $s = size($l) | |
265 | + | let $acc0 = nil | |
266 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
267 | + | then $a | |
268 | + | else cleanUpOne($a, $l[$i]) | |
269 | + | ||
270 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
271 | + | then $a | |
272 | + | else throw("List size exceeds 5") | |
273 | + | ||
274 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5) | |
275 | + | } | |
276 | + | ||
204 | 277 | ||
205 | 278 | ||
206 | 279 | @Callable(i) | |
207 | 280 | func setContext (_sender) = if ((i.caller != this)) | |
208 | 281 | then throw("Only self-call") | |
209 | 282 | else [StringEntry(k_sender, _sender)] | |
210 | 283 | ||
211 | 284 | ||
212 | 285 | ||
213 | 286 | @Callable(i) | |
214 | 287 | func resetContext () = if ((i.caller != this)) | |
215 | 288 | then throw("Only self-call") | |
216 | 289 | else [DeleteEntry(k_sender)] | |
217 | 290 | ||
218 | 291 | ||
219 | 292 | ||
220 | 293 | @Callable(i) | |
221 | 294 | func initialize (_coordinator) = if (initialized()) | |
222 | 295 | then throw("Already initialized") | |
223 | 296 | else [StringEntry(k_coordinatorAddress, _coordinator), BooleanEntry(k_initialized, true)] | |
224 | 297 | ||
225 | 298 | ||
226 | 299 | ||
227 | 300 | @Callable(i) | |
228 | - | func createOrder (_amm,_type,_triggerPrice,_limitPrice,_amountIn,_leverage,_side,_refLink) = if ((size(i.payments) > 1)) | |
229 | - | then throw("Invalid createOrder parameters: invalid payment count") | |
230 | - | else { | |
231 | - | let $t080238275 = if ((size(i.payments) == 1)) | |
232 | - | then $Tuple2(toBase58String(valueOrErrorMessage(i.payments[0].assetId, "Invalid asset id")), i.payments[0].amount) | |
233 | - | else $Tuple2("", 0) | |
234 | - | let paymentAssetId = $t080238275._1 | |
235 | - | let paymentAmount = $t080238275._2 | |
236 | - | let doCall = invoke(this, "internalCreateOrder", [toString(i.caller), _amm, _type, _triggerPrice, _limitPrice, _amountIn, _leverage, _side, _refLink, paymentAssetId, paymentAmount], nil) | |
237 | - | if ((doCall == doCall)) | |
238 | - | then nil | |
239 | - | else throw("Strict value is not equal to itself.") | |
240 | - | } | |
301 | + | func createOrder (_amm,_type,_triggerPrice,_limitPrice,_amountIn,_leverage,_side,_refLink) = { | |
302 | + | let _trader = toString(i.caller) | |
303 | + | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
304 | + | if ((cleanUp == cleanUp)) | |
305 | + | then if ((size(i.payments) > 1)) | |
306 | + | then throw("Invalid createOrder parameters: invalid payment count") | |
307 | + | else { | |
308 | + | let $t01010010352 = if ((size(i.payments) == 1)) | |
309 | + | then $Tuple2(toBase58String(valueOrErrorMessage(i.payments[0].assetId, "Invalid asset id")), i.payments[0].amount) | |
310 | + | else $Tuple2("", 0) | |
311 | + | let paymentAssetId = $t01010010352._1 | |
312 | + | let paymentAmount = $t01010010352._2 | |
313 | + | let doCall = invoke(this, "internalCreateOrder", [_trader, _amm, _type, _triggerPrice, _limitPrice, _amountIn, _leverage, _side, _refLink, paymentAssetId, paymentAmount], nil) | |
314 | + | if ((doCall == doCall)) | |
315 | + | then nil | |
316 | + | else throw("Strict value is not equal to itself.") | |
317 | + | } | |
318 | + | else throw("Strict value is not equal to itself.") | |
319 | + | } | |
241 | 320 | ||
242 | 321 | ||
243 | 322 | ||
244 | 323 | @Callable(i) | |
245 | 324 | func increasePositionWithStopLoss (_amm,_direction,_leverage,_minBaseAssetAmount,_refLink,_stopTriggerPrice,_stopLimitPrice,_takeTriggerPrice,_takeLimitPrice) = { | |
246 | 325 | let _trader = toString(i.caller) | |
247 | - | if (if (!(initialized())) | |
248 | - | then true | |
249 | - | else !(isWhitelist(_amm))) | |
250 | - | then throw("Invalid increasePositionWithStopLoss parameters") | |
251 | - | else { | |
252 | - | let positionSize = getPositionSize(_amm, _trader) | |
253 | - | if ((positionSize != 0)) | |
254 | - | then throw("Invalid increasePositionWithStopLoss parameters: only new position") | |
255 | - | else { | |
256 | - | let doSetContext = invoke(this, "setContext", [_trader], nil) | |
257 | - | if ((doSetContext == doSetContext)) | |
258 | - | then { | |
259 | - | let doClosePosition = invoke(addressFromStringValue(_amm), "increasePosition", [_direction, _leverage, _minBaseAssetAmount, _refLink], i.payments) | |
260 | - | if ((doClosePosition == doClosePosition)) | |
261 | - | then { | |
262 | - | let doResetContext = invoke(this, "resetContext", nil, nil) | |
263 | - | if ((doResetContext == doResetContext)) | |
264 | - | then { | |
265 | - | let openedPositionSize = getPositionSize(_amm, _trader) | |
266 | - | if ((openedPositionSize == openedPositionSize)) | |
267 | - | then { | |
268 | - | let amountIn = abs(openedPositionSize) | |
269 | - | let stopLossSide = if ((0 > openedPositionSize)) | |
270 | - | then LONG | |
271 | - | else SHORT | |
272 | - | let doCreateStopOrder = if ((_stopTriggerPrice > 0)) | |
273 | - | then { | |
274 | - | let doCreateStopOrder = invoke(this, "internalCreateOrder", [_trader, _amm, STOP, _stopTriggerPrice, _stopLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0], nil) | |
275 | - | if ((doCreateStopOrder == doCreateStopOrder)) | |
276 | - | then nil | |
277 | - | else throw("Strict value is not equal to itself.") | |
278 | - | } | |
279 | - | else nil | |
280 | - | if ((doCreateStopOrder == doCreateStopOrder)) | |
281 | - | then { | |
282 | - | let doCreateTakeOrder = if ((_takeTriggerPrice > 0)) | |
283 | - | then { | |
284 | - | let doCreateTakeOrder = invoke(this, "internalCreateOrder", [_trader, _amm, TAKE, _takeTriggerPrice, _takeLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0], nil) | |
285 | - | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
286 | - | then nil | |
287 | - | else throw("Strict value is not equal to itself.") | |
288 | - | } | |
289 | - | else nil | |
290 | - | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
291 | - | then nil | |
292 | - | else throw("Strict value is not equal to itself.") | |
293 | - | } | |
294 | - | else throw("Strict value is not equal to itself.") | |
295 | - | } | |
296 | - | else throw("Strict value is not equal to itself.") | |
297 | - | } | |
298 | - | else throw("Strict value is not equal to itself.") | |
299 | - | } | |
300 | - | else throw("Strict value is not equal to itself.") | |
301 | - | } | |
302 | - | else throw("Strict value is not equal to itself.") | |
303 | - | } | |
304 | - | } | |
326 | + | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
327 | + | if ((cleanUp == cleanUp)) | |
328 | + | then if (if (!(initialized())) | |
329 | + | then true | |
330 | + | else !(isWhitelist(_amm))) | |
331 | + | then throw("Invalid increasePositionWithStopLoss parameters") | |
332 | + | else { | |
333 | + | let positionSize = getPositionSize(_amm, _trader) | |
334 | + | if ((positionSize != 0)) | |
335 | + | then throw("Invalid increasePositionWithStopLoss parameters: only new position") | |
336 | + | else { | |
337 | + | let doSetContext = invoke(this, "setContext", [_trader], nil) | |
338 | + | if ((doSetContext == doSetContext)) | |
339 | + | then { | |
340 | + | let doClosePosition = invoke(addressFromStringValue(_amm), "increasePosition", [_direction, _leverage, _minBaseAssetAmount, _refLink], i.payments) | |
341 | + | if ((doClosePosition == doClosePosition)) | |
342 | + | then { | |
343 | + | let doResetContext = invoke(this, "resetContext", nil, nil) | |
344 | + | if ((doResetContext == doResetContext)) | |
345 | + | then { | |
346 | + | let openedPositionSize = getPositionSize(_amm, _trader) | |
347 | + | if ((openedPositionSize == openedPositionSize)) | |
348 | + | then { | |
349 | + | let amountIn = abs(openedPositionSize) | |
350 | + | let stopLossSide = if ((0 > openedPositionSize)) | |
351 | + | then LONG | |
352 | + | else SHORT | |
353 | + | let doCreateStopOrder = if ((_stopTriggerPrice > 0)) | |
354 | + | then { | |
355 | + | let doCreateStopOrder = invoke(this, "internalCreateOrder", [_trader, _amm, STOP, _stopTriggerPrice, _stopLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0], nil) | |
356 | + | if ((doCreateStopOrder == doCreateStopOrder)) | |
357 | + | then nil | |
358 | + | else throw("Strict value is not equal to itself.") | |
359 | + | } | |
360 | + | else nil | |
361 | + | if ((doCreateStopOrder == doCreateStopOrder)) | |
362 | + | then { | |
363 | + | let doCreateTakeOrder = if ((_takeTriggerPrice > 0)) | |
364 | + | then { | |
365 | + | let doCreateTakeOrder = invoke(this, "internalCreateOrder", [_trader, _amm, TAKE, _takeTriggerPrice, _takeLimitPrice, amountIn, 0, stopLossSide, _refLink, "", 0], nil) | |
366 | + | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
367 | + | then nil | |
368 | + | else throw("Strict value is not equal to itself.") | |
369 | + | } | |
370 | + | else nil | |
371 | + | if ((doCreateTakeOrder == doCreateTakeOrder)) | |
372 | + | then nil | |
373 | + | else throw("Strict value is not equal to itself.") | |
374 | + | } | |
375 | + | else throw("Strict value is not equal to itself.") | |
376 | + | } | |
377 | + | else throw("Strict value is not equal to itself.") | |
378 | + | } | |
379 | + | else throw("Strict value is not equal to itself.") | |
380 | + | } | |
381 | + | else throw("Strict value is not equal to itself.") | |
382 | + | } | |
383 | + | else throw("Strict value is not equal to itself.") | |
384 | + | } | |
385 | + | } | |
386 | + | else throw("Strict value is not equal to itself.") | |
305 | 387 | } | |
306 | 388 | ||
307 | 389 | ||
308 | 390 | ||
309 | 391 | @Callable(i) | |
310 | 392 | func internalCreateOrder (_trader,_amm,_type,_triggerPrice,_limitPrice,_amountIn,_leverage,_side,_refLink,_paymentAssetId,_paymentAmount) = if (if (if (if (if (if (if (if (if (!(initialized())) | |
311 | 393 | then true | |
312 | 394 | else !(isWhitelist(_amm))) | |
313 | 395 | then true | |
314 | 396 | else (0 >= _triggerPrice)) | |
315 | 397 | then true | |
316 | 398 | else (0 > _limitPrice)) | |
317 | 399 | then true | |
318 | 400 | else (0 >= _amountIn)) | |
319 | 401 | then true | |
320 | 402 | else (0 > _leverage)) | |
321 | 403 | then true | |
322 | 404 | else !(if ((_side == LONG)) | |
323 | 405 | then true | |
324 | 406 | else (_side == SHORT))) | |
325 | 407 | then true | |
326 | 408 | else !(if (if ((_type == STOP)) | |
327 | 409 | then true | |
328 | 410 | else (_type == TAKE)) | |
329 | 411 | then true | |
330 | 412 | else (_type == LIMIT))) | |
331 | 413 | then true | |
332 | 414 | else !((i.caller == this))) | |
333 | 415 | then throw("Invalid createOrder parameters") | |
334 | 416 | else { | |
335 | 417 | let orderId = (currentOrderId() + 1) | |
336 | 418 | let newTraderOrderCount = (getTraderOrderCount(_amm, _trader) + 1) | |
337 | 419 | let positionSize = getPositionSize(_amm, _trader) | |
338 | 420 | let _direction = if (if (if ((positionSize == 0)) | |
339 | 421 | then true | |
340 | 422 | else if ((positionSize > 0)) | |
341 | 423 | then (_side == LONG) | |
342 | 424 | else false) | |
343 | 425 | then true | |
344 | 426 | else if ((0 > positionSize)) | |
345 | 427 | then (_side == SHORT) | |
346 | 428 | else false) | |
347 | 429 | then INCREASE | |
348 | 430 | else DECREASE | |
349 | 431 | if (if ((positionSize == 0)) | |
350 | 432 | then if ((_type == STOP)) | |
351 | 433 | then true | |
352 | 434 | else (_type == TAKE) | |
353 | 435 | else false) | |
354 | 436 | then throw("Can not create STOP/TAKE order: no position") | |
355 | 437 | else { | |
356 | 438 | let usdnPayment = if ((_direction == INCREASE)) | |
357 | 439 | then if (if ((_paymentAssetId != toBase58String(quoteAsset()))) | |
358 | 440 | then true | |
359 | 441 | else (_paymentAmount != _amountIn)) | |
360 | 442 | then throw("Invalid createLimitOrder parameters: invalid payment") | |
361 | 443 | else { | |
362 | 444 | let stake = invoke(managerAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), _paymentAmount)]) | |
363 | 445 | if ((stake == stake)) | |
364 | 446 | then _paymentAmount | |
365 | 447 | else throw("Strict value is not equal to itself.") | |
366 | 448 | } | |
367 | 449 | else 0 | |
368 | 450 | if ((usdnPayment == usdnPayment)) | |
369 | 451 | then { | |
370 | 452 | let positionId = if ((positionSize != 0)) | |
371 | 453 | then getPositionId(_amm, _trader) | |
372 | 454 | else 0 | |
373 | 455 | if ((newTraderOrderCount > MAX_TRADER_ORDERS_PER_AMM)) | |
374 | 456 | then throw("Invalid createLimitOrder parameters: order count") | |
375 | - | else ((saveOrder(orderId, _amm, _trader, _amountIn, _leverage, _type, _triggerPrice, usdnPayment, _side, _refLink, positionId, _limitPrice) ++ updateTraderOrderCount(_amm, _trader, newTraderOrderCount)) ++ updateLastOrderId(orderId)) | |
457 | + | else (((saveOrder(orderId, _amm, _trader, _amountIn, _leverage, _type, _triggerPrice, usdnPayment, _side, _refLink, positionId, _limitPrice) ++ addRemoveOrderId(orderId, _amm, _trader, true)) ++ updateTraderOrderCount(_amm, _trader, newTraderOrderCount)) ++ updateLastOrderId(orderId)) | |
376 | 458 | } | |
377 | 459 | else throw("Strict value is not equal to itself.") | |
378 | 460 | } | |
379 | 461 | } | |
380 | 462 | ||
381 | 463 | ||
382 | 464 | ||
383 | 465 | @Callable(i) | |
384 | 466 | func cancelOrder (_orderId) = { | |
385 | - | let $ | |
386 | - | let _amm = $ | |
387 | - | let _trader = $ | |
388 | - | let _amountIn = $ | |
389 | - | let _leverage = $ | |
390 | - | let _type = $ | |
391 | - | let _triggerPrice = $ | |
392 | - | let _amountUsdn = $ | |
393 | - | let _side = $ | |
394 | - | let _refLink = $ | |
395 | - | let _positionId = $ | |
396 | - | let _limitPrice = $ | |
467 | + | let $t01572115940 = getOrder(_orderId) | |
468 | + | let _amm = $t01572115940._1 | |
469 | + | let _trader = $t01572115940._2 | |
470 | + | let _amountIn = $t01572115940._3 | |
471 | + | let _leverage = $t01572115940._4 | |
472 | + | let _type = $t01572115940._5 | |
473 | + | let _triggerPrice = $t01572115940._6 | |
474 | + | let _amountUsdn = $t01572115940._7 | |
475 | + | let _side = $t01572115940._8 | |
476 | + | let _refLink = $t01572115940._9 | |
477 | + | let _positionId = $t01572115940._10 | |
478 | + | let _limitPrice = $t01572115940._11 | |
397 | 479 | if (if (if (!(initialized())) | |
398 | 480 | then true | |
399 | 481 | else !(isValid(_orderId))) | |
400 | 482 | then true | |
401 | 483 | else !((toString(i.caller) == _trader))) | |
402 | 484 | then throw("Invalid cancelOrder parameters") | |
403 | 485 | else { | |
404 | - | let | |
405 | - | | |
486 | + | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
487 | + | if ((cleanUp == cleanUp)) | |
406 | 488 | then { | |
407 | - | let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), _amountUsdn], nil) | |
408 | - | if ((unstake == unstake)) | |
409 | - | then nil | |
489 | + | let newTraderOrderCount = (getTraderOrderCount(_amm, _trader) - 1) | |
490 | + | let withdraw = if ((_amountUsdn > 0)) | |
491 | + | then { | |
492 | + | let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), _amountUsdn], nil) | |
493 | + | if ((unstake == unstake)) | |
494 | + | then nil | |
495 | + | else throw("Strict value is not equal to itself.") | |
496 | + | } | |
497 | + | else nil | |
498 | + | if ((withdraw == withdraw)) | |
499 | + | then (((markCancelOrder(_orderId) ++ addRemoveOrderId(_orderId, _amm, _trader, false)) ++ updateTraderOrderCount(_amm, _trader, newTraderOrderCount)) ++ (if ((_amountUsdn > 0)) | |
500 | + | then [ScriptTransfer(i.caller, _amountUsdn, quoteAsset())] | |
501 | + | else nil)) | |
410 | 502 | else throw("Strict value is not equal to itself.") | |
411 | 503 | } | |
412 | - | else nil | |
413 | - | if ((withdraw == withdraw)) | |
414 | - | then ((markCancelOrder(_orderId) ++ updateTraderOrderCount(_amm, _trader, newTraderOrderCount)) ++ (if ((_amountUsdn > 0)) | |
415 | - | then [ScriptTransfer(i.caller, _amountUsdn, quoteAsset())] | |
416 | - | else nil)) | |
417 | 504 | else throw("Strict value is not equal to itself.") | |
418 | 505 | } | |
419 | 506 | } | |
420 | 507 | ||
421 | 508 | ||
422 | 509 | ||
423 | 510 | @Callable(i) | |
424 | 511 | func executeOrder (_orderId) = { | |
425 | - | let $t01456014779 = getOrder(_orderId) | |
426 | - | let _amm = $t01456014779._1 | |
427 | - | let _trader = $t01456014779._2 | |
428 | - | let _amountIn = $t01456014779._3 | |
429 | - | let _leverage = $t01456014779._4 | |
430 | - | let _type = $t01456014779._5 | |
431 | - | let _triggerPrice = $t01456014779._6 | |
432 | - | let _amountUsdn = $t01456014779._7 | |
433 | - | let _side = $t01456014779._8 | |
434 | - | let _refLink = $t01456014779._9 | |
435 | - | let _positionId = $t01456014779._10 | |
436 | - | let _limitPrice = $t01456014779._11 | |
437 | - | if (if (!(initialized())) | |
438 | - | then true | |
439 | - | else !(isValid(_orderId))) | |
440 | - | then throw("Invalid executeOrder parameters") | |
441 | - | else { | |
442 | - | let positionSize = getPositionSize(_amm, _trader) | |
443 | - | let currentPositionId = if ((positionSize != 0)) | |
444 | - | then getPositionId(_amm, _trader) | |
445 | - | else 0 | |
446 | - | let $t01510518926 = if ((_type == STOP)) | |
447 | - | then { | |
448 | - | let _positionDirection = if ((positionSize > 0)) | |
449 | - | then LONG | |
450 | - | else if ((0 > positionSize)) | |
451 | - | then SHORT | |
452 | - | else throw("Can not execute STOP order: no open position") | |
453 | - | let marketPrice = getMarketPrice(_amm) | |
454 | - | let isExecutable = if ((_side == _positionDirection)) | |
455 | - | then throw("Can not execute STOP order: reduce only") | |
456 | - | else if ((currentPositionId != _positionId)) | |
457 | - | then throw("Can not execute STOP order: position closed") | |
458 | - | else if ((_positionDirection == LONG)) | |
459 | - | then (_triggerPrice >= marketPrice) | |
460 | - | else (marketPrice >= _triggerPrice) | |
461 | - | if (isExecutable) | |
462 | - | then $Tuple3("closePosition", [minv(_amountIn, abs(positionSize)), muld(_limitPrice, abs(positionSize))], nil) | |
463 | - | else throw("Can not execute STOP order: triggerPrice mismatch") | |
464 | - | } | |
465 | - | else if ((_type == TAKE)) | |
512 | + | let $t01691117130 = getOrder(_orderId) | |
513 | + | let _amm = $t01691117130._1 | |
514 | + | let _trader = $t01691117130._2 | |
515 | + | let _amountIn = $t01691117130._3 | |
516 | + | let _leverage = $t01691117130._4 | |
517 | + | let _type = $t01691117130._5 | |
518 | + | let _triggerPrice = $t01691117130._6 | |
519 | + | let _amountUsdn = $t01691117130._7 | |
520 | + | let _side = $t01691117130._8 | |
521 | + | let _refLink = $t01691117130._9 | |
522 | + | let _positionId = $t01691117130._10 | |
523 | + | let _limitPrice = $t01691117130._11 | |
524 | + | let cleanUp = invoke(this, "cleanUpStaleOrders", [_amm, _trader], nil) | |
525 | + | if ((cleanUp == cleanUp)) | |
526 | + | then if (if (!(initialized())) | |
527 | + | then true | |
528 | + | else !(isValid(_orderId))) | |
529 | + | then throw("Invalid executeOrder parameters") | |
530 | + | else { | |
531 | + | let positionSize = getPositionSize(_amm, _trader) | |
532 | + | let currentPositionId = if ((positionSize != 0)) | |
533 | + | then getPositionId(_amm, _trader) | |
534 | + | else 0 | |
535 | + | let $t01753821359 = if ((_type == STOP)) | |
466 | 536 | then { | |
467 | 537 | let _positionDirection = if ((positionSize > 0)) | |
468 | 538 | then LONG | |
469 | 539 | else if ((0 > positionSize)) | |
470 | 540 | then SHORT | |
471 | 541 | else throw("Can not execute STOP order: no open position") | |
472 | 542 | let marketPrice = getMarketPrice(_amm) | |
473 | 543 | let isExecutable = if ((_side == _positionDirection)) | |
474 | - | then throw("Can not execute | |
544 | + | then throw("Can not execute STOP order: reduce only") | |
475 | 545 | else if ((currentPositionId != _positionId)) | |
476 | - | then throw( | |
546 | + | then throw("Can not execute STOP order: position closed") | |
477 | 547 | else if ((_positionDirection == LONG)) | |
478 | - | then ( | |
479 | - | else ( | |
548 | + | then (_triggerPrice >= marketPrice) | |
549 | + | else (marketPrice >= _triggerPrice) | |
480 | 550 | if (isExecutable) | |
481 | 551 | then $Tuple3("closePosition", [minv(_amountIn, abs(positionSize)), muld(_limitPrice, abs(positionSize))], nil) | |
482 | - | else throw("Can not execute | |
552 | + | else throw("Can not execute STOP order: triggerPrice mismatch") | |
483 | 553 | } | |
484 | - | else if ((_type == | |
554 | + | else if ((_type == TAKE)) | |
485 | 555 | then { | |
556 | + | let _positionDirection = if ((positionSize > 0)) | |
557 | + | then LONG | |
558 | + | else if ((0 > positionSize)) | |
559 | + | then SHORT | |
560 | + | else throw("Can not execute STOP order: no open position") | |
486 | 561 | let marketPrice = getMarketPrice(_amm) | |
487 | - | let spread = if ((_limitPrice == 0)) | |
488 | - | then getSpread(_triggerPrice) | |
489 | - | else abs((_triggerPrice - _limitPrice)) | |
490 | - | let isExecutable = if ((marketPrice >= (_triggerPrice - spread))) | |
491 | - | then ((_triggerPrice + spread) >= marketPrice) | |
492 | - | else false | |
562 | + | let isExecutable = if ((_side == _positionDirection)) | |
563 | + | then throw("Can not execute TAKE order: reduce only") | |
564 | + | else if ((currentPositionId != _positionId)) | |
565 | + | then throw(((("Can not execute TAKE order: position closed " + toString(currentPositionId)) + "!=") + toString(_positionId))) | |
566 | + | else if ((_positionDirection == LONG)) | |
567 | + | then (marketPrice >= _triggerPrice) | |
568 | + | else (_triggerPrice >= marketPrice) | |
493 | 569 | if (isExecutable) | |
494 | - | then { | |
495 | - | let _positionDirection = if ((positionSize > 0)) | |
496 | - | then LONG | |
497 | - | else if ((0 > positionSize)) | |
498 | - | then SHORT | |
499 | - | else -1 | |
500 | - | let direction = if ((positionSize == 0)) | |
501 | - | then INCREASE | |
502 | - | else if ((_positionDirection == _side)) | |
570 | + | then $Tuple3("closePosition", [minv(_amountIn, abs(positionSize)), muld(_limitPrice, abs(positionSize))], nil) | |
571 | + | else throw("Can not execute TAKE order: triggerPrice mismatch") | |
572 | + | } | |
573 | + | else if ((_type == LIMIT)) | |
574 | + | then { | |
575 | + | let marketPrice = getMarketPrice(_amm) | |
576 | + | let spread = if ((_limitPrice == 0)) | |
577 | + | then getSpread(_triggerPrice) | |
578 | + | else abs((_triggerPrice - _limitPrice)) | |
579 | + | let isExecutable = if ((marketPrice >= (_triggerPrice - spread))) | |
580 | + | then ((_triggerPrice + spread) >= marketPrice) | |
581 | + | else false | |
582 | + | if (isExecutable) | |
583 | + | then { | |
584 | + | let _positionDirection = if ((positionSize > 0)) | |
585 | + | then LONG | |
586 | + | else if ((0 > positionSize)) | |
587 | + | then SHORT | |
588 | + | else -1 | |
589 | + | let direction = if ((positionSize == 0)) | |
503 | 590 | then INCREASE | |
504 | - | else DECREASE | |
505 | - | if ((direction == INCREASE)) | |
506 | - | then { | |
507 | - | let amountInWithFee = (_amountUsdn - muld(_amountUsdn, getFee(_amm, _trader))) | |
508 | - | $Tuple3("increasePosition", [_side, _leverage, if ((_limitPrice == 0)) | |
509 | - | then 0 | |
510 | - | else divd(amountInWithFee, _limitPrice), _refLink], [AttachedPayment(quoteAsset(), _amountUsdn)]) | |
511 | - | } | |
512 | - | else $Tuple3("closePosition", [_amountIn, muld(_amountIn, _limitPrice)], nil) | |
513 | - | } | |
514 | - | else throw("Can not execute LIMIT order: triggerPrice mismatch") | |
515 | - | } | |
516 | - | else throw(("Invalid order type: " + toString(_type))) | |
517 | - | let method = $t01510518926._1 | |
518 | - | let args = $t01510518926._2 | |
519 | - | let payments = $t01510518926._3 | |
520 | - | let withdraw = if ((size(payments) == 1)) | |
521 | - | then { | |
522 | - | let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), payments[0].amount], nil) | |
523 | - | if ((unstake == unstake)) | |
524 | - | then nil | |
525 | - | else throw("Strict value is not equal to itself.") | |
526 | - | } | |
527 | - | else nil | |
528 | - | if ((withdraw == withdraw)) | |
529 | - | then { | |
530 | - | let doSetContext = invoke(this, "setContext", [_trader], nil) | |
531 | - | if ((doSetContext == doSetContext)) | |
532 | - | then { | |
533 | - | let doClosePosition = invoke(addressFromStringValue(_amm), method, args, payments) | |
534 | - | if ((doClosePosition == doClosePosition)) | |
535 | - | then { | |
536 | - | let doResetContext = invoke(this, "resetContext", nil, nil) | |
537 | - | if ((doResetContext == doResetContext)) | |
538 | - | then markExecuteOrder(_orderId) | |
539 | - | else throw("Strict value is not equal to itself.") | |
540 | - | } | |
541 | - | else throw("Strict value is not equal to itself.") | |
542 | - | } | |
543 | - | else throw("Strict value is not equal to itself.") | |
544 | - | } | |
545 | - | else throw("Strict value is not equal to itself.") | |
546 | - | } | |
591 | + | else if ((_positionDirection == _side)) | |
592 | + | then INCREASE | |
593 | + | else DECREASE | |
594 | + | if ((direction == INCREASE)) | |
595 | + | then { | |
596 | + | let amountInWithFee = (_amountUsdn - muld(_amountUsdn, getFee(_amm, _trader))) | |
597 | + | $Tuple3("increasePosition", [_side, _leverage, if ((_limitPrice == 0)) | |
598 | + | then 0 | |
599 | + | else divd(amountInWithFee, _limitPrice), _refLink], [AttachedPayment(quoteAsset(), _amountUsdn)]) | |
600 | + | } | |
601 | + | else $Tuple3("closePosition", [_amountIn, muld(_amountIn, _limitPrice)], nil) | |
602 | + | } | |
603 | + | else throw("Can not execute LIMIT order: triggerPrice mismatch") | |
604 | + | } | |
605 | + | else throw(("Invalid order type: " + toString(_type))) | |
606 | + | let method = $t01753821359._1 | |
607 | + | let args = $t01753821359._2 | |
608 | + | let payments = $t01753821359._3 | |
609 | + | let withdraw = if ((size(payments) == 1)) | |
610 | + | then { | |
611 | + | let unstake = invoke(managerAddress(), "withdraw", [toBase58String(quoteAsset()), payments[0].amount], nil) | |
612 | + | if ((unstake == unstake)) | |
613 | + | then nil | |
614 | + | else throw("Strict value is not equal to itself.") | |
615 | + | } | |
616 | + | else nil | |
617 | + | if ((withdraw == withdraw)) | |
618 | + | then { | |
619 | + | let doSetContext = invoke(this, "setContext", [_trader], nil) | |
620 | + | if ((doSetContext == doSetContext)) | |
621 | + | then { | |
622 | + | let doClosePosition = invoke(addressFromStringValue(_amm), method, args, payments) | |
623 | + | if ((doClosePosition == doClosePosition)) | |
624 | + | then { | |
625 | + | let doResetContext = invoke(this, "resetContext", nil, nil) | |
626 | + | if ((doResetContext == doResetContext)) | |
627 | + | then { | |
628 | + | let newTraderOrderCount = (getTraderOrderCount(_amm, _trader) - 1) | |
629 | + | ((updateTraderOrderCount(_amm, _trader, newTraderOrderCount) ++ addRemoveOrderId(_orderId, _amm, _trader, false)) ++ markExecuteOrder(_orderId)) | |
630 | + | } | |
631 | + | else throw("Strict value is not equal to itself.") | |
632 | + | } | |
633 | + | else throw("Strict value is not equal to itself.") | |
634 | + | } | |
635 | + | else throw("Strict value is not equal to itself.") | |
636 | + | } | |
637 | + | else throw("Strict value is not equal to itself.") | |
638 | + | } | |
639 | + | else throw("Strict value is not equal to itself.") | |
547 | 640 | } | |
548 | 641 | ||
549 | 642 | ||
550 | 643 | ||
551 | 644 | @Callable(i) | |
552 | 645 | func view_canExecuteOrder (_orderId) = { | |
553 | 646 | let s = invoke(this, "executeOrder", [_orderId], nil) | |
554 | 647 | if ((s == s)) | |
555 | 648 | then throw("Success") | |
556 | 649 | else throw("Strict value is not equal to itself.") | |
557 | 650 | } | |
558 | 651 | ||
559 | 652 | ||
560 | 653 | @Verifier(tx) | |
561 | 654 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], adminPublicKey()) | |
562 | 655 |
github/deemru/w8io/026f985 87.43 ms ◑