From 6dad19e3e913e00925477d790420e716e1e0599b Mon Sep 17 00:00:00 2001 From: 0x0Louis Date: Wed, 11 Jan 2023 00:40:14 +0100 Subject: [PATCH] Rewarder deploy/upgrade script --- script/deployment/fuji/Rewarder.deploy.sol | 41 ++++++++++++++++ script/deployment/fuji/Rewarder.upgrade.sol | 54 +++++++++++++++++++++ test/RewarderDeploy.t.sol | 24 +++++++++ test/RewarderUpgrade.t.sol | 34 +++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 script/deployment/fuji/Rewarder.deploy.sol create mode 100644 script/deployment/fuji/Rewarder.upgrade.sol create mode 100644 test/RewarderDeploy.t.sol create mode 100644 test/RewarderUpgrade.t.sol diff --git a/script/deployment/fuji/Rewarder.deploy.sol b/script/deployment/fuji/Rewarder.deploy.sol new file mode 100644 index 0000000..9a80687 --- /dev/null +++ b/script/deployment/fuji/Rewarder.deploy.sol @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "forge-std/Script.sol"; +import "openzeppelin/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "openzeppelin/proxy/transparent/ProxyAdmin.sol"; + +import "../../../src/Rewarder.sol"; + +contract RewarderDeployer is Script { + function run() public returns (address, address, address) { + vm.createSelectFork(stdChains["fuji"].rpcUrl); + + uint256 deployerPrivateKey = vm.envUint("DEPLOY_PRIVATE_KEY"); + + /** + * Start broadcasting the transaction to the network. + */ + vm.startBroadcast(deployerPrivateKey); + + ProxyAdmin admin = new ProxyAdmin(); + + Rewarder implementation = new Rewarder(); + + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( + address(implementation), + address(admin), + "" + ); + + Rewarder(payable(address(proxy))).initialize(30 days); + + vm.stopBroadcast(); + /** + * Stop broadcasting the transaction to the network. + */ + + return (address(proxy), address(implementation), address(admin)); + } +} diff --git a/script/deployment/fuji/Rewarder.upgrade.sol b/script/deployment/fuji/Rewarder.upgrade.sol new file mode 100644 index 0000000..469e8e2 --- /dev/null +++ b/script/deployment/fuji/Rewarder.upgrade.sol @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "forge-std/Script.sol"; +import "openzeppelin/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "openzeppelin/proxy/transparent/ProxyAdmin.sol"; + +import "../../../src/Rewarder.sol"; + +contract RewarderUpgrader is Script { + IVBS public constant vbs = IVBS(0xFFC08538077a0455E0F4077823b1A0E3e18Faf0b); + + ProxyAdmin public constant admin = ProxyAdmin(0x46709dbc09656292B27ad91EE2c5d324270D3387); + + TransparentUpgradeableProxy public constant proxy = + TransparentUpgradeableProxy(payable(0x1D336E165CbA662fa49B935fFdD7362C09Cc93ec)); + + function run() public returns (address) { + vm.createSelectFork(stdChains["fuji"].rpcUrl, 17_891_593); + + uint256 deployerPrivateKey = vm.envUint("DEPLOY_PRIVATE_KEY"); + + /** + * Start broadcasting the transaction to the network. + */ + vm.startBroadcast(deployerPrivateKey); + + Rewarder implementation = new Rewarder(); + + vbs.call( + address(admin), abi.encodeWithSelector(admin.upgrade.selector, address(proxy), address(implementation)) + ); + + vm.stopBroadcast(); + /** + * Stop broadcasting the transaction to the network. + */ + + return address(implementation); + } +} + +interface IVBS { + function getOwner(uint256 _index) external view returns (address owner); + + function getNumberOfOwners() external view returns (uint256 nbOfAdmins); + + function addOwner(address _owner) external; + + function removeOwner(address _owner) external; + + function call(address _target, bytes calldata _data) external payable; +} diff --git a/test/RewarderDeploy.t.sol b/test/RewarderDeploy.t.sol new file mode 100644 index 0000000..2aa5de2 --- /dev/null +++ b/test/RewarderDeploy.t.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "forge-std/Test.sol"; + +import "../script/deployment/fuji/Rewarder.deploy.sol"; + +contract RewarderDeployTest is Test { + RewarderDeployer public deployer; + + function setUp() public { + deployer = new RewarderDeployer(); + } + + function testDeploy() public { + (address proxy, address implementation, address admin) = deployer.run(); + + vm.startPrank(admin); + assertEq(TransparentUpgradeableProxy(payable(proxy)).admin(), admin, "proxy admin"); + assertEq(TransparentUpgradeableProxy(payable(proxy)).implementation(), implementation, "proxy implementation"); + vm.stopPrank(); + } +} diff --git a/test/RewarderUpgrade.t.sol b/test/RewarderUpgrade.t.sol new file mode 100644 index 0000000..93d9d5c --- /dev/null +++ b/test/RewarderUpgrade.t.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "forge-std/Test.sol"; + +import "../script/deployment/fuji/Rewarder.upgrade.sol"; + +contract RewarderUpgradeTest is Test { + RewarderUpgrader public upgrader; + + function setUp() public { + vm.createSelectFork(stdChains["fuji"].rpcUrl); + + upgrader = new RewarderUpgrader(); + } + + function testUpgrade() public { + address admin = address(upgrader.admin()); + address proxy = address(upgrader.proxy()); + + vm.prank(admin); + address implementation = TransparentUpgradeableProxy(payable(proxy)).implementation(); + + address newImplementation = upgrader.run(); + + assertTrue(address(implementation) != newImplementation, "new implementation"); + + vm.prank(admin); + assertEq( + TransparentUpgradeableProxy(payable(proxy)).implementation(), newImplementation, "proxy implementation" + ); + } +}