Skip to main content

Generic Router

The GenericRouter handles all trading functions (deposits, withdraws, rebalance, and restructures) using multicalls that are passed to the functions as bytecode.#

Call#

The Call type is a struct that contains a target address and the bytes call data for a function that is on the target contract. The Router functions that are implemented by GenericRouter taked a Call[] array which has been encoded into a bytes type. Using the aggregate() function in the Multicall library it loops through each Call and makes a function call to the target address.

Delegate Swap#

This contract implements the delegateSwap external function which wraps the internal _delegateSwap and allows it to be included within a Multicall. However, in order to prevent misuse, it restricts the address that may call it to the GenericRouter address itself. In this way it acts as an internal function while also including the function in the contract's ABI to be used for building multicalls.

Settlement Functions#

There are several settlement functions implemented in the GenericRouter to facilitate easier multicall creation. The basic purpose of these functions is to use the contract's current balance of a given token as the input amount for commonly used token functions. The functions are settleSwap, settleTransfer, and settleTransferFrom. All functions can only be called by the GenericRouter and therefore can only be used as part of a multicall.