@hadron-fi/sdk 0.4.1 → 0.4.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
@@ -1,3 +1,6 @@
1
+ // src/hadron.ts
2
+ import { TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID3 } from "@solana/spl-token";
3
+
1
4
  // src/helpers/sol.ts
2
5
  import {
3
6
  SystemProgram
@@ -43,9 +46,38 @@ function createWsolAtaInstruction(user) {
43
46
  TOKEN_PROGRAM_ID
44
47
  );
45
48
  }
46
- function unwrapSolInstruction(user) {
49
+ function unwrapSolInstructions(user) {
47
50
  const ata = getAssociatedTokenAddressSync(NATIVE_MINT, user, false, TOKEN_PROGRAM_ID);
48
- return createCloseAccountInstruction(ata, user, user, [], TOKEN_PROGRAM_ID);
51
+ return [
52
+ createCloseAccountInstruction(ata, user, user, [], TOKEN_PROGRAM_ID),
53
+ createAssociatedTokenAccountIdempotentInstruction(
54
+ user,
55
+ ata,
56
+ user,
57
+ NATIVE_MINT,
58
+ TOKEN_PROGRAM_ID
59
+ )
60
+ ];
61
+ }
62
+ function buildFeeRecipientAtaIxs(payer, feeRecipient, mintX, mintY, tokenProgramX = TOKEN_PROGRAM_ID, tokenProgramY = TOKEN_PROGRAM_ID) {
63
+ const ataX = getAssociatedTokenAddressSync(mintX, feeRecipient, false, tokenProgramX);
64
+ const ataY = getAssociatedTokenAddressSync(mintY, feeRecipient, false, tokenProgramY);
65
+ return [
66
+ createAssociatedTokenAccountIdempotentInstruction(
67
+ payer,
68
+ ataX,
69
+ feeRecipient,
70
+ mintX,
71
+ tokenProgramX
72
+ ),
73
+ createAssociatedTokenAccountIdempotentInstruction(
74
+ payer,
75
+ ataY,
76
+ feeRecipient,
77
+ mintY,
78
+ tokenProgramY
79
+ )
80
+ ];
49
81
  }
50
82
 
51
83
  // src/constants/index.ts
@@ -1262,7 +1294,7 @@ function buildSetPoolState(authority, configPda, params, programId = HADRON_PROG
1262
1294
  data
1263
1295
  });
1264
1296
  }
1265
- function buildUpdateDeltaStaleness(authority, configPda, params, programId = HADRON_PROGRAM_ID) {
1297
+ function buildUpdateDeltaStaleness(authority, configPda, curveMetaPda, params, programId = HADRON_PROGRAM_ID) {
1266
1298
  const data = Buffer.alloc(1 + 1);
1267
1299
  data.writeUInt8(Discriminator.UpdateDeltaStaleness, 0);
1268
1300
  data.writeUInt8(params.deltaStaleness, 1);
@@ -1270,7 +1302,8 @@ function buildUpdateDeltaStaleness(authority, configPda, params, programId = HAD
1270
1302
  programId,
1271
1303
  keys: [
1272
1304
  { pubkey: authority, isSigner: true, isWritable: false },
1273
- { pubkey: configPda, isSigner: false, isWritable: true }
1305
+ { pubkey: configPda, isSigner: false, isWritable: true },
1306
+ { pubkey: curveMetaPda, isSigner: false, isWritable: false }
1274
1307
  ],
1275
1308
  data
1276
1309
  });
@@ -1417,6 +1450,22 @@ var Hadron = class _Hadron {
1417
1450
  instructions.push(buildInitialize(payer, resolvedParams, programId));
1418
1451
  return { instructions, poolAddress, seed };
1419
1452
  }
1453
+ /**
1454
+ * Build idempotent create-ATA instructions for the fee recipient for both mints.
1455
+ *
1456
+ * These are no-ops on-chain if the ATAs already exist. Include them alongside
1457
+ * initialize or first deposit to ensure swaps don't fail due to missing fee ATAs.
1458
+ */
1459
+ static buildFeeRecipientAtaIxs(payer, feeRecipient, mintX, mintY, tokenProgramX, tokenProgramY) {
1460
+ return buildFeeRecipientAtaIxs(
1461
+ payer,
1462
+ feeRecipient,
1463
+ mintX,
1464
+ mintY,
1465
+ tokenProgramX ?? TOKEN_PROGRAM_ID3,
1466
+ tokenProgramY ?? TOKEN_PROGRAM_ID3
1467
+ );
1468
+ }
1420
1469
  /** Generate a random u64 seed. */
1421
1470
  static randomSeed() {
1422
1471
  const buf = new Uint8Array(8);
@@ -1684,6 +1733,7 @@ var Hadron = class _Hadron {
1684
1733
  return buildUpdateDeltaStaleness(
1685
1734
  authority,
1686
1735
  this.poolAddress,
1736
+ this.addresses.curveMeta,
1687
1737
  params,
1688
1738
  this.programId
1689
1739
  );
@@ -1797,7 +1847,7 @@ var Hadron = class _Hadron {
1797
1847
  }
1798
1848
  ixs.push(this.withdraw(user, params));
1799
1849
  if (hasSol) {
1800
- ixs.push(unwrapSolInstruction(user));
1850
+ ixs.push(...unwrapSolInstructions(user));
1801
1851
  }
1802
1852
  return ixs;
1803
1853
  }
@@ -1818,7 +1868,7 @@ var Hadron = class _Hadron {
1818
1868
  }
1819
1869
  ixs.push(this.swap(user, params));
1820
1870
  if (isNativeMint(outputMint)) {
1821
- ixs.push(unwrapSolInstruction(user));
1871
+ ixs.push(...unwrapSolInstructions(user));
1822
1872
  }
1823
1873
  return ixs;
1824
1874
  }
@@ -2387,9 +2437,9 @@ var HadronOrderbook = class _HadronOrderbook {
2387
2437
  import {
2388
2438
  getAssociatedTokenAddressSync as getAssociatedTokenAddressSync6,
2389
2439
  createAssociatedTokenAccountInstruction,
2390
- TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID3
2440
+ TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID4
2391
2441
  } from "@solana/spl-token";
2392
- async function getOrCreateAta(connection, mint, owner, payer, tokenProgram = TOKEN_PROGRAM_ID3, allowOwnerOffCurve = false) {
2442
+ async function getOrCreateAta(connection, mint, owner, payer, tokenProgram = TOKEN_PROGRAM_ID4, allowOwnerOffCurve = false) {
2393
2443
  const address = getAssociatedTokenAddressSync6(
2394
2444
  mint,
2395
2445
  owner,
@@ -2451,6 +2501,7 @@ export {
2451
2501
  buildApplyCurveUpdates,
2452
2502
  buildClosePool,
2453
2503
  buildDeposit,
2504
+ buildFeeRecipientAtaIxs,
2454
2505
  buildInitialize,
2455
2506
  buildInitializeFeeConfig,
2456
2507
  buildInitializePoolFeeConfig,
@@ -2504,7 +2555,7 @@ export {
2504
2555
  spreadBpsToQ32,
2505
2556
  spreadQ32ToBps,
2506
2557
  toQ32,
2507
- unwrapSolInstruction,
2558
+ unwrapSolInstructions,
2508
2559
  wrapSolInstructions
2509
2560
  };
2510
2561
  //# sourceMappingURL=index.mjs.map