@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,110 +0,0 @@
1
- import { PayoutFunction } from '@node-dlc/messaging';
2
- import BN from 'bignumber.js';
3
-
4
- import { toBigInt } from '../../utils/BigIntUtils';
5
- import { HyperbolaPayoutCurve } from '../HyperbolaPayoutCurve';
6
-
7
- const buildCurve = (
8
- strikePrice: bigint,
9
- contractSize: bigint,
10
- oracleBase: number,
11
- oracleDigits: number,
12
- ): {
13
- maxOutcome: bigint;
14
- totalCollateral: bigint;
15
- payoutCurve: HyperbolaPayoutCurve;
16
- } => {
17
- const a = new BN(1);
18
- const b = new BN(0);
19
- const c = new BN(0);
20
- const d = new BN((strikePrice * contractSize).toString());
21
-
22
- const f_1 = new BN(0);
23
- const _f_2 = new BN(0);
24
-
25
- const _tempHyperbolaPayoutCurve = new HyperbolaPayoutCurve(
26
- a,
27
- b,
28
- c,
29
- d,
30
- f_1,
31
- _f_2,
32
- );
33
-
34
- const maxOutcome = BigInt(
35
- new BN(oracleBase).pow(oracleDigits).minus(1).toString(10),
36
- );
37
- const maxOutcomePayout = _tempHyperbolaPayoutCurve
38
- .getPayout(maxOutcome)
39
- .integerValue();
40
-
41
- return {
42
- maxOutcome,
43
- totalCollateral: contractSize - toBigInt(maxOutcomePayout),
44
- payoutCurve: new HyperbolaPayoutCurve(
45
- a,
46
- b,
47
- c,
48
- d,
49
- f_1,
50
- maxOutcomePayout.negated(),
51
- ),
52
- };
53
- };
54
-
55
- const buildPayoutFunction = (
56
- strikePrice: bigint,
57
- contractSize: bigint,
58
- oracleBase: number,
59
- oracleDigits: number,
60
- ): { payoutFunction: PayoutFunction; totalCollateral: bigint } => {
61
- const { maxOutcome, totalCollateral, payoutCurve } = buildCurve(
62
- strikePrice,
63
- contractSize,
64
- oracleBase,
65
- oracleDigits,
66
- );
67
-
68
- const payoutFunction = new PayoutFunction();
69
-
70
- // Defensive fix: ensure payoutFunctionPieces is initialized as an array
71
- if (!payoutFunction.payoutFunctionPieces) {
72
- payoutFunction.payoutFunctionPieces = [];
73
- }
74
-
75
- const curvePiece = payoutCurve.toPayoutCurvePiece();
76
-
77
- // Set the left and right endpoints for the hyperbola piece (matching rust-dlc structure)
78
- curvePiece.leftEndPoint = {
79
- eventOutcome: BigInt(0),
80
- outcomePayout: totalCollateral,
81
- extraPrecision: 0,
82
- };
83
- curvePiece.rightEndPoint = {
84
- eventOutcome: maxOutcome,
85
- outcomePayout: BigInt(0),
86
- extraPrecision: 0,
87
- };
88
-
89
- payoutFunction.payoutFunctionPieces.push({
90
- endPoint: {
91
- eventOutcome: maxOutcome,
92
- outcomePayout: BigInt(0),
93
- extraPrecision: 0,
94
- },
95
- payoutCurvePiece: curvePiece,
96
- });
97
-
98
- payoutFunction.lastEndpoint = {
99
- eventOutcome: maxOutcome,
100
- outcomePayout: BigInt(0),
101
- extraPrecision: 0,
102
- };
103
-
104
- return {
105
- payoutFunction,
106
- totalCollateral,
107
- };
108
- };
109
-
110
- export const CoveredCall = { buildCurve, buildPayoutFunction };
@@ -1,498 +0,0 @@
1
- import { Value } from '@node-dlc/bitcoin';
2
- import {
3
- ContractDescriptorType,
4
- ContractInfo,
5
- ContractInfoType,
6
- DigitDecompositionEventDescriptor,
7
- MessageType,
8
- MultiOracleInfo,
9
- NumericalDescriptor,
10
- OrderPositionInfo,
11
- PayoutCurvePieceType,
12
- PayoutFunction,
13
- PolynomialPayoutCurvePiece,
14
- SingleContractInfo,
15
- SingleOracleInfo,
16
- } from '@node-dlc/messaging';
17
- import assert from 'assert';
18
- import Decimal from 'decimal.js';
19
-
20
- import {
21
- DlcParty,
22
- roundToNearestMultiplier,
23
- roundUpToNearestMultiplier,
24
- UNIT_MULTIPLIER,
25
- } from './Builder';
26
- import { HasContractInfo, HasOfferCollateral, HasType } from './OptionInfo';
27
-
28
- export interface CsoInfo {
29
- normalizedMaxGain: Value; // Max Gain Relative to 1 BTC Contract
30
- normalizedMaxLoss: Value; // Max Loss Relative to 1 BTC Contract
31
- maxGainForContractSize: Value; // Max Gain Relative to Contract Size
32
- maxLossForContractSize: Value; // Max Loss Relative to Contract Size
33
- minPayout: bigint;
34
- maxPayout: bigint;
35
- contractSize: Value;
36
- offerCollateral: Value;
37
- totalCollateral: Value;
38
- expiry: Date;
39
- }
40
-
41
- export interface CsoInfoParams {
42
- normalizedMaxGain: Value; // Max Gain Relative to 1 BTC Contract
43
- normalizedMaxLoss: Value; // Max Loss Relative to 1 BTC Contract
44
- maxGainForContractSize: Value; // Max Gain Relative to Contract Size
45
- maxLossForContractSize: Value; // Max Loss Relative to Contract Size
46
- offerCollateral: Value; // Offer Collateral
47
- }
48
-
49
- const ONE_BTC_CONTRACT = Value.fromBitcoin(1);
50
-
51
- export type MaybeHasPositionInfo = {
52
- positionInfo?: OrderPositionInfo;
53
- };
54
-
55
- /**
56
- * getCsoInfoParamsFromContractInfo V0
57
- *
58
- * Old getCsoInfoParamsFromContractInfo implementation
59
- *
60
- * @param {Value} contractSize - The size of the contract in terms of value.
61
- * @param {Value} collateral - The collateral value put up for the contract.
62
- * @param {DlcParty} shiftForFees - Specifies which party ('offeror' or 'acceptor') will bear the fees, affecting the outcome values.
63
- * @param {Value} fees - The fees associated with the contract.
64
- * @param {string} unit - The unit of measurement for the contract outcomes (e.g., 'BTC').
65
- * @param {Value} startOutcomeValue - The starting outcome value for the contract.
66
- * @param {Value} endOutcomeValue - The ending outcome value for the contract.
67
- * @returns {CsoInfoParams} An object containing the calculated CSO parameters:
68
- * - normalizedMaxGain: Maximum gain relative to a 1 BTC contract.
69
- * - normalizedMaxLoss: Maximum loss relative to a 1 BTC contract.
70
- * - maxGainForContractSize: Maximum gain for the actual contract size.
71
- * - maxLossForContractSize: Maximum loss for the actual contract size.
72
- * - offerCollateral: The offer collateral value after adjustments.
73
- *
74
- * Note: This function calculates the adjusted fees incorrectly, using collateral instead of contract size. Use v1 where possible.
75
- */
76
- export const getCsoInfoParamsFromContractInfoV0 = (
77
- contractSize: Value,
78
- collateral: Value,
79
- shiftForFees: DlcParty,
80
- fees: Value,
81
- unit: string,
82
- startOutcomeValue: Value,
83
- endOutcomeValue: Value,
84
- ): CsoInfoParams => {
85
- const leverageMultiplier = parseFloat(
86
- new Decimal(contractSize.bitcoin).dividedBy(collateral.bitcoin).toFixed(1),
87
- );
88
-
89
- const defaultContractSize = Value.fromBitcoin(1);
90
-
91
- const shiftValue =
92
- collateral.sats > 0
93
- ? Value.fromSats(
94
- roundToNearestMultiplier(
95
- (fees.sats * defaultContractSize.sats) / collateral.sats, // WARNING: this should be contract size not collateral
96
- UNIT_MULTIPLIER[unit.toLowerCase()], // (use v1 if possible)
97
- ),
98
- )
99
- : Value.zero();
100
-
101
- if (shiftForFees === 'offeror') {
102
- startOutcomeValue.sub(shiftValue);
103
- endOutcomeValue.sub(shiftValue);
104
- } else if (shiftForFees === 'acceptor') {
105
- startOutcomeValue.add(shiftValue);
106
- endOutcomeValue.add(shiftValue);
107
- }
108
-
109
- const normalizedMaxGain = endOutcomeValue.clone();
110
- normalizedMaxGain.sub(ONE_BTC_CONTRACT);
111
-
112
- const normalizedMaxLoss = ONE_BTC_CONTRACT.clone();
113
- normalizedMaxLoss.sub(startOutcomeValue);
114
-
115
- const maxGainForContractSize = Value.fromBitcoin(
116
- new Decimal(normalizedMaxGain.bitcoin)
117
- .times(leverageMultiplier)
118
- .toDecimalPlaces(5)
119
- .toNumber(),
120
- );
121
-
122
- const maxLossForContractSize = Value.fromBitcoin(
123
- new Decimal(normalizedMaxLoss.bitcoin)
124
- .times(contractSize.bitcoin)
125
- .toDecimalPlaces(
126
- 8 - Math.log10(Number(UNIT_MULTIPLIER[unit.toLowerCase()])),
127
- )
128
- .toNumber(),
129
- );
130
-
131
- const offerCollateral = collateral.clone();
132
- offerCollateral.sub(
133
- Value.fromSats(
134
- (maxGainForContractSize.sats * collateral.sats) / BigInt(1e8),
135
- ),
136
- );
137
-
138
- return {
139
- normalizedMaxGain,
140
- normalizedMaxLoss,
141
- maxGainForContractSize,
142
- maxLossForContractSize,
143
- offerCollateral,
144
- };
145
- };
146
-
147
- /**
148
- * getCsoInfoParamsFromContractInfo V1
149
- *
150
- * Fixed getCsoInfoParamsFromContractInfo implementation
151
- *
152
- * @param {Value} contractSize - The size of the contract in terms of value.
153
- * @param {Value} collateral - The collateral value put up for the contract.
154
- * @param {DlcParty} shiftForFees - Specifies which party ('offeror' or 'acceptor') will bear the fees, affecting the outcome values.
155
- * @param {Value} fees - The fees associated with the contract.
156
- * @param {string} unit - The unit of measurement for the contract outcomes (e.g., 'BTC').
157
- * @param {Value} startOutcomeValue - The starting outcome value for the contract.
158
- * @param {Value} endOutcomeValue - The ending outcome value for the contract.
159
- * @returns {CsoInfoParams} An object containing the calculated CSO parameters:
160
- * - normalizedMaxGain: Maximum gain relative to a 1 BTC contract.
161
- * - normalizedMaxLoss: Maximum loss relative to a 1 BTC contract.
162
- * - maxGainForContractSize: Maximum gain for the actual contract size.
163
- * - maxLossForContractSize: Maximum loss for the actual contract size.
164
- * - offerCollateral: The offer collateral value after adjustments.
165
- *
166
- * This version improves upon the previous by correctly adjusting fees based on the contract size, leading to more accurate
167
- * calculations of CSO parameters.
168
- */
169
- export const getCsoInfoParamsFromContractInfoV1 = (
170
- contractSize: Value,
171
- collateral: Value,
172
- shiftForFees: DlcParty,
173
- fees: Value,
174
- unit: string,
175
- startOutcomeValue: Value,
176
- endOutcomeValue: Value,
177
- ): CsoInfoParams => {
178
- const feesAdjusted = Value.fromSats(
179
- roundToNearestMultiplier(
180
- (fees.sats * BigInt(1e8)) / contractSize.sats, // NOTE: this is done correctly using contractSize
181
- BigInt(UNIT_MULTIPLIER[unit.toLowerCase()]),
182
- ),
183
- );
184
-
185
- if (shiftForFees === 'offeror') {
186
- startOutcomeValue.sub(feesAdjusted);
187
- endOutcomeValue.sub(feesAdjusted);
188
- } else if (shiftForFees === 'acceptor') {
189
- startOutcomeValue.add(feesAdjusted);
190
- endOutcomeValue.add(feesAdjusted);
191
- }
192
-
193
- const normalizedMaxGain = endOutcomeValue.clone();
194
- normalizedMaxGain.sub(ONE_BTC_CONTRACT);
195
-
196
- const normalizedMaxLoss = ONE_BTC_CONTRACT.clone();
197
- normalizedMaxLoss.sub(startOutcomeValue);
198
-
199
- const maxGainForContractSize = Value.fromSats(
200
- roundUpToNearestMultiplier(
201
- (normalizedMaxGain.sats * contractSize.sats) / BigInt(1e8),
202
- BigInt(UNIT_MULTIPLIER[unit.toLowerCase()]),
203
- ),
204
- );
205
-
206
- const maxLossForContractSize = Value.fromSats(
207
- roundUpToNearestMultiplier(
208
- (normalizedMaxLoss.sats * contractSize.sats) / BigInt(1e8),
209
- BigInt(UNIT_MULTIPLIER[unit.toLowerCase()]),
210
- ),
211
- );
212
-
213
- const offerCollateral = collateral.clone();
214
- offerCollateral.sub(maxGainForContractSize);
215
-
216
- return {
217
- normalizedMaxGain,
218
- normalizedMaxLoss,
219
- maxGainForContractSize,
220
- maxLossForContractSize,
221
- offerCollateral,
222
- };
223
- };
224
-
225
- /**
226
- * Decode CsoInfo from a ContractInfo object. Essentially the opposite of buildCustomStrategyOrderOffer
227
- *
228
- * @param {_contractInfo} ContractInfo - Contract Info object, containing oracle and descriptor info
229
- * @param {DlcParty} shiftForFees - Specifies which party ('offeror', 'acceptor', or 'neither') will pay for network fees
230
- * @param {Value} fees - Network fees associated with the contract. Defaults to 0 sats.
231
- * @param {_contractSize} Value - Optional. If not provided, it defaults to the total collateral.
232
- * @param {csoVersion} 'v0' | 'v1' - Specifies the version of the CSO parameter calculation to use. Defaults to 'v1'.
233
- * @returns {CsoInfo} An object containing the calculated CSO information:
234
- * - normalizedMaxGain: Maximum gain relative to a 1 BTC contract.
235
- * - normalizedMaxLoss: Maximum loss relative to a 1 BTC contract.
236
- * - maxGainForContractSize: Maximum gain for the actual contract size.
237
- * - maxLossForContractSize: Maximum loss for the actual contract size.
238
- * - minPayout: Minimum payout as determined by the contract's payout function.
239
- * - maxPayout: Maximum payout as determined by the contract's payout function.
240
- * - contractSize: The size of the contract in terms of value.
241
- * - offerCollateral: The offer collateral value after adjustments.
242
- * - totalCollateral: The total collateral put up for the contract.
243
- * - expiry: The expiry date of the contract based on the oracle's event maturity epoch.
244
- *
245
- * Note: This function performs several validations to ensure that the contract information and its components are of the
246
- * expected types and formats.
247
- * It throws errors if unsupported types or formats are encountered.
248
- */
249
- export const getCsoInfoFromContractInfo = (
250
- _contractInfo: ContractInfo,
251
- shiftForFees: DlcParty = 'neither',
252
- fees: Value = Value.fromSats(0),
253
- _contractSize?: Value,
254
- csoVersion: 'v0' | 'v1' = 'v1',
255
- ): CsoInfo => {
256
- if (_contractInfo.contractInfoType !== ContractInfoType.Single)
257
- throw Error('Only ContractInfoV0 currently supported');
258
-
259
- const contractInfo = _contractInfo as SingleContractInfo;
260
- if (
261
- contractInfo.contractDescriptor.contractDescriptorType !==
262
- ContractDescriptorType.NumericOutcome
263
- )
264
- throw Error('Only Numeric Descriptor currently supported');
265
-
266
- const oracleInfo = contractInfo.oracleInfo;
267
-
268
- // Handle both SingleOracleInfo and MultiOracleInfo
269
- let eventMaturityEpoch: number;
270
- let eventDescriptor: DigitDecompositionEventDescriptor;
271
-
272
- switch (oracleInfo.type) {
273
- case MessageType.SingleOracleInfo: {
274
- const singleOracleInfo = oracleInfo as SingleOracleInfo;
275
- eventMaturityEpoch =
276
- singleOracleInfo.announcement.oracleEvent.eventMaturityEpoch;
277
- eventDescriptor = singleOracleInfo.announcement.oracleEvent
278
- .eventDescriptor as DigitDecompositionEventDescriptor;
279
-
280
- if (
281
- singleOracleInfo.announcement.oracleEvent.eventDescriptor.type !==
282
- MessageType.DigitDecompositionEventDescriptor
283
- )
284
- throw Error(
285
- 'Only DigitDecompositionEventDescriptor currently supported',
286
- );
287
- break;
288
- }
289
- case MessageType.MultiOracleInfo: {
290
- const multiOracleInfo = oracleInfo as MultiOracleInfo;
291
- eventMaturityEpoch =
292
- multiOracleInfo.announcements[0].oracleEvent.eventMaturityEpoch;
293
- eventDescriptor = multiOracleInfo.announcements[0].oracleEvent
294
- .eventDescriptor as DigitDecompositionEventDescriptor;
295
-
296
- if (
297
- multiOracleInfo.announcements[0].oracleEvent.eventDescriptor.type !==
298
- MessageType.DigitDecompositionEventDescriptor
299
- )
300
- throw Error(
301
- 'Only DigitDecompositionEventDescriptor currently supported',
302
- );
303
- break;
304
- }
305
- default:
306
- throw Error('Unknown oracle info type');
307
- }
308
-
309
- const contractDescriptor = contractInfo.contractDescriptor as NumericalDescriptor;
310
- if (contractDescriptor.payoutFunction.type !== MessageType.PayoutFunction)
311
- throw Error('Only PayoutFunction currently supported');
312
-
313
- const payoutFunction = contractDescriptor.payoutFunction as PayoutFunction;
314
-
315
- validateCsoPayoutFunction(payoutFunction);
316
-
317
- const initialPiece = payoutFunction.payoutFunctionPieces[0];
318
- const midPiece = payoutFunction.payoutFunctionPieces[1];
319
-
320
- const minPayout = initialPiece.endPoint.outcomePayout;
321
- const maxPayout = midPiece.endPoint.outcomePayout;
322
-
323
- const startOutcome = initialPiece.endPoint.eventOutcome;
324
- const endOutcome = midPiece.endPoint.eventOutcome;
325
-
326
- const unit = eventDescriptor.unit;
327
-
328
- const collateral = Value.fromSats(contractInfo.totalCollateral);
329
- const contractSize =
330
- _contractSize && _contractSize.sats > 0 ? _contractSize : collateral;
331
-
332
- const startOutcomeValue = Value.fromSats(
333
- startOutcome * UNIT_MULTIPLIER[unit.toLowerCase()],
334
- );
335
- const endOutcomeValue = Value.fromSats(
336
- endOutcome * UNIT_MULTIPLIER[unit.toLowerCase()],
337
- );
338
-
339
- const getCsoInfoParamsFromContractInfo =
340
- csoVersion === 'v0'
341
- ? getCsoInfoParamsFromContractInfoV0
342
- : getCsoInfoParamsFromContractInfoV1;
343
-
344
- const {
345
- normalizedMaxGain,
346
- normalizedMaxLoss,
347
- maxGainForContractSize,
348
- maxLossForContractSize,
349
- offerCollateral,
350
- } = getCsoInfoParamsFromContractInfo(
351
- contractSize,
352
- collateral,
353
- shiftForFees,
354
- fees,
355
- unit,
356
- startOutcomeValue,
357
- endOutcomeValue,
358
- );
359
-
360
- const expiry = new Date(eventMaturityEpoch * 1000);
361
-
362
- return {
363
- normalizedMaxGain,
364
- normalizedMaxLoss,
365
- maxGainForContractSize,
366
- maxLossForContractSize,
367
- minPayout,
368
- maxPayout,
369
- contractSize,
370
- offerCollateral,
371
- totalCollateral: collateral,
372
- expiry,
373
- };
374
- };
375
-
376
- /**
377
- * Get CsoInfo from OrderOffer or DlcOffer and validate
378
- *
379
- * @param {HasContractInfo & HasType} offer
380
- * @returns {CsoInfo}
381
- */
382
- export const getCsoInfoFromOffer = (
383
- offer: HasContractInfo & HasType & HasOfferCollateral & MaybeHasPositionInfo,
384
- csoVersion: 'v0' | 'v1' = 'v1',
385
- ): CsoInfo => {
386
- if (
387
- offer.type !== MessageType.DlcOffer &&
388
- offer.type !== MessageType.OrderOffer
389
- )
390
- throw Error('Only DlcOffer and OrderOffer currently supported');
391
-
392
- let shiftForFees: DlcParty = 'neither';
393
- const fees = Value.zero();
394
- const contractSize = Value.zero();
395
-
396
- if (offer.positionInfo) {
397
- shiftForFees = (offer.positionInfo as OrderPositionInfo).shiftForFees;
398
- fees.add(Value.fromSats((offer.positionInfo as OrderPositionInfo).fees));
399
- contractSize.add(
400
- Value.fromSats((offer.positionInfo as OrderPositionInfo).contractSize),
401
- );
402
- }
403
-
404
- const positionInfo = getCsoInfoFromContractInfo(
405
- offer.contractInfo,
406
- shiftForFees,
407
- fees,
408
- contractSize,
409
- csoVersion,
410
- );
411
-
412
- if (positionInfo.offerCollateral.sats !== offer.offerCollateral)
413
- throw Error('Offer was not generated with CSO ContractInfo');
414
-
415
- return positionInfo;
416
- };
417
-
418
- /**
419
- * Validate Payout Function for proper CSO format
420
- *
421
- * It should have 3 PayoutCurvePieces which consist of a flat line (maxLoss),
422
- * ascending line (maxLoss to maxGain) and finally another flat line (maxGain)
423
- *
424
- * All PayoutCurvePieces should be type PolynomialPayoutCurvePieces
425
- *
426
- * @param {PayoutFunction} payoutFunction
427
- */
428
- export const validateCsoPayoutFunction = (
429
- payoutFunction: PayoutFunction,
430
- ): void => {
431
- assert(
432
- payoutFunction.payoutFunctionPieces.length === 3,
433
- 'CSO Payout Function must have 3 PayoutFunctionPieces',
434
- );
435
- for (const [i, piece] of payoutFunction.payoutFunctionPieces.entries()) {
436
- assert(
437
- piece.payoutCurvePiece.payoutCurvePieceType ===
438
- PayoutCurvePieceType.Polynomial ||
439
- piece.payoutCurvePiece.type === MessageType.PolynomialPayoutCurvePiece,
440
- 'CSO Payout Function PayoutCurvePieces must be PolynomialCurvePieces',
441
- );
442
-
443
- const payoutCurvePiece = piece.payoutCurvePiece as PolynomialPayoutCurvePiece;
444
- const points = payoutCurvePiece.points;
445
-
446
- // eventOutcome should always be ascending
447
- assert(
448
- points[0].eventOutcome < points[1].eventOutcome,
449
- 'CSO Payout Function PayoutCurvePiece point payout should be an ascending line',
450
- );
451
-
452
- // endpoints should always be ascending
453
- let previousPiece, previousPoints;
454
- if (i > 0) {
455
- previousPiece = payoutFunction.payoutFunctionPieces[i - 1];
456
- previousPoints = previousPiece.payoutCurvePiece.points;
457
- assert(
458
- previousPiece.endPoint.eventOutcome < piece.endPoint.eventOutcome,
459
- 'CSO Payout Function point endpoints should be an ascending line',
460
- );
461
- assert(
462
- previousPoints[1].outcomePayout === points[0].outcomePayout,
463
- 'CSO Payout Function point outcome payout should be continuous without gaps',
464
- );
465
- }
466
-
467
- switch (i) {
468
- case 0:
469
- // First piece - should start from initial endpoint
470
- // maxLoss should be a flat line
471
- assert(
472
- points[0].outcomePayout === points[1].outcomePayout,
473
- 'CSO Payout Function maxLoss PayoutCurvePiece point should be a flat line',
474
- );
475
- break;
476
- case 1:
477
- // maxLoss to maxGain should be an ascending line
478
- assert(
479
- previousPiece.endPoint.outcomePayout < piece.endPoint.outcomePayout,
480
- );
481
- assert(
482
- points[0].outcomePayout < points[1].outcomePayout,
483
- 'CSO Payout Function maxLoss to maxGain PayoutCurvePiece point should be an ascending line',
484
- );
485
- break;
486
- case 2:
487
- // maxGain should be a flat line
488
- assert(
489
- previousPiece.endPoint.outcomePayout === piece.endPoint.outcomePayout,
490
- );
491
- assert(
492
- points[0].outcomePayout === points[1].outcomePayout,
493
- 'CSO Payout Function maxGain PayoutCurvePiece point should be a flat line',
494
- );
495
- break;
496
- }
497
- }
498
- };
@@ -1,94 +0,0 @@
1
- import { PayoutFunction } from '@node-dlc/messaging';
2
- import BN from 'bignumber.js';
3
-
4
- import { PolynomialPayoutCurve } from '../PolynomialPayoutCurve';
5
-
6
- const buildPayoutFunction = (
7
- minPayout: bigint,
8
- maxPayout: bigint,
9
- startOutcome: bigint,
10
- endOutcome: bigint,
11
- oracleBase: number,
12
- oracleDigits: number,
13
- ): { payoutFunction: PayoutFunction } => {
14
- // Max outcome limited by the oracle
15
- const maxOutcome = BigInt(
16
- new BN(oracleBase).pow(oracleDigits).minus(1).toString(10),
17
- );
18
-
19
- // max loss line
20
- const payoutCurveMaxLoss = new PolynomialPayoutCurve([
21
- { outcome: new BN(0), payout: new BN(Number(minPayout)) },
22
- {
23
- outcome: new BN(Number(startOutcome)),
24
- payout: new BN(Number(minPayout)),
25
- },
26
- ]);
27
-
28
- // payout line
29
- const payoutCurve = new PolynomialPayoutCurve([
30
- {
31
- outcome: new BN(Number(startOutcome)),
32
- payout: new BN(Number(minPayout)),
33
- },
34
- {
35
- outcome: new BN(Number(endOutcome)),
36
- payout: new BN(Number(maxPayout)),
37
- },
38
- ]);
39
-
40
- // max gain line
41
- const payoutCurveMaxGain = new PolynomialPayoutCurve([
42
- { outcome: new BN(Number(endOutcome)), payout: new BN(Number(maxPayout)) },
43
- {
44
- outcome: new BN(Number(maxOutcome)),
45
- payout: new BN(Number(maxPayout)),
46
- },
47
- ]);
48
-
49
- const payoutFunction = new PayoutFunction();
50
-
51
- // Defensive fix: ensure payoutFunctionPieces is initialized as an array
52
- if (!payoutFunction.payoutFunctionPieces) {
53
- payoutFunction.payoutFunctionPieces = [];
54
- }
55
-
56
- payoutFunction.payoutFunctionPieces.push({
57
- endPoint: {
58
- eventOutcome: startOutcome,
59
- outcomePayout: minPayout,
60
- extraPrecision: 0,
61
- },
62
- payoutCurvePiece: payoutCurveMaxLoss.toPayoutCurvePiece(),
63
- });
64
-
65
- payoutFunction.payoutFunctionPieces.push({
66
- endPoint: {
67
- eventOutcome: endOutcome,
68
- outcomePayout: maxPayout,
69
- extraPrecision: 0,
70
- },
71
- payoutCurvePiece: payoutCurve.toPayoutCurvePiece(),
72
- });
73
-
74
- payoutFunction.payoutFunctionPieces.push({
75
- endPoint: {
76
- eventOutcome: maxOutcome,
77
- outcomePayout: maxPayout,
78
- extraPrecision: 0,
79
- },
80
- payoutCurvePiece: payoutCurveMaxGain.toPayoutCurvePiece(),
81
- });
82
-
83
- payoutFunction.lastEndpoint = {
84
- eventOutcome: maxOutcome,
85
- outcomePayout: maxPayout,
86
- extraPrecision: 0,
87
- };
88
-
89
- return {
90
- payoutFunction,
91
- };
92
- };
93
-
94
- export const LinearPayout = { buildPayoutFunction };