Commit Graph

77 Commits

Author SHA1 Message Date
Christian Kamm b3aabfadfc
Perp: Clarify has_open_orders use during liquidation (#412) 2023-01-23 10:45:45 +01:00
Christian Kamm 7d74c5a6a6 Liquidator: Change metric printing interval to 10min 2023-01-18 12:28:43 +01:00
Christian Kamm ff90c85874
Liquidator: reduce perp base pos if possible (#398)
- send reduce-only ioc order if possible
- settle pnl if needed
- deactivate position
2023-01-18 10:50:23 +01:00
Christian Kamm 93d33edb74
Perp: liq with token instruction (#368)
The new instruction allows the liqor to take over negative pnl (limited
by liqee settle health and settle limits) before applying the bankruptcy
logic.
2023-01-12 09:07:13 +01:00
Christian Kamm 31bd72e84a Drop AccountLoaderDynamic
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.
2022-12-29 17:40:08 +01:00
Christian Kamm 21c13fa9b1 liquidator: Skip accounts with many errors in short time 2022-12-20 14:30:26 +01:00
Christian Kamm 4bd1cf1ece liquidator: Shuffle liquidation check
This way the liquidator is less likely to get stuck on one account if
there are multiple that need liquidation.
2022-12-20 14:13:02 +01:00
Christian Kamm fb43ec0e7f liquidator: Don't panic when accounts not yet available
This can happen when users created a new serum open orders account and
it has not yet been received even though the account itself has arrived.
2022-12-20 14:13:02 +01:00
Christian Kamm 69cb21026d Rebalance: Don't use Jupiter's ExactOut method
It has limited liquidity.
2022-12-19 15:31:25 +01:00
Christian Kamm 55e8fc390f Liquidation: Ignore dust balances and perp pnl
Liquidation and perp pnl settlement may not bring spot amounts to
exactly zero. Having a small spot amount < 1 native token can otherwise
make the liquidation get stuck and not move one to the next phase.
2022-12-19 12:49:09 +01:00
Christian Kamm 5a38506f04
Liquidator, liqtest and rust client fixes (#336)
Liquidator, liqtest and rust client fixes

- Make rust MangoClient fully async
- Update and improve liquidation test setup scripts
- Update liquidator to use versioned transactions
- Update liquidator to use mango and jupiter account lookup tables
- Use jupiter v4 api to get versioned transactions

Perp liquidation is still not fully good. See discussion aboult perp_liq_pnl_with_token.
2022-12-16 13:10:46 +01:00
Christian Kamm 0ed7175341 Upgrade to solana ~1.14.9
- Update anchor submodule
- Fork and submodule switchboard-v2 package to update dep
2022-12-13 17:00:57 +01:00
Christian Kamm a29a736ba2 Move src/state/health/ -> src/health/ 2022-12-08 20:48:44 +01:00
Christian Kamm e0c403dcb9
Client: consider borrow limits in max-swap (#316) 2022-12-06 09:25:24 +01:00
riordanp 748334d674
Fix liquidator (#302)
* Fix liquidator

* Remove redundant variable.

Co-authored-by: Nicholas Clarke <nicholasgclarke@gmail.com>
2022-11-22 07:10:23 +01:00
riordanp 5d780a86dc
Upgrade to Solana 1.10.35 (#291)
* 1.10.35 upgrade & compatibility

* Patch Anchor

* Fix test compile

* Serum program update

Co-authored-by: Christian Kamm <mail@ckamm.de>
2022-11-16 10:50:40 +00:00
Christian Kamm 2ee152f7ea Oracle staleness: Check when accessing oracle price 2022-11-12 12:12:45 +01:00
Riordan Panayides 16c38975d5 Fix typo 2022-11-04 17:03:59 +00:00
silas d54f957cb4
Run as least privilege user 2022-10-26 20:27:31 +01:00
Christian Kamm 7e180c7b3a Perps: Support trusted markets 2022-09-29 15:40:31 +02:00
Christian Kamm 8ba52f46c2
Perp settle pnl: incentive for settler (#252)
This adds three new options to perp markets:
- a flat fee, that is paid for all perp settlements
- given that they exceed the configured min settle amount threshold to
  be eligible for fees
- and a fractional fee, that only applies when the benefiting account
  has low health and gradually becomes bigger as the account slides
  towards liquidation
2022-09-29 12:59:55 +02:00
Christian Kamm 984695e8d0 liquidator: Call liq_perp_bankruptcy 2022-09-29 07:36:00 +02:00
Christian Kamm 15d0a98c94 liquidator: settle pnl on liquidatable accounts 2022-09-28 10:48:41 +02:00
Christian Kamm 11daf4d0eb client: fetch top settle pnl counterparties 2022-09-28 10:48:41 +02:00
Christian Kamm 9cbc352197 liquidator: force-cancel perp orders, liq perp base positions 2022-09-28 10:47:05 +02:00
Christian Kamm a41a245e24 PerpLiqBankruptcy instruction 2022-09-21 09:46:54 +02:00
conj0iner 1c67b8ed5f
remove base_token_index from perps and include oracles (#224)
Co-authored-by: Conj0iner <conj0iner@users.noreply.github.com>
2022-09-21 09:42:45 +02:00
Christian Kamm 11160ae2fe Health: Pass price to max_swap_source_for_health_ratio
Because it's not correct to think we'll always swap at oracle price.
That was an ok assumption for liquidations, where we'll swap at slightly
better than that, but not for jup.
2022-09-20 10:41:33 +02:00
Christian Kamm b1940eea43 Liquidator: Reduce likelihood of double-sending rebalancing tx 2022-09-02 12:24:28 +02:00
Christian Kamm 8bde9e2bff Liquidator: Force cancel serum orders 2022-09-02 12:23:59 +02:00
Christian Kamm 1f0cd62846 Don't panic if accounts are shorter than 8 bytes 2022-09-01 12:00:09 +02:00
riordanp 3cca63c735
Docker CI Improvements (#195)
* Push separate images for binaries to GCR

* Add base image version arg to heroku deployment

* Test docker build

* Try setting mode

* Fix tags

* switch back to dev

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

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-31 11:37:58 +02:00
Christian Kamm 8a2d54cce8 Fix some clippy warnings 2022-08-30 13:59:34 +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 09fc5f716b Renames in MangoAccount
- Accessors in MangoAccountValue
- PerpPositions -> PerpPosition
2022-08-19 14:58:20 +02:00
Christian Kamm 4c65204c19 Liquidator: Fix condition for starting to liquidate 2022-08-16 16:19:04 +02:00
Christian Kamm 82864e5f6f Liquidator: disable allow-borrow, now that fixed program is deployed 2022-08-16 12:13:54 +02:00
Christian Kamm af5f622bd8 Liquidator: bankruptcy requires borrows 2022-08-16 12:13:54 +02:00
Riordan Panayides 8335c5495e Fix liquidator command 2022-08-12 15:31:53 +01: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 b52aad82e1 Liquidator: more pyth -> oracles renames 2022-08-10 16:24:48 +02:00
Christian Kamm 405c41edcf Liquidator: Fix rebalance to empty token accounts
By withdrawing to the liqor wallet if necessary.
2022-08-10 16:24:48 +02:00
Christian Kamm 7fcee1af96 Liquidator: reload account between rebalance steps 2022-08-10 16:24:48 +02:00
Christian Kamm 38f5502dc7 Liquidator: round up when paying back borrows to close token pos 2022-08-10 16:24:48 +02:00
Christian Kamm 2552bffc66 Liquidator: blocking-wait for data after actions
To avoid sending a second jupiter-swap while the first one is still
in-flight.
2022-08-10 16:18:41 +02:00
Christian Kamm cce1881223 Liquidator: basic sell/buy to keep only quote 2022-08-10 16:18:41 +02:00
Christian Kamm 5c40c12cf5 Liquidator: cleanups 2022-08-10 16:18:41 +02:00
Riordan Panayides 3a4327f50d Change registry URL, tidy up diff 2022-08-08 23:34:15 +01:00
riordanp 5af39e7956
Merge branch 'dev' into mc/docker 2022-08-08 20:54:31 +01:00
microwavedcola1 24c359ef92
keeper token rate update - group multiple ixs into one (#151)
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-08 13:40:33 +02:00