@audren-xyz/sdk 0.0.0-stage → 1.3.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.
@@ -0,0 +1,13 @@
1
+ export * from './constants.js';
2
+ export * from './poseidon.js';
3
+ export * from './crypto.js';
4
+ export * from './pda.js';
5
+ export * from './keys.js';
6
+ export * from './layout.js';
7
+ export * from './store.js';
8
+ export * from './scanner.js';
9
+ export * from './swap.js';
10
+ export * from './relayer.js';
11
+ export * from './instructions.js';
12
+ export * from './token2022.js';
13
+ export * from './tx-v1.js';
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ export * from './constants.js';
2
+ export * from './poseidon.js';
3
+ export * from './crypto.js';
4
+ export * from './pda.js';
5
+ export * from './keys.js';
6
+ export * from './layout.js';
7
+ export * from './store.js';
8
+ export * from './scanner.js';
9
+ export * from './swap.js';
10
+ export * from './relayer.js';
11
+ export * from './instructions.js';
12
+ export * from './token2022.js';
13
+ export * from './tx-v1.js';
@@ -0,0 +1,398 @@
1
+ /**
2
+ * Builders for all 9 Audren v1 instructions (`0x00..=0x08`) and exact SHA-256 `ctx_hash`
3
+ * transcripts matching `crates/client/src/instructions.rs` and `program/src/lib.rs` bit-for-bit.
4
+ */
5
+ import { type RouterAccountMeta } from './swap.js';
6
+ export interface AudrenInstruction {
7
+ programId: string;
8
+ accounts: RouterAccountMeta[];
9
+ data: Uint8Array;
10
+ }
11
+ export interface EscrowTokenLeg {
12
+ mint: string;
13
+ vaultAta?: string;
14
+ escrowAta?: string;
15
+ tokenProgram?: string;
16
+ }
17
+ export type UpdatePoolAction = {
18
+ kind: 'params';
19
+ noteRentFee: bigint;
20
+ nfRentFee: bigint;
21
+ } | {
22
+ kind: 'proposeAuthority';
23
+ pendingAuthority: string | Uint8Array;
24
+ } | {
25
+ kind: 'acceptAuthority';
26
+ } | {
27
+ kind: 'renounceAuthority';
28
+ };
29
+ /** Deterministic per-note `LaneRentVault` fee matching `deterministic_note_rent_fee` on-chain. */
30
+ export declare function deterministicNoteRentFee(poolNoteRentFeeCap: bigint, subRent: bigint, srRent: bigint, memoRent: bigint): bigint;
31
+ export interface PageRolloverPlan {
32
+ outSubSeq: number;
33
+ outRootSeq: number;
34
+ outMemoSeq: number;
35
+ nfPageSeq: number;
36
+ nextSubSeq?: number;
37
+ nextRootSeq?: number;
38
+ nextMemoSeq?: number;
39
+ nextNfSeq?: number;
40
+ }
41
+ /**
42
+ * Compute primary page sequences and atomic rollover page sequences matching
43
+ * `append_leaf_and_memo` and `append_nullifier_prefix` in `program/src/lib.rs` byte-for-byte.
44
+ */
45
+ export declare function computePageRollovers(params: {
46
+ leafCount: bigint | number;
47
+ outputCount: number;
48
+ nfCount: bigint | number;
49
+ spentNullifiers: number;
50
+ }): PageRolloverPlan;
51
+ /** Auto-`OpenPage` proactive pre-open thresholds (`>= 90%` full, matching on-chain `OpenPage` bounds). */
52
+ export declare const AUTO_OPEN_SUBTREE_REM_THRESHOLD = 26;
53
+ export declare const AUTO_OPEN_MEMO_REM_THRESHOLD = 10;
54
+ export declare const AUTO_OPEN_NF_REM_THRESHOLD = 60;
55
+ export declare const AUTO_OPEN_SUBROOT_SLOT_THRESHOLD = 280;
56
+ export interface AutoOpenPageTarget {
57
+ pageKind: number;
58
+ pageSeq: bigint;
59
+ pda: string;
60
+ /** `true` for mandatory rollover pages required by the tx; `false` for proactive `>= 90%` lookaheads (pass `maxPayerDeficit: 0n`). */
61
+ mandatory: boolean;
62
+ }
63
+ /**
64
+ * Zero-crank Auto-`OpenPage` planner: returns every idempotent `OpenPage` (`Tag 2`) target
65
+ * required for a lane when it is at an exact rollover boundary (`mandatory: true`) OR `>= 90%` full
66
+ * (`mandatory: false`: `subRem <= 26`, `memoRem <= 10`, `nfRem <= 60`, `subrootSlot >= 280`) and
67
+ * the target page PDA is not present in `existingPages`.
68
+ */
69
+ export declare function planAutoOpenPages(params: {
70
+ programId?: string;
71
+ poolId?: number;
72
+ laneId: number;
73
+ nextLeaf: bigint | number;
74
+ nfCount: bigint | number;
75
+ numOutputs: number;
76
+ numNfs: number;
77
+ existingPages?: ReadonlySet<string> | ReadonlyArray<string>;
78
+ }): AutoOpenPageTarget[];
79
+ /**
80
+ * Build idempotent `OpenPage` (`Tag 2`) pre-instructions returned by `planAutoOpenPages` so
81
+ * wallets and relayers keep lanes provisioned with zero external cranking.
82
+ *
83
+ * Proactive (`!mandatory`) lookahead instructions ALWAYS set `maxPayerDeficit = 0n` so
84
+ * `LaneRentVault` bears 100% of rent and TOCTOU drains revert cleanly instead of debiting `payer`.
85
+ * Pass `includeProactive: false` when `LaneRentVault` is known to be underfunded.
86
+ */
87
+ export declare function buildAutoOpenPageInstructions(params: {
88
+ programId?: string;
89
+ payer: string;
90
+ poolId: number;
91
+ laneId: number;
92
+ nextLeaf: bigint | number;
93
+ nfCount: bigint | number;
94
+ numOutputs: number;
95
+ numNfs: number;
96
+ existingPages?: ReadonlySet<string> | ReadonlyArray<string>;
97
+ includeProactive?: boolean;
98
+ mandatoryMaxPayerDeficit?: bigint;
99
+ }): AudrenInstruction[];
100
+ /** Convert an `AudrenInstruction` (base58 pubkeys) into a binary `V1Instruction` for `compileV1Message`. */
101
+ export declare function toV1Instruction(ix: AudrenInstruction): {
102
+ programId: Uint8Array;
103
+ accounts: {
104
+ pubkey: Uint8Array;
105
+ isSigner: boolean;
106
+ isWritable: boolean;
107
+ }[];
108
+ data: Uint8Array;
109
+ };
110
+ /** Compute Unit cost per failed `find_program_address` bump iteration on Solana (`1,500` CU). */
111
+ export declare const CU_PER_PDA_BUMP_ITERATION = 1500;
112
+ /**
113
+ * Compute extra Compute Unit headroom for non-255 PDA bumps (`sum((255 - bump) * 1_500)`),
114
+ * validating every bump is a `u8` integer in `0..=255` and capping safely at `1,400,000` CU.
115
+ */
116
+ export declare function computeBumpCuMargin(bumps: readonly number[]): number;
117
+ /** Recommended tight Compute Unit limit for standalone or batched `OpenPage` (`Tag 2`) instructions. */
118
+ export declare function recommendedOpenPageCuLimit(params?: {
119
+ openPageCount?: number;
120
+ bumps?: readonly number[];
121
+ }): number;
122
+ /** Recommended tight Compute Unit limit for `Deposit` (`Tag 3`) plus any prepended `OpenPage` / ATA setup instructions. */
123
+ export declare function recommendedDepositCuLimit(params?: {
124
+ hasTransferHook?: boolean;
125
+ openPageCount?: number;
126
+ createAtaCount?: number;
127
+ createToken2022AtaCount?: number;
128
+ bumps?: readonly number[];
129
+ }): number;
130
+ /** Recommended tight Compute Unit limit for `Transact` (`Tag 5`) plus any prepended `OpenPage` / ATA setup instructions. */
131
+ export declare function recommendedTransactCuLimit(params: {
132
+ assetMode: number;
133
+ outputMask?: number;
134
+ hasTransferHook?: boolean;
135
+ openPageCount?: number;
136
+ createAtaCount?: number;
137
+ createToken2022AtaCount?: number;
138
+ bumps?: readonly number[];
139
+ }): number;
140
+ /** Recommended tight Compute Unit limit for `ExecViaEscrow` (`Tag 6`) plus router CU, optional Token-2022 leg headroom, and any prepended `OpenPage` / ATA setup instructions. */
141
+ export declare function recommendedExecViaEscrowCuLimit(params?: {
142
+ routerCuLimit?: number;
143
+ hasToken2022Leg?: boolean;
144
+ openPageCount?: number;
145
+ createAtaCount?: number;
146
+ createToken2022AtaCount?: number;
147
+ bumps?: readonly number[];
148
+ }): number;
149
+ /**
150
+ * Build a canonical SPL Associated Token Account `CreateIdempotent` (`data = [1]`) instruction
151
+ * supporting both Classic SPL Token and SPL Token-2022 mints.
152
+ */
153
+ export declare function buildCreateAtaIdempotentInstruction(params: {
154
+ payer: string;
155
+ ata: string;
156
+ owner: string;
157
+ mint: string;
158
+ tokenProgram?: string;
159
+ }): AudrenInstruction;
160
+ /** Exact `Transact` (`Tag 5`) `ctx_hash` matching `program/src/lib.rs` bit-for-bit (binds `vkId`). */
161
+ export declare function computeTransactCtxHash(params: {
162
+ programId?: string;
163
+ poolId: number;
164
+ vkId?: number;
165
+ outLaneId: number;
166
+ outputMask: number;
167
+ assetMode: number;
168
+ unwrapWsol: boolean;
169
+ recipient?: string | Uint8Array | null;
170
+ relayerFeeRecipient?: string | Uint8Array | null;
171
+ publicAssetId: Uint8Array;
172
+ publicAmountOut: bigint;
173
+ relayerFeeAmount: bigint;
174
+ memosBytes: Uint8Array;
175
+ }): bigint;
176
+ /** Exact `router_accounts` hash matching `hash_router_accounts_arena` in `program/src/lib.rs`. */
177
+ export declare function computeRouterAccountsHash(routerAccounts: readonly RouterAccountMeta[]): Uint8Array;
178
+ /**
179
+ * Exact `ExecViaEscrow` (`Tag 6`) `ctx_hash` matching `program/src/lib.rs` bit-for-bit
180
+ * (binds `vkId`, SPL/Token-2022 only, `72 B` `dynMemoMask`).
181
+ *
182
+ * Applies Solana's transaction-wide writability promotion across `escrowPda`,
183
+ * `relayerFeeRecipient`, `extraWritablePubkeys`, and duplicate writable `routerAccounts`
184
+ * before hashing `router_accounts` so PDA/duplicate accounts match on-chain `AccountView::is_writable()`.
185
+ */
186
+ export declare function computeExecCtxHash(params: {
187
+ programId?: string;
188
+ poolId: number;
189
+ vkId?: number;
190
+ outLaneId: number;
191
+ escrowShard: number;
192
+ changeMask: number;
193
+ feeOnOutput: boolean;
194
+ assetIn: Uint8Array;
195
+ amountIn: bigint;
196
+ relayerFeeAmount: bigint;
197
+ relayerFeeRecipient?: string | Uint8Array | null;
198
+ assetOut: Uint8Array;
199
+ minAmountOut: bigint;
200
+ routerProg: string | Uint8Array;
201
+ routerAccounts: readonly RouterAccountMeta[];
202
+ /** Optional writable instruction accounts promoted onto `routerAccounts` matching `buildExecViaEscrowInstruction` & Solana runtime writability merge. */
203
+ payer?: string | Uint8Array | null;
204
+ escrowInAta?: string | Uint8Array | null;
205
+ escrowOutAta?: string | Uint8Array | null;
206
+ vaultInAta?: string | Uint8Array | null;
207
+ vaultOutAta?: string | Uint8Array | null;
208
+ extraWritablePubkeys?: readonly (string | Uint8Array)[];
209
+ outStealthOwner: Uint8Array;
210
+ outBlinding: Uint8Array;
211
+ dynMemoHead: Uint8Array;
212
+ dynMemoMask: Uint8Array;
213
+ routerIxData: Uint8Array;
214
+ changeMemos: Uint8Array;
215
+ }): bigint;
216
+ /** Tag 0: `InitPool` (4 accounts including `GlobalRootHistory`, 29 B). */
217
+ export declare function buildInitPoolInstruction(params: {
218
+ programId?: string;
219
+ payer: string;
220
+ poolId: number;
221
+ rootEpochInterval?: bigint;
222
+ noteRentFee: bigint;
223
+ nfRentFee: bigint;
224
+ }): AudrenInstruction;
225
+ /** Tag 1: `InitLane` (9 accounts, 6 B). */
226
+ export declare function buildInitLaneInstruction(params: {
227
+ programId?: string;
228
+ authority: string;
229
+ poolId: number;
230
+ laneId: number;
231
+ }): AudrenInstruction;
232
+ /** Tag 2: `OpenPage` (6 accounts, 23 B). */
233
+ export declare function buildOpenPageInstruction(params: {
234
+ programId?: string;
235
+ payer: string;
236
+ pageKind: number;
237
+ poolId: number;
238
+ laneId: number;
239
+ pageSeq: bigint;
240
+ /** Maximum lamports `payer` consents to cover if `LaneRentVault` cannot cover full page rent (default `0n` fail-closed, matching UniFFI Swift/Kotlin; pass an explicit budget or `U64_MAX` for mandatory rollovers). */
241
+ maxPayerDeficit?: bigint;
242
+ }): AudrenInstruction;
243
+ /**
244
+ * Tag 3: Unified `Deposit` (14 fixed accounts with writable `GlobalRootHistory` at `[2]` +
245
+ * optional rollover + optional hook accounts, 185 B).
246
+ *
247
+ * - Set `nativeSol: true` to deposit Native SOL atomically via `SyncNative` into the pool's
248
+ * canonical WSOL `vault_auth` ATA (`mint` defaults to `WSOL_MINT`, `sourceAccount` defaults to
249
+ * `depositor`, `tokenProgram` defaults to `CLASSIC_TOKEN_PROGRAM_ID`, `feeFromAmount` optional).
250
+ * - Omit `nativeSol` (or `false`) for Classic SPL / Token-2022 deposits (`mint` and `sourceAccount`
251
+ * required; `vaultAta` auto-derives the canonical `vault_auth` ATA when omitted).
252
+ */
253
+ export declare function buildDepositInstruction(params: {
254
+ programId?: string;
255
+ depositor: string;
256
+ poolId: number;
257
+ laneId: number;
258
+ subPageSeq: bigint;
259
+ rootPageSeq: bigint;
260
+ memoPageSeq: bigint;
261
+ nativeSol?: boolean;
262
+ feeFromAmount?: boolean;
263
+ mint?: string;
264
+ sourceAccount?: string;
265
+ vaultAta?: string;
266
+ tokenProgram?: string;
267
+ rollover?: {
268
+ nextSubSeq?: bigint | null;
269
+ nextMemoSeq?: bigint | null;
270
+ };
271
+ amount: bigint;
272
+ stealthOwner: bigint | Uint8Array;
273
+ blinding: bigint | Uint8Array;
274
+ memo: Uint8Array;
275
+ hookAccounts?: readonly RouterAccountMeta[];
276
+ }): AudrenInstruction;
277
+ /** Tag 4: `InitRootHistory` (`4 + activeLanes` accounts, 13 B). */
278
+ export declare function buildInitRootHistoryInstruction(params: {
279
+ programId?: string;
280
+ authority: string;
281
+ poolId: number;
282
+ rootEpochInterval?: bigint;
283
+ activeLanes: number;
284
+ }): AudrenInstruction;
285
+ /**
286
+ * Tag 5: `Transact` (`380 + num_outputs * 106 B`).
287
+ * Supports `ASSET_MODE_PRIVATE` (0) and `ASSET_MODE_PUBLIC` (1, including `unwrapWsol: true`
288
+ * atomic WSOL -> Native SOL unwrapping and pause-exempt full exits with read-only `roots`).
289
+ */
290
+ export declare function buildTransactInstruction(params: {
291
+ programId?: string;
292
+ payer: string;
293
+ poolId: number;
294
+ vkId?: number;
295
+ rootRingKind: number;
296
+ rootRingIdx: number;
297
+ outLaneId: number;
298
+ outSubSeq: bigint;
299
+ outRootSeq: bigint;
300
+ outMemoSeq: bigint;
301
+ outNfSeq: bigint;
302
+ outputMask: number;
303
+ assetMode: number;
304
+ unwrapWsol?: boolean;
305
+ publicOutflow?: {
306
+ mint: string;
307
+ vaultAta?: string;
308
+ tokenProgram?: string;
309
+ } | null;
310
+ rollover?: {
311
+ nextSubSeq?: bigint | null;
312
+ nextMemoSeq?: bigint | null;
313
+ nextNfSeq?: bigint | null;
314
+ };
315
+ proof192: Uint8Array;
316
+ nf0: Uint8Array;
317
+ nf1: Uint8Array;
318
+ cm0: Uint8Array;
319
+ cm1: Uint8Array;
320
+ cm2: Uint8Array;
321
+ publicAmountOut: bigint;
322
+ relayerFeeAmount: bigint;
323
+ recipient?: string;
324
+ relayerFeeRecipient?: string;
325
+ memosBytes: Uint8Array;
326
+ hookAccounts?: readonly RouterAccountMeta[];
327
+ }): AudrenInstruction;
328
+ /**
329
+ * Tag 6: `ExecViaEscrow` (`560 + routerIxData.length + num_changes * 106 B`, SPL/Token-2022 only).
330
+ */
331
+ export declare function buildExecViaEscrowInstruction(params: {
332
+ programId?: string;
333
+ payer: string;
334
+ poolId: number;
335
+ vkId?: number;
336
+ rootRingKind: number;
337
+ rootRingIdx: number;
338
+ outLaneId: number;
339
+ outSubSeq: bigint;
340
+ outRootSeq: bigint;
341
+ outMemoSeq: bigint;
342
+ outNfSeq: bigint;
343
+ escrowShard: number;
344
+ changeMask: number;
345
+ feeOnOutput?: boolean;
346
+ inLeg: EscrowTokenLeg;
347
+ outLeg: EscrowTokenLeg;
348
+ relayerFeeAmount: bigint;
349
+ relayerFeeRecipient?: string | null;
350
+ rollover?: {
351
+ nextSubSeq?: bigint | null;
352
+ nextMemoSeq?: bigint | null;
353
+ nextNfSeq?: bigint | null;
354
+ };
355
+ proof192: Uint8Array;
356
+ nf0: Uint8Array;
357
+ nf1: Uint8Array;
358
+ cm0: Uint8Array;
359
+ cm1: Uint8Array;
360
+ cm2: Uint8Array;
361
+ amountIn: bigint;
362
+ minAmountOut: bigint;
363
+ outStealthOwner: Uint8Array;
364
+ outBlinding: Uint8Array;
365
+ dynMemoHead: Uint8Array;
366
+ dynMemoMask: Uint8Array;
367
+ routerProg: string;
368
+ routerIxData: Uint8Array;
369
+ routerAccounts: readonly RouterAccountMeta[];
370
+ extraWritablePubkeys?: readonly string[];
371
+ changeMemos: Uint8Array;
372
+ }): AudrenInstruction;
373
+ /** Tag 7: `SetPaused` (2 accounts, 6 B). */
374
+ export declare function buildSetPausedInstruction(params: {
375
+ programId?: string;
376
+ authority: string;
377
+ poolId: number;
378
+ paused: boolean;
379
+ }): AudrenInstruction;
380
+ /**
381
+ * Tag 8: `UpdatePool` (2 accounts: `signer(s)`, `pool(w)`).
382
+ * Sub-actions: `params` (22 B: `noteRentFee` + `nfRentFee`), `proposeAuthority` (38 B),
383
+ * `acceptAuthority` (6 B), `renounceAuthority` (6 B, requires `!paused`).
384
+ */
385
+ export declare function buildUpdatePoolInstruction(params: {
386
+ programId?: string;
387
+ signer: string;
388
+ poolId: number;
389
+ action: UpdatePoolAction;
390
+ }): AudrenInstruction;
391
+ /** Tag 8 convenience builder for `UPDATE_POOL_PARAMS` (`22 B`: `noteRentFee`, `nfRentFee`). */
392
+ export declare function buildUpdatePoolParamsInstruction(params: {
393
+ programId?: string;
394
+ authority: string;
395
+ poolId: number;
396
+ noteRentFee: bigint;
397
+ nfRentFee: bigint;
398
+ }): AudrenInstruction;