@ape.swap/bonds-sdk 5.0.7 → 5.1.0-test.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/main.js CHANGED
@@ -11,7 +11,7 @@ import { getStructDecoder, fixDecoderSize, getU32Decoder, getU8Decoder, getU64De
11
11
  import { useWallet } from '@solana/wallet-adapter-react';
12
12
  import { useWalletModal } from '@solana/wallet-adapter-react-ui';
13
13
  import { ConnectButton as ConnectButton$1 } from '@rainbow-me/rainbowkit';
14
- import { getAssociatedTokenAddress, getAccount, createAssociatedTokenAccountInstruction, TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token';
14
+ import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, getAssociatedTokenAddress, getAccount, createAssociatedTokenAccountInstruction, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token';
15
15
  import { LiFiWidget } from '@lifi/widget';
16
16
 
17
17
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -46817,7 +46817,7 @@ const PUBLIC_RPC_URLS = {
46817
46817
  [main.ChainId.BSC_TESTNET]: ['https://data-seed-prebsc-2-s3.binance.org:8545/'],
46818
46818
  [main.ChainId.MATIC]: [
46819
46819
  'https://polygon.drpc.org',
46820
- 'https://polygon-rpc.com/',
46820
+ 'https://polygon-rpc.com/', // this is now freemium
46821
46821
  'https://polygon-mainnet.public.blastapi.io/',
46822
46822
  'https://rpc-mainnet.matic.network',
46823
46823
  'https://matic-mainnet.chainstacklabs.com',
@@ -59423,18 +59423,38 @@ const Actions = ({ userBill }) => {
59423
59423
  : null, disabled: !canPurchaseAgain, children: canPurchaseAgain ? 'Buy again' : 'sold out' })] }));
59424
59424
  };
59425
59425
 
59426
+ /**
59427
+ * Detects which token program owns a mint (SPL Token or Token-2022)
59428
+ * @param connection - Solana connection
59429
+ * @param mint - The mint public key to check
59430
+ * @returns The token program ID (TOKEN_PROGRAM_ID or TOKEN_2022_PROGRAM_ID)
59431
+ */
59432
+ const getTokenProgramForMint = async (connection, mint) => {
59433
+ const accountInfo = await connection.getAccountInfo(mint);
59434
+ if (!accountInfo) {
59435
+ throw new Error(`Mint account not found: ${mint.toBase58()}`);
59436
+ }
59437
+ if (accountInfo.owner.equals(TOKEN_2022_PROGRAM_ID)) {
59438
+ return TOKEN_2022_PROGRAM_ID;
59439
+ }
59440
+ return TOKEN_PROGRAM_ID;
59441
+ };
59426
59442
  /**
59427
59443
  * Checks if an Associated Token Account exists and returns creation instruction if needed
59444
+ * Now supports both SPL Token and Token-2022 by detecting the correct token program
59428
59445
  * @returns Object with ATA address and optional creation instruction
59429
59446
  */
59430
59447
  const getAtaWithCreateInstruction = async (connection, mint, owner, payer = owner) => {
59431
- const ataAddress = await getAssociatedTokenAddress(mint, owner);
59448
+ // Detect which token program owns this mint
59449
+ const tokenProgram = await getTokenProgramForMint(connection, mint);
59450
+ // Get ATA with the correct token program
59451
+ const ataAddress = await getAssociatedTokenAddress(mint, owner, true, tokenProgram);
59432
59452
  try {
59433
- await getAccount(connection, ataAddress);
59453
+ await getAccount(connection, ataAddress, undefined, tokenProgram);
59434
59454
  return { address: ataAddress, createInstruction: null };
59435
59455
  }
59436
59456
  catch (_a) {
59437
- const createInstruction = createAssociatedTokenAccountInstruction(payer, ataAddress, owner, mint);
59457
+ const createInstruction = createAssociatedTokenAccountInstruction(payer, ataAddress, owner, mint, tokenProgram);
59438
59458
  return { address: ataAddress, createInstruction };
59439
59459
  }
59440
59460
  };
@@ -59478,6 +59498,8 @@ const ActionsSolana = ({ userBill }) => {
59478
59498
  const bondIssuancePda = new PublicKey(contractAddress);
59479
59499
  const bondPricingPda = derivePda('bond_pricing', bondIssuancePda, PROGRAM_ID);
59480
59500
  const nftMint = new PublicKey(userBill.asset);
59501
+ // Detect token program for payout mint (supports Token-2022)
59502
+ const payoutTokenProgram = await getTokenProgramForMint(connection, payoutMint);
59481
59503
  const [bondTermPda] = PublicKey.findProgramAddressSync([new TextEncoder().encode('bond_term'), bondIssuancePda.toBuffer()], PROGRAM_ID);
59482
59504
  const [bondPda] = PublicKey.findProgramAddressSync([new TextEncoder().encode('bond'), bondIssuancePda.toBuffer(), nftMint.toBuffer()], PROGRAM_ID);
59483
59505
  // Get user payout ATA and creation instruction if needed
@@ -59494,7 +59516,8 @@ const ActionsSolana = ({ userBill }) => {
59494
59516
  { pubkey: nftMint, isSigner: false, isWritable: true },
59495
59517
  { pubkey: userPayoutAta, isSigner: false, isWritable: true },
59496
59518
  { pubkey: treasuryAta, isSigner: false, isWritable: true },
59497
- { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
59519
+ { pubkey: payoutMint, isSigner: false, isWritable: false }, // payout_mint
59520
+ { pubkey: payoutTokenProgram, isSigner: false, isWritable: false }, // token_program (dynamic)
59498
59521
  { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
59499
59522
  { pubkey: new PublicKey('CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d'), isSigner: false, isWritable: false }, // mplCoreProgram
59500
59523
  { pubkey: PROGRAM_ID, isSigner: false, isWritable: false }, // passing programId is the same as passing null
@@ -59901,6 +59924,8 @@ const UserBondRowSolana = ({ bill }) => {
59901
59924
  const bondIssuancePda = new PublicKey(contractAddress);
59902
59925
  const bondPricingPda = derivePda('bond_pricing', bondIssuancePda, PROGRAM_ID);
59903
59926
  const nftMint = new PublicKey(bill.asset);
59927
+ // Detect token program for payout mint (supports Token-2022)
59928
+ const payoutTokenProgram = await getTokenProgramForMint(connection, payoutMint);
59904
59929
  const [bondTermPda] = PublicKey.findProgramAddressSync([new TextEncoder().encode('bond_term'), bondIssuancePda.toBuffer()], PROGRAM_ID);
59905
59930
  const [bondPda] = PublicKey.findProgramAddressSync([new TextEncoder().encode('bond'), bondIssuancePda.toBuffer(), nftMint.toBuffer()], PROGRAM_ID);
59906
59931
  // Get user payout ATA and creation instruction if needed
@@ -59917,7 +59942,8 @@ const UserBondRowSolana = ({ bill }) => {
59917
59942
  { pubkey: nftMint, isSigner: false, isWritable: true },
59918
59943
  { pubkey: userPayoutAta, isSigner: false, isWritable: true },
59919
59944
  { pubkey: treasuryAta, isSigner: false, isWritable: true },
59920
- { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
59945
+ { pubkey: payoutMint, isSigner: false, isWritable: false }, // payout_mint
59946
+ { pubkey: payoutTokenProgram, isSigner: false, isWritable: false }, // token_program (dynamic)
59921
59947
  { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
59922
59948
  { pubkey: new PublicKey('CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d'), isSigner: false, isWritable: false }, // mplCoreProgram
59923
59949
  { pubkey: PROGRAM_ID, isSigner: false, isWritable: false }, // passing programId is the same as passing null
@@ -62535,10 +62561,12 @@ const getTokenBalanceSolana = async (currency, account) => {
62535
62561
  }
62536
62562
  else {
62537
62563
  const mint = new PublicKey((_a = currency === null || currency === void 0 ? void 0 : currency.address) === null || _a === void 0 ? void 0 : _a[main.ChainId.SOL]);
62538
- const ata = await getAssociatedTokenAddress(mint, userPubkey);
62564
+ // Detect token program to get correct ATA (supports Token-2022)
62565
+ const tokenProgram = await getTokenProgramForMint(connection, mint);
62566
+ const ata = await getAssociatedTokenAddress(mint, userPubkey, true, tokenProgram);
62539
62567
  if (!ata)
62540
62568
  return '0';
62541
- const tokenAccount = await getAccount(connection, ata);
62569
+ const tokenAccount = await getAccount(connection, ata, undefined, tokenProgram);
62542
62570
  const amount = new BigNumber$1(tokenAccount.amount.toString()).dividedBy(new BigNumber$1(10).pow((_b = currency === null || currency === void 0 ? void 0 : currency.decimals) === null || _b === void 0 ? void 0 : _b[main.ChainId.SOL]));
62543
62571
  return amount.toString();
62544
62572
  }
@@ -66189,6 +66217,11 @@ const BuyComponentSolana = ({ onDismiss, bondAddress, bondChain, isProjectView,
66189
66217
  const principalMint = new PublicKey(bondData.lpToken.address[bondData.chainId]);
66190
66218
  const payoutMint = new PublicKey(bondData.earnToken.address[bondData.chainId]);
66191
66219
  const collection = new PublicKey(bondData.billNnftAddress[bondData.chainId]);
66220
+ // Detect token programs for both mints (supports Token-2022)
66221
+ const [principalTokenProgram, payoutTokenProgram] = await Promise.all([
66222
+ getTokenProgramForMint(connection, principalMint),
66223
+ getTokenProgramForMint(connection, payoutMint),
66224
+ ]);
66192
66225
  // Fetch Bond Issuance Account
66193
66226
  const bondIssuanceAccounts = (await getBondIssuanceAccountSolana([
66194
66227
  bondIssuancePda.toBase58(),
@@ -66205,11 +66238,11 @@ const BuyComponentSolana = ({ onDismiss, bondAddress, bondChain, isProjectView,
66205
66238
  // Create NFT mint
66206
66239
  const nftMint = Keypair.generate();
66207
66240
  const [bondPda] = PublicKey.findProgramAddressSync([buffer.Buffer.from('bond'), bondIssuancePda.toBuffer(), nftMint.publicKey.toBuffer()], PROGRAM_ID);
66208
- // ATAs
66209
- const userPrincipalAta = await getAssociatedTokenAddress(principalMint, user);
66210
- const treasuryAta = await getAssociatedTokenAddress(payoutMint, bondIssuancePda, true);
66211
- const feePrincipalRecipientAta = await getAssociatedTokenAddress(principalMint, feeRecipient, true);
66212
- const partnerPrincipalRecipientAta = await getAssociatedTokenAddress(principalMint, partnerRecipient, true);
66241
+ // ATAs - use correct token program for each mint
66242
+ const userPrincipalAta = await getAssociatedTokenAddress(principalMint, user, true, principalTokenProgram);
66243
+ const treasuryAta = await getAssociatedTokenAddress(payoutMint, bondIssuancePda, true, payoutTokenProgram);
66244
+ const feePrincipalRecipientAta = await getAssociatedTokenAddress(principalMint, feeRecipient, true, principalTokenProgram);
66245
+ const partnerPrincipalRecipientAta = await getAssociatedTokenAddress(principalMint, partnerRecipient, true, principalTokenProgram);
66213
66246
  const [feePayoutRecipientAta] = PublicKey.findProgramAddressSync([feePayoutRecipient.toBuffer(), FEE_PAYOUT_CONST_SEED, payoutMint.toBuffer()], FEE_PAYOUT_PDA_PROGRAM);
66214
66247
  // Encode args
66215
66248
  const u64Codec = getU64Codec();
@@ -66230,8 +66263,11 @@ const BuyComponentSolana = ({ onDismiss, bondAddress, bondChain, isProjectView,
66230
66263
  { pubkey: partnerPrincipalRecipientAta, isSigner: false, isWritable: true },
66231
66264
  { pubkey: feePayoutRecipientAta, isSigner: false, isWritable: true },
66232
66265
  { pubkey: treasuryAta, isSigner: false, isWritable: true },
66266
+ { pubkey: principalMint, isSigner: false, isWritable: false },
66267
+ { pubkey: payoutMint, isSigner: false, isWritable: false },
66233
66268
  { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
66234
- { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
66269
+ { pubkey: principalTokenProgram, isSigner: false, isWritable: false }, // principal_token_program (dynamic)
66270
+ { pubkey: payoutTokenProgram, isSigner: false, isWritable: false }, // payout_token_program (dynamic)
66235
66271
  { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
66236
66272
  { pubkey: MPL_CORE_PROGRAM_ID, isSigner: false, isWritable: false },
66237
66273
  { pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false },
@@ -66328,11 +66364,11 @@ const BuyComponentSolana = ({ onDismiss, bondAddress, bondChain, isProjectView,
66328
66364
  });
66329
66365
  };
66330
66366
  // Helper: Ensure user's principal token account exists
66331
- const ensureUserPrincipalAtaExists = async (connection, payer, principalMint, user) => {
66332
- const userPrincipalAta = await getAssociatedTokenAddress(principalMint, user);
66367
+ const ensureUserPrincipalAtaExists = async (connection, payer, principalMint, user, tokenProgram) => {
66368
+ const userPrincipalAta = await getAssociatedTokenAddress(principalMint, user, true, tokenProgram);
66333
66369
  try {
66334
66370
  // Check if account exists
66335
- await getAccount(connection, userPrincipalAta);
66371
+ await getAccount(connection, userPrincipalAta, undefined, tokenProgram);
66336
66372
  return { ataAddress: userPrincipalAta, createInstruction: null };
66337
66373
  }
66338
66374
  catch (_a) {
@@ -66340,7 +66376,8 @@ const BuyComponentSolana = ({ onDismiss, bondAddress, bondChain, isProjectView,
66340
66376
  const createAtaIx = createAssociatedTokenAccountInstruction(payer, // fee payer
66341
66377
  userPrincipalAta, // ATA to create
66342
66378
  user, // owner of ATA
66343
- principalMint);
66379
+ principalMint, // mint
66380
+ tokenProgram);
66344
66381
  return { ataAddress: userPrincipalAta, createInstruction: createAtaIx };
66345
66382
  }
66346
66383
  };
@@ -66402,6 +66439,11 @@ const BuyComponentSolana = ({ onDismiss, bondAddress, bondChain, isProjectView,
66402
66439
  const principalMint = new PublicKey(bondData.lpToken.address[bondData.chainId]);
66403
66440
  const payoutMint = new PublicKey(bondData.earnToken.address[bondData.chainId]);
66404
66441
  const collection = new PublicKey(bondData.billNnftAddress[bondData.chainId]);
66442
+ // Detect token programs for both mints (supports Token-2022)
66443
+ const [principalTokenProgram, payoutTokenProgram] = await Promise.all([
66444
+ getTokenProgramForMint(connection, principalMint),
66445
+ getTokenProgramForMint(connection, payoutMint),
66446
+ ]);
66405
66447
  const bondIssuanceAccounts = (await getBondIssuanceAccountSolana([
66406
66448
  bondIssuancePda.toBase58(),
66407
66449
  ]));
@@ -66416,10 +66458,10 @@ const BuyComponentSolana = ({ onDismiss, bondAddress, bondChain, isProjectView,
66416
66458
  const nftMint = Keypair.generate();
66417
66459
  const [bondPda] = PublicKey.findProgramAddressSync([buffer.Buffer.from('bond'), bondIssuancePda.toBuffer(), nftMint.publicKey.toBuffer()], PROGRAM_ID);
66418
66460
  // Ensure user's USDC account exists, get creation instruction if needed
66419
- const { ataAddress: userPrincipalAta, createInstruction: createPrincipalAtaIx } = await ensureUserPrincipalAtaExists(connection, accountSolana, principalMint, accountSolana);
66420
- const treasuryAta = await getAssociatedTokenAddress(payoutMint, bondIssuancePda, true);
66421
- const feePrincipalRecipientAta = await getAssociatedTokenAddress(principalMint, feeRecipient, true);
66422
- const partnerPrincipalRecipientAta = await getAssociatedTokenAddress(principalMint, partnerRecipient, true);
66461
+ const { ataAddress: userPrincipalAta, createInstruction: createPrincipalAtaIx } = await ensureUserPrincipalAtaExists(connection, accountSolana, principalMint, accountSolana, principalTokenProgram);
66462
+ const treasuryAta = await getAssociatedTokenAddress(payoutMint, bondIssuancePda, true, payoutTokenProgram);
66463
+ const feePrincipalRecipientAta = await getAssociatedTokenAddress(principalMint, feeRecipient, true, principalTokenProgram);
66464
+ const partnerPrincipalRecipientAta = await getAssociatedTokenAddress(principalMint, partnerRecipient, true, principalTokenProgram);
66423
66465
  const [feePayoutRecipientAta] = PublicKey.findProgramAddressSync([feePayoutRecipient.toBuffer(), FEE_PAYOUT_CONST_SEED, payoutMint.toBuffer()], FEE_PAYOUT_PDA_PROGRAM);
66424
66466
  const u64Codec = getU64Codec();
66425
66467
  const maxPriceEncoded = buffer.Buffer.from(u64Codec.encode(BigInt(maxPrice)));
@@ -66436,8 +66478,11 @@ const BuyComponentSolana = ({ onDismiss, bondAddress, bondChain, isProjectView,
66436
66478
  { pubkey: partnerPrincipalRecipientAta, isSigner: false, isWritable: true },
66437
66479
  { pubkey: feePayoutRecipientAta, isSigner: false, isWritable: true },
66438
66480
  { pubkey: treasuryAta, isSigner: false, isWritable: true },
66481
+ { pubkey: principalMint, isSigner: false, isWritable: false },
66482
+ { pubkey: payoutMint, isSigner: false, isWritable: false },
66439
66483
  { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
66440
- { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
66484
+ { pubkey: principalTokenProgram, isSigner: false, isWritable: false }, // principal_token_program (dynamic)
66485
+ { pubkey: payoutTokenProgram, isSigner: false, isWritable: false }, // payout_token_program (dynamic)
66441
66486
  { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
66442
66487
  { pubkey: MPL_CORE_PROGRAM_ID, isSigner: false, isWritable: false },
66443
66488
  { pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false },
@@ -66468,8 +66513,8 @@ const BuyComponentSolana = ({ onDismiss, bondAddress, bondChain, isProjectView,
66468
66513
  console.log(` Setup ${i}: ${ix.accounts.length} accounts`);
66469
66514
  totalAccounts += ix.accounts.length;
66470
66515
  });
66471
- console.log('Bond instruction accounts:', 17);
66472
- console.log('Total accounts:', totalAccounts + 17);
66516
+ console.log('Bond instruction accounts:', 20);
66517
+ console.log('Total accounts:', totalAccounts + 20);
66473
66518
  console.log('=== END ANALYSIS ===');
66474
66519
  // STEP 3: TRY SINGLE TRANSACTION (if direct route)
66475
66520
  if (isDirectRoute) {
@@ -1,6 +1,14 @@
1
1
  import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
2
+ /**
3
+ * Detects which token program owns a mint (SPL Token or Token-2022)
4
+ * @param connection - Solana connection
5
+ * @param mint - The mint public key to check
6
+ * @returns The token program ID (TOKEN_PROGRAM_ID or TOKEN_2022_PROGRAM_ID)
7
+ */
8
+ export declare const getTokenProgramForMint: (connection: Connection, mint: PublicKey) => Promise<PublicKey>;
2
9
  /**
3
10
  * Checks if an Associated Token Account exists and returns creation instruction if needed
11
+ * Now supports both SPL Token and Token-2022 by detecting the correct token program
4
12
  * @returns Object with ATA address and optional creation instruction
5
13
  */
6
14
  export declare const getAtaWithCreateInstruction: (connection: Connection, mint: PublicKey, owner: PublicKey, payer?: PublicKey) => Promise<{
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Ape Bond SDK",
4
4
  "author": "Ape Bond",
5
5
  "license": "MIT",
6
- "version": "5.0.7",
6
+ "version": "5.1.0-test.0",
7
7
  "module": "dist/main.js",
8
8
  "type": "module",
9
9
  "types": "dist/main.d.ts",
@@ -62,7 +62,7 @@
62
62
  "@types/react": "^18.3.3",
63
63
  "@types/react-dom": "^18.3.0",
64
64
  "@vitejs/plugin-react": "^4.7.0",
65
- "axios": "1.13.2",
65
+ "axios": "1.13.5",
66
66
  "eslint": "^9.28.0",
67
67
  "eslint-plugin-react": "^7.37.5",
68
68
  "eslint-plugin-react-hooks": "^5.2.0",