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

Stable2 + WellUpgradeable #135

Merged
merged 85 commits into from
Sep 6, 2024
Merged

Stable2 + WellUpgradeable #135

merged 85 commits into from
Sep 6, 2024

Conversation

Brean0
Copy link
Contributor

@Brean0 Brean0 commented Jul 23, 2024

RFC: Stable2 Well Function

Author

bean, deadmanwalking

Summary

  • Introduce a new Well Function that allows for low slippage trades for like valued assets.

Motivation

  • Current Well Functions do not offer low slippage trading for like valued assets, which is capital inefficient.

Technical Specification

Beanstalk requires that a Well Function inherit IBeanstalkWellFunction, which requires an additional 2 functions to be implemented:

  • calcReserveAtRatioSwap calculates a reserve with a target ratio, reached through executing a swap.
  • calcReserveAtRatioLiquidity calculates a reserve with a target ratio, reached through adding/removing liquidity.

This is done using newton method, by iteratively adjusting reserves until a target ratio is found. Given the computational complexity of doing this on chain, a Lookup table is implemented in order to provide an initial guess and step size, such that the function converges within an reasonable amount of iterations.

Stable2 Lookup Tables must Inherit ILookupTable, which requires the following functions:

  • getAParameter() Returns the A parameter this lookup table was written for. A Stable2 Well Function must have the same A parameter as its Lookup Table in order to ensure an accurate initial guess and step size.
  • getRatiosFromPriceSwap(uint256) Given a price, returns the ratios of a pool with a price slightly higher and lower than the input price, through a swap.
  • getRatiosFromPriceLiquidity(uint256) Given a price, returns the ratios of a pool with a price slightly higher and lower than the input price, through adding or removing liquidity.

Given the ratios at the price higher and lower than the target price, The Well function is able to assume that the target ratio is within the bounds of the higher and lower ratios, and thus the initial guess and step size is relatively close to the final reserve (and can converge within 1-2 iterations in most cases). Future development can be done to optimize the Lookup Table values (such that most prices converge within 1 iteration), with a tighter price spread (Currently set to 0.01%)

RFC: Upgradeable Well

Author

deadmanwalking, brean

Summary

  • Introduce a new Well Implementation (WellUpgradeble.sol) that supports ownership and upgradeability. This Well Implementation allows for Well Owners to adjust its Well components (adding/removing Pumps, changing Well Functions or Implementation).

Motivation

  • Current Well Implementations are immutable, effectively bricking them when a bug is found on one of the Well Components.

Technical Specification

WellUpgradeble.sol is EIP-1822 Universal Upgradeable Proxy Standard (UUPS) compatible in order to support upgradeability of the Well.

Because Wells bored by an Aquifer requires that the Well is initialized, the Upgradeable Well Implementation provides 2 initialization functions:

-initNoWellToken() has no logic other than the initializer modifier. This should be used when initially boring the well with immutable data.

  • init() performs the standard initialization seen in Well.sol, with the addition of __Ownable_init(). This reinitializes the well with value of 2. Users using upgradeable Wells should verify that the initializer is set to 2 prior to use.

In order to upgrade the Well, the new implementation must also be a Well that was bored by an Aquifer. The UUPS proxiableUUID does not support proxy contracts out of box, given that a proxy could infinitely point to additional proxies and brick the contract. However, Wells are minimal proxy clones, which are immutable and thus do not have this issue. Thus, proxiableUUID was updated to support minimal proxy clones.

@Brean0 Brean0 requested a review from nickkatsios August 14, 2024 10:14
nickkatsios and others added 23 commits August 21, 2024 13:37
`notDelegatedOrIsMinimalProxy` modifier fix [#26]
Add check for new well tokens in `authorizeUpgrade` [#23]
Add explicit reverts in functions that use Newton's method after non-convergence [#19]
Add access control to `authorizeUpgrade` [#60] [#18]
Stable2 Well Function and Upgradeable Well Remediations.
@nickkatsios nickkatsios merged commit 582a98e into master Sep 6, 2024
2 checks passed
@nickkatsios nickkatsios deleted the stableswapWF-2 branch September 6, 2024 10:13
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.

2 participants