|
| 1 | +import "@nomiclabs/hardhat-web3"; |
| 2 | +import "@nomiclabs/hardhat-ethers"; |
| 3 | +import "@nomiclabs/hardhat-waffle"; |
| 4 | + |
| 5 | +import { |
| 6 | + HardhatRuntimeEnvironment |
| 7 | +} from 'hardhat/types'; |
| 8 | +import { assertContractVariable, getContractAddressByName, awaitCondition } from "../src/deploy-utils"; |
| 9 | +import { ethers } from 'ethers' |
| 10 | + |
| 11 | +import { |
| 12 | + ImplStorageName, |
| 13 | + ProxyStorageName, |
| 14 | + ContractFactoryName, |
| 15 | +} from "../src/types" |
| 16 | + |
| 17 | +export const SequencerInit = async ( |
| 18 | + hre: HardhatRuntimeEnvironment, |
| 19 | + path: string, |
| 20 | + deployer: any, |
| 21 | + configTmp: any |
| 22 | +): Promise<string> => { |
| 23 | + // L1Sequencer addresses |
| 24 | + const L1SequencerProxyAddress = getContractAddressByName(path, ProxyStorageName.L1SequencerProxyStorageName) |
| 25 | + const L1SequencerImplAddress = getContractAddressByName(path, ImplStorageName.L1SequencerStorageName) |
| 26 | + const L1SequencerFactory = await hre.ethers.getContractFactory(ContractFactoryName.L1Sequencer) |
| 27 | + |
| 28 | + const IL1SequencerProxy = await hre.ethers.getContractAt(ContractFactoryName.DefaultProxyInterface, L1SequencerProxyAddress, deployer) |
| 29 | + |
| 30 | + if ( |
| 31 | + (await IL1SequencerProxy.implementation()).toLocaleLowerCase() !== L1SequencerImplAddress.toLocaleLowerCase() |
| 32 | + ) { |
| 33 | + console.log('Upgrading the L1Sequencer proxy...') |
| 34 | + |
| 35 | + // Owner is the deployer (will be transferred to multisig in production) |
| 36 | + const owner = await deployer.getAddress() |
| 37 | + |
| 38 | + // Get initial sequencer address from config (first sequencer address) |
| 39 | + // Note: l2SequencerAddresses is defined in contracts/src/deploy-config/l1.ts |
| 40 | + const initialSequencer = (configTmp.l2SequencerAddresses && configTmp.l2SequencerAddresses.length > 0) |
| 41 | + ? configTmp.l2SequencerAddresses[0] |
| 42 | + : ethers.constants.AddressZero |
| 43 | + |
| 44 | + console.log('Initial sequencer address:', initialSequencer) |
| 45 | + |
| 46 | + // Upgrade and initialize the proxy with owner and initial sequencer |
| 47 | + // Note: We set sequencer in initialize() to avoid TransparentUpgradeableProxy admin restriction |
| 48 | + await IL1SequencerProxy.upgradeToAndCall( |
| 49 | + L1SequencerImplAddress, |
| 50 | + L1SequencerFactory.interface.encodeFunctionData('initialize', [owner, initialSequencer]) |
| 51 | + ) |
| 52 | + |
| 53 | + await awaitCondition( |
| 54 | + async () => { |
| 55 | + return ( |
| 56 | + (await IL1SequencerProxy.implementation()).toLocaleLowerCase() === L1SequencerImplAddress.toLocaleLowerCase() |
| 57 | + ) |
| 58 | + }, |
| 59 | + 3000, |
| 60 | + 1000 |
| 61 | + ) |
| 62 | + |
| 63 | + const contractTmp = new ethers.Contract( |
| 64 | + L1SequencerProxyAddress, |
| 65 | + L1SequencerFactory.interface, |
| 66 | + deployer, |
| 67 | + ) |
| 68 | + |
| 69 | + await assertContractVariable( |
| 70 | + contractTmp, |
| 71 | + 'owner', |
| 72 | + owner, |
| 73 | + ) |
| 74 | + |
| 75 | + if (initialSequencer !== ethers.constants.AddressZero) { |
| 76 | + await assertContractVariable( |
| 77 | + contractTmp, |
| 78 | + 'sequencer', |
| 79 | + initialSequencer, |
| 80 | + ) |
| 81 | + console.log('L1SequencerProxy upgrade success, initial sequencer set:', initialSequencer) |
| 82 | + } else { |
| 83 | + console.log('L1SequencerProxy upgrade success (no initial sequencer set)') |
| 84 | + } |
| 85 | + } |
| 86 | + return '' |
| 87 | +} |
| 88 | + |
| 89 | +export default SequencerInit |
0 commit comments