-
Notifications
You must be signed in to change notification settings - Fork 79
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
BIP–48: Whitelist BEANwstETH and Migrate Unripe Liquidity #758
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
BrendanSanderson
changed the base branch from
bip39-seedGauge
to
seedGauge-v0.1-review
January 26, 2024 17:45
Brean0
requested changes
Feb 13, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
review 1
Brean0
reviewed
Feb 13, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
review 1
BrendanSanderson
changed the title
Add stEth oracle
BIP–X: Implement WStEth Oracle + Whitelist Bean:Eth -> Bean:WStEth + Migrate Barn Raise Liquidity from Bean:Eth -> Bean:WStEth
Feb 13, 2024
Brean0
approved these changes
Jul 26, 2024
BeanstalkFarmsOperations
approved these changes
Jul 26, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BIP-48: Whitelist BEANwstETH and Migrate Unripe Liquidity
Proposer
Beanstalk Farms, Brendan Sanderson, Ben Weintraub
Proposer Wallet: 0xf1a621fe077e4e9ac2c0cefd9b69551db9c3f657
Summary
Links
Problem
Opportunities for Bean liquidity providers to receive Stalk and Seed rewards are currently limited. A wider variety of options increases utility for Silo Depositors and will be possible with the combination of the Seed Gauge System and Generalized Convert.
Beanstalk could be offering higher yield opportunities to Bean liquidity providers, including Unripe LP holders, via the ETH staking yield with minimal additional trust assumptions.
As of writing, over 99% of liquidity for Beans is currently in the BEANETH Well, which uses Multi Flow v1.0.0. Multi Flow v1.0.0 does not have a way to change the exchange rate between Well reserves when the cap on the maximum percent change in reserves per block is reached (see EBIP-9).
Beanstalk currently does not support multiple Unripe LP tokens.
Currently, the ETH:USD oracle defaults to using Chainlink when the Chainlink price is greater than 1% different than the prices in the ETH:USDC and ETH:USDT Uniswap V3 pools (which is considered manipulation).
Proposed Solution
Whitelist a BEAN:wstETH Constant Product 2 Well with Multi Flow Pump v1.1.0 for Deposit in the Silo.
We propose to set the initial Gauge Points of BEANwstETH to 400 and set the optimal distribution of the LP Seed Gauge System to 80% BEANwstETH and 20% BEANETH.
wstETH:USD Oracle Design
Beanstalk requires a wstETH:USD oracle in order to compute deltaB in the BEAN:wstETH Well.
The oracle reads from multiple data sources and calculates the wstETH:ETH price using 3 separate methods:
And computes a final wstETH:ETH price via the following logic:
Multiplying the wstETH:ETH and ETH:USD prices results in the final wstETH:USD price.
Multi Flow v1.1.0
Multi Flow v1.1.0 introduces the ability to set the maximum percent change in exchange rate between any two tokens in a Well per block. We propose setting this parameter to 0.5%.
Multi Flow v1.1.0 also introduces the ability the set the maximum percent change in LP token supply in a Well per block. We propose setting this parameter to 3%.
Because the existing BEANETH Well uses Multi Flow v1.0.0 which does not contain these improvements, we propose turning off minting from the BEANETH Well for 24 Seasons upon the deployment of this BIP while the reserves stored in its Pump catch up to the reserves in the Well post-Unripe liquidity migration.
Migration Process
Migrate the BEANETH Well LP tokens that underly the urBEANETH token to BEANwstETH Well LP tokens. In doing so, the liquidity underlying urBEANETH is migrated to the BEANwstETH Well and the urBEANETH token becomes the urBEANwstETH token (albeit, with the same token address).
*If the DAO can get a better execution price by directly staking WETH for stETH (rather than swapping), the BCM will do this.
During the migration process, attempts to Deposit, Convert or Chop Unripe assets will revert. After the migration process is complete, Conversions between urBEAN and urBEANwstETH will Convert in/out of the BEANwstETH Well instead of the BEANETH Well.
The cost of slippage during Step (3) is passed on to Unripe LP holders.
Fertilizer Changes
Upgrade the Barn to add liquidity to the BEANwstETH Well instead of the BEANETH Well upon each Fertilizer purchase.
As a result:
ETH:USD Oracle Design
Beanstalk requires an ETH:USD oracle in order to compute deltaB in the BEAN:ETH and BEAN:wstETH Wells. We propose to remove Uniswap V3 as an input to this price oracle, such that Beanstalk calculates the ETH:USD price exclusively using Chainlink.
Technical Rationale
The Season Facet must be updated to generalize
stepOracle
to support minting in any whitelisted Well.Given that the migration process cannot be executed atomically and Unripe asset functionality will be in a broken state during it, attempts to Deposit, Convert or Chop Unripe assets during the migration process will revert.
The Fertilizer Facet must be updated to use the new Barn Raise token (wstETH), which is now abstracted away via the new
LibBarnRaise
library.The Unripe Facet, BDV Facet,
LibConvert
,LibUnripeConvert
,LibEvaluate
andLibFertilizer
must be updated to reflect the use ofLibBarnRaise
.All of the oracle libraries are updated to be generalized to support reading data for any tokens that Beanstalk supports.
Economic Rationale
Beanstalk could be offering higher yield opportunities to Bean liquidity providers (and Unripe LP holders) via the ETH staking yield with minimal additional trust assumptions. stETH has the largest TVL of any liquid staking derivative. All other liquid staking derivatives with reasonable market adoption – a requirement for sufficient decentralization – still have arbitrary and unilateral upgradability privileges held by a small party.
Basin does not have a Well Implementation that tracks rebasing tokens. Thus, Basin (and thus, Beanstalk) must use wstETH (i.e., the wrapped, non-rebasing version of stETH).
Setting the optimal LP BDV distribution to 80% BEANwstETH and 20% BEANETH reflects the preference for higher yield opportunities to Depositors. Setting the BEANwstETH Gauge Points to 400 initializes the Gauge Point distribution with the same proportions as the optimal LP BDV distribution (BEANETH currently has 100 Gauge Points).
There is no wstETH:USD Chainlink feed on Ethereum mainnet. Using 3 sources for the wstETH:ETH prices increases accuracy and reliability.
For as long as most liquidity for Beans is in the existing BEANETH Well, Beanstalk is still subject to risks associated with Multi Flow v1.0.0 that were pointed out in EBIP-9.
Setting the percent exchange rate change per block cap and percent LP token supply change per block cap in Multi Flow v1.1.0 to 0.5% and 3%, respectively, minimizes both potential inter-block MEV manipulation and instances where the Pump reserves are out of sync with the Well reserves. Investigation of past data in the ETH:USDC and ETH:USDT Uniswap V2 pools can be found here.
The Uniswap V3 component of the existing ETH:USD oracle serves little to no purpose given that it already defaults to Chainlink in the case of manipulation.
Contract Changes
Initialization Contract
The
init
function on the followingInitMigrateUnripeBeanEthToBeanSteth
contract is called:0x15A2053B3d559d19FeD2D7FC429304e837cEFa00
BDV Facet
The following
BDVFacet
is being removed from Beanstalk:0xB752bfD626AD8715DE26D9bf3b3512F13632CCa1
The following
BDVFacet
is added to Beanstalk:0xaef84C2B863aB845F59f672d958B175262dcfc89
BDVFacet
Function ChangesbeanToBDV
0x5a049a47
curveToBDV
0xf984019b
unripeBeanToBDV
0xc8cda2a0
unripeLPToBDV
0xb0c22bb1
wellBdv
0xc84c7727
Convert Facet
The following
ConvertFacet
is removed from Beanstalk:0x1C55d002bf78Ced8cb4ebd8F4Cf39Ff93835C934
The following
ConvertFacet
is added to Beanstalk:0xEb1b833D3E81cb3d390514cabB9b809E6170626C
ConvertFacet
Function Changesconvert
0xb362a6e8
Convert Getters Facet
The following
ConvertGettersFacet
is removed from Beanstalk:0x0a4121F3c4ACd9825Ed5499ACAD9fEA7a8a4eeED
The following
ConvertGettersFacet
is added to Beanstalk:0x8ABa09526dc6EB6Ea44eE3f8745dD8bc9EF744E2
ConvertGettersFacet
Function ChangesgetAmountOut
0x4aa06652
getMaxAmountIn
0x24dd285c
Enroot Facet
The following
EnrootFacet
is removed from Beanstalk:0x3780b8268F19118E7e44B9FEF6CA090bC5E077e6
The following
EnrootFacet
is added to Beanstalk:0x179Bb2636F0066d837f1a446083A0FBA131c1A46
EnrootFacet
Function ChangesenrootDeposit
0x0b58f073
enrootDeposits
0x88fcd169
Fertilizer Facet
The following
FertilizerFacet
is removed from Beanstalk:0x3FA7ECcfbFDF4407932D2318401d20464189C5F1
The following
FertilizerFacet
is added to Beanstalk:0x729672c68134E2DF0CdD36D3296841A2993534c7
FertilizerFacet
Function ChangesmintFertilizer
0xbb02e10b
_getMintFertilizerOut
0x94daa221
beginBarnRaiseMigration
0xe3d4e44c
getBarnRaiseToken
0xf255da60
getBarnRaiseWell
0x93a39bea
mintFertilizer
0x363591d0
balanceOfBatchFertilizer
0x304ec65d
balanceOfFertilized
0xb6f42085
balanceOfFertilizer
0x1799b3b2
balanceOfUnfertilized
0x1edb6be1
beansPerFertilizer
0x9bb4e35a
claimFertilized
0x83e08888
getActiveFertilizer
0xdc6ba285
getCurrentHumidity
0x39448802
getEndBpf
0xc85951a1
getFertilizer
0x9c45a1d5
getFertilizers
0x34af5416
getFirst
0x1e223143
getHumidity
0x29130a66
getLast
0x4d622831
getMintFertilizerOut
0x69744dd0
getNext
0xf4a057e2
isFertilizing
0x6ae1c014
payFertilizer
0xd47aee59
remainingRecapitalization
0x4a16607c
totalFertilizedBeans
0x4f9a9678
totalFertilizerBeans
0xf9c4ebde
totalUnfertilizedBeans
0xa3ef48c9
Metadata Facet
The following
MetadataFacet
is being removed from Beanstalk:0x9F5ec59d13AfDb581A383D6215b717312e875Fd2
The following
MetadataFacet
is added to Beanstalk:0x0d8f6F09a2B806d406d511C113f2Fc3F4D608Fc1
MetadataFacet
Function ChangesimageURI
0xc20b8071
name
0x06fdde03
symbol
0x95d89b41
uri
0x0e89341c
Season Facet
The following
SeasonFacet
is removed from Beanstalk:0xB5818dE8b02394b4300F15F61083dc3ff976EAA1
The following
SeasonFacet
is added to Beanstalk:0x92458b7ade7798c45E5ff583c353F70F950d66Cf
SeasonFacet
Function Changesgm
0x64ee4b80
seasonTime
0xca7b7d7b
sunrise
0xfc06d2a6
Season Getters Facet
The following
SeasonGettersFacet
is removed from Beanstalk:0x46d11a5076EAAD1ffA24b0C2DDF38d4Aeaa19920
The following
SeasonGettersFacet
is added to Beanstalk:0x5A1675f3156c9e73D7eA20eb58470A0002865E85
SeasonGettersFacet
Function ChangesabovePeg
0x2a27c499
calcGaugePointsWithParams
0xeedc7ab9
getAverageGrownStalkPerBdv
0x7ba6cbf8
getAverageGrownStalkPerBdvPerSeason
0xeb0e1215
getBeanEthGaugePointsPerBdv
0xd1db56b8
getBeanGaugePointsPerBdv
0x69aa7e02
getBeanToMaxLpGpPerBdvRatio
0xcc88d4f9
getBeanToMaxLpGpPerBdvRatioScaled
0x673c75f0
getDeltaPodDemand
0x64b3496b
getGaugePoints
0x93523425
getGaugePointsPerBdvForToken
0x64887852
getGaugePointsPerBdvPerWell
0xb2b0556d
getGaugePointsWithParams
0x141933bf
getGrownStalkIssuedPerGp
0xf98da2de
getGrownStalkIssuedPerSeason
0x383f170f
getLargestLiqWell
0xd1943f7f
getLiquidityToSupplyRatio
0xcb2d0a3c
getPodRate
0xcce813a1
getSeedGauge
0x6af8e5a4
getSopWell
0x7d23804d
getTotalBdv
0x50539159
getTotalUsdLiquidity
0xbbf459a7
getTotalWeightedUsdLiquidity
0xf788b47c
getTwaLiquidityForWell
0xa13a3742
getWeightedTwaLiquidityForWell
0x93c9e531
paused
0x5c975abb
plentyPerRoot
0xe60d7a83
poolDeltaB
0x471bcdbe
rain
0x43def26e
season
0xc50b0fb0
sunriseBlock
0x3b2ecb70
time
0x16ada547
totalDeltaB
0x06c499d8
weather
0x686b6159
wellOracleSnapshot
0x597490c0
Unripe Facet
The following
UnripeFacet
is removed from Beanstalk:0xeBD6Fc0c2d4dc3Ea131d7F14aA2f617d63Dc0F1a
The following
UnripeFacet
is added to Beanstalk:0xD64BB5c2dBf12fEBeFc6397926A3c0aA6f8b6535
UnripeFacet
Function ChangesgetLockedBeansUnderlyingUnripeBeanEth
0x208c2c98
getLockedBeansUnderlyingUnripeLP
0x33f37f27
_getPenalizedUnderlying
0xa84643e4
addMigratedUnderlying
0x787cee99
addUnripeToken
0xfa345569
balanceOfPenalizedUnderlying
0x1acc0a47
balanceOfUnderlying
0x1be655e8
chop
0x9a516cad
getLockedBeans
0x087d78b4
getLockedBeansFromTwaReserves
0x7caa025f
getLockedBeansUnderlyingUnripeBean
0xbfe2f3be
getPenalizedUnderlying
0x6de45df2
getPenalty
0x014a8a49
getPercentPenalty
0xbb7de478
getRecapFundedPercent
0x43cc4ee0
getRecapPaidPercent
0xab434eb7
getTotalUnderlying
0xadef4533
getUnderlying
0x9f06b3fa
getUnderlyingPerUnripeToken
0xb8a04d1b
getUnderlyingToken
0x691bcc88
isUnripe
0xfc6a19df
pick
0x13ed3cea
picked
0xd3c73ec8
switchUnderlyingToken
0xa33fa99f
Whitelist Facet
The following
WhitelistFacet
is removed from Beanstalk:0x47DA294946D41E90486ca8BB2adA493A6b974A2a
The following
WhitelistFacet
is added to Beanstalk:0xDE3a2284b50E345cB7985EE677595cC720fbBB02
WhitelistFacet
Function ChangesdewhitelistToken
0x86b40a1b
getSiloTokens
0xe9522c08
getWhitelistStatus
0xd9ba32fc
getWhitelistStatuses
0x170cf084
getWhitelistedLpTokens
0x9d1d2877
getWhitelistedTokens
0xe26f7900
getWhitelistedWellLpTokens
0x76a7bc84
updateGaugeForToken
0xce5fb821
updateStalkPerBdvPerSeasonForToken
0xf18d9ed0
whitelistToken
0x371b5b03
whitelistTokenWithEncodeType
0x052ebc26
Event Changes
None.
Beans Minted
None.
Audit
Beanstalk
The commit hash of this BIP is 45afeaf1f9c57bcdf506336aff63fa8805a1081f.
An audit competition of this upgrade was held via Codehawks using commit hash 27ff8c87c9164c1fbff054be5f22e56f86cdf127. The final report can be read here.
Audit remediations were committed and documented in PR #922. All changes were reviewed by Cyfrin.
Basin
The commit hash of Multi Flow v1.1.0 is 8d54b04fd24ec621966f30683a90d4985c6bd6db.
An audit competition of this upgrade was held via Codehawks using commit hash 038609d8adf1bf941f8abd12820bc92ecd998375. The final report can be read here.
Audit remediations were committed and documented in PR #132. All changes were reviewed by Cyfrin.
Effective
Immediately upon commitment.