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