@hadron-fi/sdk 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +113 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +209 -99
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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,
|
|
@@ -468,6 +469,21 @@ declare class Hadron {
|
|
|
468
469
|
private fetchSpreadTriggers;
|
|
469
470
|
/** Build close pool instruction. */
|
|
470
471
|
closePool(authority: PublicKey): TransactionInstruction;
|
|
472
|
+
/**
|
|
473
|
+
* Build deposit instructions with automatic SOL wrapping.
|
|
474
|
+
* If mint X or Y is native SOL, prepends wrap instructions for that side.
|
|
475
|
+
*/
|
|
476
|
+
depositSol(user: PublicKey, params: DepositParams): TransactionInstruction[];
|
|
477
|
+
/**
|
|
478
|
+
* Build withdraw instructions with automatic SOL unwrapping.
|
|
479
|
+
* Creates wSOL ATA (so program can transfer into it), withdraws, then closes ATA.
|
|
480
|
+
*/
|
|
481
|
+
withdrawSol(user: PublicKey, params: WithdrawParams): TransactionInstruction[];
|
|
482
|
+
/**
|
|
483
|
+
* Build swap instructions with automatic SOL wrapping/unwrapping.
|
|
484
|
+
* Wraps SOL if the input side is native, unwraps if the output side is native.
|
|
485
|
+
*/
|
|
486
|
+
swapSol(user: PublicKey, params: SwapParams): TransactionInstruction[];
|
|
471
487
|
}
|
|
472
488
|
|
|
473
489
|
/**
|
|
@@ -704,6 +720,24 @@ declare function spreadBpsToQ32(bps: number): bigint;
|
|
|
704
720
|
/** Convert a spread factor in Q32 to basis points (e.g. toQ32(0.9995) → 5). */
|
|
705
721
|
declare function spreadQ32ToBps(q32: bigint): number;
|
|
706
722
|
|
|
723
|
+
/** Returns true if the given mint is the native SOL (wSOL) mint. */
|
|
724
|
+
declare function isNativeMint(mint: PublicKey): boolean;
|
|
725
|
+
/**
|
|
726
|
+
* Build instructions to wrap native SOL into a wSOL ATA.
|
|
727
|
+
*
|
|
728
|
+
* Returns [createATA (idempotent), transfer SOL, syncNative] instructions.
|
|
729
|
+
*/
|
|
730
|
+
declare function wrapSolInstructions(user: PublicKey, lamports: bigint): TransactionInstruction[];
|
|
731
|
+
/**
|
|
732
|
+
* Build instruction to ensure the user's wSOL ATA exists (idempotent create).
|
|
733
|
+
* Needed before withdraw/swap-output so the program has somewhere to send wSOL.
|
|
734
|
+
*/
|
|
735
|
+
declare function createWsolAtaInstruction(user: PublicKey): TransactionInstruction;
|
|
736
|
+
/**
|
|
737
|
+
* Build instruction to unwrap wSOL — closes the ATA and sends lamports back to the user.
|
|
738
|
+
*/
|
|
739
|
+
declare function unwrapSolInstruction(user: PublicKey): TransactionInstruction;
|
|
740
|
+
|
|
707
741
|
/**
|
|
708
742
|
* Get the ATA address, and optionally return a create instruction if it doesn't exist.
|
|
709
743
|
*/
|
|
@@ -878,4 +912,4 @@ declare function buildUpdateDeltaStaleness(authority: PublicKey, configPda: Publ
|
|
|
878
912
|
*/
|
|
879
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;
|
|
880
914
|
|
|
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 };
|
|
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, 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,
|
|
@@ -468,6 +469,21 @@ declare class Hadron {
|
|
|
468
469
|
private fetchSpreadTriggers;
|
|
469
470
|
/** Build close pool instruction. */
|
|
470
471
|
closePool(authority: PublicKey): TransactionInstruction;
|
|
472
|
+
/**
|
|
473
|
+
* Build deposit instructions with automatic SOL wrapping.
|
|
474
|
+
* If mint X or Y is native SOL, prepends wrap instructions for that side.
|
|
475
|
+
*/
|
|
476
|
+
depositSol(user: PublicKey, params: DepositParams): TransactionInstruction[];
|
|
477
|
+
/**
|
|
478
|
+
* Build withdraw instructions with automatic SOL unwrapping.
|
|
479
|
+
* Creates wSOL ATA (so program can transfer into it), withdraws, then closes ATA.
|
|
480
|
+
*/
|
|
481
|
+
withdrawSol(user: PublicKey, params: WithdrawParams): TransactionInstruction[];
|
|
482
|
+
/**
|
|
483
|
+
* Build swap instructions with automatic SOL wrapping/unwrapping.
|
|
484
|
+
* Wraps SOL if the input side is native, unwraps if the output side is native.
|
|
485
|
+
*/
|
|
486
|
+
swapSol(user: PublicKey, params: SwapParams): TransactionInstruction[];
|
|
471
487
|
}
|
|
472
488
|
|
|
473
489
|
/**
|
|
@@ -704,6 +720,24 @@ declare function spreadBpsToQ32(bps: number): bigint;
|
|
|
704
720
|
/** Convert a spread factor in Q32 to basis points (e.g. toQ32(0.9995) → 5). */
|
|
705
721
|
declare function spreadQ32ToBps(q32: bigint): number;
|
|
706
722
|
|
|
723
|
+
/** Returns true if the given mint is the native SOL (wSOL) mint. */
|
|
724
|
+
declare function isNativeMint(mint: PublicKey): boolean;
|
|
725
|
+
/**
|
|
726
|
+
* Build instructions to wrap native SOL into a wSOL ATA.
|
|
727
|
+
*
|
|
728
|
+
* Returns [createATA (idempotent), transfer SOL, syncNative] instructions.
|
|
729
|
+
*/
|
|
730
|
+
declare function wrapSolInstructions(user: PublicKey, lamports: bigint): TransactionInstruction[];
|
|
731
|
+
/**
|
|
732
|
+
* Build instruction to ensure the user's wSOL ATA exists (idempotent create).
|
|
733
|
+
* Needed before withdraw/swap-output so the program has somewhere to send wSOL.
|
|
734
|
+
*/
|
|
735
|
+
declare function createWsolAtaInstruction(user: PublicKey): TransactionInstruction;
|
|
736
|
+
/**
|
|
737
|
+
* Build instruction to unwrap wSOL — closes the ATA and sends lamports back to the user.
|
|
738
|
+
*/
|
|
739
|
+
declare function unwrapSolInstruction(user: PublicKey): TransactionInstruction;
|
|
740
|
+
|
|
707
741
|
/**
|
|
708
742
|
* Get the ATA address, and optionally return a create instruction if it doesn't exist.
|
|
709
743
|
*/
|
|
@@ -878,4 +912,4 @@ declare function buildUpdateDeltaStaleness(authority: PublicKey, configPda: Publ
|
|
|
878
912
|
*/
|
|
879
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;
|
|
880
914
|
|
|
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 };
|
|
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, 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/
|
|
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
|
);
|
|
@@ -59,7 +109,7 @@ function curvePrefabsSize(maxSlots, maxPoints) {
|
|
|
59
109
|
|
|
60
110
|
// src/helpers/derive.ts
|
|
61
111
|
|
|
62
|
-
|
|
112
|
+
|
|
63
113
|
function seedToBuffer(seed) {
|
|
64
114
|
const buf = Buffer.alloc(8);
|
|
65
115
|
buf.writeBigUInt64LE(seed);
|
|
@@ -1649,6 +1699,61 @@ var Hadron = class _Hadron {
|
|
|
1649
1699
|
this.programId
|
|
1650
1700
|
);
|
|
1651
1701
|
}
|
|
1702
|
+
// ==========================================================================
|
|
1703
|
+
// SOL Wrapping Convenience Methods
|
|
1704
|
+
// ==========================================================================
|
|
1705
|
+
/**
|
|
1706
|
+
* Build deposit instructions with automatic SOL wrapping.
|
|
1707
|
+
* If mint X or Y is native SOL, prepends wrap instructions for that side.
|
|
1708
|
+
*/
|
|
1709
|
+
depositSol(user, params) {
|
|
1710
|
+
const ixs = [];
|
|
1711
|
+
if (isNativeMint(this.config.mintX) && params.amountX > 0n) {
|
|
1712
|
+
ixs.push(...wrapSolInstructions(user, params.amountX));
|
|
1713
|
+
}
|
|
1714
|
+
if (isNativeMint(this.config.mintY) && params.amountY > 0n) {
|
|
1715
|
+
ixs.push(...wrapSolInstructions(user, params.amountY));
|
|
1716
|
+
}
|
|
1717
|
+
ixs.push(this.deposit(user, params));
|
|
1718
|
+
return ixs;
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* Build withdraw instructions with automatic SOL unwrapping.
|
|
1722
|
+
* Creates wSOL ATA (so program can transfer into it), withdraws, then closes ATA.
|
|
1723
|
+
*/
|
|
1724
|
+
withdrawSol(user, params) {
|
|
1725
|
+
const ixs = [];
|
|
1726
|
+
const hasSol = isNativeMint(this.config.mintX) || isNativeMint(this.config.mintY);
|
|
1727
|
+
if (hasSol) {
|
|
1728
|
+
ixs.push(createWsolAtaInstruction(user));
|
|
1729
|
+
}
|
|
1730
|
+
ixs.push(this.withdraw(user, params));
|
|
1731
|
+
if (hasSol) {
|
|
1732
|
+
ixs.push(unwrapSolInstruction(user));
|
|
1733
|
+
}
|
|
1734
|
+
return ixs;
|
|
1735
|
+
}
|
|
1736
|
+
/**
|
|
1737
|
+
* Build swap instructions with automatic SOL wrapping/unwrapping.
|
|
1738
|
+
* Wraps SOL if the input side is native, unwraps if the output side is native.
|
|
1739
|
+
*/
|
|
1740
|
+
swapSol(user, params) {
|
|
1741
|
+
const ixs = [];
|
|
1742
|
+
const inputIsX = params.isX;
|
|
1743
|
+
const inputMint = inputIsX ? this.config.mintX : this.config.mintY;
|
|
1744
|
+
const outputMint = inputIsX ? this.config.mintY : this.config.mintX;
|
|
1745
|
+
if (isNativeMint(inputMint)) {
|
|
1746
|
+
ixs.push(...wrapSolInstructions(user, params.amountIn));
|
|
1747
|
+
}
|
|
1748
|
+
if (isNativeMint(outputMint)) {
|
|
1749
|
+
ixs.push(createWsolAtaInstruction(user));
|
|
1750
|
+
}
|
|
1751
|
+
ixs.push(this.swap(user, params));
|
|
1752
|
+
if (isNativeMint(outputMint)) {
|
|
1753
|
+
ixs.push(unwrapSolInstruction(user));
|
|
1754
|
+
}
|
|
1755
|
+
return ixs;
|
|
1756
|
+
}
|
|
1652
1757
|
};
|
|
1653
1758
|
|
|
1654
1759
|
// src/orderbook.ts
|
|
@@ -2325,5 +2430,10 @@ async function getOrCreateAta(connection, mint, owner, payer, tokenProgram = _sp
|
|
|
2325
2430
|
|
|
2326
2431
|
|
|
2327
2432
|
|
|
2328
|
-
|
|
2433
|
+
|
|
2434
|
+
|
|
2435
|
+
|
|
2436
|
+
|
|
2437
|
+
|
|
2438
|
+
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.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.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.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
2439
|
//# sourceMappingURL=index.js.map
|