-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
560 additions
and
55 deletions.
There are no files selected for viewing
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
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
72 changes: 72 additions & 0 deletions
72
protocol/contracts/beanstalk/init/InitMultFlowPumpUpgrade.sol
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import {IAquifer} from "contracts/interfaces/basin/IAquifer.sol"; | ||
import {IWell, Call, IERC20} from "contracts/interfaces/basin/IWell.sol"; | ||
import {LibWhitelistedTokens} from "contracts/libraries/Silo/LibWhitelistedTokens.sol"; | ||
import {LibWellDeployer} from "contracts/libraries/Basin/LibWellDeployer.sol"; | ||
import {AppStorage} from "contracts/beanstalk/storage/AppStorage.sol"; | ||
|
||
interface IWellUpgradeable { | ||
function upgradeTo(address implementation) external; | ||
} | ||
|
||
/** | ||
* @author Brean | ||
* @title InitMultiFlowPumpUpgrade upgrades the Whitelisted Wells to use the new MultiFlowPump. | ||
**/ | ||
contract InitMultiFlowPumpUpgrade { | ||
address internal constant MULTI_FLOW_PUMP_V1_2_1 = 0xBA150002660BbCA20675D1C1535Cd76C98A95b13; | ||
address internal constant U_WELL_IMPLEMENTATION = | ||
address(0xBA510995783111be5301d93CCfD5dE4e3B28e50B); | ||
address internal constant AQUIFER = address(0xBA51AAAa8C2f911AE672e783707Ceb2dA6E97521); | ||
address internal constant CP2_WELL_FUNCTION = | ||
address(0xBA15000450Bf6d48ec50BD6327A9403E401b72b4); | ||
address internal constant BEAN_USDC = address(0xBea00ee04D8289aEd04f92EA122a96dC76A91bd7); | ||
address internal constant BEAN_USDT = address(0xbEA00fF437ca7E8354B174339643B4d1814bED33); | ||
|
||
AppStorage internal s; | ||
|
||
function init() external { | ||
address[] memory wells = LibWhitelistedTokens.getWhitelistedWellLpTokens(); | ||
|
||
for (uint256 i; i < wells.length; i++) { | ||
IWell well = IWell(wells[i]); | ||
// fetch the well's immutable and init data | ||
IERC20[] memory tokens = well.tokens(); | ||
Call memory wellFunction = well.wellFunction(); | ||
Call[] memory pumps = well.pumps(); | ||
|
||
// replace the pump addresses with the new MultiFlowPump address | ||
pumps[0].target = MULTI_FLOW_PUMP_V1_2_1; | ||
|
||
// if the well is not USDC or USDT, set the well function to CP2_WELL_FUNCTION | ||
if (wells[i] != BEAN_USDC && wells[i] != BEAN_USDT) { | ||
wellFunction.target = CP2_WELL_FUNCTION; | ||
} | ||
|
||
// encode the immutable and init data | ||
(bytes memory immutableData, bytes memory initData) = LibWellDeployer | ||
.encodeWellDeploymentData(AQUIFER, tokens, wellFunction, pumps); | ||
|
||
// deploy the new well: | ||
address minimalProxyWell = IAquifer(AQUIFER).boreWell( | ||
U_WELL_IMPLEMENTATION, | ||
immutableData, | ||
initData, | ||
bytes32("1") | ||
); | ||
|
||
// upgrade the well to the new implementation | ||
IWellUpgradeable(wells[i]).upgradeTo(minimalProxyWell); | ||
// call add liquidity to start the pump. | ||
well.sync(address(this), 0); | ||
|
||
// delete the well Oracle snapshot. | ||
delete s.sys.wellOracleSnapshots[wells[i]]; | ||
} | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import {LibArbitrum} from "contracts/libraries/LibArbitrum.sol"; | ||
|
||
/** | ||
* @title ArbSys | ||
* @author Brean | ||
* @notice ArbSys is a precompile for the Arbitrum network that provides the current block number. | ||
*/ | ||
contract ArbSys { | ||
function arbBlockNumber() external view returns (uint256) { | ||
return LibArbitrum.blockNumber(); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import {IWell} from "contracts/interfaces/basin/IWell.sol"; | ||
|
||
/** | ||
* @title IWell is the interface for the Well contract. | ||
* | ||
* In order for a Well to be verified using a permissionless on-chain registry, a Well Implementation should: | ||
* - Not be able to self-destruct (Aquifer's registry would be vulnerable to a metamorphic contract attack) | ||
* - Not be able to change its tokens, Well Function, Pumps and Well Data | ||
*/ | ||
interface IWellUpgradeable is IWell { | ||
function init(string memory name, string memory symbol) external; | ||
|
||
function initNoWellToken() external; | ||
|
||
function upgradeTo(address newImplementation) external; | ||
|
||
function upgradeToAndCall(address newImplementation, bytes memory data) external; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import {IWell, Call, IERC20} from "contracts/interfaces/basin/IWell.sol"; | ||
import {IWellUpgradeable} from "contracts/interfaces/basin/IWellUpgradeable.sol"; | ||
|
||
/** | ||
* @title LibWellDeployer | ||
* @author Brean | ||
* @notice LibWellDeployer provides helper functions for deploying Wells with Aquifers. | ||
*/ | ||
library LibWellDeployer { | ||
/** | ||
* @notice Encode the Well's immutable data. | ||
*/ | ||
function encodeWellDeploymentData( | ||
address _aquifer, | ||
IERC20[] memory _tokens, | ||
Call memory _wellFunction, | ||
Call[] memory _pumps | ||
) internal pure returns (bytes memory immutableData, bytes memory initData) { | ||
immutableData = encodeWellImmutableData(_aquifer, _tokens, _wellFunction, _pumps); | ||
initData = abi.encodeWithSelector(IWellUpgradeable.initNoWellToken.selector); | ||
} | ||
|
||
function encodeWellImmutableData( | ||
address _aquifer, | ||
IERC20[] memory _tokens, | ||
Call memory _wellFunction, | ||
Call[] memory _pumps | ||
) internal pure returns (bytes memory immutableData) { | ||
immutableData = abi.encodePacked( | ||
_aquifer, // aquifer address | ||
_tokens.length, // number of tokens | ||
_wellFunction.target, // well function address | ||
_wellFunction.data.length, // well function data length | ||
_pumps.length, // number of pumps | ||
_tokens, // tokens array | ||
_wellFunction.data // well function data (bytes) | ||
); | ||
for (uint256 i; i < _pumps.length; ++i) { | ||
immutableData = abi.encodePacked( | ||
immutableData, // previously packed pumps | ||
_pumps[i].target, // pump address | ||
_pumps[i].data.length, // pump data length | ||
_pumps[i].data // pump data (bytes) | ||
); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.