@hadron-fi/sdk 0.1.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.
@@ -0,0 +1,676 @@
1
+ import { PublicKey, Connection, TransactionInstruction } from '@solana/web3.js';
2
+
3
+ declare enum PoolState {
4
+ Uninitialized = 0,
5
+ Initialized = 1,
6
+ Paused = 2,
7
+ WithdrawOnly = 3
8
+ }
9
+ declare enum OracleMode {
10
+ /** Off-chain authority updates the oracle */
11
+ Authority = 0,
12
+ /** Midprice computed from vault ratio (vault_y / vault_x) */
13
+ Relative = 1
14
+ }
15
+ declare enum Interpolation {
16
+ Step = 0,
17
+ Linear = 1,
18
+ MarginalStep = 2,
19
+ Hyperbolic = 3,
20
+ Quadratic = 4,
21
+ Cubic = 5
22
+ }
23
+ declare enum CurveType {
24
+ PriceBid = 0,
25
+ PriceAsk = 1,
26
+ RiskBid = 2,
27
+ RiskAsk = 3
28
+ }
29
+ declare enum CurveXMode {
30
+ /** Price: absolute tokens. Risk: percent Q32. */
31
+ Native = 0,
32
+ /** Price: percent of vault Q32. Risk: absolute tokens. */
33
+ Alternate = 1
34
+ }
35
+ declare enum RiskMode {
36
+ Virtual = 0,
37
+ Integrated = 1
38
+ }
39
+ declare enum CurveUpdateOpKind {
40
+ Edit = 0,
41
+ Add = 1,
42
+ Remove = 2
43
+ }
44
+ declare enum Side {
45
+ Bid = 0,
46
+ Ask = 1
47
+ }
48
+ interface DecodedConfig {
49
+ state: PoolState;
50
+ seed: bigint;
51
+ authority: PublicKey;
52
+ mintX: PublicKey;
53
+ mintY: PublicKey;
54
+ configBump: number;
55
+ curveMeta: PublicKey;
56
+ spreadConfigInitialized: boolean;
57
+ deltaStaleness: number;
58
+ oracleMode: OracleMode;
59
+ pendingAuthority: PublicKey;
60
+ nominationExpiry: bigint;
61
+ tokenProgramX: PublicKey;
62
+ tokenProgramY: PublicKey;
63
+ }
64
+ interface DecodedMidpriceOracle {
65
+ authority: PublicKey;
66
+ sequence: bigint;
67
+ midpriceQ32: bigint;
68
+ baseSpreadQ32: bigint;
69
+ lastUpdateSlot: bigint;
70
+ }
71
+ interface DecodedCurveMeta {
72
+ authority: PublicKey;
73
+ activePriceBidSlot: number;
74
+ activePriceAskSlot: number;
75
+ activeRiskBidSlot: number;
76
+ activeRiskAskSlot: number;
77
+ initializedSlots: Uint8Array;
78
+ maxPrefabSlots: number;
79
+ maxCurvePoints: number;
80
+ }
81
+ interface DecodedFeeConfig {
82
+ initialized: boolean;
83
+ feePpm: number;
84
+ bump: number;
85
+ feeAdmin: PublicKey;
86
+ feeRecipient: PublicKey;
87
+ }
88
+ interface DecodedCurveUpdates {
89
+ authority: PublicKey;
90
+ curveMeta: PublicKey;
91
+ numOps: number;
92
+ ops: CurveUpdateOp[];
93
+ }
94
+ interface CurvePoint {
95
+ xIn: bigint;
96
+ priceFactorQ32: bigint;
97
+ interpolation: Interpolation;
98
+ params: Uint8Array;
99
+ }
100
+ interface CurveSide {
101
+ numPoints: number;
102
+ defaultInterpolation: Interpolation;
103
+ xMode: CurveXMode;
104
+ riskMode: RiskMode;
105
+ points: CurvePoint[];
106
+ }
107
+ interface CurveUpdateOp {
108
+ curveType: CurveType;
109
+ opKind: CurveUpdateOpKind;
110
+ pointIndex: number;
111
+ interpolation: Interpolation;
112
+ xIn: bigint;
113
+ priceFactorQ32: bigint;
114
+ params: Uint8Array;
115
+ }
116
+ interface InitializeParams {
117
+ /** Pool seed. If omitted, a random seed is generated automatically. */
118
+ seed?: bigint;
119
+ mintX: PublicKey;
120
+ mintY: PublicKey;
121
+ authority: PublicKey;
122
+ initialMidpriceQ32: bigint;
123
+ oracleMode?: OracleMode;
124
+ maxPrefabSlots?: number;
125
+ maxCurvePoints?: number;
126
+ /** Token program for mint X (defaults to TOKEN_PROGRAM_ID) */
127
+ tokenProgramX?: PublicKey;
128
+ /** Token program for mint Y (defaults to TOKEN_PROGRAM_ID) */
129
+ tokenProgramY?: PublicKey;
130
+ }
131
+ interface DepositParams {
132
+ amountX: bigint;
133
+ amountY: bigint;
134
+ expiration?: number;
135
+ }
136
+ interface WithdrawParams {
137
+ amountX: bigint;
138
+ amountY: bigint;
139
+ expiration?: number;
140
+ }
141
+ interface SwapParams {
142
+ isX: boolean;
143
+ amountIn: bigint;
144
+ minOut: bigint;
145
+ feeRecipient: PublicKey;
146
+ expiration?: number;
147
+ }
148
+ interface SetCurvePointInput {
149
+ xIn: bigint;
150
+ /** Price factor as floating point (e.g. 0.99). Converted to Q32 internally. */
151
+ priceFactor: number;
152
+ interpolation?: Interpolation;
153
+ params?: Uint8Array;
154
+ }
155
+ interface SetCurveParams {
156
+ side: Side;
157
+ defaultInterpolation: Interpolation;
158
+ points: SetCurvePointInput[];
159
+ slot?: number;
160
+ xMode?: CurveXMode;
161
+ }
162
+ /** Params for setting price curve on both bid and ask in one call (returns two instructions). */
163
+ interface SetCurveBothParams {
164
+ bid: Omit<SetCurveParams, "side">;
165
+ ask: Omit<SetCurveParams, "side">;
166
+ }
167
+ interface SetRiskCurvePointInput {
168
+ /** Percent of base vault (0.0 to 1.0) — converted to Q32 internally */
169
+ pctBase: number;
170
+ /** Price factor as floating point */
171
+ priceFactor: number;
172
+ interpolation?: Interpolation;
173
+ params?: Uint8Array;
174
+ }
175
+ interface SetRiskCurveAbsolutePointInput {
176
+ /** Absolute vault balance in token atoms */
177
+ vaultBalance: bigint;
178
+ priceFactor: number;
179
+ interpolation?: Interpolation;
180
+ params?: Uint8Array;
181
+ }
182
+ interface SetRiskCurveParams {
183
+ side: Side;
184
+ defaultInterpolation: Interpolation;
185
+ points: SetRiskCurvePointInput[];
186
+ slot?: number;
187
+ xMode?: CurveXMode;
188
+ riskMode?: RiskMode;
189
+ }
190
+ /** Params for setting risk curve (percent x-axis) on both bid and ask in one call. */
191
+ interface SetRiskCurveBothParams {
192
+ bid: Omit<SetRiskCurveParams, "side">;
193
+ ask: Omit<SetRiskCurveParams, "side">;
194
+ }
195
+ interface SetRiskCurveAbsoluteParams {
196
+ side: Side;
197
+ defaultInterpolation: Interpolation;
198
+ points: SetRiskCurveAbsolutePointInput[];
199
+ slot?: number;
200
+ riskMode?: RiskMode;
201
+ }
202
+ /** Params for setting risk curve (absolute x-axis) on both bid and ask in one call. */
203
+ interface SetRiskCurveAbsoluteBothParams {
204
+ bid: Omit<SetRiskCurveAbsoluteParams, "side">;
205
+ ask: Omit<SetRiskCurveAbsoluteParams, "side">;
206
+ }
207
+ interface UpdateMidpriceParams {
208
+ midpriceQ32: bigint;
209
+ sequence?: bigint;
210
+ }
211
+ interface UpdateBaseSpreadParams {
212
+ baseSpreadQ32: bigint;
213
+ sequence?: bigint;
214
+ }
215
+ interface UpdateMidpriceAndBaseSpreadParams {
216
+ midpriceQ32: bigint;
217
+ baseSpreadQ32: bigint;
218
+ sequence?: bigint;
219
+ }
220
+ interface SwitchCurveParams {
221
+ side: Side;
222
+ slot: number;
223
+ }
224
+ interface NominateAuthorityParams {
225
+ newAuthority: PublicKey;
226
+ expirySlot: bigint;
227
+ }
228
+ interface SetQuotingAuthorityParams {
229
+ newQuotingAuthority: PublicKey;
230
+ /** If provided, also updates SpreadConfig.admin */
231
+ spreadConfigPda?: PublicKey;
232
+ }
233
+ interface InitializeFeeConfigParams {
234
+ feePpm: number;
235
+ feeAdmin: PublicKey;
236
+ feeRecipient: PublicKey;
237
+ }
238
+ interface UpdateFeeConfigParams {
239
+ /** Pass null for no change (sends u32::MAX) */
240
+ feePpm: number | null;
241
+ /** Pass null for no change (sends zeros) */
242
+ feeRecipient: PublicKey | null;
243
+ }
244
+ interface RotateFeeAdminParams {
245
+ newFeeAdmin: PublicKey;
246
+ }
247
+ interface SetPoolStateParams {
248
+ newState: PoolState;
249
+ }
250
+ interface UpdateDeltaStalenessParams {
251
+ deltaStaleness: number;
252
+ }
253
+ interface InitializeSpreadConfigParams {
254
+ admin: PublicKey;
255
+ }
256
+ interface SpreadTriggerInput {
257
+ account: PublicKey;
258
+ spreadBps: number;
259
+ }
260
+ interface UpdateSpreadConfigParams {
261
+ triggers: SpreadTriggerInput[];
262
+ }
263
+ interface AllocateCurvePrefabsParams {
264
+ seed: bigint;
265
+ mintX: PublicKey;
266
+ mintY: PublicKey;
267
+ maxPrefabSlots?: number;
268
+ maxCurvePoints?: number;
269
+ }
270
+ interface PoolAddresses {
271
+ config: PublicKey;
272
+ configBump: number;
273
+ midpriceOracle: PublicKey;
274
+ curveMeta: PublicKey;
275
+ curvePrefabs: PublicKey;
276
+ curveUpdates: PublicKey;
277
+ vaultX: PublicKey;
278
+ vaultY: PublicKey;
279
+ }
280
+
281
+ /**
282
+ * Main SDK class for interacting with a Hadron pool.
283
+ *
284
+ * Usage:
285
+ * ```ts
286
+ * const pool = await Hadron.load(connection, poolAddress);
287
+ * const midprice = pool.getMidprice();
288
+ * const ix = pool.swap(user, params);
289
+ * ```
290
+ */
291
+ declare class Hadron {
292
+ readonly programId: PublicKey;
293
+ readonly poolAddress: PublicKey;
294
+ readonly addresses: PoolAddresses;
295
+ config: DecodedConfig;
296
+ oracle: DecodedMidpriceOracle;
297
+ curveMeta: DecodedCurveMeta;
298
+ curvePrefabsData: Uint8Array;
299
+ private connection;
300
+ constructor(connection: Connection, poolAddress: PublicKey, addresses: PoolAddresses, config: DecodedConfig, oracle: DecodedMidpriceOracle, curveMeta: DecodedCurveMeta, curvePrefabsData: Uint8Array, programId?: PublicKey);
301
+ /**
302
+ * Load a Hadron instance from an existing pool address.
303
+ * Fetches all required accounts from the chain.
304
+ */
305
+ static load(connection: Connection, poolAddress: PublicKey): Promise<Hadron>;
306
+ /**
307
+ * Load a Hadron instance from pool identity (seed + mints).
308
+ */
309
+ static loadFromSeed(connection: Connection, seed: bigint, mintX: PublicKey, mintY: PublicKey): Promise<Hadron>;
310
+ /**
311
+ * Build all instructions needed to initialize a new pool.
312
+ *
313
+ * Returns the allocate + initialize instructions and the derived pool address.
314
+ * The caller is responsible for grouping them into transactions and sending.
315
+ * The allocate instruction(s) must be confirmed before the initialize instruction.
316
+ *
317
+ * After the pool is live on-chain, load it with `Hadron.load(connection, poolAddress)`.
318
+ *
319
+ * ```ts
320
+ * const { instructions, poolAddress, seed } = Hadron.initialize(payer, {
321
+ * mintX,
322
+ * mintY,
323
+ * authority: payer,
324
+ * initialMidpriceQ32: Q32_ONE,
325
+ * });
326
+ * ```
327
+ */
328
+ static initialize(payer: PublicKey, params: InitializeParams): {
329
+ instructions: TransactionInstruction[];
330
+ poolAddress: PublicKey;
331
+ seed: bigint;
332
+ };
333
+ /** Generate a random u64 seed. */
334
+ private static randomSeed;
335
+ /** Re-fetch all account state from the chain. */
336
+ refetchStates(): Promise<void>;
337
+ /** Get midprice as a floating-point number. */
338
+ getMidprice(): number;
339
+ /** Get base spread as a floating-point number. */
340
+ getBaseSpread(): number;
341
+ /** Get the currently active curve slot indices. */
342
+ getActiveCurveSlots(): {
343
+ priceBid: number;
344
+ priceAsk: number;
345
+ riskBid: number;
346
+ riskAsk: number;
347
+ };
348
+ /** Decode the currently active curves from prefabs data. */
349
+ getActiveCurves(): {
350
+ priceBid: CurveSide;
351
+ priceAsk: CurveSide;
352
+ riskBid: CurveSide;
353
+ riskAsk: CurveSide;
354
+ };
355
+ /** Decode a specific curve slot. */
356
+ getCurveSlot(curveType: CurveType, slot: number): CurveSide;
357
+ /** Build deposit instruction. */
358
+ deposit(user: PublicKey, params: DepositParams): TransactionInstruction;
359
+ /** Build withdraw instruction. */
360
+ withdraw(user: PublicKey, params: WithdrawParams): TransactionInstruction;
361
+ /** Build swap instruction. */
362
+ swap(user: PublicKey, params: SwapParams): TransactionInstruction;
363
+ /** Build set curve instruction. */
364
+ setCurve(authority: PublicKey, params: SetCurveParams): TransactionInstruction;
365
+ /** Build set risk curve instruction (percent-based x-axis). */
366
+ setRiskCurve(authority: PublicKey, params: SetRiskCurveParams): TransactionInstruction;
367
+ /** Build set risk curve instruction (absolute x-axis). */
368
+ setRiskCurveAbsolute(authority: PublicKey, params: SetRiskCurveAbsoluteParams): TransactionInstruction;
369
+ /** Build set curve instructions for both bid and ask. Returns [bidIx, askIx]. */
370
+ setCurveBoth(authority: PublicKey, params: SetCurveBothParams): [TransactionInstruction, TransactionInstruction];
371
+ /** Build set risk curve instructions for both bid and ask. Returns [bidIx, askIx]. */
372
+ setRiskCurveBoth(authority: PublicKey, params: SetRiskCurveBothParams): [TransactionInstruction, TransactionInstruction];
373
+ /** Build set risk curve (absolute x-axis) instructions for both bid and ask. Returns [bidIx, askIx]. */
374
+ setRiskCurveAbsoluteBoth(authority: PublicKey, params: SetRiskCurveAbsoluteBothParams): [TransactionInstruction, TransactionInstruction];
375
+ /** Build update midprice instruction. */
376
+ updateMidprice(authority: PublicKey, params: UpdateMidpriceParams): TransactionInstruction;
377
+ /** Build update base spread instruction. */
378
+ updateBaseSpread(authority: PublicKey, params: UpdateBaseSpreadParams): TransactionInstruction;
379
+ /** Build atomic update of midprice + base spread. */
380
+ updateMidpriceAndBaseSpread(authority: PublicKey, params: UpdateMidpriceAndBaseSpreadParams): TransactionInstruction;
381
+ /** Build switch price curve instruction (hot path). */
382
+ switchPriceCurve(authority: PublicKey, params: SwitchCurveParams): TransactionInstruction;
383
+ /** Build switch risk curve instruction (hot path). */
384
+ switchRiskCurve(authority: PublicKey, params: SwitchCurveParams): TransactionInstruction;
385
+ /** Build submit curve updates instruction (hot path). */
386
+ submitCurveUpdates(authority: PublicKey, ops: CurveUpdateOp[]): TransactionInstruction;
387
+ /** Build apply curve updates instruction. */
388
+ applyCurveUpdates(authority: PublicKey): TransactionInstruction;
389
+ /** Build nominate authority instruction. */
390
+ nominateAuthority(authority: PublicKey, params: NominateAuthorityParams): TransactionInstruction;
391
+ /** Build accept authority instruction. */
392
+ acceptAuthority(newAuthority: PublicKey): TransactionInstruction;
393
+ /** Build set pool state instruction. */
394
+ setPoolState(authority: PublicKey, params: SetPoolStateParams): TransactionInstruction;
395
+ /** Build update delta staleness instruction. */
396
+ updateDeltaStaleness(authority: PublicKey, params: UpdateDeltaStalenessParams): TransactionInstruction;
397
+ /** Build close pool instruction. */
398
+ closePool(authority: PublicKey): TransactionInstruction;
399
+ }
400
+
401
+ declare const HADRON_PROGRAM_ID: PublicKey;
402
+ declare const CONFIG_SEED: Buffer<ArrayBuffer>;
403
+ declare const MIDPRICE_ORACLE_SEED: Buffer<ArrayBuffer>;
404
+ declare const CURVE_META_SEED: Buffer<ArrayBuffer>;
405
+ declare const CURVE_PREFABS_SEED: Buffer<ArrayBuffer>;
406
+ declare const CURVE_UPDATES_SEED: Buffer<ArrayBuffer>;
407
+ declare const FEE_CONFIG_SEED: Buffer<ArrayBuffer>;
408
+ declare const SPREAD_CONFIG_SEED: Buffer<ArrayBuffer>;
409
+ declare const CONFIG_SIZE = 248;
410
+ declare const MIDPRICE_ORACLE_SIZE = 64;
411
+ declare const CURVE_META_SIZE = 48;
412
+ declare const FEE_CONFIG_SIZE = 72;
413
+ declare const CURVE_UPDATES_SIZE = 258;
414
+ declare const CURVE_SIDE_HEADER = 8;
415
+ declare const CURVE_POINT_LEN = 24;
416
+ declare const DEFAULT_MAX_PREFAB_SLOTS = 10;
417
+ declare const DEFAULT_MAX_CURVE_POINTS = 16;
418
+ declare const ABSOLUTE_MAX_PREFAB_SLOTS = 16;
419
+ declare const ABSOLUTE_MAX_CURVE_POINTS = 128;
420
+ declare const MAX_SETCURVE_POINTS = 32;
421
+ declare const MAX_CURVE_UPDATE_OPS = 8;
422
+ /** Q32.32 representation of 1.0 */
423
+ declare const Q32_ONE: bigint;
424
+ declare const Discriminator: {
425
+ readonly Initialize: 0;
426
+ readonly Deposit: 1;
427
+ readonly Withdraw: 2;
428
+ readonly SwapExactIn: 3;
429
+ readonly SetCurve: 4;
430
+ readonly UpdateMidprice: 5;
431
+ readonly InitializeFeeConfig: 6;
432
+ readonly UpdateFeeConfig: 7;
433
+ readonly SetRiskCurve: 8;
434
+ readonly UpdateBaseSpread: 9;
435
+ readonly UpdateMidpriceAndBaseSpread: 10;
436
+ readonly SwitchPriceCurve: 11;
437
+ readonly SwitchRiskCurve: 12;
438
+ readonly InitializeSpreadConfig: 13;
439
+ readonly UpdateSpreadConfig: 14;
440
+ readonly UpdateDeltaStaleness: 15;
441
+ readonly NominateAuthority: 16;
442
+ readonly AcceptAuthority: 17;
443
+ readonly SubmitCurveUpdates: 18;
444
+ readonly ApplyCurveUpdates: 19;
445
+ readonly ClosePool: 20;
446
+ readonly SetPoolState: 21;
447
+ readonly AllocateCurvePrefabs: 22;
448
+ readonly SetQuotingAuthority: 23;
449
+ readonly RotateFeeAdmin: 24;
450
+ };
451
+ /** Per-point data in SetCurve/SetRiskCurve: u64 + u64 + u8 + 4 params = 21 bytes */
452
+ declare const POINT_DATA_SIZE = 21;
453
+ /** Per-op data in SubmitCurveUpdates: curve_type(1)+op_kind(1)+point_index(1)+interp(1)+x_in(8)+price(8)+params(4) = 24 bytes */
454
+ declare const CURVE_UPDATE_OP_SIZE = 24;
455
+ /** Compute CurvePrefabs account size for given pool parameters. */
456
+ declare function curvePrefabsSize(maxSlots: number, maxPoints: number): number;
457
+
458
+ declare function decodeConfig(data: Uint8Array): DecodedConfig;
459
+ declare function decodeMidpriceOracle(data: Uint8Array): DecodedMidpriceOracle;
460
+ declare function decodeCurveMeta(data: Uint8Array): DecodedCurveMeta;
461
+ /**
462
+ * Check if a specific slot is initialized in the CurveMeta bitmap.
463
+ */
464
+ declare function isSlotInitialized(initializedSlots: Uint8Array, curveType: CurveType, slot: number, maxSlots: number): boolean;
465
+ declare function decodeFeeConfig(data: Uint8Array): DecodedFeeConfig;
466
+ declare function decodeCurveUpdates(data: Uint8Array): DecodedCurveUpdates;
467
+ /**
468
+ * Decode a single curve side from a CurvePrefabs account.
469
+ */
470
+ declare function decodeCurveSide(data: Uint8Array, curveType: CurveType, slot: number, maxSlots: number, maxPoints: number): CurveSide;
471
+ /**
472
+ * Decode all active curve slots from a CurvePrefabs account using CurveMeta info.
473
+ */
474
+ declare function decodeActiveCurves(prefabsData: Uint8Array, meta: DecodedCurveMeta): {
475
+ priceBid: CurveSide;
476
+ priceAsk: CurveSide;
477
+ riskBid: CurveSide;
478
+ riskAsk: CurveSide;
479
+ };
480
+
481
+ declare function getConfigAddress(seed: bigint, mintX: PublicKey, mintY: PublicKey, programId?: PublicKey): [PublicKey, number];
482
+ declare function getMidpriceOracleAddress(seed: bigint, mintX: PublicKey, mintY: PublicKey, programId?: PublicKey): [PublicKey, number];
483
+ declare function getCurveMetaAddress(seed: bigint, mintX: PublicKey, mintY: PublicKey, programId?: PublicKey): [PublicKey, number];
484
+ declare function getCurvePrefabsAddress(seed: bigint, mintX: PublicKey, mintY: PublicKey, programId?: PublicKey): [PublicKey, number];
485
+ declare function getCurveUpdatesAddress(seed: bigint, mintX: PublicKey, mintY: PublicKey, programId?: PublicKey): [PublicKey, number];
486
+ declare function getFeeConfigAddress(programId?: PublicKey): [PublicKey, number];
487
+ declare function getSpreadConfigAddress(configPda: PublicKey, programId?: PublicKey): [PublicKey, number];
488
+ /**
489
+ * Derive all PDA addresses for a pool.
490
+ */
491
+ declare function derivePoolAddresses(seed: bigint, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, programId?: PublicKey): PoolAddresses;
492
+
493
+ /** Convert a floating-point number to Q32.32 fixed point (bigint). */
494
+ declare function toQ32(value: number): bigint;
495
+ /** Convert a Q32.32 fixed-point bigint to a floating-point number.
496
+ * Splits into integer + fractional parts to avoid precision loss
497
+ * when the integer part exceeds 2^21 (~2 million). */
498
+ declare function fromQ32(q32: bigint): number;
499
+ /** Convert a percentage (0.0 to 1.0) to Q32.32. */
500
+ declare function pctToQ32(pct: number): bigint;
501
+
502
+ /**
503
+ * Get the ATA address, and optionally return a create instruction if it doesn't exist.
504
+ */
505
+ declare function getOrCreateAta(connection: Connection, mint: PublicKey, owner: PublicKey, payer: PublicKey, tokenProgram?: PublicKey, allowOwnerOffCurve?: boolean): Promise<{
506
+ address: PublicKey;
507
+ instruction: TransactionInstruction | null;
508
+ }>;
509
+
510
+ /**
511
+ * Build an Initialize instruction.
512
+ * Creates the pool: Config, MidpriceOracle, CurveMeta, CurveUpdates.
513
+ * CurvePrefabs must be pre-allocated (use buildAllocateCurvePrefabs).
514
+ */
515
+ declare function buildInitialize(payer: PublicKey, params: InitializeParams, programId?: PublicKey): TransactionInstruction;
516
+ /**
517
+ * Build an AllocateCurvePrefabs instruction.
518
+ * Must be called before Initialize (possibly twice if size > 10240).
519
+ */
520
+ declare function buildAllocateCurvePrefabs(payer: PublicKey, params: AllocateCurvePrefabsParams, programId?: PublicKey): TransactionInstruction;
521
+
522
+ /**
523
+ * Build a Deposit instruction.
524
+ */
525
+ declare function buildDeposit(user: PublicKey, configPda: PublicKey, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, params: DepositParams, programId?: PublicKey): TransactionInstruction;
526
+
527
+ /**
528
+ * Build a Withdraw instruction.
529
+ */
530
+ declare function buildWithdraw(user: PublicKey, configPda: PublicKey, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, params: WithdrawParams, programId?: PublicKey): TransactionInstruction;
531
+
532
+ /**
533
+ * Build a SwapExactIn instruction.
534
+ *
535
+ * Account order (16 base): token_program_x, token_program_y, config,
536
+ * midprice_oracle, curve_meta, curve_prefabs, authority(=pool address PDA), user,
537
+ * user_source, vault_source, vault_dest, user_dest, fee_config,
538
+ * fee_recipient_ata, clock, curve_updates.
539
+ *
540
+ * Optional (for introspection): spread_config, instructions_sysvar.
541
+ */
542
+ declare function buildSwapExactIn(user: PublicKey, poolAddresses: PoolAddresses, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, params: SwapParams, programId?: PublicKey): TransactionInstruction;
543
+
544
+ /**
545
+ * Build a SetCurve instruction (price curve).
546
+ * Accounts: authority, curve_meta, curve_prefabs.
547
+ */
548
+ declare function buildSetCurve(authority: PublicKey, curveMetaPda: PublicKey, curvePrefabsPda: PublicKey, params: SetCurveParams, programId?: PublicKey): TransactionInstruction;
549
+ /**
550
+ * Build a SetRiskCurve instruction (risk curve, percent-based x-axis by default).
551
+ * Accounts: authority, curve_meta, curve_prefabs.
552
+ */
553
+ declare function buildSetRiskCurve(authority: PublicKey, curveMetaPda: PublicKey, curvePrefabsPda: PublicKey, params: SetRiskCurveParams, programId?: PublicKey): TransactionInstruction;
554
+ /**
555
+ * Build a SetRiskCurve instruction with absolute x-axis (CurveXMode::Alternate).
556
+ */
557
+ declare function buildSetRiskCurveAbsolute(authority: PublicKey, curveMetaPda: PublicKey, curvePrefabsPda: PublicKey, params: SetRiskCurveAbsoluteParams, programId?: PublicKey): TransactionInstruction;
558
+ /**
559
+ * Build SetCurve instructions for both bid and ask in one call.
560
+ * Returns [bidIx, askIx] — add both to the same transaction.
561
+ */
562
+ declare function buildSetCurveBoth(authority: PublicKey, curveMetaPda: PublicKey, curvePrefabsPda: PublicKey, params: SetCurveBothParams, programId?: PublicKey): [TransactionInstruction, TransactionInstruction];
563
+ /**
564
+ * Build SetRiskCurve instructions for both bid and ask in one call.
565
+ * Returns [bidIx, askIx].
566
+ */
567
+ declare function buildSetRiskCurveBoth(authority: PublicKey, curveMetaPda: PublicKey, curvePrefabsPda: PublicKey, params: SetRiskCurveBothParams, programId?: PublicKey): [TransactionInstruction, TransactionInstruction];
568
+ /**
569
+ * Build SetRiskCurve (absolute x-axis) instructions for both bid and ask in one call.
570
+ * Returns [bidIx, askIx].
571
+ */
572
+ declare function buildSetRiskCurveAbsoluteBoth(authority: PublicKey, curveMetaPda: PublicKey, curvePrefabsPda: PublicKey, params: SetRiskCurveAbsoluteBothParams, programId?: PublicKey): [TransactionInstruction, TransactionInstruction];
573
+
574
+ /**
575
+ * Build an UpdateMidprice instruction.
576
+ * Accounts: authority, midprice_oracle, clock.
577
+ */
578
+ declare function buildUpdateMidprice(authority: PublicKey, midpriceOraclePda: PublicKey, params: UpdateMidpriceParams, programId?: PublicKey): TransactionInstruction;
579
+ /**
580
+ * Build an UpdateBaseSpread instruction.
581
+ * Accounts: authority, midprice_oracle, clock.
582
+ */
583
+ declare function buildUpdateBaseSpread(authority: PublicKey, midpriceOraclePda: PublicKey, params: UpdateBaseSpreadParams, programId?: PublicKey): TransactionInstruction;
584
+ /**
585
+ * Build an UpdateMidpriceAndBaseSpread instruction (atomic update of both).
586
+ * Accounts: authority, midprice_oracle, clock.
587
+ */
588
+ declare function buildUpdateMidpriceAndBaseSpread(authority: PublicKey, midpriceOraclePda: PublicKey, params: UpdateMidpriceAndBaseSpreadParams, programId?: PublicKey): TransactionInstruction;
589
+
590
+ /**
591
+ * Build a SwitchPriceCurve instruction (hot path).
592
+ * Accounts: authority, curve_meta.
593
+ */
594
+ declare function buildSwitchPriceCurve(authority: PublicKey, curveMetaPda: PublicKey, params: SwitchCurveParams, programId?: PublicKey): TransactionInstruction;
595
+ /**
596
+ * Build a SwitchRiskCurve instruction (hot path).
597
+ * Accounts: authority, curve_meta.
598
+ */
599
+ declare function buildSwitchRiskCurve(authority: PublicKey, curveMetaPda: PublicKey, params: SwitchCurveParams, programId?: PublicKey): TransactionInstruction;
600
+
601
+ /**
602
+ * Build a SubmitCurveUpdates instruction (hot path, 2 accounts).
603
+ * Accounts: authority, curve_updates.
604
+ */
605
+ declare function buildSubmitCurveUpdates(authority: PublicKey, curveUpdatesPda: PublicKey, ops: CurveUpdateOp[], programId?: PublicKey): TransactionInstruction;
606
+ /**
607
+ * Build an ApplyCurveUpdates instruction.
608
+ * Accounts: authority, curve_meta, curve_prefabs, curve_updates.
609
+ */
610
+ declare function buildApplyCurveUpdates(authority: PublicKey, curveMetaPda: PublicKey, curvePrefabsPda: PublicKey, curveUpdatesPda: PublicKey, programId?: PublicKey): TransactionInstruction;
611
+
612
+ /**
613
+ * Build a NominateAuthority instruction (step 1 of 2-step authority transfer).
614
+ * Accounts: authority, config, clock.
615
+ */
616
+ declare function buildNominateAuthority(authority: PublicKey, configPda: PublicKey, params: NominateAuthorityParams, programId?: PublicKey): TransactionInstruction;
617
+ /**
618
+ * Build an AcceptAuthority instruction (step 2 of 2-step authority transfer).
619
+ * Only updates Config.authority. Quoting authority is managed via SetQuotingAuthority.
620
+ * Accounts: new_authority, config, clock.
621
+ */
622
+ declare function buildAcceptAuthority(newAuthority: PublicKey, configPda: PublicKey, programId?: PublicKey): TransactionInstruction;
623
+ /**
624
+ * Build a SetQuotingAuthority instruction.
625
+ * Pool authority sets a new quoting authority on MidpriceOracle, CurveMeta,
626
+ * CurveUpdates, and optionally SpreadConfig.
627
+ * Accounts: authority, config, midprice_oracle, curve_meta, curve_updates, [spread_config?].
628
+ */
629
+ declare function buildSetQuotingAuthority(authority: PublicKey, configPda: PublicKey, oraclePda: PublicKey, curveMetaPda: PublicKey, curveUpdatesPda: PublicKey, params: SetQuotingAuthorityParams, programId?: PublicKey): TransactionInstruction;
630
+
631
+ /**
632
+ * Build an InitializeFeeConfig instruction (one-time global setup).
633
+ * Accounts: payer, authority, fee_config, system_program.
634
+ */
635
+ declare function buildInitializeFeeConfig(payer: PublicKey, authority: PublicKey, params: InitializeFeeConfigParams, programId?: PublicKey): TransactionInstruction;
636
+ /**
637
+ * Build an UpdateFeeConfig instruction.
638
+ * Accounts: fee_admin, fee_config.
639
+ */
640
+ declare function buildUpdateFeeConfig(feeAdmin: PublicKey, params: UpdateFeeConfigParams, programId?: PublicKey): TransactionInstruction;
641
+ /**
642
+ * Build a RotateFeeAdmin instruction.
643
+ * Accounts: fee_admin (signer), fee_config (mut).
644
+ */
645
+ declare function buildRotateFeeAdmin(feeAdmin: PublicKey, params: RotateFeeAdminParams, programId?: PublicKey): TransactionInstruction;
646
+
647
+ /**
648
+ * Build an InitializeSpreadConfig instruction.
649
+ * Accounts: payer, authority, config, spread_config, system_program.
650
+ */
651
+ declare function buildInitializeSpreadConfig(payer: PublicKey, authority: PublicKey, configPda: PublicKey, params: InitializeSpreadConfigParams, programId?: PublicKey): TransactionInstruction;
652
+ /**
653
+ * Build an UpdateSpreadConfig instruction.
654
+ * Accounts: admin, config, spread_config.
655
+ */
656
+ declare function buildUpdateSpreadConfig(admin: PublicKey, configPda: PublicKey, params: UpdateSpreadConfigParams, programId?: PublicKey): TransactionInstruction;
657
+
658
+ /**
659
+ * Build a SetPoolState instruction.
660
+ * Accounts: authority, config.
661
+ */
662
+ declare function buildSetPoolState(authority: PublicKey, configPda: PublicKey, params: SetPoolStateParams, programId?: PublicKey): TransactionInstruction;
663
+ /**
664
+ * Build an UpdateDeltaStaleness instruction.
665
+ * Accounts: authority, config.
666
+ */
667
+ declare function buildUpdateDeltaStaleness(authority: PublicKey, configPda: PublicKey, params: UpdateDeltaStalenessParams, programId?: PublicKey): TransactionInstruction;
668
+ /**
669
+ * Build a ClosePool instruction.
670
+ * Accounts: authority, config, midprice_oracle, curve_meta, curve_prefabs,
671
+ * curve_updates, vault_x, vault_y, token_program_x, token_program_y,
672
+ * [optional: spread_config if initialized].
673
+ */
674
+ declare function buildClosePool(authority: PublicKey, configPda: PublicKey, midpriceOraclePda: PublicKey, curveMetaPda: PublicKey, curvePrefabsPda: PublicKey, curveUpdatesPda: PublicKey, vaultX: PublicKey, vaultY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, spreadConfigInitialized?: boolean, programId?: PublicKey): TransactionInstruction;
675
+
676
+ export { ABSOLUTE_MAX_CURVE_POINTS, ABSOLUTE_MAX_PREFAB_SLOTS, type AllocateCurvePrefabsParams, CONFIG_SEED, CONFIG_SIZE, CURVE_META_SEED, CURVE_META_SIZE, CURVE_POINT_LEN, CURVE_PREFABS_SEED, CURVE_SIDE_HEADER, CURVE_UPDATES_SEED, CURVE_UPDATES_SIZE, CURVE_UPDATE_OP_SIZE, type CurvePoint, type CurveSide, CurveType, type CurveUpdateOp, CurveUpdateOpKind, CurveXMode, DEFAULT_MAX_CURVE_POINTS, DEFAULT_MAX_PREFAB_SLOTS, type DecodedConfig, type DecodedCurveMeta, type DecodedCurveUpdates, type DecodedFeeConfig, type DecodedMidpriceOracle, type DepositParams, Discriminator, FEE_CONFIG_SEED, FEE_CONFIG_SIZE, HADRON_PROGRAM_ID, Hadron, type InitializeFeeConfigParams, type InitializeParams, type InitializeSpreadConfigParams, Interpolation, MAX_CURVE_UPDATE_OPS, MAX_SETCURVE_POINTS, MIDPRICE_ORACLE_SEED, MIDPRICE_ORACLE_SIZE, type NominateAuthorityParams, OracleMode, POINT_DATA_SIZE, type PoolAddresses, PoolState, Q32_ONE, RiskMode, type RotateFeeAdminParams, SPREAD_CONFIG_SEED, type SetCurveBothParams, type SetCurveParams, type SetCurvePointInput, type SetPoolStateParams, type SetQuotingAuthorityParams, type SetRiskCurveAbsoluteBothParams, type SetRiskCurveAbsoluteParams, type SetRiskCurveAbsolutePointInput, type SetRiskCurveBothParams, type SetRiskCurveParams, type SetRiskCurvePointInput, Side, type SpreadTriggerInput, type SwapParams, type SwitchCurveParams, type UpdateBaseSpreadParams, type UpdateDeltaStalenessParams, type UpdateFeeConfigParams, type UpdateMidpriceAndBaseSpreadParams, type UpdateMidpriceParams, type UpdateSpreadConfigParams, type WithdrawParams, buildAcceptAuthority, buildAllocateCurvePrefabs, buildApplyCurveUpdates, buildClosePool, buildDeposit, buildInitialize, buildInitializeFeeConfig, buildInitializeSpreadConfig, buildNominateAuthority, buildRotateFeeAdmin, buildSetCurve, buildSetCurveBoth, buildSetPoolState, buildSetQuotingAuthority, buildSetRiskCurve, buildSetRiskCurveAbsolute, buildSetRiskCurveAbsoluteBoth, buildSetRiskCurveBoth, buildSubmitCurveUpdates, buildSwapExactIn, buildSwitchPriceCurve, buildSwitchRiskCurve, buildUpdateBaseSpread, buildUpdateDeltaStaleness, buildUpdateFeeConfig, buildUpdateMidprice, buildUpdateMidpriceAndBaseSpread, buildUpdateSpreadConfig, buildWithdraw, curvePrefabsSize, decodeActiveCurves, decodeConfig, decodeCurveMeta, decodeCurveSide, decodeCurveUpdates, decodeFeeConfig, decodeMidpriceOracle, derivePoolAddresses, fromQ32, getConfigAddress, getCurveMetaAddress, getCurvePrefabsAddress, getCurveUpdatesAddress, getFeeConfigAddress, getMidpriceOracleAddress, getOrCreateAta, getSpreadConfigAddress, isSlotInitialized, pctToQ32, toQ32 };