Module IStablecoinExchange

Module IStablecoinExchange 

Expand description

StablecoinExchange interface for managing orderbook based trading of stablecoins.

The StablecoinExchange 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 IStablecoinExchange {
    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 executeBlock() 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 activeOrderId() external view returns (uint128);
    function pendingOrderId() 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_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);
    event FlipOrderPlaced(uint128 indexed orderId, address indexed maker, address indexed token, uint128 amount, bool isBid, int16 tick, int16 flipTick);
    event OrderFilled(uint128 indexed orderId, address indexed maker, uint128 amountFilled, bool partialFill);
    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();
}

Modules§

abi
Contains dynamic ABI definitions for this contract.

Structs§

BelowMinimumOrderSize
Custom error with signature BelowMinimumOrderSize(uint128) and selector 0x46628371.
FlipOrderPlaced
Event with signature FlipOrderPlaced(uint128,address,address,uint128,bool,int16,int16) and selector 0x5727f9d8eb7649f74ed404ff89e7ac2c45cf670e0c514406c3710a14afe7ed2d.
IStablecoinExchangeInstance
A IStablecoinExchange 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_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_0
Pre-Allegretto: OrderFilled event without taker parameter Event with signature OrderFilled(uint128,address,uint128,bool) and selector 0xaf763a65804243a7f09caf51674a63107bb4027ac067b8b509592d2197f1b94d.
OrderFilled_1
Post-Allegretto: OrderFilled event with taker parameter Event with signature OrderFilled(uint128,address,address,uint128,bool) and selector 0x16c08f8f2c17b3c8879b3e3cf5efdbdcdfdbd0fcb3890f9d3086f470cd601ddd.
OrderPlaced
Event with signature OrderPlaced(uint128,address,address,uint128,bool,int16) and selector 0x19e5b84a2d96d99dc8fe8825094f1aac0190b17c619c4de86d9b81b0cebb98fc.
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.
activeOrderIdCall
Function with signature activeOrderId() and selector 0x127ac5f1.
activeOrderIdReturn
Container type for the return parameters of the activeOrderId() function.
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.
createPairCall
Function with signature createPair(address) and selector 0x9ccb0744.
createPairReturn
Container type for the return parameters of the createPair(address) function.
executeBlockCall
Function with signature executeBlock() and selector 0xb306cc70.
executeBlockReturn
Container type for the return parameters of the executeBlock() 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.
pairKeyCall
Function with signature pairKey(address,address) and selector 0xcd27ca82.
pairKeyReturn
Container type for the return parameters of the pairKey(address,address) function.
pendingOrderIdCall
Function with signature pendingOrderId() and selector 0x8bd4d3be.
pendingOrderIdReturn
Container type for the return parameters of the pendingOrderId() 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§

IStablecoinExchangeCalls
Container for all the IStablecoinExchange function calls.
IStablecoinExchangeErrors
Container for all the IStablecoinExchange custom errors.
IStablecoinExchangeEvents
Container for all the IStablecoinExchange events.

Functions§

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