-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathl3Configuration.ts
More file actions
222 lines (197 loc) · 7.08 KB
/
l3Configuration.ts
File metadata and controls
222 lines (197 loc) · 7.08 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import { L3Config } from './l3ConfigType'
import fs from 'fs'
import { JsonRpcProvider } from '@ethersproject/providers'
import { createPublicClient, defineChain, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { arbOwnerPublicActions } from '@arbitrum/orbit-sdk'
import { arbGasInfoPublicActions } from '@arbitrum/orbit-sdk'
import { sanitizePrivateKey } from '@arbitrum/orbit-sdk/utils'
function createPublicClientFromChainInfo({
id,
name,
rpcUrl,
}: {
id: number
name: string
rpcUrl: string
}) {
const chain = defineChain({
id: id,
network: name,
name: name,
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
rpcUrls: {
default: {
http: [rpcUrl],
},
public: {
http: [rpcUrl],
},
},
testnet: true,
})
return createPublicClient({ chain, transport: http() })
}
export async function l3Configuration(
parentChainDeployerKey: string,
orbitChainRpc: string
) {
if (!parentChainDeployerKey || !orbitChainRpc) {
throw new Error('Required environment variable not found')
}
// Generation parent chain provider and network
const l2Provider = new JsonRpcProvider(orbitChainRpc)
const l2NetworkInfo = await l2Provider.getNetwork()
//Generating deployer signer
const deployer = privateKeyToAccount(
sanitizePrivateKey(parentChainDeployerKey)
)
// Creating Orbit chain client with arb owner and arb gas info extension
const orbitChainPublicClient = createPublicClientFromChainInfo({
id: l2NetworkInfo.chainId,
name: l2NetworkInfo.name,
rpcUrl: orbitChainRpc,
})
.extend(arbOwnerPublicActions)
.extend(arbGasInfoPublicActions)
// Read the JSON configuration
const configRaw = fs.readFileSync(
'./config/orbitSetupScriptConfig.json',
'utf-8'
)
const config: L3Config = JSON.parse(configRaw)
// Reading params for Configuration
const minOrbitChainBaseFee = config.minL2BaseFee
const networkFeeReceiver = config.networkFeeReceiver as `0x${string}`
const infrastructureFeeCollector =
config.infrastructureFeeCollector as `0x${string}`
const chainOwner = config.chainOwner
// Check if the Private Key provided is the chain owner:
if (deployer.address !== chainOwner) {
throw new Error('The Private Key you have provided is not the chain owner')
}
// Call the isChainOwner function and check the response
const isOwnerInitially = await orbitChainPublicClient.arbOwnerReadContract({
functionName: 'isChainOwner',
args: [deployer.address],
})
// assert account is not already an owner
if (!isOwnerInitially) {
throw new Error('The address you have provided is not the chain owner')
}
// Set the orbit chain base fee
console.log('Setting the Minimum Base Fee for the Orbit chain')
const setMinimumBaseFeeTransactionRequest =
await orbitChainPublicClient.arbOwnerPrepareTransactionRequest({
functionName: 'setMinimumL2BaseFee',
args: [BigInt(minOrbitChainBaseFee)],
upgradeExecutor: false,
account: deployer.address,
})
// submit tx to update minimum child chain base fee
const setMinimumBaseFeeTransactionHash =
await orbitChainPublicClient.sendRawTransaction({
serializedTransaction: await deployer.signTransaction(
setMinimumBaseFeeTransactionRequest
),
})
await orbitChainPublicClient.waitForTransactionReceipt({
hash: setMinimumBaseFeeTransactionHash,
})
// Get the updated minimum basefee on orbit chain from arbGasInfo precompile on child chain
const minOrbitChainBaseFeeRead =
await orbitChainPublicClient.arbGasInfoReadContract({
functionName: 'getMinimumGasPrice',
})
// Check if minimum basefee param is set correctly on orbit chain
if (Number(minOrbitChainBaseFeeRead) === minOrbitChainBaseFee) {
console.log('Minimum L3 base fee is set')
} else {
throw new Error('Failed to set Minimum L3 base fee')
}
// Set the network fee account
const setNetworkFeeAccountTransactionRequest =
await orbitChainPublicClient.arbOwnerPrepareTransactionRequest({
functionName: 'setNetworkFeeAccount',
args: [networkFeeReceiver],
upgradeExecutor: false,
account: deployer.address,
})
// submit tx to update infra fee receiver
const setNetworkFeeAccountTransactionHash =
await orbitChainPublicClient.sendRawTransaction({
serializedTransaction: await deployer.signTransaction(
setNetworkFeeAccountTransactionRequest
),
})
await orbitChainPublicClient.waitForTransactionReceipt({
hash: setNetworkFeeAccountTransactionHash,
})
// check if network fee account is updated correctly
const networkFeeRecieverAccount =
await orbitChainPublicClient.arbOwnerReadContract({
functionName: 'getNetworkFeeAccount',
})
if (networkFeeRecieverAccount === networkFeeReceiver) {
console.log('network fee receiver is set')
} else {
throw new Error(
'network fee receiver Setting network fee receiver transaction failed'
)
}
// Set the infra fee account
const setInfraFeeAccountTransactionRequest =
await orbitChainPublicClient.arbOwnerPrepareTransactionRequest({
functionName: 'setInfraFeeAccount',
args: [infrastructureFeeCollector],
upgradeExecutor: false,
account: deployer.address,
})
// submit tx to update infra fee receiver
const setInfraFeeAccountTransactionHash =
await orbitChainPublicClient.sendRawTransaction({
serializedTransaction: await deployer.signTransaction(
setInfraFeeAccountTransactionRequest
),
})
await orbitChainPublicClient.waitForTransactionReceipt({
hash: setInfraFeeAccountTransactionHash,
})
const infraFeeReceiver = await orbitChainPublicClient.arbOwnerReadContract({
functionName: 'getInfraFeeAccount',
})
// check if infra fee account is updated correctly
if (infraFeeReceiver === infrastructureFeeCollector) {
console.log('Infra Fee Collector changed successfully')
} else {
throw new Error('Infra Fee Collector Setting transaction failed')
}
// Setting L1 basefee estimate on L3
console.log('Getting L1 base fee estimate')
const l1BaseFeeEstimate = await orbitChainPublicClient.arbGasInfoReadContract(
{
functionName: 'getL1BaseFeeEstimate',
}
)
console.log(`L1 Base Fee estimate on L2 is ${Number(l1BaseFeeEstimate)}`)
const l2Basefee = await l2Provider.getGasPrice()
const totalGasPrice = l2Basefee.add(l1BaseFeeEstimate)
console.log(`Setting L1 base fee estimate on L3 to ${totalGasPrice}`)
const setL1PricePerUnitTransactionRequest =
await orbitChainPublicClient.arbOwnerPrepareTransactionRequest({
functionName: 'setL1PricePerUnit',
args: [BigInt(totalGasPrice.toString())],
upgradeExecutor: false,
account: deployer.address,
})
// setting setL1PricePerUnit
const setL1PricePerUnitTransactionHash =
await orbitChainPublicClient.sendRawTransaction({
serializedTransaction: await deployer.signTransaction(
setL1PricePerUnitTransactionRequest
),
})
await orbitChainPublicClient.waitForTransactionReceipt({
hash: setL1PricePerUnitTransactionHash,
})
}