import { PublicKey, Keypair } from "@solana/web3.js"; import type { DepositSource, SubmitOrderRequest, TimeInForce, TriggerType } from "../shared"; import { SignedOrder, Order, BidOrderParams, AskOrderParams } from "./types"; import { deriveConditionId } from "./utils"; /** * Generate a random salt for order uniqueness. * Capped to Number.MAX_SAFE_INTEGER (2^53 - 1) so the value round-trips * through JSON without precision loss. */ export declare function generateSalt(): bigint; /** * Hash an order using keccak256 * Layout (169 bytes - order without signature): * nonce (8) || salt (8) || maker (32) || market (32) || baseMint (32) || quoteMint (32) || * side (1) || amountIn (8) || amountOut (8) || expiration (8) * * @returns 32-byte keccak256 hash */ export declare function hashOrder(order: SignedOrder): Buffer; /** * Get the hex-encoded hash of an order */ export declare function hashOrderHex(order: SignedOrder): string; /** * Get the message to sign for an order (the order hash) */ export declare function getOrderMessage(order: SignedOrder): Buffer; /** * Sign an order with a Keypair. * Signs the hex-encoded keccak hash (64-char ASCII string) for cross-compatibility with Rust. * Returns 64-byte Ed25519 signature. */ export declare function signOrder(order: SignedOrder, signer: Keypair): Buffer; /** * Sign an order and return a new order with the signature attached */ export declare function signOrderFull(order: Omit, signer: Keypair): SignedOrder; /** * Verify an order's signature. * Verifies against the hex-encoded keccak hash. */ export declare function verifyOrderSignature(order: SignedOrder): boolean; /** * Serialize a signed order to bytes (233 bytes) * * Layout: * [0..8] nonce (u64) * [8..16] salt (u64) * [16..48] maker (Pubkey) * [48..80] market (Pubkey) * [80..112] baseMint (Pubkey) * [112..144] quoteMint (Pubkey) * [144] side (u8) * [145..153] amountIn (u64) * [153..161] amountOut (u64) * [161..169] expiration (i64) * [169..233] signature (64 bytes) */ export declare function serializeSignedOrder(order: SignedOrder): Buffer; /** * Deserialize a signed order from bytes */ export declare function deserializeSignedOrder(data: Buffer): SignedOrder; /** * Serialize a compact order to bytes (37 bytes) * * Layout: * [0..4] nonce (u32) * [4..12] salt (u64) * [12] side (u8) * [13..21] amountIn (u64) * [21..29] amountOut (u64) * [29..37] expiration (i64) */ export declare function serializeOrder(order: Order): Buffer; /** * Deserialize a compact order from bytes */ export declare function deserializeOrder(data: Buffer): Order; /** * Convert a SignedOrder to a compact Order (drop maker) */ export declare function signedOrderToOrder(order: SignedOrder): Order; /** * Expand a compact Order back to a full SignedOrder using provided pubkeys and signature. * Rust equivalent: Order::to_signed() */ export declare function orderToSigned(order: Order, maker: PublicKey, market: PublicKey, baseMint: PublicKey, quoteMint: PublicKey, signature: Buffer): SignedOrder; /** * Create a BID order (buyer wants base tokens, pays with quote tokens) */ export declare function createBidOrder(params: BidOrderParams): Omit; /** * Create an ASK order (seller offers base tokens, receives quote tokens) */ export declare function createAskOrder(params: AskOrderParams): Omit; /** * Create and sign a BID order in one step */ export declare function createSignedBidOrder(params: BidOrderParams, signer: Keypair): SignedOrder; /** * Create and sign an ASK order in one step */ export declare function createSignedAskOrder(params: AskOrderParams, signer: Keypair): SignedOrder; /** * Check if an order has expired */ export declare function isOrderExpired(order: SignedOrder | Order, currentTime?: bigint): boolean; /** * Validate order crossing (orders are compatible for matching) */ export declare function ordersCanCross(buyOrder: SignedOrder, sellOrder: SignedOrder): boolean; /** * Calculate the fill amounts for a trade */ export declare function calculateTakerFill(makerOrder: SignedOrder, makerFillAmount: bigint): bigint; /** * Get signature as hex string (128 chars) */ export declare function signatureHex(order: SignedOrder): string; /** * Check if a signed order has a non-zero signature */ export declare function isSigned(order: SignedOrder): boolean; /** * Apply an external base58-encoded signature to an unsigned order. * Rust equivalent: OrderPayload::apply_signature() */ export declare function applySignature(order: Omit, signatureBs58: string): SignedOrder; /** * Derive orderbook ID from base and quote token addresses. * Delegates to the canonical implementation in shared/types. */ export { deriveOrderbookId } from "../shared/types"; /** * Build the message bytes for cancelling an order. * The message is the order hash hex string as UTF-8 bytes (same protocol as order signing). */ export declare function cancelOrderMessage(orderHash: string): Uint8Array; /** * Build the message bytes for cancelling a trigger order. * The message is the trigger order ID as UTF-8 bytes. */ export declare function cancelTriggerOrderMessage(triggerOrderId: string): Uint8Array; /** * Sign a cancel order request. * Returns the signature as a 128-char hex string. */ export declare function signCancelOrder(orderHash: string, signer: Keypair): string; /** * Sign a cancel trigger-order request. * Returns the signature as a 128-char hex string. */ export declare function signCancelTriggerOrder(triggerOrderId: string, signer: Keypair): string; /** * Build the message string for cancelling all orders. * Format: "cancel_all:{pubkey}:{orderbook_id}:{timestamp}:{salt}" */ export declare function cancelAllMessage(userPubkey: string, orderbookId: string, timestamp: number, salt: string): string; /** * Generate a random salt for cancel-all replay protection. * Returns an RFC 4122 UUID v4 string. */ export declare function generateCancelAllSalt(): string; /** * Sign a cancel-all orders request. * Returns the signature as a 128-char hex string. */ export declare function signCancelAll(userPubkey: string, orderbookId: string, timestamp: number, salt: string, signer: Keypair): string; /** * Convert a SignedOrder to a SubmitOrderRequest-compatible object */ export interface SubmitRequestOptions { timeInForce?: TimeInForce; triggerPrice?: number; triggerType?: TriggerType; depositSource?: DepositSource; } export declare function toSubmitRequest(order: SignedOrder, orderbookId: string, options?: SubmitRequestOptions): SubmitOrderRequest; export declare const is_order_expired: typeof isOrderExpired; export declare const orders_can_cross: typeof ordersCanCross; export declare const calculate_taker_fill: typeof calculateTakerFill; export declare const cancel_order_message: typeof cancelOrderMessage; export declare const cancel_trigger_order_message: typeof cancelTriggerOrderMessage; export declare const cancel_all_message: typeof cancelAllMessage; export declare const generate_cancel_all_salt: typeof generateCancelAllSalt; export declare const derive_condition_id: typeof deriveConditionId; export declare const apply_signature: typeof applySignature; export declare const order_to_signed: typeof orderToSigned; //# sourceMappingURL=orders.d.ts.map