Skip to content

Commit

Permalink
yarn generate
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Aug 13, 2024
1 parent 748c709 commit 8d13b25
Show file tree
Hide file tree
Showing 45 changed files with 208 additions and 116 deletions.
27 changes: 21 additions & 6 deletions v2/contracts/evm/ERC20Custody.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 {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 "contracts/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,7 +78,12 @@ 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 @@ -97,7 +102,12 @@ 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 @@ -123,7 +133,12 @@ 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: 63 additions & 18 deletions 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 "contracts/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,9 +100,15 @@ 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 @@ -117,7 +123,14 @@ 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 @@ -138,7 +151,12 @@ 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 @@ -172,7 +190,12 @@ 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 @@ -188,11 +211,16 @@ 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 @@ -209,7 +237,11 @@ 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 @@ -226,11 +258,16 @@ 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 @@ -249,7 +286,11 @@ 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 @@ -266,7 +307,11 @@ 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
12 changes: 8 additions & 4 deletions v2/contracts/evm/ZetaConnectorBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

import {RevertContext} from "contracts/Revert.sol";
import {IGatewayEVM, IGatewayEVMErrors, IGatewayEVMEvents} from "contracts/evm/interfaces/IGatewayEVM.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
Expand Down Expand Up @@ -73,7 +73,9 @@ 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 @@ -87,7 +89,9 @@ 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
11 changes: 4 additions & 7 deletions v2/contracts/evm/interfaces/IERC20Custody.sol
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 "contracts/Revert.sol";
import { RevertContext } from "contracts/Revert.sol";

/// @title IERC20CustodyEvents
/// @notice Interface for the events emitted by the ERC20 custody contract.
Expand All @@ -26,11 +26,7 @@ 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 @@ -84,5 +80,6 @@ interface IERC20Custody is IERC20CustodyEvents, IERC20CustodyErrors {
uint256 amount,
bytes calldata data,
RevertContext calldata revertContext
) external;
)
external;
}
14 changes: 10 additions & 4 deletions v2/contracts/evm/interfaces/IGatewayEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ 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 @@ -121,7 +123,8 @@ 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 @@ -143,7 +146,9 @@ 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 @@ -157,7 +162,8 @@ 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
2 changes: 1 addition & 1 deletion v2/contracts/evm/interfaces/IZetaConnector.sol
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 "contracts/Revert.sol";
import { RevertContext } from "contracts/Revert.sol";

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

0 comments on commit 8d13b25

Please sign in to comment.