Some notes on the TWAMM.
These expressions might be somewhere out there, but I viewed this as an exercise to learn more about the properties of the TWAMM.
There are two reserves
Suppose a trader looks to sell token0
over token1
from the
At each time token1
the trader has received up to time
where
Our goal is to determine what the trader's average price is for the entire trade:
and then compare this to what the TWAP for the pool was over the same time period. Take each swap to happen in the infinitesimal limit such that the number of time steps
not necessarily assuming evenly distributed deployment of the
Express the infinitesimal amount sold of token0
funds at time
where token1
the trader has received up to time
and the associated average price received by the trader for the entire trade through
What's the TWAP of the pool over this same time period?
By definition, the TWAP is the time-weighted average price of the pool over a given time period. In the discrete case, this is
As
changes the TWAP expression over the entire deployment period
Comparing the average price
the average price received by the trader will be the TWAP of the pool over the time of deployment as
The condition of a constant rate of selling over the deployment period guarantees the trader receives as their average price the TWAMM pool's TWAP over that same timespan.
If the rate of capital deployment is not constant over the deployment period, the average price of their trade won't necessarily coincide with the pool's time-weighted average price.
Note that for small values of