@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,179 +0,0 @@
1
- import { Value } from '@node-dlc/bitcoin';
2
- import { expect } from 'chai';
3
-
4
- import { dualFees, dualFundingCoinSelect, UTXO } from '../../lib';
5
-
6
- const getUtxos = (totalCollateral: bigint, numUtxos = 1) => {
7
- const utxos: UTXO[] = [];
8
-
9
- for (let i = 0; i < numUtxos; i++) {
10
- utxos.push({
11
- address: 'bcrt1qjzut0906d9sk4hml4k6sz6cssljktf4c7yl80f',
12
- txid: 'c7bf12ac16aba1cf6c7769117294853453f7da3006363dfe4e8979847e32f7e1',
13
- value: Math.ceil(Number(totalCollateral) / numUtxos),
14
- vout: Math.floor(Math.random() * 11), // random integer between 0 and 10
15
- });
16
- }
17
-
18
- return utxos;
19
- };
20
-
21
- describe('CoinSelect', () => {
22
- describe('dualFundingCoinSelect', () => {
23
- it('should select coins correctly for 5 UTXOs and feeRate 450', () => {
24
- const feeRate = BigInt(450);
25
- const numUtxos = 5;
26
- const totalCollateral = Value.fromBitcoin(0.01);
27
- const offerCollateral = Value.fromBitcoin(0.0075);
28
-
29
- const utxos = getUtxos(totalCollateral.sats, numUtxos);
30
-
31
- const { fee, inputs } = dualFundingCoinSelect(
32
- utxos,
33
- [offerCollateral.sats],
34
- feeRate,
35
- );
36
-
37
- expect(fee).to.equal(BigInt(217350));
38
- expect(inputs.length).to.equal(5);
39
- });
40
-
41
- it('should fail to select coins if fee is greater than sum of utxos', () => {
42
- const feeRate = BigInt(450);
43
- const numUtxos = 5;
44
- const totalCollateral = Value.fromBitcoin(0.01);
45
- const offerCollateral = Value.fromBitcoin(0.096);
46
-
47
- const utxos = getUtxos(totalCollateral.sats, numUtxos);
48
-
49
- const { fee, inputs } = dualFundingCoinSelect(
50
- utxos,
51
- [offerCollateral.sats],
52
- feeRate,
53
- );
54
-
55
- expect(fee).to.equal(BigInt(94950));
56
- expect(inputs.length).to.equal(0);
57
- });
58
-
59
- it('should fail to select coins if detrimental input', () => {
60
- const feeRate = BigInt(450);
61
- const numUtxos = 1;
62
- const totalCollateral = Value.fromSats(30000);
63
- const offerCollateral = Value.fromSats(20000);
64
-
65
- const utxos = getUtxos(totalCollateral.sats, numUtxos);
66
-
67
- const { fee, inputs } = dualFundingCoinSelect(
68
- utxos,
69
- [offerCollateral.sats],
70
- feeRate,
71
- );
72
-
73
- expect(fee).to.equal(BigInt(94950));
74
- expect(inputs.length).to.equal(0);
75
- });
76
-
77
- it('should prioritize utxo selection', () => {
78
- const feeRate = BigInt(450);
79
- const numUtxos = 5;
80
- const totalCollateral = Value.fromBitcoin(0.01);
81
- const offerCollateral = Value.fromBitcoin(0.0075);
82
-
83
- const utxos = getUtxos(totalCollateral.sats, numUtxos);
84
-
85
- utxos.push({
86
- address: 'bcrt1qjzut0906d9sk4hml4k6sz6cssljktf4c7yl80f',
87
- txid:
88
- 'c7bf12ac16aba1cf6c7769117294853453f7da3006363dfe4e8979847e32f7e1',
89
- value: 10000,
90
- vout: Math.floor(Math.random() * 11), // random integer between 0 and 10
91
- });
92
-
93
- const { fee, inputs } = dualFundingCoinSelect(
94
- utxos,
95
- [offerCollateral.sats],
96
- feeRate,
97
- );
98
-
99
- expect(fee).to.equal(BigInt(217350));
100
- expect(inputs.length).to.equal(5);
101
- });
102
- });
103
-
104
- describe('Additional CoinSelect Tests', () => {
105
- const feeRate = BigInt(450);
106
- const totalCollateral = Value.fromBitcoin(0.01);
107
- const offerCollateral = Value.fromBitcoin(0.0075);
108
-
109
- it('should fail to select coins when all UTXOs are detrimental due to high fee rate', () => {
110
- const highFeeRate = BigInt(10000); // An exaggerated fee rate to make the point
111
- const utxos = getUtxos(totalCollateral.sats, 5);
112
-
113
- const { fee, inputs } = dualFundingCoinSelect(
114
- utxos,
115
- [offerCollateral.sats],
116
- highFeeRate,
117
- );
118
-
119
- expect(inputs.length).to.equal(0);
120
- expect(fee).to.equal(BigInt(2110000));
121
- });
122
-
123
- it('should select all UTXOs when they are just enough to cover collateral and fees', () => {
124
- const utxos = getUtxos(totalCollateral.sats, 5);
125
-
126
- const { fee, inputs } = dualFundingCoinSelect(
127
- utxos,
128
- [offerCollateral.sats],
129
- feeRate,
130
- );
131
-
132
- expect(inputs.length).to.equal(5);
133
- expect(fee).to.equal(BigInt(217350));
134
- });
135
-
136
- it('should select UTXOs optimally from a mixed set', () => {
137
- const mixedUtxos = [
138
- ...getUtxos(Value.fromBitcoin(0.005).sats, 2), // smaller UTXOs
139
- ...getUtxos(Value.fromBitcoin(0.02).sats, 3), // larger UTXOs
140
- ];
141
-
142
- const { fee, inputs } = dualFundingCoinSelect(
143
- mixedUtxos,
144
- [offerCollateral.sats],
145
- feeRate,
146
- );
147
-
148
- // Expecting it to select fewer, larger UTXOs over many small ones
149
- expect(inputs.length).to.be.lessThan(5);
150
- expect(fee).to.equal(BigInt(125550));
151
- });
152
-
153
- it('should handle an empty array of UTXOs correctly', () => {
154
- const { fee, inputs } = dualFundingCoinSelect(
155
- [],
156
- [offerCollateral.sats],
157
- feeRate,
158
- );
159
-
160
- expect(inputs.length).to.equal(0);
161
- expect(fee).to.equal(dualFees(feeRate, 1, 1)); // The fee for an attempt with no inputs
162
- });
163
-
164
- it('should select fewer UTXOs with a very low fee rate', () => {
165
- const lowFeeRate = BigInt(1); // An extremely low fee rate
166
- const utxos = getUtxos(totalCollateral.sats, 10); // More UTXOs than needed
167
-
168
- const { fee, inputs } = dualFundingCoinSelect(
169
- utxos,
170
- [offerCollateral.sats],
171
- lowFeeRate,
172
- );
173
-
174
- // Expecting it to select fewer UTXOs due to the low cost of adding an input
175
- expect(inputs.length).to.be.lessThan(10);
176
- expect(fee).to.equal(BigInt(687));
177
- });
178
- });
179
- });
@@ -1,345 +0,0 @@
1
- import {
2
- MessageType,
3
- PayoutFunction,
4
- PolynomialPayoutCurvePiece,
5
- RoundingIntervals,
6
- } from '@node-dlc/messaging';
7
- import BigNumber from 'bignumber.js';
8
- import { expect } from 'chai';
9
-
10
- import { HyperbolaPayoutCurve } from '../../lib';
11
- import { LinearPayout } from '../../lib/dlc/finance/LinearPayout';
12
- import { PolynomialPayoutCurve } from '../../lib/dlc/PolynomialPayoutCurve';
13
- import { fromPrecision } from '../../lib/utils/Precision';
14
-
15
- describe('PolynomialPayoutCurve', () => {
16
- const points = [
17
- {
18
- outcome: new BigNumber(1),
19
- payout: new BigNumber(1),
20
- },
21
- {
22
- outcome: new BigNumber(2),
23
- payout: new BigNumber(3),
24
- },
25
- ];
26
-
27
- describe('#constructor', () => {
28
- it('should create a PolynomialPayoutCurve', () => {
29
- const curve = new PolynomialPayoutCurve(points);
30
- expect(curve).to.be.instanceOf(PolynomialPayoutCurve);
31
- });
32
- it('should fail if not 2 points', () => {
33
- // 1 point
34
- expect(
35
- () =>
36
- new PolynomialPayoutCurve([
37
- {
38
- outcome: new BigNumber(1),
39
- payout: new BigNumber(1),
40
- },
41
- ]),
42
- ).to.throw('Must have two points');
43
-
44
- // 3 points
45
- expect(
46
- () =>
47
- new PolynomialPayoutCurve([
48
- {
49
- outcome: new BigNumber(1),
50
- payout: new BigNumber(1),
51
- },
52
- {
53
- outcome: new BigNumber(2),
54
- payout: new BigNumber(2),
55
- },
56
- {
57
- outcome: new BigNumber(3),
58
- payout: new BigNumber(3),
59
- },
60
- ]),
61
- ).to.throw;
62
- });
63
- });
64
-
65
- describe('#getPayout', () => {
66
- it('should get the payout for an outcome', () => {
67
- const curve = new PolynomialPayoutCurve(points);
68
- const payout = curve.getPayout(BigInt(1));
69
- expect(payout).to.deep.equal(new BigNumber(1));
70
- });
71
-
72
- it('should get the payout for an outcome', () => {
73
- const curve = new PolynomialPayoutCurve(points);
74
- const payout = curve.getPayout(BigInt(2));
75
- expect(payout).to.deep.equal(new BigNumber(3));
76
- });
77
- });
78
-
79
- describe('#getOutcomeForPayout', () => {
80
- it('should get the outcome for a payout', () => {
81
- const curve = new PolynomialPayoutCurve(points);
82
- const outcome = curve.getOutcomeForPayout(new BigNumber(1));
83
- expect(outcome).to.deep.equal(BigInt(1));
84
- });
85
-
86
- it('should get the outcome for a payout', () => {
87
- const curve = new PolynomialPayoutCurve(points);
88
- const outcome = curve.getOutcomeForPayout(new BigNumber(3));
89
- expect(outcome).to.deep.equal(BigInt(2));
90
- });
91
- });
92
-
93
- describe('#toPayoutCurvePiece', () => {
94
- it('should serialize to a PolynomialPayoutCurvePiece', () => {
95
- const curve = new PolynomialPayoutCurve(points);
96
- const piece = curve.toPayoutCurvePiece();
97
- expect(piece).to.deep.equal({
98
- type: MessageType.PolynomialPayoutCurvePiece,
99
- payoutCurvePieceType: 0, // PayoutCurvePieceType.Polynomial
100
- points: [
101
- {
102
- eventOutcome: BigInt(1),
103
- outcomePayout: BigInt(1),
104
- extraPrecision: 0,
105
- },
106
- {
107
- eventOutcome: BigInt(2),
108
- outcomePayout: BigInt(3),
109
- extraPrecision: 0,
110
- },
111
- ],
112
- });
113
- });
114
- });
115
-
116
- describe('#fromPayoutCurvePiece', () => {
117
- const points = [
118
- {
119
- eventOutcome: BigInt(1),
120
- outcomePayout: BigInt(1),
121
- extraPrecision: 0,
122
- },
123
- {
124
- eventOutcome: BigInt(2),
125
- outcomePayout: BigInt(3),
126
- extraPrecision: 0,
127
- },
128
- ];
129
-
130
- it('should deserialize from a PolynomialPayoutCurvePiece', () => {
131
- const piece = new PolynomialPayoutCurvePiece();
132
- piece.points = points;
133
- const curve = PolynomialPayoutCurve.fromPayoutCurvePiece(piece);
134
- expect(curve).to.be.instanceOf(PolynomialPayoutCurve);
135
- expect(curve['points']).to.deep.eq(
136
- points.map((p) => ({
137
- outcome: new BigNumber(p.eventOutcome.toString()),
138
- payout: new BigNumber(p.outcomePayout.toString()).plus(
139
- fromPrecision(p.extraPrecision),
140
- ),
141
- })),
142
- );
143
- });
144
- });
145
-
146
- describe('#equals', () => {
147
- it('should return true if the curves are equal', () => {
148
- const curve1 = new PolynomialPayoutCurve(points);
149
- const curve2 = new PolynomialPayoutCurve(points);
150
- expect(curve1.equals(curve2)).to.be.true;
151
- });
152
-
153
- it('should return false if the curves are not equal', () => {
154
- const curve1 = new PolynomialPayoutCurve(points);
155
- const curve2 = new PolynomialPayoutCurve([
156
- {
157
- outcome: new BigNumber(1),
158
- payout: new BigNumber(1),
159
- },
160
- {
161
- outcome: new BigNumber(3),
162
- payout: new BigNumber(3),
163
- },
164
- ]);
165
- expect(curve1.equals(curve2)).to.be.false;
166
- });
167
- });
168
-
169
- describe('#computePayouts', () => {
170
- it('should compute the correct payouts for simple interval', () => {
171
- const numDigits = 18;
172
- const oracleBase = 2;
173
- const minPayout = 40n;
174
- const maxPayout = 60n;
175
- const startOutcome = 40n;
176
- const endOutcome = 60n;
177
-
178
- const { payoutFunction } = LinearPayout.buildPayoutFunction(
179
- minPayout,
180
- maxPayout,
181
- startOutcome,
182
- endOutcome,
183
- oracleBase,
184
- numDigits,
185
- );
186
-
187
- const intervals = [{ beginInterval: 0n, roundingMod: 1n }];
188
- const roundingIntervals = new RoundingIntervals();
189
- roundingIntervals.intervals = intervals;
190
-
191
- const payouts = PolynomialPayoutCurve.computePayouts(
192
- payoutFunction,
193
- maxPayout,
194
- roundingIntervals,
195
- );
196
-
197
- const n = payouts.length - 1;
198
-
199
- const maxOutcome = BigInt(
200
- new BigNumber(oracleBase).pow(numDigits).minus(1).toString(10),
201
- );
202
-
203
- expect(n).to.eq(20);
204
-
205
- // max loss CETS
206
- expect(payouts[0].indexFrom).to.eq(0n);
207
- expect(payouts[0].indexTo).to.eq(startOutcome);
208
- expect(payouts[0].payout).to.eq(minPayout);
209
-
210
- // payout curve CETS
211
- for (let i = 1; i < n - 1; ++i) {
212
- expect(payouts[i].indexFrom).to.eq(startOutcome + BigInt(i));
213
- expect(payouts[i].indexTo).to.eq(startOutcome + BigInt(i));
214
- expect(payouts[i].payout).to.eq(minPayout + BigInt(i));
215
- }
216
-
217
- // max gain CETS
218
- expect(payouts[n].indexFrom).to.eq(endOutcome);
219
- expect(payouts[n].indexTo).to.eq(maxOutcome);
220
- expect(payouts[n].payout).to.eq(maxPayout);
221
- });
222
-
223
- it('should compute the correct payouts for advanced interval', () => {
224
- const numDigits = 18;
225
- const oracleBase = 2;
226
- const minPayout = 40n;
227
- const maxPayout = 60n;
228
- const startOutcome = 40n;
229
- const endOutcome = 60n;
230
-
231
- const { payoutFunction } = LinearPayout.buildPayoutFunction(
232
- minPayout,
233
- maxPayout,
234
- startOutcome,
235
- endOutcome,
236
- oracleBase,
237
- numDigits,
238
- );
239
-
240
- const intervals = [{ beginInterval: 0n, roundingMod: 2n }];
241
- const roundingIntervals = new RoundingIntervals();
242
- roundingIntervals.intervals = intervals;
243
-
244
- const payouts = PolynomialPayoutCurve.computePayouts(
245
- payoutFunction,
246
- maxPayout,
247
- roundingIntervals,
248
- );
249
-
250
- const n = payouts.length - 1;
251
-
252
- const maxOutcome = BigInt(
253
- new BigNumber(oracleBase).pow(numDigits).minus(1).toString(10),
254
- );
255
-
256
- expect(n).to.eq(10);
257
-
258
- // max loss CETS
259
- expect(payouts[0].indexFrom).to.eq(0n);
260
- expect(payouts[0].indexTo).to.eq(startOutcome);
261
- expect(payouts[0].payout).to.eq(minPayout);
262
-
263
- // payout curve CETS
264
- for (let i = 1; i < n; ++i) {
265
- expect(payouts[i].indexFrom).to.eq(
266
- startOutcome + 2n * BigInt(i - 1) + 1n,
267
- );
268
- expect(payouts[i].indexTo).to.eq(startOutcome + 2n * BigInt(i));
269
- expect(payouts[i].payout).to.eq(minPayout + 2n * BigInt(i));
270
- }
271
-
272
- // max gain CETS
273
- expect(payouts[n].indexFrom).to.eq(endOutcome - 1n);
274
- expect(payouts[n].indexTo).to.eq(maxOutcome);
275
- expect(payouts[n].payout).to.eq(maxPayout);
276
- });
277
-
278
- it('should fail if < 1 payout function pieces', () => {
279
- const maxPayout = 60n;
280
-
281
- const payoutFunction = new PayoutFunction();
282
- payoutFunction.payoutFunctionPieces = [];
283
- payoutFunction.lastEndpoint = {
284
- eventOutcome: BigInt(0),
285
- outcomePayout: BigInt(0),
286
- extraPrecision: 0,
287
- };
288
-
289
- const intervals = [{ beginInterval: 0n, roundingMod: 1n }];
290
- const roundingIntervals = new RoundingIntervals();
291
- roundingIntervals.intervals = intervals;
292
-
293
- expect(() => {
294
- PolynomialPayoutCurve.computePayouts(
295
- payoutFunction,
296
- maxPayout,
297
- roundingIntervals,
298
- );
299
- }).to.throw('Must have at least one piece');
300
- });
301
-
302
- it('should fail if there is a non-polynomial payout curve piece', () => {
303
- const maxPayout = 60n;
304
-
305
- const hyperbola = new HyperbolaPayoutCurve(
306
- new BigNumber(1),
307
- new BigNumber(0),
308
- new BigNumber(0),
309
- new BigNumber(500000),
310
- new BigNumber(0),
311
- new BigNumber(0),
312
- true,
313
- ).toPayoutCurvePiece();
314
-
315
- const payoutFunction = new PayoutFunction();
316
- payoutFunction.payoutFunctionPieces = [
317
- {
318
- endPoint: {
319
- eventOutcome: 2n,
320
- outcomePayout: 2n,
321
- extraPrecision: 0,
322
- },
323
- payoutCurvePiece: hyperbola,
324
- },
325
- ];
326
- payoutFunction.lastEndpoint = {
327
- eventOutcome: 0n,
328
- outcomePayout: 0n,
329
- extraPrecision: 0,
330
- };
331
-
332
- const intervals = [{ beginInterval: 0n, roundingMod: 1n }];
333
- const roundingIntervals = new RoundingIntervals();
334
- roundingIntervals.intervals = intervals;
335
-
336
- expect(() => {
337
- PolynomialPayoutCurve.computePayouts(
338
- payoutFunction,
339
- maxPayout,
340
- roundingIntervals,
341
- );
342
- }).to.throw('Payout curve piece must be a polynomial');
343
- });
344
- });
345
- });