-
Notifications
You must be signed in to change notification settings - Fork 0
/
zksync.ts
50 lines (43 loc) · 1.5 KB
/
zksync.ts
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
import { ethers } from 'ethers'
import { MessengerParams, Bridge } from './bridge'
import { RelicClient } from '../client'
import { getConnectionInfo } from '../utils'
import { Provider, Wallet, utils as zksyncUtils } from 'zksync-web3'
export class ZkSyncBridge extends Bridge {
private zkWallet: Wallet
constructor(client: RelicClient) {
super(client)
const provider = new Provider(getConnectionInfo(client.provider))
// Wallet is needed for some methods, but we don't care about the priv key
this.zkWallet = Wallet.createRandom()
.connect(provider)
.connectToL1(this.client.dataProvider)
}
override async getParams(
blockNum: ethers.BigNumberish,
blockHash: string
): Promise<MessengerParams> {
const contract = this.client.blockHistory.getContract()
const call = await contract.populateTransaction.importTrustedHash(
blockNum,
blockHash
)
const request = {
contractAddress: call.to!,
calldata: call.data!,
caller: zksyncUtils.applyL1ToL2Alias(this.messenger.address),
}
const l2GasLimit = await this.zkWallet.provider.estimateL1ToL2Execute(
request
)
const l2Tx = await this.zkWallet.getRequestExecuteTx(request)
const value = l2Tx.value!
const l2GasPerPubdataByteLimit =
zksyncUtils.REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT
const params = ethers.utils.defaultAbiCoder.encode(
['uint256', 'uint256'],
[l2GasLimit, l2GasPerPubdataByteLimit]
)
return { value, params }
}
}