Skip to content

Commit

Permalink
Misc Protocol Cleanup (#1122)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickkatsios committed Sep 29, 2024
2 parents 80cea02 + 017a650 commit 2cb48f6
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 42 deletions.
3 changes: 0 additions & 3 deletions protocol/contracts/beanstalk/init/InitalizeDiamond.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ contract InitalizeDiamond {
// set current season to 1.
s.sys.season.current = 1;

// set withdraw seasons to 0. Kept here for verbosity.
s.sys.season.withdrawSeasons = 0;

// initalize the duration of 1 season in seconds.
s.sys.season.period = C.CURRENT_SEASON_PERIOD;

Expand Down
4 changes: 1 addition & 3 deletions protocol/contracts/beanstalk/init/reseed/L2/ReseedBean.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ contract ReseedBean {

using SafeERC20 for IERC20;

address internal constant OWNER = address(0xa9bA2C40b263843C04d344727b954A545c81D043);
AppStorage internal s;

// A default well salt is used to prevent front-running attacks
Expand Down Expand Up @@ -119,8 +118,7 @@ contract ReseedBean {
bytes32 internal constant FERTILIZER_PROXY_SALT =
0xd1a0060ba708bc4bcd3da6c37efa8dedf015fb70fb8fe6ecbb7a4fead78f65ee;

// BCM (TODO: Replace with actual L2 address)
address internal constant L2_BCM = address(0xa9bA2C40b263843C04d344727b954A545c81D043);
address internal constant L2_BCM = address(0xDd5b31E73dB1c566Ca09e1F1f74Df34913DaaF69);

/**
* @notice deploys bean, unripe bean, unripe lp, and wells.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ contract MarketplaceFacet is Invariable, Order {
amount = end - start;
}

/**
* @notice Approves pods to be spent by `spender`.
*/
function approvePods(
address spender,
uint256 fieldId,
Expand Down
22 changes: 13 additions & 9 deletions protocol/contracts/beanstalk/storage/System.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ struct Field {
* @param fertilizedPaidIndex The total number of Fertilizer Beans that have been sent out to users.
* @param fertFirst The lowest active Fertilizer Id (start of linked list that is stored by nextFid).
* @param fertLast The highest active Fertilizer Id (end of linked list that is stored by nextFid).
* @param bpf The cumulative Beans Per Fertilizer (bfp) minted over all Season.
* @param recapitalized The number of USDC that has been recapitalized in the Barn Raise.
* @param bpf The cumulative Beans Per Fertilizer (bfp) minted over all Seasons.
* @param recapitalized The number of USD that has been recapitalized in the Barn Raise.
* @param leftoverBeans Amount of Beans that have shipped to Fert but not yet reflected in bpf.
* @param _buffer Reserved storage for future expansion.
*/
Expand All @@ -167,7 +167,6 @@ struct Fertilizer {
* @notice System-level Season state variables.
* @param current The current Season in Beanstalk.
* @param lastSop The Season in which the most recent consecutive series of Seasons of Plenty started.
* @param withdrawSeasons The number of Seasons required to Withdraw a Deposit.
* @param lastSopSeason The Season in which the most recent consecutive series of Seasons of Plenty ended.
* @param rainStart Stores the most recent Season in which Rain started.
* @param raining True if it is Raining (P > 1, Pod Rate Excessively Low).
Expand All @@ -184,7 +183,6 @@ struct Fertilizer {
struct Season {
uint32 current;
uint32 lastSop;
uint8 withdrawSeasons;
uint32 lastSopSeason;
uint32 rainStart;
bool raining;
Expand All @@ -202,8 +200,8 @@ struct Season {
/**
* @notice System-level Weather state variables.
* @param lastDeltaSoil Delta Soil; the number of Soil purchased last Season.
* @param lastSowTime The number of seconds it for Soil to sell out last Season.
* @param thisSowTime The number of seconds it for Soil to sell out this Season.
* @param lastSowTime The number of seconds it took for Soil to sell out last Season.
* @param thisSowTime The number of seconds it took for Soil to sell out this Season.
* @param temp Temperature is max interest rate in current Season for sowing Beans in Soil. Adjusted each Season.
* @param _buffer Reserved storage for future expansion.
*/
Expand Down Expand Up @@ -338,7 +336,7 @@ struct AssetSettings {
* - Unripe LP, with its `underlyingToken` as BEAN:3CRV LP.
*
* Unripe Tokens are initially distributed through the use of a `merkleRoot`.
*
* The `underlyingToken` for Unripe LP was modified and currently set to BEAN:WSTEH well LP.
* The existence of a non-zero {UnripeSettings} implies that a Token is an Unripe Token.
*/
struct UnripeSettings {
Expand All @@ -362,6 +360,12 @@ struct Deposited {
uint128 bdv;
}

/**
* @notice Stores convert capacity data for a given block.
* @param overallConvertCapacityUsed The amount of overall deltaB that can be converted towards peg within a block.
* @param wellConvertCapacityUsed A mapping from well to the amount of deltaB
* that can be converted in the given block.
*/
struct ConvertCapacity {
uint256 overallConvertCapacityUsed;
mapping(address => uint256) wellConvertCapacityUsed;
Expand Down Expand Up @@ -389,7 +393,7 @@ struct ShipmentRoute {
}

/**
* @notice storage relating to the L2 Migration. Can be removed upon a full migration.
* @notice storage relating to the L2 Migration of smart contracts. Can be removed upon a full migration.
* @param migratedL1Beans the amount of L1 Beans that have been migrated to L2.
* @param contractata a mapping from a L1 contract to an approved L2 receiver.
* @param _buffer_ Reserved storage for future additions.
Expand All @@ -401,7 +405,7 @@ struct L2Migration {
}

/**
* @notice contains data relating to migration.
* @notice contains data relating to migration of a smart contract from L1 to L2.
*/
struct MigrationData {
address receiver;
Expand Down
1 change: 1 addition & 0 deletions protocol/contracts/beanstalk/sun/OracleFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ contract OracleFacet is Invariable, ReentrancyGuard {
/**
* @notice Fetches the amount of USD equal 1 token is worth, using a lookback
* @param token address of token to get the price of.
* @param lookback the amount of time to look back in seconds.
*/
function getTokenUsdTwap(address token, uint256 lookback) external view returns (uint256) {
return LibUsdOracle.getTokenPrice(token, lookback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contract GaugeGettersFacet {
/**
* @notice Returns the average grown stalk per BDV per season.
* @dev 6 decimal precision (1 GrownStalkPerBdvPerSeason = 1e6);
* note that stalk has 10 decimals.
* note that stalk has 16 decimals.
*/
function getAverageGrownStalkPerBdvPerSeason() public view returns (uint128) {
return s.sys.seedGauge.averageGrownStalkPerBdvPerSeason;
Expand Down Expand Up @@ -103,6 +103,9 @@ contract GaugeGettersFacet {
}
}

/**
* @notice returns the largest Gauge Points per BDV of all whitelisted LP tokens.
*/
function getLargestGpPerBdv() public view returns (uint256) {
uint256 largestGpPerBdv;
address[] memory whitelistedLpTokens = LibWhitelistedTokens.getWhitelistedLpTokens();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ contract SeasonGettersFacet {
revert("Oracle: Pool not supported");
}

/**
* @notice Returns the current Delta B for a given well using `calculateDeltaBFromReserves`.
* @return deltaB The deltaB for the well, calculated by its reserves.
*/
function poolCurrentDeltaB(address pool) public view returns (int256 deltaB) {
if (LibWell.isWell(pool)) {
(deltaB) = LibDeltaB.currentDeltaB(pool);
Expand All @@ -116,6 +120,9 @@ contract SeasonGettersFacet {
}
}

/**
* @notice Returns the cumulative Delta B from a given list of wells.
*/
function cumulativeCurrentDeltaB(
address[] calldata pools
) external view returns (int256 deltaB) {
Expand Down Expand Up @@ -170,6 +177,9 @@ contract SeasonGettersFacet {
}
}

/**
* @notice Returns the well with the largest USD time weighted average liquidity.
*/
function getLargestLiqWell() external view returns (address) {
uint256 beanSupply = BeanstalkERC20(s.sys.tokens.bean).totalSupply();
(, address well, ) = LibEvaluate.calcLPToSupplyRatio(beanSupply);
Expand Down
1 change: 0 additions & 1 deletion protocol/contracts/interfaces/IMockFBeanstalk.sol
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ interface IMockFBeanstalk {
struct Season {
uint32 current;
uint32 lastSop;
uint8 withdrawSeasons;
uint32 lastSopSeason;
uint32 rainStart;
bool raining;
Expand Down
2 changes: 0 additions & 2 deletions protocol/contracts/libraries/Convert/LibConvert.sol
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ library LibConvert {

AssetsRemovedConvert memory a;
uint256 i = 0;
// if (user == address(0)) user = LibTractor._user();

// a bracket is included here to avoid the "stack too deep" error.
{
Expand All @@ -490,7 +489,6 @@ library LibConvert {
while ((i < stems.length) && (a.active.tokens < maxTokens)) {
// skip any stems that are germinating, due to the ability to
// circumvent the germination process.
// TODO: expose a view function that let's you pass in stems/amounts and returns the non-germinating stems/amounts?
if (germStem.germinatingStem <= stems[i]) {
i++;
continue;
Expand Down
4 changes: 2 additions & 2 deletions protocol/contracts/libraries/LibEvaluate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ library LibEvaluate {
// and thus will skip the p > EXCESSIVE_PRICE_THRESHOLD check if the well oracle fails to
// compute a valid price this Season.
// deltaB > 0 implies that address(well) != address(0).
uint256 tokenBeanPrice = LibWell.getTokenBeanPriceFromTwaReserves(well); //variable name is wrong here
uint256 tokenBeanPrice = LibWell.getTokenBeanPriceFromTwaReserves(well);
if (tokenBeanPrice > 1) {
address nonBeanToken = address(LibWell.getNonBeanTokenFromWell(well));
uint256 nonBeanTokenDecimals = IERC20Decimals(nonBeanToken).decimals();
Expand All @@ -98,7 +98,7 @@ library LibEvaluate {
}
caseId = 3;
}
// p < 1
// p < 1 (caseId = 0)
}

/**
Expand Down
1 change: 0 additions & 1 deletion protocol/contracts/mocks/mockFacets/MockSeasonFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ contract MockSeasonFacet is SeasonFacet {
s.sys.season.start = block.timestamp;
s.sys.season.timestamp = block.timestamp;
s.sys.silo.stalk = 0;
s.sys.season.withdrawSeasons = 25;
s.sys.season.current = 1;
s.sys.paused = false;
BeanstalkERC20(s.sys.tokens.bean).burn(
Expand Down
2 changes: 0 additions & 2 deletions protocol/contracts/tokens/Fertilizer/Internalizer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ contract Internalizer is
* @notice Returns the beans per fertilizer remaining for a given fertilizer Id.
* @param id - the id of the fertilizer
* Formula: bpfRemaining = id - s.bpf
* Calculated here to avoid uint underflow
* Solidity 0.8.0 has underflow protection and the tx would revert but we are using 0.7.6
*/
function calculateBpfRemaining(uint256 id) internal view returns (uint128) {
// make sure it does not underflow
Expand Down
15 changes: 0 additions & 15 deletions protocol/contracts/tokens/UnripeBean3Crv.sol

This file was deleted.

2 changes: 1 addition & 1 deletion protocol/test/foundry/utils/FertilizerDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ contract FertilizerDeployer is Utils {
IOwner(fertilizerAddress).transferOwnership(newOwner);
}

function mintFertilizer() internal {} // TODO
function mintFertilizer() internal {}

function mockMintFertilizer() internal {}

Expand Down
4 changes: 2 additions & 2 deletions protocol/test/hardhat/SopReport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe("Sop Test Cases", function () {
await mockBeanstalk.rainSunrise(); // 6 => 7

const rain = await beanstalk.rain();
let season = await beanstalk.time();
// let season = await beanstalk.time();

// there is a flood in season 8
await mockBeanstalk.rainSunrise(); // 7 => 8
Expand Down Expand Up @@ -146,7 +146,7 @@ describe("Sop Test Cases", function () {
await mockBeanstalk.rainSunrise(); // 6 => 7

const rain = await beanstalk.rain();
let season = await beanstalk.time();
// let season = await beanstalk.time();

// there is a flood in season 8
await mockBeanstalk.rainSunrise(); // 7 => 8
Expand Down

0 comments on commit 2cb48f6

Please sign in to comment.