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
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
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
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
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
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
microwavedcola1
1950d8c84a
support name edit for token and program ( #488 )
...
* support name edit for token and program
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* undo
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-03-03 10:05:12 +01:00
Christian Kamm
46c79af430
Security admin: Allow disabling token/perp init collateral ( #482 )
...
This allows the security council to say "users can't create new borrows
against this token/perp anymore". In some emergency situations this can
help reduce risk exposure.
For example, if the price of a wrapped asset permanently depegs from
its underlying or there is a successful long-term attack on an oracle,
this (and reduce-only) would significantly reduce exploitability until
the DAO's decision for how to resolve the issue goes through.
2023-02-28 11:49:07 +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
02d980f4e4
restrict what a security admin can do ( #452 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-02-13 20:02:47 +01:00
microwavedcola1
dae02885c2
log old and new in edit ixs ( #418 )
...
* log old and new in edit ixs
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* fix
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-25 09:02:27 +01:00
microwavedcola1
80f4bd8048
security admin can bring markets to reduce only ( #394 )
...
* security admin can bring markets to reduce only
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* fixes from review
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* fix from review; security admin can only turn on reduce only, security admin can only reduce init asset weight
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* --wip-- [skip ci]
* 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-23 15:02:48 +01:00
Christian Kamm
1a3d0da34a
Perp market edit: Separate out stable price resetting, like for tokens
2023-01-19 09:33:27 +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
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
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
347b225480
TokenEdit: remove bank_num arg
2022-09-20 14:22:25 +02: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
microwavedcola1
5516ecb132
remove unused param in context
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-08 21:11:15 +02:00
microwavedcola1
4f72985f2d
also allow editing group insurance fund ( #149 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-07 14:16:23 +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
5231ee7f98
Token edit: Fix bug where mintinfo.oracle goes out of sync
2022-07-18 18:18:57 +02:00
microwavedcola1
ef7d2862da
wip: dynamic rates ( #98 )
...
* dynamic rates
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* fmt
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-07-11 17:08:32 +02:00
microwavedcola1
d74cc78a84
edit tokens, perp markets, mango accounts, allow delegate to perform certain operations ( #94 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-07-05 19:31:47 +02:00