Commit Graph

85 Commits

Author SHA1 Message Date
Christian Kamm ec2d10af6e
Allow the insurance fund to be for any bank (#946)
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
2024-04-23 09:17:53 +02:00
riordanp 2a6532f1c6
Openbook V2 Integration (#836)
Co-authored-by: Tyler <tjshipe@gmail.com>
Co-authored-by: Christian Kamm <mail@ckamm.de>
Co-authored-by: Serge Farny <serge.farny@gmail.com>
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
2024-04-22 11:37:53 +02:00
Serge Farny b3b4cc8223
program: add a min health check (#913)
add a min health check
2024-03-12 08:27:40 +01:00
Serge Farny 0728bb566f
program: sequence check as u8 (#909)
* program: sequence check as u8 (reuse existing padding)
2024-03-11 10:45:53 +01:00
Serge Farny 494835631b
program: add a sequence check IX (#908)
Add a sequence check IX

This new IX `SequenceCheck` can be used to avoid having multiple concurrent TX in flight causing unexpected result (multiple borrow for example)
2024-03-07 14:59:05 +01:00
Christian Kamm e7f5cd7498 Bump program version to v0.24.0, update idl 2024-03-04 11:15:23 +01:00
Christian Kamm 46c6e86206
Add force_withdraw state and instruction (#884)
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
2024-02-19 15:06:51 +01:00
Christian Kamm 8a3a3bf70b
flash loan: Add a "swap without fees" option (#882) 2024-02-19 09:00:30 +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 ae5907ba3a
fix perp settle limit materialization (#865)
Previously, we tried to keep track of "other" and "trade" realized pnl.
An issue occured when a perp base position went to zero: the way we
computed the trade pnl included potential non-trade unsettled pnl.

That caused follow-up trouble because the value could change sign and
reset the settle limit for trade pnl.

This change aims to simplify in some ways:
- explicitly talk about oneshot-settleable pnl (fees, funding,
  liquidation) and recurring-settleable pnl (materialization of settle
  limit derived from the stable value of the base position when reducing
  the base position)
- instead of directly tracking realized settleable amounts (which
  doesn't really work), just decrease the recurring settleable amount
  when it exceeds the remaining unsettled pnl
- get rid of the directionality to avoid bugs of that kind
- stop tracking unsettled-realized trade pnl (it was wrong before, and
  no client uses it) - we already track position-lifetime realized trade
  pnl
2024-02-01 11:23:45 +01:00
Christian Kamm fcc8c85f6e
perp: Add platform liquidation fee for base (#858) 2024-01-26 10:24:20 +01:00
Christian Kamm 8383109f0d
Add a token-token platform liquidation fee (#849)
The liqor liquidation fee and platform liquidation fee for the asset and
liab token are both payed by the liqee.

The platform liquidation fee is added to the Bank's
collected_fees_native and tracked in collected_liquidation_fees.
2024-01-19 16:34:55 +01:00
Christian Kamm 18729cf04c
Configurable interest rate for 0% utilization (#848) 2024-01-15 12:45:00 +01:00
Christian Kamm 637b43fec4 Idl update 2024-01-12 10:56:24 +01:00
Christian Kamm f10fc01388
Fix idl generation, update it (#834) 2024-01-03 08:36:19 +01:00
Christian Kamm cb9848252d
update idl and client tokenEdit() (#814) 2023-12-08 11:09:57 +01:00
Christian Kamm 42e31ae859
Deposit limits (#806)
- limit deposits (via deposit, flash loan, tcs)
- limit potential deposits via openbook settle
  by restricting placable orders via potential_serum_tokens
- introduce Serum3PlaceOrderV2 for this purpose
- account for new limits in liquidator, max_swap
2023-12-05 15:43:38 +01:00
Christian Kamm 81501837a9
Openbook token tracking and price bands (#805)
- track min bid, max ask
- track maximal token outflow from oo
- add serum3_place_order_v2 with mutable receiver bank
- placing openbook orders is restricted to a certain distance from the
  oracle
2023-12-05 15:39:24 +01:00
Britt Cyr 68944747e0
Add serum3 cancel by client order id instruction (#798) 2023-12-01 13:36:29 +01:00
Christian Kamm 6d80568022
Accounts: Expect only the v3 MangoAccounts now (#783) 2023-11-27 09:30:37 +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 06dd834215 Merge remote-tracking branch 'origin/dev' into deploy 2023-11-08 13:32:08 +01:00
Christian Kamm a81d0918cc tcs start: use same naming convention as in other ix
liqee/liqor over account/caller
2023-10-30 13:41:19 +01:00
Christian Kamm 381ef7401d
Group: Limit fast-listing tokens per week (#756)
To avoid potential abuse of fast listing while even when the dao is
unresponsive.
2023-10-17 13:14:49 +02: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 c354f55423
v0.20.0 minor fixes from self-audit (#751)
* tcs::is_startable only true for premium auctions
* individual tcs premium auction / linear auction ix gates
* drop unnecessary I80F48::from(...)
* minor: adjust confusing wording in v2 mango account format doc
* idl update
* ts: prettier
2023-10-11 15:19:53 +02:00
Christian Kamm 817bf9bbc6
Tcs: linear and premium auctions (#717) 2023-10-07 21:27:19 +02:00
Christian Kamm 32e08af598 Idl update 2023-10-05 11:04:20 +02:00
Christian Kamm 1afcff5dc2
Changelog and version bump for v0.20.0 (#739) 2023-10-04 09:18:57 +02:00
Christian Kamm ea7fae4687 Changelog, version bump for program v0.19.1 2023-10-02 19:54:09 +02:00
Christian Kamm ac38ccc687
Drop HealthCache from idl, disable ComputeAccountData ix (#723)
It's used for tests, we don't want people depending on it.
2023-09-19 10:01:44 +02:00
microwavedcola1 d51c3ee85d
release 19.1 -> deploy + serum3 open orders estimation ts patch (#719)
* Serum3 open orders: Fix health overestimation (#716)

When bids or asks crossed the oracle price, the serum3 health would be
overestimated before.

The health code has no access to the open order quantites or prices and
used to assume all orders are at oracle price.

Now we track an account's max bid and min ask in each market and use that
as a worst-case price. The tracking isn't perfect for technical reasons
(compute cost, no notifications on fill) but produces an upper bound on
bids (lower bound on asks) that is sufficient to make health not
overestimate.

The tracked price is reset every time the serum3 open orders on a book
side are completely cleared.

(cherry picked from commit 2adc0339dc)

* Changelog, version bump for program v0.19.1

* ts: ts patch for the PR

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

---------

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Co-authored-by: Christian Kamm <mail@ckamm.de>
2023-09-16 11:04:38 +02:00
Christian Kamm 0aabd28cdc Merge remote-tracking branch 'origin/deploy' into dev 2023-09-07 13:14:03 +02:00
microwavedcola1 56eb48904a Merge tag 'program-v0.19.0' 2023-09-07 10:46:37 +02:00
Christian Kamm ba6bd96784
Allow account shrinking and migration (#692)
- The AccountExpand instruction can now shrink accounts by reducing
  the number of token/perp/serum/tcs/perp oo slots.
- A new AccountSizeMigration instruction can permissionlessly shrink
  accounts that are too large and migrate them to the v3 layout.
2023-09-04 09:30:57 +02:00
Christian Kamm e37f1ed996 update idl 2023-08-30 10:59:14 +02:00
Christian Kamm 2d392c8fff 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

(cherry picked from commit 1d6ce550f3)
2023-08-29 10:03:53 +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 3480b62945
Changelog and version bump for program v0.19.0 (#683) 2023-08-18 15:38:28 +02:00
Christian Kamm a244c27df6
Add account_create_v2 instruction (#680)
This one allows specifying the number of tcs slots. That way accounts
can be created without needing a separate extend instruction afterwards.
2023-08-18 15:36:36 +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
microwavedcola1 8d924a8b9b
Delegate with expiry (#663)
* delegate with expiry

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

* update idl

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-08-09 12:05:16 +02:00
Christian Kamm 4810b6afbc
Tcs: store a display-only intention enum (#667)
This way the ui can know what the user created the tcs order for.

Introduces tcs create and trigger v2 logs.
2023-08-08 18:16:59 +02:00
Christian Kamm 785e6353c1 Fix compile after merges 2023-08-08 10:36:21 +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 1be38d14cb
Tcs: Add price display style enum (#654)
Tcs orders always store prices in a fixed "sell per buy" style, but users
can create them in either price direction. When they look at them later,
the ui needs to know what their preferred style is for this order.
2023-08-03 12:37:01 +02:00