balanceofsatoshis 19.4.0 → 19.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Versions
2
2
 
3
+ ## 19.4.2
4
+
5
+ - `rebalance`: Correct for new fee buffer on close-to-balance rebalances
6
+
3
7
  ## 19.4.0
4
8
 
5
9
  - `create-fanout-group`, `join-fanout-group`: add commands for collab fanout
@@ -19,6 +19,7 @@ const {getIcons} = require('./../display');
19
19
  const {sortBy} = require('./../arrays');
20
20
 
21
21
  const bufFromHex = hex => Buffer.from(hex, 'hex');
22
+ const channelReserve = n => n.local_reserve || Math.floor(n.capacity * 0.01);
22
23
  const cltvBuffer = 3;
23
24
  const dateBytesLength = 8;
24
25
  const datePrecisionLength = 6;
@@ -41,7 +42,6 @@ const nodeKeyFamily = 6;
41
42
  const preimageByteLength = 32;
42
43
  const {now} = Date;
43
44
  const rate = n => n.commit_transaction_fee / (n.commit_transaction_weight / 4);
44
- const reserveRatio = 0.01;
45
45
  const signatureType = '34349337';
46
46
  const tokAsMtok = tokens => (BigInt(tokens || 0) * BigInt(1e3)).toString();
47
47
 
@@ -331,7 +331,7 @@ module.exports = (args, cbk) => {
331
331
  }],
332
332
 
333
333
  // Outgoing channel id
334
- outgoingChannelId: ['getChannels', 'to', ({getChannels, to}, cbk) => {
334
+ outId: ['getChannels', 'to', ({getChannels, to}, cbk) => {
335
335
  if (!getChannels) {
336
336
  return cbk();
337
337
  }
@@ -350,7 +350,7 @@ module.exports = (args, cbk) => {
350
350
 
351
351
  const withBalance = withPeer.filter(n => {
352
352
  const fees = n.commit_transaction_fee + (htlcOutputSize * rate(n));
353
- const reserve = n.local_reserve || floor(n.capacity * reserveRatio);
353
+ const reserve = channelReserve(n);
354
354
 
355
355
  return n.local_balance - tokens > reserve + feeBuffer(fees);
356
356
  });
@@ -363,7 +363,15 @@ module.exports = (args, cbk) => {
363
363
 
364
364
  const [channel] = sortBy({attribute, array: withBalance}).sorted;
365
365
 
366
- return cbk(null, channel.id);
366
+ const bufferFees = htlcOutputSize * rate(channel);
367
+ const reserve = channelReserve(channel);
368
+
369
+ const fees = channel.commit_transaction_fee + bufferFees;
370
+ const spendable = channel.local_balance - reserve;
371
+
372
+ const maxPayable = floor(spendable - feeBuffer(fees));
373
+
374
+ return cbk(null, {id: channel.id, max: maxPayable || args.find_max});
367
375
  }],
368
376
 
369
377
  // Log sending towards destination
@@ -390,9 +398,9 @@ module.exports = (args, cbk) => {
390
398
  'getIcons',
391
399
  'getIdentity',
392
400
  'messages',
393
- 'outgoingChannelId',
401
+ 'outId',
394
402
  'to',
395
- ({getFeatures, getIcons, messages, outgoingChannelId, to}, cbk) =>
403
+ ({getFeatures, getIcons, messages, outId, to}, cbk) =>
396
404
  {
397
405
  return executeProbe({
398
406
  messages,
@@ -407,7 +415,7 @@ module.exports = (args, cbk) => {
407
415
  max_fee: args.max_fee,
408
416
  max_fee_mtokens: args.max_fee_mtokens,
409
417
  mtokens: !BigInt(to.mtokens) ? tokAsMtok(defaultTokens) : to.mtokens,
410
- outgoing_channel: outgoingChannelId,
418
+ outgoing_channel: !!outId ? outId.id : undefined,
411
419
  payment: to.payment,
412
420
  routes: to.routes,
413
421
  tagged: !!getIcons ? getIcons.nodes : undefined,
@@ -418,7 +426,7 @@ module.exports = (args, cbk) => {
418
426
  }],
419
427
 
420
428
  // Get maximum value of the successful route
421
- getMax: ['probe', 'to', ({probe, to}, cbk) => {
429
+ getMax: ['outId', 'probe', 'to', ({outId, probe, to}, cbk) => {
422
430
  if (!args.find_max || !probe.route) {
423
431
  return cbk(null, {});
424
432
  }
@@ -445,7 +453,7 @@ module.exports = (args, cbk) => {
445
453
  // Found a successful high value route
446
454
  sub.once('success', ({maximum}) => {
447
455
  return cbk(null, {
448
- maximum: min(args.find_max, max(maximum, probe.route.tokens)),
456
+ maximum: min(outId.max, max(maximum, probe.route.tokens)),
449
457
  });
450
458
  });
451
459
 
package/package.json CHANGED
@@ -83,5 +83,5 @@
83
83
  "postpublish": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t alexbosworth/balanceofsatoshis -t alexbosworth/balanceofsatoshis:$npm_package_version --push .",
84
84
  "test": "npx nyc@17.0.0 node --experimental-test-coverage --test test/arrays/*.js test/balances/*.js test/chain/*.js test/display/*.js test/encryption/*.js test/lnd/*.js test/network/*.js test/nodes/*.js test/peers/*.js test/responses/*.js test/routing/*.js test/services/*.js test/swaps/*.js test/tags/*.js test/telegram/*.js test/wallets/*.js"
85
85
  },
86
- "version": "19.4.0"
86
+ "version": "19.4.2"
87
87
  }