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:
Name Type Description oracleProvider address The 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:
Name Type Description _marketDiamondCutFacet address The market diamond cut facet address. _marketLoupeFacet address The market loupe facet address. _marketStateFacet address The market state facet address. _marketAddLiquidityFacet address The market liquidity facet address for adding and claiming liquidity. _marketRemoveLiquidityFacet address The market liquidity facet address for removing and withdrawing liquidity. _marketLiquidityLensFacet address The market liquidity lens facet address. _marketTradeOpenPositionFacet address The market trade facet address for opening positions. _marketTradeClosePositionFacet address The market trade facet address for closing and claiming positions. _marketLiquidateFacet address The market liquidate facet address. _marketSettleFacet address The 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:
Name Type Description _dao address The 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:
Name Type Description _treasury address The 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:
Name Type Description _liquidator address The 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:
Name Type Description _keeperFeePayer address The 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:
Name Type Description _defaultProtocolFeeRate uint16 The 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:
Name Type Description _vault address The 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:
Name Type Description _marketSettlement address The new market settlement task address.
getMarkets
function getMarkets() external view returns (address[])
Returns an array of all market addresses.
Return Values:
Name Type Description [0] address[]
getMarketsBySettlmentToken
function getMarketsBySettlmentToken(address settlementToken) external view returns (address[])
Returns an array of market addresses associated with a settlement token.
Parameters:
Name Type Description settlementToken address The address of the settlement token. Return Values:
Name Type Description [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:
Name Type Description oracleProvider address The address of the oracle provider. settlementToken address The address of the settlement token. Return Values:
Name Type Description [0] address The address of the market.
isRegisteredMarket
function isRegisteredMarket(address market) external view returns (bool)
Checks if a market is registered.
Parameters:
Name Type Description market address The address of the market. Return Values:
Name Type Description [0] bool True 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:
Name Type Description oracleProvider address The address of the oracle provider. settlementToken address The 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:
Name Type Description oracleProvider address The address of the oracle provider to register. properties struct OracleProviderProperties The 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:
Name Type Description oracleProvider address The address of the oracle provider to unregister.
registeredOracleProviders
function registeredOracleProviders() external view returns (address[])
Gets the registered oracle providers.
Return Values:
Name Type Description [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:
Name Type Description oracleProvider address The address of the oracle provider to check. Return Values:
Name Type Description [0] bool A 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:
Name Type Description oracleProvider address The address of the oracle provider. Return Values:
Name Type Description [0] struct OracleProviderProperties The 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:
Name Type Description oracleProvider address The address of the oracle provider. minTakeProfitBPS uint32 The new minimum take-profit basis points. maxTakeProfitBPS uint32 The 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:
Name Type Description oracleProvider address The address of the oracle provider. level uint8 The 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:
Name Type Description token address The address of the settlement token to register. oracleProvider address The oracle provider address for the settlement token. minimumMargin uint256 The minimum margin for the settlement token. interestRate uint256 The interest rate for the settlement token. flashLoanFeeRate uint256 The flash loan fee rate for the settlement token. earningDistributionThreshold uint256 The earning distribution threshold for the settlement token. uniswapFeeTier uint24 The Uniswap fee tier for the settlement token.
registeredSettlementTokens
function registeredSettlementTokens() external view returns (address[])
Gets the list of registered settlement tokens.
Return Values:
Name Type Description [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:
Name Type Description token address The address of the settlement token to check. Return Values:
Name Type Description [0] bool True 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:
Name Type Description token address The address of the settlement token. Return Values:
Name Type Description [0] address The 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:
Name Type Description token address The address of the settlement token. oracleProvider address The 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:
Name Type Description token address The address of the settlement token. Return Values:
Name Type Description [0] uint256 The 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:
Name Type Description token address The address of the settlement token. minimumMargin uint256 The 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:
Name Type Description token address The address of the settlement token. Return Values:
Name Type Description [0] uint256 The 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:
Name Type Description token address The address of the settlement token. flashLoanFeeRate uint256 The 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:
Name Type Description token address The address of the settlement token. Return Values:
Name Type Description [0] uint256 The 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:
Name Type Description token address The address of the settlement token. earningDistributionThreshold uint256 The 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:
Name Type Description token address The address of the settlement token. Return Values:
Name Type Description [0] uint24 The 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:
Name Type Description token address The address of the settlement token. uniswapFeeTier uint24 The 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:
Name Type Description token address The address of the settlement token. annualRateBPS uint256 The annual interest rate in basis points (BPS). beginTimestamp uint256 The 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:
Name Type Description token address The 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:
Name Type Description token address The address of the settlement token. Return Values:
Name Type Description [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:
Name Type Description token address The address of the settlement token. Return Values:
Name Type Description annualRateBPS uint256 The 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:
Name Type Description token address The address of the token. amount uint256 The amount of the token. from uint256 The starting timestamp (inclusive) of the time range. to uint256 The ending timestamp (exclusive) of the time range. Return Values:
Name Type Description [0] uint256 The accrued interest for the specified token and amount within the given time range.