forked from unlock-protocol/unlock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
010-arbitrum-l1-l2-messaging.js
263 lines (246 loc) · 7.31 KB
/
010-arbitrum-l1-l2-messaging.js
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
const ethers = require('ethers')
const {
L1ToL2MessageGasEstimator,
} = require('@arbitrum/sdk/dist/lib/message/L1ToL2MessageGasEstimator')
const { arbLog } = require('arb-shared-dependencies')
const {
EthBridger,
getL2Network,
addDefaultLocalNetwork,
} = require('@arbitrum/sdk')
const { getBaseFee } = require('@arbitrum/sdk/dist/lib/utils/lib')
const ERC20_ABI = [
{
inputs: [
{
internalType: 'address',
name: 'account',
type: 'address',
},
],
name: 'balanceOf',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: 'to',
type: 'address',
},
{
internalType: 'uint256',
name: 'amount',
type: 'uint256',
},
],
name: 'transfer',
outputs: [
{
internalType: 'bool',
name: '',
type: 'bool',
},
],
stateMutability: 'nonpayable',
type: 'function',
},
]
const INBOX_ABI = [
{
inputs: [
{
internalType: 'address',
name: 'to',
type: 'address',
},
{
internalType: 'uint256',
name: 'l2CallValue',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'maxSubmissionCost',
type: 'uint256',
},
{
internalType: 'address',
name: 'excessFeeRefundAddress',
type: 'address',
},
{
internalType: 'address',
name: 'callValueRefundAddress',
type: 'address',
},
{
internalType: 'uint256',
name: 'gasLimit',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'maxFeePerGas',
type: 'uint256',
},
{
internalType: 'bytes',
name: 'data',
type: 'bytes',
},
],
name: 'createRetryableTicket',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'payable',
type: 'function',
},
]
/**
* Set up: instantiate L1 / L2 wallets connected to providers
*/
const walletPrivateKey = process.env.DEVNET_PRIVKEY
const l1Provider = new ethers.JsonRpcProvider(process.env.L1RPC)
const l2Provider = new ethers.JsonRpcProvider(process.env.L2RPC)
// const l1Wallet = new ethers.Wallet(walletPrivateKey, l1Provider)
const l2Wallet = new ethers.Wallet(walletPrivateKey, l2Provider)
module.exports = async () => {
await arbLog('Cross-chain Proposer')
addDefaultLocalNetwork()
const l2Network = await getL2Network(l2Provider)
const ethBridger = new EthBridger(l2Network)
const inboxAddress = ethBridger.l2Network.ethBridge.inbox
const ARBTokenAddressOnL2 = '0x912CE59144191C1204E64559FE8253a0e49E6548' // ARB TOKEN ADDRESS ON ARBITRUM ONE
const grantsContractAddress = '0x00D5E0d31d37cc13C645D86410aB4cB7Cb428ccA'
const L2Alias = '0x28ffDfB0A6e6E06E95B3A1f928Dc4024240bD87c' // Timelock Alias Address on L2
const L1TimelockContract = '0x17EEDFb0a6E6e06E95B3A1F928dc4024240BC76B' // Timelock Address mainnet
const L2TokenContract = new ethers.Contract(
ARBTokenAddressOnL2,
ERC20_ABI,
l2Wallet
).connect(l2Wallet)
const balanceOf = await L2TokenContract.balanceOf(L2Alias)
console.log('ARB BALANCE::', ethers.formatEther(await balanceOf))
const tokenAmount = ethers.parseEther('1')
// Create an instance of the Interface from the ABIs
const iface_erc20 = new ethers.Interface(ERC20_ABI)
const iface_inbox = new ethers.Interface(INBOX_ABI)
// Encode the ERC20 Token transfer calldata
const transfer_calldata = iface_erc20.encodeFunctionData('transfer', [
grantsContractAddress,
tokenAmount,
])
/**
* Now we can query the required gas params using the estimateAll method in Arbitrum SDK
*/
const l1ToL2MessageGasEstimate = new L1ToL2MessageGasEstimator(l2Provider)
/**
* The estimateAll method gives us the following values for sending an L1->L2 message
* (1) maxSubmissionCost: The maximum cost to be paid for submitting the transaction
* (2) gasLimit: The L2 gas limit
* (3) deposit: The total amount to deposit on L1 to cover L2 gas and L2 call value
*/
const L1ToL2MessageGasParams = await l1ToL2MessageGasEstimate.estimateAll(
{
from: L1TimelockContract,
to: ARBTokenAddressOnL2,
l2CallValue: 0,
excessFeeRefundAddress: l2Wallet.address,
callValueRefundAddress: l2Wallet.address,
data: transfer_calldata,
},
await getBaseFee(l1Provider),
l1Provider
)
console.log(':::::::::L1ToL2MessageGasParams::::::::::')
console.log(
'GasParams::::gasLimit',
L1ToL2MessageGasParams.gasLimit.toNumber()
)
console.log(
'GasParams::::maxSubmissionCost',
L1ToL2MessageGasParams.maxSubmissionCost.toNumber()
)
console.log(
'GasParams::::maxGas',
L1ToL2MessageGasParams.maxFeePerGas.toNumber()
)
console.log('GasParams::::deposit', L1ToL2MessageGasParams.deposit.toNumber())
console.log(
`Current retryable base submission price is: ${L1ToL2MessageGasParams.maxSubmissionCost.toString()}`
)
const gasPriceBid = await l2Provider.getGasPrice()
console.log(`L2 gas price: ${gasPriceBid.toString()}`)
const inbox_calldata = iface_inbox.encodeFunctionData(
'createRetryableTicket',
[
ARBTokenAddressOnL2,
0,
L1ToL2MessageGasParams.maxSubmissionCost,
l2Wallet.address,
l2Wallet.address,
L1ToL2MessageGasParams.gasLimit,
gasPriceBid,
transfer_calldata,
]
)
const proposalName = `# Test Transaction before 7k ARB Transfer To Fund Unlock Protocol’s Ecosystem via Grants Stack This proposal requests to use 1 ARB from the tokens given to Unlock Protocol DAO by ArbitrumDAO to run a test transaction to de-risk the transfer of 7k ARB tokens to fund the retroQF round on Grants Stack.`
console.log(proposalName)
// Proposal ARGS i.e Call Governor.propose() directly with these values
// targets: Inbox contract
// values: depost * 10
// calldatas: inbox_calldata
// description
const targets = [inboxAddress]
const values = [L1ToL2MessageGasParams.deposit.toNumber() * 10] // I Multiply by 10 to add extra in case gas changes
const calldatas = [inbox_calldata]
console.log(
'______________________________________________________________________\n'
)
console.log(
'PROPOSAL ARGS - Can Call Propose function on Governor with the following::'
)
console.log(
'______________________________________________________________________\n'
)
console.log('TARGETS:: ', targets)
console.log('VALUES:: ', values)
console.log('CALLDATAS:: ', calldatas)
console.log('DESCRIPTION:: ', proposalName)
const calls = [
{
contractNameOrAbi: INBOX_ABI,
contractAddress: inboxAddress,
functionName: 'createRetryableTicket',
functionArgs: [
ARBTokenAddressOnL2,
0,
L1ToL2MessageGasParams.maxSubmissionCost,
l2Wallet.address,
l2Wallet.address,
L1ToL2MessageGasParams.gasLimit,
gasPriceBid,
transfer_calldata,
],
value: L1ToL2MessageGasParams.deposit.toNumber() * 10, // I Multiply by 10 to add extra in case gas changes due to proposal delay
},
]
return {
proposalName,
calls,
}
}