Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to enable CacheManager through UpgradeExecutor #231

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading