Commit Graph

50 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
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
Lou-Kamades 59001b3631 reduce CU cost of fallback oracles 2023-11-28 22:55:19 -06:00
Lou-Kamades 20261bf734 test: add fallback oracle withdrawal test 2023-11-22 11:35:26 -06:00
Christian Kamm 12d74789ef
cli: save-snapshot command (#773) 2023-11-08 10:27:55 +01:00
Christian Kamm 643a997723
Oracles: Fix units of deviation in OracleState (#675) 2023-08-11 16:47:52 +02:00
Christian Kamm 4f810edebc
Allow token withdraws/deposits even with stale oracles (#646) 2023-08-07 16:15:45 +02:00
Christian Kamm e535e81257
Pyth: Read agg.price or prev_price, depending on staleness (#631)
This updates our use of pyth oracle accounts to be more in line with
what the pyth sdk is doing.
2023-07-05 12:58:42 +02:00
Christian Kamm dd56881a41 Revert "Pyth oracles: Check that status is "trading" (#607)"
This reverts commit bbf0186398.
2023-07-04 11:08:48 +02:00
Christian Kamm 35064d4ab0
Token conditional swaps (#604)
Users can request token swaps to happen when the oracle price
is within a price band. Once the price is right, an executor can
trigger the swap. The executors are rewarded with a premium
over the oracle price.

This allows limit and stop loss orders on arbitrary spot pairs.

The PR comes with basic ts support and adjustments to the liquidator,
to execute available token conditional swaps.

Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
2023-07-03 14:09:11 +02:00
Christian Kamm bbf0186398
Pyth oracles: Check that status is "trading" (#607) 2023-06-15 10:43:44 +02:00
Christian Kamm 5a05e9cb2e
Update anchor to v0.27.0, stop using submodule (#582) 2023-05-12 13:54:53 +02:00
Nicholas Clarke c0ea9970b6
Clarkeni/oracle confidence (#568)
* Add oracle confidence and oracle type to update funding logs.

* Return price and OracleState struct from oracle_price_and_state.
2023-05-05 23:44:14 -07:00
Nicholas Clarke 37ae7549fb
Clarkeni/perp trade logging (#535)
* 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).
2023-04-13 10:50:39 -07: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
microwavedcola1 be15f54225
agg pub slot was recent even if price was not updated, switch to last slot which seems more relevant (#393)
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-01-17 14:48:06 +01:00
Christian Kamm 375b2b3fb3
Use bytemuck::Pod derives to check for accidental padding (#317) 2022-12-06 09:25:43 +01:00
microwavedcola1 25312bc398
struct layout reorg + reserved pass (#315)
* reorder structs + review reserved space + split const assets into individual fields for correct checking
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* Fixes from review

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

* Fixes from review

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

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-12-05 15:23:20 +01:00
Christian Kamm 2ee152f7ea Oracle staleness: Check when accessing oracle price 2022-11-12 12:12:45 +01:00
Christian Kamm 58f7ff2e0e Add staleness param to OracleConfig
Since Bank can't expand the existing OracleConfig, add a new one to Bank
and (temporarily!) copy over the old value to the new one in
TokenUpdateIndexAndRate.

Add some reserved space to OracleConfig to make this easier in the
future.

Breaks the PerpMarket and PerpPosition layouts
2022-11-12 12:11:09 +01: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 3128115dca PerpMarket: Add helper for getting oracle price 2022-09-06 14:26:06 +02:00
Christian Kamm 7a343a9a8d checked_math: support casts and I80F48::from 2022-08-14 15:01:15 +02:00
Christian Kamm d91a676e3d Oracle: Decimal constant cleanup 2022-08-14 15:01:15 +02:00
microwavedcola1 c516e45d08
mc/review reserved on accounts (#130)
* review and extend reserved on accounts

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

* revert changes to node size, stack gets smashed in rust unit tests

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

* max possible

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

* max

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

* Fixes from review

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

* header version

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

* Fix from review

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>

* fix from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-01 16:53:30 +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
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
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 470292024e
Filter out bad switchboard prices (#70)
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-20 18:03:16 +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
Christian Kamm b3568b7f3e
Make health/oracle functions usable from clients (#63)
* Make health/oracle functions usable from clients

By creating a shared trait that is implementable for AccountInfo and
AccountSharedData.

* Health: fixup tests
2022-06-08 13:43:12 +02:00
microwavedcola1 47bccfeec8 Fix oracle price decimal usage
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-06-02 19:16:30 +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
microwavedcola1 717b72857d
Remove anchor dummy type workaround (#53)
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-18 17:16:14 +02:00
microwavedcola1 9debc63a6a
update idl, add tokenmint to stuboracle for gpa (#34)
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-03 05:43:32 +02:00
microwavedcola1 c7d3103e6b --wip-- [skip ci] 2022-04-02 20:42:17 +02:00
microwavedcola1 f135ca4d9b fix clippy warnings
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-23 09:33:51 +01:00
Christian Kamm 6aa4724b45 Serum: Health computation first steps 2022-03-16 16:45:54 +01:00
microwavedcola1 6702cdbba6
mc/pyth (#14)
* pyth integration

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-02 21:11:05 +01:00
microwavedcola1 d9c7260375 code review
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-01 06:28:12 +01:00
microwavedcola1 12d2a9f962 make clippy happy
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 12:56:26 +01:00
microwavedcola1 1c47f0d004 add ix handling for stub oracles
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 12:37:12 +01:00
microwavedcola1 3355ed1dcf dont need special crate for this
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 11:18:55 +01:00
microwavedcola1 e8b1563223 optimise imports
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 11:07:04 +01:00
microwavedcola1 3648cba0d0 use discriminator to differentiate between oracles, removes need for a magic constant, same could be done for other oracles
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 11:05:15 +01:00
microwavedcola1 6345d3ebd4 add todo
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 10:45:03 +01:00
microwavedcola1 c0c115bd03 remove unused
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 10:44:08 +01:00
microwavedcola1 823fbeb6b5 stub oracle ix and account state
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-02-28 10:36:31 +01:00