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

Introduce RecoveryModeHelper #2068

Merged
merged 3 commits into from
Nov 28, 2022
Merged

Introduce RecoveryModeHelper #2068

merged 3 commits into from
Nov 28, 2022

Conversation

nventuro
Copy link
Contributor

Description

This introduces an external helper contract that can be used to compute recovery mode exits. Unlike all exits we've had so far, it uses the 'cash' balance of the Pool exclusively. By placing this code outside of the Pool, we can reduce its bytecode size.

This initial version only works with Composable Pools, but it's easily extendable to also work with regular Pools. On a later PR I'll modify ManagedPool so that it uses this helper.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Dependency changes
  • Code refactor / cleanup
  • Documentation or wording changes
  • Other

Checklist:

  • The diff is legible and has no extraneous changes
  • Complex code has been commented, including external interfaces
  • Tests are included for all code paths
  • The base branch is either master, or there's a description of how to merge

Issue Resolution

Part of #2042

Copy link
Collaborator

@EndymionJkb EndymionJkb left a comment

Choose a reason for hiding this comment

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

Using cash is good future-proofing for when we start using asset managers for various unseeded things (managed add/remove, LBPs, etc.) Comments inline.

This should be highlighted in the documentation though, since recovery UIs or users on Etherscan would likely not think of this, and expect values proportional to the total balances

pkg/pool-utils/contracts/RecoveryModeHelper.sol Outdated Show resolved Hide resolved
pkg/pool-utils/contracts/RecoveryModeHelper.sol Outdated Show resolved Hide resolved

bptAmountIn = userData.recoveryModeExit();

amountsOut = WeightedMath._calcTokensOutGivenExactBptIn(cashBalances, bptAmountIn, virtualSupply);
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the same vein as the above comment about overfitting to pool types, we have several versions of the _calcTokensOutGivenExactBptIn function (and with stable it's embedded in the recovery mode exit). Since it's external anyway, maybe implement a version locally here (like the old _computeProportionalAmountsOut) for all pool types to use, so that we avoid using libraries specific to weighted pools?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I want to have those in the library for recovery mode user data decoding. I didn't do that yet because it'll cause conflicts with the stable composable branch merge, but we should do it once that's in.

Copy link
Contributor

Choose a reason for hiding this comment

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

@nventuro nventuro requested a review from EndymionJkb November 28, 2022 20:30
Copy link
Collaborator

@EndymionJkb EndymionJkb left a comment

Choose a reason for hiding this comment

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

Looks good then, given that the rest of the comments will be addressed in future PRs (after the stable deployment)

@nventuro nventuro merged commit c53bd24 into master Nov 28, 2022
@nventuro nventuro deleted the managed-recovery branch November 28, 2022 20:51
Copy link
Contributor

@jubeira jubeira left a comment

Choose a reason for hiding this comment

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

I was 30 secs late 💀
LGTM though; just a few nits / suggestions.

interface IRecoveryModeHelper {
/**
* @dev Computes a Recovery Mode Exit BPT and token amounts for a Pool. Only 'cash' balances are considered, to
* avoid scenarios where the last LPs to attempt to exit the Pool cannot because only 'managed' balance remains.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* avoid scenarios where the last LPs to attempt to exit the Pool cannot because only 'managed' balance remains.
* avoid scenarios where the last LPs to attempt to exit the Pool cannot do it because only 'managed' balance
* remains.

_vault = vault;
}

function getVault() public view returns (IVault) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe consider adding this to the interface?

Perhaps it's not necessary, but there are other interfaces where we do include it.


bptAmountIn = userData.recoveryModeExit();

amountsOut = WeightedMath._calcTokensOutGivenExactBptIn(cashBalances, bptAmountIn, virtualSupply);
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines +80 to +81
async updateManaged(poolId: string, managedl: BigNumberish[]): Promise<ContractTransaction> {
return this.instance.updateManaged(poolId, managedl);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
async updateManaged(poolId: string, managedl: BigNumberish[]): Promise<ContractTransaction> {
return this.instance.updateManaged(poolId, managedl);
async updateManaged(poolId: string, managed: BigNumberish[]): Promise<ContractTransaction> {
return this.instance.updateManaged(poolId, managed);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch! I didn't see that one

@jubeira jubeira mentioned this pull request Nov 28, 2022
11 tasks
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