Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mainnet #29

Merged
merged 21 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions script/DeployPuffETH.s.sol
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;

import { ERC1967Proxy } from "openzeppelin/proxy/ERC1967/ERC1967Proxy.sol";
import { BaseScript } from "script/BaseScript.s.sol";
import { stdJson } from "forge-std/StdJson.sol";
import { ERC1967Proxy } from "openzeppelin/proxy/ERC1967/ERC1967Proxy.sol";
import { BaseScript } from "./BaseScript.s.sol";
import { AccessManager } from "openzeppelin/access/manager/AccessManager.sol";
import { PufferDepositor } from "src/PufferDepositor.sol";
import { PufferOracle } from "src/PufferOracle.sol";
import { PufferVault } from "src/PufferVault.sol";
import { Timelock } from "src/Timelock.sol";
import { NoImplementation } from "src/NoImplementation.sol";
import { PufferDeployment } from "src/structs/PufferDeployment.sol";
import { IEigenLayer } from "src/interface/EigenLayer/IEigenLayer.sol";
import { IStrategy } from "src/interface/EigenLayer/IStrategy.sol";
import { IStETH } from "src/interface/Lido/IStETH.sol";
import { ILidoWithdrawalQueue } from "src/interface/Lido/ILidoWithdrawalQueue.sol";
import { stETHMock } from "test/mocks/stETHMock.sol";
import { LidoWithdrawalQueueMock } from "test/mocks/LidoWithdrawalQueueMock.sol";
import { stETHStrategyMock } from "test/mocks/stETHStrategyMock.sol";
import { EigenLayerManagerMock } from "test/mocks/EigenLayerManagerMock.sol";
import { PufferDepositor } from "../src/PufferDepositor.sol";
import { PufferVault } from "../src/PufferVault.sol";
import { Timelock } from "../src/Timelock.sol";
import { NoImplementation } from "../src/NoImplementation.sol";
import { PufferDeployment } from "../src/structs/PufferDeployment.sol";
import { IEigenLayer } from "../src/interface/EigenLayer/IEigenLayer.sol";
import { IStrategy } from "../src/interface/EigenLayer/IStrategy.sol";
import { IStETH } from "../src/interface/Lido/IStETH.sol";
import { ILidoWithdrawalQueue } from "../src/interface/Lido/ILidoWithdrawalQueue.sol";
import { stETHMock } from "../test/mocks/stETHMock.sol";
import { LidoWithdrawalQueueMock } from "../test/mocks/LidoWithdrawalQueueMock.sol";
import { stETHStrategyMock } from "../test/mocks/stETHStrategyMock.sol";
import { EigenLayerManagerMock } from "../test/mocks/EigenLayerManagerMock.sol";
import { UUPSUpgradeable } from "@openzeppelin-contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { IWETH } from "../src/interface/Other/IWETH.sol";
import { WETH9 } from "../test/mocks/WETH9.sol";
import { ROLE_ID_UPGRADER, ROLE_ID_OPERATIONS } from "./Roles.sol";

/**
* @title DeployPuffer
Expand All @@ -38,15 +40,13 @@ import { UUPSUpgradeable } from "@openzeppelin-contracts-upgradeable/proxy/utils
* PK=${deployer_pk} forge script script/DeployPuffETH.s.sol:DeployPuffETH -vvvv --rpc-url=... --broadcast
*/
contract DeployPuffETH is BaseScript {
uint64 constant ROLE_ID_UPGRADER = 1;
uint64 constant ROLE_ID_OPERATIONS = 22;

/**
* @dev Ethereum Mainnet addresses
*/
IStrategy internal constant _EIGEN_STETH_STRATEGY = IStrategy(0x93c4b944D05dfe6df7645A86cd2206016c51564D);
IEigenLayer internal constant _EIGEN_STRATEGY_MANAGER = IEigenLayer(0x858646372CC42E1A627fcE94aa7A7033e7CF075A);
IStETH internal constant _ST_ETH = IStETH(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
IWETH internal constant _WETH = IWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
ILidoWithdrawalQueue internal constant _LIDO_WITHDRAWAL_QUEUE =
ILidoWithdrawalQueue(0x889edC2eDab5f40e902b864aD4d7AdE8E412F9B1);

Expand All @@ -55,7 +55,6 @@ contract DeployPuffETH is BaseScript {

PufferDepositor pufferDepositor;
PufferDepositor pufferDepositorImplementation;
PufferOracle pufferOracle;
Timelock timelock;

ERC1967Proxy depositorProxy;
Expand All @@ -64,6 +63,7 @@ contract DeployPuffETH is BaseScript {
AccessManager accessManager;

address stETHAddress;
address wethAddress;

address operationsMultisig = vm.envOr("OPERATIONS_MULTISIG", makeAddr("operationsMultisig"));
address pauserMultisig = vm.envOr("PAUSER_MULTISIG", makeAddr("pauserMultisig"));
Expand All @@ -87,7 +87,6 @@ contract DeployPuffETH is BaseScript {
vaultProxy = new ERC1967Proxy{ salt: pufferVaultSalt }(noImpl, "");
vm.label(address(vaultProxy), "PufferVault");

// Deploy mock Puffer oracle
timelock = new Timelock({
accessManager: address(accessManager),
communityMultisig: communityMultisig,
Expand All @@ -99,12 +98,14 @@ contract DeployPuffETH is BaseScript {
{
(
IStETH stETH,
IWETH weth,
ILidoWithdrawalQueue lidoWithdrawalQueue,
IStrategy stETHStrategy,
IEigenLayer eigenStrategyManager
) = _getArgs();

stETHAddress = address(stETH);
wethAddress = address(weth);

// Deploy implementation contracts
pufferVaultImplementation =
Expand Down Expand Up @@ -142,6 +143,7 @@ contract DeployPuffETH is BaseScript {
pufferVaultImplementation: address(pufferVaultImplementation),
pufferOracle: address(0),
stETH: stETHAddress,
weth: wethAddress,
timelock: address(timelock)
});
}
Expand Down Expand Up @@ -184,7 +186,7 @@ contract DeployPuffETH is BaseScript {
// Grant roles to operations & community

// Operations Multisig has 7 day delay
uint256 delayInSeconds = 604800; // 7 days
uint256 delayInSeconds = 0; // 7 days //@todo this is for testing, real deployment has 7 days delay
calldatas[2] = abi.encodeWithSelector(
AccessManager.grantRole.selector, ROLE_ID_UPGRADER, operationsMultisig, delayInSeconds
);
Expand Down Expand Up @@ -245,18 +247,21 @@ contract DeployPuffETH is BaseScript {
internal
returns (
IStETH stETH,
IWETH weth,
ILidoWithdrawalQueue lidoWithdrawalQueue,
IStrategy stETHStrategy,
IEigenLayer eigenStrategyManager
)
{
if (isMainnet()) {
stETH = _ST_ETH;
weth = _WETH;
lidoWithdrawalQueue = _LIDO_WITHDRAWAL_QUEUE;
stETHStrategy = _EIGEN_STETH_STRATEGY;
eigenStrategyManager = _EIGEN_STRATEGY_MANAGER;
} else {
stETH = IStETH(address(new stETHMock()));
weth = new WETH9();
lidoWithdrawalQueue = new LidoWithdrawalQueueMock();
stETHStrategy = new stETHStrategyMock();
eigenStrategyManager = new EigenLayerManagerMock();
Expand Down
14 changes: 14 additions & 0 deletions script/Roles.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;

// Operations & Community multisig have this role
// Operations with 7 day delay, Community 0
uint64 constant ROLE_ID_UPGRADER = 1;
// Role assigned to Operations Multisig
uint64 constant ROLE_ID_OPERATIONS = 22;

// Role assigned to the Puffer Protocol
uint64 constant ROLE_ID_PUFFER_PROTOCOL = 1234;
uint64 constant ROLE_ID_DAO = 77;
uint64 constant ROLE_ID_GUARDIANS = 88;
uint64 constant ROLE_ID_PAUSER = 999;
97 changes: 97 additions & 0 deletions script/UpgradePuffETH.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// SPDX-License-Identifier: GPL-3.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bxmmm1 is there a test that shows this upgrade works as expected? E.g. we can call the upgrade on the vault and try calling some of the functions in a test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pragma solidity >=0.8.0 <0.9.0;

import { stdJson } from "forge-std/StdJson.sol";
import { BaseScript } from ".//BaseScript.s.sol";
import { PufferVault } from "../src/PufferVault.sol";
import { PufferVaultMainnet } from "../src/PufferVaultMainnet.sol";
import { IEigenLayer } from "../src/interface/EigenLayer/IEigenLayer.sol";
import { IStrategy } from "../src/interface/EigenLayer/IStrategy.sol";
import { IStETH } from "../src/interface/Lido/IStETH.sol";
import { ILidoWithdrawalQueue } from "../src/interface/Lido/ILidoWithdrawalQueue.sol";
import { stETHMock } from "../test/mocks/stETHMock.sol";
import { LidoWithdrawalQueueMock } from "../test/mocks/LidoWithdrawalQueueMock.sol";
import { stETHStrategyMock } from "../test/mocks/stETHStrategyMock.sol";
import { EigenLayerManagerMock } from "../test/mocks/EigenLayerManagerMock.sol";
import { UUPSUpgradeable } from "@openzeppelin-contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { IWETH } from "../src/interface/Other/IWETH.sol";
import { IPufferOracle } from "../src/interface/IPufferOracle.sol";
import { WETH9 } from "../test/mocks/WETH9.sol";
import { Initializable } from "openzeppelin/proxy/utils/Initializable.sol";
import { AccessManager } from "openzeppelin/access/manager/AccessManager.sol";

/**
* @title UpgradePufETH
* @author Puffer Finance
* @notice Upgrades PufETH
* @dev
*
*
* NOTE:
*
* If you ran the deployment script, but did not `--broadcast` the transaction, it will still update your local chainId-deployment.json file.
* Other scripts will fail because addresses will be updated in deployments file, but the deployment never happened.
*
* BaseScript.sol holds the private key logic, if you don't have `PK` ENV variable, it will use the default one PK from `makeAddr("pufferDeployer")`
*
* PK=${deployer_pk} forge script script/UpgradePuffETH.s.sol:UpgradePuffETH --sig 'run(address)' "VAULTADDRESS" -vvvv --rpc-url=... --broadcast
*/
contract UpgradePuffETH is BaseScript {
/**
* @dev Ethereum Mainnet addresses
*/
IStrategy internal constant _EIGEN_STETH_STRATEGY = IStrategy(0x93c4b944D05dfe6df7645A86cd2206016c51564D);
IEigenLayer internal constant _EIGEN_STRATEGY_MANAGER = IEigenLayer(0x858646372CC42E1A627fcE94aa7A7033e7CF075A);
IStETH internal constant _ST_ETH = IStETH(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
IWETH internal constant _WETH = IWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
ILidoWithdrawalQueue internal constant _LIDO_WITHDRAWAL_QUEUE =
ILidoWithdrawalQueue(0x889edC2eDab5f40e902b864aD4d7AdE8E412F9B1);

function run(address pufferVault, address accessManager, address pufferOracle) public broadcast {
(
IStETH stETH,
IWETH weth,
ILidoWithdrawalQueue lidoWithdrawalQueue,
IStrategy stETHStrategy,
IEigenLayer eigenStrategyManager
) = _getArgs();

//@todo this is for tests only
AccessManager(accessManager).grantRole(1, _broadcaster, 0);

PufferVaultMainnet newImplementation = new PufferVaultMainnet(
stETH, weth, lidoWithdrawalQueue, stETHStrategy, eigenStrategyManager, IPufferOracle(pufferOracle)
);

vm.expectEmit(true, true, true, true);
emit Initializable.Initialized(2);
UUPSUpgradeable(pufferVault).upgradeToAndCall(
address(newImplementation), abi.encodeCall(PufferVaultMainnet.initialize, ())
);
}

function _getArgs()
internal
returns (
IStETH stETH,
IWETH weth,
ILidoWithdrawalQueue lidoWithdrawalQueue,
IStrategy stETHStrategy,
IEigenLayer eigenStrategyManager
)
{
if (isMainnet()) {
stETH = _ST_ETH;
weth = _WETH;
lidoWithdrawalQueue = _LIDO_WITHDRAWAL_QUEUE;
stETHStrategy = _EIGEN_STETH_STRATEGY;
eigenStrategyManager = _EIGEN_STRATEGY_MANAGER;
} else {
stETH = IStETH(address(new stETHMock()));
weth = new WETH9();
lidoWithdrawalQueue = new LidoWithdrawalQueueMock();
stETHStrategy = new stETHStrategyMock();
eigenStrategyManager = new EigenLayerManagerMock();
}
}
}
12 changes: 6 additions & 6 deletions src/PufferDepositor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { IERC20 } from "openzeppelin/token/ERC20/IERC20.sol";
import { AccessManagedUpgradeable } from
"@openzeppelin-contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";
import { UUPSUpgradeable } from "@openzeppelin-contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { IStETH } from "src/interface/Lido/IStETH.sol";
import { IWstETH } from "src/interface/Lido/IWstETH.sol";
import { PufferVault } from "src/PufferVault.sol";
import { PufferDepositorStorage } from "src/PufferDepositorStorage.sol";
import { IStETH } from "./interface/Lido/IStETH.sol";
import { IWstETH } from "./interface/Lido/IWstETH.sol";
import { PufferVault } from "./PufferVault.sol";
import { PufferDepositorStorage } from "./PufferDepositorStorage.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { ISushiRouter } from "src/interface/Other/ISushiRouter.sol";
import { IPufferDepositor } from "src/interface/IPufferDepositor.sol";
import { ISushiRouter } from "./interface/Other/ISushiRouter.sol";
import { IPufferDepositor } from "./interface/IPufferDepositor.sol";

/**
* @title PufferDepositor
Expand Down
78 changes: 0 additions & 78 deletions src/PufferOracle.sol

This file was deleted.

12 changes: 6 additions & 6 deletions src/PufferVault.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;

import { IPufferVault } from "src/interface/IPufferVault.sol";
import { IPufferVault } from "./interface/IPufferVault.sol";
import { IERC20 } from "openzeppelin/token/ERC20/IERC20.sol";
import { IStETH } from "src/interface/Lido/IStETH.sol";
import { ILidoWithdrawalQueue } from "src/interface/Lido/ILidoWithdrawalQueue.sol";
import { IEigenLayer } from "src/interface/EigenLayer/IEigenLayer.sol";
import { IStrategy } from "src/interface/EigenLayer/IStrategy.sol";
import { PufferVaultStorage } from "src/PufferVaultStorage.sol";
import { IStETH } from "./interface/Lido/IStETH.sol";
import { ILidoWithdrawalQueue } from "./interface/Lido/ILidoWithdrawalQueue.sol";
import { IEigenLayer } from "./interface/EigenLayer/IEigenLayer.sol";
import { IStrategy } from "./interface/EigenLayer/IStrategy.sol";
import { PufferVaultStorage } from "./PufferVaultStorage.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC721Receiver } from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
Expand Down Expand Up @@ -74,7 +74,7 @@
__ERC20_init("pufETH", "pufETH");
}

receive() external payable virtual {

Check warning on line 77 in src/PufferVault.sol

View workflow job for this annotation

GitHub Actions / solhint

Fallback function must be simple
// If we don't use this pattern, somebody can create a Lido withdrawal, claim it to this contract
// Making `$.lidoLockedETH -= msg.value` revert
VaultStorage storage $ = _getPufferVaultStorage();
Expand Down
Loading
Loading