diff --git a/examples/call/yarn.lock b/examples/call/yarn.lock index 5c7ac502..65dd7967 100644 --- a/examples/call/yarn.lock +++ b/examples/call/yarn.lock @@ -2775,16 +2775,6 @@ "@zetachain/networks" "^10.0.0" ethers "5.6.8" -"@zetachain/protocol-contracts@10.0.0-rc11": - version "10.0.0-rc11" - resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-10.0.0-rc11.tgz#53f55ead492f7b5802b1feae4e51abc75730af33" - integrity sha512-qWazjqnIGRngf4OmyeSIv7sHICQRdMQ1CKPIQIqxA8qFR+gHhDHSfvMdRAvgWbsfkimXOIFiHVIATypyWhviJw== - dependencies: - "@openzeppelin/contracts" "^5.0.2" - "@openzeppelin/contracts-upgradeable" "^5.0.2" - "@zetachain/networks" "^10.0.0" - ethers "^6.13.1" - "@zetachain/protocol-contracts@9.0.0": version "9.0.0" resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-9.0.0.tgz#c20ad5da43f6f3676f31556b303d1cb4ea17357e" diff --git a/examples/nft/contracts/Connected.sol b/examples/nft/contracts/Connected.sol index b756a745..2db31627 100644 --- a/examples/nft/contracts/Connected.sol +++ b/examples/nft/contracts/Connected.sol @@ -47,9 +47,13 @@ contract Connected is } function safeMint(address to, string memory uri) public onlyOwner { - if (to == address(0)) revert InvalidAddress(); + uint256 hash = uint256( + keccak256( + abi.encodePacked(address(this), block.number, _nextTokenId++) + ) + ); - uint256 tokenId = _nextTokenId++; + uint256 tokenId = hash & 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; _safeMint(to, tokenId); _setTokenURI(tokenId, uri); @@ -74,7 +78,6 @@ contract Connected is message, 0 ); - if (destination == address(0)) { gateway.call(counterparty, message, revertOptions); } else { diff --git a/examples/nft/contracts/Universal.sol b/examples/nft/contracts/Universal.sol index 988c09f3..10bc87ae 100644 --- a/examples/nft/contracts/Universal.sol +++ b/examples/nft/contracts/Universal.sol @@ -23,8 +23,7 @@ contract Universal is Events { GatewayZEVM public immutable gateway; - SystemContract public immutable systemContract = - SystemContract(0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9); + SystemContract public immutable systemContract; uint256 private _nextTokenId; bool public isUniversal = true; uint256 public gasLimit; @@ -46,12 +45,17 @@ contract Universal is address owner, string memory name, string memory symbol, - uint256 gas + uint256 gas, + address systemContractAddress ) ERC721(name, symbol) Ownable(owner) { - if (gatewayAddress == address(0) || owner == address(0)) - revert InvalidAddress(); + if ( + gatewayAddress == address(0) || + owner == address(0) || + systemContractAddress == address(0) + ) revert InvalidAddress(); if (gas == 0) revert InvalidGasLimit(); gateway = GatewayZEVM(gatewayAddress); + systemContract = SystemContract(systemContractAddress); gasLimit = gas; } @@ -115,15 +119,12 @@ contract Universal is _setTokenURI(tokenId, uri); } - event Foo(address); - function onCall( MessageContext calldata context, address zrc20, uint256 amount, bytes calldata message ) external override onlyGateway { - emit Foo(context.sender); if (context.sender != counterparty[zrc20]) revert("Unauthorized"); ( diff --git a/examples/nft/scripts/testnet.sh b/examples/nft/scripts/testnet.sh new file mode 100755 index 00000000..2f42b65c --- /dev/null +++ b/examples/nft/scripts/testnet.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -e +set -x + +npx hardhat compile --force --quiet + +UNIVERSAL=$(npx hardhat deploy --name Universal --network zeta_testnet --gateway 0x6c533f7fe93fae114d0954697069df33c9b74fd7 --system-contract 0xEdf1c3275d13489aCdC6cD6eD246E72458B8795B --gas-limit 500000 --json | jq -r '.contractAddress') +CONNECTED_BASE=$(npx hardhat deploy --name Connected --network base_sepolia --gateway 0x0c487a766110c85d301d96e33579c5b317fa4995 --json | jq -r '.contractAddress') +CONNECTED_BNB=$(npx hardhat deploy --name Connected --network bsc_testnet --gateway 0x0c487a766110c85d301d96e33579c5b317fa4995 --json | jq -r '.contractAddress') + +ZRC20_BASE=0x236b0DE675cC8F46AE186897fCCeFe3370C9eDeD +ZRC20_BNB=0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891 + +npx hardhat connected-set-counterparty --network base_sepolia --contract "$CONNECTED_BASE" --counterparty "$UNIVERSAL" --json + +npx hardhat connected-set-counterparty --network bsc_testnet --contract "$CONNECTED_BNB" --counterparty "$UNIVERSAL" --json + +npx hardhat universal-set-counterparty --network zeta_testnet --contract "$UNIVERSAL" --counterparty "$CONNECTED_BASE" --zrc20 "$ZRC20_BASE" --json + +npx hardhat universal-set-counterparty --network zeta_testnet --contract "$UNIVERSAL" --counterparty "$CONNECTED_BNB" --zrc20 "$ZRC20_BNB" --json \ No newline at end of file diff --git a/examples/nft/tasks/deploy.ts b/examples/nft/tasks/deploy.ts index 895512b0..9fd18499 100644 --- a/examples/nft/tasks/deploy.ts +++ b/examples/nft/tasks/deploy.ts @@ -12,13 +12,16 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { } const factory: any = await hre.ethers.getContractFactory(args.name); + const contract = await factory.deploy( args.gateway, signer.address, args.nftName, args.nftSymbol, - ...(args.gasLimit ? [args.gasLimit] : []) + ...(args.gasLimit ? [args.gasLimit] : []), + ...(args.systemContract ? [args.systemContract] : []) ); + await contract.deployed(); if (args.json) { @@ -47,4 +50,5 @@ task("deploy", "Deploy the NFT contract", main) "gateway", "Gateway address (default: ZetaChain Gateway)", "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707" - ); + ) + .addOptionalParam("systemContract", "System contract address"); diff --git a/examples/nft/tasks/transfer.ts b/examples/nft/tasks/transfer.ts index e0e47abe..56f5e188 100644 --- a/examples/nft/tasks/transfer.ts +++ b/examples/nft/tasks/transfer.ts @@ -33,13 +33,8 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const gasAmount = ethers.utils.parseUnits(args.gasAmount, 18); const receiver = args.receiver || signer.address; - - tx = await (contract as any).transferCrossChain( - args.tokenId, - receiver, - args.to, - { ...txOptions, value: gasAmount } - ); + console.log(args.tokenId, receiver, args.to); + tx = await contract.transferCrossChain(args.tokenId, receiver, args.to); await tx.wait(); if (args.json) { @@ -53,10 +48,10 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { ); } else { console.log(`🚀 Successfully transferred NFT to the contract. -📜 Contract address: ${args.from} -🖼 NFT Contract address: ${args.nftContract} -🆔 Token ID: ${args.tokenId} -🔗 Transaction hash: ${tx.hash}`); + 📜 Contract address: ${args.from} + 🖼 NFT Contract address: ${args.nftContract} + 🆔 Token ID: ${args.tokenId} + 🔗 Transaction hash: ${tx.hash}`); } };