Router

Structs & enums used in the contract

struct TransactionData {
Action[] actions;
TokenAmount[] inputs;
Fee fee;
AbsoluteTokenAmount[] requiredOutputs;
uint256 salt;
}
struct Action {
bytes32 protocolAdapterName;
ActionType actionType;
TokenAmount[] tokenAmounts;
bytes data;
}
struct TokenAmount {
address token;
uint256 amount;
AmountType amountType;
}
struct Fee {
uint256 share;
address beneficiary;
}
enum ActionType { None, Deposit, Withdraw }
enum AmountType { None, Relative, Absolute }

State-changing functions

startExecution

The main function for interaction is execute() / executeWithChi(). To use executeWithChi() function, the user must approve CHI tokens to the Router contract prior to the function call. It returns resulting funds to the msg.sender address.

function execute(
Action[] actions,
TokenAmount[] inputs,
Fee memory fee,
AbsoluteTokenAmount[] requiredOutputs
) payable returns (AbsoluteTokenAmount[])

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 be listed in inputs array as 0xEeee...EEeE.

fee

Fee struct containing beneficiary and fee share scaled by 1e18.

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 execute 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 execute(
TransactionData data,
bytes signature
)
payable returns (AbsoluteTokenAmount[])
function executeWithChi(
TransactionData data,
bytes signature
)
payable returns (AbsoluteTokenAmount[])

view functions

getRequiredAllowances

function getRequiredAllowances(
TokenAmount[] inputs,
address account
)
view
returns (AbsoluteTokenAmount[] allowances)

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

getRequiredBalances

function getRequiredBalances(
TokenAmount[] inputs,
address account
)
view
returns (AbsoluteTokenAmount[] balances)

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