๐ฆReserves
Last updated
Last updated
A reserves mechanism was introduced to track increases in pool balances. Reserves reflect the last known pool balances - after the last major pool action has been performed (mint
/burn
/swap
/collect
/flash
). Immediately after interaction with the pool, under normal conditions, reserves should have the following values:
Synchronization of reserves and balances after interaction with the pool occurs based on the expected change in balances - using the number of tokens sent or requested by the pool. For example, sending tokens to a user () causes the next change in the corresponding reserve:
On the other hand, when is received, the reserve is increased accordingly:
Thus, the value of the reserve at any given moment reflects the number of jettons the pool expects to have on its balance.
At the beginning of the main pool interactions, it is checked whether the pool balances match the expected reserve values. In case of discrepancy, the corresponding jetton surplus (jettonDelta) is calculated and distributed among active liquidity positions as additional fees if the current liquidity is not zero:
If current liquidity is zero (), no synchronization occurs until liquidity becomes non-zero.
Thanks to this mechanism it became possible to support jetton rebase by the TONCO protocol - the pool can detect an increase in jetton balances due to external reasons and distribute the excess jettons among active liquidity providers.
However, this restriction means that TONCO does not guarantee full pooling performance when using jettons with totalSupply greater than the maximum value of uint120
. For most pool interactions, if the pool interaction results in the reserve exceeding the maximum allowed value, the coins would be returned to the user
To minimize the number of unnecessary transfers, Protocol Fee is not sent to the Pool Admin at each swap. Instead, the accumulated part of the commissions is recorded in the variables poolv3::collectedProtocolFee{0,1}
.
Accumulation and sending of Protocol Fee is taken into account in tracking pool reserves.
The reserve value for each of the jettons is limited to the maximum value of the data type uint128
: . This restriction allows us to minimize the cost of gas when interacting with the pool.