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[])

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.

Last updated