From 47989be933f4720a80d39c7da42a97b0cfdf7311 Mon Sep 17 00:00:00 2001 From: Goran Vladika Date: Mon, 12 Aug 2024 10:40:04 +0200 Subject: [PATCH 1/2] Add option to enable CacheManager through UpgradeExecutor --- scripts/deploymentUtils.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/scripts/deploymentUtils.ts b/scripts/deploymentUtils.ts index 582ae67d..b8748d81 100644 --- a/scripts/deploymentUtils.ts +++ b/scripts/deploymentUtils.ts @@ -1,5 +1,5 @@ import { ethers } from 'hardhat' -import { ContractFactory, Contract, Overrides, BigNumber } from 'ethers' +import { ContractFactory, Contract, Overrides, BigNumber, Wallet } from 'ethers' import '@nomiclabs/hardhat-ethers' import { run } from 'hardhat' import { @@ -245,7 +245,7 @@ export async function deployAllContracts( } export async function deployAndSetCacheManager( - chainOwnerWallet: any, + chainOwnerWallet: Wallet, verify: boolean = true ) { const cacheManagerLogic = await deployContract( @@ -280,7 +280,23 @@ export async function deployAndSetCacheManager( ARB_OWNER_ADDRESS, chainOwnerWallet ) - await (await arbOwner.addWasmCacheManager(cacheManagerProxy.address)).wait() + + const arbOwnerAccount = (await arbOwner.getAllChainOwners())[0] + if ((await chainOwnerWallet.provider.getCode(arbOwnerAccount)) === '0x') { + // arb owner is EOA, add cache manager directly + await (await arbOwner.addWasmCacheManager(cacheManagerProxy.address)).wait() + } else { + // assume upgrade executor is arb owner + const upgradeExecutor = new ethers.Contract( + arbOwnerAccount, + UpgradeExecutorABI, + chainOwnerWallet + ) + const data = arbOwner.interface.encodeFunctionData('addWasmCacheManager', [ + cacheManagerProxy.address, + ]) + await (await upgradeExecutor.executeCall(ARB_OWNER_ADDRESS, data)).wait() + } return cacheManagerProxy } From 99c07a7db2fcce75b751c5a2bd4936e898cda065 Mon Sep 17 00:00:00 2001 From: Goran Vladika Date: Mon, 12 Aug 2024 13:27:12 +0200 Subject: [PATCH 2/2] Use arb owner public to poll for chain owners --- scripts/deploymentUtils.ts | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/scripts/deploymentUtils.ts b/scripts/deploymentUtils.ts index b8748d81..4f1198e4 100644 --- a/scripts/deploymentUtils.ts +++ b/scripts/deploymentUtils.ts @@ -9,6 +9,7 @@ import { import { Toolkit4844 } from '../test/contract/toolkit4844' import { ArbOwner__factory, + ArbOwnerPublic__factory, ArbSys__factory, CacheManager__factory, } from '../build/types' @@ -16,6 +17,7 @@ import { const INIT_CACHE_SIZE = 536870912 const INIT_DECAY = 10322197911 const ARB_OWNER_ADDRESS = '0x0000000000000000000000000000000000000070' +const ARB_OWNER_PUBLIC_ADDRESS = '0x000000000000000000000000000000000000006b' const ARB_SYS_ADDRESS = '0x0000000000000000000000000000000000000064' // Define a verification function @@ -248,20 +250,19 @@ export async function deployAndSetCacheManager( chainOwnerWallet: Wallet, verify: boolean = true ) { + // deploy CacheManager const cacheManagerLogic = await deployContract( 'CacheManager', chainOwnerWallet, [], verify ) - const proxyAdmin = await deployContract( 'ProxyAdmin', chainOwnerWallet, [], verify ) - const cacheManagerProxy = await deployContract( 'TransparentUpgradeableProxy', chainOwnerWallet, @@ -269,22 +270,30 @@ export async function deployAndSetCacheManager( verify ) + // initialize CacheManager const cacheManager = CacheManager__factory.connect( cacheManagerProxy.address, chainOwnerWallet ) - await (await cacheManager.initialize(INIT_CACHE_SIZE, INIT_DECAY)).wait() - const arbOwner = ArbOwner__factory.connect( + /// add CacheManager to ArbOwner + const arbOwnerAccount = ( + await ArbOwnerPublic__factory.connect( + ARB_OWNER_PUBLIC_ADDRESS, + chainOwnerWallet + ).getAllChainOwners() + )[0] + + const arbOwnerPrecompile = ArbOwner__factory.connect( ARB_OWNER_ADDRESS, chainOwnerWallet ) - - const arbOwnerAccount = (await arbOwner.getAllChainOwners())[0] if ((await chainOwnerWallet.provider.getCode(arbOwnerAccount)) === '0x') { // arb owner is EOA, add cache manager directly - await (await arbOwner.addWasmCacheManager(cacheManagerProxy.address)).wait() + await ( + await arbOwnerPrecompile.addWasmCacheManager(cacheManagerProxy.address) + ).wait() } else { // assume upgrade executor is arb owner const upgradeExecutor = new ethers.Contract( @@ -292,9 +301,10 @@ export async function deployAndSetCacheManager( UpgradeExecutorABI, chainOwnerWallet ) - const data = arbOwner.interface.encodeFunctionData('addWasmCacheManager', [ - cacheManagerProxy.address, - ]) + const data = arbOwnerPrecompile.interface.encodeFunctionData( + 'addWasmCacheManager', + [cacheManagerProxy.address] + ) await (await upgradeExecutor.executeCall(ARB_OWNER_ADDRESS, data)).wait() }