fix: solana token sends to pda addresses and receive qr fiat amounts (#3799)
What changed, and why it matters
This commit fixes two separate bugs in Cake Wallet. First, it improves Solana token sends to addresses that are Program Derived Addresses (PDAs) — special address types used by smart contracts. Previously, sending tokens to such addresses could fail or create associated token accounts incorrectly. The fix checks whether the destination is a PDA, verifies it is not itself a token account, and then allows the off-curve owner when deriving the recipient's associated token account. Second, it fixes a UI bug where fiat-to-crypto conversion in QR code receive amounts could show too many decimal places for tokens with fewer decimals than 8, by capping the displayed precision to the cryptocurrency's actual decimal count. It also corrects a typo in an error message ('receipient' to 'recipient').
Review the Solana token send path for additional edge cases with off-curve recipients, and verify that the new account-info RPC call handles network failures and null responses safely. Consider whether the fiat-to-crypto QR fix should also apply to other amount-formatting locations.
Security signals we found
Off-curve Solana address handling added for token sends
Validation that off-curve destination is not itself a token account
allowOwnerOffCurve flag enabled for PDA owners in associated token account derivation
Precision cap added to fiat-to-crypto QR amount conversion
Evidence from the diff
In cw_solana/lib/solana_client.dart, the Solana token transfer flow now: (1) wraps the destination address as a SolAddress and checks isOnCurve; (2) if off-curve, fetches account info and rejects destinations whose owner is the SPL Token or Token-2022 program, throwing SolanaCreateAssociatedTokenAccountException with a clearer message; (3) passes allowOwnerOffCurve: true to associatedTokenAccount derivation when the owner is off-curve. In lib/view_model/wallet_address_list/wallet_address_list_view_model.dart, fiat-amount-to-crypto conversion for receive QR codes now uses min(cryptoCurrency.decimals, 8) instead of hardcoded 8, preventing precision overflow for low-decimal assets. The strings file corrects a typo only.
Changed components
cw_solana/lib/solana_client.dartlib/view_model/wallet_address_list/wallet_address_list_view_model.dartres/values/strings_en.arbInspect captured patch +23 / −3
### cw_solana/lib/solana_client.dart
@@ -1859,10 +1859,28 @@ class SolanaWalletClient {
bool shouldCreateRecipientAccount = false;
try {
+ final recipientOwner = SolAddress(destinationAddress);
+ final isOffCurveRecipient = !recipientOwner.isOnCurve;
+
+ if (isOffCurveRecipient) {
+ final destinationInfo = await _provider!.request(
+ SolanaRPCGetAccountInfo(account: recipientOwner, commitment: Commitment.confirmed),
+ );
+
+ final destinationOwnerProgram = destinationInfo?.owner.address;
+ if (destinationOwnerProgram == SPLTokenProgramConst.tokenProgramId.address ||
+ destinationOwnerProgram == SPLTokenProgramConst.token2022ProgramId.address) {
+ throw SolanaCreateAssociatedTokenAccountException(
+ "Recipient $destinationAddress is a token account, not a wallet address",
+ );
+ }
+ }
+
final recipientPDA = AssociatedTokenAccountProgramUtils.associatedTokenAccount(
mint: mintAddress,
- owner: SolAddress(destinationAddress),
+ owner: recipientOwner,
tokenProgramId: senderTokenProgramId,
+ allowOwnerOffCurve: isOffCurveRecipient,
);
SolanaAccountInfo? recipientInfo;
### lib/view_model/wallet_address_list/wallet_address_list_view_model.dart
@@ -1,5 +1,6 @@
import "dart:core";
import "dart:developer" as dev;
+import "dart:math";
import "package:cake_wallet/bitcoin/bitcoin.dart";
import "package:cake_wallet/core/amount_parsing_proxy.dart";
@@ -771,7 +772,8 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
}
try {
- final crypto = (double.parse(_amount.replaceAll(",", ".")) / fiatRate).toStringAsFixed(8);
+ final crypto = (double.parse(_amount.replaceAll(",", ".")) / fiatRate)
+ .toStringAsFixed(min(cryptoCurrency.decimals, 8));
if (_amount != crypto) {
_amount = crypto;
}
### res/values/strings_en.arb
@@ -1270,7 +1270,7 @@
"skip_verification_title": "Are you sure?",
"skip_verification_warning": "If you don’t back up your Recovery Phrase and then you lose access to either Cake Wallet or your device, your assets will be lost.",
"slidable": "Slidable",
- "solana_create_associated_token_account_exception": "Error creating associated token account for receipient address.",
+ "solana_create_associated_token_account_exception": "Error creating associated token account for recipient address.",
"solana_invalid_data_message": "Error parsing associated token account for token. Kindly confirm receive address and try again.",
"solana_no_associated_token_account_exception": "There is no associated token account for this address.",
"solana_sign_native_transaction_rent_exception": "Transaction cannot be completed. Insufficient SOL left for rent after transaction. Kindly top up your SOL balance or reduce the amount of SOL you are sending.",Why this scored 41/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.