@atomicfinance/bitcoin-wallet-provider 4.0.0 → 4.0.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.
Files changed (227) hide show
  1. package/.turbo/turbo-lint.log +1 -0
  2. package/.yalc/@node-dlc/core/.nyc_output/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +1 -0
  3. package/.yalc/@node-dlc/core/.nyc_output/processinfo/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +1 -0
  4. package/.yalc/@node-dlc/core/.nyc_output/processinfo/index.json +1 -0
  5. package/.yalc/@node-dlc/core/README.md +11 -0
  6. package/.yalc/@node-dlc/core/__tests__/core.spec.ts +7 -0
  7. package/.yalc/@node-dlc/core/__tests__/dlc/CETCalculator.spec.ts +1029 -0
  8. package/.yalc/@node-dlc/core/__tests__/dlc/CoinSelect.spec.ts +179 -0
  9. package/.yalc/@node-dlc/core/__tests__/dlc/PolynomialPayoutCurve.spec.ts +345 -0
  10. package/.yalc/@node-dlc/core/__tests__/dlc/TxBuilder.spec.ts +424 -0
  11. package/.yalc/@node-dlc/core/__tests__/dlc/finance/Builder.spec.ts +492 -0
  12. package/.yalc/@node-dlc/core/__tests__/dlc/finance/CoveredCall.spec.ts +112 -0
  13. package/.yalc/@node-dlc/core/__tests__/dlc/finance/CsoInfo.spec.ts +1124 -0
  14. package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongCall.spec.ts +55 -0
  15. package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongPut.spec.ts +55 -0
  16. package/.yalc/@node-dlc/core/__tests__/dlc/finance/OptionInfo.spec.ts +226 -0
  17. package/.yalc/@node-dlc/core/__tests__/dlc/finance/ShortPut.spec.ts +62 -0
  18. package/.yalc/@node-dlc/core/__tests__/tsconfig.json +8 -0
  19. package/.yalc/@node-dlc/core/__tests__/utils/precision.spec.ts +40 -0
  20. package/.yalc/@node-dlc/core/coverage/lcov-report/base.css +224 -0
  21. package/.yalc/@node-dlc/core/coverage/lcov-report/block-navigation.js +79 -0
  22. package/.yalc/@node-dlc/core/coverage/lcov-report/favicon.png +0 -0
  23. package/.yalc/@node-dlc/core/coverage/lcov-report/index.html +171 -0
  24. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/AsyncProcessingQueue.ts.html +269 -0
  25. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Base32.ts.html +86 -0
  26. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BigIntUtils.ts.html +86 -0
  27. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BitField.ts.html +86 -0
  28. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ChannelId.ts.html +86 -0
  29. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedList.ts.html +413 -0
  30. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedListNode.ts.html +122 -0
  31. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Queue.ts.html +188 -0
  32. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelId.ts.html +86 -0
  33. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelIdUtils.ts.html +107 -0
  34. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CETCalculator.ts.html +1430 -0
  35. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CoinSelect.ts.html +431 -0
  36. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/HyperbolaPayoutCurve.ts.html +644 -0
  37. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/PolynomialPayoutCurve.ts.html +878 -0
  38. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxBuilder.ts.html +1088 -0
  39. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxFinalizer.ts.html +731 -0
  40. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/Builder.ts.html +2270 -0
  41. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CoveredCall.ts.html +410 -0
  42. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CsoInfo.ts.html +1574 -0
  43. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LinearPayout.ts.html +362 -0
  44. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongCall.ts.html +302 -0
  45. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongPut.ts.html +302 -0
  46. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/OptionInfo.ts.html +626 -0
  47. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/ShortPut.ts.html +305 -0
  48. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/index.html +216 -0
  49. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/index.html +186 -0
  50. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.html +261 -0
  51. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.ts.html +278 -0
  52. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelId.ts.html +242 -0
  53. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelKeys.ts.html +407 -0
  54. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentNumber.ts.html +362 -0
  55. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecret.ts.html +203 -0
  56. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecretStore.ts.html +332 -0
  57. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/Htlc.ts.html +236 -0
  58. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/HtlcDirection.ts.html +131 -0
  59. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ScriptFactory.ts.html +530 -0
  60. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/TxFactory.ts.html +1094 -0
  61. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/index.html +231 -0
  62. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/BigIntUtils.ts.html +272 -0
  63. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/Precision.ts.html +149 -0
  64. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/index.html +126 -0
  65. package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.css +1 -0
  66. package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.js +2 -0
  67. package/.yalc/@node-dlc/core/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  68. package/.yalc/@node-dlc/core/coverage/lcov-report/sorter.js +170 -0
  69. package/.yalc/@node-dlc/core/coverage/lcov.info +2426 -0
  70. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.d.ts +22 -0
  71. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js +55 -0
  72. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js.map +1 -0
  73. package/.yalc/@node-dlc/core/dist/Base32.d.ts +1 -0
  74. package/.yalc/@node-dlc/core/dist/Base32.js +7 -0
  75. package/.yalc/@node-dlc/core/dist/Base32.js.map +1 -0
  76. package/.yalc/@node-dlc/core/dist/BigIntUtils.d.ts +1 -0
  77. package/.yalc/@node-dlc/core/dist/BigIntUtils.js +8 -0
  78. package/.yalc/@node-dlc/core/dist/BigIntUtils.js.map +1 -0
  79. package/.yalc/@node-dlc/core/dist/BitField.d.ts +1 -0
  80. package/.yalc/@node-dlc/core/dist/BitField.js +7 -0
  81. package/.yalc/@node-dlc/core/dist/BitField.js.map +1 -0
  82. package/.yalc/@node-dlc/core/dist/ChannelId.d.ts +1 -0
  83. package/.yalc/@node-dlc/core/dist/ChannelId.js +7 -0
  84. package/.yalc/@node-dlc/core/dist/ChannelId.js.map +1 -0
  85. package/.yalc/@node-dlc/core/dist/LinkedList.d.ts +30 -0
  86. package/.yalc/@node-dlc/core/dist/LinkedList.js +104 -0
  87. package/.yalc/@node-dlc/core/dist/LinkedList.js.map +1 -0
  88. package/.yalc/@node-dlc/core/dist/LinkedListNode.d.ts +9 -0
  89. package/.yalc/@node-dlc/core/dist/LinkedListNode.js +15 -0
  90. package/.yalc/@node-dlc/core/dist/LinkedListNode.js.map +1 -0
  91. package/.yalc/@node-dlc/core/dist/Queue.d.ts +22 -0
  92. package/.yalc/@node-dlc/core/dist/Queue.js +38 -0
  93. package/.yalc/@node-dlc/core/dist/Queue.js.map +1 -0
  94. package/.yalc/@node-dlc/core/dist/ShortChannelId.d.ts +1 -0
  95. package/.yalc/@node-dlc/core/dist/ShortChannelId.js +7 -0
  96. package/.yalc/@node-dlc/core/dist/ShortChannelId.js.map +1 -0
  97. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.d.ts +1 -0
  98. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js +12 -0
  99. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js.map +1 -0
  100. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.d.ts +50 -0
  101. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js +332 -0
  102. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js.map +1 -0
  103. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.d.ts +23 -0
  104. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js +77 -0
  105. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js.map +1 -0
  106. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.d.ts +20 -0
  107. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js +117 -0
  108. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js.map +1 -0
  109. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.d.ts +5 -0
  110. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js +3 -0
  111. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js.map +1 -0
  112. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.d.ts +52 -0
  113. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js +173 -0
  114. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js.map +1 -0
  115. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.d.ts +55 -0
  116. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js +217 -0
  117. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js.map +1 -0
  118. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.d.ts +40 -0
  119. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js +146 -0
  120. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js.map +1 -0
  121. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.d.ts +193 -0
  122. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js +422 -0
  123. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js.map +1 -0
  124. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.d.ts +13 -0
  125. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js +67 -0
  126. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js.map +1 -0
  127. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.d.ts +114 -0
  128. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js +290 -0
  129. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js.map +1 -0
  130. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.d.ts +6 -0
  131. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js +79 -0
  132. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js.map +1 -0
  133. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.d.ts +13 -0
  134. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js +47 -0
  135. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js.map +1 -0
  136. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.d.ts +13 -0
  137. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js +47 -0
  138. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js.map +1 -0
  139. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.d.ts +20 -0
  140. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js +101 -0
  141. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js.map +1 -0
  142. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.d.ts +12 -0
  143. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js +46 -0
  144. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js.map +1 -0
  145. package/.yalc/@node-dlc/core/dist/index.d.ts +39 -0
  146. package/.yalc/@node-dlc/core/dist/index.js +78 -0
  147. package/.yalc/@node-dlc/core/dist/index.js.map +1 -0
  148. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.d.ts +31 -0
  149. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js +52 -0
  150. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js.map +1 -0
  151. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.d.ts +55 -0
  152. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js +105 -0
  153. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js.map +1 -0
  154. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.d.ts +55 -0
  155. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js +76 -0
  156. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js.map +1 -0
  157. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.d.ts +26 -0
  158. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js +44 -0
  159. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js.map +1 -0
  160. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.d.ts +41 -0
  161. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js +79 -0
  162. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js.map +1 -0
  163. package/.yalc/@node-dlc/core/dist/lightning/Htlc.d.ts +46 -0
  164. package/.yalc/@node-dlc/core/dist/lightning/Htlc.js +46 -0
  165. package/.yalc/@node-dlc/core/dist/lightning/Htlc.js.map +1 -0
  166. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.d.ts +16 -0
  167. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js +21 -0
  168. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js.map +1 -0
  169. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.d.ts +76 -0
  170. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js +102 -0
  171. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js.map +1 -0
  172. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.d.ts +83 -0
  173. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js +222 -0
  174. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js.map +1 -0
  175. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.d.ts +9 -0
  176. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js +59 -0
  177. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js.map +1 -0
  178. package/.yalc/@node-dlc/core/dist/utils/Precision.d.ts +13 -0
  179. package/.yalc/@node-dlc/core/dist/utils/Precision.js +28 -0
  180. package/.yalc/@node-dlc/core/dist/utils/Precision.js.map +1 -0
  181. package/.yalc/@node-dlc/core/lib/AsyncProcessingQueue.ts +63 -0
  182. package/.yalc/@node-dlc/core/lib/Base32.ts +2 -0
  183. package/.yalc/@node-dlc/core/lib/BigIntUtils.ts +2 -0
  184. package/.yalc/@node-dlc/core/lib/BitField.ts +2 -0
  185. package/.yalc/@node-dlc/core/lib/ChannelId.ts +2 -0
  186. package/.yalc/@node-dlc/core/lib/LinkedList.ts +111 -0
  187. package/.yalc/@node-dlc/core/lib/LinkedListNode.ts +14 -0
  188. package/.yalc/@node-dlc/core/lib/Queue.ts +36 -0
  189. package/.yalc/@node-dlc/core/lib/ShortChannelId.ts +2 -0
  190. package/.yalc/@node-dlc/core/lib/ShortChannelIdUtils.ts +9 -0
  191. package/.yalc/@node-dlc/core/lib/dlc/CETCalculator.ts +450 -0
  192. package/.yalc/@node-dlc/core/lib/dlc/CoinSelect.ts +117 -0
  193. package/.yalc/@node-dlc/core/lib/dlc/HyperbolaPayoutCurve.ts +188 -0
  194. package/.yalc/@node-dlc/core/lib/dlc/PayoutCurve.ts +6 -0
  195. package/.yalc/@node-dlc/core/lib/dlc/PolynomialPayoutCurve.ts +266 -0
  196. package/.yalc/@node-dlc/core/lib/dlc/TxBuilder.ts +336 -0
  197. package/.yalc/@node-dlc/core/lib/dlc/TxFinalizer.ts +217 -0
  198. package/.yalc/@node-dlc/core/lib/dlc/finance/Builder.ts +730 -0
  199. package/.yalc/@node-dlc/core/lib/dlc/finance/CoveredCall.ts +110 -0
  200. package/.yalc/@node-dlc/core/lib/dlc/finance/CsoInfo.ts +498 -0
  201. package/.yalc/@node-dlc/core/lib/dlc/finance/LinearPayout.ts +94 -0
  202. package/.yalc/@node-dlc/core/lib/dlc/finance/LongCall.ts +74 -0
  203. package/.yalc/@node-dlc/core/lib/dlc/finance/LongPut.ts +74 -0
  204. package/.yalc/@node-dlc/core/lib/dlc/finance/OptionInfo.ts +182 -0
  205. package/.yalc/@node-dlc/core/lib/dlc/finance/ShortPut.ts +75 -0
  206. package/.yalc/@node-dlc/core/lib/index.ts +66 -0
  207. package/.yalc/@node-dlc/core/lib/lightning/ChannelId.ts +54 -0
  208. package/.yalc/@node-dlc/core/lib/lightning/ChannelKeys.ts +109 -0
  209. package/.yalc/@node-dlc/core/lib/lightning/CommitmentNumber.ts +94 -0
  210. package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecret.ts +41 -0
  211. package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecretStore.ts +84 -0
  212. package/.yalc/@node-dlc/core/lib/lightning/Htlc.ts +52 -0
  213. package/.yalc/@node-dlc/core/lib/lightning/HtlcDirection.ts +17 -0
  214. package/.yalc/@node-dlc/core/lib/lightning/ScriptFactory.ts +150 -0
  215. package/.yalc/@node-dlc/core/lib/lightning/TxFactory.ts +338 -0
  216. package/.yalc/@node-dlc/core/lib/utils/BigIntUtils.ts +64 -0
  217. package/.yalc/@node-dlc/core/lib/utils/Precision.ts +23 -0
  218. package/.yalc/@node-dlc/core/package.json +38 -0
  219. package/.yalc/@node-dlc/core/tsconfig.json +8 -0
  220. package/.yalc/@node-dlc/core/yalc.sig +1 -0
  221. package/CHANGELOG.md +56 -5
  222. package/dist/BitcoinWalletProvider.d.ts +4 -2
  223. package/dist/BitcoinWalletProvider.js +1 -0
  224. package/dist/BitcoinWalletProvider.js.map +1 -1
  225. package/lib/BitcoinWalletProvider.ts +11 -3
  226. package/package.json +5 -5
  227. package/yalc.lock +10 -0
@@ -0,0 +1,74 @@
1
+ import { PayoutFunctionV0 } from '@node-dlc/messaging';
2
+ import BN from 'bignumber.js';
3
+
4
+ import { HyperbolaPayoutCurve } from '../HyperbolaPayoutCurve';
5
+
6
+ const buildCurve = (
7
+ strikePrice: bigint,
8
+ contractSize: bigint,
9
+ oracleBase: number,
10
+ oracleDigits: number,
11
+ ): {
12
+ maxOutcome: bigint;
13
+ totalCollateral: bigint;
14
+ payoutCurve: HyperbolaPayoutCurve;
15
+ } => {
16
+ const a = new BN(-1);
17
+ const b = new BN(0);
18
+ const c = new BN(0);
19
+ const d = new BN((strikePrice * contractSize).toString());
20
+
21
+ const f_1 = new BN(0);
22
+ const f_2 = new BN(Number(contractSize));
23
+
24
+ const payoutCurve = new HyperbolaPayoutCurve(a, b, c, d, f_1, f_2);
25
+
26
+ const maxOutcome = BigInt(
27
+ new BN(oracleBase).pow(oracleDigits).minus(1).toString(10),
28
+ );
29
+
30
+ return {
31
+ maxOutcome,
32
+ totalCollateral: contractSize,
33
+ payoutCurve,
34
+ };
35
+ };
36
+
37
+ const buildPayoutFunction = (
38
+ strikePrice: bigint,
39
+ contractSize: bigint,
40
+ totalCollateral: bigint,
41
+ oracleBase: number,
42
+ oracleDigits: number,
43
+ ): { payoutFunction: PayoutFunctionV0; totalCollateral: bigint } => {
44
+ const { maxOutcome, payoutCurve } = buildCurve(
45
+ strikePrice,
46
+ contractSize,
47
+ oracleBase,
48
+ oracleDigits,
49
+ );
50
+
51
+ const payoutFunction = new PayoutFunctionV0();
52
+
53
+ payoutFunction.payoutFunctionPieces.push({
54
+ endPoint: {
55
+ eventOutcome: maxOutcome,
56
+ outcomePayout: totalCollateral,
57
+ extraPrecision: 0,
58
+ },
59
+ payoutCurvePiece: payoutCurve.toPayoutCurvePiece(),
60
+ });
61
+
62
+ payoutFunction.lastEndpoint = {
63
+ eventOutcome: maxOutcome,
64
+ outcomePayout: totalCollateral,
65
+ extraPrecision: 0,
66
+ };
67
+
68
+ return {
69
+ payoutFunction,
70
+ totalCollateral,
71
+ };
72
+ };
73
+
74
+ export const LongCall = { buildCurve, buildPayoutFunction };
@@ -0,0 +1,74 @@
1
+ import { PayoutFunctionV0 } from '@node-dlc/messaging';
2
+ import BN from 'bignumber.js';
3
+
4
+ import { HyperbolaPayoutCurve } from '../HyperbolaPayoutCurve';
5
+
6
+ const buildCurve = (
7
+ strikePrice: bigint,
8
+ contractSize: bigint,
9
+ oracleBase: number,
10
+ oracleDigits: number,
11
+ ): {
12
+ maxOutcome: bigint;
13
+ totalCollateral: bigint;
14
+ payoutCurve: HyperbolaPayoutCurve;
15
+ } => {
16
+ const a = new BN(1);
17
+ const b = new BN(0);
18
+ const c = new BN(0);
19
+ const d = new BN((strikePrice * contractSize).toString());
20
+
21
+ const f_1 = new BN(0);
22
+ const f_2 = new BN(-Number(contractSize));
23
+
24
+ const payoutCurve = new HyperbolaPayoutCurve(a, b, c, d, f_1, f_2);
25
+
26
+ const maxOutcome = BigInt(
27
+ new BN(oracleBase).pow(oracleDigits).minus(1).toString(10),
28
+ );
29
+
30
+ return {
31
+ maxOutcome,
32
+ totalCollateral: contractSize,
33
+ payoutCurve,
34
+ };
35
+ };
36
+
37
+ const buildPayoutFunction = (
38
+ strikePrice: bigint,
39
+ contractSize: bigint,
40
+ totalCollateral: bigint,
41
+ oracleBase: number,
42
+ oracleDigits: number,
43
+ ): { payoutFunction: PayoutFunctionV0; totalCollateral: bigint } => {
44
+ const { maxOutcome, payoutCurve } = buildCurve(
45
+ strikePrice,
46
+ contractSize,
47
+ oracleBase,
48
+ oracleDigits,
49
+ );
50
+
51
+ const payoutFunction = new PayoutFunctionV0();
52
+
53
+ payoutFunction.payoutFunctionPieces.push({
54
+ endPoint: {
55
+ eventOutcome: maxOutcome,
56
+ outcomePayout: BigInt(0),
57
+ extraPrecision: 0,
58
+ },
59
+ payoutCurvePiece: payoutCurve.toPayoutCurvePiece(),
60
+ });
61
+
62
+ payoutFunction.lastEndpoint = {
63
+ eventOutcome: maxOutcome,
64
+ outcomePayout: BigInt(0),
65
+ extraPrecision: 0,
66
+ };
67
+
68
+ return {
69
+ payoutFunction,
70
+ totalCollateral,
71
+ };
72
+ };
73
+
74
+ export const LongPut = { buildCurve, buildPayoutFunction };
@@ -0,0 +1,182 @@
1
+ import {
2
+ ContractDescriptorType,
3
+ ContractInfo,
4
+ DigitDecompositionEventDescriptor,
5
+ HyperbolaPayoutCurvePiece,
6
+ MessageType,
7
+ MultiOracleInfo,
8
+ NumericalDescriptor,
9
+ PayoutCurvePieceType,
10
+ PayoutFunction,
11
+ SingleContractInfo,
12
+ SingleOracleInfo,
13
+ } from '@node-dlc/messaging';
14
+ import BN from 'bignumber.js';
15
+
16
+ import { HyperbolaPayoutCurve } from '../HyperbolaPayoutCurve';
17
+ import { CoveredCall } from './CoveredCall';
18
+ import { ShortPut } from './ShortPut';
19
+
20
+ export interface OptionInfo {
21
+ contractSize: bigint;
22
+ strikePrice: bigint;
23
+ premium?: bigint;
24
+ type?: OptionType;
25
+ expiry: Date;
26
+ }
27
+
28
+ export type HasOfferCollateral = {
29
+ offerCollateral: bigint;
30
+ };
31
+
32
+ export type HasContractInfo = {
33
+ contractInfo: ContractInfo;
34
+ };
35
+
36
+ export type HasType = {
37
+ type: MessageType;
38
+ };
39
+
40
+ export type OptionType = 'put' | 'call';
41
+
42
+ export function getOptionInfoFromContractInfo(
43
+ _contractInfo: ContractInfo,
44
+ ): OptionInfo {
45
+ if (_contractInfo.type !== MessageType.SingleContractInfo)
46
+ throw Error('Only SingleContractInfo currently supported');
47
+
48
+ const contractInfo = _contractInfo as SingleContractInfo;
49
+ if (
50
+ contractInfo.contractDescriptor.contractDescriptorType !==
51
+ ContractDescriptorType.NumericOutcome
52
+ )
53
+ throw Error('Numeric Descriptor currently supported');
54
+
55
+ const oracleInfo = contractInfo.oracleInfo;
56
+
57
+ // Handle both SingleOracleInfo and MultiOracleInfo using proper type discrimination
58
+ let eventMaturityEpoch: number;
59
+ let eventDescriptor: DigitDecompositionEventDescriptor;
60
+
61
+ switch (oracleInfo.type) {
62
+ case MessageType.SingleOracleInfo: {
63
+ const singleOracleInfo = oracleInfo as SingleOracleInfo;
64
+ eventMaturityEpoch =
65
+ singleOracleInfo.announcement.oracleEvent.eventMaturityEpoch;
66
+ eventDescriptor = singleOracleInfo.announcement.oracleEvent
67
+ .eventDescriptor as DigitDecompositionEventDescriptor;
68
+
69
+ if (
70
+ singleOracleInfo.announcement.oracleEvent.eventDescriptor.type !==
71
+ MessageType.DigitDecompositionEventDescriptorV0
72
+ ) {
73
+ throw Error(
74
+ 'Only DigitDecompositionEventDescriptorV0 currently supported',
75
+ );
76
+ }
77
+ break;
78
+ }
79
+ case MessageType.MultiOracleInfo: {
80
+ const multiOracleInfo = oracleInfo as MultiOracleInfo;
81
+ eventMaturityEpoch =
82
+ multiOracleInfo.announcements[0].oracleEvent.eventMaturityEpoch;
83
+ eventDescriptor = multiOracleInfo.announcements[0].oracleEvent
84
+ .eventDescriptor as DigitDecompositionEventDescriptor;
85
+
86
+ if (
87
+ multiOracleInfo.announcements[0].oracleEvent.eventDescriptor.type !==
88
+ MessageType.DigitDecompositionEventDescriptorV0
89
+ ) {
90
+ throw Error(
91
+ 'Only DigitDecompositionEventDescriptorV0 currently supported',
92
+ );
93
+ }
94
+ break;
95
+ }
96
+ default:
97
+ throw Error(`Unknown oracle info type: ${oracleInfo.type}`);
98
+ }
99
+
100
+ const { base: oracleBase, nbDigits: oracleDigits } = eventDescriptor;
101
+
102
+ const contractDescriptor = contractInfo.contractDescriptor as NumericalDescriptor;
103
+ if (contractDescriptor.payoutFunction.type !== MessageType.PayoutFunction)
104
+ throw Error('Only PayoutFunction currently supported');
105
+
106
+ const payoutFunction = contractDescriptor.payoutFunction as PayoutFunction;
107
+ if (payoutFunction.payoutFunctionPieces.length === 0)
108
+ throw Error('PayoutFunction must have at least once PayoutFunctionPiece');
109
+ if (payoutFunction.payoutFunctionPieces.length > 1)
110
+ throw Error('More than one PayoutFunctionPiece not supported');
111
+
112
+ const payoutCurvePiece = payoutFunction.payoutFunctionPieces[0]
113
+ .payoutCurvePiece as HyperbolaPayoutCurvePiece;
114
+ if (payoutCurvePiece.payoutCurvePieceType !== PayoutCurvePieceType.Hyperbola)
115
+ throw Error('Must be HyperbolaPayoutCurvePiece');
116
+ if (!payoutCurvePiece.b.isZero() || !payoutCurvePiece.c.isZero())
117
+ throw Error('b and c HyperbolaPayoutCurvePiece values must be 0');
118
+
119
+ const curve = HyperbolaPayoutCurve.fromPayoutCurvePiece(payoutCurvePiece);
120
+ const maxOutcome = BigInt(
121
+ new BN(oracleBase).pow(oracleDigits).minus(1).toString(10),
122
+ );
123
+
124
+ // For the new PayoutFunction structure, we need to get the initial payout from the first piece
125
+ const initialPayout =
126
+ payoutFunction.payoutFunctionPieces[0].endPoint.outcomePayout;
127
+ const isAscending = curve.getPayout(maxOutcome).gt(Number(initialPayout));
128
+
129
+ const expiry = new Date(eventMaturityEpoch * 1000);
130
+ const totalCollateral = contractInfo.totalCollateral;
131
+
132
+ // if curve is ascending, assume it is a put.
133
+ const contractSize = isAscending
134
+ ? BigInt(payoutCurvePiece.translatePayout.toDecimal().toString()) -
135
+ totalCollateral
136
+ : totalCollateral -
137
+ BigInt(payoutCurvePiece.translatePayout.toDecimal().toString());
138
+
139
+ const strikePrice =
140
+ BigInt(payoutCurvePiece.d.toDecimal().toString()) / contractSize;
141
+
142
+ // rebuild payout curve from option info and perform a sanity check
143
+ const { payoutCurve: sanityCurve } = isAscending
144
+ ? ShortPut.buildCurve(
145
+ strikePrice,
146
+ contractSize,
147
+ totalCollateral,
148
+ oracleBase,
149
+ oracleDigits,
150
+ )
151
+ : CoveredCall.buildCurve(
152
+ strikePrice,
153
+ contractSize,
154
+ oracleBase,
155
+ oracleDigits,
156
+ );
157
+ const type = isAscending ? 'put' : 'call';
158
+
159
+ if (!curve.equals(sanityCurve))
160
+ throw new Error(
161
+ 'Payout curve built from extracted OptionInfo does not match original payout curve',
162
+ );
163
+
164
+ return { contractSize, strikePrice, expiry, type };
165
+ }
166
+
167
+ export function getOptionInfoFromOffer(
168
+ offer: HasOfferCollateral & HasContractInfo & HasType,
169
+ ): OptionInfo {
170
+ if (
171
+ offer.type !== MessageType.DlcOffer &&
172
+ offer.type !== MessageType.OrderOffer
173
+ )
174
+ throw Error('Only DlcOffer and OrderOffer currently supported');
175
+
176
+ const premium = offer.contractInfo.totalCollateral - offer.offerCollateral;
177
+
178
+ return {
179
+ ...getOptionInfoFromContractInfo(offer.contractInfo),
180
+ premium,
181
+ };
182
+ }
@@ -0,0 +1,75 @@
1
+ import { PayoutFunctionV0 } from '@node-dlc/messaging';
2
+ import BN from 'bignumber.js';
3
+
4
+ import { HyperbolaPayoutCurve } from '../HyperbolaPayoutCurve';
5
+
6
+ const buildCurve = (
7
+ strikePrice: bigint,
8
+ contractSize: bigint,
9
+ totalCollateral: bigint,
10
+ oracleBase: number,
11
+ oracleDigits: number,
12
+ ): {
13
+ maxOutcome: bigint;
14
+ totalCollateral: bigint;
15
+ payoutCurve: HyperbolaPayoutCurve;
16
+ } => {
17
+ const a = new BN(-1);
18
+ const b = new BN(0);
19
+ const c = new BN(0);
20
+ const d = new BN((strikePrice * contractSize).toString());
21
+
22
+ const f_1 = new BN(0);
23
+ const f_2 = new BN(Number(contractSize)).plus(Number(totalCollateral));
24
+
25
+ const payoutCurve = new HyperbolaPayoutCurve(a, b, c, d, f_1, f_2);
26
+
27
+ const maxOutcome = BigInt(
28
+ new BN(oracleBase).pow(oracleDigits).minus(1).toString(10),
29
+ );
30
+
31
+ return {
32
+ maxOutcome,
33
+ totalCollateral,
34
+ payoutCurve,
35
+ };
36
+ };
37
+
38
+ const buildPayoutFunction = (
39
+ strikePrice: bigint,
40
+ contractSize: bigint,
41
+ totalCollateral: bigint,
42
+ oracleBase: number,
43
+ oracleDigits: number,
44
+ ): { payoutFunction: PayoutFunctionV0 } => {
45
+ const { maxOutcome, payoutCurve } = buildCurve(
46
+ strikePrice,
47
+ contractSize,
48
+ totalCollateral,
49
+ oracleBase,
50
+ oracleDigits,
51
+ );
52
+
53
+ const payoutFunction = new PayoutFunctionV0();
54
+
55
+ payoutFunction.payoutFunctionPieces.push({
56
+ endPoint: {
57
+ eventOutcome: maxOutcome,
58
+ outcomePayout: totalCollateral,
59
+ extraPrecision: 0,
60
+ },
61
+ payoutCurvePiece: payoutCurve.toPayoutCurvePiece(),
62
+ });
63
+
64
+ payoutFunction.lastEndpoint = {
65
+ eventOutcome: maxOutcome,
66
+ outcomePayout: totalCollateral,
67
+ extraPrecision: 0,
68
+ };
69
+
70
+ return {
71
+ payoutFunction,
72
+ };
73
+ };
74
+
75
+ export const ShortPut = { buildCurve, buildPayoutFunction };
@@ -0,0 +1,66 @@
1
+ export * from '@node-dlc/bitcoin';
2
+
3
+ // Explicitly re-export commonly used types from bitcoin for better TypeScript support
4
+ export * from './AsyncProcessingQueue';
5
+ export * from './Base32';
6
+ export * from './BigIntUtils';
7
+ export * from './BitField';
8
+ export * from './ChannelId';
9
+ export * from './LinkedList';
10
+ export * from './LinkedListNode';
11
+ export * from './Queue';
12
+ export * from './ShortChannelId';
13
+ export * from './ShortChannelIdUtils';
14
+ export {
15
+ HashByteOrder,
16
+ HashValue,
17
+ OutPoint,
18
+ Script,
19
+ Tx,
20
+ TxBuilder,
21
+ TxIn,
22
+ TxOut,
23
+ Value,
24
+ } from '@node-dlc/bitcoin';
25
+
26
+ // Explicitly export the utility functions that wire needs
27
+ export {
28
+ shortChannelIdFromBuffer,
29
+ shortChannelIdFromNumber,
30
+ shortChannelIdFromString,
31
+ shortChannelIdToBuffer,
32
+ shortChannelIdToNumber,
33
+ shortChannelIdToString,
34
+ } from './ShortChannelIdUtils';
35
+
36
+ // Lightning subdirectory exports (excluding ChannelId to avoid conflict)
37
+ export { ChannelId as LightningChannelId } from './lightning/ChannelId';
38
+ export * from './lightning/ChannelKeys';
39
+ export * from './lightning/CommitmentNumber';
40
+ export * from './lightning/CommitmentSecret';
41
+ export * from './lightning/CommitmentSecretStore';
42
+ export * from './lightning/Htlc';
43
+ export * from './lightning/HtlcDirection';
44
+ export * from './lightning/ScriptFactory';
45
+ export * from './lightning/TxFactory';
46
+
47
+ // Original node-dlc core exports
48
+ export * from './dlc/CETCalculator';
49
+ export * from './dlc/CoinSelect';
50
+ export * from './dlc/HyperbolaPayoutCurve';
51
+ export * from './dlc/PayoutCurve';
52
+ export * from './dlc/PolynomialPayoutCurve';
53
+ export * from './dlc/TxBuilder';
54
+ export * from './dlc/TxFinalizer';
55
+
56
+ // Finance subdirectory exports
57
+ export * from './dlc/finance/Builder';
58
+ export * from './dlc/finance/CoveredCall';
59
+ export * from './dlc/finance/CsoInfo';
60
+ export * from './dlc/finance/LinearPayout';
61
+ export * from './dlc/finance/LongCall';
62
+ export * from './dlc/finance/LongPut';
63
+ export * from './dlc/finance/OptionInfo';
64
+ export * from './dlc/finance/ShortPut';
65
+ export * from './utils/BigIntUtils';
66
+ export * from './utils/Precision';
@@ -0,0 +1,54 @@
1
+ import { HashByteOrder, OutPoint } from '@node-dlc/bitcoin';
2
+
3
+ /**
4
+ * ChannelId type that that encapsulates an outpoint as a 32-byte value
5
+ * and is used to identify a channel. This type is defined in BOLT 2
6
+ * under the peer protocol. It is defined as combinging the funding_txid
7
+ * and the funding_output_index, using big-endian XOR (meaning the
8
+ * output_index modifies the last two bytes).
9
+ */
10
+ export class ChannelId {
11
+ public static fromOutPoint(outpoint: OutPoint): ChannelId {
12
+ const txid = outpoint.txid.serialize(HashByteOrder.RPC);
13
+
14
+ if (outpoint.outputIndex > 0xffff) {
15
+ throw new Error('Invalid output index length');
16
+ }
17
+
18
+ txid[30] ^= outpoint.outputIndex >> 8;
19
+ txid[31] ^= outpoint.outputIndex & 0xff;
20
+
21
+ return new ChannelId(txid);
22
+ }
23
+
24
+ constructor(readonly value: Buffer) {}
25
+
26
+ /**
27
+ * Converts the ChannelId into a buffer
28
+ */
29
+ public toBuffer(): Buffer {
30
+ return Buffer.from(this.value);
31
+ }
32
+
33
+ /**
34
+ * Converts the ChannelId into a hex-encoded string
35
+ */
36
+ public toString(): string {
37
+ return this.toHex();
38
+ }
39
+
40
+ /**
41
+ * Converts the ChannelId to a hex-encoded string
42
+ */
43
+ public toHex(): string {
44
+ return this.value.toString('hex');
45
+ }
46
+
47
+ /**
48
+ * Returns true if the ChannelIds are byte-wise equal
49
+ * @param other
50
+ */
51
+ public equals(other: ChannelId): boolean {
52
+ return this.value.equals(other.value);
53
+ }
54
+ }
@@ -0,0 +1,109 @@
1
+ import * as crypto from '@node-dlc/crypto';
2
+
3
+ export class ChannelKeys {
4
+ /**
5
+ * Derives a public key that can be used for local or remote
6
+ * pubkey, htlc_pubkey, or delayed_pubkey
7
+ *
8
+ * Derived via:
9
+ * pubkey = basepoint + SHA256(per_commitment_point || basepoint) * G
10
+ *
11
+ * @param perCommitmentPoint 33-byte buffer
12
+ * @param basePoint 33-byte base point
13
+ * @returns 33-byte buffer
14
+ */
15
+ public static derivePubKey(
16
+ perCommitmentPoint: Buffer,
17
+ basePoint: Buffer,
18
+ ): Buffer {
19
+ const tweak = crypto.sha256(Buffer.concat([perCommitmentPoint, basePoint]));
20
+ return crypto.publicKeyTweakAdd(basePoint, tweak, true);
21
+ }
22
+
23
+ /**
24
+ * Derives the private keys based on local basepoint secrets and can
25
+ * be used to derive per-commitment
26
+ * - payment_scret
27
+ * - delayedpayment_secret
28
+ * - htlc_secret
29
+ *
30
+ * Derived via:
31
+ * privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)
32
+ *
33
+ * @param perCommitmentPoint 32-byte buffer
34
+ * @param basePointSecret 32-byte buffer
35
+ * @return 32-byte buffer
36
+ */
37
+ public static derivePrivKey(
38
+ perCommitmentPoint: Buffer,
39
+ basePointSecret: Buffer,
40
+ ): Buffer {
41
+ const basePoint = crypto.getPublicKey(basePointSecret, true);
42
+ const tweak = crypto.sha256(Buffer.concat([perCommitmentPoint, basePoint]));
43
+ return crypto.privateKeyTweakAdd(basePointSecret, tweak);
44
+ }
45
+
46
+ /**
47
+ * Derives the revocationpubkey blinded key for either local or
48
+ * remote revocation pubkey generation.
49
+ *
50
+ * Derived via:
51
+ * revocationpubkey = revocation_basepoint * SHA256(revocation_basepoint || per_commitment_point) +
52
+ * per_commitment_point * SHA256(per_commitment_point || revocation_basepoint)
53
+ *
54
+ * @param perCommitmentPoint 33-byte buffer
55
+ * @param basePoint 33-byte buffer
56
+ * @returns 33-byte buffer
57
+ */
58
+ public static deriveRevocationPubKey(
59
+ perCommitmentPoint: Buffer,
60
+ basePoint: Buffer,
61
+ ): Buffer {
62
+ const tweakA = crypto.sha256(
63
+ Buffer.concat([basePoint, perCommitmentPoint]),
64
+ );
65
+ const a = crypto.publicKeyTweakMul(basePoint, tweakA, true);
66
+
67
+ const tweakB = crypto.sha256(
68
+ Buffer.concat([perCommitmentPoint, basePoint]),
69
+ );
70
+ const b = crypto.publicKeyTweakMul(perCommitmentPoint, tweakB, true);
71
+
72
+ return crypto.publicKeyCombine([a, b], true);
73
+ }
74
+
75
+ /**
76
+ * Derives the revocationprivkey which is used by the local node
77
+ * and with a per_commitment_secret that was revealed by the
78
+ * counterparty.
79
+ *
80
+ * Derived via:
81
+ * revocationprivkey = revocation_basepoint_secret * SHA256(revocation_basepoint || per_commitment_point) +
82
+ * per_commitment_secret * SHA256(per_commitment_point || revocation_basepoint)
83
+ * @param perCommitmentPointSecret 32-byte buffer
84
+ * @param basePointSecret 32-byte buffer
85
+ */
86
+ public static deriveRevocationPrivKey(
87
+ perCommitmentPointSecret: Buffer,
88
+ basePointSecret: Buffer,
89
+ ): Buffer {
90
+ const basePoint = crypto.getPublicKey(basePointSecret, true);
91
+ const perCommitmentPoint = crypto.getPublicKey(
92
+ perCommitmentPointSecret,
93
+ true,
94
+ );
95
+
96
+ const tweakA = crypto.sha256(
97
+ Buffer.concat([basePoint, perCommitmentPoint]),
98
+ );
99
+ const a = crypto.privateKeyTweakMul(basePointSecret, tweakA);
100
+
101
+ const tweakB = crypto.sha256(
102
+ Buffer.concat([perCommitmentPoint, basePoint]),
103
+ );
104
+ const b = crypto.privateKeyTweakMul(perCommitmentPointSecret, tweakB);
105
+
106
+ const result = crypto.privateKeyTweakAdd(a, b);
107
+ return result;
108
+ }
109
+ }