Router

Structs & enums used in the contract

struct TransactionData {
Action[] actions;
Input[] inputs;
Output[] outputs;
uint256 nonce;
}
struct Action {
ActionType actionType;
bytes32 protocolName;
uint256 adapterIndex;
address[] tokens;
uint256[] amounts;
AmountType[] amountTypes;
bytes data;
}
struct Input {
address token;
uint256 amount;
AmountType amountType;
uint256 fee;
address beneficiary;
}
struct Output {
address token;
uint256 amount;
}
enum ActionType { None, Deposit, Withdraw }
enum AmountType { None, Relative, Absolute }

State-changing functions

startExecution

The main function for interaction is startExecution(). It returns funds to the msg.sender address.

function startExecution(
Action[] actions,
Input[] inputs,
Output[] requiredOutputs
)
public
payable
returns (Output[] actualOutputs)

Parameter

Description

actions

Array of actions to be executed.

inputs

Array of tokens and amounts to be taken from msg.sender's account for the execution. ETH should not be listed in inputs array.

requiredOutputs

Array of required token amounts to be returned after the execution of all the actions from actions array.

actualOutputs

Array of actual token amounts to be returned after the execution of all the actions from actions array (note: only tokens from requiredOutputs are listed).

Note, that this function can be called both using "call" and "send". When calling this function with zero requiredOutputs, the function will return actualOutputs, and returned value may be used in requiredOutputs when sending transaction in order to prevent high slippage.

Router contract supports EIP712, i.e. the user may sign his data and the Router will transfer tokens from the recovered address. In this case, all the parameters will be wrapped in one struct. It returns funds to the recovered address.

function startExecution(
TransactionData data,
bytes signature
)
payable

Here, TransactionData is the following struct:

struct TransactionData {
Action[] actions;
Input[] inputs;
Output[] outputs;
uint256 nonce;
}

view functions

getRequiredAllowances

function getRequiredAllowances(
Input[] inputs,
address account
)
view
returns (Output[] allowances)

Returns difference between required token allowance and current allowance for every token in inputs array

getRequiredBalances

function getRequiredBalances(
Input[] inputs,
address account
)
view
returns (Output[] balances)

Returns difference between required token amount and current balance for every token in inputs array