Commit Graph

63 Commits

Author SHA1 Message Date
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
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 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 aed2afbde4 ensure fallbacks are only used for stale or unconfident oracles 2023-11-22 11:42:32 -06:00
Lou-Kamades 6288f2dd7d add fallback oracles to bank and mintinfo 2023-11-22 11:35:26 -06:00
Christian Kamm eceef44a96
Log emissions: Serialize to buffer on stack instead of using heap (#787)
Emitting many events could previously cause heap exhaustion.
2023-11-22 16:00:47 +01:00
Christian Kamm 2d1bf023c6
TokenRegister: Add arg for group insurance fund flag (#782) 2023-11-16 08:16:18 +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 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 1ba6513b5e
Compile and test fix (#645) 2023-07-14 16:27:52 +02:00
Christian Kamm a77515acbf
Improve listing with invalid oracles (#620)
* Stable Price: Reset on first price != 0

This helps when listing tokens or perp markets with an upcoming
oracle. Currently the stable price would be 0 and would need to be
manually reset by DAO proposal.

With this change, the first non-zero value will be used as the starting
point for the stable price instead.

* Listing instructions: Succeed even if oracle is invalid

But require the stable price to reset once it becomes valid.
2023-06-21 15:25:24 +02: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 99360e69a3 TokenRegister: Sanity checks on token_index 2023-03-20 14:02:03 +01:00
Christian Kamm b6bfb01879
token_liq_bankruptcy: Use oracle for valuing insurance fund tokens (#503)
Previously a token from the insurance fund was valued at 1 USD. Now it
uses the oracle associated with it (USDC oracle).
2023-03-16 11:23:45 +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
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
microwavedcola1 0012907ee3
Mc/ix toggler (#419)
* add gating to individual ixs

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>

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-01-26 20:27:39 +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
microwavedcola1 5ef04d6d08
group halt (#370)
* group halt

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

* Fixes from review

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

* format

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

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-01-12 09:12:55 +01:00
microwavedcola1 86c9331647
reduce only order type and mode for tokens and perp markets (#353)
* reduce only order type and mode for tokens and perp markets

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

* Fix from review

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

* Fix from review

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

* Fixes from review

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

* tests

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

* remove token

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

* fixes

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>
2023-01-04 09:24:40 +01:00
Christian Kamm 777c1a7804
Rename bank fields, make weight scale limits editable (#319) 2022-12-06 09:34:02 +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 c8f1f3c821
Net borrow limits: Limit in quote, not native (#312)
* Net borrow limits: Limit in quote, not native
* make perp settle limit disableable
2022-12-02 12:24:11 +01:00
Christian Kamm cf34a5b4b7 Health: Add soft deposit and borrow limits 2022-12-02 08:20:22 +01:00
microwavedcola1 1732a5aff4
net borrow limits (#301)
* net borrow limits

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

* fix client

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

* Fixes from review

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

* Fix tests

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

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Co-authored-by: Christian Kamm <mail@ckamm.de>
2022-11-25 13:45:17 +01:00
Christian Kamm c276353289
Implement a stable_price on banks and perp markets (#303)
It is tracked in the StablePriceModel and updated on
TokenUpdateIndexAndRate and PerpUpdateFunding instructions.

The stable price is used in health computations.
2022-11-24 11:55:22 +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
Christian Kamm b6361bad37
PerpUpdateFunding: update automatically on PerpPlaceOrder (#287) 2022-11-10 14:41:20 +01:00
Nicholas Clarke 96344d7de1
Clarkeni/perp logging (#265)
* Perp instruction logging
* Onchain funding calculation
* perp_spot_transfers field on perp positions
* Logging on register token, perp market
* Additional fields on update token index logging
* maker and taker volume fields on perp position
2022-10-07 12:12:55 -07:00
Christian Kamm ccba4ee597
Cleanups and bugfixes from the audit (#163)
* AccountExpand: cleanups from audit

* Group instructions: cleanups from audit

* AccountClose: cleanups from audit

* TokenAddBank: Audit fixes, including significant bugs

Must not take collected_fees and bump from the existing bank.

* Instruction comment updates

* GroupEdit: Add version/testing flag changes

Ported from mc/vanity
2022-08-13 19:54:58 +02:00
Christian Kamm 21815612ae
Let all PDA seeds start with a unique prefix (#166)
This is mostly paranoia. Now it's guaranteed that different PDA types
have unique seeds.
2022-08-13 19:30:35 +02:00
Christian Kamm a3067e2448 Avoid custom Debug impls by using derivative crate 2022-08-13 10:18:04 +02:00
microwavedcola1 d594286266
reserve for ALTs (#152)
* reserve for ALTs

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

* add explicit padding

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

* fix from review

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

* fix from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-08 18:50:59 +02:00
microwavedcola1 59d28c97a1
fix name and error message check in flash loan (#145)
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-06 12:59:13 +02:00
Christian Kamm a994626ef5 TokenRegister: Fix anchor seed derivation
It likes names constant, but not constant literals.
2022-08-04 08:25:41 +02:00
microwavedcola1 9d117c84ac fix from review
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-03 15:45:10 +02:00
microwavedcola1 505cbd48aa fixes from review
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-03 15:45:10 +02:00
microwavedcola1 59dd3aa66e insurance fund for trustless vs not trustful
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-03 15:45:10 +02:00