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§
- Below
Minimum Order Size - Custom error with signature
BelowMinimumOrderSize(uint128)and selector0x46628371. - Flip
Order Placed - Event with signature
FlipOrderPlaced(uint128,address,address,uint128,bool,int16,int16)and selector0x5727f9d8eb7649f74ed404ff89e7ac2c45cf670e0c514406c3710a14afe7ed2d. - IStablecoin
Exchange Instance - A
IStablecoinExchangeinstance. - Identical
Tokens - Custom error with signature
IdenticalTokens()and selector0x5c6d7b73. - Insufficient
Balance - Custom error with signature
InsufficientBalance()and selector0xf4d678b8. - Insufficient
Liquidity - Custom error with signature
InsufficientLiquidity()and selector0xbb55fd27. - Insufficient
Output - Custom error with signature
InsufficientOutput()and selector0xbb2875c3. - Invalid
Base Token - Custom error with signature
InvalidBaseToken()and selector0x0e442a4a. - Invalid
Flip Tick - Custom error with signature
InvalidFlipTick()and selector0xf88aeb80. - Invalid
Tick - Custom error with signature
InvalidTick()and selector0xce8ef7fc. - Invalid
Token - Custom error with signature
InvalidToken()and selector0xc1ab6dc1. - MAX_
PRICE Call - Function with signature
MAX_PRICE()and selector0x01c11d96. - MAX_
PRICE Return - Container type for the return parameters of the
MAX_PRICE()function. - MAX_
TICK Call - Function with signature
MAX_TICK()and selector0x6882a888. - MAX_
TICK Return - Container type for the return parameters of the
MAX_TICK()function. - MIN_
PRICE Call - Function with signature
MIN_PRICE()and selector0xad9f20a6. - MIN_
PRICE Return - Container type for the return parameters of the
MIN_PRICE()function. - MIN_
TICK Call - Function with signature
MIN_TICK()and selector0xa1634b14. - MIN_
TICK Return - Container type for the return parameters of the
MIN_TICK()function. - MaxInput
Exceeded - Custom error with signature
MaxInputExceeded()and selector0xde9d3c88. - Order
- Order
Cancelled - Event with signature
OrderCancelled(uint128)and selector0x06ff08ed6b6987bb7df963009d8b54dc03988f4e465c009924929bb010fe03e7. - Order
Does NotExist - Custom error with signature
OrderDoesNotExist()and selector0x5dcaf2d7. - Order
Filled_ 0 - Pre-Allegretto: OrderFilled event without taker parameter
Event with signature
OrderFilled(uint128,address,uint128,bool)and selector0xaf763a65804243a7f09caf51674a63107bb4027ac067b8b509592d2197f1b94d. - Order
Filled_ 1 - Post-Allegretto: OrderFilled event with taker parameter
Event with signature
OrderFilled(uint128,address,address,uint128,bool)and selector0x16c08f8f2c17b3c8879b3e3cf5efdbdcdfdbd0fcb3890f9d3086f470cd601ddd. - Order
Placed - Event with signature
OrderPlaced(uint128,address,address,uint128,bool,int16)and selector0x19e5b84a2d96d99dc8fe8825094f1aac0190b17c619c4de86d9b81b0cebb98fc. - Orderbook
- PRICE_
SCALE Call - Function with signature
PRICE_SCALE()and selector0xc33f59d3. - PRICE_
SCALE Return - Container type for the return parameters of the
PRICE_SCALE()function. - Pair
Already Exists - Custom error with signature
PairAlreadyExists()and selector0xc9bb25eb. - Pair
Created - Event with signature
PairCreated(bytes32,address,address)and selector0xaff90cfc97c741e6d1ffffa62656c16a763f41dc773055d7b0c36950a823babf. - Pair
Does NotExist - Custom error with signature
PairDoesNotExist()and selector0xc5fc4bf4. - Price
Level - TICK_
SPACING Call - Function with signature
TICK_SPACING()and selector0x46ca626b. - TICK_
SPACING Return - Container type for the return parameters of the
TICK_SPACING()function. - Tick
OutOf Bounds - Custom error with signature
TickOutOfBounds(int16)and selector0xb549f7dd. - Unauthorized
- Custom error with signature
Unauthorized()and selector0x82b42900. - active
Order IdCall - Function with signature
activeOrderId()and selector0x127ac5f1. - active
Order IdReturn - Container type for the return parameters of the
activeOrderId()function. - balance
OfCall - Function with signature
balanceOf(address,address)and selector0xf7888aec. - balance
OfReturn - Container type for the return parameters of the
balanceOf(address,address)function. - books
Call - Function with signature
books(bytes32)and selector0x0c0dee70. - books
Return - Container type for the return parameters of the
books(bytes32)function. - cancel
Call - Function with signature
cancel(uint128)and selector0x81649d06. - cancel
Return - Container type for the return parameters of the
cancel(uint128)function. - create
Pair Call - Function with signature
createPair(address)and selector0x9ccb0744. - create
Pair Return - Container type for the return parameters of the
createPair(address)function. - execute
Block Call - Function with signature
executeBlock()and selector0xb306cc70. - execute
Block Return - Container type for the return parameters of the
executeBlock()function. - getOrder
Call - Function with signature
getOrder(uint128)and selector0x117d4128. - getOrder
Return - Container type for the return parameters of the
getOrder(uint128)function. - getTick
Level Call - Function with signature
getTickLevel(address,int16,bool)and selector0x949bc662. - getTick
Level Return - Container type for the return parameters of the
getTickLevel(address,int16,bool)function. - pair
KeyCall - Function with signature
pairKey(address,address)and selector0xcd27ca82. - pair
KeyReturn - Container type for the return parameters of the
pairKey(address,address)function. - pending
Order IdCall - Function with signature
pendingOrderId()and selector0x8bd4d3be. - pending
Order IdReturn - Container type for the return parameters of the
pendingOrderId()function. - place
Call - Function with signature
place(address,uint128,bool,int16)and selector0x63813125. - place
Flip Call - Function with signature
placeFlip(address,uint128,bool,int16,int16)and selector0x922828f1. - place
Flip Return - Container type for the return parameters of the
placeFlip(address,uint128,bool,int16,int16)function. - place
Return - Container type for the return parameters of the
place(address,uint128,bool,int16)function. - price
ToTick Call - Function with signature
priceToTick(uint32)and selector0x87b4e352. - price
ToTick Return - Container type for the return parameters of the
priceToTick(uint32)function. - quote
Swap Exact Amount InCall - Function with signature
quoteSwapExactAmountIn(address,address,uint128)and selector0xe7c98f1a. - quote
Swap Exact Amount InReturn - Container type for the return parameters of the
quoteSwapExactAmountIn(address,address,uint128)function. - quote
Swap Exact Amount OutCall - Function with signature
quoteSwapExactAmountOut(address,address,uint128)and selector0x1576fa0e. - quote
Swap Exact Amount OutReturn - Container type for the return parameters of the
quoteSwapExactAmountOut(address,address,uint128)function. - swap
Exact Amount InCall - Function with signature
swapExactAmountIn(address,address,uint128,uint128)and selector0xf8856c0f. - swap
Exact Amount InReturn - Container type for the return parameters of the
swapExactAmountIn(address,address,uint128,uint128)function. - swap
Exact Amount OutCall - Function with signature
swapExactAmountOut(address,address,uint128,uint128)and selector0xf0122b75. - swap
Exact Amount OutReturn - Container type for the return parameters of the
swapExactAmountOut(address,address,uint128,uint128)function. - tick
ToPrice Call - Function with signature
tickToPrice(int16)and selector0x269a311d. - tick
ToPrice Return - Container type for the return parameters of the
tickToPrice(int16)function. - withdraw
Call - Function with signature
withdraw(address,uint128)and selector0x08fab167. - withdraw
Return - Container type for the return parameters of the
withdraw(address,uint128)function.
Enums§
- IStablecoin
Exchange Calls - Container for all the
IStablecoinExchangefunction calls. - IStablecoin
Exchange Errors - Container for all the
IStablecoinExchangecustom errors. - IStablecoin
Exchange Events - Container for all the
IStablecoinExchangeevents.
Functions§
- new
- Creates a new wrapper around an on-chain
IStablecoinExchangecontract instance.