Commit Graph

66 Commits

Author SHA1 Message Date
Maximilian Schneider c006948319
Enable self-trading protection (#533)
Co-authored-by: Christian Kamm <mail@ckamm.de>
2023-05-15 10:40:41 +02:00
Maximilian Schneider 9166b761e9
log taker trade summary (#579)
* add new event for taker trade so arb bots can verify their execution cost without waiting for consume events

Co-authored-by: Nicholas <nicholasgclarke@gmail.com>
2023-05-13 17:54:27 +02:00
Christian Kamm d20ae0abcb
Perp: Exit matching loop when no more base lots can be filled (#576) 2023-05-08 06:40:38 +02:00
Nicholas Clarke 2dce1398d3
Fix to seq num logging. Seq num was incremented between event and logging (#556) 2023-04-25 13:38:31 +02:00
Nicholas Clarke 37ae7549fb
Clarkeni/perp trade logging (#535)
* Emit the slot corresponding to the oracle price to PerpUpdateFundingLog.

* Emit a new FilledPerpOrderLog consisting of just the group, perp market and seq num. This will be used to correlate perp fills to the transactions they were matched (not consumed).
2023-04-13 10:50:39 -07:00
Christian Kamm 9a13c1366a
Fee buyback: Credit only perp fees that go to the dao (#479) 2023-02-27 19:51:09 +01:00
Christian Kamm e4d46c3c5b
Buyback fees: Add staggered expiry (#478) 2023-02-27 16:36:27 +01:00
microwavedcola1 d88d44b34a
buyback perp fees with mngo at a discount (#464)
buyback perp fees with mngo

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-02-25 20:34:16 +01:00
Christian Kamm 5c7a2e3e10
Use the overflow-checks=true equivalent with the fixed crate (#476)
* Vendor `fixed` crate to have checked math in release mode
* remove all cm!()
* drop superfluous parens
* drop use of checked_math crate
* manual removal of redundant checked_* functions
2023-02-24 11:56:33 +01:00
Christian Kamm f6abd9579d
Perp cancel all: Don't error when orders are filled/expired (#453) 2023-02-14 10:44:51 +01:00
Christian Kamm 5328003183
Perp: Reorganize fill events, add client order id to LeafNodes (#426)
- don't store internal order ids: unneeded
- provide the maker client order id for user correlation
- store fees as f32 to waste fewer bytes
- new FillLogV2
2023-02-02 09:15:06 +01:00
microwavedcola1 0192728efc
return order id from a perp place order ix (#417)
* return order id from a perp place order ix

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* fix

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* fixes from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-01-25 09:03:35 +01:00
Christian Kamm 8b4a4c82fb Perp: move Book::new_order() code around 2023-01-20 14:42:35 +01:00
Christian Kamm be37f33946 Perp: Add PerpOpenOrder::is_active_for_market() 2023-01-20 14:42:35 +01:00
microwavedcola1 44f599ca62
dont process orders which have 0 lots; dont return early, we still want to apply ioc penalty (#404)
* skip iteration if the incoming order has no lots to process

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* fixes from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-01-19 11:29:00 +01:00
Christian Kamm 0a86257309 Perp: Move best_price/impact_price from Orderbook to BookSide 2023-01-19 09:31:59 +01:00
Christian Kamm c5d875e04d
Perp settle limit extension to realized pnl (#359)
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
2023-01-11 14:32:15 +01:00
Christian Kamm 450007d34b
Perp: Drop client order id from LeafNodes (#323)
This saves 8 bytes and only the FillEvents, FillLogs were populated from
the data.
2022-12-08 19:55:32 +01:00
Christian Kamm 947d9b2b60
Split into perp bids and perp asks (#322)
Separate, smaller accounts that are easy to extend if needed.
2022-12-07 21:03:28 +01:00
Christian Kamm c44dc045cf
Perp: Merge ordertrees for fixed and oracle_pegged (#321)
By sharing the nodes list we're much less likely to grossly
over-allocate space.
2022-12-07 20:54:18 +01:00
Christian Kamm 375b2b3fb3
Use bytemuck::Pod derives to check for accidental padding (#317) 2022-12-06 09:25:43 +01:00
microwavedcola1 25312bc398
struct layout reorg + reserved pass (#315)
* reorder structs + review reserved space + split const assets into individual fields for correct checking
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* Fixes from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* Fixes from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-12-05 15:23:20 +01:00
microwavedcola1 d64d9285f4
limit settleable pnl (#295)
Co-authored-by: Christian Kamm <mail@ckamm.de>
2022-11-30 13:20:19 +01:00
microwavedcola1 d3661bac7b
mc/oracle peg ts client (#290)
* oracle peg client support

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* Fixes from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* Fixes from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* Fix from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-11-21 19:34:41 +01:00
Christian Kamm 5731ce8faa
Perp oracle peg feature (#264)
This introduces the ability to use oracle peg orders on perp markets.

This PR has significant non-backwards compatible changes, for example all
order trees are now in a single account instead of separate.
2022-11-08 15:27:56 +01:00
Nicholas Clarke 96344d7de1
Clarkeni/perp logging (#265)
* Perp instruction logging
* Onchain funding calculation
* perp_spot_transfers field on perp positions
* Logging on register token, perp market
* Additional fields on update token index logging
* maker and taker volume fields on perp position
2022-10-07 12:12:55 -07:00
Conj0iner 55f77ad6c6 Added IOC penalty 2022-09-23 00:55:12 +08:00
Christian Kamm 1f26a54399
Perps: introduce explicit position close (#216)
* Perps: fix position lifetime; explicit closing

When an order is placed and the position needs to be created, the
settlement token is marked as in use. The perp position and the in-use
flag are only released with the new perp_close_position instruction.

* Tests: Factor out common floating-point comparisons

* Rename PerpClosePosition -> PerpDeactivatePosition
2022-09-09 10:50:09 +02:00
Christian Kamm 6c32077d1a Perps: Let all base lot changes go through a function
Direct access to base_position_lots and quote_position_native is not
allowed anymore.

Fixes an issue where quote_lots were used instead of quote_native, and
also takes fees into account for the entry price.
2022-09-08 13:12:50 +02:00
Christian Kamm e56ed3776c Perp: Api cleanups
- Clarification of close_order vs close_all_orders
- Remove of get_ prefixes
- Remove find_min/find_max/find_min_max, duplicated with
  min_leaf/max_leaf
2022-09-08 13:11:45 +02:00
Christian Kamm 79a7bdc299 Checked math: support cm!(a += b) 2022-09-06 08:55:27 +02:00
Christian Kamm 801b68b93c MangoAccount: add unittests 2022-08-30 13:11:47 +02:00
Christian Kamm 7d508e5df5 MangoAccount: Fixes after audit 2022-08-29 16:13:15 +02:00
Christian Kamm 09fc5f716b Renames in MangoAccount
- Accessors in MangoAccountValue
- PerpPositions -> PerpPosition
2022-08-19 14:58:20 +02:00
microwavedcola1 0b2e1e6e6c
Mc/realloc 4 (#119)
Realloc + dynamic mango account

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Co-authored-by: Christian Kamm <mail@ckamm.de>
2022-07-25 16:07:53 +02:00
Christian Kamm 20fc9d557a Satisfy anchor's lint by adding CHECK: comments 2022-06-24 12:36:35 +02:00
Christian Kamm 648b462352 Rename MangoAccount components 2022-06-23 10:04:54 +02:00
Christian Kamm b3568b7f3e
Make health/oracle functions usable from clients (#63)
* Make health/oracle functions usable from clients

By creating a shared trait that is implementable for AccountInfo and
AccountSharedData.

* Health: fixup tests
2022-06-08 13:43:12 +02:00
microwavedcola1 717b72857d
Remove anchor dummy type workaround (#53)
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-18 17:16:14 +02:00
microwavedcola1 2de149f74c checked math + rustfmt
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-17 17:08:00 +02:00
microwavedcola1 db82fcbbcc perp cancel order instructions
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-16 10:49:11 +02:00
Christian Kamm 6f3673bcdf Perp: Track taker and maker orders in the account; test 2022-04-04 10:39:13 +02:00
Christian Kamm 9f0a7f67ae Orderbook: Port over unittests 2022-04-02 13:51:26 +02:00
Christian Kamm cbc3cc7bbd MangoAccount: Rename how tokens/serum3/perps data is stored
token_account_map -> tokens
serum3_account_map -> serum3
perp -> perps
2022-04-02 13:51:26 +02:00
Christian Kamm d26caf1c87 Perp: Rename fields to be explicit about being in lots 2022-04-01 15:47:12 +02:00
Christian Kamm f2607889e3 Perps: Place accounts and open orders in MangoAccount::perp
Also make test_perp succeed by fixing the FillEvent size.
2022-04-01 12:45:01 +02:00
Christian Kamm f48a7f5ed9 Clippy: Address issues 2022-04-01 12:21:19 +02:00
Christian Kamm 833a909aa4 Orderbook: unify new_bid/new_ask 2022-04-01 12:21:19 +02:00
microwavedcola1 64e3ba0d7c --wip-- [skip ci] 2022-03-28 21:13:16 +02:00
microwavedcola1 b851dd13ad add new ask
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-26 17:06:55 +01:00