@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,55 @@
1
+ import { HyperbolaPayoutCurvePiece } from '@node-dlc/messaging';
2
+ import { expect } from 'chai';
3
+
4
+ import { LongCall } from '../../../lib/dlc/finance/LongCall';
5
+ import { HyperbolaPayoutCurve } from '../../../lib/dlc/HyperbolaPayoutCurve';
6
+
7
+ describe('LongCall', () => {
8
+ describe('1BTC-50k-base2-18digit curve', () => {
9
+ const strikePrice = BigInt(50000);
10
+ const contractSize = BigInt(10) ** BigInt(8);
11
+ const oracleBase = 2;
12
+ const oracleDigits = 18;
13
+
14
+ const { payoutCurve } = LongCall.buildCurve(
15
+ strikePrice,
16
+ contractSize,
17
+ oracleBase,
18
+ oracleDigits,
19
+ );
20
+
21
+ describe('payout', () => {
22
+ const priceIncrease = BigInt(1000);
23
+
24
+ it('should be positive as the position goes ITM', () => {
25
+ expect(
26
+ payoutCurve
27
+ .getPayout(strikePrice + priceIncrease)
28
+ .integerValue()
29
+ .toNumber(),
30
+ ).to.equal(
31
+ Number(
32
+ (contractSize * priceIncrease) / (strikePrice + priceIncrease),
33
+ ),
34
+ );
35
+ });
36
+
37
+ it('should be zero at strike price', () => {
38
+ expect(payoutCurve.getPayout(strikePrice).toNumber()).to.equal(0);
39
+ });
40
+ });
41
+
42
+ it('should serialize and deserialize properly', () => {
43
+ const payout = payoutCurve.getPayout(strikePrice);
44
+
45
+ const _tlv = payoutCurve.toPayoutCurvePiece().serialize();
46
+ const pf = HyperbolaPayoutCurvePiece.deserialize(_tlv);
47
+
48
+ const deserializedCurve = HyperbolaPayoutCurve.fromPayoutCurvePiece(pf);
49
+
50
+ expect(payout.toNumber()).to.be.eq(
51
+ deserializedCurve.getPayout(strikePrice).toNumber(),
52
+ );
53
+ });
54
+ });
55
+ });
@@ -0,0 +1,55 @@
1
+ import { HyperbolaPayoutCurvePiece } from '@node-dlc/messaging';
2
+ import { expect } from 'chai';
3
+
4
+ import { LongPut } from '../../../lib';
5
+ import { HyperbolaPayoutCurve } from '../../../lib/dlc/HyperbolaPayoutCurve';
6
+
7
+ describe('LongPut', () => {
8
+ describe('1BTC-50k-base2-18digit curve', () => {
9
+ const strikePrice = BigInt(50000);
10
+ const contractSize = BigInt(10) ** BigInt(8);
11
+ const oracleBase = 2;
12
+ const oracleDigits = 18;
13
+
14
+ const { payoutCurve } = LongPut.buildCurve(
15
+ strikePrice,
16
+ contractSize,
17
+ oracleBase,
18
+ oracleDigits,
19
+ );
20
+
21
+ describe('payout', () => {
22
+ const priceDecrease = BigInt(1000);
23
+
24
+ it('should be positive as the position goes ITM', () => {
25
+ expect(
26
+ payoutCurve
27
+ .getPayout(strikePrice - priceDecrease)
28
+ .integerValue()
29
+ .toNumber(),
30
+ ).to.equal(
31
+ Number(
32
+ (contractSize * priceDecrease) / (strikePrice - priceDecrease),
33
+ ),
34
+ );
35
+ });
36
+
37
+ it('should be zero at strike price', () => {
38
+ expect(payoutCurve.getPayout(strikePrice).toNumber()).to.equal(0);
39
+ });
40
+ });
41
+
42
+ it('should serialize and deserialize properly', () => {
43
+ const payout = payoutCurve.getPayout(strikePrice);
44
+
45
+ const _tlv = payoutCurve.toPayoutCurvePiece().serialize();
46
+ const pf = HyperbolaPayoutCurvePiece.deserialize(_tlv);
47
+
48
+ const deserializedCurve = HyperbolaPayoutCurve.fromPayoutCurvePiece(pf);
49
+
50
+ expect(payout.toNumber()).to.be.eq(
51
+ deserializedCurve.getPayout(strikePrice).toNumber(),
52
+ );
53
+ });
54
+ });
55
+ });
@@ -0,0 +1,226 @@
1
+ import { F64 } from '@node-dlc/messaging';
2
+ import {
3
+ DigitDecompositionEventDescriptorV0,
4
+ DlcOffer,
5
+ HyperbolaPayoutCurvePiece,
6
+ NumericalDescriptor,
7
+ OracleAnnouncement,
8
+ OracleEvent,
9
+ PayoutFunction,
10
+ SingleContractInfo,
11
+ SingleOracleInfo,
12
+ } from '@node-dlc/messaging';
13
+ import { expect } from 'chai';
14
+
15
+ import { CoveredCall } from '../../../lib/dlc/finance/CoveredCall';
16
+ import {
17
+ getOptionInfoFromContractInfo,
18
+ getOptionInfoFromOffer,
19
+ } from '../../../lib/dlc/finance/OptionInfo';
20
+ import { ShortPut } from '../../../lib/dlc/finance/ShortPut';
21
+
22
+ describe('OptionInfo', () => {
23
+ describe('OptionInfo from covered call messages', () => {
24
+ const strikePrice = BigInt(50000);
25
+ const contractSize = BigInt(10) ** BigInt(8);
26
+ const premium = BigInt(50000);
27
+ const expiry = new Date(1620014750000);
28
+
29
+ const oracleBase = 2;
30
+ const oracleDigits = 17;
31
+
32
+ const { totalCollateral, payoutFunction } = CoveredCall.buildPayoutFunction(
33
+ strikePrice,
34
+ contractSize,
35
+ oracleBase,
36
+ oracleDigits,
37
+ );
38
+
39
+ const dlcOffer = buildDlcOfferFixture(
40
+ oracleDigits,
41
+ expiry,
42
+ payoutFunction,
43
+ totalCollateral,
44
+ premium,
45
+ );
46
+
47
+ const contractInfo = dlcOffer.contractInfo;
48
+
49
+ it('should get correct OptionInfo from ContractInfo', () => {
50
+ const optionInfo = getOptionInfoFromContractInfo(contractInfo);
51
+
52
+ expect(optionInfo).to.deep.equal({
53
+ contractSize,
54
+ strikePrice,
55
+ expiry,
56
+ type: 'call',
57
+ });
58
+ });
59
+
60
+ it('should get correct OptionInfoWithPremium from DlcOffer', () => {
61
+ const optionInfo = getOptionInfoFromOffer(dlcOffer);
62
+
63
+ expect(optionInfo).to.deep.equal({
64
+ contractSize,
65
+ strikePrice,
66
+ expiry,
67
+ premium,
68
+ type: 'call',
69
+ });
70
+ });
71
+
72
+ it('should throw on an invalid curve', () => {
73
+ const {
74
+ totalCollateral,
75
+ payoutFunction,
76
+ } = CoveredCall.buildPayoutFunction(
77
+ strikePrice,
78
+ contractSize,
79
+ oracleBase,
80
+ oracleDigits,
81
+ );
82
+
83
+ const invalidDlcOffer = buildDlcOfferFixture(
84
+ oracleDigits,
85
+ expiry,
86
+ payoutFunction,
87
+ totalCollateral,
88
+ premium,
89
+ );
90
+
91
+ const contractInfo = invalidDlcOffer.contractInfo as SingleContractInfo;
92
+ const contractDescriptor = contractInfo.contractDescriptor as NumericalDescriptor;
93
+ const payoutFunc = contractDescriptor.payoutFunction as PayoutFunction;
94
+ const hyperbolaPiece = payoutFunc.payoutFunctionPieces[0]
95
+ .payoutCurvePiece as HyperbolaPayoutCurvePiece;
96
+
97
+ hyperbolaPiece.translateOutcome = F64.fromNumber(4);
98
+
99
+ expect(() => {
100
+ getOptionInfoFromOffer(invalidDlcOffer);
101
+ }).to.throw();
102
+ });
103
+ });
104
+
105
+ describe('OptionInfo from short call messages', () => {
106
+ const strikePrice = BigInt(50000);
107
+ const contractSize = BigInt(10) ** BigInt(8);
108
+ const totalCollateral = BigInt(9) ** BigInt(8);
109
+
110
+ const premium = BigInt(50000);
111
+ const expiry = new Date(1620014750000);
112
+
113
+ const oracleBase = 2;
114
+ const oracleDigits = 17;
115
+
116
+ const { payoutFunction } = ShortPut.buildPayoutFunction(
117
+ strikePrice,
118
+ contractSize,
119
+ totalCollateral,
120
+ oracleBase,
121
+ oracleDigits,
122
+ );
123
+
124
+ const dlcOffer = buildDlcOfferFixture(
125
+ oracleDigits,
126
+ expiry,
127
+ payoutFunction,
128
+ totalCollateral,
129
+ premium,
130
+ );
131
+
132
+ const contractInfo = dlcOffer.contractInfo;
133
+
134
+ it('should get correct OptionInfo from ContractInfo', () => {
135
+ const optionInfo = getOptionInfoFromContractInfo(contractInfo);
136
+
137
+ expect(optionInfo).to.deep.equal({
138
+ contractSize,
139
+ strikePrice,
140
+ expiry,
141
+ type: 'put',
142
+ });
143
+ });
144
+
145
+ it('should get correct OptionInfoWithPremium from DlcOffer', () => {
146
+ const optionInfo = getOptionInfoFromOffer(dlcOffer);
147
+
148
+ expect(optionInfo).to.deep.equal({
149
+ contractSize,
150
+ strikePrice,
151
+ expiry,
152
+ premium,
153
+ type: 'put',
154
+ });
155
+ });
156
+
157
+ it('should throw on an invalid curve', () => {
158
+ const { payoutFunction } = ShortPut.buildPayoutFunction(
159
+ strikePrice,
160
+ contractSize,
161
+ totalCollateral,
162
+ oracleBase,
163
+ oracleDigits,
164
+ );
165
+
166
+ const invalidDlcOffer = buildDlcOfferFixture(
167
+ oracleDigits,
168
+ expiry,
169
+ payoutFunction,
170
+ totalCollateral,
171
+ premium,
172
+ );
173
+
174
+ const contractInfo = invalidDlcOffer.contractInfo as SingleContractInfo;
175
+ const contractDescriptor = contractInfo.contractDescriptor as NumericalDescriptor;
176
+ const payoutFunc = contractDescriptor.payoutFunction as PayoutFunction;
177
+ const hyperbolaPiece = payoutFunc.payoutFunctionPieces[0]
178
+ .payoutCurvePiece as HyperbolaPayoutCurvePiece;
179
+
180
+ hyperbolaPiece.translateOutcome = F64.fromNumber(4);
181
+
182
+ expect(() => {
183
+ getOptionInfoFromOffer(invalidDlcOffer);
184
+ }).to.throw();
185
+ });
186
+ });
187
+ });
188
+
189
+ function buildDlcOfferFixture(
190
+ oracleDigits: number,
191
+ expiry: Date,
192
+ payoutFunction: PayoutFunction,
193
+ totalCollateral: bigint,
194
+ premium: bigint,
195
+ ) {
196
+ const eventDescriptor = new DigitDecompositionEventDescriptorV0();
197
+ eventDescriptor.base = 2;
198
+ eventDescriptor.isSigned = false;
199
+ eventDescriptor.unit = 'BTC-USD';
200
+ eventDescriptor.precision = 0;
201
+ eventDescriptor.nbDigits = oracleDigits;
202
+
203
+ const oracleEvent = new OracleEvent();
204
+ oracleEvent.eventMaturityEpoch = Math.floor(expiry.getTime() / 1000);
205
+ oracleEvent.eventDescriptor = eventDescriptor;
206
+
207
+ const oracleAnnouncement = new OracleAnnouncement();
208
+ oracleAnnouncement.oracleEvent = oracleEvent;
209
+
210
+ const oracleInfo = new SingleOracleInfo();
211
+ oracleInfo.announcement = oracleAnnouncement;
212
+
213
+ const contractDescriptor = new NumericalDescriptor();
214
+ contractDescriptor.numDigits = oracleDigits;
215
+ contractDescriptor.payoutFunction = payoutFunction;
216
+
217
+ const contractInfo = new SingleContractInfo();
218
+ contractInfo.totalCollateral = totalCollateral;
219
+ contractInfo.contractDescriptor = contractDescriptor;
220
+ contractInfo.oracleInfo = oracleInfo;
221
+
222
+ const dlcOffer = new DlcOffer();
223
+ dlcOffer.contractInfo = contractInfo;
224
+ dlcOffer.offerCollateral = totalCollateral - premium;
225
+ return dlcOffer;
226
+ }
@@ -0,0 +1,62 @@
1
+ import { HyperbolaPayoutCurvePiece } from '@node-dlc/messaging';
2
+ import { expect } from 'chai';
3
+
4
+ import { ShortPut } from '../../../lib/dlc/finance/ShortPut';
5
+ import { HyperbolaPayoutCurve } from '../../../lib/dlc/HyperbolaPayoutCurve';
6
+
7
+ describe('ShortPut', () => {
8
+ describe('1BTC-50k-base2-20digit curve', () => {
9
+ const strikePrice = BigInt(50000);
10
+ const contractSize = BigInt(10) ** BigInt(8);
11
+ const totalCollateral = contractSize;
12
+ const oracleBase = 2;
13
+ const oracleDigits = 20;
14
+
15
+ const { payoutCurve } = ShortPut.buildCurve(
16
+ strikePrice,
17
+ contractSize,
18
+ totalCollateral,
19
+ oracleBase,
20
+ oracleDigits,
21
+ );
22
+
23
+ describe('payout', () => {
24
+ it('should be zero at half of strike price', () => {
25
+ expect(
26
+ payoutCurve.getPayout(strikePrice / BigInt(2)).toNumber(),
27
+ ).to.be.equal(0);
28
+ });
29
+
30
+ it('should be correct at $30,000 settlement price', () => {
31
+ const settlementPrice = BigInt(30000);
32
+
33
+ expect(payoutCurve.getPayout(settlementPrice).toFixed(3)).to.be.eq(
34
+ (
35
+ 2 * Number(contractSize) -
36
+ (Number(contractSize) * Number(strikePrice)) /
37
+ Number(settlementPrice)
38
+ ).toFixed(3),
39
+ );
40
+ });
41
+
42
+ it('should be equal to totalCollateral at strike price', () => {
43
+ expect(payoutCurve.getPayout(strikePrice).toNumber()).to.equal(
44
+ Number(totalCollateral),
45
+ );
46
+ });
47
+ });
48
+
49
+ it('should serialize and deserialize properly', () => {
50
+ const payout = payoutCurve.getPayout(strikePrice);
51
+
52
+ const _tlv = payoutCurve.toPayoutCurvePiece().serialize();
53
+ const pf = HyperbolaPayoutCurvePiece.deserialize(_tlv);
54
+
55
+ const deserializedCurve = HyperbolaPayoutCurve.fromPayoutCurvePiece(pf);
56
+
57
+ expect(payout.toNumber()).to.be.eq(
58
+ deserializedCurve.getPayout(strikePrice).toNumber(),
59
+ );
60
+ });
61
+ });
62
+ });
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": true
5
+ },
6
+ "include": ["**/*.spec.ts"],
7
+ "exclude": []
8
+ }
@@ -0,0 +1,40 @@
1
+ // write tests for getPrecision and fromPrecision
2
+
3
+ import BigNumber from 'bignumber.js';
4
+ import { expect } from 'chai';
5
+
6
+ import { fromPrecision, getPrecision } from '../../lib/utils/Precision';
7
+
8
+ describe('getPrecision', () => {
9
+ it('should get correct precision for integers', () => {
10
+ const num = new BigNumber(1);
11
+ expect(getPrecision(num)).eq(0);
12
+ });
13
+
14
+ it('should get correct precision for multiple decimal points', () => {
15
+ const num = new BigNumber(1.123456789);
16
+ expect(getPrecision(num)).eq(1234567890000000);
17
+ });
18
+
19
+ it('should get correct precision for max decimal points', () => {
20
+ const num = new BigNumber('1.112233445566778899');
21
+ expect(getPrecision(num)).eq(1122334455667789);
22
+ });
23
+ });
24
+
25
+ describe('fromPrecision', () => {
26
+ it('should create correct number from precision', () => {
27
+ const num = 12345;
28
+ expect(fromPrecision(num).toFormat()).eq('0.0000000000012345');
29
+ });
30
+
31
+ it('should create correct number from precision for max precision', () => {
32
+ const num = 1122334455667788;
33
+ expect(fromPrecision(num).toFormat()).eq('0.1122334455667788');
34
+ });
35
+
36
+ it('should throw error if precision is too large', () => {
37
+ const num = Number('11223344556677889');
38
+ expect(() => fromPrecision(num)).to.throw(Error);
39
+ });
40
+ });
@@ -0,0 +1,224 @@
1
+ body, html {
2
+ margin:0; padding: 0;
3
+ height: 100%;
4
+ }
5
+ body {
6
+ font-family: Helvetica Neue, Helvetica, Arial;
7
+ font-size: 14px;
8
+ color:#333;
9
+ }
10
+ .small { font-size: 12px; }
11
+ *, *:after, *:before {
12
+ -webkit-box-sizing:border-box;
13
+ -moz-box-sizing:border-box;
14
+ box-sizing:border-box;
15
+ }
16
+ h1 { font-size: 20px; margin: 0;}
17
+ h2 { font-size: 14px; }
18
+ pre {
19
+ font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace;
20
+ margin: 0;
21
+ padding: 0;
22
+ -moz-tab-size: 2;
23
+ -o-tab-size: 2;
24
+ tab-size: 2;
25
+ }
26
+ a { color:#0074D9; text-decoration:none; }
27
+ a:hover { text-decoration:underline; }
28
+ .strong { font-weight: bold; }
29
+ .space-top1 { padding: 10px 0 0 0; }
30
+ .pad2y { padding: 20px 0; }
31
+ .pad1y { padding: 10px 0; }
32
+ .pad2x { padding: 0 20px; }
33
+ .pad2 { padding: 20px; }
34
+ .pad1 { padding: 10px; }
35
+ .space-left2 { padding-left:55px; }
36
+ .space-right2 { padding-right:20px; }
37
+ .center { text-align:center; }
38
+ .clearfix { display:block; }
39
+ .clearfix:after {
40
+ content:'';
41
+ display:block;
42
+ height:0;
43
+ clear:both;
44
+ visibility:hidden;
45
+ }
46
+ .fl { float: left; }
47
+ @media only screen and (max-width:640px) {
48
+ .col3 { width:100%; max-width:100%; }
49
+ .hide-mobile { display:none!important; }
50
+ }
51
+
52
+ .quiet {
53
+ color: #7f7f7f;
54
+ color: rgba(0,0,0,0.5);
55
+ }
56
+ .quiet a { opacity: 0.7; }
57
+
58
+ .fraction {
59
+ font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
60
+ font-size: 10px;
61
+ color: #555;
62
+ background: #E8E8E8;
63
+ padding: 4px 5px;
64
+ border-radius: 3px;
65
+ vertical-align: middle;
66
+ }
67
+
68
+ div.path a:link, div.path a:visited { color: #333; }
69
+ table.coverage {
70
+ border-collapse: collapse;
71
+ margin: 10px 0 0 0;
72
+ padding: 0;
73
+ }
74
+
75
+ table.coverage td {
76
+ margin: 0;
77
+ padding: 0;
78
+ vertical-align: top;
79
+ }
80
+ table.coverage td.line-count {
81
+ text-align: right;
82
+ padding: 0 5px 0 20px;
83
+ }
84
+ table.coverage td.line-coverage {
85
+ text-align: right;
86
+ padding-right: 10px;
87
+ min-width:20px;
88
+ }
89
+
90
+ table.coverage td span.cline-any {
91
+ display: inline-block;
92
+ padding: 0 5px;
93
+ width: 100%;
94
+ }
95
+ .missing-if-branch {
96
+ display: inline-block;
97
+ margin-right: 5px;
98
+ border-radius: 3px;
99
+ position: relative;
100
+ padding: 0 4px;
101
+ background: #333;
102
+ color: yellow;
103
+ }
104
+
105
+ .skip-if-branch {
106
+ display: none;
107
+ margin-right: 10px;
108
+ position: relative;
109
+ padding: 0 4px;
110
+ background: #ccc;
111
+ color: white;
112
+ }
113
+ .missing-if-branch .typ, .skip-if-branch .typ {
114
+ color: inherit !important;
115
+ }
116
+ .coverage-summary {
117
+ border-collapse: collapse;
118
+ width: 100%;
119
+ }
120
+ .coverage-summary tr { border-bottom: 1px solid #bbb; }
121
+ .keyline-all { border: 1px solid #ddd; }
122
+ .coverage-summary td, .coverage-summary th { padding: 10px; }
123
+ .coverage-summary tbody { border: 1px solid #bbb; }
124
+ .coverage-summary td { border-right: 1px solid #bbb; }
125
+ .coverage-summary td:last-child { border-right: none; }
126
+ .coverage-summary th {
127
+ text-align: left;
128
+ font-weight: normal;
129
+ white-space: nowrap;
130
+ }
131
+ .coverage-summary th.file { border-right: none !important; }
132
+ .coverage-summary th.pct { }
133
+ .coverage-summary th.pic,
134
+ .coverage-summary th.abs,
135
+ .coverage-summary td.pct,
136
+ .coverage-summary td.abs { text-align: right; }
137
+ .coverage-summary td.file { white-space: nowrap; }
138
+ .coverage-summary td.pic { min-width: 120px !important; }
139
+ .coverage-summary tfoot td { }
140
+
141
+ .coverage-summary .sorter {
142
+ height: 10px;
143
+ width: 7px;
144
+ display: inline-block;
145
+ margin-left: 0.5em;
146
+ background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
147
+ }
148
+ .coverage-summary .sorted .sorter {
149
+ background-position: 0 -20px;
150
+ }
151
+ .coverage-summary .sorted-desc .sorter {
152
+ background-position: 0 -10px;
153
+ }
154
+ .status-line { height: 10px; }
155
+ /* yellow */
156
+ .cbranch-no { background: yellow !important; color: #111; }
157
+ /* dark red */
158
+ .red.solid, .status-line.low, .low .cover-fill { background:#C21F39 }
159
+ .low .chart { border:1px solid #C21F39 }
160
+ .highlighted,
161
+ .highlighted .cstat-no, .highlighted .fstat-no, .highlighted .cbranch-no{
162
+ background: #C21F39 !important;
163
+ }
164
+ /* medium red */
165
+ .cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE }
166
+ /* light red */
167
+ .low, .cline-no { background:#FCE1E5 }
168
+ /* light green */
169
+ .high, .cline-yes { background:rgb(230,245,208) }
170
+ /* medium green */
171
+ .cstat-yes { background:rgb(161,215,106) }
172
+ /* dark green */
173
+ .status-line.high, .high .cover-fill { background:rgb(77,146,33) }
174
+ .high .chart { border:1px solid rgb(77,146,33) }
175
+ /* dark yellow (gold) */
176
+ .status-line.medium, .medium .cover-fill { background: #f9cd0b; }
177
+ .medium .chart { border:1px solid #f9cd0b; }
178
+ /* light yellow */
179
+ .medium { background: #fff4c2; }
180
+
181
+ .cstat-skip { background: #ddd; color: #111; }
182
+ .fstat-skip { background: #ddd; color: #111 !important; }
183
+ .cbranch-skip { background: #ddd !important; color: #111; }
184
+
185
+ span.cline-neutral { background: #eaeaea; }
186
+
187
+ .coverage-summary td.empty {
188
+ opacity: .5;
189
+ padding-top: 4px;
190
+ padding-bottom: 4px;
191
+ line-height: 1;
192
+ color: #888;
193
+ }
194
+
195
+ .cover-fill, .cover-empty {
196
+ display:inline-block;
197
+ height: 12px;
198
+ }
199
+ .chart {
200
+ line-height: 0;
201
+ }
202
+ .cover-empty {
203
+ background: white;
204
+ }
205
+ .cover-full {
206
+ border-right: none !important;
207
+ }
208
+ pre.prettyprint {
209
+ border: none !important;
210
+ padding: 0 !important;
211
+ margin: 0 !important;
212
+ }
213
+ .com { color: #999 !important; }
214
+ .ignore-none { color: #999; font-weight: normal; }
215
+
216
+ .wrapper {
217
+ min-height: 100%;
218
+ height: auto !important;
219
+ height: 100%;
220
+ margin: 0 auto -48px;
221
+ }
222
+ .footer, .push {
223
+ height: 48px;
224
+ }