@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,188 +0,0 @@
1
- import {
2
- HyperbolaPayoutCurvePiece,
3
- MessageType,
4
- PayoutCurvePieceType,
5
- PayoutFunctionV0,
6
- RoundingIntervals,
7
- } from '@node-dlc/messaging';
8
- import BigNumber from 'bignumber.js';
9
-
10
- import { CETPayout } from '..';
11
- import { splitIntoRanges } from './CETCalculator';
12
- import PayoutCurve from './PayoutCurve';
13
-
14
- export class HyperbolaPayoutCurve implements PayoutCurve {
15
- constructor(
16
- private a: BigNumber,
17
- private b: BigNumber,
18
- private c: BigNumber,
19
- private d: BigNumber,
20
- private translateOutcome: BigNumber,
21
- private translatePayout: BigNumber,
22
- private positive: boolean = true, // TODO: support negative pieces
23
- ) {}
24
-
25
- getPayout(_x: bigint): BigNumber {
26
- const { a, b, c, d, translateOutcome, translatePayout } = this;
27
- const x = new BigNumber(Number(_x));
28
-
29
- const payout = c
30
- .times(
31
- x
32
- .minus(translateOutcome)
33
- .plus(
34
- x
35
- .minus(translateOutcome)
36
- .exponentiatedBy(2)
37
- .minus(a.times(b).times(4))
38
- .squareRoot(),
39
- )
40
- .div(a.times(2)),
41
- )
42
- .plus(
43
- a
44
- .times(d)
45
- .times(2)
46
- .div(
47
- x
48
- .minus(translateOutcome)
49
- .plus(
50
- x
51
- .minus(translateOutcome)
52
- .exponentiatedBy(2)
53
- .minus(a.times(b).times(4))
54
- .squareRoot(),
55
- ),
56
- ),
57
- )
58
- .plus(translatePayout);
59
-
60
- return payout;
61
- }
62
-
63
- getOutcomeForPayout(payout: BigNumber): bigint {
64
- const { a, b, c, d, translateOutcome, translatePayout } = this;
65
-
66
- // Inverse function
67
- // y=(-ad^{2}-bf_{2}^{2}+2bf_{2}x-bx^{2}+df_{1}f_{2}-df_{1}x)/(d(f_{2}-x))
68
- if (c.eq(0)) {
69
- const denominator = d.times(translatePayout.minus(payout));
70
-
71
- if (denominator.eq(0)) {
72
- return BigInt(-1);
73
- }
74
-
75
- const outcome = a
76
- .negated()
77
- .times(d.exponentiatedBy(2))
78
- .minus(b.times(translatePayout.exponentiatedBy(2)))
79
- .plus(b.times(translatePayout).times(payout).times(2))
80
- .minus(b.times(payout.exponentiatedBy(2)))
81
- .plus(d.times(translateOutcome).times(translatePayout))
82
- .minus(d.times(translateOutcome).times(payout))
83
- .dividedBy(denominator)
84
- .integerValue();
85
-
86
- if (outcome.isFinite()) return BigInt(outcome.toString());
87
- return BigInt(-1);
88
- } else {
89
- // y=\left((\sqrt{((adf_{2}-adx+bcf_{2}-bcx-2c\cdot d\cdot f_{1})^{2}-4cd(a^{2}d^{2}-2abcd+abf_{2}^{2}-2abf_{2}x+abx^{2}-adf_{1}f_{2}+adf_{1}x+b^{2}c^{2}-bcf_{1}f_{2}+bcf_{1}x+c\cdot d\cdot f_{1}^{2}))}-adf_{2}+adx-bcf_{2}+bcx+2c\cdot d\cdot f_{1})\right)/(2cd)
90
- throw new Error('Not supported');
91
- }
92
- }
93
-
94
- toPayoutCurvePiece(): HyperbolaPayoutCurvePiece {
95
- const { a, b, c, d, translateOutcome, translatePayout, positive } = this;
96
-
97
- // Use the constructor with string values to avoid F64 dependency issues
98
- const piece = new HyperbolaPayoutCurvePiece(
99
- positive,
100
- translateOutcome.toString(),
101
- translatePayout.toString(),
102
- a.toString(),
103
- b.toString(),
104
- c.toString(),
105
- d.toString(),
106
- );
107
-
108
- return piece;
109
- }
110
-
111
- equals(curve: HyperbolaPayoutCurve): boolean {
112
- return (
113
- this.a.eq(curve.a) &&
114
- this.b.eq(curve.b) &&
115
- this.c.eq(curve.c) &&
116
- this.d.eq(curve.d) &&
117
- this.translateOutcome.eq(curve.translateOutcome) &&
118
- this.translatePayout.eq(curve.translatePayout) &&
119
- this.positive === curve.positive
120
- );
121
- }
122
-
123
- static fromPayoutCurvePiece(
124
- piece: HyperbolaPayoutCurvePiece,
125
- ): HyperbolaPayoutCurve {
126
- // Convert F64 values to BigNumber using toDecimal().toString() to preserve precision
127
- const a = new BigNumber(piece.a.toDecimal().toString());
128
- const b = new BigNumber(piece.b.toDecimal().toString());
129
- const c = new BigNumber(piece.c.toDecimal().toString());
130
- const d = new BigNumber(piece.d.toDecimal().toString());
131
- const translateOutcome = new BigNumber(
132
- piece.translateOutcome.toDecimal().toString(),
133
- );
134
- const translatePayout = new BigNumber(
135
- piece.translatePayout.toDecimal().toString(),
136
- );
137
-
138
- return new HyperbolaPayoutCurve(
139
- a,
140
- b,
141
- c,
142
- d,
143
- translateOutcome,
144
- translatePayout,
145
- piece.usePositivePiece,
146
- );
147
- }
148
-
149
- static computePayouts(
150
- payoutFunction: PayoutFunctionV0,
151
- totalCollateral: bigint,
152
- roundingIntervals: RoundingIntervals,
153
- ): CETPayout[] {
154
- if (payoutFunction.payoutFunctionPieces.length !== 1)
155
- throw new Error('Must have at least one piece');
156
- const {
157
- endPoint,
158
- payoutCurvePiece,
159
- } = payoutFunction.payoutFunctionPieces[0];
160
-
161
- if (
162
- payoutCurvePiece.payoutCurvePieceType !==
163
- PayoutCurvePieceType.Hyperbola &&
164
- payoutCurvePiece.type !== MessageType.HyperbolaPayoutCurvePiece &&
165
- payoutCurvePiece.type !== MessageType.OldHyperbolaPayoutCurvePiece
166
- )
167
- throw new Error('Payout curve piece must be a hyperbola');
168
-
169
- const _payoutCurvePiece = payoutCurvePiece as HyperbolaPayoutCurvePiece;
170
- const curve = this.fromPayoutCurvePiece(_payoutCurvePiece);
171
-
172
- // For the new PayoutFunction structure, get the starting point from the hyperbola piece's leftEndPoint
173
- // This matches the rust-dlc implementation where get_first_outcome() returns left_end_point.event_outcome
174
- const initialEventOutcome =
175
- _payoutCurvePiece.leftEndPoint?.eventOutcome || BigInt(0);
176
- const initialOutcomePayout =
177
- _payoutCurvePiece.leftEndPoint?.outcomePayout || BigInt(0);
178
- return splitIntoRanges(
179
- initialEventOutcome,
180
- endPoint.eventOutcome,
181
- initialOutcomePayout,
182
- endPoint.outcomePayout,
183
- totalCollateral,
184
- curve,
185
- roundingIntervals.intervals,
186
- );
187
- }
188
- }
@@ -1,6 +0,0 @@
1
- import BigNumber from 'bignumber.js';
2
-
3
- export default interface PayoutCurve {
4
- getPayout(x: bigint): BigNumber;
5
- getOutcomeForPayout(y: BigNumber): bigint;
6
- }
@@ -1,266 +0,0 @@
1
- import {
2
- MessageType,
3
- PayoutCurvePieceType,
4
- PayoutFunction,
5
- PolynomialPayoutCurvePiece,
6
- RoundingIntervals,
7
- } from '@node-dlc/messaging';
8
- import BigNumber from 'bignumber.js';
9
-
10
- import { fromPrecision, getPrecision } from '../utils/Precision';
11
- import { CETPayout, mergePayouts, splitIntoRanges } from './CETCalculator';
12
-
13
- interface DlcPoint {
14
- outcome: BigNumber;
15
- payout: BigNumber;
16
- }
17
-
18
- export class PolynomialPayoutCurve {
19
- private readonly points: DlcPoint[];
20
- private readonly slope: BigNumber;
21
- private readonly left: DlcPoint;
22
- private readonly right: DlcPoint;
23
-
24
- constructor(points: DlcPoint[]) {
25
- if (points.length !== 2) throw new Error('Must have two points');
26
- this.points = points;
27
- this.left = points[0];
28
- this.right = points[points.length - 1];
29
-
30
- // m = (y2 - y1) / (x2 - x1)
31
- this.slope = this.right.payout
32
- .minus(this.left.payout)
33
- .dividedBy(this.right.outcome.minus(this.left.outcome));
34
- }
35
-
36
- /**
37
- * Get the payout for a given outcome
38
- * @param outcome The outcome to get the payout for
39
- * @returns The payout for the outcome
40
- */
41
- getPayout(outcome: bigint): BigNumber {
42
- const { left, slope } = this;
43
-
44
- const x = new BigNumber(Number(outcome));
45
-
46
- // y = mx + b
47
- const payout = slope.times(x.minus(left.outcome)).plus(left.payout);
48
-
49
- return payout;
50
- }
51
-
52
- /**
53
- * Get the outcome for a given payout
54
- * @param payout The payout to get the outcome for
55
- * @returns The outcome for the payout
56
- */
57
- getOutcomeForPayout(payout: BigNumber): bigint {
58
- const { left, right, slope } = this;
59
- const y = new BigNumber(Number(payout));
60
-
61
- // Handle constant payout curve (slope = 0)
62
- if (slope.isZero()) {
63
- // For constant curves, if the payout matches, return any outcome in the range
64
- // If it doesn't match, this is an invalid request
65
- if (y.eq(left.payout)) {
66
- return BigInt(left.outcome.toString());
67
- } else {
68
- // For constant curves, if payout doesn't match, return left outcome
69
- // This prevents Infinity errors in calculations
70
- return BigInt(left.outcome.toString());
71
- }
72
- }
73
-
74
- // Find the x value for the given y
75
- // slope = (y2 - y1) / (x2 - x1)
76
- // x1 = (y2 - y1) / slope + x2
77
- const outcome = y
78
- .minus(left.payout)
79
- .dividedBy(slope)
80
- .plus(left.outcome)
81
- .integerValue();
82
-
83
- // Clamp the outcome to the valid range
84
- const clampedOutcome = BigNumber.max(
85
- left.outcome,
86
- BigNumber.min(outcome, right.outcome),
87
- );
88
-
89
- return BigInt(clampedOutcome.toString());
90
- }
91
-
92
- /**
93
- * Serializes PolynomialPayoutCurve to a PolynomialPayoutCurvePiece (for transport)
94
- * @returns A PolynomialPayoutCurvePiece
95
- */
96
- toPayoutCurvePiece(): PolynomialPayoutCurvePiece {
97
- const { points } = this;
98
-
99
- const piece = new PolynomialPayoutCurvePiece();
100
-
101
- piece.points = points.map((point) => {
102
- const eventOutcome = BigInt(point.outcome.toString());
103
- const outcomePayout = BigInt(point.payout.toString());
104
- const extraPrecision = getPrecision(point.payout);
105
- return { eventOutcome, outcomePayout, extraPrecision };
106
- });
107
-
108
- return piece;
109
- }
110
-
111
- /**
112
- * Determine if the payout curve is equal to another
113
- * @param curve A PolynomialPayoutCurve
114
- * @returns True if the curves are the same
115
- */
116
- equals(curve: PolynomialPayoutCurve): boolean {
117
- return this.points.every((point, i) => {
118
- const otherPoint = curve.points[i];
119
- return (
120
- point.outcome.eq(otherPoint.outcome) &&
121
- point.payout.eq(otherPoint.payout)
122
- );
123
- });
124
- }
125
-
126
- /**
127
- * Creates a PolynomialPayoutCurve from a PolynomialPayoutCurvePiece
128
- * @param piece
129
- * @returns A PolynomialPayoutCurve
130
- */
131
- static fromPayoutCurvePiece(
132
- piece: PolynomialPayoutCurvePiece,
133
- ): PolynomialPayoutCurve {
134
- const points = piece.points.map((point) => {
135
- const outcome = new BigNumber(point.eventOutcome.toString());
136
- const payout = new BigNumber(point.outcomePayout.toString()).plus(
137
- fromPrecision(point.extraPrecision),
138
- );
139
- return { outcome, payout };
140
- });
141
- return new PolynomialPayoutCurve(points);
142
- }
143
-
144
- /**
145
- * Computes all CETs for a given payout curve
146
- * @param payoutFunction The payout function
147
- * @param totalCollateral The total collateral
148
- * @param roundingIntervals The rounding intervals
149
- * @returns A list of CETs
150
- */
151
- static computePayouts(
152
- payoutFunction: PayoutFunction,
153
- totalCollateral: bigint,
154
- roundingIntervals: RoundingIntervals,
155
- ): CETPayout[] {
156
- if (payoutFunction.payoutFunctionPieces.length < 1)
157
- throw new Error('Must have at least one piece');
158
-
159
- payoutFunction.payoutFunctionPieces.forEach((piece) => {
160
- if (
161
- piece.payoutCurvePiece.payoutCurvePieceType !==
162
- PayoutCurvePieceType.Polynomial &&
163
- piece.payoutCurvePiece.type !== MessageType.PolynomialPayoutCurvePiece
164
- )
165
- throw new Error('Payout curve piece must be a polynomial');
166
- });
167
-
168
- const CETS: CETPayout[] = [];
169
-
170
- // 1. Add the first piece to the list
171
- const { payoutCurvePiece } = payoutFunction.payoutFunctionPieces[0];
172
-
173
- const curve = this.fromPayoutCurvePiece(
174
- payoutCurvePiece as PolynomialPayoutCurvePiece,
175
- );
176
-
177
- // For the first piece, start from 0 and go to the first endpoint
178
- const firstPiece = payoutFunction.payoutFunctionPieces[0];
179
-
180
- // Calculate the start payout by evaluating the curve at outcome 0
181
- const startPayout = curve.getPayout(BigInt(0));
182
- const startPayoutBigInt = BigInt(startPayout.integerValue().toString());
183
-
184
- // Only add ranges if there's actually a range to cover
185
- if (firstPiece.endPoint.eventOutcome > 0) {
186
- CETS.push(
187
- ...splitIntoRanges(
188
- BigInt(0), // Start from 0
189
- firstPiece.endPoint.eventOutcome,
190
- startPayoutBigInt, // Start payout calculated from curve
191
- firstPiece.endPoint.outcomePayout, // End payout from endpoint
192
- totalCollateral,
193
- curve,
194
- roundingIntervals.intervals,
195
- ),
196
- );
197
- }
198
-
199
- // 2. If there are subsequent pieces, add them to the list
200
- for (let i = 1; i < payoutFunction.payoutFunctionPieces.length; i++) {
201
- const { payoutCurvePiece } = payoutFunction.payoutFunctionPieces[i];
202
-
203
- const curve = this.fromPayoutCurvePiece(
204
- payoutCurvePiece as PolynomialPayoutCurvePiece,
205
- );
206
-
207
- CETS.push(
208
- ...splitIntoRanges(
209
- payoutFunction.payoutFunctionPieces[i - 1].endPoint.eventOutcome,
210
- payoutFunction.payoutFunctionPieces[i].endPoint.eventOutcome,
211
- payoutFunction.payoutFunctionPieces[i - 1].endPoint.outcomePayout,
212
- payoutFunction.payoutFunctionPieces[i].endPoint.outcomePayout,
213
- totalCollateral,
214
- curve,
215
- roundingIntervals.intervals,
216
- ),
217
- );
218
- }
219
-
220
- // 3. Handle the final range from the last piece to lastEndpoint if it exists
221
- if (
222
- payoutFunction.lastEndpoint &&
223
- payoutFunction.payoutFunctionPieces.length > 0
224
- ) {
225
- const lastPieceIndex = payoutFunction.payoutFunctionPieces.length - 1;
226
- const lastPiece = payoutFunction.payoutFunctionPieces[lastPieceIndex];
227
-
228
- // Check if there's a range to cover
229
- if (
230
- payoutFunction.lastEndpoint.eventOutcome >
231
- lastPiece.endPoint.eventOutcome
232
- ) {
233
- // For the final range, we'll assume a constant payout from the last piece endpoint to lastEndpoint
234
- // This is a common pattern for DLC payout functions
235
- const finalCurve = new PolynomialPayoutCurve([
236
- {
237
- outcome: new BigNumber(lastPiece.endPoint.eventOutcome.toString()),
238
- payout: new BigNumber(lastPiece.endPoint.outcomePayout.toString()),
239
- },
240
- {
241
- outcome: new BigNumber(
242
- payoutFunction.lastEndpoint.eventOutcome.toString(),
243
- ),
244
- payout: new BigNumber(
245
- payoutFunction.lastEndpoint.outcomePayout.toString(),
246
- ),
247
- },
248
- ]);
249
-
250
- CETS.push(
251
- ...splitIntoRanges(
252
- lastPiece.endPoint.eventOutcome,
253
- payoutFunction.lastEndpoint.eventOutcome,
254
- lastPiece.endPoint.outcomePayout,
255
- payoutFunction.lastEndpoint.outcomePayout,
256
- totalCollateral,
257
- finalCurve,
258
- roundingIntervals.intervals,
259
- ),
260
- );
261
- }
262
- }
263
-
264
- return mergePayouts(CETS);
265
- }
266
- }