How gasp-xyz/gasp-dev-kit works
Project Type and Purpose
• Recognize that this is a library/SDK (not a full-stack web app)—its focus is on communication with a blockchain node.
• The README describes it as a “comprehensive toolset” with method groups covering query, fee, RPC, tokens, xyk, and utility operations.
• Its primary intent is to abstract complex blockchain interactions (e.g., liquidity pool management, price calculations, asset transfers) into an easier-to-use API.
High-Level Architectural Components
• SDK Core / Entry Point: Represent the public API exposed to developers via the Mangata instance (e.g., using Mangata.instance() to obtain a connection).
• Query Module: Methods for fetching data from the blockchain (e.g., getAssetInfo, getBlockNumber, getPools).
• RPC Module: Methods that perform calculations and node-related queries (e.g., getChain, getNodeVersion, calculateBuyPrice).
• XYK (Liquidity) Module: Methods to handle liquidity pool actions (e.g., createPool, activateLiquidity).
• Fee Module: Methods to obtain fee structures for various operations.
• Tokens Module: Methods to manage token transfers and balances.
• Utility Module: Utility functions that support parameter validation, error handling, logging, and transaction signing.
• Submitable Extrinsic: For building and batching transactions.
• Type and Interface Definitions: A separate package devoted to type definitions and interfaces (“packages/types” and “packages/type-definitions”) which supports type safety and structure for API responses and function parameters.
Interaction and Data Flow
• Application/Client Code calls the SDK’s entry point.
• The entry point then forwards calls to the appropriate module (query, rpc, tokens, etc.).
• These modules often use underlying utilities (found in the "utils" directory) for tasks like error handling and signing transactions.
• For blockchain operations, the SDK forms connections through given endpoints (e.g., wss://kusama-archive.mangata.online), interacting with external Mangata nodes.
• How client code initiates calls to the SDK.
• The communication from each module to external services (blockchain nodes).
• Internal dependencies (e.g., utility functions supporting multiple modules).
Architectural Patterns and Design Principles
• Modular Design: Organized separation by method groups (e.g., fee, query, rpc, xyk) suggests a modular architecture.
• Abstraction: The SDK abstracts low-level blockchain interactions into higher-level API calls.
• Configuration and Testing: Notice the existence of multiple configuration files (ESLint, Prettier, tsconfig) and tests – indicating adherence to best practices.
• Object-Oriented and Functional Mix: Although written in TypeScript, functionality is grouped into objects (“Mangata instance”, method groups) and helper utility functions.