User applications on LayerZero are required to whitelist remote contracts as trusted message senders, the trustedRemotes.
In ULN (Ultra-light Node) V2, the trusted remote has been changed to the full path, which concatinates the remote and the local contract address using abi.encodePacked().
For example,
- 0x1234... on chain ID 101 (20 bytes / 42 characters in hex (e.g. 0x1234567890123456789012345678901234567890))
- 0xabcd... on chain ID 102 (20 bytes)
On chain 101 contract 0x1234..., setTrustedRemote(102, 0xabcd...1234...) (40 bytes)
On chain 102 contract 0xabcd..., setTrustedRemote(101, 0x1234...abcd...) (40 bytes)
Modify your dApp to ULNv2 by calling setTrustedRemote in one of two ways:
- Script
- Manual Update
This script will update the set trusted remotes to point to the new virtual chainId which is defined in constants/virtualChainIds.json
.
Instead of setting it to only the remote address
it will set it to new remote address + local address
standard, as mentioned above.
Very carefully fill out constants/setTrustedRemoteConfig.json
with the name of your setTrustedRemote methodName
, trustedRemoteLookup mapName
(in case they are different), and the address
of your contracts on the respective chains.
- Run yarn install
- Add a .env file (to the root project directory) with the MNEMONIC="" that owns the contracts.
- Add your contract addresses to
constants/setTrustedRemoteConfig.json
yarn install
npx hardhat setTrustedRemote --networks ethereum,bsc,avalanche,polygon,arbitrum,optimism,fantom
Note: Make sure the script finishes with 100% success and no failures. You may need to run this script multiple times.
-
Each contract built on LayerZero has a function,
setTrustedRemote(uint16, bytes)
(or something similar), which specifies its trusted contracts. You will have already set your trusted remotes once. You will need to do this again with the new format for addresses. -
setTrustedRemote(uint16, bytes)
takes two parameters:
- uint16 chainId
let remoteChainId = BigNumber.from(remoteId);
- A bytes path, which concatinates the remote and the local contract address using abi.encodePacked().
let trustedRemote = hre.ethers.utils.solidityPack(['address','address'],[REMOTE_ADDRESS, LOCAL_ADDRESS])
- Call setTrustedRemote() for the NEW chainIds your contracts need for LayerZero messaging.
let tx = await (await contract.connect(wallet).setTrustedRemote(remoteChainId, trustedRemote, {gasPrice: finalGasPrice})).wait()