Skip to content

Commit

Permalink
Fix: Reseed Whitelist (#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickkatsios authored Sep 11, 2024
2 parents 09a0f93 + 92a65bb commit 8b240c2
Show file tree
Hide file tree
Showing 18 changed files with 242 additions and 96 deletions.
18 changes: 8 additions & 10 deletions protocol/contracts/beanstalk/init/reseed/L2/ReseedBean.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,51 +69,49 @@ contract ReseedBean {
address internal constant AQUIFER = address(0xBA51AAAa8C2f911AE672e783707Ceb2dA6E97521);
address internal constant CONSTANT_PRODUCT_2 =
address(0xBA5104f2df98974A83CD10d16E24282ce6Bb647f);
// TODO: Replace with actual address.
address internal constant STABLE_2 = address(0xd771D7C0e1EBE89C9E9F663824851BB89b926d1a);
// TODO: Replace with actual address.
address internal constant STABLE_2 = address(0xBA51055Ac3068Ffd884B495BF58314493cde9653);
address internal constant UPGRADEABLE_WELL_IMPLEMENTATION =
address(0x2706A171ECb68E0038378D40Dd1d136361d0cB7d);
address(0xBA510995783111be5301d93CCfD5dE4e3B28e50B);
address internal constant MULTIFLOW_PUMP = address(0xBA510482E3e6B96C88A1fe34Ce58385fB554C9a9);

// BEAN_ETH parameters.
bytes32 internal constant BEAN_ETH_SALT =
0xd1a0060ba708bc4bcd3da6c37efa8dedf015fb70a730b1101631795f48768830;
0xd1a0060ba708bc4bcd3da6c37efa8dedf015fb70cf610e2f8ba3a784783d50c7;
string internal constant BEAN_ETH_NAME = "BEAN:WETH Constant Product 2 Upgradeable Well";
string internal constant BEAN_ETH_SYMBOL = "U-BEANWETHCP2w";
address internal constant WETH = address(0x82aF49447D8a07e3bd95BD0d56f35241523fBab1);

// BEAN_WSTETH parameters.
bytes32 internal constant BEAN_WSTETH_SALT =
0xd1a0060ba708bc4bcd3da6c37efa8dedf015fb70d1f6ffabd835875bcb0f750d;
0xd1a0060ba708bc4bcd3da6c37efa8dedf015fb702dd812d82cc04280f90dac20;
string internal constant BEAN_WSTETH_NAME = "BEAN:WSTETH Constant Product 2 Upgradeable Well";
string internal constant BEAN_WSTETH_SYMBOL = "U-BEANWSTETHCP2w";
address internal constant WSTETH = address(0x5979D7b546E38E414F7E9822514be443A4800529);

// BEAN_WEETH parameters.
bytes32 internal constant BEAN_WEETH_SALT =
0xd1a0060ba708bc4bcd3da6c37efa8dedf015fb70282162c4d51072ae5848bcab;
0xd1a0060ba708bc4bcd3da6c37efa8dedf015fb7076e0c3991a85b21f3c6d2327;
string internal constant BEAN_WEETH_NAME = "BEAN:WEETH Constant Product 2 Upgradeable Well";
string internal constant BEAN_WEETH_SYMBOL = "U-BEANWEETHCCP2w";
address internal constant WEETH = address(0x35751007a407ca6FEFfE80b3cB397736D2cf4dbe);

// BEAN_WBTC parameters.
bytes32 internal constant BEAN_WBTC_SALT =
0xd1a0060ba708bc4bcd3da6c37efa8dedf015fb70680eb1a5a9088f3a5adde7cf;
0xd1a0060ba708bc4bcd3da6c37efa8dedf015fb7031803f7cfbaef420a33da4e2;
string internal constant BEAN_WBTC_NAME = "BEAN:WBTC Constant Product 2 Upgradeable Well";
string internal constant BEAN_WBTC_SYMBOL = "U-BEANWBTCCP2w";
address internal constant WBTC = address(0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f);

// BEAN_USDC parameters.
bytes32 internal constant BEAN_USDC_SALT =
0xd1a0060ba708bc4bcd3da6c37efa8dedf015fb70e8dd58a81854e1c93f594f45;
0xd1a0060ba708bc4bcd3da6c37efa8dedf015fb7029aa50efeb2cc4e37ef5b62c;
string internal constant BEAN_USDC_NAME = "BEAN:USDC Stable 2 Upgradeable Well";
string internal constant BEAN_USDC_SYMBOL = "U-BEANUSDCS2w";
address internal constant USDC = address(0xaf88d065e77c8cC2239327C5EDb3A432268e5831);

// BEAN_USDT parameters.
bytes32 internal constant BEAN_USDT_SALT =
0xd1a0060ba708bc4bcd3da6c37efa8dedf015fb703042ef0b0e0e77d3a3e484ae;
0xd1a0060ba708bc4bcd3da6c37efa8dedf015fb7082e11ce3f89b8cd399ffa9ee;
string internal constant BEAN_USDT_NAME = "BEAN:USDT Stable 2 Upgradeable Well";
string internal constant BEAN_USDT_SYMBOL = "U-BEANUSDTS2w";
address internal constant USDT = address(0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,27 @@ contract ReseedWhitelist {
*/
function init(
address[] calldata tokens,
address[] calldata nonBeanTokens,
AssetSettings[] calldata assets,
WhitelistStatus[] calldata whitelistStatus,
Implementation[] calldata oracle
) external {
for (uint i; i < tokens.length; i++) {
address token = tokens[i];
address nonBeanToken = nonBeanTokens[i];
// If an LP token, initialize oracle storage variables.
if (token != address(s.sys.tokens.bean) && !LibUnripe.isUnripe(token)) {
s.sys.usdTokenPrice[token] = 1;
s.sys.twaReserves[token].reserve0 = 1;
s.sys.twaReserves[token].reserve1 = 1;
}
// add asset settings for the underlying lp token
s.sys.silo.assetSettings[token] = assets[i];

// add whitelist status
s.sys.silo.whitelistStatuses.push(whitelistStatus[i]);
// the Oracle should return the price for the non-bean asset in USD
s.sys.oracleImplementation[token] = oracle[i];
s.sys.oracleImplementation[nonBeanToken] = oracle[i];
}
}
}
8 changes: 2 additions & 6 deletions protocol/contracts/ecosystem/price/BeanstalkPrice.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@ contract BeanstalkPrice is WellPrice {

/**
* @notice Returns the non-manipulation resistant on-chain liquidiy, deltaB and price data for
* Bean in the following liquidity pools.
* - Constant Product Bean:Eth Well
* - Constant Product Bean:Wsteth Well
* NOTE: Assumes all whitelisted Wells are CP2 wells. Needs to be updated if this changes.
* Bean in all whitelisted liquidity pools.
* @dev No protocol should use this function to calculate manipulation resistant Bean price data.
**/
function price() external view returns (Prices memory p) {
address[] memory wells = beanstalk.getWhitelistedWellLpTokens();
p.ps = new P.Pool[](wells.length);
for (uint256 i = 0; i < wells.length; i++) {
// Assume all Wells are CP2 wells.
p.ps[i] = getConstantProductWell(wells[i]);
p.ps[i] = getWell(wells[i]);
}

// assumes that liquidity and prices on all pools uses the same precision.
Expand Down
4 changes: 2 additions & 2 deletions protocol/contracts/ecosystem/price/WellPrice.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ contract WellPrice {

/**
* @notice Returns the non-manipulation resistant on-chain liquidiy, deltaB and price data for
* Bean a given Well.
* Bean in a given Well.
* @dev No protocol should use this function to calculate manipulation resistant Bean price data.
**/
function getConstantProductWell(address wellAddress) public view returns (P.Pool memory pool) {
function getWell(address wellAddress) public view returns (P.Pool memory pool) {
IWell well = IWell(wellAddress);
pool.pool = wellAddress;

Expand Down
3 changes: 2 additions & 1 deletion protocol/contracts/libraries/Oracle/LibUsdOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ library LibUsdOracle {
* @dev if address is 0, use the current contract.
* If encodeType is 0x01, use the default chainlink implementation.
* Returns 0 rather than reverting if the call fails.
* Note: token here refers to the non bean token when quoting for a well price.
*/
function getTokenPriceFromExternal(
address token,
Expand All @@ -75,7 +76,7 @@ library LibUsdOracle {
Implementation memory oracleImpl = s.sys.oracleImplementation[token];

// If the encode type is type 1, use the default chainlink implementation instead.
// `target` refers to the address of the price aggergator implmenation
// `target` refers to the address of the price aggergator implmentation
if (oracleImpl.encodeType == bytes1(0x01)) {
// if the address in the oracle implementation is 0, use the chainlink registry to lookup address
address chainlinkOraclePriceAddress = oracleImpl.target;
Expand Down
1 change: 0 additions & 1 deletion protocol/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ ignored_warnings_from = [
gas_reports = ['*']
# Cache to `$HOME/.foundry/cache/<chain id>/<block number>`.
no_storage_caching = false
no_match_contract = "ReseedStateTest"

[profile.differential]
match_test = "testDiff"
Expand Down
2 changes: 1 addition & 1 deletion protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"dependencies": {
"@beanstalk/wells": "0.4.1",
"@beanstalk/wells1.2": "npm:@beanstalk/wells@1.2.0-prerelease3",
"@beanstalk/wells1.2": "npm:@beanstalk/wells@1.2.0",
"@ethereum-waffle/chai": "4.0.10",
"@nomicfoundation/hardhat-network-helpers": "^1.0.7",
"@openzeppelin/contracts": "5.0.2",
Expand Down
3 changes: 3 additions & 0 deletions protocol/reseed/data/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@
"0",
"0",
"0",
"0",
"0",
"0",
"0"
],
[
Expand Down
83 changes: 83 additions & 0 deletions protocol/reseed/data/mocks/r9-whitelist-mock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
[
[
"0xBEA0005B8599265D41256905A9B3073D397812E4",
"0xBEA0005B8599265D41256905A9B3073D397812E4",
[
"0x5a049a47",
"0",
"10000",
"0",
"0",
"0x00",
"0",
"0",
"0",
["0x0000000000000000000000000000000000000000", "0x00000000", "0x00", "0x00"],
["0x0000000000000000000000000000000000000000", "0x00000000", "0x00", "0x00"]
],
["0xBEA0005B8599265D41256905A9B3073D397812E4", true, false, false, false],
["0x0000000000000000000000000000000000000000", "0x00000000", "0x00", "0x00"]
],
[
"0x1BEA054dddBca12889e07B3E076f511Bf1d27543",
"0x1BEA054dddBca12889e07B3E076f511Bf1d27543",
[
"0xc8cda2a0",
"1",
"10000",
"0",
"0",
"0x00",
"0",
"0",
"0",
["0x0000000000000000000000000000000000000000", "0x00000000", "0x00", "0x00"],
["0x0000000000000000000000000000000000000000", "0x00000000", "0x00", "0x00"]
],
["0x1BEA054dddBca12889e07B3E076f511Bf1d27543", true, false, false, false],
["0x0000000000000000000000000000000000000000", "0x00000000", "0x00", "0x00"]
],
[
"0x1BEA059c3Ea15F6C10be1c53d70C75fD1266D788",
"0x1BEA059c3Ea15F6C10be1c53d70C75fD1266D788",
[
"0xb0c22bb1",
"1",
"10000",
"0",
"0",
"0x00",
"0",
"0",
"0",
["0x0000000000000000000000000000000000000000", "0x00000000", "0x00", "0x00"],
["0x0000000000000000000000000000000000000000", "0x00000000", "0x00", "0x00"]
],
["0x1BEA059c3Ea15F6C10be1c53d70C75fD1266D788", true, false, false, false],
["0x0000000000000000000000000000000000000000", "0x00000000", "0x00", "0x00"]
],
[
"0xBEA00A3F7aaF99476862533Fe7DcA4b50f6158cB",
"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
[
"0xc84c7727",
"0",
"10000",
"0",
"0",
"0x01",
"0",
"160000000000000000000",
"16000000",
["0x0000000000000000000000000000000000000000", "0xd8317c71", "0x00", "0x00"],
["0x0000000000000000000000000000000000000000", "0xa8b0bb83", "0x00", "0x00"]
],
["0xBEA00A3F7aaF99476862533Fe7DcA4b50f6158cB", true, true, true, true],
[
"0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612",
"0x00000000",
"0x01",
"0x000000000000000000000000000000000000000000000000000000000001fa40"
]
]
]
Loading

0 comments on commit 8b240c2

Please sign in to comment.