Commit Graph

151 Commits

Author SHA1 Message Date
microwavedcola1 ec5e959804 further work on perps
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-22 07:06:33 +01:00
Christian Kamm 34d14ef267 Serum: serum3_liq_force_cancel_orders instruction
Still needs a test.
2022-03-21 17:39:52 +01:00
Christian Kamm 27f882a333 Tests: More flexible test context construction 2022-03-21 10:45:55 +01:00
Christian Kamm a6a31f226c Tests: Unify group + tokens setup 2022-03-21 07:49:51 +01:00
Christian Kamm 75ac224b6e Tests: Bank deposit/withdraw/active/dust tests 2022-03-21 07:01:25 +01:00
microwavedcola1 e7b32c6149 clippy
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-20 10:16:02 +01:00
microwavedcola1 fbedea9424 reorg, placeholder for place perp order
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-20 10:11:36 +01:00
Christian Kamm 1ad0826573 Clippy warnings 2022-03-19 12:53:24 +01:00
Christian Kamm 6f72cd27e8 Serum: Cancel order instruction 2022-03-19 12:19:16 +01:00
Christian Kamm 63050c3661 Serum: No health check needed after settle_funds
It just moves free funds from open_orders to the user account.
2022-03-19 09:05:42 +01:00
Christian Kamm 9fb16f3906 Add comments 2022-03-19 08:54:33 +01:00
microwavedcola1 9475d9545c add comment
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-19 08:52:38 +01:00
microwavedcola1 479bd60ecf extend perp market with indices, which make it easier to lookup the perp market and base and quote tokens
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-19 07:28:37 +01:00
Christian Kamm 70316fb927 Serum: Settle funds instruction
Also move serum3 cpi helpers to a separate file, to allow reuse of calls
like settle_funds from multiple mango instructions.
2022-03-18 19:27:23 +01:00
microwavedcola1 4987e072cd fix test
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-18 17:49:13 +01:00
microwavedcola1 ab61c6b244 remove unused
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-18 16:30:18 +01:00
microwavedcola1 ba9bc82df2 Merge branch 'mc/perps' 2022-03-18 15:16:13 +01:00
Christian Kamm 9d05db68f9 Serum: Prefix instructions with serum3_ and related renames 2022-03-18 13:42:20 +01:00
microwavedcola1 b5734e4f97 fix trailing space
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-18 13:00:52 +01:00
Christian Kamm a40eb94833 Serum: settle_funds after place_order
Avoid using anchor_spl::dex helpers, because calling serum through these
functions costs significantly more compute, likely because AccountInfos
need to be cloned twice.

Examples:
- new_order_v3: direct 26.8k CU, helpers 37.5k CU
- settle funds: direct 24.9k CU, helpers 31.8k CU
2022-03-18 12:17:09 +01:00
microwavedcola1 4f7e3a5738 create perp market wip
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-18 10:14:30 +01:00
Christian Kamm 57c06bc2da Health: add a missing group check for remainingAccount Banks 2022-03-18 07:54:20 +01:00
Christian Kamm 7b3cd9a81f Health: Use split_at_mut to get two element &muts
Previously we re-indexed token_infos every time, now we can just have
mutable references to the base and quote elements at the same time.
2022-03-18 07:44:44 +01:00
Christian Kamm 430d5c85fa Health: compute optimizations
Basic caching of multiplications and divisions.
2022-03-17 21:53:41 +01:00
Christian Kamm af2f4a0923 Health compute tests 2022-03-17 14:17:28 +01:00
Christian Kamm 9351d0652d Serum: health based on worst case order outcome 2022-03-17 12:05:07 +01:00
Christian Kamm 0593aa81f7 Serum: more health computation
Now the open orders are actually read
2022-03-16 18:33:11 +01:00
Christian Kamm 6aa4724b45 Serum: Health computation first steps 2022-03-16 16:45:54 +01:00
Christian Kamm f5d2964f1d Serum: Store base/quote token index in MangoAccount
To avoid having to pass SerumMarket when health needs to be computed.
2022-03-16 13:48:43 +01:00
Christian Kamm 1953d12f0f Health: expect serum open orders accounts 2022-03-16 13:42:29 +01:00
microwavedcola1 7a68aa71e5 simplify
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-15 16:38:24 +01:00
microwavedcola1 75721d8f06 fix bug where position mutation was not persisted in margin trade
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-15 16:25:44 +01:00
Christian Kamm 3bb94777f3 MangoAccount field renames
indexed_positions -> token_account_map
serum_open_orders_map -> serum_account_map

in the future we should add the perp_account_map
2022-03-15 15:08:53 +01:00
Christian Kamm 54641692fa PlaceSerumOrders: indexed positions are guaranteed to exist 2022-03-15 14:59:15 +01:00
Christian Kamm baa980c659 PlaceSerumOrder: Track vault balances before and after 2022-03-15 14:44:47 +01:00
Christian Kamm 28a26e66da PlaceSerumOrder: More account validation 2022-03-14 21:53:30 +01:00
Christian Kamm 6b342ffeb9 PlaceSerumOrder basic test 2022-03-14 17:21:16 +01:00
Christian Kamm a51fdd42f7 Serialization of new serum order instruction data 2022-03-14 15:28:06 +01:00
Christian Kamm 0b2f691f5b RegisterSerumMarket: pass market_index explicitly 2022-03-14 13:47:34 +01:00
Christian Kamm 07c9b9de7e Further harmonizing of PDA seeds 2022-03-14 13:39:54 +01:00
Christian Kamm 71cd1755ec Stop storing token info in Group
It is just not needed, the individual Bank accounts have all the
necessary info.
2022-03-14 13:35:38 +01:00
Christian Kamm 1cd0f8d6be RegisterToken: Pass token_index explicitly
This guarantees stability when a gov proposal adds a new token and a new
market in one transaction. This way the RegisterMarket instruction knows
exactly what index the new token will have.

Previously, the new token index was generated automatically, meaning
you couldn't be sure what index a new token would get in advance.
2022-03-14 13:19:50 +01:00
Christian Kamm 2502f0ac1b checked_math: use a panic
This reduces compute use further and still produces good error messages.
2022-03-14 12:45:32 +01:00
Christian Kamm 38d239462f checked_math: construct errors lazily
bad benchmark of compute needs for 100 add-assigns of I80F48:
3465 a + b
3465 a.checked_add(b).unwrap()
3465 cm with unwrap()     <- maybe future if we fix panics
4366 cm with ok_or_else() <- now
56494 cm with ok_or()     <- old
2022-03-13 20:55:28 +01:00
Christian Kamm 6964340773 CI: Fix test runs
For some reason an explicit build-bpf step is needed, otherwise test-bpf
will fail with an error.
2022-03-13 15:45:50 +01:00
Christian Kamm 449fe4dc6d Add checked_math library for convenient overflow checking
Instead of
    x.checked_add(y).ok_or(error!(MangoError::MathError))?
we can write
    cm!(x + y)
2022-03-13 15:45:50 +01:00
Christian Kamm fce2316b03 Simplify health fn call, use in place serum order 2022-03-12 14:13:19 +01:00
Christian Kamm 16c0a95679 PlaceSerumOrder instruction stub 2022-03-12 14:13:19 +01:00
microwavedcola1 e742926ce2 change seeds literals to camelcase, camel case was how mango did in v3, also matches struct names
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-11 20:10:15 +01:00
microwavedcola1 241dd6080a
Merge pull request #24 from blockworks-foundation/mc/re-org
move unused to a unused mod, preparation for working on perp markets
2022-03-11 17:51:32 +01:00