Skip to content
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

testing onabort #230

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/slither.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ jobs:
file: "call.sarif"
- project: "examples/swap"
file: "swap.sarif"
- project: "examples/nft"
file: "nft.sarif"
- project: "examples/token"
file: "token.sarif"
permissions:
contents: read
security-events: write
Expand Down
4 changes: 3 additions & 1 deletion examples/call/contracts/Connected.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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
using SafeERC20 for IERC20;

GatewayEVM public immutable gateway;

Expand Down Expand Up @@ -76,12 +76,14 @@ contract Connected {

function hello(string memory message) external payable {
emit HelloEvent("Hello on EVM", message);
revert();
}

function onCall(
MessageContext calldata context,
bytes calldata message
) external payable onlyGateway returns (bytes4) {
revert();
emit HelloEvent("Hello on EVM from onCall()", "hey");
return "";
}
Expand Down
45 changes: 45 additions & 0 deletions examples/call/contracts/Universal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ import "@zetachain/protocol-contracts/contracts/zevm/interfaces/UniversalContrac
import "@zetachain/protocol-contracts/contracts/zevm/interfaces/IGatewayZEVM.sol";
import "@zetachain/protocol-contracts/contracts/zevm/GatewayZEVM.sol";

struct AbortContext {
bytes sender;
address asset;
uint256 amount;
bool outgoing;
uint256 chainID;
bytes revertMessage;
}

contract Universal is UniversalContract {
GatewayZEVM public immutable gateway;

event HelloEvent(string, string);
event RevertEvent(string, RevertContext);
event AbortEvent(string, AbortContext);

error TransferFailed();
error Unauthorized();
Expand Down Expand Up @@ -41,6 +51,36 @@ contract Universal is UniversalContract {
gateway.call(receiver, zrc20, message, callOptions, revertOptions);
}

function callMulti(
bytes[] memory receiverArray,
address[] memory zrc20Array,
bytes calldata messages,
CallOptions memory callOptions,
RevertOptions memory revertOptions
) external {
for (uint256 i = 0; i < zrc20Array.length; i++) {
(, uint256 gasFee) = IZRC20(zrc20Array[i])
.withdrawGasFeeWithGasLimit(callOptions.gasLimit);
if (
!IZRC20(zrc20Array[i]).transferFrom(
msg.sender,
address(this),
gasFee
)
) {
revert TransferFailed();
}
IZRC20(zrc20Array[i]).approve(address(gateway), gasFee);
gateway.call(
receiverArray[i],
zrc20Array[i],
messages,
callOptions,
revertOptions
);
}
}

function withdraw(
bytes memory receiver,
uint256 amount,
Expand Down Expand Up @@ -110,6 +150,7 @@ contract Universal is UniversalContract {
uint256 amount,
bytes calldata message
) external override onlyGateway {
revert();
string memory name = abi.decode(message, (string));
emit HelloEvent("Hello on ZetaChain", name);
}
Expand All @@ -119,4 +160,8 @@ contract Universal is UniversalContract {
) external onlyGateway {
emit RevertEvent("Revert on ZetaChain", revertContext);
}

function onAbort(AbortContext calldata abortContext) external {
emit AbortEvent("Abort on ZetaChain", abortContext);
}
}
22 changes: 8 additions & 14 deletions examples/call/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import "./tasks/deploy";
import "./tasks/universalCall";
import "./tasks/connectedCall";
import "./tasks/connectedDeposit";
import "./tasks/connectedDepositAndCall";
import "./tasks/universalWithdraw";
import "./tasks/universalWithdrawAndCall";
import "@zetachain/localnet/tasks";
import "@nomicfoundation/hardhat-toolbox";
import { HardhatUserConfig } from "hardhat/config";
import * as dotenv from "dotenv";

import "./tasks";
import "@zetachain/localnet/tasks";
import "@zetachain/toolkit/tasks";
import { getHardhatConfig } from "@zetachain/toolkit/client";

import { getHardhatConfigNetworks } from "@zetachain/networks";
import { HardhatUserConfig } from "hardhat/config";
dotenv.config();

const config: HardhatUserConfig = {
networks: {
...getHardhatConfigNetworks(),
},
solidity: "0.8.26",
...getHardhatConfig({ accounts: [process.env.PRIVATE_KEY] }),
};

export default config;
10 changes: 6 additions & 4 deletions examples/call/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"@types/node": ">=12.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"@zetachain/localnet": "4.0.0-rc6",
"@zetachain/toolkit": "13.0.0-rc7",
"@zetachain/localnet": "5.0.0-rc1",
"@zetachain/toolkit": "13.0.0-rc15",
"axios": "^1.3.6",
"chai": "^4.2.0",
"dotenv": "^16.0.3",
Expand Down Expand Up @@ -57,6 +57,8 @@
"@solana-developers/helpers": "^2.4.0",
"@solana/spl-memo": "^0.2.5",
"@solana/web3.js": "^1.95.8",
"@zetachain/protocol-contracts": "11.0.0-rc3"
"@zetachain/networks": "10.0.0-rc4",
"@zetachain/protocol-contracts": "11.0.0-rc3",
"@zetachain/protocol-contracts-solana": "2.0.0-rc1"
}
}
}
Loading