0.1.7 • Published 8 months ago

@hinkal/data v0.1.7

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

@hinkal/data

The @hinkal/data package provides a collection of constants, types, token registries, and instance data related to the Hinkal Protocol. This package is designed to help developers integrate with Hinkal's smart contracts and utilities seamlessly.

Table of Contents

Installation

To install the package, use npm or yarn:

npm install @hinkal/data

or

yarn add @hinkal/data

Overview

Constants

The package exports a variety of constants that are essential for interacting with the Hinkal Protocol. These constants are categorized into several modules:

  • assets: Asset-related constants
  • chains: Blockchain network identifiers and configurations
  • server: Server and API configurations
  • protocol: Protocol-specific constants
  • coingecko: Coingecko API integration constants
  • backend: Backend service configurations
  • reorg-depths: Reorganization depth settings for blockchains
  • defaults: Default values used across the protocol
  • error-codes: Standardized error codes
  • config: General configuration settings
  • time: Time-related constants

Types

Type definitions are provided to ensure type safety and ease of development when interacting with the protocol's data structures.

The following modules provide type definitions:

  • circom-data: Types related to zero-knowledge proof circuits data
  • coingecko: Types for Coingecko API data
  • commitments: Commitment-related types
  • crypto: Cryptographic types
  • external-action: Types for external actions
  • hinkal: Core Hinkal types
  • network: Network and blockchain types
  • snark: SNARK proof types
  • tokens: Token-related types
  • transactions: Transaction types

Token Registries

The package includes token registries to manage and interact with ERC20 tokens and custom tokens within the Hinkal Protocol:

  • ERC20Registry: Standard ERC20 token registry
  • CustomTokenRegistry: Registry for custom tokens
  • coingeckoRegistry: Integration with Coingecko for token price data

Example

import { ERC20Registry } from '@hinkal/data';

const tokenRegistry = new ERC20Registry();
const token = tokenRegistry.getTokenByAddress('0x...');

console.log(token);

Chains Module (@chains.ts)

The chains.ts module is a central part of the Hinkal Protocol's data package, providing comprehensive configurations and utilities for interacting with various blockchain networks. This module defines supported chains, their respective providers, protocol instances, and network registries, enabling seamless integration and interaction across different blockchain environments.

Key Components

  1. Chain Enumeration (Chain)

    The Chain enum lists all supported blockchain networks with their unique identifiers. This enumeration is essential for referencing specific chains throughout the application.

    export enum Chain {
      polygon = 137,
      arbMainnet = 42161,
      ethMainnet = 1,
      // ... other chains
    }
  2. Fallback Providers (fallbackProviders)

    This object maps each Chain to its corresponding ethers provider. These providers serve as default RPC endpoints for interacting with the blockchain networks.

    export const fallbackProviders = {
      [Chain.ethMainnet]: new ethers.providers.JsonRpcProvider('https://rpc.ankr.com/eth'),
      [Chain.polygon]: new ethers.providers.JsonRpcProvider('https://polygon-rpc.com'),
      // ... other providers
    };
  3. Protocols (Protocols)

    The Protocols object contains instances of various protocol contracts connected to their respective providers. This setup facilitates interactions with smart contracts across different chains.

    export const Protocols = {
      [Chain.ethMainnet]: {
        crossChainAccessToken: CrossChainAccessToken__factory.connect(
          ethMainnetData.crossChainAccessTokenAddress,
          fallbackProviders[Chain.ethMainnet],
        ),
        // ... other protocol instances
      },
      // ... other chains
    };
  4. Network Registry (networkRegistry)

    The networkRegistry provides detailed configurations for each supported network, including protocol instances, Uniswap integrations, and access token fees.

    export const networkRegistry: { [key in Chain]?: EthereumNetwork } = {
      [Chain.ethMainnet]: {
        name: 'Ethereum',
        provider: fallbackProviders[Chain.ethMainnet],
        protocol: Protocols[Chain.ethMainnet],
        // ... other configurations
      },
      // ... other networks
    };
  5. Utility Functions

    • isAccessTokenAvailable: Checks if the access token is available for a given chain.
    • isOptimismLike: Determines if a chain is Optimism-like.
    export const isAccessTokenAvailable = (chain: Chain) =>
      [
        Chain.ethMainnet,
        Chain.arbMainnet,
        // ... other chains
      ].includes(chain);
    
    export const isOptimismLike = (chain: Chain) => [Chain.optimism, Chain.base, Chain.blast].includes(chain);

How to Use chains.ts

To leverage the chains.ts module in your project, follow these steps:

  1. Import Necessary Components

    Begin by importing the required enums, providers, and protocols from the module.

    import { Chain, fallbackProviders, Protocols, isAccessTokenAvailable } from '@hinkal/data';
  2. Access a Specific Provider

    Retrieve the provider for a specific chain using the Chain enum.

    const ethereumProvider = fallbackProviders[Chain.ethMainnet];
  3. Interact with Protocol Instances

    Use the Protocols object to interact with protocol-specific contracts.

    const ethProtocol = Protocols[Chain.ethMainnet];
    const accessToken = ethProtocol.crossChainAccessToken;
    
    // Example: Fetching the Access Token Balance
    const balance = await accessToken.balanceOf('0xYourAddress');
    console.log(`Access Token Balance: ${balance}`);
  4. Check Availability of Features

    Utilize utility functions to conditionally execute code based on chain capabilities.

    if (isAccessTokenAvailable(Chain.polygon)) {
      // Execute logic related to access tokens on Polygon
    }
  5. Example Usage

    Here's a complete example demonstrating how to fetch and log the Uniswap Quoter address for Ethereum Mainnet:

    import { networkRegistry, Chain } from '@hinkal/data';
    
    const ethereumNetwork = networkRegistry[Chain.ethMainnet];
    
    if (ethereumNetwork) {
      console.log(`Uniswap Quoter Address on Ethereum: ${ethereumNetwork.uniswapQuoter.address}`);
    } else {
      console.error('Ethereum network configuration not found.');
    }

Additional Information

  • Network Types: The module categorizes chains into different network types such as Mainnet, Testnet, and Local, facilitating environment-specific configurations.

    export const chainIdsByType = {
      [EthereumNetworkType.Mainnet]: [Chain.polygon, Chain.ethMainnet /* ... */],
      [EthereumNetworkType.Testnet]: [Chain.bnbTestnet, Chain.polygonMumbai],
      [EthereumNetworkType.Local]: [Chain.localhost, Chain.axelar1, Chain.axelar2],
    };
  • Extensibility: Easily add support for new chains by updating the Chain enum, adding a new provider in fallbackProviders, configuring protocol instances in Protocols, and updating the networkRegistry.

0.1.7

8 months ago

0.1.4

8 months ago

0.1.6

8 months ago

0.1.5

8 months ago

0.1.3

9 months ago