ContextCoin (CTX) Solana ICO & Resource Management CLI

ContextCoin (CTX) Solana ICO & Resource Management CLI

A comprehensive CLI tool built with Python and Typer for interacting with a Solana program that manages an Initial Coin Offering (ICO) using an on-chain linear bonding curve and controls access to off-chain resources through pay-to-access functionality.

โœจ Features

Note: This project has undergone significant refactoring. The core logic is now split into modules within the src/ directory (solana_client.py, ico_manager.py, resource_manager.py, pda_utils.py, config.py, etc.) and the CLI uses typer instead of argparse.

Prerequisites

๐Ÿ“ฆ Recent Improvements

The codebase has undergone significant refactoring and quality improvements:

๐Ÿš€ Quick Start

  1. Clone and setup: bash git clone <repository_url> cd solana-ico python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install -r requirements.txt

  2. Configure environment: bash export SOLANA_CLUSTER_URL="http://localhost:8899" export SOLANA_PROGRAM_ID="YourProgramIdHere"

  3. Verify setup: bash python -m src.main config verify

  4. Check token info: bash python -m src.main info

๐Ÿ“ฆ Installation

  1. Clone the repository: bash git clone <repository_url> cd solana-ico

  2. Install dependencies: bash pip install -r requirements.txt --user

  3. Set up environment variables: ```bash # For local development export SOLANA_CLUSTER_URL="http://localhost:8899" export SOLANA_PROGRAM_ID="YourDeployedProgramIdHere"

    Or create a .env file

    echo "SOLANA_CLUSTER_URL=http://localhost:8899" > .env echo "SOLANA_PROGRAM_ID=YourDeployedProgramIdHere" >> .env ```

License

This project is licensed under the MIT-0 License. See the LICENSE file for details.

Configuration

The CLI requires two environment variables to be set:

  1. SOLANA_CLUSTER_URL: The HTTP URL of the Solana cluster RPC endpoint.
    • Defaults to http://localhost:8899 if not set.
    • Example: export SOLANA_CLUSTER_URL="https://api.devnet.solana.com"
  2. SOLANA_PROGRAM_ID: The public key (as a base58 string) of the deployed Solana program.
    • This must be set. There is no default.
    • Example: export SOLANA_PROGRAM_ID="YourProgramIdGoesHere..."

You can set these variables directly in your shell or place them in a .env file in the project root directory (the CLI uses python-dotenv to load it automatically).

SOLANA_CLUSTER_URL=http://localhost:8899
SOLANA_PROGRAM_ID=YourProgramIdGoesHere...

You can verify the configuration and connection using the config verify command.

๐Ÿ–ฅ๏ธ Usage

The main entry point is src/main.py. You can run commands using python -m src.main <command> [subcommand] [arguments].

๐Ÿ“‹ Available Commands

Get help for any command using --help:

python -m src.main --help          # Show all commands
python -m src.main info --help     # Show help for specific command
python -m src.main ico --help      # Show ICO subcommands

General Commands:

Configuration Commands:

ICO Commands (ico):

Resource Commands (resource):

Bonding Curve Mechanism

The ICO utilizes a linear bonding curve implemented directly within the deployed Solana program. This means the actual token price calculation, minting, and burning during ico buy and ico sell operations happen on-chain according to the parameters set during ico init (base_price, scaling_factor).

The src/curve_estimator.py module in this CLI provides a client-side function (calculate_price) to estimate the current token price based on the known tokenomics constants. This estimation is for informational purposes and may differ slightly from the exact price calculated by the on-chain program at the moment of a transaction due to potential state changes between estimation and execution.

Testing

The project uses unittest and unittest.mock. Tests are located in the src/tests/ directory.

To run the tests, ensure you have pytest installed (pip install pytest --user) and run it from the project root directory:

pytest

The pytest.ini file configures pytest to find modules within the src directory correctly.

Troubleshooting

Source Code

Browse the source repository