* Emit the slot corresponding to the oracle price to PerpUpdateFundingLog.
* Emit a new FilledPerpOrderLog consisting of just the group, perp market and seq num. This will be used to correlate perp fills to the transactions they were matched (not consumed).
To do that, split up the Accounts objects and the instruction
implementations.
GPL code is only used when the "enable-gpl" feature is enabled. That
means compiling the program or running tests need explicit feature
activation now.
Due to the safety features in v4, the init health can differ from maint
health a lot more than it used to in v3. This is because of stable-price
adjusted oracle prices used in init health, and the weight scaling based
on total deposits and borrows used in init health.
The effect is that once an account becomes liquidatable, it could be
liquidated a lot until it reaches init>=0.
The original idea of liquidating until init>=0 was just to provide some
buffer, such that liquidated accounts wouldn't immediately become
liquidatable again.
This patch decouples the buffer idea explicit from init health by
creating a new LiquidationEnd health type. Liquidation proceeds until
the LiquidationEnd health becomes positive.
Co-authored-by: microwavedcola1 <89031858+microwavedcola1@users.noreply.github.com>
* return order id from a perp place order ix
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* fix
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* fixes from review
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This gives us better compatibility with released anchor versions.
Instead of using AccountLoaderDynamic<MangoAccount>, we now use
a standard AccountLoader<MangoAccountFixed>. This will generally work
(except for load_init(), which is dangerous).
A new trait, MangoAccountLoader, provides load_full(), load_full_mut()
etc on the AccountLoader<MangoAccountFixed> to create accessor structs
that can read and write to the dynamic part of the mango account data.
It is tracked in the StablePriceModel and updated on
TokenUpdateIndexAndRate and PerpUpdateFunding instructions.
The stable price is used in health computations.
This introduces the ability to use oracle peg orders on perp markets.
This PR has significant non-backwards compatible changes, for example all
order trees are now in a single account instead of separate.
* 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
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.
Instead, check for any liquidatable assets in liq_token_bankruptcy.
Bankrupt accounts may use the same operations as any other
negative-health account.
* 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>
* Make health/oracle functions usable from clients
By creating a shared trait that is implementable for AccountInfo and
AccountSharedData.
* Health: fixup tests