Skip to content

Nanle-code/Automated-Rent-Reclaim-Bot

Repository files navigation

Kora Automated Rent-Reclaim Bot

An automated solution for Kora Node Operators to monitor sponsored accounts and reclaim locked rent-exempt SOL.

Overview

Kora is a fee abstraction layer on Solana that allows applications to sponsor transactions. A common use case for Kora is sponsoring account creation (e.g., Associated Token Accounts for new users).

The Rent Lockup Problem

On Solana, every account must maintain a minimum balance to be "rent-exempt" (currently ~0.002 SOL for a standard Token Account). When a Kora node sponsors account creation, this SOL is provided by the operator.

Over time:

  1. Users abandon accounts (e.g., they empty their balance).
  2. The account remains on-chain, locking 0.002 SOL.
  3. Operators experience "silent capital loss" as thousands of these accounts accumulate.

This bot solves that by identifying these accounts and reclaiming the SOL once they are no longer needed.


Features

  • Automated Scanning: Historically scans the operator's transaction history to find accounts they funded.
  • Smart Filtering: Detects which accounts are truly "sponsored" vs. just processed.
  • Eligibility Detection: Checks if accounts have zero balance and are safe to close.
  • Automated Reclamation: Closes eligible accounts and returns the SOL to the operator's treasury.
  • Reporting Dashboard: Provides a clear summary of total rent locked, potential savings, and reclaimed funds.

Technical Approach

1. Account Discovery

The bot uses the getSignaturesForAddress RPC method on the Kora Operator's public key. It parses each transaction to find:

  • SystemProgram.CreateAccount instructions where the operator is the funder.
  • AssociatedTokenAccount.Create instructions where the operator is the payer.

2. Monitoring

Discovered accounts are periodically checked for status.

  • Active: Account has tokens or data.
  • Empty: Account has 0 balance and is eligible for closure.
  • Reclaimed: Account has already been closed.

3. Reclaiming Logic

The bot issues a closeAccount instruction. For maximum safety and effectiveness, it is recommended that the Kora node is configured to set the Operator address as the closeAuthority during account creation sponsorship.


Getting Started

Prerequisites

  • Node.js & NPM
  • A Solana Keypair for your Kora Operator

Installation

npm install

Configuration

Create a .env file:

SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
KORA_OPERATOR_KEYPAIR_PATH=./operator-keypair.json
TREASURY_ADDRESS=YourTreasuryAddressHere

Running the Bot

npx ts-node src/bot.ts

Safety & Controls

  • Whitelists: You can extend the logic in scanner.ts to avoid reclaiming certain active accounts.
  • Simulation: Reclaim transactions are sent with confirmed commitment for reliability.
  • Transparency: Every action is logged with the transaction signature for audit trails.

Security Best Practices

  1. Cold Wallet Treasury: Set your TREASURY_ADDRESS to a cold wallet. The bot only needs the operator's private key for signing, but recovered SOL should go somewhere safer.
  2. Close Authority: For best results, ensure your Kora Node configuration sets the operator's public key as the closeAuthority during account creation instructions.

Troubleshooting

  • Permission Denied: If the bot fails to close an account, verify that the operator keypair is the designated closeAuthority for that account.
  • Rate Limits: If scanning many transactions, use a private RPC provider (e.g., Helius, QuickNode) to avoid being throttled by public endpoints.

License

Open Source (MIT)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors