xud
Version:
Exchange Union Daemon
225 lines (224 loc) • 7.56 kB
TypeScript
/// <reference types="node" />
import { EventEmitter } from 'events';
import { Observable } from 'rxjs';
import { ProvidePreimageEvent, TransferReceivedEvent } from '../connextclient/types';
import { Owner, SwapClientType } from '../constants/enums';
import { Level } from '../Logger';
import { Currency, OrderPortion } from '../orderbook/types';
import { ResolveRequest, SwapAccepted, SwapFailure, SwapSuccess, TradingLimits } from '../swaps/types';
import { ServiceComponents, ServiceOrder, ServiceOrderSidesArrays, ServicePlaceOrderEvent, ServiceTrade, XudInfo } from './types';
interface Service {
on(event: 'logLevel', listener: (level: Level) => void): this;
emit(event: 'logLevel', level: Level): boolean;
}
/** A class containing the available RPC methods for an unlocked, running instance of xud. */
declare class Service extends EventEmitter {
shutdown: () => void;
/** Whether the service is disabled - in other words whether xud is locked. */
disabled: boolean;
private orderBook;
private swapClientManager;
private pool;
private version;
private swaps;
private logger;
private nodekey;
/** Create an instance of available RPC methods and bind all exposed functions. */
constructor(components: ServiceComponents);
/** Adds a currency. */
addCurrency: (args: {
currency: string;
swapClient: SwapClientType | number;
decimalPlaces: number;
tokenAddress?: string;
}) => Promise<void>;
/** Adds a trading pair. */
addPair: (args: {
baseCurrency: string;
quoteCurrency: string;
}) => Promise<void>;
removeOrder: (args: {
orderId: string;
quantity?: number;
}) => {
removedQuantity: number;
onHoldQuantity: number;
pairId: string;
remainingQuantity: number;
};
removeAllOrders: () => Promise<{
removedOrderLocalIds: string[];
onHoldOrderLocalIds: string[];
}>;
/** Gets the total balance for one or all currencies. */
getBalance: (args: {
currency: string;
}) => Promise<Map<string, {
channelBalance: number;
pendingChannelBalance: number;
inactiveChannelBalance: number;
walletBalance: number;
unconfirmedWalletBalance: number;
totalBalance: number;
}>>;
/** Gets the trading limits (max outbound and inbound capacities for a distinct channel) for one or all currencies. */
tradingLimits: (args: {
currency: string;
}) => Promise<Map<string, TradingLimits>>;
/**
* Connect to an XU node on a given node uri.
*/
connect: (args: {
nodeUri: string;
retryConnecting: boolean;
}) => Promise<void>;
walletDeposit: (args: {
currency: string;
}) => Promise<string>;
walletWithdraw: (args: {
currency: string;
amount: number;
destination: string;
all: boolean;
fee: number;
}) => Promise<string>;
closeChannel: (args: {
nodeIdentifier: string;
currency: string;
force: boolean;
destination: string;
amount: number;
fee?: number;
}) => Promise<string[]>;
openChannel: (args: {
nodeIdentifier: string;
amount: number;
currency: string;
pushAmount?: number;
fee?: number;
}) => Promise<string>;
ban: (args: {
nodeIdentifier: string;
}) => Promise<void>;
unban: (args: {
nodeIdentifier: string;
reconnect: boolean;
}) => Promise<void>;
executeSwap: (args: {
orderId: string;
pairId: string;
peerPubKey: string;
quantity: number;
}) => Promise<SwapSuccess>;
/**
* Gets information about a specified node.
*/
getMnemonic: () => Promise<string[]>;
/**
* Gets Ethereum mnemonic
*/
getETHMnemonic: () => Promise<string>;
/**
* Gets information about a specified node.
*/
getNodeInfo: (args: {
nodeIdentifier: string;
}) => Promise<{
reputationScore: import("../constants/enums").ReputationEvent;
banned?: boolean | undefined;
}>;
/**
* Get general information about this Exchange Union node.
*/
getInfo: () => Promise<XudInfo>;
setLogLevel: (args: {
logLevel: number;
}) => Promise<void>;
private toServiceOrder;
/**
* Get a map between pair ids and its orders from the order book.
*/
listOrders: (args: {
pairId: string;
owner: Owner | number;
limit: number;
includeAliases: boolean;
}) => Map<string, ServiceOrderSidesArrays>;
/**
* Get the list of the order book's supported currencies
* @returns A list of supported currency ticker symbols
*/
listCurrencies: () => Map<string, Currency>;
/**
* Get the list of the order book's supported pairs.
* @returns A list of supported trading pair tickers
*/
listPairs: () => string[];
/**
* Get information about currently connected peers.
* @returns A list of connected peers with key information for each peer
*/
listPeers: () => import("../p2p/Peer").PeerInfo[];
/**
* Gets trading history.
*/
tradeHistory: (args: {
limit: number;
}) => Promise<ServiceTrade[]>;
/**
* Add an order to the order book.
* If price is zero or unspecified a market order will get added.
*/
placeOrder: (args: {
pairId: string;
price: number;
quantity: number;
orderId: string;
side: number;
replaceOrderId: string;
immediateOrCancel: boolean;
}, callback?: ((e: ServicePlaceOrderEvent) => void) | undefined) => Promise<import("../orderbook/types").PlaceOrderResult>;
/** Removes a currency. */
removeCurrency: (args: {
currency: string;
}) => Promise<void>;
/** Removes a trading pair. */
removePair: (args: {
pairId: string;
}) => Promise<void>;
/** Discover nodes from a specific peer and apply new connections */
discoverNodes: (args: {
nodeIdentifier: string;
}) => Promise<number>;
subscribeOrders: (args: {
existing: boolean;
}, callback: (order?: ServiceOrder | undefined, orderRemoval?: OrderPortion | undefined) => void, cancelled$: Observable<void>) => void;
subscribeSwaps: (args: {
includeTaker: boolean;
}, callback: (swapSuccess: SwapSuccess) => void, cancelled$: Observable<void>) => Promise<void>;
subscribeSwapsAccepted: (_args: {}, callback: (swapAccepted: SwapAccepted) => void, cancelled$: Observable<void>) => Promise<void>;
subscribeSwapFailures: (args: {
includeTaker: boolean;
}, callback: (swapFailure: SwapFailure) => void, cancelled$: Observable<void>) => Promise<void>;
/**
* Resolves a hash to its preimage.
*/
resolveHash: (request: ResolveRequest) => Promise<string>;
/**
* Provides preimage for a hash.
*/
providePreimage: (event: ProvidePreimageEvent) => Promise<void>;
/**
* Notifies Connext client that a transfer has been received.
*/
transferReceived: (event: TransferReceivedEvent) => Promise<void>;
/**
* Notifies Connext client that a deposit has been confirmed.
*/
depositConfirmed: (hash: string) => void;
changePassword: ({ newPassword, oldPassword }: {
newPassword: string;
oldPassword: string;
}) => Promise<void>;
}
export default Service;