Skip to content

Commit

Permalink
refactor: disable ZETA related functions and remove call functions no…
Browse files Browse the repository at this point in the history
…t using `callOptions` (#393)

Co-authored-by: skosito <[email protected]>
  • Loading branch information
lumtis and skosito authored Oct 16, 2024
1 parent a675f8a commit db2f95f
Show file tree
Hide file tree
Showing 45 changed files with 676 additions and 1,594 deletions.
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 {
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 @@ -39,6 +39,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)
13 changes: 13 additions & 0 deletions v2/docs/src/contracts/Errors.sol/interface.INotSupportedMethods.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/main/v2/contracts/Errors.sol)

Interface for contracts that with non supported methods.


## Errors
### ZETANotSupported

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

Loading

0 comments on commit db2f95f

Please sign in to comment.