Contracts to perform migration of any ERC20 token to other chain using Layer Zero network.
Users will send their ERC20 tokens to Burner
contract on source chain, and through LayerZero,
Minter
contract on destination chain will be called thus calling mint()
of your new ERC20.
-
Create
.env
file based on.env.example
file. -
Install dependencies, compile contracts, and run tests:
yarn && npx hardhat test
-
On the source chain (where your ERC20) is located, deploy
Burner
contract:npx hardhat --network <burner-network> deploy --tags Burner
-
On the destination chain, deploy your new ERC20 token implementing
IMintable
. -
On the destination chain, deploy
Minter
contract (make sureMinter
can callmint()
of your new ERC20):npx hardhat --network <minter-network> deploy --tags Minter
-
Run
setTrsutedRemotes
task:-
npx hardhat --network <burner-network> setTrustedRemote --target-network <minter-netowrk> --local-contract Burner --remote-contract Minter
-
npx hardhat --network <minter-network> setTrustedRemote --target-network <burner-netowrk> --local-contract Minter --remote-contract Burner
-
-
(Optional) verify with:
npx hardhat --network <network> etherscan-verify --api-key <api-key>
-
Unpause
Burner
contract to enable migrating:npx hardhat --network <burner-network> pause --unpause
-
Approve amount of ERC20 to migrate to
Burner
contract. -
Call
estimateFee()
ofBurner
contract. -
Call
migrate()
ofBurner
contract, withfee
copied fromestimateFee()
output.Also
msg.value
in native tokens should matchfee
. -
Copy tx hash, and check your migration on LayerZero Scan
-
If message Status is
Delivered
, but Destination transaction error isStored payload
, refer to troubleshooting down below, otherwise migration should be succesfull.
You can also listen for MigrationStarted
and MigrationFinished
events.
No network in hardhat
Update hardhat.confid.ts
with new networks if needed.
PayloadStored error in LayerZero Scan
It should only happen if mint()
function of your new ERC20 reverts, eg. by being Paused.
It will block all further migrations until you unblock mint()
function and retry message.
You can check <amount>
and <user-address>
in MigrationStarted
event of Burner
contract,
with nonce
same as one with PayloadStored
in LayerZero Scan Example.
`npx hardhat --network <minter-network> retryPayload --amount <amount> --user <user-address> --source-chain <burner-network>`