Liquidity routing
This page is currently being updated - thank you for your understanding.
Maker contracts can be set to utilize a %%router|router%% in order to manage %%outbound|outbound%% and %%inbound|inbound%% tokens reserves of %%offer owners|offer-owner%%. Routers' interface are constrained by the AbstractRouter
contract and use %%hooks|hook%% to customize the public functions described below.
Function modifier onlyMakers
requires that only an approved maker contract can call this functions. Modifier onlyAdmin
requires function caller to be the admin of the router. Modifier makerOrAdmin
is a disjunction of both the above requirements.
Useful routersβ
SimpleRouter
β
The SimpleRouter
contract provides a (simple) router instance. We illustrate the usage of the main router functions through it.
SmartRouter
β
The SmartRouter
contract is an implementation, and must not be called directly. It delegates pull and push logic implementation to arbitrary contracts that implement the AbstractRoutingLogic
interface. It implements SimpleRouter
as its default route.
When requested to do so, the ProxyFactory deploys a RouterProxy. It is created specifically for the caller, and will forward all the push/pull calls to the SmartRouter, which forward those to the corresponding routing logic (ex: AaveLogic).
Thefore, the push/pull functions are delegated from the Proxy > SmartRouter > RoutingLogic. The Proxy contract basically works like an intelligent router.
Liquidity flowsβ
Routers receive requests from approved %%maker contracts|maker-contract%% (see gatekeeping). Request can be either to manage inbound (offer taker's payment) or outbound cash flow.
Push requestβ
loading...
- Input:
token
is the asset the maker contract wishes to pushreserveId
is the address of the offer owner whose funds are being pushedamount
is the amount of asset that should be transferred from the calling maker contract
- Output: fraction of
amount
that was successfullypushed
to offer owner'sreserveId
. - Usage: transfer funds from the maker contracts to an offer owner's reserve. For instance if the reserve is an account on a lender, the router will have a custom
push
that will take care of calling the proper deposit function. - SimpleRouter behavior: transfer funds from
msg.sender
toreserveId
. Returns 0 if transfer failed, returnsamount
otherwise.
Pull requestβ
loading...
- Input:
token
is the asset the maker contract wishes to pullreserveId
is the address of the offer owner where the funds need to be pulled fromamount
is the amount of asset that should be transferred fromreserveId
to the calling maker contractstrict
is used when the calling maker contract accepts to receive more funds from reserve than required (this may happen for gas optimization)
- Output: fraction of
amount
that was successfullypulled
tomsg.sender
. - Usage: transfer funds from an offer owner's reserve to the calling maker contracts. For instance if the reserve is an account on a lender, the router will have a custom
pull
that will take care of calling the proper redeem function. - SimpleRouter behavior: transfer funds from
reserveId
tomsg.sender
. Returns 0 if transfer failed, returnsamount
otherwise.
Gatekeepingβ
Binding a router to a maker contractβ
loading...
Function approves makerContract
as a user of the router. The unbind
function can be called to revoke the approval.
Router activationβ
loading...
- Usage: performs all router centric approvals that are necessary to route
token
liquidity. For instance a router using a lender might need to approve the lender for transferringtoken
in deposit calls. - SimpleRouter behavior: SimpleRouter does not need to approve any contract, and
activate
is a no-op in that context.
Router checklistβ
loading...
- Usage: verifies that the router has performed and received all the necessary approvals to route
token
liquidity for offer owner'sreserveId
. The function throws with a reason when the first missing approval is detected. - SimpleRouter behavior: it verifies that
reserveId
has approved the router fortoken
transfer. Does not throw if offer owner'sreserveId
is the router itself.
Since routers are autonomous smart contracts, it is possible to modify an offer logic without redeploying the corresponding maker contracts. The setRouter
function of all library based maker contracts can be used to set a new router. By setting a new router for the maker contract, you are indirectly modifying the offer logic of the contract. However the gas requirement of the offer logic is impacted by the router's design. To cope with this, routers provide the routerGaseq()
function that returns the amount of gas that is necessary to cover a call to pull
and push
.
Note that maker contracts' view offerGasreq
returns the sum of the offer logic's raw %%gasreq
|gasreq%% (without taking router into account) and the router specific gasreq