balanceofsatoshis 18.2.6 → 18.2.8
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 +1 -1
- package/package.json +4 -4
- package/swaps/rebalance.js +58 -50
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -24,20 +24,20 @@
|
|
|
24
24
|
"bitcoinjs-lib": "6.1.6",
|
|
25
25
|
"bolt01": "2.0.0",
|
|
26
26
|
"bolt03": "1.3.2",
|
|
27
|
-
"bolt07": "1.9.
|
|
27
|
+
"bolt07": "1.9.4",
|
|
28
28
|
"cbor": "9.0.2",
|
|
29
29
|
"colorette": "2.0.20",
|
|
30
30
|
"crypto-js": "4.2.0",
|
|
31
31
|
"csv-parse": "5.5.6",
|
|
32
32
|
"ecpair": "2.1.0",
|
|
33
33
|
"goldengate": "14.0.7",
|
|
34
|
-
"grammy": "1.
|
|
34
|
+
"grammy": "1.25.0",
|
|
35
35
|
"hot-formula-parser": "4.0.0",
|
|
36
36
|
"import-lazy": "4.0.0",
|
|
37
37
|
"ini": "4.1.3",
|
|
38
38
|
"inquirer": "9.2.23",
|
|
39
39
|
"ln-accounting": "8.0.3",
|
|
40
|
-
"ln-service": "57.14.
|
|
40
|
+
"ln-service": "57.14.3",
|
|
41
41
|
"ln-sync": "6.0.4",
|
|
42
42
|
"ln-telegram": "6.1.6",
|
|
43
43
|
"moment": "2.30.1",
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"postpublish": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t alexbosworth/balanceofsatoshis -t alexbosworth/balanceofsatoshis:$npm_package_version --push .",
|
|
83
83
|
"test": "npx nyc@15.1.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"
|
|
84
84
|
},
|
|
85
|
-
"version": "18.2.
|
|
85
|
+
"version": "18.2.8"
|
|
86
86
|
}
|
package/swaps/rebalance.js
CHANGED
|
@@ -10,7 +10,6 @@ const {getHeight} = require('ln-service');
|
|
|
10
10
|
const {getIdentity} = require('ln-service');
|
|
11
11
|
const {getNode} = require('ln-service');
|
|
12
12
|
const {getPeerLiquidity} = require('ln-sync');
|
|
13
|
-
const {getRouteThroughHops} = require('ln-service');
|
|
14
13
|
const {getWalletVersion} = require('ln-service');
|
|
15
14
|
const {parseAmount} = require('ln-accounting');
|
|
16
15
|
const {payViaRoutes} = require('ln-service');
|
|
@@ -697,59 +696,17 @@ module.exports = (args, cbk) => {
|
|
|
697
696
|
// Get the current height
|
|
698
697
|
getHeight: ['channels', 'lnd', ({lnd}, cbk) => getHeight({lnd}, cbk)],
|
|
699
698
|
|
|
700
|
-
// Get route for rebalance
|
|
701
|
-
getRoute: ['channels', 'invoice', ({channels, invoice}, cbk) => {
|
|
702
|
-
// Find any inbound policy, LND 0.18.0 miscalculates fees here
|
|
703
|
-
const hasInboundPolicy = channels.find(channel => {
|
|
704
|
-
return channel.policies.find(policy => {
|
|
705
|
-
if (policy.inbound_base_discount_mtokens !== '0') {
|
|
706
|
-
return true;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
if (policy.inbound_rate_discount !== 0) {
|
|
710
|
-
return true;
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
return false;
|
|
714
|
-
});
|
|
715
|
-
});
|
|
716
|
-
|
|
717
|
-
// Exit early when there is an inbound fee that needs a recalc
|
|
718
|
-
if (!!hasInboundPolicy) {
|
|
719
|
-
return cbk(null, {});
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
return getRouteThroughHops({
|
|
723
|
-
cltv_delta: cltvDelta,
|
|
724
|
-
lnd: args.lnd,
|
|
725
|
-
mtokens: invoice.mtokens,
|
|
726
|
-
payment: invoice.payment,
|
|
727
|
-
public_keys: channels.map(n => n.destination),
|
|
728
|
-
total_mtokens: !!invoice.payment ? invoice.mtokens : undefined,
|
|
729
|
-
},
|
|
730
|
-
(err, res) => {
|
|
731
|
-
// Exit early when there is an error and use local route calculation
|
|
732
|
-
if (!!err) {
|
|
733
|
-
return cbk(null, {});
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
return cbk(null, {route: res.route});
|
|
737
|
-
});
|
|
738
|
-
}],
|
|
739
|
-
|
|
740
699
|
// Calculate route for rebalance
|
|
741
700
|
routes: [
|
|
742
701
|
'channels',
|
|
743
702
|
'getHeight',
|
|
744
703
|
'getPublicKey',
|
|
745
|
-
'getRoute',
|
|
746
704
|
'invoice',
|
|
747
705
|
'tokens',
|
|
748
706
|
({
|
|
749
707
|
channels,
|
|
750
708
|
getHeight,
|
|
751
709
|
getPublicKey,
|
|
752
|
-
getRoute,
|
|
753
710
|
invoice,
|
|
754
711
|
tokens,
|
|
755
712
|
},
|
|
@@ -766,16 +723,15 @@ module.exports = (args, cbk) => {
|
|
|
766
723
|
total_mtokens: !!invoice.payment ? invoice.mtokens : undefined,
|
|
767
724
|
});
|
|
768
725
|
|
|
769
|
-
const endRoute = getRoute.route || route;
|
|
770
726
|
const maxFee = args.max_fee || defaultMaxFee;
|
|
771
727
|
const maxFeeRate = args.max_fee_rate || defaultMaxFeeRate;
|
|
772
728
|
|
|
773
|
-
if (
|
|
729
|
+
if (route.tokens < minRebalanceAmount) {
|
|
774
730
|
return cbk([503, 'EncounteredUnexpectedRouteLiquidityFailure']);
|
|
775
731
|
}
|
|
776
732
|
|
|
777
733
|
const [highFeeAt] = sortBy({
|
|
778
|
-
array:
|
|
734
|
+
array: route.hops.map(hop => ({
|
|
779
735
|
to: hop.public_key,
|
|
780
736
|
fee: hop.fee,
|
|
781
737
|
})),
|
|
@@ -783,15 +739,15 @@ module.exports = (args, cbk) => {
|
|
|
783
739
|
}).sorted.reverse().map(n => n.to);
|
|
784
740
|
|
|
785
741
|
// Exit early when a max fee is specified and exceeded
|
|
786
|
-
if (!!maxFee &&
|
|
742
|
+
if (!!maxFee && route.fee > maxFee) {
|
|
787
743
|
return cbk([
|
|
788
744
|
400,
|
|
789
745
|
'RebalanceTotalFeeTooHigh',
|
|
790
|
-
{needed_max_fee:
|
|
746
|
+
{needed_max_fee: route.fee.toString(), high_fee: highFeeAt},
|
|
791
747
|
]);
|
|
792
748
|
}
|
|
793
749
|
|
|
794
|
-
const feeRate = ceil(
|
|
750
|
+
const feeRate = ceil(route.fee / route.tokens * rateDivisor);
|
|
795
751
|
|
|
796
752
|
// Exit early when the max fee rate is specified and exceeded
|
|
797
753
|
if (!!maxFeeRate && feeRate > maxFeeRate) {
|
|
@@ -802,12 +758,61 @@ module.exports = (args, cbk) => {
|
|
|
802
758
|
]);
|
|
803
759
|
}
|
|
804
760
|
|
|
805
|
-
return cbk(null, [
|
|
761
|
+
return cbk(null, [route]);
|
|
806
762
|
} catch (err) {
|
|
807
763
|
return cbk([500, 'FailedToConstructRebalanceRoute', {err}]);
|
|
808
764
|
}
|
|
809
765
|
}],
|
|
810
766
|
|
|
767
|
+
// Calculate the total inbound fee discount
|
|
768
|
+
discount: [
|
|
769
|
+
'channels',
|
|
770
|
+
'getHeight',
|
|
771
|
+
'getPublicKey',
|
|
772
|
+
'invoice',
|
|
773
|
+
'routes',
|
|
774
|
+
({
|
|
775
|
+
channels,
|
|
776
|
+
getHeight,
|
|
777
|
+
getPublicKey,
|
|
778
|
+
invoice,
|
|
779
|
+
routes,
|
|
780
|
+
tokens,
|
|
781
|
+
},
|
|
782
|
+
cbk) =>
|
|
783
|
+
{
|
|
784
|
+
const {route} = routeFromChannels({
|
|
785
|
+
channels: channels.map(channel => ({
|
|
786
|
+
capacity: channel.capacity,
|
|
787
|
+
destination: channel.destination,
|
|
788
|
+
id: channel.id,
|
|
789
|
+
policies: channel.policies.map(policy => ({
|
|
790
|
+
base_fee_mtokens: policy.base_fee_mtokens,
|
|
791
|
+
cltv_delta: policy.cltv_delta,
|
|
792
|
+
fee_rate: policy.fee_rate,
|
|
793
|
+
is_disabled: policy.is_disabled,
|
|
794
|
+
max_htlc_mtokens: policy.max_htlc_mtokens,
|
|
795
|
+
min_htlc_mtokens: policy.min_htlc_mtokens,
|
|
796
|
+
public_key: policy.public_key,
|
|
797
|
+
})),
|
|
798
|
+
})),
|
|
799
|
+
cltv_delta: cltvDelta,
|
|
800
|
+
destination: getPublicKey.public_key,
|
|
801
|
+
height: getHeight.current_block_height,
|
|
802
|
+
mtokens: (BigInt(invoice.tokens) * mtokensPerToken).toString(),
|
|
803
|
+
payment: invoice.payment,
|
|
804
|
+
total_mtokens: !!invoice.payment ? invoice.mtokens : undefined,
|
|
805
|
+
});
|
|
806
|
+
|
|
807
|
+
const [discounted] = routes;
|
|
808
|
+
|
|
809
|
+
const dif = BigInt(route.fee_mtokens) - BigInt(discounted.fee_mtokens);
|
|
810
|
+
|
|
811
|
+
return cbk(null, {
|
|
812
|
+
lowered: tokAsBigTok(Number(dif / mtokensPerToken)),
|
|
813
|
+
});
|
|
814
|
+
}],
|
|
815
|
+
|
|
811
816
|
// Execute the rebalance
|
|
812
817
|
pay: ['invoice', 'lnd', 'routes', ({invoice, lnd, routes}, cbk) => {
|
|
813
818
|
return payViaRoutes({lnd, routes, id: invoice.id}, (err, res) => {
|
|
@@ -845,12 +850,14 @@ module.exports = (args, cbk) => {
|
|
|
845
850
|
|
|
846
851
|
// Final rebalancing outcome
|
|
847
852
|
rebalance: [
|
|
853
|
+
'discount',
|
|
848
854
|
'getAdjustedInbound',
|
|
849
855
|
'getAdjustedOutbound',
|
|
850
856
|
'getInbound',
|
|
851
857
|
'getOutbound',
|
|
852
858
|
'pay',
|
|
853
859
|
({
|
|
860
|
+
discount,
|
|
854
861
|
getAdjustedInbound,
|
|
855
862
|
getAdjustedOutbound,
|
|
856
863
|
getInbound,
|
|
@@ -872,6 +879,7 @@ module.exports = (args, cbk) => {
|
|
|
872
879
|
const outPendingOut = getAdjustedOutbound.outbound_pending;
|
|
873
880
|
|
|
874
881
|
return cbk(null, {
|
|
882
|
+
got_inbound_fee_discount: discount.lowered,
|
|
875
883
|
rebalance: [
|
|
876
884
|
{
|
|
877
885
|
increased_inbound_on: inOn,
|