-
Notifications
You must be signed in to change notification settings - Fork 61
ping pong #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ping pong #202
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cc57caa
Call from EVM
fadeev 73379dd
immutable
fadeev 5814704
gateway param
fadeev 231e856
check types/values length
fadeev 6e40182
removed gas limit param
fadeev e223861
connect signer
fadeev 923f041
update localnet
fadeev f64ec1d
withdraw and call
fadeev 6e921bf
update addresses
fadeev 19b6de3
remove ping pong
fadeev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,15 +1,45 @@ | ||
| # ZetaChain Contracts Template | ||
| # Hello Example | ||
|
|
||
| ## Getting Started | ||
| ``` | ||
| yarn deploy | ||
| ``` | ||
|
|
||
| ## EVM | ||
|
|
||
| Successful call: | ||
|
|
||
| ``` | ||
| npx hardhat echo-call --contract 0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E --receiver 0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690 --network localhost --types '["string"]' hello | ||
| ``` | ||
|
|
||
| Failed call: | ||
|
|
||
| ``` | ||
| npx hardhat echo-call --contract 0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E --receiver 0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690 --network localhost --types '["uint256"]' 42 | ||
| ``` | ||
|
|
||
| Install dependencies: | ||
| Failed call with handled revert: | ||
|
|
||
| ``` | ||
| yarn | ||
| npx hardhat echo-call --contract 0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E --receiver 0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690 --network localhost --revert-address 0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E --revert-message 0x --call-on-revert --types '["uint256"]' 42 | ||
| ``` | ||
|
|
||
| ## Next Steps | ||
| ## ZetaChain | ||
|
|
||
| Ready to dive in? Follow our [**🚀 smart contract | ||
| tutorials**](https://www.zetachain.com/docs/developers/tutorials/intro/) to | ||
| start building universal app contracts. | ||
| Successful call: | ||
|
|
||
| ``` | ||
| npx hardhat hell-call --contract 0x67d269191c92Caf3cD7723F116c85e6E9bf55933 --receiver 0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690 --zrc20 0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe --function "hello(string)" --network localhost --types '["string"]' hello | ||
| ``` | ||
|
|
||
| Failed call: | ||
|
|
||
| ``` | ||
| npx hardhat hell-call --contract 0x67d269191c92Caf3cD7723F116c85e6E9bf55933 --receiver 0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690 --zrc20 0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe --function "hello(string)" --network localhost --types '["uint256"]' 42 | ||
| ``` | ||
|
|
||
| Failed call with handled revert: | ||
|
|
||
| ``` | ||
| npx hardhat hell-call --contract 0x67d269191c92Caf3cD7723F116c85e6E9bf55933 --receiver 0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690 --zrc20 0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe --function "hello(string)" --network localhost --revert-address 0x67d269191c92Caf3cD7723F116c85e6E9bf55933 --revert-message 0x --call-on-revert --types '["uint256"]' 42 | ||
| ``` |
This file contains hidden or 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,36 @@ | ||
| // 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 Echo { | ||
| GatewayEVM public immutable gateway; | ||
|
|
||
| event RevertEvent(string, RevertContext); | ||
| event HelloEvent(string, string); | ||
|
|
||
| constructor(address payable gatewayAddress) { | ||
| gateway = GatewayEVM(gatewayAddress); | ||
| } | ||
|
|
||
| function hello(string memory message) external payable { | ||
| emit HelloEvent("Hello on EVM", message); | ||
| } | ||
|
|
||
| function onRevert(RevertContext calldata revertContext) external { | ||
| emit RevertEvent("Revert on EVM", revertContext); | ||
| } | ||
|
|
||
| function call( | ||
| address receiver, | ||
| bytes calldata message, | ||
| RevertOptions memory revertOptions | ||
| ) external { | ||
| gateway.call(receiver, message, revertOptions); | ||
| } | ||
|
|
||
| receive() external payable {} | ||
|
|
||
| fallback() external payable {} | ||
| } | ||
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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,99 @@ | ||
| import { task, types } from "hardhat/config"; | ||
| import type { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
|
|
||
| const main = async (args: any, hre: HardhatRuntimeEnvironment) => { | ||
| const { ethers } = hre; | ||
| const [signer] = await ethers.getSigners(); | ||
|
|
||
| const txOptions = { | ||
| gasPrice: args.txOptionsGasPrice, | ||
| gasLimit: args.txOptionsGasLimit, | ||
| }; | ||
|
|
||
| const revertOptions = { | ||
| abortAddress: "0x0000000000000000000000000000000000000000", // not used | ||
| callOnRevert: args.callOnRevert, | ||
| onRevertGasLimit: args.onRevertGasLimit, | ||
| revertAddress: args.revertAddress, | ||
| revertMessage: ethers.utils.hexlify( | ||
| ethers.utils.toUtf8Bytes(args.revertMessage) | ||
| ), | ||
| }; | ||
|
|
||
| const types = JSON.parse(args.types); | ||
|
|
||
| if (types.length !== args.values.length) { | ||
| throw new Error( | ||
| `The number of types (${types.length}) does not match the number of values (${args.values.length}).` | ||
| ); | ||
| } | ||
|
|
||
| const valuesArray = args.values.map((value: any, index: number) => { | ||
| const type = types[index]; | ||
|
|
||
| if (type === "bool") { | ||
| try { | ||
| return JSON.parse(value.toLowerCase()); | ||
| } catch (e) { | ||
| throw new Error(`Invalid boolean value: ${value}`); | ||
| } | ||
| } else if (type.startsWith("uint") || type.startsWith("int")) { | ||
| return ethers.BigNumber.from(value); | ||
| } else { | ||
| return value; | ||
| } | ||
| }); | ||
| const encodedParameters = ethers.utils.defaultAbiCoder.encode( | ||
| types, | ||
| valuesArray | ||
| ); | ||
|
|
||
| const factory = (await hre.ethers.getContractFactory(args.name)) as any; | ||
| const contract = factory.attach(args.contract).connect(signer); | ||
|
|
||
| const tx = await contract.call( | ||
| args.receiver, | ||
| encodedParameters, | ||
| revertOptions, | ||
| txOptions | ||
| ); | ||
|
|
||
| console.log(`Transaction hash: ${tx.hash}`); | ||
| await tx.wait(); | ||
| console.log("gatewayCall executed successfully"); | ||
| }; | ||
|
|
||
| task("echo-call", "Calls the gateway on a contract on EVM", main) | ||
| .addParam("contract", "The address of the deployed contract") | ||
| .addOptionalParam( | ||
| "txOptionsGasPrice", | ||
| "The gas price for the transaction", | ||
| 10000000000, | ||
| types.int | ||
| ) | ||
| .addOptionalParam( | ||
| "txOptionsGasLimit", | ||
| "The gas limit for the transaction", | ||
| 7000000, | ||
| types.int | ||
| ) | ||
| .addFlag("callOnRevert", "Whether to call on revert") | ||
| .addOptionalParam( | ||
| "revertAddress", | ||
| "Revert address", | ||
| "0x0000000000000000000000000000000000000000" | ||
| ) | ||
| .addOptionalParam("revertMessage", "Revert message", "0x") | ||
| .addParam( | ||
| "receiver", | ||
| "The address of the receiver contract on a connected chain" | ||
| ) | ||
| .addOptionalParam( | ||
| "onRevertGasLimit", | ||
| "The gas limit for the revert transaction", | ||
| 7000000, | ||
| types.int | ||
| ) | ||
| .addParam("name", "The name of the contract", "Echo") | ||
| .addParam("types", `The types of the parameters (example: '["string"]')`) | ||
| .addVariadicPositionalParam("values", "The values of the parameters"); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / Slither
Contracts that lock Ether