UNPKG

@oax/client

Version:
146 lines (145 loc) 5.07 kB
import { BigNumber } from 'bignumber.js'; import { ILot } from '@oax/common/types/BasicTypes'; import { IOrder, IOrderBook, ITradeExternal, IExchangeBalances } from '@oax/common/types/ExchangeTypes'; import { L2Client } from '../operator/L2Client'; import { HTTPClient } from '../common/HTTPClient'; import { AssetRegistry } from '@oax/common/AssetRegistry'; import { Identity } from '@oax/common/identity/Identity'; declare type ClientConfig = { transport?: HTTPClient; mediatorAddress?: string; nonce?: string; fee?: ILot; }; export declare class ExchangeClient { readonly assetRegistry: AssetRegistry; readonly config: ClientConfig; private identity; private hubClient; private transport; private _isConnected; /** * Constructor * * @param identity Identity used by the operator for signing * @param hubClient L2Client to communicate with the operator layer * @param assetRegistry AssetRegistry, mapping asset symbols to Ethereum addresses * @param config Configuration object including mediator address, fees, etc */ constructor(identity: Identity, hubClient: L2Client, assetRegistry: AssetRegistry, config: ClientConfig); /** * Joins an OAX hub * * Each wallet address must join the operator at least once * * @signing_required */ join(): Promise<void>; /** * Leaves an OAX hub * * Gracefully leaves an OAX hub, doing the necessary cleanup. */ leave(): Promise<void>; /** * Get the order book for a symbol asset pair * * @param symbol Asset pair (e.g. OAX/WETH) */ fetchOrderBook(symbol: string): Promise<IOrderBook>; /** * Trade history for a symbol/asset pair * * @param symbol Asset pair (e.g. OAX/WETH) */ fetchTrades(symbol: string): Promise<ITradeExternal[]>; /** * Get all balances for each asset */ fetchBalances(): Promise<IExchangeBalances>; /** * Create order * * @param symbol Asset pair (e.g. OAX/WETH) * @param orderType Must be 'limit' * @param side Must be 'buy' or 'sell' * @param amount Amount to buy or sell (in Ether units) * @param price Limit price for the order * @returns The ID for the newly created order * * @signing_required */ createOrder(symbol: string, orderType: 'limit', side: 'buy' | 'sell', amount: BigNumber, price: BigNumber): Promise<string>; /** * Cancels an active order * @param id ID of the order to cancel */ cancelOrder(id: string): Promise<void>; /** * Get order details * @param id ID of the order to fetch */ fetchOrder(id: string): Promise<IOrder | null>; /** * Get all user orders */ fetchOrders(): Promise<IOrder[]>; /** * Deposit asset * * @param asset Address of the token for the deposit * @param amount Quantity of tokens to be deposited * @param approve Whether to call ERC20.approve before doing the deposit * * @onchain * @signing_required */ deposit(asset: string, amount: BigNumber, approve: boolean): Promise<void>; /** * Non-collaborative asset withdrawal request * * In case if the hub is unresponsive, the withdrawal request can be * submitted directly to the hub smart contract. * * A withdrawal confirmation window must pass * (approximately X hours currently) before the user can perform the actual * withdrawal by calling on-chain withdrawal. * * Note: Confirmation of withdrawal handled by hubClient on new Quarter. * * @param asset Address of the token for the withdrawal * @param amount Quantity of tokens to be withdrawn * @param convertToWei True if the amount needs to be converted to wei * * @onchain * @signing_required */ requestWithdrawalConvert(asset: string, amount: BigNumber, convertToWei: boolean): Promise<void>; /** * Initiates a withdrawal with wei conversion * @param address Address of the token for the withdrawal * @param amount Quantity of tokens (will be converted to wei) */ requestWithdrawalWithWeiConversion(asset: string, amount: BigNumber): Promise<void>; /** * Initiates a withdrawal without wei conversion * @param asset Address of the token for the withdrawal * @param amount Quantity of tokens to withdraw (in wei) */ requestWithdrawal(asset: string, amount: BigNumber): Promise<void>; /** * Confirms an elligible withdrawal * * The withdrawal must have been initiated with requestWithdrawal and * additional conditions must be met for it to be elligible for confirmation. * * @param asset Address of the asset to confirm for */ confirmWithdrawal(asset: string): Promise<void>; /** * Returns whether the client is currently connected */ readonly isConnected: boolean; } export declare function orderWeiToEther(order: IOrder): IOrder; export {};