How solana-program/token-2022 works
Main Components
• On-Chain Program: Represented by the “program” directory that contains the Solana program’s source code (entrypoint, instructions, error handling, extensions like confidential transfer, memo transfer, etc.). This is the core blockchain component.
• Client Libraries: There are multiple client implementations:
– JS Client (in “clients/js” and “clients/js-legacy”) that interact with the on-chain program.
– CLI Client (in “clients/cli”) that likely provides direct command-line access.
– Rust Client (in “clients/rust” and “clients/rust-legacy”).
• Confidential Transfer Modules: The “confidential-transfer” folder includes submodules for ciphertext arithmetic, elgamal registry, proof extraction, proof generation, and related tests. These modules are critical for key aspects of confidential computations and extending the token program.
• Build, Test, and Deployment Tools: Various scripts (in “scripts/” and “.github/” folders) for building, testing, formatting, linting, IDL generation, client generation, and managing the local validator.
• External Dependencies & Validator Setup: The README discusses incorporating external programs (with specific program IDs) into the local validator configuration.
Establish Component Relationships
• Off-Chain Clients ↔ On-Chain Program:
• Confidential Transfer Modules ↔ On-Chain Program:
– Show how confidential transfer extensions (and cryptographic modules) integrate with or extend the core Solana program functionality.
• Build/CI/CD Pipelines ↔ Code Components:
• External Programs:
• Development & Testing Tools:
– Incorporate elements for running local validator (start/stop scripts) and additional testing frameworks (unit tests, end-to-end tests).
Architectural Patterns / Design Principles
• Separation of Concerns:
– Clearly separate the on-chain components (Solana program) from off-chain components (client libraries and scripts).
• Modular Design:
– Each client library and the confidential transfer module are developed as separate modules, allowing independent evolution of technology stacks (Rust vs JavaScript).
• CI/CD and Automation:
– Highlight the integration of build scripts and GitHub workflows for continuous integration and deployment.
Technologies, Frameworks, and Tools
• Programming Languages: Rust (for program logic and some clients), JavaScript/TypeScript (for client and tooling), and CLI tool in Rust.
• Build Tools: Cargo (Rust’s package manager), PNPM (for managing JS dependencies and scripts), and various scripts (MJS files).
• Deployment and Testing: GitHub Actions for CI/CD, local validator scripts for on-chain testing.
• Solana-specific Tools: Shank and/or Anchor for generating IDLs; external program dependencies integrated via addresses.