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

build: limit modules #179

Merged
merged 12 commits into from
Oct 6, 2023
Merged

build: limit modules #179

merged 12 commits into from
Oct 6, 2023

Conversation

Schlagonia
Copy link
Collaborator

Description

  • add a default max_withdraw function that simulates a actual withdraw to make sure the maxWithdraw and maxRedeem functions comply to the 4626 standard.
  • add the option to add deposit and withdraw modules for custom deposit and withdraw limits.

Fixes # (issue)

Checklist

  • I have run vyper and solidity linting
  • I have run the tests on my machine
  • I have followed commitlint guidelines
  • I have rebased my changes to the latest version of the main branch

Copy link
Contributor

@jmonteer jmonteer left a comment

Choose a reason for hiding this comment

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

  1. I have a concern about a vault manager using both deposit_limit and deposit_limit_module and not have the expected output. (i.e. set deposit_limit to 0 while deposit_limit_module returns a different value can lead to the manager to think nobody can deposit, but that not being true). A potential solution could be to require deposit_limit to be uint256.max to set deposit_limit_module, and deposit_limit_module to be set to empty(address) if you want to set deposit_limit. Does that make sense?

  2. The only think I don't like about deposit_limit_module and withdraw_limit_module is that it adds gas to the most basic functions (deposit and redeem). but I like freedom of set up

@Schlagonia
Copy link
Collaborator Author

  1. I have a concern about a vault manager using both deposit_limit and deposit_limit_module and not have the expected output. (i.e. set deposit_limit to 0 while deposit_limit_module returns a different value can lead to the manager to think nobody can deposit, but that not being true). A potential solution could be to require deposit_limit to be uint256.max to set deposit_limit_module, and deposit_limit_module to be set to empty(address) if you want to set deposit_limit. Does that make sense?

This is a good point. Added asserts to both setters to make sure both arent used at once 5cc8b5f

  1. The only think I don't like about deposit_limit_module and withdraw_limit_module is that it adds gas to the most basic functions (deposit and redeem). but I like freedom of set up

Yes, its not ideal. However the withdraw_limit_module could actually be cheaper due to the need to iterate over a queue in order to get a correct amount with the new version.

contracts/VaultV3.vy Outdated Show resolved Hide resolved
contracts/VaultV3.vy Outdated Show resolved Hide resolved
@@ -443,6 +459,9 @@ def _convert_to_assets(shares: uint256, rounding: Rounding) -> uint256:
"""
assets = shares * (total_assets / total_supply) --- (== price_per_share * shares)
"""
if shares == MAX_UINT256:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we also special case 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well people shouldnt be sending 0 in any of the external functions as an input.

But there is the case that the report event calls convert_to_assets twice with a 0 value if no fees are charged. So it would save gas there

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added ecf23db

Copy link
Collaborator

@fp-crypto fp-crypto left a comment

Choose a reason for hiding this comment

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

LGTM, but i did have 1 minor comment #179 (comment)

@Schlagonia Schlagonia merged commit 0387181 into yearn:master Oct 6, 2023
7 checks passed
@Schlagonia Schlagonia deleted the limit-module branch October 6, 2023 23:08
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