I'm trying to swap wsol against usdc and then in second transaction wsol against the usdc it's sort of arbitrage script. Now that I don't have wsol balance but the Jupiter aggregator uses sol from my wallet to wrap them into wsol. But when I read the wsol balance it return zero.. So my question is does the Jupiter will also give me sol out instead of wsol in second swap because below is a function that read the balance of token for other token it has no issue but for the wsol it always return 0. Is it due to
same machenism of wrapping and unwrapping.
private async getTokenBalance(
wallet: PublicKey,
tokenMint: PublicKey
): Promise<number> {
try {
let tokenAccountPublicKey: PublicKey;
if (tokenMint.equals(new PublicKey("So11111111111111111111111111111111111111112"))) {
// For WSOL, fetch the associated token account for the wallet
tokenAccountPublicKey = await getAssociatedTokenAddress(
tokenMint, // The mint address for WSOL
wallet, // Wallet public key
false // Specify if the account should be writable (false by default)
);
} else {
// For other SPL tokens, get the associated token account
const tokenAccounts = await this.solanaConnection.getTokenAccountsByOwner(wallet, {
mint: tokenMint,
});
if (tokenAccounts.value.length === 0) return 0; // No associated token account found
tokenAccountPublicKey = tokenAccounts.value[0].pubkey;
}
// Fetch the account information for the token account
const tokenAccountInfo = await this.solanaConnection.getParsedAccountInfo(tokenAccountPublicKey);
const tokenBalance = (tokenAccountInfo.value?.data as any)?.parsed?.info?.tokenAmount?.uiAmount;
return tokenBalance || 0; // Return the balance, or 0 if not found
} catch (error) {
console.error("Error fetching token balance:", error);
return 0; // Return 0 in case of an error
}
}