@hadron-fi/sdk 0.4.0 → 0.4.2
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 +48 -6
- package/dist/index.d.ts +48 -6
- package/dist/index.js +135 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +135 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -57,6 +57,7 @@ interface DecodedConfig {
|
|
|
57
57
|
spreadConfigInitialized: boolean;
|
|
58
58
|
deltaStaleness: number;
|
|
59
59
|
oracleMode: OracleMode;
|
|
60
|
+
hasPoolFee: boolean;
|
|
60
61
|
pendingAuthority: PublicKey;
|
|
61
62
|
nominationExpiry: bigint;
|
|
62
63
|
tokenProgramX: PublicKey;
|
|
@@ -256,6 +257,17 @@ interface UpdateFeeConfigParams {
|
|
|
256
257
|
interface RotateFeeAdminParams {
|
|
257
258
|
newFeeAdmin: PublicKey;
|
|
258
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
|
+
}
|
|
259
271
|
interface SetPoolStateParams {
|
|
260
272
|
newState: PoolState;
|
|
261
273
|
}
|
|
@@ -278,6 +290,7 @@ interface AllocateCurvePrefabsParams {
|
|
|
278
290
|
mintY: PublicKey;
|
|
279
291
|
maxPrefabSlots?: number;
|
|
280
292
|
maxCurvePoints?: number;
|
|
293
|
+
authority: PublicKey;
|
|
281
294
|
}
|
|
282
295
|
type OrderSide = "bid" | "ask";
|
|
283
296
|
interface PlaceOrderParams {
|
|
@@ -384,6 +397,13 @@ declare class Hadron {
|
|
|
384
397
|
poolAddress: PublicKey;
|
|
385
398
|
seed: bigint;
|
|
386
399
|
};
|
|
400
|
+
/**
|
|
401
|
+
* Build idempotent create-ATA instructions for the fee recipient for both mints.
|
|
402
|
+
*
|
|
403
|
+
* These are no-ops on-chain if the ATAs already exist. Include them alongside
|
|
404
|
+
* initialize or first deposit to ensure swaps don't fail due to missing fee ATAs.
|
|
405
|
+
*/
|
|
406
|
+
static buildFeeRecipientAtaIxs(payer: PublicKey, feeRecipient: PublicKey, mintX: PublicKey, mintY: PublicKey, tokenProgramX?: PublicKey, tokenProgramY?: PublicKey): TransactionInstruction[];
|
|
387
407
|
/** Generate a random u64 seed. */
|
|
388
408
|
private static randomSeed;
|
|
389
409
|
/** Re-fetch all account state from the chain. */
|
|
@@ -468,7 +488,7 @@ declare class Hadron {
|
|
|
468
488
|
/** Fetch and decode the current spread config triggers from chain. */
|
|
469
489
|
private fetchSpreadTriggers;
|
|
470
490
|
/** Build close pool instruction. */
|
|
471
|
-
closePool(authority: PublicKey): TransactionInstruction;
|
|
491
|
+
closePool(authority: PublicKey, authorityAtaX?: PublicKey, authorityAtaY?: PublicKey): TransactionInstruction;
|
|
472
492
|
/**
|
|
473
493
|
* Build deposit instructions with automatic SOL wrapping.
|
|
474
494
|
* If mint X or Y is native SOL, prepends wrap instructions for that side.
|
|
@@ -663,6 +683,8 @@ declare const Discriminator: {
|
|
|
663
683
|
readonly AllocateCurvePrefabs: 22;
|
|
664
684
|
readonly SetQuotingAuthority: 23;
|
|
665
685
|
readonly RotateFeeAdmin: 24;
|
|
686
|
+
readonly InitializePoolFeeConfig: 25;
|
|
687
|
+
readonly UpdatePoolFeeConfig: 26;
|
|
666
688
|
};
|
|
667
689
|
/** Per-point data in SetCurve/SetRiskCurve: u64 + u64 + u8 + 4 params = 21 bytes */
|
|
668
690
|
declare const POINT_DATA_SIZE = 21;
|
|
@@ -701,6 +723,7 @@ declare function getCurveMetaAddress(seed: bigint, mintX: PublicKey, mintY: Publ
|
|
|
701
723
|
declare function getCurvePrefabsAddress(seed: bigint, mintX: PublicKey, mintY: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
702
724
|
declare function getCurveUpdatesAddress(seed: bigint, mintX: PublicKey, mintY: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
703
725
|
declare function getFeeConfigAddress(programId?: PublicKey): [PublicKey, number];
|
|
726
|
+
declare function getPoolFeeConfigAddress(configPda: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
704
727
|
declare function getSpreadConfigAddress(configPda: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
705
728
|
/**
|
|
706
729
|
* Derive all PDA addresses for a pool.
|
|
@@ -734,9 +757,18 @@ declare function wrapSolInstructions(user: PublicKey, lamports: bigint): Transac
|
|
|
734
757
|
*/
|
|
735
758
|
declare function createWsolAtaInstruction(user: PublicKey): TransactionInstruction;
|
|
736
759
|
/**
|
|
737
|
-
* Build
|
|
760
|
+
* Build instructions to unwrap wSOL — closes the ATA (sending lamports back to
|
|
761
|
+
* the user) and immediately re-creates it so the ATA remains open for future
|
|
762
|
+
* deposits (e.g. fee collection).
|
|
763
|
+
*/
|
|
764
|
+
declare function unwrapSolInstructions(user: PublicKey): TransactionInstruction[];
|
|
765
|
+
/**
|
|
766
|
+
* Build idempotent create-ATA instructions for the fee recipient for both mints.
|
|
767
|
+
*
|
|
768
|
+
* These are no-ops if the ATAs already exist. Include them in the initialize or
|
|
769
|
+
* first deposit transaction to ensure swaps don't fail due to missing fee ATAs.
|
|
738
770
|
*/
|
|
739
|
-
declare function
|
|
771
|
+
declare function buildFeeRecipientAtaIxs(payer: PublicKey, feeRecipient: PublicKey, mintX: PublicKey, mintY: PublicKey, tokenProgramX?: PublicKey, tokenProgramY?: PublicKey): TransactionInstruction[];
|
|
740
772
|
|
|
741
773
|
/**
|
|
742
774
|
* Get the ATA address, and optionally return a create instruction if it doesn't exist.
|
|
@@ -778,7 +810,7 @@ declare function buildWithdraw(user: PublicKey, configPda: PublicKey, mintX: Pub
|
|
|
778
810
|
*
|
|
779
811
|
* When spread config is initialized: spread_config (#16) + instructions_sysvar (#17).
|
|
780
812
|
*/
|
|
781
|
-
declare function buildSwapExactIn(user: PublicKey, poolAddresses: PoolAddresses, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, params: SwapParams, programId?: PublicKey, spreadConfigInitialized?: boolean): TransactionInstruction;
|
|
813
|
+
declare function buildSwapExactIn(user: PublicKey, poolAddresses: PoolAddresses, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, params: SwapParams, programId?: PublicKey, spreadConfigInitialized?: boolean, feeConfigOverride?: PublicKey): TransactionInstruction;
|
|
782
814
|
|
|
783
815
|
/**
|
|
784
816
|
* Build a SetCurve instruction (price curve).
|
|
@@ -882,6 +914,16 @@ declare function buildUpdateFeeConfig(feeAdmin: PublicKey, params: UpdateFeeConf
|
|
|
882
914
|
* Accounts: fee_admin (signer), fee_config (mut).
|
|
883
915
|
*/
|
|
884
916
|
declare function buildRotateFeeAdmin(feeAdmin: PublicKey, params: RotateFeeAdminParams, programId?: PublicKey): TransactionInstruction;
|
|
917
|
+
/**
|
|
918
|
+
* Build an InitializePoolFeeConfig instruction.
|
|
919
|
+
* Accounts: payer, fee_admin, config, pool_fee_config, global_fee_config, system_program.
|
|
920
|
+
*/
|
|
921
|
+
declare function buildInitializePoolFeeConfig(payer: PublicKey, feeAdmin: PublicKey, configPda: PublicKey, params: InitializePoolFeeConfigParams, programId?: PublicKey): TransactionInstruction;
|
|
922
|
+
/**
|
|
923
|
+
* Build an UpdatePoolFeeConfig instruction.
|
|
924
|
+
* Accounts: fee_admin, config, pool_fee_config.
|
|
925
|
+
*/
|
|
926
|
+
declare function buildUpdatePoolFeeConfig(feeAdmin: PublicKey, configPda: PublicKey, params: UpdatePoolFeeConfigParams, programId?: PublicKey): TransactionInstruction;
|
|
885
927
|
|
|
886
928
|
/**
|
|
887
929
|
* Build an InitializeSpreadConfig instruction.
|
|
@@ -910,6 +952,6 @@ declare function buildUpdateDeltaStaleness(authority: PublicKey, configPda: Publ
|
|
|
910
952
|
* curve_updates, vault_x, vault_y, token_program_x, token_program_y,
|
|
911
953
|
* [optional: spread_config if initialized].
|
|
912
954
|
*/
|
|
913
|
-
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;
|
|
955
|
+
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;
|
|
914
956
|
|
|
915
|
-
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, createWsolAtaInstruction, curvePrefabsSize, decodeActiveCurves, decodeConfig, decodeCurveMeta, decodeCurveSide, decodeCurveUpdates, decodeFeeConfig, decodeMidpriceOracle, decodeSpreadConfig, derivePoolAddresses, fromQ32, getConfigAddress, getCurveMetaAddress, getCurvePrefabsAddress, getCurveUpdatesAddress, getFeeConfigAddress, getMidpriceOracleAddress, getOrCreateAta, getSpreadConfigAddress, isNativeMint, isSlotInitialized, pctToQ32, spreadBpsToQ32, spreadQ32ToBps, toQ32,
|
|
957
|
+
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, buildFeeRecipientAtaIxs, 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, unwrapSolInstructions, wrapSolInstructions };
|
package/dist/index.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ interface DecodedConfig {
|
|
|
57
57
|
spreadConfigInitialized: boolean;
|
|
58
58
|
deltaStaleness: number;
|
|
59
59
|
oracleMode: OracleMode;
|
|
60
|
+
hasPoolFee: boolean;
|
|
60
61
|
pendingAuthority: PublicKey;
|
|
61
62
|
nominationExpiry: bigint;
|
|
62
63
|
tokenProgramX: PublicKey;
|
|
@@ -256,6 +257,17 @@ interface UpdateFeeConfigParams {
|
|
|
256
257
|
interface RotateFeeAdminParams {
|
|
257
258
|
newFeeAdmin: PublicKey;
|
|
258
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
|
+
}
|
|
259
271
|
interface SetPoolStateParams {
|
|
260
272
|
newState: PoolState;
|
|
261
273
|
}
|
|
@@ -278,6 +290,7 @@ interface AllocateCurvePrefabsParams {
|
|
|
278
290
|
mintY: PublicKey;
|
|
279
291
|
maxPrefabSlots?: number;
|
|
280
292
|
maxCurvePoints?: number;
|
|
293
|
+
authority: PublicKey;
|
|
281
294
|
}
|
|
282
295
|
type OrderSide = "bid" | "ask";
|
|
283
296
|
interface PlaceOrderParams {
|
|
@@ -384,6 +397,13 @@ declare class Hadron {
|
|
|
384
397
|
poolAddress: PublicKey;
|
|
385
398
|
seed: bigint;
|
|
386
399
|
};
|
|
400
|
+
/**
|
|
401
|
+
* Build idempotent create-ATA instructions for the fee recipient for both mints.
|
|
402
|
+
*
|
|
403
|
+
* These are no-ops on-chain if the ATAs already exist. Include them alongside
|
|
404
|
+
* initialize or first deposit to ensure swaps don't fail due to missing fee ATAs.
|
|
405
|
+
*/
|
|
406
|
+
static buildFeeRecipientAtaIxs(payer: PublicKey, feeRecipient: PublicKey, mintX: PublicKey, mintY: PublicKey, tokenProgramX?: PublicKey, tokenProgramY?: PublicKey): TransactionInstruction[];
|
|
387
407
|
/** Generate a random u64 seed. */
|
|
388
408
|
private static randomSeed;
|
|
389
409
|
/** Re-fetch all account state from the chain. */
|
|
@@ -468,7 +488,7 @@ declare class Hadron {
|
|
|
468
488
|
/** Fetch and decode the current spread config triggers from chain. */
|
|
469
489
|
private fetchSpreadTriggers;
|
|
470
490
|
/** Build close pool instruction. */
|
|
471
|
-
closePool(authority: PublicKey): TransactionInstruction;
|
|
491
|
+
closePool(authority: PublicKey, authorityAtaX?: PublicKey, authorityAtaY?: PublicKey): TransactionInstruction;
|
|
472
492
|
/**
|
|
473
493
|
* Build deposit instructions with automatic SOL wrapping.
|
|
474
494
|
* If mint X or Y is native SOL, prepends wrap instructions for that side.
|
|
@@ -663,6 +683,8 @@ declare const Discriminator: {
|
|
|
663
683
|
readonly AllocateCurvePrefabs: 22;
|
|
664
684
|
readonly SetQuotingAuthority: 23;
|
|
665
685
|
readonly RotateFeeAdmin: 24;
|
|
686
|
+
readonly InitializePoolFeeConfig: 25;
|
|
687
|
+
readonly UpdatePoolFeeConfig: 26;
|
|
666
688
|
};
|
|
667
689
|
/** Per-point data in SetCurve/SetRiskCurve: u64 + u64 + u8 + 4 params = 21 bytes */
|
|
668
690
|
declare const POINT_DATA_SIZE = 21;
|
|
@@ -701,6 +723,7 @@ declare function getCurveMetaAddress(seed: bigint, mintX: PublicKey, mintY: Publ
|
|
|
701
723
|
declare function getCurvePrefabsAddress(seed: bigint, mintX: PublicKey, mintY: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
702
724
|
declare function getCurveUpdatesAddress(seed: bigint, mintX: PublicKey, mintY: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
703
725
|
declare function getFeeConfigAddress(programId?: PublicKey): [PublicKey, number];
|
|
726
|
+
declare function getPoolFeeConfigAddress(configPda: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
704
727
|
declare function getSpreadConfigAddress(configPda: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
705
728
|
/**
|
|
706
729
|
* Derive all PDA addresses for a pool.
|
|
@@ -734,9 +757,18 @@ declare function wrapSolInstructions(user: PublicKey, lamports: bigint): Transac
|
|
|
734
757
|
*/
|
|
735
758
|
declare function createWsolAtaInstruction(user: PublicKey): TransactionInstruction;
|
|
736
759
|
/**
|
|
737
|
-
* Build
|
|
760
|
+
* Build instructions to unwrap wSOL — closes the ATA (sending lamports back to
|
|
761
|
+
* the user) and immediately re-creates it so the ATA remains open for future
|
|
762
|
+
* deposits (e.g. fee collection).
|
|
763
|
+
*/
|
|
764
|
+
declare function unwrapSolInstructions(user: PublicKey): TransactionInstruction[];
|
|
765
|
+
/**
|
|
766
|
+
* Build idempotent create-ATA instructions for the fee recipient for both mints.
|
|
767
|
+
*
|
|
768
|
+
* These are no-ops if the ATAs already exist. Include them in the initialize or
|
|
769
|
+
* first deposit transaction to ensure swaps don't fail due to missing fee ATAs.
|
|
738
770
|
*/
|
|
739
|
-
declare function
|
|
771
|
+
declare function buildFeeRecipientAtaIxs(payer: PublicKey, feeRecipient: PublicKey, mintX: PublicKey, mintY: PublicKey, tokenProgramX?: PublicKey, tokenProgramY?: PublicKey): TransactionInstruction[];
|
|
740
772
|
|
|
741
773
|
/**
|
|
742
774
|
* Get the ATA address, and optionally return a create instruction if it doesn't exist.
|
|
@@ -778,7 +810,7 @@ declare function buildWithdraw(user: PublicKey, configPda: PublicKey, mintX: Pub
|
|
|
778
810
|
*
|
|
779
811
|
* When spread config is initialized: spread_config (#16) + instructions_sysvar (#17).
|
|
780
812
|
*/
|
|
781
|
-
declare function buildSwapExactIn(user: PublicKey, poolAddresses: PoolAddresses, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, params: SwapParams, programId?: PublicKey, spreadConfigInitialized?: boolean): TransactionInstruction;
|
|
813
|
+
declare function buildSwapExactIn(user: PublicKey, poolAddresses: PoolAddresses, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, params: SwapParams, programId?: PublicKey, spreadConfigInitialized?: boolean, feeConfigOverride?: PublicKey): TransactionInstruction;
|
|
782
814
|
|
|
783
815
|
/**
|
|
784
816
|
* Build a SetCurve instruction (price curve).
|
|
@@ -882,6 +914,16 @@ declare function buildUpdateFeeConfig(feeAdmin: PublicKey, params: UpdateFeeConf
|
|
|
882
914
|
* Accounts: fee_admin (signer), fee_config (mut).
|
|
883
915
|
*/
|
|
884
916
|
declare function buildRotateFeeAdmin(feeAdmin: PublicKey, params: RotateFeeAdminParams, programId?: PublicKey): TransactionInstruction;
|
|
917
|
+
/**
|
|
918
|
+
* Build an InitializePoolFeeConfig instruction.
|
|
919
|
+
* Accounts: payer, fee_admin, config, pool_fee_config, global_fee_config, system_program.
|
|
920
|
+
*/
|
|
921
|
+
declare function buildInitializePoolFeeConfig(payer: PublicKey, feeAdmin: PublicKey, configPda: PublicKey, params: InitializePoolFeeConfigParams, programId?: PublicKey): TransactionInstruction;
|
|
922
|
+
/**
|
|
923
|
+
* Build an UpdatePoolFeeConfig instruction.
|
|
924
|
+
* Accounts: fee_admin, config, pool_fee_config.
|
|
925
|
+
*/
|
|
926
|
+
declare function buildUpdatePoolFeeConfig(feeAdmin: PublicKey, configPda: PublicKey, params: UpdatePoolFeeConfigParams, programId?: PublicKey): TransactionInstruction;
|
|
885
927
|
|
|
886
928
|
/**
|
|
887
929
|
* Build an InitializeSpreadConfig instruction.
|
|
@@ -910,6 +952,6 @@ declare function buildUpdateDeltaStaleness(authority: PublicKey, configPda: Publ
|
|
|
910
952
|
* curve_updates, vault_x, vault_y, token_program_x, token_program_y,
|
|
911
953
|
* [optional: spread_config if initialized].
|
|
912
954
|
*/
|
|
913
|
-
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;
|
|
955
|
+
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;
|
|
914
956
|
|
|
915
|
-
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, createWsolAtaInstruction, curvePrefabsSize, decodeActiveCurves, decodeConfig, decodeCurveMeta, decodeCurveSide, decodeCurveUpdates, decodeFeeConfig, decodeMidpriceOracle, decodeSpreadConfig, derivePoolAddresses, fromQ32, getConfigAddress, getCurveMetaAddress, getCurvePrefabsAddress, getCurveUpdatesAddress, getFeeConfigAddress, getMidpriceOracleAddress, getOrCreateAta, getSpreadConfigAddress, isNativeMint, isSlotInitialized, pctToQ32, spreadBpsToQ32, spreadQ32ToBps, toQ32,
|
|
957
|
+
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, buildFeeRecipientAtaIxs, 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, unwrapSolInstructions, wrapSolInstructions };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/hadron.ts
|
|
2
|
+
var _spltoken = require('@solana/spl-token');
|
|
3
|
+
|
|
4
|
+
// src/helpers/sol.ts
|
|
2
5
|
|
|
3
6
|
|
|
4
7
|
var _web3js = require('@solana/web3.js');
|
|
@@ -7,7 +10,7 @@ var _web3js = require('@solana/web3.js');
|
|
|
7
10
|
|
|
8
11
|
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
|
|
11
14
|
|
|
12
15
|
|
|
13
16
|
|
|
@@ -43,9 +46,38 @@ function createWsolAtaInstruction(user) {
|
|
|
43
46
|
_spltoken.TOKEN_PROGRAM_ID
|
|
44
47
|
);
|
|
45
48
|
}
|
|
46
|
-
function
|
|
49
|
+
function unwrapSolInstructions(user) {
|
|
47
50
|
const ata = _spltoken.getAssociatedTokenAddressSync.call(void 0, _spltoken.NATIVE_MINT, user, false, _spltoken.TOKEN_PROGRAM_ID);
|
|
48
|
-
return
|
|
51
|
+
return [
|
|
52
|
+
_spltoken.createCloseAccountInstruction.call(void 0, ata, user, user, [], _spltoken.TOKEN_PROGRAM_ID),
|
|
53
|
+
_spltoken.createAssociatedTokenAccountIdempotentInstruction.call(void 0,
|
|
54
|
+
user,
|
|
55
|
+
ata,
|
|
56
|
+
user,
|
|
57
|
+
_spltoken.NATIVE_MINT,
|
|
58
|
+
_spltoken.TOKEN_PROGRAM_ID
|
|
59
|
+
)
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
function buildFeeRecipientAtaIxs(payer, feeRecipient, mintX, mintY, tokenProgramX = _spltoken.TOKEN_PROGRAM_ID, tokenProgramY = _spltoken.TOKEN_PROGRAM_ID) {
|
|
63
|
+
const ataX = _spltoken.getAssociatedTokenAddressSync.call(void 0, mintX, feeRecipient, false, tokenProgramX);
|
|
64
|
+
const ataY = _spltoken.getAssociatedTokenAddressSync.call(void 0, mintY, feeRecipient, false, tokenProgramY);
|
|
65
|
+
return [
|
|
66
|
+
_spltoken.createAssociatedTokenAccountIdempotentInstruction.call(void 0,
|
|
67
|
+
payer,
|
|
68
|
+
ataX,
|
|
69
|
+
feeRecipient,
|
|
70
|
+
mintX,
|
|
71
|
+
tokenProgramX
|
|
72
|
+
),
|
|
73
|
+
_spltoken.createAssociatedTokenAccountIdempotentInstruction.call(void 0,
|
|
74
|
+
payer,
|
|
75
|
+
ataY,
|
|
76
|
+
feeRecipient,
|
|
77
|
+
mintY,
|
|
78
|
+
tokenProgramY
|
|
79
|
+
)
|
|
80
|
+
];
|
|
49
81
|
}
|
|
50
82
|
|
|
51
83
|
// src/constants/index.ts
|
|
@@ -99,7 +131,9 @@ var Discriminator = {
|
|
|
99
131
|
SetPoolState: 21,
|
|
100
132
|
AllocateCurvePrefabs: 22,
|
|
101
133
|
SetQuotingAuthority: 23,
|
|
102
|
-
RotateFeeAdmin: 24
|
|
134
|
+
RotateFeeAdmin: 24,
|
|
135
|
+
InitializePoolFeeConfig: 25,
|
|
136
|
+
UpdatePoolFeeConfig: 26
|
|
103
137
|
};
|
|
104
138
|
var POINT_DATA_SIZE = 21;
|
|
105
139
|
var CURVE_UPDATE_OP_SIZE = 24;
|
|
@@ -163,6 +197,12 @@ function getCurveUpdatesAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_I
|
|
|
163
197
|
function getFeeConfigAddress(programId = HADRON_PROGRAM_ID) {
|
|
164
198
|
return _web3js.PublicKey.findProgramAddressSync([FEE_CONFIG_SEED], programId);
|
|
165
199
|
}
|
|
200
|
+
function getPoolFeeConfigAddress(configPda, programId = HADRON_PROGRAM_ID) {
|
|
201
|
+
return _web3js.PublicKey.findProgramAddressSync(
|
|
202
|
+
[FEE_CONFIG_SEED, configPda.toBuffer()],
|
|
203
|
+
programId
|
|
204
|
+
);
|
|
205
|
+
}
|
|
166
206
|
function getSpreadConfigAddress(configPda, programId = HADRON_PROGRAM_ID) {
|
|
167
207
|
return _web3js.PublicKey.findProgramAddressSync(
|
|
168
208
|
[SPREAD_CONFIG_SEED, configPda.toBuffer()],
|
|
@@ -301,7 +341,9 @@ function decodeConfig(data) {
|
|
|
301
341
|
offset += 1;
|
|
302
342
|
const oracleMode = buf.readUInt8(offset);
|
|
303
343
|
offset += 1;
|
|
304
|
-
offset
|
|
344
|
+
const hasPoolFee = buf.readUInt8(offset) !== 0;
|
|
345
|
+
offset += 1;
|
|
346
|
+
offset += 2;
|
|
305
347
|
const pendingAuthority = new (0, _web3js.PublicKey)(buf.subarray(offset, offset + 32));
|
|
306
348
|
offset += 32;
|
|
307
349
|
const nominationExpiry = buf.readBigUInt64LE(offset);
|
|
@@ -320,6 +362,7 @@ function decodeConfig(data) {
|
|
|
320
362
|
spreadConfigInitialized,
|
|
321
363
|
deltaStaleness,
|
|
322
364
|
oracleMode,
|
|
365
|
+
hasPoolFee,
|
|
323
366
|
pendingAuthority,
|
|
324
367
|
nominationExpiry,
|
|
325
368
|
tokenProgramX,
|
|
@@ -541,7 +584,7 @@ function buildInitialize(payer, params, programId = HADRON_PROGRAM_ID) {
|
|
|
541
584
|
function buildAllocateCurvePrefabs(payer, params, programId = HADRON_PROGRAM_ID) {
|
|
542
585
|
const maxPrefabSlots = _nullishCoalesce(params.maxPrefabSlots, () => ( DEFAULT_MAX_PREFAB_SLOTS));
|
|
543
586
|
const maxCurvePoints = _nullishCoalesce(params.maxCurvePoints, () => ( DEFAULT_MAX_CURVE_POINTS));
|
|
544
|
-
const data = Buffer.alloc(1 + 8 + 32 + 32 + 1 + 1);
|
|
587
|
+
const data = Buffer.alloc(1 + 8 + 32 + 32 + 1 + 1 + 32);
|
|
545
588
|
let offset = 0;
|
|
546
589
|
data.writeUInt8(Discriminator.AllocateCurvePrefabs, offset);
|
|
547
590
|
offset += 1;
|
|
@@ -554,6 +597,8 @@ function buildAllocateCurvePrefabs(payer, params, programId = HADRON_PROGRAM_ID)
|
|
|
554
597
|
data.writeUInt8(maxPrefabSlots, offset);
|
|
555
598
|
offset += 1;
|
|
556
599
|
data.writeUInt8(maxCurvePoints, offset);
|
|
600
|
+
offset += 1;
|
|
601
|
+
params.authority.toBuffer().copy(data, offset);
|
|
557
602
|
const [curvePrefabsPda] = _web3js.PublicKey.findProgramAddressSync(
|
|
558
603
|
[
|
|
559
604
|
Buffer.from("hadron-curve-prefabs"),
|
|
@@ -653,7 +698,7 @@ function buildWithdraw(user, configPda, mintX, mintY, tokenProgramX, tokenProgra
|
|
|
653
698
|
|
|
654
699
|
|
|
655
700
|
|
|
656
|
-
function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID, spreadConfigInitialized = false) {
|
|
701
|
+
function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID, spreadConfigInitialized = false, feeConfigOverride) {
|
|
657
702
|
const data = Buffer.alloc(1 + 1 + 8 + 8 + 8);
|
|
658
703
|
let offset = 0;
|
|
659
704
|
data.writeUInt8(Discriminator.SwapExactIn, offset);
|
|
@@ -669,7 +714,7 @@ function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, toke
|
|
|
669
714
|
const userX = _spltoken.getAssociatedTokenAddressSync.call(void 0, mintX, user, false, tokenProgramX);
|
|
670
715
|
const userY = _spltoken.getAssociatedTokenAddressSync.call(void 0, mintY, user, false, tokenProgramY);
|
|
671
716
|
const [userSource, vaultSource, vaultDest, userDest] = params.isX ? [userX, poolAddresses.vaultX, poolAddresses.vaultY, userY] : [userY, poolAddresses.vaultY, poolAddresses.vaultX, userX];
|
|
672
|
-
const
|
|
717
|
+
const feeConfigPda = _nullishCoalesce(feeConfigOverride, () => ( getFeeConfigAddress(programId)[0]));
|
|
673
718
|
const inputMint = params.isX ? mintX : mintY;
|
|
674
719
|
const inputMintProgram = params.isX ? tokenProgramX : tokenProgramY;
|
|
675
720
|
const feeRecipientAta = _spltoken.getAssociatedTokenAddressSync.call(void 0,
|
|
@@ -1137,6 +1182,52 @@ function buildRotateFeeAdmin(feeAdmin, params, programId = HADRON_PROGRAM_ID) {
|
|
|
1137
1182
|
data
|
|
1138
1183
|
});
|
|
1139
1184
|
}
|
|
1185
|
+
function buildInitializePoolFeeConfig(payer, feeAdmin, configPda, params, programId = HADRON_PROGRAM_ID) {
|
|
1186
|
+
const [poolFeeConfigPda] = getPoolFeeConfigAddress(configPda, programId);
|
|
1187
|
+
const [globalFeeConfigPda] = getFeeConfigAddress(programId);
|
|
1188
|
+
const data = Buffer.alloc(1 + 4 + 32 + 32);
|
|
1189
|
+
let offset = 0;
|
|
1190
|
+
data.writeUInt8(Discriminator.InitializePoolFeeConfig, offset);
|
|
1191
|
+
offset += 1;
|
|
1192
|
+
data.writeUInt32LE(params.feePpm, offset);
|
|
1193
|
+
offset += 4;
|
|
1194
|
+
params.feeAdmin.toBuffer().copy(data, offset);
|
|
1195
|
+
offset += 32;
|
|
1196
|
+
params.feeRecipient.toBuffer().copy(data, offset);
|
|
1197
|
+
return new (0, _web3js.TransactionInstruction)({
|
|
1198
|
+
programId,
|
|
1199
|
+
keys: [
|
|
1200
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
1201
|
+
{ pubkey: feeAdmin, isSigner: true, isWritable: false },
|
|
1202
|
+
{ pubkey: configPda, isSigner: false, isWritable: true },
|
|
1203
|
+
{ pubkey: poolFeeConfigPda, isSigner: false, isWritable: true },
|
|
1204
|
+
{ pubkey: globalFeeConfigPda, isSigner: false, isWritable: false },
|
|
1205
|
+
{ pubkey: _web3js.SystemProgram.programId, isSigner: false, isWritable: false }
|
|
1206
|
+
],
|
|
1207
|
+
data
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
function buildUpdatePoolFeeConfig(feeAdmin, configPda, params, programId = HADRON_PROGRAM_ID) {
|
|
1211
|
+
const [poolFeeConfigPda] = getPoolFeeConfigAddress(configPda, programId);
|
|
1212
|
+
const data = Buffer.alloc(1 + 4 + 32);
|
|
1213
|
+
let offset = 0;
|
|
1214
|
+
data.writeUInt8(Discriminator.UpdatePoolFeeConfig, offset);
|
|
1215
|
+
offset += 1;
|
|
1216
|
+
data.writeUInt32LE(params.feePpm !== null ? params.feePpm : 4294967295, offset);
|
|
1217
|
+
offset += 4;
|
|
1218
|
+
if (params.feeRecipient) {
|
|
1219
|
+
params.feeRecipient.toBuffer().copy(data, offset);
|
|
1220
|
+
}
|
|
1221
|
+
return new (0, _web3js.TransactionInstruction)({
|
|
1222
|
+
programId,
|
|
1223
|
+
keys: [
|
|
1224
|
+
{ pubkey: feeAdmin, isSigner: true, isWritable: false },
|
|
1225
|
+
{ pubkey: configPda, isSigner: false, isWritable: false },
|
|
1226
|
+
{ pubkey: poolFeeConfigPda, isSigner: false, isWritable: true }
|
|
1227
|
+
],
|
|
1228
|
+
data
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1140
1231
|
|
|
1141
1232
|
// src/instructions/spreadConfig.ts
|
|
1142
1233
|
|
|
@@ -1216,7 +1307,7 @@ function buildUpdateDeltaStaleness(authority, configPda, params, programId = HAD
|
|
|
1216
1307
|
data
|
|
1217
1308
|
});
|
|
1218
1309
|
}
|
|
1219
|
-
function buildClosePool(authority, configPda, midpriceOraclePda, curveMetaPda, curvePrefabsPda, curveUpdatesPda, vaultX, vaultY, tokenProgramX, tokenProgramY, spreadConfigInitialized = false, programId = HADRON_PROGRAM_ID) {
|
|
1310
|
+
function buildClosePool(authority, configPda, midpriceOraclePda, curveMetaPda, curvePrefabsPda, curveUpdatesPda, vaultX, vaultY, tokenProgramX, tokenProgramY, spreadConfigInitialized = false, authorityAtaX, authorityAtaY, programId = HADRON_PROGRAM_ID) {
|
|
1220
1311
|
const data = Buffer.alloc(1);
|
|
1221
1312
|
data.writeUInt8(Discriminator.ClosePool, 0);
|
|
1222
1313
|
const keys = [
|
|
@@ -1239,6 +1330,12 @@ function buildClosePool(authority, configPda, midpriceOraclePda, curveMetaPda, c
|
|
|
1239
1330
|
isWritable: true
|
|
1240
1331
|
});
|
|
1241
1332
|
}
|
|
1333
|
+
if (authorityAtaX) {
|
|
1334
|
+
keys.push({ pubkey: authorityAtaX, isSigner: false, isWritable: true });
|
|
1335
|
+
}
|
|
1336
|
+
if (authorityAtaY) {
|
|
1337
|
+
keys.push({ pubkey: authorityAtaY, isSigner: false, isWritable: true });
|
|
1338
|
+
}
|
|
1242
1339
|
return new (0, _web3js.TransactionInstruction)({ programId, keys, data });
|
|
1243
1340
|
}
|
|
1244
1341
|
|
|
@@ -1340,7 +1437,8 @@ var Hadron = class _Hadron {
|
|
|
1340
1437
|
mintX: params.mintX,
|
|
1341
1438
|
mintY: params.mintY,
|
|
1342
1439
|
maxPrefabSlots,
|
|
1343
|
-
maxCurvePoints
|
|
1440
|
+
maxCurvePoints,
|
|
1441
|
+
authority: params.authority
|
|
1344
1442
|
};
|
|
1345
1443
|
const instructions = [];
|
|
1346
1444
|
const size = curvePrefabsSize(maxPrefabSlots, maxCurvePoints);
|
|
@@ -1351,6 +1449,22 @@ var Hadron = class _Hadron {
|
|
|
1351
1449
|
instructions.push(buildInitialize(payer, resolvedParams, programId));
|
|
1352
1450
|
return { instructions, poolAddress, seed };
|
|
1353
1451
|
}
|
|
1452
|
+
/**
|
|
1453
|
+
* Build idempotent create-ATA instructions for the fee recipient for both mints.
|
|
1454
|
+
*
|
|
1455
|
+
* These are no-ops on-chain if the ATAs already exist. Include them alongside
|
|
1456
|
+
* initialize or first deposit to ensure swaps don't fail due to missing fee ATAs.
|
|
1457
|
+
*/
|
|
1458
|
+
static buildFeeRecipientAtaIxs(payer, feeRecipient, mintX, mintY, tokenProgramX, tokenProgramY) {
|
|
1459
|
+
return buildFeeRecipientAtaIxs(
|
|
1460
|
+
payer,
|
|
1461
|
+
feeRecipient,
|
|
1462
|
+
mintX,
|
|
1463
|
+
mintY,
|
|
1464
|
+
_nullishCoalesce(tokenProgramX, () => ( _spltoken.TOKEN_PROGRAM_ID)),
|
|
1465
|
+
_nullishCoalesce(tokenProgramY, () => ( _spltoken.TOKEN_PROGRAM_ID))
|
|
1466
|
+
);
|
|
1467
|
+
}
|
|
1354
1468
|
/** Generate a random u64 seed. */
|
|
1355
1469
|
static randomSeed() {
|
|
1356
1470
|
const buf = new Uint8Array(8);
|
|
@@ -1683,7 +1797,7 @@ var Hadron = class _Hadron {
|
|
|
1683
1797
|
return decoded.triggers;
|
|
1684
1798
|
}
|
|
1685
1799
|
/** Build close pool instruction. */
|
|
1686
|
-
closePool(authority) {
|
|
1800
|
+
closePool(authority, authorityAtaX, authorityAtaY) {
|
|
1687
1801
|
return buildClosePool(
|
|
1688
1802
|
authority,
|
|
1689
1803
|
this.poolAddress,
|
|
@@ -1696,6 +1810,8 @@ var Hadron = class _Hadron {
|
|
|
1696
1810
|
this.config.tokenProgramX,
|
|
1697
1811
|
this.config.tokenProgramY,
|
|
1698
1812
|
this.config.spreadConfigInitialized,
|
|
1813
|
+
authorityAtaX,
|
|
1814
|
+
authorityAtaY,
|
|
1699
1815
|
this.programId
|
|
1700
1816
|
);
|
|
1701
1817
|
}
|
|
@@ -1729,7 +1845,7 @@ var Hadron = class _Hadron {
|
|
|
1729
1845
|
}
|
|
1730
1846
|
ixs.push(this.withdraw(user, params));
|
|
1731
1847
|
if (hasSol) {
|
|
1732
|
-
ixs.push(
|
|
1848
|
+
ixs.push(...unwrapSolInstructions(user));
|
|
1733
1849
|
}
|
|
1734
1850
|
return ixs;
|
|
1735
1851
|
}
|
|
@@ -1750,7 +1866,7 @@ var Hadron = class _Hadron {
|
|
|
1750
1866
|
}
|
|
1751
1867
|
ixs.push(this.swap(user, params));
|
|
1752
1868
|
if (isNativeMint(outputMint)) {
|
|
1753
|
-
ixs.push(
|
|
1869
|
+
ixs.push(...unwrapSolInstructions(user));
|
|
1754
1870
|
}
|
|
1755
1871
|
return ixs;
|
|
1756
1872
|
}
|
|
@@ -2435,5 +2551,9 @@ async function getOrCreateAta(connection, mint, owner, payer, tokenProgram = _sp
|
|
|
2435
2551
|
|
|
2436
2552
|
|
|
2437
2553
|
|
|
2438
|
-
|
|
2554
|
+
|
|
2555
|
+
|
|
2556
|
+
|
|
2557
|
+
|
|
2558
|
+
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.buildFeeRecipientAtaIxs = buildFeeRecipientAtaIxs; 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.unwrapSolInstructions = unwrapSolInstructions; exports.wrapSolInstructions = wrapSolInstructions;
|
|
2439
2559
|
//# sourceMappingURL=index.js.map
|