Skip to content

Commit 2116455

Browse files
authored
Merge 1d1cfc4 into 880a671
2 parents 880a671 + 1d1cfc4 commit 2116455

9 files changed

+594
-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: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 { SettlementChainGateway } from "../../../src/settlement-chain/SettlementChainGateway.sol";
11+
import { SettlementChainGatewayDeployer } from "../../../script/deployers/SettlementChainGatewayDeployer.sol";
12+
import { Utils } from "../../script/utils/Utils.sol";
13+
14+
interface ISettlementChainGateway {
15+
function parameterRegistry() external view returns (address);
16+
function appChainGateway() external view returns (address);
17+
function feeToken() external view returns (address);
18+
function migrate() external;
19+
function migratorParameterKey() external pure returns (string memory);
20+
}
21+
22+
contract SettlementChainGatewayUpgrader is Script {
23+
error PrivateKeyNotSet();
24+
error EnvironmentNotSet();
25+
26+
string internal _environment;
27+
28+
uint256 internal _privateKey;
29+
address internal _admin;
30+
31+
Utils.DeploymentData internal deployment;
32+
33+
function setUp() external {
34+
_environment = vm.envString("ENVIRONMENT");
35+
36+
if (bytes(_environment).length == 0) revert EnvironmentNotSet();
37+
38+
console.log("Environment: %s", _environment);
39+
40+
deployment = Utils.parseDeploymentData(string.concat("config/", _environment, ".json"));
41+
42+
_privateKey = uint256(vm.envBytes32("ADMIN_PRIVATE_KEY"));
43+
44+
if (_privateKey == 0) revert PrivateKeyNotSet();
45+
46+
_admin = vm.addr(_privateKey);
47+
48+
console.log("Admin: %s", _admin);
49+
}
50+
51+
function UpgradeSettlementChainGateway() external {
52+
address factory = deployment.factory;
53+
console.log("factory" , factory);
54+
address paramRegistry = deployment.parameterRegistryProxy;
55+
console.log("paramRegistry" , paramRegistry);
56+
address settlementChainGateway = deployment.gatewayProxy;
57+
console.log("settlementChainGateway" , settlementChainGateway);
58+
address feeToken = deployment.feeTokenProxy;
59+
console.log("feeToken" , feeToken);
60+
address proxy = deployment.gatewayProxy;
61+
console.log("proxy" , proxy);
62+
63+
vm.startBroadcast(_privateKey);
64+
(address newImpl, ) = SettlementChainGatewayDeployer.deployImplementation(
65+
factory,
66+
paramRegistry,
67+
settlementChainGateway,
68+
feeToken
69+
);
70+
console.log("newImpl", newImpl);
71+
72+
GenericEIP1967Migrator migrator = new GenericEIP1967Migrator(newImpl);
73+
console.log("migrator", address(migrator));
74+
string memory key = ISettlementChainGateway(proxy).migratorParameterKey();
75+
IParameterRegistry(paramRegistry).set(key, bytes32(uint256(uint160(address(migrator)))));
76+
77+
SettlementChainGateway(settlementChainGateway).migrate();
78+
79+
vm.stopBroadcast();
80+
}
81+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 {SettlementChainParameterRegistryDeployer} from "../deployers/SettlementChainParameterRegistryDeployer.sol";
12+
13+
contract SettlementChainParameterRegistryUpgrader is Script {
14+
error PrivateKeyNotSet();
15+
error EnvironmentNotSet();
16+
17+
string internal _environment;
18+
19+
uint256 internal _privateKey;
20+
address internal _admin;
21+
22+
Utils.DeploymentData internal deployment;
23+
24+
function setUp() external {
25+
_environment = vm.envString("ENVIRONMENT");
26+
27+
if (bytes(_environment).length == 0) revert EnvironmentNotSet();
28+
29+
console.log("Environment: %s", _environment);
30+
31+
deployment = Utils.parseDeploymentData(string.concat("config/", _environment, ".json"));
32+
33+
_privateKey = uint256(vm.envBytes32("ADMIN_PRIVATE_KEY"));
34+
35+
if (_privateKey == 0) revert PrivateKeyNotSet();
36+
37+
_admin = vm.addr(_privateKey);
38+
39+
console.log("Admin: %s", _admin);
40+
}
41+
42+
function UpgradeSettlementParameterRegistry() external {
43+
address factory = deployment.factory;
44+
console.log("factory" , factory);
45+
address paramRegistry = deployment.parameterRegistryProxy;
46+
console.log("paramRegistry" , paramRegistry);
47+
48+
vm.startBroadcast(_privateKey);
49+
(address newImpl, ) = SettlementChainParameterRegistryDeployer.deployImplementation(
50+
factory
51+
);
52+
console.log("newImpl", newImpl);
53+
54+
GenericEIP1967Migrator migrator = new GenericEIP1967Migrator(newImpl);
55+
console.log("migrator", address(migrator));
56+
string memory key = IParameterRegistry(paramRegistry).migratorParameterKey();
57+
IParameterRegistry(paramRegistry).set(key, bytes32(uint256(uint160(address(migrator)))));
58+
59+
IParameterRegistry(paramRegistry).migrate();
60+
61+
vm.stopBroadcast();
62+
}
63+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.28;
3+
4+
import { IERC1967 } from "../../src/abstract/interfaces/IERC1967.sol";
5+
6+
/**
7+
* @title GenericEIP1967Migrator
8+
* @notice Minimal migrator that upgrades an EIP-1967 proxy to a new implementation.
9+
*
10+
* @dev HOW IT WORKS
11+
* - This contract is deployed as a *standalone* “migrator”.
12+
* - Your proxied contract implements the XMTP `Migratable` pattern. When governance
13+
* sets this migrator’s address in the ParameterRegistry and calls `proxy.migrate()`,
14+
* the proxy will `delegatecall("")` into this contract (empty calldata).
15+
* - Because it’s a `delegatecall`, *this fallback executes in the proxy’s storage
16+
* context*, so it can write the EIP-1967 implementation slot on the proxy.
17+
*
18+
* WHAT IT DOES
19+
* - Writes `NEW_IMPL` into the EIP-1967 implementation slot.
20+
* - Emits the standard `IERC1967.Upgraded(newImpl)` event.
21+
*
22+
* WHAT IT DOES NOT DO
23+
* - Does not run any initialization or data migration on the new implementation.
24+
* If you need state transforms or an `initialize(...)` call, use a purpose-built
25+
* migrator that (after setting the slot) `delegatecall`s the new impl with the
26+
* desired calldata.
27+
*
28+
* SAFETY NOTES
29+
* - This migrator is intentionally tiny: fewer moving parts, easier to audit.
30+
* - Make sure `NEW_IMPL` preserves storage layout and initializer semantics.
31+
* - Only allow `migrate()` to be reachable via your governed parameter (`migrator` key).
32+
*/
33+
contract GenericEIP1967Migrator {
34+
error InvalidImplementation();
35+
36+
/// @notice The implementation that the proxy will be upgraded to.
37+
address public immutable NEW_IMPL;
38+
39+
/// @dev bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)
40+
bytes32 private constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
41+
42+
/**
43+
* @param newImpl_ The address of the new implementation (must be non-zero).
44+
*/
45+
constructor(address newImpl_) {
46+
if (newImpl_ == address(0)) revert InvalidImplementation();
47+
NEW_IMPL = newImpl_;
48+
}
49+
50+
/**
51+
* @notice Entry point when the proxy `delegatecall`s this contract with empty calldata.
52+
* @dev Runs in the *proxy’s* context (storage is the proxy’s), so we can sstore the slot.
53+
* Emits the standard ERC-1967 `Upgraded` event via the imported interface.
54+
*/
55+
fallback() external payable {
56+
address impl = NEW_IMPL;
57+
58+
assembly {
59+
sstore(_IMPLEMENTATION_SLOT, impl)
60+
}
61+
62+
emit IERC1967.Upgraded(impl);
63+
}
64+
}

0 commit comments

Comments
 (0)