OrderbookFactory

State Variables

NameTypeDescription

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

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

NameTypeDescription

impl_

address

The address of the implementation contract.

createBook

Creates a new orderbook contract for the specified base and quote assets. This function can only be called by the engine contract.

Parameters

NameTypeDescription

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

NameTypeDescription

orderbook

address

The address of the created orderbook contract.

isClone

Checks if a given address is a clone of the orderbook implementation contract.

Parameters

NameTypeDescription

vault

address

The address to check.

Returns

NameTypeDescription

cloned

bool

Indicates whether the address is a clone of the implementation contract (true) or not (false).

getBook

Retrieves the address of an orderbook contract based on its index in the allOrderbooks array.

Parameters

NameTypeDescription

bookId_

uint256

The index of the orderbook contract.

Returns

NameTypeDescription

orderbook

address

The address of the orderbook contract.

getBookByPair

Retrieves the address of an orderbook contract based on the base and quote assets.

Parameters

NameTypeDescription

base

address

The address of the base asset.

quote

address

The address of the quote asset.

Returns

NameTypeDescription

book

address

The address of the orderbook contract.

getPairs

Retrieves an array of pairs of base and quote assets for a range of orderbook contracts.

Parameters

NameTypeDescription

start

uint

The start index of the range.

end

uint

The end index of the range.

Returns

NameTypeDescription

pairs

IOrderbookFactory.Pair[] memory

An array of pairs of base and quote assets.

getBaseQuote

Retrieves the base and quote assets associated with an orderbook contract.

Parameters

NameTypeDescription

orderbook

address

The address of the orderbook contract.

Returns

NameTypeDescription

base

address

The address of the base asset.

quote

address

The address of the quote asset.

initialize

Initializes the orderbook factory contract with the engine contract address. This function is called when deploying the contract.

Parameters

NameTypeDescription

engine_

address

The address of the engine contract.

allOrderbooksLength()

Retrieves the total number of created orderbooks.

Returns

NameTypeDescription

length

uint256

The length of the allOrderbooks array.

Error Types

ErrorDescription

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.

  1. InvalidRole(bytes32 role, address sender): This error is raised when an invalid role is provided for an operation.

  2. InvalidAccess(address sender, address allowed): This error is raised when a caller does not have access to perform a specific operation.

  3. PairAlreadyExists(address base, address quote): This error is raised when an orderbook already exists for the provided base and quote assets.

Last updated