@meteora-ag/dlmm 1.0.7 → 1.0.8

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
@@ -4544,10 +4544,11 @@ import { AnchorProvider, BN as BN6, Program } from "@coral-xyz/anchor";
4544
4544
  import {
4545
4545
  NATIVE_MINT,
4546
4546
  TOKEN_PROGRAM_ID,
4547
+ TokenAccountNotFoundError,
4548
+ TokenInvalidAccountOwnerError,
4547
4549
  createAssociatedTokenAccountInstruction,
4548
4550
  createCloseAccountInstruction,
4549
4551
  getAccount,
4550
- getAssociatedTokenAddress,
4551
4552
  getAssociatedTokenAddressSync,
4552
4553
  getMint
4553
4554
  } from "@solana/spl-token";
@@ -5517,25 +5518,27 @@ async function getTokenDecimals(conn, mint) {
5517
5518
  return await token.decimals;
5518
5519
  }
5519
5520
  var getOrCreateATAInstruction = async (connection, tokenMint, owner, payer = owner, allowOwnerOffCurve = true) => {
5521
+ const toAccount = getAssociatedTokenAddressSync(
5522
+ tokenMint,
5523
+ owner,
5524
+ allowOwnerOffCurve
5525
+ );
5520
5526
  try {
5521
- const toAccount = await getAssociatedTokenAddress(
5522
- tokenMint,
5523
- owner,
5524
- allowOwnerOffCurve
5525
- );
5526
- const account = await connection.getAccountInfo(toAccount);
5527
- if (account)
5528
- return { ataPubKey: toAccount, ix: void 0 };
5529
- const ix = createAssociatedTokenAccountInstruction(
5530
- payer,
5531
- toAccount,
5532
- owner,
5533
- tokenMint
5534
- );
5535
- return { ataPubKey: toAccount, ix };
5527
+ await getAccount(connection, toAccount);
5528
+ return { ataPubKey: toAccount, ix: void 0 };
5536
5529
  } catch (e) {
5537
- console.error("Error::getOrCreateATAInstruction", e);
5538
- throw e;
5530
+ if (e instanceof TokenAccountNotFoundError || e instanceof TokenInvalidAccountOwnerError) {
5531
+ const ix = createAssociatedTokenAccountInstruction(
5532
+ payer,
5533
+ toAccount,
5534
+ owner,
5535
+ tokenMint
5536
+ );
5537
+ return { ataPubKey: toAccount, ix };
5538
+ } else {
5539
+ console.error("Error::getOrCreateATAInstruction", e);
5540
+ throw e;
5541
+ }
5539
5542
  }
5540
5543
  };
5541
5544
  async function getTokenBalance(conn, tokenAccount) {