Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ExchangeUnion/xud into fe…
Browse files Browse the repository at this point in the history
…ature/buy-sell-all-grpc
  • Loading branch information
rsercano committed Sep 29, 2020
2 parents fedfa8f + a583d0e commit 8155d93
Show file tree
Hide file tree
Showing 14 changed files with 354 additions and 320 deletions.
43 changes: 41 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
# [1.1.0](https://github.com/ExchangeUnion/xud/compare/v1.0.0...v1.1.0) (2020-09-28)

Most notable features of this release:
- Xud now automatically requests inbound liquidity for connext currencies (ETH/ERC20) and prevents orders from entering the orderbook until there is sufficient inbound liquidity to cover the order. This "smart collateralization" feature considerably increases the likelihood that the orders can be executed successfully.
- The [DAI](https://etherscan.io/token/0x6b175474e89094c44da98b954eedeac495271d0f) token and `USDT/DAI` trading pair have been enabled by default.

### Bug Fixes

* bold link, mm link ([#1873](https://github.com/ExchangeUnion/xud/issues/1873)) ([54bd9ce](https://github.com/ExchangeUnion/xud/commit/54bd9ce11fc6297319b4c48c7fe9537b3031817b))
* don't activate unsupported pairs with peers ([0fe2d66](https://github.com/ExchangeUnion/xud/commit/0fe2d66d85c2fcc2d559740662977750ddae21e1))
* grpc throws error for addpair/withdraw for wrong argument ([#1844](https://github.com/ExchangeUnion/xud/issues/1844)) ([48a0a33](https://github.com/ExchangeUnion/xud/commit/48a0a33811c2ba52f3791b73f1eef8b8933e09cc))
* handling insufficient balance errors for swap clients ([246889b](https://github.com/ExchangeUnion/xud/commit/246889b89f7f9fa27ba47a31d1a2408d7a4a58a7))
* implemented showing all pairs instead of active ones for listpeers ([206dad0](https://github.com/ExchangeUnion/xud/commit/206dad04b0151e3514f7883e066c361c034defca))
* listorders limit displays first orders instead of last ([#1883](https://github.com/ExchangeUnion/xud/issues/1883)) ([e101e6f](https://github.com/ExchangeUnion/xud/commit/e101e6fb3d0ede2cf6439d10dafa410b533035da))
* order invalidation only be sent to peers with active pair ([#1530](https://github.com/ExchangeUnion/xud/issues/1530)) ([#1890](https://github.com/ExchangeUnion/xud/issues/1890)) ([0dc85bd](https://github.com/ExchangeUnion/xud/commit/0dc85bd83ad0514241e85ae3a958bb01d31594b0))
* propagating nodes on database if initDB true even DB is filled ([#1907](https://github.com/ExchangeUnion/xud/issues/1907)) ([246136e](https://github.com/ExchangeUnion/xud/commit/246136e3d2992711ce5e09d132cf79348bf99e6e))
* xudrpc GetBalanceResponse json_name ([#1909](https://github.com/ExchangeUnion/xud/issues/1909)) ([26f89e6](https://github.com/ExchangeUnion/xud/commit/26f89e6d01cce2ec9d66dc39c0538d142a5af18c))
* **connext:** avoid scientific notation for amount ([#1905](https://github.com/ExchangeUnion/xud/issues/1905)) ([cc1e689](https://github.com/ExchangeUnion/xud/commit/cc1e689181bfe4bafa19112d634a6eb12178cbe9))
* **connext:** display error message for 400 status code ([#1911](https://github.com/ExchangeUnion/xud/issues/1911)) ([b4e1858](https://github.com/ExchangeUnion/xud/commit/b4e1858fd78005b43dcedf4ec5b5425c727639c5))
* **connext:** remove BigInt to avoid precision loss ([#1893](https://github.com/ExchangeUnion/xud/issues/1893)) ([d9ddd1c](https://github.com/ExchangeUnion/xud/commit/d9ddd1cfa16614fc914c61ded2c5e84fd7bd743c))


### Features

* **connext:** reject app install for transfers without status field ([#1863](https://github.com/ExchangeUnion/xud/issues/1863)) ([519aa54](https://github.com/ExchangeUnion/xud/commit/519aa54fa9bfd138d6086f0de0406462a62a57bc))
* **connext:** request collateral for order amount ([75078c0](https://github.com/ExchangeUnion/xud/commit/75078c059bfd752ae47c4530a671bd7a95568975)), closes [#1845](https://github.com/ExchangeUnion/xud/issues/1845)
* **orderbook:** better replace order hold message ([b7fa00a](https://github.com/ExchangeUnion/xud/commit/b7fa00a7afc8ab0fe4e4f495395434e49e00f357))
* **rpc:** show connext status on create/restore node ([#1902](https://github.com/ExchangeUnion/xud/issues/1902)) ([82e16a5](https://github.com/ExchangeUnion/xud/commit/82e16a5e4ed4fa91e481eac638b16eb10e5bb7de))
* **simnet:** add DAI ([#1915](https://github.com/ExchangeUnion/xud/issues/1915)) ([35e85b3](https://github.com/ExchangeUnion/xud/commit/35e85b31bfbfa72430f5db982b7f64f19b346f2a))
* sat_per_byte custom fee for openchannel ([#1832](https://github.com/ExchangeUnion/xud/issues/1832)) ([b56ad98](https://github.com/ExchangeUnion/xud/commit/b56ad98ecb31f94d304a31d3c060693506ae829a)), closes [#1829](https://github.com/ExchangeUnion/xud/issues/1829)
* **connext:** unlock expired transfer apps ([#1857](https://github.com/ExchangeUnion/xud/issues/1857)) ([023434d](https://github.com/ExchangeUnion/xud/commit/023434de1eabe4811986b9156beef7a5a670c047))
* **logging:** order holds on trace level ([#1865](https://github.com/ExchangeUnion/xud/issues/1865)) ([5e3ad04](https://github.com/ExchangeUnion/xud/commit/5e3ad04ed8f2e35cb06479d2172d25bffa002768))
* **orderbook:** log error message on remove order ([#1901](https://github.com/ExchangeUnion/xud/issues/1901)) ([788490f](https://github.com/ExchangeUnion/xud/commit/788490f430691e2e93a28e4aab39aa260213e5b3))
* **p2p:** don't log empty order packets ([#1871](https://github.com/ExchangeUnion/xud/issues/1871)) ([1b6d6d6](https://github.com/ExchangeUnion/xud/commit/1b6d6d6cf522517dbe138b8c7dda908b36f2d1a4))
* **p2p:** increase reconnection delay backoff ([#1870](https://github.com/ExchangeUnion/xud/issues/1870)) ([44af197](https://github.com/ExchangeUnion/xud/commit/44af19722ced03fa2fd89702fea88d07ef51ae08))
* **rpc:** add txid to open/close channel response ([0669a3f](https://github.com/ExchangeUnion/xud/commit/0669a3f41f6a8de9cc6afcf4d8d58c91d18d5b58)), closes [#1860](https://github.com/ExchangeUnion/xud/issues/1860)
* **simnet:** change USDT contract address ([#1912](https://github.com/ExchangeUnion/xud/issues/1912)) ([0a2bdfd](https://github.com/ExchangeUnion/xud/commit/0a2bdfdba3507cbd0bba1a0af6d6f8b8b92c3272))
* **simnet:** upgrade simnet USDT contract address ([#1906](https://github.com/ExchangeUnion/xud/issues/1906)) ([7e5f8ef](https://github.com/ExchangeUnion/xud/commit/7e5f8ef30a1d01a4405757d4359b827ef86cf750))



## [1.0.1](https://github.com/ExchangeUnion/xud/compare/v1.0.0...v1.0.1) (2020-09-08)


Expand Down Expand Up @@ -752,5 +793,3 @@ command line arguments.
* **rpc:** add GetNodeInfo call ([#570](https://github.com/ExchangeUnion/xud/issues/570)) ([1a038a2](https://github.com/ExchangeUnion/xud/commit/1a038a2)), closes [#529](https://github.com/ExchangeUnion/xud/issues/529)
* **swaps:** store swapdeals in database ([#569](https://github.com/ExchangeUnion/xud/pull/569)) ([9a7a629a](https://github.com/ExchangeUnion/xud/commit/9a7a629a9b2c9b8d28d035dc32543aed5e30be47)), closes [#562](https://github.com/ExchangeUnion/xud/issues/562)



2 changes: 1 addition & 1 deletion docs/api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions lib/cli/placeorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const placeOrderBuilder = (argv: Argv, side: OrderSide) => {
const command = side === OrderSide.BUY ? 'buy' : 'sell';
argv.positional('quantity', {
type: 'string',
describe: 'the quantity to trade, `all` trades everything',
describe: 'the quantity to trade, `max` trades everything',
})
.positional('pair_id', {
type: 'string',
Expand Down Expand Up @@ -39,8 +39,8 @@ export const placeOrderBuilder = (argv: Argv, side: OrderSide) => {
describe: 'immediate-or-cancel',
})
.example(`$0 ${command} 5 LTC/BTC .01 1337`, `place a limit order to ${command} 5 LTC @ 0.01 BTC with local order id 1337`)
.example(`$0 ${command} all LTC/BTC .01`, `place a limit order to ${command} all LTC @ 0.01 BTC`)
.example(`$0 ${command} all BTC/USDT mkt`, `place a market order to ${command} all BTC for USDT`)
.example(`$0 ${command} max LTC/BTC .01`, `place a limit order to ${command} max LTC @ 0.01 BTC`)
.example(`$0 ${command} max BTC/USDT mkt`, `place a market order to ${command} max BTC for USDT`)
.example(`$0 ${command} 3 BTC/USDT mkt`, `place a market order to ${command} 3 BTC for USDT`)
.example(`$0 ${command} 1 BTC/USDT market`, `place a market order to ${command} 1 BTC for USDT`);
};
Expand All @@ -50,10 +50,10 @@ export const placeOrderHandler = async (argv: Arguments<any>, side: OrderSide) =

const numericPrice = Number(argv.price);
const priceStr = argv.price.toLowerCase();
const isAll = argv.quantity === 'all';
const isMax = argv.quantity === 'max';

if (isAll) {
request.setAll(true);
if (isMax) {
request.setMax(true);
} else {
if (isNaN(argv.quantity)) {
console.error('quantity is not a valid number');
Expand Down Expand Up @@ -91,7 +91,7 @@ export const placeOrderHandler = async (argv: Arguments<any>, side: OrderSide) =
} else {
const subscription = client.placeOrder(request);
let noMatches = true;
let remainingQuantity = isAll ? 0 : coinsToSats(parseFloat(argv.quantity));
let remainingQuantity = isMax ? 0 : coinsToSats(parseFloat(argv.quantity));
subscription.on('data', (response: PlaceOrderEvent) => {
if (argv.json) {
console.log(JSON.stringify(response.toObject(), undefined, 2));
Expand Down Expand Up @@ -123,7 +123,7 @@ export const placeOrderHandler = async (argv: Arguments<any>, side: OrderSide) =
subscription.on('end', () => {
if (noMatches) {
console.log('no matches found');
} else if (isAll) {
} else if (isMax) {
console.log('no more matches found');
} else if (remainingQuantity > 0) {
console.log(`no more matches found, ${satsToCoinsStr(remainingQuantity)} qty will be discarded`);
Expand Down
19 changes: 13 additions & 6 deletions lib/db/seeds/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,19 @@ const currencies = [
] as db.CurrencyAttributes[];

const pairs = [
{ baseCurrency: 'ETH', quoteCurrency: 'BTC' },
{ baseCurrency: 'LTC', quoteCurrency: 'BTC' },
{ baseCurrency: 'LTC', quoteCurrency: 'USDT' },
{ baseCurrency: 'BTC', quoteCurrency: 'USDT' },
{ baseCurrency: 'BTC', quoteCurrency: 'DAI' },
{ baseCurrency: 'USDT', quoteCurrency: 'DAI' },
// { baseCurrency: 'BTC', quoteCurrency: 'DAI' },
{ baseCurrency: 'BTC', quoteCurrency: 'USDT' },
{ baseCurrency: 'ETH', quoteCurrency: 'BTC' },
// { baseCurrency: 'ETH', quoteCurrency: 'DAI' },
// { baseCurrency: 'ETH', quoteCurrency: 'USDT' },
{ baseCurrency: 'LTC', quoteCurrency: 'BTC' },
// { baseCurrency: 'LTC', quoteCurrency: 'DAI' },
// { baseCurrency: 'LTC', quoteCurrency: 'USDT' },
{ baseCurrency: 'USDT', quoteCurrency: 'DAI' },
// { baseCurrency: 'XUC', quoteCurrency: 'BTC' },
// { baseCurrency: 'XUC', quoteCurrency: 'ETH' },
// { baseCurrency: 'XUC', quoteCurrency: 'DAI' },
// { baseCurrency: 'XUC', quoteCurrency: 'USDT' },
] as db.PairAttributes[];

export {
Expand Down
19 changes: 10 additions & 9 deletions lib/db/seeds/simnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,19 @@ const currencies = [
] as db.CurrencyAttributes[];

const pairs = [
{ baseCurrency: 'ETH', quoteCurrency: 'BTC' },
{ baseCurrency: 'LTC', quoteCurrency: 'BTC' },
{ baseCurrency: 'LTC', quoteCurrency: 'USDT' },
{ baseCurrency: 'BTC', quoteCurrency: 'USDT' },
{ baseCurrency: 'BTC', quoteCurrency: 'DAI' },
{ baseCurrency: 'USDT', quoteCurrency: 'DAI' },
// { baseCurrency: 'XUC', quoteCurrency: 'BTC' },
// { baseCurrency: 'ETH', quoteCurrency: 'USDT' },
// { baseCurrency: 'BTC', quoteCurrency: 'DAI' },
{ baseCurrency: 'BTC', quoteCurrency: 'USDT' },
{ baseCurrency: 'ETH', quoteCurrency: 'BTC' },
// { baseCurrency: 'ETH', quoteCurrency: 'DAI' },
// { baseCurrency: 'ETH', quoteCurrency: 'USDT' },
{ baseCurrency: 'LTC', quoteCurrency: 'BTC' },
// { baseCurrency: 'LTC', quoteCurrency: 'DAI' },
// { baseCurrency: 'XUC', quoteCurrency: 'USDT' },
// { baseCurrency: 'LTC', quoteCurrency: 'USDT' },
{ baseCurrency: 'USDT', quoteCurrency: 'DAI' },
// { baseCurrency: 'XUC', quoteCurrency: 'BTC' },
// { baseCurrency: 'XUC', quoteCurrency: 'ETH' },
// { baseCurrency: 'XUC', quoteCurrency: 'DAI' },
// { baseCurrency: 'XUC', quoteCurrency: 'USDT' },
] as db.PairAttributes[];

export {
Expand Down
15 changes: 9 additions & 6 deletions lib/orderbook/OrderBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,12 +860,15 @@ class OrderBook extends EventEmitter {
throw errors.QUANTITY_ON_HOLD(localId, order.hold);
}

this.removeOwnOrder({
orderId: order.id,
pairId: order.pairId,
quantityToRemove: removableQuantity,
});
remainingQuantityToRemove -= removableQuantity;
if (removableQuantity > 0) {
// we can remove any portion of the order that's not on hold up front
this.removeOwnOrder({
orderId: order.id,
pairId: order.pairId,
quantityToRemove: removableQuantity,
});
remainingQuantityToRemove -= removableQuantity;
}

const failedHandler = (deal: SwapDeal) => {
if (deal.orderId === order.id) {
Expand Down
2 changes: 1 addition & 1 deletion lib/proto/xudrpc.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/proto/xudrpc_pb.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions lib/proto/xudrpc_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 17 additions & 33 deletions lib/service/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,15 +611,29 @@ class Service {
*/
public placeOrder = async (
args: { pairId: string, price: number, quantity?: number, orderId: string, side: number,
replaceOrderId: string, immediateOrCancel: boolean, all?: boolean },
replaceOrderId: string, immediateOrCancel: boolean, max?: boolean },
callback?: (e: ServicePlaceOrderEvent) => void,
) => {
argChecks.PRICE_NON_NEGATIVE(args);
argChecks.PRICE_MAX_DECIMAL_PLACES(args);
argChecks.HAS_PAIR_ID(args);
const { pairId, price, quantity, orderId, side, replaceOrderId, immediateOrCancel, all } = args;
const { pairId, price, quantity, orderId, side, replaceOrderId, immediateOrCancel, max } = args;

const calculatedQuantity = this.calculateQuantity(all, pairId, price, side, quantity);
let calculatedQuantity: number;

if (max) {
if (side === OrderSide.Sell) {
const currency = pairId.split('/')[0];
calculatedQuantity = (await this.getBalance({ currency })).get(currency)?.channelBalance || 0;
} else {
// TODO
calculatedQuantity = 0;
}

this.logger.debug(`max flag is true to place order, calculated quantity from balance is ${calculatedQuantity}`);
} else {
calculatedQuantity = quantity || 0;
}

const order: OwnMarketOrder | OwnLimitOrder = {
pairId,
Expand Down Expand Up @@ -650,36 +664,6 @@ class Service {
await this.orderBook.placeMarketOrder(placeOrderRequest);
}

private calculateQuantity(all: boolean | undefined, pairId: string, price: number, side: number, quantity: number | undefined) {
let calculatedQuantity: number;

if (all) {
calculatedQuantity = 0;
this.listOrders({ pairId, owner: Owner.Both, limit: 0, includeAliases: false }).forEach((orderArrays, _) => {
function iterateOrdersAndAddQuantity(orderArray: ServiceOrder[]) {
for (const order of orderArray) {
if (order.quantity) {
if (!price || order.price === price) {
calculatedQuantity += order.quantity;
}
}
}
}

if (side === OrderSide.Buy) {
iterateOrdersAndAddQuantity(orderArrays.sellArray);
} else if (side === OrderSide.Sell) {
iterateOrdersAndAddQuantity(orderArrays.buyArray);
}
});

this.logger.debug(`all flag is true to place order, calculated quantity from orderbook is ${calculatedQuantity}`);
} else {
calculatedQuantity = quantity || 0;
}
return calculatedQuantity;
}

/** Removes a currency. */
public removeCurrency = async (args: { currency: string }) => {
argChecks.VALID_CURRENCY(args);
Expand Down
8 changes: 4 additions & 4 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "xud",
"minCompatibleVersion": "1.0.0-rc.1",
"version": "1.0.1",
"version": "1.1.0",
"description": "Exchange Union Daemon",
"main": "lib/Xud.js",
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion proto/xudrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ message PlaceOrderRequest {
bool immediate_or_cancel = 7 [json_name = "immediate_or_cancel"];
// Whether to trade all available funds.
// If true, the quantity field is ignored.
bool all = 8 [json_name = "all"];
bool max = 8 [json_name = "max"];
}
message PlaceOrderResponse {
// A list of own orders (or portions thereof) that matched the newly placed order.
Expand Down
Loading

0 comments on commit 8155d93

Please sign in to comment.