Commit Graph

911 Commits

Author SHA1 Message Date
Serge Farny 7e3a72048e
Program: fix openbook-v2 integration tests (stack overflow issue) (#950) 2024-04-23 11:06:07 +02:00
Christian Kamm ec2d10af6e
Allow the insurance fund to be for any bank (#946)
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
2024-04-23 09:17:53 +02:00
riordanp 2a6532f1c6
Openbook V2 Integration (#836)
Co-authored-by: Tyler <tjshipe@gmail.com>
Co-authored-by: Christian Kamm <mail@ckamm.de>
Co-authored-by: Serge Farny <serge.farny@gmail.com>
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
2024-04-22 11:37:53 +02:00
Serge Farny fe86295d3c
program; fix health check ix gate (#940) 2024-04-11 07:22:29 +02:00
Serge Farny 75a07e986a
program: remove delegate account withdrawal limit (#939)
This is necessary for new liquidator feature of rebalancing using limit orders:
We need to close the token and market slot so that it's available for new liquidation, but at the same time, it's possible that the min order quantity for a given market is still bigger than allowed max withdrawal.
2024-04-10 15:24:39 +02:00
Christian Kamm 653cf9f30b
token_withdraw: avoid silencing errors with is_ok() (#936) 2024-04-08 16:28:25 +02:00
Christian Kamm 9df73a0dfd
Audit: Remove unused fn, add comments (#935) 2024-04-08 15:14:52 +02:00
Serge Farny f54bb6f0b0
Serge/liquidator split tcs and liquidation (#914)
liquidator: split TCS triggering and liquidation job

Concurrent execution of candidate lookup and tx building/sending
- Also added an health assertion IX to protect liqor in multi liquidation scenario
- And a timeout for jupiter v6 queries (avoid blocking liquidation because of slow TCS)
2024-03-20 15:25:52 +01:00
Serge Farny 769f940a66
program: fix health check ix (#918) 2024-03-18 17:52:51 +01:00
Christian Kamm 6f85dfa42d Merge remote-tracking branch 'origin/deploy' into dev 2024-03-14 11:26:33 +01:00
microwavedcola1 928ac343f8 Fix merge errors
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2024-03-12 11:27:30 +01:00
Serge Farny b3b4cc8223
program: add a min health check (#913)
add a min health check
2024-03-12 08:27:40 +01:00
Christian Kamm 4fcaf09c09
test: Allow replay of live transaction in program test (#911) 2024-03-11 15:08:58 +01:00
Christian Kamm 61117ccd11
withdraw: replace overflow with better error (#910) 2024-03-11 14:02:54 +01:00
Serge Farny 0728bb566f
program: sequence check as u8 (#909)
* program: sequence check as u8 (reuse existing padding)
2024-03-11 10:45:53 +01:00
microwavedcola1 f2442428b6 Merge branch 'main' into deploy 2024-03-10 14:26:29 +01:00
Serge Farny 494835631b
program: add a sequence check IX (#908)
Add a sequence check IX

This new IX `SequenceCheck` can be used to avoid having multiple concurrent TX in flight causing unexpected result (multiple borrow for example)
2024-03-07 14:59:05 +01:00
Christian Kamm a7aaaff07e
allow skipping banks and oracles in fixed-order health account list (#891)
The following instructions now allow skipping banks and oracles if health
and the token position balance is not negative:
- token_withdraw
- token_deposit
- serum3_place_order
- perp_place_order
- flash_loan

They also allow skipping oracles that are stale.
2024-03-04 15:49:14 +01:00
Christian Kamm a30c5a9e06 Bump program version to v0.23.0, update idl 2024-03-04 11:22:08 +01:00
Christian Kamm e7f5cd7498 Bump program version to v0.24.0, update idl 2024-03-04 11:15:23 +01:00
Lou-Kamades 6b13841513 add TokenBalanceLog in token_charge_collateral_fees (#894)
* add TokenBalanceLog in token_charge_collateral_fees

* increase cu_per_charge_collateral_fees_token

(cherry picked from commit e7f9af9261)
2024-02-29 08:10:13 +01:00
Christian Kamm d2c55c23e1 Bank: more parameter sanity checks (#895)
(cherry picked from commit aa9bc8b1f1)
2024-02-29 08:10:09 +01:00
Lou-Kamades e7f9af9261
add TokenBalanceLog in token_charge_collateral_fees (#894)
* add TokenBalanceLog in token_charge_collateral_fees

* increase cu_per_charge_collateral_fees_token
2024-02-28 09:31:00 -08:00
Christian Kamm aa9bc8b1f1
Bank: more parameter sanity checks (#895) 2024-02-27 15:56:14 +01:00
Christian Kamm ebe3e455a2
tests: cleanup (#896)
- nicer floating point equality comparisons using macros
- nicer send-tx-and-expect-error calls
2024-02-27 15:56:03 +01:00
Lou-Kamades 4c91d36255
Add raydium CLMM oracle fallbacks (#856)
* add RaydiumCLMM oracle type

* add deserializing raydium pool state

* test: consolidate clmm oralce unit tests

* test: add failure check to test_orca_fallback_oracle

* test: add test_raydium_fallback_oracle

* restore get_quote_oracle()

* ensure RaydiumCLMM is a valid fallback type
2024-02-26 09:45:14 -08:00
Christian Kamm 8f19514a25 Audit v0.22 fixes (#887)
- apply recurring settle allowance constraint also in
  available_settle_limit
- bank constraints on util0, util1
- cleanup
- perp liq: take over oneshot and recurring limits separately

(cherry picked from commit efe4a1ae3d)
2024-02-21 09:01:23 +01:00
Christian Kamm efe4a1ae3d
Audit v0.22 fixes (#887)
- apply recurring settle allowance constraint also in
  available_settle_limit
- bank constraints on util0, util1
- cleanup
- perp liq: take over oneshot and recurring limits separately
2024-02-21 09:00:57 +01:00
Christian Kamm 46c6e86206
Add force_withdraw state and instruction (#884)
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
2024-02-19 15:06:51 +01:00
Christian Kamm 8a3a3bf70b
flash loan: Add a "swap without fees" option (#882) 2024-02-19 09:00:30 +01:00
Christian Kamm 3993a3fa66
collateral fees: fixes after devnet test (#880) 2024-02-14 11:32:57 +01:00
Christian Kamm 4f5ec41d7a
tests: Check mango account backwards compatibility (#878) 2024-02-14 10:00:09 +01:00
Christian Kamm e57dcdc2a9
Add collateral fees (#868)
- New permissionless instruction to regularly charge collateral fees
- Bank and group configuration to set rate and interval
- Keeper addition to call the instruction
2024-02-13 12:39:28 +01:00
Serge Farny 08a5ee8f53
rust client: Perp - Auto close account when needed (#875)
* perp: auto close perp market account when needing to open a new one with no slot available

* rust_client: do not send health accounts when deactivating a perp position (not needed on program side)

* rust_client: add perp place order command
2024-02-09 11:19:52 +01:00
Christian Kamm 5e4da1dd3c 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.

(cherry picked from commit a4cddf3129)
2024-02-07 14:20:19 +01:00
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 1392f726ba 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

(cherry picked from commit ae5907ba3a)
2024-02-01 11:24:39 +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 699321653a delegate withdraw: require target to have expected owner
(cherry picked from commit 719aee37ae)
2024-01-29 15:13:54 +01:00
Christian Kamm 5253db8495 allocator: Don't allow growth beyond heap memory region
(cherry picked from commit afc2ff9e80)
2024-01-29 15:13:52 +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 8f593e00b8 perp: Add platform liquidation fee for base (#858)
(cherry picked from commit fcc8c85f6e)
2024-01-26 10:25:35 +01:00
Christian Kamm a4e5cf9b02 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.

(cherry picked from commit 8383109f0d)
2024-01-26 10:25:27 +01:00
Christian Kamm 5f97f60719 Configurable interest rate for 0% utilization (#848)
(cherry picked from commit 18729cf04c)
2024-01-26 10:25:13 +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