Commit Graph

337 Commits

Author SHA1 Message Date
Conj0iner a6ddf232cb Fixed tests 2022-09-09 18:50:11 +08:00
Conj0iner 3b3286a5b3 Changed max_settle_amount to u64 2022-09-09 18:29:02 +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 1d7d5e9a6d Test: simplify by adding a TestKeypair that's Clone+Copy
This means a lot less annoyance because of &'a Keypair or Arc<Keypair>
2022-09-07 14:23:52 +02:00
Christian Kamm c714fb213d Tests: Auto-advance the slot after sending a transaction
This fixes a recurring error where it would look as if a transaction you
send would not be processed at all.
2022-09-07 11:34:47 +02:00
Christian Kamm 3c51449040 Tests: Remove unused imports 2022-09-05 18:40:42 +02:00
Conj0iner c34ee54233 Added perp_settle_fees instruction 2022-09-05 22:18:40 +08:00
Conj0iner 97eed4081d Added perp_settle_pnl instruction 2022-09-02 00:07:57 +08:00
Christian Kamm c31f11013f Serum deregister: Close index reservation account
Only safe because this is a testing-only instruction
2022-09-01 12:15:00 +02:00
Christian Kamm d0fef4a586 Test: simplify allow(dead_code) to be per-file 2022-08-30 15:32:59 +02:00
Christian Kamm 1f0138d1de SerumCloseOO: Reduce in_use_count of token positions 2022-08-30 12:05:07 +02:00
Christian Kamm 8e30870689 SerumLiqForceClose: Proper health/liq checking 2022-08-30 12:05:07 +02:00
Christian Kamm e0437305ee SerumPlaceOrder: Only pass the payer bank/vault 2022-08-30 12:05:07 +02:00
Christian Kamm 36723792a1 SerumRegister: Block using the same market index twice 2022-08-30 12:05:07 +02:00
Christian Kamm dc4acd0dd7 Serum: loan origination fee, don't auto-settle, fix vault check
- Loan origination fees: The previous approach of tracking the reserved
  amount did not work because OutEvents will also reduce the reserved
  amount. This means we can't know if it was an OutEvent-cancel or an
  order execution that caused the reduction.

  Instead, we now track the amount of borrows that was made (without
  applying origination fees) in place order. Whenever we try to settle
  and the amount of tokens on the oo account is less than the potential
  borrows, we can be certain that the borrow has actualized.

- Place order is no longer automatically followed by a settle.

  This can reduce compute use when people want to place multiple orders
  in sequence. Now they can use the HealthRegion instructions to place
  their orders, settle once at the end, and then have health checked.

- Vault check: Place order previously rejected valid orders because it
  didn't consider that there could be free tokens on the oo account.

- Tests: Some infrastructure for less verbose serum testing.
2022-08-30 08:38:13 +02:00
Christian Kamm e1adbf0217 Tests: Fix concurrent log capture 2022-08-30 08:37:29 +02:00
Christian Kamm d6d66402f7 Tests: Helper for create + fund 2022-08-30 08:37:29 +02:00
microwavedcola1 453248bbe5
token_deregister: remove redundant token index and add doc (#192)
* token_deregister: remove redundant token index

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

* fix test

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

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-25 19:25:56 +02:00
Christian Kamm bba27ed6f0 PlacePerpOrder: pre-health computation 2022-08-24 16:07:22 +02:00
Christian Kamm cb0a9e5d2b Tests: allow checking of logged "post_health" 2022-08-24 14:15:01 +02:00
Christian Kamm c8159746e7 Tests: Remove unnecessary argument 2022-08-24 14:15:01 +02:00
Christian Kamm 45f52ae535 Serum3PlaceOrder: compute pre-health 2022-08-24 14:15:01 +02:00
Christian Kamm 2d2cef35a0 Add HealthRegion instructions
You can do
- HealthRegionBegin
- ... mango instructions ...
- HealthRegionEnd

and the account health will only be checked at the start and end
instead of for every instruction.
2022-08-24 10:07:45 +02:00
Christian Kamm c9fb4c7133 Tests: Fix program log capture 2022-08-24 10:07:45 +02:00
Nicholas Clarke 704dfcaa27
Clarkeni/loan fee logging (#180)
Logging for loan origination fees and token bankruptcy
2022-08-19 18:50:54 -07:00
Christian Kamm 09fc5f716b Renames in MangoAccount
- Accessors in MangoAccountValue
- PerpPositions -> PerpPosition
2022-08-19 14:58:20 +02:00
Christian Kamm a23afed7de Fix computation of utilization time-weighted average 2022-08-17 15:29:11 +02:00
Nicholas Clarke 8a1c58e723
FlashLoan: Add flash_loan_type (#164)
Co-authored-by: Christian Kamm <mail@ckamm.de>
2022-08-17 12:36:55 +02:00
Christian Kamm e8bbfbef83 Bank: fix collection of loan fee
Instead of changing indexed_borrows, change borrow_index!
2022-08-16 16:27:45 +02:00
Christian Kamm 421b2d3d19 FlashLoan: Fix validation holes
- Pass the group to Begin and End and ensure it is the same.
- Enforce target token accounts can't be group-owned.
- Now End can consistently derive the number of vaults/token accounts.
2022-08-16 13:10:05 +02:00
Christian Kamm 54222c5b3f liq_token_bankruptcy: don't pass redundant index 2022-08-16 13:08:57 +02:00
Christian Kamm 0265b9b0a9 Account: Change type of net_deposts / net_settled
Because f32 doesn't have enough significant digits for large deposits.
2022-08-15 10:48:43 +02:00
Christian Kamm 6a77a5c349 tests: fix compilation warnings 2022-08-15 10:48:43 +02:00
Christian Kamm 21815612ae
Let all PDA seeds start with a unique prefix (#166)
This is mostly paranoia. Now it's guaranteed that different PDA types
have unique seeds.
2022-08-13 19:30:35 +02:00
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
Christian Kamm e8479e2e7c liq_token_with_token: Correctly adjust health cache for dusting
Previously the health cache adjustments didn't take into account that
positions between 0 and 1 native token would be dusted to 0.

This makes a difference for valuable tokens with few decimals. For
example 1 BTC-native token is currently worth 500k SOL-native tokens.
That means 0.9 BTC-native would easily be enough collateral for a 10k
SOL-native borrow -- but if the 0.9 get dusted, then the whole account
is bankrupt instead.
2022-08-10 16:24:48 +02:00
microwavedcola1 e06736660a
remove account size, make mango account feature position counts explicit (#148)
* remove account size from program, make position counts explicit

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

* cargo-fix

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-07 14:16:06 +02:00
Nicholas Clarke e4a073c83b
Clarkeni/group logging (#142)
* Add group logging and updateIndexAndRate anchor test
* Bugfix on health account ordering
2022-08-05 10:11:44 -07:00
microwavedcola1 331bb7ebf0 refactor,format
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-04 12:13:36 +02:00
microwavedcola1 505cbd48aa fixes from review
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-03 15:45:10 +02:00
microwavedcola1 9c10101166 remove traces of address lookup tables aka transactions v2
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-02 09:39:08 +02:00
microwavedcola1 a9a03b97ac
mc/registration time (#132)
* registration time

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

* fix from review

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

* fix from review

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

* mc/u32 numbers - consistent numbers in pdas (#133)

* consistent numbers in pdas

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

* fix

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-01 18:46:45 +02:00
microwavedcola1 5c3b2c1189
mc/kill flash loan 1 & 2 and rename flash loan 3 to flash loan (#131)
* remove flash loan 1 & 2

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

* rename flash loan 3 to flash loan

* fix test

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-01 16:55:17 +02:00
microwavedcola1 e8e774a1a4
mc/feature gating (#129)
* feature gating

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

* Fixes from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-01 12:56:29 +02:00
microwavedcola1 91d59c1918 close insurance vault also
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-07-31 09:57:56 +02:00
microwavedcola1 45fd36642e
prepare group for ownership transfer to governance (#125)
* prepare group for ownership transfer to governance

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

* Fixes from reviews

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

* fix from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-07-31 09:28:16 +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 ea85824ccb Remove code copied from solana-address-lookup-table-program
This removes the ProgramInstruction enum from the IDL, which was unused
and could break clients.
2022-07-21 06:49:04 +02:00
microwavedcola1 39686d3d0f CU of test has increased, accomodate only for this test
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-07-20 15:51:10 +02:00
microwavedcola1 3eae2cdc34 upgrade anchor to latest, upgrade solana dependencies to match what latest anchor uses
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-07-20 15:51:10 +02:00
Christian Kamm 2bff4bba3d Drop being_liquidated after bankruptcy resolves 2022-07-20 09:47:37 +02:00
Christian Kamm b77af54f15 Fix tests 2022-07-11 22:31:00 +02:00
microwavedcola1 ef7d2862da
wip: dynamic rates (#98)
* dynamic rates

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

* fmt

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-07-11 17:08:32 +02:00
Christian Kamm 45da68c6ac LiqTokenWithToken: Close inactive token positions 2022-07-07 12:24:48 +02:00
Christian Kamm ffd83a7a05
Rename instructions to follow naming pattern (#97) 2022-07-06 14:51:15 +02:00
Nicholas Clarke 348fbc1cb9
Track cumulative net deposits (deposits - withdraws) (#91)
Track cumulative net deposits (deposits - withdraws) using prices at the time of the deposit and withdraw.
This is used for calculating overall pnl (across all tokens).
I want to store UI amount * UI price = (native amount / base decimals) * (oracle price * base decimals / quote decimals) => native amount * oracle price / quote decimals.
I have used f32 here to reduce the space required on the mango account - we don't need so much precision for this as it's purely a display value.
I've also included a field for net_settled - this will be used for perp pnl but is not implemented yet (as perp settling instructions are not ready).

Co-authored-by: Christian Kamm <mail@ckamm.de>
2022-07-06 12:07:30 +02:00
Christian Kamm de86b69e1a Client/program interface changes
- rearrange structs to have gPA data in front and add comments about the
  offsets being relevant
- add insuranceMint to group creation in client
- drop quoteTokenIndex storage on PerpMarket
- fixes to editAccount in example1-user and client
2022-07-06 11:34:07 +02:00
Christian Kamm 35517bdb75 Review fixes 2022-07-06 11:34:04 +02:00
Christian Kamm b25f6d5f4f Insurance fund 2022-07-06 09:07:50 +02:00
Christian Kamm 35ca4d31b3 liq_token_bankruptcy instruction for socialized loss 2022-07-06 09:07:49 +02:00
Nicholas Clarke 30fc7def77
Add oracle price to update_index logging. (#89)
* Add oracle price to update_index logging.

* Update IDL with changes to update_index instruction and logging.
2022-07-05 11:59:44 -07: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
microwavedcola1 dff3f7cd8c client functions via program simulation
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-07-04 14:11:38 +02:00
Christian Kamm 30a221047c Bank: rename indexed total deposits and schedule for removal 2022-07-01 14:08:28 +02:00
microwavedcola1 e8cb27610e
close mango account without checks when testing flag is set on the group, workaround weird issues when all dust cant be withdraw (#92)
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-07-01 13:38:50 +02: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
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
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
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 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 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
microwavedcola1 9462be7f0b Fix margin trade interface
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-18 17:14:20 +02:00
microwavedcola1 4864562ff3
margin trade, support multi cpi (#68)
* margin trade, support multi cpi

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

* Fix from review

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

* todo

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-18 16:43:45 +02:00
microwavedcola1 0f34851c64
switchboard support (#67)
* switchboard support

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

* Fix from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-18 16:38:46 +02:00
microwavedcola1 740ff0c09e
Close various things (#65)
* close bank, vaults, mint infos, stub oracles, serum OO (doesnt work, throws https://github.com/project-serum/serum-dex/blob/master/dex/src/error.rs\#L88), close serum market

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

* serum oo closing example in ts

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

* Fix from code review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-09 18:27:31 +02:00
microwavedcola1 a20d04b6ff
Fix oracle price read by using decimals from pyth (#62)
* Fix oracle price read by using decimals from pyth

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

* fix

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-02 10:36:04 +02:00
Christian Kamm 48cb1f0b88 Compute health in perp_place_order 2022-05-29 20:50:21 +02:00
Christian Kamm 65a5139db7 Tests: Send perp markets as health accounts 2022-05-29 20:50:21 +02:00
Christian Kamm b1fcb4a7e6 CreateGroup: Allow multiple groups per admin 2022-05-27 11:36:50 +02:00
microwavedcola1 ed4e63a82f Change tuple to a struct, seemingly anchor ts doesnt support tuples
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-24 22:03:35 +02:00
Christian Kamm 53a5e208fd margin_trade: loan origination fees, limited withdraws 2022-05-23 08:55:30 +02:00
Christian Kamm 21af012d1f Improvements to margin_trade
- don't hard-code the group as the first passed account
- token::approve() banks for each token vault
- sign for each bank
- deal with using tokens without an existing position
- handle deactivation of token account if balance goes to 0
2022-05-20 10:16:09 +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 6ecd4a0da9 Update funding for keeper
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-17 15:59:47 +02:00
microwavedcola1 fac9b4a57a perp funding
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-17 10:07:24 +02:00
microwavedcola1 db82fcbbcc perp cancel order instructions
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-16 10:49:11 +02:00
microwavedcola1 ee6fe93b26 Fix tests
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-16 10:49:11 +02:00
microwavedcola1 81f0f38188 ts client support for perps
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-11 20:06:07 +02:00
microwavedcola1 15961ec81c fees for borrows
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-09 11:14:50 +02:00
microwavedcola1 5266668bc2 keeper: consume events
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-06 14:19:49 +02:00
microwavedcola1 9f5a2fd32e add a test for consume events, add debug impl for mango account for easy debugging in tests
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-05 10:25:32 +02:00
microwavedcola1 7ead988ba4 small ticker size
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-12 20:38:35 +02:00
microwavedcola1 e3a60a637a format
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-12 17:35:39 +02:00
microwavedcola1 62ee1bc5c0 prepare for multiple ts packages
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-12 17:28:47 +02:00
microwavedcola1 03ae43017c account, market and bank names
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-12 16:19:58 +02:00
microwavedcola1 1b1dd1a541 poc keeper
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-09 21:18:07 +02:00
microwavedcola1 5ab48fb6e0 rust: Fix args in tests to more realistic values, ts: expose args, update idl
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-09 17:09:06 +02:00
microwavedcola1 57d9de86c8 comment
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-09 16:55:00 +02:00
microwavedcola1 257ccf76ad multi legged interest rates + keeper ix
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-09 16:53:30 +02:00
microwavedcola1 884d638e36
Merge pull request #33 from blockworks-foundation/mc/stub-oracle-ext
Mc/stub oracle ext
2022-04-03 05:36:24 +02:00
microwavedcola1 ace5df2a85 revert unintended changes
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-03 05:21:16 +02:00
microwavedcola1 d7a8c5c91d add todo
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-02 21:04:00 +02:00
microwavedcola1 77ddbd4eeb fix test
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-02 21:02:48 +02:00
microwavedcola1 c7d3103e6b --wip-- [skip ci] 2022-04-02 20:42:17 +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 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 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 10ab9804d1 Rename perp instructions to have perp_ prefix 2022-04-01 08:01:56 +02:00
Christian Kamm 8038f9e257 Add CloseAccount instruction to make testing easier 2022-03-31 17:22:56 +02:00
Christian Kamm 9cf4f1a748 Rearrange MangoAccount to avoid padding bytes 2022-03-31 14:01:08 +02:00
Christian Kamm 85b0b420d4 Disable address lookup tables
Because the ALT program isn't available on devnet yet, so prohibits
testing there.
2022-03-31 09:25:47 +02:00
Christian Kamm afbfd3b7f9 serum3_register_market: better validation
Previously we just trusted the base and quote token index to be correct,
now the appropriate banks are validated.
2022-03-30 12:24:49 +02:00
Christian Kamm 14d4147efa liq test: Cover more cases 2022-03-30 09:37:31 +02:00
Christian Kamm d6ebffd346 liq: functionality fixes and test 2022-03-29 17:47:19 +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 a6ff388e20 health: avoid divisions, reducing compute needs 2022-03-27 14:47:42 +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 b139f6beab ask example test
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-26 17:27:50 +01:00
microwavedcola1 b851dd13ad add new ask
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-26 17:06:55 +01:00
microwavedcola1 223179b278 basic test to measure cu
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-26 06:16:52 +01:00
microwavedcola1 0e953f5e80 more
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-24 19:15:46 +01:00
microwavedcola1 f895467bf5 weights
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-24 17:29:30 +01:00
microwavedcola1 ba4300accc simplify
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-24 14:40:08 +01:00
microwavedcola1 f7fb9b7e35 add event queue
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-23 07:53:45 +01:00
microwavedcola1 3443ab0d70
Merge pull request #27 from blockworks-foundation/mc/ci
checked math
2022-03-22 11:47:10 +01:00
microwavedcola1 237d776e2b fix test cu requirement
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-22 11:33:06 +01:00
microwavedcola1 974724cfe1 fix some clippy warnings
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-22 11:19:12 +01:00
Christian Kamm 43eba0a529 Serum: Test for force cancel orders 2022-03-22 09:25:13 +01:00
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 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
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 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
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 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 1953d12f0f Health: expect serum open orders accounts 2022-03-16 13:42:29 +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 baa980c659 PlaceSerumOrder: Track vault balances before and after 2022-03-15 14:44:47 +01:00
Christian Kamm 6b342ffeb9 PlaceSerumOrder basic test 2022-03-14 17:21:16 +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 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
Christian Kamm 693ac17996 Serum: Store open orders pubkey in account 2022-03-11 17:50:04 +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
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 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 01e8458093 Tests: Read banks/oracles from address lookup table 2022-03-01 15:12:53 +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 d9c7260375 code review
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-01 06:28:12 +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 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 e8b1563223 optimise imports
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 11:07:04 +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 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