bolt07 1.9.2 → 1.9.3

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,6 +1,6 @@
1
1
  # Versions
2
2
 
3
- ## 1.9.2
3
+ ## 1.9.3
4
4
 
5
5
  - `hopsFromChannels`, `routeFromChannels`, `routeFromHops`: Add support for
6
6
  inbound discounts
package/package.json CHANGED
@@ -28,5 +28,5 @@
28
28
  "scripts": {
29
29
  "test": "npx nyc@15.1 node --experimental-test-coverage --test"
30
30
  },
31
- "version": "1.9.2"
31
+ "version": "1.9.3"
32
32
  }
@@ -4,12 +4,14 @@ const rateDivisor = BigInt(1e6);
4
4
  /** Fee for policy
5
5
 
6
6
  {
7
+ inbound: {
8
+ [inbound_base_discount_mtokens]: <Source Base Fee Reduction String>
9
+ [inbound_rate_discount]: <Source Per Million Rate Reduction Number>
10
+ }
7
11
  mtokens: <Millitokens String>
8
12
  policy: {
9
13
  base_fee_mtokens: <Base Fee Millitokens String>
10
14
  fee_rate: <Fee Rate Number>
11
- [inbound_base_discount_mtokens]: <Source Base Fee Reduction String>
12
- [inbound_rate_discount]: <Source Per Million Rate Reduction Number>
13
15
  }
14
16
  }
15
17
 
@@ -21,7 +23,7 @@ const rateDivisor = BigInt(1e6);
21
23
  fee_mtokens: <Fee Millitokens String>
22
24
  }
23
25
  */
24
- module.exports = ({mtokens, policy}) => {
26
+ module.exports = ({inbound, mtokens, policy}) => {
25
27
  if (mtokens === undefined) {
26
28
  throw new Error('ExpectedMillitokensForPolicyFeeCalculation');
27
29
  }
@@ -41,8 +43,8 @@ module.exports = ({mtokens, policy}) => {
41
43
  const baseFeeMtokens = BigInt(policy.base_fee_mtokens);
42
44
  const feeRate = BigInt(policy.fee_rate);
43
45
  const forwardMtokens = BigInt(mtokens);
44
- const lowerBaseFee = BigInt(policy.inbound_base_discount_mtokens || none);
45
- const lowerFeeRate = BigInt(policy.inbound_rate_discount || none);
46
+ const lowerBaseFee = BigInt(inbound.inbound_base_discount_mtokens || none);
47
+ const lowerFeeRate = BigInt(inbound.inbound_rate_discount || none);
46
48
 
47
49
  const fee = baseFeeMtokens + forwardMtokens * feeRate / rateDivisor;
48
50
 
@@ -112,7 +112,11 @@ module.exports = args => {
112
112
  let feeMtokens = BigInt(minFee);
113
113
 
114
114
  if (!!i) {
115
- const forward = policyFee({policy: hops[i-1], mtokens: forwardMtokens});
115
+ const forward = policyFee({
116
+ inbound: hops[i],
117
+ policy: hops[i-1],
118
+ mtokens: forwardMtokens,
119
+ });
116
120
 
117
121
  feeMtokens = BigInt(forward.fee_mtokens);
118
122
  }
@@ -6,52 +6,48 @@ const policyFee = require('./../../routing/policy_fee');
6
6
 
7
7
  const tests = [
8
8
  {
9
- args: {},
9
+ args: {inbound: {}},
10
10
  description: 'Mtokens are required',
11
11
  error: 'ExpectedMillitokensForPolicyFeeCalculation',
12
12
  },
13
13
  {
14
- args: {mtokens: '1000000'},
14
+ args: {inbound: {}, mtokens: '1000000'},
15
15
  description: 'A policy is required',
16
16
  error: 'ExpectedPolicyToCalculateFeeFor',
17
17
  },
18
18
  {
19
- args: {mtokens: '1000000', policy: {}},
19
+ args: {inbound: {}, mtokens: '1000000', policy: {}},
20
20
  description: 'Base fee tokens are required',
21
21
  error: 'ExpectedBaseFeeMillitokensForPolicyFeeCalculation',
22
22
  },
23
23
  {
24
- args: {mtokens: '1000000', policy: {base_fee_mtokens: '1'}},
24
+ args: {inbound: {}, mtokens: '1000000', policy: {base_fee_mtokens: '1'}},
25
25
  description: 'Fee rate is required',
26
26
  error: 'ExpectedFeeRateForPolicyFeeCalculation',
27
27
  },
28
28
  {
29
- args: {mtokens: '1000000', policy: {base_fee_mtokens: '1', fee_rate: 1}},
29
+ args: {
30
+ inbound: {},
31
+ mtokens: '1000000',
32
+ policy: {base_fee_mtokens: '1', fee_rate: 1},
33
+ },
30
34
  description: 'Fee is calculated',
31
35
  expected: {fee_mtokens: '2'},
32
36
  },
33
37
  {
34
38
  args: {
39
+ inbound: {inbound_base_discount_mtokens: '1', inbound_rate_discount: 1},
35
40
  mtokens: '1000000',
36
- policy: {
37
- base_fee_mtokens: '1',
38
- fee_rate: 1,
39
- inbound_base_discount_mtokens: '1',
40
- inbound_rate_discount: 1,
41
- },
41
+ policy: {base_fee_mtokens: '1', fee_rate: 1},
42
42
  },
43
43
  description: 'Fee rate with discount is calculated',
44
44
  expected: {fee_mtokens: '0'},
45
45
  },
46
46
  {
47
47
  args: {
48
+ inbound: {inbound_base_discount_mtokens: '10', inbound_rate_discount: 1},
48
49
  mtokens: '1000000',
49
- policy: {
50
- base_fee_mtokens: '1',
51
- fee_rate: 1,
52
- inbound_base_discount_mtokens: '10',
53
- inbound_rate_discount: 1,
54
- },
50
+ policy: {base_fee_mtokens: '1', fee_rate: 1},
55
51
  },
56
52
  description: 'Fee rate with big discount is calculated',
57
53
  expected: {fee_mtokens: '0'},