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

5 - closePositions respects minimumTransactionAmount (depends on 4) #49

Open
wants to merge 4 commits into
base: mcclurejt/fix/min-tx-amount-buffer
Choose a base branch
from

Conversation

mcclurejt
Copy link
Contributor

@mcclurejt mcclurejt commented Dec 31, 2024

Currently, closePositions(..) does not check whether a partial closure will result in a position value less than the minimum transaction amount.

This PR adds the necessary logic for this check as well as a test to ensure it is behaving as expected.

issue

depends on changes from the fix for 4

@mcclurejt mcclurejt changed the title 5 - closePositions respects minimumTransactionAmount 5 - closePositions respects minimumTransactionAmount (depends on 4) Dec 31, 2024
Comment on lines 505 to 510
// Calculate the amount of bonds needed to reach the minimum
// transaction amount.
uint256 minimumBonds = minimumTransactionAmount().mulDivUp(
position.bondAmount,
totalPositionValue
);
Copy link

Choose a reason for hiding this comment

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

when you're closing longs, the minimum tx amount refers to bond amounts, you don't need to do any base <> share conversions then. just use _poolConfig.minimumTransactionAmount.

See https://github.com/delvtech/hyperdrive/blob/02d3cd465afbf86cc5f490c618a3a850c6dc6bfe/contracts/src/internal/HyperdriveLong.sol#L167-L171:

if (_bondAmount < _minimumTransactionAmount) {
    revert IHyperdrive.MinimumTransactionAmount();
}

Copy link

Choose a reason for hiding this comment

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

So I don't think we even need to do this calculation to convert it to base (or share) units.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! Thanks for pointing this out. Included the fix

// We need to close at least the `minimumTransactionAmount`
// value of bonds. It's safe to assume that the position
// has at least that much.
bondsNeeded = bondsNeeded.max(minimumBonds);
Copy link

Choose a reason for hiding this comment

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

see above: shouldn't this just be _poolConfig.minimumTransactionAmount?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After applying changes from above I decided to leave minimumBonds as a variable with a comment on why conversion isn't necessary.

I know it's a bit more gas but I feel like it's worth it for the readability/explanation.

Happy to change if you think otherwise :)

Currently, `closePositions(..)` does not check whether a partial closure
will result in a position value less than the minimum transaction
amount.

This PR adds the necessary logic for this check as well as a test to
ensure it is behaving as expected.

[issue](https://cantina.xyz/code/4f25dfd5-d3e6-4e7a-9481-d7306b795f2b/findings/5)
@mcclurejt mcclurejt force-pushed the mcclurejt/fix/close-positions-respect-min-tx-amount branch from e6060fd to 8464f8c Compare January 7, 2025 12:05
No conversions are needed for min tx amount when closing longs since
it's denominated in bonds not execution tokens
@mcclurejt mcclurejt requested a review from MrToph January 7, 2025 12:49
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