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

Safer swap fee bounds #1054

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Safer swap fee bounds #1054

wants to merge 21 commits into from

Conversation

EndymionJkb
Copy link
Collaborator

Description

We check that the swap fee can never be > 100% (to keep the math well-behaved), but if it is exactly 100%, ExactOut swaps will revert with an arithmetic error, which is not ideal.

It is also confusing that we have something called MAX_FEE_PERCENTAGE that is set to 1e18 - when the actual maximum fee is less than that. Also, it is used interchangeably with 1e18/FixedPoint.ONE, which makes an invalid assumption.

This sets the values that should be 1e18 to FixedPoint.ONE, and sets MAX_FEE_PERCENTAGE to a value less than 1e18. Since we also have precision constraints, it is reasonable to set it to the maximum value under 100% that meets the precision.

The same fix applies to the pool creator fee (i.e., in case all other fees are 0, to keep the LP fees > 0).

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

Resolves #1053
Resolves #887

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!

# Conflicts:
#	pkg/pool-stable/test/gas/.hardhat-snapshots/[StablePool - Standard] add liquidity unbalanced - warm slots
#	pkg/pool-stable/test/gas/.hardhat-snapshots/[StablePool - With rate] remove liquidity single token exact out - warm slots
# Conflicts:
#	pkg/vault/test/.contract-sizes/VaultAdmin
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.

Clearer revert reason for 100% fees Consider limiting pool creator fee to 99%
2 participants