OrderbookFactory
State Variables
Name | Type | Description |
---|---|---|
allOrderbooks | address[] | An array that stores the addresses of all created orderbooks. |
engine | address | The address of the manager or engine contract that controls the orderbook factory. |
version | uint32 | The version number of the orderbook implementation. |
impl | address | The address of the orderbook implementation contract that provides the business logic for orderbook creation. |
orderbookByBaseQuote | mapping(address => mapping(address => address)) | A mapping that stores the address of the orderbook contract based on the base and quote assets. |
baseQuoteByOrderbook | mapping(address => IOrderbookFactory.Pair) | A mapping that stores the base and quote assets of the orderbook contract. |
Note: The IOrderbookFactory.Pair
represents a struct that contains the base and quote assets of an orderbook.
Functions
setImpl
setImpl
Sets the implementation address to be used for orderbook creation. This function can only be called by the contract owner with the DEFAULT_ADMIN_ROLE
role.
Parameters
Name | Type | Description |
---|---|---|
impl_ | address | The address of the implementation contract. |
createBook
createBook
Creates a new orderbook contract for the specified base and quote assets. This function can only be called by the engine contract.
Parameters
Name | Type | Description |
---|---|---|
bid_ | address | The address of the base asset. |
ask_ | address | The address of the quote asset. |
engine_ | address | The address of the engine contract. |
Returns
Name | Type | Description |
---|---|---|
orderbook | address | The address of the created orderbook contract. |
isClone
isClone
Checks if a given address is a clone of the orderbook implementation contract.
Parameters
Name | Type | Description |
---|---|---|
vault | address | The address to check. |
Returns
Name | Type | Description |
---|---|---|
cloned | bool | Indicates whether the address is a clone of the implementation contract (true) or not (false). |
getBook
getBook
Retrieves the address of an orderbook contract based on its index in the allOrderbooks
array.
Parameters
Name | Type | Description |
---|---|---|
bookId_ | uint256 | The index of the orderbook contract. |
Returns
Name | Type | Description |
---|---|---|
orderbook | address | The address of the orderbook contract. |
getBookByPair
getBookByPair
Retrieves the address of an orderbook contract based on the base and quote assets.
Parameters
Name | Type | Description |
---|---|---|
base | address | The address of the base asset. |
quote | address | The address of the quote asset. |
Returns
Name | Type | Description |
---|---|---|
book | address | The address of the orderbook contract. |
getPairs
getPairs
Retrieves an array of pairs of base and quote assets for a range of orderbook contracts.
Parameters
Name | Type | Description |
---|---|---|
start | uint | The start index of the range. |
end | uint | The end index of the range. |
Returns
Name | Type | Description |
---|---|---|
pairs | IOrderbookFactory.Pair[] memory | An array of pairs of base and quote assets. |
getBaseQuote
getBaseQuote
Retrieves the base and quote assets associated with an orderbook contract.
Parameters
Name | Type | Description |
---|---|---|
orderbook | address | The address of the orderbook contract. |
Returns
Name | Type | Description |
---|---|---|
base | address | The address of the base asset. |
quote | address | The address of the quote asset. |
initialize
initialize
Initializes the orderbook factory contract with the engine contract address. This function is called when deploying the contract.
Parameters
Name | Type | Description |
---|---|---|
engine_ | address | The address of the engine contract. |
allOrderbooksLength()
allOrderbooksLength()
Retrieves the total number of created orderbooks.
Returns
Name | Type | Description |
---|---|---|
length | uint256 | The length of the allOrderbooks array. |
Error Types
Error | Description |
---|---|
InvalidRole | Raised when an invalid role is provided for an operation. |
InvalidAccess | Raised when a caller does not have access to perform a specific operation. |
PairAlreadyExists | Raised when an orderbook already exists for the provided base and quote assets. |
InvalidRole(bytes32 role, address sender)
: This error is raised when an invalid role is provided for an operation.InvalidAccess(address sender, address allowed)
: This error is raised when a caller does not have access to perform a specific operation.PairAlreadyExists(address base, address quote)
: This error is raised when an orderbook already exists for the provided base and quote assets.
Last updated