Class: KandelDistributionHelper
Title
Helper for handling Kandel offer distributions.
Constructorsβ
constructorβ
β’ new KandelDistributionHelper(market
): KandelDistributionHelper
Constructor
Parametersβ
Name | Type | Description |
---|---|---|
market | KeyResolvedForCalculation | The key data about the market. |
Returnsβ
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β
Name | Type | Description |
---|---|---|
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β
Name | Type | Description |
---|---|---|
delta | undefined | Big | The total amount to change. |
values | Big [] | The values to change. |
minimumValue | Big | The minimum value for each value. |
round | (value : Big ) => Big | The function to round the values. |
Returnsβ
Object
The new values and the total change.
Name | Type |
---|---|
newValues | any [] |
totalChange | Big |
Defined inβ
@mangrovedao/mangrove.js/src/kandel/kandelDistributionHelper.ts:47
uniformlyIncreaseβ
βΈ uniformlyIncrease(values
, totalDelta
, round
): Object
Uniformly increases values by a total amount.
Parametersβ
Name | Type | Description |
---|---|---|
values | Big [] | The values to increase. |
totalDelta | Big | The total amount to increase. |
round | (value : Big ) => Big | The function to round the values. |
Returnsβ
Object
The new values and the total change.
Name | Type |
---|---|
newValues | any [] |
totalChange | Big |
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β
Name | Type | Description |
---|---|---|
values | Big [] | The values to decrease. |
totalDelta | Big | The total amount to decrease. |
minimumValue | Big | The minimum value for each value. |
round | (value : Big ) => Big | The function to round each value. |
Returnsβ
Object
The new values and the total change.
Name | Type |
---|---|
newValues | Big [] |
totalChange | Big |
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β
Name | Type | Description |
---|---|---|
minimumBasePerOffer | Big | The minimum base to give for each offer. |
minimumQuotePerOffer | Big | The minimum quote to give for each offer. |
bidTicks | number [] | The ticks for bids. |
askTicks | number [] | 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.
Name | Type |
---|---|
askGives | Big |
bidGives | Big |
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β
Name | Type | Description |
---|---|---|
offerType | BA | The offer type to get the index for. |
index | number | The index of the originating offer. |
pricePoints | number | The number of price points in the distribution. |
stepSize | number | The 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β
Name | Type | Description |
---|---|---|
from | number | The start of the range. |
to | number | The end of the range. |
maxOffersInChunk | number | The 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β
Name | Type | Description |
---|---|---|
from | number | The start of the range. |
to | number | The end of the range. |
maxOffersInChunk | number | The maximum number of offers in a single chunk. |
middle? | number | The 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β
Name | Type | Description |
---|---|---|
params | Object | The parameters used to calculate the provision. |
params.market | Market | The market to get provisions for bids and asks from. |
params.gasreq | number | The gas required to execute a trade. |
params.gasprice | number | The gas price to calculate provision for. |
params.bidCount | number | The number of bids to calculate provision for. |
params.askCount | number | The 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