Skip to main content

Convert

Git Source

Functions

toLiquidityAssets

function toLiquidityAssets(
uint256 liquidityShares,
uint256 reservesAssets,
uint256 activeLiquidityAssets,
uint256 depositLiquidityAssets,
uint256 depositLiquidityShares
) internal pure returns (uint256);

toAssets

function toAssets(
uint256 shares,
uint256 totalAssets,
uint256 totalShares,
bool roundingUp
) internal pure returns (uint256 _assets);

toShares

function toShares(
uint256 assets,
uint256 totalAssets,
uint256 totalShares,
bool roundingUp
) internal pure returns (uint256 _shares);

mulDiv

function mulDiv(uint256 x, uint256 y, uint256 z, bool roundingUp) internal pure returns (uint256 result);

calculateReserveAdjustmentsForMissingAssets

helper method to calculate balance adjustment for missing assets

In the depleted case the adjusted reserve is (reserve - missing) * bufferNumerator, matching the BUFFER_NUMERATOR scaling applied by calculateBalanceAfterFees so the K comparison stays division-free. For updateObservation, different scaled buffer and bufferNumerator values are supplied so the adjusted reserve reflects observation-specific logic.

function calculateReserveAdjustmentsForMissingAssets(
uint256 reserve,
uint256 missing,
uint256 buffer,
uint256 bufferNumerator
) internal pure returns (uint256 reserveAdjustment);

Parameters

NameTypeDescription
reserveuint256the starting reserve
missinguint256the missing assets, zero if deposits > borrows of X or Y
bufferuint256Scaling factor applied to the reserve for the depletion comparison.
bufferNumeratoruint256Scaling factor applied to the missing amount for the comparison and for computing the depleted-case adjusted reserve.

Returns

NameTypeDescription
reserveAdjustmentuint256The adjusted reserve value used for swap or updateObservation depends on the buffer, bufferNumerator to be passed in.

depletionAdjustedActiveLiquidity

Depletion-adjusted active liquidity, sqrt of the adjusted-reserve product using the swap K-check buffer. Shared by interest accrual and TokenController.calculateActiveLiquidityAssets so every active-liquidity reader uses one basis.

function depletionAdjustedActiveLiquidity(
uint256 reserveXAssets,
uint256 reserveYAssets,
uint256 missingXAssets,
uint256 missingYAssets
) internal pure returns (uint256);

Parameters

NameTypeDescription
reserveXAssetsuint256reserve X used for the active-liquidity calculation.
reserveYAssetsuint256reserve Y used for the active-liquidity calculation.
missingXAssetsuint256missing X assets, zero if deposits > borrows of X.
missingYAssetsuint256missing Y assets, zero if deposits > borrows of Y.

Returns

NameTypeDescription
<none>uint256The depletion-adjusted active liquidity.