Commit Graph

539 Commits

Author SHA1 Message Date
tjs 91b2e770e6 add esm tsconfig 2022-06-30 13:17:10 -04: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
tjs ecbffe499f wip: add flash loan 3 2022-06-29 23:36:57 -04:00
tjs 273b8dd597 add deposits and borrows fn to mangoAccount 2022-06-29 15:55:42 -04:00
microwavedcola1 1c02ccd21d
Transfer dust from bank vaults to a dust account, without this we wont be able to close bank vaults (#88) 2022-06-29 09:11:14 +02:00
microwavedcola1 cce3836b09 update idl
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-28 16:55:00 +02:00
Christian Kamm 86d635f5d0 FlashLoan3: Variant that transfers directly
FlashLoan2 requires the user to set up transfers to and from the Mango
vault accounts. This version directly provides the loaned funds into a
target token account and repays everything that exceeds the initial
token account balance at the end.
2022-06-28 15:32:26 +02:00
Christian Kamm d786a672f1 FlashLoan2: API with Begin and End instructions
For FlashLoan users had to pass the target cpi programs, accounts and
data to the FlashLoan instruction itself.

The new API allows existing instructions to be used unchanged, they
just need to be bracketed by FlashLoan2Begin and FlashLoan2End.
2022-06-28 15:30:13 +02:00
Christian Kamm 3eedba67b1 Fix serum3_cancel_order
accidental removal of mut in 20fc9d557a
2022-06-27 11:38:55 +02:00
microwavedcola1 9fc8a5a56a
multiple banks (#82)
* multiple banks

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

* Fixes from review

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

* test for closing multiple banks for a registered token

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

* fix deregister_token

* update idl

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

* Fixes from review

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

Co-authored-by: Christian Kamm <mail@ckamm.de>
2022-06-27 11:27:17 +02:00
tjs 0758125db8 fix vaultIndex and transfer the minOutAmount back to vault 2022-06-24 19:01:57 +02:00
tjs 86deab72c5 Merge branch 'ts/token-transfer' into dev 2022-06-24 16:43:32 +02:00
tjs 997c610ec9 use jupiter swap and remove orca integration code 2022-06-24 16:41:04 +02:00
Christian Kamm 20fc9d557a Satisfy anchor's lint by adding CHECK: comments 2022-06-24 12:36:35 +02:00
microwavedcola1 7a28a3bfb0 improvements to flash loan
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-23 16:41:24 +02:00
tjs 719b944f89 update type names; fix flashLoan client fn 2022-06-23 16:02:35 +02:00
microwavedcola1 a151dea893 Merge branch 'dev' into ts/token-transfer 2022-06-23 15:36:33 +02:00
microwavedcola1 1177213bb3 Fix type
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-23 15:36:08 +02:00
microwavedcola1 8c024f438e Merge branch 'dev' into ts/token-transfer 2022-06-23 15:25:38 +02:00
microwavedcola1 84b89d4a1d fix
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-23 15:24:48 +02:00
microwavedcola1 c1dea82a55
mainnet scripts (#80)
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-23 15:22:59 +02:00
tjs 997d363195 wip margin trade with spl token transfers 2022-06-23 15:20:32 +02:00
microwavedcola1 54c0306ae7 Fix flash loan
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-23 13:10:15 +02:00
Christian Kamm 0bd5b8fdf3 Rename margin_trade.rs -> flash_loan.rs 2022-06-23 10:23:52 +02:00
Christian Kamm c8ebc1f611 Rename MarginTrade -> FlashLoan 2022-06-23 10:23:52 +02:00
Christian Kamm d8a6a29e70 Renames: propagate to idl and ts 2022-06-23 10:04:54 +02:00
Christian Kamm 648b462352 Rename MangoAccount components 2022-06-23 10:04:54 +02:00
tjs 743f650494 fix orca import path 2022-06-22 17:09:18 +02:00
Christian Kamm 1143b38d3c Health review comments 2022-06-22 16:52:11 +02:00
Christian Kamm ba79995c01 Health: order-independent serum3 health
Now all the reserved funds in serum3 open orders accounts are added into
each possible token at the same time. Then the worse case from applying
the reserved funds to either quote or base is selected.

This is reasonably cheap to compute, leads to unchanged results when no
markets share (non USDC) base or quote tokens, but can underestimate
the "true" health value when markets do.

An additional advantage is that HealthCache is now indepenent of serum
open orders and can compute the init and maint health when the user has
active OpenOrders accounts.
2022-06-22 16:52:11 +02:00
Christian Kamm d4cec8dfa4 Bank: Fix bug when when depositing to exactly 0 2022-06-22 16:51:16 +02:00
Christian Kamm 033cdeab7c client: remove failing doctests 2022-06-22 16:51:16 +02:00
microwavedcola1 c19c3480e7
change format of ids json (#73)
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-21 20:04:21 +02:00
tjs 46f3fd4c29 adds fn to get oracle prices for group tokens 2022-06-21 19:14:24 +02:00
Christian Kamm aeb94642ce fix clippy warnings 2022-06-21 13:10:37 +02:00
Christian Kamm 5dd186ac13 Health: fix unittests 2022-06-21 13:02:47 +02:00
Christian Kamm 6f41efad0f Health: helper for finding token info by index 2022-06-21 13:02:47 +02:00
microwavedcola1 b0fd4c2a61 Fix warnings
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-21 13:02:30 +02:00
tjs 2a39e4c603 add deposit and borrow rate client fns 2022-06-21 12:38:05 +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 cb0010b2b5 Health: never allow positive contributions from perps 2022-06-21 11:07:13 +02:00
Christian Kamm be98f6524a Orderbook: Avoid usize fields in data 2022-06-21 11:05:46 +02:00
Christian Kamm 6ff4ff5910 Add a ComputeHealth instruction
This way the client can ask for simulation to determine an account's
health.
2022-06-21 11:05:32 +02:00
Christian Kamm 712bece0b2 Remove stray log message from health computation 2022-06-20 18:21:26 +02:00
microwavedcola1 470292024e
Filter out bad switchboard prices (#70)
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-20 18:03:16 +02:00
microwavedcola1 fc716c6da4 Fix script
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-20 13:28:18 +02:00
microwavedcola1 0841bf5f68 Fix type usage
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-20 13:26:47 +02:00
Christian Kamm 28bf02ffa1 Fix offsets inside PerpMarket 2022-06-20 12:52:27 +02:00
Christian Kamm 1d7f09331b Fix example1-admin stub oracle check 2022-06-20 12:47:51 +02:00
microwavedcola1 94f865fa57 todo
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-19 20:16:12 +02:00