@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,1029 +0,0 @@
1
- import BigNumber from 'bignumber.js';
2
- import { expect } from 'chai';
3
-
4
- import {
5
- CETPayout,
6
- decompose,
7
- groupByIgnoringDigits,
8
- RoundingInterval,
9
- roundPayout,
10
- splitIntoRanges,
11
- } from '../../lib/dlc/CETCalculator';
12
- import { CoveredCall } from '../../lib/dlc/finance/CoveredCall';
13
- import { ShortPut } from '../../lib/dlc/finance/ShortPut';
14
- import { HyperbolaPayoutCurve } from '../../lib/dlc/HyperbolaPayoutCurve';
15
- import { BigIntMath } from '../../lib/utils/BigIntUtils';
16
-
17
- const decompositionTestCases: {
18
- decomposed: number[];
19
- composed: string;
20
- base: number;
21
- nbDigits: number;
22
- }[] = [
23
- {
24
- composed: '123456789',
25
- decomposed: [1, 2, 3, 4, 5, 6, 7, 8, 9],
26
- base: 10,
27
- nbDigits: 9,
28
- },
29
- {
30
- composed: '4321',
31
- decomposed: [1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1],
32
- base: 2,
33
- nbDigits: 13,
34
- },
35
- {
36
- composed: '0',
37
- decomposed: [0, 0, 0, 0],
38
- base: 8,
39
- nbDigits: 4,
40
- },
41
- {
42
- composed: '2',
43
- decomposed: [0, 2],
44
- base: 10,
45
- nbDigits: 2,
46
- },
47
- {
48
- composed: '1',
49
- decomposed: [1],
50
- base: 2,
51
- nbDigits: 1,
52
- },
53
- ];
54
-
55
- const groupingTestCases: {
56
- startIndex: bigint;
57
- endIndex: bigint;
58
- base: number;
59
- nbDigits: number;
60
- expected: number[][];
61
- }[] = [
62
- {
63
- startIndex: BigInt(123),
64
- endIndex: BigInt(123),
65
- base: 10,
66
- nbDigits: 3,
67
- expected: [[1, 2, 3]],
68
- },
69
- {
70
- startIndex: BigInt(171),
71
- endIndex: BigInt(210),
72
- base: 16,
73
- nbDigits: 2,
74
- expected: [
75
- [10, 11],
76
- [10, 12],
77
- [10, 13],
78
- [10, 14],
79
- [10, 15],
80
- [11],
81
- [12],
82
- [13, 0],
83
- [13, 1],
84
- [13, 2],
85
- ],
86
- },
87
- {
88
- startIndex: BigInt(73899),
89
- endIndex: BigInt(73938),
90
- base: 16,
91
- nbDigits: 6,
92
- expected: [
93
- [0, 1, 2, 0, 10, 11],
94
- [0, 1, 2, 0, 10, 12],
95
- [0, 1, 2, 0, 10, 13],
96
- [0, 1, 2, 0, 10, 14],
97
- [0, 1, 2, 0, 10, 15],
98
- [0, 1, 2, 0, 11],
99
- [0, 1, 2, 0, 12],
100
- [0, 1, 2, 0, 13, 0],
101
- [0, 1, 2, 0, 13, 1],
102
- [0, 1, 2, 0, 13, 2],
103
- ],
104
- },
105
- {
106
- startIndex: BigInt(1234),
107
- endIndex: BigInt(4321),
108
- base: 10,
109
- nbDigits: 4,
110
- expected: [
111
- [1, 2, 3, 4],
112
- [1, 2, 3, 5],
113
- [1, 2, 3, 6],
114
- [1, 2, 3, 7],
115
- [1, 2, 3, 8],
116
- [1, 2, 3, 9],
117
- [1, 2, 4],
118
- [1, 2, 5],
119
- [1, 2, 6],
120
- [1, 2, 7],
121
- [1, 2, 8],
122
- [1, 2, 9],
123
- [1, 3],
124
- [1, 4],
125
- [1, 5],
126
- [1, 6],
127
- [1, 7],
128
- [1, 8],
129
- [1, 9],
130
- [2],
131
- [3],
132
- [4, 0],
133
- [4, 1],
134
- [4, 2],
135
- [4, 3, 0],
136
- [4, 3, 1],
137
- [4, 3, 2, 0],
138
- [4, 3, 2, 1],
139
- ],
140
- },
141
- {
142
- startIndex: BigInt(1201234),
143
- endIndex: BigInt(1204321),
144
- base: 10,
145
- nbDigits: 8,
146
- expected: [
147
- [0, 1, 2, 0, 1, 2, 3, 4],
148
- [0, 1, 2, 0, 1, 2, 3, 5],
149
- [0, 1, 2, 0, 1, 2, 3, 6],
150
- [0, 1, 2, 0, 1, 2, 3, 7],
151
- [0, 1, 2, 0, 1, 2, 3, 8],
152
- [0, 1, 2, 0, 1, 2, 3, 9],
153
- [0, 1, 2, 0, 1, 2, 4],
154
- [0, 1, 2, 0, 1, 2, 5],
155
- [0, 1, 2, 0, 1, 2, 6],
156
- [0, 1, 2, 0, 1, 2, 7],
157
- [0, 1, 2, 0, 1, 2, 8],
158
- [0, 1, 2, 0, 1, 2, 9],
159
- [0, 1, 2, 0, 1, 3],
160
- [0, 1, 2, 0, 1, 4],
161
- [0, 1, 2, 0, 1, 5],
162
- [0, 1, 2, 0, 1, 6],
163
- [0, 1, 2, 0, 1, 7],
164
- [0, 1, 2, 0, 1, 8],
165
- [0, 1, 2, 0, 1, 9],
166
- [0, 1, 2, 0, 2],
167
- [0, 1, 2, 0, 3],
168
- [0, 1, 2, 0, 4, 0],
169
- [0, 1, 2, 0, 4, 1],
170
- [0, 1, 2, 0, 4, 2],
171
- [0, 1, 2, 0, 4, 3, 0],
172
- [0, 1, 2, 0, 4, 3, 1],
173
- [0, 1, 2, 0, 4, 3, 2, 0],
174
- [0, 1, 2, 0, 4, 3, 2, 1],
175
- ],
176
- },
177
- {
178
- startIndex: BigInt(2200),
179
- endIndex: BigInt(4999),
180
- base: 10,
181
- nbDigits: 4,
182
- expected: [
183
- [2, 2],
184
- [2, 3],
185
- [2, 4],
186
- [2, 5],
187
- [2, 6],
188
- [2, 7],
189
- [2, 8],
190
- [2, 9],
191
- [3],
192
- [4],
193
- ],
194
- },
195
- {
196
- startIndex: BigInt(0),
197
- endIndex: BigInt(99),
198
- base: 10,
199
- nbDigits: 2,
200
- expected: [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]],
201
- },
202
- {
203
- startIndex: BigInt(100),
204
- endIndex: BigInt(199),
205
- base: 10,
206
- nbDigits: 3,
207
- expected: [[1]],
208
- },
209
- {
210
- startIndex: BigInt(100),
211
- endIndex: BigInt(200),
212
- base: 10,
213
- nbDigits: 3,
214
- expected: [[1], [2, 0, 0]],
215
- },
216
- {
217
- startIndex: BigInt(11),
218
- endIndex: BigInt(18),
219
- base: 10,
220
- nbDigits: 2,
221
- expected: [
222
- [1, 1],
223
- [1, 2],
224
- [1, 3],
225
- [1, 4],
226
- [1, 5],
227
- [1, 6],
228
- [1, 7],
229
- [1, 8],
230
- ],
231
- },
232
- {
233
- startIndex: BigInt(11),
234
- endIndex: BigInt(23),
235
- base: 2,
236
- nbDigits: 5,
237
- expected: [
238
- [0, 1, 0, 1, 1],
239
- [0, 1, 1],
240
- [1, 0],
241
- ],
242
- },
243
- {
244
- startIndex: BigInt(5677),
245
- endIndex: BigInt(8621),
246
- base: 2,
247
- nbDigits: 14,
248
- expected: [
249
- [0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1],
250
- [0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1],
251
- [0, 1, 0, 1, 1, 0, 0, 0, 1, 1],
252
- [0, 1, 0, 1, 1, 0, 0, 1],
253
- [0, 1, 0, 1, 1, 0, 1],
254
- [0, 1, 0, 1, 1, 1],
255
- [0, 1, 1],
256
- [1, 0, 0, 0, 0, 0],
257
- [1, 0, 0, 0, 0, 1, 0],
258
- [1, 0, 0, 0, 0, 1, 1, 0, 0],
259
- [1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0],
260
- [1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0],
261
- [1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0],
262
- ],
263
- },
264
- ];
265
-
266
- describe('CETCalculator', () => {
267
- describe('outcome decomposition tests', () => {
268
- it('should properly decompose values', () => {
269
- for (const test of decompositionTestCases) {
270
- expect(
271
- decompose(BigInt(parseInt(test.composed)), test.base, test.nbDigits),
272
- ).deep.equal(test.decomposed);
273
- }
274
- });
275
- });
276
-
277
- describe('grouping tests', () => {
278
- it('should properly compute all groupings', () => {
279
- for (const test of groupingTestCases) {
280
- expect(
281
- groupByIgnoringDigits(
282
- test.startIndex,
283
- test.endIndex,
284
- test.base,
285
- test.nbDigits,
286
- ),
287
- ).deep.equal(test.expected);
288
- }
289
- });
290
- });
291
-
292
- describe('descending hyperbola a=1 d=5000 tests', () => {
293
- const hyperbola = new HyperbolaPayoutCurve(
294
- new BigNumber(1),
295
- new BigNumber(0),
296
- new BigNumber(0),
297
- new BigNumber(500000),
298
- new BigNumber(0),
299
- new BigNumber(0),
300
- true,
301
- );
302
-
303
- it('should properly split and round with one interval', () => {
304
- const roundingIntervals: RoundingInterval[] = [
305
- {
306
- beginInterval: BigInt(0),
307
- roundingMod: BigInt(10),
308
- },
309
- ];
310
-
311
- const totalCollateral = BigInt(100);
312
- const from = BigInt(0);
313
- const to = BigInt(999999);
314
- const fromPayout = totalCollateral;
315
- const toPayout = BigInt(0);
316
-
317
- const ranges = splitIntoRanges(
318
- from,
319
- to,
320
- fromPayout,
321
- toPayout,
322
- totalCollateral,
323
- hyperbola,
324
- roundingIntervals,
325
- );
326
-
327
- expect(ranges).deep.equal([
328
- { payout: BigInt(100), indexFrom: BigInt(0), indexTo: BigInt(5263) },
329
- { payout: BigInt(90), indexFrom: BigInt(5264), indexTo: BigInt(5882) },
330
- { payout: BigInt(80), indexFrom: BigInt(5883), indexTo: BigInt(6666) },
331
- { payout: BigInt(70), indexFrom: BigInt(6667), indexTo: BigInt(7692) },
332
- { payout: BigInt(60), indexFrom: BigInt(7693), indexTo: BigInt(9090) },
333
- { payout: BigInt(50), indexFrom: BigInt(9091), indexTo: BigInt(11111) },
334
- {
335
- payout: BigInt(40),
336
- indexFrom: BigInt(11112),
337
- indexTo: BigInt(14285),
338
- },
339
- {
340
- payout: BigInt(30),
341
- indexFrom: BigInt(14286),
342
- indexTo: BigInt(20000),
343
- },
344
- {
345
- payout: BigInt(20),
346
- indexFrom: BigInt(20001),
347
- indexTo: BigInt(33333),
348
- },
349
- {
350
- payout: BigInt(10),
351
- indexFrom: BigInt(33334),
352
- indexTo: BigInt(100000),
353
- },
354
- {
355
- payout: BigInt(0),
356
- indexFrom: BigInt(100001),
357
- indexTo: BigInt(999999),
358
- },
359
- ]);
360
-
361
- validateRanges(
362
- ranges,
363
- from,
364
- fromPayout,
365
- to,
366
- toPayout,
367
- hyperbola,
368
- roundingIntervals,
369
- totalCollateral,
370
- );
371
- });
372
-
373
- it('should properly split and round with non-even rounding mod', () => {
374
- const roundingIntervals: RoundingInterval[] = [
375
- {
376
- beginInterval: BigInt(0),
377
- roundingMod: BigInt(15),
378
- },
379
- ];
380
-
381
- const totalCollateral = BigInt(100);
382
- const from = BigInt(0);
383
- const to = BigInt(999999);
384
- const fromPayout = totalCollateral;
385
- const toPayout = BigInt(0);
386
-
387
- const ranges = splitIntoRanges(
388
- from,
389
- to,
390
- fromPayout,
391
- toPayout,
392
- totalCollateral,
393
- hyperbola,
394
- roundingIntervals,
395
- );
396
-
397
- expect(ranges).to.deep.equal([
398
- { payout: BigInt(100), indexFrom: BigInt(0), indexTo: BigInt(5128) },
399
- { payout: BigInt(90), indexFrom: BigInt(5129), indexTo: BigInt(6060) },
400
- { payout: BigInt(75), indexFrom: BigInt(6061), indexTo: BigInt(7407) },
401
- { payout: BigInt(60), indexFrom: BigInt(7408), indexTo: BigInt(9523) },
402
- { payout: BigInt(45), indexFrom: BigInt(9524), indexTo: BigInt(13333) },
403
- {
404
- payout: BigInt(30),
405
- indexFrom: BigInt(13334),
406
- indexTo: BigInt(22222),
407
- },
408
- {
409
- payout: BigInt(15),
410
- indexFrom: BigInt(22223),
411
- indexTo: BigInt(66666),
412
- },
413
- {
414
- payout: BigInt(0),
415
- indexFrom: BigInt(66667),
416
- indexTo: BigInt(999999),
417
- },
418
- ]);
419
-
420
- validateRanges(
421
- ranges,
422
- from,
423
- fromPayout,
424
- to,
425
- toPayout,
426
- hyperbola,
427
- roundingIntervals,
428
- totalCollateral,
429
- );
430
- });
431
- });
432
-
433
- describe('ascending hyperbola a=-1 d=500000 f2=100 tests', () => {
434
- const hyperbola = new HyperbolaPayoutCurve(
435
- new BigNumber(-1),
436
- new BigNumber(0),
437
- new BigNumber(0),
438
- new BigNumber(500000),
439
- new BigNumber(0),
440
- new BigNumber(100),
441
- true,
442
- );
443
-
444
- it('should properly split and round with one interval', () => {
445
- const roundingIntervals: RoundingInterval[] = [
446
- {
447
- beginInterval: BigInt(0),
448
- roundingMod: BigInt(10),
449
- },
450
- ];
451
-
452
- const totalCollateral = BigInt(100);
453
- const from = BigInt(0);
454
- const to = BigInt(999999);
455
- const fromPayout = BigInt(0);
456
- const toPayout = totalCollateral;
457
-
458
- const ranges = splitIntoRanges(
459
- from,
460
- to,
461
- fromPayout,
462
- toPayout,
463
- totalCollateral,
464
- hyperbola,
465
- roundingIntervals,
466
- );
467
-
468
- expect(ranges).to.deep.equal([
469
- { payout: BigInt(0), indexFrom: BigInt(0), indexTo: BigInt(5263) },
470
- { payout: BigInt(10), indexFrom: BigInt(5264), indexTo: BigInt(5882) },
471
- { payout: BigInt(20), indexFrom: BigInt(5883), indexTo: BigInt(6666) },
472
- { payout: BigInt(30), indexFrom: BigInt(6667), indexTo: BigInt(7692) },
473
- { payout: BigInt(40), indexFrom: BigInt(7693), indexTo: BigInt(9090) },
474
- { payout: BigInt(50), indexFrom: BigInt(9091), indexTo: BigInt(11111) },
475
- {
476
- payout: BigInt(60),
477
- indexFrom: BigInt(11112),
478
- indexTo: BigInt(14285),
479
- },
480
- {
481
- payout: BigInt(70),
482
- indexFrom: BigInt(14286),
483
- indexTo: BigInt(19999),
484
- },
485
- {
486
- payout: BigInt(80),
487
- indexFrom: BigInt(20000),
488
- indexTo: BigInt(33333),
489
- },
490
- {
491
- payout: BigInt(90),
492
- indexFrom: BigInt(33334),
493
- indexTo: BigInt(99999),
494
- },
495
- {
496
- payout: BigInt(100),
497
- indexFrom: BigInt(100000),
498
- indexTo: BigInt(999999),
499
- },
500
- ]);
501
-
502
- validateRanges(
503
- ranges,
504
- from,
505
- fromPayout,
506
- to,
507
- toPayout,
508
- hyperbola,
509
- roundingIntervals,
510
- totalCollateral,
511
- );
512
- });
513
-
514
- it('should properly split and round with multiple rounding intervals', () => {
515
- const roundingIntervals: RoundingInterval[] = [
516
- {
517
- beginInterval: BigInt(0),
518
- roundingMod: BigInt(7),
519
- },
520
- { beginInterval: BigInt(5432), roundingMod: BigInt(12) },
521
- { beginInterval: BigInt(6432), roundingMod: BigInt(25) },
522
- ];
523
-
524
- const totalCollateral = BigInt(100);
525
- const from = BigInt(0);
526
- const to = BigInt(999999);
527
- const fromPayout = BigInt(0);
528
- const toPayout = totalCollateral;
529
-
530
- const ranges = splitIntoRanges(
531
- from,
532
- to,
533
- fromPayout,
534
- toPayout,
535
- totalCollateral,
536
- hyperbola,
537
- roundingIntervals,
538
- );
539
-
540
- expect(ranges).to.deep.equal([
541
- { payout: BigInt(0), indexFrom: BigInt(0), indexTo: BigInt(5181) },
542
- { payout: BigInt(7), indexFrom: BigInt(5182), indexTo: BigInt(5431) },
543
- { payout: BigInt(12), indexFrom: BigInt(5432), indexTo: BigInt(6097) },
544
- { payout: BigInt(24), indexFrom: BigInt(6098), indexTo: BigInt(6431) },
545
- { payout: BigInt(25), indexFrom: BigInt(6432), indexTo: BigInt(7999) },
546
- { payout: BigInt(50), indexFrom: BigInt(8000), indexTo: BigInt(13333) },
547
- {
548
- payout: BigInt(75),
549
- indexFrom: BigInt(13334),
550
- indexTo: BigInt(39999),
551
- },
552
- {
553
- payout: BigInt(100),
554
- indexFrom: BigInt(40000),
555
- indexTo: BigInt(999999),
556
- },
557
- ]);
558
-
559
- validateRanges(
560
- ranges,
561
- from,
562
- fromPayout,
563
- to,
564
- toPayout,
565
- hyperbola,
566
- roundingIntervals,
567
- totalCollateral,
568
- );
569
- });
570
-
571
- it('should properly split and round with non-even rounding mod', () => {
572
- const roundingIntervals: RoundingInterval[] = [
573
- {
574
- beginInterval: BigInt(0),
575
- roundingMod: BigInt(15),
576
- },
577
- ];
578
-
579
- const totalCollateral = BigInt(100);
580
- const from = BigInt(0);
581
- const to = BigInt(999999);
582
- const fromPayout = BigInt(0);
583
- const toPayout = totalCollateral;
584
-
585
- const ranges = splitIntoRanges(
586
- from,
587
- to,
588
- fromPayout,
589
- toPayout,
590
- totalCollateral,
591
- hyperbola,
592
- roundingIntervals,
593
- );
594
-
595
- expect(ranges).to.deep.equal([
596
- { payout: BigInt(0), indexFrom: BigInt(0), indexTo: BigInt(5405) },
597
- { payout: BigInt(15), indexFrom: BigInt(5406), indexTo: BigInt(6451) },
598
- { payout: BigInt(30), indexFrom: BigInt(6452), indexTo: BigInt(7999) },
599
- { payout: BigInt(45), indexFrom: BigInt(8000), indexTo: BigInt(10526) },
600
- {
601
- payout: BigInt(60),
602
- indexFrom: BigInt(10527),
603
- indexTo: BigInt(15384),
604
- },
605
- {
606
- payout: BigInt(75),
607
- indexFrom: BigInt(15385),
608
- indexTo: BigInt(28571),
609
- },
610
- {
611
- payout: BigInt(90),
612
- indexFrom: BigInt(28572),
613
- indexTo: BigInt(199999),
614
- },
615
- {
616
- payout: BigInt(100),
617
- indexFrom: BigInt(200000),
618
- indexTo: BigInt(999999),
619
- },
620
- ]);
621
-
622
- validateRanges(
623
- ranges,
624
- from,
625
- fromPayout,
626
- to,
627
- toPayout,
628
- hyperbola,
629
- roundingIntervals,
630
- totalCollateral,
631
- );
632
- });
633
- });
634
-
635
- describe('large descending hyperbola a=1 d=5000000000000 tests (50k 1BTC covered call)', () => {
636
- const hyperbola = new HyperbolaPayoutCurve(
637
- new BigNumber(1),
638
- new BigNumber(0),
639
- new BigNumber(0),
640
- new BigNumber(5000000000000),
641
- new BigNumber(0),
642
- new BigNumber(0),
643
- true,
644
- );
645
-
646
- it('should properly split and round with one interval', () => {
647
- const roundingIntervals: RoundingInterval[] = [
648
- {
649
- beginInterval: BigInt(0),
650
- roundingMod: BigInt(100000),
651
- },
652
- ];
653
-
654
- const totalCollateral = BigInt(100000000);
655
- const from = BigInt(0);
656
- const to = BigInt(999999);
657
- const fromPayout = totalCollateral;
658
- const toPayout = BigInt(0);
659
-
660
- const ranges = splitIntoRanges(
661
- from,
662
- to,
663
- fromPayout,
664
- toPayout,
665
- totalCollateral,
666
- hyperbola,
667
- roundingIntervals,
668
- );
669
-
670
- validateRanges(
671
- ranges,
672
- from,
673
- fromPayout,
674
- to,
675
- toPayout,
676
- hyperbola,
677
- roundingIntervals,
678
- totalCollateral,
679
- );
680
- });
681
-
682
- it('should properly split and round with non-even rounding mod', () => {
683
- const roundingIntervals: RoundingInterval[] = [
684
- {
685
- beginInterval: BigInt(0),
686
- roundingMod: BigInt(150000),
687
- },
688
- ];
689
-
690
- const totalCollateral = BigInt(100000000);
691
- const from = BigInt(0);
692
- const to = BigInt(999999);
693
- const fromPayout = totalCollateral;
694
- const toPayout = BigInt(0);
695
-
696
- const ranges = splitIntoRanges(
697
- from,
698
- to,
699
- fromPayout,
700
- toPayout,
701
- totalCollateral,
702
- hyperbola,
703
- roundingIntervals,
704
- );
705
-
706
- validateRanges(
707
- ranges,
708
- from,
709
- fromPayout,
710
- to,
711
- toPayout,
712
- hyperbola,
713
- roundingIntervals,
714
- totalCollateral,
715
- );
716
- });
717
- });
718
-
719
- describe('descending hyperbola a=1 d=7500000000000 f2=-7500000 tests', () => {
720
- const hyperbola = new HyperbolaPayoutCurve(
721
- new BigNumber(1),
722
- new BigNumber(0),
723
- new BigNumber(0),
724
- new BigNumber(7500000000000),
725
- new BigNumber(0),
726
- new BigNumber(-7500008),
727
- true,
728
- );
729
-
730
- it('should properly split and round with one interval', () => {
731
- const roundingIntervals: RoundingInterval[] = [
732
- {
733
- beginInterval: BigInt(0),
734
- roundingMod: BigInt(250000),
735
- },
736
- ];
737
-
738
- const totalCollateral = BigInt(92499992);
739
- const from = BigInt(0);
740
- const to = BigInt(999999);
741
- const fromPayout = totalCollateral;
742
- const toPayout = BigInt(0);
743
-
744
- const ranges = splitIntoRanges(
745
- from,
746
- to,
747
- fromPayout,
748
- toPayout,
749
- totalCollateral,
750
- hyperbola,
751
- roundingIntervals,
752
- );
753
-
754
- validateRanges(
755
- ranges,
756
- from,
757
- fromPayout,
758
- to,
759
- toPayout,
760
- hyperbola,
761
- roundingIntervals,
762
- totalCollateral,
763
- );
764
- });
765
- });
766
-
767
- describe('descending hyperbola (31520 1BTC covered call)', () => {
768
- const {
769
- payoutCurve: hyperbola,
770
- totalCollateral,
771
- maxOutcome,
772
- } = CoveredCall.buildCurve(BigInt(31520), BigInt(1e8), 2, 17);
773
-
774
- it('should properly split and round with two intervals', () => {
775
- const roundingIntervals: RoundingInterval[] = [
776
- {
777
- beginInterval: BigInt(0),
778
- roundingMod: BigInt(1),
779
- },
780
- {
781
- beginInterval: BigInt(31520),
782
- roundingMod: BigInt(100000),
783
- },
784
- ];
785
-
786
- const from = BigInt(0);
787
- const to = maxOutcome;
788
- const fromPayout = totalCollateral;
789
- const toPayout = BigInt(0);
790
-
791
- const ranges = splitIntoRanges(
792
- from,
793
- to,
794
- fromPayout,
795
- toPayout,
796
- totalCollateral,
797
- hyperbola,
798
- roundingIntervals,
799
- );
800
-
801
- validateRanges(
802
- ranges,
803
- from,
804
- fromPayout,
805
- to,
806
- toPayout,
807
- hyperbola,
808
- roundingIntervals,
809
- totalCollateral,
810
- );
811
- });
812
- });
813
-
814
- describe('ascending hyperbola (31520 1BTC short put)', () => {
815
- const contractSize = BigInt(1e8);
816
- const totalCollateral = contractSize - BigInt(23213);
817
-
818
- const { payoutCurve: hyperbola, maxOutcome } = ShortPut.buildCurve(
819
- BigInt(31520),
820
- contractSize,
821
- totalCollateral,
822
- 2,
823
- 17,
824
- );
825
-
826
- it('should properly split and round with two intervals', () => {
827
- const roundingIntervals: RoundingInterval[] = [
828
- {
829
- beginInterval: BigInt(0),
830
- roundingMod: BigInt(100000),
831
- },
832
- {
833
- beginInterval: BigInt(31520),
834
- roundingMod: BigInt(1),
835
- },
836
- ];
837
-
838
- const from = BigInt(0);
839
- const to = maxOutcome;
840
- const fromPayout = BigInt(0);
841
- const toPayout = totalCollateral;
842
-
843
- const ranges = splitIntoRanges(
844
- from,
845
- to,
846
- fromPayout,
847
- toPayout,
848
- totalCollateral,
849
- hyperbola,
850
- roundingIntervals,
851
- );
852
-
853
- validateRanges(
854
- ranges,
855
- from,
856
- fromPayout,
857
- to,
858
- toPayout,
859
- hyperbola,
860
- roundingIntervals,
861
- totalCollateral,
862
- );
863
- });
864
- });
865
-
866
- describe('ascending hyperbola (62000 0.01 BTC short put)', () => {
867
- const contractSize = BigInt(1011502);
868
- const totalCollateral = BigInt(960926);
869
-
870
- const { payoutCurve: hyperbola, maxOutcome } = ShortPut.buildCurve(
871
- BigInt(62000),
872
- contractSize,
873
- totalCollateral,
874
- 2,
875
- 18,
876
- );
877
-
878
- it('should properly split and round with two intervals', () => {
879
- const roundingIntervals: RoundingInterval[] = [
880
- {
881
- beginInterval: BigInt(0),
882
- roundingMod: BigInt(1011),
883
- },
884
- {
885
- beginInterval: BigInt(62000),
886
- roundingMod: BigInt(1),
887
- },
888
- ];
889
-
890
- const from = BigInt(0);
891
- const to = maxOutcome;
892
- const fromPayout = BigInt(0);
893
- const toPayout = totalCollateral;
894
-
895
- const ranges = splitIntoRanges(
896
- from,
897
- to,
898
- fromPayout,
899
- toPayout,
900
- totalCollateral,
901
- hyperbola,
902
- roundingIntervals,
903
- );
904
-
905
- validateRanges(
906
- ranges,
907
- from,
908
- fromPayout,
909
- to,
910
- toPayout,
911
- hyperbola,
912
- roundingIntervals,
913
- totalCollateral,
914
- );
915
- });
916
-
917
- it('should properly split and round with many interval', () => {
918
- const roundingIntervals: RoundingInterval[] = [
919
- {
920
- beginInterval: BigInt(0),
921
- roundingMod: BigInt(1011),
922
- },
923
- {
924
- beginInterval: BigInt(32000),
925
- roundingMod: BigInt(4302),
926
- },
927
- {
928
- beginInterval: BigInt(32001),
929
- roundingMod: BigInt(1011),
930
- },
931
- {
932
- beginInterval: BigInt(34001),
933
- roundingMod: BigInt(7011),
934
- },
935
- {
936
- beginInterval: BigInt(62000),
937
- roundingMod: BigInt(1),
938
- },
939
- ];
940
-
941
- const from = BigInt(0);
942
- const to = maxOutcome;
943
- const fromPayout = BigInt(0);
944
- const toPayout = totalCollateral;
945
-
946
- const ranges = splitIntoRanges(
947
- from,
948
- to,
949
- fromPayout,
950
- toPayout,
951
- totalCollateral,
952
- hyperbola,
953
- roundingIntervals,
954
- );
955
-
956
- validateRanges(
957
- ranges,
958
- from,
959
- fromPayout,
960
- to,
961
- toPayout,
962
- hyperbola,
963
- roundingIntervals,
964
- totalCollateral,
965
- );
966
- });
967
- });
968
- });
969
-
970
- function validateRanges(
971
- ranges: CETPayout[],
972
- from: bigint,
973
- fromPayout: bigint,
974
- to: bigint,
975
- toPayout: bigint,
976
- hyperbola: HyperbolaPayoutCurve,
977
- roundingIntervals: RoundingInterval[],
978
- totalCollateral: bigint,
979
- ) {
980
- const reversedIntervals = [...roundingIntervals].reverse();
981
-
982
- // for each rounded payout at indexTo, expect to be equal to range payout
983
- ranges.forEach((range) => {
984
- if (range.indexFrom === from || range.indexTo === from)
985
- return expect(range.payout).to.be.eq(fromPayout);
986
- if (range.indexFrom === to || range.indexTo === to)
987
- return expect(range.payout).to.be.eq(toPayout);
988
-
989
- const payout = hyperbola.getPayout(range.indexTo);
990
- const roundingIndex = reversedIntervals.findIndex(
991
- (interval) => interval.beginInterval <= range.indexTo,
992
- );
993
- const rounding =
994
- roundingIndex !== -1
995
- ? reversedIntervals[roundingIndex].roundingMod
996
- : BigInt(1);
997
- const roundedPayout = BigIntMath.clamp(
998
- BigInt(0),
999
- roundPayout(payout, rounding),
1000
- totalCollateral,
1001
- );
1002
-
1003
- expect(range.payout).to.eq(roundedPayout);
1004
- });
1005
-
1006
- // for each rounded payout at indexFrom, expect to be equal to range payout
1007
- ranges.forEach((range) => {
1008
- if (range.indexFrom === from || range.indexTo === from)
1009
- return expect(range.payout).to.be.eq(fromPayout);
1010
- if (range.indexFrom === to || range.indexTo === to)
1011
- return expect(range.payout).to.be.eq(toPayout);
1012
-
1013
- const payout = hyperbola.getPayout(range.indexFrom);
1014
- const roundingIndex = reversedIntervals.findIndex(
1015
- (interval) => interval.beginInterval <= range.indexTo,
1016
- );
1017
- const rounding =
1018
- roundingIndex !== -1
1019
- ? reversedIntervals[roundingIndex].roundingMod
1020
- : BigInt(1);
1021
- const roundedPayout = BigIntMath.clamp(
1022
- BigInt(0),
1023
- roundPayout(payout, rounding),
1024
- totalCollateral,
1025
- );
1026
-
1027
- expect(roundedPayout).to.eq(range.payout);
1028
- });
1029
- }