diff --git a/examples/router/contracts/Connected.sol b/examples/router/contracts/Connected.sol index d17535f1..a9832af3 100644 --- a/examples/router/contracts/Connected.sol +++ b/examples/router/contracts/Connected.sol @@ -56,7 +56,6 @@ contract Connected is Ownable { } function hello(string memory message) external payable { - revert("revert"); emit HelloEvent("Event from hello()", message); } diff --git a/examples/router/contracts/Universal.sol b/examples/router/contracts/Universal.sol index e60567a7..d4cc6d9b 100644 --- a/examples/router/contracts/Universal.sol +++ b/examples/router/contracts/Universal.sol @@ -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"); _; @@ -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 { diff --git a/examples/router/scripts/test.sh b/examples/router/scripts/test.sh index 9eaa2b99..32e236e1 100755 --- a/examples/router/scripts/test.sh +++ b/examples/router/scripts/test.sh @@ -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 diff --git a/examples/router/tasks/transfer.ts b/examples/router/tasks/transfer.ts index 235c774a..10c4131f 100644 --- a/examples/router/tasks/transfer.ts +++ b/examples/router/tasks/transfer.ts @@ -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",