Commit Graph

24 Commits

Author SHA1 Message Date
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 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
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 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
Lou-Kamades 838df8cd7c
Merge pull request #790 from blockworks-foundation/lou/fallback-oracle
Add fallback oracles
2023-12-01 12:59:38 -06:00
Britt Cyr 68944747e0
Add serum3 cancel by client order id instruction (#798) 2023-12-01 13:36:29 +01: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
Christian Kamm f690514638
rust client: ix cu limits based on health compute cost (#768)
Many instructions now return PreparedInstructions instead of a direct
Instruction or Vec<Instruction>. That way they can keep track of the
expected cu cost of the instructions for the compute limit instruction
that gets added once all instructions are made.
2023-11-03 11:20:37 +01:00
Christian Kamm 26549ffd92
Bank: track deposits in serum oo accounts (#769) 2023-11-02 10:40:31 +01:00
Christian Kamm 2adc0339dc
Serum3 open orders: Fix health overestimation (#716)
When bids or asks crossed the oracle price, the serum3 health would be
overestimated before.

The health code has no access to the open order quantites or prices and
used to assume all orders are at oracle price.

Now we track an account's max bid and min ask in each market and use that
as a worst-case price. The tracking isn't perfect for technical reasons
(compute cost, no notifications on fill) but produces an upper bound on
bids (lower bound on asks) that is sufficient to make health not
overestimate.

The tracked price is reset every time the serum3 open orders on a book
side are completely cleared.
2023-09-13 09:35:10 +02:00
Christian Kamm 4f810edebc
Allow token withdraws/deposits even with stale oracles (#646) 2023-08-07 16:15:45 +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 eeef6711ab Update test_serum_loan_origination_fees test
Now that it always uses the v2 settle, fee buyback potential does
accumulate.
2023-06-19 14:48:08 +02:00
Christian Kamm 0281a1b8ed
Deprecate Serum3SettleFunds, require use of V2 instruction (#606) 2023-06-15 17:34:56 +02:00
Christian Kamm 57e1d981ac
Health: Allow actions while init health does not decrease (#592)
Instead of requiring a strict increase when init health < 0.

This allows users to still place reducing limit orders on the spot and
perp orderbooks as long as these orders keep the health unchanged.
2023-06-15 10:44:11 +02:00
Christian Kamm 0da1b6728b
OpenBook place order: respect bank reduce_only flags (#569) 2023-05-04 08:02:28 +02:00
Christian Kamm b7dd8e0663
Fee buyback: Respect USDC oracle (#504) 2023-03-20 11:18:11 +01:00
Christian Kamm 252210d194
Serum settle funds V2: fees can go to users (#484)
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
2023-03-03 14:04:45 +01:00
Christian Kamm df4a7b0474
Fees buyback: Credit users for ui part of serum fees (#481)
At least for markets with USDC quote currency.
2023-02-28 09:48:15 +01:00
Christian Kamm f75e3ee656
Serum: Track referrer rebates as Mango platform fees (#469)
And start sharing code between serum3 settle and force cancel
2023-02-22 12:04:21 +01:00
Christian Kamm 8916c28b99
License: Mark instructions GPLv3 and everything else MIT (#454)
To do that, split up the Accounts objects and the instruction
implementations.

GPL code is only used when the "enable-gpl" feature is enabled. That
means compiling the program or running tests need explicit feature
activation now.
2023-02-15 08:42:07 +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