npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hinkal/data

v0.1.8

Published

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.

Downloads

613

Readme

@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.