@atomicfinance/bitcoin-wallet-provider 4.2.7 → 4.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.
Files changed (226) hide show
  1. package/.turbo/turbo-build.log +4 -5
  2. package/CHANGELOG.md +12 -0
  3. package/package.json +6 -6
  4. package/.turbo/turbo-lint$colon$fix.log +0 -4
  5. package/.turbo/turbo-lint.log +0 -5
  6. package/.turbo/turbo-test.log +0 -0
  7. package/.yalc/@node-dlc/core/.nyc_output/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +0 -1
  8. package/.yalc/@node-dlc/core/.nyc_output/processinfo/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +0 -1
  9. package/.yalc/@node-dlc/core/.nyc_output/processinfo/index.json +0 -1
  10. package/.yalc/@node-dlc/core/README.md +0 -11
  11. package/.yalc/@node-dlc/core/__tests__/core.spec.ts +0 -7
  12. package/.yalc/@node-dlc/core/__tests__/dlc/CETCalculator.spec.ts +0 -1029
  13. package/.yalc/@node-dlc/core/__tests__/dlc/CoinSelect.spec.ts +0 -179
  14. package/.yalc/@node-dlc/core/__tests__/dlc/PolynomialPayoutCurve.spec.ts +0 -345
  15. package/.yalc/@node-dlc/core/__tests__/dlc/TxBuilder.spec.ts +0 -424
  16. package/.yalc/@node-dlc/core/__tests__/dlc/finance/Builder.spec.ts +0 -492
  17. package/.yalc/@node-dlc/core/__tests__/dlc/finance/CoveredCall.spec.ts +0 -112
  18. package/.yalc/@node-dlc/core/__tests__/dlc/finance/CsoInfo.spec.ts +0 -1124
  19. package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongCall.spec.ts +0 -55
  20. package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongPut.spec.ts +0 -55
  21. package/.yalc/@node-dlc/core/__tests__/dlc/finance/OptionInfo.spec.ts +0 -226
  22. package/.yalc/@node-dlc/core/__tests__/dlc/finance/ShortPut.spec.ts +0 -62
  23. package/.yalc/@node-dlc/core/__tests__/tsconfig.json +0 -8
  24. package/.yalc/@node-dlc/core/__tests__/utils/precision.spec.ts +0 -40
  25. package/.yalc/@node-dlc/core/coverage/lcov-report/base.css +0 -224
  26. package/.yalc/@node-dlc/core/coverage/lcov-report/block-navigation.js +0 -79
  27. package/.yalc/@node-dlc/core/coverage/lcov-report/favicon.png +0 -0
  28. package/.yalc/@node-dlc/core/coverage/lcov-report/index.html +0 -171
  29. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/AsyncProcessingQueue.ts.html +0 -269
  30. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Base32.ts.html +0 -86
  31. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BigIntUtils.ts.html +0 -86
  32. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BitField.ts.html +0 -86
  33. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ChannelId.ts.html +0 -86
  34. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedList.ts.html +0 -413
  35. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedListNode.ts.html +0 -122
  36. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Queue.ts.html +0 -188
  37. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelId.ts.html +0 -86
  38. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelIdUtils.ts.html +0 -107
  39. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CETCalculator.ts.html +0 -1430
  40. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CoinSelect.ts.html +0 -431
  41. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/HyperbolaPayoutCurve.ts.html +0 -644
  42. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/PolynomialPayoutCurve.ts.html +0 -878
  43. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxBuilder.ts.html +0 -1088
  44. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxFinalizer.ts.html +0 -731
  45. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/Builder.ts.html +0 -2270
  46. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CoveredCall.ts.html +0 -410
  47. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CsoInfo.ts.html +0 -1574
  48. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LinearPayout.ts.html +0 -362
  49. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongCall.ts.html +0 -302
  50. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongPut.ts.html +0 -302
  51. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/OptionInfo.ts.html +0 -626
  52. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/ShortPut.ts.html +0 -305
  53. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/index.html +0 -216
  54. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/index.html +0 -186
  55. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.html +0 -261
  56. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.ts.html +0 -278
  57. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelId.ts.html +0 -242
  58. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelKeys.ts.html +0 -407
  59. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentNumber.ts.html +0 -362
  60. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecret.ts.html +0 -203
  61. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecretStore.ts.html +0 -332
  62. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/Htlc.ts.html +0 -236
  63. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/HtlcDirection.ts.html +0 -131
  64. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ScriptFactory.ts.html +0 -530
  65. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/TxFactory.ts.html +0 -1094
  66. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/index.html +0 -231
  67. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/BigIntUtils.ts.html +0 -272
  68. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/Precision.ts.html +0 -149
  69. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/index.html +0 -126
  70. package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.css +0 -1
  71. package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.js +0 -2
  72. package/.yalc/@node-dlc/core/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  73. package/.yalc/@node-dlc/core/coverage/lcov-report/sorter.js +0 -170
  74. package/.yalc/@node-dlc/core/coverage/lcov.info +0 -2426
  75. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.d.ts +0 -22
  76. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js +0 -55
  77. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js.map +0 -1
  78. package/.yalc/@node-dlc/core/dist/Base32.d.ts +0 -1
  79. package/.yalc/@node-dlc/core/dist/Base32.js +0 -7
  80. package/.yalc/@node-dlc/core/dist/Base32.js.map +0 -1
  81. package/.yalc/@node-dlc/core/dist/BigIntUtils.d.ts +0 -1
  82. package/.yalc/@node-dlc/core/dist/BigIntUtils.js +0 -8
  83. package/.yalc/@node-dlc/core/dist/BigIntUtils.js.map +0 -1
  84. package/.yalc/@node-dlc/core/dist/BitField.d.ts +0 -1
  85. package/.yalc/@node-dlc/core/dist/BitField.js +0 -7
  86. package/.yalc/@node-dlc/core/dist/BitField.js.map +0 -1
  87. package/.yalc/@node-dlc/core/dist/ChannelId.d.ts +0 -1
  88. package/.yalc/@node-dlc/core/dist/ChannelId.js +0 -7
  89. package/.yalc/@node-dlc/core/dist/ChannelId.js.map +0 -1
  90. package/.yalc/@node-dlc/core/dist/LinkedList.d.ts +0 -30
  91. package/.yalc/@node-dlc/core/dist/LinkedList.js +0 -104
  92. package/.yalc/@node-dlc/core/dist/LinkedList.js.map +0 -1
  93. package/.yalc/@node-dlc/core/dist/LinkedListNode.d.ts +0 -9
  94. package/.yalc/@node-dlc/core/dist/LinkedListNode.js +0 -15
  95. package/.yalc/@node-dlc/core/dist/LinkedListNode.js.map +0 -1
  96. package/.yalc/@node-dlc/core/dist/Queue.d.ts +0 -22
  97. package/.yalc/@node-dlc/core/dist/Queue.js +0 -38
  98. package/.yalc/@node-dlc/core/dist/Queue.js.map +0 -1
  99. package/.yalc/@node-dlc/core/dist/ShortChannelId.d.ts +0 -1
  100. package/.yalc/@node-dlc/core/dist/ShortChannelId.js +0 -7
  101. package/.yalc/@node-dlc/core/dist/ShortChannelId.js.map +0 -1
  102. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.d.ts +0 -1
  103. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js +0 -12
  104. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js.map +0 -1
  105. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.d.ts +0 -50
  106. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js +0 -332
  107. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js.map +0 -1
  108. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.d.ts +0 -23
  109. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js +0 -77
  110. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js.map +0 -1
  111. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.d.ts +0 -20
  112. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js +0 -117
  113. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js.map +0 -1
  114. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.d.ts +0 -5
  115. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js +0 -3
  116. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js.map +0 -1
  117. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.d.ts +0 -52
  118. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js +0 -173
  119. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js.map +0 -1
  120. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.d.ts +0 -55
  121. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js +0 -217
  122. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js.map +0 -1
  123. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.d.ts +0 -40
  124. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js +0 -146
  125. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js.map +0 -1
  126. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.d.ts +0 -193
  127. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js +0 -422
  128. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js.map +0 -1
  129. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.d.ts +0 -13
  130. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js +0 -67
  131. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js.map +0 -1
  132. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.d.ts +0 -114
  133. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js +0 -290
  134. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js.map +0 -1
  135. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.d.ts +0 -6
  136. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js +0 -79
  137. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js.map +0 -1
  138. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.d.ts +0 -13
  139. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js +0 -47
  140. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js.map +0 -1
  141. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.d.ts +0 -13
  142. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js +0 -47
  143. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js.map +0 -1
  144. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.d.ts +0 -20
  145. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js +0 -101
  146. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js.map +0 -1
  147. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.d.ts +0 -12
  148. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js +0 -46
  149. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js.map +0 -1
  150. package/.yalc/@node-dlc/core/dist/index.d.ts +0 -39
  151. package/.yalc/@node-dlc/core/dist/index.js +0 -78
  152. package/.yalc/@node-dlc/core/dist/index.js.map +0 -1
  153. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.d.ts +0 -31
  154. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js +0 -52
  155. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js.map +0 -1
  156. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.d.ts +0 -55
  157. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js +0 -105
  158. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js.map +0 -1
  159. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.d.ts +0 -55
  160. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js +0 -76
  161. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js.map +0 -1
  162. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.d.ts +0 -26
  163. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js +0 -44
  164. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js.map +0 -1
  165. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.d.ts +0 -41
  166. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js +0 -79
  167. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js.map +0 -1
  168. package/.yalc/@node-dlc/core/dist/lightning/Htlc.d.ts +0 -46
  169. package/.yalc/@node-dlc/core/dist/lightning/Htlc.js +0 -46
  170. package/.yalc/@node-dlc/core/dist/lightning/Htlc.js.map +0 -1
  171. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.d.ts +0 -16
  172. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js +0 -21
  173. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js.map +0 -1
  174. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.d.ts +0 -76
  175. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js +0 -102
  176. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js.map +0 -1
  177. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.d.ts +0 -83
  178. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js +0 -222
  179. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js.map +0 -1
  180. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.d.ts +0 -9
  181. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js +0 -59
  182. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js.map +0 -1
  183. package/.yalc/@node-dlc/core/dist/utils/Precision.d.ts +0 -13
  184. package/.yalc/@node-dlc/core/dist/utils/Precision.js +0 -28
  185. package/.yalc/@node-dlc/core/dist/utils/Precision.js.map +0 -1
  186. package/.yalc/@node-dlc/core/lib/AsyncProcessingQueue.ts +0 -63
  187. package/.yalc/@node-dlc/core/lib/Base32.ts +0 -2
  188. package/.yalc/@node-dlc/core/lib/BigIntUtils.ts +0 -2
  189. package/.yalc/@node-dlc/core/lib/BitField.ts +0 -2
  190. package/.yalc/@node-dlc/core/lib/ChannelId.ts +0 -2
  191. package/.yalc/@node-dlc/core/lib/LinkedList.ts +0 -111
  192. package/.yalc/@node-dlc/core/lib/LinkedListNode.ts +0 -14
  193. package/.yalc/@node-dlc/core/lib/Queue.ts +0 -36
  194. package/.yalc/@node-dlc/core/lib/ShortChannelId.ts +0 -2
  195. package/.yalc/@node-dlc/core/lib/ShortChannelIdUtils.ts +0 -9
  196. package/.yalc/@node-dlc/core/lib/dlc/CETCalculator.ts +0 -450
  197. package/.yalc/@node-dlc/core/lib/dlc/CoinSelect.ts +0 -117
  198. package/.yalc/@node-dlc/core/lib/dlc/HyperbolaPayoutCurve.ts +0 -188
  199. package/.yalc/@node-dlc/core/lib/dlc/PayoutCurve.ts +0 -6
  200. package/.yalc/@node-dlc/core/lib/dlc/PolynomialPayoutCurve.ts +0 -266
  201. package/.yalc/@node-dlc/core/lib/dlc/TxBuilder.ts +0 -336
  202. package/.yalc/@node-dlc/core/lib/dlc/TxFinalizer.ts +0 -217
  203. package/.yalc/@node-dlc/core/lib/dlc/finance/Builder.ts +0 -730
  204. package/.yalc/@node-dlc/core/lib/dlc/finance/CoveredCall.ts +0 -110
  205. package/.yalc/@node-dlc/core/lib/dlc/finance/CsoInfo.ts +0 -498
  206. package/.yalc/@node-dlc/core/lib/dlc/finance/LinearPayout.ts +0 -94
  207. package/.yalc/@node-dlc/core/lib/dlc/finance/LongCall.ts +0 -74
  208. package/.yalc/@node-dlc/core/lib/dlc/finance/LongPut.ts +0 -74
  209. package/.yalc/@node-dlc/core/lib/dlc/finance/OptionInfo.ts +0 -182
  210. package/.yalc/@node-dlc/core/lib/dlc/finance/ShortPut.ts +0 -75
  211. package/.yalc/@node-dlc/core/lib/index.ts +0 -66
  212. package/.yalc/@node-dlc/core/lib/lightning/ChannelId.ts +0 -54
  213. package/.yalc/@node-dlc/core/lib/lightning/ChannelKeys.ts +0 -109
  214. package/.yalc/@node-dlc/core/lib/lightning/CommitmentNumber.ts +0 -94
  215. package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecret.ts +0 -41
  216. package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecretStore.ts +0 -84
  217. package/.yalc/@node-dlc/core/lib/lightning/Htlc.ts +0 -52
  218. package/.yalc/@node-dlc/core/lib/lightning/HtlcDirection.ts +0 -17
  219. package/.yalc/@node-dlc/core/lib/lightning/ScriptFactory.ts +0 -150
  220. package/.yalc/@node-dlc/core/lib/lightning/TxFactory.ts +0 -338
  221. package/.yalc/@node-dlc/core/lib/utils/BigIntUtils.ts +0 -64
  222. package/.yalc/@node-dlc/core/lib/utils/Precision.ts +0 -23
  223. package/.yalc/@node-dlc/core/package.json +0 -38
  224. package/.yalc/@node-dlc/core/tsconfig.json +0 -8
  225. package/.yalc/@node-dlc/core/yalc.sig +0 -1
  226. package/yalc.lock +0 -10
@@ -1,36 +0,0 @@
1
- import { LinkedList } from './LinkedList';
2
-
3
- /**
4
- * FIFO queue implemented with O(1) enqueue and dequeue operations
5
- */
6
- export class Queue<T> {
7
- private _list: LinkedList<T> = new LinkedList<T>();
8
-
9
- /**
10
- * Peak the tip value
11
- */
12
- public peak(): T {
13
- return this._list.head && this._list.head.value;
14
- }
15
-
16
- /**
17
- * Returns the length of the queue
18
- */
19
- get length(): number {
20
- return this._list.length;
21
- }
22
-
23
- /**
24
- * Enqueue a value
25
- */
26
- public enqueue(value: T): void {
27
- this._list.add(value);
28
- }
29
-
30
- /**
31
- * Dequeue top most value
32
- */
33
- public dequeue(): T {
34
- return this._list.remove(0);
35
- }
36
- }
@@ -1,2 +0,0 @@
1
- // Re-export ShortChannelId from common package to maintain backward compatibility
2
- export { ShortChannelId } from '@node-dlc/common';
@@ -1,9 +0,0 @@
1
- // Re-export ShortChannelId utilities from common package to maintain backward compatibility
2
- export {
3
- shortChannelIdFromBuffer,
4
- shortChannelIdFromNumber,
5
- shortChannelIdFromString,
6
- shortChannelIdToBuffer,
7
- shortChannelIdToNumber,
8
- shortChannelIdToString,
9
- } from '@node-dlc/common';
@@ -1,450 +0,0 @@
1
- import BigNumber from 'bignumber.js';
2
-
3
- import { BigIntMath, toBigInt } from '../utils/BigIntUtils';
4
- import { HyperbolaPayoutCurve } from './HyperbolaPayoutCurve';
5
- import { PolynomialPayoutCurve } from './PolynomialPayoutCurve';
6
-
7
- export function zipWithIndex<T>(arr: T[]): [T, number][] {
8
- return arr.map((a, i) => [a, i]);
9
- }
10
-
11
- export function dropUntil<T>(data: T[], check: (_: T) => boolean): T[] {
12
- for (let i = 0; i < data.length; i++) {
13
- if (check(data[i])) {
14
- return data.slice(i);
15
- }
16
- }
17
- return [];
18
- }
19
-
20
- export function decompose(
21
- num: bigint,
22
- base: number,
23
- numDigits: number,
24
- ): number[] {
25
- let currentNumber = num;
26
- const digits = [];
27
- while (numDigits > 0) {
28
- digits.push(Number(currentNumber % BigInt(base)));
29
- currentNumber = currentNumber / BigInt(base);
30
- numDigits--;
31
- }
32
- return digits.reverse();
33
- }
34
-
35
- export function separatePrefix(
36
- start: bigint,
37
- end: bigint,
38
- base: number,
39
- numDigits: number,
40
- ): {
41
- prefixDigits: number[];
42
- startDigits: number[];
43
- endDigits: number[];
44
- } {
45
- const startDigits = decompose(start, base, numDigits);
46
- const endDigits = decompose(end, base, numDigits);
47
-
48
- const prefixDigits: number[] = [];
49
- for (let i = 0; i < startDigits.length; i++) {
50
- if (startDigits[i] === endDigits[i]) {
51
- prefixDigits.push(startDigits[i]);
52
- } else break;
53
- }
54
-
55
- return {
56
- prefixDigits,
57
- startDigits: startDigits.splice(prefixDigits.length),
58
- endDigits: endDigits.splice(prefixDigits.length),
59
- };
60
- }
61
-
62
- export function frontGroupings(digits: number[], base: number): number[][] {
63
- const digitsReversed = Array.from(digits).reverse();
64
- const nonZeroDigits = dropUntil(
65
- zipWithIndex(digitsReversed),
66
- (a) => a[0] !== 0,
67
- );
68
-
69
- if (nonZeroDigits.length === 0) {
70
- return [[0]];
71
- }
72
- const fromFront = nonZeroDigits
73
- .filter((_, i) => i !== nonZeroDigits.length - 1)
74
- .flatMap(([d, i]) => {
75
- const fixedDigits = Array.from(digits);
76
- fixedDigits.length = fixedDigits.length - (i + 1);
77
-
78
- const result: number[][] = [];
79
- for (let n = d + 1; n < base; n++) {
80
- result.push([...Array.from(fixedDigits), n]);
81
- }
82
- return result;
83
- });
84
-
85
- return [nonZeroDigits.map((a) => a[0]).reverse(), ...fromFront];
86
- }
87
-
88
- export function backGroupings(digits: number[], base: number): number[][] {
89
- const digitsReversed = Array.from(digits).reverse();
90
- const nonMaxDigits = dropUntil(
91
- zipWithIndex(digitsReversed),
92
- (a) => a[0] !== base - 1,
93
- );
94
-
95
- if (nonMaxDigits.length === 0) {
96
- return [[base - 1]];
97
- }
98
-
99
- const fromBack = nonMaxDigits
100
- .filter((_, i) => i !== nonMaxDigits.length - 1)
101
- .flatMap(([d, i]) => {
102
- const fixedDigits = Array.from(digits);
103
- fixedDigits.length = fixedDigits.length - (i + 1);
104
-
105
- const result: number[][] = [];
106
- for (let n = d - 1; n >= 0; n--) {
107
- result.push([...Array.from(fixedDigits), n]);
108
- }
109
-
110
- return result;
111
- });
112
-
113
- return [...fromBack.reverse(), nonMaxDigits.map((a) => a[0]).reverse()];
114
- }
115
-
116
- export function middleGroupings(
117
- firstDigitStart: number,
118
- firstDigitEnd: number,
119
- ): number[][] {
120
- const result = [];
121
- while (++firstDigitStart < firstDigitEnd) {
122
- result.push([firstDigitStart]);
123
- }
124
- return result;
125
- }
126
-
127
- export function groupByIgnoringDigits(
128
- start: bigint,
129
- end: bigint,
130
- base: number,
131
- numDigits: number,
132
- ): number[][] {
133
- const { prefixDigits, startDigits, endDigits } = separatePrefix(
134
- start,
135
- end,
136
- base,
137
- numDigits,
138
- );
139
-
140
- if (
141
- start === end ||
142
- (startDigits.every((n) => n === 0) &&
143
- endDigits.every((n) => n === base - 1) &&
144
- prefixDigits.length !== 0)
145
- ) {
146
- return [prefixDigits];
147
- } else if (prefixDigits.length === numDigits - 1) {
148
- const result = [];
149
- for (
150
- let i = startDigits[startDigits.length - 1];
151
- i <= endDigits[endDigits.length - 1];
152
- i++
153
- ) {
154
- result.push([...prefixDigits, i]);
155
- }
156
-
157
- return result;
158
- } else {
159
- const front = frontGroupings(startDigits, base);
160
- const middle = middleGroupings(startDigits[0], endDigits[0]);
161
- const back = backGroupings(endDigits, base);
162
-
163
- const groupings = [...front, ...middle, ...back];
164
-
165
- return groupings.map((g) => [...prefixDigits, ...g]);
166
- }
167
- }
168
-
169
- export interface RoundingInterval {
170
- beginInterval: bigint;
171
- roundingMod: bigint;
172
- }
173
-
174
- export type CETPayout = {
175
- indexFrom: bigint;
176
- indexTo: bigint;
177
- payout: bigint;
178
- };
179
-
180
- /**
181
- * Performs optimized evaluation and rounding for strictly monotonic hyperbolas on intervals (from, to)
182
- * e.g. hyperbolas with the form b = c = 0
183
- *
184
- * The next start of a payout range is determined by finding the outcome at the next mid-rounding payout.
185
- * Uses an inverse function of the hyperbola to find the outcome.
186
- *
187
- * Optimizes rounding from O(to - from) to O(totalCollateral / rounding)
188
- *
189
- *
190
- * Evaluates and rounds a payout_function equivalent to:
191
- *
192
- * payout_function_v0
193
- * num_pieces: 1
194
- * endpoint_0: from
195
- * endpoint_payout_0: fromPayout
196
- * extra_precision_0: 0
197
- * payout_curve_piece: HyperbolaPayoutCurve
198
- * endpoint_1: to
199
- * endpoint_payout_1: toPayout
200
- */
201
- export function splitIntoRanges(
202
- from: bigint,
203
- to: bigint,
204
- fromPayout: bigint, // endpoint_payout
205
- toPayout: bigint, // endpoint_payout
206
- totalCollateral: bigint,
207
- curve: HyperbolaPayoutCurve | PolynomialPayoutCurve,
208
- roundingIntervals: RoundingInterval[],
209
- ): CETPayout[] {
210
- if (to - from <= 0) {
211
- throw new Error('`to` must be strictly greater than `from`');
212
- }
213
-
214
- const reversedIntervals = [...roundingIntervals].reverse();
215
-
216
- const getRoundingForOutcome = (outcome: bigint): [bigint, number] => {
217
- const roundingIndex = reversedIntervals.findIndex(
218
- (interval) => interval.beginInterval <= outcome,
219
- );
220
-
221
- return [
222
- roundingIndex !== -1
223
- ? reversedIntervals[roundingIndex].roundingMod
224
- : BigInt(1),
225
- roundingIndex,
226
- ];
227
- };
228
-
229
- const clamp = (val: bigint) =>
230
- BigIntMath.clamp(BigInt(0), val, totalCollateral);
231
-
232
- const totalCollateralBN = new BigNumber(totalCollateral.toString());
233
- const clampBN = (val: BigNumber) =>
234
- BigNumber.max(0, BigNumber.min(val, totalCollateralBN));
235
-
236
- const result: CETPayout[] = [];
237
-
238
- // outcome = endpoint_0
239
- result.push({
240
- payout: fromPayout,
241
- indexFrom: from,
242
- indexTo: from,
243
- });
244
-
245
- // In the case of a constant payout curve (fromPayout === toPayout), we can skip the range evaluation
246
- if (fromPayout === toPayout) {
247
- result.push({
248
- payout: toPayout,
249
- indexFrom: from,
250
- indexTo: to,
251
- });
252
- // outcome = endpoint_1
253
- result.push({
254
- payout: toPayout,
255
- indexFrom: to,
256
- indexTo: to,
257
- });
258
- // merge neighbouring ranges with same payout
259
- return mergePayouts(result);
260
- }
261
-
262
- let currentOutcome = from + BigInt(1);
263
-
264
- // iterate over entire range of outcomes from [from, to]
265
- while (currentOutcome < to) {
266
- const [rounding, roundingIndex] = getRoundingForOutcome(currentOutcome);
267
-
268
- // either the next rounding interval, or the end of the range
269
- const nextFirstRoundingOutcome =
270
- reversedIntervals[roundingIndex - 1]?.beginInterval || to;
271
-
272
- // temporary variable to hold the current payout
273
- let currentPayout = new BigNumber(
274
- roundPayout(
275
- clampBN(curve.getPayout(currentOutcome)),
276
- rounding,
277
- ).toString(),
278
- );
279
-
280
- let currentMidRoundedOutcome = currentOutcome;
281
-
282
- const isAscending = curve
283
- .getPayout(nextFirstRoundingOutcome)
284
- .gt(currentPayout);
285
-
286
- // Add loop counter to prevent infinite loops
287
- let loopCounter = 0;
288
- const maxIterations = Number(to - from) + 1000; // Allow some extra iterations
289
-
290
- while (currentMidRoundedOutcome < nextFirstRoundingOutcome) {
291
- // Prevent infinite loops
292
- if (++loopCounter > maxIterations) {
293
- // Breaking out of potential infinite loop - add remaining range and exit
294
- result.push({
295
- payout: clamp(toBigInt(currentPayout)),
296
- indexFrom: currentMidRoundedOutcome,
297
- indexTo: to - BigInt(1),
298
- });
299
- currentOutcome = to;
300
- break;
301
- }
302
-
303
- const nextRoundedPayout = currentPayout
304
- .integerValue()
305
- .plus(isAscending ? Number(rounding) : -Number(rounding));
306
-
307
- const nextRoundedPayoutBigInt = toBigInt(nextRoundedPayout);
308
-
309
- const nextMidRoundedPayout = currentPayout.plus(
310
- isAscending ? Number(rounding) / 2 : -Number(rounding) / 2,
311
- );
312
-
313
- let nextMidRoundedOutcome = curve.getOutcomeForPayout(
314
- nextMidRoundedPayout,
315
- );
316
-
317
- // Handle invalid outcomes from getOutcomeForPayout
318
- if (nextMidRoundedOutcome < 0) {
319
- // If getOutcomeForPayout returns invalid value, advance manually
320
- nextMidRoundedOutcome = currentMidRoundedOutcome + BigInt(1);
321
- }
322
-
323
- if (
324
- (!isAscending &&
325
- nextMidRoundedOutcome >= 0 &&
326
- curve.getPayout(nextMidRoundedOutcome).lt(nextMidRoundedPayout)) ||
327
- (isAscending &&
328
- nextMidRoundedOutcome >= 0 &&
329
- curve.getPayout(nextMidRoundedOutcome).gte(nextMidRoundedPayout))
330
- ) {
331
- nextMidRoundedOutcome = nextMidRoundedOutcome - BigInt(1);
332
- // Ensure we don't go negative
333
- if (nextMidRoundedOutcome < 0) {
334
- nextMidRoundedOutcome = currentMidRoundedOutcome;
335
- }
336
- }
337
-
338
- const nextOutcome = curve.getOutcomeForPayout(nextRoundedPayout);
339
-
340
- if (nextMidRoundedOutcome >= nextFirstRoundingOutcome) {
341
- result.push({
342
- payout: clamp(toBigInt(currentPayout)),
343
- indexFrom: currentMidRoundedOutcome,
344
- indexTo: nextFirstRoundingOutcome - BigInt(1),
345
- });
346
-
347
- currentOutcome = nextFirstRoundingOutcome;
348
- break;
349
- }
350
-
351
- if (
352
- nextRoundedPayoutBigInt > totalCollateral ||
353
- nextRoundedPayoutBigInt < 0 ||
354
- nextOutcome >= to ||
355
- nextOutcome < 0 // undefined on curve
356
- ) {
357
- if (nextMidRoundedOutcome < from || nextMidRoundedOutcome > to) {
358
- result.push({
359
- payout: clamp(toBigInt(currentPayout)),
360
- indexFrom: currentMidRoundedOutcome,
361
- indexTo: to,
362
- });
363
- } else {
364
- result.push(
365
- {
366
- payout: clamp(toBigInt(currentPayout)),
367
- indexFrom: currentMidRoundedOutcome,
368
- indexTo: nextMidRoundedOutcome,
369
- },
370
- {
371
- payout: clamp(nextRoundedPayoutBigInt),
372
- indexFrom: nextMidRoundedOutcome + BigInt(1),
373
- indexTo: to - BigInt(1),
374
- },
375
- );
376
- }
377
-
378
- currentOutcome = to;
379
- break;
380
- }
381
-
382
- result.push({
383
- payout: clamp(toBigInt(currentPayout)),
384
- indexFrom: currentMidRoundedOutcome,
385
- indexTo: nextMidRoundedOutcome,
386
- });
387
-
388
- // Handle case where nextOutcome is invalid
389
- if (nextOutcome < 0) {
390
- // Advance manually if getOutcomeForPayout returns invalid value
391
- currentOutcome = currentMidRoundedOutcome + BigInt(1);
392
- } else {
393
- currentOutcome = nextOutcome + BigInt(1);
394
- }
395
-
396
- currentPayout = nextRoundedPayout;
397
-
398
- // Additional safety check: ensure we're making progress
399
- const previousMidRoundedOutcome = currentMidRoundedOutcome;
400
- currentMidRoundedOutcome = nextMidRoundedOutcome + BigInt(1);
401
-
402
- if (currentMidRoundedOutcome <= previousMidRoundedOutcome) {
403
- // No progress detected in splitIntoRanges loop, breaking
404
- currentOutcome = nextFirstRoundingOutcome;
405
- break;
406
- }
407
- }
408
- }
409
-
410
- // outcome = endpoint_1
411
- result.push({
412
- payout: toPayout,
413
- indexFrom: to,
414
- indexTo: to,
415
- });
416
-
417
- // merge neighbouring ranges with same payout
418
- return mergePayouts(result);
419
- }
420
-
421
- export const mergePayouts = (payouts: CETPayout[]): CETPayout[] => {
422
- return payouts.reduce((acc: CETPayout[], range) => {
423
- const prev = acc[acc.length - 1];
424
- if (prev) {
425
- if (
426
- (prev.indexTo === range.indexFrom ||
427
- prev.indexTo + BigInt(1) === range.indexFrom) &&
428
- prev.payout === range.payout
429
- ) {
430
- prev.indexTo = range.indexTo;
431
- return acc;
432
- }
433
- }
434
-
435
- return [...acc, range];
436
- }, []);
437
- };
438
-
439
- export function roundPayout(payout: BigNumber, rounding: bigint): bigint {
440
- const roundingBN = new BigNumber(rounding.toString());
441
- const mod = payout.gte(0)
442
- ? payout.mod(roundingBN)
443
- : payout.mod(roundingBN).plus(roundingBN);
444
-
445
- const roundedPayout = mod.gte(roundingBN.dividedBy(2))
446
- ? payout.plus(roundingBN).minus(mod)
447
- : payout.minus(mod);
448
-
449
- return toBigInt(roundedPayout);
450
- }
@@ -1,117 +0,0 @@
1
- import { FundingInput } from '@node-dlc/messaging';
2
-
3
- import { DualFundingTxFinalizer } from './TxFinalizer';
4
-
5
- export interface UTXO {
6
- txid: string;
7
- vout: number;
8
- value: number;
9
- address: string;
10
- derivationPath?: string;
11
- }
12
-
13
- const TX_INPUT_SIZE = {
14
- LEGACY: 148,
15
- P2SH: 92,
16
- BECH32: 69,
17
- };
18
-
19
- const inputBytes = () => {
20
- return BigInt(TX_INPUT_SIZE.BECH32);
21
- };
22
-
23
- export const dustThreshold = (feeRate: bigint): bigint => {
24
- return BigInt(inputBytes()) * feeRate;
25
- };
26
-
27
- // order by descending value, minus the inputs approximate fee
28
- const utxoScore = (x: UTXO, feeRate: bigint): bigint => {
29
- return BigInt(x.value) - feeRate * inputBytes();
30
- };
31
-
32
- export const dualFees = (
33
- feeRate: bigint,
34
- numInputs: number,
35
- numContracts: number,
36
- ): bigint => {
37
- const input = new FundingInput();
38
- input.maxWitnessLen = 108;
39
- input.redeemScript = Buffer.from('', 'hex');
40
-
41
- const fakeSPK = Buffer.from(
42
- '0014663117d27e78eb432505180654e603acb30e8a4a',
43
- 'hex',
44
- );
45
-
46
- const offerInputs = Array.from({ length: numInputs }, () => input);
47
- const acceptInputs = Array.from({ length: 1 }, () => input);
48
-
49
- return new DualFundingTxFinalizer(
50
- offerInputs,
51
- fakeSPK,
52
- fakeSPK,
53
- acceptInputs,
54
- fakeSPK,
55
- fakeSPK,
56
- feeRate,
57
- numContracts,
58
- ).offerFees;
59
- };
60
-
61
- /**
62
- * Selects UTXOs for dual funding
63
- * @param utxos - UTXOs to select from
64
- * @param collaterals - Collaterals to fund (just one for non-batch tx)
65
- * @param feeRate - Fee rate in satoshis per byte
66
- * @returns Inputs and fee
67
- * @description
68
- * Add inputs until we reach or surpass the target value (or deplete)
69
- * Worst-case: O(n)
70
- */
71
- export const dualFundingCoinSelect = (
72
- utxos: UTXO[],
73
- collaterals: bigint[], // in satoshis
74
- feeRate: bigint,
75
- ): { inputs: UTXO[]; fee: bigint } => {
76
- utxos = [...utxos].sort((a, b) =>
77
- Number(utxoScore(b, feeRate) - utxoScore(a, feeRate)),
78
- );
79
-
80
- let inAccum = 0;
81
- const inputs: UTXO[] = [];
82
- const outAccum =
83
- collaterals.reduce((acc, val) => acc + val, BigInt(0)) +
84
- dustThreshold(feeRate); // sum of collaterals
85
-
86
- for (let i = 0; i < utxos.length; ++i) {
87
- const utxo = utxos[i];
88
- const utxoBytes = inputBytes();
89
- const utxoFee = feeRate * utxoBytes;
90
- const utxoValue = utxo.value;
91
-
92
- // skip detrimental input
93
- if (utxoFee > utxo.value) {
94
- if (i === utxos.length - 1)
95
- return {
96
- fee: dualFees(feeRate, 1, collaterals.length),
97
- inputs: [],
98
- };
99
- continue;
100
- }
101
-
102
- inAccum += utxoValue;
103
- inputs.push(utxo);
104
-
105
- const fee = dualFees(feeRate, inputs.length, collaterals.length);
106
-
107
- // go again?
108
- if (inAccum < outAccum + fee) continue;
109
-
110
- return { inputs, fee };
111
- }
112
-
113
- return {
114
- fee: dualFees(feeRate, 1, collaterals.length),
115
- inputs: [],
116
- };
117
- };