Commit Graph

310 Commits

Author SHA1 Message Date
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 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
Christian Kamm 693ac17996 Serum: Store open orders pubkey in account 2022-03-11 17:50:04 +01:00
microwavedcola1 c2f91489af move unused to a unused mod
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-11 17:11:46 +01:00
Christian Kamm c86a6f8d29 Serum: Create OOs is functional and called from a test 2022-03-11 15:28:27 +01:00
Christian Kamm 9be5ad6488 Test: Add CreateSerumOpenOrders test stub 2022-03-11 14:26:42 +01:00
Christian Kamm da31b6317f Drop unnecessary rent accounts 2022-03-11 13:02:20 +01:00
Christian Kamm dbd8409ce8 Test: Add RegisterSerumMarket test stub 2022-03-11 12:59:42 +01:00
Christian Kamm e3960dc5e2 Outlines of RegisterSerumMarket / CreateSerumOpenOrders 2022-03-11 12:40:16 +01:00
microwavedcola1 4dc0262546 reformat
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-08 12:45:59 +01:00
microwavedcola1 b3f2ca51fa fixes from cr
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-08 11:11:28 +01:00
Christian Kamm f6d2df1ad4 Rename to Bank and Group 2022-03-07 16:16:34 +01:00
Christian Kamm 2d65078c23 Fix margin_trade instruction call 2022-03-07 15:43:29 +01:00
Christian Kamm cea0f9441a Build fixes 2022-03-07 15:29:44 +01:00
microwavedcola1 8921ac0441 todo
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-07 15:24:50 +01:00
microwavedcola1 2882476724 clipppy
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-07 15:24:50 +01:00
microwavedcola1 dcacadbcbf margin trade test
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-07 15:24:50 +01:00
Christian Kamm 425e22a086 Deposit: Compute account health
Even if it's currently unused, it will become useful in the future.

Make a function to get the list of accounts needed for health checks in
tests, which is now shared between deposit and withdraw.
2022-03-07 15:22:23 +01:00
Christian Kamm 98cf8a7cff Position lifetime, dust etc
- withdraw and deposit may deactivate positions explicitly
- adjusting bank positions may collect dust for positions between
  0 and 1 native tokens
- health check always assumes all active and new banks/oracles are
  passed
2022-03-07 15:21:19 +01:00
Christian Kamm 51991d8546 Add global address lookup table test 2022-03-04 20:57:33 +01:00
Christian Kamm c6031acbdb Move to global address lookup tables 2022-03-04 20:57:33 +01:00
Christian Kamm 9692f9976f Compile and warning fixes 2022-03-03 13:10:20 +01:00
microwavedcola1 ce5f2027a1 extract health, flesh out margin trade, todo - test
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-03 11:43:56 +01:00
microwavedcola1 6702cdbba6
mc/pyth (#14)
* pyth integration

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-02 21:11:05 +01:00
Christian Kamm 01e8458093 Tests: Read banks/oracles from address lookup table 2022-03-01 15:12:53 +01:00
Christian Kamm fa008a8aa1 Move address map functions into separate module 2022-03-01 15:01:50 +01:00
Christian Kamm eb38fb4f18 Make module for address_lookup_table functions 2022-03-01 13:57:46 +01:00
Christian Kamm a7975d390d Tests: Fix warnings 2022-03-01 13:49:59 +01:00
microwavedcola1 2a698f3135
Merge pull request #13 from blockworks-foundation/mc/oracle-in-withdraw
basic stub oracle integration in tests and withdraw
2022-03-01 06:38:13 +01:00
microwavedcola1 d9c7260375 code review
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-01 06:28:12 +01:00
Christian Kamm 3e6d722e01 Deposit: Don't add accounts to lookup table twice 2022-02-28 20:12:37 +01:00
Christian Kamm 5ebf425a65 Deposit: Extend the lookup table with bank and oracle
When the position goes from inactive to active.
2022-02-28 19:43:40 +01:00
microwavedcola1 5299e31ff8 basic stub oracle integration in tests and withdraw
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 17:17:01 +01:00
Christian Kamm 9a50325718 fix outdated comment 2022-02-28 15:45:56 +01:00
Christian Kamm 75092f7681 CreateAccount: Initialize an address lookup table 2022-02-28 15:43:08 +01:00
microwavedcola1 c7cd564d11 fix test, was missing oracle
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 14:48:59 +01:00
microwavedcola1 362b180069 add oracle to to token registration
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 14:44:08 +01:00
microwavedcola1 12d2a9f962 make clippy happy
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 12:56:26 +01:00
microwavedcola1 1c47f0d004 add ix handling for stub oracles
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 12:37:12 +01:00
microwavedcola1 3355ed1dcf dont need special crate for this
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 11:18:55 +01:00
microwavedcola1 364f5d895b fix use statement location
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 11:18:35 +01:00
microwavedcola1 e8b1563223 optimise imports
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 11:07:04 +01:00
microwavedcola1 3648cba0d0 use discriminator to differentiate between oracles, removes need for a magic constant, same could be done for other oracles
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 11:05:15 +01:00
microwavedcola1 6345d3ebd4 add todo
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 10:45:03 +01:00
microwavedcola1 c0c115bd03 remove unused
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 10:44:08 +01:00
microwavedcola1 823fbeb6b5 stub oracle ix and account state
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 10:36:31 +01:00
Christian Kamm b88989bf3a Tests: Transport error info on send_tx() 2022-02-28 09:12:24 +01:00
Christian Kamm 7aa2cd7e13 Test cleanups 2022-02-28 09:03:43 +01:00
Christian Kamm 1b404cc652 Basic health check, no oracles yet 2022-02-26 17:47:16 +01:00
Christian Kamm 174d38a199 Don't check PDA seeds on use, instead store addresses
This saves about 5000 CU currently, making Deposit/Withdraw go from
26000 CU to 21000 CU.
2022-02-26 12:17:20 +01:00
Christian Kamm 2ef2424ac5 Move the asset/liab weights to the Bank account 2022-02-26 12:04:42 +01:00
Christian Kamm 8f5becc0d5 Asset/liab weights and withdraw amounts 2022-02-25 18:29:54 +01:00
Christian Kamm d1e2cc28b7 Outline of withdraw instruction 2022-02-25 15:14:15 +01:00
Christian Kamm 5f5ba723d6 Add basic test setup 2022-02-25 13:12:16 +01:00
Christian Kamm 818bd6fe48 Enable anchor seeds extraction 2022-02-23 10:55:23 +01:00
Christian Kamm 70d3603cb4 Rename group.owner -> group.admin 2022-02-23 10:19:54 +01:00
Christian Kamm 9f013fb22a Initialize bank indexes 2022-02-23 10:15:33 +01:00
Christian Kamm 5a4b6263ac Add deposits/borrows tracking 2022-02-23 10:09:01 +01:00
Christian Kamm 8bc0416ef6 Helper functions to simplify 2022-02-22 17:13:26 +01:00
Christian Kamm 6b5162cce0 Remove root bank 2022-02-22 16:46:55 +01:00
Christian Kamm 1b935335fb Drop Default impls, manually set account space
This fixes stack issues.

I don't know why anchor uses bytemuck::from_bytes(&T::default()).len()
2022-02-22 15:55:30 +01:00
Christian Kamm 13d1ebb614 Remove bad annotation 2022-02-22 14:40:49 +01:00
Christian Kamm fdfab14e43 Drop unneeded associated token account program 2022-02-22 14:35:10 +01:00
Christian Kamm c9ad4f0c94 Very basic deposit instruction 2022-02-22 14:23:13 +01:00
Christian Kamm 901062d0c1 Add token bank and vault accounts 2022-02-22 13:31:18 +01:00
Christian Kamm 76a4e717c3 Add forgotten create_account.rs 2022-02-22 13:31:03 +01:00
Christian Kamm 9b16feaf44 CreateAccount instruction outline 2022-02-22 13:15:13 +01:00
Christian Kamm 6a7881b725 RegisterToken instruction outline 2022-02-22 10:19:40 +01:00
Christian Kamm cb94c7c598 CreateGroup instruction outline 2022-02-22 10:16:13 +01:00
Christian Kamm 6160a80457 First ideas for MangoGroup and MangoAccount accounts 2022-02-22 10:15:37 +01:00
Christian Kamm d4246f7da1 Upgrade to anchor 0.22.0 2022-02-22 10:09:40 +01:00
Christian Kamm a79ee2c8e2 Fix compile by disabling unadapted state/ structs 2022-02-22 10:09:40 +01:00
microwavedcola1 b362d3320b notes for self
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-10 10:50:57 +01:00
microwavedcola1 f2921d2272 add todos
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-10 10:49:45 +01:00
microwavedcola1 268db58294 fix imports
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-10 10:04:47 +01:00
microwavedcola1 5ab8f6e09e copy structs from v3, next goal is to see what we can retain and what to change
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-10 09:07:34 +01:00
microwavedcola1 d7229d7a48 Program struct
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-02 11:55:44 +01:00
microwavedcola1 b35802c555 turn off doc tests, make script executable
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-01-21 19:25:13 +01:00
microwavedcola1 66172881a1 First commit
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-01-21 19:21:46 +01:00