Skip to content

Commit

Permalink
prettier auto formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nickkatsios authored and github-actions[bot] committed Aug 7, 2024
1 parent 93af651 commit c3ca145
Show file tree
Hide file tree
Showing 19 changed files with 287 additions and 262 deletions.
37 changes: 21 additions & 16 deletions protocol/contracts/beanstalk/barn/UnripeFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ contract UnripeFacet is Invariable, ReentrancyGuard {
address unripeToken,
uint256 amount
) public view returns (uint256 redeem) {
return LibUnripe.getPenalizedUnderlying(unripeToken, amount, IBean(unripeToken).totalSupply());
return
LibUnripe.getPenalizedUnderlying(unripeToken, amount, IBean(unripeToken).totalSupply());
}

/**
Expand Down Expand Up @@ -195,18 +196,21 @@ contract UnripeFacet is Invariable, ReentrancyGuard {
* @dev `address` parameter retained for backwards compatiability.
*/
function getPercentPenalty(address unripeToken) external view returns (uint256 penalty) {
if (unripeToken == C.UNRIPE_BEAN) {
return LibUnripe.getPenalizedUnderlying(
unripeToken,
LibUnripe.DECIMALS,
IERC20(unripeToken).totalSupply()
);
if (unripeToken == C.UNRIPE_BEAN) {
return
LibUnripe.getPenalizedUnderlying(
unripeToken,
LibUnripe.DECIMALS,
IERC20(unripeToken).totalSupply()
);
}

if (unripeToken == C.UNRIPE_LP) {
return LibUnripe.getTotalRecapitalizedPercent()
.mul(LibUnripe.getTotalRecapitalizedPercent())
.div(LibUnripe.DECIMALS);

if (unripeToken == C.UNRIPE_LP) {
return
LibUnripe
.getTotalRecapitalizedPercent()
.mul(LibUnripe.getTotalRecapitalizedPercent())
.div(LibUnripe.DECIMALS);
}
}

Expand Down Expand Up @@ -328,10 +332,11 @@ contract UnripeFacet is Invariable, ReentrancyGuard {
* @notice Returns the number of Beans that are locked underneath the Unripe Bean token.
*/
function getLockedBeansUnderlyingUnripeBean() external view returns (uint256) {
return LibLockedUnderlying.getLockedUnderlying(
C.UNRIPE_BEAN,
LibUnripe.getTotalRecapitalizedPercent()
);
return
LibLockedUnderlying.getLockedUnderlying(
C.UNRIPE_BEAN,
LibUnripe.getTotalRecapitalizedPercent()
);
}

/**
Expand Down
11 changes: 3 additions & 8 deletions protocol/contracts/beanstalk/init/InitBipMiscImprovements.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@ import "../../tokens/Fertilizer/Fertilizer.sol";
* @author deadmanwalking
* @title InitBipMiscImprovements updates the Fertilizer implementation
* to use a decentralized uri
**/
**/

contract InitBipMiscImprovements {

function init() external {

// deploy new Fertilizer implementation
Fertilizer fertilizer = new Fertilizer();
// get the address of the new Fertilizer implementation
address fertilizerImplementation = address(fertilizer);

// upgrade to new Fertilizer implementation
C.fertilizerAdmin().upgrade(
C.fertilizerAddress(),
fertilizerImplementation
);
C.fertilizerAdmin().upgrade(C.fertilizerAddress(), fertilizerImplementation);
}
}
15 changes: 10 additions & 5 deletions protocol/contracts/beanstalk/silo/ConvertFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,20 @@ contract ConvertFacet is Invariable, ReentrancyGuard {
uint256 grownStalk;
LibConvert.ConvertParams memory cp = LibConvert.convert(convertData);

if (cp.decreaseBDV) {require(stems.length == 1 && amounts.length == 1, "Convert: DecreaseBDV only supports updating one deposit.");}

if (cp.decreaseBDV) {
require(
stems.length == 1 && amounts.length == 1,
"Convert: DecreaseBDV only supports updating one deposit."
);
}

require(cp.fromAmount > 0, "Convert: From amount is 0.");

LibSilo._mow(LibTractor._user(), cp.fromToken);

// If the fromToken and toToken are different, mow the toToken as well.
if (cp.fromToken != cp.toToken) LibSilo._mow(LibTractor._user(), cp.toToken);

// Withdraw the tokens from the deposit.
(pipeData.grownStalk, fromBdv) = LibConvert._withdrawTokens(
cp.fromToken,
Expand All @@ -105,7 +110,7 @@ contract ConvertFacet is Invariable, ReentrancyGuard {
uint256 newBdv = LibTokenSilo.beanDenominatedValue(cp.toToken, cp.toAmount);

// If `decreaseBDV` flag is not enabled, set toBDV to the max of the two bdvs.
toBdv = (newBdv > fromBdv || cp.decreaseBDV) ? newBdv : fromBdv;
toBdv = (newBdv > fromBdv || cp.decreaseBDV) ? newBdv : fromBdv;

toStem = LibConvert._depositTokensForConvert(cp.toToken, cp.toAmount, toBdv, grownStalk);

Expand All @@ -115,4 +120,4 @@ contract ConvertFacet is Invariable, ReentrancyGuard {

emit Convert(LibTractor._user(), cp.fromToken, cp.toToken, cp.fromAmount, cp.toAmount);
}
}
}
24 changes: 11 additions & 13 deletions protocol/contracts/beanstalk/sun/SeasonFacet/Sun.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,15 @@ contract Sun is Oracle, Distribution {
}

/**
* @param twaDeltaB The time weighted average precalculated deltaB
* from {Oracle.stepOracle} at the start of the season.
* @dev When below peg, Beanstalk wants to issue debt for beans to be sown(burned),
* and removed from the supply, pushing the price up. To avoid soil over issuance,
* Beanstalk can read inter-block MEV manipulation resistant instantaneous reserves
* for whitelisted Well LP tokens via Multi Flow, compare it to the twaDeltaB calculated
* at the start of the season, and pick the minimum of the two.
*/
* @param twaDeltaB The time weighted average precalculated deltaB
* from {Oracle.stepOracle} at the start of the season.
* @dev When below peg, Beanstalk wants to issue debt for beans to be sown(burned),
* and removed from the supply, pushing the price up. To avoid soil over issuance,
* Beanstalk can read inter-block MEV manipulation resistant instantaneous reserves
* for whitelisted Well LP tokens via Multi Flow, compare it to the twaDeltaB calculated
* at the start of the season, and pick the minimum of the two.
*/
function setSoilBelowPeg(int256 twaDeltaB) internal {

// Calculate deltaB from instantaneous reserves of all whitelisted Wells.
int256 instDeltaB;
address[] memory tokens = LibWhitelistedTokens.getWhitelistedWellLpTokens();
Expand All @@ -108,13 +107,12 @@ contract Sun is Oracle, Distribution {
} else {
setSoil(uint256(-twaDeltaB));
}

}

/**
* @param amount The new amount of Soil available.
* @dev Sets the amount of Soil available and emits a Soil event.
*/
* @param amount The new amount of Soil available.
* @dev Sets the amount of Soil available and emits a Soil event.
*/
function setSoil(uint256 amount) internal {
s.sys.soil = amount.toUint128();
emit Soil(s.sys.season.current, amount.toUint128());
Expand Down
6 changes: 1 addition & 5 deletions protocol/contracts/libraries/Convert/LibChopConvert.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ library LibChopConvert {
uint256 amountIn
) internal view returns (uint256 amount) {
// tokenIn == unripe bean address
amount = LibUnripe.getPenalizedUnderlying(
tokenIn,
amountIn,
IBean(tokenIn).totalSupply()
);
amount = LibUnripe.getPenalizedUnderlying(tokenIn, amountIn, IBean(tokenIn).totalSupply());
}
}
68 changes: 30 additions & 38 deletions protocol/contracts/libraries/Convert/LibConvert.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ library LibConvert {
* If it is anti-lambda, account is the address of the account to update the deposit
* and decreaseBDV is true
*/
function convert(bytes calldata convertData)
external
returns (ConvertParams memory cp)
{
function convert(bytes calldata convertData) external returns (ConvertParams memory cp) {
LibConvertData.ConvertKind kind = convertData.convertKind();

if (kind == LibConvertData.ConvertKind.BEANS_TO_WELL_LP) {
Expand All @@ -122,74 +119,69 @@ library LibConvert {
(cp.toToken, cp.fromToken, cp.toAmount, cp.fromAmount) = LibChopConvert
.convertUnripeToRipe(convertData);
} else if (kind == LibConvertData.ConvertKind.LAMBDA_LAMBDA) {
(cp.toToken, cp.fromToken, cp.toAmount, cp.fromAmount) = LibLambdaConvert
.convert(convertData);
(cp.toToken, cp.fromToken, cp.toAmount, cp.fromAmount) = LibLambdaConvert.convert(
convertData
);
} else if (kind == LibConvertData.ConvertKind.ANTI_LAMBDA_LAMBDA) {
(cp.toToken, cp.fromToken, cp.toAmount, cp.fromAmount, cp.account, cp.decreaseBDV) = LibLambdaConvert
.antiConvert(convertData);
(
cp.toToken,
cp.fromToken,
cp.toAmount,
cp.fromAmount,
cp.account,
cp.decreaseBDV
) = LibLambdaConvert.antiConvert(convertData);
} else {
revert("Convert: Invalid payload");
}
}

function getMaxAmountIn(address fromToken, address toToken)
internal
view
returns (uint256)
{
function getMaxAmountIn(address fromToken, address toToken) internal view returns (uint256) {
// Lambda -> Lambda &
// Anti-Lambda -> Lambda
if (fromToken == toToken)
return type(uint256).max;
if (fromToken == toToken) return type(uint256).max;

// Bean -> Well LP Token
if (fromToken == C.BEAN && toToken.isWell())
return LibWellConvert.beansToPeg(toToken);
if (fromToken == C.BEAN && toToken.isWell()) return LibWellConvert.beansToPeg(toToken);

// Well LP Token -> Bean
if (fromToken.isWell() && toToken == C.BEAN)
return LibWellConvert.lpToPeg(fromToken);
if (fromToken.isWell() && toToken == C.BEAN) return LibWellConvert.lpToPeg(fromToken);

// urLP Convert
if (fromToken == C.UNRIPE_LP){
if (fromToken == C.UNRIPE_LP) {
// UrBEANETH -> urBEAN
if (toToken == C.UNRIPE_BEAN)
return LibUnripeConvert.lpToPeg();
if (toToken == C.UNRIPE_BEAN) return LibUnripeConvert.lpToPeg();
// UrBEANETH -> BEANETH
if (toToken == LibBarnRaise.getBarnRaiseWell())
return type(uint256).max;
if (toToken == LibBarnRaise.getBarnRaiseWell()) return type(uint256).max;
}

// urBEAN Convert
if (fromToken == C.UNRIPE_BEAN){
if (fromToken == C.UNRIPE_BEAN) {
// urBEAN -> urLP
if (toToken == C.UNRIPE_LP)
return LibUnripeConvert.beansToPeg();
if (toToken == C.UNRIPE_LP) return LibUnripeConvert.beansToPeg();
// UrBEAN -> BEAN
if (toToken == C.BEAN)
return type(uint256).max;
if (toToken == C.BEAN) return type(uint256).max;
}

revert("Convert: Tokens not supported");
}

function getAmountOut(address fromToken, address toToken, uint256 fromAmount)
internal
view
returns (uint256)
{
function getAmountOut(
address fromToken,
address toToken,
uint256 fromAmount
) internal view returns (uint256) {
/// urLP -> urBEAN
if (fromToken == C.UNRIPE_LP && toToken == C.UNRIPE_BEAN)
return LibUnripeConvert.getBeanAmountOut(fromAmount);

/// urBEAN -> urLP
if (fromToken == C.UNRIPE_BEAN && toToken == C.UNRIPE_LP)
return LibUnripeConvert.getLPAmountOut(fromAmount);

// Lambda -> Lambda &
// Anti-Lambda -> Lambda
if (fromToken == toToken)
return fromAmount;
if (fromToken == toToken) return fromAmount;

// Bean -> Well LP Token
if (fromToken == C.BEAN && toToken.isWell())
Expand Down
11 changes: 4 additions & 7 deletions protocol/contracts/libraries/Convert/LibConvertData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,13 @@ library LibConvertData {
(, amount, token) = abi.decode(self, (ConvertKind, uint256, address));
}


/// @notice Decoder for the antiLambdaConvert
/// @dev contains an additional address parameter for the account to update the deposit
/// and a bool to indicate whether to decrease the bdv
function antiLambdaConvert(bytes memory self)
internal
pure
returns (uint256 amount, address token, address account, bool decreaseBDV)
{
(, amount, token, account) = abi.decode(self, (ConvertKind, uint256, address , address));
function antiLambdaConvert(
bytes memory self
) internal pure returns (uint256 amount, address token, address account, bool decreaseBDV) {
(, amount, token, account) = abi.decode(self, (ConvertKind, uint256, address, address));
decreaseBDV = true;
}
}
18 changes: 11 additions & 7 deletions protocol/contracts/libraries/Convert/LibLambdaConvert.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import {LibConvertData} from "./LibConvertData.sol";
*/
library LibLambdaConvert {
using LibConvertData for bytes;

/**
* @notice This function returns the full input for use in lambda convert
* In lambda convert, the account converts from and to the same token.
*/
function convert(bytes memory convertData)
*/
function convert(
bytes memory convertData
)
internal
pure
returns (address tokenOut, address tokenIn, uint256 amountOut, uint256 amountIn)
Expand All @@ -25,13 +27,15 @@ library LibLambdaConvert {
amountOut = amountIn;
}

/**
/**
* @notice This function returns the full input for use in anti-lamda convert
* In anti lamda convert, any user can convert on behalf of an account
* In anti lamda convert, any user can convert on behalf of an account
* to update a deposit's bdv.
* This is why the additional 'account' parameter is returned.
*/
function antiConvert(bytes memory convertData)
*/
function antiConvert(
bytes memory convertData
)
internal
pure
returns (
Expand Down
Loading

0 comments on commit c3ca145

Please sign in to comment.