@hadron-fi/sdk 0.3.2 → 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.mjs 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
  import { PublicKey as PublicKey3 } from "@solana/web3.js";
@@ -275,9 +281,9 @@ function decodeMidpriceOracle(data) {
275
281
  const authority = new PublicKey3(buf.subarray(0, 32));
276
282
  const sequence = buf.readBigUInt64LE(32);
277
283
  const midpriceQ32 = buf.readBigUInt64LE(40);
278
- const baseSpreadQ32 = buf.readBigUInt64LE(48);
284
+ const spreadFactorQ32 = buf.readBigUInt64LE(48);
279
285
  const lastUpdateSlot = buf.length >= MIDPRICE_ORACLE_SIZE ? buf.readBigUInt64LE(56) : 0n;
280
- return { authority, sequence, midpriceQ32, baseSpreadQ32, lastUpdateSlot };
286
+ return { authority, sequence, midpriceQ32, spreadFactorQ32, lastUpdateSlot };
281
287
  }
282
288
  function decodeCurveMeta(data) {
283
289
  const buf = Buffer.from(data);
@@ -850,7 +856,7 @@ function buildUpdateBaseSpread(authority, midpriceOraclePda, params, programId =
850
856
  const data = Buffer.alloc(1 + 8 + 8);
851
857
  data.writeUInt8(Discriminator.UpdateBaseSpread, 0);
852
858
  data.writeBigUInt64LE(params.sequence ?? 0n, 1);
853
- data.writeBigUInt64LE(params.baseSpreadQ32, 9);
859
+ data.writeBigUInt64LE(params.spreadFactorQ32, 9);
854
860
  return new TransactionInstruction6({
855
861
  programId,
856
862
  keys: [
@@ -866,7 +872,7 @@ function buildUpdateMidpriceAndBaseSpread(authority, midpriceOraclePda, params,
866
872
  data.writeUInt8(Discriminator.UpdateMidpriceAndBaseSpread, 0);
867
873
  data.writeBigUInt64LE(params.sequence ?? 0n, 1);
868
874
  data.writeBigUInt64LE(params.midpriceQ32, 9);
869
- data.writeBigUInt64LE(params.baseSpreadQ32, 17);
875
+ data.writeBigUInt64LE(params.spreadFactorQ32, 17);
870
876
  return new TransactionInstruction6({
871
877
  programId,
872
878
  keys: [
@@ -1321,9 +1327,13 @@ var Hadron = class _Hadron {
1321
1327
  getMidprice() {
1322
1328
  return fromQ32(this.oracle.midpriceQ32);
1323
1329
  }
1324
- /** Get base spread as a floating-point number. */
1325
- getBaseSpread() {
1326
- return fromQ32(this.oracle.baseSpreadQ32);
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;
1327
1337
  }
1328
1338
  /** Get the currently active curve slot indices. */
1329
1339
  getActiveCurveSlots() {
@@ -2300,6 +2310,8 @@ export {
2300
2310
  getSpreadConfigAddress,
2301
2311
  isSlotInitialized,
2302
2312
  pctToQ32,
2313
+ spreadBpsToQ32,
2314
+ spreadQ32ToBps,
2303
2315
  toQ32
2304
2316
  };
2305
2317
  //# sourceMappingURL=index.mjs.map