Skip to content

Does not detect tokens, neither at startup nor after swap #1

Description

@ra549243

Does not detect LAUNCHCOIN tokens that might already be in the wallet at startup. Proceeds to swap some SOL and still doesn't detect the swapped LAUNCHCOIN, causing it to create a single sided position (SOL only).

This fixes the second part (workaround - there's a problem with fetchBalances apparently):

// Fix: Get actual token balance from swap transaction (Jupiter uses different ATA)
const txInfo = await connection.getParsedTransaction(sig, { 
  maxSupportedTransactionVersion: 0, commitment: 'confirmed' 
});

if (txInfo?.meta?.postTokenBalances) {
  const myOutputBalance = txInfo.meta.postTokenBalances.find(
    balance => balance.mint === outputMint && 
               balance.owner === userKeypair.publicKey.toString() &&
               balance.uiTokenAmount.amount !== '0'
  );
  
  if (myOutputBalance) {
    const actualTokenBalance = new BN(myOutputBalance.uiTokenAmount.amount);
    
    // Update balance directly instead of using fetchBalances for swapped token
    if (outputMint === X_MINT) {
      lamX = actualTokenBalance;
      lamY = (await fetchBalances(connection, dlmmPool, userKeypair.publicKey)).lamY;
    } else {
      lamY = actualTokenBalance;
      lamX = (await fetchBalances(connection, dlmmPool, userKeypair.publicKey)).lamX;
    }
  }
} else {
  // Fallback to regular balance fetching if transaction parsing fails
  ({ lamX, lamY } = await fetchBalances(connection, dlmmPool, userKeypair.publicKey));
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions