-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Hello and Swap to authenticated calls (#218)
- Loading branch information
Showing
81 changed files
with
2,738 additions
and
1,952 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,6 @@ artifacts | |
out | ||
cache_forge | ||
|
||
access_token | ||
access_token | ||
|
||
localnet.json |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Hello Example | ||
|
||
Tutorial: https://www.zetachain.com/docs/developers/tutorials/call/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.26; | ||
|
||
import {RevertContext} from "@zetachain/protocol-contracts/contracts/Revert.sol"; | ||
import "@zetachain/protocol-contracts/contracts/evm/GatewayEVM.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
||
contract Connected { | ||
using SafeERC20 for IERC20; // Use SafeERC20 for IERC20 operations | ||
|
||
GatewayEVM public immutable gateway; | ||
|
||
event RevertEvent(string, RevertContext); | ||
event HelloEvent(string, string); | ||
|
||
error Unauthorized(); | ||
|
||
modifier onlyGateway() { | ||
if (msg.sender != address(gateway)) revert Unauthorized(); | ||
_; | ||
} | ||
|
||
constructor(address payable gatewayAddress) { | ||
gateway = GatewayEVM(gatewayAddress); | ||
} | ||
|
||
function call( | ||
address receiver, | ||
bytes calldata message, | ||
RevertOptions memory revertOptions | ||
) external { | ||
gateway.call(receiver, message, revertOptions); | ||
} | ||
|
||
function deposit( | ||
address receiver, | ||
RevertOptions memory revertOptions | ||
) external payable { | ||
gateway.deposit{value: msg.value}(receiver, revertOptions); | ||
} | ||
|
||
function deposit( | ||
address receiver, | ||
uint256 amount, | ||
address asset, | ||
RevertOptions memory revertOptions | ||
) external { | ||
IERC20(asset).safeTransferFrom(msg.sender, address(this), amount); | ||
IERC20(asset).approve(address(gateway), amount); | ||
gateway.deposit(receiver, amount, asset, revertOptions); | ||
} | ||
|
||
function depositAndCall( | ||
address receiver, | ||
uint256 amount, | ||
address asset, | ||
bytes calldata message, | ||
RevertOptions memory revertOptions | ||
) external { | ||
IERC20(asset).safeTransferFrom(msg.sender, address(this), amount); | ||
IERC20(asset).approve(address(gateway), amount); | ||
gateway.depositAndCall(receiver, amount, asset, message, revertOptions); | ||
} | ||
|
||
function depositAndCall( | ||
address receiver, | ||
bytes calldata message, | ||
RevertOptions memory revertOptions | ||
) external payable { | ||
gateway.depositAndCall{value: msg.value}( | ||
receiver, | ||
message, | ||
revertOptions | ||
); | ||
} | ||
|
||
function hello(string memory message) external payable { | ||
emit HelloEvent("Hello on EVM", message); | ||
} | ||
|
||
function onCall( | ||
MessageContext calldata context, | ||
bytes calldata message | ||
) external payable onlyGateway returns (bytes4) { | ||
emit HelloEvent("Hello on EVM from onCall()", "hey"); | ||
return ""; | ||
} | ||
|
||
function onRevert( | ||
RevertContext calldata revertContext | ||
) external onlyGateway { | ||
emit RevertEvent("Revert on EVM", revertContext); | ||
} | ||
|
||
receive() external payable {} | ||
|
||
fallback() external payable {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.