@hadron-fi/sdk 0.3.1 → 0.3.3
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 +17 -8
- package/dist/index.d.ts +17 -8
- package/dist/index.js +66 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -40
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -65,7 +65,8 @@ interface DecodedMidpriceOracle {
|
|
|
65
65
|
authority: PublicKey;
|
|
66
66
|
sequence: bigint;
|
|
67
67
|
midpriceQ32: bigint;
|
|
68
|
-
|
|
68
|
+
/** Spread as a discount factor in Q32 (e.g. toQ32(0.9995) = 5 bps). */
|
|
69
|
+
spreadFactorQ32: bigint;
|
|
69
70
|
lastUpdateSlot: bigint;
|
|
70
71
|
}
|
|
71
72
|
interface DecodedCurveMeta {
|
|
@@ -217,12 +218,14 @@ interface UpdateMidpriceParams {
|
|
|
217
218
|
sequence?: bigint;
|
|
218
219
|
}
|
|
219
220
|
interface UpdateBaseSpreadParams {
|
|
220
|
-
|
|
221
|
+
/** Spread as a discount factor in Q32 (e.g. toQ32(0.9995) = 5 bps). */
|
|
222
|
+
spreadFactorQ32: bigint;
|
|
221
223
|
sequence?: bigint;
|
|
222
224
|
}
|
|
223
225
|
interface UpdateMidpriceAndBaseSpreadParams {
|
|
224
226
|
midpriceQ32: bigint;
|
|
225
|
-
|
|
227
|
+
/** Spread as a discount factor in Q32 (e.g. toQ32(0.9995) = 5 bps). */
|
|
228
|
+
spreadFactorQ32: bigint;
|
|
226
229
|
sequence?: bigint;
|
|
227
230
|
}
|
|
228
231
|
interface SwitchCurveParams {
|
|
@@ -386,8 +389,10 @@ declare class Hadron {
|
|
|
386
389
|
refetchStates(): Promise<void>;
|
|
387
390
|
/** Get midprice as a floating-point number. */
|
|
388
391
|
getMidprice(): number;
|
|
389
|
-
/** Get
|
|
390
|
-
|
|
392
|
+
/** Get spread factor as a floating-point number (e.g. 0.9995 = 5 bps). */
|
|
393
|
+
getSpreadFactor(): number;
|
|
394
|
+
/** Get spread in basis points (e.g. 5 for a 0.9995 factor). */
|
|
395
|
+
getSpreadBps(): number;
|
|
391
396
|
/** Get the currently active curve slot indices. */
|
|
392
397
|
getActiveCurveSlots(): {
|
|
393
398
|
priceBid: number;
|
|
@@ -692,6 +697,10 @@ declare function toQ32(value: number): bigint;
|
|
|
692
697
|
declare function fromQ32(q32: bigint): number;
|
|
693
698
|
/** Convert a percentage (0.0 to 1.0) to Q32.32. */
|
|
694
699
|
declare function pctToQ32(pct: number): bigint;
|
|
700
|
+
/** Convert basis points to a spread factor in Q32 (e.g. 5 bps → toQ32(0.9995)). */
|
|
701
|
+
declare function spreadBpsToQ32(bps: number): bigint;
|
|
702
|
+
/** Convert a spread factor in Q32 to basis points (e.g. toQ32(0.9995) → 5). */
|
|
703
|
+
declare function spreadQ32ToBps(q32: bigint): number;
|
|
695
704
|
|
|
696
705
|
/**
|
|
697
706
|
* Get the ATA address, and optionally return a create instruction if it doesn't exist.
|
|
@@ -731,9 +740,9 @@ declare function buildWithdraw(user: PublicKey, configPda: PublicKey, mintX: Pub
|
|
|
731
740
|
* user_source, vault_source, vault_dest, user_dest, fee_config,
|
|
732
741
|
* fee_recipient_ata, clock, curve_updates.
|
|
733
742
|
*
|
|
734
|
-
*
|
|
743
|
+
* When spread config is initialized: spread_config (#16) + instructions_sysvar (#17).
|
|
735
744
|
*/
|
|
736
|
-
declare function buildSwapExactIn(user: PublicKey, poolAddresses: PoolAddresses, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, params: SwapParams, programId?: PublicKey): TransactionInstruction;
|
|
745
|
+
declare function buildSwapExactIn(user: PublicKey, poolAddresses: PoolAddresses, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, params: SwapParams, programId?: PublicKey, spreadConfigInitialized?: boolean): TransactionInstruction;
|
|
737
746
|
|
|
738
747
|
/**
|
|
739
748
|
* Build a SetCurve instruction (price curve).
|
|
@@ -867,4 +876,4 @@ declare function buildUpdateDeltaStaleness(authority: PublicKey, configPda: Publ
|
|
|
867
876
|
*/
|
|
868
877
|
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;
|
|
869
878
|
|
|
870
|
-
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, toQ32 };
|
|
879
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -65,7 +65,8 @@ interface DecodedMidpriceOracle {
|
|
|
65
65
|
authority: PublicKey;
|
|
66
66
|
sequence: bigint;
|
|
67
67
|
midpriceQ32: bigint;
|
|
68
|
-
|
|
68
|
+
/** Spread as a discount factor in Q32 (e.g. toQ32(0.9995) = 5 bps). */
|
|
69
|
+
spreadFactorQ32: bigint;
|
|
69
70
|
lastUpdateSlot: bigint;
|
|
70
71
|
}
|
|
71
72
|
interface DecodedCurveMeta {
|
|
@@ -217,12 +218,14 @@ interface UpdateMidpriceParams {
|
|
|
217
218
|
sequence?: bigint;
|
|
218
219
|
}
|
|
219
220
|
interface UpdateBaseSpreadParams {
|
|
220
|
-
|
|
221
|
+
/** Spread as a discount factor in Q32 (e.g. toQ32(0.9995) = 5 bps). */
|
|
222
|
+
spreadFactorQ32: bigint;
|
|
221
223
|
sequence?: bigint;
|
|
222
224
|
}
|
|
223
225
|
interface UpdateMidpriceAndBaseSpreadParams {
|
|
224
226
|
midpriceQ32: bigint;
|
|
225
|
-
|
|
227
|
+
/** Spread as a discount factor in Q32 (e.g. toQ32(0.9995) = 5 bps). */
|
|
228
|
+
spreadFactorQ32: bigint;
|
|
226
229
|
sequence?: bigint;
|
|
227
230
|
}
|
|
228
231
|
interface SwitchCurveParams {
|
|
@@ -386,8 +389,10 @@ declare class Hadron {
|
|
|
386
389
|
refetchStates(): Promise<void>;
|
|
387
390
|
/** Get midprice as a floating-point number. */
|
|
388
391
|
getMidprice(): number;
|
|
389
|
-
/** Get
|
|
390
|
-
|
|
392
|
+
/** Get spread factor as a floating-point number (e.g. 0.9995 = 5 bps). */
|
|
393
|
+
getSpreadFactor(): number;
|
|
394
|
+
/** Get spread in basis points (e.g. 5 for a 0.9995 factor). */
|
|
395
|
+
getSpreadBps(): number;
|
|
391
396
|
/** Get the currently active curve slot indices. */
|
|
392
397
|
getActiveCurveSlots(): {
|
|
393
398
|
priceBid: number;
|
|
@@ -692,6 +697,10 @@ declare function toQ32(value: number): bigint;
|
|
|
692
697
|
declare function fromQ32(q32: bigint): number;
|
|
693
698
|
/** Convert a percentage (0.0 to 1.0) to Q32.32. */
|
|
694
699
|
declare function pctToQ32(pct: number): bigint;
|
|
700
|
+
/** Convert basis points to a spread factor in Q32 (e.g. 5 bps → toQ32(0.9995)). */
|
|
701
|
+
declare function spreadBpsToQ32(bps: number): bigint;
|
|
702
|
+
/** Convert a spread factor in Q32 to basis points (e.g. toQ32(0.9995) → 5). */
|
|
703
|
+
declare function spreadQ32ToBps(q32: bigint): number;
|
|
695
704
|
|
|
696
705
|
/**
|
|
697
706
|
* Get the ATA address, and optionally return a create instruction if it doesn't exist.
|
|
@@ -731,9 +740,9 @@ declare function buildWithdraw(user: PublicKey, configPda: PublicKey, mintX: Pub
|
|
|
731
740
|
* user_source, vault_source, vault_dest, user_dest, fee_config,
|
|
732
741
|
* fee_recipient_ata, clock, curve_updates.
|
|
733
742
|
*
|
|
734
|
-
*
|
|
743
|
+
* When spread config is initialized: spread_config (#16) + instructions_sysvar (#17).
|
|
735
744
|
*/
|
|
736
|
-
declare function buildSwapExactIn(user: PublicKey, poolAddresses: PoolAddresses, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, params: SwapParams, programId?: PublicKey): TransactionInstruction;
|
|
745
|
+
declare function buildSwapExactIn(user: PublicKey, poolAddresses: PoolAddresses, mintX: PublicKey, mintY: PublicKey, tokenProgramX: PublicKey, tokenProgramY: PublicKey, params: SwapParams, programId?: PublicKey, spreadConfigInitialized?: boolean): TransactionInstruction;
|
|
737
746
|
|
|
738
747
|
/**
|
|
739
748
|
* Build a SetCurve instruction (price curve).
|
|
@@ -867,4 +876,4 @@ declare function buildUpdateDeltaStaleness(authority: PublicKey, configPda: Publ
|
|
|
867
876
|
*/
|
|
868
877
|
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;
|
|
869
878
|
|
|
870
|
-
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, toQ32 };
|
|
879
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -166,6 +166,12 @@ function fromQ32(q32) {
|
|
|
166
166
|
function pctToQ32(pct) {
|
|
167
167
|
return toQ32(pct);
|
|
168
168
|
}
|
|
169
|
+
function spreadBpsToQ32(bps) {
|
|
170
|
+
return toQ32(1 - bps / 1e4);
|
|
171
|
+
}
|
|
172
|
+
function spreadQ32ToBps(q32) {
|
|
173
|
+
return (1 - fromQ32(q32)) * 1e4;
|
|
174
|
+
}
|
|
169
175
|
|
|
170
176
|
// src/accounts/index.ts
|
|
171
177
|
|
|
@@ -275,9 +281,9 @@ function decodeMidpriceOracle(data) {
|
|
|
275
281
|
const authority = new (0, _web3js.PublicKey)(buf.subarray(0, 32));
|
|
276
282
|
const sequence = buf.readBigUInt64LE(32);
|
|
277
283
|
const midpriceQ32 = buf.readBigUInt64LE(40);
|
|
278
|
-
const
|
|
284
|
+
const spreadFactorQ32 = buf.readBigUInt64LE(48);
|
|
279
285
|
const lastUpdateSlot = buf.length >= MIDPRICE_ORACLE_SIZE ? buf.readBigUInt64LE(56) : 0n;
|
|
280
|
-
return { authority, sequence, midpriceQ32,
|
|
286
|
+
return { authority, sequence, midpriceQ32, spreadFactorQ32, lastUpdateSlot };
|
|
281
287
|
}
|
|
282
288
|
function decodeCurveMeta(data) {
|
|
283
289
|
const buf = Buffer.from(data);
|
|
@@ -596,7 +602,8 @@ function buildWithdraw(user, configPda, mintX, mintY, tokenProgramX, tokenProgra
|
|
|
596
602
|
|
|
597
603
|
|
|
598
604
|
|
|
599
|
-
|
|
605
|
+
|
|
606
|
+
function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID, spreadConfigInitialized = false) {
|
|
600
607
|
const data = Buffer.alloc(1 + 1 + 8 + 8 + 8);
|
|
601
608
|
let offset = 0;
|
|
602
609
|
data.writeUInt8(Discriminator.SwapExactIn, offset);
|
|
@@ -621,39 +628,50 @@ function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, toke
|
|
|
621
628
|
false,
|
|
622
629
|
inputMintProgram
|
|
623
630
|
);
|
|
631
|
+
const keys = [
|
|
632
|
+
{ pubkey: tokenProgramX, isSigner: false, isWritable: false },
|
|
633
|
+
{ pubkey: tokenProgramY, isSigner: false, isWritable: false },
|
|
634
|
+
{ pubkey: poolAddresses.config, isSigner: false, isWritable: false },
|
|
635
|
+
{
|
|
636
|
+
pubkey: poolAddresses.midpriceOracle,
|
|
637
|
+
isSigner: false,
|
|
638
|
+
isWritable: false
|
|
639
|
+
},
|
|
640
|
+
{ pubkey: poolAddresses.curveMeta, isSigner: false, isWritable: false },
|
|
641
|
+
{
|
|
642
|
+
pubkey: poolAddresses.curvePrefabs,
|
|
643
|
+
isSigner: false,
|
|
644
|
+
isWritable: true
|
|
645
|
+
},
|
|
646
|
+
{ pubkey: poolAddresses.config, isSigner: false, isWritable: false },
|
|
647
|
+
// authority = pool address PDA
|
|
648
|
+
{ pubkey: user, isSigner: true, isWritable: false },
|
|
649
|
+
{ pubkey: userSource, isSigner: false, isWritable: true },
|
|
650
|
+
{ pubkey: vaultSource, isSigner: false, isWritable: true },
|
|
651
|
+
{ pubkey: vaultDest, isSigner: false, isWritable: true },
|
|
652
|
+
{ pubkey: userDest, isSigner: false, isWritable: true },
|
|
653
|
+
{ pubkey: feeConfigPda, isSigner: false, isWritable: false },
|
|
654
|
+
{ pubkey: feeRecipientAta, isSigner: false, isWritable: true },
|
|
655
|
+
{ pubkey: _web3js.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false },
|
|
656
|
+
{
|
|
657
|
+
pubkey: poolAddresses.curveUpdates,
|
|
658
|
+
isSigner: false,
|
|
659
|
+
isWritable: true
|
|
660
|
+
}
|
|
661
|
+
];
|
|
662
|
+
if (spreadConfigInitialized) {
|
|
663
|
+
const [spreadConfigPda] = getSpreadConfigAddress(
|
|
664
|
+
poolAddresses.config,
|
|
665
|
+
programId
|
|
666
|
+
);
|
|
667
|
+
keys.push(
|
|
668
|
+
{ pubkey: spreadConfigPda, isSigner: false, isWritable: false },
|
|
669
|
+
{ pubkey: _web3js.SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false }
|
|
670
|
+
);
|
|
671
|
+
}
|
|
624
672
|
return new (0, _web3js.TransactionInstruction)({
|
|
625
673
|
programId,
|
|
626
|
-
keys
|
|
627
|
-
{ pubkey: tokenProgramX, isSigner: false, isWritable: false },
|
|
628
|
-
{ pubkey: tokenProgramY, isSigner: false, isWritable: false },
|
|
629
|
-
{ pubkey: poolAddresses.config, isSigner: false, isWritable: false },
|
|
630
|
-
{
|
|
631
|
-
pubkey: poolAddresses.midpriceOracle,
|
|
632
|
-
isSigner: false,
|
|
633
|
-
isWritable: false
|
|
634
|
-
},
|
|
635
|
-
{ pubkey: poolAddresses.curveMeta, isSigner: false, isWritable: false },
|
|
636
|
-
{
|
|
637
|
-
pubkey: poolAddresses.curvePrefabs,
|
|
638
|
-
isSigner: false,
|
|
639
|
-
isWritable: true
|
|
640
|
-
},
|
|
641
|
-
{ pubkey: poolAddresses.config, isSigner: false, isWritable: false },
|
|
642
|
-
// authority = pool address PDA
|
|
643
|
-
{ pubkey: user, isSigner: true, isWritable: false },
|
|
644
|
-
{ pubkey: userSource, isSigner: false, isWritable: true },
|
|
645
|
-
{ pubkey: vaultSource, isSigner: false, isWritable: true },
|
|
646
|
-
{ pubkey: vaultDest, isSigner: false, isWritable: true },
|
|
647
|
-
{ pubkey: userDest, isSigner: false, isWritable: true },
|
|
648
|
-
{ pubkey: feeConfigPda, isSigner: false, isWritable: false },
|
|
649
|
-
{ pubkey: feeRecipientAta, isSigner: false, isWritable: true },
|
|
650
|
-
{ pubkey: _web3js.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false },
|
|
651
|
-
{
|
|
652
|
-
pubkey: poolAddresses.curveUpdates,
|
|
653
|
-
isSigner: false,
|
|
654
|
-
isWritable: true
|
|
655
|
-
}
|
|
656
|
-
],
|
|
674
|
+
keys,
|
|
657
675
|
data
|
|
658
676
|
});
|
|
659
677
|
}
|
|
@@ -838,7 +856,7 @@ function buildUpdateBaseSpread(authority, midpriceOraclePda, params, programId =
|
|
|
838
856
|
const data = Buffer.alloc(1 + 8 + 8);
|
|
839
857
|
data.writeUInt8(Discriminator.UpdateBaseSpread, 0);
|
|
840
858
|
data.writeBigUInt64LE(_nullishCoalesce(params.sequence, () => ( 0n)), 1);
|
|
841
|
-
data.writeBigUInt64LE(params.
|
|
859
|
+
data.writeBigUInt64LE(params.spreadFactorQ32, 9);
|
|
842
860
|
return new (0, _web3js.TransactionInstruction)({
|
|
843
861
|
programId,
|
|
844
862
|
keys: [
|
|
@@ -854,7 +872,7 @@ function buildUpdateMidpriceAndBaseSpread(authority, midpriceOraclePda, params,
|
|
|
854
872
|
data.writeUInt8(Discriminator.UpdateMidpriceAndBaseSpread, 0);
|
|
855
873
|
data.writeBigUInt64LE(_nullishCoalesce(params.sequence, () => ( 0n)), 1);
|
|
856
874
|
data.writeBigUInt64LE(params.midpriceQ32, 9);
|
|
857
|
-
data.writeBigUInt64LE(params.
|
|
875
|
+
data.writeBigUInt64LE(params.spreadFactorQ32, 17);
|
|
858
876
|
return new (0, _web3js.TransactionInstruction)({
|
|
859
877
|
programId,
|
|
860
878
|
keys: [
|
|
@@ -1309,9 +1327,13 @@ var Hadron = class _Hadron {
|
|
|
1309
1327
|
getMidprice() {
|
|
1310
1328
|
return fromQ32(this.oracle.midpriceQ32);
|
|
1311
1329
|
}
|
|
1312
|
-
/** Get
|
|
1313
|
-
|
|
1314
|
-
return fromQ32(this.oracle.
|
|
1330
|
+
/** Get spread factor as a floating-point number (e.g. 0.9995 = 5 bps). */
|
|
1331
|
+
getSpreadFactor() {
|
|
1332
|
+
return fromQ32(this.oracle.spreadFactorQ32);
|
|
1333
|
+
}
|
|
1334
|
+
/** Get spread in basis points (e.g. 5 for a 0.9995 factor). */
|
|
1335
|
+
getSpreadBps() {
|
|
1336
|
+
return (1 - fromQ32(this.oracle.spreadFactorQ32)) * 1e4;
|
|
1315
1337
|
}
|
|
1316
1338
|
/** Get the currently active curve slot indices. */
|
|
1317
1339
|
getActiveCurveSlots() {
|
|
@@ -1375,7 +1397,8 @@ var Hadron = class _Hadron {
|
|
|
1375
1397
|
this.config.tokenProgramX,
|
|
1376
1398
|
this.config.tokenProgramY,
|
|
1377
1399
|
params,
|
|
1378
|
-
this.programId
|
|
1400
|
+
this.programId,
|
|
1401
|
+
this.config.spreadConfigInitialized
|
|
1379
1402
|
);
|
|
1380
1403
|
}
|
|
1381
1404
|
/** Build set curve instruction. */
|
|
@@ -2288,5 +2311,7 @@ async function getOrCreateAta(connection, mint, owner, payer, tokenProgram = _sp
|
|
|
2288
2311
|
|
|
2289
2312
|
|
|
2290
2313
|
|
|
2291
|
-
|
|
2314
|
+
|
|
2315
|
+
|
|
2316
|
+
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;
|
|
2292
2317
|
//# sourceMappingURL=index.js.map
|