Skip to content

Helpers ​

Git Source

Inherits:CommonImport

Functions ​

_reentrancyLock ​

solidity
modifier _reentrancyLock();

_getExtraDataSlot ​

solidity
function _getExtraDataSlot() internal view returns (address extraDataAddress_);

_getGovernanceAddr ​

solidity
function _getGovernanceAddr() internal view returns (address governance_);

_callExtraDataSlot ​

solidity
function _callExtraDataSlot(bytes memory data_) internal;

_tenPow ​

solidity
function _tenPow(uint256 power_) internal pure returns (uint256);

_calculateReservesOutsideRange ​

getting reserves outside range.

solidity
function _calculateReservesOutsideRange(uint256 gp_, uint256 pa_, uint256 rx_, uint256 ry_)
    internal
    pure
    returns (uint256 xa_, uint256 yb_);

Parameters

NameTypeDescription
gp_uint256is geometric mean pricing of upper percent & lower percent
pa_uint256price of upper range or lower range
rx_uint256real reserves of token0 or token1
ry_uint256whatever is rx_ the other will be ry_

_calcShiftingDone ​

This function calculates the new value of a parameter after a shifting process

solidity
function _calcShiftingDone(uint256 current_, uint256 old_, uint256 timePassed_, uint256 shiftDuration_)
    internal
    pure
    returns (uint256);

Parameters

NameTypeDescription
current_uint256The current value is the final value where the shift ends
old_uint256The old value from where shifting started
timePassed_uint256The time passed since shifting started
shiftDuration_uint256The total duration of the shift when old_ reaches current_

Returns

NameTypeDescription
<none>uint256The new value of the parameter after the shift

_calcRangeShifting ​

This function handles the gradual shifting of range values over time

If the shift is complete, it updates the state and clears the shift data

Calculates the new upper and lower range values during an active range shift

solidity
function _calcRangeShifting(uint256 upperRange_, uint256 lowerRange_, bytes8 dexId_)
    internal
    returns (uint256, uint256);

Parameters

NameTypeDescription
upperRange_uint256The target upper range value
lowerRange_uint256The target lower range value
dexId_bytes8

_calcThresholdShifting ​

This function handles the gradual shifting of threshold values over time

If the shift is complete, it updates the state and clears the shift data

Calculates the new upper and lower threshold values during an active threshold shift

solidity
function _calcThresholdShifting(uint256 upperThreshold_, uint256 lowerThreshold_, bytes8 dexId_)
    internal
    returns (uint256, uint256);

Parameters

NameTypeDescription
upperThreshold_uint256The target upper threshold value
lowerThreshold_uint256The target lower threshold value
dexId_bytes8

Returns

NameTypeDescription
<none>uint256The updated upper threshold, lower threshold
<none>uint256

_calcCenterPrice ​

This function gradually shifts the center price towards a new target price over time

It uses an external price source (via ICenterPrice) to determine the target price

The shift continues until the current price reaches the target, or the shift duration ends

Once the shift is complete, it updates the state and clears the shift data

The shift rate is dynamic and depends on:

  • Time remaining in the shift duration

  • The new center price (fetched externally, which may change)

  • The current (old) center price

This results in a fuzzy shifting mechanism where the rate can change as these parameters evolve

The externally fetched new center price is expected to not differ significantly from the last externally fetched center price

Calculates the new center price during an active price shift

solidity
function _calcCenterPrice(DexKey calldata dexKey_, uint256 dexVariables_, bytes8 dexId_)
    internal
    returns (uint256 newCenterPrice_);

Parameters

NameTypeDescription
dexKey_DexKey
dexVariables_uint256The current state of dex variables
dexId_bytes8

Returns

NameTypeDescription
newCenterPrice_uint256The updated center price

_getPricesAndReserves ​

Calculates and returns the current prices and exchange prices for the pool

solidity
function _getPricesAndReserves(
    DexKey calldata dexKey_,
    uint256 dexVariables_,
    bytes8 dexId_,
    uint256 token0Supply_,
    uint256 token1Supply_
) internal returns (uint256 centerPrice_, uint256 token0ImaginaryReserves_, uint256 token1ImaginaryReserves_);

Parameters

NameTypeDescription
dexKey_DexKey
dexVariables_uint256The first set of DEX variables containing various pool parameters
dexId_bytes8
token0Supply_uint256
token1Supply_uint256

_getRebalancingStatus ​

solidity
function _getRebalancingStatus(
    uint256 dexVariables_,
    bytes8 dexId_,
    uint256 rebalancingStatus_,
    uint256 price_,
    uint256 centerPrice_
) internal returns (uint256);

_transferTokens ​

solidity
function _transferTokens(
    address tokenIn_,
    uint256 amountIn_,
    address tokenOut_,
    uint256 amountOut_,
    address to_,
    bool isCallback_,
    bytes calldata callbackData_
) internal;

_spell ​

do any arbitrary call

solidity
function _spell(address target_, bytes memory data_) internal returns (bytes memory response_);

Parameters

NameTypeDescription
target_addressAddress to which the call needs to be delegated
data_bytesData to execute at the delegated address