@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.
- package/dist/components/dealer/DealerNFTList.d.ts +6 -0
- package/dist/components/dealer/DealerNFTList.d.ts.map +1 -0
- package/dist/components/dealer/DealerNFTList.js +46 -0
- package/dist/components/dealer/DealerNFTList.js.map +1 -0
- package/dist/components/dealer/DealerNFTSelector.d.ts +8 -0
- package/dist/components/dealer/DealerNFTSelector.d.ts.map +1 -0
- package/dist/components/dealer/DealerNFTSelector.js +10 -0
- package/dist/components/dealer/DealerNFTSelector.js.map +1 -0
- package/dist/components/dealer/UpcomingGamesWidget.d.ts +8 -0
- package/dist/components/dealer/UpcomingGamesWidget.d.ts.map +1 -0
- package/dist/components/dealer/UpcomingGamesWidget.js +68 -0
- package/dist/components/dealer/UpcomingGamesWidget.js.map +1 -0
- package/dist/components/icons/index.d.ts +2 -0
- package/dist/components/icons/index.d.ts.map +1 -0
- package/dist/components/icons/index.js +2 -0
- package/dist/components/icons/index.js.map +1 -0
- package/dist/components/market/GameMarketsSection.d.ts +16 -0
- package/dist/components/market/GameMarketsSection.d.ts.map +1 -0
- package/dist/components/market/GameMarketsSection.js +18 -0
- package/dist/components/market/GameMarketsSection.js.map +1 -0
- package/dist/components/market/InlineCreateMarketForm.d.ts +17 -0
- package/dist/components/market/InlineCreateMarketForm.d.ts.map +1 -0
- package/dist/components/market/InlineCreateMarketForm.js +274 -0
- package/dist/components/market/InlineCreateMarketForm.js.map +1 -0
- package/dist/components/market/LeagueMarketsSection.d.ts +16 -0
- package/dist/components/market/LeagueMarketsSection.d.ts.map +1 -0
- package/dist/components/market/LeagueMarketsSection.js +15 -0
- package/dist/components/market/LeagueMarketsSection.js.map +1 -0
- package/dist/components/market/MarketCard.d.ts +8 -0
- package/dist/components/market/MarketCard.d.ts.map +1 -0
- package/dist/components/market/MarketCard.js +30 -0
- package/dist/components/market/MarketCard.js.map +1 -0
- package/dist/components/market/MarketList.d.ts +9 -0
- package/dist/components/market/MarketList.d.ts.map +1 -0
- package/dist/components/market/MarketList.js +17 -0
- package/dist/components/market/MarketList.js.map +1 -0
- package/dist/components/market/MarketStatusBadge.d.ts +8 -0
- package/dist/components/market/MarketStatusBadge.d.ts.map +1 -0
- package/dist/components/market/MarketStatusBadge.js +31 -0
- package/dist/components/market/MarketStatusBadge.js.map +1 -0
- package/dist/components/market/PredictionSlider.d.ts +11 -0
- package/dist/components/market/PredictionSlider.d.ts.map +1 -0
- package/dist/components/market/PredictionSlider.js +55 -0
- package/dist/components/market/PredictionSlider.js.map +1 -0
- package/dist/components/market/SportPredictionCard.d.ts +15 -0
- package/dist/components/market/SportPredictionCard.d.ts.map +1 -0
- package/dist/components/market/SportPredictionCard.js +92 -0
- package/dist/components/market/SportPredictionCard.js.map +1 -0
- package/dist/components/market/TeamMarketsSection.d.ts +17 -0
- package/dist/components/market/TeamMarketsSection.d.ts.map +1 -0
- package/dist/components/market/TeamMarketsSection.js +8 -0
- package/dist/components/market/TeamMarketsSection.js.map +1 -0
- package/dist/components/market/TeamTournamentMarketForm.d.ts +19 -0
- package/dist/components/market/TeamTournamentMarketForm.d.ts.map +1 -0
- package/dist/components/market/TeamTournamentMarketForm.js +92 -0
- package/dist/components/market/TeamTournamentMarketForm.js.map +1 -0
- package/dist/components/market/TournamentMarketForm.d.ts +19 -0
- package/dist/components/market/TournamentMarketForm.d.ts.map +1 -0
- package/dist/components/market/TournamentMarketForm.js +86 -0
- package/dist/components/market/TournamentMarketForm.js.map +1 -0
- package/dist/components/market/index.d.ts +12 -0
- package/dist/components/market/index.d.ts.map +1 -0
- package/dist/components/market/index.js +12 -0
- package/dist/components/market/index.js.map +1 -0
- package/dist/components/sports/SeasonSelector.d.ts +10 -0
- package/dist/components/sports/SeasonSelector.d.ts.map +1 -0
- package/dist/components/sports/SeasonSelector.js +13 -0
- package/dist/components/sports/SeasonSelector.js.map +1 -0
- package/dist/components/ui/AnimatedCollapse.d.ts +9 -0
- package/dist/components/ui/AnimatedCollapse.d.ts.map +1 -0
- package/dist/components/ui/AnimatedCollapse.js +8 -0
- package/dist/components/ui/AnimatedCollapse.js.map +1 -0
- package/dist/components/ui/FavoriteStar.d.ts +13 -0
- package/dist/components/ui/FavoriteStar.d.ts.map +1 -0
- package/dist/components/ui/FavoriteStar.js +47 -0
- package/dist/components/ui/FavoriteStar.js.map +1 -0
- package/dist/components/wallet/ConnectedWalletMenu.d.ts +16 -0
- package/dist/components/wallet/ConnectedWalletMenu.d.ts.map +1 -0
- package/dist/components/wallet/ConnectedWalletMenu.js +131 -0
- package/dist/components/wallet/ConnectedWalletMenu.js.map +1 -0
- package/dist/components/wallet/DealerRoute.d.ts +6 -0
- package/dist/components/wallet/DealerRoute.d.ts.map +1 -0
- package/dist/components/wallet/DealerRoute.js +20 -0
- package/dist/components/wallet/DealerRoute.js.map +1 -0
- package/dist/components/wallet/ProtectedRoute.d.ts +8 -0
- package/dist/components/wallet/ProtectedRoute.d.ts.map +1 -0
- package/dist/components/wallet/ProtectedRoute.js +17 -0
- package/dist/components/wallet/ProtectedRoute.js.map +1 -0
- package/dist/components/wallet/WalletConnectionModal.d.ts +7 -0
- package/dist/components/wallet/WalletConnectionModal.d.ts.map +1 -0
- package/dist/components/wallet/WalletConnectionModal.js +334 -0
- package/dist/components/wallet/WalletConnectionModal.js.map +1 -0
- package/dist/config/app.d.ts +24 -0
- package/dist/config/app.d.ts.map +1 -0
- package/dist/config/app.js +18 -0
- package/dist/config/app.js.map +1 -0
- package/dist/config/chains.d.ts +1070 -0
- package/dist/config/chains.d.ts.map +1 -0
- package/dist/config/chains.js +28 -0
- package/dist/config/chains.js.map +1 -0
- package/dist/config/contracts.d.ts +15 -0
- package/dist/config/contracts.d.ts.map +1 -0
- package/dist/config/contracts.js +62 -0
- package/dist/config/contracts.js.map +1 -0
- package/dist/config/sportCodes.d.ts +58 -0
- package/dist/config/sportCodes.d.ts.map +1 -0
- package/dist/config/sportCodes.js +78 -0
- package/dist/config/sportCodes.js.map +1 -0
- package/dist/context/IndexerContext.d.ts +34 -0
- package/dist/context/IndexerContext.d.ts.map +1 -0
- package/dist/context/IndexerContext.js +40 -0
- package/dist/context/IndexerContext.js.map +1 -0
- package/dist/context/WalletAuthContext.d.ts +26 -0
- package/dist/context/WalletAuthContext.d.ts.map +1 -0
- package/dist/context/WalletAuthContext.js +148 -0
- package/dist/context/WalletAuthContext.js.map +1 -0
- package/dist/hooks/index.d.ts +13 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +13 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useContractWithToast.d.ts +1348 -0
- package/dist/hooks/useContractWithToast.d.ts.map +1 -0
- package/dist/hooks/useContractWithToast.js +395 -0
- package/dist/hooks/useContractWithToast.js.map +1 -0
- package/dist/hooks/useDealerNFT.d.ts +71 -0
- package/dist/hooks/useDealerNFT.d.ts.map +1 -0
- package/dist/hooks/useDealerNFT.js +127 -0
- package/dist/hooks/useDealerNFT.js.map +1 -0
- package/dist/hooks/useDealerPermission.d.ts +11 -0
- package/dist/hooks/useDealerPermission.d.ts.map +1 -0
- package/dist/hooks/useDealerPermission.js +48 -0
- package/dist/hooks/useDealerPermission.js.map +1 -0
- package/dist/hooks/useFilteredSportsData.d.ts +20 -0
- package/dist/hooks/useFilteredSportsData.d.ts.map +1 -0
- package/dist/hooks/useFilteredSportsData.js +52 -0
- package/dist/hooks/useFilteredSportsData.js.map +1 -0
- package/dist/hooks/useGameMarkets.d.ts +23 -0
- package/dist/hooks/useGameMarkets.d.ts.map +1 -0
- package/dist/hooks/useGameMarkets.js +50 -0
- package/dist/hooks/useGameMarkets.js.map +1 -0
- package/dist/hooks/useLeagueMarkets.d.ts +11 -0
- package/dist/hooks/useLeagueMarkets.d.ts.map +1 -0
- package/dist/hooks/useLeagueMarkets.js +38 -0
- package/dist/hooks/useLeagueMarkets.js.map +1 -0
- package/dist/hooks/useMarketContract.d.ts +219 -0
- package/dist/hooks/useMarketContract.d.ts.map +1 -0
- package/dist/hooks/useMarketContract.js +790 -0
- package/dist/hooks/useMarketContract.js.map +1 -0
- package/dist/hooks/useToastActions.d.ts +13 -0
- package/dist/hooks/useToastActions.d.ts.map +1 -0
- package/dist/hooks/useToastActions.js +40 -0
- package/dist/hooks/useToastActions.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/evmClient.d.ts +299 -0
- package/dist/lib/evmClient.d.ts.map +1 -0
- package/dist/lib/evmClient.js +691 -0
- package/dist/lib/evmClient.js.map +1 -0
- package/dist/types/auth.d.ts +44 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +17 -0
- package/dist/types/auth.js.map +1 -0
- package/dist/types/dealer.d.ts +59 -0
- package/dist/types/dealer.d.ts.map +1 -0
- package/dist/types/dealer.js +31 -0
- package/dist/types/dealer.js.map +1 -0
- package/dist/types/market.d.ts +79 -0
- package/dist/types/market.d.ts.map +1 -0
- package/dist/types/market.js +47 -0
- package/dist/types/market.js.map +1 -0
- package/dist/utils/conditionData.d.ts +8 -0
- package/dist/utils/conditionData.d.ts.map +1 -0
- package/dist/utils/conditionData.js +7 -0
- package/dist/utils/conditionData.js.map +1 -0
- package/dist/utils/datetime.d.ts +3 -0
- package/dist/utils/datetime.d.ts.map +1 -0
- package/dist/utils/datetime.js +13 -0
- package/dist/utils/datetime.js.map +1 -0
- package/dist/utils/format.d.ts +79 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +144 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/marketDisplay.d.ts +28 -0
- package/dist/utils/marketDisplay.d.ts.map +1 -0
- package/dist/utils/marketDisplay.js +45 -0
- package/dist/utils/marketDisplay.js.map +1 -0
- package/dist/utils/marketId.d.ts +8 -0
- package/dist/utils/marketId.d.ts.map +1 -0
- package/dist/utils/marketId.js +12 -0
- package/dist/utils/marketId.js.map +1 -0
- package/dist/utils/oracleId.d.ts +33 -0
- package/dist/utils/oracleId.d.ts.map +1 -0
- package/dist/utils/oracleId.js +62 -0
- package/dist/utils/oracleId.js.map +1 -0
- package/dist/utils/sportsSeason.d.ts +10 -0
- package/dist/utils/sportsSeason.d.ts.map +1 -0
- package/dist/utils/sportsSeason.js +39 -0
- package/dist/utils/sportsSeason.js.map +1 -0
- 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
|