@vercora-protocol/sdk 0.0.1 → 0.0.4
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/client.d.ts +55 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +195 -30
- package/dist/client.js.map +1 -1
- package/dist/generated/vercora.d.ts +469 -109
- package/dist/generated/vercora.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/pda.d.ts +9 -2
- package/dist/pda.d.ts.map +1 -1
- package/dist/pda.js +14 -7
- package/dist/pda.js.map +1 -1
- package/dist/types.d.ts +75 -24
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as anchor from '@coral-xyz/anchor';
|
|
|
2
2
|
import { Program, BN } from '@coral-xyz/anchor';
|
|
3
3
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
4
4
|
import type { Vercora } from './generated/vercora';
|
|
5
|
-
import type { CreateMarketParams, InitializeParimutuelStateParams, ParimutuelStakeParams, ParimutuelWithdrawParams, ParimutuelClaimParams, InitializeConfigParams, UpdateConfigParams, InitializeMarketResolverSlotsParams, MintCompleteSetParams, RedeemCompleteSetParams, VoteResolutionParams, FinalizeResolutionParams, RevokeResolutionVoteParams, RedeemWinningParams, CloseMarketEarlyParams, VoidMarketParams, GlobalConfigAccount, MarketAccount, ResolverAccount, UpsertUserProfileParams, VerifyUserProfileParams, UserProfileAccount, ParimutuelStateAccount, ParimutuelPositionAccount, ParimutuelOdds } from './types';
|
|
5
|
+
import type { CreateMarketParams, InitializeParimutuelStateParams, ParimutuelStakeParams, ParimutuelWithdrawParams, ParimutuelClaimParams, InitializeConfigParams, UpdateConfigParams, InitializeMarketResolverSlotsParams, InitializeMarketOutcomeSlotsParams, MintCompleteSetParams, RedeemCompleteSetParams, VoteResolutionParams, FinalizeResolutionParams, RevokeResolutionVoteParams, RedeemWinningParams, CloseMarketEarlyParams, VoidMarketParams, AbandonMarketParams, GlobalConfigAccount, MarketAccount, ResolverAccount, UpsertUserProfileParams, VerifyUserProfileParams, UserProfileAccount, ParimutuelStateAccount, ParimutuelPositionAccount, ParimutuelOdds, MarketCategoryAccount, CreateMarketCategoryParams, UpdateMarketCategoryParams, UpdateParimutuelStateParams, ResolutionVoteAccount } from './types';
|
|
6
6
|
export declare class PredictionMarketClient {
|
|
7
7
|
readonly program: Program<Vercora>;
|
|
8
8
|
readonly connection: Connection;
|
|
@@ -32,6 +32,13 @@ export declare class PredictionMarketClient {
|
|
|
32
32
|
addAllowedCollateralMint(mint: PublicKey, opts?: anchor.web3.ConfirmOptions): Promise<string>;
|
|
33
33
|
/** Remove a collateral mint from the allowlist. */
|
|
34
34
|
removeAllowedCollateralMint(mint: PublicKey, opts?: anchor.web3.ConfirmOptions): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Create a new `MarketCategory` PDA.
|
|
37
|
+
* `params.categoryId` must equal `globalConfig.nextCategoryId` at call time.
|
|
38
|
+
*/
|
|
39
|
+
createMarketCategory(params: CreateMarketCategoryParams, opts?: anchor.web3.ConfirmOptions): Promise<string>;
|
|
40
|
+
/** Update an existing market category's name and active state. */
|
|
41
|
+
updateMarketCategory(params: UpdateMarketCategoryParams, opts?: anchor.web3.ConfirmOptions): Promise<string>;
|
|
35
42
|
/**
|
|
36
43
|
* Step 1 — Create Market + Vault.
|
|
37
44
|
* Returns the market PDA and the transaction signature.
|
|
@@ -46,6 +53,10 @@ export declare class PredictionMarketClient {
|
|
|
46
53
|
* dependency vs resolvers on-chain).
|
|
47
54
|
*/
|
|
48
55
|
initializeMarketResolverSlots(marketPda: PublicKey, params: InitializeMarketResolverSlotsParams, opts?: anchor.web3.ConfirmOptions, parimutuelStateParams?: InitializeParimutuelStateParams): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Initialize `MarketOutcome` PDAs for indices `0..labels.length-1` (creator as payer).
|
|
58
|
+
*/
|
|
59
|
+
initializeMarketOutcomeSlots(marketPda: PublicKey, params: InitializeMarketOutcomeSlotsParams, opts?: anchor.web3.ConfirmOptions): Promise<string>;
|
|
49
60
|
/**
|
|
50
61
|
* Step 3 — Initialize 8 Outcome Mints.
|
|
51
62
|
* Decimals are inherited from the collateral mint stored on the market account.
|
|
@@ -60,6 +71,11 @@ export declare class PredictionMarketClient {
|
|
|
60
71
|
resolverPubkeys: PublicKey[], params: CreateMarketParams, opts?: anchor.web3.ConfirmOptions): Promise<PublicKey>;
|
|
61
72
|
/** Pari-mutuel pool + penalty params (step after resolvers, replaces mint init). */
|
|
62
73
|
initializeParimutuelState(marketPda: PublicKey, params: InitializeParimutuelStateParams, opts?: anchor.web3.ConfirmOptions): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Update early-exit penalty parameters on an open pari-mutuel pool.
|
|
76
|
+
* Only callable by the market creator.
|
|
77
|
+
*/
|
|
78
|
+
updateParimutuelState(marketPda: PublicKey, params: UpdateParimutuelStateParams, opts?: anchor.web3.ConfirmOptions): Promise<string>;
|
|
63
79
|
parimutuelStake(marketPda: PublicKey, params: ParimutuelStakeParams, opts?: anchor.web3.ConfirmOptions): Promise<string>;
|
|
64
80
|
parimutuelWithdraw(marketPda: PublicKey, params: ParimutuelWithdrawParams, opts?: anchor.web3.ConfirmOptions): Promise<string>;
|
|
65
81
|
parimutuelClaim(marketPda: PublicKey, params: ParimutuelClaimParams, opts?: anchor.web3.ConfirmOptions): Promise<string>;
|
|
@@ -102,12 +118,50 @@ export declare class PredictionMarketClient {
|
|
|
102
118
|
closeMarketEarly(marketPda: PublicKey, params: CloseMarketEarlyParams, opts?: anchor.web3.ConfirmOptions): Promise<string>;
|
|
103
119
|
/** Void the market (cancel); enables full-set redemption for all holders. Creator or global authority only. */
|
|
104
120
|
voidMarket(marketPda: PublicKey, params: VoidMarketParams, opts?: anchor.web3.ConfirmOptions): Promise<string>;
|
|
121
|
+
/**
|
|
122
|
+
* Abandon an incomplete market and recover all rent (market account + vault).
|
|
123
|
+
*
|
|
124
|
+
* Only callable by the market creator while the vault holds zero collateral.
|
|
125
|
+
* Guards on the program side additionally reject resolved and voided markets.
|
|
126
|
+
* On success the market and vault accounts are closed and lamports returned to creator.
|
|
127
|
+
*/
|
|
128
|
+
abandonMarket(marketPda: PublicKey, params: AbandonMarketParams, opts?: anchor.web3.ConfirmOptions): Promise<string>;
|
|
105
129
|
fetchGlobalConfig(): Promise<GlobalConfigAccount>;
|
|
106
130
|
fetchMarket(market: PublicKey): Promise<MarketAccount>;
|
|
131
|
+
/**
|
|
132
|
+
* Read `MarketOutcome.label` for each active outcome index (parallel fetches).
|
|
133
|
+
* Missing accounts yield `Outcome {i+1}` placeholders.
|
|
134
|
+
*/
|
|
135
|
+
fetchMarketOutcomeLabels(marketPda: PublicKey, outcomeCount: number): Promise<string[]>;
|
|
107
136
|
/** Returns the collateral balance (base units) held in the vault. */
|
|
108
137
|
fetchVaultBalance(market: PublicKey): Promise<bigint>;
|
|
109
138
|
/** Returns the outcome token balance (base units) for a user and outcome index. */
|
|
110
139
|
fetchOutcomeBalance(market: PublicKey, user: PublicKey, outcomeIndex: number): Promise<bigint>;
|
|
140
|
+
/** Fetch a single `MarketCategory` account by its PDA. */
|
|
141
|
+
fetchMarketCategory(categoryPda: PublicKey): Promise<MarketCategoryAccount>;
|
|
142
|
+
/**
|
|
143
|
+
* Fetch all on-chain `MarketCategory` accounts.
|
|
144
|
+
* Returns an array sorted by `id` ascending.
|
|
145
|
+
*/
|
|
146
|
+
fetchAllMarketCategories(): Promise<{
|
|
147
|
+
pubkey: PublicKey;
|
|
148
|
+
account: MarketCategoryAccount;
|
|
149
|
+
}[]>;
|
|
150
|
+
/**
|
|
151
|
+
* Fetch the `ResolutionVote` PDA for a specific resolver slot.
|
|
152
|
+
* Returns `null` if the account does not exist (resolver has not voted).
|
|
153
|
+
*/
|
|
154
|
+
fetchResolutionVote(marketPda: PublicKey, resolverIndex: number): Promise<ResolutionVoteAccount | null>;
|
|
155
|
+
/**
|
|
156
|
+
* Fetch the resolver vote tally (resolutionVoteCount) for all 8 outcome slots.
|
|
157
|
+
* Missing PDAs return 0.
|
|
158
|
+
*/
|
|
159
|
+
fetchOutcomeTallyCounts(marketPda: PublicKey): Promise<number[]>;
|
|
160
|
+
/**
|
|
161
|
+
* Fetch all allowed collateral mints from the platform allowlist.
|
|
162
|
+
* Returns an array of mint public keys sorted lexicographically.
|
|
163
|
+
*/
|
|
164
|
+
fetchAllowedCollateralMints(): Promise<PublicKey[]>;
|
|
111
165
|
/**
|
|
112
166
|
* Create or update the caller's on-chain user profile.
|
|
113
167
|
* The PDA `["user-profile", wallet]` is initialized on first call (payer = wallet);
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACL,UAAU,EACV,SAAS,EAKV,MAAM,iBAAiB,CAAC;AASzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACL,UAAU,EACV,SAAS,EAKV,MAAM,iBAAiB,CAAC;AASzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAmBnD,OAAO,KAAK,EACV,kBAAkB,EAClB,+BAA+B,EAC/B,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,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AA;KAAE,EAAE,CAAC;YAmB5C,WAAW;CA2B1B"}
|
package/dist/client.js
CHANGED
|
@@ -48,7 +48,7 @@ class PredictionMarketClient {
|
|
|
48
48
|
*/
|
|
49
49
|
async initializeConfig(params, opts) {
|
|
50
50
|
return this.program.methods
|
|
51
|
-
.initializeConfig(params.secondaryAuthority, params.depositPlatformFeeBps, params.platformTreasuryWallet, params.platformFeeLamports, params.
|
|
51
|
+
.initializeConfig(params.secondaryAuthority, params.depositPlatformFeeBps, params.platformTreasuryWallet, params.platformFeeLamports, params.parimutuelWithdrawPlatformFeeBps)
|
|
52
52
|
.accounts({
|
|
53
53
|
globalConfig: this.globalConfig,
|
|
54
54
|
authority: this.walletKey,
|
|
@@ -63,7 +63,7 @@ class PredictionMarketClient {
|
|
|
63
63
|
*/
|
|
64
64
|
async updateConfig(params, opts) {
|
|
65
65
|
return this.program.methods
|
|
66
|
-
.updateConfig(params.secondaryAuthority, params.depositPlatformFeeBps, params.platformTreasuryWallet, params.platformFeeLamports, params.
|
|
66
|
+
.updateConfig(params.secondaryAuthority, params.depositPlatformFeeBps, params.platformTreasuryWallet, params.platformFeeLamports, params.parimutuelWithdrawPlatformFeeBps)
|
|
67
67
|
.accounts({
|
|
68
68
|
globalConfig: this.globalConfig,
|
|
69
69
|
authority: this.walletKey,
|
|
@@ -99,6 +99,33 @@ class PredictionMarketClient {
|
|
|
99
99
|
})
|
|
100
100
|
.rpc(opts ?? { skipPreflight: true });
|
|
101
101
|
}
|
|
102
|
+
// ─── Market categories ───────────────────────────────────────────────────────
|
|
103
|
+
/**
|
|
104
|
+
* Create a new `MarketCategory` PDA.
|
|
105
|
+
* `params.categoryId` must equal `globalConfig.nextCategoryId` at call time.
|
|
106
|
+
*/
|
|
107
|
+
async createMarketCategory(params, opts) {
|
|
108
|
+
return this.program.methods
|
|
109
|
+
.createMarketCategory(params.categoryId, params.name)
|
|
110
|
+
.accounts({
|
|
111
|
+
globalConfig: this.globalConfig,
|
|
112
|
+
marketCategory: (0, pda_1.deriveMarketCategory)(this.program.programId, params.categoryId),
|
|
113
|
+
authority: this.walletKey,
|
|
114
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
115
|
+
})
|
|
116
|
+
.rpc(opts ?? { skipPreflight: true });
|
|
117
|
+
}
|
|
118
|
+
/** Update an existing market category's name and active state. */
|
|
119
|
+
async updateMarketCategory(params, opts) {
|
|
120
|
+
return this.program.methods
|
|
121
|
+
.updateMarketCategory(params.name, params.active)
|
|
122
|
+
.accounts({
|
|
123
|
+
globalConfig: this.globalConfig,
|
|
124
|
+
marketCategory: (0, pda_1.deriveMarketCategory)(this.program.programId, params.categoryId),
|
|
125
|
+
authority: this.walletKey,
|
|
126
|
+
})
|
|
127
|
+
.rpc(opts ?? { skipPreflight: true });
|
|
128
|
+
}
|
|
102
129
|
// ─── Market creation (3 steps) ──────────────────────────────────────────────
|
|
103
130
|
/**
|
|
104
131
|
* Step 1 — Create Market + Vault.
|
|
@@ -126,6 +153,7 @@ class PredictionMarketClient {
|
|
|
126
153
|
creatorFeeBps: params.creatorFeeBps,
|
|
127
154
|
depositPlatformFeeBps: params.depositPlatformFeeBps,
|
|
128
155
|
numResolvers: params.numResolvers,
|
|
156
|
+
maxOutcomeInvestment: params.maxOutcomeInvestment ?? new anchor_1.BN(0),
|
|
129
157
|
title: params.title,
|
|
130
158
|
marketType: (0, types_1.toMarketTypeIx)(params.marketType),
|
|
131
159
|
})
|
|
@@ -190,7 +218,6 @@ class PredictionMarketClient {
|
|
|
190
218
|
marketId: parimutuelStateParams.marketId,
|
|
191
219
|
earlyWithdrawPenaltyBps: parimutuelStateParams.earlyWithdrawPenaltyBps,
|
|
192
220
|
penaltyKeptInPoolBps: parimutuelStateParams.penaltyKeptInPoolBps,
|
|
193
|
-
penaltySurplusCreatorShareBps: parimutuelStateParams.penaltySurplusCreatorShareBps,
|
|
194
221
|
})
|
|
195
222
|
.accounts({
|
|
196
223
|
payer: this.walletKey,
|
|
@@ -204,6 +231,31 @@ class PredictionMarketClient {
|
|
|
204
231
|
}
|
|
205
232
|
return await provider.sendAndConfirm(tx, undefined, opts ?? { skipPreflight: true });
|
|
206
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Initialize `MarketOutcome` PDAs for indices `0..labels.length-1` (creator as payer).
|
|
236
|
+
*/
|
|
237
|
+
async initializeMarketOutcomeSlots(marketPda, params, opts) {
|
|
238
|
+
const provider = this.program.provider;
|
|
239
|
+
const tx = new web3_js_1.Transaction();
|
|
240
|
+
for (let i = 0; i < params.labels.length; i++) {
|
|
241
|
+
const label = params.labels[i];
|
|
242
|
+
const ix = await this.program.methods
|
|
243
|
+
.initializeMarketOutcome({
|
|
244
|
+
marketId: params.marketId,
|
|
245
|
+
outcomeIndex: i,
|
|
246
|
+
label,
|
|
247
|
+
})
|
|
248
|
+
.accounts({
|
|
249
|
+
payer: this.walletKey,
|
|
250
|
+
market: marketPda,
|
|
251
|
+
marketOutcome: (0, pda_1.deriveMarketOutcome)(this.program.programId, marketPda, i),
|
|
252
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
253
|
+
})
|
|
254
|
+
.instruction();
|
|
255
|
+
tx.add(ix);
|
|
256
|
+
}
|
|
257
|
+
return await provider.sendAndConfirm(tx, undefined, opts ?? { skipPreflight: true });
|
|
258
|
+
}
|
|
207
259
|
/**
|
|
208
260
|
* Step 3 — Initialize 8 Outcome Mints.
|
|
209
261
|
* Decimals are inherited from the collateral mint stored on the market account.
|
|
@@ -236,11 +288,14 @@ class PredictionMarketClient {
|
|
|
236
288
|
/** Length must equal `params.numResolvers` (typically the first N of an 8-slot UI). */
|
|
237
289
|
resolverPubkeys, params, opts) {
|
|
238
290
|
const { marketPda } = await this.createMarket(creator, collateralMint, creatorFeeAccount, params, opts);
|
|
291
|
+
const labels = params.outcomeLabels ??
|
|
292
|
+
Array.from({ length: params.outcomeCount }, (_, i) => `Outcome ${i}`);
|
|
293
|
+
if (labels.length !== params.outcomeCount) {
|
|
294
|
+
throw new Error('outcomeLabels length must equal outcomeCount');
|
|
295
|
+
}
|
|
296
|
+
await this.initializeMarketOutcomeSlots(marketPda, { marketId: params.marketId, labels }, opts);
|
|
239
297
|
if (params.marketType === 'parimutuel') {
|
|
240
|
-
const gc = await this.fetchGlobalConfig();
|
|
241
298
|
const pi = params.parimutuelInit ?? {};
|
|
242
|
-
const penaltySurplusCreatorShareBps = pi.penaltySurplusCreatorShareBps ??
|
|
243
|
-
10000 - gc.parimutuelPenaltyProtocolShareBps;
|
|
244
299
|
await this.initializeMarketResolverSlots(marketPda, {
|
|
245
300
|
marketId: params.marketId,
|
|
246
301
|
resolverPubkeys: resolverPubkeys.slice(0, params.numResolvers),
|
|
@@ -248,7 +303,6 @@ class PredictionMarketClient {
|
|
|
248
303
|
marketId: params.marketId,
|
|
249
304
|
earlyWithdrawPenaltyBps: pi.earlyWithdrawPenaltyBps ?? 500,
|
|
250
305
|
penaltyKeptInPoolBps: pi.penaltyKeptInPoolBps ?? 8000,
|
|
251
|
-
penaltySurplusCreatorShareBps,
|
|
252
306
|
});
|
|
253
307
|
}
|
|
254
308
|
else {
|
|
@@ -271,7 +325,6 @@ class PredictionMarketClient {
|
|
|
271
325
|
marketId: params.marketId,
|
|
272
326
|
earlyWithdrawPenaltyBps: params.earlyWithdrawPenaltyBps,
|
|
273
327
|
penaltyKeptInPoolBps: params.penaltyKeptInPoolBps,
|
|
274
|
-
penaltySurplusCreatorShareBps: params.penaltySurplusCreatorShareBps,
|
|
275
328
|
})
|
|
276
329
|
.accounts({
|
|
277
330
|
payer: this.walletKey,
|
|
@@ -287,15 +340,34 @@ class PredictionMarketClient {
|
|
|
287
340
|
tx.add(pariIx);
|
|
288
341
|
return await provider.sendAndConfirm(tx, [], opts ?? { commitment: 'confirmed', skipPreflight: true });
|
|
289
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Update early-exit penalty parameters on an open pari-mutuel pool.
|
|
345
|
+
* Only callable by the market creator.
|
|
346
|
+
*/
|
|
347
|
+
async updateParimutuelState(marketPda, params, opts) {
|
|
348
|
+
return this.program.methods
|
|
349
|
+
.updateParimutuelState({
|
|
350
|
+
marketId: params.marketId,
|
|
351
|
+
earlyWithdrawPenaltyBps: params.earlyWithdrawPenaltyBps,
|
|
352
|
+
penaltyKeptInPoolBps: params.penaltyKeptInPoolBps,
|
|
353
|
+
})
|
|
354
|
+
.accounts({
|
|
355
|
+
creator: this.walletKey,
|
|
356
|
+
market: marketPda,
|
|
357
|
+
parimutuelState: (0, pda_1.deriveParimutuelState)(this.program.programId, marketPda),
|
|
358
|
+
})
|
|
359
|
+
.rpc(opts ?? { skipPreflight: true });
|
|
360
|
+
}
|
|
290
361
|
async parimutuelStake(marketPda, params, opts) {
|
|
291
362
|
const parimutuelState = (0, pda_1.deriveParimutuelState)(this.program.programId, marketPda);
|
|
292
363
|
const market = await this.fetchMarket(marketPda);
|
|
293
364
|
const globalConfig = await this.fetchGlobalConfig();
|
|
365
|
+
const collateralTokenProgram = await this.collateralTokenProgramForMint(market.collateralMint);
|
|
294
366
|
const position = (0, pda_1.deriveParimutuelPosition)(this.program.programId, marketPda, this.walletKey, params.outcomeIndex);
|
|
295
367
|
const vaultPda = (0, pda_1.deriveVault)(this.program.programId, marketPda);
|
|
296
368
|
const allowedMint = (0, pda_1.deriveAllowedMint)(this.program.programId, market.collateralMint);
|
|
297
|
-
const userCollateral = (0, spl_token_1.getAssociatedTokenAddressSync)(market.collateralMint, this.walletKey, false,
|
|
298
|
-
const platformTreasuryAta = (0, spl_token_1.getAssociatedTokenAddressSync)(market.collateralMint, globalConfig.platformTreasury, false,
|
|
369
|
+
const userCollateral = (0, spl_token_1.getAssociatedTokenAddressSync)(market.collateralMint, this.walletKey, false, collateralTokenProgram, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
370
|
+
const platformTreasuryAta = (0, spl_token_1.getAssociatedTokenAddressSync)(market.collateralMint, globalConfig.platformTreasury, false, collateralTokenProgram, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
299
371
|
return this.program.methods
|
|
300
372
|
.parimutuelStake({
|
|
301
373
|
marketId: params.marketId,
|
|
@@ -315,7 +387,7 @@ class PredictionMarketClient {
|
|
|
315
387
|
platformTreasuryWallet: globalConfig.platformTreasury,
|
|
316
388
|
platformTreasuryAta,
|
|
317
389
|
allowedMint,
|
|
318
|
-
collateralTokenProgram
|
|
390
|
+
collateralTokenProgram,
|
|
319
391
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
320
392
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
321
393
|
})
|
|
@@ -327,8 +399,9 @@ class PredictionMarketClient {
|
|
|
327
399
|
const position = (0, pda_1.deriveParimutuelPosition)(this.program.programId, marketPda, this.walletKey, params.outcomeIndex);
|
|
328
400
|
const vaultPda = (0, pda_1.deriveVault)(this.program.programId, marketPda);
|
|
329
401
|
const globalConfig = await this.fetchGlobalConfig();
|
|
330
|
-
const
|
|
331
|
-
const
|
|
402
|
+
const collateralTokenProgram = await this.collateralTokenProgramForMint(market.collateralMint);
|
|
403
|
+
const userCollateral = (0, spl_token_1.getAssociatedTokenAddressSync)(market.collateralMint, this.walletKey, false, collateralTokenProgram, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
404
|
+
const platformTreasuryAta = (0, spl_token_1.getAssociatedTokenAddressSync)(market.collateralMint, globalConfig.platformTreasury, false, collateralTokenProgram, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
332
405
|
return this.program.methods
|
|
333
406
|
.parimutuelWithdraw({
|
|
334
407
|
marketId: params.marketId,
|
|
@@ -347,7 +420,7 @@ class PredictionMarketClient {
|
|
|
347
420
|
globalConfig: this.globalConfig,
|
|
348
421
|
platformTreasuryWallet: globalConfig.platformTreasury,
|
|
349
422
|
platformTreasuryAta,
|
|
350
|
-
collateralTokenProgram
|
|
423
|
+
collateralTokenProgram,
|
|
351
424
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
352
425
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
353
426
|
})
|
|
@@ -356,9 +429,10 @@ class PredictionMarketClient {
|
|
|
356
429
|
async parimutuelClaim(marketPda, params, opts) {
|
|
357
430
|
const parimutuelState = (0, pda_1.deriveParimutuelState)(this.program.programId, marketPda);
|
|
358
431
|
const market = await this.fetchMarket(marketPda);
|
|
432
|
+
const collateralTokenProgram = await this.collateralTokenProgramForMint(market.collateralMint);
|
|
359
433
|
const position = (0, pda_1.deriveParimutuelPosition)(this.program.programId, marketPda, this.walletKey, params.outcomeIndex);
|
|
360
434
|
const vaultPda = (0, pda_1.deriveVault)(this.program.programId, marketPda);
|
|
361
|
-
const userCollateral = (0, spl_token_1.getAssociatedTokenAddressSync)(market.collateralMint, this.walletKey, false,
|
|
435
|
+
const userCollateral = (0, spl_token_1.getAssociatedTokenAddressSync)(market.collateralMint, this.walletKey, false, collateralTokenProgram, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
362
436
|
return this.program.methods
|
|
363
437
|
.parimutuelClaim({
|
|
364
438
|
marketId: params.marketId,
|
|
@@ -372,7 +446,7 @@ class PredictionMarketClient {
|
|
|
372
446
|
vault: vaultPda,
|
|
373
447
|
collateralMint: market.collateralMint,
|
|
374
448
|
userCollateralAccount: userCollateral,
|
|
375
|
-
collateralTokenProgram
|
|
449
|
+
collateralTokenProgram,
|
|
376
450
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
377
451
|
})
|
|
378
452
|
.rpc(opts ?? { skipPreflight: true });
|
|
@@ -462,7 +536,7 @@ class PredictionMarketClient {
|
|
|
462
536
|
*/
|
|
463
537
|
async voteResolution(marketPda, params, opts) {
|
|
464
538
|
const votePda = (0, pda_1.deriveResolutionVote)(this.program.programId, marketPda, params.resolverIndex);
|
|
465
|
-
const
|
|
539
|
+
const marketOutcomePda = (0, pda_1.deriveMarketOutcome)(this.program.programId, marketPda, params.outcomeIndex);
|
|
466
540
|
return this.program.methods
|
|
467
541
|
.voteResolution({
|
|
468
542
|
marketId: params.marketId,
|
|
@@ -474,7 +548,7 @@ class PredictionMarketClient {
|
|
|
474
548
|
market: marketPda,
|
|
475
549
|
resolver: (0, pda_1.deriveResolver)(this.program.programId, marketPda, params.resolverIndex),
|
|
476
550
|
resolutionVote: votePda,
|
|
477
|
-
|
|
551
|
+
marketOutcome: marketOutcomePda,
|
|
478
552
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
479
553
|
})
|
|
480
554
|
.rpc(opts ?? { skipPreflight: true });
|
|
@@ -482,7 +556,7 @@ class PredictionMarketClient {
|
|
|
482
556
|
/** Clears the resolver’s active vote and decrements that outcome’s on-chain tally. */
|
|
483
557
|
async revokeResolutionVote(marketPda, params, opts) {
|
|
484
558
|
const votePda = (0, pda_1.deriveResolutionVote)(this.program.programId, marketPda, params.resolverIndex);
|
|
485
|
-
const
|
|
559
|
+
const marketOutcomePda = (0, pda_1.deriveMarketOutcome)(this.program.programId, marketPda, params.outcomeIndex);
|
|
486
560
|
return this.program.methods
|
|
487
561
|
.revokeResolutionVote({
|
|
488
562
|
marketId: params.marketId,
|
|
@@ -494,7 +568,7 @@ class PredictionMarketClient {
|
|
|
494
568
|
market: marketPda,
|
|
495
569
|
resolver: (0, pda_1.deriveResolver)(this.program.programId, marketPda, params.resolverIndex),
|
|
496
570
|
resolutionVote: votePda,
|
|
497
|
-
|
|
571
|
+
marketOutcome: marketOutcomePda,
|
|
498
572
|
})
|
|
499
573
|
.rpc(opts ?? { skipPreflight: true });
|
|
500
574
|
}
|
|
@@ -504,20 +578,20 @@ class PredictionMarketClient {
|
|
|
504
578
|
* Passes optional per-outcome tally accounts (null if that tally PDA was never created).
|
|
505
579
|
*/
|
|
506
580
|
async finalizeResolution(marketPda, params, opts) {
|
|
507
|
-
const
|
|
508
|
-
const infos = await Promise.all(
|
|
581
|
+
const outcomes = (0, pda_1.deriveAllMarketOutcomes)(this.program.programId, marketPda);
|
|
582
|
+
const infos = await Promise.all(outcomes.map((p) => this.connection.getAccountInfo(p)));
|
|
509
583
|
return this.program.methods
|
|
510
584
|
.finalizeResolution({ marketId: params.marketId })
|
|
511
585
|
.accounts({
|
|
512
586
|
market: marketPda,
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
587
|
+
marketOutcome0: infos[0] ? outcomes[0] : null,
|
|
588
|
+
marketOutcome1: infos[1] ? outcomes[1] : null,
|
|
589
|
+
marketOutcome2: infos[2] ? outcomes[2] : null,
|
|
590
|
+
marketOutcome3: infos[3] ? outcomes[3] : null,
|
|
591
|
+
marketOutcome4: infos[4] ? outcomes[4] : null,
|
|
592
|
+
marketOutcome5: infos[5] ? outcomes[5] : null,
|
|
593
|
+
marketOutcome6: infos[6] ? outcomes[6] : null,
|
|
594
|
+
marketOutcome7: infos[7] ? outcomes[7] : null,
|
|
521
595
|
})
|
|
522
596
|
.rpc(opts ?? { skipPreflight: true });
|
|
523
597
|
}
|
|
@@ -584,6 +658,29 @@ class PredictionMarketClient {
|
|
|
584
658
|
})
|
|
585
659
|
.rpc(opts ?? { skipPreflight: true });
|
|
586
660
|
}
|
|
661
|
+
/**
|
|
662
|
+
* Abandon an incomplete market and recover all rent (market account + vault).
|
|
663
|
+
*
|
|
664
|
+
* Only callable by the market creator while the vault holds zero collateral.
|
|
665
|
+
* Guards on the program side additionally reject resolved and voided markets.
|
|
666
|
+
* On success the market and vault accounts are closed and lamports returned to creator.
|
|
667
|
+
*/
|
|
668
|
+
async abandonMarket(marketPda, params, opts) {
|
|
669
|
+
const market = await this.fetchMarket(marketPda);
|
|
670
|
+
const collateralMint = market.collateralMint;
|
|
671
|
+
const collateralTokenProgram = await this.collateralTokenProgramForMint(collateralMint);
|
|
672
|
+
return this.program.methods
|
|
673
|
+
.abandonMarket({ marketId: params.marketId })
|
|
674
|
+
.accounts({
|
|
675
|
+
creator: this.walletKey,
|
|
676
|
+
market: marketPda,
|
|
677
|
+
vault: (0, pda_1.deriveVault)(this.program.programId, marketPda),
|
|
678
|
+
collateralMint,
|
|
679
|
+
collateralTokenProgram,
|
|
680
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
681
|
+
})
|
|
682
|
+
.rpc(opts ?? { skipPreflight: true });
|
|
683
|
+
}
|
|
587
684
|
// ─── State readers ───────────────────────────────────────────────────────────
|
|
588
685
|
async fetchGlobalConfig() {
|
|
589
686
|
return this.program.account.globalConfig.fetch(this.globalConfig);
|
|
@@ -591,6 +688,23 @@ class PredictionMarketClient {
|
|
|
591
688
|
async fetchMarket(market) {
|
|
592
689
|
return this.program.account.market.fetch(market);
|
|
593
690
|
}
|
|
691
|
+
/**
|
|
692
|
+
* Read `MarketOutcome.label` for each active outcome index (parallel fetches).
|
|
693
|
+
* Missing accounts yield `Outcome {i+1}` placeholders.
|
|
694
|
+
*/
|
|
695
|
+
async fetchMarketOutcomeLabels(marketPda, outcomeCount) {
|
|
696
|
+
return Promise.all(Array.from({ length: outcomeCount }, async (_, i) => {
|
|
697
|
+
const pda = (0, pda_1.deriveMarketOutcome)(this.program.programId, marketPda, i);
|
|
698
|
+
try {
|
|
699
|
+
const acc = (await this.program.account.marketOutcome.fetch(pda));
|
|
700
|
+
const t = (acc.label ?? '').trim();
|
|
701
|
+
return t || `Outcome ${i + 1}`;
|
|
702
|
+
}
|
|
703
|
+
catch {
|
|
704
|
+
return `Outcome ${i + 1}`;
|
|
705
|
+
}
|
|
706
|
+
}));
|
|
707
|
+
}
|
|
594
708
|
/** Returns the collateral balance (base units) held in the vault. */
|
|
595
709
|
async fetchVaultBalance(market) {
|
|
596
710
|
const vault = (0, pda_1.deriveVault)(this.program.programId, market);
|
|
@@ -604,6 +718,57 @@ class PredictionMarketClient {
|
|
|
604
718
|
const acc = await (0, spl_token_1.getAccount)(this.connection, ata, undefined, spl_token_1.TOKEN_PROGRAM_ID);
|
|
605
719
|
return acc.amount;
|
|
606
720
|
}
|
|
721
|
+
/** Fetch a single `MarketCategory` account by its PDA. */
|
|
722
|
+
async fetchMarketCategory(categoryPda) {
|
|
723
|
+
return this.program.account.marketCategory.fetch(categoryPda);
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Fetch all on-chain `MarketCategory` accounts.
|
|
727
|
+
* Returns an array sorted by `id` ascending.
|
|
728
|
+
*/
|
|
729
|
+
async fetchAllMarketCategories() {
|
|
730
|
+
const rows = await this.program.account.marketCategory.all();
|
|
731
|
+
return rows
|
|
732
|
+
.map((r) => ({ pubkey: r.publicKey, account: r.account }))
|
|
733
|
+
.sort((a, b) => a.account.id.cmp(b.account.id));
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Fetch the `ResolutionVote` PDA for a specific resolver slot.
|
|
737
|
+
* Returns `null` if the account does not exist (resolver has not voted).
|
|
738
|
+
*/
|
|
739
|
+
async fetchResolutionVote(marketPda, resolverIndex) {
|
|
740
|
+
const pda = (0, pda_1.deriveResolutionVote)(this.program.programId, marketPda, resolverIndex);
|
|
741
|
+
const info = await this.connection.getAccountInfo(pda);
|
|
742
|
+
if (!info)
|
|
743
|
+
return null;
|
|
744
|
+
return this.program.account.resolutionVote.fetch(pda);
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Fetch the resolver vote tally (resolutionVoteCount) for all 8 outcome slots.
|
|
748
|
+
* Missing PDAs return 0.
|
|
749
|
+
*/
|
|
750
|
+
async fetchOutcomeTallyCounts(marketPda) {
|
|
751
|
+
const pdas = (0, pda_1.deriveAllMarketOutcomes)(this.program.programId, marketPda);
|
|
752
|
+
return Promise.all(pdas.map(async (pda) => {
|
|
753
|
+
try {
|
|
754
|
+
const acc = (await this.program.account.marketOutcome.fetch(pda));
|
|
755
|
+
return Number(acc.resolutionVoteCount ?? 0);
|
|
756
|
+
}
|
|
757
|
+
catch {
|
|
758
|
+
return 0;
|
|
759
|
+
}
|
|
760
|
+
}));
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Fetch all allowed collateral mints from the platform allowlist.
|
|
764
|
+
* Returns an array of mint public keys sorted lexicographically.
|
|
765
|
+
*/
|
|
766
|
+
async fetchAllowedCollateralMints() {
|
|
767
|
+
const rows = await this.program.account.allowedMint.all();
|
|
768
|
+
const mints = rows.map((r) => r.account.mint);
|
|
769
|
+
mints.sort((a, b) => a.toBase58().localeCompare(b.toBase58()));
|
|
770
|
+
return mints;
|
|
771
|
+
}
|
|
607
772
|
// ─── User profiles ───────────────────────────────────────────────────────────
|
|
608
773
|
/**
|
|
609
774
|
* Create or update the caller's on-chain user profile.
|