Skip to content
LogoLogo

EligiblePrice

Git Source

Exact-price summaries on a priority-key radix tree.

A buy subtree stores its maximum limit; a sell subtree its minimum. This is an existence certificate, not an approximation of an order's limit.

Functions

le

Exact comparison of positive-denominator ratios using two 512-bit products.

function le(Ratio memory a, Ratio memory b) internal pure returns (bool result);

Parameters

NameTypeDescription
aRatio
bRatio

Returns

NameTypeDescription
resultbool

refresh

function refresh(
        RadixPriceTree.Tree storage tree,
        mapping(uint32 => Ratio) storage bounds,
        uint128 rank,
        Ratio memory price,
        bool isBuy
    ) public;

Parameters

NameTypeDescription
treeRadixPriceTree.Tree
boundsmapping(uint32 => Ratio)
rankuint128
priceRatio
isBuybool

remove

function remove(RadixPriceTree.Tree storage tree, mapping(uint32 => Ratio) storage bounds, uint128 rank, bool isBuy)
        public;

Parameters

NameTypeDescription
treeRadixPriceTree.Tree
boundsmapping(uint32 => Ratio)
rankuint128
isBuybool

_repair

function _repair(
        RadixPriceTree.Tree storage tree,
        mapping(uint32 => Ratio) storage bounds,
        uint32 cursor,
        bool isBuy,
        bool forceFirst
    ) private;

Parameters

NameTypeDescription
treeRadixPriceTree.Tree
boundsmapping(uint32 => Ratio)
cursoruint32
isBuybool
forceFirstbool

_eligible

function _eligible(Ratio memory bound, Ratio memory limit, bool isBuy) private pure returns (bool);

Parameters

NameTypeDescription
boundRatio
limitRatio
isBuybool

Returns

NameTypeDescription
<none>bool

best

Highest priority key among orders crossing limit, in at most 128 branches.

Right children have greater priority keys. No backtracking or linear scan.

function best(
        RadixPriceTree.Tree storage tree,
        mapping(uint32 => Ratio) storage bounds,
        Ratio memory limit,
        bool isBuy
    ) internal view returns (bool found, uint128 rank);

Parameters

NameTypeDescription
treeRadixPriceTree.Tree
boundsmapping(uint32 => Ratio)
limitRatio
isBuybool

Returns

NameTypeDescription
foundbool
rankuint128

Structs

Ratio

struct Ratio {
        uint256 numerator;
        uint256 denominator;
    }

Properties

NameTypeDescription
numeratoruint256
denominatoruint256