Skip to main content

OpenMevRouter

Functions

constructor

  function constructor(
) public

Initialize contract by setting aave assets

factory

  function factory(
) external returns (address)

WETH

  function WETH(
) external returns (address)

addLiquidity

  function addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity)

Adds liquidity to an ERC-20⇄ERC-20 pool. msg.sender should have already given the router an allowance of at least amountADesired/amountBDesired on tokenA/tokenB

Parameters:

NameTypeDescription
tokenAaddressToken in pool
tokenBaddressToken in pool
amountADesireduint256Amount of token A desired to add to pool
amountBDesireduint256Amount of token B desired to add to pool
amountAMinuint256Minimum amount of token A, can be 0
amountBMinuint256Minimum amount of token B, can be 0
toaddressAddress to receive liquidity token
deadlineuint256Unix timestamp in seconds after which the transaction will revert

Return Values:

TypeDescription
uint256amountA exact amount of token A added to pool
uint256amountB exact amount of token B added to pool
uint256liquidity amount of liquidity token received

addLiquidityETH

  function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountToken, uint256 amountETH, uint256 liquidity)

/ @notice Adds liquidity to an ERC-20⇄WETH pool with ETH. msg.sender should have already given the router an allowance of at least amountTokenDesired on token. msg.value is treated as a amountETHDesired. Leftover ETH, if any, is returned to msg.sender

Parameters:

NameTypeDescription
tokenaddressToken in pool
amountTokenDesireduint256Amount of token desired to add to pool
amountTokenMinuint256Minimum amount of token, can be 0
amountETHMinuint256Minimum amount of ETH, can be 0
toaddressAddress to receive liquidity token
deadlineuint256Unix timestamp in seconds after which the transaction will revert

Return Values:

TypeDescription
uint256amountToken exact amount of token added to pool
uint256amountETH exact amount of ETH added to pool
uint256liquidity amount of liquidity token received

removeLiquidity

  function removeLiquidity(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) public returns (uint256 amountA, uint256 amountB)

Removes liquidity from an ERC-20⇄ERC-20 pool. msg.sender should have already given the router an allowance of at least liquidity on the pool.

Parameters:

NameTypeDescription
tokenAaddressToken in pool
tokenBaddressToken in pool
liquidityuint256Amount of liquidity tokens to remove
amountAMinuint256Minimum amount of token A, can be 0
amountBMinuint256Minimum amount of token B, can be 0
toaddressAddress to receive pool tokens
deadlineuint256Unix timestamp in seconds after which the transaction will revert

Return Values:

TypeDescription
uint256amountA Amount of token A received
uint256amountB Amount of token B received
f

removeLiquidityETH

  function removeLiquidityETH(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) public returns (uint256 amountToken, uint256 amountETH)

otice Removes liquidity from an ERC-20⇄WETH pool and receive ETH. msg.sender should have already given the router an allowance of at least liquidity on the pool.

Parameters:

NameTypeDescription
tokenaddressToken in pool
liquidityuint256Amount of liquidity tokens to remove
amountTokenMinuint256Minimum amount of token, can be 0
amountETHMinuint256Minimum amount of ETH, can be 0
toaddressAddress to receive pool tokens
deadlineuint256Unix timestamp in seconds after which the transaction will revert

Return Values:

TypeDescription
uint256amountToken Amount of token received
uint256amountETH Amount of ETH received
fun

removeLiquidityWithPermit

  function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountA, uint256 amountB)

ice Removes liquidity from an ERC-20⇄ERC-20 pool without pre-approval, thanks to permit.

Parameters:

NameTypeDescription
tokenAaddressToken in pool
tokenBaddressToken in pool
liquidityuint256Amount of liquidity tokens to remove
amountAMinuint256Minimum amount of token A, can be 0
amountBMinuint256Minimum amount of token B, can be 0
toaddressAddress to receive pool tokens
deadlineuint256Unix timestamp in seconds after which the transaction will revert
approveMaxboolWhether or not the approval amount in the signature is for liquidity or uint(-1)
vuint8The v component of the permit signature
rbytes32The r component of the permit signature
sbytes32The s component of the permit signature

Return Values:

TypeDescription
uint256amountA Amount of token A received
uint256amountB Amount of token B received
funct

removeLiquidityETHWithPermit

  function removeLiquidityETHWithPermit(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountToken, uint256 amountETH)

e Removes liquidity from an ERC-20⇄WETTH pool and receive ETH without pre-approval, thanks to permit

Parameters:

NameTypeDescription
tokenaddressToken in pool
liquidityuint256Amount of liquidity tokens to remove
amountTokenMinuint256Minimum amount of token, can be 0
amountETHMinuint256Minimum amount of ETH, can be 0
toaddressAddress to receive pool tokens
deadlineuint256Unix timestamp in seconds after which the transaction will revert
approveMaxboolWhether or not the approval amount in the signature is for liquidity or uint(-1)
vuint8The v component of the permit signature
rbytes32The r component of the permit signature
sbytes32The s component of the permit signature

Return Values:

TypeDescription
uint256amountToken Amount of token received
uint256amountETH Amount of ETH received
functio

removeLiquidityETHSupportingFeeOnTransferTokens

  function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) public returns (uint256 amountETH)

Identical to removeLiquidityETH, but succeeds for tokens that take a fee on transfer. msg.sender should have already given the router an allowance of at least liquidity on the pool.

Parameters:

NameTypeDescription
tokenaddressToken in pool
liquidityuint256Amount of liquidity tokens to remove
amountTokenMinuint256Minimum amount of token, can be 0
amountETHMinuint256Minimum amount of ETH, can be 0
toaddressAddress to receive pool tokens
deadlineuint256Unix timestamp in seconds after which the transaction will revert

Return Values:

TypeDescription
uint256amountETH Amount of ETH received
functio

removeLiquidityETHWithPermitSupportingFeeOnTransferTokens

  function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountETH)

Identical to removeLiquidityETHWithPermit, but succeeds for tokens that take a fee on transfer.

Parameters:

NameTypeDescription
tokenaddressToken in pool
liquidityuint256Amount of liquidity tokens to remove
amountTokenMinuint256Minimum amount of token, can be 0
amountETHMinuint256Minimum amount of ETH, can be 0
toaddressAddress to receive pool tokens
deadlineuint256Unix timestamp in seconds after which the transaction will revert
approveMaxboolWhether or not the approval amount in the signature is for liquidity or uint(-1)
vuint8The v component of the permit signature
rbytes32The r component of the permit signature
sbytes32The s component of the permit signature

Return Values:

TypeDescription
uint256amountETH Amount of ETH received
functio

swapExactTokensForTokens

  function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] path,
address to,
uint256 deadline
) external returns (uint256[] amounts)

Swaps an exact amount of input tokens for as many output tokens as possible, along the route determined by the path. The first element of path is the input token, the last is the output token, and any intermediate elements represent intermediate pairs to trade through. msg.sender should have already given the router an allowance of at least amountIn on the input token.

Require has been replaced with revert for gas optimization. Fallback alternate router check for insufficient output amount. Attempt to back-run swaps.

Parameters:

NameTypeDescription
amountInuint256Amount of input tokens to send.
amountOutMinuint256Minimum amount of output tokens that must be received
pathaddress[]Array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity
toaddressAddress of receiver
deadlineuint256Unix timestamp in seconds after which the transaction will revert

Return Values:

TypeDescription
uint256[]amounts Array of input token amount and all subsequent output token amounts
functio

swapTokensForExactTokens

  function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] path,
address to,
uint256 deadline
) external returns (uint256[] amounts)

Receive an exact amount of output tokens for as few input tokens as possible, along the route determined by the path. msg.sender should have already given the router an allowance of at least amountInMax on the input token.

Require has been replaced with revert for gas optimization. Fallback alternate router check for insufficient output amount. Attempt to back-run swaps.

Parameters:

NameTypeDescription
amountOutuint256Amount of output tokens to receive
amountInMaxuint256Maximum amount of input tokens
pathaddress[]Array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity
toaddressAddress of receiver
deadlineuint256Unix timestamp in seconds after which the transaction will revert

Return Values:

TypeDescription
uint256[]amounts Array of input token amount and all subsequent output token amounts
functio

swapExactETHForTokens

  function swapExactETHForTokens(
uint256 amountOutMin,
address[] path,
address to,
uint256 deadline
) external returns (uint256[] amounts)

Swaps an exact amount of ETH for as many output tokens as possible, along the route determined by the path. The first element of path must be WETH, the last is the output token. amountIn = msg.value

Require has been replaced with revert for gas optimization. Fallback alternate router check for insufficient output amount. Attempt to back-run swaps.

Parameters:

NameTypeDescription
amountOutMinuint256Minimum amount of output tokens that must be received
pathaddress[]Array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity
toaddressAddress of receiver
deadlineuint256Unix timestamp in seconds after which the transaction will revert

Return Values:

TypeDescription
uint256[]amounts Array of input token amount and all subsequent output token amounts
functio

swapTokensForExactETH

  function swapTokensForExactETH(
uint256 amountOut,
uint256 amountInMax,
address[] path,
address to,
uint256 deadline
) external returns (uint256[] amounts)

Receive an exact amount of ETH for as few input tokens as possible, along the route determined by the path. The first element of path is the input token, the last must be WETH. msg.sender should have already given the router an allowance of at least amountInMax on the input token.

Require has been replaced with revert for gas optimization. Fallback alternate router check for insufficient output amount. Attempt to back-run swaps.

Parameters:

NameTypeDescription
amountOutuint256Amount of ETH to receive
amountInMaxuint256Maximum amount of input tokens
pathaddress[]Array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity
toaddressAddress of receiver
deadlineuint256Unix timestamp in seconds after which the transaction will revert

Return Values:

TypeDescription
uint256[]amounts Array of input token amount and all subsequent output token amounts
functio

swapExactTokensForETH

  function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
address[] path,
address to,
uint256 deadline
) external returns (uint256[] amounts)

Swaps an exact amount of tokens for as much ETH as possible, along the route determined by the path. The first element of path is the input token, the last must be WETH.

Require has been replaced with revert for gas optimization. Fallback alternate router check for insufficient output amount. Attempt to back-run swaps.

Parameters:

NameTypeDescription
amountInuint256Amount of input tokens to send.
amountOutMinuint256Minimum amount of ETH that must be received
pathaddress[]Array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity
toaddressAddress of receiver
deadlineuint256Unix timestamp in seconds after which the transaction will revert

Return Values:

TypeDescription
uint256[]amounts Array of input token amount and all subsequent output token amounts
functio

swapETHForExactTokens

  function swapETHForExactTokens(
uint256 amountOut,
address[] path,
address to,
uint256 deadline
) external returns (uint256[] amounts)

Receive an exact amount of tokens for as little ETH as possible, along the route determined by the path. The first element of path must be WETH. Leftover ETH, if any, is returned to msg.sender. amountInMax = msg.value

Require has been replaced with revert for gas optimization. Fallback alternate router check for insufficient output amount. Attempt to back-run swaps.

Parameters:

NameTypeDescription
amountOutuint256Amount of output tokens that must be received
pathaddress[]Array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity
toaddressAddress of receiver
deadlineuint256Unix timestamp in seconds after which the transaction will revert

Return Values:

TypeDescription
uint256[]amounts Array of input token amount and all subsequent output token amounts
functio

swapExactTokensForTokensSupportingFeeOnTransferTokens

  function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] path,
address to,
uint256 deadline
) external

Identical to swapExactTokensForTokens, but succeeds for tokens that take a fee on transfer. msg.sender should have already given the router an allowance of at least amountIn on the input token.

Require has been replaced with revert for gas optimization. Attempt to back-run swaps.

Parameters:

NameTypeDescription
amountInuint256Amount of input tokens to send.
amountOutMinuint256Minimum amount of output tokens that must be received
pathaddress[]Array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity
toaddressAddress of receiver
deadlineuint256Unix timestamp in seconds after which the transaction will revert
functio

swapExactETHForTokensSupportingFeeOnTransferTokens

  function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] path,
address to,
uint256 deadline
) external

Identical to swapExactETHForTokens, but succeeds for tokens that take a fee on transfer. amountIn = msg.value

Require has been replaced with revert for gas optimization. Attempt to back-run swaps.

Parameters:

NameTypeDescription
amountOutMinuint256Minimum amount of output tokens that must be received
pathaddress[]Array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity
toaddressAddress of receiver
deadlineuint256Unix timestamp in seconds after which the transaction will revert
functio

swapExactTokensForETHSupportingFeeOnTransferTokens

  function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] path,
address to,
uint256 deadline
) external

Identical to swapExactTokensForETH, but succeeds for tokens that take a fee on transfer.

Require has been replaced with revert for gas optimization. Attempt to back-run swaps.

Parameters:

NameTypeDescription
amountInuint256Amount of input tokens to send.
amountOutMinuint256Minimum amount of ETH that must be received
pathaddress[]Array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity
toaddressAddress of receiver
deadlineuint256Unix timestamp in seconds after which the transaction will revert
functio

quote

  function quote(
) external returns (uint256 amountB)

getAmountOut

  function getAmountOut(
) external returns (uint256 amountOut)

getAmountIn

  function getAmountIn(
) external returns (uint256 amountIn)

getAmountsOut

  function getAmountsOut(
) external returns (uint256[] amounts)

getAmountsIn

  function getAmountsIn(
) external returns (uint256[] amounts)

onFlashLoan

  function onFlashLoan(
address sender,
address token,
uint256 amount,
uint256 fee,
bytes data
) external

Called from BentoBox Lending pool after contract has received the flash loaned amount

Reverts if not profitable.

Parameters:

NameTypeDescription
senderaddressAddress of flashloan initiator
tokenaddressToken to loan
amountuint256Amount to loan
feeuint256Fee to repay on loan amount
databytesEncoded factories and tokens
functio

executeOperation

  function executeOperation(
address[] assets,
uint256[] amounts,
uint256[] premiums,
address initiator,
bytes params
) external returns (bool)

Called from Aave Lending pool after contract has received the flash loaned amount (https://docs.aave.com/developers/v/2.0/guides/flash-loans)

Reverts if not profitable.

Parameters:

NameTypeDescription
assetsaddress[]Array of tokens to loan
amountsuint256[]Array of amounts to loan
premiumsuint256[]Array of premiums to repay on loan amounts
initiatoraddressAddress of flashloan initiator
paramsbytesEncoded factories and tokens

Return Values:

TypeDescription
boolsuccess indicating success
functio

harvest

  function harvest(
uint256 percentage,
address[] tokens,
address[] receivers
) external

Multi-sig consensus call to distribute a given percentage of specified tokens to specified receivers.

Parameters:

NameTypeDescription
percentageuint256Percentage of balance to distribute
tokensaddress[]Array of token addresses to distribute
receiversaddress[]Array of addresses for receiving distribution
functio

updateAaveAsset

  function updateAaveAsset(
bool isActive,
address asset
) external

Update internal Aave asset flag

Parameters:

NameTypeDescription
isActiveboolBoolean flagging whether to use the asset for Aave flashloans
assetaddressAddress of asset
functio

updateAllAaveAssets

  function updateAllAaveAssets(
) external

Update all internal Aave assets functio

receive

  function receive(
) external

Function to receive Ether. msg.data must be empty receive

fallback

  function fallback(
) external

Fallback function is called when msg.data is not empty fallbac

owner

  function owner(
) external returns (address)

Returns the address of the current owner.

isOwner

  function isOwner(
) public returns (bool)

Returns true if the caller is the current owner.

transferOwnership

  function transferOwnership(
) external

Allows a new account (newOwner) to accept ownership. Can only be called by the current owner.

cancelOwnershipTransfer

  function cancelOwnershipTransfer(
) external

Cancel a transfer of ownership to a new account. Can only be called by the current owner.

acceptOwnership

  function acceptOwnership(
) external

Transfers ownership of the contract to the caller. Can only be called by a new potential owner set by the current owner.

Events

OpenMEV

  event OpenMEV(
)

LoanError

  event LoanError(
)

OwnershipTransferred

  event OwnershipTransferred(
)