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
Contributor

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
Contributor

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
Contributor

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
Contributor

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
Schlagonia added a commit that referenced this pull request Sep 24, 2024
* chore: updgrade ape

* build: allow max uint (#204)

* build: allow max uint

* fix: lint version

* forge install: openzeppelin-contracts

v4.9.5

* chore: oz sub module

* forge install: tokenized-strategy

v3.0.2

* test: fix foundry tests

* chore: bump version

* fix: workflow (#207)

* chore: update wf version

* chore: add statemind report

* feat: update name and symbol (#206)

* feat: set name and symbol

* chore: spech

* test: fix emergency

* fix: test workflow (#208)

* fix: config override

* chore: manual setup

* fix: requirements

* fix: ape version

* chore: rebase

* chore: dont double pull from storage (#212)

* feat: report on self (#205)

* feat: report on self

* chore: comment

* chore: add back

* build: auto allocate (#203)

* build: auto allocate

* build: dont revert debt increase

* chore: remove decrease revert

* chore: update spech

* chore: spech

* chore: comments

* fix: event

* fix: comments

Co-authored-by: spalen0 <[email protected]>

* feat: pack pf config (#211)

* feat: pack pf config

* chore: remove event

* chore: formatting

* test: interface updates

* chore: comments

* fix: deposit flow (#209)

* forge install: openzeppelin-contracts

v4.9.5

* chore: oz sub module

* test: fix foundry tests

* fix: deposit flow

* fix: zero total assets

* fix: flow

* test: full loss

* chore: comment

* test: add invariants

* fix: comments

* fix: user msg sender

* fix: comments

* fix: comment

* chore: add to interfaces

* fix: comments

* chore: match gov abi (#213)

* chore: deployment

* chore: deployed

---------

Co-authored-by: FP <[email protected]>
Co-authored-by: spalen0 <[email protected]>
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