@atomicfinance/bitcoin-wallet-provider 4.2.6 → 4.2.8

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 (226) hide show
  1. package/.turbo/turbo-build.log +4 -5
  2. package/CHANGELOG.md +24 -0
  3. package/package.json +7 -7
  4. package/.turbo/turbo-lint$colon$fix.log +0 -4
  5. package/.turbo/turbo-lint.log +0 -5
  6. package/.turbo/turbo-test.log +0 -0
  7. package/.yalc/@node-dlc/core/.nyc_output/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +0 -1
  8. package/.yalc/@node-dlc/core/.nyc_output/processinfo/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +0 -1
  9. package/.yalc/@node-dlc/core/.nyc_output/processinfo/index.json +0 -1
  10. package/.yalc/@node-dlc/core/README.md +0 -11
  11. package/.yalc/@node-dlc/core/__tests__/core.spec.ts +0 -7
  12. package/.yalc/@node-dlc/core/__tests__/dlc/CETCalculator.spec.ts +0 -1029
  13. package/.yalc/@node-dlc/core/__tests__/dlc/CoinSelect.spec.ts +0 -179
  14. package/.yalc/@node-dlc/core/__tests__/dlc/PolynomialPayoutCurve.spec.ts +0 -345
  15. package/.yalc/@node-dlc/core/__tests__/dlc/TxBuilder.spec.ts +0 -424
  16. package/.yalc/@node-dlc/core/__tests__/dlc/finance/Builder.spec.ts +0 -492
  17. package/.yalc/@node-dlc/core/__tests__/dlc/finance/CoveredCall.spec.ts +0 -112
  18. package/.yalc/@node-dlc/core/__tests__/dlc/finance/CsoInfo.spec.ts +0 -1124
  19. package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongCall.spec.ts +0 -55
  20. package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongPut.spec.ts +0 -55
  21. package/.yalc/@node-dlc/core/__tests__/dlc/finance/OptionInfo.spec.ts +0 -226
  22. package/.yalc/@node-dlc/core/__tests__/dlc/finance/ShortPut.spec.ts +0 -62
  23. package/.yalc/@node-dlc/core/__tests__/tsconfig.json +0 -8
  24. package/.yalc/@node-dlc/core/__tests__/utils/precision.spec.ts +0 -40
  25. package/.yalc/@node-dlc/core/coverage/lcov-report/base.css +0 -224
  26. package/.yalc/@node-dlc/core/coverage/lcov-report/block-navigation.js +0 -79
  27. package/.yalc/@node-dlc/core/coverage/lcov-report/favicon.png +0 -0
  28. package/.yalc/@node-dlc/core/coverage/lcov-report/index.html +0 -171
  29. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/AsyncProcessingQueue.ts.html +0 -269
  30. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Base32.ts.html +0 -86
  31. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BigIntUtils.ts.html +0 -86
  32. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BitField.ts.html +0 -86
  33. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ChannelId.ts.html +0 -86
  34. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedList.ts.html +0 -413
  35. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedListNode.ts.html +0 -122
  36. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Queue.ts.html +0 -188
  37. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelId.ts.html +0 -86
  38. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelIdUtils.ts.html +0 -107
  39. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CETCalculator.ts.html +0 -1430
  40. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CoinSelect.ts.html +0 -431
  41. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/HyperbolaPayoutCurve.ts.html +0 -644
  42. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/PolynomialPayoutCurve.ts.html +0 -878
  43. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxBuilder.ts.html +0 -1088
  44. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxFinalizer.ts.html +0 -731
  45. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/Builder.ts.html +0 -2270
  46. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CoveredCall.ts.html +0 -410
  47. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CsoInfo.ts.html +0 -1574
  48. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LinearPayout.ts.html +0 -362
  49. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongCall.ts.html +0 -302
  50. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongPut.ts.html +0 -302
  51. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/OptionInfo.ts.html +0 -626
  52. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/ShortPut.ts.html +0 -305
  53. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/index.html +0 -216
  54. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/index.html +0 -186
  55. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.html +0 -261
  56. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.ts.html +0 -278
  57. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelId.ts.html +0 -242
  58. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelKeys.ts.html +0 -407
  59. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentNumber.ts.html +0 -362
  60. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecret.ts.html +0 -203
  61. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecretStore.ts.html +0 -332
  62. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/Htlc.ts.html +0 -236
  63. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/HtlcDirection.ts.html +0 -131
  64. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ScriptFactory.ts.html +0 -530
  65. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/TxFactory.ts.html +0 -1094
  66. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/index.html +0 -231
  67. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/BigIntUtils.ts.html +0 -272
  68. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/Precision.ts.html +0 -149
  69. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/index.html +0 -126
  70. package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.css +0 -1
  71. package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.js +0 -2
  72. package/.yalc/@node-dlc/core/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  73. package/.yalc/@node-dlc/core/coverage/lcov-report/sorter.js +0 -170
  74. package/.yalc/@node-dlc/core/coverage/lcov.info +0 -2426
  75. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.d.ts +0 -22
  76. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js +0 -55
  77. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js.map +0 -1
  78. package/.yalc/@node-dlc/core/dist/Base32.d.ts +0 -1
  79. package/.yalc/@node-dlc/core/dist/Base32.js +0 -7
  80. package/.yalc/@node-dlc/core/dist/Base32.js.map +0 -1
  81. package/.yalc/@node-dlc/core/dist/BigIntUtils.d.ts +0 -1
  82. package/.yalc/@node-dlc/core/dist/BigIntUtils.js +0 -8
  83. package/.yalc/@node-dlc/core/dist/BigIntUtils.js.map +0 -1
  84. package/.yalc/@node-dlc/core/dist/BitField.d.ts +0 -1
  85. package/.yalc/@node-dlc/core/dist/BitField.js +0 -7
  86. package/.yalc/@node-dlc/core/dist/BitField.js.map +0 -1
  87. package/.yalc/@node-dlc/core/dist/ChannelId.d.ts +0 -1
  88. package/.yalc/@node-dlc/core/dist/ChannelId.js +0 -7
  89. package/.yalc/@node-dlc/core/dist/ChannelId.js.map +0 -1
  90. package/.yalc/@node-dlc/core/dist/LinkedList.d.ts +0 -30
  91. package/.yalc/@node-dlc/core/dist/LinkedList.js +0 -104
  92. package/.yalc/@node-dlc/core/dist/LinkedList.js.map +0 -1
  93. package/.yalc/@node-dlc/core/dist/LinkedListNode.d.ts +0 -9
  94. package/.yalc/@node-dlc/core/dist/LinkedListNode.js +0 -15
  95. package/.yalc/@node-dlc/core/dist/LinkedListNode.js.map +0 -1
  96. package/.yalc/@node-dlc/core/dist/Queue.d.ts +0 -22
  97. package/.yalc/@node-dlc/core/dist/Queue.js +0 -38
  98. package/.yalc/@node-dlc/core/dist/Queue.js.map +0 -1
  99. package/.yalc/@node-dlc/core/dist/ShortChannelId.d.ts +0 -1
  100. package/.yalc/@node-dlc/core/dist/ShortChannelId.js +0 -7
  101. package/.yalc/@node-dlc/core/dist/ShortChannelId.js.map +0 -1
  102. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.d.ts +0 -1
  103. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js +0 -12
  104. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js.map +0 -1
  105. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.d.ts +0 -50
  106. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js +0 -332
  107. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js.map +0 -1
  108. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.d.ts +0 -23
  109. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js +0 -77
  110. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js.map +0 -1
  111. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.d.ts +0 -20
  112. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js +0 -117
  113. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js.map +0 -1
  114. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.d.ts +0 -5
  115. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js +0 -3
  116. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js.map +0 -1
  117. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.d.ts +0 -52
  118. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js +0 -173
  119. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js.map +0 -1
  120. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.d.ts +0 -55
  121. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js +0 -217
  122. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js.map +0 -1
  123. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.d.ts +0 -40
  124. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js +0 -146
  125. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js.map +0 -1
  126. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.d.ts +0 -193
  127. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js +0 -422
  128. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js.map +0 -1
  129. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.d.ts +0 -13
  130. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js +0 -67
  131. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js.map +0 -1
  132. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.d.ts +0 -114
  133. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js +0 -290
  134. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js.map +0 -1
  135. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.d.ts +0 -6
  136. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js +0 -79
  137. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js.map +0 -1
  138. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.d.ts +0 -13
  139. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js +0 -47
  140. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js.map +0 -1
  141. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.d.ts +0 -13
  142. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js +0 -47
  143. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js.map +0 -1
  144. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.d.ts +0 -20
  145. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js +0 -101
  146. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js.map +0 -1
  147. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.d.ts +0 -12
  148. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js +0 -46
  149. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js.map +0 -1
  150. package/.yalc/@node-dlc/core/dist/index.d.ts +0 -39
  151. package/.yalc/@node-dlc/core/dist/index.js +0 -78
  152. package/.yalc/@node-dlc/core/dist/index.js.map +0 -1
  153. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.d.ts +0 -31
  154. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js +0 -52
  155. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js.map +0 -1
  156. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.d.ts +0 -55
  157. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js +0 -105
  158. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js.map +0 -1
  159. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.d.ts +0 -55
  160. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js +0 -76
  161. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js.map +0 -1
  162. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.d.ts +0 -26
  163. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js +0 -44
  164. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js.map +0 -1
  165. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.d.ts +0 -41
  166. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js +0 -79
  167. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js.map +0 -1
  168. package/.yalc/@node-dlc/core/dist/lightning/Htlc.d.ts +0 -46
  169. package/.yalc/@node-dlc/core/dist/lightning/Htlc.js +0 -46
  170. package/.yalc/@node-dlc/core/dist/lightning/Htlc.js.map +0 -1
  171. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.d.ts +0 -16
  172. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js +0 -21
  173. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js.map +0 -1
  174. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.d.ts +0 -76
  175. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js +0 -102
  176. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js.map +0 -1
  177. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.d.ts +0 -83
  178. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js +0 -222
  179. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js.map +0 -1
  180. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.d.ts +0 -9
  181. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js +0 -59
  182. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js.map +0 -1
  183. package/.yalc/@node-dlc/core/dist/utils/Precision.d.ts +0 -13
  184. package/.yalc/@node-dlc/core/dist/utils/Precision.js +0 -28
  185. package/.yalc/@node-dlc/core/dist/utils/Precision.js.map +0 -1
  186. package/.yalc/@node-dlc/core/lib/AsyncProcessingQueue.ts +0 -63
  187. package/.yalc/@node-dlc/core/lib/Base32.ts +0 -2
  188. package/.yalc/@node-dlc/core/lib/BigIntUtils.ts +0 -2
  189. package/.yalc/@node-dlc/core/lib/BitField.ts +0 -2
  190. package/.yalc/@node-dlc/core/lib/ChannelId.ts +0 -2
  191. package/.yalc/@node-dlc/core/lib/LinkedList.ts +0 -111
  192. package/.yalc/@node-dlc/core/lib/LinkedListNode.ts +0 -14
  193. package/.yalc/@node-dlc/core/lib/Queue.ts +0 -36
  194. package/.yalc/@node-dlc/core/lib/ShortChannelId.ts +0 -2
  195. package/.yalc/@node-dlc/core/lib/ShortChannelIdUtils.ts +0 -9
  196. package/.yalc/@node-dlc/core/lib/dlc/CETCalculator.ts +0 -450
  197. package/.yalc/@node-dlc/core/lib/dlc/CoinSelect.ts +0 -117
  198. package/.yalc/@node-dlc/core/lib/dlc/HyperbolaPayoutCurve.ts +0 -188
  199. package/.yalc/@node-dlc/core/lib/dlc/PayoutCurve.ts +0 -6
  200. package/.yalc/@node-dlc/core/lib/dlc/PolynomialPayoutCurve.ts +0 -266
  201. package/.yalc/@node-dlc/core/lib/dlc/TxBuilder.ts +0 -336
  202. package/.yalc/@node-dlc/core/lib/dlc/TxFinalizer.ts +0 -217
  203. package/.yalc/@node-dlc/core/lib/dlc/finance/Builder.ts +0 -730
  204. package/.yalc/@node-dlc/core/lib/dlc/finance/CoveredCall.ts +0 -110
  205. package/.yalc/@node-dlc/core/lib/dlc/finance/CsoInfo.ts +0 -498
  206. package/.yalc/@node-dlc/core/lib/dlc/finance/LinearPayout.ts +0 -94
  207. package/.yalc/@node-dlc/core/lib/dlc/finance/LongCall.ts +0 -74
  208. package/.yalc/@node-dlc/core/lib/dlc/finance/LongPut.ts +0 -74
  209. package/.yalc/@node-dlc/core/lib/dlc/finance/OptionInfo.ts +0 -182
  210. package/.yalc/@node-dlc/core/lib/dlc/finance/ShortPut.ts +0 -75
  211. package/.yalc/@node-dlc/core/lib/index.ts +0 -66
  212. package/.yalc/@node-dlc/core/lib/lightning/ChannelId.ts +0 -54
  213. package/.yalc/@node-dlc/core/lib/lightning/ChannelKeys.ts +0 -109
  214. package/.yalc/@node-dlc/core/lib/lightning/CommitmentNumber.ts +0 -94
  215. package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecret.ts +0 -41
  216. package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecretStore.ts +0 -84
  217. package/.yalc/@node-dlc/core/lib/lightning/Htlc.ts +0 -52
  218. package/.yalc/@node-dlc/core/lib/lightning/HtlcDirection.ts +0 -17
  219. package/.yalc/@node-dlc/core/lib/lightning/ScriptFactory.ts +0 -150
  220. package/.yalc/@node-dlc/core/lib/lightning/TxFactory.ts +0 -338
  221. package/.yalc/@node-dlc/core/lib/utils/BigIntUtils.ts +0 -64
  222. package/.yalc/@node-dlc/core/lib/utils/Precision.ts +0 -23
  223. package/.yalc/@node-dlc/core/package.json +0 -38
  224. package/.yalc/@node-dlc/core/tsconfig.json +0 -8
  225. package/.yalc/@node-dlc/core/yalc.sig +0 -1
  226. package/yalc.lock +0 -10
@@ -1,1124 +0,0 @@
1
- import { Value } from '@node-dlc/bitcoin';
2
- import {
3
- ContractDescriptorV1,
4
- ContractInfoV0,
5
- DigitDecompositionEventDescriptorV0,
6
- DlcOffer,
7
- OracleAnnouncement,
8
- OracleEvent,
9
- OracleInfoV0,
10
- PayoutFunctionV0,
11
- PolynomialPayoutCurvePiece,
12
- } from '@node-dlc/messaging';
13
- import { BitcoinNetworks } from 'bitcoin-networks';
14
- import { expect } from 'chai';
15
-
16
- import {
17
- buildCustomStrategyOrderOffer,
18
- buildRoundingIntervalsFromIntervals,
19
- DlcParty,
20
- dustThreshold,
21
- getFinalizerByCount,
22
- LinearPayout,
23
- roundDownToNearestMultiplier,
24
- roundUpToNearestMultiplier,
25
- } from '../../../lib';
26
- import {
27
- getCsoInfoFromContractInfo,
28
- getCsoInfoFromOffer,
29
- validateCsoPayoutFunction,
30
- } from '../../../lib/dlc/finance/CsoInfo';
31
-
32
- const buildOracleAnnouncement = (oracleDigits: number, expiry: Date) => {
33
- const eventDescriptor = new DigitDecompositionEventDescriptorV0();
34
- eventDescriptor.base = 2;
35
- eventDescriptor.isSigned = false;
36
- eventDescriptor.unit = 'bits';
37
- eventDescriptor.precision = 0;
38
- eventDescriptor.nbDigits = oracleDigits;
39
-
40
- const oracleEvent = new OracleEvent();
41
- oracleEvent.eventMaturityEpoch = Math.floor(expiry.getTime() / 1000);
42
- oracleEvent.eventDescriptor = eventDescriptor;
43
-
44
- const oracleAnnouncement = new OracleAnnouncement();
45
- oracleAnnouncement.oracleEvent = oracleEvent;
46
-
47
- return oracleAnnouncement;
48
- };
49
-
50
- const buildCsoDlcOfferFixture = (
51
- oracleDigits: number,
52
- expiry: Date,
53
- payoutFunction: PayoutFunctionV0,
54
- totalCollateral: bigint,
55
- offerCollateral: bigint,
56
- ): DlcOffer => {
57
- const oracleAnnouncement = buildOracleAnnouncement(oracleDigits, expiry);
58
-
59
- const oracleInfo = new OracleInfoV0();
60
- oracleInfo.announcement = oracleAnnouncement;
61
-
62
- const contractDescriptor = new ContractDescriptorV1();
63
- contractDescriptor.numDigits = oracleDigits;
64
- contractDescriptor.payoutFunction = payoutFunction;
65
-
66
- const contractInfo = new ContractInfoV0();
67
- contractInfo.totalCollateral = totalCollateral;
68
- contractInfo.contractDescriptor = contractDescriptor;
69
- contractInfo.oracleInfo = oracleInfo;
70
-
71
- const dlcOffer = new DlcOffer();
72
-
73
- // Set all required properties following DlcOffer.spec.ts pattern
74
- dlcOffer.contractFlags = Buffer.from('00', 'hex');
75
- dlcOffer.chainHash = Buffer.from(
76
- '06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f',
77
- 'hex',
78
- );
79
- dlcOffer.temporaryContractId = Buffer.from(
80
- '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
81
- 'hex',
82
- );
83
- dlcOffer.fundingPubkey = Buffer.from(
84
- '0327efea09ff4dfb13230e887cbab8821d5cc249c7ff28668c6633ff9f4b4c08e3',
85
- 'hex',
86
- );
87
- dlcOffer.payoutSpk = Buffer.from(
88
- '00142bbdec425007dc360523b0294d2c64d2213af498',
89
- 'hex',
90
- );
91
- dlcOffer.payoutSerialId = BigInt(11555292);
92
- dlcOffer.changeSpk = Buffer.from(
93
- '0014afa16f949f3055f38bd3a73312bed00b61558884',
94
- 'hex',
95
- );
96
- dlcOffer.changeSerialId = BigInt(2008045);
97
- dlcOffer.fundOutputSerialId = BigInt(5411962);
98
- dlcOffer.feeRatePerVb = BigInt(1);
99
- dlcOffer.cetLocktime = 100;
100
- dlcOffer.refundLocktime = 200;
101
-
102
- dlcOffer.contractInfo = contractInfo;
103
- dlcOffer.offerCollateral = offerCollateral;
104
-
105
- return dlcOffer;
106
- };
107
-
108
- describe('CsoInfo', () => {
109
- const minPayout = 60000000n;
110
- const maxPayout = 100000000n;
111
- const startOutcome = 800000n;
112
- const endOutcome = 1200000n;
113
- const offerCollateralValue = 80000000n;
114
-
115
- const oracleBase = 2;
116
- const oracleDigits = 21;
117
-
118
- const expiry = new Date(1620014750000);
119
-
120
- const maxGain = Value.fromBitcoin(0.2);
121
- const maxLoss = Value.fromBitcoin(0.2);
122
- const maxGainForContractSize = Value.fromBitcoin(0.2);
123
- const maxLossForContractSize = Value.fromBitcoin(0.2);
124
-
125
- const contractSize = Value.fromBitcoin(1);
126
- const totalCollateral = Value.fromBitcoin(1);
127
- const offerCollateral = Value.fromBitcoin(0.8);
128
-
129
- const network = BitcoinNetworks.bitcoin;
130
-
131
- const highestPrecisionRounding = Value.fromSats(10000);
132
- const highPrecisionRounding = Value.fromSats(25000);
133
- const mediumPrecisionRounding = Value.fromSats(100000);
134
- const lowPrecisionRounding = Value.fromSats(200000);
135
-
136
- const oracleAnnouncement = OracleAnnouncement.deserialize(
137
- Buffer.from(
138
- 'fdd824fd0344340d5e431a385a8bb3819c0410c749b2a11ae5bebdd363e2dc23af057c6cbd3fd097fffa8e6beef46cb02389fb6ef102d3653a281dda5ff0d6e3f4d42a14df6830bbf19aa3a986ed4e5640240b507901d6e03d6bbd71a281ed356a145516c655fdd822fd02de0015b4ced0696e0c7b8636b816e8742944cfd652f3366d659694add4d186da20f06e1750ce25afb96aee7aedbc5a3981b7e62a22baf768f94fe0ffd455cb6ccb4da1a07fadc76aada50705e583aa77b664f1217212d4537f9d5398630716cd26e5fcdba1a300388860a9f5feed894ca9d5caf9daffaca23f53fd46071f69007b286050e798293f7524223f1882667d5e282be7b09faada3179496630053a060c1af1d2c80d212dc871bf56a846a6b70cfca17b47d2fcb86e57cef165215f2a526cc40215c3c6002fbeb5f0a9d545379004fd108a8a5ee96ac0bd33d1495c609724e6554fe1bf90fe92e679df8883df6df9173e8c476b5e83493f55bf2e20e9c85acd21f7f710a9a380233fc28254077fb751c4ffbd5124639421cc05ae2e3886bbc29177c02ad5ab569b5a89c4dd5da2e131ab41ac4ce2347f5425230b8822198cd805047b1a35fa00cd3877fdc902857293f94fcad3f0e418448b0756e99ce6cc46d1a4cf8673823a89819a9bd9d4c3506975d37835a5310a1bee056887124b6d0fc0ae8974371e1e12e13d68f844878bd9fa51bfdb2455f6bb6c93e49998b37e4fa2b01ff31c665b16313015311007d624fe77df48ac69d8475ca06500d618fbff38ab6f50575d4b0fd3efe4fd6e561797070ec365ecda8a62e6dcb993b8eff16a2e5af7ad7b93cb6a028cdab351251e368c4f188d620ad86fa43886ee57f91be033feab89cd381c486b9cb9c102ae2d3d3cc15068ecb5e0822e8f5ff5a2faef2598308ec40acc4f122023722e8e6758034f98bb45136117154cb7690a2c04b9504a747ce3f69be7d29299462181fcf721d795233aacf010309af5b1709309cb5c2ceae7926ea0868b1c8a2573554284f86310d1df7ed82e6be49d417ec494da9f15f9fac757bdee7cb49c3e7fdcfabc28801bde8f90b90cf3eb37784bb91d9c35662b5f00fdd80a0e00020004626974730000000000152561746f6d69632d656e67696e652d6d6f6e74686c792d323646454232342d32364150523234',
139
- 'hex',
140
- ),
141
- );
142
-
143
- describe('CsoInfo from linear curve message', () => {
144
- const { payoutFunction } = LinearPayout.buildPayoutFunction(
145
- minPayout,
146
- maxPayout,
147
- startOutcome,
148
- endOutcome,
149
- oracleBase,
150
- oracleDigits,
151
- );
152
-
153
- const dlcOffer = buildCsoDlcOfferFixture(
154
- oracleDigits,
155
- expiry,
156
- payoutFunction,
157
- maxPayout,
158
- offerCollateralValue,
159
- );
160
-
161
- const contractInfo = dlcOffer.contractInfo;
162
-
163
- it('should get correct CsoInfo from ContractInfo', () => {
164
- const csoInfo = getCsoInfoFromContractInfo(
165
- contractInfo,
166
- 'neither',
167
- Value.fromSats(0),
168
- undefined,
169
- 'v0',
170
- );
171
-
172
- expect(csoInfo).to.deep.equal({
173
- normalizedMaxGain: maxGain,
174
- normalizedMaxLoss: maxLoss,
175
- maxGainForContractSize,
176
- maxLossForContractSize,
177
- minPayout,
178
- maxPayout,
179
- contractSize,
180
- offerCollateral,
181
- totalCollateral,
182
- expiry,
183
- });
184
- });
185
-
186
- it('should get correct CsoInfo from ContractInfo', () => {
187
- const csoInfo = getCsoInfoFromOffer(dlcOffer, 'v0');
188
-
189
- expect(csoInfo).to.deep.equal({
190
- normalizedMaxGain: maxGain,
191
- normalizedMaxLoss: maxLoss,
192
- maxGainForContractSize,
193
- maxLossForContractSize,
194
- minPayout,
195
- maxPayout,
196
- contractSize,
197
- offerCollateral,
198
- totalCollateral,
199
- expiry,
200
- });
201
- });
202
-
203
- it('should throw if offerCollateralSatoshis does not match calculated offerCollateral', () => {
204
- const { payoutFunction } = LinearPayout.buildPayoutFunction(
205
- minPayout,
206
- maxPayout,
207
- startOutcome,
208
- endOutcome,
209
- oracleBase,
210
- oracleDigits,
211
- );
212
-
213
- const dlcOffer = buildCsoDlcOfferFixture(
214
- oracleDigits,
215
- expiry,
216
- payoutFunction,
217
- maxPayout,
218
- offerCollateralValue,
219
- );
220
-
221
- dlcOffer.offerCollateral -= BigInt(10000);
222
-
223
- expect(() => getCsoInfoFromOffer(dlcOffer)).to.throw(Error);
224
- });
225
-
226
- it('should get correct CsoInfo from ContractInfo with fees shifted', () => {
227
- const contractSize = Value.fromBitcoin(1);
228
-
229
- const maxLoss = Value.fromBitcoin(0.2);
230
- const maxGain = Value.fromBitcoin(0.04);
231
-
232
- const feeRate = 10n;
233
-
234
- const highestPrecisionRounding = Value.fromSats(10000);
235
- const highPrecisionRounding = Value.fromSats(25000);
236
- const mediumPrecisionRounding = Value.fromSats(100000);
237
- const lowPrecisionRounding = Value.fromSats(200000);
238
-
239
- const roundingIntervals = buildRoundingIntervalsFromIntervals(
240
- contractSize,
241
- [
242
- { beginInterval: 0n, rounding: lowPrecisionRounding },
243
- { beginInterval: 750000n, rounding: mediumPrecisionRounding },
244
- { beginInterval: 850000n, rounding: highPrecisionRounding },
245
- { beginInterval: 950000n, rounding: highestPrecisionRounding },
246
- ],
247
- );
248
-
249
- const network = BitcoinNetworks.bitcoin;
250
-
251
- const shiftForFees: DlcParty = 'offeror';
252
- const fees = Value.fromSats(10000);
253
-
254
- const csoOrderOffer = buildCustomStrategyOrderOffer(
255
- oracleAnnouncement,
256
- contractSize,
257
- maxLoss,
258
- maxGain,
259
- feeRate,
260
- roundingIntervals,
261
- network,
262
- shiftForFees,
263
- fees,
264
- );
265
-
266
- const csoInfoFromContractInfo = getCsoInfoFromContractInfo(
267
- csoOrderOffer.contractInfo,
268
- shiftForFees,
269
- fees,
270
- );
271
- const csoInfoFromOffer = getCsoInfoFromOffer(csoOrderOffer);
272
-
273
- expect(csoInfoFromContractInfo.normalizedMaxGain.sats).to.equal(
274
- maxGain.sats,
275
- );
276
- expect(csoInfoFromContractInfo.normalizedMaxLoss.sats).to.equal(
277
- maxLoss.sats,
278
- );
279
-
280
- expect(csoInfoFromOffer.normalizedMaxGain.sats).to.equal(maxGain.sats);
281
- expect(csoInfoFromOffer.normalizedMaxLoss.sats).to.equal(maxLoss.sats);
282
- });
283
-
284
- it('should get correct ContractInfo with smaller max gain', () => {
285
- const contractSize = Value.fromBitcoin(1);
286
-
287
- const maxLoss = Value.fromBitcoin(0.95);
288
- const maxGain = Value.fromBitcoin(0.005);
289
-
290
- const feeRate = 10n;
291
-
292
- const highestPrecisionRounding = Value.fromSats(10000);
293
- const highPrecisionRounding = Value.fromSats(25000);
294
- const mediumPrecisionRounding = Value.fromSats(100000);
295
- const lowPrecisionRounding = Value.fromSats(200000);
296
-
297
- const roundingIntervals = buildRoundingIntervalsFromIntervals(
298
- contractSize,
299
- [
300
- { beginInterval: 0n, rounding: lowPrecisionRounding },
301
- { beginInterval: 750000n, rounding: mediumPrecisionRounding },
302
- { beginInterval: 850000n, rounding: highPrecisionRounding },
303
- { beginInterval: 950000n, rounding: highestPrecisionRounding },
304
- ],
305
- );
306
-
307
- const network = BitcoinNetworks.bitcoin;
308
-
309
- const shiftForFees: DlcParty = 'offeror';
310
- const fees = Value.fromSats(10000);
311
-
312
- const csoOrderOffer = buildCustomStrategyOrderOffer(
313
- oracleAnnouncement,
314
- contractSize,
315
- maxLoss,
316
- maxGain,
317
- feeRate,
318
- roundingIntervals,
319
- network,
320
- shiftForFees,
321
- fees,
322
- );
323
-
324
- const csoInfoFromContractInfo = getCsoInfoFromContractInfo(
325
- csoOrderOffer.contractInfo,
326
- shiftForFees,
327
- fees,
328
- );
329
- const csoInfoFromOffer = getCsoInfoFromOffer(csoOrderOffer);
330
-
331
- expect(csoInfoFromContractInfo.normalizedMaxGain.sats).to.equal(
332
- maxGain.sats,
333
- );
334
- expect(csoInfoFromContractInfo.normalizedMaxLoss.sats).to.equal(
335
- maxLoss.sats,
336
- );
337
-
338
- expect(csoInfoFromOffer.normalizedMaxGain.sats).to.equal(maxGain.sats);
339
- expect(csoInfoFromOffer.normalizedMaxLoss.sats).to.equal(maxLoss.sats);
340
- });
341
-
342
- it('should get correct CsoInfo from ContractInfo with fees shifted contract size 0.01', () => {
343
- const contractSize = Value.fromBitcoin(0.01);
344
-
345
- const maxLoss = Value.fromBitcoin(0.2);
346
- const maxGain = Value.fromBitcoin(0.04);
347
-
348
- const feeRate = 10n;
349
-
350
- const highestPrecisionRounding = Value.fromSats(10000);
351
- const highPrecisionRounding = Value.fromSats(25000);
352
- const mediumPrecisionRounding = Value.fromSats(100000);
353
- const lowPrecisionRounding = Value.fromSats(200000);
354
-
355
- const roundingIntervals = buildRoundingIntervalsFromIntervals(
356
- contractSize,
357
- [
358
- { beginInterval: 0n, rounding: lowPrecisionRounding },
359
- { beginInterval: 750000n, rounding: mediumPrecisionRounding },
360
- { beginInterval: 850000n, rounding: highPrecisionRounding },
361
- { beginInterval: 950000n, rounding: highestPrecisionRounding },
362
- ],
363
- );
364
-
365
- const network = BitcoinNetworks.bitcoin;
366
-
367
- const shiftForFees: DlcParty = 'neither';
368
- const fees = Value.fromSats(0);
369
-
370
- const csoOrderOffer = buildCustomStrategyOrderOffer(
371
- oracleAnnouncement,
372
- contractSize,
373
- maxLoss,
374
- maxGain,
375
- feeRate,
376
- roundingIntervals,
377
- network,
378
- shiftForFees,
379
- fees,
380
- );
381
-
382
- const csoInfoFromContractInfo = getCsoInfoFromContractInfo(
383
- csoOrderOffer.contractInfo,
384
- shiftForFees,
385
- fees,
386
- );
387
- const csoInfoFromOffer = getCsoInfoFromOffer(csoOrderOffer);
388
-
389
- expect(csoInfoFromContractInfo.normalizedMaxGain.sats).to.equal(
390
- maxGain.sats,
391
- );
392
- expect(csoInfoFromContractInfo.normalizedMaxLoss.sats).to.equal(
393
- maxLoss.sats,
394
- );
395
-
396
- expect(csoInfoFromOffer.normalizedMaxGain.sats).to.equal(maxGain.sats);
397
- expect(csoInfoFromOffer.normalizedMaxLoss.sats).to.equal(maxLoss.sats);
398
- });
399
-
400
- const fees = [0, 1116, 29384, 34, 245, 11293, 2223, 10410];
401
- const contractSizes = [0.01, 0.1, 0.5, 1, 2, 5, 10, 50];
402
-
403
- contractSizes.forEach((contractSizeNum) => {
404
- fees.forEach((fee) => {
405
- it(`should get correct CsoInfo from ContractInfo with fees shifted contract size ${contractSizeNum} and fee ${fee}`, () => {
406
- const contractSize = Value.fromBitcoin(contractSizeNum);
407
-
408
- // const eventDescriptor = new DigitDecompositionEventDescriptorV0();
409
- // eventDescriptor.base = 2;
410
- // eventDescriptor.isSigned = false;
411
- // eventDescriptor.unit = 'bits';
412
- // eventDescriptor.precision = 0;
413
- // eventDescriptor.nbDigits = oracleDigits;
414
-
415
- // const oracleEvent = new OracleEventV0();
416
- // oracleEvent.eventMaturityEpoch = Math.floor(expiry.getTime() / 1000);
417
- // oracleEvent.eventDescriptor = eventDescriptor;
418
-
419
- // const oracleAnnouncement = new OracleAnnouncementV0();
420
- // oracleAnnouncement.oracleEvent = oracleEvent;
421
-
422
- const maxLoss = Value.fromBitcoin(0.2);
423
- const maxGain = Value.fromBitcoin(0.04);
424
-
425
- const feeRate = 4n;
426
-
427
- const highestPrecisionRounding = Value.fromSats(10000);
428
- const highPrecisionRounding = Value.fromSats(25000);
429
- const mediumPrecisionRounding = Value.fromSats(100000);
430
- const lowPrecisionRounding = Value.fromSats(200000);
431
-
432
- const roundingIntervals = buildRoundingIntervalsFromIntervals(
433
- contractSize,
434
- [
435
- { beginInterval: 0n, rounding: lowPrecisionRounding },
436
- { beginInterval: 750000n, rounding: mediumPrecisionRounding },
437
- { beginInterval: 850000n, rounding: highPrecisionRounding },
438
- { beginInterval: 950000n, rounding: highestPrecisionRounding },
439
- ],
440
- );
441
-
442
- const network = BitcoinNetworks.bitcoin;
443
-
444
- const shiftForFees: DlcParty = 'acceptor';
445
- const fees = Value.fromSats(fee);
446
-
447
- const csoOrderOffer = buildCustomStrategyOrderOffer(
448
- oracleAnnouncement,
449
- contractSize,
450
- maxLoss,
451
- maxGain,
452
- feeRate,
453
- roundingIntervals,
454
- network,
455
- shiftForFees,
456
- fees,
457
- );
458
-
459
- const csoInfo = getCsoInfoFromOffer(csoOrderOffer);
460
-
461
- expect(csoInfo.normalizedMaxGain.sats).to.equal(maxGain.sats);
462
- expect(csoInfo.normalizedMaxLoss.sats).to.equal(maxLoss.sats);
463
- });
464
- });
465
- });
466
- });
467
-
468
- describe('validateCsoPayoutFunction', () => {
469
- it('should throw if event outcome is not an ascending line', () => {
470
- const startOutcome = 900000n;
471
- const endOutcome = 900000n;
472
-
473
- const { payoutFunction } = LinearPayout.buildPayoutFunction(
474
- minPayout,
475
- maxPayout,
476
- startOutcome,
477
- endOutcome,
478
- oracleBase,
479
- oracleDigits,
480
- );
481
-
482
- expect(() => validateCsoPayoutFunction(payoutFunction)).to.throw(Error);
483
- });
484
- });
485
-
486
- it('should throw if maxLoss to maxGain is not an ascending line', () => {
487
- const minPayout = 100000000n;
488
- const maxPayout = 100000000n;
489
-
490
- const { payoutFunction } = LinearPayout.buildPayoutFunction(
491
- minPayout,
492
- maxPayout,
493
- startOutcome,
494
- endOutcome,
495
- oracleBase,
496
- oracleDigits,
497
- );
498
-
499
- expect(() => validateCsoPayoutFunction(payoutFunction)).to.throw(Error);
500
- });
501
-
502
- it('should throw if Payout Function point outcome payout not continuous', () => {
503
- const { payoutFunction } = LinearPayout.buildPayoutFunction(
504
- minPayout,
505
- maxPayout,
506
- startOutcome,
507
- endOutcome,
508
- oracleBase,
509
- oracleDigits,
510
- );
511
-
512
- // Subtract 1 from outcomePayout to create gap in point outcome payout
513
- (payoutFunction.payoutFunctionPieces[0]
514
- .payoutCurvePiece as PolynomialPayoutCurvePiece).points[1].outcomePayout -= BigInt(
515
- 1,
516
- );
517
-
518
- expect(() => validateCsoPayoutFunction(payoutFunction)).to.throw(Error);
519
- });
520
-
521
- describe('CsoInfo collateral', () => {
522
- const oracleAnnouncement = OracleAnnouncement.deserialize(
523
- Buffer.from(
524
- 'fdd824fd0344340d5e431a385a8bb3819c0410c749b2a11ae5bebdd363e2dc23af057c6cbd3fd097fffa8e6beef46cb02389fb6ef102d3653a281dda5ff0d6e3f4d42a14df6830bbf19aa3a986ed4e5640240b507901d6e03d6bbd71a281ed356a145516c655fdd822fd02de0015b4ced0696e0c7b8636b816e8742944cfd652f3366d659694add4d186da20f06e1750ce25afb96aee7aedbc5a3981b7e62a22baf768f94fe0ffd455cb6ccb4da1a07fadc76aada50705e583aa77b664f1217212d4537f9d5398630716cd26e5fcdba1a300388860a9f5feed894ca9d5caf9daffaca23f53fd46071f69007b286050e798293f7524223f1882667d5e282be7b09faada3179496630053a060c1af1d2c80d212dc871bf56a846a6b70cfca17b47d2fcb86e57cef165215f2a526cc40215c3c6002fbeb5f0a9d545379004fd108a8a5ee96ac0bd33d1495c609724e6554fe1bf90fe92e679df8883df6df9173e8c476b5e83493f55bf2e20e9c85acd21f7f710a9a380233fc28254077fb751c4ffbd5124639421cc05ae2e3886bbc29177c02ad5ab569b5a89c4dd5da2e131ab41ac4ce2347f5425230b8822198cd805047b1a35fa00cd3877fdc902857293f94fcad3f0e418448b0756e99ce6cc46d1a4cf8673823a89819a9bd9d4c3506975d37835a5310a1bee056887124b6d0fc0ae8974371e1e12e13d68f844878bd9fa51bfdb2455f6bb6c93e49998b37e4fa2b01ff31c665b16313015311007d624fe77df48ac69d8475ca06500d618fbff38ab6f50575d4b0fd3efe4fd6e561797070ec365ecda8a62e6dcb993b8eff16a2e5af7ad7b93cb6a028cdab351251e368c4f188d620ad86fa43886ee57f91be033feab89cd381c486b9cb9c102ae2d3d3cc15068ecb5e0822e8f5ff5a2faef2598308ec40acc4f122023722e8e6758034f98bb45136117154cb7690a2c04b9504a747ce3f69be7d29299462181fcf721d795233aacf010309af5b1709309cb5c2ceae7926ea0868b1c8a2573554284f86310d1df7ed82e6be49d417ec494da9f15f9fac757bdee7cb49c3e7fdcfabc28801bde8f90b90cf3eb37784bb91d9c35662b5f00fdd80a0e00020004626974730000000000152561746f6d69632d656e67696e652d6d6f6e74686c792d323646454232342d32364150523234',
525
- 'hex',
526
- ),
527
- );
528
-
529
- const roundingIntervals = buildRoundingIntervalsFromIntervals(
530
- contractSize,
531
- [
532
- { beginInterval: 0n, rounding: lowPrecisionRounding },
533
- { beginInterval: 750000n, rounding: mediumPrecisionRounding },
534
- { beginInterval: 850000n, rounding: highPrecisionRounding },
535
- { beginInterval: 950000n, rounding: highestPrecisionRounding },
536
- ],
537
- );
538
-
539
- it('should get cso info from offer with contract size greater than collateral', () => {
540
- const contractSize = Value.fromBitcoin(0.03);
541
- const collateral = Value.fromBitcoin(0.01);
542
- const numOfferInputs = 3;
543
- const numContracts = 1;
544
-
545
- const normalizedMaxGain = Value.fromBitcoin(0.005);
546
- const normalizedMaxLoss = Value.fromBitcoin(0.04);
547
-
548
- const feePerByte = BigInt(100);
549
-
550
- const shiftForFees: DlcParty = 'offeror'; // 'offeror pays network fees
551
- const fees = Value.fromSats(
552
- getFinalizerByCount(feePerByte, numOfferInputs, 1, numContracts)
553
- .offerFees,
554
- );
555
-
556
- const skipValidation = false;
557
-
558
- const csoOrderOffer = buildCustomStrategyOrderOffer(
559
- oracleAnnouncement,
560
- contractSize,
561
- normalizedMaxLoss,
562
- normalizedMaxGain,
563
- feePerByte,
564
- roundingIntervals,
565
- network,
566
- shiftForFees,
567
- fees,
568
- collateral,
569
- numOfferInputs,
570
- numContracts,
571
- skipValidation,
572
- );
573
-
574
- getCsoInfoFromOffer(csoOrderOffer, 'v1');
575
- });
576
-
577
- it('should get cso info from offer with contract size equal to collateral with both v0 and v1', () => {
578
- const contractSize = Value.fromBitcoin(0.01);
579
- const collateral = Value.fromBitcoin(0.01);
580
- const numOfferInputs = 3;
581
- const numContracts = 1;
582
-
583
- const normalizedMaxGain = Value.fromBitcoin(0.005);
584
- const normalizedMaxLoss = Value.fromBitcoin(0.04);
585
-
586
- const feePerByte = BigInt(100);
587
-
588
- const shiftForFees: DlcParty = 'offeror'; // 'offeror pays network fees
589
- const fees = Value.fromSats(
590
- getFinalizerByCount(feePerByte, numOfferInputs, 1, numContracts)
591
- .offerFees,
592
- );
593
-
594
- const skipValidation = false;
595
-
596
- const csoOrderOffer = buildCustomStrategyOrderOffer(
597
- oracleAnnouncement,
598
- contractSize,
599
- normalizedMaxLoss,
600
- normalizedMaxGain,
601
- feePerByte,
602
- roundingIntervals,
603
- network,
604
- shiftForFees,
605
- fees,
606
- collateral,
607
- numOfferInputs,
608
- numContracts,
609
- skipValidation,
610
- );
611
-
612
- getCsoInfoFromOffer(csoOrderOffer, 'v0');
613
- getCsoInfoFromOffer(csoOrderOffer, 'v1');
614
- });
615
-
616
- describe('high leverage with high fees', () => {
617
- const contractSize = Value.fromBitcoin(0.36);
618
- const collateral = Value.fromBitcoin(0.02);
619
- const numOfferInputs = 5;
620
- const numContracts = 5;
621
-
622
- const normalizedMaxGain = Value.fromBitcoin(0.005);
623
- const normalizedMaxLoss = Value.fromBitcoin(0.04);
624
-
625
- const feePerByte = BigInt(450);
626
-
627
- const skipValidation = false;
628
-
629
- it('should build and decode shift for fees offeror', () => {
630
- const shiftForFees: DlcParty = 'offeror'; // 'offeror' pays network fees
631
- const fees = Value.fromSats(
632
- getFinalizerByCount(feePerByte, numOfferInputs, 3, numContracts)
633
- .acceptFees,
634
- );
635
-
636
- const csoOrderOffer = buildCustomStrategyOrderOffer(
637
- oracleAnnouncement,
638
- contractSize,
639
- normalizedMaxLoss,
640
- normalizedMaxGain,
641
- feePerByte,
642
- roundingIntervals,
643
- network,
644
- shiftForFees,
645
- fees,
646
- collateral,
647
- numOfferInputs,
648
- numContracts,
649
- skipValidation,
650
- );
651
-
652
- const {
653
- normalizedMaxGain: actualNormalizedMaxGain,
654
- normalizedMaxLoss: actualNormalizedMaxLoss,
655
- maxGainForContractSize: actualMaxGainForContractSize,
656
- maxLossForContractSize: actualMaxLossForContractSize,
657
- minPayout,
658
- maxPayout,
659
- contractSize: actualContractSize,
660
- offerCollateral: actualOfferCollateral,
661
- totalCollateral: actualTotalCollateral,
662
- } = getCsoInfoFromOffer(csoOrderOffer, 'v1');
663
-
664
- // Fees are very high, so use dust threshold for max gain
665
- const offerFees = Value.fromSats(
666
- getFinalizerByCount(feePerByte, numOfferInputs, 3, numContracts)
667
- .offerFees,
668
- );
669
- const expectedMaxGainForContractSize_ = offerFees.addn(
670
- Value.fromSats(dustThreshold(BigInt(feePerByte))),
671
- );
672
- const expectedMaxGainForContractSize = Value.fromSats(
673
- roundUpToNearestMultiplier(
674
- expectedMaxGainForContractSize_.sats,
675
- BigInt(100),
676
- ),
677
- );
678
-
679
- const expectedMaxLossForContractSize = Value.fromSats(
680
- roundUpToNearestMultiplier(
681
- (normalizedMaxLoss.sats * contractSize.sats) / BigInt(1e8),
682
- BigInt(100),
683
- ),
684
- );
685
-
686
- const expectedNormalizedMaxGain = Value.fromSats(
687
- roundDownToNearestMultiplier(
688
- (expectedMaxGainForContractSize.sats * BigInt(1e8)) /
689
- contractSize.sats,
690
- BigInt(100),
691
- ),
692
- );
693
-
694
- expect(actualMaxGainForContractSize.sats).to.equal(
695
- expectedMaxGainForContractSize.sats,
696
- );
697
- expect(actualMaxLossForContractSize.sats).to.equal(
698
- expectedMaxLossForContractSize.sats,
699
- );
700
- expect(actualNormalizedMaxLoss.sats).to.equal(normalizedMaxLoss.sats);
701
- expect(actualNormalizedMaxGain.sats).to.equal(
702
- expectedNormalizedMaxGain.sats,
703
- ); // TODO: Fix issue with this line
704
- expect(minPayout).to.equal(BigInt(121200));
705
- expect(maxPayout).to.equal(collateral.sats);
706
- expect(actualContractSize.sats).to.equal(contractSize.sats);
707
- expect(actualOfferCollateral.sats).to.equal(
708
- collateral.subn(expectedMaxGainForContractSize).sats,
709
- );
710
- expect(actualTotalCollateral.sats).to.equal(collateral.sats);
711
- });
712
-
713
- it('should build and decode shift for fees acceptor', () => {
714
- const shiftForFees: DlcParty = 'acceptor'; // 'acceptor' pays network fees
715
- const fees = Value.fromSats(
716
- getFinalizerByCount(feePerByte, numOfferInputs, 3, numContracts)
717
- .offerFees,
718
- );
719
-
720
- const csoOrderOffer = buildCustomStrategyOrderOffer(
721
- oracleAnnouncement,
722
- contractSize,
723
- normalizedMaxLoss,
724
- normalizedMaxGain,
725
- feePerByte,
726
- roundingIntervals,
727
- network,
728
- shiftForFees,
729
- fees,
730
- collateral,
731
- numOfferInputs,
732
- numContracts,
733
- skipValidation,
734
- );
735
-
736
- const {
737
- normalizedMaxGain: actualNormalizedMaxGain,
738
- normalizedMaxLoss: actualNormalizedMaxLoss,
739
- maxGainForContractSize: actualMaxGainForContractSize,
740
- maxLossForContractSize: actualMaxLossForContractSize,
741
- minPayout,
742
- maxPayout,
743
- contractSize: actualContractSize,
744
- offerCollateral: actualOfferCollateral,
745
- totalCollateral: actualTotalCollateral,
746
- } = getCsoInfoFromOffer(csoOrderOffer, 'v1');
747
-
748
- // Fees are very high, so use dust threshold for max gain
749
- const offerFees = Value.fromSats(
750
- getFinalizerByCount(feePerByte, numOfferInputs, 3, numContracts)
751
- .offerFees,
752
- );
753
- const expectedMaxGainForContractSize_ = offerFees.addn(
754
- Value.fromSats(dustThreshold(BigInt(feePerByte))),
755
- );
756
- const expectedMaxGainForContractSize = Value.fromSats(
757
- roundUpToNearestMultiplier(
758
- expectedMaxGainForContractSize_.sats,
759
- BigInt(100),
760
- ),
761
- );
762
-
763
- const expectedMaxLossForContractSize = Value.fromSats(
764
- roundUpToNearestMultiplier(
765
- (normalizedMaxLoss.sats * contractSize.sats) / BigInt(1e8),
766
- BigInt(100),
767
- ),
768
- );
769
-
770
- const expectedNormalizedMaxGain = Value.fromSats(
771
- roundDownToNearestMultiplier(
772
- (expectedMaxGainForContractSize.sats * BigInt(1e8)) /
773
- contractSize.sats,
774
- BigInt(100),
775
- ),
776
- );
777
-
778
- expect(actualNormalizedMaxGain.sats).to.equal(
779
- expectedNormalizedMaxGain.sats,
780
- );
781
- expect(actualNormalizedMaxLoss.sats).to.equal(normalizedMaxLoss.sats);
782
- expect(actualMaxGainForContractSize.sats).to.equal(
783
- expectedMaxGainForContractSize.sats,
784
- );
785
- expect(actualMaxLossForContractSize.sats).to.equal(
786
- expectedMaxLossForContractSize.sats,
787
- );
788
- expect(minPayout).to.equal(BigInt(121200));
789
- expect(maxPayout).to.equal(collateral.sats);
790
- expect(actualContractSize.sats).to.equal(contractSize.sats);
791
- expect(actualOfferCollateral.sats).to.equal(
792
- collateral.subn(expectedMaxGainForContractSize).sats,
793
- );
794
- expect(actualTotalCollateral.sats).to.equal(collateral.sats);
795
- });
796
-
797
- it('should build and decode shift for fees neither', () => {
798
- const shiftForFees: DlcParty = 'neither'; // both parties pay their fair share for network fees
799
- const fees = Value.fromSats(
800
- getFinalizerByCount(feePerByte, numOfferInputs, 3, numContracts)
801
- .offerFees,
802
- );
803
-
804
- const csoOrderOffer = buildCustomStrategyOrderOffer(
805
- oracleAnnouncement,
806
- contractSize,
807
- normalizedMaxLoss,
808
- normalizedMaxGain,
809
- feePerByte,
810
- roundingIntervals,
811
- network,
812
- shiftForFees,
813
- fees,
814
- collateral,
815
- numOfferInputs,
816
- numContracts,
817
- skipValidation,
818
- );
819
-
820
- const {
821
- normalizedMaxGain: actualNormalizedMaxGain,
822
- normalizedMaxLoss: actualNormalizedMaxLoss,
823
- maxGainForContractSize: actualMaxGainForContractSize,
824
- maxLossForContractSize: actualMaxLossForContractSize,
825
- minPayout,
826
- maxPayout,
827
- contractSize: actualContractSize,
828
- offerCollateral: actualOfferCollateral,
829
- totalCollateral: actualTotalCollateral,
830
- } = getCsoInfoFromOffer(csoOrderOffer, 'v1');
831
-
832
- // Fees are very high, so use dust threshold for max gain
833
- const offerFees = Value.fromSats(
834
- getFinalizerByCount(feePerByte, numOfferInputs, 3, numContracts)
835
- .offerFees,
836
- );
837
- const expectedMaxGainForContractSize_ = offerFees.addn(
838
- Value.fromSats(dustThreshold(BigInt(feePerByte))),
839
- );
840
- const expectedMaxGainForContractSize = Value.fromSats(
841
- roundUpToNearestMultiplier(
842
- expectedMaxGainForContractSize_.sats,
843
- BigInt(100),
844
- ),
845
- );
846
-
847
- const expectedMaxLossForContractSize = Value.fromSats(
848
- roundUpToNearestMultiplier(
849
- (normalizedMaxLoss.sats * contractSize.sats) / BigInt(1e8),
850
- BigInt(100),
851
- ),
852
- );
853
-
854
- const expectedNormalizedMaxGain = Value.fromSats(
855
- roundDownToNearestMultiplier(
856
- (expectedMaxGainForContractSize.sats * BigInt(1e8)) /
857
- contractSize.sats,
858
- BigInt(100),
859
- ),
860
- );
861
-
862
- expect(actualNormalizedMaxGain.sats).to.equal(
863
- expectedNormalizedMaxGain.sats,
864
- );
865
- expect(actualNormalizedMaxLoss.sats).to.equal(normalizedMaxLoss.sats);
866
- expect(actualMaxGainForContractSize.sats).to.equal(
867
- expectedMaxGainForContractSize.sats,
868
- );
869
- expect(actualMaxLossForContractSize.sats).to.equal(
870
- expectedMaxLossForContractSize.sats,
871
- );
872
- expect(minPayout).to.equal(BigInt(121200));
873
- expect(maxPayout).to.equal(collateral.sats);
874
- expect(actualContractSize.sats).to.equal(contractSize.sats);
875
- expect(actualOfferCollateral.sats).to.equal(
876
- collateral.subn(expectedMaxGainForContractSize).sats,
877
- );
878
- expect(actualTotalCollateral.sats).to.equal(collateral.sats);
879
- });
880
- });
881
-
882
- describe('high leverage with low fees', () => {
883
- const contractSize = Value.fromBitcoin(0.36);
884
- const collateral = Value.fromBitcoin(0.02);
885
- const numOfferInputs = 5;
886
- const numContracts = 5;
887
-
888
- const normalizedMaxGain = Value.fromBitcoin(0.005);
889
- const normalizedMaxLoss = Value.fromBitcoin(0.04);
890
-
891
- const feePerByte = BigInt(50);
892
-
893
- const skipValidation = false;
894
-
895
- it('should build and decode shift for fees offeror', () => {
896
- const shiftForFees: DlcParty = 'offeror'; // 'offeror' pays network fees
897
- const fees = Value.fromSats(
898
- getFinalizerByCount(feePerByte, numOfferInputs, 3, numContracts)
899
- .acceptFees,
900
- );
901
-
902
- const csoOrderOffer = buildCustomStrategyOrderOffer(
903
- oracleAnnouncement,
904
- contractSize,
905
- normalizedMaxLoss,
906
- normalizedMaxGain,
907
- feePerByte,
908
- roundingIntervals,
909
- network,
910
- shiftForFees,
911
- fees,
912
- collateral,
913
- numOfferInputs,
914
- numContracts,
915
- skipValidation,
916
- );
917
-
918
- const {
919
- normalizedMaxGain: actualNormalizedMaxGain,
920
- normalizedMaxLoss: actualNormalizedMaxLoss,
921
- maxGainForContractSize: actualMaxGainForContractSize,
922
- maxLossForContractSize: actualMaxLossForContractSize,
923
- minPayout,
924
- maxPayout,
925
- contractSize: actualContractSize,
926
- offerCollateral: actualOfferCollateral,
927
- totalCollateral: actualTotalCollateral,
928
- } = getCsoInfoFromOffer(csoOrderOffer, 'v1');
929
-
930
- const expectedMaxGainForContractSize = Value.fromSats(
931
- roundUpToNearestMultiplier(
932
- (normalizedMaxGain.sats * contractSize.sats) / BigInt(1e8),
933
- BigInt(100),
934
- ),
935
- );
936
-
937
- const expectedMaxLossForContractSize = Value.fromSats(
938
- roundUpToNearestMultiplier(
939
- (normalizedMaxLoss.sats * contractSize.sats) / BigInt(1e8),
940
- BigInt(100),
941
- ),
942
- );
943
-
944
- const expectedNormalizedMaxGain = Value.fromSats(
945
- roundUpToNearestMultiplier(
946
- (expectedMaxGainForContractSize.sats * BigInt(1e8)) /
947
- contractSize.sats,
948
- BigInt(100),
949
- ),
950
- );
951
-
952
- expect(actualNormalizedMaxGain.sats).to.equal(
953
- expectedNormalizedMaxGain.sats,
954
- );
955
- expect(actualNormalizedMaxLoss.sats).to.equal(normalizedMaxLoss.sats);
956
- expect(actualMaxGainForContractSize.sats).to.equal(
957
- expectedMaxGainForContractSize.sats,
958
- );
959
- expect(actualMaxLossForContractSize.sats).to.equal(
960
- expectedMaxLossForContractSize.sats,
961
- );
962
- expect(minPayout).to.equal(BigInt(380000));
963
- expect(maxPayout).to.equal(collateral.sats);
964
- expect(actualContractSize.sats).to.equal(contractSize.sats);
965
- expect(actualOfferCollateral.sats).to.equal(
966
- collateral.subn(expectedMaxGainForContractSize).sats,
967
- );
968
- expect(actualTotalCollateral.sats).to.equal(collateral.sats);
969
- });
970
-
971
- it('should build and decode shift for fees acceptor', () => {
972
- const shiftForFees: DlcParty = 'acceptor'; // 'acceptor' pays network fees
973
- const fees = Value.fromSats(
974
- getFinalizerByCount(feePerByte, numOfferInputs, 3, numContracts)
975
- .offerFees,
976
- );
977
-
978
- const csoOrderOffer = buildCustomStrategyOrderOffer(
979
- oracleAnnouncement,
980
- contractSize,
981
- normalizedMaxLoss,
982
- normalizedMaxGain,
983
- feePerByte,
984
- roundingIntervals,
985
- network,
986
- shiftForFees,
987
- fees,
988
- collateral,
989
- numOfferInputs,
990
- numContracts,
991
- skipValidation,
992
- );
993
-
994
- const {
995
- normalizedMaxGain: actualNormalizedMaxGain,
996
- normalizedMaxLoss: actualNormalizedMaxLoss,
997
- maxGainForContractSize: actualMaxGainForContractSize,
998
- maxLossForContractSize: actualMaxLossForContractSize,
999
- minPayout,
1000
- maxPayout,
1001
- contractSize: actualContractSize,
1002
- offerCollateral: actualOfferCollateral,
1003
- totalCollateral: actualTotalCollateral,
1004
- } = getCsoInfoFromOffer(csoOrderOffer, 'v1');
1005
-
1006
- const expectedMaxGainForContractSize = Value.fromSats(
1007
- roundUpToNearestMultiplier(
1008
- (normalizedMaxGain.sats * contractSize.sats) / BigInt(1e8),
1009
- BigInt(100),
1010
- ),
1011
- );
1012
-
1013
- const expectedMaxLossForContractSize = Value.fromSats(
1014
- roundUpToNearestMultiplier(
1015
- (normalizedMaxLoss.sats * contractSize.sats) / BigInt(1e8),
1016
- BigInt(100),
1017
- ),
1018
- );
1019
-
1020
- const expectedNormalizedMaxGain = Value.fromSats(
1021
- roundUpToNearestMultiplier(
1022
- (expectedMaxGainForContractSize.sats * BigInt(1e8)) /
1023
- contractSize.sats,
1024
- BigInt(100),
1025
- ),
1026
- );
1027
-
1028
- expect(actualNormalizedMaxGain.sats).to.equal(
1029
- expectedNormalizedMaxGain.sats,
1030
- );
1031
- expect(actualNormalizedMaxLoss.sats).to.equal(normalizedMaxLoss.sats);
1032
- expect(actualMaxGainForContractSize.sats).to.equal(
1033
- expectedMaxGainForContractSize.sats,
1034
- );
1035
- expect(actualMaxLossForContractSize.sats).to.equal(
1036
- expectedMaxLossForContractSize.sats,
1037
- );
1038
- expect(minPayout).to.equal(BigInt(380000));
1039
- expect(maxPayout).to.equal(collateral.sats);
1040
- expect(actualContractSize.sats).to.equal(contractSize.sats);
1041
- expect(actualOfferCollateral.sats).to.equal(
1042
- collateral.subn(expectedMaxGainForContractSize).sats,
1043
- );
1044
- expect(actualTotalCollateral.sats).to.equal(collateral.sats);
1045
- });
1046
-
1047
- it('should build and decode shift for fees neither', () => {
1048
- const shiftForFees: DlcParty = 'neither'; // both parties pay their fair share for network fees
1049
- const fees = Value.fromSats(
1050
- getFinalizerByCount(feePerByte, numOfferInputs, 3, numContracts)
1051
- .offerFees,
1052
- );
1053
-
1054
- const csoOrderOffer = buildCustomStrategyOrderOffer(
1055
- oracleAnnouncement,
1056
- contractSize,
1057
- normalizedMaxLoss,
1058
- normalizedMaxGain,
1059
- feePerByte,
1060
- roundingIntervals,
1061
- network,
1062
- shiftForFees,
1063
- fees,
1064
- collateral,
1065
- numOfferInputs,
1066
- numContracts,
1067
- skipValidation,
1068
- );
1069
-
1070
- const {
1071
- normalizedMaxGain: actualNormalizedMaxGain,
1072
- normalizedMaxLoss: actualNormalizedMaxLoss,
1073
- maxGainForContractSize: actualMaxGainForContractSize,
1074
- maxLossForContractSize: actualMaxLossForContractSize,
1075
- minPayout,
1076
- maxPayout,
1077
- contractSize: actualContractSize,
1078
- offerCollateral: actualOfferCollateral,
1079
- totalCollateral: actualTotalCollateral,
1080
- } = getCsoInfoFromOffer(csoOrderOffer, 'v1');
1081
-
1082
- const expectedMaxGainForContractSize = Value.fromSats(
1083
- roundUpToNearestMultiplier(
1084
- (normalizedMaxGain.sats * contractSize.sats) / BigInt(1e8),
1085
- BigInt(100),
1086
- ),
1087
- );
1088
-
1089
- const expectedMaxLossForContractSize = Value.fromSats(
1090
- roundUpToNearestMultiplier(
1091
- (normalizedMaxLoss.sats * contractSize.sats) / BigInt(1e8),
1092
- BigInt(100),
1093
- ),
1094
- );
1095
-
1096
- const expectedNormalizedMaxGain = Value.fromSats(
1097
- roundUpToNearestMultiplier(
1098
- (expectedMaxGainForContractSize.sats * BigInt(1e8)) /
1099
- contractSize.sats,
1100
- BigInt(100),
1101
- ),
1102
- );
1103
-
1104
- expect(actualNormalizedMaxGain.sats).to.equal(
1105
- expectedNormalizedMaxGain.sats,
1106
- );
1107
- expect(actualNormalizedMaxLoss.sats).to.equal(normalizedMaxLoss.sats);
1108
- expect(actualMaxGainForContractSize.sats).to.equal(
1109
- expectedMaxGainForContractSize.sats,
1110
- );
1111
- expect(actualMaxLossForContractSize.sats).to.equal(
1112
- expectedMaxLossForContractSize.sats,
1113
- );
1114
- expect(minPayout).to.equal(BigInt(380000));
1115
- expect(maxPayout).to.equal(collateral.sats);
1116
- expect(actualContractSize.sats).to.equal(contractSize.sats);
1117
- expect(actualOfferCollateral.sats).to.equal(
1118
- collateral.subn(expectedMaxGainForContractSize).sats,
1119
- );
1120
- expect(actualTotalCollateral.sats).to.equal(collateral.sats);
1121
- });
1122
- });
1123
- });
1124
- });