Skip to main content

ChromaticRouter.sol

ChromaticRouter​

A router contract that facilitates liquidity provision and trading on Chromatic.

AddLiquidityCallbackData​

struct AddLiquidityCallbackData {
address provider;
uint256 amount;
}

Struct representing the data for an addLiquidity callback.

NameTypeDescription
provideraddressThe address of the liquidity provider.
amountuint256The amount of tokens being added as liquidity.

AddLiquidityBatchCallbackData​

struct AddLiquidityBatchCallbackData {
address provider;
uint256 amount;
}

Struct representing the data for an addLiquidityBatch callback.

NameTypeDescription
provideraddressThe address of the liquidity provider.
amountuint256The amount of tokens being added as liquidity.

RemoveLiquidityCallbackData​

struct RemoveLiquidityCallbackData {
address provider;
uint256 clbTokenAmount;
}

Struct representing the data for a removeLiquidity callback.

NameTypeDescription
provideraddressThe address of the liquidity provider.
clbTokenAmountuint256The amount of CLB tokens being removed.

RemoveLiquidityBatchCallbackData​

struct RemoveLiquidityBatchCallbackData {
address provider;
uint256[] clbTokenAmounts;
}

Struct representing the data for a removeLiquidityBatch callback.

NameTypeDescription
provideraddressThe address of the liquidity provider.
clbTokenAmountsuint256[]An array of CLB token amounts being removed.

providerMap​

mapping(address => mapping(uint256 => address)) providerMap

receiptIds​

mapping(address => mapping(address => struct EnumerableSet.UintSet)) receiptIds

constructor​

constructor(address _marketFactory) public

Initializes the ChromaticRouter contract.

  • Parameters:

    NameTypeDescription
    _marketFactoryaddressThe address of the ChromaticMarketFactory contract.

addLiquidityCallback​

function addLiquidityCallback(address settlementToken, address vault, bytes data) external

Handles the callback after adding liquidity to the Chromatic protocol.

  • Parameters:

    NameTypeDescription
    settlementTokenaddressThe address of the settlement token used for adding liquidity.
    vaultaddressThe address of the vault where the liquidity is added.
    databytesAdditional data associated with the liquidity addition.

addLiquidityBatchCallback​

function addLiquidityBatchCallback(address settlementToken, address vault, bytes data) external

Handles the callback after adding liquidity to the Chromatic protocol.

  • Parameters:

    NameTypeDescription
    settlementTokenaddressThe address of the settlement token used for adding liquidity.
    vaultaddressThe address of the vault where the liquidity is added.
    databytesAdditional data associated with the liquidity addition.

claimLiquidityCallback​

function claimLiquidityCallback(uint256 receiptId, int16, uint256, uint256, bytes) external

Handles the callback after claiming liquidity from the Chromatic protocol.

  • Parameters:

    NameTypeDescription
    receiptIduint256The ID of the liquidity claim receipt.
    int16
    uint256
    uint256
    bytes

claimLiquidityBatchCallback​

function claimLiquidityBatchCallback(uint256[] _receiptIds, int16[], uint256[], uint256[], bytes) external

Handles the callback after claiming liquidity from the Chromatic protocol.

  • Parameters:

    NameTypeDescription
    _receiptIdsuint256[]
    int16[]
    uint256[]
    uint256[]
    bytes

removeLiquidityCallback​

function removeLiquidityCallback(address clbToken, uint256 clbTokenId, bytes data) external

Handles the callback after removing liquidity from the Chromatic protocol.

  • Parameters:

    NameTypeDescription
    clbTokenaddressThe address of the Chromatic liquidity token.
    clbTokenIduint256The ID of the Chromatic liquidity token to be removed.
    databytesAdditional data associated with the liquidity removal.

removeLiquidityBatchCallback​

function removeLiquidityBatchCallback(address clbToken, uint256[] clbTokenIds, bytes data) external

Handles the callback after removing liquidity from the Chromatic protocol.

  • Parameters:

    NameTypeDescription
    clbTokenaddressThe address of the Chromatic liquidity token.
    clbTokenIdsuint256[]The array of the Chromatic liquidity token IDs to be removed.
    databytesAdditional data associated with the liquidity removal.

withdrawLiquidityCallback​

function withdrawLiquidityCallback(uint256 receiptId, int16, uint256, uint256, bytes) external

Handles the callback after withdrawing liquidity from the Chromatic protocol.

  • Parameters:

    NameTypeDescription
    receiptIduint256The ID of the liquidity withdrawal receipt.
    int16
    uint256
    uint256
    bytes

withdrawLiquidityBatchCallback​

function withdrawLiquidityBatchCallback(uint256[] _receiptIds, int16[], uint256[], uint256[], bytes) external

Handles the callback after withdrawing liquidity from the Chromatic protocol.

  • Parameters:

    NameTypeDescription
    _receiptIdsuint256[]
    int16[]
    uint256[]
    uint256[]
    bytes

openPosition​

function openPosition(address market, int256 qty, uint256 takerMargin, uint256 makerMargin, uint256 maxAllowableTradingFee) external returns (struct OpenPositionInfo)

Opens a new position in a ChromaticMarket contract.

  • Parameters:

    NameTypeDescription
    marketaddressThe address of the ChromaticMarket contract.
    qtyint256The quantity of the position.
    takerMarginuint256The margin amount for the taker.
    makerMarginuint256The margin amount for the maker.
    maxAllowableTradingFeeuint256The maximum allowable trading fee.
  • Return Values:

    NameTypeDescription
    [0]struct OpenPositionInfoposition The new position.

_openPosition​

function _openPosition(address market, int256 qty, uint256 takerMargin, uint256 makerMargin, uint256 maxAllowableTradingFee) internal returns (struct OpenPositionInfo openPositionInfo)

_calcUsdPrice​

function _calcUsdPrice(address market, uint256 amount) internal view returns (uint256)

Calculates the price in USD for a specified amount of the settlement token in a ChromaticMarket.

  • Parameters:

    NameTypeDescription
    marketaddressThe address of the ChromaticMarket contract.
    amountuint256The amount of the settlement token.
  • Return Values:

    NameTypeDescription
    [0]uint256The price in USD as an int256.

closePosition​

function closePosition(address market, uint256 positionId) external

Closes a position in a ChromaticMarket contract.

  • Parameters:

    NameTypeDescription
    marketaddressThe address of the ChromaticMarket contract.
    positionIduint256The ID of the position to close.

claimPosition​

function claimPosition(address market, uint256 positionId) external

Claims a position from a ChromaticMarket contract.

  • Parameters:

    NameTypeDescription
    marketaddressThe address of the ChromaticMarket contract.
    positionIduint256The ID of the position to claim.

addLiquidity​

function addLiquidity(address market, int16 feeRate, uint256 amount, address recipient) external returns (struct LpReceipt receipt)

Adds liquidity to a ChromaticMarket contract.

  • Parameters:

    NameTypeDescription
    marketaddressThe address of the ChromaticMarket contract.
    feeRateint16The fee rate of the liquidity bin.
    amountuint256The amount to add as liquidity.
    recipientaddressThe recipient address.
  • Return Values:

    NameTypeDescription
    receiptstruct LpReceiptreceipt The LP receipt.

claimLiquidity​

function claimLiquidity(address market, uint256 receiptId) external

Claims liquidity from a ChromaticMarket contract.

This function allows the liquidity provider to claim their liquidity by calling the claimLiquidity function in the specified market contract.

  • Parameters:

    NameTypeDescription
    marketaddressThe address of the ChromaticMarket contract.
    receiptIduint256The ID of the LP receipt.

removeLiquidity​

function removeLiquidity(address market, int16 feeRate, uint256 clbTokenAmount, address recipient) external returns (struct LpReceipt receipt)

Removes liquidity from a ChromaticMarket contract.

  • Parameters:

    NameTypeDescription
    marketaddressThe address of the ChromaticMarket contract.
    feeRateint16The fee rate of the liquidity bin.
    clbTokenAmountuint256The amount of CLB tokens to remove as liquidity.
    recipientaddressThe recipient address.
  • Return Values:

    NameTypeDescription
    receiptstruct LpReceiptreceipt The LP receipt.

withdrawLiquidity​

function withdrawLiquidity(address market, uint256 receiptId) external

Withdraws liquidity from a ChromaticMarket contract.

This function allows the liquidity provider to withdraw their liquidity by calling the withdrawLiquidity function in the specified market contract.

  • Parameters:

    NameTypeDescription
    marketaddressThe address of the ChromaticMarket contract.
    receiptIduint256The ID of the LP receipt.

_getAccount​

function _getAccount(address owner) internal view returns (contract ChromaticAccount)

Retrieves the account of the specified owner.

  • Parameters:

    NameTypeDescription
    owneraddressThe owner of the account.
  • Return Values:

    NameTypeDescription
    [0]contract ChromaticAccountThe account address.

getLpReceiptIds​

function getLpReceiptIds(address market) external view returns (uint256[])

Retrieves the LP receipt IDs of the caller for the specified market.

  • Parameters:

    NameTypeDescription
    marketaddressThe address of the ChromaticMarket contract.
  • Return Values:

    NameTypeDescription
    [0]uint256[]An array of LP receipt IDs.

getLpReceiptIds​

function getLpReceiptIds(address market, address owner) public view returns (uint256[])

Get the LP receipt IDs associated with a specific market and owner.

  • Parameters:

    NameTypeDescription
    marketaddressThe address of the ChromaticMarket contract.
    owneraddressThe address of the owner.
  • Return Values:

    NameTypeDescription
    [0]uint256[]An array of LP receipt IDs.

addLiquidityBatch​

function addLiquidityBatch(address market, address recipient, int16[] feeRates, uint256[] amounts) external returns (struct LpReceipt[] lpReceipts)

Adds liquidity to multiple liquidity bins of ChromaticMarket contract in a batch.

  • Parameters:

    NameTypeDescription
    marketaddressThe address of the ChromaticMarket contract.
    recipientaddressThe address of the recipient for each liquidity bin.
    feeRatesint16[]An array of fee rates for each liquidity bin.
    amountsuint256[]An array of amounts to add as liquidity for each bin.
  • Return Values:

    NameTypeDescription
    lpReceiptsstruct LpReceipt[]An array of LP receipts.

claimLiquidityBatch​

function claimLiquidityBatch(address market, uint256[] _receiptIds) external

Claims liquidity from multiple ChromaticMarket contracts in a batch.

  • Parameters:

    NameTypeDescription
    marketaddressThe address of the ChromaticMarket contract.
    _receiptIdsuint256[]

removeLiquidityBatch​

function removeLiquidityBatch(address market, address recipient, int16[] feeRates, uint256[] clbTokenAmounts) external returns (struct LpReceipt[] lpReceipts)

Removes liquidity from multiple ChromaticMarket contracts in a batch.

  • Parameters:

    NameTypeDescription
    marketaddressThe address of the ChromaticMarket contract.
    recipientaddressThe address of the recipient for each liquidity bin.
    feeRatesint16[]An array of fee rates for each liquidity bin.
    clbTokenAmountsuint256[]An array of CLB token amounts to remove as liquidity for each bin.
  • Return Values:

    NameTypeDescription
    lpReceiptsstruct LpReceipt[]An array of LP receipts.

withdrawLiquidityBatch​

function withdrawLiquidityBatch(address market, uint256[] _receiptIds) external

Withdraws liquidity from multiple ChromaticMarket contracts in a batch.

  • Parameters:

    NameTypeDescription
    marketaddressThe address of the ChromaticMarket contract.
    _receiptIdsuint256[]