Skip to main content

Class: KandelDistribution

Title

A distribution of bids and ask for Kandel.

Properties

offers

offers: OfferDistribution

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:20


baseDecimals

baseDecimals: number

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:21


quoteDecimals

quoteDecimals: number

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:22


ratio

ratio: Big

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:23


pricePoints

pricePoints: number

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:24


helper

helper: KandelDistributionHelper

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:25

Constructors

constructor

new KandelDistribution(ratio, pricePoints, offers, baseDecimals, quoteDecimals)

Constructor

Parameters

NameTypeDescription
ratioBigThe ratio used when calculating the price distribution.
pricePointsnumberThe number of price points in the distribution. Can be more than the number of offers if a subset is considered.
offersOfferDistributionThe distribution of bids and asks.
baseDecimalsnumberThe number of decimals for the base token.
quoteDecimalsnumberThe number of decimals for the quote token.

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:34

Methods

getOfferCount

getOfferCount(): number

Gets the number of offers in the distribution. This can be lower than the number of price points when a subset is considered.

Returns

number

The number of offers in the distribution.

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:53


calculateOfferGives

calculateOfferGives(offerType, offerCount, totalVolume): Big

Calculates the gives for a single offer of the given type given the total available volume and the count of offers of that type.

Parameters

NameTypeDescription
offerTypeBAThe type of offer.
offerCountnumberThe count of offers of the given type.
totalVolumeBigThe total available volume.

Returns

Big

The amount of base or quote to give for the offer.

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:63


calculateConstantGivesPerOffer

calculateConstantGivesPerOffer(availableBase?, availableQuote?): Object

Calculates the gives for bids and asks based on the available volume for the distribution.

Parameters

NameTypeDescription
availableBase?BigThe available base to consume.
availableQuote?BigThe available quote to consume.

Returns

Object

The amount of base or quote to give for each offer.

NameType
askGivesundefined | Big
bidGivesundefined | Big

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:90


getFirstAskIndex

getFirstAskIndex(): number

Gets the index of the first ask in the distribution. If there are no asks, then the length of the distribution is returned.

Returns

number

The index of the first ask in the distribution; or the length of the distribution if there are no asks.

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:110


getOffersIndexOfFirstAskIndex

getOffersIndexOfFirstAskIndex(): number

Gets the index of the first ask in the subset of offers in offers for the distribution. If there are no asks, then the length of offers is returned.

Returns

number

The index of the first ask in the subset of offers in offers for the distribution. If there are no asks, then the length of offers is returned.

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:119


chunkDistribution

chunkDistribution(pivots, maxOffersInChunk): { pivots: number[] ; distribution: OfferDistribution }[]

Split a distribution and its pivots into chunks according to the maximum number of offers in a single chunk.

Parameters

NameTypeDescription
pivotsnumber[]The pivots for the distribution.
maxOffersInChunknumberThe maximum number of offers in a single chunk.

Returns

{ pivots: number[] ; distribution: OfferDistribution }[]

The chunks.

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:133


getPricesForDistribution

getPricesForDistribution(): (undefined | Big)[]

Gets the prices for the distribution, with undefined for prices not represented by offers in the distribution.

Returns

(undefined | Big)[]

The prices in the distribution.

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:174


getOfferedVolumeForDistribution

getOfferedVolumeForDistribution(): Object

Gets the required volume of base and quote for the distribution to be fully provisioned.

Returns

Object

The offered volume of base and quote for the distribution to be fully provisioned.

NameType
requiredBaseBig
requiredQuoteBig

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:186


verifyDistribution

verifyDistribution(): void

Verifies the distribution is valid.

Remarks

Throws if the distribution is invalid. The verification checks that indices are ascending and bids come before asks. The price distribution is not verified.

Returns

void

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:208


getRequiredProvision

getRequiredProvision(params): Promise<Big>

Determines the required provision for the listed offers in the distribution (disregarding the number of price points).

Remarks

This takes into account that each of the offers represent a price point which can become both an ask and a bid which both require provision.

Parameters

NameTypeDescription
paramsObjectThe parameters used to calculate the provision.
params.marketMarketThe market to get provisions for bids and asks from.
params.gasreqnumberThe gas required to execute a trade.
params.gaspricenumberThe gas price to calculate provision for.

Returns

Promise<Big>

The provision required for the number of offers.

Defined in

@mangrovedao/mangrove.js/src/kandel/kandelDistribution.ts:237

  • Properties
    • offers
    • baseDecimals
    • quoteDecimals
    • ratio
    • pricePoints
    • helper
  • Constructors
    • constructor
  • Methods
    • getOfferCount
    • calculateOfferGives
    • calculateConstantGivesPerOffer
    • getFirstAskIndex
    • getOffersIndexOfFirstAskIndex
    • chunkDistribution
    • getPricesForDistribution
    • getOfferedVolumeForDistribution
    • verifyDistribution
    • getRequiredProvision