Christian Kamm
f3f8359fd1
Fix open_interest doc comment
2023-06-16 16:11:25 +02:00
Christian Kamm
b5c9f6d039
Audit fixes ( #613 )
...
* TokenForceCloseBorrows: Respect reduce-only flag
* ForceCancelOrders: Readability of early-out condition
2023-06-16 13:34:54 +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
bbf0186398
Pyth oracles: Check that status is "trading" ( #607 )
2023-06-15 10:43:44 +02:00
Christian Kamm
66c6926419
Audit fixes for the fee buyback feature ( #608 )
...
* reduce_buyback_fees_accrued: forbid reducing more than accrued
* Buyback fees: Expire accrued during event processing
2023-06-15 10:43:31 +02:00
Nicholas Clarke
23761ef28c
Add price to WithdrawLoanLog ( #603 )
2023-06-14 09:41:54 +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
Britt Cyr
7803f1dc9d
Fix warning when running tests
2023-06-01 08:16:11 +02:00
Christian Kamm
1cc77af7fa
Bump version to 0.17.0, changelog updates, idl update
2023-05-31 09:11:56 +02:00
Christian Kamm
56b010eb71
HealthRegion: Whitelist new perp_place_order_(pegged_)v2 ix ( #597 )
2023-05-26 16:48:19 +02:00
Britt Cyr
2ea8f73ad1
Fix typo in token_liq_with_token comment ( #594 )
2023-05-25 12:35:22 +02:00
Christian Kamm
9f9f3d257c
Docs: improve HealthCache comments ( #590 )
2023-05-19 14:42:14 +02:00
Maximilian Schneider
0b22e41acd
manage dependencies in workspace ( #588 )
...
* move important dependencies to workspace
* enable workspace inheritance
2023-05-17 20:48:14 +02:00
Christian Kamm
5fc7aa1092
Configurable perp settle token ( #550 )
...
This changes perp market margining to no longer assume all pnl is in USD
while settlement is in USDC. Instead, a configurable settle token is used for
pnl and settlement, defaulting to USDC.
There is no difference while the USDC price is forced to $1 and the init and liab
weights are 1. But with this patch, it becomes possible to change that.
For now it is not recommended to use a token other than USDC or USDT (or
another USD targeting stable token) for perp settlement.
The patch also updates all insurance vault use to be aware that the insurance
fund is not in USD but in USDC and apply the USDC price before payouts.
To do this, the previous PerpLiqNegativePnlOrBankruptcy was replaced by
a new PerpLiqNegativePnlOrBankruptcyV2 instruction.
Co-authored-by: microwavedcola1 <89031858+microwavedcola1@users.noreply.github.com>
2023-05-17 15:50:05 +02:00
Christian Kamm
be5618aa2b
PerpTakerTradeLog: Add decremented base lots ( #584 )
2023-05-16 11:10:26 +02:00
Maximilian Schneider
c006948319
Enable self-trading protection ( #533 )
...
Co-authored-by: Christian Kamm <mail@ckamm.de>
2023-05-15 10:40:41 +02:00
Maximilian Schneider
9166b761e9
log taker trade summary ( #579 )
...
* add new event for taker trade so arb bots can verify their execution cost without waiting for consume events
Co-authored-by: Nicholas <nicholasgclarke@gmail.com>
2023-05-13 17:54:27 +02:00
microwavedcola1
784ef88927
document unused ( #581 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-05-13 10:03:28 +02:00
Christian Kamm
5a05e9cb2e
Update anchor to v0.27.0, stop using submodule ( #582 )
2023-05-12 13:54:53 +02:00
Christian Kamm
9429d3991d
Bump program version to v0.16.0 and add deploy info
2023-05-11 13:46:43 +02:00
Christian Kamm
450f446032
Make clippy happy ( #580 )
2023-05-09 21:08:55 +02:00
Christian Kamm
2205fe7260
Changelog for program v0.15.0, version bump, idl update ( #577 )
2023-05-08 08:13:50 +02:00
Christian Kamm
d20ae0abcb
Perp: Exit matching loop when no more base lots can be filled ( #576 )
2023-05-08 06:40:38 +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
Christian Kamm
2f4976e81f
Improve error message for FixedAccountRetriever ( #566 )
...
When an invalid number of accounts is passed in, which is one of the
most common error messages new integrators will see.
2023-05-05 09:11:25 +02:00
microwavedcola1
abba3de4ce
Fix bug in flash loan for delegates where compute budget program was not allowed, also improved logging ( #572 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-05-04 14:46:09 +02:00
Christian Kamm
0da1b6728b
OpenBook place order: respect bank reduce_only flags ( #569 )
2023-05-04 08:02:28 +02:00
Christian Kamm
6f47ad92d6
token_register_trustless: Disable borrowing by default ( #567 )
...
Previously tokens listed this way could be borrowed. Now tokens start
with reduce-only set to the "no borrows" mode.
Also decrease the default soft borrow/deposit limits significantly, even
if they don't come into effect when there are no borrows and the deposit
weight is 0 anyway.
2023-05-04 07:59:39 +02:00
Christian Kamm
4504ed8ff9
Compile fix and idl update
2023-04-26 09:07:05 +02:00
microwavedcola1
4e4af83d98
Fix bugs for release ( #564 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-04-25 16:18:35 +02:00
Christian Kamm
7ec8fbffe5
Fix build without enable-gpl
2023-04-25 13:39:01 +02:00
Nicholas Clarke
2dce1398d3
Fix to seq num logging. Seq num was incremented between event and logging ( #556 )
2023-04-25 13:38:31 +02:00
Nicholas Clarke
5d77ba6834
Add PerpForceClosePositionLog and TokenForceCloseBorrowsWithTokenLog ( #555 )
2023-04-25 13:38:08 +02:00
Christian Kamm
507cb500e9
Fix settle limit accounting for positive pnl takeover ( #562 )
2023-04-25 13:37:34 +02:00
microwavedcola1
3741f78da5
insurance fund withdraw ix ( #561 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-04-25 09:20:44 +02:00
Christian Kamm
fe8d1a63bd
Fix building with "no-entrypoint" feature ( #558 )
...
Without this, anchor complains about a missing lifetime on a struct
relating to Benchmark.
2023-04-24 09:52:44 +02:00
Christian Kamm
898788909e
Fix account borrow issue in perp_liq_force_cancel_orders ( #557 )
2023-04-24 09:52:33 +02:00
Christian Kamm
10113443df
Minor test compile fix
2023-04-24 09:35:46 +02:00
microwavedcola1
497012042c
Force close for serum3 market ( #551 )
...
* force close for serum3 market
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* Fixes from review
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* always require admin
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>
* format
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* Fixes from review
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* update client
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-04-20 10:19:23 +02:00
microwavedcola1
6fba1692e9
Fix type
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-04-20 10:13:14 +02:00
microwavedcola1
6ac9f19287
Perp force close positions in a market ( #525 )
...
* 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>
* force close perp market
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>
* test
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* update
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* add back staleness slot check
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-04-19 17:42:01 +02:00
microwavedcola1
55bfcc3a76
fix bug where flash loans couldnt be executed by delegates ( #552 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-04-19 16:17:26 +02:00
microwavedcola1
fa5b39adad
bump version for next release
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-04-14 16:59:02 +02:00
Christian Kamm
0e831db687
IxGate: Fix check for re-enabling instructions ( #540 )
...
The bug allowed the security admin to enable instructions. This was
supposed to require the group admin.
2023-04-14 16:12:17 +02:00
Christian Kamm
98a79505e1
FlashLoan: Don't deduce vault_len, add more checks ( #542 )
...
It looks like it wasn't possible to exploit the program by
re-initializing the user-owned token accounts used in flash loan because
the later use of health_ais with the health computation would error out
if any token account was included there.
However, the check and a few others were too indirect. In this patch:
- We pass the number of loans into FlashLoanEnd explicitly (verified
from FlashLoanBegin)
- Add explicit checks for token mints, so it's no longer possible to use
token accounts for foreign mints in Begin when the loan amount is zero,
and it's clearer to see that the bookkeeping in End won't break if the
user reinited the account for a different mint.
- Also add a few other extra comments and checks.
The updated FlashLoanEnd instruction is called FlashLoanEndV2
2023-04-14 15:18:02 +02:00
Christian Kamm
13279536aa
Drop leftover conflict markers
2023-04-14 08:26:05 +02: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
c813940054
Fix method calls
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-04-13 19:34:45 +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
2dca3003df
Don't incentivise using asset tokens with high liquidation fee during liquidation ( #536 )
...
* Don't incentivise using non-usdc coins to liquidate tokens
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* fix tests
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* fix tests
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* review: add back test comment
---------
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Co-authored-by: Christian Kamm <mail@ckamm.de>
2023-04-13 12:43:31 +02:00
Christian Kamm
61a4f62ea4
Bump program version to v0.13.0 and update idl
2023-04-13 09:53:15 +02:00
Christian Kamm
74f7282d4e
Bump program version to v0.12.0 and update idl
2023-04-13 09:46:58 +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
Nicholas Clarke
0ba41e3471
Emit perp fees settled on update_funding. Required to have a full picture of total perp market fees. ( #530 )
2023-04-06 22:09:50 -07:00
Christian Kamm
535b0b2d0c
Changelog for program-v0.11.0, bump version, update idl
2023-03-31 18:47:34 +02:00
Christian Kamm
762608ecce
Limit funding and interest accrual during downtimes ( #529 )
...
Previously, if the funding or interest updating instruction wasn't
called for a long time (like for a solana downtime or the security
council halting the program), the next update would apply funding or
interest for the whole time interval since the last update.
This could lead to a bad downtime situation becoming worse. Instead,
limit the maximum funding and interest time interval to one hour.
2023-03-31 12:48:34 +02:00
microwavedcola1
7080c9bf3c
sync rate params to latest proposal ( #523 )
...
* sync rate params to latest proposal
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-03-31 12:45:26 +02:00
microwavedcola1
cd39a9f432
Fix test
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-03-31 12:45:05 +02:00
Christian Kamm
8559d3ef07
Perp funding: Fix logging in update funding + deactivate pos ( #528 )
2023-03-31 10:58:04 +02:00
Christian Kamm
312a60fe4f
Net borrow limits: Use correct price for check ( #527 )
2023-03-30 17:25:29 +02:00
microwavedcola1
2957796de8
in perp settle fees, dont error, rather return early, this enables blindly concatenating perp settle fees to perp settle pnl ( #526 )
...
* in perp settle fees, dont error, rather return early
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-30 17:00:41 +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
7c02075c80
Bump program version to v0.10.0
2023-03-21 12:51:21 +01:00
Christian Kamm
b22a1e7f57
HealthRegion: Whitelist allowed instruction types ( #508 )
...
This fixes a security issue where bankruptcy related instructions could
be called inside a health region. Now health regions are limited to
compute optimization like when placing multiple orders in one
transaction.
This limitation also makes it impossible to abuse health regions for
flash loans. Use the FlashLoan instructions for that purpose.
2023-03-20 14:02:35 +01:00
Christian Kamm
658a220095
Allow token/market names to fill storage bytes completely
...
Previously the last byte was always zero.
2023-03-20 14:02:03 +01:00
Christian Kamm
99360e69a3
TokenRegister: Sanity checks on token_index
2023-03-20 14:02:03 +01:00
Christian Kamm
d1e3da2b75
IxGateSet: Log AccountBuybackFeesWithMngo state
2023-03-20 14:02:03 +01:00
Christian Kamm
b7dd8e0663
Fee buyback: Respect USDC oracle ( #504 )
2023-03-20 11:18:11 +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
c7dd6cd9e3
Bump program version to v0.9.0
2023-03-12 08:19:05 +01:00
Christian Kamm
6ee3cb1e19
Perp: More comments on fields and funding computation ( #497 )
2023-03-07 20:53:07 +01:00
microwavedcola1
5cd9279a21
add todo
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-03-07 10:05:02 +01:00
Nicholas Clarke
97895dfb1e
buyback fees with mngo logging ( #489 )
...
* buyback fees with mngo logging
* add logging of usdc balances for account_buyback_fees_with_mngo
2023-03-06 14:42:10 +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
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
f29fffd331
Perp: User-selected reduce-only behaves more intuitively ( #483 )
...
The previous strict behavior of taking existing open orders into account
is only used when the perp market itself is also flagged as reduce-only.
2023-03-03 09:53:27 +01:00
Christian Kamm
255c6fb138
Fee buyback: Limit MNGO price by stable price ( #485 )
...
This makes it much harder to temporarily manipulate the MNGO price to
get a more favorable buyback deal.
2023-03-01 09:58:47 +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
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
9a13c1366a
Fee buyback: Credit only perp fees that go to the dao ( #479 )
2023-02-27 19:51:09 +01:00
microwavedcola1
16599dd506
admins can also register trustless tokens ( #477 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-02-27 16:37:57 +01:00
Christian Kamm
e4d46c3c5b
Buyback fees: Add staggered expiry ( #478 )
2023-02-27 16:36:27 +01:00
microwavedcola1
d88d44b34a
buyback perp fees with mngo at a discount ( #464 )
...
buyback perp fees with mngo
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-02-25 20:34:16 +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
cfcda705e6
Bump program version to v0.8.0
2023-02-22 14:49:18 +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
microwavedcola1
ae2f74a928
security admin can move openbook market to reduce only ( #472 )
...
* security admin can move openbook market to reduce only
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-02-22 09:24:38 +01:00
Christian Kamm
5c7f23adb1
Perp place order: more logging for reduce only ( #468 )
2023-02-21 13:14:40 +01:00
Christian Kamm
8f9700ed2d
Settle pnl: Always grant the fractional fee on low health
2023-02-15 15:11:58 +01:00
Christian Kamm
a3a6d9d636
Settle pnl: Move fee-computation to PerpMarket
...
So it can be used in client code to decide what accounts to settle.
2023-02-15 15:11:58 +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
30a84ce6c0
Bump to program version to v0.7.0
2023-02-14 16:09:53 +01:00
Christian Kamm
f6abd9579d
Perp cancel all: Don't error when orders are filled/expired ( #453 )
2023-02-14 10:44:51 +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
Christian Kamm
1f66bef88f
Change liquidation end target to a new, third health type ( #447 )
...
Due to the safety features in v4, the init health can differ from maint
health a lot more than it used to in v3. This is because of stable-price
adjusted oracle prices used in init health, and the weight scaling based
on total deposits and borrows used in init health.
The effect is that once an account becomes liquidatable, it could be
liquidated a lot until it reaches init>=0.
The original idea of liquidating until init>=0 was just to provide some
buffer, such that liquidated accounts wouldn't immediately become
liquidatable again.
This patch decouples the buffer idea explicit from init health by
creating a new LiquidationEnd health type. Liquidation proceeds until
the LiquidationEnd health becomes positive.
Co-authored-by: microwavedcola1 <89031858+microwavedcola1@users.noreply.github.com>
2023-02-10 09:00:36 +01:00
microwavedcola1
74a6c72f45
fix log amount in token deposit ( #446 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-02-09 13:31:41 +01:00
Christian Kamm
2cb4da8b58
Liquidation: Fix amounts when stable price != oracle price ( #440 )
...
Previously liquidation would overestimate the amount required, because
it used the oracle price for computing the health gain from
liquidation.
Now it uses the correct (stable price adjusted) price for figuring out
the amount of liquidation required, while still executing at
fee-adjusted oracle price.
2023-02-08 09:05:17 +01:00
microwavedcola1
4e3a7f22b9
remove perp zero out, was only added to cleanup testing perp market, can be re-added if needed ( #430 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-02-06 11:59:12 +01:00
Christian Kamm
257aeb298c
Enable release-mode overflow checks ( #438 )
...
The checked_math macro is still needed for I80F48 though
2023-02-06 08:33:08 +01:00
Maximilian Schneider
4c9490f004
update serum to most recent openbook version ( #437 )
2023-02-05 10:26:04 +09:00
Christian Kamm
38d408126e
client: Increase binary search iter limit
2023-02-03 17:23:25 +01:00
Christian Kamm
40696f40a1
Bump program version to 0.6.0
2023-02-02 10:54:54 +01:00
Nicholas Clarke
4c93a2740a
Add market index to Serum3OpenOrdersBalanceLog ( #429 )
2023-02-02 10:01:19 +01:00
Christian Kamm
5328003183
Perp: Reorganize fill events, add client order id to LeafNodes ( #426 )
...
- don't store internal order ids: unneeded
- provide the maker client order id for user correlation
- store fees as f32 to waste fewer bytes
- new FillLogV2
2023-02-02 09:15:06 +01:00
Christian Kamm
a91a9ae998
Perp: Fix liq instructions ( #424 )
...
- Rename to perp_liq_base_or_positive_pnl and perp_liq_negative_pnl_or_bankruptcy
- Deal with situations where overall asset weight is zero and base position reduction
would not improve liqee health
- Add ability for liqors to take over positive unsettled pnl if that improves liqee health
2023-02-02 09:00:37 +01:00
Christian Kamm
bac15698e6
Add explicit self-liquidation checks ( #427 )
...
Just for safety, the other conditions and borrowing pattern would
already make it impossible.
2023-02-01 16:15:58 +01:00
Christian Kamm
50c820ddce
Perps: Rename pnl_asset_weight -> overall_asset_weight ( #428 )
...
Calling it "pnl" was confusing, because the thing that is weighted isn't
the pnl, but `(weighted base value + quote position)`.
2023-02-01 16:15:45 +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
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
f30ebf4ff8
logging + prevention of setting admin to default pk ( #423 )
...
* logging + prevention of setting admin to default pk
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-25 15:33:19 +01:00
microwavedcola1
0192728efc
return order id from a perp place order ix ( #417 )
...
* return order id from a perp place order ix
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:03:35 +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
Christian Kamm
1224fa4297
Bump program version to v0.5.0
2023-01-24 10:24:50 +01:00
Christian Kamm
4fd8139854
Token deposit: put expensive computation behind gates ( #421 )
2023-01-24 10:05:37 +01:00
Christian Kamm
eb079e1f4c
PerpEditMarket: Fix permission for oracle change ( #420 )
2023-01-24 10:03:10 +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
microwavedcola1
64dda20cb5
group level token deposit limit ( #415 )
...
* group level token deposit limit
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* fix
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* fix
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>
* 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 14:58:03 +01:00
microwavedcola1
f0c797a2e4
zero out perp position and orders for a broken market ( #413 )
...
* zero out perp position and orders for a broken market
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* fix
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* client code
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 12:50:20 +01:00
Christian Kamm
b3aabfadfc
Perp: Clarify has_open_orders use during liquidation ( #412 )
2023-01-23 10:45:45 +01:00
Christian Kamm
8b4a4c82fb
Perp: move Book::new_order() code around
2023-01-20 14:42:35 +01:00
Christian Kamm
be37f33946
Perp: Add PerpOpenOrder::is_active_for_market()
2023-01-20 14:42:35 +01:00
Christian Kamm
30ebf173ee
Perp: documentation in bookside_iterator.rs
2023-01-20 14:42:35 +01:00
Christian Kamm
d65e0794f4
Perp: Documentation in nodes.rs
2023-01-20 14:42:35 +01:00
Christian Kamm
549d9a8108
Perp: Remove EventQueue::empty() - is_empty() exists as well
2023-01-20 14:42:35 +01:00
Christian Kamm
1b4140c078
Perp: Don't allow orders with effective price_lots<1
2023-01-20 14:42:35 +01:00
Christian Kamm
e7b51d1dbf
Perp: Simplify consume events ( #406 )
2023-01-19 13:41:36 +01:00
Christian Kamm
a28fd49099
Delete perp_liq_bankruptcy again
...
Snuck back in in unrelated PR, but was unused
2023-01-19 12:59:24 +01:00
microwavedcola1
44f599ca62
dont process orders which have 0 lots; dont return early, we still want to apply ioc penalty ( #404 )
...
* skip iteration if the incoming order has no lots to process
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-19 11:29:00 +01:00
Christian Kamm
1a3d0da34a
Perp market edit: Separate out stable price resetting, like for tokens
2023-01-19 09:33:27 +01:00
Christian Kamm
2db617cea5
Perp ix: Mention and reference important constraints
2023-01-19 09:33:27 +01:00
Christian Kamm
f16f1a6c92
Perp market field documentation pass
2023-01-19 09:31:59 +01:00
Christian Kamm
0a86257309
Perp: Move best_price/impact_price from Orderbook to BookSide
2023-01-19 09:31:59 +01:00
Christian Kamm
886a6696da
Perp audit: ix constraint fixes ( #399 )
2023-01-19 09:31:03 +01:00
Christian Kamm
ff90c85874
Liquidator: reduce perp base pos if possible ( #398 )
...
- send reduce-only ioc order if possible
- settle pnl if needed
- deactivate position
2023-01-18 10:50:23 +01:00
Christian Kamm
71b13efc95
Bump program version to v0.4.0
2023-01-17 15:01:04 +01:00
microwavedcola1
be15f54225
agg pub slot was recent even if price was not updated, switch to last slot which seems more relevant ( #393 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-01-17 14:48:06 +01:00
Christian Kamm
9346c8e546
Perps: track overall realized pnl relating to a position ( #392 )
...
This includes trade pnl, funding and fees. Tracking this makes it easier
for uis to display a consistent position overall pnl value that doesn't
decrease by settling.
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
2023-01-17 14:07:58 +01:00
Christian Kamm
ec99376a8f
Perp: Allow setting pnl asset weights ( #391 )
...
This replaces the previous distinction between trusted and untrusted
markets, they are equivalent to setting the asset weights to 1 or 0
instead.
This way, we can weigh positive pnl in the trusted case at less than 1
which is more correct from a risk point of view and allows for more
flexibility when it comes to liquidation.
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
2023-01-16 16:49:09 +01:00
Christian Kamm
15b9b911d1
Bump program version to 0.3.0
2023-01-13 11:38:56 +01:00
Christian Kamm
c238ed4f28
Bump version to v0.2.0
2023-01-13 11:25:08 +01:00
Christian Kamm
bda8cb9387
v0.1.2 version bump and changelog ( #383 )
2023-01-13 10:36:47 +01:00
Christian Kamm
42657dcf80
Drop unused HealthCache function, rename ClampedToNum ( #382 )
2023-01-13 10:21:01 +01:00
microwavedcola1
3ed416a97f
Fix type ( #381 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-01-13 10:20:39 +01:00
Christian Kamm
5227daa0b8
Allow serum/perp order force cancelling on frozen accounts ( #374 )
2023-01-13 08:13:15 +01:00
microwavedcola1
a7a5c740c9
Fix typo ( #375 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-01-12 20:39:46 +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
7c69197505
mango account freeze ( #372 )
...
* mango account freeze
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* format
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-12 13:08:10 +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