Commit Graph

23 Commits

Author SHA1 Message Date
Christian Kamm a7aaaff07e
allow skipping banks and oracles in fixed-order health account list (#891)
The following instructions now allow skipping banks and oracles if health
and the token position balance is not negative:
- token_withdraw
- token_deposit
- serum3_place_order
- perp_place_order
- flash_loan

They also allow skipping oracles that are stale.
2024-03-04 15:49:14 +01:00
riordanp 24d8a5753a
Merge dev changes (#532)
* Fix script

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

* Fix docs build job (#501)

* workaround where rpc rejects base58 encoded pubkeys (#502)

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

* Rename settle-bot to settler, fix build (#492)

* Fix settler build, rename due to heroku not liking '-'

* Temporarily remove ref tag

* Remove temporary branch trigger

* Add oracleProvider to Bank and PerpMarket (#491)

* Add oracleProvider to Bank and PerpMarket

* v0.9.6

* Fix null checks on getters for PerpMarket and Bank (#505)

* Export OracleProvider

* Fix null checks on getters

* 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).

* v0.9.7

* ts: Fix ix gate enum, add code for creating a disable-tx gov ix

* Fee buyback: Respect USDC oracle (#504)

* refactor script (#509)

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

* IxGateSet: Log AccountBuybackFeesWithMngo state

* TokenRegister: Sanity checks on token_index

* Allow token/market names to fill storage bytes completely

Previously the last byte was always zero.

* 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.

* Add fly deploy scripts (#490)

* Bump program version to v0.10.0

* liquidator docs (#512)

* liquidator docs

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

* update

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

* update

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

---------

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

* Quality of life fixes (#511)

* breaking: make pegLimit an optional arg
* pass externally cached blockhashes to sendTransaction
* convenience accessors for connection & walletPk on client

* add script to sim accounts with leverage change (#514)

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

* 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>

* extend script, fix util function

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

* Fix interest rate computation in client (#520)

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

* minor ts fixes

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

* Temporarily disable health region use on mm script (#507)

* Use new shared mango-feeds-connector crate for chain_data (#515)

* Add prometheus metrics to crank (#517)

* Add prometheus metrics to keeper

* update script

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

* fix bug where unrealised profit was not abs'ed

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

* Fix script

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

* update script

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

* 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>

* update script

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

* Net borrow limits: Use correct price for check (#527)

* Changelog for program-v0.10.0 and idl update

* script for grabbing logs

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

* Perp funding: Fix logging in update funding + deactivate pos (#528)

* update

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

* Fix test

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

* 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>

* 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.

* Changelog for program-v0.11.0, bump version, update idl

* Don't reload openorders if there's no active markets

* update

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

* reorg

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

* Emit perp fees settled on update_funding. Required to have a full picture of total perp market fees. (#530)

---------

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
Co-authored-by: microwavedcola1 <89031858+microwavedcola1@users.noreply.github.com>
Co-authored-by: Christian Kamm <mail@ckamm.de>
Co-authored-by: Maximilian Schneider <mail@maximilianschneider.net>
Co-authored-by: tlrsssss <tjshipe@gmail.com>
Co-authored-by: Nicholas Clarke <nicholasgclarke@gmail.com>
2023-04-07 13:57:53 +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 f236a0521a
Fast I80F48 division with reduced precision (#300) 2022-11-24 11:59:00 +01:00
Christian Kamm 79a7bdc299 Checked math: support cm!(a += b) 2022-09-06 08:55:27 +02: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 8a2d54cce8 Fix some clippy warnings 2022-08-30 13:59:34 +02:00
Christian Kamm a3067e2448 Avoid custom Debug impls by using derivative crate 2022-08-13 10:18:04 +02:00
Christian Kamm b3568b7f3e
Make health/oracle functions usable from clients (#63)
* Make health/oracle functions usable from clients

By creating a shared trait that is implementable for AccountInfo and
AccountSharedData.

* Health: fixup tests
2022-06-08 13:43:12 +02:00
microwavedcola1 81f0f38188 ts client support for perps
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-05-11 20:06:07 +02:00
microwavedcola1 6db679d35e support longer account names
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-12 20:23:45 +02:00
microwavedcola1 03ae43017c account, market and bank names
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-04-12 16:19:58 +02:00
Christian Kamm 82819720e0 liq token: progress
Change bank.deposit()/withdraw() to work with I80F48 values so we don't
need to round during liquidation.
2022-03-27 14:46:51 +02:00
microwavedcola1 f895467bf5 weights
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-24 17:29:30 +01:00
Christian Kamm bfcb672116 Health: allow account order to be fixed, or to scan for accounts
The latter is important when we want to compute health for two different
accounts. Then the remainingAccounts would hold the union of the
necessary accounts, and each health check would need to look for the
accounts that it needs.

This patch al so reduces the compute needs for fixed-layout health
checks significantly (Deposit for an account with 8 tokens and 7 markets
takes 65k instead of 70k cu)
2022-03-22 14:13:07 +01:00
microwavedcola1 ec5e959804 further work on perps
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-22 07:06:33 +01:00
Christian Kamm 6aa4724b45 Serum: Health computation first steps 2022-03-16 16:45:54 +01:00
Christian Kamm 2502f0ac1b checked_math: use a panic
This reduces compute use further and still produces good error messages.
2022-03-14 12:45:32 +01:00
Christian Kamm 38d239462f checked_math: construct errors lazily
bad benchmark of compute needs for 100 add-assigns of I80F48:
3465 a + b
3465 a.checked_add(b).unwrap()
3465 cm with unwrap()     <- maybe future if we fix panics
4366 cm with ok_or_else() <- now
56494 cm with ok_or()     <- old
2022-03-13 20:55:28 +01:00
Christian Kamm 449fe4dc6d Add checked_math library for convenient overflow checking
Instead of
    x.checked_add(y).ok_or(error!(MangoError::MathError))?
we can write
    cm!(x + y)
2022-03-13 15:45:50 +01:00
microwavedcola1 2882476724 clipppy
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-07 15:24:50 +01:00
microwavedcola1 dcacadbcbf margin trade test
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-07 15:24:50 +01:00
microwavedcola1 ce5f2027a1 extract health, flesh out margin trade, todo - test
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
2022-03-03 11:43:56 +01:00