Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bigz/add-lp-order-risk-mitigations #766

Merged
merged 21 commits into from
Jan 11, 2024

Conversation

0xbigz
Copy link
Member

@0xbigz 0xbigz commented Dec 14, 2023

No description provided.

Copy link

codecov bot commented Dec 14, 2023

Codecov Report

Merging #766 (3156829) into master (1e2d0ab) will decrease coverage by 0.04%.
Report is 17 commits behind head on master.
The diff coverage is 66.27%.

❗ Current head 3156829 differs from pull request most recent head 7b3c111. Consider uploading reports for the commit 7b3c111 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #766      +/-   ##
==========================================
- Coverage   74.66%   74.62%   -0.04%     
==========================================
  Files         128      128              
  Lines       29765    30011     +246     
==========================================
+ Hits        22224    22397     +173     
- Misses       7541     7614      +73     
Components Coverage Δ
drift 74.82% <66.27%> (-0.04%) ⬇️

@karthik-pepperdex
Copy link

hey @0xbigz, can you please give a brief of what kind of new risk parameters does this enforce?

@0xbigz
Copy link
Member Author

0xbigz commented Jan 4, 2024

hey @0xbigz, can you please give a brief of what kind of new risk parameters does this enforce?

created discord thread of summary for more accessibility
https://discord.com/channels/849494028176588802/1163928155736789082/threads/1192573342528585748

programs/drift/src/controller/orders.rs Outdated Show resolved Hide resolved
programs/drift/src/controller/orders.rs Show resolved Hide resolved
programs/drift/src/controller/pnl.rs Outdated Show resolved Hide resolved
programs/drift/src/controller/orders.rs Outdated Show resolved Hide resolved
programs/drift/src/controller/orders.rs Outdated Show resolved Hide resolved
let estimated_mark_offset = market
.amm
.last_ask_price_twap
.safe_add(market.amm.last_bid_price_twap)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this max with 0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think you want to start at the middle (mark) of these and end at the opposite side + buffer (based on volatility)

auction_start_price: Some(estimated_offset_to_start),
auction_end_price: Some(estimated_offset_to_close),
auction_duration: Some(80),
oracle_price_offset: Some(0),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think oyu can use oracle_price_offset with a limit order

market_index: market.market_index,
base_asset_amount,
reduce_only: true,
auction_start_price: Some(estimated_offset_to_start),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should ensure auction start/end/limit all are monotonically increasing/decreasing

@@ -92,6 +92,60 @@ impl OrderParams {

Ok(())
}

pub fn get_aggressive_close_params(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should have a bunch of tests

@crispheaney crispheaney merged commit 606ab63 into master Jan 11, 2024
8 of 9 checks passed
wphan added a commit that referenced this pull request Feb 27, 2024
* sdk: release v2.54.0-beta.5

* sdk: tweak polling tx confirmation (#812)

* sdk: fix tests not building

* sdk: tweak polling tx confirmation

* sdk: release v2.54.0-beta.6

* sdk: add option to get signed settlepnl tix from a market order (#813)

* sdk: add option to get signed settlepnl tix from a market order

* fix lint

* sdk: release v2.54.0-beta.7

* ts-sdk: remove unncessary logs on tx failure

* linter

* prettify

* sdk: release v2.54.0-beta.8

* math/constants.rs: correct QUOTE AMOUNTS constant name

* ts-sdk: filter out erroneous logs in EventSubscriber (#815)

* sdk: release v2.54.0-beta.9

* program: auto derisk lp positions in settle pnl (#766)

* bigz/add-lp-order-risk-mitigations

* friendly perp position iter

* update parmams mutability

* add time_since_last_liquidity_change

* add new variable to margin context mode

* add attempt to burn shares in force cancel/settle pnl

* remove from force cancel orders

* sdk: fix tests not building

* change place orders

* rmeove unused mut

* address some comments

* add to settle_pnl

* use oracle orders

* tweak order params

* oracle order tests

* add typescript test, fix order param market_type

* remove logic from settle_expired_position

* CHANGELOG

---------

Co-authored-by: Chris Heaney <[email protected]>

* sdk: release v2.54.0-beta.10

* v2.54.0

* sdk: release v2.55.0-beta.0

* Revert "sdk: release v2.55.0-beta.0"

This reverts commit 21c4a46.

* Revert "v2.54.0"

This reverts commit 63c7208.

* sdk: release v2.54.0-beta.11

* ts-sdk: fix mixing stopWaiting

* sdk: release v2.54.0-beta.12

* v2.54.0

* sdk: release v2.55.0-beta.0

* Added handling for signature time measurement (#818)

* Added handling for signature time measurement

* Added opt-in metrics flag to drift client

* fixed prettier

---------

Co-authored-by: lowkeynicc <[email protected]>

* sdk: release v2.55.0-beta.1

* sdk: fix ts timeout

* sdk: fix getUnrealizedPNL for market index 0

* sdk: release v2.55.0-beta.2

* sdk: release v2.55.0-beta.3

* sdk: dlp updates (#822)

* dlp updates

* add optional custom margin ratio param to initAndDeposit

* prettify

* sdk: release v2.55.0-beta.4

* program: fix risk reduction dlp burn from not being step size (#826)

* program: fix risk reduction dlp burn from not being step size

* CHANGELOG

* fix lp burn

* v2.55.0

* sdk: release v2.56.0-beta.0

* Luke/extra tx sending (#827)

* added raw tx endpoints to tx senders

* Swapped additional tx endpoints for callbacks

* sdk: account for settle lp in accoutnt breakdown (#828)

* sdk: add settle pnl option to cost basis calc

* sdk: catch error in priorityFeeSubscriber.load (#834)

* Replace sendRawTransaction with sendTransaction (#833)

* program: make it easier for jit fills (#835)

* program: make it easier for jit fills

* CHANGELOG

* sdk: prettify:fix

* sdk: release v2.56.0-beta.1

* v2.56.0

* sdk: release v2.57.0-beta.0

* devnet-market-index-23 (#837)

* devnet-market-index-23

* comment out used oracle

* sdk: release v2.57.0-beta.1

* program: add recenter amm ix (#836)

* bigz/add-amm-recenter-fcn

* add recenter-amm-2 test

* passing recenter_amm_2 test

* add test_move_amm test

* update todo msg

* add to adminClient

* add get_lower_bound_sqrt_k functor

* CHANGELOG

---------

Co-authored-by: Chris Heaney <[email protected]>

* sdk: release v2.57.0-beta.2

* v2.57.0

* sdk: release v2.58.0-beta.0

* add helius method to PriorityFeeSubscriber (#832)

* add helius method to PriorityFeeSubscriber

* eagerly convert PubicKey to string

* use helius from connection obj, or optional rpc url

* lints

* sdk: release v2.58.0-beta.1

* program: AmmPaused doesnt block all fills

* v2.58.0

* sdk: release v2.59.0-beta.0

* sdk: allow hotswap addresses in PriorityFeeSubscriber

* sdk: release v2.59.0-beta.1

* sdk: fix priorityFeeSubscriber rpc endpoint loading

* sdk: release v2.59.0-beta.2

* sdk: add max fee clamp to priority fee

* sdk: release v2.59.0-beta.3

* sdk: fix priority fee clamp, add getter

* sdk: release v2.59.0-beta.4

* program: bump phoenix dependency

* no state ws resub

* sdk: release v2.59.0-beta.5

* program: use decayed last_oracle_conf_pct as lower bound for update (#840)

* bigz/add-oracle-volatility-protections

* fix pct vs price bug, add test + changelog

* cleanup code (naming, mutables)

* program: add paused operations flag (#839)

* program: init pause_operations flag

* tweaks

* write tests for paused operations

* split out spot and perp operations

* fixes

* add sdk and use PerpOperation/SpotOperation naming convention

* fix update funding ix

* stop update to deprecated market status

* add admin fn

* add logging for admin fn

* CHANGELOG

* sdk: release v2.59.0-beta.6

* v2.59.0

* sdk: release v2.60.0-beta.0

* implement parallel processing in sync() method

---------

Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: lil perp <[email protected]>
Co-authored-by: lowkeynicc <[email protected]>
Co-authored-by: wphan <[email protected]>
Co-authored-by: 0xbigz <[email protected]>
Co-authored-by: Luke <[email protected]>
Co-authored-by: lowkeynicc <[email protected]>
Co-authored-by: Chester Sim <[email protected]>
Co-authored-by: Evan Pipta <[email protected]>
Co-authored-by: Nour Alharithi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants