Skip to content

Commit

Permalink
Rewarder deploy/upgrade script
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0Louis committed Jan 11, 2023
1 parent 2343fb7 commit 6dad19e
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 0 deletions.
41 changes: 41 additions & 0 deletions script/deployment/fuji/Rewarder.deploy.sol
Original file line number Diff line number Diff line change
@@ -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));
}
}
54 changes: 54 additions & 0 deletions script/deployment/fuji/Rewarder.upgrade.sol
Original file line number Diff line number Diff line change
@@ -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;
}
24 changes: 24 additions & 0 deletions test/RewarderDeploy.t.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}
34 changes: 34 additions & 0 deletions test/RewarderUpgrade.t.sol
Original file line number Diff line number Diff line change
@@ -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"
);
}
}

0 comments on commit 6dad19e

Please sign in to comment.