-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ryan Goulding <[email protected]>
- Loading branch information
1 parent
c641d31
commit 6ef54d1
Showing
42 changed files
with
2,699 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- | ||
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ | ||
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' | ||
# | ||
# Example environment configuration | ||
# | ||
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- | ||
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ | ||
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' | ||
|
||
# By default, the examples support both mnemonic-based and private key-based authentication | ||
# | ||
# You don't need to set both of these values, just pick the one that you prefer and set that one | ||
MNEMONIC= | ||
PRIVATE_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
artifacts | ||
cache | ||
dist | ||
node_modules | ||
out | ||
*.log | ||
*.sol | ||
*.yaml | ||
*.lock | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require('@rushstack/eslint-patch/modern-module-resolution'); | ||
|
||
module.exports = { | ||
extends: ['@layerzerolabs/eslint-config-next/recommended'], | ||
rules: { | ||
// @layerzerolabs/eslint-config-next defines rules for turborepo-based projects | ||
// that are not relevant for this particular project | ||
'turbo/no-undeclared-env-vars': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
|
||
|
||
# LayerZero specific files | ||
.layerzero | ||
|
||
# foundry test compilation files | ||
out | ||
|
||
# pnpm | ||
pnpm-error.log | ||
|
||
# Editor and OS files | ||
.DS_Store | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v18.18.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
artifacts/ | ||
cache/ | ||
dist/ | ||
node_modules/ | ||
out/ | ||
*.log | ||
*ignore | ||
*.yaml | ||
*.lock | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
...require('@layerzerolabs/prettier-config-next'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<p align="center"> | ||
<a href="https://layerzero.network"> | ||
<img alt="LayerZero" style="width: 400px" src="https://docs.layerzero.network/img/LayerZero_Logo_White.svg"/> | ||
</a> | ||
</p> | ||
|
||
<p align="center"> | ||
<a href="https://layerzero.network" style="color: #a77dff">Homepage</a> | <a href="https://docs.layerzero.network/" style="color: #a77dff">Docs</a> | <a href="https://layerzero.network/developers" style="color: #a77dff">Developers</a> | ||
</p> | ||
|
||
<h1 align="center">ONFT721 Example</h1> | ||
|
||
<p align="center"> | ||
<a href="https://docs.layerzero.network/v2/developers/evm/onft721/quickstart" style="color: #a77dff">Quickstart</a> | <a href="https://docs.layerzero.network/contracts/oapp-configuration" style="color: #a77dff">Configuration</a> | <a href="https://docs.layerzero.network/contracts/options" style="color: #a77dff">Message Execution Options</a> | <a href="https://docs.layerzero.network/contracts/endpoint-addresses" style="color: #a77dff">Endpoint Addresses</a> | ||
</p> | ||
|
||
<p align="center">Template project for getting started with LayerZero's <code>ONFT721</code> contract development.</p> | ||
|
||
:warning: ** This code is currently under audit and should not yet be used in production. ** | ||
|
||
## 1) Developing Contracts | ||
|
||
#### Installing dependencies | ||
|
||
We recommend using `pnpm` as a package manager (but you can of course use a package manager of your choice): | ||
|
||
```bash | ||
pnpm install | ||
``` | ||
|
||
#### Compiling your contracts | ||
|
||
This project supports both `hardhat` and `forge` compilation. By default, the `compile` command will execute both: | ||
|
||
```bash | ||
pnpm compile | ||
``` | ||
|
||
If you prefer one over the other, you can use the tooling-specific commands: | ||
|
||
```bash | ||
pnpm compile:forge | ||
pnpm compile:hardhat | ||
``` | ||
|
||
Or adjust the `package.json` to for example remove `forge` build: | ||
|
||
```diff | ||
- "compile": "$npm_execpath run compile:forge && $npm_execpath run compile:hardhat", | ||
- "compile:forge": "forge build", | ||
- "compile:hardhat": "hardhat compile", | ||
+ "compile": "hardhat compile" | ||
``` | ||
|
||
#### Running tests | ||
|
||
Similarly to the contract compilation, we support both `hardhat` and `forge` tests. By default, the `test` command will execute both: | ||
|
||
```bash | ||
pnpm test | ||
``` | ||
|
||
If you prefer one over the other, you can use the tooling-specific commands: | ||
|
||
```bash | ||
pnpm test:forge | ||
pnpm test:hardhat | ||
``` | ||
|
||
Or adjust the `package.json` to for example remove `hardhat` tests: | ||
|
||
```diff | ||
- "test": "$npm_execpath test:forge && $npm_execpath test:hardhat", | ||
- "test:forge": "forge test", | ||
- "test:hardhat": "$npm_execpath hardhat test" | ||
+ "test": "forge test" | ||
``` | ||
|
||
## 2) Deploying Contracts | ||
|
||
Set up deployer wallet/account: | ||
|
||
- Rename `.env.example` -> `.env` | ||
- Choose your preferred means of setting up your deployer wallet/account: | ||
|
||
``` | ||
MNEMONIC="test test test test test test test test test test test junk" | ||
or... | ||
PRIVATE_KEY="0xabc...def" | ||
``` | ||
|
||
- Fund this address with the corresponding chain's native tokens you want to deploy to. | ||
|
||
To deploy your contracts to your desired blockchains, run the following command in your project's folder: | ||
|
||
```bash | ||
npx hardhat lz:deploy | ||
``` | ||
|
||
More information about available CLI arguments can be found using the `--help` flag: | ||
|
||
```bash | ||
npx hardhat lz:deploy --help | ||
``` | ||
|
||
By following these steps, you can focus more on creating innovative omnichain solutions and less on the complexities of cross-chain communication. | ||
|
||
<br></br> | ||
|
||
<p align="center"> | ||
Join our community on <a href="https://discord-layerzero.netlify.app/discord" style="color: #a77dff">Discord</a> | Follow us on <a href="https://twitter.com/LayerZero_Labs" style="color: #a77dff">Twitter</a> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.22; | ||
|
||
import { ONFT721 } from "@layerzerolabs/onft-evm/contracts/onft721/ONFT721.sol"; | ||
|
||
contract MyONFT721 is ONFT721 { | ||
constructor( | ||
string memory _name, | ||
string memory _symbol, | ||
address _lzEndpoint, | ||
address _delegate | ||
) ONFT721(_name, _symbol, _lzEndpoint, _delegate) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.22; | ||
|
||
import { MyONFT721 } from "../MyONFT721.sol"; | ||
|
||
// @dev WARNING: This is for testing purposes only | ||
contract MyONFT721Mock is MyONFT721 { | ||
constructor( | ||
string memory _name, | ||
string memory _symbol, | ||
address _lzEndpoint, | ||
address _delegate | ||
) MyONFT721(_name, _symbol, _lzEndpoint, _delegate) {} | ||
|
||
function mint(address _to, uint256 _amount) public { | ||
_mint(_to, _amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import assert from 'assert' | ||
|
||
import { type DeployFunction } from 'hardhat-deploy/types' | ||
|
||
const contractName = 'MyONFT721' | ||
|
||
const deploy: DeployFunction = async (hre) => { | ||
const { getNamedAccounts, deployments } = hre | ||
|
||
const { deploy } = deployments | ||
const { deployer } = await getNamedAccounts() | ||
|
||
assert(deployer, 'Missing named deployer account') | ||
|
||
console.log(`Network: ${hre.network.name}`) | ||
console.log(`Deployer: ${deployer}`) | ||
|
||
// This is an external deployment pulled in from @layerzerolabs/lz-evm-sdk-v2 | ||
// | ||
// @layerzerolabs/toolbox-hardhat takes care of plugging in the external deployments | ||
// from @layerzerolabs packages based on the configuration in your hardhat config | ||
// | ||
// For this to work correctly, your network config must define an eid property | ||
// set to `EndpointId` as defined in @layerzerolabs/lz-definitions | ||
// | ||
// For example: | ||
// | ||
// networks: { | ||
// fuji: { | ||
// ... | ||
// eid: EndpointId.AVALANCHE_V2_TESTNET | ||
// } | ||
// } | ||
const endpointV2Deployment = await hre.deployments.get('EndpointV2') | ||
|
||
const { address } = await deploy(contractName, { | ||
from: deployer, | ||
args: [ | ||
'MyONFT721', // name | ||
'ONFT', // symbol | ||
endpointV2Deployment.address, // LayerZero's EndpointV2 address | ||
deployer, // owner | ||
], | ||
log: true, | ||
skipIfAlreadyDeployed: false, | ||
}) | ||
|
||
console.log(`Deployed contract: ${contractName}, network: ${hre.network.name}, address: ${address}`) | ||
} | ||
|
||
deploy.tags = [contractName] | ||
|
||
export default deploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[profile.default] | ||
solc-version = '0.8.22' | ||
src = 'contracts' | ||
out = 'out' | ||
test = 'test/foundry' | ||
cache_path = 'cache' | ||
libs = [ | ||
# We provide a set of useful contract utilities | ||
# in the lib directory of @layerzerolabs/toolbox-foundry: | ||
# | ||
# - forge-std | ||
# - ds-test | ||
# - solidity-bytes-utils | ||
'node_modules/@layerzerolabs/toolbox-foundry/lib', | ||
'node_modules', | ||
] | ||
|
||
remappings = [ | ||
# Due to a misconfiguration of solidity-bytes-utils, an outdated version | ||
# of forge-std is being dragged in | ||
# | ||
# To remedy this, we'll remap the ds-test and forge-std imports to ou own versions | ||
'ds-test/=node_modules/@layerzerolabs/toolbox-foundry/lib/ds-test', | ||
'forge-std/=node_modules/@layerzerolabs/toolbox-foundry/lib/forge-std', | ||
'@layerzerolabs/=node_modules/@layerzerolabs/', | ||
'@openzeppelin/=node_modules/@openzeppelin/', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Get the environment configuration from .env file | ||
// | ||
// To make use of automatic environment setup: | ||
// - Duplicate .env.example file and name it .env | ||
// - Fill in the environment variables | ||
import 'dotenv/config' | ||
|
||
import 'hardhat-deploy' | ||
import 'hardhat-contract-sizer' | ||
import '@nomiclabs/hardhat-ethers' | ||
import '@layerzerolabs/toolbox-hardhat' | ||
import { HardhatUserConfig, HttpNetworkAccountsUserConfig } from 'hardhat/types' | ||
|
||
import { EndpointId } from '@layerzerolabs/lz-definitions' | ||
|
||
// Set your preferred authentication method | ||
// | ||
// If you prefer using a mnemonic, set a MNEMONIC environment variable | ||
// to a valid mnemonic | ||
const MNEMONIC = process.env.MNEMONIC | ||
|
||
// If you prefer to be authenticated using a private key, set a PRIVATE_KEY environment variable | ||
const PRIVATE_KEY = process.env.PRIVATE_KEY | ||
|
||
const accounts: HttpNetworkAccountsUserConfig | undefined = MNEMONIC | ||
? { mnemonic: MNEMONIC } | ||
: PRIVATE_KEY | ||
? [PRIVATE_KEY] | ||
: undefined | ||
|
||
if (accounts == null) { | ||
console.warn( | ||
'Could not find MNEMONIC or PRIVATE_KEY environment variables. It will not be possible to execute transactions in your example.' | ||
) | ||
} | ||
|
||
const config: HardhatUserConfig = { | ||
solidity: { | ||
compilers: [ | ||
{ | ||
version: '0.8.22', | ||
settings: { | ||
optimizer: { | ||
enabled: true, | ||
runs: 200, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
networks: { | ||
sepolia: { | ||
eid: EndpointId.SEPOLIA_V2_TESTNET, | ||
url: process.env.RPC_URL_SEPOLIA || 'https://rpc.sepolia.org/', | ||
accounts, | ||
}, | ||
fuji: { | ||
eid: EndpointId.AVALANCHE_V2_TESTNET, | ||
url: process.env.RPC_URL_FUJI || 'https://rpc.ankr.com/avalanche_fuji', | ||
accounts, | ||
}, | ||
amoy: { | ||
eid: EndpointId.AMOY_V2_TESTNET, | ||
url: process.env.RPC_URL_AMOY || 'https://polygon-amoy-bor-rpc.publicnode.com', | ||
accounts, | ||
}, | ||
}, | ||
namedAccounts: { | ||
deployer: { | ||
default: 0, // wallet address of index[0], of the mnemonic in .env | ||
}, | ||
}, | ||
} | ||
|
||
export default config |
Oops, something went wrong.