bolt07 1.9.0 → 1.9.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,6 +1,6 @@
1
1
  # Versions
2
2
 
3
- ## 1.9.0
3
+ ## 1.9.2
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.0"
31
+ "version": "1.9.2"
32
32
  }
@@ -44,13 +44,16 @@ module.exports = ({mtokens, policy}) => {
44
44
  const lowerBaseFee = BigInt(policy.inbound_base_discount_mtokens || none);
45
45
  const lowerFeeRate = BigInt(policy.inbound_rate_discount || none);
46
46
 
47
- const discount = lowerBaseFee + forwardMtokens * lowerFeeRate / rateDivisor;
48
47
  const fee = baseFeeMtokens + forwardMtokens * feeRate / rateDivisor;
49
48
 
49
+ const total = fee + forwardMtokens;
50
+
51
+ const discount = lowerBaseFee + total * lowerFeeRate / rateDivisor;
52
+
50
53
  // Exit early when the discount drowns out the fee
51
- if (-discount > fee) {
54
+ if (discount > fee) {
52
55
  return {fee_mtokens: none};
53
56
  }
54
57
 
55
- return {fee_mtokens: (fee + discount).toString()};
58
+ return {fee_mtokens: (fee - discount).toString()};
56
59
  };
@@ -36,8 +36,8 @@ const tests = [
36
36
  policy: {
37
37
  base_fee_mtokens: '1',
38
38
  fee_rate: 1,
39
- inbound_base_discount_mtokens: '-1',
40
- inbound_rate_discount: -1,
39
+ inbound_base_discount_mtokens: '1',
40
+ inbound_rate_discount: 1,
41
41
  },
42
42
  },
43
43
  description: 'Fee rate with discount is calculated',
@@ -49,8 +49,8 @@ const tests = [
49
49
  policy: {
50
50
  base_fee_mtokens: '1',
51
51
  fee_rate: 1,
52
- inbound_base_discount_mtokens: '-10',
53
- inbound_rate_discount: -1,
52
+ inbound_base_discount_mtokens: '10',
53
+ inbound_rate_discount: 1,
54
54
  },
55
55
  },
56
56
  description: 'Fee rate with big discount is calculated',