@bench.games/conviction-markets 0.1.5 → 0.1.6

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.
@@ -1,104 +1,16 @@
1
- import type { PublicKey } from "@solana/web3.js";
2
- import type { BN } from "@coral-xyz/anchor";
3
1
  /**
4
- * Conviction Market account structure
2
+ * Account types are now inferred from the Anchor program and exported from utils/accounts.ts
5
3
  *
6
- * Represents a prediction/voting market where users can stake capital
7
- * on their preferred option with encrypted votes.
8
- */
9
- export interface ConvictionMarketAccount {
10
- /** Encrypted available shares state */
11
- encryptedAvailableShares: Uint8Array[][];
12
- /** PDA bump seed */
13
- bump: number;
14
- /** Market creator's public key */
15
- creator: PublicKey;
16
- /** Unique market index */
17
- index: BN;
18
- /** Current number of options added */
19
- totalOptions: number;
20
- /** Maximum number of options allowed */
21
- maxOptions: number;
22
- /** Timestamp when market opens for trading */
23
- openTimestamp?: BN;
24
- /** Duration of staking period in seconds */
25
- timeToStake: BN;
26
- /** Duration of reveal period in seconds */
27
- timeToReveal: BN;
28
- /** Selected winning option (if set) */
29
- selectedOption?: number;
30
- /** Nonce for encrypted state */
31
- stateNonce: BN;
32
- /** Maximum shares available for purchase */
33
- maxShares: BN;
34
- /** Reward pool in lamports for winners */
35
- rewardLamports: BN;
36
- /** Optional authority that can select winning option */
37
- selectAuthority?: PublicKey;
38
- }
39
- /**
40
- * Vote Token Account structure
41
- *
42
- * Holds a user's encrypted vote token balance.
43
- * Vote tokens are used to purchase market shares.
44
- */
45
- export interface VoteTokenAccountData {
46
- /** Encrypted token balance state */
47
- encryptedState: Uint8Array[][];
48
- /** PDA bump seed */
49
- bump: number;
50
- /** Account owner's public key */
51
- owner: PublicKey;
52
- /** Nonce for encrypted state */
53
- stateNonce: BN;
54
- }
55
- /**
56
- * Share Account structure
57
- *
58
- * Represents a user's encrypted position in a specific market,
59
- * including the amount of shares and selected option.
60
- */
61
- export interface ShareAccountData {
62
- /** Encrypted state: [share_amount, selected_option] */
63
- encryptedState: Uint8Array[][];
64
- /** Nonce for encrypted state */
65
- stateNonce: BN;
66
- /** PDA bump seed */
67
- bump: number;
68
- /** Account owner's public key */
69
- owner: PublicKey;
70
- /** Market this share account is for */
71
- market: PublicKey;
72
- /** Encrypted state disclosure for analytics */
73
- encryptedStateDisclosure: Uint8Array[][];
74
- /** Nonce for disclosure state */
75
- stateNonceDisclosure: BN;
76
- /** Timestamp when shares were purchased */
77
- boughtAtTimestamp: BN;
78
- /** Revealed share amount (after reveal) */
79
- revealedAmount?: BN;
80
- /** Revealed option choice (after reveal) */
81
- revealedOption?: number;
82
- /** Conviction score (amount * time-in-market) */
83
- revealedScore?: BN;
84
- /** Whether tally has been incremented for this share */
85
- totalIncremented: boolean;
86
- }
87
- /**
88
- * Market Option structure
4
+ * Use the following exports:
5
+ * - VoteTokenAccountData
6
+ * - ShareAccountData
7
+ * - ConvictionMarketAccount
8
+ * - ConvictionMarketOptionData
9
+ * - DecryptedVoteTokenBalance
10
+ * - DecryptedShareAccount
11
+ * - DecryptedMarketShares
89
12
  *
90
- * Represents a named voting option in a market.
13
+ * All imported from: @bench.games/conviction-markets (utils/accounts module)
91
14
  */
92
- export interface ConvictionMarketOptionData {
93
- /** PDA bump seed */
94
- bump: number;
95
- /** Market creator's public key */
96
- creator: PublicKey;
97
- /** Human-readable name of the option */
98
- name: string;
99
- /** Total shares bought for this option */
100
- totalShares?: BN;
101
- /** Total conviction score for this option */
102
- totalScore?: BN;
103
- }
15
+ export type { VoteTokenAccountData, ShareAccountData, ConvictionMarketAccount, ConvictionMarketOptionData, DecryptedVoteTokenBalance, DecryptedShareAccount, DecryptedMarketShares, } from "../utils/accounts";
104
16
  //# sourceMappingURL=accounts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/types/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,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uC;IACvC,MAAM,EAAE,SAAS,CAAC;IAClB,+CAA+C;IAC/C,wBAAwB,EAAE,UAAU,EAAE,EAAE,CAAC;IACzC,iCAAiC;IACjC,oBAAoB,EAAE,EAAE,CAAC;IACzB,2CAA2C;IAC3C,iBAAiB,EAAE,EAAE,CAAC;IACtB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,EAAE,CAAC;IACpB,4CAA4C;IAC5C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iDAAiD;IACjD,aAAa,CAAC,EAAE,EAAE,CAAC;IACnB,wDAAwD;IACxD,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED;;;;GAIG;AACH,MAAM,WAAW,0BAA0B;IACzC,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,OAAO,EAAE,SAAS,CAAC;IACnB,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,WAAW,CAAC,EAAE,EAAE,CAAC;IACjB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,EAAE,CAAC;CACjB"}
1
+ {"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/types/accounts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,YAAY,EACV,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,EACvB,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,mBAAmB,CAAC"}
@@ -1,2 +1,16 @@
1
+ /**
2
+ * Account types are now inferred from the Anchor program and exported from utils/accounts.ts
3
+ *
4
+ * Use the following exports:
5
+ * - VoteTokenAccountData
6
+ * - ShareAccountData
7
+ * - ConvictionMarketAccount
8
+ * - ConvictionMarketOptionData
9
+ * - DecryptedVoteTokenBalance
10
+ * - DecryptedShareAccount
11
+ * - DecryptedMarketShares
12
+ *
13
+ * All imported from: @bench.games/conviction-markets (utils/accounts module)
14
+ */
1
15
  export {};
2
16
  //# sourceMappingURL=accounts.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"accounts.js","sourceRoot":"","sources":["../../src/types/accounts.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"accounts.js","sourceRoot":"","sources":["../../src/types/accounts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
@@ -0,0 +1,191 @@
1
+ import { Program, type AnchorProvider } from "@coral-xyz/anchor";
2
+ import type { PublicKey } from "@solana/web3.js";
3
+ import type { ConvictionMarket } from "../idl/conviction_market";
4
+ /**
5
+ * Creates a Program instance for the Conviction Market program
6
+ *
7
+ * @param provider - Anchor provider
8
+ * @returns Program instance
9
+ */
10
+ export declare function createProgram(provider: AnchorProvider): Program<ConvictionMarket>;
11
+ /**
12
+ * Fetches and decrypts a user's vote token balance
13
+ *
14
+ * @param program - Anchor program instance
15
+ * @param voteTokenAccountPda - PDA of the vote token account
16
+ * @param userX25519Keypair - User's X25519 keypair for decryption
17
+ * @returns Decrypted balance and account data
18
+ * @throws If account doesn't exist or decryption fails
19
+ */
20
+ export declare function fetchAndDecryptVoteTokenBalance(program: Program<ConvictionMarket>, voteTokenAccountPda: PublicKey, userX25519Keypair: {
21
+ publicKey: Uint8Array;
22
+ secretKey: Uint8Array;
23
+ }): Promise<{
24
+ balance: bigint;
25
+ account: {
26
+ encryptedState: number[][];
27
+ bump: number;
28
+ owner: PublicKey;
29
+ stateNonce: import("bn.js");
30
+ };
31
+ }>;
32
+ export type DecryptedVoteTokenBalance = Awaited<ReturnType<typeof fetchAndDecryptVoteTokenBalance>>;
33
+ /**
34
+ * Fetches and decrypts a user's share account
35
+ *
36
+ * @param program - Anchor program instance
37
+ * @param shareAccountPda - PDA of the share account
38
+ * @param userX25519Keypair - User's X25519 keypair for decryption
39
+ * @returns Decrypted share data and account data
40
+ * @throws If account doesn't exist or decryption fails
41
+ */
42
+ export declare function fetchAndDecryptShareAccount(program: Program<ConvictionMarket>, shareAccountPda: PublicKey, userX25519Keypair: {
43
+ publicKey: Uint8Array;
44
+ secretKey: Uint8Array;
45
+ }): Promise<{
46
+ amount: bigint;
47
+ selectedOption: bigint;
48
+ account: {
49
+ encryptedState: number[][];
50
+ stateNonce: import("bn.js");
51
+ bump: number;
52
+ owner: PublicKey;
53
+ market: PublicKey;
54
+ encryptedStateDisclosure: number[][];
55
+ stateNonceDisclosure: import("bn.js");
56
+ boughtAtTimestamp: import("bn.js");
57
+ revealedAmount: import("bn.js") | null;
58
+ revealedOption: number | null;
59
+ revealedScore: import("bn.js") | null;
60
+ totalIncremented: boolean;
61
+ };
62
+ }>;
63
+ export type DecryptedShareAccount = Awaited<ReturnType<typeof fetchAndDecryptShareAccount>>;
64
+ /**
65
+ * Fetches and decrypts a market's available shares
66
+ *
67
+ * @param program - Anchor program instance
68
+ * @param marketPda - PDA of the conviction market
69
+ * @param userX25519Keypair - User's X25519 keypair for decryption
70
+ * @returns Decrypted available shares and account data
71
+ * @throws If account doesn't exist or decryption fails
72
+ */
73
+ export declare function fetchAndDecryptMarketShares(program: Program<ConvictionMarket>, marketPda: PublicKey, userX25519Keypair: {
74
+ publicKey: Uint8Array;
75
+ secretKey: Uint8Array;
76
+ }): Promise<{
77
+ availableShares: bigint;
78
+ account: {
79
+ encryptedAvailableShares: number[][];
80
+ bump: number;
81
+ creator: PublicKey;
82
+ index: import("bn.js");
83
+ totalOptions: number;
84
+ maxOptions: number;
85
+ openTimestamp: import("bn.js") | null;
86
+ timeToStake: import("bn.js");
87
+ timeToReveal: import("bn.js");
88
+ selectedOption: number | null;
89
+ stateNonce: import("bn.js");
90
+ maxShares: import("bn.js");
91
+ rewardLamports: import("bn.js");
92
+ selectAuthority: PublicKey | null;
93
+ };
94
+ }>;
95
+ export type DecryptedMarketShares = Awaited<ReturnType<typeof fetchAndDecryptMarketShares>>;
96
+ /**
97
+ * Fetches a vote token account without decryption
98
+ *
99
+ * @param program - Anchor program instance
100
+ * @param voteTokenAccountPda - PDA of the vote token account
101
+ * @returns Vote token account data
102
+ * @throws If account doesn't exist
103
+ */
104
+ export declare function fetchVoteTokenAccount(program: Program<ConvictionMarket>, voteTokenAccountPda: PublicKey): Promise<{
105
+ encryptedState: number[][];
106
+ bump: number;
107
+ owner: PublicKey;
108
+ stateNonce: import("bn.js");
109
+ }>;
110
+ export type VoteTokenAccountData = Awaited<ReturnType<typeof fetchVoteTokenAccount>>;
111
+ /**
112
+ * Fetches a share account without decryption
113
+ *
114
+ * @param program - Anchor program instance
115
+ * @param shareAccountPda - PDA of the share account
116
+ * @returns Share account data
117
+ * @throws If account doesn't exist
118
+ */
119
+ export declare function fetchShareAccount(program: Program<ConvictionMarket>, shareAccountPda: PublicKey): Promise<{
120
+ encryptedState: number[][];
121
+ stateNonce: import("bn.js");
122
+ bump: number;
123
+ owner: PublicKey;
124
+ market: PublicKey;
125
+ encryptedStateDisclosure: number[][];
126
+ stateNonceDisclosure: import("bn.js");
127
+ boughtAtTimestamp: import("bn.js");
128
+ revealedAmount: import("bn.js") | null;
129
+ revealedOption: number | null;
130
+ revealedScore: import("bn.js") | null;
131
+ totalIncremented: boolean;
132
+ }>;
133
+ export type ShareAccountData = Awaited<ReturnType<typeof fetchShareAccount>>;
134
+ /**
135
+ * Fetches a conviction market account
136
+ *
137
+ * @param program - Anchor program instance
138
+ * @param marketPda - PDA of the conviction market
139
+ * @returns Conviction market account data
140
+ * @throws If account doesn't exist
141
+ */
142
+ export declare function fetchConvictionMarket(program: Program<ConvictionMarket>, marketPda: PublicKey): Promise<{
143
+ encryptedAvailableShares: number[][];
144
+ bump: number;
145
+ creator: PublicKey;
146
+ index: import("bn.js");
147
+ totalOptions: number;
148
+ maxOptions: number;
149
+ openTimestamp: import("bn.js") | null;
150
+ timeToStake: import("bn.js");
151
+ timeToReveal: import("bn.js");
152
+ selectedOption: number | null;
153
+ stateNonce: import("bn.js");
154
+ maxShares: import("bn.js");
155
+ rewardLamports: import("bn.js");
156
+ selectAuthority: PublicKey | null;
157
+ }>;
158
+ export type ConvictionMarketAccount = Awaited<ReturnType<typeof fetchConvictionMarket>>;
159
+ /**
160
+ * Fetches a market option account
161
+ *
162
+ * @param program - Anchor program instance
163
+ * @param optionPda - PDA of the market option
164
+ * @returns Market option account data
165
+ * @throws If account doesn't exist
166
+ */
167
+ export declare function fetchMarketOption(program: Program<ConvictionMarket>, optionPda: PublicKey): Promise<{
168
+ bump: number;
169
+ creator: PublicKey;
170
+ name: string;
171
+ totalShares: import("bn.js") | null;
172
+ totalScore: import("bn.js") | null;
173
+ }>;
174
+ export type ConvictionMarketOptionData = Awaited<ReturnType<typeof fetchMarketOption>>;
175
+ /**
176
+ * Checks if a vote token account exists
177
+ *
178
+ * @param provider - Anchor provider
179
+ * @param voteTokenAccountPda - PDA of the vote token account
180
+ * @returns True if account exists, false otherwise
181
+ */
182
+ export declare function voteTokenAccountExists(provider: AnchorProvider, voteTokenAccountPda: PublicKey): Promise<boolean>;
183
+ /**
184
+ * Checks if a share account exists
185
+ *
186
+ * @param provider - Anchor provider
187
+ * @param shareAccountPda - PDA of the share account
188
+ * @returns True if account exists, false otherwise
189
+ */
190
+ export declare function shareAccountExists(provider: AnchorProvider, shareAccountPda: PublicKey): Promise<boolean>;
191
+ //# sourceMappingURL=accounts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/utils/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAIjE;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAKjF;AAED;;;;;;;;GAQG;AACH,wBAAsB,+BAA+B,CACnD,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,EAClC,mBA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AU,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC;AAE7E;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,EAClC,SAAS,EAAE,SAAS;;;;;;;;;;;;;;;GAGrB;AAED,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC,CAAC;AAExF;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,EAClC,SAAS,EAAE,SAAS;;;;;;GAGrB;AAED,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC;AAEvF;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,cAAc,EACxB,mBAAmB,EAAE,SAAS,GAC7B,OAAO,CAAC,OAAO,CAAC,CAGlB;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,cAAc,EACxB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,OAAO,CAAC,CAGlB"}
@@ -0,0 +1,149 @@
1
+ import { Program } from "@coral-xyz/anchor";
2
+ import { createEncryptionContext, fetchMXEPublicKey } from "./encryption";
3
+ import IDL from "../idl/conviction_market.json";
4
+ /**
5
+ * Creates a Program instance for the Conviction Market program
6
+ *
7
+ * @param provider - Anchor provider
8
+ * @returns Program instance
9
+ */
10
+ export function createProgram(provider) {
11
+ return new Program(IDL, provider);
12
+ }
13
+ /**
14
+ * Fetches and decrypts a user's vote token balance
15
+ *
16
+ * @param program - Anchor program instance
17
+ * @param voteTokenAccountPda - PDA of the vote token account
18
+ * @param userX25519Keypair - User's X25519 keypair for decryption
19
+ * @returns Decrypted balance and account data
20
+ * @throws If account doesn't exist or decryption fails
21
+ */
22
+ export async function fetchAndDecryptVoteTokenBalance(program, voteTokenAccountPda, userX25519Keypair) {
23
+ const account = await program.account.voteTokenAccount.fetch(voteTokenAccountPda);
24
+ // Fetch MXE public key and create encryption context
25
+ const mxePublicKey = await fetchMXEPublicKey(program.provider, program.programId);
26
+ const encryptionContext = createEncryptionContext(userX25519Keypair, mxePublicKey);
27
+ const decrypted = encryptionContext.cipher.decrypt(account.encryptedState, Uint8Array.from(account.stateNonce.toArray("le", 16)));
28
+ if (!decrypted[0]) {
29
+ throw new Error("Failed to decrypt balance");
30
+ }
31
+ return {
32
+ balance: decrypted[0],
33
+ account,
34
+ };
35
+ }
36
+ /**
37
+ * Fetches and decrypts a user's share account
38
+ *
39
+ * @param program - Anchor program instance
40
+ * @param shareAccountPda - PDA of the share account
41
+ * @param userX25519Keypair - User's X25519 keypair for decryption
42
+ * @returns Decrypted share data and account data
43
+ * @throws If account doesn't exist or decryption fails
44
+ */
45
+ export async function fetchAndDecryptShareAccount(program, shareAccountPda, userX25519Keypair) {
46
+ const account = await program.account.shareAccount.fetch(shareAccountPda);
47
+ // Fetch MXE public key and create encryption context
48
+ const mxePublicKey = await fetchMXEPublicKey(program.provider, program.programId);
49
+ const encryptionContext = createEncryptionContext(userX25519Keypair, mxePublicKey);
50
+ const decrypted = encryptionContext.cipher.decrypt(account.encryptedState, Uint8Array.from(account.stateNonce.toArray("le", 16)));
51
+ if (!decrypted[0] || !decrypted[1]) {
52
+ throw new Error("Failed to decrypt share account");
53
+ }
54
+ return {
55
+ amount: decrypted[0],
56
+ selectedOption: decrypted[1],
57
+ account,
58
+ };
59
+ }
60
+ /**
61
+ * Fetches and decrypts a market's available shares
62
+ *
63
+ * @param program - Anchor program instance
64
+ * @param marketPda - PDA of the conviction market
65
+ * @param userX25519Keypair - User's X25519 keypair for decryption
66
+ * @returns Decrypted available shares and account data
67
+ * @throws If account doesn't exist or decryption fails
68
+ */
69
+ export async function fetchAndDecryptMarketShares(program, marketPda, userX25519Keypair) {
70
+ const account = await program.account.convictionMarket.fetch(marketPda);
71
+ // Fetch MXE public key and create encryption context
72
+ const mxePublicKey = await fetchMXEPublicKey(program.provider, program.programId);
73
+ const encryptionContext = createEncryptionContext(userX25519Keypair, mxePublicKey);
74
+ const decrypted = encryptionContext.cipher.decrypt(account.encryptedAvailableShares, Uint8Array.from(account.stateNonce.toArray("le", 16)));
75
+ if (!decrypted[0]) {
76
+ throw new Error("Failed to decrypt market shares");
77
+ }
78
+ return {
79
+ availableShares: decrypted[0],
80
+ account,
81
+ };
82
+ }
83
+ /**
84
+ * Fetches a vote token account without decryption
85
+ *
86
+ * @param program - Anchor program instance
87
+ * @param voteTokenAccountPda - PDA of the vote token account
88
+ * @returns Vote token account data
89
+ * @throws If account doesn't exist
90
+ */
91
+ export async function fetchVoteTokenAccount(program, voteTokenAccountPda) {
92
+ return await program.account.voteTokenAccount.fetch(voteTokenAccountPda);
93
+ }
94
+ /**
95
+ * Fetches a share account without decryption
96
+ *
97
+ * @param program - Anchor program instance
98
+ * @param shareAccountPda - PDA of the share account
99
+ * @returns Share account data
100
+ * @throws If account doesn't exist
101
+ */
102
+ export async function fetchShareAccount(program, shareAccountPda) {
103
+ return await program.account.shareAccount.fetch(shareAccountPda);
104
+ }
105
+ /**
106
+ * Fetches a conviction market account
107
+ *
108
+ * @param program - Anchor program instance
109
+ * @param marketPda - PDA of the conviction market
110
+ * @returns Conviction market account data
111
+ * @throws If account doesn't exist
112
+ */
113
+ export async function fetchConvictionMarket(program, marketPda) {
114
+ return await program.account.convictionMarket.fetch(marketPda);
115
+ }
116
+ /**
117
+ * Fetches a market option account
118
+ *
119
+ * @param program - Anchor program instance
120
+ * @param optionPda - PDA of the market option
121
+ * @returns Market option account data
122
+ * @throws If account doesn't exist
123
+ */
124
+ export async function fetchMarketOption(program, optionPda) {
125
+ return await program.account.convictionMarketOption.fetch(optionPda);
126
+ }
127
+ /**
128
+ * Checks if a vote token account exists
129
+ *
130
+ * @param provider - Anchor provider
131
+ * @param voteTokenAccountPda - PDA of the vote token account
132
+ * @returns True if account exists, false otherwise
133
+ */
134
+ export async function voteTokenAccountExists(provider, voteTokenAccountPda) {
135
+ const accountInfo = await provider.connection.getAccountInfo(voteTokenAccountPda);
136
+ return accountInfo !== null;
137
+ }
138
+ /**
139
+ * Checks if a share account exists
140
+ *
141
+ * @param provider - Anchor provider
142
+ * @param shareAccountPda - PDA of the share account
143
+ * @returns True if account exists, false otherwise
144
+ */
145
+ export async function shareAccountExists(provider, shareAccountPda) {
146
+ const accountInfo = await provider.connection.getAccountInfo(shareAccountPda);
147
+ return accountInfo !== null;
148
+ }
149
+ //# sourceMappingURL=accounts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.js","sourceRoot":"","sources":["../../src/utils/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAuB,MAAM,mBAAmB,CAAC;AAGjE,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,GAAG,MAAM,+BAA+B,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,QAAwB;IACpD,OAAO,IAAI,OAAO,CAChB,GAAuB,EACvB,QAAQ,CACoB,CAAC;AACjC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,+BAA+B,CACnD,OAAkC,EAClC,mBAA8B,EAC9B,iBAAmE;IAEnE,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAElF,qDAAqD;IACrD,MAAM,YAAY,GAAG,MAAM,iBAAiB,CAC1C,OAAO,CAAC,QAA0B,EAClC,OAAO,CAAC,SAAS,CAClB,CAAC;IACF,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;IAEnF,MAAM,SAAS,GAAG,iBAAiB,CAAC,MAAM,CAAC,OAAO,CAChD,OAAO,CAAC,cAAc,EACtB,UAAU,CAAC,IAAI,CAAC,OAA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AAC;AAID;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAkC,EAClC,SAAoB;IAEpB,OAAO,MAAM,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACvE,CAAC;AAID;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,QAAwB,EACxB,mBAA8B;IAE9B,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC;IAClF,OAAO,WAAW,KAAK,IAAI,CAAC;AAC9B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAAwB,EACxB,eAA0B;IAE1B,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IAC9E,OAAO,WAAW,KAAK,IAAI,CAAC;AAC9B,CAAC"}
@@ -4,4 +4,5 @@ export * from "./computations";
4
4
  export * from "./encryption";
5
5
  export * from "./awaitComputationFinalization";
6
6
  export * from "./arcium";
7
+ export * from "./accounts";
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
@@ -4,4 +4,5 @@ export * from "./computations";
4
4
  export * from "./encryption";
5
5
  export * from "./awaitComputationFinalization";
6
6
  export * from "./arcium";
7
+ export * from "./accounts";
7
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bench.games/conviction-markets",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "author": "Bench",
5
5
  "main": "./dist/index.js",
6
6
  "devDependencies": {