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

refactor: disable ZETA related functions and remove call functions not using callOptions #393

Merged
merged 12 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
8 changes: 8 additions & 0 deletions v2/contracts/Errors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

/// @title INotSupportedMethods
/// @notice Interface for contracts that with non supported methods.
interface INotSupportedMethods {
lumtis marked this conversation as resolved.
Show resolved Hide resolved
error ZETANotSupported();
}
23 changes: 15 additions & 8 deletions v2/contracts/evm/GatewayEVM.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { INotSupportedMethods } from "../../contracts/Errors.sol";
import { RevertContext, RevertOptions, Revertable } from "../../contracts/Revert.sol";
import { ZetaConnectorBase } from "./ZetaConnectorBase.sol";
import { IERC20Custody } from "./interfaces/IERC20Custody.sol";
Expand All @@ -23,7 +24,8 @@ contract GatewayEVM is
UUPSUpgradeable,
IGatewayEVM,
ReentrancyGuardUpgradeable,
PausableUpgradeable
PausableUpgradeable,
INotSupportedMethods
{
using SafeERC20 for IERC20;

Expand Down Expand Up @@ -390,13 +392,18 @@ contract GatewayEVM is
/// @param amount Amount of tokens to transfer.
function _transferFromToAssetHandler(address from, address token, uint256 amount) private {
if (token == zetaToken) {
// transfer to connector
// transfer amount to gateway
IERC20(token).safeTransferFrom(from, address(this), amount);
// approve connector to handle tokens depending on connector version (eg. lock or burn)
if (!IERC20(token).approve(zetaConnector, amount)) revert ApprovalFailed();
// send tokens to connector
ZetaConnectorBase(zetaConnector).receiveTokens(amount);
// TODO: remove error and comment out code once ZETA supported back
// https://github.com/zeta-chain/protocol-contracts/issues/394
// ZETA token is currently not supported for deposit
revert ZETANotSupported();

// // transfer to connector
// // transfer amount to gateway
// IERC20(token).safeTransferFrom(from, address(this), amount);
// // approve connector to handle tokens depending on connector version (eg. lock or burn)
// if (!IERC20(token).approve(zetaConnector, amount)) revert ApprovalFailed();
// // send tokens to connector
// ZetaConnectorBase(zetaConnector).receiveTokens(amount);
} else {
// transfer to custody
if (!IERC20Custody(custody).whitelisted(token)) revert NotWhitelistedInCustody();
Expand Down
202 changes: 58 additions & 144 deletions v2/contracts/zevm/GatewayZEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.26;

import { CallOptions, IGatewayZEVM } from "./interfaces/IGatewayZEVM.sol";

import { INotSupportedMethods } from "../../contracts/Errors.sol";
import { RevertContext, RevertOptions, Revertable } from "../../contracts/Revert.sol";
import "./interfaces/IWZETA.sol";
import { IZRC20 } from "./interfaces/IZRC20.sol";
Expand All @@ -23,7 +24,8 @@ contract GatewayZEVM is
AccessControlUpgradeable,
UUPSUpgradeable,
ReentrancyGuardUpgradeable,
PausableUpgradeable
PausableUpgradeable,
INotSupportedMethods
{
/// @notice Error indicating a zero address was provided.
error ZeroAddress();
Expand Down Expand Up @@ -160,45 +162,6 @@ contract GatewayZEVM is
);
}

/// @notice Withdraw ZRC20 tokens and call a smart contract on an external chain.
/// @param receiver The receiver address on the external chain.
/// @param amount The amount of tokens to withdraw.
/// @param zrc20 The address of the ZRC20 token.
/// @param message The calldata to pass to the contract call.
/// @param gasLimit Gas limit.
/// @param revertOptions Revert options.
function withdrawAndCall(
bytes memory receiver,
uint256 amount,
address zrc20,
bytes calldata message,
uint256 gasLimit,
RevertOptions calldata revertOptions
)
external
nonReentrant
whenNotPaused
{
if (receiver.length == 0) revert ZeroAddress();
if (amount == 0) revert InsufficientZRC20Amount();
if (gasLimit == 0) revert InsufficientGasLimit();
if (message.length + revertOptions.revertMessage.length > MAX_MESSAGE_SIZE) revert MessageSizeExceeded();

uint256 gasFee = _withdrawZRC20WithGasLimit(amount, zrc20, gasLimit);
emit Withdrawn(
msg.sender,
0,
receiver,
zrc20,
amount,
gasFee,
IZRC20(zrc20).PROTOCOL_FLAT_FEE(),
message,
CallOptions({ gasLimit: gasLimit, isArbitraryCall: true }),
revertOptions
);
}

/// @notice Withdraw ZRC20 tokens and call a smart contract on an external chain.
/// @param receiver The receiver address on the external chain.
/// @param amount The amount of tokens to withdraw.
Expand Down Expand Up @@ -239,102 +202,76 @@ contract GatewayZEVM is
}

/// @notice Withdraw ZETA tokens to an external chain.
/// @param receiver The receiver address on the external chain.
/// @param amount The amount of tokens to withdraw.
/// @param revertOptions Revert options.
//// @param receiver The receiver address on the external chain.
//// @param amount The amount of tokens to withdraw.
//// @param revertOptions Revert options.
function withdraw(
bytes memory receiver,
uint256 amount,
uint256 chainId,
RevertOptions calldata revertOptions
bytes memory, /*receiver*/
uint256, /*amount*/
uint256, /*chainId*/
RevertOptions calldata /*revertOptions*/
)
external
nonReentrant
whenNotPaused
{
if (receiver.length == 0) revert ZeroAddress();
if (amount == 0) revert InsufficientZetaAmount();
if (revertOptions.revertMessage.length > MAX_MESSAGE_SIZE) revert MessageSizeExceeded();

_transferZETA(amount, PROTOCOL_ADDRESS);
emit Withdrawn(
msg.sender,
chainId,
receiver,
address(zetaToken),
amount,
0,
0,
"",
CallOptions({ gasLimit: 0, isArbitraryCall: true }),
revertOptions
);
// TODO: remove error and comment out code once ZETA supported back
// https://github.com/zeta-chain/protocol-contracts/issues/394
// ZETA is not currently supported for withdraws
revert ZETANotSupported();

// if (receiver.length == 0) revert ZeroAddress();
// if (amount == 0) revert InsufficientZetaAmount();
// if (revertOptions.revertMessage.length > MAX_MESSAGE_SIZE) revert MessageSizeExceeded();

// _transferZETA(amount, PROTOCOL_ADDRESS);
// emit Withdrawn(
// msg.sender,
// chainId,
// receiver,
// address(zetaToken),
// amount,
// 0,
// 0,
// "",
// CallOptions({ gasLimit: 0, isArbitraryCall: true }),
// revertOptions
// );
}

/// @notice Withdraw ZETA tokens and call a smart contract on an external chain.
/// @param receiver The receiver address on the external chain.
/// @param amount The amount of tokens to withdraw.
/// @param chainId Chain id of the external chain.
/// @param message The calldata to pass to the contract call.
/// @param revertOptions Revert options.
//// @param receiver The receiver address on the external chain.
//// @param amount The amount of tokens to withdraw.
//// @param chainId Chain id of the external chain.
//// @param message The calldata to pass to the contract call.
//// @param callOptions Call options including gas limit and arbirtrary call flag.
//// @param revertOptions Revert options.
function withdrawAndCall(
bytes memory receiver,
uint256 amount,
uint256 chainId,
bytes calldata message,
RevertOptions calldata revertOptions
)
external
nonReentrant
whenNotPaused
{
if (receiver.length == 0) revert ZeroAddress();
if (amount == 0) revert InsufficientZetaAmount();
if (message.length + revertOptions.revertMessage.length > MAX_MESSAGE_SIZE) revert MessageSizeExceeded();

_transferZETA(amount, PROTOCOL_ADDRESS);
emit Withdrawn(
msg.sender,
chainId,
receiver,
address(zetaToken),
amount,
0,
0,
message,
CallOptions({ gasLimit: 0, isArbitraryCall: true }),
revertOptions
);
}

/// @notice Withdraw ZETA tokens and call a smart contract on an external chain.
/// @param receiver The receiver address on the external chain.
/// @param amount The amount of tokens to withdraw.
/// @param chainId Chain id of the external chain.
/// @param message The calldata to pass to the contract call.
/// @param callOptions Call options including gas limit and arbirtrary call flag.
/// @param revertOptions Revert options.
function withdrawAndCall(
bytes memory receiver,
uint256 amount,
uint256 chainId,
bytes calldata message,
CallOptions calldata callOptions,
RevertOptions calldata revertOptions
bytes memory, /*receiver*/
uint256, /*amount*/
uint256, /*chainId*/
bytes calldata, /*message*/
CallOptions calldata, /*callOptions*/
RevertOptions calldata /*revertOptions*/
)
external
nonReentrant
whenNotPaused
{
if (receiver.length == 0) revert ZeroAddress();
if (amount == 0) revert InsufficientZetaAmount();
if (callOptions.gasLimit == 0) revert InsufficientGasLimit();
if (message.length + revertOptions.revertMessage.length > MAX_MESSAGE_SIZE) revert MessageSizeExceeded();

_transferZETA(amount, PROTOCOL_ADDRESS);
emit Withdrawn(
msg.sender, chainId, receiver, address(zetaToken), amount, 0, 0, message, callOptions, revertOptions
);
// TODO: remove error and comment out code once ZETA supported back
// https://github.com/zeta-chain/protocol-contracts/issues/394
// ZETA is not currently supported for withdraws
revert ZETANotSupported();

// if (receiver.length == 0) revert ZeroAddress();
// if (amount == 0) revert InsufficientZetaAmount();
// if (callOptions.gasLimit == 0) revert InsufficientGasLimit();
// if (message.length + revertOptions.revertMessage.length > MAX_MESSAGE_SIZE) revert MessageSizeExceeded();

// _transferZETA(amount, PROTOCOL_ADDRESS);
// emit Withdrawn(
// msg.sender, chainId, receiver, address(zetaToken), amount, 0, 0, message, callOptions, revertOptions
// );
}

/// @notice Call a smart contract on an external chain without asset transfer.
Expand All @@ -360,29 +297,6 @@ contract GatewayZEVM is
_call(receiver, zrc20, message, callOptions, revertOptions);
}

/// @notice Call a smart contract on an external chain without asset transfer.
/// @param receiver The receiver address on the external chain.
/// @param zrc20 Address of zrc20 to pay fees.
/// @param message The calldata to pass to the contract call.
/// @param gasLimit Gas limit.
/// @param revertOptions Revert options.
function call(
bytes memory receiver,
address zrc20,
bytes calldata message,
uint256 gasLimit,
RevertOptions calldata revertOptions
)
external
nonReentrant
whenNotPaused
{
if (gasLimit == 0) revert InsufficientGasLimit();
if (message.length + revertOptions.revertMessage.length > MAX_MESSAGE_SIZE) revert MessageSizeExceeded();

_call(receiver, zrc20, message, CallOptions({ gasLimit: gasLimit, isArbitraryCall: true }), revertOptions);
}

function _call(
bytes memory receiver,
address zrc20,
Expand Down
47 changes: 0 additions & 47 deletions v2/contracts/zevm/interfaces/IGatewayZEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,6 @@ interface IGatewayZEVM is IGatewayZEVMErrors, IGatewayZEVMEvents {
)
external;

/// @notice Withdraw ZRC20 tokens and call a smart contract on an external chain.
/// @param receiver The receiver address on the external chain.
/// @param amount The amount of tokens to withdraw.
/// @param zrc20 The address of the ZRC20 token.
/// @param message The calldata to pass to the contract call.
/// @param gasLimit Gas limit.
/// @param revertOptions Revert options.
function withdrawAndCall(
bytes memory receiver,
uint256 amount,
address zrc20,
bytes calldata message,
uint256 gasLimit,
RevertOptions calldata revertOptions
)
external;

/// @notice Withdraw ZRC20 tokens and call a smart contract on an external chain.
/// @param receiver The receiver address on the external chain.
/// @param amount The amount of tokens to withdraw.
Expand All @@ -154,21 +137,6 @@ interface IGatewayZEVM is IGatewayZEVMErrors, IGatewayZEVMEvents {
)
external;

/// @notice Withdraw ZETA tokens and call a smart contract on an external chain.
/// @param receiver The receiver address on the external chain.
/// @param amount The amount of tokens to withdraw.
/// @param chainId Chain id of the external chain.
/// @param message The calldata to pass to the contract call.
/// @param revertOptions Revert options.
function withdrawAndCall(
bytes memory receiver,
uint256 amount,
uint256 chainId,
bytes calldata message,
RevertOptions calldata revertOptions
)
external;

/// @notice Withdraw ZETA tokens and call a smart contract on an external chain.
/// @param receiver The receiver address on the external chain.
/// @param amount The amount of tokens to withdraw.
Expand Down Expand Up @@ -201,21 +169,6 @@ interface IGatewayZEVM is IGatewayZEVMErrors, IGatewayZEVMEvents {
)
external;

/// @notice Call a smart contract on an external chain without asset transfer.
/// @param receiver The receiver address on the external chain.
/// @param zrc20 Address of zrc20 to pay fees.
/// @param message The calldata to pass to the contract call.
/// @param gasLimit Gas limit.
/// @param revertOptions Revert options.
function call(
bytes memory receiver,
address zrc20,
bytes calldata message,
uint256 gasLimit,
RevertOptions calldata revertOptions
)
external;

/// @notice Deposit foreign coins into ZRC20.
/// @param zrc20 The address of the ZRC20 token.
/// @param amount The amount of tokens to deposit.
Expand Down
1 change: 1 addition & 0 deletions v2/docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- [SystemContract](contracts/zevm/SystemContract.sol/contract.SystemContract.md)
- [ZRC20Errors](contracts/zevm/ZRC20.sol/interface.ZRC20Errors.md)
- [ZRC20](contracts/zevm/ZRC20.sol/contract.ZRC20.md)
- [INotSupportedMethods](contracts/Errors.sol/interface.INotSupportedMethods.md)
- [RevertOptions](contracts/Revert.sol/struct.RevertOptions.md)
- [RevertContext](contracts/Revert.sol/struct.RevertContext.md)
- [Revertable](contracts/Revert.sol/interface.Revertable.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# INotSupportedMethods
[Git Source](https://github.com/zeta-chain/protocol-contracts/blob/7e13d4407420cd4ff52ed44cc892c54d5f3d02cd/contracts/Errors.sol)

Interface for contracts that with non supported methods.


## Errors
### ZETANotSupported

```solidity
error ZETANotSupported();
```

Loading