Commit Graph

83 Commits

Author SHA1 Message Date
Christian Kamm 92a37f23ed Remove is_bankrupt
Instead, check for any liquidatable assets in liq_token_bankruptcy.

Bankrupt accounts may use the same operations as any other
negative-health account.
2022-08-11 22:57:53 +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 a82bab4ed7 Better error when vault doesn't have enough funds
The spl_token transfer cpi instruction just says "error code: 1", which
is too opaque.
2022-07-19 13:43:05 +02:00
Christian Kamm 693333b71e Serum3 place/settle: deactivate inactive token positions 2022-07-07 13:16:23 +02:00
Christian Kamm 31831454b4 Return raw position index from get_mut() 2022-07-07 12:01:18 +02:00
Christian Kamm 35ca4d31b3 liq_token_bankruptcy instruction for socialized loss 2022-07-06 09:07:49 +02:00
microwavedcola1 d74cc78a84
edit tokens, perp markets, mango accounts, allow delegate to perform certain operations (#94)
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-07-05 19:31:47 +02:00
Nicholas Clarke f8da1f6a40
Clarkeni/logging (#81)
* Add logging

* Added new_fixed_order_account_retriever to allow us to more easily access oracle prices outside of health calculations for logging purposes

* Add token balances logging to token and token liquidation and add logging to margin trade

* rust format

* fix clippy errors

* Address PR requested changes

* fix flash_loan

* Recalculate raw_token_index in token withdraw to account for position becoming inactive

* Fix retrieving oracle for logging

in get_mut_or_create(), return the raw index into the account's token
positions as well as the index into active positions only. The latter
index is useful for indexing into banks in the health account list.

* Add logging flash_loan2 and flash_loan3

* Refactoring flash loan logging

Co-authored-by: Christian Kamm <mail@ckamm.de>
2022-06-30 14:35:05 +02:00
Christian Kamm 20fc9d557a Satisfy anchor's lint by adding CHECK: comments 2022-06-24 12:36:35 +02:00
microwavedcola1 b0fd4c2a61 Fix warnings
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-21 13:02:30 +02:00
microwavedcola1 86c8817e0b
serum3 loan origination fees (#69)
* serum3 loan origination fees

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

* Fix tests
Fix from review

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>

* Fixes from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-21 11:45:38 +02:00
Christian Kamm 8a8b36e345 Fold loan origination fee handling into Bank 2022-05-18 22:53:03 +02:00
microwavedcola1 a1034c08b7 refactor
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-16 10:49:11 +02:00
microwavedcola1 fbd3fd410c loan_origination_fees
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-16 10:49:11 +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
microwavedcola1 1d15db37c5 clippy
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-02 10:02:12 +02:00
microwavedcola1 9cd08a1355 improve checks
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-02 09:52:40 +02:00
microwavedcola1 87bcc538cd compiles
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-02 09:05:31 +02:00
microwavedcola1 0bdbd19ddd Make Serum3 ix anchor friendly
Make work with changes in mango account, add no deploy part to release script
Clippy
Fixes from cr

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-02 08:59:07 +02:00
Christian Kamm f48a7f5ed9 Clippy: Address issues 2022-04-01 12:21:19 +02:00
Christian Kamm 9cf4f1a748 Rearrange MangoAccount to avoid padding bytes 2022-03-31 14:01:08 +02:00
Christian Kamm babbff6bec Add is_bankrupt check to most instructions 2022-03-30 12:24:49 +02:00
Christian Kamm 69426d6d96 liq: Introduce HealthCache to get init/maint health after liquidation
The concept only works if all serum3 open orders have been fully
cancelled and settled.
2022-03-29 09:18:13 +02:00
Christian Kamm 82819720e0 liq token: progress
Change bank.deposit()/withdraw() to work with I80F48 values so we don't
need to round during liquidation.
2022-03-27 14:46:51 +02:00
microwavedcola1 5919a5a1df Merge branch 'main' into mc/clippy 2022-03-23 09:53:50 +01:00
microwavedcola1 f135ca4d9b fix clippy warnings
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-23 09:33:51 +01:00
Christian Kamm bfcb672116 Health: allow account order to be fixed, or to scan for accounts
The latter is important when we want to compute health for two different
accounts. Then the remainingAccounts would hold the union of the
necessary accounts, and each health check would need to look for the
accounts that it needs.

This patch al so reduces the compute needs for fixed-layout health
checks significantly (Deposit for an account with 8 tokens and 7 markets
takes 65k instead of 70k cu)
2022-03-22 14:13:07 +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 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 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
Christian Kamm 9d05db68f9 Serum: Prefix instructions with serum3_ and related renames 2022-03-18 13:42:20 +01:00