Commit Graph

17 Commits

Author SHA1 Message Date
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
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
Lou-Kamades 59001b3631 reduce CU cost of fallback oracles 2023-11-28 22:55:19 -06:00
Lou-Kamades 2b0a0e3a3e add fallback CU and serum tests 2023-11-22 16:40:48 -06:00
Lou-Kamades a0a47af6a4 ScanningAccountRetriever uses fallback oracles 2023-11-22 11:35:26 -06:00
Lou-Kamades 20261bf734 test: add fallback oracle withdrawal test 2023-11-22 11:35:26 -06:00
Christian Kamm 93d85c3f71
Bank: allow maint weights to change over time (#780)
- token_edit can set it up to gradually scale to new target values
- security admin can abort an ongoing change via token_edit
- all health computations are now time dependent and get the weight
  based on it
- when the change is done, the keeper "cleans up" and moves the new
  values into the default fields
2023-11-14 14:52:04 +01:00
Christian Kamm dfde7ec43f
serum health: use lower-precision division (#750)
This saves around 1/3rd of the compute for active serum markets.
2023-10-11 15:19:24 +02:00
Christian Kamm 20eb02af01
program-test improvements: performance, cu test output, warnings (#749)
* tests: Upgrade tx log capturing

Instead of overriding the system logger to intercept the logs, we can
now ask solana to return the logs of a tx execution directly.

This speeds up tests a lot because we don't need to hold a global lock
on tx execution anymore!

* tests: Improve token, serum, perp cu test
* benchmark: add a few more operations
2023-10-11 15:18:23 +02:00
Christian Kamm f63163d737
Account limits: Prefer 4 perp + 4 serum (#689) 2023-08-21 16:26:49 +02:00
Christian Kamm a151ebcf11
Account size: restict more, but only increases (#688)
* Account size: Don't fail on unrelated resize

If the account was previously resized to larger than is allowed now,
don't fail unrelated resizes.

* Further reduce account size limits

Out of caution and future-proofing. Can always raise again.

Perp settle pnl needs 6 accounts plus 2 health account lists that could
be nearly fully disjoint.
2023-08-21 14:34:52 +02:00
Christian Kamm 34a875d968
Restrict account growth (#686)
Because of the 64-accounts-per-tx limit. Making a single account use
more than half of these could be problematic.
2023-08-19 08:20:40 +02:00
Maximilian Schneider c006948319
Enable self-trading protection (#533)
Co-authored-by: Christian Kamm <mail@ckamm.de>
2023-05-15 10:40:41 +02:00
Christian Kamm 5c7a2e3e10
Use the overflow-checks=true equivalent with the fixed crate (#476)
* Vendor `fixed` crate to have checked math in release mode
* remove all cm!()
* drop superfluous parens
* drop use of checked_math crate
* manual removal of redundant checked_* functions
2023-02-24 11:56:33 +01:00
Christian Kamm 257aeb298c
Enable release-mode overflow checks (#438)
The checked_math macro is still needed for I80F48 though
2023-02-06 08:33:08 +01:00
Christian Kamm a91a9ae998
Perp: Fix liq instructions (#424)
- Rename to perp_liq_base_or_positive_pnl and perp_liq_negative_pnl_or_bankruptcy
- Deal with situations where overall asset weight is zero and base position reduction
  would not improve liqee health
- Add ability for liqors to take over positive unsettled pnl if that improves liqee health
2023-02-02 09:00:37 +01:00
Christian Kamm d3cbb9e2ec
Create a single rust test binary (#425)
Speeds up the linking step, needs way less disk space for test binaries
and executes tests significantly faster.

Test execution went from 35s -> 29s for me and compilation improved a
lot.
2023-01-30 21:09:47 +01:00