Router

Structs & enums used in the contract

struct TransactionData {
Action[] actions;
Input[] inputs;
Output[] outputs;
uint256 nonce;
}
struct Action {
bytes32 protocolAdapterName;
ActionType actionType;
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 resulting funds to the msg.sender address.

function startExecution(
Action[] actions,
Input[] inputs,
Output[] requiredOutputs
)
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: tokens from inputs andrequiredOutputs are listed).

Note, that this function can be called both using "call" and "send".

The suggested flow is the following:

  1. Call startExecution function with zero amounts in requiredOutputs.

  2. Fetch amounts in actualOutputs – these are expected returned amounts.

  3. Use expected returned values 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 to 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.