From 0d8baccdd4873dddba767356108284bb1d6d0f25 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Wed, 8 May 2024 16:48:10 +0300 Subject: [PATCH] Reorg of cross-chain messaging contracts (#173) --- messaging/counter/README.md | 183 ------------------ messaging/counter/tasks/counter_show.ts | 23 --- messaging/{counter => erc20}/.eslintignore | 0 messaging/{counter => erc20}/.eslintrc.js | 0 messaging/{counter => erc20}/.gitignore | 0 messaging/{counter => erc20}/LICENSE | 0 messaging/erc20/README.md | 30 +++ .../contracts/CrossChainERC20.sol} | 48 ++--- messaging/{value => erc20}/hardhat.config.ts | 0 messaging/{warriors => erc20}/package.json | 2 +- messaging/{counter => erc20}/tasks/deploy.ts | 49 +++-- .../{counter => erc20}/tasks/interact.ts | 14 +- messaging/{counter => erc20}/tsconfig.json | 4 +- messaging/{counter => erc20}/yarn.lock | 65 ++++--- messaging/message/README.md | 169 +--------------- .../message/contracts/CrossChainMessage.sol | 33 +--- messaging/message/hardhat.config.ts | 4 - messaging/message/package.json | 2 +- messaging/message/tasks/deploy.ts | 52 +++-- messaging/message/tasks/interact.ts | 3 +- messaging/message/tsconfig.json | 4 +- messaging/message/yarn.lock | 65 ++++--- messaging/{value => nft}/.eslintignore | 0 messaging/{value => nft}/.eslintrc.js | 0 messaging/{value => nft}/.gitignore | 0 messaging/{value => nft}/LICENSE | 0 messaging/nft/README.md | 30 +++ .../contracts/CrossChainNFT.sol} | 85 +++----- messaging/{warriors => nft}/hardhat.config.ts | 0 messaging/{value => nft}/package.json | 2 +- messaging/{warriors => nft}/tasks/deploy.ts | 55 +++--- messaging/{warriors => nft}/tasks/interact.ts | 9 +- messaging/{warriors => nft}/tasks/mint.ts | 2 +- messaging/{value => nft}/tsconfig.json | 4 +- messaging/{value => nft}/yarn.lock | 65 ++++--- messaging/value/README.md | 183 ------------------ messaging/warriors/README.md | 183 ------------------ messaging/{warriors => zeta}/.eslintignore | 0 messaging/{warriors => zeta}/.eslintrc.js | 0 messaging/{warriors => zeta}/.gitignore | 0 messaging/{warriors => zeta}/LICENSE | 0 messaging/zeta/README.md | 30 +++ .../contracts/CrossChainZeta.sol} | 19 +- messaging/{counter => zeta}/hardhat.config.ts | 1 - messaging/{counter => zeta}/package.json | 2 +- messaging/{value => zeta}/tasks/deploy.ts | 38 ++-- messaging/{value => zeta}/tasks/interact.ts | 2 +- messaging/{warriors => zeta}/tsconfig.json | 4 +- messaging/{warriors => zeta}/yarn.lock | 65 ++++--- 49 files changed, 434 insertions(+), 1095 deletions(-) delete mode 100644 messaging/counter/README.md delete mode 100644 messaging/counter/tasks/counter_show.ts rename messaging/{counter => erc20}/.eslintignore (100%) rename messaging/{counter => erc20}/.eslintrc.js (100%) rename messaging/{counter => erc20}/.gitignore (100%) rename messaging/{counter => erc20}/LICENSE (100%) create mode 100644 messaging/erc20/README.md rename messaging/{counter/contracts/Counter.sol => erc20/contracts/CrossChainERC20.sol} (61%) rename messaging/{value => erc20}/hardhat.config.ts (100%) rename messaging/{warriors => erc20}/package.json (97%) rename messaging/{counter => erc20}/tasks/deploy.ts (71%) rename messaging/{counter => erc20}/tasks/interact.ts (72%) rename messaging/{counter => erc20}/tsconfig.json (74%) rename messaging/{counter => erc20}/yarn.lock (99%) rename messaging/{value => nft}/.eslintignore (100%) rename messaging/{value => nft}/.eslintrc.js (100%) rename messaging/{value => nft}/.gitignore (100%) rename messaging/{value => nft}/LICENSE (100%) create mode 100644 messaging/nft/README.md rename messaging/{warriors/contracts/CrossChainWarriors.sol => nft/contracts/CrossChainNFT.sol} (50%) rename messaging/{warriors => nft}/hardhat.config.ts (100%) rename messaging/{value => nft}/package.json (97%) rename messaging/{warriors => nft}/tasks/deploy.ts (70%) rename messaging/{warriors => nft}/tasks/interact.ts (88%) rename messaging/{warriors => nft}/tasks/mint.ts (95%) rename messaging/{value => nft}/tsconfig.json (74%) rename messaging/{value => nft}/yarn.lock (99%) delete mode 100644 messaging/value/README.md delete mode 100644 messaging/warriors/README.md rename messaging/{warriors => zeta}/.eslintignore (100%) rename messaging/{warriors => zeta}/.eslintrc.js (100%) rename messaging/{warriors => zeta}/.gitignore (100%) rename messaging/{warriors => zeta}/LICENSE (100%) create mode 100644 messaging/zeta/README.md rename messaging/{value/contracts/Value.sol => zeta/contracts/CrossChainZeta.sol} (73%) rename messaging/{counter => zeta}/hardhat.config.ts (91%) rename messaging/{counter => zeta}/package.json (97%) rename messaging/{value => zeta}/tasks/deploy.ts (77%) rename messaging/{value => zeta}/tasks/interact.ts (95%) rename messaging/{warriors => zeta}/tsconfig.json (74%) rename messaging/{warriors => zeta}/yarn.lock (99%) diff --git a/messaging/counter/README.md b/messaging/counter/README.md deleted file mode 100644 index f86c7d35..00000000 --- a/messaging/counter/README.md +++ /dev/null @@ -1,183 +0,0 @@ -# Template for a ZetaChain Hardhat Project - -This is a simple Hardhat template that provides a starting point for developing -smart contract applications on the ZetaChain blockchain. - -## Prerequisites - -Before getting started, ensure that you have -[Node.js](https://nodejs.org/en/download) and [Yarn](https://yarnpkg.com/) -installed on your system. - -## Getting Started - -To get started, install the necessary dependencies: - -``` -yarn -``` - -## Hardhat Tasks - -This template includes Hardhat tasks that can be used make it easier to build -with ZetaChain. - -### Generating a Random Wallet - -To generate a random wallet: - -``` -npx hardhat account --save -``` - -This command generates a random wallet, prints information about the wallet to -the terminal, and saves the private key to a `.env` file to make it accessible -to Hardhat. If you don't want to save the wallet (for example, if you just need -an address to send tokens to for testing purposes), you can run the command -without the `--save` flag. - -### Querying for Token Balances - -To query for token balances: - -``` -npx hardhat balances -``` - -This command queries token balances for the account address derived from the -private key specified in the `.env`. - -If you want to query for token balances for a different account, you can use the -`--address` flag: - -``` -npx hardhat balances --address ADDRESS -``` - -### Requesting Tokens from the Faucet - -To request ZETA tokens from the faucet: - -``` -npx hardhat faucet -``` - -This command requests tokens from the faucet for the account address derived -from the private key specified in the `.env`. Tokens sent to the address on -ZetaChain. To specify a different chain use a flag: - -``` -npx hardhat faucet --chain goerli_testnet -``` - -You can also specify a different address to send the tokens to: - -``` -npx hardhat faucet --address ADDRESS -``` - -Alternatively, you can install a standalone faucet CLI: - -``` -yarn global add @zetachain/faucet-cli@athens3 -``` - -You can then use it with the following command: - -``` -zetafaucet -h -``` - -### Creating an Omnichain Contract - -To create a new omnichain contract: - -``` -npx hardhat omnichain MyContract -``` - -This command creates a new omnichain contract in `contracts/MyContract.sol`, a -task to deploy the contract in `tasks/deploy.ts`, and a task to interact with -the contract in `tasks/interact.ts`. - -When an omnichain contract is called, it can receive data in the `data` field of -a transaction. This data is passed to the `message` parameter of the contract's -`onCrossChainCall` function. To specify the fields of the `message` parameter, -use positional arguments: - -``` -npx hardhat omnichain MyContract recepient:address description quantity:uint256 -``` - -A field may have a type specified after the field name, separated by a colon. If -no type is specified, the type defaults to `bytes32`. - -Learn more about omnichain contracts by following the -[tutorials](https://www.zetachain.com/docs/developers/omnichain/tutorials/hello/). - -### Tracking a Cross-Chain Transaction - -After broadcasting a cross-chain transaction on a connected chain either to a -cross-chain messaging contract or to trigger an omnichain contract, you can -track its status: - -``` -npx hardhat cctx --tx TX_HASH -``` - -### Verifying a Contract - -To verify a contract deployed on ZetaChain: - -``` -npx hardhat verify:zeta --contract ADDRESS -``` - -Select the contract to verify: - -``` -? Select a contract to verify: (Use arrow keys) - @zetachain/zevm-protocol-contracts/contracts/interfaces/IZRC20.sol:IZRC20 - @zetachain/zevm-protocol-contracts/contracts/interfaces/zContract.sol:zContract -❯ contracts/Withdraw.sol:Withdraw -``` - -After the confirmation the contract will be verified. - -### Sending Tokens - -Sending ZETA from ZetaChain to Goerli: - -``` -npx hardhat send-zeta --amount 1 --network zeta_testnet --destination goerli_testnet -``` - -Sending ZETA from Goerli to ZetaChain: - -``` -npx hardhat send-zeta --amount 1 --network goerli_testnet --destination zeta_testnet -``` - -Depositing gETH to ZetaChain as ZRC-20: - -``` -npx hardhat send-zrc20 --amount 1 --network goerli_testnet --destination zeta_testnet -``` - -Withdrawing ZRC-20 from ZetaChain go Goerli as gETH: - -``` -npx hardhat send-zrc20 --amount 1 --network zeta_testnet --destination goerli_testnet -``` - -Depositing tBTC from the Bitcoin testnet to ZetaChain: - -``` -npx hardhat send-btc --amount 1 --recipient TSS_ADDRESS --memo RECIPIENT_ADDRESS_WITHOUT_0x -``` - -## Next Steps - -To learn more about building decentralized apps on ZetaChain, follow the -tutorials available in -[the documentation](https://www.zetachain.com/docs/developers/overview/). diff --git a/messaging/counter/tasks/counter_show.ts b/messaging/counter/tasks/counter_show.ts deleted file mode 100644 index 44f66e75..00000000 --- a/messaging/counter/tasks/counter_show.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { task } from "hardhat/config"; -import { HardhatRuntimeEnvironment } from "hardhat/types"; - -const contractName = "CrossChainCounter"; - -const main = async (args: any, hre: HardhatRuntimeEnvironment) => { - const [signer] = await hre.ethers.getSigners(); - console.log(`🔑 Using account: ${signer.address}\n`); - - const factory = await hre.ethers.getContractFactory(contractName); - const contract = factory.attach(args.contract); - - const counter = await contract.counter(signer.address); - - console.log(`🔢 The counter for ${signer.address} is: ${counter.toString()} -`); -}; - -task( - "counter:show", - "Sends a message from one chain to another.", - main -).addParam("contract", "Contract address"); diff --git a/messaging/counter/.eslintignore b/messaging/erc20/.eslintignore similarity index 100% rename from messaging/counter/.eslintignore rename to messaging/erc20/.eslintignore diff --git a/messaging/counter/.eslintrc.js b/messaging/erc20/.eslintrc.js similarity index 100% rename from messaging/counter/.eslintrc.js rename to messaging/erc20/.eslintrc.js diff --git a/messaging/counter/.gitignore b/messaging/erc20/.gitignore similarity index 100% rename from messaging/counter/.gitignore rename to messaging/erc20/.gitignore diff --git a/messaging/counter/LICENSE b/messaging/erc20/LICENSE similarity index 100% rename from messaging/counter/LICENSE rename to messaging/erc20/LICENSE diff --git a/messaging/erc20/README.md b/messaging/erc20/README.md new file mode 100644 index 00000000..59b7739e --- /dev/null +++ b/messaging/erc20/README.md @@ -0,0 +1,30 @@ +# Hardhat Template for ZetaChain + +This is a simple Hardhat template that provides a starting point for developing +smart contract applications on ZetaChain. + +## Prerequisites + +Before getting started, ensure that you have +[Node.js](https://nodejs.org/en/download) (version 18 or above) and +[Yarn](https://yarnpkg.com/) installed on your system. + +## Getting Started + +To get started, install the necessary dependencies: + +``` +yarn +``` + +## Hardhat Tasks + +This template includes Hardhat tasks that streamline smart contract development. +Learn more about the template and the functionality it provides +[in the docs](https://www.zetachain.com/docs/developers/template/). + +## Next Steps + +To learn more about building decentralized apps on ZetaChain, follow the +tutorials available in +[the introduction to ZetaChain](https://www.zetachain.com/docs/developers/overview/). diff --git a/messaging/counter/contracts/Counter.sol b/messaging/erc20/contracts/CrossChainERC20.sol similarity index 61% rename from messaging/counter/contracts/Counter.sol rename to messaging/erc20/contracts/CrossChainERC20.sol index 78507134..864fe3c6 100644 --- a/messaging/counter/contracts/Counter.sol +++ b/messaging/erc20/contracts/CrossChainERC20.sol @@ -5,17 +5,15 @@ import "@openzeppelin/contracts/interfaces/IERC20.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@zetachain/protocol-contracts/contracts/evm/tools/ZetaInteractor.sol"; import "@zetachain/protocol-contracts/contracts/evm/interfaces/ZetaInterfaces.sol"; +import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; -contract Counter is ZetaInteractor, ZetaReceiver { - error InvalidMessageType(); - error DecrementOverflow(); +contract CrossChainERC20 is ERC20, ERC20Burnable, ZetaInteractor, ZetaReceiver { + error InsufficientBalance(); - event CounterEvent(address); - event CounterRevertedEvent(address); - mapping(address => uint256) public counter; + event CrossChainERC20Event(address, uint256); + event CrossChainERC20RevertedEvent(address, uint256); - bytes32 public constant COUNTER_MESSAGE_TYPE = - keccak256("CROSS_CHAIN_COUNTER"); ZetaTokenConsumer private immutable _zetaConsumer; IERC20 internal immutable _zetaToken; @@ -23,12 +21,18 @@ contract Counter is ZetaInteractor, ZetaReceiver { address connectorAddress, address zetaTokenAddress, address zetaConsumerAddress - ) ZetaInteractor(connectorAddress) { + ) ERC20("CrossChain Token", "CCT") ZetaInteractor(connectorAddress) { _zetaToken = IERC20(zetaTokenAddress); _zetaConsumer = ZetaTokenConsumer(zetaConsumerAddress); + + _mint(msg.sender, 1000000 * 10 ** decimals()); } - function sendMessage(uint256 destinationChainId) external payable { + function sendMessage( + uint256 destinationChainId, + address to, + uint256 value + ) external payable { if (!_isValidChainId(destinationChainId)) revert InvalidDestinationChainId(); @@ -38,12 +42,15 @@ contract Counter is ZetaInteractor, ZetaReceiver { }(address(this), crossChainGas); _zetaToken.approve(address(connector), zetaValueAndGas); + if (balanceOf(msg.sender) < value) revert InsufficientBalance(); + _burn(msg.sender, value); + connector.send( ZetaInterfaces.SendInput({ destinationChainId: destinationChainId, destinationAddress: interactorsByChainId[destinationChainId], destinationGasLimit: 300000, - message: abi.encode(COUNTER_MESSAGE_TYPE, msg.sender), + message: abi.encode(to, value, msg.sender), zetaValueAndGas: zetaValueAndGas, zetaParams: abi.encode("") }) @@ -53,29 +60,26 @@ contract Counter is ZetaInteractor, ZetaReceiver { function onZetaMessage( ZetaInterfaces.ZetaMessage calldata zetaMessage ) external override isValidMessageCall(zetaMessage) { - (bytes32 messageType, address from) = abi.decode( + (address to, uint256 value) = abi.decode( zetaMessage.message, - (bytes32, address) + (address, uint256) ); - if (messageType != COUNTER_MESSAGE_TYPE) revert InvalidMessageType(); + _mint(to, value); - counter[from]++; - emit CounterEvent(from); + emit CrossChainERC20Event(to, value); } function onZetaRevert( ZetaInterfaces.ZetaRevert calldata zetaRevert ) external override isValidRevertCall(zetaRevert) { - (bytes32 messageType, address from) = abi.decode( + (address to, uint256 value, address from) = abi.decode( zetaRevert.message, - (bytes32, address) + (address, uint256, address) ); - if (messageType != COUNTER_MESSAGE_TYPE) revert InvalidMessageType(); + _mint(from, value); - if (counter[from] <= 0) revert DecrementOverflow(); - counter[from]--; - emit CounterRevertedEvent(from); + emit CrossChainERC20RevertedEvent(to, value); } } diff --git a/messaging/value/hardhat.config.ts b/messaging/erc20/hardhat.config.ts similarity index 100% rename from messaging/value/hardhat.config.ts rename to messaging/erc20/hardhat.config.ts diff --git a/messaging/warriors/package.json b/messaging/erc20/package.json similarity index 97% rename from messaging/warriors/package.json rename to messaging/erc20/package.json index 4ee4d6d3..01eff927 100644 --- a/messaging/warriors/package.json +++ b/messaging/erc20/package.json @@ -26,7 +26,7 @@ "@types/node": ">=12.0.0", "@typescript-eslint/eslint-plugin": "^5.59.9", "@typescript-eslint/parser": "^5.59.9", - "@zetachain/toolkit": "6.0.0", + "@zetachain/toolkit": "7.0.0", "axios": "^1.3.6", "chai": "^4.2.0", "dotenv": "^16.0.3", diff --git a/messaging/counter/tasks/deploy.ts b/messaging/erc20/tasks/deploy.ts similarity index 71% rename from messaging/counter/tasks/deploy.ts rename to messaging/erc20/tasks/deploy.ts index 27dd53e4..1b1efff0 100644 --- a/messaging/counter/tasks/deploy.ts +++ b/messaging/erc20/tasks/deploy.ts @@ -2,15 +2,15 @@ import { getAddress } from "@zetachain/protocol-contracts"; import { ethers } from "ethers"; import { task, types } from "hardhat/config"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import { getSupportedNetworks } from "@zetachain/networks"; +import type { ParamChainName } from "@zetachain/protocol-contracts"; -const contractName = "Counter"; +const contractName = "CrossChainERC20"; const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const networks = args.networks.split(","); const contracts: { [key: string]: string } = {}; await Promise.all( - networks.map(async (networkName: string) => { + networks.map(async (networkName: ParamChainName) => { contracts[networkName] = await deployContract( hre, networkName, @@ -21,7 +21,13 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { ); for (const source in contracts) { - await setInteractors(hre, source, contracts, args.json, args.gasLimit); + await setInteractors( + hre, + source as ParamChainName, + contracts, + args.json, + args.gasLimit + ); } if (args.json) { @@ -29,7 +35,10 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { } }; -const initWallet = (hre: HardhatRuntimeEnvironment, networkName: string) => { +const initWallet = ( + hre: HardhatRuntimeEnvironment, + networkName: ParamChainName +) => { const { url } = hre.config.networks[networkName] as any; const provider = new ethers.providers.JsonRpcProvider(url); const wallet = new ethers.Wallet(process.env.PRIVATE_KEY as string, provider); @@ -39,31 +48,24 @@ const initWallet = (hre: HardhatRuntimeEnvironment, networkName: string) => { const deployContract = async ( hre: HardhatRuntimeEnvironment, - networkName: string, + networkName: ParamChainName, json: boolean = false, gasLimit: number ) => { const wallet = initWallet(hre, networkName); - const connector = getAddress("connector", networkName as any); - const zetaToken = getAddress("zetaToken", networkName as any); - const zetaTokenConsumerUniV2 = getAddress( - "zetaTokenConsumerUniV2", - networkName as any - ); - const zetaTokenConsumerUniV3 = getAddress( - "zetaTokenConsumerUniV3", - networkName as any - ); + const connector = getAddress("connector", networkName); + const zetaToken = getAddress("zetaToken", networkName); + const zetaTokenConsumer = getAddress("zetaTokenConsumerUniV3", networkName); const { abi, bytecode } = await hre.artifacts.readArtifact(contractName); const factory = new ethers.ContractFactory(abi, bytecode, wallet); - const contract = await factory.deploy(connector, zetaToken, zetaTokenConsumerUniV2 || zetaTokenConsumerUniV3, { gasLimit }); + const contract = await factory.deploy(connector, zetaToken, zetaTokenConsumer, { gasLimit }); await contract.deployed(); if (!json) { console.log(` -🚀 Successfully deployed contract on ${networkName}. +🚀 Successfully deployed contract on ${networkName} 📜 Contract address: ${contract.address}`); } return contract.address; @@ -71,7 +73,7 @@ const deployContract = async ( const setInteractors = async ( hre: HardhatRuntimeEnvironment, - source: string, + source: ParamChainName, contracts: { [key: string]: string }, json: boolean = false, gasLimit: number @@ -89,7 +91,7 @@ const setInteractors = async ( for (const counterparty in contracts) { if (counterparty === source) continue; - const counterpartyContract = hre.ethers.utils.solidityPack( + const counterpartyContract = ethers.utils.solidityPack( ["address"], [contracts[counterparty]] ); @@ -108,11 +110,6 @@ const setInteractors = async ( }; task("deploy", "Deploy the contract", main) - .addParam( - "networks", - `Comma separated list of networks to deploy to (e.g. ${getSupportedNetworks( - "ccm" - )})` - ) + .addParam("networks", "Comma separated list of networks to deploy to") .addOptionalParam("gasLimit", "Gas limit", 10000000, types.int) .addFlag("json", "Output JSON"); diff --git a/messaging/counter/tasks/interact.ts b/messaging/erc20/tasks/interact.ts similarity index 72% rename from messaging/counter/tasks/interact.ts rename to messaging/erc20/tasks/interact.ts index adc48965..1665a115 100644 --- a/messaging/counter/tasks/interact.ts +++ b/messaging/erc20/tasks/interact.ts @@ -5,7 +5,7 @@ import { parseEther } from "@ethersproject/units"; const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const [signer] = await hre.ethers.getSigners(); - const factory = await hre.ethers.getContractFactory("Counter"); + const factory = await hre.ethers.getContractFactory("CrossChainERC20"); const contract = factory.attach(args.contract); const destination = hre.config.networks[args.destination]?.chainId; @@ -13,9 +13,15 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { throw new Error(`${args.destination} is not a valid destination chain`); } + const paramTo = hre.ethers.utils.getAddress(args.to); +const paramValue = hre.ethers.BigNumber.from(args.value); + const value = parseEther(args.amount); - const tx = await contract.connect(signer).sendMessage(destination, { value }); + + const tx = await contract + .connect(signer) + .sendMessage(destination, paramTo, paramValue, { value }); const receipt = await tx.wait(); if (args.json) { @@ -32,4 +38,6 @@ task("interact", "Sends a message from one chain to another.", main) .addFlag("json", "Output JSON") .addParam("contract", "Contract address") .addParam("amount", "Token amount to send") - .addParam("destination", "Destination chain"); + .addParam("destination", "Destination chain") + .addParam("to", "address") + .addParam("value", "uint256") diff --git a/messaging/counter/tsconfig.json b/messaging/erc20/tsconfig.json similarity index 74% rename from messaging/counter/tsconfig.json rename to messaging/erc20/tsconfig.json index 574e785c..fb0567b3 100644 --- a/messaging/counter/tsconfig.json +++ b/messaging/erc20/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { - "target": "es2020", - "module": "commonjs", + "module": "nodenext", + "moduleResolution": "nodenext", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, diff --git a/messaging/counter/yarn.lock b/messaging/erc20/yarn.lock similarity index 99% rename from messaging/counter/yarn.lock rename to messaging/erc20/yarn.lock index 90dd53c5..5adafe6f 100644 --- a/messaging/counter/yarn.lock +++ b/messaging/erc20/yarn.lock @@ -777,11 +777,6 @@ "@ethersproject/properties" "^5.7.0" "@ethersproject/strings" "^5.7.0" -"@fastify/busboy@^2.0.0": - version "2.1.1" - resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d" - integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA== - "@humanwhocodes/config-array@^0.11.10": version "0.11.10" resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.10.tgz#5a3ffe32cc9306365fb3fd572596cd602d5e12d2" @@ -1283,7 +1278,7 @@ table "^6.8.0" undici "^5.14.0" -"@openzeppelin/contracts@^4.9.2": +"@openzeppelin/contracts@^4.9.6": version "4.9.6" resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.6.tgz#2a880a24eb19b4f8b25adc2a5095f2aa27f39677" integrity sha512-xSmezSupL+y9VkHZJGDoCBpmnB2ogM13ccaYDWqJTfS3dbuHkgjuwDFUmaFauBCboQMGB/S5UqUl2y54X99BmA== @@ -1704,10 +1699,10 @@ typescript "5.0.4" zod "3.19.1" -"@zetachain/networks@6.0.0": - version "6.0.0" - resolved "https://registry.yarnpkg.com/@zetachain/networks/-/networks-6.0.0.tgz#ae5d3cd1678b32510edfaa71f8f4a6f4cbc1d9ab" - integrity sha512-yKFVP/yJDp76Q5lBGfZSpY/KO3TZ9ldo0lhE4MpBW43EsBxOZWixg6sqb56mcU/gg1lbWG8sHHWtYFK51SByjQ== +"@zetachain/networks@7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@zetachain/networks/-/networks-7.0.0.tgz#a5f8a188d633e2064ee7c77499351381ba891441" + integrity sha512-/amSq+KNJe+EGj0ioZS+DZJtsnbPSDotp9LsrAbaEVMAxKvBK/XkvggH73sJyRWWeMpfhHrNPlrKTLrN+mRkIg== dependencies: dotenv "^16.1.4" @@ -1716,18 +1711,18 @@ resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-7.0.0-rc1.tgz#588483d1ec70e572b7e40e84ef5b34282b0ab375" integrity sha512-vgS+Pjh4MysOyw8WbqTQVBsHJYqKvMcdV7cNVqxaTJd/dl2ak7NNvsIeaeUnxQrp8XfQol2B8GXJpVLM6MK/dg== -"@zetachain/toolkit@6.0.0": - version "6.0.0" - resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-6.0.0.tgz#385cfd11f1ac39cbb6ca6410109523e2ab6f8841" - integrity sha512-JAtl7CX8cMJ+iw/byjcbLqgCfPS87vkdYCZOPBBOudqUySPTz4owqVgGZB/xYRyXBsF0KW0F6R65sc+fleQ86A== +"@zetachain/toolkit@7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-7.0.0.tgz#7301ccab40c37d3fd8fcc347f99c831ec31b1bd3" + integrity sha512-5cOJVBIEcosF2A2TJbNGFfh4Bob8UcodQII1RdHRstqvV3toZ18r1gVWpLGQ8w2N6T2FCPE8ueN4Q5zH68q20Q== dependencies: "@inquirer/prompts" "^2.1.1" "@inquirer/select" "1.1.3" "@nomiclabs/hardhat-ethers" "^2.2.3" - "@openzeppelin/contracts" "^4.9.2" + "@openzeppelin/contracts" "^4.9.6" "@uniswap/v2-periphery" "^1.1.0-beta.0" "@zetachain/faucet-cli" "^4.0.1" - "@zetachain/networks" "6.0.0" + "@zetachain/networks" "7.0.0" "@zetachain/protocol-contracts" "7.0.0-rc1" axios "^1.4.0" bech32 "^2.0.0" @@ -2088,9 +2083,9 @@ axios@1.2.3: proxy-from-env "^1.1.0" axios@^1.3.6, axios@^1.4.0: - version "1.6.1" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.1.tgz#76550d644bf0a2d469a01f9244db6753208397d7" - integrity sha512-vfBmhDpKafglh0EldBEbVuoe7DyAavGSLWhuSm5ZSEKQnHhBf0xAAwybbNH1IkrJNGnS/VG4I5yxig1pCEXE4g== + version "1.4.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.4.0.tgz#38a7bf1224cd308de271146038b551d725f0be1f" + integrity sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA== dependencies: follow-redirects "^1.15.0" form-data "^4.0.0" @@ -2309,6 +2304,13 @@ buffer@^6.0.3: base64-js "^1.3.1" ieee754 "^1.2.1" +busboy@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/busboy/-/busboy-1.6.0.tgz#966ea36a9502e43cdb9146962523b92f531f6893" + integrity sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA== + dependencies: + streamsearch "^1.1.0" + bytes@3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.2.tgz#8b0beeb98605adf1b128fa4386403c009e0221a5" @@ -3572,9 +3574,9 @@ flatted@^3.1.0: integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ== follow-redirects@^1.12.1, follow-redirects@^1.15.0: - version "1.15.6" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" - integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== + version "1.15.2" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" + integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== for-each@^0.3.3: version "0.3.3" @@ -3715,9 +3717,9 @@ get-caller-file@^2.0.1, get-caller-file@^2.0.5: integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== get-func-name@^2.0.0: - version "2.0.2" - resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.2.tgz#0d7cf20cd13fda808669ffa88f4ffc7a3943fc41" - integrity sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ== + version "2.0.0" + resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41" + integrity sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig== get-intrinsic@^1.0.2, get-intrinsic@^1.1.1, get-intrinsic@^1.1.3, get-intrinsic@^1.2.0, get-intrinsic@^1.2.1: version "1.2.1" @@ -5965,6 +5967,11 @@ stealthy-require@^1.1.1: resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b" integrity sha512-ZnWpYnYugiOVEY5GkcuJK1io5V8QmNYChG62gSit9pQVGErXtrKuPC55ITaVSukmMta5qpMU7vqLt2Lnni4f/g== +streamsearch@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764" + integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg== + string-format@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/string-format/-/string-format-2.0.0.tgz#f2df2e7097440d3b65de31b6d40d54c96eaffb9b" @@ -6446,11 +6453,11 @@ unbox-primitive@^1.0.2: which-boxed-primitive "^1.0.2" undici@^5.14.0: - version "5.28.4" - resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068" - integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g== + version "5.23.0" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.23.0.tgz#e7bdb0ed42cebe7b7aca87ced53e6eaafb8f8ca0" + integrity sha512-1D7w+fvRsqlQ9GscLBwcAJinqcZGHUKjbOmXdlE/v8BvEGXjeWAax+341q44EuTcHXXnfyKNbKRq4Lg7OzhMmg== dependencies: - "@fastify/busboy" "^2.0.0" + busboy "^1.6.0" universalify@^0.1.0: version "0.1.2" diff --git a/messaging/message/README.md b/messaging/message/README.md index f86c7d35..59b7739e 100644 --- a/messaging/message/README.md +++ b/messaging/message/README.md @@ -1,13 +1,13 @@ -# Template for a ZetaChain Hardhat Project +# Hardhat Template for ZetaChain This is a simple Hardhat template that provides a starting point for developing -smart contract applications on the ZetaChain blockchain. +smart contract applications on ZetaChain. ## Prerequisites Before getting started, ensure that you have -[Node.js](https://nodejs.org/en/download) and [Yarn](https://yarnpkg.com/) -installed on your system. +[Node.js](https://nodejs.org/en/download) (version 18 or above) and +[Yarn](https://yarnpkg.com/) installed on your system. ## Getting Started @@ -19,165 +19,12 @@ yarn ## Hardhat Tasks -This template includes Hardhat tasks that can be used make it easier to build -with ZetaChain. - -### Generating a Random Wallet - -To generate a random wallet: - -``` -npx hardhat account --save -``` - -This command generates a random wallet, prints information about the wallet to -the terminal, and saves the private key to a `.env` file to make it accessible -to Hardhat. If you don't want to save the wallet (for example, if you just need -an address to send tokens to for testing purposes), you can run the command -without the `--save` flag. - -### Querying for Token Balances - -To query for token balances: - -``` -npx hardhat balances -``` - -This command queries token balances for the account address derived from the -private key specified in the `.env`. - -If you want to query for token balances for a different account, you can use the -`--address` flag: - -``` -npx hardhat balances --address ADDRESS -``` - -### Requesting Tokens from the Faucet - -To request ZETA tokens from the faucet: - -``` -npx hardhat faucet -``` - -This command requests tokens from the faucet for the account address derived -from the private key specified in the `.env`. Tokens sent to the address on -ZetaChain. To specify a different chain use a flag: - -``` -npx hardhat faucet --chain goerli_testnet -``` - -You can also specify a different address to send the tokens to: - -``` -npx hardhat faucet --address ADDRESS -``` - -Alternatively, you can install a standalone faucet CLI: - -``` -yarn global add @zetachain/faucet-cli@athens3 -``` - -You can then use it with the following command: - -``` -zetafaucet -h -``` - -### Creating an Omnichain Contract - -To create a new omnichain contract: - -``` -npx hardhat omnichain MyContract -``` - -This command creates a new omnichain contract in `contracts/MyContract.sol`, a -task to deploy the contract in `tasks/deploy.ts`, and a task to interact with -the contract in `tasks/interact.ts`. - -When an omnichain contract is called, it can receive data in the `data` field of -a transaction. This data is passed to the `message` parameter of the contract's -`onCrossChainCall` function. To specify the fields of the `message` parameter, -use positional arguments: - -``` -npx hardhat omnichain MyContract recepient:address description quantity:uint256 -``` - -A field may have a type specified after the field name, separated by a colon. If -no type is specified, the type defaults to `bytes32`. - -Learn more about omnichain contracts by following the -[tutorials](https://www.zetachain.com/docs/developers/omnichain/tutorials/hello/). - -### Tracking a Cross-Chain Transaction - -After broadcasting a cross-chain transaction on a connected chain either to a -cross-chain messaging contract or to trigger an omnichain contract, you can -track its status: - -``` -npx hardhat cctx --tx TX_HASH -``` - -### Verifying a Contract - -To verify a contract deployed on ZetaChain: - -``` -npx hardhat verify:zeta --contract ADDRESS -``` - -Select the contract to verify: - -``` -? Select a contract to verify: (Use arrow keys) - @zetachain/zevm-protocol-contracts/contracts/interfaces/IZRC20.sol:IZRC20 - @zetachain/zevm-protocol-contracts/contracts/interfaces/zContract.sol:zContract -❯ contracts/Withdraw.sol:Withdraw -``` - -After the confirmation the contract will be verified. - -### Sending Tokens - -Sending ZETA from ZetaChain to Goerli: - -``` -npx hardhat send-zeta --amount 1 --network zeta_testnet --destination goerli_testnet -``` - -Sending ZETA from Goerli to ZetaChain: - -``` -npx hardhat send-zeta --amount 1 --network goerli_testnet --destination zeta_testnet -``` - -Depositing gETH to ZetaChain as ZRC-20: - -``` -npx hardhat send-zrc20 --amount 1 --network goerli_testnet --destination zeta_testnet -``` - -Withdrawing ZRC-20 from ZetaChain go Goerli as gETH: - -``` -npx hardhat send-zrc20 --amount 1 --network zeta_testnet --destination goerli_testnet -``` - -Depositing tBTC from the Bitcoin testnet to ZetaChain: - -``` -npx hardhat send-btc --amount 1 --recipient TSS_ADDRESS --memo RECIPIENT_ADDRESS_WITHOUT_0x -``` +This template includes Hardhat tasks that streamline smart contract development. +Learn more about the template and the functionality it provides +[in the docs](https://www.zetachain.com/docs/developers/template/). ## Next Steps To learn more about building decentralized apps on ZetaChain, follow the tutorials available in -[the documentation](https://www.zetachain.com/docs/developers/overview/). +[the introduction to ZetaChain](https://www.zetachain.com/docs/developers/overview/). diff --git a/messaging/message/contracts/CrossChainMessage.sol b/messaging/message/contracts/CrossChainMessage.sol index 62f1e483..720536b9 100644 --- a/messaging/message/contracts/CrossChainMessage.sol +++ b/messaging/message/contracts/CrossChainMessage.sol @@ -7,29 +7,19 @@ import "@zetachain/protocol-contracts/contracts/evm/tools/ZetaInteractor.sol"; import "@zetachain/protocol-contracts/contracts/evm/interfaces/ZetaInterfaces.sol"; contract CrossChainMessage is ZetaInteractor, ZetaReceiver { - error InvalidMessageType(); event CrossChainMessageEvent(string); event CrossChainMessageRevertedEvent(string); - bytes32 public constant CROSS_CHAIN_MESSAGE_MESSAGE_TYPE = - keccak256("CROSS_CHAIN_CROSS_CHAIN_MESSAGE"); ZetaTokenConsumer private immutable _zetaConsumer; IERC20 internal immutable _zetaToken; - constructor( - address connectorAddress, - address zetaTokenAddress, - address zetaConsumerAddress - ) ZetaInteractor(connectorAddress) { + constructor(address connectorAddress, address zetaTokenAddress, address zetaConsumerAddress) ZetaInteractor(connectorAddress) { _zetaToken = IERC20(zetaTokenAddress); _zetaConsumer = ZetaTokenConsumer(zetaConsumerAddress); } - function sendMessage( - uint256 destinationChainId, - string memory message - ) external payable { + function sendMessage(uint256 destinationChainId, string memory message) external payable { if (!_isValidChainId(destinationChainId)) revert InvalidDestinationChainId(); @@ -44,38 +34,33 @@ contract CrossChainMessage is ZetaInteractor, ZetaReceiver { destinationChainId: destinationChainId, destinationAddress: interactorsByChainId[destinationChainId], destinationGasLimit: 300000, - message: abi.encode(CROSS_CHAIN_MESSAGE_MESSAGE_TYPE, message), + message: abi.encode(message), zetaValueAndGas: zetaValueAndGas, zetaParams: abi.encode("") }) ); } + function onZetaMessage( ZetaInterfaces.ZetaMessage calldata zetaMessage ) external override isValidMessageCall(zetaMessage) { - (bytes32 messageType, string memory message) = abi.decode( - zetaMessage.message, - (bytes32, string) + (string memory message ) = abi.decode( + zetaMessage.message, (string) ); - if (messageType != CROSS_CHAIN_MESSAGE_MESSAGE_TYPE) - revert InvalidMessageType(); - emit CrossChainMessageEvent(message); } function onZetaRevert( ZetaInterfaces.ZetaRevert calldata zetaRevert ) external override isValidRevertCall(zetaRevert) { - (bytes32 messageType, string memory message) = abi.decode( + (string memory message) = abi.decode( zetaRevert.message, - (bytes32, string) + (string) ); - if (messageType != CROSS_CHAIN_MESSAGE_MESSAGE_TYPE) - revert InvalidMessageType(); - emit CrossChainMessageRevertedEvent(message); } + } diff --git a/messaging/message/hardhat.config.ts b/messaging/message/hardhat.config.ts index 73d918f0..b28f6f15 100644 --- a/messaging/message/hardhat.config.ts +++ b/messaging/message/hardhat.config.ts @@ -9,10 +9,6 @@ import { HardhatUserConfig } from "hardhat/config"; const config: HardhatUserConfig = { networks: { ...getHardhatConfigNetworks(), - bsc_testnet: { - ...getHardhatConfigNetworks().bsc_testnet, - url: "https://bsc-testnet.blockpi.network/v1/rpc/public", - }, }, solidity: "0.8.7", }; diff --git a/messaging/message/package.json b/messaging/message/package.json index 4ee4d6d3..01eff927 100644 --- a/messaging/message/package.json +++ b/messaging/message/package.json @@ -26,7 +26,7 @@ "@types/node": ">=12.0.0", "@typescript-eslint/eslint-plugin": "^5.59.9", "@typescript-eslint/parser": "^5.59.9", - "@zetachain/toolkit": "6.0.0", + "@zetachain/toolkit": "7.0.0", "axios": "^1.3.6", "chai": "^4.2.0", "dotenv": "^16.0.3", diff --git a/messaging/message/tasks/deploy.ts b/messaging/message/tasks/deploy.ts index 0441a14b..b3ff75e9 100644 --- a/messaging/message/tasks/deploy.ts +++ b/messaging/message/tasks/deploy.ts @@ -2,7 +2,7 @@ import { getAddress } from "@zetachain/protocol-contracts"; import { ethers } from "ethers"; import { task, types } from "hardhat/config"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import { getSupportedNetworks } from "@zetachain/networks"; +import type { ParamChainName } from "@zetachain/protocol-contracts"; const contractName = "CrossChainMessage"; @@ -10,7 +10,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const networks = args.networks.split(","); const contracts: { [key: string]: string } = {}; await Promise.all( - networks.map(async (networkName: string) => { + networks.map(async (networkName: ParamChainName) => { contracts[networkName] = await deployContract( hre, networkName, @@ -21,7 +21,13 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { ); for (const source in contracts) { - await setInteractors(hre, source, contracts, args.json, args.gasLimit); + await setInteractors( + hre, + source as ParamChainName, + contracts, + args.json, + args.gasLimit + ); } if (args.json) { @@ -29,7 +35,10 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { } }; -const initWallet = (hre: HardhatRuntimeEnvironment, networkName: string) => { +const initWallet = ( + hre: HardhatRuntimeEnvironment, + networkName: ParamChainName +) => { const { url } = hre.config.networks[networkName] as any; const provider = new ethers.providers.JsonRpcProvider(url); const wallet = new ethers.Wallet(process.env.PRIVATE_KEY as string, provider); @@ -39,36 +48,24 @@ const initWallet = (hre: HardhatRuntimeEnvironment, networkName: string) => { const deployContract = async ( hre: HardhatRuntimeEnvironment, - networkName: string, + networkName: ParamChainName, json: boolean = false, gasLimit: number ) => { const wallet = initWallet(hre, networkName); - const connector = getAddress("connector", networkName as any); - const zetaToken = getAddress("zetaToken", networkName as any); - const zetaTokenConsumerUniV2 = getAddress( - "zetaTokenConsumerUniV2", - networkName as any - ); - const zetaTokenConsumerUniV3 = getAddress( - "zetaTokenConsumerUniV3", - networkName as any - ); + const connector = getAddress("connector", networkName); + const zetaToken = getAddress("zetaToken", networkName); + const zetaTokenConsumer = getAddress("zetaTokenConsumerUniV3", networkName); const { abi, bytecode } = await hre.artifacts.readArtifact(contractName); const factory = new ethers.ContractFactory(abi, bytecode, wallet); - const contract = await factory.deploy( - connector, - zetaToken, - zetaTokenConsumerUniV2 || zetaTokenConsumerUniV3, - { gasLimit } - ); + const contract = await factory.deploy(connector, zetaToken, zetaTokenConsumer, { gasLimit }); await contract.deployed(); if (!json) { console.log(` -🚀 Successfully deployed contract on ${networkName}. +🚀 Successfully deployed contract on ${networkName} 📜 Contract address: ${contract.address}`); } return contract.address; @@ -76,7 +73,7 @@ const deployContract = async ( const setInteractors = async ( hre: HardhatRuntimeEnvironment, - source: string, + source: ParamChainName, contracts: { [key: string]: string }, json: boolean = false, gasLimit: number @@ -94,7 +91,7 @@ const setInteractors = async ( for (const counterparty in contracts) { if (counterparty === source) continue; - const counterpartyContract = hre.ethers.utils.solidityPack( + const counterpartyContract = ethers.utils.solidityPack( ["address"], [contracts[counterparty]] ); @@ -113,11 +110,6 @@ const setInteractors = async ( }; task("deploy", "Deploy the contract", main) - .addParam( - "networks", - `Comma separated list of networks to deploy to (e.g. ${getSupportedNetworks( - "ccm" - )})` - ) + .addParam("networks", "Comma separated list of networks to deploy to") .addOptionalParam("gasLimit", "Gas limit", 10000000, types.int) .addFlag("json", "Output JSON"); diff --git a/messaging/message/tasks/interact.ts b/messaging/message/tasks/interact.ts index 4b95326f..472f5d47 100644 --- a/messaging/message/tasks/interact.ts +++ b/messaging/message/tasks/interact.ts @@ -17,6 +17,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const value = parseEther(args.amount); + const tx = await contract .connect(signer) .sendMessage(destination, paramMessage, { value }); @@ -37,4 +38,4 @@ task("interact", "Sends a message from one chain to another.", main) .addParam("contract", "Contract address") .addParam("amount", "Token amount to send") .addParam("destination", "Destination chain") - .addParam("message", "string"); + .addParam("message", "string") diff --git a/messaging/message/tsconfig.json b/messaging/message/tsconfig.json index 574e785c..fb0567b3 100644 --- a/messaging/message/tsconfig.json +++ b/messaging/message/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { - "target": "es2020", - "module": "commonjs", + "module": "nodenext", + "moduleResolution": "nodenext", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, diff --git a/messaging/message/yarn.lock b/messaging/message/yarn.lock index 90dd53c5..5adafe6f 100644 --- a/messaging/message/yarn.lock +++ b/messaging/message/yarn.lock @@ -777,11 +777,6 @@ "@ethersproject/properties" "^5.7.0" "@ethersproject/strings" "^5.7.0" -"@fastify/busboy@^2.0.0": - version "2.1.1" - resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d" - integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA== - "@humanwhocodes/config-array@^0.11.10": version "0.11.10" resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.10.tgz#5a3ffe32cc9306365fb3fd572596cd602d5e12d2" @@ -1283,7 +1278,7 @@ table "^6.8.0" undici "^5.14.0" -"@openzeppelin/contracts@^4.9.2": +"@openzeppelin/contracts@^4.9.6": version "4.9.6" resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.6.tgz#2a880a24eb19b4f8b25adc2a5095f2aa27f39677" integrity sha512-xSmezSupL+y9VkHZJGDoCBpmnB2ogM13ccaYDWqJTfS3dbuHkgjuwDFUmaFauBCboQMGB/S5UqUl2y54X99BmA== @@ -1704,10 +1699,10 @@ typescript "5.0.4" zod "3.19.1" -"@zetachain/networks@6.0.0": - version "6.0.0" - resolved "https://registry.yarnpkg.com/@zetachain/networks/-/networks-6.0.0.tgz#ae5d3cd1678b32510edfaa71f8f4a6f4cbc1d9ab" - integrity sha512-yKFVP/yJDp76Q5lBGfZSpY/KO3TZ9ldo0lhE4MpBW43EsBxOZWixg6sqb56mcU/gg1lbWG8sHHWtYFK51SByjQ== +"@zetachain/networks@7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@zetachain/networks/-/networks-7.0.0.tgz#a5f8a188d633e2064ee7c77499351381ba891441" + integrity sha512-/amSq+KNJe+EGj0ioZS+DZJtsnbPSDotp9LsrAbaEVMAxKvBK/XkvggH73sJyRWWeMpfhHrNPlrKTLrN+mRkIg== dependencies: dotenv "^16.1.4" @@ -1716,18 +1711,18 @@ resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-7.0.0-rc1.tgz#588483d1ec70e572b7e40e84ef5b34282b0ab375" integrity sha512-vgS+Pjh4MysOyw8WbqTQVBsHJYqKvMcdV7cNVqxaTJd/dl2ak7NNvsIeaeUnxQrp8XfQol2B8GXJpVLM6MK/dg== -"@zetachain/toolkit@6.0.0": - version "6.0.0" - resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-6.0.0.tgz#385cfd11f1ac39cbb6ca6410109523e2ab6f8841" - integrity sha512-JAtl7CX8cMJ+iw/byjcbLqgCfPS87vkdYCZOPBBOudqUySPTz4owqVgGZB/xYRyXBsF0KW0F6R65sc+fleQ86A== +"@zetachain/toolkit@7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-7.0.0.tgz#7301ccab40c37d3fd8fcc347f99c831ec31b1bd3" + integrity sha512-5cOJVBIEcosF2A2TJbNGFfh4Bob8UcodQII1RdHRstqvV3toZ18r1gVWpLGQ8w2N6T2FCPE8ueN4Q5zH68q20Q== dependencies: "@inquirer/prompts" "^2.1.1" "@inquirer/select" "1.1.3" "@nomiclabs/hardhat-ethers" "^2.2.3" - "@openzeppelin/contracts" "^4.9.2" + "@openzeppelin/contracts" "^4.9.6" "@uniswap/v2-periphery" "^1.1.0-beta.0" "@zetachain/faucet-cli" "^4.0.1" - "@zetachain/networks" "6.0.0" + "@zetachain/networks" "7.0.0" "@zetachain/protocol-contracts" "7.0.0-rc1" axios "^1.4.0" bech32 "^2.0.0" @@ -2088,9 +2083,9 @@ axios@1.2.3: proxy-from-env "^1.1.0" axios@^1.3.6, axios@^1.4.0: - version "1.6.1" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.1.tgz#76550d644bf0a2d469a01f9244db6753208397d7" - integrity sha512-vfBmhDpKafglh0EldBEbVuoe7DyAavGSLWhuSm5ZSEKQnHhBf0xAAwybbNH1IkrJNGnS/VG4I5yxig1pCEXE4g== + version "1.4.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.4.0.tgz#38a7bf1224cd308de271146038b551d725f0be1f" + integrity sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA== dependencies: follow-redirects "^1.15.0" form-data "^4.0.0" @@ -2309,6 +2304,13 @@ buffer@^6.0.3: base64-js "^1.3.1" ieee754 "^1.2.1" +busboy@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/busboy/-/busboy-1.6.0.tgz#966ea36a9502e43cdb9146962523b92f531f6893" + integrity sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA== + dependencies: + streamsearch "^1.1.0" + bytes@3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.2.tgz#8b0beeb98605adf1b128fa4386403c009e0221a5" @@ -3572,9 +3574,9 @@ flatted@^3.1.0: integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ== follow-redirects@^1.12.1, follow-redirects@^1.15.0: - version "1.15.6" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" - integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== + version "1.15.2" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" + integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== for-each@^0.3.3: version "0.3.3" @@ -3715,9 +3717,9 @@ get-caller-file@^2.0.1, get-caller-file@^2.0.5: integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== get-func-name@^2.0.0: - version "2.0.2" - resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.2.tgz#0d7cf20cd13fda808669ffa88f4ffc7a3943fc41" - integrity sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ== + version "2.0.0" + resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41" + integrity sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig== get-intrinsic@^1.0.2, get-intrinsic@^1.1.1, get-intrinsic@^1.1.3, get-intrinsic@^1.2.0, get-intrinsic@^1.2.1: version "1.2.1" @@ -5965,6 +5967,11 @@ stealthy-require@^1.1.1: resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b" integrity sha512-ZnWpYnYugiOVEY5GkcuJK1io5V8QmNYChG62gSit9pQVGErXtrKuPC55ITaVSukmMta5qpMU7vqLt2Lnni4f/g== +streamsearch@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764" + integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg== + string-format@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/string-format/-/string-format-2.0.0.tgz#f2df2e7097440d3b65de31b6d40d54c96eaffb9b" @@ -6446,11 +6453,11 @@ unbox-primitive@^1.0.2: which-boxed-primitive "^1.0.2" undici@^5.14.0: - version "5.28.4" - resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068" - integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g== + version "5.23.0" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.23.0.tgz#e7bdb0ed42cebe7b7aca87ced53e6eaafb8f8ca0" + integrity sha512-1D7w+fvRsqlQ9GscLBwcAJinqcZGHUKjbOmXdlE/v8BvEGXjeWAax+341q44EuTcHXXnfyKNbKRq4Lg7OzhMmg== dependencies: - "@fastify/busboy" "^2.0.0" + busboy "^1.6.0" universalify@^0.1.0: version "0.1.2" diff --git a/messaging/value/.eslintignore b/messaging/nft/.eslintignore similarity index 100% rename from messaging/value/.eslintignore rename to messaging/nft/.eslintignore diff --git a/messaging/value/.eslintrc.js b/messaging/nft/.eslintrc.js similarity index 100% rename from messaging/value/.eslintrc.js rename to messaging/nft/.eslintrc.js diff --git a/messaging/value/.gitignore b/messaging/nft/.gitignore similarity index 100% rename from messaging/value/.gitignore rename to messaging/nft/.gitignore diff --git a/messaging/value/LICENSE b/messaging/nft/LICENSE similarity index 100% rename from messaging/value/LICENSE rename to messaging/nft/LICENSE diff --git a/messaging/nft/README.md b/messaging/nft/README.md new file mode 100644 index 00000000..59b7739e --- /dev/null +++ b/messaging/nft/README.md @@ -0,0 +1,30 @@ +# Hardhat Template for ZetaChain + +This is a simple Hardhat template that provides a starting point for developing +smart contract applications on ZetaChain. + +## Prerequisites + +Before getting started, ensure that you have +[Node.js](https://nodejs.org/en/download) (version 18 or above) and +[Yarn](https://yarnpkg.com/) installed on your system. + +## Getting Started + +To get started, install the necessary dependencies: + +``` +yarn +``` + +## Hardhat Tasks + +This template includes Hardhat tasks that streamline smart contract development. +Learn more about the template and the functionality it provides +[in the docs](https://www.zetachain.com/docs/developers/template/). + +## Next Steps + +To learn more about building decentralized apps on ZetaChain, follow the +tutorials available in +[the introduction to ZetaChain](https://www.zetachain.com/docs/developers/overview/). diff --git a/messaging/warriors/contracts/CrossChainWarriors.sol b/messaging/nft/contracts/CrossChainNFT.sol similarity index 50% rename from messaging/warriors/contracts/CrossChainWarriors.sol rename to messaging/nft/contracts/CrossChainNFT.sol index 151a6412..57977cd4 100644 --- a/messaging/warriors/contracts/CrossChainWarriors.sol +++ b/messaging/nft/contracts/CrossChainNFT.sol @@ -6,24 +6,18 @@ import "@openzeppelin/contracts/access/Ownable.sol"; import "@zetachain/protocol-contracts/contracts/evm/tools/ZetaInteractor.sol"; import "@zetachain/protocol-contracts/contracts/evm/interfaces/ZetaInterfaces.sol"; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; -import "@openzeppelin/contracts/utils/Counters.sol"; -contract CrossChainWarriors is +contract CrossChainNFT is + ERC721("CrossChainNFT", "CCNFT"), ZetaInteractor, - ZetaReceiver, - ERC721("CrossChainWarriors", "CCWAR") + ZetaReceiver { - error InvalidMessageType(); + event CrossChainNFTEvent(address, uint256); + event CrossChainNFTRevertedEvent(address, uint256); - event CrossChainWarriorsEvent(uint256, address, address); - event CrossChainWarriorsRevertedEvent(uint256, address, address); - - using Counters for Counters.Counter; - Counters.Counter public tokenIds; - bytes32 public constant CROSS_CHAIN_WARRIORS_MESSAGE_TYPE = - keccak256("CROSS_CHAIN_CROSS_CHAIN_WARRIORS"); ZetaTokenConsumer private immutable _zetaConsumer; IERC20 internal immutable _zetaToken; + uint256 private _tokenIds; constructor( address connectorAddress, @@ -34,32 +28,14 @@ contract CrossChainWarriors is _zetaToken = IERC20(zetaTokenAddress); _zetaConsumer = ZetaTokenConsumer(zetaConsumerAddress); - tokenIds.increment(); - if (useEven) tokenIds.increment(); - } - - function mint(address to) public returns (uint256) { - uint256 newWarriorId = tokenIds.current(); - - tokenIds.increment(); - tokenIds.increment(); - - _safeMint(to, newWarriorId); - return newWarriorId; - } - - function _mintId(address to, uint256 tokenId) internal { - _safeMint(to, tokenId); - } - - function _burnWarrior(uint256 burnedWarriorId) internal { - _burn(burnedWarriorId); + _tokenIds++; + if (useEven) _tokenIds++; } function sendMessage( uint256 destinationChainId, - uint256 token, - address to + address to, + uint256 token ) external payable { if (!_isValidChainId(destinationChainId)) revert InvalidDestinationChainId(); @@ -70,19 +46,14 @@ contract CrossChainWarriors is }(address(this), crossChainGas); _zetaToken.approve(address(connector), zetaValueAndGas); - _burnWarrior(token); + _burn(token); connector.send( ZetaInterfaces.SendInput({ destinationChainId: destinationChainId, destinationAddress: interactorsByChainId[destinationChainId], destinationGasLimit: 300000, - message: abi.encode( - CROSS_CHAIN_WARRIORS_MESSAGE_TYPE, - token, - msg.sender, - to - ), + message: abi.encode(to, token, msg.sender), zetaValueAndGas: zetaValueAndGas, zetaParams: abi.encode("") }) @@ -92,28 +63,34 @@ contract CrossChainWarriors is function onZetaMessage( ZetaInterfaces.ZetaMessage calldata zetaMessage ) external override isValidMessageCall(zetaMessage) { - (bytes32 messageType, uint256 token, address sender, address to) = abi - .decode(zetaMessage.message, (bytes32, uint256, address, address)); - - if (messageType != CROSS_CHAIN_WARRIORS_MESSAGE_TYPE) - revert InvalidMessageType(); + (address to, uint256 token) = abi.decode( + zetaMessage.message, + (address, uint256) + ); - _mintId(to, token); + _safeMint(to, token); - emit CrossChainWarriorsEvent(token, sender, to); + emit CrossChainNFTEvent(to, token); } function onZetaRevert( ZetaInterfaces.ZetaRevert calldata zetaRevert ) external override isValidRevertCall(zetaRevert) { - (bytes32 messageType, uint256 token, address sender, address to) = abi - .decode(zetaRevert.message, (bytes32, uint256, address, address)); + (address to, uint256 token, address from) = abi.decode( + zetaRevert.message, + (address, uint256, address) + ); + + _safeMint(from, token); - if (messageType != CROSS_CHAIN_WARRIORS_MESSAGE_TYPE) - revert InvalidMessageType(); + emit CrossChainNFTRevertedEvent(to, token); + } - _mintId(to, token); + function mint(address to) public returns (uint256) { + _tokenIds++; + _tokenIds++; - emit CrossChainWarriorsRevertedEvent(token, sender, to); + _safeMint(to, _tokenIds); + return _tokenIds; } } diff --git a/messaging/warriors/hardhat.config.ts b/messaging/nft/hardhat.config.ts similarity index 100% rename from messaging/warriors/hardhat.config.ts rename to messaging/nft/hardhat.config.ts diff --git a/messaging/value/package.json b/messaging/nft/package.json similarity index 97% rename from messaging/value/package.json rename to messaging/nft/package.json index 4ee4d6d3..01eff927 100644 --- a/messaging/value/package.json +++ b/messaging/nft/package.json @@ -26,7 +26,7 @@ "@types/node": ">=12.0.0", "@typescript-eslint/eslint-plugin": "^5.59.9", "@typescript-eslint/parser": "^5.59.9", - "@zetachain/toolkit": "6.0.0", + "@zetachain/toolkit": "7.0.0", "axios": "^1.3.6", "chai": "^4.2.0", "dotenv": "^16.0.3", diff --git a/messaging/warriors/tasks/deploy.ts b/messaging/nft/tasks/deploy.ts similarity index 70% rename from messaging/warriors/tasks/deploy.ts rename to messaging/nft/tasks/deploy.ts index f569b654..6e4d26db 100644 --- a/messaging/warriors/tasks/deploy.ts +++ b/messaging/nft/tasks/deploy.ts @@ -2,9 +2,9 @@ import { getAddress } from "@zetachain/protocol-contracts"; import { ethers } from "ethers"; import { task, types } from "hardhat/config"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import { getSupportedNetworks } from "@zetachain/networks"; +import type { ParamChainName } from "@zetachain/protocol-contracts"; -const contractName = "CrossChainWarriors"; +const contractName = "CrossChainNFT"; const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const networks = args.networks.split(","); @@ -14,7 +14,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const parity = i % 2 == 0; contracts[networkName] = await deployContract( hre, - networkName, + networkName as ParamChainName, parity, args.json, args.gasLimit @@ -23,7 +23,13 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { ); for (const source in contracts) { - await setInteractors(hre, source, contracts, args.json, args.gasLimit); + await setInteractors( + hre, + source as ParamChainName, + contracts, + args.json, + args.gasLimit + ); } if (args.json) { @@ -31,7 +37,10 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { } }; -const initWallet = (hre: HardhatRuntimeEnvironment, networkName: string) => { +const initWallet = ( + hre: HardhatRuntimeEnvironment, + networkName: ParamChainName +) => { const { url } = hre.config.networks[networkName] as any; const provider = new ethers.providers.JsonRpcProvider(url); const wallet = new ethers.Wallet(process.env.PRIVATE_KEY as string, provider); @@ -41,38 +50,25 @@ const initWallet = (hre: HardhatRuntimeEnvironment, networkName: string) => { const deployContract = async ( hre: HardhatRuntimeEnvironment, - networkName: string, + networkName: ParamChainName, parity: boolean, json: boolean = false, gasLimit: number ) => { const wallet = initWallet(hre, networkName); - const connector = getAddress("connector", networkName as any); - const zetaToken = getAddress("zetaToken", networkName as any); - const zetaTokenConsumerUniV2 = getAddress( - "zetaTokenConsumerUniV2", - networkName as any - ); - const zetaTokenConsumerUniV3 = getAddress( - "zetaTokenConsumerUniV3", - networkName as any - ); + const connector = getAddress("connector", networkName); + const zetaToken = getAddress("zetaToken", networkName); + const zetaTokenConsumer = getAddress("zetaTokenConsumerUniV3", networkName); const { abi, bytecode } = await hre.artifacts.readArtifact(contractName); const factory = new ethers.ContractFactory(abi, bytecode, wallet); - const contract = await factory.deploy( - connector, - zetaToken, - zetaTokenConsumerUniV2 || zetaTokenConsumerUniV3, - parity, - { gasLimit } - ); + const contract = await factory.deploy(connector, zetaToken, zetaTokenConsumer, parity, { gasLimit }); await contract.deployed(); if (!json) { console.log(` -🚀 Successfully deployed contract on ${networkName}. +🚀 Successfully deployed contract on ${networkName} 📜 Contract address: ${contract.address}`); } return contract.address; @@ -80,7 +76,7 @@ const deployContract = async ( const setInteractors = async ( hre: HardhatRuntimeEnvironment, - source: string, + source: ParamChainName, contracts: { [key: string]: string }, json: boolean = false, gasLimit: number @@ -98,7 +94,7 @@ const setInteractors = async ( for (const counterparty in contracts) { if (counterparty === source) continue; - const counterpartyContract = hre.ethers.utils.solidityPack( + const counterpartyContract = ethers.utils.solidityPack( ["address"], [contracts[counterparty]] ); @@ -117,11 +113,6 @@ const setInteractors = async ( }; task("deploy", "Deploy the contract", main) - .addParam( - "networks", - `Comma separated list of networks to deploy to (e.g. ${getSupportedNetworks( - "ccm" - )})` - ) + .addParam("networks", "Comma separated list of networks to deploy to") .addOptionalParam("gasLimit", "Gas limit", 10000000, types.int) .addFlag("json", "Output JSON"); diff --git a/messaging/warriors/tasks/interact.ts b/messaging/nft/tasks/interact.ts similarity index 88% rename from messaging/warriors/tasks/interact.ts rename to messaging/nft/tasks/interact.ts index 3faa6c16..a3a595e6 100644 --- a/messaging/warriors/tasks/interact.ts +++ b/messaging/nft/tasks/interact.ts @@ -5,7 +5,7 @@ import { parseEther } from "@ethersproject/units"; const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const [signer] = await hre.ethers.getSigners(); - const factory = await hre.ethers.getContractFactory("CrossChainWarriors"); + const factory = await hre.ethers.getContractFactory("CrossChainNFT"); const contract = factory.attach(args.contract); const destination = hre.config.networks[args.destination]?.chainId; @@ -13,14 +13,15 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { throw new Error(`${args.destination} is not a valid destination chain`); } - const paramToken = hre.ethers.BigNumber.from(args.token); const paramTo = hre.ethers.utils.getAddress(args.to); +const paramToken = hre.ethers.BigNumber.from(args.token); const value = parseEther(args.amount); + const tx = await contract .connect(signer) - .sendMessage(destination, paramToken, paramTo, { value }); + .sendMessage(destination, paramTo, paramToken, { value }); const receipt = await tx.wait(); if (args.json) { @@ -38,5 +39,5 @@ task("interact", "Sends a message from one chain to another.", main) .addParam("contract", "Contract address") .addParam("amount", "Token amount to send") .addParam("destination", "Destination chain") + .addParam("to", "address") .addParam("token", "uint256") - .addParam("to", "address"); diff --git a/messaging/warriors/tasks/mint.ts b/messaging/nft/tasks/mint.ts similarity index 95% rename from messaging/warriors/tasks/mint.ts rename to messaging/nft/tasks/mint.ts index 6484d600..95fc1e1a 100644 --- a/messaging/warriors/tasks/mint.ts +++ b/messaging/nft/tasks/mint.ts @@ -1,7 +1,7 @@ import { task } from "hardhat/config"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -const contractName = "CrossChainWarriors"; +const contractName = "CrossChainNFT"; const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const [signer] = await hre.ethers.getSigners(); diff --git a/messaging/value/tsconfig.json b/messaging/nft/tsconfig.json similarity index 74% rename from messaging/value/tsconfig.json rename to messaging/nft/tsconfig.json index 574e785c..fb0567b3 100644 --- a/messaging/value/tsconfig.json +++ b/messaging/nft/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { - "target": "es2020", - "module": "commonjs", + "module": "nodenext", + "moduleResolution": "nodenext", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, diff --git a/messaging/value/yarn.lock b/messaging/nft/yarn.lock similarity index 99% rename from messaging/value/yarn.lock rename to messaging/nft/yarn.lock index 90dd53c5..5adafe6f 100644 --- a/messaging/value/yarn.lock +++ b/messaging/nft/yarn.lock @@ -777,11 +777,6 @@ "@ethersproject/properties" "^5.7.0" "@ethersproject/strings" "^5.7.0" -"@fastify/busboy@^2.0.0": - version "2.1.1" - resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d" - integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA== - "@humanwhocodes/config-array@^0.11.10": version "0.11.10" resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.10.tgz#5a3ffe32cc9306365fb3fd572596cd602d5e12d2" @@ -1283,7 +1278,7 @@ table "^6.8.0" undici "^5.14.0" -"@openzeppelin/contracts@^4.9.2": +"@openzeppelin/contracts@^4.9.6": version "4.9.6" resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.6.tgz#2a880a24eb19b4f8b25adc2a5095f2aa27f39677" integrity sha512-xSmezSupL+y9VkHZJGDoCBpmnB2ogM13ccaYDWqJTfS3dbuHkgjuwDFUmaFauBCboQMGB/S5UqUl2y54X99BmA== @@ -1704,10 +1699,10 @@ typescript "5.0.4" zod "3.19.1" -"@zetachain/networks@6.0.0": - version "6.0.0" - resolved "https://registry.yarnpkg.com/@zetachain/networks/-/networks-6.0.0.tgz#ae5d3cd1678b32510edfaa71f8f4a6f4cbc1d9ab" - integrity sha512-yKFVP/yJDp76Q5lBGfZSpY/KO3TZ9ldo0lhE4MpBW43EsBxOZWixg6sqb56mcU/gg1lbWG8sHHWtYFK51SByjQ== +"@zetachain/networks@7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@zetachain/networks/-/networks-7.0.0.tgz#a5f8a188d633e2064ee7c77499351381ba891441" + integrity sha512-/amSq+KNJe+EGj0ioZS+DZJtsnbPSDotp9LsrAbaEVMAxKvBK/XkvggH73sJyRWWeMpfhHrNPlrKTLrN+mRkIg== dependencies: dotenv "^16.1.4" @@ -1716,18 +1711,18 @@ resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-7.0.0-rc1.tgz#588483d1ec70e572b7e40e84ef5b34282b0ab375" integrity sha512-vgS+Pjh4MysOyw8WbqTQVBsHJYqKvMcdV7cNVqxaTJd/dl2ak7NNvsIeaeUnxQrp8XfQol2B8GXJpVLM6MK/dg== -"@zetachain/toolkit@6.0.0": - version "6.0.0" - resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-6.0.0.tgz#385cfd11f1ac39cbb6ca6410109523e2ab6f8841" - integrity sha512-JAtl7CX8cMJ+iw/byjcbLqgCfPS87vkdYCZOPBBOudqUySPTz4owqVgGZB/xYRyXBsF0KW0F6R65sc+fleQ86A== +"@zetachain/toolkit@7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-7.0.0.tgz#7301ccab40c37d3fd8fcc347f99c831ec31b1bd3" + integrity sha512-5cOJVBIEcosF2A2TJbNGFfh4Bob8UcodQII1RdHRstqvV3toZ18r1gVWpLGQ8w2N6T2FCPE8ueN4Q5zH68q20Q== dependencies: "@inquirer/prompts" "^2.1.1" "@inquirer/select" "1.1.3" "@nomiclabs/hardhat-ethers" "^2.2.3" - "@openzeppelin/contracts" "^4.9.2" + "@openzeppelin/contracts" "^4.9.6" "@uniswap/v2-periphery" "^1.1.0-beta.0" "@zetachain/faucet-cli" "^4.0.1" - "@zetachain/networks" "6.0.0" + "@zetachain/networks" "7.0.0" "@zetachain/protocol-contracts" "7.0.0-rc1" axios "^1.4.0" bech32 "^2.0.0" @@ -2088,9 +2083,9 @@ axios@1.2.3: proxy-from-env "^1.1.0" axios@^1.3.6, axios@^1.4.0: - version "1.6.1" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.1.tgz#76550d644bf0a2d469a01f9244db6753208397d7" - integrity sha512-vfBmhDpKafglh0EldBEbVuoe7DyAavGSLWhuSm5ZSEKQnHhBf0xAAwybbNH1IkrJNGnS/VG4I5yxig1pCEXE4g== + version "1.4.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.4.0.tgz#38a7bf1224cd308de271146038b551d725f0be1f" + integrity sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA== dependencies: follow-redirects "^1.15.0" form-data "^4.0.0" @@ -2309,6 +2304,13 @@ buffer@^6.0.3: base64-js "^1.3.1" ieee754 "^1.2.1" +busboy@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/busboy/-/busboy-1.6.0.tgz#966ea36a9502e43cdb9146962523b92f531f6893" + integrity sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA== + dependencies: + streamsearch "^1.1.0" + bytes@3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.2.tgz#8b0beeb98605adf1b128fa4386403c009e0221a5" @@ -3572,9 +3574,9 @@ flatted@^3.1.0: integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ== follow-redirects@^1.12.1, follow-redirects@^1.15.0: - version "1.15.6" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" - integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== + version "1.15.2" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" + integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== for-each@^0.3.3: version "0.3.3" @@ -3715,9 +3717,9 @@ get-caller-file@^2.0.1, get-caller-file@^2.0.5: integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== get-func-name@^2.0.0: - version "2.0.2" - resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.2.tgz#0d7cf20cd13fda808669ffa88f4ffc7a3943fc41" - integrity sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ== + version "2.0.0" + resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41" + integrity sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig== get-intrinsic@^1.0.2, get-intrinsic@^1.1.1, get-intrinsic@^1.1.3, get-intrinsic@^1.2.0, get-intrinsic@^1.2.1: version "1.2.1" @@ -5965,6 +5967,11 @@ stealthy-require@^1.1.1: resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b" integrity sha512-ZnWpYnYugiOVEY5GkcuJK1io5V8QmNYChG62gSit9pQVGErXtrKuPC55ITaVSukmMta5qpMU7vqLt2Lnni4f/g== +streamsearch@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764" + integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg== + string-format@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/string-format/-/string-format-2.0.0.tgz#f2df2e7097440d3b65de31b6d40d54c96eaffb9b" @@ -6446,11 +6453,11 @@ unbox-primitive@^1.0.2: which-boxed-primitive "^1.0.2" undici@^5.14.0: - version "5.28.4" - resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068" - integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g== + version "5.23.0" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.23.0.tgz#e7bdb0ed42cebe7b7aca87ced53e6eaafb8f8ca0" + integrity sha512-1D7w+fvRsqlQ9GscLBwcAJinqcZGHUKjbOmXdlE/v8BvEGXjeWAax+341q44EuTcHXXnfyKNbKRq4Lg7OzhMmg== dependencies: - "@fastify/busboy" "^2.0.0" + busboy "^1.6.0" universalify@^0.1.0: version "0.1.2" diff --git a/messaging/value/README.md b/messaging/value/README.md deleted file mode 100644 index f86c7d35..00000000 --- a/messaging/value/README.md +++ /dev/null @@ -1,183 +0,0 @@ -# Template for a ZetaChain Hardhat Project - -This is a simple Hardhat template that provides a starting point for developing -smart contract applications on the ZetaChain blockchain. - -## Prerequisites - -Before getting started, ensure that you have -[Node.js](https://nodejs.org/en/download) and [Yarn](https://yarnpkg.com/) -installed on your system. - -## Getting Started - -To get started, install the necessary dependencies: - -``` -yarn -``` - -## Hardhat Tasks - -This template includes Hardhat tasks that can be used make it easier to build -with ZetaChain. - -### Generating a Random Wallet - -To generate a random wallet: - -``` -npx hardhat account --save -``` - -This command generates a random wallet, prints information about the wallet to -the terminal, and saves the private key to a `.env` file to make it accessible -to Hardhat. If you don't want to save the wallet (for example, if you just need -an address to send tokens to for testing purposes), you can run the command -without the `--save` flag. - -### Querying for Token Balances - -To query for token balances: - -``` -npx hardhat balances -``` - -This command queries token balances for the account address derived from the -private key specified in the `.env`. - -If you want to query for token balances for a different account, you can use the -`--address` flag: - -``` -npx hardhat balances --address ADDRESS -``` - -### Requesting Tokens from the Faucet - -To request ZETA tokens from the faucet: - -``` -npx hardhat faucet -``` - -This command requests tokens from the faucet for the account address derived -from the private key specified in the `.env`. Tokens sent to the address on -ZetaChain. To specify a different chain use a flag: - -``` -npx hardhat faucet --chain goerli_testnet -``` - -You can also specify a different address to send the tokens to: - -``` -npx hardhat faucet --address ADDRESS -``` - -Alternatively, you can install a standalone faucet CLI: - -``` -yarn global add @zetachain/faucet-cli@athens3 -``` - -You can then use it with the following command: - -``` -zetafaucet -h -``` - -### Creating an Omnichain Contract - -To create a new omnichain contract: - -``` -npx hardhat omnichain MyContract -``` - -This command creates a new omnichain contract in `contracts/MyContract.sol`, a -task to deploy the contract in `tasks/deploy.ts`, and a task to interact with -the contract in `tasks/interact.ts`. - -When an omnichain contract is called, it can receive data in the `data` field of -a transaction. This data is passed to the `message` parameter of the contract's -`onCrossChainCall` function. To specify the fields of the `message` parameter, -use positional arguments: - -``` -npx hardhat omnichain MyContract recepient:address description quantity:uint256 -``` - -A field may have a type specified after the field name, separated by a colon. If -no type is specified, the type defaults to `bytes32`. - -Learn more about omnichain contracts by following the -[tutorials](https://www.zetachain.com/docs/developers/omnichain/tutorials/hello/). - -### Tracking a Cross-Chain Transaction - -After broadcasting a cross-chain transaction on a connected chain either to a -cross-chain messaging contract or to trigger an omnichain contract, you can -track its status: - -``` -npx hardhat cctx --tx TX_HASH -``` - -### Verifying a Contract - -To verify a contract deployed on ZetaChain: - -``` -npx hardhat verify:zeta --contract ADDRESS -``` - -Select the contract to verify: - -``` -? Select a contract to verify: (Use arrow keys) - @zetachain/zevm-protocol-contracts/contracts/interfaces/IZRC20.sol:IZRC20 - @zetachain/zevm-protocol-contracts/contracts/interfaces/zContract.sol:zContract -❯ contracts/Withdraw.sol:Withdraw -``` - -After the confirmation the contract will be verified. - -### Sending Tokens - -Sending ZETA from ZetaChain to Goerli: - -``` -npx hardhat send-zeta --amount 1 --network zeta_testnet --destination goerli_testnet -``` - -Sending ZETA from Goerli to ZetaChain: - -``` -npx hardhat send-zeta --amount 1 --network goerli_testnet --destination zeta_testnet -``` - -Depositing gETH to ZetaChain as ZRC-20: - -``` -npx hardhat send-zrc20 --amount 1 --network goerli_testnet --destination zeta_testnet -``` - -Withdrawing ZRC-20 from ZetaChain go Goerli as gETH: - -``` -npx hardhat send-zrc20 --amount 1 --network zeta_testnet --destination goerli_testnet -``` - -Depositing tBTC from the Bitcoin testnet to ZetaChain: - -``` -npx hardhat send-btc --amount 1 --recipient TSS_ADDRESS --memo RECIPIENT_ADDRESS_WITHOUT_0x -``` - -## Next Steps - -To learn more about building decentralized apps on ZetaChain, follow the -tutorials available in -[the documentation](https://www.zetachain.com/docs/developers/overview/). diff --git a/messaging/warriors/README.md b/messaging/warriors/README.md deleted file mode 100644 index f86c7d35..00000000 --- a/messaging/warriors/README.md +++ /dev/null @@ -1,183 +0,0 @@ -# Template for a ZetaChain Hardhat Project - -This is a simple Hardhat template that provides a starting point for developing -smart contract applications on the ZetaChain blockchain. - -## Prerequisites - -Before getting started, ensure that you have -[Node.js](https://nodejs.org/en/download) and [Yarn](https://yarnpkg.com/) -installed on your system. - -## Getting Started - -To get started, install the necessary dependencies: - -``` -yarn -``` - -## Hardhat Tasks - -This template includes Hardhat tasks that can be used make it easier to build -with ZetaChain. - -### Generating a Random Wallet - -To generate a random wallet: - -``` -npx hardhat account --save -``` - -This command generates a random wallet, prints information about the wallet to -the terminal, and saves the private key to a `.env` file to make it accessible -to Hardhat. If you don't want to save the wallet (for example, if you just need -an address to send tokens to for testing purposes), you can run the command -without the `--save` flag. - -### Querying for Token Balances - -To query for token balances: - -``` -npx hardhat balances -``` - -This command queries token balances for the account address derived from the -private key specified in the `.env`. - -If you want to query for token balances for a different account, you can use the -`--address` flag: - -``` -npx hardhat balances --address ADDRESS -``` - -### Requesting Tokens from the Faucet - -To request ZETA tokens from the faucet: - -``` -npx hardhat faucet -``` - -This command requests tokens from the faucet for the account address derived -from the private key specified in the `.env`. Tokens sent to the address on -ZetaChain. To specify a different chain use a flag: - -``` -npx hardhat faucet --chain goerli_testnet -``` - -You can also specify a different address to send the tokens to: - -``` -npx hardhat faucet --address ADDRESS -``` - -Alternatively, you can install a standalone faucet CLI: - -``` -yarn global add @zetachain/faucet-cli@athens3 -``` - -You can then use it with the following command: - -``` -zetafaucet -h -``` - -### Creating an Omnichain Contract - -To create a new omnichain contract: - -``` -npx hardhat omnichain MyContract -``` - -This command creates a new omnichain contract in `contracts/MyContract.sol`, a -task to deploy the contract in `tasks/deploy.ts`, and a task to interact with -the contract in `tasks/interact.ts`. - -When an omnichain contract is called, it can receive data in the `data` field of -a transaction. This data is passed to the `message` parameter of the contract's -`onCrossChainCall` function. To specify the fields of the `message` parameter, -use positional arguments: - -``` -npx hardhat omnichain MyContract recepient:address description quantity:uint256 -``` - -A field may have a type specified after the field name, separated by a colon. If -no type is specified, the type defaults to `bytes32`. - -Learn more about omnichain contracts by following the -[tutorials](https://www.zetachain.com/docs/developers/omnichain/tutorials/hello/). - -### Tracking a Cross-Chain Transaction - -After broadcasting a cross-chain transaction on a connected chain either to a -cross-chain messaging contract or to trigger an omnichain contract, you can -track its status: - -``` -npx hardhat cctx --tx TX_HASH -``` - -### Verifying a Contract - -To verify a contract deployed on ZetaChain: - -``` -npx hardhat verify:zeta --contract ADDRESS -``` - -Select the contract to verify: - -``` -? Select a contract to verify: (Use arrow keys) - @zetachain/zevm-protocol-contracts/contracts/interfaces/IZRC20.sol:IZRC20 - @zetachain/zevm-protocol-contracts/contracts/interfaces/zContract.sol:zContract -❯ contracts/Withdraw.sol:Withdraw -``` - -After the confirmation the contract will be verified. - -### Sending Tokens - -Sending ZETA from ZetaChain to Goerli: - -``` -npx hardhat send-zeta --amount 1 --network zeta_testnet --destination goerli_testnet -``` - -Sending ZETA from Goerli to ZetaChain: - -``` -npx hardhat send-zeta --amount 1 --network goerli_testnet --destination zeta_testnet -``` - -Depositing gETH to ZetaChain as ZRC-20: - -``` -npx hardhat send-zrc20 --amount 1 --network goerli_testnet --destination zeta_testnet -``` - -Withdrawing ZRC-20 from ZetaChain go Goerli as gETH: - -``` -npx hardhat send-zrc20 --amount 1 --network zeta_testnet --destination goerli_testnet -``` - -Depositing tBTC from the Bitcoin testnet to ZetaChain: - -``` -npx hardhat send-btc --amount 1 --recipient TSS_ADDRESS --memo RECIPIENT_ADDRESS_WITHOUT_0x -``` - -## Next Steps - -To learn more about building decentralized apps on ZetaChain, follow the -tutorials available in -[the documentation](https://www.zetachain.com/docs/developers/overview/). diff --git a/messaging/warriors/.eslintignore b/messaging/zeta/.eslintignore similarity index 100% rename from messaging/warriors/.eslintignore rename to messaging/zeta/.eslintignore diff --git a/messaging/warriors/.eslintrc.js b/messaging/zeta/.eslintrc.js similarity index 100% rename from messaging/warriors/.eslintrc.js rename to messaging/zeta/.eslintrc.js diff --git a/messaging/warriors/.gitignore b/messaging/zeta/.gitignore similarity index 100% rename from messaging/warriors/.gitignore rename to messaging/zeta/.gitignore diff --git a/messaging/warriors/LICENSE b/messaging/zeta/LICENSE similarity index 100% rename from messaging/warriors/LICENSE rename to messaging/zeta/LICENSE diff --git a/messaging/zeta/README.md b/messaging/zeta/README.md new file mode 100644 index 00000000..59b7739e --- /dev/null +++ b/messaging/zeta/README.md @@ -0,0 +1,30 @@ +# Hardhat Template for ZetaChain + +This is a simple Hardhat template that provides a starting point for developing +smart contract applications on ZetaChain. + +## Prerequisites + +Before getting started, ensure that you have +[Node.js](https://nodejs.org/en/download) (version 18 or above) and +[Yarn](https://yarnpkg.com/) installed on your system. + +## Getting Started + +To get started, install the necessary dependencies: + +``` +yarn +``` + +## Hardhat Tasks + +This template includes Hardhat tasks that streamline smart contract development. +Learn more about the template and the functionality it provides +[in the docs](https://www.zetachain.com/docs/developers/template/). + +## Next Steps + +To learn more about building decentralized apps on ZetaChain, follow the +tutorials available in +[the introduction to ZetaChain](https://www.zetachain.com/docs/developers/overview/). diff --git a/messaging/value/contracts/Value.sol b/messaging/zeta/contracts/CrossChainZeta.sol similarity index 73% rename from messaging/value/contracts/Value.sol rename to messaging/zeta/contracts/CrossChainZeta.sol index 12e0f430..cf5a3cbb 100644 --- a/messaging/value/contracts/Value.sol +++ b/messaging/zeta/contracts/CrossChainZeta.sol @@ -7,31 +7,21 @@ import "@zetachain/protocol-contracts/contracts/evm/tools/ZetaInteractor.sol"; import "@zetachain/protocol-contracts/contracts/evm/interfaces/ZetaInterfaces.sol"; import "@zetachain/protocol-contracts/contracts/evm/Zeta.eth.sol"; -contract Value is ZetaInteractor { +contract CrossChainZeta is ZetaInteractor { error ErrorTransferringZeta(); IERC20 internal immutable _zetaToken; - constructor( - address connectorAddress, - address zetaTokenAddress - ) ZetaInteractor(connectorAddress) { + constructor(address connectorAddress, address zetaTokenAddress) ZetaInteractor(connectorAddress) { _zetaToken = IERC20(zetaTokenAddress); } - function sendMessage( - uint256 destinationChainId, - uint256 zetaValueAndGas - ) external payable { + function sendMessage(uint256 destinationChainId, uint256 zetaValueAndGas) external payable { if (!_isValidChainId(destinationChainId)) revert InvalidDestinationChainId(); bool success1 = _zetaToken.approve(address(connector), zetaValueAndGas); - bool success2 = _zetaToken.transferFrom( - msg.sender, - address(this), - zetaValueAndGas - ); + bool success2 = _zetaToken.transferFrom(msg.sender, address(this), zetaValueAndGas); if (!(success1 && success2)) revert ErrorTransferringZeta(); connector.send( @@ -45,4 +35,5 @@ contract Value is ZetaInteractor { }) ); } + } diff --git a/messaging/counter/hardhat.config.ts b/messaging/zeta/hardhat.config.ts similarity index 91% rename from messaging/counter/hardhat.config.ts rename to messaging/zeta/hardhat.config.ts index e6c8e9dc..b28f6f15 100644 --- a/messaging/counter/hardhat.config.ts +++ b/messaging/zeta/hardhat.config.ts @@ -1,6 +1,5 @@ import "./tasks/interact"; import "./tasks/deploy"; -import "./tasks/counter_show.ts"; import "@nomicfoundation/hardhat-toolbox"; import "@zetachain/toolkit/tasks"; diff --git a/messaging/counter/package.json b/messaging/zeta/package.json similarity index 97% rename from messaging/counter/package.json rename to messaging/zeta/package.json index 4ee4d6d3..01eff927 100644 --- a/messaging/counter/package.json +++ b/messaging/zeta/package.json @@ -26,7 +26,7 @@ "@types/node": ">=12.0.0", "@typescript-eslint/eslint-plugin": "^5.59.9", "@typescript-eslint/parser": "^5.59.9", - "@zetachain/toolkit": "6.0.0", + "@zetachain/toolkit": "7.0.0", "axios": "^1.3.6", "chai": "^4.2.0", "dotenv": "^16.0.3", diff --git a/messaging/value/tasks/deploy.ts b/messaging/zeta/tasks/deploy.ts similarity index 77% rename from messaging/value/tasks/deploy.ts rename to messaging/zeta/tasks/deploy.ts index ebdcbc18..9fcbe44e 100644 --- a/messaging/value/tasks/deploy.ts +++ b/messaging/zeta/tasks/deploy.ts @@ -2,15 +2,15 @@ import { getAddress } from "@zetachain/protocol-contracts"; import { ethers } from "ethers"; import { task, types } from "hardhat/config"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import { getSupportedNetworks } from "@zetachain/networks"; +import type { ParamChainName } from "@zetachain/protocol-contracts"; -const contractName = "Value"; +const contractName = "CrossChainZeta"; const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const networks = args.networks.split(","); const contracts: { [key: string]: string } = {}; await Promise.all( - networks.map(async (networkName: string) => { + networks.map(async (networkName: ParamChainName) => { contracts[networkName] = await deployContract( hre, networkName, @@ -21,7 +21,13 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { ); for (const source in contracts) { - await setInteractors(hre, source, contracts, args.json, args.gasLimit); + await setInteractors( + hre, + source as ParamChainName, + contracts, + args.json, + args.gasLimit + ); } if (args.json) { @@ -29,7 +35,10 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { } }; -const initWallet = (hre: HardhatRuntimeEnvironment, networkName: string) => { +const initWallet = ( + hre: HardhatRuntimeEnvironment, + networkName: ParamChainName +) => { const { url } = hre.config.networks[networkName] as any; const provider = new ethers.providers.JsonRpcProvider(url); const wallet = new ethers.Wallet(process.env.PRIVATE_KEY as string, provider); @@ -39,14 +48,14 @@ const initWallet = (hre: HardhatRuntimeEnvironment, networkName: string) => { const deployContract = async ( hre: HardhatRuntimeEnvironment, - networkName: string, + networkName: ParamChainName, json: boolean = false, gasLimit: number ) => { const wallet = initWallet(hre, networkName); - const connector = getAddress("connector", networkName as any); - const zetaToken = getAddress("zetaToken", networkName as any); + const connector = getAddress("connector", networkName); + const zetaToken = getAddress("zetaToken", networkName); const { abi, bytecode } = await hre.artifacts.readArtifact(contractName); const factory = new ethers.ContractFactory(abi, bytecode, wallet); @@ -55,7 +64,7 @@ const deployContract = async ( await contract.deployed(); if (!json) { console.log(` -🚀 Successfully deployed contract on ${networkName}. +🚀 Successfully deployed contract on ${networkName} 📜 Contract address: ${contract.address}`); } return contract.address; @@ -63,7 +72,7 @@ const deployContract = async ( const setInteractors = async ( hre: HardhatRuntimeEnvironment, - source: string, + source: ParamChainName, contracts: { [key: string]: string }, json: boolean = false, gasLimit: number @@ -81,7 +90,7 @@ const setInteractors = async ( for (const counterparty in contracts) { if (counterparty === source) continue; - const counterpartyContract = hre.ethers.utils.solidityPack( + const counterpartyContract = ethers.utils.solidityPack( ["address"], [contracts[counterparty]] ); @@ -100,11 +109,6 @@ const setInteractors = async ( }; task("deploy", "Deploy the contract", main) - .addParam( - "networks", - `Comma separated list of networks to deploy to (e.g. ${getSupportedNetworks( - "ccm" - )})` - ) + .addParam("networks", "Comma separated list of networks to deploy to") .addOptionalParam("gasLimit", "Gas limit", 10000000, types.int) .addFlag("json", "Output JSON"); diff --git a/messaging/value/tasks/interact.ts b/messaging/zeta/tasks/interact.ts similarity index 95% rename from messaging/value/tasks/interact.ts rename to messaging/zeta/tasks/interact.ts index b0c83168..b7f234fe 100644 --- a/messaging/value/tasks/interact.ts +++ b/messaging/zeta/tasks/interact.ts @@ -6,7 +6,7 @@ import { getAddress } from "@zetachain/protocol-contracts"; const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const [signer] = await hre.ethers.getSigners(); - const factory = await hre.ethers.getContractFactory("Value"); + const factory = await hre.ethers.getContractFactory("CrossChainZeta"); const contract = factory.attach(args.contract); const destination = hre.config.networks[args.destination]?.chainId; diff --git a/messaging/warriors/tsconfig.json b/messaging/zeta/tsconfig.json similarity index 74% rename from messaging/warriors/tsconfig.json rename to messaging/zeta/tsconfig.json index 574e785c..fb0567b3 100644 --- a/messaging/warriors/tsconfig.json +++ b/messaging/zeta/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { - "target": "es2020", - "module": "commonjs", + "module": "nodenext", + "moduleResolution": "nodenext", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, diff --git a/messaging/warriors/yarn.lock b/messaging/zeta/yarn.lock similarity index 99% rename from messaging/warriors/yarn.lock rename to messaging/zeta/yarn.lock index 90dd53c5..5adafe6f 100644 --- a/messaging/warriors/yarn.lock +++ b/messaging/zeta/yarn.lock @@ -777,11 +777,6 @@ "@ethersproject/properties" "^5.7.0" "@ethersproject/strings" "^5.7.0" -"@fastify/busboy@^2.0.0": - version "2.1.1" - resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d" - integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA== - "@humanwhocodes/config-array@^0.11.10": version "0.11.10" resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.10.tgz#5a3ffe32cc9306365fb3fd572596cd602d5e12d2" @@ -1283,7 +1278,7 @@ table "^6.8.0" undici "^5.14.0" -"@openzeppelin/contracts@^4.9.2": +"@openzeppelin/contracts@^4.9.6": version "4.9.6" resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.6.tgz#2a880a24eb19b4f8b25adc2a5095f2aa27f39677" integrity sha512-xSmezSupL+y9VkHZJGDoCBpmnB2ogM13ccaYDWqJTfS3dbuHkgjuwDFUmaFauBCboQMGB/S5UqUl2y54X99BmA== @@ -1704,10 +1699,10 @@ typescript "5.0.4" zod "3.19.1" -"@zetachain/networks@6.0.0": - version "6.0.0" - resolved "https://registry.yarnpkg.com/@zetachain/networks/-/networks-6.0.0.tgz#ae5d3cd1678b32510edfaa71f8f4a6f4cbc1d9ab" - integrity sha512-yKFVP/yJDp76Q5lBGfZSpY/KO3TZ9ldo0lhE4MpBW43EsBxOZWixg6sqb56mcU/gg1lbWG8sHHWtYFK51SByjQ== +"@zetachain/networks@7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@zetachain/networks/-/networks-7.0.0.tgz#a5f8a188d633e2064ee7c77499351381ba891441" + integrity sha512-/amSq+KNJe+EGj0ioZS+DZJtsnbPSDotp9LsrAbaEVMAxKvBK/XkvggH73sJyRWWeMpfhHrNPlrKTLrN+mRkIg== dependencies: dotenv "^16.1.4" @@ -1716,18 +1711,18 @@ resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-7.0.0-rc1.tgz#588483d1ec70e572b7e40e84ef5b34282b0ab375" integrity sha512-vgS+Pjh4MysOyw8WbqTQVBsHJYqKvMcdV7cNVqxaTJd/dl2ak7NNvsIeaeUnxQrp8XfQol2B8GXJpVLM6MK/dg== -"@zetachain/toolkit@6.0.0": - version "6.0.0" - resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-6.0.0.tgz#385cfd11f1ac39cbb6ca6410109523e2ab6f8841" - integrity sha512-JAtl7CX8cMJ+iw/byjcbLqgCfPS87vkdYCZOPBBOudqUySPTz4owqVgGZB/xYRyXBsF0KW0F6R65sc+fleQ86A== +"@zetachain/toolkit@7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-7.0.0.tgz#7301ccab40c37d3fd8fcc347f99c831ec31b1bd3" + integrity sha512-5cOJVBIEcosF2A2TJbNGFfh4Bob8UcodQII1RdHRstqvV3toZ18r1gVWpLGQ8w2N6T2FCPE8ueN4Q5zH68q20Q== dependencies: "@inquirer/prompts" "^2.1.1" "@inquirer/select" "1.1.3" "@nomiclabs/hardhat-ethers" "^2.2.3" - "@openzeppelin/contracts" "^4.9.2" + "@openzeppelin/contracts" "^4.9.6" "@uniswap/v2-periphery" "^1.1.0-beta.0" "@zetachain/faucet-cli" "^4.0.1" - "@zetachain/networks" "6.0.0" + "@zetachain/networks" "7.0.0" "@zetachain/protocol-contracts" "7.0.0-rc1" axios "^1.4.0" bech32 "^2.0.0" @@ -2088,9 +2083,9 @@ axios@1.2.3: proxy-from-env "^1.1.0" axios@^1.3.6, axios@^1.4.0: - version "1.6.1" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.1.tgz#76550d644bf0a2d469a01f9244db6753208397d7" - integrity sha512-vfBmhDpKafglh0EldBEbVuoe7DyAavGSLWhuSm5ZSEKQnHhBf0xAAwybbNH1IkrJNGnS/VG4I5yxig1pCEXE4g== + version "1.4.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.4.0.tgz#38a7bf1224cd308de271146038b551d725f0be1f" + integrity sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA== dependencies: follow-redirects "^1.15.0" form-data "^4.0.0" @@ -2309,6 +2304,13 @@ buffer@^6.0.3: base64-js "^1.3.1" ieee754 "^1.2.1" +busboy@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/busboy/-/busboy-1.6.0.tgz#966ea36a9502e43cdb9146962523b92f531f6893" + integrity sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA== + dependencies: + streamsearch "^1.1.0" + bytes@3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.2.tgz#8b0beeb98605adf1b128fa4386403c009e0221a5" @@ -3572,9 +3574,9 @@ flatted@^3.1.0: integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ== follow-redirects@^1.12.1, follow-redirects@^1.15.0: - version "1.15.6" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" - integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== + version "1.15.2" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" + integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== for-each@^0.3.3: version "0.3.3" @@ -3715,9 +3717,9 @@ get-caller-file@^2.0.1, get-caller-file@^2.0.5: integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== get-func-name@^2.0.0: - version "2.0.2" - resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.2.tgz#0d7cf20cd13fda808669ffa88f4ffc7a3943fc41" - integrity sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ== + version "2.0.0" + resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41" + integrity sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig== get-intrinsic@^1.0.2, get-intrinsic@^1.1.1, get-intrinsic@^1.1.3, get-intrinsic@^1.2.0, get-intrinsic@^1.2.1: version "1.2.1" @@ -5965,6 +5967,11 @@ stealthy-require@^1.1.1: resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b" integrity sha512-ZnWpYnYugiOVEY5GkcuJK1io5V8QmNYChG62gSit9pQVGErXtrKuPC55ITaVSukmMta5qpMU7vqLt2Lnni4f/g== +streamsearch@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764" + integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg== + string-format@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/string-format/-/string-format-2.0.0.tgz#f2df2e7097440d3b65de31b6d40d54c96eaffb9b" @@ -6446,11 +6453,11 @@ unbox-primitive@^1.0.2: which-boxed-primitive "^1.0.2" undici@^5.14.0: - version "5.28.4" - resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068" - integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g== + version "5.23.0" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.23.0.tgz#e7bdb0ed42cebe7b7aca87ced53e6eaafb8f8ca0" + integrity sha512-1D7w+fvRsqlQ9GscLBwcAJinqcZGHUKjbOmXdlE/v8BvEGXjeWAax+341q44EuTcHXXnfyKNbKRq4Lg7OzhMmg== dependencies: - "@fastify/busboy" "^2.0.0" + busboy "^1.6.0" universalify@^0.1.0: version "0.1.2"