@@ -183,24 +183,42 @@ contract L2Genesis is Script {
183183
184184 /// @notice Set up Ethscriptions system contracts
185185 function setEthscriptionsPredeploys () internal {
186- // Create genesis Ethscriptions first (this handles the Ethscriptions contract setup)
186+ // Ensure proxies exist across the full 0x330… namespace, mirroring OP's approach
187+ bytes memory proxyCode = vm.getDeployedCode ("Proxy.sol:Proxy " );
188+ uint160 prefix = uint160 (0x330 ) << 148 ;
187189
188- // Deploy other Ethscriptions-related contracts
189- _setEthscriptionsCode (Predeploys.TOKEN_MANAGER, "TokenManager " );
190- _setEthscriptionsCode (Predeploys.COLLECTIONS_MANAGER, "CollectionsManager " );
191- _setEthscriptionsCode (Predeploys.ETHSCRIPTIONS_PROVER, "EthscriptionsProver " );
192- _setEthscriptionsCode (Predeploys.ERC20_TEMPLATE , "EthscriptionsERC20 " );
193- _setEthscriptionsCode (Predeploys.ERC721_TEMPLATE , "EthscriptionERC721 " );
190+ for (uint256 i = 0 ; i < PREDEPLOY_COUNT; i++ ) {
191+ address addr = address (prefix | uint160 (i));
194192
193+ // Deploy proxy shell and prime nonce for deterministic CREATEs
194+ vm.etch (addr, proxyCode);
195+ vm.setNonce (addr, 1 );
196+ setProxyAdminSlot (addr, Predeploys.PROXY_ADMIN);
197+
198+ // Wire up implementations for the Ethscriptions predeploys that use proxies
199+ bool isProxiedContract = addr == Predeploys.ETHSCRIPTIONS ||
200+ addr == Predeploys.TOKEN_MANAGER ||
201+ addr == Predeploys.ETHSCRIPTIONS_PROVER ||
202+ addr == Predeploys.COLLECTIONS_MANAGER;
203+ if (isProxiedContract) {
204+ address impl = Predeploys.predeployToCodeNamespace (addr);
205+ setImplementation (addr, impl);
206+ }
207+ }
208+
209+ // Set implementation code for non-ETHSCRIPTIONS contracts now
210+ _setImplementationCodeNamed (Predeploys.TOKEN_MANAGER, "TokenManager " );
211+ _setImplementationCodeNamed (Predeploys.COLLECTIONS_MANAGER, "CollectionsManager " );
212+ _setImplementationCodeNamed (Predeploys.ETHSCRIPTIONS_PROVER, "EthscriptionsProver " );
213+ // Templates live directly at their implementation addresses (no proxy wrapping)
214+ _setCodeAt (Predeploys.ERC20_TEMPLATE_IMPLEMENTATION , "EthscriptionsERC20 " );
215+ _setCodeAt (Predeploys.ERC721_TEMPLATE_IMPLEMENTATION , "EthscriptionERC721 " );
216+
217+ // Create genesis Ethscriptions (writes via proxy to proxy storage)
195218 createGenesisEthscriptions ();
196219
197- // Register protocol handlers
220+ // Register protocol handlers via the Ethscriptions proxy
198221 registerProtocolHandlers ();
199-
200- // Disable initializers on all Ethscriptions contracts
201- _disableInitializers (Predeploys.ETHSCRIPTIONS);
202- _disableInitializers (Predeploys.ERC20_TEMPLATE );
203- _disableInitializers (Predeploys.ERC721_TEMPLATE );
204222 }
205223
206224 /// @notice Register protocol handlers with the Ethscriptions contract
@@ -265,13 +283,15 @@ contract L2Genesis is Script {
265283 uint256 totalCount = abi.decode (vm.parseJson (json, ".metadata.totalCount " ), (uint256 ));
266284 console.log ("Found " , totalCount, "genesis Ethscriptions " );
267285
268- // First, etch the GenesisEthscriptions contract temporarily
269- address ethscriptionsAddr = Predeploys.ETHSCRIPTIONS;
270- vm. etch (ethscriptionsAddr, type (GenesisEthscriptions).runtimeCode );
286+ // Use the Ethscriptions proxy address and its implementation code-namespace address
287+ address ethscriptionsProxy = Predeploys.ETHSCRIPTIONS;
288+ address implAddr = Predeploys. predeployToCodeNamespace (ethscriptionsProxy );
271289
272- vm.setNonce (ethscriptionsAddr, 1 );
290+ // Temporarily etch GenesisEthscriptions at the implementation address
291+ vm.etch (implAddr, type (GenesisEthscriptions).runtimeCode);
273292
274- GenesisEthscriptions genesisContract = GenesisEthscriptions (ethscriptionsAddr);
293+ // Call through the proxy using the GenesisEthscriptions interface
294+ GenesisEthscriptions genesisContract = GenesisEthscriptions (ethscriptionsProxy);
275295
276296 // Process each ethscription (this will increment the nonce as SSTORE2 contracts are deployed)
277297 for (uint256 i = 0 ; i < totalCount; i++ ) {
@@ -280,9 +300,9 @@ contract L2Genesis is Script {
280300
281301 console.log ("Created " , totalCount, "genesis Ethscriptions " );
282302
283- // Now etch the real Ethscriptions contract over the GenesisEthscriptions
284- // IMPORTANT: Do NOT reset the nonce here - it needs to continue from where it left off
285- _setEthscriptionsCode (ethscriptionsAddr , "Ethscriptions " );
303+ // Overwrite the implementation bytecode with the real Ethscriptions
304+ // Do not reset nonce on the proxy; we only swap the implementation code
305+ _setImplementationCodeNamed (Predeploys.ETHSCRIPTIONS , "Ethscriptions " );
286306 }
287307
288308 /// @notice Helper to create a single genesis ethscription
@@ -343,11 +363,22 @@ contract L2Genesis is Script {
343363 vm.store (_addr, Constants.INITIALIZABLE_STORAGE, bytes32 (uint256 (0x000000000000000000000000000000000000000000000000ffffffffffffffff )));
344364 }
345365
346- /// @notice Set bytecode for Ethscriptions contracts
347- function _setEthscriptionsCode (address _addr , string memory _name ) internal {
366+ /// @notice Set implementation bytecode for a given predeploy using an explicit contract name
367+ function _setImplementationCodeNamed (address _predeploy , string memory _name ) internal returns (address impl ) {
368+ impl = Predeploys.predeployToCodeNamespace (_predeploy);
369+ bytes memory code = vm.getDeployedCode (string .concat (_name, ".sol: " , _name));
370+ console.log ("Setting implementation code for " , _predeploy, "to " , impl);
371+
372+ _disableInitializers (impl);
373+
374+ vm.etch (impl, code);
375+ }
376+
377+ /// @notice Etch contract bytecode directly at a target address (used for non-proxy templates)
378+ function _setCodeAt (address _addr , string memory _name ) internal {
348379 bytes memory code = vm.getDeployedCode (string .concat (_name, ".sol: " , _name));
380+ _disableInitializers (_addr);
349381 vm.etch (_addr, code);
350- // Don't reset nonce here - let the caller manage it
351382 }
352383
353384 /// @notice Set the admin of a proxy contract
0 commit comments