-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy path11_layer_zero.ts
executable file
·79 lines (71 loc) · 3.18 KB
/
11_layer_zero.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
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
declare var global: any;
import path from 'path';
import fs from 'fs';
import { BytesLike, ContractFactory, Contract, BigNumber } from 'ethers';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { DeployFunction } from '@holographxyz/hardhat-deploy-holographed/types';
import { LeanHardhatRuntimeEnvironment, hreSplit, zeroAddress, txParams, getDeployer } from '../scripts/utils/helpers';
import { MultisigAwareTx } from '../scripts/utils/multisig-aware-tx';
import { NetworkType, networks } from '@holographxyz/networks';
const func: DeployFunction = async function (hre1: HardhatRuntimeEnvironment) {
console.log(`Starting deploy script: ${path.basename(__filename)} 👇`);
let { hre, hre2 } = await hreSplit(hre1, global.__companionNetwork);
const deployer = await getDeployer(hre);
const deployerAddress = await deployer.signer.getAddress();
const salt = hre.deploymentSalt;
const currentNetworkType: NetworkType = networks[hre.networkName].type;
let lzEndpoint = networks[hre.networkName].lzEndpoint?.toLowerCase();
if (lzEndpoint) {
if (currentNetworkType === NetworkType.local && lzEndpoint === zeroAddress) {
lzEndpoint = (await hre.getNamedAccounts()).lzEndpoint;
const mockLZEndpoint = await hre.deployments.deploy('MockLZEndpoint', {
...(await txParams({
hre,
from: lzEndpoint,
to: '0x0000000000000000000000000000000000000000',
gasLimit: await hre.ethers.provider.estimateGas(
(await hre.ethers.getContractFactory('MockLZEndpoint')).getDeployTransaction()
),
})),
args: [],
log: true,
waitConfirmations: 1,
} as any);
lzEndpoint = mockLZEndpoint.address.toLowerCase();
console.log(`Deployed MockLZEndpoint to: ${mockLZEndpoint.address}`);
}
const layerZeroModuleProxy = await hre.ethers.getContract('LayerZeroModuleProxy', deployerAddress);
const layerZeroModule = (await hre.ethers.getContractAt(
'LayerZeroModule',
layerZeroModuleProxy.address,
deployerAddress
)) as Contract;
if ((await layerZeroModule.getLZEndpoint()).toLowerCase() !== lzEndpoint) {
const lzTx = await MultisigAwareTx(
hre,
'LayerZeroModule',
layerZeroModule,
await layerZeroModule.populateTransaction.setLZEndpoint(lzEndpoint, {
...(await txParams({
hre,
from: deployerAddress,
to: layerZeroModule,
data: layerZeroModule.populateTransaction.setLZEndpoint(lzEndpoint),
})),
})
);
console.log('Transaction hash:', lzTx.hash);
await lzTx.wait();
console.log(`Registered lzEndpoint to: ${await layerZeroModule.getLZEndpoint()}`);
} else {
console.log(`lzEndpoint is already registered to: ${await layerZeroModule.getLZEndpoint()}`);
}
} else {
console.log(`Skipping for ${hre1.network.name} network because lzEndpoint is not set`);
}
console.log(`Exiting script: ${__filename} ✅\n`);
};
export default func;
func.tags = ['MockLZEndpoint', 'LayerZero'];
func.dependencies = ['HolographGenesis', 'DeploySources', 'LayerZeroModule'];