@sudobility/heavymath_ui 0.0.3

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 (201) hide show
  1. package/dist/components/dealer/DealerNFTList.d.ts +6 -0
  2. package/dist/components/dealer/DealerNFTList.d.ts.map +1 -0
  3. package/dist/components/dealer/DealerNFTList.js +46 -0
  4. package/dist/components/dealer/DealerNFTList.js.map +1 -0
  5. package/dist/components/dealer/DealerNFTSelector.d.ts +8 -0
  6. package/dist/components/dealer/DealerNFTSelector.d.ts.map +1 -0
  7. package/dist/components/dealer/DealerNFTSelector.js +10 -0
  8. package/dist/components/dealer/DealerNFTSelector.js.map +1 -0
  9. package/dist/components/dealer/UpcomingGamesWidget.d.ts +8 -0
  10. package/dist/components/dealer/UpcomingGamesWidget.d.ts.map +1 -0
  11. package/dist/components/dealer/UpcomingGamesWidget.js +68 -0
  12. package/dist/components/dealer/UpcomingGamesWidget.js.map +1 -0
  13. package/dist/components/icons/index.d.ts +2 -0
  14. package/dist/components/icons/index.d.ts.map +1 -0
  15. package/dist/components/icons/index.js +2 -0
  16. package/dist/components/icons/index.js.map +1 -0
  17. package/dist/components/market/GameMarketsSection.d.ts +16 -0
  18. package/dist/components/market/GameMarketsSection.d.ts.map +1 -0
  19. package/dist/components/market/GameMarketsSection.js +18 -0
  20. package/dist/components/market/GameMarketsSection.js.map +1 -0
  21. package/dist/components/market/InlineCreateMarketForm.d.ts +17 -0
  22. package/dist/components/market/InlineCreateMarketForm.d.ts.map +1 -0
  23. package/dist/components/market/InlineCreateMarketForm.js +274 -0
  24. package/dist/components/market/InlineCreateMarketForm.js.map +1 -0
  25. package/dist/components/market/LeagueMarketsSection.d.ts +16 -0
  26. package/dist/components/market/LeagueMarketsSection.d.ts.map +1 -0
  27. package/dist/components/market/LeagueMarketsSection.js +15 -0
  28. package/dist/components/market/LeagueMarketsSection.js.map +1 -0
  29. package/dist/components/market/MarketCard.d.ts +8 -0
  30. package/dist/components/market/MarketCard.d.ts.map +1 -0
  31. package/dist/components/market/MarketCard.js +30 -0
  32. package/dist/components/market/MarketCard.js.map +1 -0
  33. package/dist/components/market/MarketList.d.ts +9 -0
  34. package/dist/components/market/MarketList.d.ts.map +1 -0
  35. package/dist/components/market/MarketList.js +17 -0
  36. package/dist/components/market/MarketList.js.map +1 -0
  37. package/dist/components/market/MarketStatusBadge.d.ts +8 -0
  38. package/dist/components/market/MarketStatusBadge.d.ts.map +1 -0
  39. package/dist/components/market/MarketStatusBadge.js +31 -0
  40. package/dist/components/market/MarketStatusBadge.js.map +1 -0
  41. package/dist/components/market/PredictionSlider.d.ts +11 -0
  42. package/dist/components/market/PredictionSlider.d.ts.map +1 -0
  43. package/dist/components/market/PredictionSlider.js +55 -0
  44. package/dist/components/market/PredictionSlider.js.map +1 -0
  45. package/dist/components/market/SportPredictionCard.d.ts +15 -0
  46. package/dist/components/market/SportPredictionCard.d.ts.map +1 -0
  47. package/dist/components/market/SportPredictionCard.js +92 -0
  48. package/dist/components/market/SportPredictionCard.js.map +1 -0
  49. package/dist/components/market/TeamMarketsSection.d.ts +17 -0
  50. package/dist/components/market/TeamMarketsSection.d.ts.map +1 -0
  51. package/dist/components/market/TeamMarketsSection.js +8 -0
  52. package/dist/components/market/TeamMarketsSection.js.map +1 -0
  53. package/dist/components/market/TeamTournamentMarketForm.d.ts +19 -0
  54. package/dist/components/market/TeamTournamentMarketForm.d.ts.map +1 -0
  55. package/dist/components/market/TeamTournamentMarketForm.js +92 -0
  56. package/dist/components/market/TeamTournamentMarketForm.js.map +1 -0
  57. package/dist/components/market/TournamentMarketForm.d.ts +19 -0
  58. package/dist/components/market/TournamentMarketForm.d.ts.map +1 -0
  59. package/dist/components/market/TournamentMarketForm.js +86 -0
  60. package/dist/components/market/TournamentMarketForm.js.map +1 -0
  61. package/dist/components/market/index.d.ts +12 -0
  62. package/dist/components/market/index.d.ts.map +1 -0
  63. package/dist/components/market/index.js +12 -0
  64. package/dist/components/market/index.js.map +1 -0
  65. package/dist/components/sports/SeasonSelector.d.ts +10 -0
  66. package/dist/components/sports/SeasonSelector.d.ts.map +1 -0
  67. package/dist/components/sports/SeasonSelector.js +13 -0
  68. package/dist/components/sports/SeasonSelector.js.map +1 -0
  69. package/dist/components/ui/AnimatedCollapse.d.ts +9 -0
  70. package/dist/components/ui/AnimatedCollapse.d.ts.map +1 -0
  71. package/dist/components/ui/AnimatedCollapse.js +8 -0
  72. package/dist/components/ui/AnimatedCollapse.js.map +1 -0
  73. package/dist/components/ui/FavoriteStar.d.ts +13 -0
  74. package/dist/components/ui/FavoriteStar.d.ts.map +1 -0
  75. package/dist/components/ui/FavoriteStar.js +47 -0
  76. package/dist/components/ui/FavoriteStar.js.map +1 -0
  77. package/dist/components/wallet/ConnectedWalletMenu.d.ts +16 -0
  78. package/dist/components/wallet/ConnectedWalletMenu.d.ts.map +1 -0
  79. package/dist/components/wallet/ConnectedWalletMenu.js +131 -0
  80. package/dist/components/wallet/ConnectedWalletMenu.js.map +1 -0
  81. package/dist/components/wallet/DealerRoute.d.ts +6 -0
  82. package/dist/components/wallet/DealerRoute.d.ts.map +1 -0
  83. package/dist/components/wallet/DealerRoute.js +20 -0
  84. package/dist/components/wallet/DealerRoute.js.map +1 -0
  85. package/dist/components/wallet/ProtectedRoute.d.ts +8 -0
  86. package/dist/components/wallet/ProtectedRoute.d.ts.map +1 -0
  87. package/dist/components/wallet/ProtectedRoute.js +17 -0
  88. package/dist/components/wallet/ProtectedRoute.js.map +1 -0
  89. package/dist/components/wallet/WalletConnectionModal.d.ts +7 -0
  90. package/dist/components/wallet/WalletConnectionModal.d.ts.map +1 -0
  91. package/dist/components/wallet/WalletConnectionModal.js +334 -0
  92. package/dist/components/wallet/WalletConnectionModal.js.map +1 -0
  93. package/dist/config/app.d.ts +24 -0
  94. package/dist/config/app.d.ts.map +1 -0
  95. package/dist/config/app.js +18 -0
  96. package/dist/config/app.js.map +1 -0
  97. package/dist/config/chains.d.ts +1070 -0
  98. package/dist/config/chains.d.ts.map +1 -0
  99. package/dist/config/chains.js +28 -0
  100. package/dist/config/chains.js.map +1 -0
  101. package/dist/config/contracts.d.ts +15 -0
  102. package/dist/config/contracts.d.ts.map +1 -0
  103. package/dist/config/contracts.js +62 -0
  104. package/dist/config/contracts.js.map +1 -0
  105. package/dist/config/sportCodes.d.ts +58 -0
  106. package/dist/config/sportCodes.d.ts.map +1 -0
  107. package/dist/config/sportCodes.js +78 -0
  108. package/dist/config/sportCodes.js.map +1 -0
  109. package/dist/context/IndexerContext.d.ts +34 -0
  110. package/dist/context/IndexerContext.d.ts.map +1 -0
  111. package/dist/context/IndexerContext.js +40 -0
  112. package/dist/context/IndexerContext.js.map +1 -0
  113. package/dist/context/WalletAuthContext.d.ts +26 -0
  114. package/dist/context/WalletAuthContext.d.ts.map +1 -0
  115. package/dist/context/WalletAuthContext.js +148 -0
  116. package/dist/context/WalletAuthContext.js.map +1 -0
  117. package/dist/hooks/index.d.ts +13 -0
  118. package/dist/hooks/index.d.ts.map +1 -0
  119. package/dist/hooks/index.js +13 -0
  120. package/dist/hooks/index.js.map +1 -0
  121. package/dist/hooks/useContractWithToast.d.ts +1348 -0
  122. package/dist/hooks/useContractWithToast.d.ts.map +1 -0
  123. package/dist/hooks/useContractWithToast.js +395 -0
  124. package/dist/hooks/useContractWithToast.js.map +1 -0
  125. package/dist/hooks/useDealerNFT.d.ts +71 -0
  126. package/dist/hooks/useDealerNFT.d.ts.map +1 -0
  127. package/dist/hooks/useDealerNFT.js +127 -0
  128. package/dist/hooks/useDealerNFT.js.map +1 -0
  129. package/dist/hooks/useDealerPermission.d.ts +11 -0
  130. package/dist/hooks/useDealerPermission.d.ts.map +1 -0
  131. package/dist/hooks/useDealerPermission.js +48 -0
  132. package/dist/hooks/useDealerPermission.js.map +1 -0
  133. package/dist/hooks/useFilteredSportsData.d.ts +20 -0
  134. package/dist/hooks/useFilteredSportsData.d.ts.map +1 -0
  135. package/dist/hooks/useFilteredSportsData.js +52 -0
  136. package/dist/hooks/useFilteredSportsData.js.map +1 -0
  137. package/dist/hooks/useGameMarkets.d.ts +23 -0
  138. package/dist/hooks/useGameMarkets.d.ts.map +1 -0
  139. package/dist/hooks/useGameMarkets.js +50 -0
  140. package/dist/hooks/useGameMarkets.js.map +1 -0
  141. package/dist/hooks/useLeagueMarkets.d.ts +11 -0
  142. package/dist/hooks/useLeagueMarkets.d.ts.map +1 -0
  143. package/dist/hooks/useLeagueMarkets.js +38 -0
  144. package/dist/hooks/useLeagueMarkets.js.map +1 -0
  145. package/dist/hooks/useMarketContract.d.ts +219 -0
  146. package/dist/hooks/useMarketContract.d.ts.map +1 -0
  147. package/dist/hooks/useMarketContract.js +790 -0
  148. package/dist/hooks/useMarketContract.js.map +1 -0
  149. package/dist/hooks/useToastActions.d.ts +13 -0
  150. package/dist/hooks/useToastActions.d.ts.map +1 -0
  151. package/dist/hooks/useToastActions.js +40 -0
  152. package/dist/hooks/useToastActions.js.map +1 -0
  153. package/dist/index.d.ts +43 -0
  154. package/dist/index.d.ts.map +1 -0
  155. package/dist/index.js +47 -0
  156. package/dist/index.js.map +1 -0
  157. package/dist/lib/evmClient.d.ts +299 -0
  158. package/dist/lib/evmClient.d.ts.map +1 -0
  159. package/dist/lib/evmClient.js +691 -0
  160. package/dist/lib/evmClient.js.map +1 -0
  161. package/dist/types/auth.d.ts +44 -0
  162. package/dist/types/auth.d.ts.map +1 -0
  163. package/dist/types/auth.js +17 -0
  164. package/dist/types/auth.js.map +1 -0
  165. package/dist/types/dealer.d.ts +59 -0
  166. package/dist/types/dealer.d.ts.map +1 -0
  167. package/dist/types/dealer.js +31 -0
  168. package/dist/types/dealer.js.map +1 -0
  169. package/dist/types/market.d.ts +79 -0
  170. package/dist/types/market.d.ts.map +1 -0
  171. package/dist/types/market.js +47 -0
  172. package/dist/types/market.js.map +1 -0
  173. package/dist/utils/conditionData.d.ts +8 -0
  174. package/dist/utils/conditionData.d.ts.map +1 -0
  175. package/dist/utils/conditionData.js +7 -0
  176. package/dist/utils/conditionData.js.map +1 -0
  177. package/dist/utils/datetime.d.ts +3 -0
  178. package/dist/utils/datetime.d.ts.map +1 -0
  179. package/dist/utils/datetime.js +13 -0
  180. package/dist/utils/datetime.js.map +1 -0
  181. package/dist/utils/format.d.ts +79 -0
  182. package/dist/utils/format.d.ts.map +1 -0
  183. package/dist/utils/format.js +144 -0
  184. package/dist/utils/format.js.map +1 -0
  185. package/dist/utils/marketDisplay.d.ts +28 -0
  186. package/dist/utils/marketDisplay.d.ts.map +1 -0
  187. package/dist/utils/marketDisplay.js +45 -0
  188. package/dist/utils/marketDisplay.js.map +1 -0
  189. package/dist/utils/marketId.d.ts +8 -0
  190. package/dist/utils/marketId.d.ts.map +1 -0
  191. package/dist/utils/marketId.js +12 -0
  192. package/dist/utils/marketId.js.map +1 -0
  193. package/dist/utils/oracleId.d.ts +33 -0
  194. package/dist/utils/oracleId.d.ts.map +1 -0
  195. package/dist/utils/oracleId.js +62 -0
  196. package/dist/utils/oracleId.js.map +1 -0
  197. package/dist/utils/sportsSeason.d.ts +10 -0
  198. package/dist/utils/sportsSeason.d.ts.map +1 -0
  199. package/dist/utils/sportsSeason.js +39 -0
  200. package/dist/utils/sportsSeason.js.map +1 -0
  201. package/package.json +85 -0
@@ -0,0 +1,691 @@
1
+ /**
2
+ * @fileoverview EVM Prediction Client
3
+ * @description Wraps all PredictionMarket smart contract interactions via viem.
4
+ * Handles ERC-20 allowance approval, transaction execution, and contract reads.
5
+ */
6
+ import { erc20Abi, getAddress } from 'viem';
7
+ // PredictionMarket ABI - minimal subset needed for our operations
8
+ const predictionMarketAbi = [
9
+ {
10
+ inputs: [
11
+ { name: 'tokenId', type: 'uint256' },
12
+ { name: 'category', type: 'uint256' },
13
+ { name: 'subCategory', type: 'uint256' },
14
+ { name: 'deadline', type: 'uint256' },
15
+ { name: 'description', type: 'string' },
16
+ { name: 'oracleId', type: 'bytes32' },
17
+ ],
18
+ name: 'createMarket',
19
+ outputs: [],
20
+ stateMutability: 'nonpayable',
21
+ type: 'function',
22
+ },
23
+ {
24
+ inputs: [
25
+ { name: 'tokenId', type: 'uint256' },
26
+ { name: 'category', type: 'uint256' },
27
+ { name: 'subCategory', type: 'uint256' },
28
+ { name: 'deadline', type: 'uint256' },
29
+ { name: 'description', type: 'string' },
30
+ { name: 'oracleId', type: 'bytes32' },
31
+ { name: 'conditionData', type: 'bytes32' },
32
+ ],
33
+ name: 'createMarketWithCondition',
34
+ outputs: [],
35
+ stateMutability: 'nonpayable',
36
+ type: 'function',
37
+ },
38
+ {
39
+ inputs: [
40
+ { name: 'marketId', type: 'uint256' },
41
+ { name: 'percentage', type: 'uint256' },
42
+ { name: 'amount', type: 'uint256' },
43
+ ],
44
+ name: 'placePrediction',
45
+ outputs: [],
46
+ stateMutability: 'nonpayable',
47
+ type: 'function',
48
+ },
49
+ {
50
+ inputs: [
51
+ { name: 'marketId', type: 'uint256' },
52
+ { name: 'newPercentage', type: 'uint256' },
53
+ { name: 'additionalAmount', type: 'uint256' },
54
+ ],
55
+ name: 'updatePrediction',
56
+ outputs: [],
57
+ stateMutability: 'nonpayable',
58
+ type: 'function',
59
+ },
60
+ {
61
+ inputs: [{ name: 'marketId', type: 'uint256' }],
62
+ name: 'withdrawPrediction',
63
+ outputs: [],
64
+ stateMutability: 'nonpayable',
65
+ type: 'function',
66
+ },
67
+ {
68
+ inputs: [{ name: 'marketId', type: 'uint256' }],
69
+ name: 'cancelMarket',
70
+ outputs: [],
71
+ stateMutability: 'nonpayable',
72
+ type: 'function',
73
+ },
74
+ {
75
+ inputs: [{ name: 'marketId', type: 'uint256' }],
76
+ name: 'abandonMarket',
77
+ outputs: [],
78
+ stateMutability: 'nonpayable',
79
+ type: 'function',
80
+ },
81
+ {
82
+ inputs: [
83
+ { name: 'marketId', type: 'uint256' },
84
+ { name: 'positiveOutcome', type: 'bool' },
85
+ ],
86
+ name: 'resolveMarket',
87
+ outputs: [],
88
+ stateMutability: 'nonpayable',
89
+ type: 'function',
90
+ },
91
+ {
92
+ inputs: [{ name: 'marketId', type: 'uint256' }],
93
+ name: 'resolveMarketWithOracle',
94
+ outputs: [],
95
+ stateMutability: 'nonpayable',
96
+ type: 'function',
97
+ },
98
+ {
99
+ inputs: [{ name: 'marketId', type: 'uint256' }],
100
+ name: 'requestOracleResolution',
101
+ outputs: [],
102
+ stateMutability: 'nonpayable',
103
+ type: 'function',
104
+ },
105
+ {
106
+ inputs: [{ name: 'marketId', type: 'uint256' }],
107
+ name: 'completeOracleResolution',
108
+ outputs: [],
109
+ stateMutability: 'nonpayable',
110
+ type: 'function',
111
+ },
112
+ {
113
+ inputs: [{ name: 'marketId', type: 'uint256' }],
114
+ name: 'claimWinnings',
115
+ outputs: [],
116
+ stateMutability: 'nonpayable',
117
+ type: 'function',
118
+ },
119
+ {
120
+ inputs: [{ name: 'marketId', type: 'uint256' }],
121
+ name: 'claimRefund',
122
+ outputs: [],
123
+ stateMutability: 'nonpayable',
124
+ type: 'function',
125
+ },
126
+ {
127
+ inputs: [{ name: 'marketId', type: 'uint256' }],
128
+ name: 'lockMarket',
129
+ outputs: [],
130
+ stateMutability: 'nonpayable',
131
+ type: 'function',
132
+ },
133
+ {
134
+ inputs: [{ name: 'marketId', type: 'uint256' }],
135
+ name: 'calculateMarketSplit',
136
+ outputs: [
137
+ { name: 'negPct', type: 'uint256' },
138
+ { name: 'posPct', type: 'uint256' },
139
+ { name: 'negAmt', type: 'uint256' },
140
+ { name: 'posAmt', type: 'uint256' },
141
+ { name: 'valid', type: 'bool' },
142
+ ],
143
+ stateMutability: 'view',
144
+ type: 'function',
145
+ },
146
+ {
147
+ inputs: [{ name: 'marketId', type: 'uint256' }],
148
+ name: 'lockRefunds',
149
+ outputs: [
150
+ { name: 'negativePercentage', type: 'uint256' },
151
+ { name: 'positivePercentage', type: 'uint256' },
152
+ { name: 'negativeAllowedAmount', type: 'uint256' },
153
+ { name: 'positiveAllowedAmount', type: 'uint256' },
154
+ ],
155
+ stateMutability: 'view',
156
+ type: 'function',
157
+ },
158
+ {
159
+ inputs: [{ name: 'marketId', type: 'uint256' }],
160
+ name: 'claimLockRefund',
161
+ outputs: [],
162
+ stateMutability: 'nonpayable',
163
+ type: 'function',
164
+ },
165
+ {
166
+ inputs: [
167
+ { name: 'marketId', type: 'uint256' },
168
+ { name: 'predictor', type: 'address' },
169
+ ],
170
+ name: 'getLockRefundAmount',
171
+ outputs: [{ name: '', type: 'uint256' }],
172
+ stateMutability: 'view',
173
+ type: 'function',
174
+ },
175
+ {
176
+ inputs: [{ name: 'marketId', type: 'uint256' }],
177
+ name: 'withdrawDealerFees',
178
+ outputs: [],
179
+ stateMutability: 'nonpayable',
180
+ type: 'function',
181
+ },
182
+ {
183
+ inputs: [],
184
+ name: 'withdrawSystemFees',
185
+ outputs: [],
186
+ stateMutability: 'nonpayable',
187
+ type: 'function',
188
+ },
189
+ {
190
+ inputs: [],
191
+ name: 'stakeToken',
192
+ outputs: [{ name: '', type: 'address' }],
193
+ stateMutability: 'view',
194
+ type: 'function',
195
+ },
196
+ {
197
+ inputs: [],
198
+ name: 'testMode',
199
+ outputs: [{ name: '', type: 'bool' }],
200
+ stateMutability: 'view',
201
+ type: 'function',
202
+ },
203
+ {
204
+ inputs: [{ name: 'marketId', type: 'uint256' }],
205
+ name: 'markets',
206
+ outputs: [
207
+ { name: 'dealer', type: 'address' },
208
+ { name: 'tokenId', type: 'uint256' },
209
+ { name: 'category', type: 'uint256' },
210
+ { name: 'subCategory', type: 'uint256' },
211
+ { name: 'deadline', type: 'uint256' },
212
+ { name: 'description', type: 'string' },
213
+ { name: 'createdAt', type: 'uint256' },
214
+ { name: 'dealerFeeBps', type: 'uint256' },
215
+ { name: 'status', type: 'uint8' },
216
+ { name: 'positiveOutcome', type: 'bool' },
217
+ { name: 'oracleId', type: 'bytes32' },
218
+ { name: 'conditionData', type: 'bytes32' },
219
+ ],
220
+ stateMutability: 'view',
221
+ type: 'function',
222
+ },
223
+ {
224
+ inputs: [
225
+ { name: 'marketId', type: 'uint256' },
226
+ { name: 'account', type: 'address' },
227
+ ],
228
+ name: 'predictions',
229
+ outputs: [
230
+ { name: 'amount', type: 'uint256' },
231
+ { name: 'percentage', type: 'uint256' },
232
+ { name: 'placedAt', type: 'uint256' },
233
+ { name: 'claimed', type: 'bool' },
234
+ ],
235
+ stateMutability: 'view',
236
+ type: 'function',
237
+ },
238
+ ];
239
+ /**
240
+ * Client for interacting with the PredictionMarket smart contract.
241
+ * Wraps all contract operations and handles ERC-20 allowance management.
242
+ */
243
+ export class EVMPredictionClient {
244
+ /**
245
+ * Create a new EVMPredictionClient.
246
+ *
247
+ * @param addresses - The contract addresses to interact with
248
+ */
249
+ constructor(addresses) {
250
+ Object.defineProperty(this, "abi", {
251
+ enumerable: true,
252
+ configurable: true,
253
+ writable: true,
254
+ value: void 0
255
+ });
256
+ Object.defineProperty(this, "addresses", {
257
+ enumerable: true,
258
+ configurable: true,
259
+ writable: true,
260
+ value: void 0
261
+ });
262
+ Object.defineProperty(this, "stakeTokenCache", {
263
+ enumerable: true,
264
+ configurable: true,
265
+ writable: true,
266
+ value: void 0
267
+ });
268
+ this.addresses = addresses;
269
+ this.abi = predictionMarketAbi;
270
+ }
271
+ predictionMarketAddress() {
272
+ return this.addresses.predictionMarket;
273
+ }
274
+ ensureAccount(wallet) {
275
+ const account = wallet.walletClient.account?.address;
276
+ if (!account) {
277
+ throw new Error('Wallet client is not configured with an account');
278
+ }
279
+ return getAddress(account);
280
+ }
281
+ getPublicClient(wallet) {
282
+ if (wallet.publicClient) {
283
+ return wallet.publicClient;
284
+ }
285
+ throw new Error('A viem PublicClient is required for this operation. Provide wallet.publicClient.');
286
+ }
287
+ async resolveStakeToken(wallet) {
288
+ if (this.addresses.stakeToken) {
289
+ return getAddress(this.addresses.stakeToken);
290
+ }
291
+ if (this.stakeTokenCache) {
292
+ return this.stakeTokenCache;
293
+ }
294
+ const publicClient = this.getPublicClient(wallet);
295
+ const address = (await publicClient.readContract({
296
+ address: this.predictionMarketAddress(),
297
+ abi: this.abi,
298
+ functionName: 'stakeToken',
299
+ }));
300
+ this.stakeTokenCache = getAddress(address);
301
+ return this.stakeTokenCache;
302
+ }
303
+ /**
304
+ * Ensure the PredictionMarket contract has sufficient ERC-20 allowance.
305
+ * Automatically approves if current allowance is insufficient.
306
+ */
307
+ async ensureAllowance(wallet, amount) {
308
+ if (amount === 0n) {
309
+ return;
310
+ }
311
+ const token = await this.resolveStakeToken(wallet);
312
+ const owner = this.ensureAccount(wallet);
313
+ const spender = this.predictionMarketAddress();
314
+ const publicClient = this.getPublicClient(wallet);
315
+ const currentAllowance = (await publicClient.readContract({
316
+ address: token,
317
+ abi: erc20Abi,
318
+ functionName: 'allowance',
319
+ args: [owner, spender],
320
+ }));
321
+ if (currentAllowance >= amount) {
322
+ return;
323
+ }
324
+ const approveHash = await wallet.walletClient.writeContract({
325
+ address: token,
326
+ abi: erc20Abi,
327
+ functionName: 'approve',
328
+ args: [spender, amount],
329
+ chain: wallet.chain,
330
+ account: wallet.walletClient.account,
331
+ });
332
+ // Wait for the approval to be mined before proceeding,
333
+ // otherwise the subsequent contract call may fail gas estimation
334
+ // because the allowance isn't confirmed on-chain yet.
335
+ await publicClient.waitForTransactionReceipt({ hash: approveHash });
336
+ }
337
+ /**
338
+ * Execute a contract write operation and optionally wait for the receipt.
339
+ * Simulates first via the public client to surface clear revert reasons
340
+ * instead of confusing gas estimation errors.
341
+ */
342
+ async execute(wallet, functionName, args) {
343
+ const contractParams = {
344
+ address: this.predictionMarketAddress(),
345
+ abi: this.abi,
346
+ functionName,
347
+ args,
348
+ chain: wallet.chain,
349
+ account: wallet.walletClient.account,
350
+ };
351
+ // Simulate first to get a clear revert reason if the tx would fail.
352
+ // Without this, a reverting tx produces a confusing "gas limit too high" error
353
+ // because gas estimation returns an inflated value that exceeds the node cap.
354
+ if (wallet.publicClient) {
355
+ await wallet.publicClient.simulateContract(contractParams);
356
+ }
357
+ const hash = await wallet.walletClient.writeContract(contractParams);
358
+ if (wallet.publicClient) {
359
+ const receipt = await wallet.publicClient.waitForTransactionReceipt({
360
+ hash,
361
+ });
362
+ return { hash, receiptHash: receipt.transactionHash };
363
+ }
364
+ return { hash };
365
+ }
366
+ /**
367
+ * Create a new prediction market.
368
+ *
369
+ * @param wallet - Wallet context for signing
370
+ * @param params - Market creation parameters
371
+ * @returns Transaction result with hash
372
+ */
373
+ async createMarket(wallet, params) {
374
+ const ZERO_BYTES32 = '0x0000000000000000000000000000000000000000000000000000000000000000';
375
+ const oracle = params.oracleId ?? ZERO_BYTES32;
376
+ const condition = params.conditionData ?? ZERO_BYTES32;
377
+ // Use createMarketWithCondition when conditionData is non-zero
378
+ if (condition !== ZERO_BYTES32) {
379
+ return this.execute(wallet, 'createMarketWithCondition', [
380
+ params.tokenId,
381
+ params.category,
382
+ params.subCategory,
383
+ params.deadline,
384
+ params.description,
385
+ oracle,
386
+ condition,
387
+ ]);
388
+ }
389
+ return this.execute(wallet, 'createMarket', [
390
+ params.tokenId,
391
+ params.category,
392
+ params.subCategory,
393
+ params.deadline,
394
+ params.description,
395
+ oracle,
396
+ ]);
397
+ }
398
+ /**
399
+ * Place a prediction on a market. Auto-approves USDC allowance if needed.
400
+ *
401
+ * @param wallet - Wallet context for signing
402
+ * @param marketId - The market to predict on
403
+ * @param percentage - Prediction percentage (0-100)
404
+ * @param amount - USDC amount to stake
405
+ * @returns Transaction result
406
+ */
407
+ async placePrediction(wallet, marketId, percentage, amount) {
408
+ await this.ensureAllowance(wallet, amount);
409
+ return this.execute(wallet, 'placePrediction', [
410
+ marketId,
411
+ BigInt(percentage),
412
+ amount,
413
+ ]);
414
+ }
415
+ /**
416
+ * Update an existing prediction. Auto-approves USDC allowance for additional amount.
417
+ *
418
+ * @param wallet - Wallet context for signing
419
+ * @param marketId - The market of the prediction
420
+ * @param newPercentage - Updated percentage
421
+ * @param additionalAmount - Additional USDC to add (can be 0)
422
+ * @returns Transaction result
423
+ */
424
+ async updatePrediction(wallet, marketId, newPercentage, additionalAmount) {
425
+ if (additionalAmount > 0n) {
426
+ await this.ensureAllowance(wallet, additionalAmount);
427
+ }
428
+ return this.execute(wallet, 'updatePrediction', [
429
+ marketId,
430
+ BigInt(newPercentage),
431
+ additionalAmount,
432
+ ]);
433
+ }
434
+ /**
435
+ * Withdraw a prediction from a market (before deadline).
436
+ *
437
+ * @param wallet - Wallet context for signing
438
+ * @param marketId - The market to withdraw from
439
+ * @returns Transaction result
440
+ */
441
+ async withdrawPrediction(wallet, marketId) {
442
+ return this.execute(wallet, 'withdrawPrediction', [marketId]);
443
+ }
444
+ /**
445
+ * Cancel a market (dealer only).
446
+ *
447
+ * @param wallet - Wallet context for signing
448
+ * @param marketId - The market to cancel
449
+ * @returns Transaction result
450
+ */
451
+ async cancelMarket(wallet, marketId) {
452
+ return this.execute(wallet, 'cancelMarket', [marketId]);
453
+ }
454
+ /**
455
+ * Abandon a market (dealer only, after deadline without resolution).
456
+ *
457
+ * @param wallet - Wallet context for signing
458
+ * @param marketId - The market to abandon
459
+ * @returns Transaction result
460
+ */
461
+ async abandonMarket(wallet, marketId) {
462
+ return this.execute(wallet, 'abandonMarket', [marketId]);
463
+ }
464
+ /**
465
+ * Resolve a market with a manual resolution value (dealer only).
466
+ *
467
+ * @param wallet - Wallet context for signing
468
+ * @param marketId - The market to resolve
469
+ * @param positiveOutcome - true = positive side wins, false = negative side wins
470
+ * @returns Transaction result
471
+ */
472
+ async resolveMarket(wallet, marketId, positiveOutcome) {
473
+ return this.execute(wallet, 'resolveMarket', [marketId, positiveOutcome]);
474
+ }
475
+ /**
476
+ * Resolve a market using its configured oracle.
477
+ *
478
+ * @param wallet - Wallet context for signing
479
+ * @param marketId - The market to resolve via oracle
480
+ * @returns Transaction result
481
+ */
482
+ async resolveMarketWithOracle(wallet, marketId) {
483
+ return this.execute(wallet, 'resolveMarketWithOracle', [marketId]);
484
+ }
485
+ /**
486
+ * Request oracle resolution via Chainlink (step 1 of 2).
487
+ * Anyone can call. Sends a Chainlink request to fetch the game result.
488
+ *
489
+ * @param wallet - Wallet context for signing
490
+ * @param marketId - The market to request resolution for
491
+ * @returns Transaction result
492
+ */
493
+ async requestOracleResolution(wallet, marketId) {
494
+ return this.execute(wallet, 'requestOracleResolution', [marketId]);
495
+ }
496
+ /**
497
+ * Complete oracle resolution after Chainlink callback (step 2 of 2).
498
+ * Anyone can call after the Chainlink callback has delivered the result.
499
+ *
500
+ * @param wallet - Wallet context for signing
501
+ * @param marketId - The market to complete resolution for
502
+ * @returns Transaction result
503
+ */
504
+ async completeOracleResolution(wallet, marketId) {
505
+ return this.execute(wallet, 'completeOracleResolution', [marketId]);
506
+ }
507
+ /**
508
+ * Claim winnings from a resolved market.
509
+ *
510
+ * @param wallet - Wallet context for signing
511
+ * @param marketId - The market to claim winnings from
512
+ * @returns Transaction result
513
+ */
514
+ async claimWinnings(wallet, marketId) {
515
+ return this.execute(wallet, 'claimWinnings', [marketId]);
516
+ }
517
+ /**
518
+ * Claim a refund from a cancelled or abandoned market.
519
+ *
520
+ * @param wallet - Wallet context for signing
521
+ * @param marketId - The market to claim a refund from
522
+ * @returns Transaction result
523
+ */
524
+ async claimRefund(wallet, marketId) {
525
+ return this.execute(wallet, 'claimRefund', [marketId]);
526
+ }
527
+ /**
528
+ * Lock a market after its deadline, calculating the market split and enabling partial refunds.
529
+ * Anyone can call this after the market deadline.
530
+ *
531
+ * @param wallet - Wallet context for signing
532
+ * @param marketId - The market to lock
533
+ * @returns Transaction result
534
+ */
535
+ async lockMarket(wallet, marketId) {
536
+ return this.execute(wallet, 'lockMarket', [marketId]);
537
+ }
538
+ /**
539
+ * Calculate the market split boundaries (view function).
540
+ *
541
+ * @param publicClient - Public client for reading
542
+ * @param marketId - The market to calculate split for
543
+ * @returns Split boundaries: negPct, posPct, negAmt, posAmt, valid
544
+ */
545
+ async calculateMarketSplit(publicClient, marketId) {
546
+ return publicClient.readContract({
547
+ address: this.predictionMarketAddress(),
548
+ abi: predictionMarketAbi,
549
+ functionName: 'calculateMarketSplit',
550
+ args: [marketId],
551
+ });
552
+ }
553
+ /**
554
+ * Claim partial refund from a locked market (for overweight side bettors).
555
+ *
556
+ * @param wallet - Wallet context for signing
557
+ * @param marketId - The market to claim lock refund from
558
+ * @returns Transaction result
559
+ */
560
+ async claimLockRefund(wallet, marketId) {
561
+ return this.execute(wallet, 'claimLockRefund', [marketId]);
562
+ }
563
+ /**
564
+ * Read the lock refund amount for a specific predictor.
565
+ *
566
+ * @param publicClient - A viem PublicClient for reading state
567
+ * @param marketId - The market ID
568
+ * @param predictor - The predictor's wallet address
569
+ * @returns The refund amount as bigint
570
+ */
571
+ async getLockRefundAmount(publicClient, marketId, predictor) {
572
+ const result = await publicClient.readContract({
573
+ address: this.predictionMarketAddress(),
574
+ abi: this.abi,
575
+ functionName: 'getLockRefundAmount',
576
+ args: [marketId, predictor],
577
+ });
578
+ return BigInt(result);
579
+ }
580
+ /**
581
+ * Read the lock refund split boundaries for a locked market.
582
+ *
583
+ * @param publicClient - A viem PublicClient for reading state
584
+ * @param marketId - The market ID
585
+ * @returns { negativePercentage, positivePercentage, negativeAllowedAmount, positiveAllowedAmount }
586
+ */
587
+ async getLockRefundsSplit(publicClient, marketId) {
588
+ const result = (await publicClient.readContract({
589
+ address: this.predictionMarketAddress(),
590
+ abi: this.abi,
591
+ functionName: 'lockRefunds',
592
+ args: [marketId],
593
+ }));
594
+ return {
595
+ negativePercentage: result[0],
596
+ positivePercentage: result[1],
597
+ negativeAllowedAmount: result[2],
598
+ positiveAllowedAmount: result[3],
599
+ };
600
+ }
601
+ /**
602
+ * Withdraw accumulated dealer fees from a resolved market (dealer only).
603
+ *
604
+ * @param wallet - Wallet context for signing
605
+ * @param marketId - The market to withdraw fees from
606
+ * @returns Transaction result
607
+ */
608
+ async withdrawDealerFees(wallet, marketId) {
609
+ return this.execute(wallet, 'withdrawDealerFees', [marketId]);
610
+ }
611
+ /**
612
+ * Withdraw accumulated system fees (admin only).
613
+ *
614
+ * @param wallet - Wallet context for signing
615
+ * @returns Transaction result
616
+ */
617
+ async withdrawSystemFees(wallet) {
618
+ return this.execute(wallet, 'withdrawSystemFees', []);
619
+ }
620
+ /**
621
+ * Read market data from the smart contract.
622
+ *
623
+ * @param publicClient - A viem PublicClient for reading state
624
+ * @param marketId - The market ID to read
625
+ * @returns Formatted market data
626
+ */
627
+ async getMarket(publicClient, marketId) {
628
+ const raw = await publicClient.readContract({
629
+ address: this.predictionMarketAddress(),
630
+ abi: this.abi,
631
+ functionName: 'markets',
632
+ args: [marketId],
633
+ });
634
+ return formatMarket(raw);
635
+ }
636
+ /**
637
+ * Read prediction data for a specific user on a market.
638
+ *
639
+ * @param publicClient - A viem PublicClient for reading state
640
+ * @param marketId - The market ID
641
+ * @param account - The user's wallet address
642
+ * @returns Prediction data (amount, percentage, placedAt, claimed)
643
+ */
644
+ /**
645
+ * Read whether the contract is in test mode.
646
+ */
647
+ async getTestMode(publicClient) {
648
+ return (await publicClient.readContract({
649
+ address: this.predictionMarketAddress(),
650
+ abi: this.abi,
651
+ functionName: 'testMode',
652
+ }));
653
+ }
654
+ async getPrediction(publicClient, marketId, account) {
655
+ const raw = (await publicClient.readContract({
656
+ address: this.predictionMarketAddress(),
657
+ abi: this.abi,
658
+ functionName: 'predictions',
659
+ args: [marketId, account],
660
+ }));
661
+ return {
662
+ amount: BigInt(raw[0]),
663
+ percentage: BigInt(raw[1]),
664
+ placedAt: BigInt(raw[2]),
665
+ claimed: Boolean(raw[3]),
666
+ };
667
+ }
668
+ }
669
+ /**
670
+ * Format raw contract market data into a structured object.
671
+ *
672
+ * @param raw - Raw tuple from the contract's markets() call
673
+ * @returns Formatted market state object
674
+ */
675
+ function formatMarket(raw) {
676
+ return {
677
+ dealer: getAddress(raw[0]),
678
+ tokenId: BigInt(raw[1]),
679
+ category: BigInt(raw[2]),
680
+ subCategory: BigInt(raw[3]),
681
+ deadline: BigInt(raw[4]),
682
+ description: raw[5],
683
+ createdAt: BigInt(raw[6]),
684
+ dealerFeeBps: BigInt(raw[7]),
685
+ status: Number(raw[8]),
686
+ positiveOutcome: Boolean(raw[9]),
687
+ oracleId: raw[10],
688
+ conditionData: raw[11],
689
+ };
690
+ }
691
+ //# sourceMappingURL=evmClient.js.map