Skip to content

Commit 1d1cfc4

Browse files
committed
upgrades
1 parent a480cc4 commit 1d1cfc4

File tree

4 files changed

+265
-0
lines changed

4 files changed

+265
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.28;
3+
4+
import { Script, console } from "../../lib/forge-std/src/Script.sol";
5+
6+
import { GenericEIP1967Migrator } from "../../../src/any-chain/GenericEIP1967Migrator.sol";
7+
import { IERC1967 } from "../../../src/abstract/interfaces/IERC1967.sol";
8+
import { PayerRegistry } from "../../../src/settlement-chain/PayerRegistry.sol";
9+
10+
import { IParameterRegistry } from "../../../src/abstract/interfaces/IParameterRegistry.sol";
11+
import { Utils } from "../../script/utils/Utils.sol";
12+
import {PayerRegistryDeployer} from "../deployers/PayerRegistryDeployer.sol";
13+
14+
15+
contract PayerRegistryUpgrader is Script {
16+
error PrivateKeyNotSet();
17+
error EnvironmentNotSet();
18+
19+
string internal _environment;
20+
21+
uint256 internal _privateKey;
22+
address internal _admin;
23+
24+
Utils.DeploymentData internal deployment;
25+
26+
function setUp() external {
27+
_environment = vm.envString("ENVIRONMENT");
28+
29+
if (bytes(_environment).length == 0) revert EnvironmentNotSet();
30+
31+
console.log("Environment: %s", _environment);
32+
33+
deployment = Utils.parseDeploymentData(string.concat("config/", _environment, ".json"));
34+
35+
_privateKey = uint256(vm.envBytes32("ADMIN_PRIVATE_KEY"));
36+
37+
if (_privateKey == 0) revert PrivateKeyNotSet();
38+
39+
_admin = vm.addr(_privateKey);
40+
41+
console.log("Admin: %s", _admin);
42+
}
43+
44+
function UpgradePayerRegistry() external {
45+
address factory = deployment.factory;
46+
console.log("factory" , factory);
47+
address paramRegistry = deployment.parameterRegistryProxy;
48+
console.log("paramRegistry" , paramRegistry);
49+
address feeToken = deployment.feeTokenProxy;
50+
console.log("feeToken" , feeToken);
51+
address proxy = deployment.payerRegistryProxy;
52+
console.log("proxy" , proxy);
53+
54+
vm.startBroadcast(_privateKey);
55+
(address newImpl, ) = PayerRegistryDeployer.deployImplementation(
56+
factory,
57+
paramRegistry,
58+
feeToken
59+
);
60+
console.log("newImpl", newImpl);
61+
62+
GenericEIP1967Migrator migrator = new GenericEIP1967Migrator(newImpl);
63+
console.log("migrator", address(migrator));
64+
string memory key = PayerRegistry(proxy).migratorParameterKey();
65+
IParameterRegistry(paramRegistry).set(key, bytes32(uint256(uint160(address(migrator)))));
66+
67+
PayerRegistry(proxy).migrate();
68+
69+
vm.stopBroadcast();
70+
}
71+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.28;
3+
4+
import { Script, console } from "../../lib/forge-std/src/Script.sol";
5+
6+
import { GenericEIP1967Migrator } from "../../../src/any-chain/GenericEIP1967Migrator.sol";
7+
import { IERC1967 } from "../../../src/abstract/interfaces/IERC1967.sol";
8+
9+
import { IParameterRegistry } from "../../../src/abstract/interfaces/IParameterRegistry.sol";
10+
import { Utils } from "../../script/utils/Utils.sol";
11+
import {PayerReportManager} from "../../src/settlement-chain/PayerReportManager.sol";
12+
import {PayerReportManagerDeployer} from "../deployers/PayerReportManagerDeployer.sol";
13+
14+
15+
contract PayerReportManagerUpgrader is Script {
16+
error PrivateKeyNotSet();
17+
error EnvironmentNotSet();
18+
19+
string internal _environment;
20+
21+
uint256 internal _privateKey;
22+
address internal _admin;
23+
24+
Utils.DeploymentData internal deployment;
25+
26+
function setUp() external {
27+
_environment = vm.envString("ENVIRONMENT");
28+
29+
if (bytes(_environment).length == 0) revert EnvironmentNotSet();
30+
31+
console.log("Environment: %s", _environment);
32+
33+
deployment = Utils.parseDeploymentData(string.concat("config/", _environment, ".json"));
34+
35+
_privateKey = uint256(vm.envBytes32("ADMIN_PRIVATE_KEY"));
36+
37+
if (_privateKey == 0) revert PrivateKeyNotSet();
38+
39+
_admin = vm.addr(_privateKey);
40+
41+
console.log("Admin: %s", _admin);
42+
}
43+
44+
function UpgradePayerReportManager() external {
45+
address factory = deployment.factory;
46+
console.log("factory" , factory);
47+
address paramRegistry = deployment.parameterRegistryProxy;
48+
console.log("paramRegistry" , paramRegistry);
49+
address proxy = deployment.payerReportManagerProxy;
50+
console.log("proxy" , proxy);
51+
address nodeRegistry = deployment.nodeRegistryProxy;
52+
console.log("nodeRegistry" , nodeRegistry);
53+
address payerRegistry = deployment.payerRegistryProxy;
54+
console.log("payerRegistry" , payerRegistry);
55+
56+
vm.startBroadcast(_privateKey);
57+
(address newImpl, ) = PayerReportManagerDeployer.deployImplementation(
58+
factory,
59+
paramRegistry,
60+
nodeRegistry,
61+
payerRegistry
62+
);
63+
console.log("newImpl", newImpl);
64+
65+
GenericEIP1967Migrator migrator = new GenericEIP1967Migrator(newImpl);
66+
console.log("migrator", address(migrator));
67+
string memory key = PayerReportManager(proxy).migratorParameterKey();
68+
IParameterRegistry(paramRegistry).set(key, bytes32(uint256(uint160(address(migrator)))));
69+
70+
PayerReportManager(proxy).migrate();
71+
72+
vm.stopBroadcast();
73+
}
74+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.28;
3+
4+
import "forge-std/Test.sol";
5+
6+
import { IERC1967 } from "../../src/abstract/interfaces/IERC1967.sol";
7+
import { IParameterRegistry } from "../../src/abstract/interfaces/IParameterRegistry.sol";
8+
import { PayerRegistry } from "../../src/settlement-chain/PayerRegistry.sol";
9+
10+
import { GenericEIP1967Migrator } from "../../src/any-chain/GenericEIP1967Migrator.sol";
11+
import { Utils } from "../../script/utils/Utils.sol";
12+
import {PayerRegistryDeployer} from "../../script/deployers/PayerRegistryDeployer.sol";
13+
14+
contract PayerRegistryUpgradeForkTest is Test {
15+
address constant admin = 0x560469CBb7D1E29c7d56EfE765B21FbBaC639dC7;
16+
17+
Utils.DeploymentData internal deployment;
18+
19+
function setUp() external {
20+
// Hardcoded environment and RPC
21+
string memory rpc = "https://sepolia.base.org";
22+
vm.createSelectFork(rpc);
23+
24+
string memory environment = "testnet-staging";
25+
deployment = Utils.parseDeploymentData(string.concat("config/", environment, ".json"));
26+
}
27+
28+
function test_payer_registry() external {
29+
address factory = deployment.factory;
30+
address paramRegistry = deployment.parameterRegistryProxy;
31+
address settlementChainGateway = deployment.gatewayProxy;
32+
address feeToken = deployment.feeTokenProxy;
33+
address proxy = deployment.payerRegistryProxy;
34+
35+
address oldImpl = IERC1967(proxy).implementation();
36+
37+
(address newImpl, ) = PayerRegistryDeployer.deployImplementation(
38+
factory,
39+
paramRegistry,
40+
feeToken
41+
);
42+
43+
// Deploy migrator
44+
GenericEIP1967Migrator migrator = new GenericEIP1967Migrator(newImpl);
45+
46+
// Set the migrator in ParameterRegistry (impersonate admin)
47+
vm.startPrank(admin);
48+
string memory key = PayerRegistry(proxy).migratorParameterKey();
49+
IParameterRegistry(paramRegistry).set(key, bytes32(uint256(uint160(address(migrator)))));
50+
vm.stopPrank();
51+
52+
// Execute migration
53+
PayerRegistry(proxy).migrate();
54+
55+
// Confirm the implementation changed
56+
address afterImpl = IERC1967(proxy).implementation();
57+
assertEq(afterImpl, newImpl, "Implementation did not update");
58+
}
59+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.28;
3+
4+
import "forge-std/Test.sol";
5+
6+
import { IERC1967 } from "../../src/abstract/interfaces/IERC1967.sol";
7+
import { IParameterRegistry } from "../../src/abstract/interfaces/IParameterRegistry.sol";
8+
import { PayerReportManager } from "../../src/settlement-chain/PayerReportManager.sol";
9+
10+
import { GenericEIP1967Migrator } from "../../src/any-chain/GenericEIP1967Migrator.sol";
11+
import { Utils } from "../../script/utils/Utils.sol";
12+
import {PayerRegistryDeployer} from "../../script/deployers/PayerRegistryDeployer.sol";
13+
import {PayerReportManagerDeployer} from "../../script/deployers/PayerReportManagerDeployer.sol";
14+
15+
contract PayerReportManagerUpgradeForkTest is Test {
16+
address constant admin = 0x560469CBb7D1E29c7d56EfE765B21FbBaC639dC7;
17+
18+
Utils.DeploymentData internal deployment;
19+
20+
function setUp() external {
21+
// Hardcoded environment and RPC
22+
string memory rpc = "https://sepolia.base.org";
23+
vm.createSelectFork(rpc);
24+
25+
string memory environment = "testnet-staging";
26+
deployment = Utils.parseDeploymentData(string.concat("config/", environment, ".json"));
27+
}
28+
29+
function test_payer_report_manager() external {
30+
address factory = deployment.factory;
31+
address paramRegistry = deployment.parameterRegistryProxy;
32+
address proxy = deployment.payerReportManagerProxy;
33+
address nodeRegistry = deployment.nodeRegistryProxy;
34+
address payerRegistry = deployment.payerRegistryProxy;
35+
36+
address oldImpl = IERC1967(proxy).implementation();
37+
38+
(address newImpl, ) = PayerReportManagerDeployer.deployImplementation(
39+
factory,
40+
paramRegistry,
41+
nodeRegistry,
42+
payerRegistry
43+
);
44+
45+
// Deploy migrator
46+
GenericEIP1967Migrator migrator = new GenericEIP1967Migrator(newImpl);
47+
48+
// Set the migrator in ParameterRegistry (impersonate admin)
49+
vm.startPrank(admin);
50+
string memory key = PayerReportManager(proxy).migratorParameterKey();
51+
IParameterRegistry(paramRegistry).set(key, bytes32(uint256(uint160(address(migrator)))));
52+
vm.stopPrank();
53+
54+
// Execute migration
55+
PayerReportManager(proxy).migrate();
56+
57+
// Confirm the implementation changed
58+
address afterImpl = IERC1967(proxy).implementation();
59+
assertEq(afterImpl, newImpl, "Implementation did not update");
60+
}
61+
}

0 commit comments

Comments
 (0)