@atomicfinance/bitcoin-wallet-provider 4.2.8 → 4.3.1

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 +1 -1
  2. package/.turbo/turbo-lint$colon$fix.log +4 -0
  3. package/.turbo/turbo-lint.log +5 -0
  4. package/.turbo/turbo-test.log +0 -0
  5. package/.yalc/@node-dlc/core/.nyc_output/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +1 -0
  6. package/.yalc/@node-dlc/core/.nyc_output/processinfo/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +1 -0
  7. package/.yalc/@node-dlc/core/.nyc_output/processinfo/index.json +1 -0
  8. package/.yalc/@node-dlc/core/README.md +11 -0
  9. package/.yalc/@node-dlc/core/__tests__/core.spec.ts +7 -0
  10. package/.yalc/@node-dlc/core/__tests__/dlc/CETCalculator.spec.ts +1029 -0
  11. package/.yalc/@node-dlc/core/__tests__/dlc/CoinSelect.spec.ts +179 -0
  12. package/.yalc/@node-dlc/core/__tests__/dlc/PolynomialPayoutCurve.spec.ts +345 -0
  13. package/.yalc/@node-dlc/core/__tests__/dlc/TxBuilder.spec.ts +424 -0
  14. package/.yalc/@node-dlc/core/__tests__/dlc/finance/Builder.spec.ts +492 -0
  15. package/.yalc/@node-dlc/core/__tests__/dlc/finance/CoveredCall.spec.ts +112 -0
  16. package/.yalc/@node-dlc/core/__tests__/dlc/finance/CsoInfo.spec.ts +1124 -0
  17. package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongCall.spec.ts +55 -0
  18. package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongPut.spec.ts +55 -0
  19. package/.yalc/@node-dlc/core/__tests__/dlc/finance/OptionInfo.spec.ts +226 -0
  20. package/.yalc/@node-dlc/core/__tests__/dlc/finance/ShortPut.spec.ts +62 -0
  21. package/.yalc/@node-dlc/core/__tests__/tsconfig.json +8 -0
  22. package/.yalc/@node-dlc/core/__tests__/utils/precision.spec.ts +40 -0
  23. package/.yalc/@node-dlc/core/coverage/lcov-report/base.css +224 -0
  24. package/.yalc/@node-dlc/core/coverage/lcov-report/block-navigation.js +79 -0
  25. package/.yalc/@node-dlc/core/coverage/lcov-report/favicon.png +0 -0
  26. package/.yalc/@node-dlc/core/coverage/lcov-report/index.html +171 -0
  27. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/AsyncProcessingQueue.ts.html +269 -0
  28. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Base32.ts.html +86 -0
  29. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BigIntUtils.ts.html +86 -0
  30. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BitField.ts.html +86 -0
  31. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ChannelId.ts.html +86 -0
  32. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedList.ts.html +413 -0
  33. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedListNode.ts.html +122 -0
  34. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Queue.ts.html +188 -0
  35. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelId.ts.html +86 -0
  36. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelIdUtils.ts.html +107 -0
  37. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CETCalculator.ts.html +1430 -0
  38. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CoinSelect.ts.html +431 -0
  39. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/HyperbolaPayoutCurve.ts.html +644 -0
  40. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/PolynomialPayoutCurve.ts.html +878 -0
  41. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxBuilder.ts.html +1088 -0
  42. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxFinalizer.ts.html +731 -0
  43. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/Builder.ts.html +2270 -0
  44. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CoveredCall.ts.html +410 -0
  45. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CsoInfo.ts.html +1574 -0
  46. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LinearPayout.ts.html +362 -0
  47. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongCall.ts.html +302 -0
  48. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongPut.ts.html +302 -0
  49. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/OptionInfo.ts.html +626 -0
  50. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/ShortPut.ts.html +305 -0
  51. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/index.html +216 -0
  52. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/index.html +186 -0
  53. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.html +261 -0
  54. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.ts.html +278 -0
  55. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelId.ts.html +242 -0
  56. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelKeys.ts.html +407 -0
  57. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentNumber.ts.html +362 -0
  58. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecret.ts.html +203 -0
  59. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecretStore.ts.html +332 -0
  60. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/Htlc.ts.html +236 -0
  61. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/HtlcDirection.ts.html +131 -0
  62. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ScriptFactory.ts.html +530 -0
  63. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/TxFactory.ts.html +1094 -0
  64. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/index.html +231 -0
  65. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/BigIntUtils.ts.html +272 -0
  66. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/Precision.ts.html +149 -0
  67. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/index.html +126 -0
  68. package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.css +1 -0
  69. package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.js +2 -0
  70. package/.yalc/@node-dlc/core/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  71. package/.yalc/@node-dlc/core/coverage/lcov-report/sorter.js +170 -0
  72. package/.yalc/@node-dlc/core/coverage/lcov.info +2426 -0
  73. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.d.ts +22 -0
  74. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js +55 -0
  75. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js.map +1 -0
  76. package/.yalc/@node-dlc/core/dist/Base32.d.ts +1 -0
  77. package/.yalc/@node-dlc/core/dist/Base32.js +7 -0
  78. package/.yalc/@node-dlc/core/dist/Base32.js.map +1 -0
  79. package/.yalc/@node-dlc/core/dist/BigIntUtils.d.ts +1 -0
  80. package/.yalc/@node-dlc/core/dist/BigIntUtils.js +8 -0
  81. package/.yalc/@node-dlc/core/dist/BigIntUtils.js.map +1 -0
  82. package/.yalc/@node-dlc/core/dist/BitField.d.ts +1 -0
  83. package/.yalc/@node-dlc/core/dist/BitField.js +7 -0
  84. package/.yalc/@node-dlc/core/dist/BitField.js.map +1 -0
  85. package/.yalc/@node-dlc/core/dist/ChannelId.d.ts +1 -0
  86. package/.yalc/@node-dlc/core/dist/ChannelId.js +7 -0
  87. package/.yalc/@node-dlc/core/dist/ChannelId.js.map +1 -0
  88. package/.yalc/@node-dlc/core/dist/LinkedList.d.ts +30 -0
  89. package/.yalc/@node-dlc/core/dist/LinkedList.js +104 -0
  90. package/.yalc/@node-dlc/core/dist/LinkedList.js.map +1 -0
  91. package/.yalc/@node-dlc/core/dist/LinkedListNode.d.ts +9 -0
  92. package/.yalc/@node-dlc/core/dist/LinkedListNode.js +15 -0
  93. package/.yalc/@node-dlc/core/dist/LinkedListNode.js.map +1 -0
  94. package/.yalc/@node-dlc/core/dist/Queue.d.ts +22 -0
  95. package/.yalc/@node-dlc/core/dist/Queue.js +38 -0
  96. package/.yalc/@node-dlc/core/dist/Queue.js.map +1 -0
  97. package/.yalc/@node-dlc/core/dist/ShortChannelId.d.ts +1 -0
  98. package/.yalc/@node-dlc/core/dist/ShortChannelId.js +7 -0
  99. package/.yalc/@node-dlc/core/dist/ShortChannelId.js.map +1 -0
  100. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.d.ts +1 -0
  101. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js +12 -0
  102. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js.map +1 -0
  103. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.d.ts +50 -0
  104. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js +332 -0
  105. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js.map +1 -0
  106. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.d.ts +23 -0
  107. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js +77 -0
  108. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js.map +1 -0
  109. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.d.ts +20 -0
  110. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js +117 -0
  111. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js.map +1 -0
  112. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.d.ts +5 -0
  113. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js +3 -0
  114. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js.map +1 -0
  115. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.d.ts +52 -0
  116. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js +173 -0
  117. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js.map +1 -0
  118. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.d.ts +55 -0
  119. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js +217 -0
  120. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js.map +1 -0
  121. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.d.ts +40 -0
  122. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js +146 -0
  123. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js.map +1 -0
  124. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.d.ts +193 -0
  125. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js +422 -0
  126. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js.map +1 -0
  127. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.d.ts +13 -0
  128. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js +67 -0
  129. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js.map +1 -0
  130. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.d.ts +114 -0
  131. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js +290 -0
  132. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js.map +1 -0
  133. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.d.ts +6 -0
  134. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js +79 -0
  135. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js.map +1 -0
  136. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.d.ts +13 -0
  137. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js +47 -0
  138. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js.map +1 -0
  139. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.d.ts +13 -0
  140. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js +47 -0
  141. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js.map +1 -0
  142. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.d.ts +20 -0
  143. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js +101 -0
  144. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js.map +1 -0
  145. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.d.ts +12 -0
  146. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js +46 -0
  147. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js.map +1 -0
  148. package/.yalc/@node-dlc/core/dist/index.d.ts +39 -0
  149. package/.yalc/@node-dlc/core/dist/index.js +78 -0
  150. package/.yalc/@node-dlc/core/dist/index.js.map +1 -0
  151. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.d.ts +31 -0
  152. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js +52 -0
  153. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js.map +1 -0
  154. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.d.ts +55 -0
  155. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js +105 -0
  156. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js.map +1 -0
  157. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.d.ts +55 -0
  158. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js +76 -0
  159. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js.map +1 -0
  160. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.d.ts +26 -0
  161. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js +44 -0
  162. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js.map +1 -0
  163. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.d.ts +41 -0
  164. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js +79 -0
  165. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js.map +1 -0
  166. package/.yalc/@node-dlc/core/dist/lightning/Htlc.d.ts +46 -0
  167. package/.yalc/@node-dlc/core/dist/lightning/Htlc.js +46 -0
  168. package/.yalc/@node-dlc/core/dist/lightning/Htlc.js.map +1 -0
  169. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.d.ts +16 -0
  170. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js +21 -0
  171. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js.map +1 -0
  172. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.d.ts +76 -0
  173. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js +102 -0
  174. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js.map +1 -0
  175. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.d.ts +83 -0
  176. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js +222 -0
  177. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js.map +1 -0
  178. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.d.ts +9 -0
  179. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js +59 -0
  180. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js.map +1 -0
  181. package/.yalc/@node-dlc/core/dist/utils/Precision.d.ts +13 -0
  182. package/.yalc/@node-dlc/core/dist/utils/Precision.js +28 -0
  183. package/.yalc/@node-dlc/core/dist/utils/Precision.js.map +1 -0
  184. package/.yalc/@node-dlc/core/lib/AsyncProcessingQueue.ts +63 -0
  185. package/.yalc/@node-dlc/core/lib/Base32.ts +2 -0
  186. package/.yalc/@node-dlc/core/lib/BigIntUtils.ts +2 -0
  187. package/.yalc/@node-dlc/core/lib/BitField.ts +2 -0
  188. package/.yalc/@node-dlc/core/lib/ChannelId.ts +2 -0
  189. package/.yalc/@node-dlc/core/lib/LinkedList.ts +111 -0
  190. package/.yalc/@node-dlc/core/lib/LinkedListNode.ts +14 -0
  191. package/.yalc/@node-dlc/core/lib/Queue.ts +36 -0
  192. package/.yalc/@node-dlc/core/lib/ShortChannelId.ts +2 -0
  193. package/.yalc/@node-dlc/core/lib/ShortChannelIdUtils.ts +9 -0
  194. package/.yalc/@node-dlc/core/lib/dlc/CETCalculator.ts +450 -0
  195. package/.yalc/@node-dlc/core/lib/dlc/CoinSelect.ts +117 -0
  196. package/.yalc/@node-dlc/core/lib/dlc/HyperbolaPayoutCurve.ts +188 -0
  197. package/.yalc/@node-dlc/core/lib/dlc/PayoutCurve.ts +6 -0
  198. package/.yalc/@node-dlc/core/lib/dlc/PolynomialPayoutCurve.ts +266 -0
  199. package/.yalc/@node-dlc/core/lib/dlc/TxBuilder.ts +336 -0
  200. package/.yalc/@node-dlc/core/lib/dlc/TxFinalizer.ts +217 -0
  201. package/.yalc/@node-dlc/core/lib/dlc/finance/Builder.ts +730 -0
  202. package/.yalc/@node-dlc/core/lib/dlc/finance/CoveredCall.ts +110 -0
  203. package/.yalc/@node-dlc/core/lib/dlc/finance/CsoInfo.ts +498 -0
  204. package/.yalc/@node-dlc/core/lib/dlc/finance/LinearPayout.ts +94 -0
  205. package/.yalc/@node-dlc/core/lib/dlc/finance/LongCall.ts +74 -0
  206. package/.yalc/@node-dlc/core/lib/dlc/finance/LongPut.ts +74 -0
  207. package/.yalc/@node-dlc/core/lib/dlc/finance/OptionInfo.ts +182 -0
  208. package/.yalc/@node-dlc/core/lib/dlc/finance/ShortPut.ts +75 -0
  209. package/.yalc/@node-dlc/core/lib/index.ts +66 -0
  210. package/.yalc/@node-dlc/core/lib/lightning/ChannelId.ts +54 -0
  211. package/.yalc/@node-dlc/core/lib/lightning/ChannelKeys.ts +109 -0
  212. package/.yalc/@node-dlc/core/lib/lightning/CommitmentNumber.ts +94 -0
  213. package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecret.ts +41 -0
  214. package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecretStore.ts +84 -0
  215. package/.yalc/@node-dlc/core/lib/lightning/Htlc.ts +52 -0
  216. package/.yalc/@node-dlc/core/lib/lightning/HtlcDirection.ts +17 -0
  217. package/.yalc/@node-dlc/core/lib/lightning/ScriptFactory.ts +150 -0
  218. package/.yalc/@node-dlc/core/lib/lightning/TxFactory.ts +338 -0
  219. package/.yalc/@node-dlc/core/lib/utils/BigIntUtils.ts +64 -0
  220. package/.yalc/@node-dlc/core/lib/utils/Precision.ts +23 -0
  221. package/.yalc/@node-dlc/core/package.json +38 -0
  222. package/.yalc/@node-dlc/core/tsconfig.json +8 -0
  223. package/.yalc/@node-dlc/core/yalc.sig +1 -0
  224. package/CHANGELOG.md +23 -0
  225. package/package.json +7 -7
  226. package/yalc.lock +10 -0
@@ -0,0 +1,36 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ // Re-export ShortChannelId from common package to maintain backward compatibility
2
+ export { ShortChannelId } from '@node-dlc/common';
@@ -0,0 +1,9 @@
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';
@@ -0,0 +1,450 @@
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
+ }
@@ -0,0 +1,117 @@
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
+ };