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

Repay/Withdraw max #123

Closed
wants to merge 12 commits into from
Closed

Repay/Withdraw max #123

wants to merge 12 commits into from

Conversation

MerlinEgalite
Copy link
Contributor

Fixes #40

@MerlinEgalite MerlinEgalite changed the title Repay/Withdraw all Repay/Withdraw max Jul 12, 2023
@MerlinEgalite MerlinEgalite marked this pull request as ready for review July 12, 2023 18:16
@MerlinEgalite MerlinEgalite linked an issue Jul 12, 2023 that may be closed by this pull request
pakim249CAL
pakim249CAL previously approved these changes Jul 12, 2023
makcandrov
makcandrov previously approved these changes Jul 12, 2023
src/Blue.sol Outdated Show resolved Hide resolved
test/forge/Blue.t.sol Outdated Show resolved Hide resolved
src/Blue.sol Show resolved Hide resolved
src/Blue.sol Outdated Show resolved Hide resolved
@MerlinEgalite MerlinEgalite requested a review from Rubilmax July 15, 2023 14:59
Copy link
Contributor

@MathisGD MathisGD left a comment

Choose a reason for hiding this comment

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

Copy link
Contributor

@QGarchery QGarchery left a comment

Choose a reason for hiding this comment

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

It would also be nice to have a concrete example of a rounding error that is prevented by this PR.

In general, I think that we should first make sure that we know where all the rounding errors can come from before doing patches like this, and try to find a solution that applies globally

@MerlinEgalite
Copy link
Contributor Author

It would also be nice to have a concrete example of a rounding error that is prevented by this PR.

In general, I think that we should first make sure that we know where all the rounding errors can come from before doing patches like this, and try to find a solution that applies globally

I don't understand your comment. The PR as it is, is not a patch of rounding but it allows to repay everything by passing type(uint256).max

@QGarchery
Copy link
Contributor

I don't understand your comment. The PR as it is, is not a patch of rounding but it allows to repay everything by passing type(uint256).max

You're right. I was thinking of the issue highlighted by @Jean-Grimal and how this PR introduces another type of rounding error (going from shares to amounts in the withdraw function)

@MerlinEgalite
Copy link
Contributor Author

I'm ok to put this PR on hold until we're clear about roundings, wdty?

@Rubilmax
Copy link
Collaborator

I'm ok to put this PR on hold until we're clear about roundings, wdty?

The rounding issue raised in this PR is actually introduced in this PR, and I believe I have a clear view over it, as described here: #123 (comment).
I am in favor of a change similar to what @Jean-Grimal suggested. I can take care of it.

@MerlinEgalite
Copy link
Contributor Author

Yes you can do a PR on top if you want.

Rubilmax and others added 3 commits July 19, 2023 14:08
Co-authored-by: Jean-Grimal <[email protected]>
Signed-off-by: Romain Milon <[email protected]>
Signed-off-by: Romain Milon <[email protected]>
…roundings

fix(repay/withdraw): edge case
Jean-Grimal
Jean-Grimal previously approved these changes Jul 20, 2023
makcandrov
makcandrov previously approved these changes Jul 24, 2023
pakim249CAL
pakim249CAL previously approved these changes Jul 25, 2023
Copy link
Contributor

@julien-devatom julien-devatom left a comment

Choose a reason for hiding this comment

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

The disadvantage of using a maxuint256 as exact value is that it complexity the implementation with a permit 2 into a Metamorpho vault where the amount is maximized by maxUint160.
You have to add a specific logic, such as

if(amount == type(uint160).max) 
    MORPHO.supply(market, type(uint256).max, address(this));

@Rubilmax
Copy link
Collaborator

The disadvantage of using a maxuint256 as exact value is that it complexity the implementation with a permit 2 into a Metamorpho vault where the amount is maximized by maxUint160.
You have to add a specific logic, such as

if(amount == type(uint160).max) 
    MORPHO.supply(market, type(uint256).max, address(this));

Why would the approval amount and the repay amount be equal? Can't we just approve type(uint160).max via Permit2 and repay type(uint256).max?

@MerlinEgalite
Copy link
Contributor Author

The disadvantage of using a maxuint256 as exact value is that it complexity the implementation with a permit 2 into a Metamorpho vault where the amount is maximized by maxUint160. You have to add a specific logic, such as

if(amount == type(uint160).max) 
    MORPHO.supply(market, type(uint256).max, address(this));

I'm not even sure we can use permit2 into ERC4626 vaults because you can't pass the signature if you follow the standard.

But this is a very good point though (and a bit annoying for the bulker).

@julien-devatom
Copy link
Contributor

We can, this is a workaround. My point is that if your contract build onto Blue has amount limitation, it locks the max repay/withdraw. Permit2 is just an example.

For example, on ma3 optimizer, the amount defined in repayWithPermit cannot be higher than maxUint128, since the amount is the same one as the permit2 signature one.

My first take would be just to acknowledge that this is a blue specification.
My second one would be to use min(amount, balance).

Btw for the Bulker, this is not blocking since the transferFrom2 and repay are handled separately.

@Rubilmax
Copy link
Collaborator

Indeed, it forces integrators to only use type(uint256).max to repay/withdraw all.
If we use the min, an integrator may expect to repay/withdraw x but would end up repaying/withdrawing less than x.

In any case, I don't think it's a big deal, so I'm ok with any solution, though I prefer the type(uint256).max option.

Reminder: this was also discussed in the corresponding issue.

@MerlinEgalite
Copy link
Contributor Author

Oh so let's integrate this

src/Blue.sol Outdated Show resolved Hide resolved
@Rubilmax Rubilmax dismissed stale reviews from pakim249CAL, makcandrov, Jean-Grimal, and themself via 0b37029 August 1, 2023 09:26
pakim249CAL
pakim249CAL previously approved these changes Aug 1, 2023
Jean-Grimal
Jean-Grimal previously approved these changes Aug 1, 2023
@Rubilmax Rubilmax force-pushed the feat/repay-withdraw-all branch from fd93b63 to 6c3f418 Compare August 4, 2023 15:34
@MathisGD
Copy link
Contributor

MathisGD commented Aug 4, 2023

Replaced by #194, now that we have the equivalent even with shares

@MathisGD MathisGD closed this Aug 4, 2023
@MerlinEgalite MerlinEgalite deleted the feat/repay-withdraw-all branch August 15, 2023 13:30
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.

Repay/Withdraw max
8 participants