-
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.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
"test": "echo \"Error: no test specified\" && exit 1", | ||
"lint:fix": "npx eslint . --ext .js,.ts --fix", | ||
"lint": "npx eslint . --ext .js,.ts", | ||
"deploy": "npx hardhat compile --force && npx hardhat deploy --network localhost --name Hello && npx hardhat deploy --network localhost --name ReceiverContract" | ||
"deploy:localnet": "npx hardhat compile --force && npx hardhat deploy --network localhost --gateway 0x9A676e781A523b5d0C0e43731313A708CB607508 && npx hardhat deploy --name Echo --network localhost --gateway 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
|
@@ -28,9 +28,8 @@ | |
"@types/node": ">=12.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.59.9", | ||
"@typescript-eslint/parser": "^5.59.9", | ||
"@zetachain/localnet": "^1.0.1", | ||
"@zetachain/protocol-contracts": "9.0.0", | ||
"@zetachain/toolkit": "^10.0.0", | ||
"@zetachain/localnet": "4.0.0-rc6", | ||
"@zetachain/toolkit": "13.0.0-rc7", | ||
"axios": "^1.3.6", | ||
"chai": "^4.2.0", | ||
"dotenv": "^16.0.3", | ||
|
@@ -55,9 +54,9 @@ | |
"packageManager": "[email protected]+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72", | ||
"dependencies": { | ||
"@coral-xyz/anchor": "0.30.0", | ||
"@openzeppelin/contracts": "^4.9.6", | ||
"@solana-developers/helpers": "^2.4.0", | ||
"@solana/spl-memo": "^0.2.5", | ||
"@solana/web3.js": "^1.95.2" | ||
"@solana/web3.js": "^1.95.2", | ||
"@zetachain/protocol-contracts": "11.0.0-rc3" | ||
} | ||
} |
Oops, something went wrong.