Linear Math
Overview
Linear math is designed to facilitate swaps between assets and their yield bearing, wrapped counterparts. For example, DAI and aDAI from Aave. This pairing is done using the identity function, with consideration for the exchange rate between the main (unwrapped) and wrapped assets. Linear pools are the base layer for boosted pools.
Implementations
TypeScript
Developers can use the TypeScript math implementations used by the Smart Order router
Invariant
The invariant of the linear math function is trivial in nature, similar to the constant sum invariant. The main difference being the exchange rate, or rate provider, being utilized for the wrapped tokens.
Where
- ranges over the tokens in the pool
- is the nominal balance of the token in the pool
- is the rate provider or exchange rate. For the main, unwrapped token R = 1
Spot Price
Spot price is independent of the balances, and will depend on the exchange rates between the underlying assets only. This is defined as:
- is the rate provider of token going into the pool
- is the rate provider of token coming out of the pool
Swap Equations
For linear pools, the unique factor of the swap equations is the swap fees. The fee structure incentivizes swappers to maintain the unwrapped balance of the tokens in the pool to remain between an upper () and lower () boundary. The swap equations can best be described by the following piece wise functions.
outGivenIn
Where:
- is the amount out. This represents the number of tokens a user will receive from a swap.
- is the amount in. This represents the number of tokens a user will sell to perform a swap.
- The rate provider value, or exchange rate of the token in.
- The rate provider value, or exchange rate of the token out.
- - Represents the swap fee of the pool.
- The lower target boundary of the unwrapped token balance
- The upper target boundary of the unwrapped token balance
- is the unwrapped token balance within the pool.
inGivenOut
Where:
- is the amount in. This represents the number of tokens a user will sell to perform a swap.
- The rate provider value, or exchange rate of the token in.
- The rate provider value, or exchange rate of the token out.
- - Represents the swap fee of the pool.
- The lower target boundary of the unwrapped token balance
- The upper target boundary of the unwrapped token balance
- is the unwrapped token balance within the pool.