OracleSlippage

Functions

getBlockStartingAndCurrentTick

Returns the tick as of the beginning of the current block, and as of right now, for the given pool.

function getBlockStartingAndCurrentTick(IDragonswapV2Pool pool)
    internal
    view
    returns (int24 blockStartingTick, int24 currentTick);

getPoolAddress

Virtual function to get pool addresses that can be overridden in tests.

function getPoolAddress(address tokenA, address tokenB, uint24 fee)
    internal
    view
    virtual
    returns (IDragonswapV2Pool pool);

getSyntheticTicks

Returns the synthetic time-weighted average tick as of secondsAgo, as well as the current tick, for the given path. Returned synthetic ticks always represent tokenOut/tokenIn prices, meaning lower ticks are worse.

function getSyntheticTicks(bytes memory path, uint32 secondsAgo)
    internal
    view
    returns (int256 syntheticAverageTick, int256 syntheticCurrentTick);

toInt24

Cast a int256 to a int24, revert on overflow or underflow

function toInt24(int256 y) private pure returns (int24 z);

getSyntheticTicks

For each passed path, fetches the synthetic time-weighted average tick as of secondsAgo, as well as the current tick. Then, synthetic ticks from all paths are subjected to a weighted average, where the weights are the fraction of the total input amount allocated to each path. Returned synthetic ticks always represent tokenOut/tokenIn prices, meaning lower ticks are worse. Paths must all start and end in the same token.

function getSyntheticTicks(bytes[] memory paths, uint128[] memory amounts, uint32 secondsAgo)
    internal
    view
    returns (int256 averageSyntheticAverageTick, int256 averageSyntheticCurrentTick);

checkOracleSlippage

Ensures that the current (synthetic) tick over the path is no worse than maximumTickDivergence ticks away from the average as of secondsAgo

function checkOracleSlippage(bytes memory path, uint24 maximumTickDivergence, uint32 secondsAgo)
    external
    view
    override;

Parameters

NameTypeDescription

path

bytes

The path to fetch prices over

maximumTickDivergence

uint24

The maximum number of ticks that the price can degrade by

secondsAgo

uint32

The number of seconds ago to compute oracle prices against

checkOracleSlippage

Ensures that the current (synthetic) tick over the path is no worse than maximumTickDivergence ticks away from the average as of secondsAgo

function checkOracleSlippage(
    bytes[] memory paths,
    uint128[] memory amounts,
    uint24 maximumTickDivergence,
    uint32 secondsAgo
) external view override;

Parameters

NameTypeDescription

paths

bytes[]

amounts

uint128[]

maximumTickDivergence

uint24

The maximum number of ticks that the price can degrade by

secondsAgo

uint32

The number of seconds ago to compute oracle prices against

Last updated