Commit Graph

120 Commits

Author SHA1 Message Date
Christian Kamm d2c55c23e1 Bank: more parameter sanity checks (#895)
(cherry picked from commit aa9bc8b1f1)
2024-02-29 08:10:09 +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 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
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
GoodDaisy 2f10a710c9
chore: fix typos (#854) 2024-01-29 13:39:33 +01:00
Christian Kamm fcc8c85f6e
perp: Add platform liquidation fee for base (#858) 2024-01-26 10:24:20 +01:00
Christian Kamm 8383109f0d
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.
2024-01-19 16:34:55 +01:00
Christian Kamm 18729cf04c
Configurable interest rate for 0% utilization (#848) 2024-01-15 12:45:00 +01: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
Christian Kamm 30e639fe84 Bank: require borrows <= deposits
- require borrows <= deposits, even if vaults have more tokens
- change min_vault_to_deposits_ratio to be about max utilization

Reviewed and audited as part of the v0.21.1 release, original
commit was 5c2f857112
2024-01-02 11:05:58 +01:00
Christian Kamm 0e3b52b0ef Clamp utilization at 100%
To avoid excessive interest rates or interest curve moves.

Reviewed and audited as part of the v0.21.1 release, original
commit was 3914e48c24
2024-01-02 11:05:22 +01:00
Christian Kamm b5614e98c3
test: Add interest rate test (#818) 2023-12-20 11:15:29 +01:00
Christian Kamm 64d6c8c3c4
Add doc comments for new fields (#819) 2023-12-18 17:41:17 +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 25aa422e2d also log primary oracle when fallback errors 2023-12-01 12:44:35 -06:00
Lou-Kamades 59001b3631 reduce CU cost of fallback oracles 2023-11-28 22:55:19 -06:00
Lou-Kamades aed2afbde4 ensure fallbacks are only used for stale or unconfident oracles 2023-11-22 11:42:32 -06:00
Lou-Kamades a0a47af6a4 ScanningAccountRetriever uses fallback oracles 2023-11-22 11:35:26 -06:00
Lou-Kamades d4017e6038 FixedOrderAccountRetriever uses fallback oracles 2023-11-22 11:35:26 -06:00
Lou-Kamades 6288f2dd7d add fallback oracles to bank and mintinfo 2023-11-22 11:35:26 -06:00
Christian Kamm eeb172e44e
Bank: Close zero position when withdrawing 0 (#793) 2023-11-22 15:54:38 +01: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 26549ffd92
Bank: track deposits in serum oo accounts (#769) 2023-11-02 10:40:31 +01:00
Christian Kamm 3b28856692
Bank: store interest curve scale and target util separately (#755)
Allows for better configurability independent of the previous MAX_RATE
concept
2023-10-17 13:14:07 +02:00
Christian Kamm 8110dd1566
FlashLoan: Replace deposit fee by "swap fee" (#754)
Which applies to the in token amount of swaps only.

Charging a deposit fee on flash loans was a bad idea:
- It incentivizes flash loan users to make the deposit a separate
  instruction, defeating the purpose.
- For swaps, it makes traders pay a loan origination fee in in-token and
  a deposit fee in out-token, leading to more complex bookkeeping and ui
  display.

Instead, charge a fee on the in-token for all flash loans explicitly
marked as swaps only.
2023-10-13 09:02:23 +02:00
Christian Kamm 817bf9bbc6
Tcs: linear and premium auctions (#717) 2023-10-07 21:27:19 +02:00
microwavedcola1 2df4df048c
program: be more relaxed with max rate (#734)
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-10-03 21:13:50 +02:00
Christian Kamm 1d6ce550f3
FlashLoan: fee fixes (#693)
- Rename the new "swap fee" to "deposit fee" and let it apply to all
  deposits, not just for Swap-type flash loans.
- But don't apply it to withdrawals (effectively giving rebates!)

Result of audit feedback
2023-08-29 10:03:07 +02:00
Christian Kamm e4a9a56f89
Pass all params to token_register (#665)
Makes governance a little easier
2023-08-09 13:55:53 +02:00
Christian Kamm 6dcd5c925c
FlashLoan swaps: Allow charging a fee (#660)
To give more flexibility to the DAO.

The fee is deducted from any deposits that happen during the flash loan
and controlled per-bank with TokenEdit.
2023-08-09 13:27:25 +02:00
Christian Kamm 774c67909e
Tcs: Use fees config from Bank instead of Group (#659)
To give more flexibility to the DAO, the maximum tcs fees from
the buy and sell banks will be used.
2023-08-08 10:21:13 +02:00
Christian Kamm 4f810edebc
Allow token withdraws/deposits even with stale oracles (#646) 2023-08-07 16:15:45 +02:00
Christian Kamm 5dd5c507f2
Tcs: reserve token positions while tcs is open (#647)
- Update in_use_count to u16
- Pass banks to TCS cancel instruction
- Increase the in_use_count when a tcs is created and decrease on
  trigger/cancel
2023-07-17 13:14:53 +02:00
microwavedcola1 40a011a48e
Fees to dao (#644)
* withdraw fees to dao

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>

* Fixes from review

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>

* Fixes from review

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

* rename

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

* Fixes from review

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

---------

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-07-13 18:22:35 +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
Nicholas Clarke defbd8c2b1
Add loan amount to WithdrawLoanLog. Add withdraw loan logging to toke… (#599)
* Add loan amount to WithdrawLoanLog. Add withdraw loan logging to token_force_close_borrows_with_token

* Address review comments.
2023-06-11 15:37:33 -07: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
microwavedcola1 b07857c696
force close tokens program part (#518)
* force close tokens

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>

* Fixes from review

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>

* add test

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>

* Fixes from review

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>

* Fixes from review

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

* reset

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

---------

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-04-13 12:44:12 +02:00
Christian Kamm da2a7f4e0c
Net borrow limit: Separate out tracking and checking (#534)
That way it's easier to be specific about where the limit should be
checked.
2023-04-13 08:56:33 +02:00
Christian Kamm 312a60fe4f
Net borrow limits: Use correct price for check (#527) 2023-03-30 17:25:29 +02:00
microwavedcola1 258d95d035
Fix bug: only account for borrows we are offsetting (#513)
* Fix bug: only account for borrows we are offsetting

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

* fix

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

* Bank: Unittest for net borrow limits

---------

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Co-authored-by: Christian Kamm <mail@ckamm.de>
2023-03-22 09:58:31 +01:00
Christian Kamm 0349ace3b6
Downgrade the `fixed` crate to v1.11.0 (#500) 2023-03-12 08:50:42 +01: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 b4b7085e67
fix clippy (#373)
* fix clippy

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

* Fixes from review

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

* add clippy whitelist trait

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

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-01-12 14:26:55 +01:00
Christian Kamm c5d875e04d
Perp settle limit extension to realized pnl (#359)
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
2023-01-11 14:32:15 +01:00