Commit Graph

870 Commits

Author SHA1 Message Date
Christian Kamm d9a9c7d664
liquidation: Add flag to disable asset liquidation (#867)
This can be used to remove the oracle dependency for tokens with zero maint asset
weight that are not borrowable.
2024-02-07 12:52:01 +01:00
Christian Kamm a4cddf3129
deposit limit: always allow obv1-selling deposits (#869)
Previously serum3_place_order would fail when deposit limits were
exhausted on the payer token side. Now the failure only happens when
payer tokens need to be borrowed.
2024-02-05 13:06:06 +01:00
Christian Kamm ae5907ba3a
fix perp settle limit materialization (#865)
Previously, we tried to keep track of "other" and "trade" realized pnl.
An issue occured when a perp base position went to zero: the way we
computed the trade pnl included potential non-trade unsettled pnl.

That caused follow-up trouble because the value could change sign and
reset the settle limit for trade pnl.

This change aims to simplify in some ways:
- explicitly talk about oneshot-settleable pnl (fees, funding,
  liquidation) and recurring-settleable pnl (materialization of settle
  limit derived from the stable value of the base position when reducing
  the base position)
- instead of directly tracking realized settleable amounts (which
  doesn't really work), just decrease the recurring settleable amount
  when it exceeds the remaining unsettled pnl
- get rid of the directionality to avoid bugs of that kind
- stop tracking unsettled-realized trade pnl (it was wrong before, and
  no client uses it) - we already track position-lifetime realized trade
  pnl
2024-02-01 11:23:45 +01:00
Christian Kamm 719aee37ae delegate withdraw: require target to have expected owner 2024-01-29 15:13:29 +01:00
Christian Kamm afc2ff9e80 allocator: Don't allow growth beyond heap memory region 2024-01-29 15:13:29 +01:00
GoodDaisy 2f10a710c9
chore: fix typos (#854) 2024-01-29 13:39:33 +01:00
Christian Kamm fcc8c85f6e
perp: Add platform liquidation fee for base (#858) 2024-01-26 10:24:20 +01:00
Lou-Kamades db98ba5edf
Use fallback oracles in Rust client (#838)
* rename usd_opt to usdc_opt in OracleAccountInfos

* use fallbacks when fetching bank+ price in AccountFetcher struct

* feat: add derive_fallback_oracle_keys to MangoGroupContext

* test: properly assert failure CU in test_health_compute_tokens_fallback_oracles

* provide fallback oracle accounts in the rust client

* liquidator: update for fallback oracles

* set fallback config in mango services

* support fallback oracles in rust settler + keeper

* fix send error related to fetching fallbacks dynamically in tcs_start

* drop derive_fallback_oracle_keys_sync

* add fetch_multiple_accounts to AccountFetcher trait

* revert client::new() api

* deriving oracle keys uses account_fetcher

* use client helpers for deriving health_check account_metas

* add health_cache helper to mango client

* add get_slot to account_fetcher

* lint

* cached account fetcher only fetches uncached accounts

* ensure keeper client does not use cached oracles for staleness checks

* address minor review comments

* create unique job keys for CachedAccountFetcher.fetch_multiple_accounts

* fmt

* improve hashing in CachedAccountFetcher.fetch_multiple_accounts

---------

Co-authored-by: Christian Kamm <mail@ckamm.de>
2024-01-23 10:26:31 -06:00
Christian Kamm 40b6b49680 Test: Max borrow with init asset weight scaling 2024-01-22 12:56:37 +01:00
Christian Kamm 8383109f0d
Add a token-token platform liquidation fee (#849)
The liqor liquidation fee and platform liquidation fee for the asset and
liab token are both payed by the liqee.

The platform liquidation fee is added to the Bank's
collected_fees_native and tracked in collected_liquidation_fees.
2024-01-19 16:34:55 +01:00
Christian Kamm 18729cf04c
Configurable interest rate for 0% utilization (#848) 2024-01-15 12:45:00 +01:00
Christian Kamm 53bc52efe7
Update openbook v1 fast listing default parameter (#841) 2024-01-09 15:14:52 +01:00
Christian Kamm ce0713070a Merge remote-tracking branch 'origin/deploy' into dev 2024-01-09 12:31:20 +01:00
Christian Kamm 857dcb397f
Allow fast listing admin to register openbook v1 markets (#839) 2024-01-08 14:18:43 +01:00
Lou-Kamades 9ce6b67831
Add an Orca oracle type (#813)
* deps: add whirlpool crate

* allow oracle to read price from Orca CLMM

* test: add test for raw orca CLMM price

* require the USD/USDC oracle when using a CLMM oracle

* test: add CLMM oracle tests

* use KeyedAccountReader instead of AccountInfoRef for fallback fetching functions

* calculate price for inverted orca pools

* ensure that Orca fallback oracles have USDC side

* remove unused Whirlpool impl

* clmm prices have correct decimals and pyth update slot

* manually deserialize the orca Whirlpool

* refactor: use OracleAccountInfos when checking oracle price

* properly handle inverted clmm prices

* update rs client with OracleAccountInfos struct

* refactor: simplify OracleAccountInfos impl

* add clmm oracle integration test

* use OracleAccountInfos::from_reader in account_retriever

* CLM oracles inherit deviation from supplementary quote oracle

* review fixes

* use f64 division for clmm sqrt price

* standardize fixed to f64 conversion

* review fixes
2024-01-04 11:29:54 -06:00
Britt Cyr 797e866f04
Add a type to the perp cancel order instructions when not found (#833) 2024-01-04 16:00:54 +01:00
Christian Kamm 34aebf01f2
oracle: don't force logging in OracleState functions (#828)
The msg!() caused writes to stdout in the liquidator etc in codepaths
that just wanted to check if the oracle was usable.
2024-01-03 08:37:35 +01:00
Christian Kamm f10fc01388
Fix idl generation, update it (#834) 2024-01-03 08:36:19 +01:00
Christian Kamm 30e639fe84 Bank: require borrows <= deposits
- require borrows <= deposits, even if vaults have more tokens
- change min_vault_to_deposits_ratio to be about max utilization

Reviewed and audited as part of the v0.21.1 release, original
commit was 5c2f857112
2024-01-02 11:05:58 +01:00
Christian Kamm 0e3b52b0ef Clamp utilization at 100%
To avoid excessive interest rates or interest curve moves.

Reviewed and audited as part of the v0.21.1 release, original
commit was 3914e48c24
2024-01-02 11:05:22 +01:00
Christian Kamm 79ddbf21f1
Liquidation: Use asset and liab liq fee (#825) 2023-12-28 10:46:43 +01:00
Maximilian Schneider e83052a036
helpers for estimating order sizes (#823) 2023-12-27 09:56:54 +01:00
Christian Kamm 428e71e07f
Allow delegates to withdraw small token amounts (#820)
- if they're withdrawing to the owner's ata
- if they're closing the token position
- if the amount is small
2023-12-20 11:15:47 +01:00
Christian Kamm b5614e98c3
test: Add interest rate test (#818) 2023-12-20 11:15:29 +01:00
Christian Kamm 7655a87404
Perp: Always allow users to free perp open order slots (#817)
Previously, freeing would be impossible if a canceling fill or out event
was already in-flight - then the order would no longer be on the
orderbook.

Now, FillEvent and OutEvent store the order id and can check if the open
order slot on the account has been reused already. That allows canceling
orders to always free up the user slot immediately.
2023-12-20 11:15:10 +01:00
Christian Kamm 86334020e2
Use custom allocator for the program (#801)
To allow making use of extended heap sizes.
2023-12-20 11:10:18 +01:00
Christian Kamm 27b1ceebe8 Accounts: Expect only the v3 MangoAccounts now (#783) 2023-12-19 10:08:46 +01:00
Christian Kamm 64d6c8c3c4
Add doc comments for new fields (#819) 2023-12-18 17:41:17 +01:00
Christian Kamm 99cb3d4f4c liquidator: Pick better asset/liab for liq_token 2023-12-15 11:40:25 +01:00
Christian Kamm 05f03f4ed8
test: Add one for migrating interest rates for v0.21 (#816) 2023-12-12 11:28:37 +01:00
Christian Kamm d6f46bec70 Fix program tests after cherry-picks 2023-12-07 13:23:18 +01:00
Christian Kamm 509afb01b6 adjust token_register_trustless params (#810)
- since there's no borrowing or asset weight, don't put staleness or
  confidence restrictions on the oracle
- disable the tcs fees, they are not enabled anywhere yet

(cherry picked from commit 5f8f717430)
2023-12-06 16:48:00 +01:00
Christian Kamm 5f8f717430
adjust token_register_trustless params (#810)
- since there's no borrowing or asset weight, don't put staleness or
  confidence restrictions on the oracle
- disable the tcs fees, they are not enabled anywhere yet
2023-12-06 16:46:57 +01:00
Christian Kamm db4e486643 Bump program version to v0.21.0 and update idl 2023-12-05 15:57:42 +01:00
Christian Kamm e7bfa4e03e Deposit limits (#806)
- limit deposits (via deposit, flash loan, tcs)
- limit potential deposits via openbook settle
  by restricting placable orders via potential_serum_tokens
- introduce Serum3PlaceOrderV2 for this purpose
- account for new limits in liquidator, max_swap

(cherry picked from commit 42e31ae859)
2023-12-05 15:57:26 +01:00
Christian Kamm f533d65a58 Openbook token tracking and price bands (#805)
- track min bid, max ask
- track maximal token outflow from oo
- add serum3_place_order_v2 with mutable receiver bank
- placing openbook orders is restricted to a certain distance from the
  oracle

(cherry picked from commit 81501837a9)
2023-12-05 15:48:57 +01:00
Christian Kamm 42e31ae859
Deposit limits (#806)
- limit deposits (via deposit, flash loan, tcs)
- limit potential deposits via openbook settle
  by restricting placable orders via potential_serum_tokens
- introduce Serum3PlaceOrderV2 for this purpose
- account for new limits in liquidator, max_swap
2023-12-05 15:43:38 +01:00
Christian Kamm 81501837a9
Openbook token tracking and price bands (#805)
- track min bid, max ask
- track maximal token outflow from oo
- add serum3_place_order_v2 with mutable receiver bank
- placing openbook orders is restricted to a certain distance from the
  oracle
2023-12-05 15:39:24 +01:00
Christian Kamm e2c9cf2de0 tests: drop extra debug output 2023-12-05 11:16:09 +01:00
Christian Kamm ce71c67a88 Bump program version to v0.22 2023-12-05 11:15:50 +01:00
Christian Kamm 99790a01e4 revert trustless token registration params to conservative defaults (#804)
This mostly reverts commit 33bc278a2c.

(cherry picked from commit 361ba23df1)
2023-12-05 10:14:48 +01:00
Christian Kamm 04f0f55aa5 Disable TokenAddBank instruction (#803)
It was unused for a long time and it should be reevaluated before being
used.

(cherry picked from commit f03944b5dd)
2023-12-05 10:14:36 +01:00
Christian Kamm 361ba23df1
revert trustless token registration params to conservative defaults (#804)
This mostly reverts commit 33bc278a2c.
2023-12-05 10:13:55 +01:00
Christian Kamm f03944b5dd
Disable TokenAddBank instruction (#803)
It was unused for a long time and it should be reevaluated before being
used.
2023-12-05 10:12:50 +01:00
Lou-Kamades 838df8cd7c
Merge pull request #790 from blockworks-foundation/lou/fallback-oracle
Add fallback oracles
2023-12-01 12:59:38 -06:00
Lou-Kamades 25aa422e2d also log primary oracle when fallback errors 2023-12-01 12:44:35 -06:00
Britt Cyr 68944747e0
Add serum3 cancel by client order id instruction (#798) 2023-12-01 13:36:29 +01:00
Lou-Kamades ab9d3c37b4 check serum OO headers in ScanningAccountRetriever 2023-11-30 11:03:24 -06:00
Lou-Kamades b19678f874 use a Vec for fallbacks in ScannedBanksAndOracles 2023-11-29 01:03:48 -06:00
Lou-Kamades 59001b3631 reduce CU cost of fallback oracles 2023-11-28 22:55:19 -06:00