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
unlockon the Vault, allowing access to protected state-changing functions that perform token accounting by triggering thetransientmodifier. 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
swapneed to be settled. If the tab is not settled, the transaction will revert. This settlement step (i.e., whenunlockreturns and executes the rest of thetransientmodifier) closes out the tab opened with the Vault in step 1.