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
Christian Kamm
93d33edb74
Perp: liq with token instruction ( #368 )
...
The new instruction allows the liqor to take over negative pnl (limited
by liqee settle health and settle limits) before applying the bankruptcy
logic.
2023-01-12 09:07:13 +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
microwavedcola1
292cc9a450
bonk ( #363 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2023-01-05 20:08:45 +01:00
silas
15784ecd2b
add security policy and on-chain metadata ( #361 )
...
* add security-txt macro
* minor fmt fix
2023-01-04 18:13:29 +00: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
b304ce09ec
Perp: Make settle limit robust against settle window size changes
2023-01-03 14:52:04 +01:00
Christian Kamm
7a8f31c611
Perp: settlement applies no loan origination fee
...
It's likely for perp pnl to oscillate and be settled in positive and
negative direction repeatedly. If the user's USDC balance is <= 0, every
settlement of negative pnl will increase borrows and cause loan
origination fees.
Over time the fees accumulated this way could be significant. Skipping
loan origination fees for borrows created from perp settlement avoids
that.
2022-12-30 12:54:03 +01:00
Christian Kamm
31bd72e84a
Drop AccountLoaderDynamic
...
This gives us better compatibility with released anchor versions.
Instead of using AccountLoaderDynamic<MangoAccount>, we now use
a standard AccountLoader<MangoAccountFixed>. This will generally work
(except for load_init(), which is dangerous).
A new trait, MangoAccountLoader, provides load_full(), load_full_mut()
etc on the AccountLoader<MangoAccountFixed> to create accessor structs
that can read and write to the dynamic part of the mango account data.
2022-12-29 17:40:08 +01:00
microwavedcola1
770b5a8056
pop perp events without processing, when mango account is closed ( #351 )
...
* pop perp events without processing, when mango account is closed
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* fix
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-12-21 10:21:10 +01:00
Christian Kamm
6439791233
Token deposit: limit while being_liquidated
...
While the flag is true, deposits that don't bring the account health
over the init threshold are forbidden. This makes it impossible for
users to drag out liquidation by continuously depositing tiny amounts.
2022-12-20 14:12:46 +01:00
Christian Kamm
55e8fc390f
Liquidation: Ignore dust balances and perp pnl
...
Liquidation and perp pnl settlement may not bring spot amounts to
exactly zero. Having a small spot amount < 1 native token can otherwise
make the liquidation get stuck and not move one to the next phase.
2022-12-19 12:49:09 +01:00
Christian Kamm
071dc34ccc
Client: Rework max_swap function ( #340 )
...
* Client: Rework max_swap function
Determining the amounts at which the health function changes slope
becomes too difficult when serum3 open orders come in.
Instead, generally find the function's maximum and then work with that.
* max_swap: Add test for swapping into a trustless token
* ts port
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
2022-12-16 16:33:37 +01:00
Christian Kamm
5a38506f04
Liquidator, liqtest and rust client fixes ( #336 )
...
Liquidator, liqtest and rust client fixes
- Make rust MangoClient fully async
- Update and improve liquidation test setup scripts
- Update liquidator to use versioned transactions
- Update liquidator to use mango and jupiter account lookup tables
- Use jupiter v4 api to get versioned transactions
Perp liquidation is still not fully good. See discussion aboult perp_liq_pnl_with_token.
2022-12-16 13:10:46 +01:00
Christian Kamm
1c36b1b493
Fix rust test compilation
2022-12-16 13:07:19 +01:00
microwavedcola1
df4a48a558
dont do checks force close flag is used explicitly ( #341 )
...
* dont do checks force close flag is used explicitly
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* comment
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* comment
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* Fix ts
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-15 21:10:56 +01:00
microwavedcola1
4169ccb960
enforce min vault to deposits ratio in flash loan and serum3 place order, in addition to token_withdraw ( #338 )
...
* refactor
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* Enforce min vault to deposits ratio in flash loan and serum3 place order
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* refactor
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* refactor
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-15 18:27:22 +01:00
microwavedcola1
51cded4965
Mc/health max swap with serum effects ( #333 )
...
* rearrange, log before expect
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* rearrange, log before expect
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* Fix test
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* health max swap with serum effects
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* max swap: Fix with serum reserved amounts
* port rust code to ts
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* port tests
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* Fix method call
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* Fixes from review
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Co-authored-by: Christian Kamm <mail@ckamm.de>
2022-12-14 09:21:45 +01:00
Christian Kamm
0ed7175341
Upgrade to solana ~1.14.9
...
- Update anchor submodule
- Fork and submodule switchboard-v2 package to update dep
2022-12-13 17:00:57 +01:00
Christian Kamm
e0f50bf0d4
pnl limit: Clean up by adding functions, using it in get-settleable ( #329 )
2022-12-10 17:56:56 +01:00
Nicholas Clarke
e2295b2daa
Add instantaneous interest rates to update index log ( #314 )
2022-12-09 10:14:06 +01:00
Christian Kamm
ec41fe4413
Don't compile the margin-trade fixture all the time
2022-12-08 20:48:44 +01:00
Christian Kamm
57e4510b08
Remove mango-macro
2022-12-08 20:48:44 +01:00
Christian Kamm
a29a736ba2
Move src/state/health/ -> src/health/
2022-12-08 20:48:44 +01:00
Christian Kamm
450007d34b
Perp: Drop client order id from LeafNodes ( #323 )
...
This saves 8 bytes and only the FillEvents, FillLogs were populated from
the data.
2022-12-08 19:55:32 +01:00
Christian Kamm
b66dc7ae80
IDL: Fix missing OrderTreeRoot
2022-12-08 11:22:37 +01:00
microwavedcola1
fa815f1c75
switch to new vanity address
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-12-08 10:23:12 +01:00
microwavedcola1
7d9c3616af
ts client changes ( #320 )
...
* cleanup + small sync with program
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* Fixes from review
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* Update lock file
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* Fix tsc errors
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-12-08 10:16:06 +01:00
Christian Kamm
947d9b2b60
Split into perp bids and perp asks ( #322 )
...
Separate, smaller accounts that are easy to extend if needed.
2022-12-07 21:03:28 +01:00
Christian Kamm
c44dc045cf
Perp: Merge ordertrees for fixed and oracle_pegged ( #321 )
...
By sharing the nodes list we're much less likely to grossly
over-allocate space.
2022-12-07 20:54:18 +01:00
Christian Kamm
777c1a7804
Rename bank fields, make weight scale limits editable ( #319 )
2022-12-06 09:34:02 +01:00
Christian Kamm
375b2b3fb3
Use bytemuck::Pod derives to check for accidental padding ( #317 )
2022-12-06 09:25:43 +01:00
Christian Kamm
e0c403dcb9
Client: consider borrow limits in max-swap ( #316 )
2022-12-06 09:25:24 +01:00
Christian Kamm
a5a015e19f
LeafNode: tif field u8 -> u16
...
Allows for longer TIF durations
2022-12-05 15:28:13 +01:00
Christian Kamm
cbaa0098d6
LeafNode: tag field is u8 instead of u32
2022-12-05 15:28:13 +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
microwavedcola1
fa09c557a1
ts client sync with program ( #311 )
...
mostly health related code
2022-12-02 15:48:43 +01:00
Christian Kamm
9bfa574ee6
Doc: note about final health slope in max_swap_source
2022-12-02 14:08:13 +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
Christian Kamm
512eef96ea
Perp pegged orders: Add stub max oracle staleness arg
2022-12-02 08:19:51 +01:00
Christian Kamm
9757f7a509
Fix perp liq computation; doc liq fee in token liq
2022-12-02 08:19:29 +01:00
Christian Kamm
524fe110e3
Health client: Fix max perp trade ( #309 )
...
Previously we didn't take the health cap for untrusted perp markets into
account correctly.
2022-12-01 11:26:01 +01:00
Christian Kamm
7bbf045823
Separate health code into multiple files
2022-11-30 13:21:32 +01:00
microwavedcola1
d64d9285f4
limit settleable pnl ( #295 )
...
Co-authored-by: Christian Kamm <mail@ckamm.de>
2022-11-30 13:20:19 +01:00
Christian Kamm
f6d189ce29
Test fixes
2022-11-28 11:31:51 +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
502f0767a8
Adjust avg entry price / break even price computation ( #304 )
...
- Don't return result as I80F48, f64 is more honest
- Allow access to avg entry price per base lot without division
- Reset break even price when position changes sign
- Fix occasionally-failing fast division test
- Fix sign of break even price -- it can now be negative if the
position has broken even.
2022-11-25 09:59:52 +01:00
Christian Kamm
f236a0521a
Fast I80F48 division with reduced precision ( #300 )
2022-11-24 11:59:00 +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
65362cb4de
AccountRetriever review fixes
...
Done-with: conj0iner
2022-11-21 20:34:23 +01:00
microwavedcola1
d3661bac7b
mc/oracle peg ts client ( #290 )
...
* oracle peg client support
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>
* Fix from review
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-11-21 19:34:41 +01:00
Christian Kamm
6ea7eddcb3
Compute health based on two prices ( #298 )
...
Now the oracle price and a "safe" price go into the health computation and
init health uses the min of both for assets and the max for liabs.
This has far-reaching consequences for how serum and perp health need to
be computed because many intermediate values depend on the prices, which
now differ for init and maint health computations.
The biggest change is that the serum3 reservation totals need to be done
for each health call from scratch.
This PR increases the health CU host per serum3 market and perp market
significantly, check the test_health_compute tests.
2022-11-21 15:01:10 +01:00
microwavedcola1
d82608ebee
Revert "add support for msrm vault for serum3 discounts ( #285 )"
...
This reverts commit 0a4f7150d6
.
2022-11-20 15:31:16 +01:00
conj0iner
39ed94aa87
client additions + extra tests + safety ( #281 )
...
Co-authored-by: Conj0iner <conj0iner@users.noreply.github.com>
Co-authored-by: Christian Kamm <mail@ckamm.de>
2022-11-18 08:58:56 +01:00
Christian Kamm
3ccfa3241f
Perp: Remove misleading LeafNode::price()
2022-11-16 15:53:07 +01:00
riordanp
5d780a86dc
Upgrade to Solana 1.10.35 ( #291 )
...
* 1.10.35 upgrade & compatibility
* Patch Anchor
* Fix test compile
* Serum program update
Co-authored-by: Christian Kamm <mail@ckamm.de>
2022-11-16 10:50:40 +00:00
Christian Kamm
1026b2bb85
benchmark improvements
2022-11-16 11:14:46 +01:00
Christian Kamm
2ee152f7ea
Oracle staleness: Check when accessing oracle price
2022-11-12 12:12:45 +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
f5e47c47bd
Clarification of price_data for pegged orders
2022-11-11 08:18:53 +01:00
Christian Kamm
b6361bad37
PerpUpdateFunding: update automatically on PerpPlaceOrder ( #287 )
2022-11-10 14:41:20 +01:00
Christian Kamm
efec1eb906
Test fixes
2022-11-09 10:51:03 +01:00
microwavedcola1
0a4f7150d6
add support for msrm vault for serum3 discounts ( #285 )
...
* add support for msrm vault for serum3 discounts
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* Fix client
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* client support
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* More client code and todos
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* prettoer
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* remove mint, not needed
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-11-09 09:59:42 +01:00
microwavedcola1
e47e17d79f
reduce only flag for perp place order ( #286 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-11-09 09:59:34 +01:00
microwavedcola1
e8ba511c45
mc/flash loan for delegate ( #271 )
...
* flash loan for delegates
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* Fix rust client
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* prettier
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-11-09 09:35:13 +01:00
Christian Kamm
5731ce8faa
Perp oracle peg feature ( #264 )
...
This introduces the ability to use oracle peg orders on perp markets.
This PR has significant non-backwards compatible changes, for example all
order trees are now in a single account instead of separate.
2022-11-08 15:27:56 +01:00
microwavedcola1
cae10bcdae
Merge branch 'dev'
2022-11-02 11:52:43 +00:00
microwavedcola1
a66177a77e
ts: match client class definitions 1-1 to program state struct definitions ( #268 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-10-11 09:34:02 +02: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
f2cc869795
Perps: Prepare for settlement token != oracle token
...
Make sure the setting is available and that the needed accounts are
passed to the perp instructions.
2022-10-06 08:32:58 +02:00
microwavedcola1
5b549fb59f
program: fix bug where expansion would not move positions whose size remained same ( #262 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-10-03 13:06:04 +02:00
Christian Kamm
b906e3dc78
Token deposit: Split into signed and permissionless ix
...
Token accounts are a limited resource, so allowing other users to make
use of them can cause problems.
2022-10-02 16:06:39 +02:00
microwavedcola1
d1079bb1b9
Mc/ts increase error tolerance for binary search ( #258 )
...
* ts: a higher error tolerance is sufficient
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* Fixes from review
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* program: fix error size
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-09-30 14:59:12 +02:00
Christian Kamm
7e180c7b3a
Perps: Support trusted markets
2022-09-29 15:40:31 +02:00
Christian Kamm
8ba52f46c2
Perp settle pnl: incentive for settler ( #252 )
...
This adds three new options to perp markets:
- a flat fee, that is paid for all perp settlements
- given that they exceed the configured min settle amount threshold to
be eligible for fees
- and a fractional fee, that only applies when the benefiting account
has low health and gradually becomes bigger as the account slides
towards liquidation
2022-09-29 12:59:55 +02:00
Nicholas Clarke
01a958cd22
Clarkeni/onchain interest ( #244 )
...
* Onchain interest calculation
* Fix to TokenBalanceLog for token_liq_bankruptcy (was previously using liqee liab position for liqor liab position).
* Log cumulative interest when token position is deactivated.
2022-09-28 23:04:33 -07:00
Christian Kamm
984695e8d0
liquidator: Call liq_perp_bankruptcy
2022-09-29 07:36:00 +02:00
Christian Kamm
12864e15a6
Merge pull request #245 from blockworks-foundation/ckamm/perp-settle
...
Liquidator: Settle pnl on perp accounts
2022-09-29 07:35:37 +02:00
Christian Kamm
77abfd0529
Perp liq: Fix base position liquidation amount computation
...
It was wrong for quote weights != 1.
2022-09-29 07:34:52 +02:00
Christian Kamm
11daf4d0eb
client: fetch top settle pnl counterparties
2022-09-28 10:48:41 +02:00
conj0iner
a97b40a521
Merge pull request #234 from blockworks-foundation/cj/ioc_fees
...
Extra fees for IOC orders
2022-09-28 00:05:25 +08:00
Nicholas Clarke
1320451e1a
Add serum open orders balance logging. Remove price from token and perp balances. ( #236 )
2022-09-23 10:42:43 -07:00
Christian Kamm
f6c9a93ac5
Health: Avoid overflow panic in health ratio for tiny liabs
...
Spotted by microwavedcola
2022-09-23 12:04:14 +02:00
microwavedcola1
bb6790e678
ts: use price factor in maxSourceForSwap + max perp bid and ask + tests ( #237 )
...
* ts: use price factor in maxSourceForSwap
ts: max perp bid and ask
ts: mocha test for max swap
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* ts: comemnt
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-09-23 11:43:26 +02:00
Conj0iner
55f77ad6c6
Added IOC penalty
2022-09-23 00:55:12 +08:00
microwavedcola1
ae42356b22
program: remove todos for ix which have now been implemented or not relevant ( #240 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-09-22 17:43:01 +02:00
Christian Kamm
0040a1477e
Client: Compute max perp trade amount ( #231 )
2022-09-21 11:45:05 +02:00
Christian Kamm
a41a245e24
PerpLiqBankruptcy instruction
2022-09-21 09:46:54 +02:00
conj0iner
1c67b8ed5f
remove base_token_index from perps and include oracles ( #224 )
...
Co-authored-by: Conj0iner <conj0iner@users.noreply.github.com>
2022-09-21 09:42:45 +02:00
Christian Kamm
ddb68b7991
Test build fix
2022-09-20 16:59:55 +02:00
Christian Kamm
6399e6cb6c
Fix PerpMarket data layout breakage
...
The new fees_settled must be added at the end and the reserved amount
needs to be reduced.
2022-09-20 16:58:07 +02:00
microwavedcola1
b7e79a4663
WIP: ts/perps ( #220 )
...
* ts: further fleshing out of perps code
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* cleanup scripts
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* Fixes from reviews
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-09-20 12:57:01 +02:00
Christian Kamm
11160ae2fe
Health: Pass price to max_swap_source_for_health_ratio
...
Because it's not correct to think we'll always swap at oracle price.
That was an ok assumption for liquidations, where we'll swap at slightly
better than that, but not for jup.
2022-09-20 10:41:33 +02:00
Christian Kamm
a6d25071cd
Test: Fix test_alt compile
2022-09-15 19:06:46 +02:00
Christian Kamm
20eb61527b
Compile fixups after merge
2022-09-15 09:40:14 +02:00
Christian Kamm
1b3a2b07db
Update idl
2022-09-15 09:24:35 +02:00
Christian Kamm
14ca1dac35
Add alt_set / alt_extend instructions
...
alt_extend will only work in the future, when alt_set can receive lookup
tables where the authority is set to be the mango group pda.
2022-09-15 09:20:08 +02:00
Christian Kamm
50be520e99
Rename: LiqToken* -> TokenLiq*
2022-09-14 16:22:42 +02:00
Christian Kamm
f3bdfec6a6
Perp settle pnl: Limit to maint spot health ( #225 )
...
Perp settle pnl: Limit to maint spot health
We want to isolate perp markets. As such, it's not acceptable to convert
arbitrary perp losses into spot token borrows.
The safe amount for this conversion is given by the account's
maint health -- with all perp markets ignored.
2022-09-14 13:26:29 +02:00
Christian Kamm
5572242e6d
Tests: PerpLiqBaseToken tests
2022-09-10 07:45:27 +02:00
Christian Kamm
45025a1145
Perp tests: Helper for market creation
2022-09-10 07:45:27 +02:00
Christian Kamm
bb962c6781
Perp tests: Don't pass derivable accounts explicitly
...
This makes it impossible to test passing bad accounts for these through
this interface, but I think that's an ok tradeoff.
2022-09-10 07:45:25 +02:00
Christian Kamm
2dfada7377
Tests: initial perp force-cancel test
2022-09-10 07:42:58 +02:00
Christian Kamm
810998a2af
Add PerpLiqForceCancelOrders instruction
2022-09-10 07:42:58 +02:00
Christian Kamm
845a32a7c2
Add PerpLiqBasePosition instruction
2022-09-10 07:42:58 +02:00
Conj0iner
a6ddf232cb
Fixed tests
2022-09-09 18:50:11 +08:00
Conj0iner
3b3286a5b3
Changed max_settle_amount to u64
2022-09-09 18:29:02 +08:00
Christian Kamm
1f26a54399
Perps: introduce explicit position close ( #216 )
...
* Perps: fix position lifetime; explicit closing
When an order is placed and the position needs to be created, the
settlement token is marked as in use. The perp position and the in-use
flag are only released with the new perp_close_position instruction.
* Tests: Factor out common floating-point comparisons
* Rename PerpClosePosition -> PerpDeactivatePosition
2022-09-09 10:50:09 +02:00
Christian Kamm
6c32077d1a
Perps: Let all base lot changes go through a function
...
Direct access to base_position_lots and quote_position_native is not
allowed anymore.
Fixes an issue where quote_lots were used instead of quote_native, and
also takes fees into account for the entry price.
2022-09-08 13:12:50 +02:00
Christian Kamm
e56ed3776c
Perp: Api cleanups
...
- Clarification of close_order vs close_all_orders
- Remove of get_ prefixes
- Remove find_min/find_max/find_min_max, duplicated with
min_leaf/max_leaf
2022-09-08 13:11:45 +02:00
Christian Kamm
1d7d5e9a6d
Test: simplify by adding a TestKeypair that's Clone+Copy
...
This means a lot less annoyance because of &'a Keypair or Arc<Keypair>
2022-09-07 14:23:52 +02:00
Christian Kamm
4795286dbd
Perps: Account for unsettled funding in health
2022-09-07 11:37:20 +02:00
Christian Kamm
c714fb213d
Tests: Auto-advance the slot after sending a transaction
...
This fixes a recurring error where it would look as if a transaction you
send would not be processed at all.
2022-09-07 11:34:47 +02:00
Christian Kamm
3128115dca
PerpMarket: Add helper for getting oracle price
2022-09-06 14:26:06 +02:00
Christian Kamm
79a7bdc299
Checked math: support cm!(a += b)
2022-09-06 08:55:27 +02:00
Christian Kamm
3c51449040
Tests: Remove unused imports
2022-09-05 18:40:42 +02:00
Conj0iner
c34ee54233
Added perp_settle_fees instruction
2022-09-05 22:18:40 +08:00
Christian Kamm
3fbc3ca32d
TokenEdit: remove bank_num arg
2022-09-02 13:55:00 +02:00
Conj0iner
97eed4081d
Added perp_settle_pnl instruction
2022-09-02 00:07:57 +08:00
Christian Kamm
511db72f8e
Health token adjustment: Deal with odd I80F48 behavior
...
The identity
a * b = -((-a) * b)
does not hold for I80F48, probably it's rounding to -inf.
This meant that withdrawing the full native token balance could
fail because the magnitude of -position * price was bigger than
position * price.
2022-09-01 14:38:48 +02:00
Christian Kamm
868c55fef1
Serum index reservation: use a real account
...
Makes it easier and more future-proof
2022-09-01 12:28:37 +02:00
Christian Kamm
c31f11013f
Serum deregister: Close index reservation account
...
Only safe because this is a testing-only instruction
2022-09-01 12:15:00 +02:00
Christian Kamm
1f0cd62846
Don't panic if accounts are shorter than 8 bytes
2022-09-01 12:00:09 +02:00
Christian Kamm
5e0001afb8
Serum: Index reservation account has 8 bytes
...
otherwise all code needs to be able to deal with mango accounts that are
smaller than 8 bytes in size.
2022-09-01 11:49:33 +02:00
microwavedcola1
b30b2f8870
program: serum3 should work when group has version 1, perps and multiple banks should be moved to version 2 or beyond ( #205 )
...
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-09-01 09:48:38 +02:00
Christian Kamm
d0fef4a586
Test: simplify allow(dead_code) to be per-file
2022-08-30 15:32:59 +02:00
Christian Kamm
8a2d54cce8
Fix some clippy warnings
2022-08-30 13:59:34 +02:00
Christian Kamm
801b68b93c
MangoAccount: add unittests
2022-08-30 13:11:47 +02:00
Christian Kamm
77b8e6e8b9
SerumPlaceOrder: Fix vault balance check for base_lot_size
...
As spotted by microwavedcola
2022-08-30 12:05:07 +02:00
Christian Kamm
1f0138d1de
SerumCloseOO: Reduce in_use_count of token positions
2022-08-30 12:05:07 +02:00
Christian Kamm
8e30870689
SerumLiqForceClose: Proper health/liq checking
2022-08-30 12:05:07 +02:00
Christian Kamm
e0437305ee
SerumPlaceOrder: Only pass the payer bank/vault
2022-08-30 12:05:07 +02:00
Christian Kamm
36723792a1
SerumRegister: Block using the same market index twice
2022-08-30 12:05:07 +02:00
Christian Kamm
dc4acd0dd7
Serum: loan origination fee, don't auto-settle, fix vault check
...
- Loan origination fees: The previous approach of tracking the reserved
amount did not work because OutEvents will also reduce the reserved
amount. This means we can't know if it was an OutEvent-cancel or an
order execution that caused the reduction.
Instead, we now track the amount of borrows that was made (without
applying origination fees) in place order. Whenever we try to settle
and the amount of tokens on the oo account is less than the potential
borrows, we can be certain that the borrow has actualized.
- Place order is no longer automatically followed by a settle.
This can reduce compute use when people want to place multiple orders
in sequence. Now they can use the HealthRegion instructions to place
their orders, settle once at the end, and then have health checked.
- Vault check: Place order previously rejected valid orders because it
didn't consider that there could be free tokens on the oo account.
- Tests: Some infrastructure for less verbose serum testing.
2022-08-30 08:38:13 +02:00
Christian Kamm
e1adbf0217
Tests: Fix concurrent log capture
2022-08-30 08:37:29 +02:00
Christian Kamm
d6d66402f7
Tests: Helper for create + fund
2022-08-30 08:37:29 +02:00
Christian Kamm
7d508e5df5
MangoAccount: Fixes after audit
2022-08-29 16:13:15 +02:00
Christian Kamm
d63c5bfc76
Serum: Don't attempt deactivating token positions after serum actions
...
While a serum open orders is active, the base and quote token positions
for it are locked to active. It's pointless to check if they need to be
deactivated after place/settle etc.
2022-08-26 11:45:54 +02:00
Christian Kamm
1a95a84ed4
Serum: Comments on account constraints
2022-08-26 11:45:54 +02:00
microwavedcola1
453248bbe5
token_deregister: remove redundant token index and add doc ( #192 )
...
* token_deregister: remove redundant token index
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* fix test
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-08-25 19:25:56 +02:00
Christian Kamm
dfa8166aee
Health: Put common pre/post check logic into functions
2022-08-24 16:39:36 +02:00
Christian Kamm
bba27ed6f0
PlacePerpOrder: pre-health computation
2022-08-24 16:07:22 +02:00
Christian Kamm
38b349a401
Rename PerpOpenOrders -> PerpOpenOrder, since it's a single one
2022-08-24 15:22:55 +02:00