From 6a156522443d14454741f91d9c84607d014962b6 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Wed, 20 Nov 2024 10:31:15 +0300 Subject: [PATCH] rename counterparty --- examples/nft/contracts/Universal.sol | 2 +- examples/nft/contracts/shared/Events.sol | 2 +- examples/token/contracts/Connected.sol | 15 ++++++++------- examples/token/contracts/Universal.sol | 17 ++++++++--------- examples/token/contracts/shared/Events.sol | 8 ++------ examples/token/hardhat.config.ts | 4 ++-- examples/token/package.json | 2 +- examples/token/scripts/localnet.sh | 10 +++++----- ...Counterparty.ts => connectedSetUniversal.ts} | 8 ++++---- ...Counterparty.ts => universalSetConnected.ts} | 10 +++++----- examples/token/yarn.lock | 8 ++++---- 11 files changed, 41 insertions(+), 45 deletions(-) rename examples/token/tasks/{connectedSetCounterparty.ts => connectedSetUniversal.ts} (78%) rename examples/token/tasks/{universalSetCounterparty.ts => universalSetConnected.ts} (76%) diff --git a/examples/nft/contracts/Universal.sol b/examples/nft/contracts/Universal.sol index c999ea0c..54909acc 100644 --- a/examples/nft/contracts/Universal.sol +++ b/examples/nft/contracts/Universal.sol @@ -64,7 +64,7 @@ contract Universal is address contractAddress ) external onlyOwner { connected[zrc20] = contractAddress; - emit ConnectedSet(zrc20, contractAddress); + emit SetConnected(zrc20, contractAddress); } function transferCrossChain( diff --git a/examples/nft/contracts/shared/Events.sol b/examples/nft/contracts/shared/Events.sol index 747544e3..eff15810 100644 --- a/examples/nft/contracts/shared/Events.sol +++ b/examples/nft/contracts/shared/Events.sol @@ -3,6 +3,7 @@ pragma solidity ^0.8.26; contract Events { event SetUniversal(address indexed universalAddress); + event SetConnected(address indexed zrc20, address contractAddress); event TokenMinted(address indexed to, uint256 indexed tokenId, string uri); event TokenTransfer( address indexed destination, @@ -20,7 +21,6 @@ contract Events { uint256 indexed tokenId, string uri ); - event ConnectedSet(address indexed zrc20, address contractAddress); event TokenTransferToDestination( address indexed destination, address indexed sender, diff --git a/examples/token/contracts/Connected.sol b/examples/token/contracts/Connected.sol index 95f2cb3d..5f3d144c 100644 --- a/examples/token/contracts/Connected.sol +++ b/examples/token/contracts/Connected.sol @@ -9,7 +9,7 @@ import "./shared/Events.sol"; contract Connected is ERC20, Ownable2Step, Events { GatewayEVM public immutable gateway; - address public counterparty; + address public universal; uint256 public immutable gasLimit; error InvalidAddress(); @@ -22,9 +22,10 @@ contract Connected is ERC20, Ownable2Step, Events { _; } - function setCounterparty(address contractAddress) external onlyOwner { - counterparty = contractAddress; - emit SetCounterparty(contractAddress); + function setUniversal(address contractAddress) external onlyOwner { + if (contractAddress == address(0)) revert InvalidAddress(); + universal = contractAddress; + emit SetUniversal(contractAddress); } constructor( @@ -60,13 +61,13 @@ contract Connected is ERC20, Ownable2Step, Events { ); if (destination == address(0)) { gateway.call( - counterparty, + universal, message, RevertOptions(address(this), false, address(0), message, 0) ); } else { gateway.depositAndCall{value: msg.value}( - counterparty, + universal, message, RevertOptions( address(this), @@ -85,7 +86,7 @@ contract Connected is ERC20, Ownable2Step, Events { MessageContext calldata context, bytes calldata message ) external payable onlyGateway returns (bytes4) { - if (context.sender != counterparty) revert Unauthorized(); + if (context.sender != universal) revert Unauthorized(); ( address receiver, uint256 amount, diff --git a/examples/token/contracts/Universal.sol b/examples/token/contracts/Universal.sol index ad4024a4..18fec795 100644 --- a/examples/token/contracts/Universal.sol +++ b/examples/token/contracts/Universal.sol @@ -23,7 +23,7 @@ contract Universal is ERC20, Ownable2Step, UniversalContract, Events { error InvalidAddress(); error InvalidGasLimit(); - mapping(address => bytes) public counterparty; + mapping(address => address) public connected; modifier onlyGateway() { if (msg.sender != address(gateway)) revert Unauthorized(); @@ -49,12 +49,12 @@ contract Universal is ERC20, Ownable2Step, UniversalContract, Events { gasLimit = gas; } - function setCounterparty( + function setConnected( address zrc20, - bytes memory contractAddress + address contractAddress ) external onlyOwner { - counterparty[zrc20] = contractAddress; - emit CounterpartyMappingSet(zrc20, contractAddress); + connected[zrc20] = contractAddress; + emit SetConnected(zrc20, contractAddress); } function transferCrossChain( @@ -85,7 +85,7 @@ contract Universal is ERC20, Ownable2Step, UniversalContract, Events { ); gateway.call( - counterparty[destination], + abi.encodePacked(connected[destination]), destination, message, callOptions, @@ -104,8 +104,7 @@ contract Universal is ERC20, Ownable2Step, UniversalContract, Events { uint256 amount, bytes calldata message ) external override onlyGateway { - if (keccak256(context.origin) != keccak256(counterparty[zrc20])) - revert Unauthorized(); + if (context.sender != connected[zrc20]) revert Unauthorized(); ( address destination, address receiver, @@ -127,7 +126,7 @@ contract Universal is ERC20, Ownable2Step, UniversalContract, Events { ); IZRC20(destination).approve(address(gateway), out); gateway.withdrawAndCall( - abi.encodePacked(counterparty[destination]), + abi.encodePacked(connected[destination]), out - gasFee, destination, abi.encode(receiver, tokenAmount, out - gasFee, sender), diff --git a/examples/token/contracts/shared/Events.sol b/examples/token/contracts/shared/Events.sol index da95ec45..cebb4adc 100644 --- a/examples/token/contracts/shared/Events.sol +++ b/examples/token/contracts/shared/Events.sol @@ -2,12 +2,8 @@ pragma solidity ^0.8.26; contract Events { - event CounterpartyMappingSet( - address indexed zrc20, - bytes indexed contractAddress - ); - event SetCounterparty(address indexed contractAddress); - + event SetUniversal(address indexed universalAddress); + event SetConnected(address indexed zrc20, address contractAddress); event TokenMinted(address indexed to, uint256 amount); event TokenTransfer( address indexed destination, diff --git a/examples/token/hardhat.config.ts b/examples/token/hardhat.config.ts index eef5c50d..cb202293 100644 --- a/examples/token/hardhat.config.ts +++ b/examples/token/hardhat.config.ts @@ -1,8 +1,8 @@ import "./tasks/deploy"; import "./tasks/mint"; import "./tasks/transfer"; -import "./tasks/universalSetCounterparty"; -import "./tasks/connectedSetCounterparty"; +import "./tasks/universalSetConnected"; +import "./tasks/connectedSetUniversal"; import "@zetachain/localnet/tasks"; import "@nomicfoundation/hardhat-toolbox"; import "@zetachain/toolkit/tasks"; diff --git a/examples/token/package.json b/examples/token/package.json index 6bb7708b..84fec511 100644 --- a/examples/token/package.json +++ b/examples/token/package.json @@ -27,7 +27,7 @@ "@types/node": ">=12.0.0", "@typescript-eslint/eslint-plugin": "^5.59.9", "@typescript-eslint/parser": "^5.59.9", - "@zetachain/localnet": "4.0.0-rc4", + "@zetachain/localnet": "4.0.0-rc6", "@zetachain/toolkit": "13.0.0-rc8", "axios": "^1.3.6", "chai": "^4.2.0", diff --git a/examples/token/scripts/localnet.sh b/examples/token/scripts/localnet.sh index 71633b8b..dc825541 100755 --- a/examples/token/scripts/localnet.sh +++ b/examples/token/scripts/localnet.sh @@ -38,11 +38,11 @@ echo -e "šŸš€ Deployed contract on BNB chain: $CONTRACT_BNB" echo -e "\nšŸ“® User Address: $SENDER" -echo -e "\nšŸ”— Setting counterparty contracts..." -npx hardhat connected-set-counterparty --network localhost --contract "$CONTRACT_ETHEREUM" --counterparty "$CONTRACT_ZETACHAIN" --json &>/dev/null -npx hardhat connected-set-counterparty --network localhost --contract "$CONTRACT_BNB" --counterparty "$CONTRACT_ZETACHAIN" --json &>/dev/null -npx hardhat universal-set-counterparty --network localhost --contract "$CONTRACT_ZETACHAIN" --counterparty "$CONTRACT_ETHEREUM" --zrc20 "$ZRC20_ETHEREUM" --json &>/dev/null -npx hardhat universal-set-counterparty --network localhost --contract "$CONTRACT_ZETACHAIN" --counterparty "$CONTRACT_BNB" --zrc20 "$ZRC20_BNB" --json &>/dev/null +echo -e "\nšŸ”— Setting universal and connected contracts..." +npx hardhat connected-set-universal --network localhost --contract "$CONTRACT_ETHEREUM" --universal "$CONTRACT_ZETACHAIN" --json &>/dev/null +npx hardhat connected-set-universal --network localhost --contract "$CONTRACT_BNB" --universal "$CONTRACT_ZETACHAIN" --json &>/dev/null +npx hardhat universal-set-connected --network localhost --contract "$CONTRACT_ZETACHAIN" --connected "$CONTRACT_ETHEREUM" --zrc20 "$ZRC20_ETHEREUM" --json &>/dev/null +npx hardhat universal-set-connected --network localhost --contract "$CONTRACT_ZETACHAIN" --connected "$CONTRACT_BNB" --zrc20 "$ZRC20_BNB" --json &>/dev/null npx hardhat localnet-check balance diff --git a/examples/token/tasks/connectedSetCounterparty.ts b/examples/token/tasks/connectedSetUniversal.ts similarity index 78% rename from examples/token/tasks/connectedSetCounterparty.ts rename to examples/token/tasks/connectedSetUniversal.ts index 3535d52e..0e5a2c41 100644 --- a/examples/token/tasks/connectedSetCounterparty.ts +++ b/examples/token/tasks/connectedSetUniversal.ts @@ -15,13 +15,13 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { args.contract ); - const tx = await contract.setCounterparty(args.counterparty); + const tx = await contract.setUniversal(args.universal); if (args.json) { console.log( JSON.stringify({ contractAddress: args.contract, - universalContract: args.counterparty, + universalContract: args.universal, transactionHash: tx.hash, }) ); @@ -32,7 +32,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { } }; -task("connected-set-counterparty", "Sets the universal contract address", main) +task("connected-set-universal", "Sets the universal contract address", main) .addParam("contract", "The address of the deployed contract") - .addParam("counterparty", "The address of the universal contract to set") + .addParam("universal", "The address of the universal contract to set") .addFlag("json", "Output the result in JSON format"); diff --git a/examples/token/tasks/universalSetCounterparty.ts b/examples/token/tasks/universalSetConnected.ts similarity index 76% rename from examples/token/tasks/universalSetCounterparty.ts rename to examples/token/tasks/universalSetConnected.ts index 05ce0dce..b8de726c 100644 --- a/examples/token/tasks/universalSetCounterparty.ts +++ b/examples/token/tasks/universalSetConnected.ts @@ -15,14 +15,14 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { args.contract ); - const tx = await contract.setCounterparty(args.zrc20, args.counterparty); + const tx = await contract.setConnected(args.zrc20, args.connected); if (args.json) { console.log( JSON.stringify({ contractAddress: args.contract, zrc20: args.zrc20, - connectedContractAddress: args.counterparty, + connectedContractAddress: args.connected, transactionHash: tx.hash, }) ); @@ -30,13 +30,13 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { console.log(`šŸš€ Successfully set the connected contract. šŸ“œ Contract address: ${args.contract} šŸ”— ZRC20 address: ${args.zrc20} -šŸ”— Connected contract address: ${args.counterparty} +šŸ”— Connected contract address: ${args.connected} šŸ”— Transaction hash: ${tx.hash}`); } }; -task("universal-set-counterparty", "Sets the connected contract address", main) +task("universal-set-connected", "Sets the connected contract address", main) .addParam("contract", "The address of the deployed contract") .addParam("zrc20", "The ZRC20 address to link to the connected contract") - .addParam("counterparty", "The address of the connected contract to set") + .addParam("connected", "The address of the connected contract to set") .addFlag("json", "Output the result in JSON format"); diff --git a/examples/token/yarn.lock b/examples/token/yarn.lock index aa2efc96..14f87151 100644 --- a/examples/token/yarn.lock +++ b/examples/token/yarn.lock @@ -2743,10 +2743,10 @@ typescript "5.5.4" zod "3.22.4" -"@zetachain/localnet@4.0.0-rc4": - version "4.0.0-rc4" - resolved "https://registry.yarnpkg.com/@zetachain/localnet/-/localnet-4.0.0-rc4.tgz#916c58f83dd4901691fbc1216aec2ee88e7f531e" - integrity sha512-yNlA6qaQZiuHXRx4pgNLLHlJ+2ENet9WTIWxoslnLzzDljWwYTJHkErlTQcWa5oL9jjyn2/hQB/laoqXzlX1gQ== +"@zetachain/localnet@4.0.0-rc6": + version "4.0.0-rc6" + resolved "https://registry.yarnpkg.com/@zetachain/localnet/-/localnet-4.0.0-rc6.tgz#9b36f5ab0e8fac766d63cfca4b1cab6a263bdd5d" + integrity sha512-DGKspMAJZLUrgNirc3NzFYg9jRfaOyuF5ePj85D93qAA//f8lOsXpmh/6Bvq/MrEscCLpVavgVP7+ePy4KJ2Fw== dependencies: "@inquirer/prompts" "^5.5.0" "@uniswap/v2-core" "^1.0.1"