delvtech / hyperdrive

An automated market maker for fixed and variable yield with on-demand terms.
Apache License 2.0
25 stars 3 forks source link

Use the previous weighted spot price instead of the current weighted spot price for `addLiquidity` #1058

Closed jalextowle closed 2 weeks ago

jalextowle commented 2 weeks ago

Resolved Issues

Fixes: https://github.com/spearbit-audits/delv-week-review/issues/13

Description

This PR adds some tests to make sure that the weighted spot price behaves as expected with instantaneous trades and fixes an oversight where the current weighted spot price is used for the addLiquidity check instead of the previous weighted spot price.

The previous weighted spot price will never be 0 in addLiquidity because the current checkpoint is always minted with _applyCheckpoint. In _applyCheckpoint, we always update the previous weighted spot price. This uses the current spot price for the update, so unless the current spot price is 0, the weighted spot price will be non-zero. Some tests were added to clarify this.

Review Checklists

Please check each item before approving the pull request. While going through the checklist, it is recommended to leave comments on items that are referenced in the checklist to make sure that they are reviewed. If there are multiple reviewers, copy the checklists into sections titled ## [Reviewer Name]. If the PR doesn't touch Solidity, the corresponding checklist can be removed.

@mcclurejt

coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9554965756

Details


Totals Coverage Status
Change from base Build 9523138246: 0.0%
Covered Lines: 1965
Relevant Lines: 2133

šŸ’› - Coveralls
coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9554961305

Details


Totals Coverage Status
Change from base Build 9523138246: 0.0%
Covered Lines: 1965
Relevant Lines: 2133

šŸ’› - Coveralls
github-actions[bot] commented 2 weeks ago

Hyperdrive Gas Benchmark

Benchmark suite Current: 1bccaa4770ef8b93f7768ff5f9fc048bf1f264af Previous: e5525e96fea5bc61e0eec7fe694049aa6722aa1c Deviation Status
addLiquidity: min 33937 gas 33937 gas 0% šŸŸ°
addLiquidity: avg 155520 gas 155877 gas -0.2290% āœ…
addLiquidity: max 429244 gas 429437 gas -0.0449% āœ…
checkpoint: min 40316 gas 40316 gas 0% šŸŸ°
checkpoint: avg 144722 gas 144636 gas 0.0595% šŸšØ
checkpoint: max 255931 gas 255830 gas 0.0395% šŸšØ
closeLong: min 31361 gas 31361 gas 0% šŸŸ°
closeLong: avg 135883 gas 136439 gas -0.4075% āœ…
closeLong: max 2539376 gas 2621435 gas -3.1303% āœ…
closeShort: min 31327 gas 31327 gas 0% šŸŸ°
closeShort: avg 131252 gas 132305 gas -0.7959% āœ…
closeShort: max 400884 gas 272530 gas 47.0972% šŸšØ
initialize: min 31349 gas 31349 gas 0% šŸŸ°
initialize: avg 333397 gas 333352 gas 0.0135% šŸšØ
initialize: max 400023 gas 399922 gas 0.0253% šŸšØ
openLong: min 33370 gas 33370 gas 0% šŸŸ°
openLong: avg 173247 gas 174248 gas -0.5745% āœ…
openLong: max 334107 gas 335241 gas -0.3383% āœ…
openShort: min 33936 gas 33936 gas 0% šŸŸ°
openShort: avg 168353 gas 168925 gas -0.3386% āœ…
openShort: max 415244 gas 415870 gas -0.1505% āœ…
redeemWithdrawalShares: min 31251 gas 31251 gas 0% šŸŸ°
redeemWithdrawalShares: avg 75026 gas 75830 gas -1.0603% āœ…
redeemWithdrawalShares: max 305734 gas 305633 gas 0.0330% šŸšØ
removeLiquidity: min 31301 gas 31301 gas 0% šŸŸ°
removeLiquidity: avg 214867 gas 214933 gas -0.0307% āœ…
removeLiquidity: max 403825 gas 404194 gas -0.0913% āœ…

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

coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9556661001

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Totals Coverage Status
Change from base Build 9523138246: 0.07%
Covered Lines: 1971
Relevant Lines: 2138

šŸ’› - Coveralls
coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9556686918

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Totals Coverage Status
Change from base Build 9523138246: 0.07%
Covered Lines: 1971
Relevant Lines: 2138

šŸ’› - Coveralls
coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9556687808

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Totals Coverage Status
Change from base Build 9523138246: 0.07%
Covered Lines: 1971
Relevant Lines: 2138

šŸ’› - Coveralls
coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9556689438

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Totals Coverage Status
Change from base Build 9523138246: 0.07%
Covered Lines: 1971
Relevant Lines: 2138

šŸ’› - Coveralls
coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9556718283

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Totals Coverage Status
Change from base Build 9523138246: 0.07%
Covered Lines: 1971
Relevant Lines: 2138

šŸ’› - Coveralls
coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9556729015

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Totals Coverage Status
Change from base Build 9523138246: 0.07%
Covered Lines: 1971
Relevant Lines: 2138

šŸ’› - Coveralls
coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9556728706

Details


Totals Coverage Status
Change from base Build 9523138246: 0.07%
Covered Lines: 1971
Relevant Lines: 2138

šŸ’› - Coveralls
coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9557401375

Details


Totals Coverage Status
Change from base Build 9556880128: 0.07%
Covered Lines: 1971
Relevant Lines: 2138

šŸ’› - Coveralls
coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9570423024

Details


Totals Coverage Status
Change from base Build 9556880128: 0.02%
Covered Lines: 1969
Relevant Lines: 2137

šŸ’› - Coveralls