Skip to content

Commit

Permalink
rename counterparty
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Nov 20, 2024
1 parent 5013b00 commit 6a15652
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 45 deletions.
2 changes: 1 addition & 1 deletion examples/nft/contracts/Universal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ contract Universal is
address contractAddress
) external onlyOwner {
connected[zrc20] = contractAddress;
emit ConnectedSet(zrc20, contractAddress);
emit SetConnected(zrc20, contractAddress);
}

function transferCrossChain(
Expand Down
2 changes: 1 addition & 1 deletion examples/nft/contracts/shared/Events.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
15 changes: 8 additions & 7 deletions examples/token/contracts/Connected.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(
Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand Down
17 changes: 8 additions & 9 deletions examples/token/contracts/Universal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(
Expand Down Expand Up @@ -85,7 +85,7 @@ contract Universal is ERC20, Ownable2Step, UniversalContract, Events {
);

gateway.call(
counterparty[destination],
abi.encodePacked(connected[destination]),
destination,
message,
callOptions,
Expand All @@ -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,
Expand All @@ -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),
Expand Down
8 changes: 2 additions & 6 deletions examples/token/contracts/shared/Events.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions examples/token/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion examples/token/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions examples/token/scripts/localnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
);
Expand All @@ -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");
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ 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,
})
);
} else {
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");
8 changes: 4 additions & 4 deletions examples/token/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2743,10 +2743,10 @@
typescript "5.5.4"
zod "3.22.4"

"@zetachain/[email protected]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/[email protected]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"
Expand Down

0 comments on commit 6a15652

Please sign in to comment.