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

fix: deposit flow #209

Merged
merged 13 commits into from
Sep 19, 2024
Merged

fix: deposit flow #209

merged 13 commits into from
Sep 19, 2024

Conversation

Schlagonia
Copy link
Collaborator

@Schlagonia Schlagonia commented Sep 10, 2024

Description

  • Combine internal deposit and mint functionality into 1 function.
  • Remove issue_shares_for_amount in order to use consistent logic for both routes.
  • Still allow deposits AND mint to work if totalSupply == 0 but totalAssets > 0. Just make PPS == 1.

This can happen due to the profit unlocking if all shares are redeemed while some profit is still unlocking, at the end of the unlock time totalAssets >0 but totalSupply == 0.

  • Still return 0 in convertToShares if totalSupply > 0 but totalAssets == 0. Meaning a full loss.
  • Optimize to not cache totalAssets_ until needed
    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

@Schlagonia Schlagonia force-pushed the deposit_flow branch 2 times, most recently from be419b9 to 36757ef Compare September 11, 2024 18:08
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.

More eyes are better

contracts/VaultV3.vy Show resolved Hide resolved

assert assets > 0, "cannot deposit zero"
assert shares > 0, "cannot mint zero"

# Transfer the tokens to the vault first.
self._erc20_safe_transfer_from(self.asset, msg.sender, self, assets)
Copy link

Choose a reason for hiding this comment

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

Why not use the input parameter sender instead of msg.sender?
Below in the event Deposit, parameter sender is used.

I would either remove the sender parameter and go with msg.sender in both places or use the sender address for both, to limit confusion.

Copy link
Collaborator Author

@Schlagonia Schlagonia Sep 19, 2024

Choose a reason for hiding this comment

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

good point

I believe it is actually cheaper to use msg.sender than using a memory variable. And clearer so will remove the variable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

with ape.reverts("cannot mint zero"):
vault.deposit(amount, fish, sender=fish)

# shares should not be
Copy link

Choose a reason for hiding this comment

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

Shares should not be minted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

assert vault.pricePerShare() == 0
assert vault.convertToShares(amount) == 0
assert vault.convertToAssets(amount) == 0
# assert vault.maxDeposit(fish) == 0
Copy link

Choose a reason for hiding this comment

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

maxDeposit() won't return 0 but uint256.max?

return unsafe_sub(_deposit_limit, _total_assets)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, maxDeposit and maxMint wont be accurate currently in this scenario

Not sure any good way to fix it though without adding way to much complexity and extra gas.

Seems like such a minor edge case that it is not worth it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Realistically if this happens no-one should be trying to deposit and a manager should shutdown the vault anyway which will reduce the deposit limit.

Comment on lines 582 to 587
# shares should not be
assert vault.balanceOf(fish) == amount
assert vault.pricePerShare() == 0
assert vault.convertToShares(amount) == 0
assert vault.convertToAssets(amount) == 0
# assert vault.maxMint(fish) == 0
Copy link

Choose a reason for hiding this comment

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

The same questions as above, for deposit flow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

maxMint will be accurate if there is a non-max uint deposit limit, since it will then do the full conversion

@Schlagonia Schlagonia merged commit 42afe0c into 3_0_3 Sep 19, 2024
7 of 8 checks passed
@Schlagonia Schlagonia deleted the deposit_flow branch September 19, 2024 21:04
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.

4 participants