Parameter Formats
Each LDF contract receives bytes32 ldfParams when called and has different formats for decoding the actual parameters. Below are how each LDF contract encodes its parameters.
GeometricDistribution
Parameter Encoding
The ldfParams are encoded as follows:
| shiftMode (1 byte) | offset (3 bytes) | length (2 bytes) | alpha (4 bytes) | unused (22 bytes) |
- shiftMode (1 byte): A uint8value representing the shift mode (0 for BOTH, 1 for LEFT, 2 for RIGHT, 3 for STATIC).
- offset (3 bytes): An int24value representing the offset applied to the TWAP tick to get the minTick. In ticks, not ricks.
- length (2 bytes): An int16value representing the length of the distribution in number of rounded ticks.
- alpha (4 bytes): A uint32value representing the alpha parameter of the geometric distribution.
- unused (22 bytes): Unused bytes, should be set to zero.
Important Notes
- The actual minTickis calculated asroundTickSingle(twapTick + offset, tickSpacing)whenshiftModeis not STATIC.
- For STATIC mode, offsetrepresents the absoluteminTickand must be aligned to tickSpacing.
- The alphavalue is scaled byQ96 / ALPHA_BASEinternally.ALPHA_BASEis1e8.
- The distribution is bounded to be within the range of usable ticks. If minTickis outside this range, it will be adjusted accordingly.
Example Usage
Here's an example of how to encode the parameters:
function encodeParams(
    ShiftMode shiftMode,
    int24 offset,
    int16 length,
    uint32 alpha
) pure returns (bytes32) {
    return abi.encodePacked(uint8(shiftMode), offset, length, alpha);
}
Remember to ensure that all values are within their appropriate ranges and that minTick is aligned with tickSpacing for STATIC mode.
UniformDistribution
Parameter Encoding
The ldfParams for the UniformDistribution are encoded as follows:
| shiftMode (1 byte) | tickLower (3 bytes) | tickUpper (3 bytes) | unused (25 bytes) |
- shiftMode (1 byte): A uint8value representing the shift mode (3 for STATIC, as Uniform distribution is always static).
- tickLower (3 bytes): An int24value representing the lower tick of the distribution.
- tickUpper (3 bytes): An int24value representing the upper tick of the distribution.
- unused (25 bytes): Unused bytes, should be set to zero.
Important Notes
- Both tickLowerandtickUppermust be within the range of valid ticks for the pool.
- tickLowermust be less than- tickUpper.
- The ticks need to be aligned to the tick spacing.
Example Usage
Here's an example of how to encode the parameters for a uniform distribution:
function encodeParams(
    int24 tickLower,
    int24 tickUpper
) pure returns (bytes32) {
    return abi.encodePacked(uint8(3), tickLower, tickUpper);
}
Remember to ensure that tickLower and tickUpper are within the valid range of ticks for the pool, tickLower is less than tickUpper and they're both aligned to the tick spacing.
DoubleGeometricDistribution
Parameter Encoding
The ldfParams are encoded as follows:
| shiftMode (1 byte) | offset (3 bytes) | length0 (2 bytes) | alpha0 (4 bytes) | weight0 (4 bytes) | length1 (2 bytes) | alpha1 (4 bytes) | weight1 (4 bytes) | unused (8 bytes) |
- shiftMode (1 byte): A uint8value representing the shift mode (0 for BOTH, 1 for LEFT, 2 for RIGHT, 3 for STATIC).
- offset (3 bytes): An int24value representing the offset applied to the TWAP tick to get the minTick. In ticks, not ricks.
- length0 (2 bytes): An int16value representing the length of the right distribution in number of rounded ticks.
- alpha0 (4 bytes): A uint32value representing the alpha parameter of the right distribution.
- weight0 (4 bytes): A uint32value representing the weight of the right distribution.
- length1 (2 bytes): An int16value representing the length of the left distribution in number of rounded ticks.
- alpha1 (4 bytes): A uint32value representing the alpha parameter of the left distribution.
- weight1 (4 bytes): A uint32value representing the weight of the left distribution.
- unused (8 bytes): Unused bytes, should be set to zero.
Important Notes
- The actual minTickis calculated asroundTickSingle(twapTick + offset, tickSpacing)whenshiftModeis not STATIC.
- For STATIC mode, offsetrepresents the absoluteminTickand must be aligned to tickSpacing.
- The alpha0andalpha1values are scaled byQ96 / ALPHA_BASEinternally.ALPHA_BASEis1e8.
- The distribution is bounded to be within the range of usable ticks. If minTickis outside this range, it will be adjusted accordingly.
- The total length of the distribution is length0 + length1.
- weight0and- weight1don't use any particular number of decimals, they're relative weights. For example,- weight0can be- 8and- weight1can be- 2, and the respective weights would be- 8 / 10 = 80%and- 2 / 10 = 20%.
- The minimum liquidity density of each geometric part must be greater than MIN_LIQUIDITY_DENSITY(Q96 / 1e3).
Example Usage
Here's an example of how to encode the parameters:
function encodeParams(
    ShiftMode shiftMode,
    int24 offset,
    int16 length0,
    uint32 alpha0,
    uint32 weight0,
    int16 length1,
    uint32 alpha1,
    uint32 weight1
) pure returns (bytes32) {
    return abi.encodePacked(uint8(shiftMode), offset, length0, alpha0, weight0, length1, alpha1, weight1);
}
Remember to ensure that all values are within their appropriate ranges and that minTick is aligned with tickSpacing for STATIC mode.
CarpetedGeometricDistribution
Parameter Encoding
The ldfParams are encoded as follows:
| shiftMode (1 byte) | offset (3 bytes) | length (2 bytes) | alpha (4 bytes) | weightCarpet (4 bytes) | unused (18 bytes) |
- shiftMode (1 byte): A uint8value representing the shift mode (0 for BOTH, 1 for LEFT, 2 for RIGHT, 3 for STATIC).
- offset (3 bytes): An int24value representing the offset applied to the TWAP tick to get the minTick. In ticks, not ricks.
- length (2 bytes): An int16value representing the length of the geometric distribution in number of rounded ticks.
- alpha (4 bytes): A uint32value representing the alpha parameter of the geometric distribution.
- weightCarpet (4 bytes): A uint32value representing the weight of the carpet distribution.
- unused (18 bytes): Unused bytes, should be set to zero.
Important Notes
- The actual minTickis calculated asroundTickSingle(twapTick + offset, tickSpacing)whenshiftModeis not STATIC.
- For STATIC mode, offsetrepresents the absoluteminTickand must be aligned to tickSpacing.
- The alphavalue is scaled byQ96 / ALPHA_BASEinternally.ALPHA_BASEis1e8.
- The weightCarpetvalue uses 18 decimals (i.e., aweightCarpetof 500000000000000000 represents 0.5 or 50%).
- The distribution is bounded to be within the range of usable ticks. If minTickis outside this range, it will be adjusted accordingly.
- The weightCarpetmust be non-zero. It is intentionally bounded to a small max value (type(uint32).max / 1e18) because larger values allocates too many tokens at extreme tick values.
- The minimum liquidity density of the geometric part must be greater than MIN_LIQUIDITY_DENSITY(Q96 / 1e3).
Example Usage
Here's an example of how to encode the parameters:
function encodeParams(
    ShiftMode shiftMode,
    int24 offset,
    int16 length,
    uint32 alpha,
    uint32 weightCarpet
) pure returns (bytes32) {
    return abi.encodePacked(uint8(shiftMode), offset, length, alpha, weightCarpet);
}
Remember to ensure that all values are within their appropriate ranges and that minTick is aligned with tickSpacing for STATIC mode.
CarpetedDoubleGeometricDistribution
Parameter Encoding
The ldfParams are encoded as follows:
| shiftMode (1 byte) | offset (3 bytes) | length0 (2 bytes) | alpha0 (4 bytes) | weight0 (4 bytes) | length1 (2 bytes) | alpha1 (4 bytes) | weight1 (4 bytes) | weightCarpet (4 bytes) | unused (4 bytes) |
- shiftMode (1 byte): A uint8value representing the shift mode (0 for BOTH, 1 for LEFT, 2 for RIGHT, 3 for STATIC).
- offset (3 bytes): An int24value representing the offset applied to the TWAP tick to get the minTick. In ticks, not ricks.
- length0 (2 bytes): An int16value representing the length of the right distribution in number of rounded ticks.
- alpha0 (4 bytes): A uint32value representing the alpha parameter of the right distribution.
- weight0 (4 bytes): A uint32value representing the weight of the right distribution.
- length1 (2 bytes): An int16value representing the length of the left distribution in number of rounded ticks.
- alpha1 (4 bytes): A uint32value representing the alpha parameter of the left distribution.
- weight1 (4 bytes): A uint32value representing the weight of the left distribution.
- weightCarpet (4 bytes): A uint32value representing the weight of the carpet distribution.
- unused (4 bytes): Unused bytes, should be set to zero.
Important Notes
- The actual minTickis calculated asroundTickSingle(twapTick + offset, tickSpacing)whenshiftModeis not STATIC.
- For STATIC mode, offsetrepresents the absoluteminTickand must be aligned to tickSpacing.
- The alpha0andalpha1values are scaled byQ96 / ALPHA_BASEinternally.ALPHA_BASEis1e8.
- The weightCarpetvalue uses 18 decimals (i.e., a value of 500000000000000000 represents 0.5 or 50%).
- The distribution is bounded to be within the range of usable ticks. If minTickis outside this range, it will be adjusted accordingly.
- The weightCarpetmust be non-zero. It is intentionally bounded to a small max value (type(uint32).max / 1e18) because larger values allocates too many tokens at extreme tick values.
- The minimum liquidity density of each geometric part must be greater than MIN_LIQUIDITY_DENSITY(Q96 / 1e3).
- The total length of the distribution is length0 + length1.
- weight0and- weight1don't use any particular number of decimals, they're relative weights. For example,- weight0can be- 8and- weight1can be- 2, and the respective weights would be- 8 / 10 = 80%and- 2 / 10 = 20%.
Example Usage
Here's an example of how to encode the parameters:
function encodeParams(
    ShiftMode shiftMode,
    int24 offset,
    int16 length0,
    uint32 alpha0,
    uint32 weight0,
    int16 length1,
    uint32 alpha1,
    uint32 weight1,
    uint32 weightCarpet
) pure returns (bytes32) {
    return abi.encodePacked(uint8(shiftMode), offset, length0, alpha0, weight0, length1, alpha1, weight1, weightCarpet);
}
Remember to ensure that all values are within their appropriate ranges and that minTick is aligned with tickSpacing for STATIC mode.
BuyTheDipGeometricDistribution
Parameter Encoding
The ldfParams are encoded as follows:
| shiftMode (1 byte) | minTick (3 bytes) | length (2 bytes) | alpha (4 bytes) | altAlpha (4 bytes) | altThreshold (3 bytes) | altThresholdDirection (1 byte) | unused (14 bytes) |
- shiftMode (1 byte): A uint8value representing the shift mode (3 for STATIC, as this distribution is always static).
- minTick (3 bytes): An int24value representing the minimum tick of the distribution. Must be aligned to tickSpacing.
- length (2 bytes): An int16value representing the length of the distribution in number of rounded ticks.
- alpha (4 bytes): A uint32value representing the alpha parameter of the geometric distribution.
- altAlpha (4 bytes): A uint32value representing the alternative alpha parameter.
- altThreshold (3 bytes): An int24value representing the threshold for switching between alpha and altAlpha.
- altThresholdDirection (1 byte): A uint8value (0 for false, 1 for true) indicating the direction of the threshold comparison.
- unused (14 bytes): Unused bytes, should be set to zero.
Important Notes
- This distribution requires TWAP to be enabled (twapSecondsAgo != 0) to trigger the alpha switching mechanism.
- The shiftModemust be STATIC (3).
- The alphaandaltAlphavalues are scaled byQ96 / ALPHA_BASEinternally.ALPHA_BASEis1e8.
- The distribution switches between alphaandaltAlphabased on the TWAP tick andaltThreshold.
- If altThresholdDirectionis true,altAlphais used whentwapTick <= altThreshold. If false,altAlphais used whentwapTick >= altThreshold.
- The alphaandaltAlphamust be on different sides of 1 (i.e., one < ALPHA_BASE and one > ALPHA_BASE).
- The altThresholdmust be within the range(minTick, minTick + length * tickSpacing).
- The minTickmust be aligned totickSpacing.
- The lengthmust be positive and the range[minTick, minTick + length * tickSpacing]must be within the usable tick range.
- Both alphaandaltAlphamust be within the range[MIN_ALPHA, MAX_ALPHA](from1e3to12e8) and neither can be exactlyALPHA_BASE(1e8).
- The distribution is bounded to be within the range of usable ticks.
- This LDF is designed to have one end of the distribution with essentially zero liquidity, so that when the alt alpha is activated, liquidity can move to a specified price to "buy the dip".
Example Usage
Here's an example of how to encode the parameters:
function encodeParams(
    int24 minTick,
    int16 length,
    uint32 alpha,
    uint32 altAlpha,
    int24 altThreshold,
    bool altThresholdDirection
) pure returns (bytes32) {
    return abi.encodePacked(
        uint8(3), // STATIC
        minTick,
        length,
        alpha,
        altAlpha,
        altThreshold,
        altThresholdDirection ? uint8(1) : uint8(0)
    );
}
Remember to ensure that all values are within their appropriate ranges and that minTick is aligned with tickSpacing. The alpha and altAlpha values must be on different sides of 1e8 (one < 1e8 and one > 1e8), and the altThreshold must be within the range (minTick, minTick + length * tickSpacing).