Skip to content
Draft
Show file tree
Hide file tree
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
71 changes: 71 additions & 0 deletions script/upgrades/PayerRegistryUpgrader.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import { Script, console } from "../../lib/forge-std/src/Script.sol";

import { GenericEIP1967Migrator } from "../../../src/any-chain/GenericEIP1967Migrator.sol";
import { IERC1967 } from "../../../src/abstract/interfaces/IERC1967.sol";
import { PayerRegistry } from "../../../src/settlement-chain/PayerRegistry.sol";

import { IParameterRegistry } from "../../../src/abstract/interfaces/IParameterRegistry.sol";
import { Utils } from "../../script/utils/Utils.sol";
import {PayerRegistryDeployer} from "../deployers/PayerRegistryDeployer.sol";


contract PayerRegistryUpgrader is Script {
error PrivateKeyNotSet();
error EnvironmentNotSet();

string internal _environment;

uint256 internal _privateKey;
address internal _admin;

Utils.DeploymentData internal deployment;

function setUp() external {
_environment = vm.envString("ENVIRONMENT");

if (bytes(_environment).length == 0) revert EnvironmentNotSet();

console.log("Environment: %s", _environment);

deployment = Utils.parseDeploymentData(string.concat("config/", _environment, ".json"));

_privateKey = uint256(vm.envBytes32("ADMIN_PRIVATE_KEY"));

if (_privateKey == 0) revert PrivateKeyNotSet();

_admin = vm.addr(_privateKey);

console.log("Admin: %s", _admin);
}

function UpgradePayerRegistry() external {
address factory = deployment.factory;
console.log("factory" , factory);
address paramRegistry = deployment.parameterRegistryProxy;
console.log("paramRegistry" , paramRegistry);
address feeToken = deployment.feeTokenProxy;
console.log("feeToken" , feeToken);
address proxy = deployment.payerRegistryProxy;
console.log("proxy" , proxy);

vm.startBroadcast(_privateKey);
(address newImpl, ) = PayerRegistryDeployer.deployImplementation(
factory,
paramRegistry,
feeToken
);
console.log("newImpl", newImpl);

GenericEIP1967Migrator migrator = new GenericEIP1967Migrator(newImpl);
console.log("migrator", address(migrator));
string memory key = PayerRegistry(proxy).migratorParameterKey();
IParameterRegistry(paramRegistry).set(key, bytes32(uint256(uint160(address(migrator)))));

PayerRegistry(proxy).migrate();

vm.stopBroadcast();
}
}
74 changes: 74 additions & 0 deletions script/upgrades/PayerReportManager.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import { Script, console } from "../../lib/forge-std/src/Script.sol";

import { GenericEIP1967Migrator } from "../../../src/any-chain/GenericEIP1967Migrator.sol";
import { IERC1967 } from "../../../src/abstract/interfaces/IERC1967.sol";

import { IParameterRegistry } from "../../../src/abstract/interfaces/IParameterRegistry.sol";
import { Utils } from "../../script/utils/Utils.sol";
import {PayerReportManager} from "../../src/settlement-chain/PayerReportManager.sol";
import {PayerReportManagerDeployer} from "../deployers/PayerReportManagerDeployer.sol";


contract PayerReportManagerUpgrader is Script {
error PrivateKeyNotSet();
error EnvironmentNotSet();

string internal _environment;

uint256 internal _privateKey;
address internal _admin;

Utils.DeploymentData internal deployment;

function setUp() external {
_environment = vm.envString("ENVIRONMENT");

if (bytes(_environment).length == 0) revert EnvironmentNotSet();

console.log("Environment: %s", _environment);

deployment = Utils.parseDeploymentData(string.concat("config/", _environment, ".json"));

_privateKey = uint256(vm.envBytes32("ADMIN_PRIVATE_KEY"));

if (_privateKey == 0) revert PrivateKeyNotSet();

_admin = vm.addr(_privateKey);

console.log("Admin: %s", _admin);
}

function UpgradePayerReportManager() external {
address factory = deployment.factory;
console.log("factory" , factory);
address paramRegistry = deployment.parameterRegistryProxy;
console.log("paramRegistry" , paramRegistry);
address proxy = deployment.payerReportManagerProxy;
console.log("proxy" , proxy);
address nodeRegistry = deployment.nodeRegistryProxy;
console.log("nodeRegistry" , nodeRegistry);
address payerRegistry = deployment.payerRegistryProxy;
console.log("payerRegistry" , payerRegistry);

vm.startBroadcast(_privateKey);
(address newImpl, ) = PayerReportManagerDeployer.deployImplementation(
factory,
paramRegistry,
nodeRegistry,
payerRegistry
);
console.log("newImpl", newImpl);

GenericEIP1967Migrator migrator = new GenericEIP1967Migrator(newImpl);
console.log("migrator", address(migrator));
string memory key = PayerReportManager(proxy).migratorParameterKey();
IParameterRegistry(paramRegistry).set(key, bytes32(uint256(uint160(address(migrator)))));

PayerReportManager(proxy).migrate();

vm.stopBroadcast();
}
}
81 changes: 81 additions & 0 deletions script/upgrades/SettlementChainGatewayUpgrader.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import { Script, console } from "../../lib/forge-std/src/Script.sol";

import { GenericEIP1967Migrator } from "../../../src/any-chain/GenericEIP1967Migrator.sol";
import { IERC1967 } from "../../../src/abstract/interfaces/IERC1967.sol";

import { IParameterRegistry } from "../../../src/abstract/interfaces/IParameterRegistry.sol";
import { SettlementChainGateway } from "../../../src/settlement-chain/SettlementChainGateway.sol";
import { SettlementChainGatewayDeployer } from "../../../script/deployers/SettlementChainGatewayDeployer.sol";
import { Utils } from "../../script/utils/Utils.sol";

interface ISettlementChainGateway {
function parameterRegistry() external view returns (address);
function appChainGateway() external view returns (address);
function feeToken() external view returns (address);
function migrate() external;
function migratorParameterKey() external pure returns (string memory);
}

contract SettlementChainGatewayUpgrader is Script {
error PrivateKeyNotSet();
error EnvironmentNotSet();

string internal _environment;

uint256 internal _privateKey;
address internal _admin;

Utils.DeploymentData internal deployment;

function setUp() external {
_environment = vm.envString("ENVIRONMENT");

if (bytes(_environment).length == 0) revert EnvironmentNotSet();

console.log("Environment: %s", _environment);

deployment = Utils.parseDeploymentData(string.concat("config/", _environment, ".json"));

_privateKey = uint256(vm.envBytes32("ADMIN_PRIVATE_KEY"));

if (_privateKey == 0) revert PrivateKeyNotSet();

_admin = vm.addr(_privateKey);

console.log("Admin: %s", _admin);
}

function UpgradeSettlementChainGateway() external {
address factory = deployment.factory;
console.log("factory" , factory);
address paramRegistry = deployment.parameterRegistryProxy;
console.log("paramRegistry" , paramRegistry);
address settlementChainGateway = deployment.gatewayProxy;
console.log("settlementChainGateway" , settlementChainGateway);
address feeToken = deployment.feeTokenProxy;
console.log("feeToken" , feeToken);
address proxy = deployment.gatewayProxy;
console.log("proxy" , proxy);

vm.startBroadcast(_privateKey);
(address newImpl, ) = SettlementChainGatewayDeployer.deployImplementation(
factory,
paramRegistry,
settlementChainGateway,
feeToken
);
console.log("newImpl", newImpl);

GenericEIP1967Migrator migrator = new GenericEIP1967Migrator(newImpl);
console.log("migrator", address(migrator));
string memory key = ISettlementChainGateway(proxy).migratorParameterKey();
IParameterRegistry(paramRegistry).set(key, bytes32(uint256(uint160(address(migrator)))));

SettlementChainGateway(settlementChainGateway).migrate();

vm.stopBroadcast();
}
}
63 changes: 63 additions & 0 deletions script/upgrades/SettlementChainParameterRegistryUpgrader.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import { Script, console } from "../../lib/forge-std/src/Script.sol";

import { GenericEIP1967Migrator } from "../../../src/any-chain/GenericEIP1967Migrator.sol";
import { IERC1967 } from "../../../src/abstract/interfaces/IERC1967.sol";

import { IParameterRegistry } from "../../../src/abstract/interfaces/IParameterRegistry.sol";
import { Utils } from "../../script/utils/Utils.sol";
import {SettlementChainParameterRegistryDeployer} from "../deployers/SettlementChainParameterRegistryDeployer.sol";

contract SettlementChainParameterRegistryUpgrader is Script {
error PrivateKeyNotSet();
error EnvironmentNotSet();

string internal _environment;

uint256 internal _privateKey;
address internal _admin;

Utils.DeploymentData internal deployment;

function setUp() external {
_environment = vm.envString("ENVIRONMENT");

if (bytes(_environment).length == 0) revert EnvironmentNotSet();

console.log("Environment: %s", _environment);

deployment = Utils.parseDeploymentData(string.concat("config/", _environment, ".json"));

_privateKey = uint256(vm.envBytes32("ADMIN_PRIVATE_KEY"));

if (_privateKey == 0) revert PrivateKeyNotSet();

_admin = vm.addr(_privateKey);

console.log("Admin: %s", _admin);
}

function UpgradeSettlementParameterRegistry() external {
address factory = deployment.factory;
console.log("factory" , factory);
address paramRegistry = deployment.parameterRegistryProxy;
console.log("paramRegistry" , paramRegistry);

vm.startBroadcast(_privateKey);
(address newImpl, ) = SettlementChainParameterRegistryDeployer.deployImplementation(
factory
);
console.log("newImpl", newImpl);

GenericEIP1967Migrator migrator = new GenericEIP1967Migrator(newImpl);
console.log("migrator", address(migrator));
string memory key = IParameterRegistry(paramRegistry).migratorParameterKey();
IParameterRegistry(paramRegistry).set(key, bytes32(uint256(uint160(address(migrator)))));

IParameterRegistry(paramRegistry).migrate();

vm.stopBroadcast();
}
}
64 changes: 64 additions & 0 deletions src/any-chain/GenericEIP1967Migrator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import { IERC1967 } from "../../src/abstract/interfaces/IERC1967.sol";

/**
* @title GenericEIP1967Migrator
* @notice Minimal migrator that upgrades an EIP-1967 proxy to a new implementation.
*
* @dev HOW IT WORKS
* - This contract is deployed as a *standalone* “migrator”.
* - Your proxied contract implements the XMTP `Migratable` pattern. When governance
* sets this migrator’s address in the ParameterRegistry and calls `proxy.migrate()`,
* the proxy will `delegatecall("")` into this contract (empty calldata).
* - Because it’s a `delegatecall`, *this fallback executes in the proxy’s storage
* context*, so it can write the EIP-1967 implementation slot on the proxy.
*
* WHAT IT DOES
* - Writes `NEW_IMPL` into the EIP-1967 implementation slot.
* - Emits the standard `IERC1967.Upgraded(newImpl)` event.
*
* WHAT IT DOES NOT DO
* - Does not run any initialization or data migration on the new implementation.
* If you need state transforms or an `initialize(...)` call, use a purpose-built
* migrator that (after setting the slot) `delegatecall`s the new impl with the
* desired calldata.
*
* SAFETY NOTES
* - This migrator is intentionally tiny: fewer moving parts, easier to audit.
* - Make sure `NEW_IMPL` preserves storage layout and initializer semantics.
* - Only allow `migrate()` to be reachable via your governed parameter (`migrator` key).
*/
contract GenericEIP1967Migrator {
error InvalidImplementation();

/// @notice The implementation that the proxy will be upgraded to.
address public immutable NEW_IMPL;

Check failure on line 37 in src/any-chain/GenericEIP1967Migrator.sol

View workflow job for this annotation

GitHub Actions / Lint check

Immutable variables names are set to be in mixedCase

Check warning on line 37 in src/any-chain/GenericEIP1967Migrator.sol

View workflow job for this annotation

GitHub Actions / Lint check

Function order is incorrect, contract immutable declaration can not go after custom error definition (line 34)

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions Warning

Variable GenericEIP1967Migrator.NEW_IMPL is not in mixedCase

/// @dev bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)
bytes32 private constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

/**
* @param newImpl_ The address of the new implementation (must be non-zero).
*/
constructor(address newImpl_) {
if (newImpl_ == address(0)) revert InvalidImplementation();
NEW_IMPL = newImpl_;
}

/**
* @notice Entry point when the proxy `delegatecall`s this contract with empty calldata.
* @dev Runs in the *proxy’s* context (storage is the proxy’s), so we can sstore the slot.
* Emits the standard ERC-1967 `Upgraded` event via the imported interface.
*/
fallback() external payable {
address impl = NEW_IMPL;

assembly {
sstore(_IMPLEMENTATION_SLOT, impl)
}

emit IERC1967.Upgraded(impl);
}
Comment on lines +55 to +63

Check warning

Code scanning / Slither

Assembly usage Warning

}
Comment on lines +33 to +64

Check warning

Code scanning / Slither

Contracts that lock Ether Medium

Contract locking ether found:
Contract GenericEIP1967Migrator has payable functions:
- GenericEIP1967Migrator.fallback()
But does not have a function to withdraw the ether
Loading
Loading