@hadron-fi/sdk 0.3.4 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { PublicKey, Connection, TransactionInstruction } from '@solana/web3.js';
2
+ export { NATIVE_MINT } from '@solana/spl-token';
2
3
 
3
4
  declare enum PoolState {
4
5
  Uninitialized = 0,
@@ -56,6 +57,7 @@ interface DecodedConfig {
56
57
  spreadConfigInitialized: boolean;
57
58
  deltaStaleness: number;
58
59
  oracleMode: OracleMode;
60
+ hasPoolFee: boolean;
59
61
  pendingAuthority: PublicKey;
60
62
  nominationExpiry: bigint;
61
63
  tokenProgramX: PublicKey;
@@ -255,6 +257,17 @@ interface UpdateFeeConfigParams {
255
257
  interface RotateFeeAdminParams {
256
258
  newFeeAdmin: PublicKey;
257
259
  }
260
+ interface InitializePoolFeeConfigParams {
261
+ feePpm: number;
262
+ feeAdmin: PublicKey;
263
+ feeRecipient: PublicKey;
264
+ }
265
+ interface UpdatePoolFeeConfigParams {
266
+ /** Pass null for no change (sends u32::MAX) */
267
+ feePpm: number | null;
268
+ /** Pass null for no change (sends zeros) */
269
+ feeRecipient: PublicKey | null;
270
+ }
258
271
  interface SetPoolStateParams {
259
272
  newState: PoolState;
260
273
  }
@@ -277,6 +290,7 @@ interface AllocateCurvePrefabsParams {
277
290
  mintY: PublicKey;
278
291
  maxPrefabSlots?: number;
279
292
  maxCurvePoints?: number;
293
+ authority: PublicKey;
280
294
  }
281
295
  type OrderSide = "bid" | "ask";
282
296
  interface PlaceOrderParams {
@@ -467,7 +481,22 @@ declare class Hadron {
467
481
  /** Fetch and decode the current spread config triggers from chain. */
468
482
  private fetchSpreadTriggers;
469
483
  /** Build close pool instruction. */
470
- closePool(authority: PublicKey): TransactionInstruction;
484
+ closePool(authority: PublicKey, authorityAtaX?: PublicKey, authorityAtaY?: PublicKey): TransactionInstruction;
485
+ /**
486
+ * Build deposit instructions with automatic SOL wrapping.
487
+ * If mint X or Y is native SOL, prepends wrap instructions for that side.
488
+ */
489
+ depositSol(user: PublicKey, params: DepositParams): TransactionInstruction[];
490
+ /**
491
+ * Build withdraw instructions with automatic SOL unwrapping.
492
+ * Creates wSOL ATA (so program can transfer into it), withdraws, then closes ATA.
493
+ */
494
+ withdrawSol(user: PublicKey, params: WithdrawParams): TransactionInstruction[];
495
+ /**
496
+ * Build swap instructions with automatic SOL wrapping/unwrapping.
497
+ * Wraps SOL if the input side is native, unwraps if the output side is native.
498
+ */
499
+ swapSol(user: PublicKey, params: SwapParams): TransactionInstruction[];
471
500
  }
472
501
 
473
502
  /**
@@ -647,6 +676,8 @@ declare const Discriminator: {
647
676
  readonly AllocateCurvePrefabs: 22;
648
677
  readonly SetQuotingAuthority: 23;
649
678
  readonly RotateFeeAdmin: 24;
679
+ readonly InitializePoolFeeConfig: 25;
680
+ readonly UpdatePoolFeeConfig: 26;
650
681
  };
651
682
  /** Per-point data in SetCurve/SetRiskCurve: u64 + u64 + u8 + 4 params = 21 bytes */
652
683
  declare const POINT_DATA_SIZE = 21;
@@ -685,6 +716,7 @@ declare function getCurveMetaAddress(seed: bigint, mintX: PublicKey, mintY: Publ
685
716
  declare function getCurvePrefabsAddress(seed: bigint, mintX: PublicKey, mintY: PublicKey, programId?: PublicKey): [PublicKey, number];
686
717
  declare function getCurveUpdatesAddress(seed: bigint, mintX: PublicKey, mintY: PublicKey, programId?: PublicKey): [PublicKey, number];
687
718
  declare function getFeeConfigAddress(programId?: PublicKey): [PublicKey, number];
719
+ declare function getPoolFeeConfigAddress(configPda: PublicKey, programId?: PublicKey): [PublicKey, number];
688
720
  declare function getSpreadConfigAddress(configPda: PublicKey, programId?: PublicKey): [PublicKey, number];
689
721
  /**
690
722
  * Derive all PDA addresses for a pool.
@@ -704,6 +736,24 @@ declare function spreadBpsToQ32(bps: number): bigint;
704
736
  /** Convert a spread factor in Q32 to basis points (e.g. toQ32(0.9995) → 5). */
705
737
  declare function spreadQ32ToBps(q32: bigint): number;
706
738
 
739
+ /** Returns true if the given mint is the native SOL (wSOL) mint. */
740
+ declare function isNativeMint(mint: PublicKey): boolean;
741
+ /**
742
+ * Build instructions to wrap native SOL into a wSOL ATA.
743
+ *
744
+ * Returns [createATA (idempotent), transfer SOL, syncNative] instructions.
745
+ */
746
+ declare function wrapSolInstructions(user: PublicKey, lamports: bigint): TransactionInstruction[];
747
+ /**
748
+ * Build instruction to ensure the user's wSOL ATA exists (idempotent create).
749
+ * Needed before withdraw/swap-output so the program has somewhere to send wSOL.
750
+ */
751
+ declare function createWsolAtaInstruction(user: PublicKey): TransactionInstruction;
752
+ /**
753
+ * Build instruction to unwrap wSOL — closes the ATA and sends lamports back to the user.
754
+ */
755
+ declare function unwrapSolInstruction(user: PublicKey): TransactionInstruction;
756
+
707
757
  /**
708
758
  * Get the ATA address, and optionally return a create instruction if it doesn't exist.
709
759
  */
@@ -744,7 +794,7 @@ declare function buildWithdraw(user: PublicKey, configPda: PublicKey, mintX: Pub
744
794
  *
745
795
  * When spread config is initialized: spread_config (#16) + instructions_sysvar (#17).
746
796
  */
747
- declare function buildSwapExactIn(user: PublicKey, poolAddresses: PoolAddresses, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, params: SwapParams, programId?: PublicKey, spreadConfigInitialized?: boolean): TransactionInstruction;
797
+ declare function buildSwapExactIn(user: PublicKey, poolAddresses: PoolAddresses, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, params: SwapParams, programId?: PublicKey, spreadConfigInitialized?: boolean, feeConfigOverride?: PublicKey): TransactionInstruction;
748
798
 
749
799
  /**
750
800
  * Build a SetCurve instruction (price curve).
@@ -848,6 +898,16 @@ declare function buildUpdateFeeConfig(feeAdmin: PublicKey, params: UpdateFeeConf
848
898
  * Accounts: fee_admin (signer), fee_config (mut).
849
899
  */
850
900
  declare function buildRotateFeeAdmin(feeAdmin: PublicKey, params: RotateFeeAdminParams, programId?: PublicKey): TransactionInstruction;
901
+ /**
902
+ * Build an InitializePoolFeeConfig instruction.
903
+ * Accounts: payer, fee_admin, config, pool_fee_config, global_fee_config, system_program.
904
+ */
905
+ declare function buildInitializePoolFeeConfig(payer: PublicKey, feeAdmin: PublicKey, configPda: PublicKey, params: InitializePoolFeeConfigParams, programId?: PublicKey): TransactionInstruction;
906
+ /**
907
+ * Build an UpdatePoolFeeConfig instruction.
908
+ * Accounts: fee_admin, config, pool_fee_config.
909
+ */
910
+ declare function buildUpdatePoolFeeConfig(feeAdmin: PublicKey, configPda: PublicKey, params: UpdatePoolFeeConfigParams, programId?: PublicKey): TransactionInstruction;
851
911
 
852
912
  /**
853
913
  * Build an InitializeSpreadConfig instruction.
@@ -876,6 +936,6 @@ declare function buildUpdateDeltaStaleness(authority: PublicKey, configPda: Publ
876
936
  * curve_updates, vault_x, vault_y, token_program_x, token_program_y,
877
937
  * [optional: spread_config if initialized].
878
938
  */
879
- 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;
939
+ 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, authorityAtaX?: PublicKey, authorityAtaY?: PublicKey, programId?: PublicKey): TransactionInstruction;
880
940
 
881
- export { ABSOLUTE_MAX_CURVE_POINTS, ABSOLUTE_MAX_PREFAB_SLOTS, type AllocateCurvePrefabsParams, type AmendOrderParams, 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 CancelOrderParams, 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 DecodedSpreadConfig, type DepositParams, Discriminator, FEE_CONFIG_SEED, FEE_CONFIG_SIZE, HADRON_PROGRAM_ID, Hadron, HadronOrderbook, type InitializeFeeConfigParams, type InitializeParams, type InitializeSpreadConfigParams, Interpolation, MAX_CURVE_UPDATE_OPS, MAX_SETCURVE_POINTS, MIDPRICE_ORACLE_SEED, MIDPRICE_ORACLE_SIZE, type NominateAuthorityParams, OracleMode, type OrderSide, type OrderbookLevel, type OrderbookState, POINT_DATA_SIZE, type PlaceOrderParams, 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 StagedOrder, 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, decodeSpreadConfig, derivePoolAddresses, fromQ32, getConfigAddress, getCurveMetaAddress, getCurvePrefabsAddress, getCurveUpdatesAddress, getFeeConfigAddress, getMidpriceOracleAddress, getOrCreateAta, getSpreadConfigAddress, isSlotInitialized, pctToQ32, spreadBpsToQ32, spreadQ32ToBps, toQ32 };
941
+ export { ABSOLUTE_MAX_CURVE_POINTS, ABSOLUTE_MAX_PREFAB_SLOTS, type AllocateCurvePrefabsParams, type AmendOrderParams, 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 CancelOrderParams, 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 DecodedSpreadConfig, type DepositParams, Discriminator, FEE_CONFIG_SEED, FEE_CONFIG_SIZE, HADRON_PROGRAM_ID, Hadron, HadronOrderbook, type InitializeFeeConfigParams, type InitializeParams, type InitializePoolFeeConfigParams, type InitializeSpreadConfigParams, Interpolation, MAX_CURVE_UPDATE_OPS, MAX_SETCURVE_POINTS, MIDPRICE_ORACLE_SEED, MIDPRICE_ORACLE_SIZE, type NominateAuthorityParams, OracleMode, type OrderSide, type OrderbookLevel, type OrderbookState, POINT_DATA_SIZE, type PlaceOrderParams, 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 StagedOrder, type SwapParams, type SwitchCurveParams, type UpdateBaseSpreadParams, type UpdateDeltaStalenessParams, type UpdateFeeConfigParams, type UpdateMidpriceAndBaseSpreadParams, type UpdateMidpriceParams, type UpdatePoolFeeConfigParams, type UpdateSpreadConfigParams, type WithdrawParams, buildAcceptAuthority, buildAllocateCurvePrefabs, buildApplyCurveUpdates, buildClosePool, buildDeposit, buildInitialize, buildInitializeFeeConfig, buildInitializePoolFeeConfig, buildInitializeSpreadConfig, buildNominateAuthority, buildRotateFeeAdmin, buildSetCurve, buildSetCurveBoth, buildSetPoolState, buildSetQuotingAuthority, buildSetRiskCurve, buildSetRiskCurveAbsolute, buildSetRiskCurveAbsoluteBoth, buildSetRiskCurveBoth, buildSubmitCurveUpdates, buildSwapExactIn, buildSwitchPriceCurve, buildSwitchRiskCurve, buildUpdateBaseSpread, buildUpdateDeltaStaleness, buildUpdateFeeConfig, buildUpdateMidprice, buildUpdateMidpriceAndBaseSpread, buildUpdatePoolFeeConfig, buildUpdateSpreadConfig, buildWithdraw, createWsolAtaInstruction, curvePrefabsSize, decodeActiveCurves, decodeConfig, decodeCurveMeta, decodeCurveSide, decodeCurveUpdates, decodeFeeConfig, decodeMidpriceOracle, decodeSpreadConfig, derivePoolAddresses, fromQ32, getConfigAddress, getCurveMetaAddress, getCurvePrefabsAddress, getCurveUpdatesAddress, getFeeConfigAddress, getMidpriceOracleAddress, getOrCreateAta, getPoolFeeConfigAddress, getSpreadConfigAddress, isNativeMint, isSlotInitialized, pctToQ32, spreadBpsToQ32, spreadQ32ToBps, toQ32, unwrapSolInstruction, wrapSolInstructions };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { PublicKey, Connection, TransactionInstruction } from '@solana/web3.js';
2
+ export { NATIVE_MINT } from '@solana/spl-token';
2
3
 
3
4
  declare enum PoolState {
4
5
  Uninitialized = 0,
@@ -56,6 +57,7 @@ interface DecodedConfig {
56
57
  spreadConfigInitialized: boolean;
57
58
  deltaStaleness: number;
58
59
  oracleMode: OracleMode;
60
+ hasPoolFee: boolean;
59
61
  pendingAuthority: PublicKey;
60
62
  nominationExpiry: bigint;
61
63
  tokenProgramX: PublicKey;
@@ -255,6 +257,17 @@ interface UpdateFeeConfigParams {
255
257
  interface RotateFeeAdminParams {
256
258
  newFeeAdmin: PublicKey;
257
259
  }
260
+ interface InitializePoolFeeConfigParams {
261
+ feePpm: number;
262
+ feeAdmin: PublicKey;
263
+ feeRecipient: PublicKey;
264
+ }
265
+ interface UpdatePoolFeeConfigParams {
266
+ /** Pass null for no change (sends u32::MAX) */
267
+ feePpm: number | null;
268
+ /** Pass null for no change (sends zeros) */
269
+ feeRecipient: PublicKey | null;
270
+ }
258
271
  interface SetPoolStateParams {
259
272
  newState: PoolState;
260
273
  }
@@ -277,6 +290,7 @@ interface AllocateCurvePrefabsParams {
277
290
  mintY: PublicKey;
278
291
  maxPrefabSlots?: number;
279
292
  maxCurvePoints?: number;
293
+ authority: PublicKey;
280
294
  }
281
295
  type OrderSide = "bid" | "ask";
282
296
  interface PlaceOrderParams {
@@ -467,7 +481,22 @@ declare class Hadron {
467
481
  /** Fetch and decode the current spread config triggers from chain. */
468
482
  private fetchSpreadTriggers;
469
483
  /** Build close pool instruction. */
470
- closePool(authority: PublicKey): TransactionInstruction;
484
+ closePool(authority: PublicKey, authorityAtaX?: PublicKey, authorityAtaY?: PublicKey): TransactionInstruction;
485
+ /**
486
+ * Build deposit instructions with automatic SOL wrapping.
487
+ * If mint X or Y is native SOL, prepends wrap instructions for that side.
488
+ */
489
+ depositSol(user: PublicKey, params: DepositParams): TransactionInstruction[];
490
+ /**
491
+ * Build withdraw instructions with automatic SOL unwrapping.
492
+ * Creates wSOL ATA (so program can transfer into it), withdraws, then closes ATA.
493
+ */
494
+ withdrawSol(user: PublicKey, params: WithdrawParams): TransactionInstruction[];
495
+ /**
496
+ * Build swap instructions with automatic SOL wrapping/unwrapping.
497
+ * Wraps SOL if the input side is native, unwraps if the output side is native.
498
+ */
499
+ swapSol(user: PublicKey, params: SwapParams): TransactionInstruction[];
471
500
  }
472
501
 
473
502
  /**
@@ -647,6 +676,8 @@ declare const Discriminator: {
647
676
  readonly AllocateCurvePrefabs: 22;
648
677
  readonly SetQuotingAuthority: 23;
649
678
  readonly RotateFeeAdmin: 24;
679
+ readonly InitializePoolFeeConfig: 25;
680
+ readonly UpdatePoolFeeConfig: 26;
650
681
  };
651
682
  /** Per-point data in SetCurve/SetRiskCurve: u64 + u64 + u8 + 4 params = 21 bytes */
652
683
  declare const POINT_DATA_SIZE = 21;
@@ -685,6 +716,7 @@ declare function getCurveMetaAddress(seed: bigint, mintX: PublicKey, mintY: Publ
685
716
  declare function getCurvePrefabsAddress(seed: bigint, mintX: PublicKey, mintY: PublicKey, programId?: PublicKey): [PublicKey, number];
686
717
  declare function getCurveUpdatesAddress(seed: bigint, mintX: PublicKey, mintY: PublicKey, programId?: PublicKey): [PublicKey, number];
687
718
  declare function getFeeConfigAddress(programId?: PublicKey): [PublicKey, number];
719
+ declare function getPoolFeeConfigAddress(configPda: PublicKey, programId?: PublicKey): [PublicKey, number];
688
720
  declare function getSpreadConfigAddress(configPda: PublicKey, programId?: PublicKey): [PublicKey, number];
689
721
  /**
690
722
  * Derive all PDA addresses for a pool.
@@ -704,6 +736,24 @@ declare function spreadBpsToQ32(bps: number): bigint;
704
736
  /** Convert a spread factor in Q32 to basis points (e.g. toQ32(0.9995) → 5). */
705
737
  declare function spreadQ32ToBps(q32: bigint): number;
706
738
 
739
+ /** Returns true if the given mint is the native SOL (wSOL) mint. */
740
+ declare function isNativeMint(mint: PublicKey): boolean;
741
+ /**
742
+ * Build instructions to wrap native SOL into a wSOL ATA.
743
+ *
744
+ * Returns [createATA (idempotent), transfer SOL, syncNative] instructions.
745
+ */
746
+ declare function wrapSolInstructions(user: PublicKey, lamports: bigint): TransactionInstruction[];
747
+ /**
748
+ * Build instruction to ensure the user's wSOL ATA exists (idempotent create).
749
+ * Needed before withdraw/swap-output so the program has somewhere to send wSOL.
750
+ */
751
+ declare function createWsolAtaInstruction(user: PublicKey): TransactionInstruction;
752
+ /**
753
+ * Build instruction to unwrap wSOL — closes the ATA and sends lamports back to the user.
754
+ */
755
+ declare function unwrapSolInstruction(user: PublicKey): TransactionInstruction;
756
+
707
757
  /**
708
758
  * Get the ATA address, and optionally return a create instruction if it doesn't exist.
709
759
  */
@@ -744,7 +794,7 @@ declare function buildWithdraw(user: PublicKey, configPda: PublicKey, mintX: Pub
744
794
  *
745
795
  * When spread config is initialized: spread_config (#16) + instructions_sysvar (#17).
746
796
  */
747
- declare function buildSwapExactIn(user: PublicKey, poolAddresses: PoolAddresses, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, params: SwapParams, programId?: PublicKey, spreadConfigInitialized?: boolean): TransactionInstruction;
797
+ declare function buildSwapExactIn(user: PublicKey, poolAddresses: PoolAddresses, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, params: SwapParams, programId?: PublicKey, spreadConfigInitialized?: boolean, feeConfigOverride?: PublicKey): TransactionInstruction;
748
798
 
749
799
  /**
750
800
  * Build a SetCurve instruction (price curve).
@@ -848,6 +898,16 @@ declare function buildUpdateFeeConfig(feeAdmin: PublicKey, params: UpdateFeeConf
848
898
  * Accounts: fee_admin (signer), fee_config (mut).
849
899
  */
850
900
  declare function buildRotateFeeAdmin(feeAdmin: PublicKey, params: RotateFeeAdminParams, programId?: PublicKey): TransactionInstruction;
901
+ /**
902
+ * Build an InitializePoolFeeConfig instruction.
903
+ * Accounts: payer, fee_admin, config, pool_fee_config, global_fee_config, system_program.
904
+ */
905
+ declare function buildInitializePoolFeeConfig(payer: PublicKey, feeAdmin: PublicKey, configPda: PublicKey, params: InitializePoolFeeConfigParams, programId?: PublicKey): TransactionInstruction;
906
+ /**
907
+ * Build an UpdatePoolFeeConfig instruction.
908
+ * Accounts: fee_admin, config, pool_fee_config.
909
+ */
910
+ declare function buildUpdatePoolFeeConfig(feeAdmin: PublicKey, configPda: PublicKey, params: UpdatePoolFeeConfigParams, programId?: PublicKey): TransactionInstruction;
851
911
 
852
912
  /**
853
913
  * Build an InitializeSpreadConfig instruction.
@@ -876,6 +936,6 @@ declare function buildUpdateDeltaStaleness(authority: PublicKey, configPda: Publ
876
936
  * curve_updates, vault_x, vault_y, token_program_x, token_program_y,
877
937
  * [optional: spread_config if initialized].
878
938
  */
879
- 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;
939
+ 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, authorityAtaX?: PublicKey, authorityAtaY?: PublicKey, programId?: PublicKey): TransactionInstruction;
880
940
 
881
- export { ABSOLUTE_MAX_CURVE_POINTS, ABSOLUTE_MAX_PREFAB_SLOTS, type AllocateCurvePrefabsParams, type AmendOrderParams, 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 CancelOrderParams, 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 DecodedSpreadConfig, type DepositParams, Discriminator, FEE_CONFIG_SEED, FEE_CONFIG_SIZE, HADRON_PROGRAM_ID, Hadron, HadronOrderbook, type InitializeFeeConfigParams, type InitializeParams, type InitializeSpreadConfigParams, Interpolation, MAX_CURVE_UPDATE_OPS, MAX_SETCURVE_POINTS, MIDPRICE_ORACLE_SEED, MIDPRICE_ORACLE_SIZE, type NominateAuthorityParams, OracleMode, type OrderSide, type OrderbookLevel, type OrderbookState, POINT_DATA_SIZE, type PlaceOrderParams, 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 StagedOrder, 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, decodeSpreadConfig, derivePoolAddresses, fromQ32, getConfigAddress, getCurveMetaAddress, getCurvePrefabsAddress, getCurveUpdatesAddress, getFeeConfigAddress, getMidpriceOracleAddress, getOrCreateAta, getSpreadConfigAddress, isSlotInitialized, pctToQ32, spreadBpsToQ32, spreadQ32ToBps, toQ32 };
941
+ export { ABSOLUTE_MAX_CURVE_POINTS, ABSOLUTE_MAX_PREFAB_SLOTS, type AllocateCurvePrefabsParams, type AmendOrderParams, 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 CancelOrderParams, 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 DecodedSpreadConfig, type DepositParams, Discriminator, FEE_CONFIG_SEED, FEE_CONFIG_SIZE, HADRON_PROGRAM_ID, Hadron, HadronOrderbook, type InitializeFeeConfigParams, type InitializeParams, type InitializePoolFeeConfigParams, type InitializeSpreadConfigParams, Interpolation, MAX_CURVE_UPDATE_OPS, MAX_SETCURVE_POINTS, MIDPRICE_ORACLE_SEED, MIDPRICE_ORACLE_SIZE, type NominateAuthorityParams, OracleMode, type OrderSide, type OrderbookLevel, type OrderbookState, POINT_DATA_SIZE, type PlaceOrderParams, 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 StagedOrder, type SwapParams, type SwitchCurveParams, type UpdateBaseSpreadParams, type UpdateDeltaStalenessParams, type UpdateFeeConfigParams, type UpdateMidpriceAndBaseSpreadParams, type UpdateMidpriceParams, type UpdatePoolFeeConfigParams, type UpdateSpreadConfigParams, type WithdrawParams, buildAcceptAuthority, buildAllocateCurvePrefabs, buildApplyCurveUpdates, buildClosePool, buildDeposit, buildInitialize, buildInitializeFeeConfig, buildInitializePoolFeeConfig, buildInitializeSpreadConfig, buildNominateAuthority, buildRotateFeeAdmin, buildSetCurve, buildSetCurveBoth, buildSetPoolState, buildSetQuotingAuthority, buildSetRiskCurve, buildSetRiskCurveAbsolute, buildSetRiskCurveAbsoluteBoth, buildSetRiskCurveBoth, buildSubmitCurveUpdates, buildSwapExactIn, buildSwitchPriceCurve, buildSwitchRiskCurve, buildUpdateBaseSpread, buildUpdateDeltaStaleness, buildUpdateFeeConfig, buildUpdateMidprice, buildUpdateMidpriceAndBaseSpread, buildUpdatePoolFeeConfig, buildUpdateSpreadConfig, buildWithdraw, createWsolAtaInstruction, curvePrefabsSize, decodeActiveCurves, decodeConfig, decodeCurveMeta, decodeCurveSide, decodeCurveUpdates, decodeFeeConfig, decodeMidpriceOracle, decodeSpreadConfig, derivePoolAddresses, fromQ32, getConfigAddress, getCurveMetaAddress, getCurvePrefabsAddress, getCurveUpdatesAddress, getFeeConfigAddress, getMidpriceOracleAddress, getOrCreateAta, getPoolFeeConfigAddress, getSpreadConfigAddress, isNativeMint, isSlotInitialized, pctToQ32, spreadBpsToQ32, spreadQ32ToBps, toQ32, unwrapSolInstruction, wrapSolInstructions };
package/dist/index.js CHANGED
@@ -1,5 +1,55 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/constants/index.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/helpers/sol.ts
2
+
3
+
2
4
  var _web3js = require('@solana/web3.js');
5
+
6
+
7
+
8
+
9
+
10
+ var _spltoken = require('@solana/spl-token');
11
+
12
+
13
+
14
+
15
+ function isNativeMint(mint) {
16
+ return mint.equals(_spltoken.NATIVE_MINT);
17
+ }
18
+ function wrapSolInstructions(user, lamports) {
19
+ const ata = _spltoken.getAssociatedTokenAddressSync.call(void 0, _spltoken.NATIVE_MINT, user, false, _spltoken.TOKEN_PROGRAM_ID);
20
+ return [
21
+ _spltoken.createAssociatedTokenAccountIdempotentInstruction.call(void 0,
22
+ user,
23
+ ata,
24
+ user,
25
+ _spltoken.NATIVE_MINT,
26
+ _spltoken.TOKEN_PROGRAM_ID
27
+ ),
28
+ _web3js.SystemProgram.transfer({
29
+ fromPubkey: user,
30
+ toPubkey: ata,
31
+ lamports
32
+ }),
33
+ _spltoken.createSyncNativeInstruction.call(void 0, ata, _spltoken.TOKEN_PROGRAM_ID)
34
+ ];
35
+ }
36
+ function createWsolAtaInstruction(user) {
37
+ const ata = _spltoken.getAssociatedTokenAddressSync.call(void 0, _spltoken.NATIVE_MINT, user, false, _spltoken.TOKEN_PROGRAM_ID);
38
+ return _spltoken.createAssociatedTokenAccountIdempotentInstruction.call(void 0,
39
+ user,
40
+ ata,
41
+ user,
42
+ _spltoken.NATIVE_MINT,
43
+ _spltoken.TOKEN_PROGRAM_ID
44
+ );
45
+ }
46
+ function unwrapSolInstruction(user) {
47
+ const ata = _spltoken.getAssociatedTokenAddressSync.call(void 0, _spltoken.NATIVE_MINT, user, false, _spltoken.TOKEN_PROGRAM_ID);
48
+ return _spltoken.createCloseAccountInstruction.call(void 0, ata, user, user, [], _spltoken.TOKEN_PROGRAM_ID);
49
+ }
50
+
51
+ // src/constants/index.ts
52
+
3
53
  var HADRON_PROGRAM_ID = new (0, _web3js.PublicKey)(
4
54
  "Q72w4coozA552keKDdeeh2EyQw32qfMFsHPu6cbatom"
5
55
  );
@@ -49,7 +99,9 @@ var Discriminator = {
49
99
  SetPoolState: 21,
50
100
  AllocateCurvePrefabs: 22,
51
101
  SetQuotingAuthority: 23,
52
- RotateFeeAdmin: 24
102
+ RotateFeeAdmin: 24,
103
+ InitializePoolFeeConfig: 25,
104
+ UpdatePoolFeeConfig: 26
53
105
  };
54
106
  var POINT_DATA_SIZE = 21;
55
107
  var CURVE_UPDATE_OP_SIZE = 24;
@@ -59,7 +111,7 @@ function curvePrefabsSize(maxSlots, maxPoints) {
59
111
 
60
112
  // src/helpers/derive.ts
61
113
 
62
- var _spltoken = require('@solana/spl-token');
114
+
63
115
  function seedToBuffer(seed) {
64
116
  const buf = Buffer.alloc(8);
65
117
  buf.writeBigUInt64LE(seed);
@@ -113,6 +165,12 @@ function getCurveUpdatesAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_I
113
165
  function getFeeConfigAddress(programId = HADRON_PROGRAM_ID) {
114
166
  return _web3js.PublicKey.findProgramAddressSync([FEE_CONFIG_SEED], programId);
115
167
  }
168
+ function getPoolFeeConfigAddress(configPda, programId = HADRON_PROGRAM_ID) {
169
+ return _web3js.PublicKey.findProgramAddressSync(
170
+ [FEE_CONFIG_SEED, configPda.toBuffer()],
171
+ programId
172
+ );
173
+ }
116
174
  function getSpreadConfigAddress(configPda, programId = HADRON_PROGRAM_ID) {
117
175
  return _web3js.PublicKey.findProgramAddressSync(
118
176
  [SPREAD_CONFIG_SEED, configPda.toBuffer()],
@@ -251,7 +309,9 @@ function decodeConfig(data) {
251
309
  offset += 1;
252
310
  const oracleMode = buf.readUInt8(offset);
253
311
  offset += 1;
254
- offset += 3;
312
+ const hasPoolFee = buf.readUInt8(offset) !== 0;
313
+ offset += 1;
314
+ offset += 2;
255
315
  const pendingAuthority = new (0, _web3js.PublicKey)(buf.subarray(offset, offset + 32));
256
316
  offset += 32;
257
317
  const nominationExpiry = buf.readBigUInt64LE(offset);
@@ -270,6 +330,7 @@ function decodeConfig(data) {
270
330
  spreadConfigInitialized,
271
331
  deltaStaleness,
272
332
  oracleMode,
333
+ hasPoolFee,
273
334
  pendingAuthority,
274
335
  nominationExpiry,
275
336
  tokenProgramX,
@@ -491,7 +552,7 @@ function buildInitialize(payer, params, programId = HADRON_PROGRAM_ID) {
491
552
  function buildAllocateCurvePrefabs(payer, params, programId = HADRON_PROGRAM_ID) {
492
553
  const maxPrefabSlots = _nullishCoalesce(params.maxPrefabSlots, () => ( DEFAULT_MAX_PREFAB_SLOTS));
493
554
  const maxCurvePoints = _nullishCoalesce(params.maxCurvePoints, () => ( DEFAULT_MAX_CURVE_POINTS));
494
- const data = Buffer.alloc(1 + 8 + 32 + 32 + 1 + 1);
555
+ const data = Buffer.alloc(1 + 8 + 32 + 32 + 1 + 1 + 32);
495
556
  let offset = 0;
496
557
  data.writeUInt8(Discriminator.AllocateCurvePrefabs, offset);
497
558
  offset += 1;
@@ -504,6 +565,8 @@ function buildAllocateCurvePrefabs(payer, params, programId = HADRON_PROGRAM_ID)
504
565
  data.writeUInt8(maxPrefabSlots, offset);
505
566
  offset += 1;
506
567
  data.writeUInt8(maxCurvePoints, offset);
568
+ offset += 1;
569
+ params.authority.toBuffer().copy(data, offset);
507
570
  const [curvePrefabsPda] = _web3js.PublicKey.findProgramAddressSync(
508
571
  [
509
572
  Buffer.from("hadron-curve-prefabs"),
@@ -603,7 +666,7 @@ function buildWithdraw(user, configPda, mintX, mintY, tokenProgramX, tokenProgra
603
666
 
604
667
 
605
668
 
606
- function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID, spreadConfigInitialized = false) {
669
+ function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID, spreadConfigInitialized = false, feeConfigOverride) {
607
670
  const data = Buffer.alloc(1 + 1 + 8 + 8 + 8);
608
671
  let offset = 0;
609
672
  data.writeUInt8(Discriminator.SwapExactIn, offset);
@@ -619,7 +682,7 @@ function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, toke
619
682
  const userX = _spltoken.getAssociatedTokenAddressSync.call(void 0, mintX, user, false, tokenProgramX);
620
683
  const userY = _spltoken.getAssociatedTokenAddressSync.call(void 0, mintY, user, false, tokenProgramY);
621
684
  const [userSource, vaultSource, vaultDest, userDest] = params.isX ? [userX, poolAddresses.vaultX, poolAddresses.vaultY, userY] : [userY, poolAddresses.vaultY, poolAddresses.vaultX, userX];
622
- const [feeConfigPda] = getFeeConfigAddress(programId);
685
+ const feeConfigPda = _nullishCoalesce(feeConfigOverride, () => ( getFeeConfigAddress(programId)[0]));
623
686
  const inputMint = params.isX ? mintX : mintY;
624
687
  const inputMintProgram = params.isX ? tokenProgramX : tokenProgramY;
625
688
  const feeRecipientAta = _spltoken.getAssociatedTokenAddressSync.call(void 0,
@@ -1087,6 +1150,52 @@ function buildRotateFeeAdmin(feeAdmin, params, programId = HADRON_PROGRAM_ID) {
1087
1150
  data
1088
1151
  });
1089
1152
  }
1153
+ function buildInitializePoolFeeConfig(payer, feeAdmin, configPda, params, programId = HADRON_PROGRAM_ID) {
1154
+ const [poolFeeConfigPda] = getPoolFeeConfigAddress(configPda, programId);
1155
+ const [globalFeeConfigPda] = getFeeConfigAddress(programId);
1156
+ const data = Buffer.alloc(1 + 4 + 32 + 32);
1157
+ let offset = 0;
1158
+ data.writeUInt8(Discriminator.InitializePoolFeeConfig, offset);
1159
+ offset += 1;
1160
+ data.writeUInt32LE(params.feePpm, offset);
1161
+ offset += 4;
1162
+ params.feeAdmin.toBuffer().copy(data, offset);
1163
+ offset += 32;
1164
+ params.feeRecipient.toBuffer().copy(data, offset);
1165
+ return new (0, _web3js.TransactionInstruction)({
1166
+ programId,
1167
+ keys: [
1168
+ { pubkey: payer, isSigner: true, isWritable: true },
1169
+ { pubkey: feeAdmin, isSigner: true, isWritable: false },
1170
+ { pubkey: configPda, isSigner: false, isWritable: true },
1171
+ { pubkey: poolFeeConfigPda, isSigner: false, isWritable: true },
1172
+ { pubkey: globalFeeConfigPda, isSigner: false, isWritable: false },
1173
+ { pubkey: _web3js.SystemProgram.programId, isSigner: false, isWritable: false }
1174
+ ],
1175
+ data
1176
+ });
1177
+ }
1178
+ function buildUpdatePoolFeeConfig(feeAdmin, configPda, params, programId = HADRON_PROGRAM_ID) {
1179
+ const [poolFeeConfigPda] = getPoolFeeConfigAddress(configPda, programId);
1180
+ const data = Buffer.alloc(1 + 4 + 32);
1181
+ let offset = 0;
1182
+ data.writeUInt8(Discriminator.UpdatePoolFeeConfig, offset);
1183
+ offset += 1;
1184
+ data.writeUInt32LE(params.feePpm !== null ? params.feePpm : 4294967295, offset);
1185
+ offset += 4;
1186
+ if (params.feeRecipient) {
1187
+ params.feeRecipient.toBuffer().copy(data, offset);
1188
+ }
1189
+ return new (0, _web3js.TransactionInstruction)({
1190
+ programId,
1191
+ keys: [
1192
+ { pubkey: feeAdmin, isSigner: true, isWritable: false },
1193
+ { pubkey: configPda, isSigner: false, isWritable: false },
1194
+ { pubkey: poolFeeConfigPda, isSigner: false, isWritable: true }
1195
+ ],
1196
+ data
1197
+ });
1198
+ }
1090
1199
 
1091
1200
  // src/instructions/spreadConfig.ts
1092
1201
 
@@ -1166,7 +1275,7 @@ function buildUpdateDeltaStaleness(authority, configPda, params, programId = HAD
1166
1275
  data
1167
1276
  });
1168
1277
  }
1169
- function buildClosePool(authority, configPda, midpriceOraclePda, curveMetaPda, curvePrefabsPda, curveUpdatesPda, vaultX, vaultY, tokenProgramX, tokenProgramY, spreadConfigInitialized = false, programId = HADRON_PROGRAM_ID) {
1278
+ function buildClosePool(authority, configPda, midpriceOraclePda, curveMetaPda, curvePrefabsPda, curveUpdatesPda, vaultX, vaultY, tokenProgramX, tokenProgramY, spreadConfigInitialized = false, authorityAtaX, authorityAtaY, programId = HADRON_PROGRAM_ID) {
1170
1279
  const data = Buffer.alloc(1);
1171
1280
  data.writeUInt8(Discriminator.ClosePool, 0);
1172
1281
  const keys = [
@@ -1189,6 +1298,12 @@ function buildClosePool(authority, configPda, midpriceOraclePda, curveMetaPda, c
1189
1298
  isWritable: true
1190
1299
  });
1191
1300
  }
1301
+ if (authorityAtaX) {
1302
+ keys.push({ pubkey: authorityAtaX, isSigner: false, isWritable: true });
1303
+ }
1304
+ if (authorityAtaY) {
1305
+ keys.push({ pubkey: authorityAtaY, isSigner: false, isWritable: true });
1306
+ }
1192
1307
  return new (0, _web3js.TransactionInstruction)({ programId, keys, data });
1193
1308
  }
1194
1309
 
@@ -1290,7 +1405,8 @@ var Hadron = class _Hadron {
1290
1405
  mintX: params.mintX,
1291
1406
  mintY: params.mintY,
1292
1407
  maxPrefabSlots,
1293
- maxCurvePoints
1408
+ maxCurvePoints,
1409
+ authority: params.authority
1294
1410
  };
1295
1411
  const instructions = [];
1296
1412
  const size = curvePrefabsSize(maxPrefabSlots, maxCurvePoints);
@@ -1633,7 +1749,7 @@ var Hadron = class _Hadron {
1633
1749
  return decoded.triggers;
1634
1750
  }
1635
1751
  /** Build close pool instruction. */
1636
- closePool(authority) {
1752
+ closePool(authority, authorityAtaX, authorityAtaY) {
1637
1753
  return buildClosePool(
1638
1754
  authority,
1639
1755
  this.poolAddress,
@@ -1646,9 +1762,66 @@ var Hadron = class _Hadron {
1646
1762
  this.config.tokenProgramX,
1647
1763
  this.config.tokenProgramY,
1648
1764
  this.config.spreadConfigInitialized,
1765
+ authorityAtaX,
1766
+ authorityAtaY,
1649
1767
  this.programId
1650
1768
  );
1651
1769
  }
1770
+ // ==========================================================================
1771
+ // SOL Wrapping Convenience Methods
1772
+ // ==========================================================================
1773
+ /**
1774
+ * Build deposit instructions with automatic SOL wrapping.
1775
+ * If mint X or Y is native SOL, prepends wrap instructions for that side.
1776
+ */
1777
+ depositSol(user, params) {
1778
+ const ixs = [];
1779
+ if (isNativeMint(this.config.mintX) && params.amountX > 0n) {
1780
+ ixs.push(...wrapSolInstructions(user, params.amountX));
1781
+ }
1782
+ if (isNativeMint(this.config.mintY) && params.amountY > 0n) {
1783
+ ixs.push(...wrapSolInstructions(user, params.amountY));
1784
+ }
1785
+ ixs.push(this.deposit(user, params));
1786
+ return ixs;
1787
+ }
1788
+ /**
1789
+ * Build withdraw instructions with automatic SOL unwrapping.
1790
+ * Creates wSOL ATA (so program can transfer into it), withdraws, then closes ATA.
1791
+ */
1792
+ withdrawSol(user, params) {
1793
+ const ixs = [];
1794
+ const hasSol = isNativeMint(this.config.mintX) || isNativeMint(this.config.mintY);
1795
+ if (hasSol) {
1796
+ ixs.push(createWsolAtaInstruction(user));
1797
+ }
1798
+ ixs.push(this.withdraw(user, params));
1799
+ if (hasSol) {
1800
+ ixs.push(unwrapSolInstruction(user));
1801
+ }
1802
+ return ixs;
1803
+ }
1804
+ /**
1805
+ * Build swap instructions with automatic SOL wrapping/unwrapping.
1806
+ * Wraps SOL if the input side is native, unwraps if the output side is native.
1807
+ */
1808
+ swapSol(user, params) {
1809
+ const ixs = [];
1810
+ const inputIsX = params.isX;
1811
+ const inputMint = inputIsX ? this.config.mintX : this.config.mintY;
1812
+ const outputMint = inputIsX ? this.config.mintY : this.config.mintX;
1813
+ if (isNativeMint(inputMint)) {
1814
+ ixs.push(...wrapSolInstructions(user, params.amountIn));
1815
+ }
1816
+ if (isNativeMint(outputMint)) {
1817
+ ixs.push(createWsolAtaInstruction(user));
1818
+ }
1819
+ ixs.push(this.swap(user, params));
1820
+ if (isNativeMint(outputMint)) {
1821
+ ixs.push(unwrapSolInstruction(user));
1822
+ }
1823
+ return ixs;
1824
+ }
1652
1825
  };
1653
1826
 
1654
1827
  // src/orderbook.ts
@@ -2325,5 +2498,13 @@ async function getOrCreateAta(connection, mint, owner, payer, tokenProgram = _sp
2325
2498
 
2326
2499
 
2327
2500
 
2328
- exports.ABSOLUTE_MAX_CURVE_POINTS = ABSOLUTE_MAX_CURVE_POINTS; exports.ABSOLUTE_MAX_PREFAB_SLOTS = ABSOLUTE_MAX_PREFAB_SLOTS; exports.CONFIG_SEED = CONFIG_SEED; exports.CONFIG_SIZE = CONFIG_SIZE; exports.CURVE_META_SEED = CURVE_META_SEED; exports.CURVE_META_SIZE = CURVE_META_SIZE; exports.CURVE_POINT_LEN = CURVE_POINT_LEN; exports.CURVE_PREFABS_SEED = CURVE_PREFABS_SEED; exports.CURVE_SIDE_HEADER = CURVE_SIDE_HEADER; exports.CURVE_UPDATES_SEED = CURVE_UPDATES_SEED; exports.CURVE_UPDATES_SIZE = CURVE_UPDATES_SIZE; exports.CURVE_UPDATE_OP_SIZE = CURVE_UPDATE_OP_SIZE; exports.CurveType = CurveType; exports.CurveUpdateOpKind = CurveUpdateOpKind; exports.CurveXMode = CurveXMode; exports.DEFAULT_MAX_CURVE_POINTS = DEFAULT_MAX_CURVE_POINTS; exports.DEFAULT_MAX_PREFAB_SLOTS = DEFAULT_MAX_PREFAB_SLOTS; exports.Discriminator = Discriminator; exports.FEE_CONFIG_SEED = FEE_CONFIG_SEED; exports.FEE_CONFIG_SIZE = FEE_CONFIG_SIZE; exports.HADRON_PROGRAM_ID = HADRON_PROGRAM_ID; exports.Hadron = Hadron; exports.HadronOrderbook = HadronOrderbook; exports.Interpolation = Interpolation; exports.MAX_CURVE_UPDATE_OPS = MAX_CURVE_UPDATE_OPS; exports.MAX_SETCURVE_POINTS = MAX_SETCURVE_POINTS; exports.MIDPRICE_ORACLE_SEED = MIDPRICE_ORACLE_SEED; exports.MIDPRICE_ORACLE_SIZE = MIDPRICE_ORACLE_SIZE; exports.OracleMode = OracleMode; exports.POINT_DATA_SIZE = POINT_DATA_SIZE; exports.PoolState = PoolState; exports.Q32_ONE = Q32_ONE; exports.RiskMode = RiskMode; exports.SPREAD_CONFIG_SEED = SPREAD_CONFIG_SEED; exports.Side = Side; exports.buildAcceptAuthority = buildAcceptAuthority; exports.buildAllocateCurvePrefabs = buildAllocateCurvePrefabs; exports.buildApplyCurveUpdates = buildApplyCurveUpdates; exports.buildClosePool = buildClosePool; exports.buildDeposit = buildDeposit; exports.buildInitialize = buildInitialize; exports.buildInitializeFeeConfig = buildInitializeFeeConfig; exports.buildInitializeSpreadConfig = buildInitializeSpreadConfig; exports.buildNominateAuthority = buildNominateAuthority; exports.buildRotateFeeAdmin = buildRotateFeeAdmin; exports.buildSetCurve = buildSetCurve; exports.buildSetCurveBoth = buildSetCurveBoth; exports.buildSetPoolState = buildSetPoolState; exports.buildSetQuotingAuthority = buildSetQuotingAuthority; exports.buildSetRiskCurve = buildSetRiskCurve; exports.buildSetRiskCurveAbsolute = buildSetRiskCurveAbsolute; exports.buildSetRiskCurveAbsoluteBoth = buildSetRiskCurveAbsoluteBoth; exports.buildSetRiskCurveBoth = buildSetRiskCurveBoth; exports.buildSubmitCurveUpdates = buildSubmitCurveUpdates; exports.buildSwapExactIn = buildSwapExactIn; exports.buildSwitchPriceCurve = buildSwitchPriceCurve; exports.buildSwitchRiskCurve = buildSwitchRiskCurve; exports.buildUpdateBaseSpread = buildUpdateBaseSpread; exports.buildUpdateDeltaStaleness = buildUpdateDeltaStaleness; exports.buildUpdateFeeConfig = buildUpdateFeeConfig; exports.buildUpdateMidprice = buildUpdateMidprice; exports.buildUpdateMidpriceAndBaseSpread = buildUpdateMidpriceAndBaseSpread; exports.buildUpdateSpreadConfig = buildUpdateSpreadConfig; exports.buildWithdraw = buildWithdraw; exports.curvePrefabsSize = curvePrefabsSize; exports.decodeActiveCurves = decodeActiveCurves; exports.decodeConfig = decodeConfig; exports.decodeCurveMeta = decodeCurveMeta; exports.decodeCurveSide = decodeCurveSide; exports.decodeCurveUpdates = decodeCurveUpdates; exports.decodeFeeConfig = decodeFeeConfig; exports.decodeMidpriceOracle = decodeMidpriceOracle; exports.decodeSpreadConfig = decodeSpreadConfig; exports.derivePoolAddresses = derivePoolAddresses; exports.fromQ32 = fromQ32; exports.getConfigAddress = getConfigAddress; exports.getCurveMetaAddress = getCurveMetaAddress; exports.getCurvePrefabsAddress = getCurvePrefabsAddress; exports.getCurveUpdatesAddress = getCurveUpdatesAddress; exports.getFeeConfigAddress = getFeeConfigAddress; exports.getMidpriceOracleAddress = getMidpriceOracleAddress; exports.getOrCreateAta = getOrCreateAta; exports.getSpreadConfigAddress = getSpreadConfigAddress; exports.isSlotInitialized = isSlotInitialized; exports.pctToQ32 = pctToQ32; exports.spreadBpsToQ32 = spreadBpsToQ32; exports.spreadQ32ToBps = spreadQ32ToBps; exports.toQ32 = toQ32;
2501
+
2502
+
2503
+
2504
+
2505
+
2506
+
2507
+
2508
+
2509
+ exports.ABSOLUTE_MAX_CURVE_POINTS = ABSOLUTE_MAX_CURVE_POINTS; exports.ABSOLUTE_MAX_PREFAB_SLOTS = ABSOLUTE_MAX_PREFAB_SLOTS; exports.CONFIG_SEED = CONFIG_SEED; exports.CONFIG_SIZE = CONFIG_SIZE; exports.CURVE_META_SEED = CURVE_META_SEED; exports.CURVE_META_SIZE = CURVE_META_SIZE; exports.CURVE_POINT_LEN = CURVE_POINT_LEN; exports.CURVE_PREFABS_SEED = CURVE_PREFABS_SEED; exports.CURVE_SIDE_HEADER = CURVE_SIDE_HEADER; exports.CURVE_UPDATES_SEED = CURVE_UPDATES_SEED; exports.CURVE_UPDATES_SIZE = CURVE_UPDATES_SIZE; exports.CURVE_UPDATE_OP_SIZE = CURVE_UPDATE_OP_SIZE; exports.CurveType = CurveType; exports.CurveUpdateOpKind = CurveUpdateOpKind; exports.CurveXMode = CurveXMode; exports.DEFAULT_MAX_CURVE_POINTS = DEFAULT_MAX_CURVE_POINTS; exports.DEFAULT_MAX_PREFAB_SLOTS = DEFAULT_MAX_PREFAB_SLOTS; exports.Discriminator = Discriminator; exports.FEE_CONFIG_SEED = FEE_CONFIG_SEED; exports.FEE_CONFIG_SIZE = FEE_CONFIG_SIZE; exports.HADRON_PROGRAM_ID = HADRON_PROGRAM_ID; exports.Hadron = Hadron; exports.HadronOrderbook = HadronOrderbook; exports.Interpolation = Interpolation; exports.MAX_CURVE_UPDATE_OPS = MAX_CURVE_UPDATE_OPS; exports.MAX_SETCURVE_POINTS = MAX_SETCURVE_POINTS; exports.MIDPRICE_ORACLE_SEED = MIDPRICE_ORACLE_SEED; exports.MIDPRICE_ORACLE_SIZE = MIDPRICE_ORACLE_SIZE; exports.NATIVE_MINT = _spltoken.NATIVE_MINT; exports.OracleMode = OracleMode; exports.POINT_DATA_SIZE = POINT_DATA_SIZE; exports.PoolState = PoolState; exports.Q32_ONE = Q32_ONE; exports.RiskMode = RiskMode; exports.SPREAD_CONFIG_SEED = SPREAD_CONFIG_SEED; exports.Side = Side; exports.buildAcceptAuthority = buildAcceptAuthority; exports.buildAllocateCurvePrefabs = buildAllocateCurvePrefabs; exports.buildApplyCurveUpdates = buildApplyCurveUpdates; exports.buildClosePool = buildClosePool; exports.buildDeposit = buildDeposit; exports.buildInitialize = buildInitialize; exports.buildInitializeFeeConfig = buildInitializeFeeConfig; exports.buildInitializePoolFeeConfig = buildInitializePoolFeeConfig; exports.buildInitializeSpreadConfig = buildInitializeSpreadConfig; exports.buildNominateAuthority = buildNominateAuthority; exports.buildRotateFeeAdmin = buildRotateFeeAdmin; exports.buildSetCurve = buildSetCurve; exports.buildSetCurveBoth = buildSetCurveBoth; exports.buildSetPoolState = buildSetPoolState; exports.buildSetQuotingAuthority = buildSetQuotingAuthority; exports.buildSetRiskCurve = buildSetRiskCurve; exports.buildSetRiskCurveAbsolute = buildSetRiskCurveAbsolute; exports.buildSetRiskCurveAbsoluteBoth = buildSetRiskCurveAbsoluteBoth; exports.buildSetRiskCurveBoth = buildSetRiskCurveBoth; exports.buildSubmitCurveUpdates = buildSubmitCurveUpdates; exports.buildSwapExactIn = buildSwapExactIn; exports.buildSwitchPriceCurve = buildSwitchPriceCurve; exports.buildSwitchRiskCurve = buildSwitchRiskCurve; exports.buildUpdateBaseSpread = buildUpdateBaseSpread; exports.buildUpdateDeltaStaleness = buildUpdateDeltaStaleness; exports.buildUpdateFeeConfig = buildUpdateFeeConfig; exports.buildUpdateMidprice = buildUpdateMidprice; exports.buildUpdateMidpriceAndBaseSpread = buildUpdateMidpriceAndBaseSpread; exports.buildUpdatePoolFeeConfig = buildUpdatePoolFeeConfig; exports.buildUpdateSpreadConfig = buildUpdateSpreadConfig; exports.buildWithdraw = buildWithdraw; exports.createWsolAtaInstruction = createWsolAtaInstruction; exports.curvePrefabsSize = curvePrefabsSize; exports.decodeActiveCurves = decodeActiveCurves; exports.decodeConfig = decodeConfig; exports.decodeCurveMeta = decodeCurveMeta; exports.decodeCurveSide = decodeCurveSide; exports.decodeCurveUpdates = decodeCurveUpdates; exports.decodeFeeConfig = decodeFeeConfig; exports.decodeMidpriceOracle = decodeMidpriceOracle; exports.decodeSpreadConfig = decodeSpreadConfig; exports.derivePoolAddresses = derivePoolAddresses; exports.fromQ32 = fromQ32; exports.getConfigAddress = getConfigAddress; exports.getCurveMetaAddress = getCurveMetaAddress; exports.getCurvePrefabsAddress = getCurvePrefabsAddress; exports.getCurveUpdatesAddress = getCurveUpdatesAddress; exports.getFeeConfigAddress = getFeeConfigAddress; exports.getMidpriceOracleAddress = getMidpriceOracleAddress; exports.getOrCreateAta = getOrCreateAta; exports.getPoolFeeConfigAddress = getPoolFeeConfigAddress; exports.getSpreadConfigAddress = getSpreadConfigAddress; exports.isNativeMint = isNativeMint; exports.isSlotInitialized = isSlotInitialized; exports.pctToQ32 = pctToQ32; exports.spreadBpsToQ32 = spreadBpsToQ32; exports.spreadQ32ToBps = spreadQ32ToBps; exports.toQ32 = toQ32; exports.unwrapSolInstruction = unwrapSolInstruction; exports.wrapSolInstructions = wrapSolInstructions;
2329
2510
  //# sourceMappingURL=index.js.map