You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.4 KiB

#!/bin/bash
echo "🗑 Closing All Token Accounts"
echo "=============================="
echo "⚠ This will close ALL token accounts and burn any remaining tokens!"
echo "💰 You will reclaim the SOL used for rent"
echo "📍 Cluster: devnet (safe for testing)"
echo ""
# Confirm before proceeding
read -p "Are you sure you want to close ALL token accounts? (type 'yes' to confirm): " confirm
if [ "$confirm" != "yes" ]; then
echo "❌ Aborted - no accounts closed"
exit 1
fi
echo "🗑 Starting token account closure process..."
echo ""
# Set to devnet
solana config set --url devnet > /dev/null
echo "💰 Current wallet: $(solana address)"
echo "🌐 Cluster: devnet"
echo ""
echo "💰 SOL balance before: $(solana balance --url devnet)"
echo ""
# Get all token accounts and close them
echo "📊 Current token accounts:"
spl-token accounts --url devnet
echo ""
# List of specific token account addresses to close (from verbose output)
TOKEN_ACCOUNTS=(
"8zr6uF84gTzY5V1MP9EeEfy6m2LNULkH4VEFgxY1fKwh"
"679vTxSpUw55buSgPpUsEp66eiUCQs3Y7acpoeTt6W97"
"4t7iZeFsLXA2Ro1EyxoR88Aqnq62Da4txb74eiC2WovQ"
"AmNmTDXjESr1PZTjEC6QiWqLbeZxdxdQkM2TasSUL88QK"
)
# Function to close a token account
close_account() {
local account=$1
echo "🗑 Processing token account: $account"
# Try to close the account directly
local result=$(spl-token close-account $account --url devnet 2>&1)
if [ $? -eq 0 ]; then
echo " ✅ Successfully closed account and reclaimed SOL"
else
echo " ❌ Failed to close account: $result"
# If direct closure failed, try to get the mint and burn first
echo " 🔄 Trying alternative approach..."
# Get account info to find the mint
local account_info=$(solana account $account --url devnet --output json 2>/dev/null)
if [ $? -eq 0 ]; then
echo " ℹ Account exists, attempting force closure..."
spl-token close-account $account --force --url devnet 2>/dev/null
if [ $? -eq 0 ]; then
echo " ✅ Force closure successful"
else
echo " ⚠ Account could not be closed (may have non-zero balance)"
fi
else
echo " ℹ Account may already be closed or doesn't exist"
fi
fi
echo ""
}
# Close all token accounts
for account in "${TOKEN_ACCOUNTS[@]}"; do
close_account $account
done
# Also try to close by mint address (alternative approach)
echo "🔄 Attempting closure by mint address as backup..."
MINTS=(
"4auc435LJ9AfprLeMziHTJbP8wQmbSi7o4ZpeXdR66jQ"
"5xEQF57sR2L3tJBfdiiqaVtepTMa7nQR9uMybMojEY8n"
"8cJ8APx5TwwmpeRk4Zhz1Qbyi1T3HHdHUEw4GUJqxAGN"
"AK9fXWyDNWurYjZSDhbqBo6fczqLmCLbCZ3vq9Vftsqb"
)
for mint in "${MINTS[@]}"; do
echo "🗑 Attempting to close account for mint: $mint"
spl-token close $mint --url devnet 2>/dev/null
if [ $? -eq 0 ]; then
echo " ✅ Closed successfully"
else
echo " ⚠ Could not close (may not exist or have balance)"
fi
done
echo ""
echo "🎯 Token account closure process complete!"
echo ""
echo "📊 Final token account status:"
spl-token accounts --url devnet
echo ""
echo "💰 Final SOL balance:"
solana balance --url devnet
echo ""
echo "✅ Token accounts processed!"
echo "🧪 Ready for clean testing with your PoWH program"