Skip to main content

Module IStablecoinDEX

Module IStablecoinDEX 

Source
Expand description

StablecoinDEX interface for managing orderbook based trading of stablecoins.

The StablecoinDEX provides a limit orderbook system where users can:

  • Place limit orders (buy/sell) with specific price ticks
  • Place flip orders that automatically create opposite-side orders when filled
  • Execute swaps against existing liquidity
  • Manage internal balances for trading

The exchange operates on pairs between base tokens and their designated quote tokens, using a tick-based pricing system for precise order matching.

interface IStablecoinDEX {
    struct Order { uint128 orderId; address maker; bytes32 bookKey; bool isBid; int16 tick; uint128 amount; uint128 remaining; uint128 prev; uint128 next; bool isFlip; int16 flipTick; }
    struct PriceLevel { uint128 head; uint128 tail; uint128 totalLiquidity; }
    struct Orderbook { address base; address quote; int16 bestBidTick; int16 bestAskTick; }
    function createPair(address base) external returns (bytes32 key);
    function place(address token, uint128 amount, bool isBid, int16 tick) external returns (uint128 orderId);
    function placeFlip(address token, uint128 amount, bool isBid, int16 tick, int16 flipTick) external returns (uint128 orderId);
    function cancel(uint128 orderId) external;
    function cancelStaleOrder(uint128 orderId) external;
    function swapExactAmountIn(address tokenIn, address tokenOut, uint128 amountIn, uint128 minAmountOut) external returns (uint128 amountOut);
    function swapExactAmountOut(address tokenIn, address tokenOut, uint128 amountOut, uint128 maxAmountIn) external returns (uint128 amountIn);
    function quoteSwapExactAmountIn(address tokenIn, address tokenOut, uint128 amountIn) external view returns (uint128 amountOut);
    function quoteSwapExactAmountOut(address tokenIn, address tokenOut, uint128 amountOut) external view returns (uint128 amountIn);
    function balanceOf(address user, address token) external view returns (uint128);
    function withdraw(address token, uint128 amount) external;
    function getOrder(uint128 orderId) external view returns (Order memory);
    function getTickLevel(address base, int16 tick, bool isBid) external view returns (uint128 head, uint128 tail, uint128 totalLiquidity);
    function pairKey(address tokenA, address tokenB) external pure returns (bytes32);
    function nextOrderId() external view returns (uint128);
    function books(bytes32 pairKey) external view returns (Orderbook memory);
    function MIN_TICK() external pure returns (int16);
    function MAX_TICK() external pure returns (int16);
    function TICK_SPACING() external pure returns (int16);
    function PRICE_SCALE() external pure returns (uint32);
    function MIN_ORDER_AMOUNT() external pure returns (uint128);
    function MIN_PRICE() external pure returns (uint32);
    function MAX_PRICE() external pure returns (uint32);
    function tickToPrice(int16 tick) external pure returns (uint32 price);
    function priceToTick(uint32 price) external pure returns (int16 tick);
    event PairCreated(bytes32 indexed key, address indexed base, address indexed quote);
    event OrderPlaced(uint128 indexed orderId, address indexed maker, address indexed token, uint128 amount, bool isBid, int16 tick, bool isFlipOrder, int16 flipTick);
    event OrderFilled(uint128 indexed orderId, address indexed maker, address indexed taker, uint128 amountFilled, bool partialFill);
    event OrderCancelled(uint128 indexed orderId);
    error Unauthorized();
    error PairDoesNotExist();
    error PairAlreadyExists();
    error OrderDoesNotExist();
    error IdenticalTokens();
    error InvalidToken();
    error TickOutOfBounds(int16 tick);
    error InvalidTick();
    error InvalidFlipTick();
    error InsufficientBalance();
    error InsufficientLiquidity();
    error InsufficientOutput();
    error MaxInputExceeded();
    error BelowMinimumOrderSize(uint128 amount);
    error InvalidBaseToken();
    error OrderNotStale();
}

Modules§

abi
Contains dynamic ABI definitions for this contract.

Structs§

BelowMinimumOrderSize
Custom error with signature BelowMinimumOrderSize(uint128) and selector 0x46628371.
IStablecoinDEXInstance
A IStablecoinDEX instance.
IdenticalTokens
Custom error with signature IdenticalTokens() and selector 0x5c6d7b73.
InsufficientBalance
Custom error with signature InsufficientBalance() and selector 0xf4d678b8.
InsufficientLiquidity
Custom error with signature InsufficientLiquidity() and selector 0xbb55fd27.
InsufficientOutput
Custom error with signature InsufficientOutput() and selector 0xbb2875c3.
InvalidBaseToken
Custom error with signature InvalidBaseToken() and selector 0x0e442a4a.
InvalidFlipTick
Custom error with signature InvalidFlipTick() and selector 0xf88aeb80.
InvalidTick
Custom error with signature InvalidTick() and selector 0xce8ef7fc.
InvalidToken
Custom error with signature InvalidToken() and selector 0xc1ab6dc1.
MAX_PRICECall
Function with signature MAX_PRICE() and selector 0x01c11d96.
MAX_PRICEReturn
Container type for the return parameters of the MAX_PRICE() function.
MAX_TICKCall
Function with signature MAX_TICK() and selector 0x6882a888.
MAX_TICKReturn
Container type for the return parameters of the MAX_TICK() function.
MIN_ORDER_AMOUNTCall
Function with signature MIN_ORDER_AMOUNT() and selector 0x40bf2aa4.
MIN_ORDER_AMOUNTReturn
Container type for the return parameters of the MIN_ORDER_AMOUNT() function.
MIN_PRICECall
Function with signature MIN_PRICE() and selector 0xad9f20a6.
MIN_PRICEReturn
Container type for the return parameters of the MIN_PRICE() function.
MIN_TICKCall
Function with signature MIN_TICK() and selector 0xa1634b14.
MIN_TICKReturn
Container type for the return parameters of the MIN_TICK() function.
MaxInputExceeded
Custom error with signature MaxInputExceeded() and selector 0xde9d3c88.
Order
OrderCancelled
Event with signature OrderCancelled(uint128) and selector 0x06ff08ed6b6987bb7df963009d8b54dc03988f4e465c009924929bb010fe03e7.
OrderDoesNotExist
Custom error with signature OrderDoesNotExist() and selector 0x5dcaf2d7.
OrderFilled
Event with signature OrderFilled(uint128,address,address,uint128,bool) and selector 0x16c08f8f2c17b3c8879b3e3cf5efdbdcdfdbd0fcb3890f9d3086f470cd601ddd.
OrderNotStale
Custom error with signature OrderNotStale() and selector 0x68496923.
OrderPlaced
Event with signature OrderPlaced(uint128,address,address,uint128,bool,int16,bool,int16) and selector 0xc200d837816d02c5ee9bf081cba1a32ab1482de7a738b41c0b357186b0b998cd.
Orderbook
PRICE_SCALECall
Function with signature PRICE_SCALE() and selector 0xc33f59d3.
PRICE_SCALEReturn
Container type for the return parameters of the PRICE_SCALE() function.
PairAlreadyExists
Custom error with signature PairAlreadyExists() and selector 0xc9bb25eb.
PairCreated
Event with signature PairCreated(bytes32,address,address) and selector 0xaff90cfc97c741e6d1ffffa62656c16a763f41dc773055d7b0c36950a823babf.
PairDoesNotExist
Custom error with signature PairDoesNotExist() and selector 0xc5fc4bf4.
PriceLevel
TICK_SPACINGCall
Function with signature TICK_SPACING() and selector 0x46ca626b.
TICK_SPACINGReturn
Container type for the return parameters of the TICK_SPACING() function.
TickOutOfBounds
Custom error with signature TickOutOfBounds(int16) and selector 0xb549f7dd.
Unauthorized
Custom error with signature Unauthorized() and selector 0x82b42900.
balanceOfCall
Function with signature balanceOf(address,address) and selector 0xf7888aec.
balanceOfReturn
Container type for the return parameters of the balanceOf(address,address) function.
booksCall
Function with signature books(bytes32) and selector 0x0c0dee70.
booksReturn
Container type for the return parameters of the books(bytes32) function.
cancelCall
Function with signature cancel(uint128) and selector 0x81649d06.
cancelReturn
Container type for the return parameters of the cancel(uint128) function.
cancelStaleOrderCall
Function with signature cancelStaleOrder(uint128) and selector 0x928b0e7f.
cancelStaleOrderReturn
Container type for the return parameters of the cancelStaleOrder(uint128) function.
createPairCall
Function with signature createPair(address) and selector 0x9ccb0744.
createPairReturn
Container type for the return parameters of the createPair(address) function.
getOrderCall
Function with signature getOrder(uint128) and selector 0x117d4128.
getOrderReturn
Container type for the return parameters of the getOrder(uint128) function.
getTickLevelCall
Function with signature getTickLevel(address,int16,bool) and selector 0x949bc662.
getTickLevelReturn
Container type for the return parameters of the getTickLevel(address,int16,bool) function.
nextOrderIdCall
Function with signature nextOrderId() and selector 0x2a58b330.
nextOrderIdReturn
Container type for the return parameters of the nextOrderId() function.
pairKeyCall
Function with signature pairKey(address,address) and selector 0xcd27ca82.
pairKeyReturn
Container type for the return parameters of the pairKey(address,address) function.
placeCall
Function with signature place(address,uint128,bool,int16) and selector 0x63813125.
placeFlipCall
Function with signature placeFlip(address,uint128,bool,int16,int16) and selector 0x922828f1.
placeFlipReturn
Container type for the return parameters of the placeFlip(address,uint128,bool,int16,int16) function.
placeReturn
Container type for the return parameters of the place(address,uint128,bool,int16) function.
priceToTickCall
Function with signature priceToTick(uint32) and selector 0x87b4e352.
priceToTickReturn
Container type for the return parameters of the priceToTick(uint32) function.
quoteSwapExactAmountInCall
Function with signature quoteSwapExactAmountIn(address,address,uint128) and selector 0xe7c98f1a.
quoteSwapExactAmountInReturn
Container type for the return parameters of the quoteSwapExactAmountIn(address,address,uint128) function.
quoteSwapExactAmountOutCall
Function with signature quoteSwapExactAmountOut(address,address,uint128) and selector 0x1576fa0e.
quoteSwapExactAmountOutReturn
Container type for the return parameters of the quoteSwapExactAmountOut(address,address,uint128) function.
swapExactAmountInCall
Function with signature swapExactAmountIn(address,address,uint128,uint128) and selector 0xf8856c0f.
swapExactAmountInReturn
Container type for the return parameters of the swapExactAmountIn(address,address,uint128,uint128) function.
swapExactAmountOutCall
Function with signature swapExactAmountOut(address,address,uint128,uint128) and selector 0xf0122b75.
swapExactAmountOutReturn
Container type for the return parameters of the swapExactAmountOut(address,address,uint128,uint128) function.
tickToPriceCall
Function with signature tickToPrice(int16) and selector 0x269a311d.
tickToPriceReturn
Container type for the return parameters of the tickToPrice(int16) function.
withdrawCall
Function with signature withdraw(address,uint128) and selector 0x08fab167.
withdrawReturn
Container type for the return parameters of the withdraw(address,uint128) function.

Enums§

IStablecoinDEXCalls
Container for all the IStablecoinDEX function calls.
IStablecoinDEXErrors
Container for all the IStablecoinDEX custom errors.
IStablecoinDEXEvents
Container for all the IStablecoinDEX events.

Functions§

new
Creates a new wrapper around an on-chain IStablecoinDEX contract instance.