Skip to content

Commit

Permalink
Add @sei-js/registry (#137)
Browse files Browse the repository at this point in the history
* Added all registry submodules, added typescript types, added unit tests, setup nx package for @sei-js/registry

* Updated assetlist and package.json

* @sei-js/registry

- Added a new package for exporting the official sei chain registry as constants as well as the community driven asset list
- Added typedoc comments with examples to each variable, interface, and type
- Added unit tests with 100% test coverage

- Cleaned up tsconfigs across all packages

* Updated gitmodules with new community asset list

* Added submodule for community asset list

* Removed Babel in favor of TSC

* Added typedoc comments

* Removed duplicate js files from failed tsc, fixed testing issue

* Made variable names UPPERCASE

As the variables are now uppercase the typescript types can be the same name and not end with "Type"

* Added changeset

* Updated typdoc comments for new variable names
  • Loading branch information
codebycarson authored Apr 9, 2024
1 parent 42cd65f commit 53cc721
Show file tree
Hide file tree
Showing 38 changed files with 722 additions and 52 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-pears-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sei-js/registry": major
---

Intitial release of @sei-js/registry which contains exports from the official Sei chain registry as well as the community token list
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ testem.log
# System Files
.DS_Store
Thumbs.db

packages/registry/chain-registry
packages/registry/community-assetlist
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "packages/registry/community-assetlist"]
path = packages/registry/community-assetlist
url = https://github.com/Sei-Public-Goods/sei-assetlist.git
[submodule "packages/registry/chain-registry"]
path = packages/registry/chain-registry
url = https://github.com/sei-protocol/chain-registry.git
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ You can also refer to the [typedoc documentation](https://sei-protocol.github.io

SeiJS consists of smaller NPM packages within the @sei-js namespace. For more detailed documentation on each package, please refer to the table below.

| Package | Description |
|-----------------------------------|---------------------------------------------------------------------------------------------------------------------------|
| [@sei-js/cosmjs](packages/cosmjs) | TypeScript library containing helper functions for wallet connection, transaction signing, and RPC querying using cosmjs. |
| [@sei-js/evm](packages/evm) | Typescript library containing helper functions for interacting with the EVM on Sei. |
| [@sei-js/proto](packages/proto) | TypeScript library for Sei protobufs generated using [Telescope](https://github.com/osmosis-labs/telescope) |
| Package | Description |
|------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [@sei-js/cosmjs](packages/cosmjs) | TypeScript library containing helper functions for wallet connection, transaction signing, and RPC querying using cosmjs. |
| [@sei-js/evm](packages/evm) | Typescript library containing helper functions for interacting with the EVM on Sei. |
| [@sei-js/proto](packages/proto) | TypeScript library for Sei protobuf generated using [Telescope](https://github.com/osmosis-labs/telescope) |
| [@sei-js/registry](packages/proto) | TypeScript library exporting constants from the [Sei chain-registry](https://github.com/sei-protocol/chain-registry) and the [community asset list](https://github.com/Sei-Public-Goods/sei-assetlist) |

## Development
To build all packages and docs, run `yarn install` then `yarn build:all`
Expand Down
11 changes: 6 additions & 5 deletions TYPEDOC-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

## Packages

| Package | Description |
|--------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [evm](/sei-js/docs/modules/evm.html) | The `/evm` package provides utilities, functions, wrappers, and configurations for seamless interaction with Sei via the Ethereum Virtual Machine (EVM). If you're building smart contracts or integrating Sei with Ethereum-based tooling, or interacting with EVM contacts like ERC20 tokens this package contains all the configs needed. |
| [cosmjs](/sei-js/docs/modules/cosmjs.html) | The `/cosmjs` package offers similar functionality to the `/evm` package but tailored for interactions with Sei via the Cosmos interfaces. It includes utilities, functions, wrappers, and configurations specifically designed for CosmWasm and Rust development. |
| [proto](/sei-js/docs/modules/proto.html) | The `/proto` package contains Sei client libraries and types generated using protocol buffers. If you're working with Sei's protocol buffer definitions or building clients for Sei services, this package will be invaluable. |
| Package | Description |
|------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [evm](/sei-js/docs/modules/evm.html) | The `/evm` package provides utilities, functions, wrappers, and configurations for seamless interaction with Sei via the Ethereum Virtual Machine (EVM). If you're building smart contracts or integrating Sei with Ethereum-based tooling, or interacting with EVM contacts like ERC20 tokens this package contains all the configs needed. |
| [cosmjs](/sei-js/docs/modules/cosmjs.html) | The `/cosmjs` package offers similar functionality to the `/evm` package but tailored for interactions with Sei via the Cosmos interfaces. It includes utilities, functions, wrappers, and configurations specifically designed for CosmWasm and Rust development. |
| [proto](/sei-js/docs/modules/proto.html) | The `/proto` package contains Sei client libraries and types generated using protocol buffers. If you're working with Sei's protocol buffer definitions or building clients for Sei services, this package will be invaluable. |
| [registry](/sei-js/docs/modules/registry.html) | The `/registry` package contains exports data from the [Sei chain-registry](https://github.com/sei-protocol/chain-registry) and the [community asset list](https://github.com/Sei-Public-Goods/sei-assetlist) as constants in typescript. |

## Resources

Expand Down
7 changes: 7 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ flags:
proto:
paths:
- packages/proto/**
registry:
paths:
- packages/registry/**

coverage:
status:
Expand All @@ -24,3 +27,7 @@ coverage:
target: 80%
flags:
- proto
registry:
target: 80%
flags:
- registry
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
"build:all": "nx run-many --target=build",
"build:since": "nx affected --target=build",
"prebuild": "yarn build:since",
"postinstall": "git submodule update --init --recursive",
"docs": "npx typedoc",
"lint:all": "nx run-many --target=lint",
"lint:since": "nx affected --target=lint",
"prerelease": "yarn build:all",
"release": "changeset publish",
"postrelease": "git push --follow-tags",
"release:internal-evm": "yarn build:all && yarn changeset && yarn changeset version --snapshot internal-evm && yarn changeset publish --no-git-tag --snapshot --tag internal-evm",
"test:all": "nx run-many --target=test",
"test:all": "nx run-many --target=test --skip-nx-cache",
"test:since": "nx affected --target=test",
"test:coverage": "nx test --all --coverage --skip-nx-cache"
},
Expand Down Expand Up @@ -64,4 +65,3 @@
"wagmi": "^2.5.17"
}
}

1 change: 0 additions & 1 deletion packages/cosmjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"exclude": ["node_modules", "dist", "**/*.spec.ts", "**/*.test.ts"],
"compilerOptions": {
"outDir": "./dist/types",
},
Expand Down
1 change: 0 additions & 1 deletion packages/evm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"exclude": ["node_modules", "dist"],
"compilerOptions": {
"outDir": "./dist/types"
},
Expand Down
1 change: 0 additions & 1 deletion packages/proto/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.base.json",
"include": ["./src/**/*"],
"exclude": ["node_modules"],
"typedocOptions": {
"readme": "./README.md",
"name": "proto",
Expand Down
2 changes: 2 additions & 0 deletions packages/registry/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
File renamed without changes.
13 changes: 13 additions & 0 deletions packages/registry/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
src
node_modules
docs
coverage/

.gitkeep
jest.config.ts
tsconfig.json

yarn-error.log

.eslintignore
eslintrc.json
14 changes: 14 additions & 0 deletions packages/registry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# @sei-js/registry
This package contains TypeScript typed exports for the Sei registry repository as well as the community asset-list repository.

## Installation
```bash
yarn add @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')
```
2 changes: 2 additions & 0 deletions packages/registry/RUNBOOK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Init submodules
`git submodule update --init --recursive`
1 change: 1 addition & 0 deletions packages/registry/chain-registry
Submodule chain-registry added at 71938f
1 change: 1 addition & 0 deletions packages/registry/community-assetlist
Submodule community-assetlist added at 831406
3 changes: 3 additions & 0 deletions packages/registry/eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["../../eslint.base.json", "eslint:recommended", "plugin:@typescript-eslint/recommended"]
}
8 changes: 8 additions & 0 deletions packages/registry/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
modulePathIgnorePatterns: ['<rootDir>/dist/']
};
50 changes: 50 additions & 0 deletions packages/registry/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@sei-js/registry",
"version": "0.1.0",
"description": "TypeScript library for Sei chain constants and assets",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"sideEffects": false,
"files": [
"dist"
],
"scripts": {
"prebuild": "rimraf dist",
"build": "yarn build:cjs && yarn build:esm && yarn build:prettier && yarn build:types",
"build:cjs": "tsc --outDir dist/cjs --module commonjs",
"build:esm": "tsc --outDir dist/esm --module esnext",
"build:types": "tsc --project ./tsconfig.declaration.json",
"build:prettier": "prettier --write 'dist/**/*.js'",
"docs": "typedoc --out docs",
"test": "jest",
"lint": "eslint --ext .ts"
},
"homepage": "https://github.com/sei-protocol/sei-js#readme",
"keywords": [
"sei",
"javascript",
"typescript"
],
"repository": "[email protected]:sei-protocol/sei-js.git",
"license": "MIT",
"private": false,
"publishConfig": {
"access": "public"
},
"dependencies": {},
"peerDependencies": {},
"devDependencies": {
"@types/jest": "^29.5.5",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"ts-jest": "^29.1.1"
},
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"types": "./dist/types/index.d.ts"
}
}
}
19 changes: 19 additions & 0 deletions packages/registry/src/chain-info/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { CHAIN_INFO } from '../index';

describe('ChainInfo Tests', () => {
it('has the required properties with correct types', () => {
expect(typeof CHAIN_INFO.chain_name).toBe('string');
expect(['mainnet', 'testnet', 'devnet']).toContain(CHAIN_INFO.network_type);
expect(typeof CHAIN_INFO.chain_id).toBe('string');
expect(typeof CHAIN_INFO.daemon_name).toBe('string');
expect(typeof CHAIN_INFO.bech32_prefix).toBe('string');
expect(Array.isArray(CHAIN_INFO.key_algos)).toBeTruthy();
expect(typeof CHAIN_INFO.slip44).toBe('number');
expect(typeof CHAIN_INFO.fee_token).toBe('string');
expect(Array.isArray(CHAIN_INFO.supported_wallets)).toBeTruthy();
});

it("includes 'secp256k1' in key_algos", () => {
expect(CHAIN_INFO.key_algos).toContain('secp256k1');
});
});
37 changes: 37 additions & 0 deletions packages/registry/src/chain-info/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import ChainInfoJSON from '../../chain-registry/chain_info.json';

/**
* Represents the essential information about an official Sei network.
*/
export interface ChainInfo {
/** The name of the chain. (Sei) */
chain_name: string;
/** The type of network, indicating whether it's a mainnet, testnet, or devnet. */
network_type: 'mainnet' | 'testnet' | 'devnet';
/** The unique identifier for the Sei network. 'pacific-1' | 'atlantic-2' | 'arctic-1' */
chain_id: string;
/** The name of the daemon process that runs the node software for the blockchain. (seid) */
daemon_name: string;
/** The prefix used for Bech32 encoded addresses on the network. (sei) */
bech32_prefix: string;
/** An array of cryptographic algorithms supported by the network for key generation. */
key_algos: string[];
/** The SLIP-44 coin type number assigned to the network for HD wallet purposes. */
slip44: number;
/** The denomination of the fee token used for transaction fees on the network. */
fee_token: string;
/** A list of wallet software that supports this blockchain network. */
supported_wallets: string[];
}

/**
* A constant that holds the chain information, imported from the official Sei [chain-registry](https://github.com/sei-protocol/chain-registry).
*
* @example
* ```tsx
* import { CHAIN_INFO } from '@sei-js/registry';
*
* console.log(CHAIN_INFO.bech32_prefix); // 'sei'
* ```
*/
export const CHAIN_INFO: ChainInfo = ChainInfoJSON as ChainInfo;
35 changes: 35 additions & 0 deletions packages/registry/src/gas/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ModuleAdjustments, GAS_INFO, ChainGasInfo } from '../index';
import { Network } from '../../index';

describe('GasInfo Tests', () => {
// Check if GasInfo contains all expected networks
it('contains all required networks', () => {
const expectedNetworks: Network[] = ['pacific-1', 'atlantic-2', 'arctic-1'];
expectedNetworks.forEach((network) => {
expect(GAS_INFO).toHaveProperty(network);
});
});

// Validate the structure of GasInfo for each network
it('validates structure for each network', () => {
Object.values(GAS_INFO).forEach((info: ChainGasInfo) => {
expect(typeof info.denom).toBe('string');
expect(typeof info.min_gas_price).toBe('number');
expect(info).toHaveProperty('module_adjustments');
expect(info.module_adjustments).toHaveProperty('dex');

const { dex }: { dex: ModuleAdjustments['dex'] } = info.module_adjustments;
expect(typeof dex.sudo_gas_price).toBe('number');
expect(typeof dex.order_placement).toBe('number');
expect(typeof dex.order_cancellation).toBe('number');
});
});

// Example: Check specific values for a network (e.g., 'pacific-1')
it('checks specific values for pacific-1', () => {
const pacific1 = GAS_INFO['pacific-1'];
expect(pacific1.denom).toBe('usei');
expect(pacific1.min_gas_price).toBeGreaterThanOrEqual(0.01);
expect(pacific1.module_adjustments.dex.sudo_gas_price).toBeLessThanOrEqual(0.02);
});
});
53 changes: 53 additions & 0 deletions packages/registry/src/gas/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import GasInfoJSON from '../../chain-registry/gas.json';
import { Network } from '../index';

/**
* Defines the gas price adjustments for specific modules within the Sei blockchain,
* allowing for differentiated gas pricing based on transaction type.
*/
export interface ModuleAdjustments {
/** Adjustments specifically for decentralized exchange (DEX) transactions. */
dex: {
/** The sudo (superuser) gas price for critical operations. */
sudo_gas_price: number;
/** The gas price for placing orders on the DEX. */
order_placement: number;
/** The gas price for canceling orders on the DEX. */
order_cancellation: number;
};
}

/**
* Represents the gas information for a specific Sei network,
* including the default minimum gas price and module-specific adjustments.
*/
export interface ChainGasInfo {
/** The denomination of the gas fee. */
denom: string;
/** The minimum gas price required for transactions on the network. */
min_gas_price: number;
/** Gas price adjustments for specific modules. */
module_adjustments: ModuleAdjustments;
}

/**
* A mapping of network identifiers (chain id's) to their respective gas information.
*/
type GasInfo = {
/** Each network identifier is associated with its gas information. */
[network in Network]: ChainGasInfo;
};

/**
* A constant holding the gas information for each official Sei network, imported from the official Sei [chain-registry](https://github.com/sei-protocol/chain-registry).
* This includes details such as the gas denomination, minimum gas price, and module-specific adjustments.
*
* @example
* ```tsx
* import { GAS_INFO } from '@sei-js/registry';
*
* const pacific1Info = GAS_INFO['pacific-1'];
* console.log(pacific1Info.denom); // 'usei'
* ```
*/
export const GAS_INFO: GasInfo = GasInfoJSON as GasInfo;
Loading

0 comments on commit 53cc721

Please sign in to comment.