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/lp shares rebase #568

Merged
merged 33 commits into from
Aug 22, 2023
Merged

Bigz/lp shares rebase #568

merged 33 commits into from
Aug 22, 2023

Conversation

0xbigz
Copy link
Member

@0xbigz 0xbigz commented Aug 8, 2023

No description provided.

@0xbigz 0xbigz marked this pull request as ready for review August 12, 2023 19:48
programs/drift/src/controller/lp.rs Outdated Show resolved Hide resolved
programs/drift/src/controller/lp.rs Outdated Show resolved Hide resolved
programs/drift/src/controller/lp.rs Show resolved Hide resolved
base_unit = base_unit.safe_mul(rebase_divisor.cast()?)?;
} else {
let rebase_divisor = 10_u64.pow(position.per_lp_base.abs().cast()?);
n_shares = n_shares.safe_mul(rebase_divisor)?;
Copy link
Member

Choose a reason for hiding this comment

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

safe_div?


// 1/5 of fee auto goes to market
// the rest goes to lps/market proportional
let lp_fee = get_proportion_i128(
Copy link
Member

Choose a reason for hiding this comment

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

nit: might be less compute if you do (fee - fee/5)?

programs/drift/src/controller/position.rs Outdated Show resolved Hide resolved
programs/drift/src/state/perp_market.rs Outdated Show resolved Hide resolved
@crispheaney crispheaney merged commit fc5aa58 into master Aug 22, 2023
8 of 9 checks passed
0xbigz added a commit that referenced this pull request Aug 25, 2023
* start test

* improve lp_delta_quote

* improve per_lp_delta_quote

* init per_lp_base

* add rebase functions (wip)

* rm err msg

* add controller rebase to proper locations

* add rebase cargo test

* (wip) k out of wack

* fix rebase test and add more asserts

* format fix

* incorp basic example to typescript tests

* fix rebase math in position.rs (wip)

* wip continue

* working baseAssetAmountWithUnsettledLp

* mvp encapsulation of update_lp_market_position

* src/user.ts: add perLpBase to empty position

* remove logs

* simplify base unit logic more

* add get_per_lp_base_unit

* simplify per_lp_fee and add numbers to test

* properly set per_lp_base for lp_share=0 in mint_lp_shares (and add sdk/test)

* incorp feedback / format

* tests/liquidityProvider.ts: work with sdk change

* admin.rs: add constraint on per_lp_base range

* add apply_lp_rebase_to_perp_position to simulate_settled_lp_position

* use get_per_lp_base_unit consistently (wip sdk test for negative lp base)

* cut excess return values in calculate_lp_delta

* fix getPerpPositionWithLPSettle with negative perLpBase delta

---------

Co-authored-by: Chris Heaney <[email protected]>
lowkeynicc added a commit that referenced this pull request Aug 28, 2023
* sdk: release v2.37.1-beta.7

* program: fix place_and_make/take_spot

* amm_spread.rs: add conf_component logic (#577)

* amm_spread.rs: add conf_component logic

* update CHANGELOG.md

* order subscriber event emitter

* renaming new to update

* checking for length > 0 before emitting

* fixing new orders bug

* sdk: release v2.37.1-beta.8

* program: add lp shares rebase (#568)

* start test

* improve lp_delta_quote

* improve per_lp_delta_quote

* init per_lp_base

* add rebase functions (wip)

* rm err msg

* add controller rebase to proper locations

* add rebase cargo test

* (wip) k out of wack

* fix rebase test and add more asserts

* format fix

* incorp basic example to typescript tests

* fix rebase math in position.rs (wip)

* wip continue

* working baseAssetAmountWithUnsettledLp

* mvp encapsulation of update_lp_market_position

* src/user.ts: add perLpBase to empty position

* remove logs

* simplify base unit logic more

* add get_per_lp_base_unit

* simplify per_lp_fee and add numbers to test

* properly set per_lp_base for lp_share=0 in mint_lp_shares (and add sdk/test)

* incorp feedback / format

* tests/liquidityProvider.ts: work with sdk change

* admin.rs: add constraint on per_lp_base range

* add apply_lp_rebase_to_perp_position to simulate_settled_lp_position

* use get_per_lp_base_unit consistently (wip sdk test for negative lp base)

* cut excess return values in calculate_lp_delta

* fix getPerpPositionWithLPSettle with negative perLpBase delta

---------

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

* sdk: release v2.37.1-beta.9

* bigz/oracle-auction-oracle-validity-test (#584)

* sdk: fixes for getHealthComponents

* sdk: release v2.37.1-beta.10

* sdk: add option for marginCategory to getFreeCollateral (#573)

* sdk: release v2.37.1-beta.11

* wip save work

* sdk: updates to priorityfeesubscriber

* 25 default batch size

* tests: fix liquidateSpot health checks

* sdk: add debug for bulk account loader handleAccountCallbacks (#592)

* sdk: add debug for bulk account loader handleAccountCallbacks

* log callbacks individually

* sdk: release v2.37.1-beta.12

* configurable in polling config

* sdk: release v2.37.1-beta.13

* tests/driftClient.ts: add sleep

* bigz/fix-liquidatePerpAndLp-test (#593)

* bigz/fix-liquidatePerpAndLp-test

* uncomment out assert

* perpLpJit.ts: longer sleep for rc ts test

* perpLpJit.ts: longer sleep for rc ts test

* perpLpJit.ts: rm redundant check

* prepegMarketOrderBaseAssetAmount.ts: add sleep

* merge master

* v2.38.0

* sdk: release v2.38.1-beta.0

* feedback updates

* sdk: catch decoding error in polling drift client account subscriber

* sdk: release v2.38.1-beta.1

* Revert "sdk: catch decoding error in polling drift client account subscriber"

This reverts commit 36e0f0f.

* sdk: use decodeUnchecked in bulk account loader

* sdk: release v2.38.1-beta.2

* sdk: use decodeUnchecked in more places

* sdk: release v2.38.1-beta.3

* Revert "sdk: use decodeUnchecked in more places"

This reverts commit f11a3b0.

* sdk: use decodeUnchecked in PollingUserStatsAccountSubscriber

* sdk: fetchUserStatsAccount use decodeUnchecked

* sdk: update anchor to 0.28.1-beta.2 (#595)

* try 0.28.0

* try updating top dir anchor

* anchor 0.28.1-beta.2

* fix prettify

* CHANGELOG

* sdk: release v2.38.1-beta.4

---------

Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Chris Heaney <[email protected]>
Co-authored-by: bigzPubkey <[email protected]>
Co-authored-by: Nour Alharithi <[email protected]>
Co-authored-by: Evan Pipta <[email protected]>
lowkeynicc added a commit that referenced this pull request Aug 28, 2023
* sdk: PriorityFeeSubscriber init

* sdk: priority fee subscriber (fork) (#590)

* sdk: release v2.37.1-beta.7

* program: fix place_and_make/take_spot

* amm_spread.rs: add conf_component logic (#577)

* amm_spread.rs: add conf_component logic

* update CHANGELOG.md

* order subscriber event emitter

* renaming new to update

* checking for length > 0 before emitting

* fixing new orders bug

* sdk: release v2.37.1-beta.8

* program: add lp shares rebase (#568)

* start test

* improve lp_delta_quote

* improve per_lp_delta_quote

* init per_lp_base

* add rebase functions (wip)

* rm err msg

* add controller rebase to proper locations

* add rebase cargo test

* (wip) k out of wack

* fix rebase test and add more asserts

* format fix

* incorp basic example to typescript tests

* fix rebase math in position.rs (wip)

* wip continue

* working baseAssetAmountWithUnsettledLp

* mvp encapsulation of update_lp_market_position

* src/user.ts: add perLpBase to empty position

* remove logs

* simplify base unit logic more

* add get_per_lp_base_unit

* simplify per_lp_fee and add numbers to test

* properly set per_lp_base for lp_share=0 in mint_lp_shares (and add sdk/test)

* incorp feedback / format

* tests/liquidityProvider.ts: work with sdk change

* admin.rs: add constraint on per_lp_base range

* add apply_lp_rebase_to_perp_position to simulate_settled_lp_position

* use get_per_lp_base_unit consistently (wip sdk test for negative lp base)

* cut excess return values in calculate_lp_delta

* fix getPerpPositionWithLPSettle with negative perLpBase delta

---------

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

* sdk: release v2.37.1-beta.9

* bigz/oracle-auction-oracle-validity-test (#584)

* sdk: fixes for getHealthComponents

* sdk: release v2.37.1-beta.10

* sdk: add option for marginCategory to getFreeCollateral (#573)

* sdk: release v2.37.1-beta.11

* wip save work

* sdk: updates to priorityfeesubscriber

* 25 default batch size

* tests: fix liquidateSpot health checks

* sdk: add debug for bulk account loader handleAccountCallbacks (#592)

* sdk: add debug for bulk account loader handleAccountCallbacks

* log callbacks individually

* sdk: release v2.37.1-beta.12

* configurable in polling config

* sdk: release v2.37.1-beta.13

* tests/driftClient.ts: add sleep

* bigz/fix-liquidatePerpAndLp-test (#593)

* bigz/fix-liquidatePerpAndLp-test

* uncomment out assert

* perpLpJit.ts: longer sleep for rc ts test

* perpLpJit.ts: longer sleep for rc ts test

* perpLpJit.ts: rm redundant check

* prepegMarketOrderBaseAssetAmount.ts: add sleep

* merge master

* v2.38.0

* sdk: release v2.38.1-beta.0

* feedback updates

* sdk: catch decoding error in polling drift client account subscriber

* sdk: release v2.38.1-beta.1

* Revert "sdk: catch decoding error in polling drift client account subscriber"

This reverts commit 36e0f0f.

* sdk: use decodeUnchecked in bulk account loader

* sdk: release v2.38.1-beta.2

* sdk: use decodeUnchecked in more places

* sdk: release v2.38.1-beta.3

* Revert "sdk: use decodeUnchecked in more places"

This reverts commit f11a3b0.

* sdk: use decodeUnchecked in PollingUserStatsAccountSubscriber

* sdk: fetchUserStatsAccount use decodeUnchecked

* sdk: update anchor to 0.28.1-beta.2 (#595)

* try 0.28.0

* try updating top dir anchor

* anchor 0.28.1-beta.2

* fix prettify

* CHANGELOG

* sdk: release v2.38.1-beta.4

---------

Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Chris Heaney <[email protected]>
Co-authored-by: bigzPubkey <[email protected]>
Co-authored-by: Nour Alharithi <[email protected]>
Co-authored-by: Evan Pipta <[email protected]>

---------

Co-authored-by: lowkeynicc <[email protected]>
Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: bigzPubkey <[email protected]>
Co-authored-by: Nour Alharithi <[email protected]>
Co-authored-by: Evan Pipta <[email protected]>
Co-authored-by: lowkeynicc <[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.

None yet

2 participants