Skip to content

Negative Interest: Round Trip#600

Merged
jalextowle merged 3 commits intojalextowle/bug/negative-interest-mature-positionsfrom
jalextowle/negative-interest/round-trip
Sep 29, 2023
Merged

Negative Interest: Round Trip#600
jalextowle merged 3 commits intojalextowle/bug/negative-interest-mature-positionsfrom
jalextowle/negative-interest/round-trip

Conversation

@jalextowle
Copy link
Copy Markdown
Contributor

@jalextowle jalextowle commented Sep 28, 2023

The current accounting system uses the share price at the beginning of the checkpoint to assess whether or not negative interest accrued in the checkpoint. With this in mind, the system doesn't distinguish between traders that opened their positions before or after the negative interest accrued. This has the consequence that opening a long after negative interest accrues in a checkpoint locks in an immediate loss (aside from slippage and fees) since the trader's proceeds will be discounted by the negative interest if they immediately close their long. There is a separate issue with shorts that needs to be addressed in a follow-up.

A solution to this problem is to add a parameter to openLong and openShort that allows trader's to specify a minimum share price at which to open their position. If the share price is lower than this threshold, the transaction will revert. This prevents traders from getting into a bad situation in the event that negative interest accrues atomically. It's good to allow the trader to pick their own tolerance because there may be yield sources in the future that accrue dust negative interest occasionally.

@jalextowle jalextowle force-pushed the jalextowle/negative-interest/zeta-adjustment branch from 45ca838 to fe7796e Compare September 28, 2023 22:41
@jalextowle jalextowle force-pushed the jalextowle/negative-interest/round-trip branch from 9ca3b3e to a1032de Compare September 28, 2023 22:41
Copy link
Copy Markdown
Contributor

@jrhea jrhea left a comment

Choose a reason for hiding this comment

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

lgtm - just a couple of nits.

Comment thread contracts/src/HyperdriveLong.sol
Comment thread contracts/src/HyperdriveShort.sol
@jalextowle jalextowle force-pushed the jalextowle/negative-interest/zeta-adjustment branch from fe7796e to af25c00 Compare September 29, 2023 02:47
@jalextowle jalextowle force-pushed the jalextowle/negative-interest/round-trip branch from f1ce4fa to 6525ba4 Compare September 29, 2023 02:47
@jalextowle
Copy link
Copy Markdown
Contributor Author

I need to fix the rust implementation in this PR.

@jalextowle jalextowle force-pushed the jalextowle/negative-interest/round-trip branch from ef62e6c to 6730117 Compare September 29, 2023 22:04
@jalextowle jalextowle changed the base branch from jalextowle/negative-interest/zeta-adjustment to jalextowle/bug/negative-interest-mature-positions September 29, 2023 22:04
@jalextowle jalextowle merged commit 0950f34 into jalextowle/bug/negative-interest-mature-positions Sep 29, 2023
@jalextowle jalextowle deleted the jalextowle/negative-interest/round-trip branch September 29, 2023 22:04
jalextowle added a commit that referenced this pull request Oct 9, 2023
* Made some progress on the negative interest issues

* Simplified the mature negative interest flow and fixed the flow for shorts

* Fixed a discrepancy in the negative interest logic in `closeLong`

* Cleanup

* Fixed issue after merge

* Refactored out `sharePaymentWithoutFees`

* Refactored out `shareProceedsWithFees`

* Addressed review feedback from @jrhea

* "Fixed" an intermittent failure in `test_lp_withdrawal_long_and_short_maturity

* Commit intermmediate progress

* Made the share adjustment fixes

* Added a `minSharePrice`

* Fixed some tests

* Fixed the Rust codebase

* Name changes in `HyperdriveLong`

1. `shareReservesDelta` and `bondReservesDelta` always refer to the
   amount of shares or bonds that are being added or subtracted from the
   share reserves.
2. `shareCurvePayment` refers to the amount of shares priced by the
   curve. We think of this as a payment because the LPs are paying
   shares in return for a proceed in bonds, `bondCurveProceeds`.

* Removed the long share price and did some renaming in `HyperdriveShort`

* De-duplicated the negative interest logic between `closeLong` and `closeShort`

* Renamed `shareCurvePayment` and `shareCurveProceeds` to `shareCurveDelta`

* Negative Interest: Round Trip (#600)

* Added a `minSharePrice`

* Fixed some tests

* Fixed the Rust codebase

* Renamed `bondCurvePayment` and `bondCurveProceeds` to `bondCurveDelta`

* Fixed issues after merge

* Addressed review feedback
jalextowle added a commit that referenced this pull request Oct 11, 2023
* Made some progress on the negative interest issues

* Simplified the mature negative interest flow and fixed the flow for shorts

* Fixed a discrepancy in the negative interest logic in `closeLong`

* Cleanup

* Fixed issue after merge

* Refactored out `sharePaymentWithoutFees`

* Refactored out `shareProceedsWithFees`

* Addressed review feedback from @jrhea

* "Fixed" an intermittent failure in `test_lp_withdrawal_long_and_short_maturity

* Commit intermmediate progress

* Made the share adjustment fixes

* Added a `minSharePrice`

* Fixed some tests

* Fixed the Rust codebase

* Name changes in `HyperdriveLong`

1. `shareReservesDelta` and `bondReservesDelta` always refer to the
   amount of shares or bonds that are being added or subtracted from the
   share reserves.
2. `shareCurvePayment` refers to the amount of shares priced by the
   curve. We think of this as a payment because the LPs are paying
   shares in return for a proceed in bonds, `bondCurveProceeds`.

* Removed the long share price and did some renaming in `HyperdriveShort`

* De-duplicated the negative interest logic between `closeLong` and `closeShort`

* Renamed `shareCurvePayment` and `shareCurveProceeds` to `shareCurveDelta`

* Negative Interest: Round Trip (#600)

* Added a `minSharePrice`

* Fixed some tests

* Fixed the Rust codebase

* Renamed `bondCurvePayment` and `bondCurveProceeds` to `bondCurveDelta`

* Fixed issues after merge

* Fixed the path independence test and added a test for k invariance

* Addressed review feedback

* Cleaned up the comments

* Fixed a bug in `openShort` caused by negative interest

* Added negative interest to `test_path_independence`
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.

2 participants