Commit Graph

921 Commits

Author SHA1 Message Date
Serge Farny 49b461f32d 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-08-10 14:22:51 +02:00
Serge Farny e4002acf8f 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-08-10 14:22:51 +02:00
Serge Farny 69d866008c Programs: fix for audit v0.25.0 (#970)
* Programs: remove anchor close has it is done manually anyway

* Programs: fix a bug where a pegged order might be skipped even if it was valid

(cherry picked from commit 905cc01414)
(cherry picked from commit 47c2707cfe)
2024-08-09 11:06:15 +02:00
Christian Kamm 98ed7eff14 Allow the insurance fund to be for any bank (#946)
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
(cherry picked from commit ec2d10af6e)
2024-08-09 11:06:15 +02:00
Christian Kamm e6c9a3864d Fix alignment of ordertree nodes (#954)
This ensures casts of local variables don't run into alignment
differences.

(cherry picked from commit d9c4f69e0e)
(cherry picked from commit 676da3a084)
2024-08-09 10:44:37 +02:00
Serge Farny ac6925ef37 Liquidator: fix an arithmetic error in client side health computation (#986)
(cherry picked from commit f5b4bd9dd0)
2024-08-05 15:33:18 +02:00
Serge Farny 0a55f46efb
Pyth v2: compare program clock with last price publication time for oracle staleness check (#983)
Pyth v2: compare program clock with last price publication time for oracle staleness check
2024-07-22 15:41:03 +02:00
Serge Farny 9c3af5cbe6 Program: regenerate IDL and bump version to v0.24.2 2024-07-17 10:46:02 +02:00
Serge Farny b995189eb5 Program: charge collateral fee directly on borrowed tokens (#973)
* Program: charge collateral fees on borrowed tokens and fixup OO impact

(cherry picked from commit 96158e349f)
2024-07-17 10:37:27 +02:00
Serge Farny 34c8be19c7
Program: add support for pyth v2 account (#980) 2024-07-17 10:21:38 +02:00
Serge Farny fb3579e482
Program: fix TokenUpdateIndexAndRateResilient IX (#979)
Program: fix TokenUpdateIndexAndRateResilient IX
2024-07-10 01:01:04 +02:00
Serge Farny ccb98fb5b8 Program: bump version 2024-07-04 21:42:04 +02:00
Serge Farny 3f32ddac88 Program: housekeeping 2024-07-02 18:30:34 +02:00
Serge Farny 28a636857e token update index and rate- skip bad oracle (#975)
Program: skip index and rate update when oracle is invalid
(cherry picked from commit d0cb8b9b0c)
2024-06-26 08:56:08 +02:00
Serge Farny a5ba37be7d Program: add switchboard on demand oracle support (#974)
---------

Co-authored-by: Mitch Gildenberg <mitch@switchboard.xyz>
(cherry picked from commit ed28450b98)
2024-06-25 17:37:18 +02:00
Serge Farny 0dc9d9ab80 program; fix health check ix gate (#940)
(cherry picked from commit fe86295d3c)
2024-04-11 07:22:51 +02:00
Christian Kamm 5c7502d360 token_withdraw: avoid silencing errors with is_ok() (#936)
(cherry picked from commit 653cf9f30b)
2024-04-08 16:28:44 +02:00
Christian Kamm d16def9745 Audit: Remove unused fn, add comments (#935)
(cherry picked from commit 9df73a0dfd)
2024-04-08 15:15:16 +02: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