Skip to content

Commit

Permalink
Merge pull request #231 from OffchainLabs/cache-mngr-setup
Browse files Browse the repository at this point in the history
Add option to enable CacheManager through UpgradeExecutor
  • Loading branch information
gzeoneth committed Aug 15, 2024
2 parents 4cbf68f + 2b88dfb commit 21d0255
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions scripts/deploymentUtils.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -9,13 +9,15 @@ import {
import { Toolkit4844 } from '../test/contract/toolkit4844'
import {
ArbOwner__factory,
ArbOwnerPublic__factory,
ArbSys__factory,
CacheManager__factory,
} from '../build/types'

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
Expand Down Expand Up @@ -273,42 +275,66 @@ export async function deployAllContracts(
}

export async function deployAndSetCacheManager(
chainOwnerWallet: any,
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,
[cacheManagerLogic.address, proxyAdmin.address, '0x'],
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
)
await (await arbOwner.addWasmCacheManager(cacheManagerProxy.address)).wait()
if ((await chainOwnerWallet.provider.getCode(arbOwnerAccount)) === '0x') {
// arb owner is EOA, add cache manager directly
await (
await arbOwnerPrecompile.addWasmCacheManager(cacheManagerProxy.address)
).wait()
} else {
// assume upgrade executor is arb owner
const upgradeExecutor = new ethers.Contract(
arbOwnerAccount,
UpgradeExecutorABI,
chainOwnerWallet
)
const data = arbOwnerPrecompile.interface.encodeFunctionData(
'addWasmCacheManager',
[cacheManagerProxy.address]
)
await (await upgradeExecutor.executeCall(ARB_OWNER_ADDRESS, data)).wait()
}

return cacheManagerProxy
}
Expand Down

0 comments on commit 21d0255

Please sign in to comment.