@arcium-hq/reader 0.8.5 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -147,14 +147,12 @@ for (const address of arxNodeAddresses) {
147
147
  Track available computation definitions and their configurations.
148
148
 
149
149
  ```typescript
150
- import { getCompDefAccInfo } from "@arcium-hq/reader";
151
- import { getCompDefAccAddress } from "@arcium-hq/reader";
150
+ import { getCompDefAccInfo, getCompDefAccAddress } from "@arcium-hq/reader";
152
151
 
153
152
  // Get computation definition for a specific circuit
154
- const circuitName = "your_circuit_name";
155
153
  const mxeProgramId = new anchor.web3.PublicKey("YOUR_MXE_PROGRAM_ID");
156
-
157
- const compDefAddress = getCompDefAccAddress(mxeProgramId, /* offset */);
154
+ const compDefOffset = 0; // Your computation definition offset
155
+ const compDefAddress = getCompDefAccAddress(mxeProgramId, compDefOffset);
158
156
  const compDefInfo = await getCompDefAccInfo(arciumProgram, compDefAddress);
159
157
 
160
158
  console.log("Computation Definition:", {
@@ -170,12 +168,12 @@ console.log("Computation Definition:", {
170
168
  Monitor individual computation instances and their status.
171
169
 
172
170
  ```typescript
173
- import { getComputationAccInfo } from "@arcium-hq/reader";
174
- import { getComputationAccAddress } from "@arcium-hq/reader";
171
+ import { getComputationAccInfo, getComputationAccAddress } from "@arcium-hq/reader";
175
172
 
176
173
  // Get computation account info
174
+ const clusterOffset = 0; // Your cluster offset
177
175
  const computationOffset = new anchor.BN("123456789");
178
- const computationAddress = getComputationAccAddress(mxeProgramId, computationOffset);
176
+ const computationAddress = getComputationAccAddress(clusterOffset, computationOffset);
179
177
  const computationInfo = await getComputationAccInfo(arciumProgram, computationAddress);
180
178
 
181
179
  console.log("Computation:", {
@@ -191,13 +189,14 @@ console.log("Computation:", {
191
189
  Analyze pending computations in the network's memory pools.
192
190
 
193
191
  ```typescript
194
- import {
192
+ import {
195
193
  getComputationsInMempool,
196
194
  getMempoolAccAddress
197
195
  } from "@arcium-hq/reader";
198
196
 
199
- // Get mempool for an MXE
200
- const mempoolAddress = getMempoolAccAddress(mxeProgramId);
197
+ // Get mempool for a cluster (use your cluster offset)
198
+ const clusterOffset = 0; // Your cluster offset
199
+ const mempoolAddress = getMempoolAccAddress(clusterOffset);
201
200
  const pendingComputations = await getComputationsInMempool(arciumProgram, mempoolAddress);
202
201
 
203
202
  console.log(`Found ${pendingComputations.length} pending computations:`);
package/build/index.cjs CHANGED
@@ -73,95 +73,104 @@ new anchor__namespace.EventParser(ARCIUM_PROGRAM_ID, new anchor__namespace.Borsh
73
73
  const ARCIUM_BORSH_CODER = new anchor__namespace.BorshCoder(client.ARCIUM_IDL);
74
74
 
75
75
  /**
76
- * Returns all MXE account addresses.
77
- * @param conn - The Solana connection object.
76
+ * Return all MXE account addresses.
77
+ * @param conn - Solana connection object.
78
78
  * @returns Array of MXE account public keys.
79
79
  */
80
80
  async function getMXEAccAddresses(conn) {
81
81
  return getArciumAccPubkeys(conn, MXE_ACC_DISCRIMINATOR);
82
82
  }
83
83
  /**
84
- * Returns all Cluster account addresses.
85
- * @param conn - The Solana connection object.
84
+ * Return all Cluster account addresses.
85
+ * @param conn - Solana connection object.
86
86
  * @returns Array of Cluster account public keys.
87
87
  */
88
88
  async function getClusterAccAddresses(conn) {
89
89
  return getArciumAccPubkeys(conn, CLUSTER_ACC_DISCRIMINATOR);
90
90
  }
91
91
  /**
92
- * Returns all ArxNode account addresses.
93
- * @param conn - The Solana connection object.
92
+ * Return all ArxNode account addresses.
93
+ * @param conn - Solana connection object.
94
94
  * @returns Array of ArxNode account public keys.
95
95
  */
96
96
  async function getArxNodeAccAddresses(conn) {
97
97
  return getArciumAccPubkeys(conn, ARX_NODE_ACC_DISCRIMINATOR);
98
98
  }
99
99
  /**
100
- * Fetches and parses a given MXE account.
101
- * @param arciumProgram - The Anchor program instance.
102
- * @param address - The public key of the MXE account.
103
- * @param commitment - (Optional) RPC commitment level.
104
- * @returns The MXEAccount object.
100
+ * Fetch and parse an MXE account.
101
+ *
102
+ * @param arciumProgram - Anchor program instance.
103
+ * @param address - Public key of the MXE account.
104
+ * @param commitment - RPC commitment level.
105
+ * @returns Parsed MXE account data.
106
+ *
107
+ * @example
108
+ * import { getArciumProgram, getMXEAccAddress, getMXEAccInfo } from '@arcium-hq/reader';
109
+ *
110
+ * const program = getArciumProgram(provider);
111
+ * const mxeAddress = getMXEAccAddress(mxeProgramId);
112
+ * const mxeAccount = await getMXEAccInfo(program, mxeAddress);
113
+ * console.log('MXE authority:', mxeAccount.authority?.toBase58());
105
114
  */
106
115
  async function getMXEAccInfo(arciumProgram, address, commitment) {
107
116
  return arciumProgram.account.mxeAccount.fetch(address, commitment);
108
117
  }
109
118
  /**
110
- * Fetches and parses a given Cluster account.
111
- * @param arciumProgram - The Anchor program instance.
112
- * @param address - The public key of the Cluster account.
113
- * @param commitment - (Optional) RPC commitment level.
114
- * @returns The ClusterAccount object.
119
+ * Fetch and parse a Cluster account.
120
+ * @param arciumProgram - Anchor program instance.
121
+ * @param address - Public key of the Cluster account.
122
+ * @param commitment - RPC commitment level.
123
+ * @returns Parsed ClusterAccount data.
115
124
  */
116
125
  async function getClusterAccInfo(arciumProgram, address, commitment) {
117
126
  return arciumProgram.account.cluster.fetch(address, commitment);
118
127
  }
119
128
  /**
120
- * Fetches and parses a given recovery cluster account.
121
- * @param arciumProgram - The Anchor program instance.
122
- * @param address - The public key of the recovery cluster account.
123
- * @param commitment - (Optional) RPC commitment level.
124
- * @returns The RecoveryClusterAccount object.
129
+ * Fetch and parse a recovery cluster account.
130
+ * @param arciumProgram - Anchor program instance.
131
+ * @param address - Public key of the recovery cluster account.
132
+ * @param commitment - RPC commitment level.
133
+ * @returns Parsed RecoveryClusterAccount data.
125
134
  */
126
135
  async function getRecoveryClusterAccInfo(arciumProgram, address, commitment) {
127
136
  return arciumProgram.account.recoveryClusterAccount.fetch(address, commitment);
128
137
  }
129
138
  /**
130
- * Fetches and parses a given MxeRecovery account.
131
- * @param arciumProgram - The Anchor program instance.
132
- * @param address - The public key of the MxeRecovery account.
133
- * @param commitment - (Optional) RPC commitment level.
134
- * @returns The MxeRecoveryAccount object.
139
+ * Fetch and parse an MxeRecovery account.
140
+ * @param arciumProgram - Anchor program instance.
141
+ * @param address - Public key of the MxeRecovery account.
142
+ * @param commitment - RPC commitment level.
143
+ * @returns Parsed MxeRecoveryAccount data.
135
144
  */
136
145
  async function getMxeRecoveryAccInfo(arciumProgram, address, commitment) {
137
146
  return arciumProgram.account.mxeRecoveryAccount.fetch(address, commitment);
138
147
  }
139
148
  /**
140
- * Fetches and parses a given ArxNode account.
141
- * @param arciumProgram - The Anchor program instance.
142
- * @param address - The public key of the ArxNode account.
143
- * @param commitment - (Optional) RPC commitment level.
144
- * @returns The ArxNodeAccount object.
149
+ * Fetch and parse an ArxNode account.
150
+ * @param arciumProgram - Anchor program instance.
151
+ * @param address - Public key of the ArxNode account.
152
+ * @param commitment - RPC commitment level.
153
+ * @returns Parsed ArxNodeAccount data.
145
154
  */
146
155
  async function getArxNodeAccInfo(arciumProgram, address, commitment) {
147
156
  return arciumProgram.account.arxNode.fetch(address, commitment);
148
157
  }
149
158
  /**
150
- * Fetches and parses a given ComputationDefinition account.
151
- * @param arciumProgram - The Anchor program instance.
152
- * @param address - The public key of the ComputationDefinition account.
153
- * @param commitment - (Optional) RPC commitment level.
154
- * @returns The ComputationDefinitionAccount object.
159
+ * Fetch and parse a ComputationDefinition account.
160
+ * @param arciumProgram - Anchor program instance.
161
+ * @param address - Public key of the ComputationDefinition account.
162
+ * @param commitment - RPC commitment level.
163
+ * @returns Parsed ComputationDefinitionAccount data.
155
164
  */
156
165
  async function getCompDefAccInfo(arciumProgram, address, commitment) {
157
166
  return arciumProgram.account.computationDefinitionAccount.fetch(address, commitment);
158
167
  }
159
168
  /**
160
- * Fetches and parses a given Computation account.
161
- * @param arciumProgram - The Anchor program instance.
162
- * @param address - The public key of the Computation account.
163
- * @param commitment - (Optional) RPC commitment level.
164
- * @returns The Computation object.
169
+ * Fetch and parse a Computation account.
170
+ * @param arciumProgram - Anchor program instance.
171
+ * @param address - Public key of the Computation account.
172
+ * @param commitment - RPC commitment level.
173
+ * @returns Parsed ComputationAccount data.
165
174
  */
166
175
  async function getComputationAccInfo(arciumProgram, address, commitment) {
167
176
  return arciumProgram.account.computationAccount.fetch(address, commitment);
@@ -183,11 +192,28 @@ async function getArciumAccPubkeys(conn, discriminator) {
183
192
  }
184
193
 
185
194
  /**
186
- * Subscribes to computation-related events for a given MXE program ID.
187
- * @param conn - The Solana connection object.
188
- * @param mxeProgramId - The public key of the MXE program.
189
- * @param callback - Callback function to handle each computation event and its name.
190
- * @returns The subscription ID for the logs listener.
195
+ * Subscribe to computation events for an MXE program.
196
+ *
197
+ * Listens for queue, execute, and finalize events via Solana log subscriptions.
198
+ *
199
+ * @param conn - Solana connection object.
200
+ * @param mxeProgramId - Public key of the MXE program to monitor.
201
+ * @param callback - Handler called for each event with event data and event name.
202
+ * @returns Subscription ID for cleanup with {@link unsubscribeComputations}.
203
+ *
204
+ * @example
205
+ * const subId = await subscribeComputations(
206
+ * connection,
207
+ * mxeProgramId,
208
+ * (event, name) => {
209
+ * if (name === 'FinalizeComputationEvent') {
210
+ * console.log('Computation finalized:', event.computationOffset.toString());
211
+ * }
212
+ * },
213
+ * );
214
+ *
215
+ * // When done, clean up the subscription
216
+ * await unsubscribeComputations(connection, subId);
191
217
  */
192
218
  async function subscribeComputations(conn, mxeProgramId, callback) {
193
219
  return conn.onLogs(mxeProgramId, (logs) => {
@@ -198,17 +224,17 @@ async function subscribeComputations(conn, mxeProgramId, callback) {
198
224
  });
199
225
  }
200
226
  /**
201
- * Unsubscribes from computation-related events using the subscription ID.
202
- * @param conn - The Solana connection object.
203
- * @param subscriptionId - The subscription ID returned by subscribeComputations.
227
+ * Unsubscribe from computation events.
228
+ * @param conn - Solana connection object.
229
+ * @param subscriptionId - Subscription ID returned by {@link subscribeComputations}.
204
230
  */
205
231
  async function unsubscribeComputations(conn, subscriptionId) {
206
232
  conn.removeOnLogsListener(subscriptionId);
207
233
  }
208
234
  /**
209
- * Gets the computation offset from a transaction.
210
- * @param tx - The transaction to get the computation offset from.
211
- * @returns The computation offset if one is found, otherwise undefined.
235
+ * Get the computation offset from a transaction.
236
+ * @param tx - Transaction to extract the computation offset from.
237
+ * @returns Computation offset if found, otherwise undefined.
212
238
  * @throws Error if multiple computation offsets are found in the transaction.
213
239
  */
214
240
  function getComputationOffset(tx) {
@@ -224,7 +250,7 @@ function getComputationOffset(tx) {
224
250
  return computationOffset;
225
251
  }
226
252
  /**
227
- * Get the events related to arcium computations from a transaction's logs
253
+ * Get the events related to Arcium computations from a transaction's logs.
228
254
  *
229
255
  * Note: This implements a direct decode approach instead of using Anchor's EventParser.parseLogs().
230
256
  *
@@ -235,7 +261,7 @@ function getComputationOffset(tx) {
235
261
  * 3. Only parses events when execution.program() === EventParser.programId
236
262
  *
237
263
  * This breaks our use case:
238
- * - We subscribe to MXE program logs (line 29) via conn.onLogs(mxeProgramId, ...)
264
+ * - We subscribe to MXE program logs via conn.onLogs(mxeProgramId, ...) in {@link subscribeComputations}
239
265
  * - But we need to parse Arcium events emitted during MXE→Arcium CPI calls
240
266
  * - When MXE is the root program, execution.program() = MXE_PROGRAM_ID
241
267
  * - EventParser expects execution.program() = ARCIUM_PROGRAM_ID
@@ -247,8 +273,8 @@ function getComputationOffset(tx) {
247
273
  * - Works regardless of which program is root or subscription target
248
274
  * - Handles both MXE→Arcium and Arcium→MXE CPI patterns
249
275
  *
250
- * @param logs - The logs to get the events from
251
- * @returns The events in the logs.
276
+ * @param logs - Logs to get the events from.
277
+ * @returns Array of parsed Arcium computation events.
252
278
  */
253
279
  function getComputationEventsFromLogs(logs) {
254
280
  const events = [];
package/build/index.d.ts CHANGED
@@ -70,11 +70,11 @@ type ComputationDefinitionAccount = ArciumTypes['computationDefinitionAccount'];
70
70
  /**
71
71
  * Queue computation instruction type from the Arcium IDL.
72
72
  */
73
- type QueueComputationIx = ArciumIdlType['instructions']['35'];
73
+ type QueueComputationIx = ArciumIdlType['instructions']['38'];
74
74
  /**
75
75
  * Callback computation instruction type from the Arcium IDL.
76
76
  */
77
- type CallbackComputationIx = ArciumIdlType['instructions']['3'];
77
+ type CallbackComputationIx = ArciumIdlType['instructions']['4'];
78
78
  /**
79
79
  * Valid instruction names from the Arcium IDL.
80
80
  */
@@ -85,98 +85,124 @@ type ArciumInstructionName = ArciumIdlType['instructions'][number]['name'];
85
85
  type ComputationStatus = 'queued' | 'executing' | 'executed' | 'finalized' | 'failed';
86
86
 
87
87
  /**
88
- * Returns all MXE account addresses.
89
- * @param conn - The Solana connection object.
88
+ * Return all MXE account addresses.
89
+ * @param conn - Solana connection object.
90
90
  * @returns Array of MXE account public keys.
91
91
  */
92
92
  declare function getMXEAccAddresses(conn: Connection): Promise<PublicKey[]>;
93
93
  /**
94
- * Returns all Cluster account addresses.
95
- * @param conn - The Solana connection object.
94
+ * Return all Cluster account addresses.
95
+ * @param conn - Solana connection object.
96
96
  * @returns Array of Cluster account public keys.
97
97
  */
98
98
  declare function getClusterAccAddresses(conn: Connection): Promise<PublicKey[]>;
99
99
  /**
100
- * Returns all ArxNode account addresses.
101
- * @param conn - The Solana connection object.
100
+ * Return all ArxNode account addresses.
101
+ * @param conn - Solana connection object.
102
102
  * @returns Array of ArxNode account public keys.
103
103
  */
104
104
  declare function getArxNodeAccAddresses(conn: Connection): Promise<PublicKey[]>;
105
105
  /**
106
- * Fetches and parses a given MXE account.
107
- * @param arciumProgram - The Anchor program instance.
108
- * @param address - The public key of the MXE account.
109
- * @param commitment - (Optional) RPC commitment level.
110
- * @returns The MXEAccount object.
106
+ * Fetch and parse an MXE account.
107
+ *
108
+ * @param arciumProgram - Anchor program instance.
109
+ * @param address - Public key of the MXE account.
110
+ * @param commitment - RPC commitment level.
111
+ * @returns Parsed MXE account data.
112
+ *
113
+ * @example
114
+ * import { getArciumProgram, getMXEAccAddress, getMXEAccInfo } from '@arcium-hq/reader';
115
+ *
116
+ * const program = getArciumProgram(provider);
117
+ * const mxeAddress = getMXEAccAddress(mxeProgramId);
118
+ * const mxeAccount = await getMXEAccInfo(program, mxeAddress);
119
+ * console.log('MXE authority:', mxeAccount.authority?.toBase58());
111
120
  */
112
121
  declare function getMXEAccInfo(arciumProgram: anchor.Program<ArciumIdlType>, address: PublicKey, commitment?: anchor.web3.Commitment): Promise<MXEAccount>;
113
122
  /**
114
- * Fetches and parses a given Cluster account.
115
- * @param arciumProgram - The Anchor program instance.
116
- * @param address - The public key of the Cluster account.
117
- * @param commitment - (Optional) RPC commitment level.
118
- * @returns The ClusterAccount object.
123
+ * Fetch and parse a Cluster account.
124
+ * @param arciumProgram - Anchor program instance.
125
+ * @param address - Public key of the Cluster account.
126
+ * @param commitment - RPC commitment level.
127
+ * @returns Parsed ClusterAccount data.
119
128
  */
120
129
  declare function getClusterAccInfo(arciumProgram: anchor.Program<ArciumIdlType>, address: PublicKey, commitment?: anchor.web3.Commitment): Promise<ClusterAccount>;
121
130
  /**
122
- * Fetches and parses a given recovery cluster account.
123
- * @param arciumProgram - The Anchor program instance.
124
- * @param address - The public key of the recovery cluster account.
125
- * @param commitment - (Optional) RPC commitment level.
126
- * @returns The RecoveryClusterAccount object.
131
+ * Fetch and parse a recovery cluster account.
132
+ * @param arciumProgram - Anchor program instance.
133
+ * @param address - Public key of the recovery cluster account.
134
+ * @param commitment - RPC commitment level.
135
+ * @returns Parsed RecoveryClusterAccount data.
127
136
  */
128
137
  declare function getRecoveryClusterAccInfo(arciumProgram: anchor.Program<ArciumIdlType>, address: PublicKey, commitment?: anchor.web3.Commitment): Promise<RecoveryClusterAccount>;
129
138
  /**
130
- * Fetches and parses a given MxeRecovery account.
131
- * @param arciumProgram - The Anchor program instance.
132
- * @param address - The public key of the MxeRecovery account.
133
- * @param commitment - (Optional) RPC commitment level.
134
- * @returns The MxeRecoveryAccount object.
139
+ * Fetch and parse an MxeRecovery account.
140
+ * @param arciumProgram - Anchor program instance.
141
+ * @param address - Public key of the MxeRecovery account.
142
+ * @param commitment - RPC commitment level.
143
+ * @returns Parsed MxeRecoveryAccount data.
135
144
  */
136
145
  declare function getMxeRecoveryAccInfo(arciumProgram: anchor.Program<ArciumIdlType>, address: PublicKey, commitment?: anchor.web3.Commitment): Promise<MxeRecoveryAccount>;
137
146
  /**
138
- * Fetches and parses a given ArxNode account.
139
- * @param arciumProgram - The Anchor program instance.
140
- * @param address - The public key of the ArxNode account.
141
- * @param commitment - (Optional) RPC commitment level.
142
- * @returns The ArxNodeAccount object.
147
+ * Fetch and parse an ArxNode account.
148
+ * @param arciumProgram - Anchor program instance.
149
+ * @param address - Public key of the ArxNode account.
150
+ * @param commitment - RPC commitment level.
151
+ * @returns Parsed ArxNodeAccount data.
143
152
  */
144
153
  declare function getArxNodeAccInfo(arciumProgram: anchor.Program<ArciumIdlType>, address: PublicKey, commitment?: anchor.web3.Commitment): Promise<ArxNodeAccount>;
145
154
  /**
146
- * Fetches and parses a given ComputationDefinition account.
147
- * @param arciumProgram - The Anchor program instance.
148
- * @param address - The public key of the ComputationDefinition account.
149
- * @param commitment - (Optional) RPC commitment level.
150
- * @returns The ComputationDefinitionAccount object.
155
+ * Fetch and parse a ComputationDefinition account.
156
+ * @param arciumProgram - Anchor program instance.
157
+ * @param address - Public key of the ComputationDefinition account.
158
+ * @param commitment - RPC commitment level.
159
+ * @returns Parsed ComputationDefinitionAccount data.
151
160
  */
152
161
  declare function getCompDefAccInfo(arciumProgram: anchor.Program<ArciumIdlType>, address: PublicKey, commitment?: anchor.web3.Commitment): Promise<ComputationDefinitionAccount>;
153
162
  /**
154
- * Fetches and parses a given Computation account.
155
- * @param arciumProgram - The Anchor program instance.
156
- * @param address - The public key of the Computation account.
157
- * @param commitment - (Optional) RPC commitment level.
158
- * @returns The Computation object.
163
+ * Fetch and parse a Computation account.
164
+ * @param arciumProgram - Anchor program instance.
165
+ * @param address - Public key of the Computation account.
166
+ * @param commitment - RPC commitment level.
167
+ * @returns Parsed ComputationAccount data.
159
168
  */
160
169
  declare function getComputationAccInfo(arciumProgram: anchor.Program<ArciumIdlType>, address: PublicKey, commitment?: anchor.web3.Commitment): Promise<ComputationAccount>;
161
170
 
162
171
  /**
163
- * Subscribes to computation-related events for a given MXE program ID.
164
- * @param conn - The Solana connection object.
165
- * @param mxeProgramId - The public key of the MXE program.
166
- * @param callback - Callback function to handle each computation event and its name.
167
- * @returns The subscription ID for the logs listener.
172
+ * Subscribe to computation events for an MXE program.
173
+ *
174
+ * Listens for queue, execute, and finalize events via Solana log subscriptions.
175
+ *
176
+ * @param conn - Solana connection object.
177
+ * @param mxeProgramId - Public key of the MXE program to monitor.
178
+ * @param callback - Handler called for each event with event data and event name.
179
+ * @returns Subscription ID for cleanup with {@link unsubscribeComputations}.
180
+ *
181
+ * @example
182
+ * const subId = await subscribeComputations(
183
+ * connection,
184
+ * mxeProgramId,
185
+ * (event, name) => {
186
+ * if (name === 'FinalizeComputationEvent') {
187
+ * console.log('Computation finalized:', event.computationOffset.toString());
188
+ * }
189
+ * },
190
+ * );
191
+ *
192
+ * // When done, clean up the subscription
193
+ * await unsubscribeComputations(connection, subId);
168
194
  */
169
195
  declare function subscribeComputations(conn: Connection, mxeProgramId: PublicKey, callback: (event: ArciumEventData, name: ArciumEventName) => void): Promise<number>;
170
196
  /**
171
- * Unsubscribes from computation-related events using the subscription ID.
172
- * @param conn - The Solana connection object.
173
- * @param subscriptionId - The subscription ID returned by subscribeComputations.
197
+ * Unsubscribe from computation events.
198
+ * @param conn - Solana connection object.
199
+ * @param subscriptionId - Subscription ID returned by {@link subscribeComputations}.
174
200
  */
175
201
  declare function unsubscribeComputations(conn: Connection, subscriptionId: number): Promise<void>;
176
202
  /**
177
- * Gets the computation offset from a transaction.
178
- * @param tx - The transaction to get the computation offset from.
179
- * @returns The computation offset if one is found, otherwise undefined.
203
+ * Get the computation offset from a transaction.
204
+ * @param tx - Transaction to extract the computation offset from.
205
+ * @returns Computation offset if found, otherwise undefined.
180
206
  * @throws Error if multiple computation offsets are found in the transaction.
181
207
  */
182
208
  declare function getComputationOffset(tx: anchor.web3.VersionedTransactionResponse): anchor.BN | undefined;
package/build/index.mjs CHANGED
@@ -53,95 +53,104 @@ new anchor.EventParser(ARCIUM_PROGRAM_ID, new anchor.BorshCoder(ARCIUM_IDL));
53
53
  const ARCIUM_BORSH_CODER = new anchor.BorshCoder(ARCIUM_IDL);
54
54
 
55
55
  /**
56
- * Returns all MXE account addresses.
57
- * @param conn - The Solana connection object.
56
+ * Return all MXE account addresses.
57
+ * @param conn - Solana connection object.
58
58
  * @returns Array of MXE account public keys.
59
59
  */
60
60
  async function getMXEAccAddresses(conn) {
61
61
  return getArciumAccPubkeys(conn, MXE_ACC_DISCRIMINATOR);
62
62
  }
63
63
  /**
64
- * Returns all Cluster account addresses.
65
- * @param conn - The Solana connection object.
64
+ * Return all Cluster account addresses.
65
+ * @param conn - Solana connection object.
66
66
  * @returns Array of Cluster account public keys.
67
67
  */
68
68
  async function getClusterAccAddresses(conn) {
69
69
  return getArciumAccPubkeys(conn, CLUSTER_ACC_DISCRIMINATOR);
70
70
  }
71
71
  /**
72
- * Returns all ArxNode account addresses.
73
- * @param conn - The Solana connection object.
72
+ * Return all ArxNode account addresses.
73
+ * @param conn - Solana connection object.
74
74
  * @returns Array of ArxNode account public keys.
75
75
  */
76
76
  async function getArxNodeAccAddresses(conn) {
77
77
  return getArciumAccPubkeys(conn, ARX_NODE_ACC_DISCRIMINATOR);
78
78
  }
79
79
  /**
80
- * Fetches and parses a given MXE account.
81
- * @param arciumProgram - The Anchor program instance.
82
- * @param address - The public key of the MXE account.
83
- * @param commitment - (Optional) RPC commitment level.
84
- * @returns The MXEAccount object.
80
+ * Fetch and parse an MXE account.
81
+ *
82
+ * @param arciumProgram - Anchor program instance.
83
+ * @param address - Public key of the MXE account.
84
+ * @param commitment - RPC commitment level.
85
+ * @returns Parsed MXE account data.
86
+ *
87
+ * @example
88
+ * import { getArciumProgram, getMXEAccAddress, getMXEAccInfo } from '@arcium-hq/reader';
89
+ *
90
+ * const program = getArciumProgram(provider);
91
+ * const mxeAddress = getMXEAccAddress(mxeProgramId);
92
+ * const mxeAccount = await getMXEAccInfo(program, mxeAddress);
93
+ * console.log('MXE authority:', mxeAccount.authority?.toBase58());
85
94
  */
86
95
  async function getMXEAccInfo(arciumProgram, address, commitment) {
87
96
  return arciumProgram.account.mxeAccount.fetch(address, commitment);
88
97
  }
89
98
  /**
90
- * Fetches and parses a given Cluster account.
91
- * @param arciumProgram - The Anchor program instance.
92
- * @param address - The public key of the Cluster account.
93
- * @param commitment - (Optional) RPC commitment level.
94
- * @returns The ClusterAccount object.
99
+ * Fetch and parse a Cluster account.
100
+ * @param arciumProgram - Anchor program instance.
101
+ * @param address - Public key of the Cluster account.
102
+ * @param commitment - RPC commitment level.
103
+ * @returns Parsed ClusterAccount data.
95
104
  */
96
105
  async function getClusterAccInfo(arciumProgram, address, commitment) {
97
106
  return arciumProgram.account.cluster.fetch(address, commitment);
98
107
  }
99
108
  /**
100
- * Fetches and parses a given recovery cluster account.
101
- * @param arciumProgram - The Anchor program instance.
102
- * @param address - The public key of the recovery cluster account.
103
- * @param commitment - (Optional) RPC commitment level.
104
- * @returns The RecoveryClusterAccount object.
109
+ * Fetch and parse a recovery cluster account.
110
+ * @param arciumProgram - Anchor program instance.
111
+ * @param address - Public key of the recovery cluster account.
112
+ * @param commitment - RPC commitment level.
113
+ * @returns Parsed RecoveryClusterAccount data.
105
114
  */
106
115
  async function getRecoveryClusterAccInfo(arciumProgram, address, commitment) {
107
116
  return arciumProgram.account.recoveryClusterAccount.fetch(address, commitment);
108
117
  }
109
118
  /**
110
- * Fetches and parses a given MxeRecovery account.
111
- * @param arciumProgram - The Anchor program instance.
112
- * @param address - The public key of the MxeRecovery account.
113
- * @param commitment - (Optional) RPC commitment level.
114
- * @returns The MxeRecoveryAccount object.
119
+ * Fetch and parse an MxeRecovery account.
120
+ * @param arciumProgram - Anchor program instance.
121
+ * @param address - Public key of the MxeRecovery account.
122
+ * @param commitment - RPC commitment level.
123
+ * @returns Parsed MxeRecoveryAccount data.
115
124
  */
116
125
  async function getMxeRecoveryAccInfo(arciumProgram, address, commitment) {
117
126
  return arciumProgram.account.mxeRecoveryAccount.fetch(address, commitment);
118
127
  }
119
128
  /**
120
- * Fetches and parses a given ArxNode account.
121
- * @param arciumProgram - The Anchor program instance.
122
- * @param address - The public key of the ArxNode account.
123
- * @param commitment - (Optional) RPC commitment level.
124
- * @returns The ArxNodeAccount object.
129
+ * Fetch and parse an ArxNode account.
130
+ * @param arciumProgram - Anchor program instance.
131
+ * @param address - Public key of the ArxNode account.
132
+ * @param commitment - RPC commitment level.
133
+ * @returns Parsed ArxNodeAccount data.
125
134
  */
126
135
  async function getArxNodeAccInfo(arciumProgram, address, commitment) {
127
136
  return arciumProgram.account.arxNode.fetch(address, commitment);
128
137
  }
129
138
  /**
130
- * Fetches and parses a given ComputationDefinition account.
131
- * @param arciumProgram - The Anchor program instance.
132
- * @param address - The public key of the ComputationDefinition account.
133
- * @param commitment - (Optional) RPC commitment level.
134
- * @returns The ComputationDefinitionAccount object.
139
+ * Fetch and parse a ComputationDefinition account.
140
+ * @param arciumProgram - Anchor program instance.
141
+ * @param address - Public key of the ComputationDefinition account.
142
+ * @param commitment - RPC commitment level.
143
+ * @returns Parsed ComputationDefinitionAccount data.
135
144
  */
136
145
  async function getCompDefAccInfo(arciumProgram, address, commitment) {
137
146
  return arciumProgram.account.computationDefinitionAccount.fetch(address, commitment);
138
147
  }
139
148
  /**
140
- * Fetches and parses a given Computation account.
141
- * @param arciumProgram - The Anchor program instance.
142
- * @param address - The public key of the Computation account.
143
- * @param commitment - (Optional) RPC commitment level.
144
- * @returns The Computation object.
149
+ * Fetch and parse a Computation account.
150
+ * @param arciumProgram - Anchor program instance.
151
+ * @param address - Public key of the Computation account.
152
+ * @param commitment - RPC commitment level.
153
+ * @returns Parsed ComputationAccount data.
145
154
  */
146
155
  async function getComputationAccInfo(arciumProgram, address, commitment) {
147
156
  return arciumProgram.account.computationAccount.fetch(address, commitment);
@@ -163,11 +172,28 @@ async function getArciumAccPubkeys(conn, discriminator) {
163
172
  }
164
173
 
165
174
  /**
166
- * Subscribes to computation-related events for a given MXE program ID.
167
- * @param conn - The Solana connection object.
168
- * @param mxeProgramId - The public key of the MXE program.
169
- * @param callback - Callback function to handle each computation event and its name.
170
- * @returns The subscription ID for the logs listener.
175
+ * Subscribe to computation events for an MXE program.
176
+ *
177
+ * Listens for queue, execute, and finalize events via Solana log subscriptions.
178
+ *
179
+ * @param conn - Solana connection object.
180
+ * @param mxeProgramId - Public key of the MXE program to monitor.
181
+ * @param callback - Handler called for each event with event data and event name.
182
+ * @returns Subscription ID for cleanup with {@link unsubscribeComputations}.
183
+ *
184
+ * @example
185
+ * const subId = await subscribeComputations(
186
+ * connection,
187
+ * mxeProgramId,
188
+ * (event, name) => {
189
+ * if (name === 'FinalizeComputationEvent') {
190
+ * console.log('Computation finalized:', event.computationOffset.toString());
191
+ * }
192
+ * },
193
+ * );
194
+ *
195
+ * // When done, clean up the subscription
196
+ * await unsubscribeComputations(connection, subId);
171
197
  */
172
198
  async function subscribeComputations(conn, mxeProgramId, callback) {
173
199
  return conn.onLogs(mxeProgramId, (logs) => {
@@ -178,17 +204,17 @@ async function subscribeComputations(conn, mxeProgramId, callback) {
178
204
  });
179
205
  }
180
206
  /**
181
- * Unsubscribes from computation-related events using the subscription ID.
182
- * @param conn - The Solana connection object.
183
- * @param subscriptionId - The subscription ID returned by subscribeComputations.
207
+ * Unsubscribe from computation events.
208
+ * @param conn - Solana connection object.
209
+ * @param subscriptionId - Subscription ID returned by {@link subscribeComputations}.
184
210
  */
185
211
  async function unsubscribeComputations(conn, subscriptionId) {
186
212
  conn.removeOnLogsListener(subscriptionId);
187
213
  }
188
214
  /**
189
- * Gets the computation offset from a transaction.
190
- * @param tx - The transaction to get the computation offset from.
191
- * @returns The computation offset if one is found, otherwise undefined.
215
+ * Get the computation offset from a transaction.
216
+ * @param tx - Transaction to extract the computation offset from.
217
+ * @returns Computation offset if found, otherwise undefined.
192
218
  * @throws Error if multiple computation offsets are found in the transaction.
193
219
  */
194
220
  function getComputationOffset(tx) {
@@ -204,7 +230,7 @@ function getComputationOffset(tx) {
204
230
  return computationOffset;
205
231
  }
206
232
  /**
207
- * Get the events related to arcium computations from a transaction's logs
233
+ * Get the events related to Arcium computations from a transaction's logs.
208
234
  *
209
235
  * Note: This implements a direct decode approach instead of using Anchor's EventParser.parseLogs().
210
236
  *
@@ -215,7 +241,7 @@ function getComputationOffset(tx) {
215
241
  * 3. Only parses events when execution.program() === EventParser.programId
216
242
  *
217
243
  * This breaks our use case:
218
- * - We subscribe to MXE program logs (line 29) via conn.onLogs(mxeProgramId, ...)
244
+ * - We subscribe to MXE program logs via conn.onLogs(mxeProgramId, ...) in {@link subscribeComputations}
219
245
  * - But we need to parse Arcium events emitted during MXE→Arcium CPI calls
220
246
  * - When MXE is the root program, execution.program() = MXE_PROGRAM_ID
221
247
  * - EventParser expects execution.program() = ARCIUM_PROGRAM_ID
@@ -227,8 +253,8 @@ function getComputationOffset(tx) {
227
253
  * - Works regardless of which program is root or subscription target
228
254
  * - Handles both MXE→Arcium and Arcium→MXE CPI patterns
229
255
  *
230
- * @param logs - The logs to get the events from
231
- * @returns The events in the logs.
256
+ * @param logs - Logs to get the events from.
257
+ * @returns Array of parsed Arcium computation events.
232
258
  */
233
259
  function getComputationEventsFromLogs(logs) {
234
260
  const events = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcium-hq/reader",
3
- "version": "0.8.5",
3
+ "version": "0.9.1",
4
4
  "description": "Reader SDK for fetching onchain data for Arcium network programs",
5
5
  "author": "Arcium",
6
6
  "license": "GPL-3.0-only",
@@ -58,7 +58,7 @@
58
58
  "@coral-xyz/anchor": "^0.32.1",
59
59
  "@noble/curves": "^1.9.5",
60
60
  "@noble/hashes": "^1.7.1",
61
- "@arcium-hq/client": "0.8.5"
61
+ "@arcium-hq/client": "0.9.1"
62
62
  },
63
63
  "keywords": [
64
64
  "Cryptography",