Skip to content

Negative Interest: Zeta Adjustment#599

Merged
jalextowle merged 33 commits intomainfrom
jalextowle/negative-interest/zeta-adjustment
Oct 11, 2023
Merged

Negative Interest: Zeta Adjustment#599
jalextowle merged 33 commits intomainfrom
jalextowle/negative-interest/zeta-adjustment

Conversation

@jalextowle
Copy link
Copy Markdown
Contributor

@jalextowle jalextowle commented Sep 28, 2023

This PR originally included changes that modified the share adjustment logic to correct for negative interest adjustments that would break our k-invariant. These changes were mostly included in other negative interest PRs.

This PR fixes the tests related to k invariance ad path independence. We have path invariance on the curve in the sense that the effective share reserves and bond reserves coordinates are invariant under trading without liquidity changes caused by addLiquidity and removeLiquidity. We do not have path independence if we instead look at the triple (shareReserves, shareAdjustment, bondReserves). This can be explained by the fact that some traders may have accrued negative interest while others haven't. If the negative interest trader gets the best price available, more of the LPs liabilities or proceeds will be susceptible to the scaling from negative interest. Re-ordering trades can change the amount of negative interest adjustments that are applied to the reserves.

Along with fixing tests to verify the zeta adjustment changes, this PR also includes a fix to openShort. Prior to this PR, shorts benefitted from negative interest that accrued in their checkpoint. In extreme cases (like those of a bad hack), shorts could be opened for free. This PR closes this loophole by clamping the share price to the open share price. The _minSharePrice field gives shorts an easy way to prevent themselves from opening a short in a checkpoint with negative interest.

@jalextowle
Copy link
Copy Markdown
Contributor Author

test_path_independence fails with some negative interest rates. One theory for why this could be happening is that the way that negative interest is handled causes the share price to change.

@jalextowle jalextowle changed the title Zeta Adjustment: Negative Interest Negative Interest: Zeta Adjustment Sep 28, 2023
@jalextowle jalextowle force-pushed the jalextowle/bug/negative-interest-mature-positions branch from 1f61fd0 to 7ed9d53 Compare September 28, 2023 22:41
@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/bug/negative-interest-mature-positions branch from 2620297 to 29fda0e Compare September 29, 2023 02:45
@jalextowle jalextowle force-pushed the jalextowle/negative-interest/zeta-adjustment branch from fe7796e to af25c00 Compare September 29, 2023 02:47
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`.
* Added a `minSharePrice`

* Fixed some tests

* Fixed the Rust codebase
…-mature-positions' into jalextowle/negative-interest/refactor
Base automatically changed from jalextowle/bug/negative-interest-mature-positions to main September 30, 2023 00:26
@jalextowle jalextowle changed the base branch from main to jalextowle/negative-interest/refactor October 6, 2023 14:21
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Oct 6, 2023

Hyperdrive Gas Benchmark

Benchmark suite Current: 7a6cdcf Previous: cdb87e1 Deviation Status
addLiquidity: min 807 gas 807 gas 0% 🟰
addLiquidity: avg 56921 gas 57193 gas -0.4756%
addLiquidity: max 98918 gas 98964 gas -0.0465%
checkpoint: min 514 gas 514 gas 0% 🟰
checkpoint: avg 30317 gas 30269 gas 0.1586% 🚨
checkpoint: max 79955 gas 69464 gas 15.1028% 🚨
closeLong: min 852 gas 852 gas 0% 🟰
closeLong: avg 23270 gas 23279 gas -0.0387%
closeLong: max 105073 gas 126328 gas -16.8252%
closeShort: min 854 gas 765 gas 11.6340% 🚨
closeShort: avg 24404 gas 24013 gas 1.6283% 🚨
closeShort: max 105436 gas 105208 gas 0.2167% 🚨
initialize: min 803 gas 803 gas 0% 🟰
initialize: avg 161926 gas 161940 gas -0.0086%
initialize: max 235547 gas 235574 gas -0.0115%
openLong: min 768 gas 768 gas 0% 🟰
openLong: avg 57166 gas 59480 gas -3.8904%
openLong: max 224842 gas 229350 gas -1.9656%
openShort: min 744 gas 744 gas 0% 🟰
openShort: avg 58138 gas 61265 gas -5.1041%
openShort: max 222623 gas 244292 gas -8.8701%
removeLiquidity: min 784 gas 784 gas 0% 🟰
removeLiquidity: avg 78898 gas 78678 gas 0.2796% 🚨
removeLiquidity: max 184133 gas 171450 gas 7.3975% 🚨

This comment was automatically generated by workflow using github-action-benchmark.

Base automatically changed from jalextowle/negative-interest/refactor to main October 9, 2023 16:07
@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Oct 10, 2023

Coverage Status

coverage: 97.106% (-0.1%) from 97.206% when pulling 7a6cdcf on jalextowle/negative-interest/zeta-adjustment into b7bffe4 on main.

@jalextowle jalextowle force-pushed the jalextowle/negative-interest/zeta-adjustment branch from fbd9ff9 to 6d7db94 Compare October 10, 2023 00:30
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 question about one of the tests

Comment thread test/integrations/hyperdrive/PresentValueTest.t.sol
@jalextowle jalextowle enabled auto-merge (squash) October 10, 2023 18:00
@jalextowle jalextowle merged commit 4f71cf0 into main Oct 11, 2023
@jalextowle jalextowle deleted the jalextowle/negative-interest/zeta-adjustment branch October 11, 2023 02:24
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