Skip to main content

ChromaticMarketFactory.sol

ChromaticMarketFactory​

Contract for managing the creation and registration of Chromatic markets.

dao​

address dao

Returns the address of the DAO.

liquidator​

address liquidator

Returns the address of the liquidator.

vault​

address vault

Returns the address of the vault.

keeperFeePayer​

address keeperFeePayer

Returns the address of the keeper fee payer.

treasury​

address treasury

Returns the address of the DAO treasury.

marketSettlement​

address marketSettlement

Returns the address of the market settlement task.

defaultProtocolFeeRate​

uint16 defaultProtocolFeeRate

Returns the default protocol fee rate.

OnlyAccessableByDao​

error OnlyAccessableByDao()

Throws an error indicating that the caller is not the DAO.

AlreadySetVault​

error AlreadySetVault()

Throws an error indicating that the chromatic vault address is already set.

NotRegisteredOracleProvider​

error NotRegisteredOracleProvider()

Throws an error indicating that the oracle provider is not registered.

NotRegisteredSettlementToken​

error NotRegisteredSettlementToken()

Throws an error indicating that the settlement token is not registered.

ExistMarket​

error ExistMarket()

Throws an error indicating that a market already exists for the given oracle provider and settlement token.

onlyDao​

modifier onlyDao()

Modifier to restrict access to only the DAO address Throws an OnlyAccessableByDao error if the caller is not the DAO.

onlyRegisteredOracleProvider​

modifier onlyRegisteredOracleProvider(address oracleProvider)

Modifier to ensure that the specified oracle provider is registered. Throws a NotRegisteredOracleProvider error if the oracle provider is not registered.

  • Parameters:

    NameTypeDescription
    oracleProvideraddressThe address of the oracle provider to check. Requirements: - The oracleProvider address must be registered in the _oracleProviderRegistry.

constructor​

constructor(address _marketDiamondCutFacet, address _marketLoupeFacet, address _marketStateFacet, address _marketAddLiquidityFacet, address _marketRemoveLiquidityFacet, address _marketLiquidityLensFacet, address _marketTradeOpenPositionFacet, address _marketTradeClosePositionFacet, address _marketLiquidateFacet, address _marketSettleFacet) public

Initializes the ChromaticMarketFactory contract.

  • Parameters:

    NameTypeDescription
    _marketDiamondCutFacetaddressThe market diamond cut facet address.
    _marketLoupeFacetaddressThe market loupe facet address.
    _marketStateFacetaddressThe market state facet address.
    _marketAddLiquidityFacetaddressThe market liquidity facet address for adding and claiming liquidity.
    _marketRemoveLiquidityFacetaddressThe market liquidity facet address for removing and withdrawing liquidity.
    _marketLiquidityLensFacetaddressThe market liquidity lens facet address.
    _marketTradeOpenPositionFacetaddressThe market trade facet address for opening positions.
    _marketTradeClosePositionFacetaddressThe market trade facet address for closing and claiming positions.
    _marketLiquidateFacetaddressThe market liquidate facet address.
    _marketSettleFacetaddressThe market settle facet address.

_checkDao​

function _checkDao() internal view

This function can only be called by the modifier onlyDao.

updateDao​

function updateDao(address _dao) external

Updates the DAO address.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    _daoaddressThe new DAO address.

updateTreasury​

function updateTreasury(address _treasury) external

Updates the DAO treasury address.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    _treasuryaddressThe new DAO treasury address.

updateLiquidator​

function updateLiquidator(address _liquidator) external

Updates the liquidator address.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    _liquidatoraddressThe new liquidator address.

updateKeeperFeePayer​

function updateKeeperFeePayer(address _keeperFeePayer) external

Updates the keeper fee payer address.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    _keeperFeePayeraddressThe new keeper fee payer address.

updateDefaultProtocolFeeRate​

function updateDefaultProtocolFeeRate(uint16 _defaultProtocolFeeRate) external

Updates the default protocl fee rate.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    _defaultProtocolFeeRateuint16The new default protocol fee rate.

setVault​

function setVault(address _vault) external

Sets the vault address.

This function can only be called by the DAO address. Throws an AlreadySetVault error if the vault address has already been set.

  • Parameters:

    NameTypeDescription
    _vaultaddressThe vault address.

updateMarketSettlement​

function updateMarketSettlement(address _marketSettlement) external

Updates the market settlement task address.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    _marketSettlementaddressThe new market settlement task address.

getMarkets​

function getMarkets() external view returns (address[])

Returns an array of all market addresses.

  • Return Values:

    NameTypeDescription
    [0]address[]

getMarketsBySettlmentToken​

function getMarketsBySettlmentToken(address settlementToken) external view returns (address[])

Returns an array of market addresses associated with a settlement token.

  • Parameters:

    NameTypeDescription
    settlementTokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    [0]address[]An array of market addresses.

getMarket​

function getMarket(address oracleProvider, address settlementToken) external view returns (address)

Returns the address of a market associated with an oracle provider and settlement token.

  • Parameters:

    NameTypeDescription
    oracleProvideraddressThe address of the oracle provider.
    settlementTokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    [0]addressThe address of the market.

isRegisteredMarket​

function isRegisteredMarket(address market) external view returns (bool)

Checks if a market is registered.

  • Parameters:

    NameTypeDescription
    marketaddressThe address of the market.
  • Return Values:

    NameTypeDescription
    [0]boolTrue if the market is registered, false otherwise.

createMarket​

function createMarket(address oracleProvider, address settlementToken) external

Creates a new market associated with an oracle provider and settlement token.

This function creates a new market using the specified oracle provider and settlement token addresses. Throws a NotRegisteredSettlementToken error if the settlement token is not registered. Throws an ExistMarket error if the market already exists for the given oracle provider and settlement token.

  • Parameters:

    NameTypeDescription
    oracleProvideraddressThe address of the oracle provider.
    settlementTokenaddressThe address of the settlement token.

parameters​

function parameters() external view returns (address oracleProvider, address settlementToken, uint16 protocolFeeRate)

Get the parameters to be used in constructing the market, set transiently during market creation.

Called by the market constructor to fetch the parameters of the market Returns underlyingAsset The underlying asset of the market Returns settlementToken The settlement token of the market Returns protocolFeeRate The protocol fee rate of the market Returns vPoolCapacity Capacity of virtual future pool Returns vPoolA Amplification coefficient of virtual future pool, precise value

registerOracleProvider​

function registerOracleProvider(address oracleProvider, struct OracleProviderProperties properties) external

Registers an oracle provider.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    oracleProvideraddressThe address of the oracle provider to register.
    propertiesstruct OracleProviderPropertiesThe properties of the oracle provider.

unregisterOracleProvider​

function unregisterOracleProvider(address oracleProvider) external

Unregisters an oracle provider.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    oracleProvideraddressThe address of the oracle provider to unregister.

registeredOracleProviders​

function registeredOracleProviders() external view returns (address[])

Gets the registered oracle providers.

  • Return Values:

    NameTypeDescription
    [0]address[]An array of registered oracle provider addresses.

isRegisteredOracleProvider​

function isRegisteredOracleProvider(address oracleProvider) external view returns (bool)

Checks if an oracle provider is registered.

  • Parameters:

    NameTypeDescription
    oracleProvideraddressThe address of the oracle provider to check.
  • Return Values:

    NameTypeDescription
    [0]boolA boolean indicating if the oracle provider is registered.

getOracleProviderProperties​

function getOracleProviderProperties(address oracleProvider) external view returns (struct OracleProviderProperties)

Retrieves the properties of an oracle provider.

  • Parameters:

    NameTypeDescription
    oracleProvideraddressThe address of the oracle provider.
  • Return Values:

    NameTypeDescription
    [0]struct OracleProviderPropertiesThe properties of the oracle provider.

updateTakeProfitBPSRange​

function updateTakeProfitBPSRange(address oracleProvider, uint32 minTakeProfitBPS, uint32 maxTakeProfitBPS) external

Updates the take-profit basis points range of an oracle provider.

This function can only be called by the DAO and registered oracle providers.

  • Parameters:

    NameTypeDescription
    oracleProvideraddressThe address of the oracle provider.
    minTakeProfitBPSuint32The new minimum take-profit basis points.
    maxTakeProfitBPSuint32The new maximum take-profit basis points.

updateLeverageLevel​

function updateLeverageLevel(address oracleProvider, uint8 level) external

Updates the leverage level of an oracle provider in the registry.

This function can only be called by the DAO and registered oracle providers.

  • Parameters:

    NameTypeDescription
    oracleProvideraddressThe address of the oracle provider.
    leveluint8The new leverage level to be set for the oracle provider.

registerSettlementToken​

function registerSettlementToken(address token, address oracleProvider, uint256 minimumMargin, uint256 interestRate, uint256 flashLoanFeeRate, uint256 earningDistributionThreshold, uint24 uniswapFeeTier) external

Registers a new settlement token.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token to register.
    oracleProvideraddressThe oracle provider address for the settlement token.
    minimumMarginuint256The minimum margin for the settlement token.
    interestRateuint256The interest rate for the settlement token.
    flashLoanFeeRateuint256The flash loan fee rate for the settlement token.
    earningDistributionThresholduint256The earning distribution threshold for the settlement token.
    uniswapFeeTieruint24The Uniswap fee tier for the settlement token.

registeredSettlementTokens​

function registeredSettlementTokens() external view returns (address[])

Gets the list of registered settlement tokens.

  • Return Values:

    NameTypeDescription
    [0]address[]An array of addresses representing the registered settlement tokens.

isRegisteredSettlementToken​

function isRegisteredSettlementToken(address token) external view returns (bool)

Checks if a settlement token is registered.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token to check.
  • Return Values:

    NameTypeDescription
    [0]boolTrue if the settlement token is registered, false otherwise.

getSettlementTokenOracleProvider​

function getSettlementTokenOracleProvider(address token) external view returns (address)

Gets the oracle provider address for a settlement token.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    [0]addressThe oracle provider address for the settlement token.

setSettlementTokenOracleProvider​

function setSettlementTokenOracleProvider(address token, address oracleProvider) external

Sets the oracle provider address for a settlement token.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token.
    oracleProvideraddressThe new oracle provider address for the settlement token.

getMinimumMargin​

function getMinimumMargin(address token) external view returns (uint256)

Gets the minimum margin for a settlement token.

The minimumMargin is used as the minimum value for the taker margin of a position or as the minimum value for the maker margin of each bin.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    [0]uint256The minimum margin for the settlement token.

setMinimumMargin​

function setMinimumMargin(address token, uint256 minimumMargin) external

Sets the minimum margin for a settlement token.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token.
    minimumMarginuint256The new minimum margin for the settlement token.

getFlashLoanFeeRate​

function getFlashLoanFeeRate(address token) external view returns (uint256)

Gets the flash loan fee rate for a settlement token.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    [0]uint256The flash loan fee rate for the settlement token.

setFlashLoanFeeRate​

function setFlashLoanFeeRate(address token, uint256 flashLoanFeeRate) external

Sets the flash loan fee rate for a settlement token.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token.
    flashLoanFeeRateuint256The new flash loan fee rate for the settlement token.

getEarningDistributionThreshold​

function getEarningDistributionThreshold(address token) external view returns (uint256)

Gets the earning distribution threshold for a settlement token.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    [0]uint256The earning distribution threshold for the settlement token.

setEarningDistributionThreshold​

function setEarningDistributionThreshold(address token, uint256 earningDistributionThreshold) external

Sets the earning distribution threshold for a settlement token.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token.
    earningDistributionThresholduint256The new earning distribution threshold for the settlement token.

getUniswapFeeTier​

function getUniswapFeeTier(address token) external view returns (uint24)

Gets the Uniswap fee tier for a settlement token.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    [0]uint24The Uniswap fee tier for the settlement token.

setUniswapFeeTier​

function setUniswapFeeTier(address token, uint24 uniswapFeeTier) external

Sets the Uniswap fee tier for a settlement token.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token.
    uniswapFeeTieruint24The new Uniswap fee tier for the settlement token.

appendInterestRateRecord​

function appendInterestRateRecord(address token, uint256 annualRateBPS, uint256 beginTimestamp) external

Appends an interest rate record for a settlement token.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token.
    annualRateBPSuint256The annual interest rate in basis points (BPS).
    beginTimestampuint256The timestamp when the interest rate record begins.

removeLastInterestRateRecord​

function removeLastInterestRateRecord(address token) external

Removes the last interest rate record for a settlement token.

This function can only be called by the DAO address.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token.

getInterestRateRecords​

function getInterestRateRecords(address token) external view returns (struct InterestRate.Record[])

Gets all the interest rate records for a settlement token.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    [0]struct InterestRate.Record[]An array of interest rate records for the settlement token.

currentInterestRate​

function currentInterestRate(address token) external view returns (uint256 annualRateBPS)

Gets the current interest rate for a settlement token.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the settlement token.
  • Return Values:

    NameTypeDescription
    annualRateBPSuint256The current interest rate for the settlement token.

calculateInterest​

function calculateInterest(address token, uint256 amount, uint256 from, uint256 to) external view returns (uint256)

Calculates the interest accrued for a given token and amount within a specified time range.

  • Parameters:

    NameTypeDescription
    tokenaddressThe address of the token.
    amountuint256The amount of the token.
    fromuint256The starting timestamp (inclusive) of the time range.
    touint256The ending timestamp (exclusive) of the time range.
  • Return Values:

    NameTypeDescription
    [0]uint256The accrued interest for the specified token and amount within the given time range.