drift-labs / protocol-v2

On-chain perpetuals dex with multiple liquidity mechanisms
Apache License 2.0
188 stars 97 forks source link

Maker-Friendly Instructions #1131

Open soundsonacid opened 1 month ago

soundsonacid commented 1 month ago

Drift is interested in adding instructions to the smart contract in order to facilitate a smoother experience for current & prospective market makers.

We are looking for input on what sort of instructions people might find useful. Current instructions to be added:

For example, if you intended to place 5 orders and would fail the margin check on the 5th order, currently no orders would be placed. This instruction would silently fail to place the fifth order and allow the transaction to succeed, placing four out of the five orders on chain.

For example, if you had 4 buy / long orders placed on XYZ-PERP at $9, $10, $11, and $12, and sent an instruction with maximum_price: 10 and direction: PositionDirection.Long, the orders at $11 & $12 would be canceled, while the orders for $11 and $12 would remain on the book. Similarly, if you provided minimum_price: 11 and direction: PositionDirection.Long, the orders at $9 and $10 would be canceled, while the orders for $11 and $12 would remain on chain. The same logic would follow for sell / short orders. (edited)

ricardojmendez commented 1 month ago

Good ideas. For CancelOrders, it would also be useful to be able to cancel orders within +/- an oracle delta (since not all market maker orders will be at fixed limit prices).

cxp-13 commented 3 days ago

Drift is interested in adding instructions to the smart contract in order to facilitate a smoother experience for current & prospective market makers.

We are looking for input on what sort of instructions people might find useful. Current instructions to be added:

  • PlaceOrders that does not revert all orders if you run out of margin during the ix.

For example, if you intended to place 5 orders and would fail the margin check on the 5th order, currently no orders would be placed. This instruction would silently fail to place the fifth order and allow the transaction to succeed, placing four out of the five orders on chain.

  • CancelOrders that accepts a “maximum_price” or “minimum_price” parameter in conjuction with “direction” to cancel all orders up to a certain price on either longs or shorts.

For example, if you had 4 buy / long orders placed on XYZ-PERP at $9, $10, $11, and $12, and sent an instruction with maximum_price: 10 and direction: PositionDirection.Long, the orders at $11 & $12 would be canceled, while the orders for $11 and $12 would remain on the book. Similarly, if you provided minimum_price: 11 and direction: PositionDirection.Long, the orders at $9 and $10 would be canceled, while the orders for $11 and $12 would remain on chain. The same logic would follow for sell / short orders. (edited)

have they already been implemented?

cxp-13 commented 3 hours ago

I implement the cancel 。https://github.com/drift-labs/protocol-v2/pull/1197