arc-sdk-test 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,360 @@
1
+ import { PublicKey, Keypair, Connection, TransactionInstruction, Transaction } from '@solana/web3.js';
2
+ import { OracleJob } from '@switchboard-xyz/common';
3
+ import { Program } from '@coral-xyz/anchor';
4
+ import { Wallet } from '@coral-xyz/anchor/dist/cjs/provider';
5
+
6
+ type IndexerAsset = string | {
7
+ mint?: string;
8
+ asset?: string;
9
+ } | null;
10
+
11
+ /** Frontend wallet adapter or backend {@link Keypair}. */
12
+ type EncryptKeyWallet = Keypair | {
13
+ signMessage: (message: Uint8Array) => Promise<Uint8Array> | Uint8Array;
14
+ };
15
+ type BuildDepositTxParams = {
16
+ senderPublicKey: PublicKey | string;
17
+ /** Supported token mint address for the active cluster (native SOL or SPL mint). */
18
+ tokenMint: PublicKey | string;
19
+ depositAmount: number | string;
20
+ onChainBackup?: boolean;
21
+ computeUnitPrice?: number;
22
+ };
23
+ type FetchWalletBalanceOptions = {
24
+ includeDeposits?: boolean;
25
+ indexerAsset?: IndexerAsset;
26
+ };
27
+ type BuildRelayPayloadParams = {
28
+ args: unknown[];
29
+ proofHex: string;
30
+ denomination: number | bigint | string;
31
+ withdrawAddress: unknown;
32
+ relayerPubkey: unknown;
33
+ mint?: unknown;
34
+ };
35
+ type RelayPayload = Record<string, unknown>;
36
+
37
+ type DepositParams = {
38
+ nullifier: string;
39
+ secret: string;
40
+ amount: string;
41
+ commitment: string;
42
+ nullifierHash: string;
43
+ mint: string | null;
44
+ };
45
+ type GenerateDepositParamsResult = {
46
+ params: DepositParams;
47
+ note: string;
48
+ };
49
+ type GenerateWithdrawProofOptions = {
50
+ /** Override WASM path/URL (required when the SDK is bundled for the browser). */
51
+ circuitWasmPath?: string;
52
+ /** Override zkey path/URL (required when the SDK is bundled for the browser). */
53
+ circuitZkeyPath?: string;
54
+ };
55
+
56
+ type Network = "mainnet" | "devnet";
57
+ declare const MAINNET_TOKEN_MINTS: {
58
+ readonly Arcane: "3jSL5nnnYcRLmTqFmwvY1Mikh42fQsT7p7NvXPYzanon";
59
+ readonly Bitcoin: "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh";
60
+ readonly Ethereum: "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs";
61
+ readonly USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
62
+ };
63
+ type TokenSymbol = keyof typeof MAINNET_TOKEN_MINTS;
64
+ declare const TOKEN_DECIMALS: {
65
+ readonly Solana: 9;
66
+ readonly Arcane: 9;
67
+ readonly Ethereum: 8;
68
+ readonly Bitcoin: 8;
69
+ readonly USDC: 6;
70
+ };
71
+ type TokenDecimalsSymbol = keyof typeof TOKEN_DECIMALS;
72
+ /** Supported deposit denominations per token (same on mainnet and devnet). */
73
+ declare const DEPOSIT_AMOUNTS: {
74
+ readonly Solana: readonly [0.1, 1, 5, 10, 50, 100, 500];
75
+ readonly Arcane: readonly [1, 10, 50, 100, 500, 1000, 10000, 100000, 1000000];
76
+ readonly Bitcoin: readonly [0.01, 0.05, 0.1, 0.5, 1, 5];
77
+ readonly Ethereum: readonly [0.1, 1, 10, 50, 100, 500];
78
+ readonly USDC: readonly [1, 10, 50, 100, 1000, 10000, 100000, 1000000];
79
+ };
80
+ type DepositTokenSymbol = keyof typeof DEPOSIT_AMOUNTS;
81
+
82
+ type Relayer = {
83
+ isValid: true;
84
+ label: string;
85
+ url: string;
86
+ key: number;
87
+ value: string;
88
+ fee: unknown;
89
+ recentActivities: unknown;
90
+ userPubkey: unknown;
91
+ workers: unknown;
92
+ totalFeeEarningsSol: unknown;
93
+ totalWithdrawCount: unknown;
94
+ stakedAmount: unknown;
95
+ volume24hSol: unknown;
96
+ volume7dSol: unknown;
97
+ };
98
+
99
+ interface ArcaneSdkInitOptions {
100
+ /** Range API key (frontend: VITE_RANGE_API_KEY). */
101
+ rangeApiKey: string;
102
+ /** Wallet for Anchor provider transactions. */
103
+ wallet: Wallet;
104
+ /**
105
+ * Solana JSON-RPC endpoint (Node/scripts). Omit when passing {@link connection}
106
+ * from `@solana/wallet-adapter-react` (`useConnection()`).
107
+ */
108
+ rpcEndpoint?: string;
109
+ /** Existing connection (e.g. `useConnection()` in React). */
110
+ connection?: Connection;
111
+ /**
112
+ * Cluster override when the RPC URL does not contain `devnet` / `mainnet` hints
113
+ * (common with private RPC providers).
114
+ */
115
+ network?: Network;
116
+ }
117
+ interface ArcaneSdkRuntimeConfig {
118
+ rangeApiKey: string;
119
+ rpcEndpoint: string;
120
+ /** Cluster inferred from {@link rpcEndpoint}. */
121
+ network: Network;
122
+ programId: string;
123
+ /** Active relayers for {@link network}, loaded at SDK initialization. */
124
+ relayers: Relayer[];
125
+ connection: Connection;
126
+ wallet: Wallet;
127
+ program: Program;
128
+ /** Set by {@link ArcaneSDK.getEncryptionKey}; required for on-chain note backup. */
129
+ encryptKey?: Uint8Array;
130
+ }
131
+
132
+ /** Withdraw circuit artifact filenames (published under `arc-sdk-test/circuits/`). */
133
+ declare const WITHDRAW_CIRCUIT_WASM = "withdraw.wasm";
134
+ declare const WITHDRAW_CIRCUIT_ZKEY = "withdraw.zkey";
135
+ type CircuitPaths = {
136
+ wasm: string;
137
+ zkey: string;
138
+ };
139
+
140
+ type WithdrawParams = {
141
+ /** Secret note from the original deposit. */
142
+ note: string;
143
+ /** Withdrawal recipient public key. */
144
+ recipient: PublicKey | string;
145
+ };
146
+ type WithdrawResult = {
147
+ txHash: string;
148
+ jobId: string;
149
+ relayer: Relayer;
150
+ };
151
+
152
+ type QuoteRelayer = {
153
+ url: string;
154
+ [key: string]: unknown;
155
+ };
156
+ type QuoteTransaction = Record<string, unknown>;
157
+ type QuoteSplit = {
158
+ denomination: number;
159
+ totalRelayerFee: number;
160
+ relayer: QuoteRelayer;
161
+ transaction: QuoteTransaction;
162
+ };
163
+ type Quote = {
164
+ amount: number;
165
+ transactionCount: number;
166
+ recipientAmount: number;
167
+ totalRelayerFee: number;
168
+ etaSeconds: number;
169
+ splits: QuoteSplit[];
170
+ platformFee?: number;
171
+ };
172
+ type GetQuoteResponse = {
173
+ success: boolean;
174
+ quote: Quote;
175
+ };
176
+ type GetQuoteParams = {
177
+ amount: number | string;
178
+ amountLamports: number | string | bigint;
179
+ recipient: PublicKey | string;
180
+ /** Indexer asset label (default `SOL`). */
181
+ asset?: string;
182
+ /** Cluster for the quote (default active SDK network). */
183
+ network?: Network;
184
+ };
185
+ /** Fetch a withdraw quote from the indexer. Requires SDK init or an active instance context. */
186
+ declare function getQuote(params: GetQuoteParams): Promise<GetQuoteResponse>;
187
+
188
+ type ResolvedNoteAsset = {
189
+ key: string;
190
+ tokenName: TokenDecimalsSymbol;
191
+ unit: string;
192
+ multiplier: bigint;
193
+ mint: string | null;
194
+ poolAmounts: readonly number[];
195
+ decimals: number;
196
+ };
197
+
198
+ type ArcaneTransferItem = {
199
+ mint: PublicKey;
200
+ /** Human-readable token amount (e.g. `"1.5"` SOL). */
201
+ amount: string;
202
+ recipient: PublicKey;
203
+ };
204
+ type ArcaneTransferDepositFailure = {
205
+ amount: string;
206
+ mint: string;
207
+ recipient: string;
208
+ };
209
+ type ArcaneTransferWithdrawFailure = {
210
+ note: string;
211
+ recipient: string;
212
+ };
213
+ type ArcaneTransferResult = {
214
+ error: boolean;
215
+ depositFailed: ArcaneTransferDepositFailure[];
216
+ withdrawFailed: ArcaneTransferWithdrawFailure[];
217
+ };
218
+
219
+ /**
220
+ * Arcane SDK client. Create one instance per configuration (network, RPC, API keys).
221
+ *
222
+ * @example
223
+ * ```js
224
+ * const { ArcaneSDK } = require('arc-sdk-test');
225
+ * const sdk = await ArcaneSDK.create({
226
+ * rangeApiKey: process.env.RANGE_API_KEY,
227
+ * rpcEndpoint: 'https://api.devnet.solana.com',
228
+ * wallet,
229
+ * });
230
+ * console.log(sdk.config.relayers);
231
+ * ```
232
+ *
233
+ * @example React (wallet-adapter)
234
+ * ```tsx
235
+ * import { useArcaneSdk } from 'arc-sdk-test/react';
236
+ *
237
+ * function MyComponent() {
238
+ * const sdk = useArcaneSdk({ rangeApiKey: import.meta.env.VITE_RANGE_API_KEY });
239
+ * if (!sdk) return null;
240
+ * // ...
241
+ * }
242
+ * ```
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * import { ArcaneSDK } from 'arc-sdk-test';
247
+ * const sdk = await ArcaneSDK.create({ rangeApiKey, rpcEndpoint, wallet });
248
+ * await sdk.getEncryptionKey(wallet);
249
+ * await sdk.buildDepositTx({ senderPublicKey: wallet.publicKey, tokenMint: NATIVE_MINT, depositAmount: 1, onChainBackup: true });
250
+ * ```
251
+ */
252
+ declare class ArcaneSDK {
253
+ static readonly VERSION = "0.0.1";
254
+ readonly config: ArcaneSdkRuntimeConfig;
255
+ private constructor();
256
+ /** Create an SDK instance (loads relayers for the inferred network). */
257
+ static create(options: ArcaneSdkInitOptions): Promise<ArcaneSDK>;
258
+ private run;
259
+ private runAsync;
260
+ getConfig(): ArcaneSdkRuntimeConfig;
261
+ getRangeApiKey(): string;
262
+ getRpcEndpoint(): string;
263
+ getNetwork(): Network;
264
+ getProgramIdString(): string;
265
+ /** Encryption key derived by {@link getEncryptionKey}; undefined until set. */
266
+ get encryptKey(): Uint8Array | undefined;
267
+ /** Relayers loaded at initialization; use {@link fetchRelayers} to refresh. */
268
+ get relayers(): Relayer[];
269
+ getIndexerUrl(): string;
270
+ getRiskApiUrl(): string;
271
+ getTokenMints(): {
272
+ Solana: string;
273
+ Arcane: "3jSL5nnnYcRLmTqFmwvY1Mikh42fQsT7p7NvXPYzanon" | "ARCxcL6oX2pd4bKmUxhdoARaaHdKU6TJrTTthPANPQtQ";
274
+ Bitcoin: "" | "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh";
275
+ Ethereum: "" | "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs";
276
+ USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" | "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU";
277
+ };
278
+ getArcaneTokenMint(): string;
279
+ getTokenMint(symbol: TokenSymbol): string;
280
+ getDepositAmounts(symbol: DepositTokenSymbol): readonly number[];
281
+ getTokenDecimals(symbol: TokenDecimalsSymbol): number;
282
+ resolveCircuitPaths(base?: string): CircuitPaths;
283
+ getRangeRiskScoreJob(address: string): OracleJob;
284
+ getOracleQuote(payer: Keypair | PublicKey, addressToCheck: string): Promise<{
285
+ queueAccount: PublicKey;
286
+ sigVerifyIx: TransactionInstruction;
287
+ }>;
288
+ getProgramId(): PublicKey;
289
+ getPoolPDA(denominationLamports: number | bigint): [PublicKey, number];
290
+ getTokenPoolPDA(mint: PublicKey | string, denominationSmallestUnits: number | bigint): [PublicKey, number];
291
+ getTreasuryPDA(): [PublicKey, number];
292
+ getCommitmentPDA(commitmentBigInt: bigint | number | string): [PublicKey, number];
293
+ getNullifierPDA(nullifierHashBigInt: bigint | number | string): [PublicKey, number];
294
+ getNetworkStatePDA(): [PublicKey, number];
295
+ buildDepositTx(params: BuildDepositTxParams): Promise<{
296
+ tx: Transaction;
297
+ note: string;
298
+ }>;
299
+ /**
300
+ * Withdraw to `recipient` using a secret `note`.
301
+ * Relayer is chosen at random from {@link config.relayers}.
302
+ */
303
+ withdraw(params: WithdrawParams): Promise<WithdrawResult>;
304
+ /**
305
+ * Private transfer: deposit into the pool (split by supported denominations),
306
+ * then withdraw each successful note to the recipient.
307
+ *
308
+ * Requires {@link getEncryptionKey} before calling (deposits use on-chain backup).
309
+ */
310
+ arcaneTransfer(items: ArcaneTransferItem[]): Promise<ArcaneTransferResult>;
311
+ /** Validate a withdraw recipient against the risk API. */
312
+ assertWithdrawRecipientAllowed(address: string): Promise<void>;
313
+ /** Resolve the token asset encoded in a secret note. */
314
+ resolveNoteAsset(amount: string, mint?: string | null, tokenNameHint?: TokenDecimalsSymbol): ResolvedNoteAsset;
315
+ fetchPlatformFee(): Promise<string>;
316
+ /** Fetch a withdraw quote from the indexer. */
317
+ getQuote(params: GetQuoteParams): Promise<GetQuoteResponse>;
318
+ fetchCommitments(denomination: number | bigint | string, indexerAsset?: IndexerAsset): Promise<unknown>;
319
+ validateNullifier(nullifierHash: string, indexerAsset?: IndexerAsset): Promise<unknown>;
320
+ fetchTxStatus(commitmentHex: string, nullifierHashHex: string, indexerAsset?: IndexerAsset): Promise<unknown>;
321
+ fetchDepositCountByCommitment(commitment: string, denomination: number | bigint | string, indexerAsset?: IndexerAsset): Promise<unknown>;
322
+ fetchWalletBalance(wallet: string, options?: FetchWalletBalanceOptions): Promise<unknown>;
323
+ /** Re-fetch relayers from the indexer and update {@link config.relayers}. */
324
+ fetchRelayers(): Promise<Relayer[]>;
325
+ fetchLatestTransactions(type?: string, indexerAsset?: IndexerAsset): Promise<unknown>;
326
+ fetchTxCounts(type?: string, indexerAsset?: IndexerAsset): Promise<unknown>;
327
+ normalizePubkeyString(value: unknown): string;
328
+ buildRelayPayload(params: BuildRelayPayloadParams): RelayPayload;
329
+ submitToRelayer(relayerUrl: string, payload: RelayPayload): Promise<unknown>;
330
+ pollRelayerJob(relayerUrl: string, jobId: string, maxWaitMs?: number): Promise<unknown>;
331
+ /**
332
+ * Derives the note encryption key from a wallet signature and stores it on
333
+ * {@link config.encryptKey}. Required before {@link buildDepositTx} with
334
+ * `onChainBackup: true`.
335
+ *
336
+ * Accepts a frontend wallet adapter (`signMessage`) or a backend {@link Keypair}.
337
+ */
338
+ getEncryptionKey(wallet: EncryptKeyWallet): Promise<Uint8Array>;
339
+ encryptData(key: Uint8Array, plaintext: string): Uint8Array<ArrayBufferLike>;
340
+ decryptData(key: Uint8Array, combined: Uint8Array): string;
341
+ generateRandomFieldElement(): bigint;
342
+ createCommitment(nullifier: bigint | number | string, secret: bigint | number | string): bigint;
343
+ createNullifierHash(nullifier: bigint | number | string): bigint;
344
+ generateDepositParams(amountLamports: bigint | number | string, mint?: string | null): GenerateDepositParamsResult;
345
+ parseSecretNote(note: string): Record<string, string>;
346
+ publicKeyToFieldElement(publicKeyBytes: Uint8Array | number[]): bigint;
347
+ amountToFieldElement(amount: bigint | number | string): bigint;
348
+ generateMerkleProof(depositParams: Record<string, unknown>, leaves: unknown[]): unknown;
349
+ generateWithdrawProof(depositParams: Record<string, unknown>, leaves: unknown[], recipient: PublicKey | string, relayer: PublicKey | string, fee: bigint | number | string, refund: bigint | number | string, options?: GenerateWithdrawProofOptions): Promise<unknown>;
350
+ convertProofToBytes(proof: unknown): Promise<number[] | Uint8Array<ArrayBufferLike>>;
351
+ to32ByteBuffer(bigInt: bigint | number | string): Uint8Array<ArrayBufferLike>;
352
+ toFixedHex(value: bigint | number | string, length?: number): string;
353
+ toFieldElementHex(value: bigint | number | string): string;
354
+ formatNoteForDisplay(note: string, segmentLen?: number): string;
355
+ appendIndexerAsset(params: URLSearchParams, indexerAsset?: IndexerAsset): void;
356
+ /** Program ID for a cluster without an SDK instance. */
357
+ static getProgramIdForNetwork(network: Network): string;
358
+ }
359
+
360
+ export { ArcaneSDK as A, type BuildDepositTxParams as B, type CircuitPaths as C, type DepositTokenSymbol as D, type EncryptKeyWallet as E, type FetchWalletBalanceOptions as F, type GenerateDepositParamsResult as G, type IndexerAsset as I, type Network as N, type Quote as Q, type RelayPayload as R, type TokenDecimalsSymbol as T, WITHDRAW_CIRCUIT_WASM as W, type ArcaneSdkInitOptions as a, type ArcaneSdkRuntimeConfig as b, type ArcaneTransferDepositFailure as c, type ArcaneTransferItem as d, type ArcaneTransferResult as e, type ArcaneTransferWithdrawFailure as f, type BuildRelayPayloadParams as g, type GenerateWithdrawProofOptions as h, type GetQuoteParams as i, type GetQuoteResponse as j, type QuoteRelayer as k, type QuoteSplit as l, type QuoteTransaction as m, type Relayer as n, type ResolvedNoteAsset as o, type TokenSymbol as p, WITHDRAW_CIRCUIT_ZKEY as q, type WithdrawParams as r, type WithdrawResult as s, getQuote as t };