// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {Script, console} from "forge-std/Script.sol";
import {Chain138MainnetCheckpoint} from "../../contracts/mainnet-checkpoint/Chain138MainnetCheckpoint.sol";

/// @notice UUPS upgrade: PaymentLeafV2 submit + V2 extension payloads. IMPLEMENTATION_VERSION 4.
contract UpgradeChain138MainnetCheckpointV4 is Script {
    function run() external {
        address proxy = vm.envAddress("CHAIN138_MAINNET_CHECKPOINT_PROXY");
        uint256 pk = vm.envUint("PRIVATE_KEY");

        vm.startBroadcast(pk);
        Chain138MainnetCheckpoint newImpl = new Chain138MainnetCheckpoint();
        console.log("New impl v4:", address(newImpl));
        Chain138MainnetCheckpoint(proxy).upgradeToAndCall(address(newImpl), "");
        require(Chain138MainnetCheckpoint(proxy).IMPLEMENTATION_VERSION() == 4, "version");
        vm.stopBroadcast();
    }
}
