@@ -6,40 +6,56 @@ import {AdminProxy} from "../src/AdminProxy.sol";
66
77/// @title GenerateAdminProxyAlloc
88/// @notice Generates genesis alloc JSON for deploying AdminProxy at a deterministic address
9- /// @dev Run with: forge script script/GenerateAdminProxyAlloc.s.sol -vvv
9+ /// @dev Run with: OWNER=0xYourAddress forge script script/GenerateAdminProxyAlloc.s.sol -vvv
1010///
1111/// This script outputs the bytecode and storage layout needed to deploy AdminProxy
12- /// in the genesis block. The contract is deployed with owner = address(0), allowing
13- /// the first caller to claim ownership post-genesis.
12+ /// in the genesis block. The owner is set directly in storage slot 0.
1413///
1514/// Usage:
16- /// 1. Run this script to get the bytecode
17- /// 2. Add to genesis.json alloc section at desired address (e.g., 0x...AD00)
18- /// 3. Set that address as mintAdmin in chainspec config
15+ /// 1. Set OWNER env var to your initial admin EOA address
16+ /// 2. Run this script to get the bytecode and storage
17+ /// 3. Add to genesis.json alloc section at desired address (e.g., 0x...Ad00)
18+ /// 4. Set that address as mintAdmin in chainspec config
1919contract GenerateAdminProxyAlloc is Script {
2020 // Suggested deterministic address for AdminProxy
2121 // Using a memorable address in the precompile-adjacent range
2222 address constant SUGGESTED_ADDRESS = 0x000000000000000000000000000000000000Ad00 ;
2323
2424 function run () external {
25+ // Get owner from environment, default to zero if not set
26+ address owner = vm.envOr ("OWNER " , address (0 ));
27+
2528 // Deploy to get runtime bytecode
2629 AdminProxy proxy = new AdminProxy ();
2730
2831 // Get runtime bytecode (not creation code)
2932 bytes memory runtimeCode = address (proxy).code;
3033
34+ // Convert owner to storage slot value (left-padded to 32 bytes)
35+ bytes32 ownerSlotValue = bytes32 (uint256 (uint160 (owner)));
36+
3137 console.log ("========== AdminProxy Genesis Alloc ========== " );
3238 console.log ("" );
3339 console.log ("Suggested address: " , SUGGESTED_ADDRESS);
40+ console.log ("Owner (from OWNER env): " , owner);
3441 console.log ("" );
42+
43+ if (owner == address (0 )) {
44+ console.log ("WARNING: OWNER not set! Set OWNER env var to your admin EOA. " );
45+ console.log ("Example: OWNER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 forge script ... " );
46+ console.log ("" );
47+ }
48+
3549 console.log ("Add this to your genesis.json 'alloc' section: " );
3650 console.log ("" );
3751 console.log ("{ " );
3852 console.log (' "alloc": { ' );
3953 console.log (' "000000000000000000000000000000000000Ad00": { ' );
4054 console.log (' "balance": "0x0", ' );
4155 console.log (' "code": "0x%s", ' , vm.toString (runtimeCode));
42- console.log (' "storage": {} ' );
56+ console.log (' "storage": { ' );
57+ console.log (' "0x0": "0x%s" ' , vm.toString (ownerSlotValue));
58+ console.log (" } " );
4359 console.log (" } " );
4460 console.log (" } " );
4561 console.log ("} " );
@@ -58,30 +74,37 @@ contract GenerateAdminProxyAlloc is Script {
5874 console.log ("============================================== " );
5975 console.log ("" );
6076 console.log ("Post-genesis steps: " );
61- console.log ("1. Call claimOwnership() from desired EOA " );
77+ console.log ("1. Owner can immediately use the proxy (no claiming needed) " );
6278 console.log ("2. Deploy multisig (e.g., Safe) " );
6379 console.log ("3. Call transferOwnership(multisigAddress) " );
6480 console.log ("4. From multisig, call acceptOwnership() " );
6581 console.log ("" );
6682
6783 // Also output raw values for programmatic use
6884 console.log ("Raw bytecode length: " , runtimeCode.length );
85+ console.log ("Owner storage slot (0x0): " , vm.toString (ownerSlotValue));
6986 }
7087}
7188
7289/// @title GenerateAdminProxyAllocJSON
7390/// @notice Outputs just the JSON snippet for easy copy-paste
91+ /// @dev Run with: OWNER=0xYourAddress forge script script/GenerateAdminProxyAlloc.s.sol:GenerateAdminProxyAllocJSON -vvv
7492contract GenerateAdminProxyAllocJSON is Script {
7593 function run () external {
94+ address owner = vm.envOr ("OWNER " , address (0 ));
95+
7696 AdminProxy proxy = new AdminProxy ();
7797 bytes memory runtimeCode = address (proxy).code;
98+ bytes32 ownerSlotValue = bytes32 (uint256 (uint160 (owner)));
7899
79100 // Output minimal JSON that can be merged into genesis
80101 string memory json = string (
81102 abi.encodePacked (
82103 '{"000000000000000000000000000000000000Ad00":{"balance":"0x0","code":"0x ' ,
83104 vm.toString (runtimeCode),
84- '","storage":{}}} '
105+ '","storage":{"0x0":"0x ' ,
106+ vm.toString (ownerSlotValue),
107+ '"}}} '
85108 )
86109 );
87110
0 commit comments