diff --git a/protocol/contracts/beanstalk/barn/UnripeFacet.sol b/protocol/contracts/beanstalk/barn/UnripeFacet.sol index 7850c8f4a..993752487 100644 --- a/protocol/contracts/beanstalk/barn/UnripeFacet.sol +++ b/protocol/contracts/beanstalk/barn/UnripeFacet.sol @@ -196,7 +196,7 @@ 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) { + if (unripeToken == s.sys.tokens.urBean) { return LibUnripe.getPenalizedUnderlying( unripeToken, @@ -205,7 +205,7 @@ contract UnripeFacet is Invariable, ReentrancyGuard { ); } - if (unripeToken == C.UNRIPE_LP) { + if (unripeToken == s.sys.tokens.urLp) { return LibUnripe .getTotalRecapitalizedPercent() @@ -335,7 +335,7 @@ contract UnripeFacet is Invariable, ReentrancyGuard { return LibLockedUnderlying.getLockedUnderlying( s.sys.tokens.urBean, - LibUnripe.getRecapPaidPercentAmount(1e6) + LibUnripe.getTotalRecapitalizedPercent() ); } diff --git a/protocol/contracts/beanstalk/init/InitBipMiscImprovements.sol b/protocol/contracts/beanstalk/init/InitBipMiscImprovements.sol index 6e167e1cc..00832d48b 100644 --- a/protocol/contracts/beanstalk/init/InitBipMiscImprovements.sol +++ b/protocol/contracts/beanstalk/init/InitBipMiscImprovements.sol @@ -5,8 +5,8 @@ pragma solidity ^0.8.20; pragma experimental ABIEncoderV2; -import "../../C.sol"; import "../../tokens/Fertilizer/Fertilizer.sol"; +import {IProxyAdmin} from "../../interfaces/IProxyAdmin.sol"; /** * @author deadmanwalking @@ -15,6 +15,9 @@ import "../../tokens/Fertilizer/Fertilizer.sol"; **/ contract InitBipMiscImprovements { + address constant FERTILIZER = 0x402c84De2Ce49aF88f5e2eF3710ff89bFED36cB6; + address constant PROXY_ADMIN = 0xfECB01359263C12Aa9eD838F878A596F0064aa6e; + function init() external { // deploy new Fertilizer implementation Fertilizer fertilizer = new Fertilizer(); @@ -22,6 +25,6 @@ contract InitBipMiscImprovements { address fertilizerImplementation = address(fertilizer); // upgrade to new Fertilizer implementation - C.fertilizerAdmin().upgrade(C.fertilizerAddress(), fertilizerImplementation); + IProxyAdmin(PROXY_ADMIN).upgrade(address(FERTILIZER), fertilizerImplementation); } } diff --git a/protocol/contracts/libraries/Convert/LibConvert.sol b/protocol/contracts/libraries/Convert/LibConvert.sol index b4a4d0560..3569724f7 100644 --- a/protocol/contracts/libraries/Convert/LibConvert.sol +++ b/protocol/contracts/libraries/Convert/LibConvert.sol @@ -136,34 +136,34 @@ library LibConvert { } } - function getMaxAmountIn(address tokenIn, address tokenOut) internal view returns (uint256) { + function getMaxAmountIn(address fromToken, address toToken) internal view returns (uint256) { AppStorage storage s = LibAppStorage.diamondStorage(); // Lambda -> Lambda & // Anti-Lambda -> Lambda if (fromToken == toToken) return type(uint256).max; // Bean -> Well LP Token - if (tokenIn == s.sys.tokens.bean && tokenOut.isWell()) - return LibWellConvert.beansToPeg(tokenOut); + if (fromToken == s.sys.tokens.bean && toToken.isWell()) + return LibWellConvert.beansToPeg(toToken); // Well LP Token -> Bean - if (tokenIn.isWell() && tokenOut == s.sys.tokens.bean) - return LibWellConvert.lpToPeg(tokenIn); + if (fromToken.isWell() && toToken == s.sys.tokens.bean) + return LibWellConvert.lpToPeg(fromToken); // urLP Convert - if (tokenIn == s.sys.tokens.urLp) { + if (fromToken == s.sys.tokens.urLp) { // UrBEANETH -> urBEAN - if (tokenOut == s.sys.tokens.urBean) return LibUnripeConvert.lpToPeg(); + if (toToken == s.sys.tokens.urBean) return LibUnripeConvert.lpToPeg(); // UrBEANETH -> BEANETH if (toToken == LibBarnRaise.getBarnRaiseWell()) return type(uint256).max; } // urBEAN Convert - if (tokenIn == s.sys.tokens.urBean) { + if (fromToken == s.sys.tokens.urBean) { // urBEAN -> urLP - if (tokenOut == s.sys.tokens.urLp) return LibUnripeConvert.beansToPeg(); + if (toToken == s.sys.tokens.urLp) return LibUnripeConvert.beansToPeg(); // UrBEAN -> BEAN - if (tokenOut == s.sys.tokens.bean) return type(uint256).max; + if (toToken == s.sys.tokens.bean) return type(uint256).max; } revert("Convert: Tokens not supported"); @@ -176,32 +176,32 @@ library LibConvert { ) internal view returns (uint256) { AppStorage storage s = LibAppStorage.diamondStorage(); /// urLP -> urBEAN - if (tokenIn == s.sys.tokens.urLp && tokenOut == s.sys.tokens.urBean) - return LibUnripeConvert.getBeanAmountOut(amountIn); + if (fromToken == s.sys.tokens.urLp && toToken == s.sys.tokens.urBean) + return LibUnripeConvert.getBeanAmountOut(fromAmount); /// urBEAN -> urLP - if (tokenIn == s.sys.tokens.urBean && tokenOut == s.sys.tokens.urLp) - return LibUnripeConvert.getLPAmountOut(amountIn); + if (fromToken == s.sys.tokens.urBean && toToken == s.sys.tokens.urLp) + return LibUnripeConvert.getLPAmountOut(fromAmount); // Lambda -> Lambda & // Anti-Lambda -> Lambda if (fromToken == toToken) return fromAmount; // Bean -> Well LP Token - if (tokenIn == s.sys.tokens.bean && tokenOut.isWell()) - return LibWellConvert.getLPAmountOut(tokenOut, amountIn); + if (fromToken == s.sys.tokens.bean && toToken.isWell()) + return LibWellConvert.getLPAmountOut(toToken, fromAmount); // Well LP Token -> Bean - if (tokenIn.isWell() && tokenOut == s.sys.tokens.bean) - return LibWellConvert.getBeanAmountOut(tokenIn, amountIn); + if (fromToken.isWell() && toToken == s.sys.tokens.bean) + return LibWellConvert.getBeanAmountOut(fromToken, fromAmount); // UrBEAN -> Bean - if (tokenIn == s.sys.tokens.urBean && tokenOut == s.sys.tokens.bean) - return LibChopConvert.getConvertedUnderlyingOut(tokenIn, amountIn); + if (fromToken == s.sys.tokens.urBean && toToken == s.sys.tokens.bean) + return LibChopConvert.getConvertedUnderlyingOut(fromToken, fromAmount); // UrBEANETH -> BEANETH - if (tokenIn == s.sys.tokens.urLp && tokenOut == LibBarnRaise.getBarnRaiseWell()) - return LibChopConvert.getConvertedUnderlyingOut(tokenIn, amountIn); + if (fromToken == s.sys.tokens.urLp && toToken == LibBarnRaise.getBarnRaiseWell()) + return LibChopConvert.getConvertedUnderlyingOut(fromToken, fromAmount); revert("Convert: Tokens not supported"); } diff --git a/protocol/contracts/libraries/LibFertilizer.sol b/protocol/contracts/libraries/LibFertilizer.sol index 9a2862b2b..d21e4374e 100644 --- a/protocol/contracts/libraries/LibFertilizer.sol +++ b/protocol/contracts/libraries/LibFertilizer.sol @@ -218,6 +218,7 @@ library LibFertilizer { * @return totalDollars The total dollar amount. */ function getTotalRecapDollarsNeeded() internal view returns (uint256) { + AppStorage storage s = LibAppStorage.diamondStorage(); return getTotalRecapDollarsNeeded(IERC20(s.sys.tokens.urLp).totalSupply()); } diff --git a/protocol/contracts/libraries/LibUnripe.sol b/protocol/contracts/libraries/LibUnripe.sol index 656692655..fe91ef76b 100644 --- a/protocol/contracts/libraries/LibUnripe.sol +++ b/protocol/contracts/libraries/LibUnripe.sol @@ -173,7 +173,7 @@ library LibUnripe { // If the token being chopped is unripeLP, getting the current supply here is inaccurate due to the burn // Instead, we use the supply passed in as an argument to getTotalRecapDollarsNeeded since the supply variable // here is the total urToken supply queried before burnning the unripe token - uint256 totalUsdNeeded = unripeToken == C.UNRIPE_LP + uint256 totalUsdNeeded = unripeToken == s.sys.tokens.urLp ? LibFertilizer.getTotalRecapDollarsNeeded(supply) : LibFertilizer.getTotalRecapDollarsNeeded(); // chop rate = total redeemable * (%DollarRecapitalized)^2 * share of unripe tokens diff --git a/protocol/contracts/mocks/mockFacets/MockUnripeFacet.sol b/protocol/contracts/mocks/mockFacets/MockUnripeFacet.sol index 895af3ba1..3a549545d 100644 --- a/protocol/contracts/mocks/mockFacets/MockUnripeFacet.sol +++ b/protocol/contracts/mocks/mockFacets/MockUnripeFacet.sol @@ -43,7 +43,7 @@ contract MockUnripeFacet is UnripeFacet { function getLegacyLockedUnderlyingBean() public view returns (uint256) { return LibLockedUnderlying.getLockedUnderlying( - C.UNRIPE_BEAN, + s.sys.tokens.urBean, LibUnripe.getRecapPaidPercentAmount(1e6) ); } @@ -51,7 +51,7 @@ contract MockUnripeFacet is UnripeFacet { function getLegacyLockedUnderlyingLP() public view returns (uint256) { return LibLockedUnderlying.getLockedUnderlying( - C.UNRIPE_LP, + s.sys.tokens.urLp, LibUnripe.getRecapPaidPercentAmount(1e6) ); } diff --git a/protocol/test/foundry/sun/Gauge.t.sol b/protocol/test/foundry/sun/Gauge.t.sol index 0f48393b8..57a4dcb1d 100644 --- a/protocol/test/foundry/sun/Gauge.t.sol +++ b/protocol/test/foundry/sun/Gauge.t.sol @@ -289,9 +289,10 @@ contract GaugeTest is TestHelper { // verify the locked beans increased. assertGe(bs.getLockedBeansUnderlyingUnripeBean(), lockedBeans); uint256 totalUnderlying = bs.getTotalUnderlying(UNRIPE_BEAN); - assertEq( + assertApproxEqAbs( bs.getLockedBeansUnderlyingUnripeBean(), - (totalUnderlying * 0.4587658967980477e18) / 1e18 + (totalUnderlying * 0.458765896798e18) / 1e18, + 1 ); } diff --git a/protocol/test/foundry/sun/Sun.t.sol b/protocol/test/foundry/sun/Sun.t.sol index dc5341026..6785b1efc 100644 --- a/protocol/test/foundry/sun/Sun.t.sol +++ b/protocol/test/foundry/sun/Sun.t.sol @@ -421,8 +421,8 @@ contract SunTest is TestHelper { function test_soilBelowPeg() public { // set inst reserves (instDeltaB: -1999936754446796632414) - setInstantaneousReserves(C.BEAN_WSTETH_WELL, 1000e18, 1000e18); - setInstantaneousReserves(C.BEAN_ETH_WELL, 1000e18, 1000e18); + setInstantaneousReserves(BEAN_WSTETH_WELL, 1000e18, 1000e18); + setInstantaneousReserves(BEAN_ETH_WELL, 1000e18, 1000e18); int256 twaDeltaB = -1000; uint32 currentSeason = bs.season(); vm.expectEmit(); @@ -434,8 +434,8 @@ contract SunTest is TestHelper { function test_soilBelowPegInstGtZero() public { // set inst reserves (instDeltaB: +415127766016) - setInstantaneousReserves(C.BEAN_WSTETH_WELL, 10000e6, 10000000e18); - setInstantaneousReserves(C.BEAN_ETH_WELL, 100000e6, 10000000e18); + setInstantaneousReserves(BEAN_WSTETH_WELL, 10000e6, 10000000e18); + setInstantaneousReserves(BEAN_ETH_WELL, 100000e6, 10000000e18); int256 twaDeltaB = -1000; uint32 currentSeason = bs.season(); vm.expectEmit(); diff --git a/protocol/test/foundry/utils/OracleDeployer.sol b/protocol/test/foundry/utils/OracleDeployer.sol index b6bb6d091..61d2cab39 100644 --- a/protocol/test/foundry/utils/OracleDeployer.sol +++ b/protocol/test/foundry/utils/OracleDeployer.sol @@ -186,8 +186,8 @@ contract OracleDeployer is Utils { // init wsteth oracle. setupLSDChainlinkOracleForToken( - C.WSTETH, - C.WSTETH_ETH_CHAINLINK_PRICE_AGGREGATOR, + WSTETH, + WSTETH_ETH_CHAINLINK_PRICE_AGGREGATOR, FOUR_HOUR_TIMEOUT ); }