Smart Contracts
CLOB Contracts
Central Limit Order Book smart contracts
The CLOB contracts implement a Central Limit Order Book for the MuchFi protocol, enabling efficient order matching and trade execution.
| Contract | Address |
|---|
| CLOB Router | Coming soon |
| CLOB Pool Manager | Coming soon |
| CLOB Balance Manager | Coming soon |
| CLOB Quoter | Coming soon |
| Contract | Address |
|---|
| CLOB Router | 0x6E613404350c32f3F864D4b852CcD573ECEb4679 |
| CLOB Pool Manager | 0x997De90D186aFE1c0b6cFe97B42942D9F6537869 |
| CLOB Balance Manager | 0x8d777945EF39A2191111ba16F362C29C75774a74 |
| CLOB Quoter | 0x891684a15072Fc8A284ae19462a5B95259DF2727 |
Tip
CLOB is fully enabled on Testnet. You can test order book trading here.
The main entry point for CLOB trading operations.
| Function | Description |
|---|
placeOrder(pool, price, quantity, side, user) | Place a limit order |
placeOrderWithDeposit(pool, price, quantity, side, user) | Place order with token deposit |
placeOrderWithDepositETH(pool, price, quantity, side) | Place order with ETH deposit (payable) |
placeMarketOrder(pool, quantity, side, user, minAmountOut) | Place a market order |
placeMarketOrderWithDeposit(pool, quantity, side, user, minAmountOut) | Market order with deposit |
placeMarketOrderWithDepositETH(pool, quantity, side, minAmountOut) | Market order with ETH (payable) |
placeBatchOrders(orders, atomic) | Place multiple orders in batch |
| Function | Description |
|---|
cancelOrder(pool, orderId) | Cancel a single order |
cancelBatchOrders(pool, orderIds) | Cancel multiple orders |
| Function | Description |
|---|
swap(srcCurrency, dstCurrency, srcAmount, minDstAmount, maxHops, user) | Execute token swap |
swapETHForTokens(dstCurrency, minDstAmount, maxHops) | Swap ETH for tokens (payable) |
swapTokensForETH(srcCurrency, srcAmount, minETHOut, maxHops) | Swap tokens for ETH |
| Function | Returns | Description |
|---|
getQuote(baseCurrency, quoteCurrency, orderType, side, quantity, price) | QuoteResult | Get quote for order |
getQuoteByQuoteAmount(baseCurrency, quoteCurrency, side, quoteAmount) | QuoteResult | Get quote by quote amount |
getBatchQuote(orders) | QuoteResult[] | Get quotes for batch orders |
QuoteResult struct:
expectedAmountOut - Expected output amount
totalQuoteAmount - Total quote currency amount
executionPrice - Execution price
avgExecutionPrice - Average execution price
priceImpact - Price impact percentage
fee - Trading fee
executable - Whether order can execute
message - Status message
| Function | Returns | Description |
|---|
getOrder(baseCurrency, quoteCurrency, orderId) | Order | Get order details |
getBestPrice(baseCurrency, quoteCurrency, side) | PriceVolume | Get best bid/ask price |
getNextBestPrices(pool, side, price, count) | PriceVolume[] | Get next best prices |
getOrderQueue(baseCurrency, quoteCurrency, side, price) | (orderCount, totalVolume) | Get order queue info |
calculateOrderAmounts(pool, price, quantity, side, orderType) | (orderAmount, quoteAmount) | Calculate order amounts |
| Function | Returns | Description |
|---|
getWETH() | address | Get WETH contract address |
getMaxBatchSize() | uint256 | Get maximum batch size |
owner() | address | Contract owner |
| Event | Description |
|---|
BatchOrderPlaced(orderId, batchIndex, success, message) | Batch order placed |
BatchOrderCancelled(orderId, batchIndex, success, message) | Batch order cancelled |
Initialized(version) | Contract initialized |
OwnershipTransferred(previousOwner, newOwner) | Ownership transferred |
| Error | Description |
|---|
FillOrKillNotFulfilled(filledAmount, requestedAmount) | FOK order not fully filled |
InsufficientBalance(requiredDeposit, userBalance) | Insufficient balance |
InvalidPrice(price) | Invalid price |
InvalidPriceIncrement | Price not on valid tick |
InvalidQuantity | Invalid quantity |
InvalidQuantityIncrement | Quantity not on valid increment |
MaxOrdersExceeded(totalOrders, maxOrders) | Max orders exceeded |
OrderNotFound | Order not found |
OrderTooLarge(amount, maxAmount) | Order exceeds max size |
OrderTooSmall(amount, minAmount) | Order below min size |
PostOnlyWouldTake | Post-only order would cross |
SlippageExceeded(requestedPrice, limitPrice) | Slippage exceeded |
SlippageTooHigh(received, minReceived) | Slippage too high |
TradingPaused | Trading is paused |
UnauthorizedCancellation | Not authorized to cancel |
Manages user balances and fund locking for CLOB trading.
| Function | Description |
|---|
deposit(currency, amount, sender, user) | Deposit tokens to account |
depositAndLock(currency, amount, user, orderBook) | Deposit and lock for trading |
| Function | Description |
|---|
withdraw(currency, amount) | Withdraw tokens |
withdraw(currency, amount, user) | Withdraw tokens for user |
| Function | Description |
|---|
lock(user, currency, amount) | Lock funds for order |
lock(user, currency, amount, orderBook) | Lock funds for specific orderbook |
unlock(user, currency, amount) | Unlock funds after cancellation |
| Function | Description |
|---|
transferFrom(sender, receiver, currency, amount) | Transfer between accounts |
transferLockedFrom(sender, receiver, currency, amount) | Transfer locked funds |
transferOut(sender, receiver, currency, amount) | Transfer out of system |
| Function | Returns | Description |
|---|
getBalance(user, currency) | uint256 | Get user balance |
getLockedBalance(user, operator, currency) | uint256 | Get locked balance |
feeMaker() | uint256 | Maker fee rate |
feeTaker() | uint256 | Taker fee rate |
feeReceiver() | address | Fee receiver address |
getFeeUnit() | uint256 | Fee unit denominator |
| Event | Description |
|---|
Deposit(user, id, amount) | Funds deposited |
Withdrawal(user, id, amount) | Funds withdrawn |
Lock(user, id, amount) | Funds locked |
Unlock(user, id, amount) | Funds unlocked |
TransferFrom(operator, sender, receiver, id, amount, feeAmount) | Internal transfer |
TransferLockedFrom(operator, sender, receiver, id, amount, feeAmount) | Locked transfer |
| Error | Description |
|---|
InsufficientBalance(user, id, want, have) | Insufficient balance |
UnauthorizedCaller(caller) | Unauthorized caller |
UnauthorizedOperator(operator) | Unauthorized operator |
ZeroAmount | Zero amount not allowed |
TransferError(user, currency, amount) | Transfer failed |
NativeTransferFailed | Native token transfer failed |
Individual order book contract for each trading pair.
| Function | Description |
|---|
placeOrder(price, quantity, side, user, timeInForce) | Place limit order |
placeMarketOrder(quantity, side, user) | Place market order |
cancelOrder(orderId, user) | Cancel order |
| Function | Returns | Description |
|---|
getOrder(orderId) | Order | Get order details |
getBestPrice(side) | PriceVolume | Get best price for side |
getNextBestPrices(side, price, count) | PriceVolume[] | Get next prices |
getOrderQueue(side, price) | (orderCount, totalVolume) | Get queue at price |
getTradingRules() | TradingRules | Get trading rules |
Order struct:
user - Order owner
id - Order ID
quantity - Order quantity
filled - Filled amount
price - Order price
expiry - Expiration timestamp
status - Order status
orderType - Order type
side - Buy/Sell side
TradingRules struct:
minTradeAmount - Minimum trade amount
minAmountMovement - Minimum amount increment
minPriceMovement - Minimum price tick
minOrderSize - Minimum order size
Side:
OrderType:
TimeInForce:
0 = GTC (Good Till Cancel)
1 = IOC (Immediate or Cancel)
2 = FOK (Fill or Kill)
3 = PostOnly
Status:
0 = Open
1 = PartiallyFilled
2 = Filled
3 = Cancelled
| Event | Description |
|---|
OrderPlaced(orderId, user, side, price, quantity, expiry, isMarketOrder, status) | Order placed |
OrderCancelled(orderId, user, timestamp, status) | Order cancelled |
OrderMatched(user, buyOrderId, sellOrderId, side, timestamp, executionPrice, executedQuantity) | Orders matched |
UpdateOrder(orderId, timestamp, filled, status) | Order updated |