chore: add transfer2 close safeguard#2234
Conversation
📝 WalkthroughWalkthroughThis PR adds a runtime validation check to the Solana token closing path that verifies the token account balance is zero before allowing the close operation to proceed. Non-zero balances will trigger a NonNativeHasBalance error, preventing improper account closure. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
programs/compressed-token/program/src/compressed_token/transfer2/compression/ctoken/compress_and_close.rs (1)
28-30:⚠️ Potential issue | 🟠 MajorImport and use
convert_token_errorforToken::amount_from_slicefailures.At lines 274-275,
Token::amount_from_slicereturns aTokenErrorfrom the SPL Token interface, but the current code discards it and maps to the genericProgramError::InvalidAccountData. This breaks the expected ErrorCode contract by losing the SPL Token error information.Import
convert_token_errorfrom the shared module and apply it to the error:🔧 Fix
use crate::{ compressed_token::transfer2::accounts::Transfer2Accounts, shared::convert_program_error, + shared::convert_token_error, }; ... let amount = Token::amount_from_slice(&data) - .map_err(|_| ProgramError::InvalidAccountData)?; + .map_err(convert_token_error)?;
Summary by CodeRabbit