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

nest upgrade script: add more checks to deployment, remove test & get private key from env. #94

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 38 additions & 11 deletions nest/script/UpgradeNestContracts.s.sol
Original file line number Diff line number Diff line change
@@ -1,30 +1,57 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import { AggregateToken } from "../src/AggregateToken.sol";
import { AggregateTokenProxy } from "../src/proxy/AggregateTokenProxy.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { Script } from "forge-std/Script.sol";
import { Test } from "forge-std/Test.sol";
import { console2 } from "forge-std/console2.sol";

import { AggregateToken } from "../src/AggregateToken.sol";
import { AggregateTokenProxy } from "../src/proxy/AggregateTokenProxy.sol";

contract UpgradeNestContracts is Script, Test {
contract UpgradeNestContracts is Script {

address private constant NEST_ADMIN_ADDRESS = 0xb015762405De8fD24d29A6e0799c12e0Ea81c1Ff;

UUPSUpgradeable private constant AGGREGATE_TOKEN_PROXY =
UUPSUpgradeable(payable(0x659619AEdf381c3739B0375082C2d61eC1fD8835));

function test() public { }
Copy link
Member

Choose a reason for hiding this comment

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

I think we should keep the test() so it doesn't show up in forge coverage as untested?


function run() external {
vm.startBroadcast(NEST_ADMIN_ADDRESS);

AggregateToken newAggregateTokenImpl = new AggregateToken();
assertGt(address(newAggregateTokenImpl).code.length, 0, "AggregateToken should be deployed");
console2.log("New AggregateToken Implementation deployed to:", address(newAggregateTokenImpl));
// Get private key from environment
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
address deployer = vm.addr(deployerPrivateKey);

console2.log("Deploying with address:", deployer);

if (deployer == NEST_ADMIN_ADDRESS) {
AggregateToken newAggregateTokenImpl = new AggregateToken();
address newImplAddress = address(newAggregateTokenImpl);

require(address(newAggregateTokenImpl).code.length > 0, "Implementation contract 0 byte code");

console2.log("New AggregateToken Implementation deployed to:", address(newAggregateTokenImpl));

AGGREGATE_TOKEN_PROXY.upgradeToAndCall(address(newAggregateTokenImpl), "");

// Get implementation address after upgrade
address implAddress = address(
uint160(
uint256(
vm.load(
address(AGGREGATE_TOKEN_PROXY),
// ERC1967 IMPLEMENTATION storage slot
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
Copy link
Member

Choose a reason for hiding this comment

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

Can you make this into a constant? bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)

)
)
)
);

require(implAddress == newImplAddress, "Implementation address mismatch");

AGGREGATE_TOKEN_PROXY.upgradeToAndCall(address(newAggregateTokenImpl), "");
console2.log("Upgrade completed successfully");
} else {
Copy link
Member

Choose a reason for hiding this comment

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

It should already automatically fail because vm.startBroadcast(NEST_ADMIN_ADDRESS); will say you haven't unlocked NEST_ADMIN_ADDRESS

console2.log("we need NEST_ADMIN_ADDRESS PK to upgrade AggregateToken, please try again with correct PK.");
}

vm.stopBroadcast();
}
Expand Down