@arcium-hq/reader 0.1.46 → 0.2.0
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 +237 -70
- package/build/index.cjs +147 -45
- package/build/index.d.ts +104 -15
- package/build/index.mjs +126 -25
- package/package.json +10 -8
package/README.md
CHANGED
|
@@ -1,126 +1,293 @@
|
|
|
1
1
|
# Arcium Reader SDK
|
|
2
2
|
|
|
3
|
-
The Arcium Reader SDK is a TypeScript library
|
|
3
|
+
The Arcium Reader SDK is a TypeScript library for passively observing and querying the Arcium network state. It provides read-only access to account data, computation tracking, and event monitoring without requiring a wallet or signer.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @arcium-hq/reader
|
|
9
|
-
|
|
10
|
-
or
|
|
11
|
-
|
|
12
|
-
```bash
|
|
9
|
+
# or
|
|
13
10
|
yarn add @arcium-hq/reader
|
|
14
|
-
|
|
15
|
-
or
|
|
16
|
-
|
|
17
|
-
```bash
|
|
11
|
+
# or
|
|
18
12
|
pnpm add @arcium-hq/reader
|
|
19
13
|
```
|
|
20
14
|
|
|
21
|
-
##
|
|
22
|
-
|
|
23
|
-
### Getting the Read-only Program
|
|
15
|
+
## Quick Start
|
|
24
16
|
|
|
25
|
-
|
|
17
|
+
### 1. Setup
|
|
26
18
|
|
|
27
19
|
```typescript
|
|
28
20
|
import * as anchor from "@coral-xyz/anchor";
|
|
29
21
|
import { getArciumProgramReadonly } from "@arcium-hq/reader";
|
|
30
22
|
|
|
31
|
-
//
|
|
32
|
-
const
|
|
33
|
-
const
|
|
23
|
+
// Setup connection (no wallet required)
|
|
24
|
+
const connection = new anchor.web3.Connection("https://api.mainnet-beta.solana.com");
|
|
25
|
+
const provider = new anchor.AnchorProvider(connection, null, {});
|
|
26
|
+
const arciumProgram = getArciumProgramReadonly(provider);
|
|
34
27
|
```
|
|
35
28
|
|
|
36
|
-
###
|
|
29
|
+
### 2. Query Account Information
|
|
37
30
|
|
|
38
|
-
|
|
31
|
+
```typescript
|
|
32
|
+
import {
|
|
33
|
+
getMXEAccAddresses,
|
|
34
|
+
getMXEAccInfo,
|
|
35
|
+
getClusterAccAddresses,
|
|
36
|
+
getClusterAccInfo,
|
|
37
|
+
} from "@arcium-hq/reader";
|
|
38
|
+
|
|
39
|
+
// Get all MXE accounts
|
|
40
|
+
const mxeAddresses = await getMXEAccAddresses(connection);
|
|
41
|
+
console.log(`Found ${mxeAddresses.length} MXE accounts`);
|
|
42
|
+
|
|
43
|
+
// Get detailed information for first MXE
|
|
44
|
+
if (mxeAddresses.length > 0) {
|
|
45
|
+
const mxeInfo = await getMXEAccInfo(arciumProgram, mxeAddresses[0]);
|
|
46
|
+
console.log("MXE Info:", {
|
|
47
|
+
authority: mxeInfo.authority,
|
|
48
|
+
cluster: mxeInfo.cluster,
|
|
49
|
+
computationDefinitions: mxeInfo.computationDefinitions.length,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
```
|
|
39
53
|
|
|
40
|
-
|
|
54
|
+
### 3. Monitor Computations
|
|
41
55
|
|
|
42
56
|
```typescript
|
|
43
|
-
import {
|
|
57
|
+
import { subscribeComputations } from "@arcium-hq/reader";
|
|
44
58
|
|
|
45
|
-
//
|
|
46
|
-
const
|
|
59
|
+
// Subscribe to computation events for an MXE program
|
|
60
|
+
const mxeProgramId = new anchor.web3.PublicKey("YOUR_MXE_PROGRAM_ID");
|
|
47
61
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
62
|
+
const subscriptionId = await subscribeComputations(
|
|
63
|
+
connection,
|
|
64
|
+
mxeProgramId,
|
|
65
|
+
(eventData, eventName) => {
|
|
66
|
+
console.log(`Event: ${eventName}`, eventData);
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Account Types and Queries
|
|
72
|
+
|
|
73
|
+
### MXE (Multi-party eXecution Environment) Accounts
|
|
74
|
+
|
|
75
|
+
MXE accounts represent execution environments for secure computations.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { getMXEAccAddresses, getMXEAccInfo } from "@arcium-hq/reader";
|
|
79
|
+
|
|
80
|
+
// Get all MXE account addresses
|
|
81
|
+
const mxeAddresses = await getMXEAccAddresses(connection);
|
|
82
|
+
|
|
83
|
+
// Fetch detailed MXE information
|
|
84
|
+
for (const address of mxeAddresses) {
|
|
85
|
+
const mxeInfo = await getMXEAccInfo(arciumProgram, address);
|
|
86
|
+
|
|
87
|
+
console.log("MXE Account:", {
|
|
88
|
+
address: address.toBase58(),
|
|
89
|
+
authority: mxeInfo.authority?.toBase58(),
|
|
90
|
+
cluster: mxeInfo.cluster,
|
|
91
|
+
x25519KeySet: 'set' in mxeInfo.x25519Pubkey,
|
|
92
|
+
computationDefinitions: mxeInfo.computationDefinitions,
|
|
93
|
+
fallbackClusters: mxeInfo.fallbackClusters,
|
|
94
|
+
});
|
|
53
95
|
}
|
|
54
96
|
```
|
|
55
97
|
|
|
56
|
-
|
|
98
|
+
### Cluster Accounts
|
|
99
|
+
|
|
100
|
+
Cluster accounts manage collections of ARX nodes that execute computations.
|
|
57
101
|
|
|
58
102
|
```typescript
|
|
59
|
-
import {
|
|
103
|
+
import { getClusterAccAddresses, getClusterAccInfo } from "@arcium-hq/reader";
|
|
104
|
+
|
|
105
|
+
// Get all cluster addresses
|
|
106
|
+
const clusterAddresses = await getClusterAccAddresses(connection);
|
|
107
|
+
|
|
108
|
+
// Analyze cluster information
|
|
109
|
+
for (const address of clusterAddresses) {
|
|
110
|
+
const clusterInfo = await getClusterAccInfo(arciumProgram, address);
|
|
111
|
+
|
|
112
|
+
console.log("Cluster:", {
|
|
113
|
+
address: address.toBase58(),
|
|
114
|
+
nodeCount: clusterInfo.nodes.length,
|
|
115
|
+
mxeCount: clusterInfo.mxes.length,
|
|
116
|
+
threshold: clusterInfo.threshold,
|
|
117
|
+
state: clusterInfo.state,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### ArxNode Accounts
|
|
60
123
|
|
|
61
|
-
|
|
62
|
-
const clusterAccPubkeys = await getClusterAccs(provider.connection);
|
|
124
|
+
ArxNode accounts represent individual computation nodes in the network.
|
|
63
125
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
126
|
+
```typescript
|
|
127
|
+
import { getArxNodeAccAddresses, getArxNodeAccInfo } from "@arcium-hq/reader";
|
|
128
|
+
|
|
129
|
+
// Get all ARX node addresses
|
|
130
|
+
const arxNodeAddresses = await getArxNodeAccAddresses(connection);
|
|
131
|
+
|
|
132
|
+
// Get node information
|
|
133
|
+
for (const address of arxNodeAddresses) {
|
|
134
|
+
const nodeInfo = await getArxNodeAccInfo(arciumProgram, address);
|
|
135
|
+
|
|
136
|
+
console.log("ARX Node:", {
|
|
137
|
+
address: address.toBase58(),
|
|
138
|
+
authority: nodeInfo.authority?.toBase58(),
|
|
139
|
+
clusterMemberships: nodeInfo.clusterMemberships,
|
|
140
|
+
encryptionPubkey: Buffer.from(nodeInfo.encryptionPubkey).toString('hex'),
|
|
141
|
+
});
|
|
69
142
|
}
|
|
70
143
|
```
|
|
71
144
|
|
|
72
|
-
|
|
145
|
+
### Computation Definition Accounts
|
|
146
|
+
|
|
147
|
+
Track available computation definitions and their configurations.
|
|
73
148
|
|
|
74
149
|
```typescript
|
|
75
|
-
import {
|
|
150
|
+
import { getCompDefAccInfo } from "@arcium-hq/reader";
|
|
151
|
+
import { getCompDefAccAddress } from "@arcium-hq/reader";
|
|
152
|
+
|
|
153
|
+
// Get computation definition for a specific circuit
|
|
154
|
+
const circuitName = "your_circuit_name";
|
|
155
|
+
const mxeProgramId = new anchor.web3.PublicKey("YOUR_MXE_PROGRAM_ID");
|
|
156
|
+
|
|
157
|
+
const compDefAddress = getCompDefAccAddress(mxeProgramId, /* offset */);
|
|
158
|
+
const compDefInfo = await getCompDefAccInfo(arciumProgram, compDefAddress);
|
|
159
|
+
|
|
160
|
+
console.log("Computation Definition:", {
|
|
161
|
+
finalizationAuthority: compDefInfo.finalizationAuthority?.toBase58(),
|
|
162
|
+
finalizesDuringCallback: compDefInfo.finalizeDuringCallback,
|
|
163
|
+
cuAmount: compDefInfo.cuAmount.toString(),
|
|
164
|
+
circuitSource: compDefInfo.circuitSource,
|
|
165
|
+
});
|
|
166
|
+
```
|
|
76
167
|
|
|
77
|
-
|
|
78
|
-
const arxNodeAccPubkeys = await getArxNodeAccs(provider.connection);
|
|
168
|
+
### Computation Accounts
|
|
79
169
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
170
|
+
Monitor individual computation instances and their status.
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { getComputationAccInfo } from "@arcium-hq/reader";
|
|
174
|
+
import { getComputationAccAddress } from "@arcium-hq/reader";
|
|
175
|
+
|
|
176
|
+
// Get computation account info
|
|
177
|
+
const computationOffset = new anchor.BN("123456789");
|
|
178
|
+
const computationAddress = getComputationAccAddress(mxeProgramId, computationOffset);
|
|
179
|
+
const computationInfo = await getComputationAccInfo(arciumProgram, computationAddress);
|
|
180
|
+
|
|
181
|
+
console.log("Computation:", {
|
|
182
|
+
status: computationInfo.status,
|
|
183
|
+
arguments: computationInfo.arguments,
|
|
184
|
+
results: computationInfo.results,
|
|
185
|
+
submitter: computationInfo.submitter.toBase58(),
|
|
186
|
+
});
|
|
86
187
|
```
|
|
87
188
|
|
|
88
|
-
|
|
189
|
+
## Mempool Analysis
|
|
89
190
|
|
|
90
|
-
|
|
191
|
+
Analyze pending computations in the network's memory pools.
|
|
91
192
|
|
|
92
193
|
```typescript
|
|
93
|
-
import {
|
|
94
|
-
|
|
194
|
+
import {
|
|
195
|
+
getComputationsInMempool,
|
|
196
|
+
getMempoolAccAddress
|
|
197
|
+
} from "@arcium-hq/reader";
|
|
198
|
+
|
|
199
|
+
// Get mempool for an MXE
|
|
200
|
+
const mempoolAddress = getMempoolAccAddress(mxeProgramId);
|
|
201
|
+
const pendingComputations = await getComputationsInMempool(arciumProgram, mempoolAddress);
|
|
202
|
+
|
|
203
|
+
console.log(`Found ${pendingComputations.length} pending computations:`);
|
|
204
|
+
|
|
205
|
+
for (const compRef of pendingComputations) {
|
|
206
|
+
console.log("Pending Computation:", {
|
|
207
|
+
computationOffset: compRef.computationOffset.toString(),
|
|
208
|
+
priorityFee: compRef.priorityFee.toString(),
|
|
209
|
+
computationDefinitionOffset: compRef.computationDefinitionOffset,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
```
|
|
95
213
|
|
|
96
|
-
|
|
97
|
-
const mxeProgramId = new PublicKey("YOUR_MXE_PROGRAM_ID");
|
|
214
|
+
## Event Monitoring
|
|
98
215
|
|
|
99
|
-
|
|
216
|
+
### Real-time Event Subscription
|
|
100
217
|
|
|
101
|
-
|
|
102
|
-
const eventCallback = (eventData: any, eventName: string) => {
|
|
103
|
-
console.log(`Received event: ${eventName}`, eventData);
|
|
104
|
-
eventLog.push({ event: eventData, name: eventName });
|
|
105
|
-
// Events typically include QueueComputationEvent, InitComputationEvent,
|
|
106
|
-
// CallbackComputationEvent, FinalizeComputationEvent
|
|
107
|
-
};
|
|
218
|
+
Monitor computation lifecycle events in real-time:
|
|
108
219
|
|
|
109
|
-
|
|
110
|
-
|
|
220
|
+
```typescript
|
|
221
|
+
import {
|
|
222
|
+
subscribeComputations,
|
|
223
|
+
unsubscribeComputations,
|
|
224
|
+
ArciumEventData,
|
|
225
|
+
ArciumEventName
|
|
226
|
+
} from "@arcium-hq/reader";
|
|
227
|
+
|
|
228
|
+
const eventLog: Array<{event: ArciumEventData, name: ArciumEventName, timestamp: Date}> = [];
|
|
229
|
+
|
|
230
|
+
// Subscribe to events
|
|
111
231
|
const subscriptionId = await subscribeComputations(
|
|
112
|
-
|
|
113
|
-
mxeProgramId,
|
|
114
|
-
|
|
232
|
+
connection,
|
|
233
|
+
mxeProgramId,
|
|
234
|
+
(eventData, eventName) => {
|
|
235
|
+
eventLog.push({
|
|
236
|
+
event: eventData,
|
|
237
|
+
name: eventName,
|
|
238
|
+
timestamp: new Date()
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
console.log(`[${eventName}] Computation ${eventData.computationOffset.toString()}`);
|
|
242
|
+
|
|
243
|
+
// Handle specific event types
|
|
244
|
+
switch (eventName) {
|
|
245
|
+
case 'QueueComputationEvent':
|
|
246
|
+
console.log(" → Computation queued for execution");
|
|
247
|
+
break;
|
|
248
|
+
case 'InitComputationEvent':
|
|
249
|
+
console.log(" → Computation execution started");
|
|
250
|
+
break;
|
|
251
|
+
case 'CallbackComputationEvent':
|
|
252
|
+
console.log(" → Computation callback received");
|
|
253
|
+
break;
|
|
254
|
+
case 'FinalizeComputationEvent':
|
|
255
|
+
console.log(" → Computation finalized");
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
115
259
|
);
|
|
116
260
|
|
|
117
|
-
console.log(`
|
|
261
|
+
console.log(`Subscribed to events with ID: ${subscriptionId}`);
|
|
262
|
+
|
|
263
|
+
// Later, unsubscribe
|
|
264
|
+
// await unsubscribeComputations(connection, subscriptionId);
|
|
265
|
+
```
|
|
118
266
|
|
|
119
|
-
|
|
267
|
+
### Transaction Analysis
|
|
120
268
|
|
|
121
|
-
|
|
122
|
-
await unsubscribeComputations(provider.connection, subscriptionId);
|
|
123
|
-
console.log(`Unsubscribed from computation events.`);
|
|
269
|
+
Extract computation events from transaction logs:
|
|
124
270
|
|
|
271
|
+
```typescript
|
|
272
|
+
import { getComputationOffset } from "@arcium-hq/reader";
|
|
273
|
+
|
|
274
|
+
// Analyze a specific transaction
|
|
275
|
+
const txSignature = "YOUR_TRANSACTION_SIGNATURE";
|
|
276
|
+
const tx = await connection.getTransaction(txSignature, {
|
|
277
|
+
commitment: "confirmed",
|
|
278
|
+
maxSupportedTransactionVersion: 0
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
if (tx) {
|
|
282
|
+
const computationOffset = getComputationOffset(tx);
|
|
283
|
+
if (computationOffset) {
|
|
284
|
+
console.log(`Transaction contains computation: ${computationOffset.toString()}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
125
287
|
```
|
|
126
288
|
|
|
289
|
+
## API Reference
|
|
290
|
+
|
|
291
|
+
<!-- TODO: Add API reference url -->
|
|
292
|
+
|
|
293
|
+
For detailed API documentation, please refer to the [Arcium TypeScript SDK API reference](https://github.com/arcium-hq).
|
package/build/index.cjs
CHANGED
|
@@ -23,35 +23,102 @@ function _interopNamespaceDefault(e) {
|
|
|
23
23
|
var anchor__namespace = /*#__PURE__*/_interopNamespaceDefault(anchor);
|
|
24
24
|
|
|
25
25
|
const ARCIUM_PROGRAM_ID_STRING = 'BKck65TgoKRokMjQM3datB9oRwJ8rAj2jxPXvHXUvcL6';
|
|
26
|
+
/**
|
|
27
|
+
* Discriminator for the ArxNode account type. Used to filter and identify ArxNode accounts on-chain.
|
|
28
|
+
*/
|
|
26
29
|
const ARX_NODE_ACC_DISCRIMINATOR = [2, 207, 122, 223, 93, 97, 231, 199];
|
|
30
|
+
/**
|
|
31
|
+
* Discriminator for the Cluster account type. Used to filter and identify Cluster accounts on-chain.
|
|
32
|
+
*/
|
|
27
33
|
const CLUSTER_ACC_DISCRIMINATOR = [236, 225, 118, 228, 173, 106, 18, 60];
|
|
28
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Discriminator for the MXE account type. Used to filter and identify MXE accounts on-chain.
|
|
36
|
+
*/
|
|
37
|
+
const MXE_ACC_DISCRIMINATOR = [103, 26, 85, 250, 179, 159, 17, 117];
|
|
38
|
+
/**
|
|
39
|
+
* The public key of the deployed Arcium program on Solana.
|
|
40
|
+
*/
|
|
29
41
|
const ARCIUM_PROGRAM_ID = new anchor__namespace.web3.PublicKey(ARCIUM_PROGRAM_ID_STRING);
|
|
42
|
+
/**
|
|
43
|
+
* Anchor coder for encoding and decoding Arcium program instructions.
|
|
44
|
+
*/
|
|
30
45
|
new anchor__namespace.BorshInstructionCoder(client.ARCIUM_IDL);
|
|
46
|
+
/**
|
|
47
|
+
* Anchor event parser for parsing Arcium program events from transaction logs.
|
|
48
|
+
*/
|
|
31
49
|
const ARCIUM_EVENT_CODER = new anchor__namespace.EventParser(ARCIUM_PROGRAM_ID, new anchor__namespace.BorshCoder(client.ARCIUM_IDL));
|
|
32
50
|
|
|
33
|
-
|
|
34
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Returns all MXE account addresses.
|
|
53
|
+
* @param conn - The Solana connection object.
|
|
54
|
+
* @returns Array of MXE account public keys.
|
|
55
|
+
*/
|
|
56
|
+
async function getMXEAccAddresses(conn) {
|
|
35
57
|
return getArciumAccPubkeys(conn, MXE_ACC_DISCRIMINATOR);
|
|
36
58
|
}
|
|
37
|
-
|
|
38
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Returns all Cluster account addresses.
|
|
61
|
+
* @param conn - The Solana connection object.
|
|
62
|
+
* @returns Array of Cluster account public keys.
|
|
63
|
+
*/
|
|
64
|
+
async function getClusterAccAddresses(conn) {
|
|
39
65
|
return getArciumAccPubkeys(conn, CLUSTER_ACC_DISCRIMINATOR);
|
|
40
66
|
}
|
|
41
|
-
|
|
42
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Returns all ArxNode account addresses.
|
|
69
|
+
* @param conn - The Solana connection object.
|
|
70
|
+
* @returns Array of ArxNode account public keys.
|
|
71
|
+
*/
|
|
72
|
+
async function getArxNodeAccAddresses(conn) {
|
|
43
73
|
return getArciumAccPubkeys(conn, ARX_NODE_ACC_DISCRIMINATOR);
|
|
44
74
|
}
|
|
45
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Fetches and parses a given MXE account.
|
|
77
|
+
* @param arciumProgram - The Anchor program instance.
|
|
78
|
+
* @param address - The public key of the MXE account.
|
|
79
|
+
* @param commitment - (Optional) RPC commitment level.
|
|
80
|
+
* @returns The MXEAccount object.
|
|
81
|
+
*/
|
|
46
82
|
async function getMXEAccInfo(arciumProgram, address, commitment) {
|
|
47
|
-
return arciumProgram.account.
|
|
83
|
+
return arciumProgram.account.mxeAccount.fetch(address, commitment);
|
|
48
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Fetches and parses a given Cluster account.
|
|
87
|
+
* @param arciumProgram - The Anchor program instance.
|
|
88
|
+
* @param address - The public key of the Cluster account.
|
|
89
|
+
* @param commitment - (Optional) RPC commitment level.
|
|
90
|
+
* @returns The ClusterAccount object.
|
|
91
|
+
*/
|
|
49
92
|
async function getClusterAccInfo(arciumProgram, address, commitment) {
|
|
50
93
|
return arciumProgram.account.cluster.fetch(address, commitment);
|
|
51
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Fetches and parses a given ArxNode account.
|
|
97
|
+
* @param arciumProgram - The Anchor program instance.
|
|
98
|
+
* @param address - The public key of the ArxNode account.
|
|
99
|
+
* @param commitment - (Optional) RPC commitment level.
|
|
100
|
+
* @returns The ArxNodeAccount object.
|
|
101
|
+
*/
|
|
52
102
|
async function getArxNodeAccInfo(arciumProgram, address, commitment) {
|
|
53
103
|
return arciumProgram.account.arxNode.fetch(address, commitment);
|
|
54
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Fetches and parses a given ComputationDefinition account.
|
|
107
|
+
* @param arciumProgram - The Anchor program instance.
|
|
108
|
+
* @param address - The public key of the ComputationDefinition account.
|
|
109
|
+
* @param commitment - (Optional) RPC commitment level.
|
|
110
|
+
* @returns The ComputationDefinitionAccount object.
|
|
111
|
+
*/
|
|
112
|
+
async function getCompDefAccInfo(arciumProgram, address, commitment) {
|
|
113
|
+
return arciumProgram.account.computationDefinitionAccount.fetch(address, commitment);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Returns all computation references in the mempool for a given account.
|
|
117
|
+
* Only non-stake computations are included.
|
|
118
|
+
* @param arciumProgram - The Anchor program instance.
|
|
119
|
+
* @param address - The public key of the mempool account.
|
|
120
|
+
* @returns Array of ComputationReference objects.
|
|
121
|
+
*/
|
|
55
122
|
async function getComputationsInMempool(arciumProgram, address) {
|
|
56
123
|
const mempool = await client.getMempoolAccData(arciumProgram.provider, address);
|
|
57
124
|
const startIndex = mempool.inner.computations.startIndex;
|
|
@@ -75,27 +142,40 @@ async function getComputationsInMempool(arciumProgram, address) {
|
|
|
75
142
|
refs.push(...elems[idx].entries);
|
|
76
143
|
}
|
|
77
144
|
}
|
|
78
|
-
return refs
|
|
145
|
+
return refs
|
|
146
|
+
.flat()
|
|
147
|
+
.filter((ref) => !isNullRef(ref));
|
|
79
148
|
}
|
|
80
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Fetches and parses a given Computation account.
|
|
151
|
+
* @param arciumProgram - The Anchor program instance.
|
|
152
|
+
* @param address - The public key of the Computation account.
|
|
153
|
+
* @param commitment - (Optional) RPC commitment level.
|
|
154
|
+
* @returns The Computation object.
|
|
155
|
+
*/
|
|
156
|
+
async function getComputationAccInfo(arciumProgram, address, commitment) {
|
|
81
157
|
return arciumProgram.account.computationAccount.fetch(address, commitment);
|
|
82
158
|
}
|
|
83
159
|
async function getArciumAccPubkeys(conn, discriminator) {
|
|
84
160
|
const accs = await conn.getProgramAccounts(ARCIUM_PROGRAM_ID, {
|
|
85
161
|
dataSlice: { offset: 0, length: 0 },
|
|
86
|
-
filters: [
|
|
162
|
+
filters: [
|
|
163
|
+
{
|
|
87
164
|
memcmp: {
|
|
88
165
|
offset: 0,
|
|
89
166
|
encoding: 'base64',
|
|
90
167
|
bytes: Buffer.from(discriminator).toString('base64'),
|
|
91
168
|
},
|
|
92
|
-
}
|
|
169
|
+
},
|
|
170
|
+
],
|
|
93
171
|
});
|
|
94
172
|
return accs.map((acc) => acc.pubkey);
|
|
95
173
|
}
|
|
96
174
|
function isNullRef(ref) {
|
|
97
175
|
const bigZero = new anchor__namespace.BN(0);
|
|
98
|
-
return ref.computationDefinitionOffset === 0
|
|
176
|
+
return (ref.computationDefinitionOffset === 0
|
|
177
|
+
&& ref.computationOffset === bigZero
|
|
178
|
+
&& ref.priorityFee === bigZero);
|
|
99
179
|
}
|
|
100
180
|
|
|
101
181
|
const ArciumEventNames = [
|
|
@@ -104,6 +184,13 @@ const ArciumEventNames = [
|
|
|
104
184
|
'CallbackComputationEvent',
|
|
105
185
|
'FinalizeComputationEvent',
|
|
106
186
|
];
|
|
187
|
+
/**
|
|
188
|
+
* Subscribes to computation-related events for a given MXE program ID.
|
|
189
|
+
* @param conn - The Solana connection object.
|
|
190
|
+
* @param mxeProgramId - The public key of the MXE program.
|
|
191
|
+
* @param callback - Callback function to handle each computation event and its name.
|
|
192
|
+
* @returns The subscription ID for the logs listener.
|
|
193
|
+
*/
|
|
107
194
|
async function subscribeComputations(conn, mxeProgramId, callback) {
|
|
108
195
|
return conn.onLogs(mxeProgramId, (logs) => {
|
|
109
196
|
const events = getComputationEventsFromLogs(logs.logs);
|
|
@@ -112,14 +199,19 @@ async function subscribeComputations(conn, mxeProgramId, callback) {
|
|
|
112
199
|
}
|
|
113
200
|
});
|
|
114
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Unsubscribes from computation-related events using the subscription ID.
|
|
204
|
+
* @param conn - The Solana connection object.
|
|
205
|
+
* @param subscriptionId - The subscription ID returned by subscribeComputations.
|
|
206
|
+
*/
|
|
115
207
|
async function unsubscribeComputations(conn, subscriptionId) {
|
|
116
208
|
conn.removeOnLogsListener(subscriptionId);
|
|
117
209
|
}
|
|
118
210
|
/**
|
|
119
|
-
*
|
|
120
|
-
* @param tx - The transaction to get the computation offset from
|
|
121
|
-
* @returns The computation offset if one is found, otherwise
|
|
122
|
-
* @throws Error if multiple computation offsets are found in the transaction
|
|
211
|
+
* Gets the computation offset from a transaction.
|
|
212
|
+
* @param tx - The transaction to get the computation offset from.
|
|
213
|
+
* @returns The computation offset if one is found, otherwise undefined.
|
|
214
|
+
* @throws Error if multiple computation offsets are found in the transaction.
|
|
123
215
|
*/
|
|
124
216
|
function getComputationOffset(tx) {
|
|
125
217
|
const events = getComputationEventsFromLogs(tx.meta?.logMessages ?? []);
|
|
@@ -128,7 +220,7 @@ function getComputationOffset(tx) {
|
|
|
128
220
|
}
|
|
129
221
|
const computationOffsets = events.map((e) => e.event.computationOffset);
|
|
130
222
|
const computationOffset = computationOffsets[0];
|
|
131
|
-
if (computationOffsets.some((offset) => offset
|
|
223
|
+
if (computationOffsets.some((offset) => !offset.eq(computationOffset))) {
|
|
132
224
|
throw new Error(`Multiple computation offsets found in computation: ${JSON.stringify(computationOffsets)}`);
|
|
133
225
|
}
|
|
134
226
|
return computationOffset;
|
|
@@ -141,60 +233,70 @@ function getComputationOffset(tx) {
|
|
|
141
233
|
function getComputationEventsFromLogs(logs) {
|
|
142
234
|
return Array.from(ARCIUM_EVENT_CODER.parseLogs(logs))
|
|
143
235
|
.filter((e) => ArciumEventNames.includes(e.name))
|
|
144
|
-
.map((e) =>
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
236
|
+
.map((e) => {
|
|
237
|
+
const eventData = {
|
|
238
|
+
computationOffset: e.data.computation_offset,
|
|
239
|
+
...e.data,
|
|
240
|
+
};
|
|
241
|
+
if (e.data.mxe_program_id) {
|
|
242
|
+
eventData.mxeProgramId = e.data.mxe_program_id;
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
event: eventData,
|
|
246
|
+
name: e.name,
|
|
247
|
+
};
|
|
248
|
+
});
|
|
148
249
|
}
|
|
149
250
|
|
|
150
251
|
Object.defineProperty(exports, "getArciumProgramReadonly", {
|
|
151
252
|
enumerable: true,
|
|
152
253
|
get: function () { return client.getArciumProgramReadonly; }
|
|
153
254
|
});
|
|
154
|
-
Object.defineProperty(exports, "
|
|
255
|
+
Object.defineProperty(exports, "getArxNodeAccAddress", {
|
|
155
256
|
enumerable: true,
|
|
156
|
-
get: function () { return client.
|
|
257
|
+
get: function () { return client.getArxNodeAccAddress; }
|
|
157
258
|
});
|
|
158
|
-
Object.defineProperty(exports, "
|
|
259
|
+
Object.defineProperty(exports, "getClockAccAddress", {
|
|
159
260
|
enumerable: true,
|
|
160
|
-
get: function () { return client.
|
|
261
|
+
get: function () { return client.getClockAccAddress; }
|
|
161
262
|
});
|
|
162
|
-
Object.defineProperty(exports, "
|
|
263
|
+
Object.defineProperty(exports, "getClusterAccAddress", {
|
|
163
264
|
enumerable: true,
|
|
164
|
-
get: function () { return client.
|
|
265
|
+
get: function () { return client.getClusterAccAddress; }
|
|
165
266
|
});
|
|
166
|
-
Object.defineProperty(exports, "
|
|
267
|
+
Object.defineProperty(exports, "getCompDefAccAddress", {
|
|
167
268
|
enumerable: true,
|
|
168
|
-
get: function () { return client.
|
|
269
|
+
get: function () { return client.getCompDefAccAddress; }
|
|
169
270
|
});
|
|
170
|
-
Object.defineProperty(exports, "
|
|
271
|
+
Object.defineProperty(exports, "getComputationAccAddress", {
|
|
171
272
|
enumerable: true,
|
|
172
|
-
get: function () { return client.
|
|
273
|
+
get: function () { return client.getComputationAccAddress; }
|
|
173
274
|
});
|
|
174
|
-
Object.defineProperty(exports, "
|
|
275
|
+
Object.defineProperty(exports, "getExecutingPoolAccAddress", {
|
|
175
276
|
enumerable: true,
|
|
176
|
-
get: function () { return client.
|
|
277
|
+
get: function () { return client.getExecutingPoolAccAddress; }
|
|
177
278
|
});
|
|
178
|
-
Object.defineProperty(exports, "
|
|
279
|
+
Object.defineProperty(exports, "getMXEAccAddress", {
|
|
179
280
|
enumerable: true,
|
|
180
|
-
get: function () { return client.
|
|
281
|
+
get: function () { return client.getMXEAccAddress; }
|
|
181
282
|
});
|
|
182
|
-
Object.defineProperty(exports, "
|
|
283
|
+
Object.defineProperty(exports, "getMempoolAccAddress", {
|
|
183
284
|
enumerable: true,
|
|
184
|
-
get: function () { return client.
|
|
285
|
+
get: function () { return client.getMempoolAccAddress; }
|
|
185
286
|
});
|
|
186
|
-
Object.defineProperty(exports, "
|
|
287
|
+
Object.defineProperty(exports, "getStakingPoolAccAddress", {
|
|
187
288
|
enumerable: true,
|
|
188
|
-
get: function () { return client.
|
|
289
|
+
get: function () { return client.getStakingPoolAccAddress; }
|
|
189
290
|
});
|
|
291
|
+
exports.getArxNodeAccAddresses = getArxNodeAccAddresses;
|
|
190
292
|
exports.getArxNodeAccInfo = getArxNodeAccInfo;
|
|
191
|
-
exports.
|
|
293
|
+
exports.getClusterAccAddresses = getClusterAccAddresses;
|
|
192
294
|
exports.getClusterAccInfo = getClusterAccInfo;
|
|
193
|
-
exports.
|
|
194
|
-
exports.
|
|
295
|
+
exports.getCompDefAccInfo = getCompDefAccInfo;
|
|
296
|
+
exports.getComputationAccInfo = getComputationAccInfo;
|
|
195
297
|
exports.getComputationOffset = getComputationOffset;
|
|
196
298
|
exports.getComputationsInMempool = getComputationsInMempool;
|
|
299
|
+
exports.getMXEAccAddresses = getMXEAccAddresses;
|
|
197
300
|
exports.getMXEAccInfo = getMXEAccInfo;
|
|
198
|
-
exports.getMXEAccs = getMXEAccs;
|
|
199
301
|
exports.subscribeComputations = subscribeComputations;
|
|
200
302
|
exports.unsubscribeComputations = unsubscribeComputations;
|
package/build/index.d.ts
CHANGED
|
@@ -1,41 +1,130 @@
|
|
|
1
1
|
import { ArciumIdlType } from '@arcium-hq/client';
|
|
2
|
-
export { getArciumProgramReadonly,
|
|
2
|
+
export { getArciumProgramReadonly, getArxNodeAccAddress, getClockAccAddress, getClusterAccAddress, getCompDefAccAddress, getComputationAccAddress, getExecutingPoolAccAddress, getMXEAccAddress, getMempoolAccAddress, getStakingPoolAccAddress } from '@arcium-hq/client';
|
|
3
3
|
import * as anchor from '@coral-xyz/anchor';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Shared type aliases and utility types for the Arcium program.
|
|
7
|
+
* Many types are derived from the Anchor-generated IDL and are used throughout the reader package.
|
|
8
|
+
*/
|
|
9
|
+
|
|
5
10
|
type PublicKey = anchor.web3.PublicKey;
|
|
6
11
|
type Connection = anchor.web3.Connection;
|
|
7
12
|
type Program<T extends anchor.Idl> = anchor.Program<T>;
|
|
8
13
|
type ArciumTypes = anchor.IdlTypes<ArciumIdlType>;
|
|
14
|
+
/**
|
|
15
|
+
* All events emitted by the Arcium program, keyed by event name.
|
|
16
|
+
*/
|
|
9
17
|
type ArciumEvent = anchor.IdlEvents<ArciumIdlType>;
|
|
18
|
+
/**
|
|
19
|
+
* Capitalized event names, matching the format as emitted by the program.
|
|
20
|
+
*/
|
|
10
21
|
type ArciumEventName = Capitalize<keyof ArciumEvent>;
|
|
22
|
+
/**
|
|
23
|
+
* Data structure for any Arcium event, as parsed from logs.
|
|
24
|
+
*/
|
|
11
25
|
type ArciumEventData = ArciumEvent[keyof ArciumEvent];
|
|
12
|
-
type MXEAccount = ArciumTypes['
|
|
26
|
+
type MXEAccount = ArciumTypes['mxeAccount'];
|
|
13
27
|
type ClusterAccount = ArciumTypes['cluster'];
|
|
14
28
|
type ArxNodeAccount = ArciumTypes['arxNode'];
|
|
15
|
-
type
|
|
29
|
+
type ComputationAccount = ArciumTypes['computationAccount'];
|
|
16
30
|
type ComputationReference = ArciumTypes['computationReference'];
|
|
17
|
-
type
|
|
18
|
-
type
|
|
19
|
-
type
|
|
31
|
+
type ComputationDefinitionAccount = ArciumTypes['computationDefinitionAccount'];
|
|
32
|
+
type QueueComputationIx = ArciumIdlType['instructions']['23'];
|
|
33
|
+
type CallbackComputationIx = ArciumIdlType['instructions']['3'];
|
|
34
|
+
type FinalizeComputationIx = ArciumIdlType['instructions']['8'];
|
|
35
|
+
/**
|
|
36
|
+
* Status values for a computation, as defined by the Arcium protocol.
|
|
37
|
+
*/
|
|
20
38
|
type ComputationStatus = 'queued' | 'executing' | 'executed' | 'finalized' | 'failed';
|
|
21
39
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Returns all MXE account addresses.
|
|
42
|
+
* @param conn - The Solana connection object.
|
|
43
|
+
* @returns Array of MXE account public keys.
|
|
44
|
+
*/
|
|
45
|
+
declare function getMXEAccAddresses(conn: Connection): Promise<PublicKey[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Returns all Cluster account addresses.
|
|
48
|
+
* @param conn - The Solana connection object.
|
|
49
|
+
* @returns Array of Cluster account public keys.
|
|
50
|
+
*/
|
|
51
|
+
declare function getClusterAccAddresses(conn: Connection): Promise<PublicKey[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Returns all ArxNode account addresses.
|
|
54
|
+
* @param conn - The Solana connection object.
|
|
55
|
+
* @returns Array of ArxNode account public keys.
|
|
56
|
+
*/
|
|
57
|
+
declare function getArxNodeAccAddresses(conn: Connection): Promise<PublicKey[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Fetches and parses a given MXE account.
|
|
60
|
+
* @param arciumProgram - The Anchor program instance.
|
|
61
|
+
* @param address - The public key of the MXE account.
|
|
62
|
+
* @param commitment - (Optional) RPC commitment level.
|
|
63
|
+
* @returns The MXEAccount object.
|
|
64
|
+
*/
|
|
25
65
|
declare function getMXEAccInfo(arciumProgram: anchor.Program<ArciumIdlType>, address: PublicKey, commitment?: anchor.web3.Commitment): Promise<MXEAccount>;
|
|
66
|
+
/**
|
|
67
|
+
* Fetches and parses a given Cluster account.
|
|
68
|
+
* @param arciumProgram - The Anchor program instance.
|
|
69
|
+
* @param address - The public key of the Cluster account.
|
|
70
|
+
* @param commitment - (Optional) RPC commitment level.
|
|
71
|
+
* @returns The ClusterAccount object.
|
|
72
|
+
*/
|
|
26
73
|
declare function getClusterAccInfo(arciumProgram: anchor.Program<ArciumIdlType>, address: PublicKey, commitment?: anchor.web3.Commitment): Promise<ClusterAccount>;
|
|
74
|
+
/**
|
|
75
|
+
* Fetches and parses a given ArxNode account.
|
|
76
|
+
* @param arciumProgram - The Anchor program instance.
|
|
77
|
+
* @param address - The public key of the ArxNode account.
|
|
78
|
+
* @param commitment - (Optional) RPC commitment level.
|
|
79
|
+
* @returns The ArxNodeAccount object.
|
|
80
|
+
*/
|
|
27
81
|
declare function getArxNodeAccInfo(arciumProgram: anchor.Program<ArciumIdlType>, address: PublicKey, commitment?: anchor.web3.Commitment): Promise<ArxNodeAccount>;
|
|
82
|
+
/**
|
|
83
|
+
* Fetches and parses a given ComputationDefinition account.
|
|
84
|
+
* @param arciumProgram - The Anchor program instance.
|
|
85
|
+
* @param address - The public key of the ComputationDefinition account.
|
|
86
|
+
* @param commitment - (Optional) RPC commitment level.
|
|
87
|
+
* @returns The ComputationDefinitionAccount object.
|
|
88
|
+
*/
|
|
89
|
+
declare function getCompDefAccInfo(arciumProgram: anchor.Program<ArciumIdlType>, address: PublicKey, commitment?: anchor.web3.Commitment): Promise<ComputationDefinitionAccount>;
|
|
90
|
+
/**
|
|
91
|
+
* Returns all computation references in the mempool for a given account.
|
|
92
|
+
* Only non-stake computations are included.
|
|
93
|
+
* @param arciumProgram - The Anchor program instance.
|
|
94
|
+
* @param address - The public key of the mempool account.
|
|
95
|
+
* @returns Array of ComputationReference objects.
|
|
96
|
+
*/
|
|
28
97
|
declare function getComputationsInMempool(arciumProgram: anchor.Program<ArciumIdlType>, address: PublicKey): Promise<ComputationReference[]>;
|
|
29
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Fetches and parses a given Computation account.
|
|
100
|
+
* @param arciumProgram - The Anchor program instance.
|
|
101
|
+
* @param address - The public key of the Computation account.
|
|
102
|
+
* @param commitment - (Optional) RPC commitment level.
|
|
103
|
+
* @returns The Computation object.
|
|
104
|
+
*/
|
|
105
|
+
declare function getComputationAccInfo(arciumProgram: anchor.Program<ArciumIdlType>, address: PublicKey, commitment?: anchor.web3.Commitment): Promise<ComputationAccount>;
|
|
30
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Subscribes to computation-related events for a given MXE program ID.
|
|
109
|
+
* @param conn - The Solana connection object.
|
|
110
|
+
* @param mxeProgramId - The public key of the MXE program.
|
|
111
|
+
* @param callback - Callback function to handle each computation event and its name.
|
|
112
|
+
* @returns The subscription ID for the logs listener.
|
|
113
|
+
*/
|
|
31
114
|
declare function subscribeComputations(conn: Connection, mxeProgramId: PublicKey, callback: (event: ArciumEventData, name: ArciumEventName) => void): Promise<number>;
|
|
115
|
+
/**
|
|
116
|
+
* Unsubscribes from computation-related events using the subscription ID.
|
|
117
|
+
* @param conn - The Solana connection object.
|
|
118
|
+
* @param subscriptionId - The subscription ID returned by subscribeComputations.
|
|
119
|
+
*/
|
|
32
120
|
declare function unsubscribeComputations(conn: Connection, subscriptionId: number): Promise<void>;
|
|
33
121
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @param tx - The transaction to get the computation offset from
|
|
36
|
-
* @returns The computation offset if one is found, otherwise
|
|
37
|
-
* @throws Error if multiple computation offsets are found in the transaction
|
|
122
|
+
* Gets the computation offset from a transaction.
|
|
123
|
+
* @param tx - The transaction to get the computation offset from.
|
|
124
|
+
* @returns The computation offset if one is found, otherwise undefined.
|
|
125
|
+
* @throws Error if multiple computation offsets are found in the transaction.
|
|
38
126
|
*/
|
|
39
127
|
declare function getComputationOffset(tx: anchor.web3.VersionedTransactionResponse): anchor.BN | undefined;
|
|
40
128
|
|
|
41
|
-
export {
|
|
129
|
+
export { getArxNodeAccAddresses, getArxNodeAccInfo, getClusterAccAddresses, getClusterAccInfo, getCompDefAccInfo, getComputationAccInfo, getComputationOffset, getComputationsInMempool, getMXEAccAddresses, getMXEAccInfo, subscribeComputations, unsubscribeComputations };
|
|
130
|
+
export type { ArciumEvent, ArciumEventData, ArciumEventName, ArciumTypes, ArxNodeAccount, CallbackComputationIx, ClusterAccount, ComputationAccount, ComputationDefinitionAccount, ComputationReference, ComputationStatus, Connection, FinalizeComputationIx, MXEAccount, Program, PublicKey, QueueComputationIx };
|
package/build/index.mjs
CHANGED
|
@@ -1,37 +1,104 @@
|
|
|
1
1
|
import { ARCIUM_IDL, getMempoolAccData } from '@arcium-hq/client';
|
|
2
|
-
export { getArciumProgramReadonly,
|
|
2
|
+
export { getArciumProgramReadonly, getArxNodeAccAddress, getClockAccAddress, getClusterAccAddress, getCompDefAccAddress, getComputationAccAddress, getExecutingPoolAccAddress, getMXEAccAddress, getMempoolAccAddress, getStakingPoolAccAddress } from '@arcium-hq/client';
|
|
3
3
|
import * as anchor from '@coral-xyz/anchor';
|
|
4
4
|
|
|
5
5
|
const ARCIUM_PROGRAM_ID_STRING = 'BKck65TgoKRokMjQM3datB9oRwJ8rAj2jxPXvHXUvcL6';
|
|
6
|
+
/**
|
|
7
|
+
* Discriminator for the ArxNode account type. Used to filter and identify ArxNode accounts on-chain.
|
|
8
|
+
*/
|
|
6
9
|
const ARX_NODE_ACC_DISCRIMINATOR = [2, 207, 122, 223, 93, 97, 231, 199];
|
|
10
|
+
/**
|
|
11
|
+
* Discriminator for the Cluster account type. Used to filter and identify Cluster accounts on-chain.
|
|
12
|
+
*/
|
|
7
13
|
const CLUSTER_ACC_DISCRIMINATOR = [236, 225, 118, 228, 173, 106, 18, 60];
|
|
8
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Discriminator for the MXE account type. Used to filter and identify MXE accounts on-chain.
|
|
16
|
+
*/
|
|
17
|
+
const MXE_ACC_DISCRIMINATOR = [103, 26, 85, 250, 179, 159, 17, 117];
|
|
18
|
+
/**
|
|
19
|
+
* The public key of the deployed Arcium program on Solana.
|
|
20
|
+
*/
|
|
9
21
|
const ARCIUM_PROGRAM_ID = new anchor.web3.PublicKey(ARCIUM_PROGRAM_ID_STRING);
|
|
22
|
+
/**
|
|
23
|
+
* Anchor coder for encoding and decoding Arcium program instructions.
|
|
24
|
+
*/
|
|
10
25
|
new anchor.BorshInstructionCoder(ARCIUM_IDL);
|
|
26
|
+
/**
|
|
27
|
+
* Anchor event parser for parsing Arcium program events from transaction logs.
|
|
28
|
+
*/
|
|
11
29
|
const ARCIUM_EVENT_CODER = new anchor.EventParser(ARCIUM_PROGRAM_ID, new anchor.BorshCoder(ARCIUM_IDL));
|
|
12
30
|
|
|
13
|
-
|
|
14
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Returns all MXE account addresses.
|
|
33
|
+
* @param conn - The Solana connection object.
|
|
34
|
+
* @returns Array of MXE account public keys.
|
|
35
|
+
*/
|
|
36
|
+
async function getMXEAccAddresses(conn) {
|
|
15
37
|
return getArciumAccPubkeys(conn, MXE_ACC_DISCRIMINATOR);
|
|
16
38
|
}
|
|
17
|
-
|
|
18
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Returns all Cluster account addresses.
|
|
41
|
+
* @param conn - The Solana connection object.
|
|
42
|
+
* @returns Array of Cluster account public keys.
|
|
43
|
+
*/
|
|
44
|
+
async function getClusterAccAddresses(conn) {
|
|
19
45
|
return getArciumAccPubkeys(conn, CLUSTER_ACC_DISCRIMINATOR);
|
|
20
46
|
}
|
|
21
|
-
|
|
22
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Returns all ArxNode account addresses.
|
|
49
|
+
* @param conn - The Solana connection object.
|
|
50
|
+
* @returns Array of ArxNode account public keys.
|
|
51
|
+
*/
|
|
52
|
+
async function getArxNodeAccAddresses(conn) {
|
|
23
53
|
return getArciumAccPubkeys(conn, ARX_NODE_ACC_DISCRIMINATOR);
|
|
24
54
|
}
|
|
25
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Fetches and parses a given MXE account.
|
|
57
|
+
* @param arciumProgram - The Anchor program instance.
|
|
58
|
+
* @param address - The public key of the MXE account.
|
|
59
|
+
* @param commitment - (Optional) RPC commitment level.
|
|
60
|
+
* @returns The MXEAccount object.
|
|
61
|
+
*/
|
|
26
62
|
async function getMXEAccInfo(arciumProgram, address, commitment) {
|
|
27
|
-
return arciumProgram.account.
|
|
63
|
+
return arciumProgram.account.mxeAccount.fetch(address, commitment);
|
|
28
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Fetches and parses a given Cluster account.
|
|
67
|
+
* @param arciumProgram - The Anchor program instance.
|
|
68
|
+
* @param address - The public key of the Cluster account.
|
|
69
|
+
* @param commitment - (Optional) RPC commitment level.
|
|
70
|
+
* @returns The ClusterAccount object.
|
|
71
|
+
*/
|
|
29
72
|
async function getClusterAccInfo(arciumProgram, address, commitment) {
|
|
30
73
|
return arciumProgram.account.cluster.fetch(address, commitment);
|
|
31
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Fetches and parses a given ArxNode account.
|
|
77
|
+
* @param arciumProgram - The Anchor program instance.
|
|
78
|
+
* @param address - The public key of the ArxNode account.
|
|
79
|
+
* @param commitment - (Optional) RPC commitment level.
|
|
80
|
+
* @returns The ArxNodeAccount object.
|
|
81
|
+
*/
|
|
32
82
|
async function getArxNodeAccInfo(arciumProgram, address, commitment) {
|
|
33
83
|
return arciumProgram.account.arxNode.fetch(address, commitment);
|
|
34
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Fetches and parses a given ComputationDefinition account.
|
|
87
|
+
* @param arciumProgram - The Anchor program instance.
|
|
88
|
+
* @param address - The public key of the ComputationDefinition account.
|
|
89
|
+
* @param commitment - (Optional) RPC commitment level.
|
|
90
|
+
* @returns The ComputationDefinitionAccount object.
|
|
91
|
+
*/
|
|
92
|
+
async function getCompDefAccInfo(arciumProgram, address, commitment) {
|
|
93
|
+
return arciumProgram.account.computationDefinitionAccount.fetch(address, commitment);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Returns all computation references in the mempool for a given account.
|
|
97
|
+
* Only non-stake computations are included.
|
|
98
|
+
* @param arciumProgram - The Anchor program instance.
|
|
99
|
+
* @param address - The public key of the mempool account.
|
|
100
|
+
* @returns Array of ComputationReference objects.
|
|
101
|
+
*/
|
|
35
102
|
async function getComputationsInMempool(arciumProgram, address) {
|
|
36
103
|
const mempool = await getMempoolAccData(arciumProgram.provider, address);
|
|
37
104
|
const startIndex = mempool.inner.computations.startIndex;
|
|
@@ -55,27 +122,40 @@ async function getComputationsInMempool(arciumProgram, address) {
|
|
|
55
122
|
refs.push(...elems[idx].entries);
|
|
56
123
|
}
|
|
57
124
|
}
|
|
58
|
-
return refs
|
|
125
|
+
return refs
|
|
126
|
+
.flat()
|
|
127
|
+
.filter((ref) => !isNullRef(ref));
|
|
59
128
|
}
|
|
60
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Fetches and parses a given Computation account.
|
|
131
|
+
* @param arciumProgram - The Anchor program instance.
|
|
132
|
+
* @param address - The public key of the Computation account.
|
|
133
|
+
* @param commitment - (Optional) RPC commitment level.
|
|
134
|
+
* @returns The Computation object.
|
|
135
|
+
*/
|
|
136
|
+
async function getComputationAccInfo(arciumProgram, address, commitment) {
|
|
61
137
|
return arciumProgram.account.computationAccount.fetch(address, commitment);
|
|
62
138
|
}
|
|
63
139
|
async function getArciumAccPubkeys(conn, discriminator) {
|
|
64
140
|
const accs = await conn.getProgramAccounts(ARCIUM_PROGRAM_ID, {
|
|
65
141
|
dataSlice: { offset: 0, length: 0 },
|
|
66
|
-
filters: [
|
|
142
|
+
filters: [
|
|
143
|
+
{
|
|
67
144
|
memcmp: {
|
|
68
145
|
offset: 0,
|
|
69
146
|
encoding: 'base64',
|
|
70
147
|
bytes: Buffer.from(discriminator).toString('base64'),
|
|
71
148
|
},
|
|
72
|
-
}
|
|
149
|
+
},
|
|
150
|
+
],
|
|
73
151
|
});
|
|
74
152
|
return accs.map((acc) => acc.pubkey);
|
|
75
153
|
}
|
|
76
154
|
function isNullRef(ref) {
|
|
77
155
|
const bigZero = new anchor.BN(0);
|
|
78
|
-
return ref.computationDefinitionOffset === 0
|
|
156
|
+
return (ref.computationDefinitionOffset === 0
|
|
157
|
+
&& ref.computationOffset === bigZero
|
|
158
|
+
&& ref.priorityFee === bigZero);
|
|
79
159
|
}
|
|
80
160
|
|
|
81
161
|
const ArciumEventNames = [
|
|
@@ -84,6 +164,13 @@ const ArciumEventNames = [
|
|
|
84
164
|
'CallbackComputationEvent',
|
|
85
165
|
'FinalizeComputationEvent',
|
|
86
166
|
];
|
|
167
|
+
/**
|
|
168
|
+
* Subscribes to computation-related events for a given MXE program ID.
|
|
169
|
+
* @param conn - The Solana connection object.
|
|
170
|
+
* @param mxeProgramId - The public key of the MXE program.
|
|
171
|
+
* @param callback - Callback function to handle each computation event and its name.
|
|
172
|
+
* @returns The subscription ID for the logs listener.
|
|
173
|
+
*/
|
|
87
174
|
async function subscribeComputations(conn, mxeProgramId, callback) {
|
|
88
175
|
return conn.onLogs(mxeProgramId, (logs) => {
|
|
89
176
|
const events = getComputationEventsFromLogs(logs.logs);
|
|
@@ -92,14 +179,19 @@ async function subscribeComputations(conn, mxeProgramId, callback) {
|
|
|
92
179
|
}
|
|
93
180
|
});
|
|
94
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Unsubscribes from computation-related events using the subscription ID.
|
|
184
|
+
* @param conn - The Solana connection object.
|
|
185
|
+
* @param subscriptionId - The subscription ID returned by subscribeComputations.
|
|
186
|
+
*/
|
|
95
187
|
async function unsubscribeComputations(conn, subscriptionId) {
|
|
96
188
|
conn.removeOnLogsListener(subscriptionId);
|
|
97
189
|
}
|
|
98
190
|
/**
|
|
99
|
-
*
|
|
100
|
-
* @param tx - The transaction to get the computation offset from
|
|
101
|
-
* @returns The computation offset if one is found, otherwise
|
|
102
|
-
* @throws Error if multiple computation offsets are found in the transaction
|
|
191
|
+
* Gets the computation offset from a transaction.
|
|
192
|
+
* @param tx - The transaction to get the computation offset from.
|
|
193
|
+
* @returns The computation offset if one is found, otherwise undefined.
|
|
194
|
+
* @throws Error if multiple computation offsets are found in the transaction.
|
|
103
195
|
*/
|
|
104
196
|
function getComputationOffset(tx) {
|
|
105
197
|
const events = getComputationEventsFromLogs(tx.meta?.logMessages ?? []);
|
|
@@ -108,7 +200,7 @@ function getComputationOffset(tx) {
|
|
|
108
200
|
}
|
|
109
201
|
const computationOffsets = events.map((e) => e.event.computationOffset);
|
|
110
202
|
const computationOffset = computationOffsets[0];
|
|
111
|
-
if (computationOffsets.some((offset) => offset
|
|
203
|
+
if (computationOffsets.some((offset) => !offset.eq(computationOffset))) {
|
|
112
204
|
throw new Error(`Multiple computation offsets found in computation: ${JSON.stringify(computationOffsets)}`);
|
|
113
205
|
}
|
|
114
206
|
return computationOffset;
|
|
@@ -121,10 +213,19 @@ function getComputationOffset(tx) {
|
|
|
121
213
|
function getComputationEventsFromLogs(logs) {
|
|
122
214
|
return Array.from(ARCIUM_EVENT_CODER.parseLogs(logs))
|
|
123
215
|
.filter((e) => ArciumEventNames.includes(e.name))
|
|
124
|
-
.map((e) =>
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
216
|
+
.map((e) => {
|
|
217
|
+
const eventData = {
|
|
218
|
+
computationOffset: e.data.computation_offset,
|
|
219
|
+
...e.data,
|
|
220
|
+
};
|
|
221
|
+
if (e.data.mxe_program_id) {
|
|
222
|
+
eventData.mxeProgramId = e.data.mxe_program_id;
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
event: eventData,
|
|
226
|
+
name: e.name,
|
|
227
|
+
};
|
|
228
|
+
});
|
|
128
229
|
}
|
|
129
230
|
|
|
130
|
-
export { getArxNodeAccInfo,
|
|
231
|
+
export { getArxNodeAccAddresses, getArxNodeAccInfo, getClusterAccAddresses, getClusterAccInfo, getCompDefAccInfo, getComputationAccInfo, getComputationOffset, getComputationsInMempool, getMXEAccAddresses, getMXEAccInfo, subscribeComputations, unsubscribeComputations };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcium-hq/reader",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Reader SDK for fetching onchain data for Arcium network programs",
|
|
5
5
|
"author": "Arcium",
|
|
6
6
|
"license": "GPL-3.0-only",
|
|
@@ -41,24 +41,26 @@
|
|
|
41
41
|
"@types/bn.js": "^5.1.6",
|
|
42
42
|
"@types/chai": "^5.0.0",
|
|
43
43
|
"@types/mocha": "^10.0.9",
|
|
44
|
+
"@types/node": "^22.10.2",
|
|
44
45
|
"@types/snarkjs": "^0.7.8",
|
|
45
|
-
"@typescript-eslint/eslint-plugin": "
|
|
46
|
-
"@typescript-eslint/parser": "
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^8.15.0",
|
|
47
|
+
"@typescript-eslint/parser": "^8.15.0",
|
|
47
48
|
"chai": "^5.1.2",
|
|
48
|
-
"eslint": "
|
|
49
|
-
"eslint-config-airbnb-base": "15.0.0",
|
|
50
|
-
"eslint-plugin-import": "2.
|
|
49
|
+
"eslint": "^9.15.0",
|
|
50
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
51
|
+
"eslint-plugin-import": "^2.31.0",
|
|
51
52
|
"mocha": "^10.8.2",
|
|
52
53
|
"rollup": "^4.24.0",
|
|
53
54
|
"rollup-plugin-dts": "^6.1.1",
|
|
54
55
|
"ts-node": "^10.9.2",
|
|
55
|
-
"typescript": "^
|
|
56
|
+
"typescript": "^5.6.3",
|
|
57
|
+
"typescript-eslint": "^8.15.0"
|
|
56
58
|
},
|
|
57
59
|
"dependencies": {
|
|
58
60
|
"@coral-xyz/anchor": "^0.31.1",
|
|
59
61
|
"@noble/curves": "^1.8.1",
|
|
60
62
|
"@noble/hashes": "^1.7.1",
|
|
61
|
-
"@arcium-hq/client": "0.
|
|
63
|
+
"@arcium-hq/client": "0.2.0"
|
|
62
64
|
},
|
|
63
65
|
"keywords": [
|
|
64
66
|
"Cryptography",
|