Info
This section is a technical explainer of how the Router works. If you are looking to integrate with the Router, take a look at the API docs.
Example Transaction Flow
The Router and Vault interact in a back and forth manner to achieve the intended outcome of liquidity or query operations.
Every user interaction going through the Router follows the same pattern of execution flow. The elegance of unlock
wrapping the transaction in a Vault context is further explained in the transient accounting section
- The Router calls
unlock
on the Vault, allowing access to protected state-changing functions that perform token accounting by triggering thetransient
modifier. You can think of this step as the Router opening a tab with the Vault, after which any debts or credits from subsequent Vault operations accrue to that tab. - The Router executes a hook function (ie:
swapSingleTokenHook
) which calls the Vault's primitives (ie:swap
). These operations incur debt or supply credit to the currently open tab. - To finalize the user operation, all outstanding debts and credits accrued during
swap
need to be settled. If the tab is not settled, the transaction will revert. This settlement step (i.e., whenunlock
returns and executes the rest of thetransient
modifier) closes out the tab opened with the Vault in step 1.