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

Filter surge cases for unbalanced liquidity #1259

Merged
merged 7 commits into from
Jan 30, 2025

Conversation

jubeira
Copy link
Contributor

@jubeira jubeira commented Jan 24, 2025

Description

PoC: allow unbalanced liquidity for stable surge, blocking operations that would make the pool surge past the threshold (proportional excluded).

Using after hooks because it's easier to reconstruct original balances without caring about the operation kind. Also prevents reloading balances unnecessarily at the vault.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Dependency changes
  • Code refactor / cleanup
  • Optimization: [ ] gas / [ ] bytecode
  • Documentation or wording changes
  • Other

Checklist:

  • The diff is legible and has no extraneous changes
  • Complex code has been commented, including external interfaces
  • Tests have 100% code coverage
  • The base branch is either main, or there's a description of how to merge

Issue Resolution

@jubeira jubeira requested a review from EndymionJkb January 28, 2025 20:33
@jubeira jubeira marked this pull request as ready for review January 28, 2025 20:33
@jubeira jubeira requested a review from joaobrunoah January 28, 2025 20:34
Copy link
Collaborator

@EndymionJkb EndymionJkb left a comment

Choose a reason for hiding this comment

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

Looks good!

pkg/pool-hooks/contracts/StableSurgeHook.sol Outdated Show resolved Hide resolved
Copy link
Contributor

@joaobrunoah joaobrunoah left a comment

Choose a reason for hiding this comment

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

LGTM!

address pool,
uint256 staticSwapFeePercentage
) public view returns (uint256) {
uint256 amountCalculatedScaled18 = StablePool(pool).onSwap(params);
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be a very stupid idea, and maybe it's too late for this.

This line is an approximation, since the real amount calculated will be affected by the surge fee. If this is an approximation, why don't we use the linear math instead of the pool math, which is cheaper in terms of gas? The result of the linear math will be more pessimist, so the fee tends to be a bit higher, which favors the vault and LPs. Besides, the math is simpler.

@jubeira jubeira merged commit 4680d59 into main Jan 30, 2025
14 checks passed
@jubeira jubeira deleted the stable-surge-disable-unbalanced-liquidity branch January 30, 2025 21:25
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