Skip to content

Commit

Permalink
add ONFT721Adapter Example (#1158)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Goulding <[email protected]>
  • Loading branch information
ryandgoulding authored Jan 9, 2025
1 parent 30c4bae commit 0995096
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 0 deletions.
10 changes: 10 additions & 0 deletions examples/onft721/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@

<p align="center">Template project for getting started with LayerZero's <code>ONFT721</code> contract development.</p>

### ONFT721Adapter additional setup:

- In your `hardhat.config.ts` file, add the following configuration to the network you want to deploy the ONFT721Adapter to:
```typescript
// Replace `0x0` with the address of the ERC721 token you want to adapt to the ONFT721 functionality.
onft721Adapter: {
tokenAddress: '0x0',
}
```

## 1) Developing Contracts

#### Installing dependencies
Expand Down
12 changes: 12 additions & 0 deletions examples/onft721/contracts/MyONFT721Adapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.22;

import { ONFT721Adapter } from "@layerzerolabs/onft-evm/contracts/onft721/ONFT721Adapter.sol";

contract MyONFT721Adapter is ONFT721Adapter {
constructor(
address _token,
address _lzEndpoint,
address _delegate
) ONFT721Adapter(_token, _lzEndpoint, _delegate) {}
}
7 changes: 7 additions & 0 deletions examples/onft721/deploy/MyONFT721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ const deploy: DeployFunction = async (hre) => {
// }
const endpointV2Deployment = await hre.deployments.get('EndpointV2')

// If the onft721Adapter configuration is defined on a network that is deploying an ONFT721,
// the deployment will log a warning and skip the deployment
if (hre.network.config.onft721Adapter != null) {
console.warn(`onft721Adapter configuration found on OFT deployment, skipping ONFT721 deployment`)
return
}

const { address } = await deploy(contractName, {
from: deployer,
args: [
Expand Down
59 changes: 59 additions & 0 deletions examples/onft721/deploy/MyONFT721Adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import assert from 'assert'

import { type DeployFunction } from 'hardhat-deploy/types'

const contractName = 'MyONFT721Adapter'

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')

// The token address must be defined in hardhat.config.ts
// If the token address is not defined, the deployment will log a warning and skip the deployment
if (hre.network.config.onft721Adapter == null) {
console.warn(`onft721Adapter not configured on network config, skipping ONFT721 deployment`)
return
}

const { address } = await deploy(contractName, {
from: deployer,
args: [
hre.network.config.onft721Adapter.tokenAddress, // existing ERC721 address
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
2 changes: 2 additions & 0 deletions examples/onft721/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { HardhatUserConfig, HttpNetworkAccountsUserConfig } from 'hardhat/types'

import { EndpointId } from '@layerzerolabs/lz-definitions'

import './type-extensions'

// Set your preferred authentication method
//
// If you prefer using a mnemonic, set a MNEMONIC environment variable
Expand Down
23 changes: 23 additions & 0 deletions examples/onft721/type-extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'hardhat/types/config'

interface Onft721AdapterConfig {
tokenAddress: string
}

declare module 'hardhat/types/config' {
interface HardhatNetworkUserConfig {
onft721Adapter?: never
}

interface HardhatNetworkConfig {
onft721Adapter?: never
}

interface HttpNetworkUserConfig {
onft721Adapter?: Onft721AdapterConfig
}

interface HttpNetworkConfig {
onft721Adapter?: Onft721AdapterConfig
}
}

0 comments on commit 0995096

Please sign in to comment.