Skip to main content

Class: KandelDistributionHelper

Title

Helper for handling Kandel offer distributions.

Constructors​

constructor​

β€’ new KandelDistributionHelper(market): KandelDistributionHelper

Constructor

Parameters​

NameTypeDescription
marketKeyResolvedForCalculationThe key data about the market.

Returns​

KandelDistributionHelper

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistributionHelper.ts:26

Properties​

askTickPriceHelper​

β€’ askTickPriceHelper: TickPriceHelper

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistributionHelper.ts:19


bidTickPriceHelper​

β€’ bidTickPriceHelper: TickPriceHelper

Defined in​

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


market​

β€’ market: KeyResolvedForCalculation

Defined in​

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

Methods​

sortByIndex​

β–Έ sortByIndex(list): { index: number }[]

Sorts an array in-place according to an index property in ascending order.

Parameters​

NameTypeDescription
list{ index: number }[]The list to sort.

Returns​

{ index: number }[]

The sorted list.

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistributionHelper.ts:36


changeValues​

β–Έ changeValues(delta, values, minimumValue, round): Object

Uniformly changes values by a total amount without decreasing below a minimum for each value. A value already below minimum will not be changed.

Parameters​

NameTypeDescription
deltaundefined | BigThe total amount to change.
valuesBig[]The values to change.
minimumValueBigThe minimum value for each value.
round(value: Big) => BigThe function to round the values.

Returns​

Object

The new values and the total change.

NameType
newValuesany[]
totalChangeBig

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistributionHelper.ts:47


uniformlyIncrease​

β–Έ uniformlyIncrease(values, totalDelta, round): Object

Uniformly increases values by a total amount.

Parameters​

NameTypeDescription
valuesBig[]The values to increase.
totalDeltaBigThe total amount to increase.
round(value: Big) => BigThe function to round the values.

Returns​

Object

The new values and the total change.

NameType
newValuesany[]
totalChangeBig

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistributionHelper.ts:75


uniformlyDecrease​

β–Έ uniformlyDecrease(values, totalDelta, minimumValue, round): Object

Uniformly decreases values by a total amount without decreasing below a minimum for each value. A value already below minimum will not be changed.

Parameters​

NameTypeDescription
valuesBig[]The values to decrease.
totalDeltaBigThe total amount to decrease.
minimumValueBigThe minimum value for each value.
round(value: Big) => BigThe function to round each value.

Returns​

Object

The new values and the total change.

NameType
newValuesBig[]
totalChangeBig

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistributionHelper.ts:108


calculateMinimumInitialGives​

β–Έ calculateMinimumInitialGives(minimumBasePerOffer, minimumQuotePerOffer, bidTicks, askTicks): Object

Calculates the minimum initial gives for each offer such that all possible gives of fully taken offers at all price points will be above the minimums provided.

Parameters​

NameTypeDescription
minimumBasePerOfferBigThe minimum base to give for each offer.
minimumQuotePerOfferBigThe minimum quote to give for each offer.
bidTicksnumber[]The ticks for bids.
askTicksnumber[]The ticks for asks.

Returns​

Object

The minimum initial gives for each offer such that all possible gives of fully taken offers at all price points will be above the minimums provided.

NameType
askGivesBig
bidGivesBig

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistributionHelper.ts:147


getDualIndex​

β–Έ getDualIndex(offerType, index, pricePoints, stepSize): number

Gets the dual index for an offer in the same manner as the solidity implementation.

Parameters​

NameTypeDescription
offerTypeBAThe offer type to get the index for.
indexnumberThe index of the originating offer.
pricePointsnumberThe number of price points in the distribution.
stepSizenumberThe step size to use.

Returns​

number

The dual index.

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistributionHelper.ts:187


chunkIndices​

β–Έ chunkIndices(from, to, maxOffersInChunk): { from: number ; to: number }[]

Splits a range of indices into chunks according to the maximum number of offers in a single chunk.

Parameters​

NameTypeDescription
fromnumberThe start of the range.
tonumberThe end of the range.
maxOffersInChunknumberThe maximum number of offers in a single chunk.

Returns​

{ from: number ; to: number }[]

The chunks.

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistributionHelper.ts:215


chunkIndicesAroundMiddle​

β–Έ chunkIndicesAroundMiddle(from, to, maxOffersInChunk, middle?): { from: number ; to: number }[]

Splits a range of indices into chunks starting from the middle index according to the maximum number of offers in a single chunk.

Parameters​

NameTypeDescription
fromnumberThe start of the range.
tonumberThe end of the range.
maxOffersInChunknumberThe maximum number of offers in a single chunk.
middle?numberThe middle to split around; typically the index of the first ask in the distribution; if not provided, the midpoint between from and to is used.

Returns​

{ from: number ; to: number }[]

The chunks.

Dev

Since each chunk should contain pairs of offers and their duals the returned chunks will each have size less than maxOffersInChunk/2.

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistributionHelper.ts:234


getRequiredProvision​

β–Έ getRequiredProvision(params): Promise<Big>

Determines the required provision for the offers in the distribution.

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.
params.bidCountnumberThe number of bids to calculate provision for.
params.askCountnumberThe number of asks to calculate provision for.

Returns​

Promise<Big>

The provision required for the number of offers.

Defined in​

@mangrovedao/mangrove.js/src/kandel/kandelDistributionHelper.ts:294

  • Constructors
    • constructor
  • Properties
    • askTickPriceHelper
    • bidTickPriceHelper
    • market
  • Methods
    • sortByIndex
    • changeValues
    • uniformlyIncrease
    • uniformlyDecrease
    • calculateMinimumInitialGives
    • getDualIndex
    • chunkIndices
    • chunkIndicesAroundMiddle
    • getRequiredProvision