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: rename src to contracts #314

Merged
merged 25 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { IERC20Custody } from "./interfaces/IERC20Custody.sol";
import { IGatewayEVM } from "./interfaces/IGatewayEVM.sol";
import {IERC20Custody} from "./interfaces/IERC20Custody.sol";
import {IGatewayEVM} from "./interfaces/IGatewayEVM.sol";

import { RevertContext } from "src/Revert.sol";
import {RevertContext} from "../../contracts/Revert.sol";

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand Down Expand Up @@ -78,12 +78,7 @@ contract ERC20Custody is IERC20Custody, ReentrancyGuard, AccessControl, Pausable
address to,
address token,
uint256 amount
)
external
nonReentrant
onlyRole(WITHDRAWER_ROLE)
whenNotPaused
{
) external nonReentrant onlyRole(WITHDRAWER_ROLE) whenNotPaused {
if (!whitelisted[token]) revert NotWhitelisted();

IERC20(token).safeTransfer(to, amount);
Expand All @@ -102,12 +97,7 @@ contract ERC20Custody is IERC20Custody, ReentrancyGuard, AccessControl, Pausable
address token,
uint256 amount,
bytes calldata data
)
public
nonReentrant
onlyRole(WITHDRAWER_ROLE)
whenNotPaused
{
) public nonReentrant onlyRole(WITHDRAWER_ROLE) whenNotPaused {
if (!whitelisted[token]) revert NotWhitelisted();

// Transfer the tokens to the Gateway contract
Expand All @@ -133,12 +123,7 @@ contract ERC20Custody is IERC20Custody, ReentrancyGuard, AccessControl, Pausable
uint256 amount,
bytes calldata data,
RevertContext calldata revertContext
)
public
nonReentrant
onlyRole(WITHDRAWER_ROLE)
whenNotPaused
{
) public nonReentrant onlyRole(WITHDRAWER_ROLE) whenNotPaused {
if (!whitelisted[token]) revert NotWhitelisted();

// Transfer the tokens to the Gateway contract
Expand Down
81 changes: 18 additions & 63 deletions v2/src/evm/GatewayEVM.sol → v2/contracts/evm/GatewayEVM.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { ZetaConnectorBase } from "./ZetaConnectorBase.sol";
import { IERC20Custody } from "./interfaces/IERC20Custody.sol";
import { IGatewayEVM } from "./interfaces/IGatewayEVM.sol";
import { RevertContext, RevertOptions, Revertable } from "src/Revert.sol";
import {ZetaConnectorBase} from "./ZetaConnectorBase.sol";
import {IERC20Custody} from "./interfaces/IERC20Custody.sol";
import {IGatewayEVM} from "./interfaces/IGatewayEVM.sol";
import {RevertContext, RevertOptions, Revertable} from "../../contracts/Revert.sol";

import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
Expand Down Expand Up @@ -69,14 +69,14 @@ contract GatewayEVM is

/// @dev Authorizes the upgrade of the contract, sender must be owner.
/// @param newImplementation Address of the new implementation.
function _authorizeUpgrade(address newImplementation) internal override onlyRole(DEFAULT_ADMIN_ROLE) { }
function _authorizeUpgrade(address newImplementation) internal override onlyRole(DEFAULT_ADMIN_ROLE) {}

/// @dev Internal function to execute a call to a destination address.
/// @param destination Address to call.
/// @param data Calldata to pass to the call.
/// @return The result of the call.
function _execute(address destination, bytes calldata data) internal returns (bytes memory) {
(bool success, bytes memory result) = destination.call{ value: msg.value }(data);
(bool success, bytes memory result) = destination.call{value: msg.value}(data);
if (!success) revert ExecutionFailed();

return result;
Expand All @@ -100,15 +100,9 @@ contract GatewayEVM is
address destination,
bytes calldata data,
RevertContext calldata revertContext
)
public
payable
onlyRole(TSS_ROLE)
whenNotPaused
nonReentrant
{
) public payable onlyRole(TSS_ROLE) whenNotPaused nonReentrant {
if (destination == address(0)) revert ZeroAddress();
(bool success,) = destination.call{ value: msg.value }("");
(bool success, ) = destination.call{value: msg.value}("");
if (!success) revert ExecutionFailed();
Revertable(destination).onRevert(revertContext);

Expand All @@ -123,14 +117,7 @@ contract GatewayEVM is
function execute(
address destination,
bytes calldata data
)
external
payable
onlyRole(TSS_ROLE)
whenNotPaused
nonReentrant
returns (bytes memory)
{
) external payable onlyRole(TSS_ROLE) whenNotPaused nonReentrant returns (bytes memory) {
if (destination == address(0)) revert ZeroAddress();
bytes memory result = _execute(destination, data);

Expand All @@ -151,12 +138,7 @@ contract GatewayEVM is
address to,
uint256 amount,
bytes calldata data
)
public
onlyRole(ASSET_HANDLER_ROLE)
whenNotPaused
nonReentrant
{
) public onlyRole(ASSET_HANDLER_ROLE) whenNotPaused nonReentrant {
if (amount == 0) revert InsufficientERC20Amount();
if (to == address(0)) revert ZeroAddress();
// Approve the target contract to spend the tokens
Expand Down Expand Up @@ -190,12 +172,7 @@ contract GatewayEVM is
uint256 amount,
bytes calldata data,
RevertContext calldata revertContext
)
external
onlyRole(ASSET_HANDLER_ROLE)
whenNotPaused
nonReentrant
{
) external onlyRole(ASSET_HANDLER_ROLE) whenNotPaused nonReentrant {
if (amount == 0) revert InsufficientERC20Amount();
if (to == address(0)) revert ZeroAddress();

Expand All @@ -211,16 +188,11 @@ contract GatewayEVM is
function deposit(
address receiver,
RevertOptions calldata revertOptions
)
external
payable
whenNotPaused
nonReentrant
{
) external payable whenNotPaused nonReentrant {
if (msg.value == 0) revert InsufficientETHAmount();
if (receiver == address(0)) revert ZeroAddress();

(bool deposited,) = tssAddress.call{ value: msg.value }("");
(bool deposited, ) = tssAddress.call{value: msg.value}("");

if (!deposited) revert DepositFailed();

Expand All @@ -237,11 +209,7 @@ contract GatewayEVM is
uint256 amount,
address asset,
RevertOptions calldata revertOptions
)
external
whenNotPaused
nonReentrant
{
) external whenNotPaused nonReentrant {
if (amount == 0) revert InsufficientERC20Amount();
if (receiver == address(0)) revert ZeroAddress();

Expand All @@ -258,16 +226,11 @@ contract GatewayEVM is
address receiver,
bytes calldata payload,
RevertOptions calldata revertOptions
)
external
payable
whenNotPaused
nonReentrant
{
) external payable whenNotPaused nonReentrant {
if (msg.value == 0) revert InsufficientETHAmount();
if (receiver == address(0)) revert ZeroAddress();

(bool deposited,) = tssAddress.call{ value: msg.value }("");
(bool deposited, ) = tssAddress.call{value: msg.value}("");

if (!deposited) revert DepositFailed();

Expand All @@ -286,11 +249,7 @@ contract GatewayEVM is
address asset,
bytes calldata payload,
RevertOptions calldata revertOptions
)
external
whenNotPaused
nonReentrant
{
) external whenNotPaused nonReentrant {
if (amount == 0) revert InsufficientERC20Amount();
if (receiver == address(0)) revert ZeroAddress();

Expand All @@ -307,11 +266,7 @@ contract GatewayEVM is
address receiver,
bytes calldata payload,
RevertOptions calldata revertOptions
)
external
whenNotPaused
nonReentrant
{
) external whenNotPaused nonReentrant {
if (receiver == address(0)) revert ZeroAddress();
emit Called(msg.sender, receiver, payload, revertOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

import { RevertContext } from "src/Revert.sol";
import { IGatewayEVM, IGatewayEVMErrors, IGatewayEVMEvents } from "src/evm/interfaces/IGatewayEVM.sol";
import "src/evm/interfaces/IZetaConnector.sol";
import {RevertContext} from "../../contracts/Revert.sol";
import {IGatewayEVM, IGatewayEVMErrors, IGatewayEVMEvents} from "../../contracts/evm/interfaces/IGatewayEVM.sol";
import "../../contracts/evm/interfaces/IZetaConnector.sol";

/// @title ZetaConnectorBase
/// @notice Abstract base contract for ZetaConnector.
Expand Down Expand Up @@ -73,9 +73,7 @@ abstract contract ZetaConnectorBase is IZetaConnectorEvents, ReentrancyGuard, Pa
uint256 amount,
bytes calldata data,
bytes32 internalSendHash
)
external
virtual;
) external virtual;

/// @notice Withdraw tokens and call a contract with a revert callback through Gateway.
/// @param to The address to withdraw tokens to.
Expand All @@ -89,9 +87,7 @@ abstract contract ZetaConnectorBase is IZetaConnectorEvents, ReentrancyGuard, Pa
bytes calldata data,
bytes32 internalSendHash,
RevertContext calldata revertContext
)
external
virtual;
) external virtual;

/// @notice Handle received tokens.
/// @param amount The amount of tokens received.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { RevertContext } from "src/Revert.sol";
import {RevertContext} from "../../../contracts/Revert.sol";

/// @title IERC20CustodyEvents
/// @notice Interface for the events emitted by the ERC20 custody contract.
Expand All @@ -26,7 +26,11 @@ interface IERC20CustodyEvents {
/// @param data The calldata passed to the contract call.
/// @param revertContext Revert context to pass to onRevert.
event WithdrawnAndReverted(
address indexed token, address indexed to, uint256 amount, bytes data, RevertContext revertContext
address indexed token,
address indexed to,
uint256 amount,
bytes data,
RevertContext revertContext
);

/// @notice Emitted when ERC20 token is whitelisted
Expand Down Expand Up @@ -80,6 +84,5 @@ interface IERC20Custody is IERC20CustodyEvents, IERC20CustodyErrors {
uint256 amount,
bytes calldata data,
RevertContext calldata revertContext
)
external;
) external;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import "src/Revert.sol";
import "../../../contracts/Revert.sol";

/// @title IGatewayEVMEvents
/// @notice Interface for the events emitted by the GatewayEVM contract.
Expand Down Expand Up @@ -101,9 +101,7 @@ interface IGatewayEVM is IGatewayEVMErrors, IGatewayEVMEvents {
address destination,
bytes calldata data,
RevertContext calldata revertContext
)
external
payable;
) external payable;

/// @notice Executes a call to a contract.
/// @param destination The address of the contract to call.
Expand All @@ -123,8 +121,7 @@ interface IGatewayEVM is IGatewayEVMErrors, IGatewayEVMEvents {
uint256 amount,
bytes calldata data,
RevertContext calldata revertContext
)
external;
) external;

/// @notice Deposits ETH to the TSS address.
/// @param receiver Address of the receiver.
Expand All @@ -146,9 +143,7 @@ interface IGatewayEVM is IGatewayEVMErrors, IGatewayEVMEvents {
address receiver,
bytes calldata payload,
RevertOptions calldata revertOptions
)
external
payable;
) external payable;

/// @notice Deposits ERC20 tokens to the custody or connector contract and calls an omnichain smart contract.
/// @param receiver Address of the receiver.
Expand All @@ -162,8 +157,7 @@ interface IGatewayEVM is IGatewayEVMErrors, IGatewayEVMEvents {
address asset,
bytes calldata payload,
RevertOptions calldata revertOptions
)
external;
) external;

/// @notice Calls an omnichain smart contract without asset transfer.
/// @param receiver Address of the receiver.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { RevertContext } from "src/Revert.sol";
import {RevertContext} from "../../../contracts/Revert.sol";

/// @title IZetaConnectorEvents
/// @notice Interface for the events emitted by the ZetaConnector contracts.
Expand Down
Loading
Loading