-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'auth-call-hello-swap' into router-example
- Loading branch information
Showing
91 changed files
with
12,033 additions
and
1,861 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,104 @@ | ||
// 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"; | ||
|
||
contract Connected { | ||
GatewayEVM public immutable gateway; | ||
|
||
event RevertEvent(string, RevertContext); | ||
event HelloEvent(string, string); | ||
|
||
error TransferFailed(); | ||
error ApprovalFailed(); | ||
|
||
modifier onlyGateway() { | ||
require(msg.sender == address(gateway), "Caller is not the gateway"); | ||
_; | ||
} | ||
|
||
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 { | ||
if (!IERC20(asset).transferFrom(msg.sender, address(this), amount)) { | ||
revert TransferFailed(); | ||
} | ||
if (!IERC20(asset).approve(address(gateway), amount)) { | ||
revert ApprovalFailed(); | ||
} | ||
gateway.deposit(receiver, amount, asset, revertOptions); | ||
} | ||
|
||
function depositAndCall( | ||
address receiver, | ||
uint256 amount, | ||
address asset, | ||
bytes calldata message, | ||
RevertOptions memory revertOptions | ||
) external { | ||
if (!IERC20(asset).transferFrom(msg.sender, address(this), amount)) { | ||
revert TransferFailed(); | ||
} | ||
if (!IERC20(asset).approve(address(gateway), amount)) { | ||
revert ApprovalFailed(); | ||
} | ||
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
Oops, something went wrong.