Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Nov 7, 2024
1 parent c58d68c commit 4ec97a0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
1 change: 0 additions & 1 deletion examples/router/contracts/Connected.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ contract Connected is Ownable {
}

function hello(string memory message) external payable {
revert("revert");
emit HelloEvent("Event from hello()", message);
}

Expand Down
36 changes: 17 additions & 19 deletions examples/router/contracts/Universal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ contract Universal is UniversalContract, Ownable {
event GasFeeAndOut(uint256 gasFee, uint256 out);
event RevertEvent(string);

event Data(bytes);

modifier onlyGateway() {
require(msg.sender == address(gateway), "Caller is not the gateway");
_;
Expand Down Expand Up @@ -89,25 +91,21 @@ contract Universal is UniversalContract, Ownable {
gasLimit
);

if (callOptions.isArbitraryCall) {
gateway.withdrawAndCall(
receiver,
out - gasFee,
destination,
abi.encodePacked(data, context.origin, true),
callOptions,
revertOptionsUniversal
);
} else {
gateway.withdrawAndCall(
receiver,
out - gasFee,
destination,
abi.encode(data, context.origin, true),
callOptions,
revertOptionsUniversal
);
}
emit Data(abi.encodePacked(data, context.origin, true));
emit Data(abi.encode(data, context.origin, true));

bytes memory m = callOptions.isArbitraryCall
? abi.encodePacked(data, context.origin, true)
: abi.encode(data, context.origin, true);

gateway.withdrawAndCall(
receiver,
out - gasFee,
destination,
m,
callOptions,
revertOptionsUniversal
);
}

function onRevert(RevertContext calldata context) external onlyGateway {
Expand Down
6 changes: 3 additions & 3 deletions examples/router/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ npx hardhat universal-set-counterparty --network localhost --contract "$CONTRACT
npx hardhat connected-set-router --network localhost --contract "$CONTRACT_ETHEREUM" --counterparty "$CONTRACT_ZETACHAIN" --json &>/dev/null
npx hardhat connected-set-router --network localhost --contract "$CONTRACT_BNB" --counterparty "$CONTRACT_ZETACHAIN" --json &>/dev/null

# echo -e "\nMaking an authenticated call..."
# npx hardhat transfer --network localhost --json --from "$CONTRACT_ETHEREUM" --to "$ZRC20_BNB" --gas-amount 1 --call-on-revert --revert-address "$CONTRACT_ETHEREUM" --revert-message "hello" --types '["string"]' alice
echo -e "\nMaking an authenticated call..."
npx hardhat transfer --network localhost --json --from "$CONTRACT_ETHEREUM" --to "$ZRC20_BNB" --gas-amount 1 --call-on-revert --revert-address "$CONTRACT_ETHEREUM" --revert-message "hello" --types '["string"]' alice

# sleep 5
sleep 5

echo -e "\nMaking an arbitrary call..."
npx hardhat transfer --network localhost --json --from "$CONTRACT_ETHEREUM" --to "$ZRC20_BNB" --gas-amount 1 --call-options-is-arbitrary-call --function "hello(string)" --revert-address "$CONTRACT_ETHEREUM" --revert-message "hello" --types '["string"]' alice
Expand Down
2 changes: 1 addition & 1 deletion examples/router/tasks/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
// }
};

task("transfer", "Transfer and lock an NFT", main)
task("transfer", "Make a cross-chain call", main)
.addParam("from", "The contract being transferred from")
.addOptionalParam(
"txOptionsGasPrice",
Expand Down

0 comments on commit 4ec97a0

Please sign in to comment.