Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 159 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ To build everything you need in one shot:
bun build:all
```

If this fails you may need to check your output and potentially run `"rustup target add wasm32-wasip1`.
If this fails you may need to check your output and potentially run `"rustup target add wasm32-wasip1`.

To build just the Chainlink SDK Javy plugin:

Expand Down Expand Up @@ -250,3 +250,161 @@ This project uses [ts-proto](https://github.com/stephenh/ts-proto) for generatin
- **package.json** - buf version managed as dev dependency

Generated files are placed in `src/generated/`.

# Generated Chain Selectors

This directory contains auto-generated TypeScript files for Chainlink Chain Selectors.

## Overview

The chain selectors are automatically generated from the official [Chainlink chain-selectors repository](https://github.com/smartcontractkit/chain-selectors) YAML files. The repository is installed as a dev dependency, ensuring consistent builds without network dependencies.

## Structure

### Individual Network Files

Each network has its own TypeScript file organized by blockchain family:

```
src/generated/chain-selectors/
├── evm/
│ ├── ethereum-mainnet.ts
│ ├── ethereum-mainnet-optimism-1.ts
│ ├── polygon-mainnet.ts
│ └── ... (231 EVM networks)
├── solana/
│ ├── solana-mainnet.ts
│ ├── solana-testnet.ts
│ └── solana-devnet.ts
├── aptos/
│ ├── aptos-mainnet.ts
│ ├── aptos-testnet.ts
│ └── aptos-localnet.ts
├── sui/
├── ton/
└── tron/
```

Each file exports a single network configuration:

```typescript
// src/generated/chain-selectors/evm/ethereum-mainnet.ts
export default {
chainId: "1",
chainSelector: {
name: "ethereum-mainnet",
selector: "5009297550715158000",
},
chainFamily: "evm",
};
```

### Networks Array

All networks are also available as a single array:

```typescript
// src/generated/networks.ts
export const ALL_NETWORKS: NetworkInfo[] = [
// ... all 247 networks
];
```

## Usage

### Direct Import of Specific Networks

```typescript
import ethereumMainnet from "./generated/chain-selectors/evm/ethereum-mainnet";
import solanaMainnet from "./generated/chain-selectors/solana/solana-mainnet";

console.log(ethereumMainnet.chainSelector.name); // "ethereum-mainnet"
console.log(solanaMainnet.chainSelector.selector); // "124615329519749600"
```

### Using Utility Functions

```typescript
import {
getAllNetworks,
getNetworkBySelector,
getNetworksByFamily,
getNetworkByFamilyAndChainId,
getNetworkByChainSelectorName,
} from "./sdk/utils/chain-selectors";

// Get network by selector
const network = getNetworkBySelector("5009297550715158000");

// Get network by name
const ethereum = getNetworkByChainSelectorName("ethereum-mainnet");

// Get network by family and chain ID
const evmNetwork = getNetworkByFamilyAndChainId("evm", "1");

// Get all networks for a family
const evmNetworks = getNetworksByFamily("evm");

// Get all networks
const allNetworks = getAllNetworks();
```

## Supported Blockchain Families

- **EVM**: 231 networks - Ethereum Virtual Machine compatible chains
- **Solana**: 3 networks - Solana networks
- **Aptos**: 3 networks - Aptos networks
- **Sui**: 3 networks - Sui networks
- **TON**: 3 networks - TON networks
- **Tron**: 4 networks - Tron networks

## Regenerating

To update with the latest chain selectors:

```bash
bun generate:chain-selectors
```

This will:

1. Read the local YAML files from the chain-selectors dev dependency
2. Generate individual network files organized by blockchain family
3. Create the main networks array file
4. Generate utility functions
5. Format the output with Biome

To update to the latest chain selectors, update the dependency:

```bash
bun update chain-selectors
bun generate:chain-selectors
```

## Key Features

- **Individual Files**: Each network has its own importable file
- **Family Organization**: Networks organized by blockchain family directories
- **Type Safety**: All data structures are fully typed with TypeScript
- **Tree Shaking**: Import only the networks you need
- **Offline Builds**: No internet required during generation
- **Consistent Builds**: Locked to specific dependency version

## Files Generated

- `chain-selectors/[family]/[network-name].ts` - Individual network files
- `networks.ts` - Array of all networks
- Utility functions in `src/sdk/utils/chain-selectors/`

## Source Data

The generator reads data from these YAML files in the local chain-selectors dependency:

- `selectors.yml` - EVM chains
- `selectors_solana.yml` - Solana networks
- `selectors_aptos.yml` - Aptos networks
- `selectors_sui.yml` - Sui networks
- `selectors_ton.yml` - TON networks
- `selectors_tron.yml` - Tron networks

All files are sourced from the official [Chainlink chain-selectors repository](https://github.com/smartcontractkit/chain-selectors).
6 changes: 6 additions & 0 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
"@biomejs/biome": "2.1.3",
"@bufbuild/buf": "1.56.0",
"@types/bun": "1.2.21",
"chain-selectors": "https://github.com/smartcontractkit/chain-selectors.git#8b963095ae797a3024c8e55822cced7bf618176f",
"fast-glob": "3.3.3",
"ts-proto": "2.7.5",
"typescript": "5.9.2",
"yaml": "2.8.1",
},
},
},
Expand Down Expand Up @@ -100,6 +102,8 @@

"case-anything": ["case-anything@2.1.13", "", {}, "sha512-zlOQ80VrQ2Ue+ymH5OuM/DlDq64mEm+B9UTdHULv5osUMD6HalNTblf2b1u/m6QecjsnOkBpqVZ+XPwIVsy7Ng=="],

"chain-selectors": ["chain-selectors@github:smartcontractkit/chain-selectors#8b96309", {}, "smartcontractkit-chain-selectors-8b96309"],

"csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],

"debug": ["debug@4.4.1", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ=="],
Expand Down Expand Up @@ -162,6 +166,8 @@

"ws": ["ws@8.18.3", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg=="],

"yaml": ["yaml@2.8.1", "", { "bin": { "yaml": "bin.mjs" } }, "sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw=="],

"zod": ["zod@3.25.76", "", {}, "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ=="],

"@bufbuild/protoplugin/typescript": ["typescript@5.4.5", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ=="],
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"javy:linux": "./bin/javy-arm-linux-v5.0.4",
"start": "bun --watch src/index.ts",
"typecheck": "tsc",
"build:generate:sdk": "bun proto:generate && bun scripts/generate-sdks.ts && BIOME_PATHS=\"src/generated src/generated-sdk\" bun biome:format",
"build:generate:sdk": "bun build:generate:chain-selectors && bun proto:generate && bun scripts/generate-sdks.ts && BIOME_PATHS=\"src/generated src/generated-sdk\" bun biome:format",
"build:generate:chain-selectors": "bun scripts/generate-chain-selectors.ts && BIOME_PATHS=\"src/generated\" bun biome:format",
"proto:generate": "bunx @bufbuild/buf generate",
"proto:lint": "bunx @bufbuild/buf lint",
"proto:format": "bunx @bufbuild/buf format --write",
Expand All @@ -38,8 +39,10 @@
"@biomejs/biome": "2.1.3",
"@bufbuild/buf": "1.56.0",
"@types/bun": "1.2.21",
"chain-selectors": "https://github.com/smartcontractkit/chain-selectors.git#8b963095ae797a3024c8e55822cced7bf618176f",
"fast-glob": "3.3.3",
"ts-proto": "2.7.5",
"typescript": "5.9.2"
"typescript": "5.9.2",
"yaml": "2.8.1"
}
}
Loading
Loading