UNPKG

@fleupold/dex-contracts

Version:

Contracts for dFusion multi-token batch auction exchange

49 lines (48 loc) 1.7 kB
/** * encoding.js * * This NPM module provide encoding and decoding utilities for interacting with * dFusion smart contracts where manual byte encoding was needed because of * solidity ABI limitations. */ import BN from "bn.js"; export interface Order<T = BN> { user: string; sellTokenBalance: T; buyToken: number; sellToken: number; validFrom: number; validUntil: number; priceNumerator: T; priceDenominator: T; remainingAmount: T; } export interface IndexedOrder<T = BN> extends Order<T> { orderId: number; } /** * Decodes a byte-encoded variable length array of orders. This can be used to * decode the result of `BatchExchange.getEncodedUserOrders` and * `BatchExchange.getEncodedOrders`. */ export declare function decodeOrders(bytes: string | null): Order<BN>[]; /** * Decodes a byte-encoded variable length array of orders and their indices. * This can be used to decode the result of `BatchExchangeViewer.getOpenOrderBook` and * `BatchExchangeViewer.getFinalizedOrderBook`. */ export declare function decodeIndexedOrders(bytes: string | null): IndexedOrder<BN>[]; declare type EncodableInt = string | { toString(base: number): string; }; /** * Encodes an array of orders into a `Uint8Array` of bytes. This uses the same * format as `BatchExchange.getEncodedOrders`. */ export declare function encodeOrders<T extends EncodableInt>(orders: Order<T>[]): Uint8Array; /** * Encodes an array of indexed orders into a `Uint8Array` of bytes. This uses * the same format as `BatchExchangeViewer.getFilteredOrderBook`. */ export declare function encodeIndexedOrders<T extends EncodableInt>(orders: IndexedOrder<T>[]): Uint8Array; export {};