PythLazerChangeOwnership.s.sol 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // SPDX-License-Identifier: UNLICENSED
  2. pragma solidity ^0.8.13;
  3. // --- Script Purpose ---
  4. // This script transfers ownership of the deployed PythLazer contract (proxy) to a new owner contract (typically the governance executor contract).
  5. // Usage: Run this script after deploying the new executor contract on the target chain. Ensure the executor address is correct and deployed.
  6. // Preconditions:
  7. // - The LAZER_PROXY_ADDRESS must point to the deployed PythLazer proxy contract. Currently set to 0xACeA761c27A909d4D3895128EBe6370FDE2dF481, which was made using createX.
  8. // - The NEW_OWNER must be the deployed executor contract address on this chain.
  9. // - The script must be run by the current owner (OLD_OWNER) of the PythLazer contract.
  10. // - The DEPLOYER_PRIVATE_KEY environment variable must be set to the current owner's private key.
  11. //
  12. // Steps:
  13. // 1. Log current and new owner addresses, and the proxy address.
  14. // 2. Check the current owner matches the expected OLD_OWNER.
  15. // 3. Transfer ownership to the NEW_OWNER (executor contract).
  16. // 4. Log the new owner for verification.
  17. //
  18. // Note: This script is intended for use with Foundry (forge-std) tooling.
  19. import {Script, console} from "forge-std/Script.sol";
  20. import {PythLazer} from "../src/PythLazer.sol";
  21. import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
  22. import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
  23. // Main script contract for ownership transfer
  24. contract PythLazerChangeOwnership is Script {
  25. // Address of the deployed PythLazer proxy contract
  26. address public constant LAZER_PROXY_ADDRESS =
  27. address(0xACeA761c27A909d4D3895128EBe6370FDE2dF481);
  28. // Private key of the current owner, loaded from environment variable
  29. uint256 public OLD_OWNER_PRIVATE_KEY = vm.envUint("DEPLOYER_PRIVATE_KEY");
  30. // Current owner address, derived from private key
  31. address public OLD_OWNER = vm.addr(OLD_OWNER_PRIVATE_KEY);
  32. // Address of the new owner (should be the deployed executor contract)
  33. address public NEW_OWNER = vm.envAddress("NEW_OWNER");
  34. // Entry point for the script
  35. function run() public {
  36. // Log relevant addresses for traceability
  37. console.log("Old owner: %s", OLD_OWNER);
  38. console.log("New owner: %s", NEW_OWNER);
  39. console.log("Lazer proxy address: %s", LAZER_PROXY_ADDRESS);
  40. console.log("Lazer owner: %s", PythLazer(LAZER_PROXY_ADDRESS).owner());
  41. console.log("Moving ownership from %s to %s", OLD_OWNER, NEW_OWNER);
  42. // Get the PythLazer contract instance at the proxy address
  43. PythLazer lazer = PythLazer(LAZER_PROXY_ADDRESS);
  44. // Start broadcasting transactions as the old owner
  45. vm.startBroadcast(OLD_OWNER_PRIVATE_KEY);
  46. // Ensure the current owner matches the expected old owner
  47. require(lazer.owner() == OLD_OWNER, "Old owner mismatch");
  48. // Transfer ownership to the new owner (executor contract)
  49. lazer.transferOwnership(NEW_OWNER);
  50. console.log("Ownership transferred");
  51. // Log the new owner for verification
  52. console.log(
  53. "New Lazer owner: %s",
  54. PythLazer(LAZER_PROXY_ADDRESS).owner()
  55. );
  56. // Stop broadcasting
  57. vm.stopBroadcast();
  58. }
  59. }