WETHGateway

Git Source

Inherits: IWETHGateway

Author: Morpho Labs

A contract allowing to wrap and unwrap ETH when interacting with Morpho.

State Variables

_WETH

The address of the WETH contract.

address internal constant _WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;

_MORPHO_DAO

The address of the Morpho DAO.

address internal constant _MORPHO_DAO = 0xcBa28b38103307Ec8dA98377ffF9816C164f9AFa;

_MORPHO

The address of the Morpho protocol.

IMorpho internal immutable _MORPHO;

Functions

constructor

Contract constructor.

constructor(address morpho);

Parameters

NameTypeDescription
morphoaddressThe address of the Morpho protocol.

WETH

Returns the address of the WETH contract.

function WETH() external pure returns (address);

MORPHO

Returns the address of the Morpho protocol.

function MORPHO() external view returns (address);

MORPHO_DAO

Returns the address of the Morpho DAO.

function MORPHO_DAO() external pure returns (address);

skim

Transfers this contract's given ERC20 balance to the Morpho DAO, to avoid having funds stuck.

function skim(address underlying) external;

supplyETH

Wraps msg.value ETH in WETH and supplies them to Morpho on behalf of onBehalf.

function supplyETH(address onBehalf, uint256 maxIterations) external payable returns (uint256);

Returns

NameTypeDescription
<none>uint256The actual amount supplied (in wei).

supplyCollateralETH

Wraps msg.value ETH in WETH and supplies them as collateral to Morpho on behalf of onBehalf.

function supplyCollateralETH(address onBehalf) external payable returns (uint256);

Returns

NameTypeDescription
<none>uint256The actual amount supplied as collateral (in wei).

borrowETH

Borrows WETH on behalf of msg.sender, unwraps the ETH and sends them to receiver. Note: msg.sender must have approved this contract to be its manager.

function borrowETH(uint256 amount, address receiver, uint256 maxIterations) external returns (uint256 borrowed);

Returns

NameTypeDescription
borroweduint256The actual amount borrowed (in wei).

repayETH

Wraps msg.value ETH in WETH and repays onBehalf's debt on Morpho.

function repayETH(address onBehalf) external payable returns (uint256 repaid);

Returns

NameTypeDescription
repaiduint256The actual amount repaid (in wei).

withdrawETH

Withdraws WETH up to amount on behalf of msg.sender, unwraps it to WETH and sends it to receiver. Note: msg.sender must have approved this contract to be its manager.

function withdrawETH(uint256 amount, address receiver, uint256 maxIterations) external returns (uint256 withdrawn);

Returns

NameTypeDescription
withdrawnuint256The actual amount withdrawn (in wei).

withdrawCollateralETH

Withdraws WETH as collateral up to amount on behalf of msg.sender, unwraps it to WETH and sends it to receiver. Note: msg.sender must have approved this contract to be its manager.

function withdrawCollateralETH(uint256 amount, address receiver) external returns (uint256 withdrawn);

Returns

NameTypeDescription
withdrawnuint256The actual collateral amount withdrawn (in wei).

receive

Only the WETH contract is allowed to transfer ETH to this contracts.

receive() external payable;

_wrapETH

Wraps amount of ETH to WETH.

function _wrapETH(uint256 amount) internal;

_unwrapAndTransferETH

Unwraps amount of WETH to ETH and transfers it to receiver.

function _unwrapAndTransferETH(uint256 amount, address receiver) internal;

Errors

OnlyWETH

Thrown when another address than WETH sends ETH to the contract.

error OnlyWETH();

AddressIsZero

Thrown when the morpho address passed in the constructor is zero.

error AddressIsZero();

AmountIsZero

Thrown when the amount used is zero.

error AmountIsZero();