TransferHelper

Git Source

Author: transientlabs.xyz

Abstract contract that has helper function for sending ETH and ERC20's safely

Functions

_safeTransferETH

Function to force transfer ETH, defaulting to forwarding 100k gas

On failure to send the ETH, the ETH is converted to WETH and sent

Care should be taken to always pass the proper WETH address that adheres to IWETH

function _safeTransferETH(address recipient, uint256 amount, address weth) internal;

Parameters

NameTypeDescription
recipientaddressThe recipient of the ETH
amountuint256The amount of ETH to send
wethaddressThe WETH token address

_safeTransferETH

Function to force transfer ETH, with a gas limit

On failure to send the ETH, the ETH is converted to WETH and sent

Care should be taken to always pass the proper WETH address that adheres to IWETH

If the amount is zero, the function returns in order to save gas

function _safeTransferETH(address recipient, uint256 amount, address weth, uint256 gasLimit) internal;

Parameters

NameTypeDescription
recipientaddressThe recipient of the ETH
amountuint256The amount of ETH to send
wethaddressThe WETH token address
gasLimituint256The gas to forward

_safeTransferERC20

Function to safely transfer ERC-20 tokens from the contract, without checking for token tax

Does not check if the sender has enough balance as that is handled by the token contract

Does not check for token tax as that could lock up funds in the contract

Reverts on failure to transfer

If the amount is zero, the function returns in order to save gas

function _safeTransferERC20(address recipient, address currency, uint256 amount) internal;

Parameters

NameTypeDescription
recipientaddressThe recipient of the ERC-20 token
currencyaddressThe address of the ERC-20 token
amountuint256The amount of ERC-20 to send

_safeTransferFromERC20

Function to safely transfer ERC-20 tokens from another address to a recipient

Does not check if the sender has enough balance or allowance for this contract as that is handled by the token contract

Reverts on failure to transfer

Reverts if there is a token tax taken out

Returns and doesn't do anything if the sender and recipient are the same address

If the amount is zero, the function returns in order to save gas

function _safeTransferFromERC20(address sender, address recipient, address currency, uint256 amount) internal;

Parameters

NameTypeDescription
senderaddressThe sender of the tokens
recipientaddressThe recipient of the ERC-20 token
currencyaddressThe address of the ERC-20 token
amountuint256The amount of ERC-20 to send

Errors

ETHTransferFailed

ETH transfer failed

error ETHTransferFailed();

InsufficentERC20Transfer

Transferred too few ERC-20 tokens

error InsufficentERC20Transfer();