Skip to content

Commit

Permalink
fix OFT and OFTV2 deployment code and corresponding README.md instruc…
Browse files Browse the repository at this point in the history
…tions

The instructions for deploying OFTV2 in README.md did not work, as the deployment scripts refer
to ExampleOFT and ExampleOFTV2 contracts, which don't exist.  I changed these to OFTMock and
OFTV2Mock respectively.  Additionally, instructions failed to mention that the deployer *must*
set a minDstGasLimit in this version of code.  I added this instruction in and was able to send
tokens successfully.

Lastly, even though there is not an example for OFT, we failed to include a task to mintTokens(...).
This PR includes a small task to mint tokens so the OFT example can be tested.

Signed-off-by: Ryan Goulding <[email protected]>
  • Loading branch information
ryandgoulding committed Nov 2, 2023
1 parent b68756e commit 80b89b2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ If the decimal point is 18, then uint64 can only represent approximately 18 toke

## OFTV2Mock.sol - an omnichain ERC20

> :warning: **You must perform `setTrustedRemote()` (step 2). This is a mock deployment that auto mints tokens to `msg.sender`**
:warning: **You must perform `setTrustedRemote()` (step 2). This is a mock deployment that auto mints tokens to `msg.sender`**

1. Deploy two contracts:

```shell
npx hardhat --network goerli deploy --tags OFTV2Mock
npx hardhat --network fuji deploy --tags OFTV2Mock
npx hardhat --network goerli deploy --tags ExampleOFTV2
npx hardhat --network fuji deploy --tags ExampleOFTV2
```

2. Set the "trusted remotes" (ie: your contracts) so each of them can receive messages from one another, and `only` one another.
Expand All @@ -56,7 +56,16 @@ npx hardhat --network goerli setTrustedRemote --target-network fuji --contract O
npx hardhat --network fuji setTrustedRemote --target-network goerli --contract OFTV2Mock
```

3. Send tokens from goerli to fuji
3. Set the "minDstGas" required on the destination chain.

```shell
npx hardhat --network goerli setMinDstGas --packet-type 0 --target-network fuji --contract OFTV2Mock --min-gas 100000
npx hardhat --network fuji setMinDstGas --packet-type 0 --target-network goerli --contract OFTV2Mock --min-gas 100000
```

:warning: Although `100000` is used for `min-gas` in this example, you should set this value based on careful gas consumption analysis.

4. Send tokens from goerli to fuji

```shell
npx hardhat --network goerli oftv2Send --target-network fuji --qty 42 --contract OFTV2Mock
Expand All @@ -71,13 +80,13 @@ Check the `ONFT_ARGS` constant defined in ONFT721 deploy script for the specific

## ONFT721Mock.sol

> :warning: **You must perform the `setTrustedRemote()` (step 2).**
:warning: **You must perform the `setTrustedRemote()` (step 2).**

1. Deploy two contracts:

```shell
npx hardhat --network bsc-testnet deploy --tags ONFT721Mock
npx hardhat --network fuji deploy --tags ONFT721Mock
npx hardhat --network bsc-testnet deploy --tags ONFT721
npx hardhat --network fuji deploy --tags ONFT721
```

2. Set the "trusted remotes", so each contract can send & receive messages from one another, and **only** one another.
Expand Down
2 changes: 1 addition & 1 deletion deploy/ExampleOFT.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = async function ({ deployments, getNamedAccounts }) {
const endpointAddr = LZ_ENDPOINTS[hre.network.name]
console.log(`[${hre.network.name}] LayerZero Endpoint address: ${endpointAddr}`)

await deploy("ExampleOFT", {
await deploy("OFTMock", {
from: deployer,
args: [endpointAddr],
log: true,
Expand Down
2 changes: 1 addition & 1 deletion deploy/ExampleOFTV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = async function ({ deployments, getNamedAccounts }) {
const globalSupply = ethers.utils.parseUnits("1000000", 18)
const sharedDecimals = 6

await deploy("ExampleOFTV2", {
await deploy("OFTV2Mock", {
from: deployer,
args: [lzEndpointAddress, globalSupply, sharedDecimals],
log: true,
Expand Down
5 changes: 5 additions & 0 deletions tasks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ task(
.addOptionalParam("remoteContract", "Name of remote contract if the names are different")
.addOptionalParam("contract", "If both contracts are the same name")

//
task("oftMint", "mint tokens", require("./oftMint"))
.addParam("toAddress", "address to mint to")
.addParam("qty", "qty of tokens to mint")

//
task("oftSend", "send tokens to another chain", require("./oftSend"))
.addParam("qty", "qty of tokens to send")
Expand Down
12 changes: 12 additions & 0 deletions tasks/oftMint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = async function (taskArgs, hre) {
let owner = (await ethers.getSigners())[0]
let toAddress = owner.address
let qty = ethers.utils.parseEther(taskArgs.qty)

const oftMock = await ethers.getContract("OFTMock")

let tx = await (
await oftMock.mintTokens(toAddress, qty)
).wait()
console.log(`✅ OFT minted [${hre.network.name}] to: [${toAddress}] qty: [${qty}]`)
}
6 changes: 5 additions & 1 deletion tasks/oftv2Send.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ module.exports = async function (taskArgs, hre) {
remoteChainId, // remote LayerZero chainId
toAddressBytes, // 'to' address to send tokens
qty, // amount of tokens to send (in wei)
[owner.address, ethers.constants.AddressZero, "0x"],
{
refundAddress: owner.address,
zroPaymentAddress: ethers.constants.AddressZero,
adapterParams,
},
{ value: fees[0] }
)
).wait()
Expand Down

0 comments on commit 80b89b2

Please sign in to comment.