1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* Imports: External */
import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import { getDeployedContract } from '../src/hardhat-deploy-ethers'
import { predeploys } from '../src/predeploys'
import { NON_ZERO_ADDRESS } from '../test/helpers/constants'
import { getContractFactory } from '../src/contract-defs'
import l1StandardBridgeJson from '../artifacts/contracts/L1/messaging/OVM_L1StandardBridge.sol/OVM_L1StandardBridge.json'
const deployFn: DeployFunction = async (hre) => {
const { deploy } = hre.deployments
const { deployer } = await hre.getNamedAccounts()
const Lib_AddressManager = await getDeployedContract(
hre,
'Lib_AddressManager',
{
signerOrProvider: deployer,
}
)
const result = await deploy('Proxy__OVM_L1StandardBridge', {
contract: 'L1ChugSplashProxy',
from: deployer,
args: [deployer],
log: true,
})
if (!result.newlyDeployed) {
return
}
// Create a contract object at the Proxy address with the proxy interface.
const Proxy__WithChugSplashInterface = await getDeployedContract(
hre,
'Proxy__OVM_L1StandardBridge',
{
signerOrProvider: deployer,
iface: 'L1ChugSplashProxy',
}
)
// Create a contract object at the Proxy address with the brige implementation interface.
const Proxy__WithBridgeInterface = await getDeployedContract(
hre,
'Proxy__OVM_L1StandardBridge',
{
signerOrProvider: deployer,
iface: 'OVM_L1StandardBridge',
}
)
// Set the implementation code
const bridgeCode = l1StandardBridgeJson.deployedBytecode
await Proxy__WithChugSplashInterface.setCode(bridgeCode)
// Set slot 0 to the L1 Messenger Address
const l1MessengerAddress = await Lib_AddressManager.getAddress(
'Proxy__OVM_L1CrossDomainMessenger'
)
await Proxy__WithChugSplashInterface.setStorage(
hre.ethers.constants.HashZero,
hre.ethers.utils.hexZeroPad(l1MessengerAddress, 32)
)
// Verify that the slot was set correctly
const l1MessengerStored =
await Proxy__WithBridgeInterface.callStatic.messenger()
console.log('l1MessengerStored:', l1MessengerStored)
if (l1MessengerStored !== l1MessengerAddress) {
throw new Error(
'L1 messenger address was not correctly set, check the key value used in setStorage'
)
}
// Set Slot 1 to the L2 Standard Bridge Address
await Proxy__WithChugSplashInterface.setStorage(
hre.ethers.utils.hexZeroPad('0x01', 32),
hre.ethers.utils.hexZeroPad(predeploys.OVM_L2StandardBridge, 32)
)
// Verify that the slot was set correctly
const l2TokenBridgeStored =
await Proxy__WithBridgeInterface.callStatic.l2TokenBridge()
console.log('l2TokenBridgeStored:', l2TokenBridgeStored)
if (l2TokenBridgeStored !== predeploys.OVM_L2StandardBridge) {
throw new Error(
'L2 bridge address was not correctly set, check the key value used in setStorage'
)
}
// transfer ownership to Address Manager owner
const addressManagerOwner = Lib_AddressManager.callStatic.owner()
await Proxy__WithChugSplashInterface.setOwner(addressManagerOwner)
// Todo: remove this after adding chugsplash proxy
await Lib_AddressManager.setAddress(
'Proxy__OVM_L1StandardBridge',
result.address
)
}
deployFn.dependencies = ['Lib_AddressManager', 'OVM_L1StandardBridge']
deployFn.tags = ['Proxy__OVM_L1StandardBridge']
export default deployFn