diff --git a/.gitignore b/.gitignore index 86ca8e9a..c5d25659 100644 --- a/.gitignore +++ b/.gitignore @@ -37,7 +37,6 @@ node_modules /coverage /libpeerconnection.log npm-debug.log -yarn-error.log testem.log /typings .next diff --git a/README.md b/README.md index 84616c07..52895f84 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ please refer to the table below. | [@sei-js/create-sei](packages/create-sei) | CLI Tool used to quickly spin up Sei Projects and dApps in either the cosmos or EVM ecosystem | | [@sei-js/mcp-server](packages/mcp-server) | MCP server for interacting with Sei via LLM's and agents | | [@sei-js/sei-global-wallet](packages/sei-global-wallet) | A global wallet conforming to EIP-6963 allowing for AA across dApps. | +| [@sei-js/registry](packages/registry) | Typed constants for Sei chain info, tokens, networks, IBC, and gas configuration. | | [@sei-js/ledger](packages/ledger) | TypeScript library transacting on Sei using a Ledger device. | ## Development @@ -40,3 +41,13 @@ The correct Yarn version will be automatically used thanks to the `packageManage ### Building To build all packages and docs, run `pnpm install` then `pnpm build:all` + +### Testing + +```bash +# Sequential (all packages via package scripts) +pnpm run test:all + +# Parallel (all packages concurrently) +pnpm run test:parallel +``` diff --git a/biome.json b/biome.json index cd801888..e44fa298 100644 --- a/biome.json +++ b/biome.json @@ -7,7 +7,7 @@ }, "files": { "ignoreUnknown": false, - "ignore": ["*/coverage/*", "*/dist/*", "packages/create-sei/templates/**"] + "ignore": ["*/coverage/*", "*/dist/*", "packages/create-sei/templates/**", "packages/create-sei/extensions/**"] }, "formatter": { "enabled": true, diff --git a/docs/docs.json b/docs/docs.json index 4463fc07..4812c7c0 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -14,7 +14,11 @@ "dark": "#780000" }, "contextual": { - "options": ["copy", "chatgpt", "claude"] + "options": [ + "copy", + "chatgpt", + "claude" + ] }, "navigation": { "global": { @@ -43,11 +47,16 @@ "pages": [ { "group": "Introduction", - "pages": ["introduction", "overview"] + "pages": [ + "introduction", + "overview" + ] }, { "group": "Local Development", - "pages": ["contributing"] + "pages": [ + "contributing" + ] } ] }, @@ -58,15 +67,26 @@ "pages": [ { "group": "About", - "pages": ["mcp-server/introduction", "mcp-server/transports"] + "pages": [ + "mcp-server/introduction", + "mcp-server/transports" + ] }, { "group": "Setup", - "pages": ["mcp-server/quickstart", "mcp-server/environment-variables", "mcp-server/troubleshooting"] + "pages": [ + "mcp-server/quickstart", + "mcp-server/environment-variables", + "mcp-server/troubleshooting" + ] }, { "group": "Capabilities", - "pages": ["mcp-server/tools", "mcp-server/prompts", "mcp-server/context"] + "pages": [ + "mcp-server/tools", + "mcp-server/prompts", + "mcp-server/context" + ] } ] }, @@ -77,7 +97,11 @@ "pages": [ { "group": "Getting Started", - "pages": ["create-sei/welcome", "create-sei/quick-start", "create-sei/templates"] + "pages": [ + "create-sei/welcome", + "create-sei/quick-start", + "create-sei/templates" + ] } ] }, @@ -88,7 +112,10 @@ "pages": [ { "group": "Getting Started", - "pages": ["sei-global-wallet/introduction", "sei-global-wallet/quickstart"] + "pages": [ + "sei-global-wallet/introduction", + "sei-global-wallet/quickstart" + ] }, { "group": "Integrations", @@ -109,7 +136,10 @@ "pages": [ { "group": "Getting Started", - "pages": ["precompiles/introduction", "precompiles/quick-start"] + "pages": [ + "precompiles/introduction", + "precompiles/quick-start" + ] }, { "group": "Precompiles", @@ -129,11 +159,27 @@ } ] }, + { + "dropdown": "@sei-js/registry", + "description": "Chain constants and token lists", + "icon": "database", + "pages": [ + { + "group": "Getting Started", + "pages": [ + "registry/introduction", + "registry/usage" + ] + } + ] + }, { "dropdown": "@sei-js/ledger", "description": "Hardware wallet connection", "icon": "shield", - "pages": ["ledger/introduction"] + "pages": [ + "ledger/introduction" + ] }, { "dropdown": "x402", @@ -142,15 +188,24 @@ "pages": [ { "group": "Introduction", - "pages": ["x402/introduction", "x402/overview", "x402/quickstart"] + "pages": [ + "x402/introduction", + "x402/overview", + "x402/quickstart" + ] }, { "group": "Facilitators", - "pages": ["x402/facilitators/introduction", "x402/facilitators/example"] + "pages": [ + "x402/facilitators/introduction", + "x402/facilitators/example" + ] }, { "group": "Client Integration", - "pages": ["x402/clients/fetch"] + "pages": [ + "x402/clients/fetch" + ] }, { "group": "Packages", diff --git a/docs/registry/introduction.mdx b/docs/registry/introduction.mdx new file mode 100644 index 00000000..d9ac4fdc --- /dev/null +++ b/docs/registry/introduction.mdx @@ -0,0 +1,59 @@ +--- +title: "Introduction" +description: "@sei-js/registry provides typed constants for Sei chain info, tokens, networks, IBC channels, and gas configuration" +icon: "database" +--- + +## Overview + +The `@sei-js/registry` package provides fully typed TypeScript constants sourced from the official [Sei chain registry](https://github.com/sei-protocol/chain-registry) and the community [asset list](https://github.com/Sei-Public-Goods/sei-assetlist). Use it to access chain metadata, network endpoints, token lists, IBC channel info, and gas configuration without hardcoding values. + +## Key Exports + +| Export | Description | +|---|---| +| `CHAIN_IDS` | Mainnet, testnet, and devnet chain ID strings | +| `CHAIN_INFO` | Core chain metadata (bech32 prefix, slip44, fee token, supported wallets) | +| `NETWORKS` | Network configs with RPC, REST, gRPC, EVM, and WebSocket endpoints | +| `TOKEN_LIST` | Community-maintained token list per network | +| `IBC_INFO` | IBC channel configurations per network | +| `GAS_INFO` | Gas denomination and pricing per network | + +## Installation + + + +```bash npm +npm install @sei-js/registry +``` + +```bash yarn +yarn add @sei-js/registry +``` + +```bash pnpm +pnpm add @sei-js/registry +``` + +```bash bun +bun add @sei-js/registry +``` + + + +## Quick Example + +```typescript +import { CHAIN_IDS, NETWORKS, TOKEN_LIST } from "@sei-js/registry"; + +// Get the mainnet chain ID +console.log(CHAIN_IDS.mainnet); // "pacific-1" + +// Access mainnet RPC endpoints +const mainnet = NETWORKS["pacific-1"]; +console.log(mainnet.rpc[0].url); + +// Find the SEI token on mainnet +const sei = TOKEN_LIST["pacific-1"].find((t) => t.symbol === "sei"); +console.log(sei?.name); // "Sei" +``` diff --git a/docs/registry/usage.mdx b/docs/registry/usage.mdx new file mode 100644 index 00000000..3bf1c1e9 --- /dev/null +++ b/docs/registry/usage.mdx @@ -0,0 +1,177 @@ +--- +title: "Usage" +description: "Detailed examples for every @sei-js/registry export" +icon: "code" +--- + +## Chain IDs + +The `CHAIN_IDS` constant maps human-readable network names to their official chain identifiers. The `Network` type represents the valid chain ID strings. + +```typescript +import { CHAIN_IDS, type Network } from "@sei-js/registry"; + +console.log(CHAIN_IDS.mainnet); // "pacific-1" +console.log(CHAIN_IDS.testnet); // "atlantic-2" +console.log(CHAIN_IDS.devnet); // "arctic-1" + +// Use the Network type for type-safe chain references +function getExplorerUrl(network: Network): string { + const explorers: Record = { + "pacific-1": "https://seitrace.com", + "atlantic-2": "https://seitrace.com/?chain=atlantic-2", + "arctic-1": "https://seitrace.com/?chain=arctic-1", + }; + return explorers[network]; +} +``` + +## Chain Info + +`CHAIN_INFO` contains core metadata about the Sei blockchain sourced from the official [chain registry](https://github.com/sei-protocol/chain-registry). + +```typescript +import { CHAIN_INFO } from "@sei-js/registry"; + +console.log(CHAIN_INFO.chain_name); // "Sei" +console.log(CHAIN_INFO.bech32_prefix); // "sei" +console.log(CHAIN_INFO.slip44); // 118 +console.log(CHAIN_INFO.fee_token); // "usei" +console.log(CHAIN_INFO.daemon_name); // "seid" +console.log(CHAIN_INFO.supported_wallets); // ["compass", "keplr", ...] +``` + + +Use `CHAIN_INFO.bech32_prefix` when configuring CosmJS clients instead of hardcoding `"sei"`. + + +## Networks + +`NETWORKS` provides endpoint configurations for each Sei network, including RPC, REST, gRPC, EVM RPC, EVM WebSocket, explorer, and faucet URLs. + +```typescript +import { NETWORKS } from "@sei-js/registry"; + +// Access mainnet configuration +const mainnet = NETWORKS["pacific-1"]; + +// Get the first RPC endpoint +const rpcUrl = mainnet.rpc[0].url; +const restUrl = mainnet.rest[0].url; + +// EVM endpoints (optional, may not exist on all networks) +const evmRpcUrl = mainnet.evm_rpc?.[0]?.url; +const evmWsUrl = mainnet.evm_ws?.[0]?.url; + +// Testnet faucets +const testnet = NETWORKS["atlantic-2"]; +const faucetUrl = testnet.faucets?.[0]?.url; + +// Get all explorers for a network +const explorers = mainnet.explorers ?? []; +for (const explorer of explorers) { + console.log(`${explorer.name}: ${explorer.url}`); +} +``` + +### Configuring a Viem client with registry endpoints + +```typescript +import { createPublicClient, http } from "viem"; +import { sei } from "viem/chains"; +import { NETWORKS } from "@sei-js/registry"; + +const evmRpc = NETWORKS["pacific-1"].evm_rpc?.[0]?.url; + +const client = createPublicClient({ + chain: sei, + transport: http(evmRpc), +}); + +const blockNumber = await client.getBlockNumber(); +console.log("Current block:", blockNumber); +``` + +## Token List + +`TOKEN_LIST` is a community-maintained mapping of tokens per network. Each token includes its name, symbol, denominations, and optional image URLs. + + +The token list is community-driven and subject to change. Always verify and filter tokens before use in production. + + +```typescript +import { TOKEN_LIST } from "@sei-js/registry"; + +// Find a specific token on mainnet +const seiToken = TOKEN_LIST["pacific-1"].find((t) => t.symbol === "sei"); +console.log(seiToken?.name); // "Sei" +console.log(seiToken?.base); // "usei" +console.log(seiToken?.display); // "sei" +console.log(seiToken?.denom_units); // [{ denom: "usei", exponent: 0, aliases: [] }, ...] + +// Get all token symbols on testnet +const testnetSymbols = TOKEN_LIST["atlantic-2"].map((t) => t.symbol); +console.log(testnetSymbols); + +// Access token images +const tokenWithImage = TOKEN_LIST["pacific-1"].find((t) => t.images?.png); +console.log(tokenWithImage?.images.png); +``` + +## IBC Info + +`IBC_INFO` provides IBC channel configurations for cross-chain communication on each Sei network. + +```typescript +import { IBC_INFO } from "@sei-js/registry"; + +// Find the Cosmos Hub IBC channel on mainnet +const cosmosChannel = IBC_INFO["pacific-1"].find( + (ch) => ch.counterparty_chain_name === "cosmoshub-4" +); + +if (cosmosChannel) { + console.log(cosmosChannel.src_channel); // Sei-side channel + console.log(cosmosChannel.dst_channel); // Cosmos Hub-side channel + console.log(cosmosChannel.port_id); // "transfer" +} + +// List all IBC connections for a network +for (const channel of IBC_INFO["pacific-1"]) { + console.log(`${channel.counterparty_chain_name}: ${channel.src_channel} → ${channel.dst_channel}`); +} +``` + +## Gas Info + +`GAS_INFO` contains gas denomination, minimum gas prices, and module-specific gas adjustments per network. + +```typescript +import { GAS_INFO } from "@sei-js/registry"; + +const mainnetGas = GAS_INFO["pacific-1"]; + +console.log(mainnetGas.denom); // "usei" +console.log(mainnetGas.min_gas_price); // minimum gas price + +// Module-specific gas adjustments +const dexGas = mainnetGas.module_adjustments.dex; +console.log(dexGas.order_placement); // gas price for DEX order placement +console.log(dexGas.order_cancellation); // gas price for DEX order cancellation +console.log(dexGas.sudo_gas_price); // superuser gas price +``` + +### Setting gas in a CosmJS transaction + +```typescript +import { GAS_INFO } from "@sei-js/registry"; +import type { StdFee } from "@cosmjs/stargate"; + +const gasInfo = GAS_INFO["pacific-1"]; + +const fee: StdFee = { + amount: [{ denom: gasInfo.denom, amount: "20000" }], + gas: "200000", +}; +``` diff --git a/package.json b/package.json index f839277c..14171e70 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "release": "changeset publish && git push --follow-tags", "release:internal": "pnpm build:all && pnpm changeset && pnpm changeset version --snapshot internal && pnpm changeset publish --no-git-tag --snapshot --tag internal", "test:all": "pnpm -r run test", + "test:parallel": "pnpm -r --parallel run test", "test:coverage": "pnpm -r run test --coverage" }, "dependencies": { diff --git a/packages/registry/README.md b/packages/registry/README.md index 33f11e5c..a12dcaf7 100644 --- a/packages/registry/README.md +++ b/packages/registry/README.md @@ -1,14 +1,31 @@ +
+ # @sei-js/registry -This package contains TypeScript typed exports for the Sei registry repository as well as the community asset-list repository. -## Installation +[![npm version](https://badge.fury.io/js/@sei-js%2Fregistry.svg)](https://badge.fury.io/js/@sei-js%2Fregistry) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?logo=typescript&logoColor=white)](https://www.typescriptlang.org/) +[![Sei Network](https://img.shields.io/badge/Sei-Network-red)](https://sei.io) + +**Typed constants for Sei chain info, tokens, networks, IBC, and gas configuration** + +[Documentation](https://sei-js.docs.sei.io/registry/introduction) • [GitHub](https://github.com/sei-protocol/sei-js) • [NPM](https://www.npmjs.com/package/@sei-js/registry) • [Telegram](https://t.me/+LPW_1djQwRQwMzlk) + +
+ +## 🚀 Quick Start + ```bash -yarn add @sei-js/registry +npm install @sei-js/registry ``` -## Usage ```typescript import { TOKEN_LIST, NETWORKS, IBC_INFO, GAS_INFO } from '@sei-js/registry' const uAtom = TOKEN_LIST.find(asset => asset.denom === 'uatom') ``` + +## 📚 Documentation + +For complete documentation, examples, and guides, visit: +**[sei-js.docs.sei.io/registry](https://sei-js.docs.sei.io/registry/introduction)**