Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🗞️ onft721 tasks #672

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/swift-walls-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@layerzerolabs/onft721-example": patch
---

Add mint/send commands for ONFT721
4 changes: 2 additions & 2 deletions examples/onft721/contracts/mocks/MyONFT721Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract MyONFT721Mock is MyONFT721 {
address _delegate
) MyONFT721(_name, _symbol, _lzEndpoint, _delegate) {}

function mint(address _to, uint256 _amount) public {
_mint(_to, _amount);
function mint(address _to, uint256 _id) public {
_mint(_to, _id);
}
}
1 change: 1 addition & 0 deletions examples/onft721/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'hardhat-deploy'
import 'hardhat-contract-sizer'
import '@nomiclabs/hardhat-ethers'
import '@layerzerolabs/toolbox-hardhat'
import './tasks'
import { HardhatUserConfig, HttpNetworkAccountsUserConfig } from 'hardhat/types'

import { EndpointId } from '@layerzerolabs/lz-definitions'
Expand Down
1 change: 1 addition & 0 deletions examples/onft721/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"devDependencies": {
"@babel/core": "^7.23.9",
"@layerzerolabs/devtools": "~0.3.28",
"@layerzerolabs/eslint-config-next": "~2.3.39",
"@layerzerolabs/lz-definitions": "^2.3.39",
"@layerzerolabs/lz-evm-messagelib-v2": "^2.3.39",
Expand Down
2 changes: 2 additions & 0 deletions examples/onft721/tasks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './mint'
import './send'
28 changes: 28 additions & 0 deletions examples/onft721/tasks/mint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { task } from 'hardhat/config'
import { ActionType, HardhatRuntimeEnvironment } from 'hardhat/types'

const ABI = ['function mint(address _to, uint256 _tokenId) public']

const createMyONFT721MockContract = async (hre: HardhatRuntimeEnvironment, onft721Address: string) => {
return await hre.ethers.getContractAt(ABI, onft721Address)
}

interface TaskArgs {
onft721Address: string
tokenId: number
}

const action: ActionType<TaskArgs> = async (taskArgs: TaskArgs, hre) => {
const signer = (await hre.getNamedAccounts()).deployer
const user = await hre.ethers.getSigner(signer)

const myONFT721Mock = await createMyONFT721MockContract(hre, taskArgs.onft721Address)

const tx = await myONFT721Mock.mint(user.address, taskArgs.tokenId)
const txReceipt = await tx.wait()
console.log(`Transaction hash: ${txReceipt.transactionHash}`)
}

task('mint', 'Mint ONFT721 Mock', action)
.addParam('onft721Address', 'ONFT721 contract address')
.addParam('tokenId', 'Token ID')
56 changes: 56 additions & 0 deletions examples/onft721/tasks/send.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { task } from 'hardhat/config'
import { ActionType, HardhatRuntimeEnvironment } from 'hardhat/types'

import { makeBytes32 } from '@layerzerolabs/devtools'

const DEFAULT_EXTRA_OPTIONS = '0x'
const DEFAULT_COMPOSE_MSG = '0x'
const DEFAULT_OFT_CMD = '0x'

const ONFT721_ABI = [
'function send((uint32 dstEid,bytes32 to,uint256 tokenId,bytes extraOptions,bytes composeMsg,bytes oftCmd),(uint256 nativeFee,uint256 lzFee),address refundAddress) external payable returns (MessagingReceipt msgReceipt)',
'function quoteSend((uint32 dstEid,bytes32 to,uint256 tokenId,bytes extraOptions,bytes composeMsg,bytes oftCmd),bool payInLzToken) external view returns ((uint256, uint256))',
]

const getONFT721Contract = async (hre: HardhatRuntimeEnvironment, onft721Address: string, signer: SignerWithAddress) =>
hre.ethers.getContractAt(ONFT721_ABI, onft721Address, signer)

const createSendParam = (user: SignerWithAddress, taskArgs: TaskArgs) => {
return {
dstEid: taskArgs.dstEid,
to: makeBytes32(user.address),
tokenId: taskArgs.tokenId,
extraOptions: DEFAULT_EXTRA_OPTIONS,
composeMsg: DEFAULT_COMPOSE_MSG,
oftCmd: DEFAULT_OFT_CMD,
}
}

interface TaskArgs {
onft721Address: string
dstEid: number
to: string
tokenId: number
}

const action: ActionType<TaskArgs> = async (taskArgs: TaskArgs, hre) => {
const signer = (await hre.getNamedAccounts()).deployer
const user = await hre.ethers.getSigner(signer)

const sendParam = createSendParam(user, taskArgs)
const onft721 = await getONFT721Contract(hre, taskArgs.onft721Address, user)
const messagingFee = await onft721.quoteSend(sendParam, false)

const tx = await onft721.send(sendParam, messagingFee, user.address, {
value: messagingFee[0],
gasLimit: 1_000_000,
})
const txReceipt = await tx.wait()
console.log(`Transaction hash: ${txReceipt.transactionHash}`)
}

task('send', 'Send ONFT721 from one chain to another', action)
.addParam('onft721Address', 'ONFT721 contract address')
.addParam('dstEid', 'Destination LayerZero EndpointV2 ID')
.addParam('tokenId', 'Token ID')
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading