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.
Name | Type | Description |
---|---|---|
provider | address | The address of the liquidity provider. |
amount | uint256 | The amount of tokens being added as liquidity. |
AddLiquidityBatchCallbackData
struct AddLiquidityBatchCallbackData {
address provider;
uint256 amount;
}
Struct representing the data for an addLiquidityBatch callback.
Name | Type | Description |
---|---|---|
provider | address | The address of the liquidity provider. |
amount | uint256 | The amount of tokens being added as liquidity. |
RemoveLiquidityCallbackData
struct RemoveLiquidityCallbackData {
address provider;
uint256 clbTokenAmount;
}
Struct representing the data for a removeLiquidity callback.
Name | Type | Description |
---|---|---|
provider | address | The address of the liquidity provider. |
clbTokenAmount | uint256 | The amount of CLB tokens being removed. |
RemoveLiquidityBatchCallbackData
struct RemoveLiquidityBatchCallbackData {
address provider;
uint256[] clbTokenAmounts;
}
Struct representing the data for a removeLiquidityBatch callback.
Name | Type | Description |
---|---|---|
provider | address | The address of the liquidity provider. |
clbTokenAmounts | uint256[] | 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:
Name Type Description _marketFactory address The 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:
Name Type Description settlementToken address The address of the settlement token used for adding liquidity. vault address The address of the vault where the liquidity is added. data bytes Additional 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:
Name Type Description settlementToken address The address of the settlement token used for adding liquidity. vault address The address of the vault where the liquidity is added. data bytes Additional 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:
Name Type Description receiptId uint256 The 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:
Name Type Description _receiptIds uint256[] 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:
Name Type Description clbToken address The address of the Chromatic liquidity token. clbTokenId uint256 The ID of the Chromatic liquidity token to be removed. data bytes Additional 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:
Name Type Description clbToken address The address of the Chromatic liquidity token. clbTokenIds uint256[] The array of the Chromatic liquidity token IDs to be removed. data bytes Additional 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:
Name Type Description receiptId uint256 The 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:
Name Type Description _receiptIds uint256[] 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:
Name Type Description market address The address of the ChromaticMarket contract. qty int256 The quantity of the position. takerMargin uint256 The margin amount for the taker. makerMargin uint256 The margin amount for the maker. maxAllowableTradingFee uint256 The maximum allowable trading fee. Return Values:
Name Type Description [0] struct OpenPositionInfo position 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:
Name Type Description market address The address of the ChromaticMarket contract. amount uint256 The amount of the settlement token. Return Values:
Name Type Description [0] uint256 The price in USD as an int256.
closePosition
function closePosition(address market, uint256 positionId) external
Closes a position in a ChromaticMarket contract.
Parameters:
Name Type Description market address The address of the ChromaticMarket contract. positionId uint256 The ID of the position to close.
claimPosition
function claimPosition(address market, uint256 positionId) external
Claims a position from a ChromaticMarket contract.
Parameters:
Name Type Description market address The address of the ChromaticMarket contract. positionId uint256 The 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:
Name Type Description market address The address of the ChromaticMarket contract. feeRate int16 The fee rate of the liquidity bin. amount uint256 The amount to add as liquidity. recipient address The recipient address. Return Values:
Name Type Description receipt struct LpReceipt receipt 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:
Name Type Description market address The address of the ChromaticMarket contract. receiptId uint256 The 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:
Name Type Description market address The address of the ChromaticMarket contract. feeRate int16 The fee rate of the liquidity bin. clbTokenAmount uint256 The amount of CLB tokens to remove as liquidity. recipient address The recipient address. Return Values:
Name Type Description receipt struct LpReceipt receipt 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:
Name Type Description market address The address of the ChromaticMarket contract. receiptId uint256 The ID of the LP receipt.
_getAccount
function _getAccount(address owner) internal view returns (contract ChromaticAccount)
Retrieves the account of the specified owner.
Parameters:
Name Type Description owner address The owner of the account. Return Values:
Name Type Description [0] contract ChromaticAccount The account address.
getLpReceiptIds
function getLpReceiptIds(address market) external view returns (uint256[])
Retrieves the LP receipt IDs of the caller for the specified market.
Parameters:
Name Type Description market address The address of the ChromaticMarket contract. Return Values:
Name Type Description [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:
Name Type Description market address The address of the ChromaticMarket contract. owner address The address of the owner. Return Values:
Name Type Description [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:
Name Type Description market address The address of the ChromaticMarket contract. recipient address The address of the recipient for each liquidity bin. feeRates int16[] An array of fee rates for each liquidity bin. amounts uint256[] An array of amounts to add as liquidity for each bin. Return Values:
Name Type Description lpReceipts struct LpReceipt[] An array of LP receipts.
claimLiquidityBatch
function claimLiquidityBatch(address market, uint256[] _receiptIds) external
Claims liquidity from multiple ChromaticMarket contracts in a batch.
Parameters:
Name Type Description market address The address of the ChromaticMarket contract. _receiptIds uint256[]
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:
Name Type Description market address The address of the ChromaticMarket contract. recipient address The address of the recipient for each liquidity bin. feeRates int16[] An array of fee rates for each liquidity bin. clbTokenAmounts uint256[] An array of CLB token amounts to remove as liquidity for each bin. Return Values:
Name Type Description lpReceipts struct LpReceipt[] An array of LP receipts.
withdrawLiquidityBatch
function withdrawLiquidityBatch(address market, uint256[] _receiptIds) external
Withdraws liquidity from multiple ChromaticMarket contracts in a batch.
Parameters:
Name Type Description market address The address of the ChromaticMarket contract. _receiptIds uint256[]