diff --git a/README.md b/README.md index 3adce49..8b0ce82 100644 --- a/README.md +++ b/README.md @@ -31,12 +31,13 @@ Add the chain definition to the `./_data/chains/` directory. ```json { - "id": "ethereum", - "name": "Ethereum Mainnet", - "icon": "ethereum", - "block": "ethereum", - "chainId": 1, - "networkId": 1 + "id": "mainnet", + "name": "Ethereum", + "namespace": "eip155", + "block": "ethereum", + "genesis_hash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", + "chain_id": 1, + "network_id": 1 } ``` @@ -51,13 +52,13 @@ Add the provider definition to the `./_data/providers/` directory. "rpc": [], "firehose": [ { - "id": "ethereum", + "id": "mainnet", "url": "https://mainnet.eth.streamingfast.io:443" } ], "substreams": [ { - "id": "ethereum", + "id": "mainnet", "url": "https://mainnet.eth.streamingfast.io:443" } ] @@ -93,3 +94,12 @@ Provide token SVG to and add matching Graph ID to `_data - [Pinax Chains](https://github.com/pinax-network/chains) - [Ethereum ChainID](https://github.com/ethereum-lists/chains) () - [DefiLlama ChainList](https://github.com/DefiLlama/chainlist/tree/main) () + +## CAIP-2 + +- https://namespaces.chainagnostic.org/solana/caip2 +- https://namespaces.chainagnostic.org/bip122/caip2 +- https://namespaces.chainagnostic.org/antelope/caip2 +- https://namespaces.chainagnostic.org/eip155/caip2 +- https://namespaces.chainagnostic.org/cosmos/caip2 +- https://namespaces.chainagnostic.org/starknet/README diff --git a/__tests__/caip2.spec.ts b/__tests__/caip2.spec.ts new file mode 100644 index 0000000..4038cdf --- /dev/null +++ b/__tests__/caip2.spec.ts @@ -0,0 +1,7 @@ +import { expect, test, it } from "bun:test"; + +test("caip2", async () => { + it("Dummy max length(8 + 1 + 32 = 41 chars / bytes)", async () => { + expect(true).toBeTrue(); + }); +}); diff --git a/__tests__/typespec.spec.ts b/__tests__/typespec.spec.ts index 3dc2557..024fd85 100644 --- a/__tests__/typespec.spec.ts +++ b/__tests__/typespec.spec.ts @@ -1,6 +1,6 @@ import { expect, test, it } from "bun:test"; -test("typespec chains", async () => { +test("typespec", async () => { it("typespec does not match", async () => { expect(true).toBeTrue(); }); diff --git a/__tests__/web3icons.ts b/__tests__/web3icons.ts new file mode 100644 index 0000000..a30b19a --- /dev/null +++ b/__tests__/web3icons.ts @@ -0,0 +1,7 @@ +import { expect, test, it } from "bun:test"; + +test("web3icons", async () => { + it("web3icons does not exists", async () => { + expect(true).toBeTrue(); + }); +}); diff --git a/_data/chain_id.json b/_data/chain_id.json deleted file mode 100644 index e05ebf0..0000000 --- a/_data/chain_id.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mainnet": 1, - "arbitrum-one": 42161 -} \ No newline at end of file diff --git a/_data/chains/arbitrum-one.json b/_data/chains/arbitrum-one.json index dba1c2a..f1ce226 100644 --- a/_data/chains/arbitrum-one.json +++ b/_data/chains/arbitrum-one.json @@ -1,5 +1,9 @@ { "id": "arbitrum-one", "name": "Arbitrum One", - "block": "ethereum" + "namespace": "eip155", + "block": "ethereum", + "genesis_hash": "0x7ee576b35482195fc49205cec9af72ce14f003b9ae69f6ba0faef4514be8b442", + "chain_id": 42161, + "network_id": 42161 } \ No newline at end of file diff --git a/_data/chains/bitcoin.json b/_data/chains/bitcoin.json new file mode 100644 index 0000000..0a4fedd --- /dev/null +++ b/_data/chains/bitcoin.json @@ -0,0 +1,8 @@ +{ + "id": "bitcoin", + "name": "Bitcoin", + "namespace": "bip122", + "block": "bitcoin", + "genesis_hash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f", + "chain_id": "000000000019d6689c085ae165831e93" +} \ No newline at end of file diff --git a/_data/chains/mainnet.json b/_data/chains/mainnet.json index 0c828c9..ee87cdb 100644 --- a/_data/chains/mainnet.json +++ b/_data/chains/mainnet.json @@ -1,5 +1,9 @@ { "id": "mainnet", "name": "Ethereum", - "block": "ethereum" + "namespace": "eip155", + "block": "ethereum", + "genesis_hash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", + "chain_id": 1, + "network_id": 1 } \ No newline at end of file diff --git a/_data/chains/solana.json b/_data/chains/solana.json new file mode 100644 index 0000000..8300e8d --- /dev/null +++ b/_data/chains/solana.json @@ -0,0 +1,8 @@ +{ + "id": "solana", + "name": "Solana", + "namespace": "solana", + "block": "solana", + "genesis_hash": "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d", + "chain_id": "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp" +} \ No newline at end of file diff --git a/_data/cmc_id.json b/_data/cmc_id.json deleted file mode 100644 index eece88b..0000000 --- a/_data/cmc_id.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mainnet": "ethereum", - "arbitrum-one": "arbitrum" -} \ No newline at end of file diff --git a/_data/defillama_id.json b/_data/defillama_id.json deleted file mode 100644 index cae73ed..0000000 --- a/_data/defillama_id.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mainnet": "Ethereum", - "arbitrum-one": "Arbitrum" -} \ No newline at end of file diff --git a/_data/gecko_id.json b/_data/gecko_id.json deleted file mode 100644 index eece88b..0000000 --- a/_data/gecko_id.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mainnet": "ethereum", - "arbitrum-one": "arbitrum" -} \ No newline at end of file diff --git a/_data/icons/branded/arbitrum-one.svg b/_data/icons/branded/arbitrum-one.svg new file mode 100644 index 0000000..9fb0d6c --- /dev/null +++ b/_data/icons/branded/arbitrum-one.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/_data/icons/branded/bitcoin.svg b/_data/icons/branded/bitcoin.svg new file mode 100644 index 0000000..50e26a8 --- /dev/null +++ b/_data/icons/branded/bitcoin.svg @@ -0,0 +1,3 @@ + + + diff --git a/_data/icons/branded/mainnet.svg b/_data/icons/branded/mainnet.svg new file mode 100644 index 0000000..7ee800d --- /dev/null +++ b/_data/icons/branded/mainnet.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/_data/icons/branded/solana.svg b/_data/icons/branded/solana.svg new file mode 100644 index 0000000..05dc731 --- /dev/null +++ b/_data/icons/branded/solana.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/_data/icons/mono/arbitrum-one.svg b/_data/icons/mono/arbitrum-one.svg new file mode 100644 index 0000000..9b93212 --- /dev/null +++ b/_data/icons/mono/arbitrum-one.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/_data/icons/mono/bitcoin.svg b/_data/icons/mono/bitcoin.svg new file mode 100644 index 0000000..b50879f --- /dev/null +++ b/_data/icons/mono/bitcoin.svg @@ -0,0 +1,3 @@ + + + diff --git a/_data/icons/mono/mainnet.svg b/_data/icons/mono/mainnet.svg new file mode 100644 index 0000000..ee4074d --- /dev/null +++ b/_data/icons/mono/mainnet.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/_data/icons/mono/solana.svg b/_data/icons/mono/solana.svg new file mode 100644 index 0000000..9782a26 --- /dev/null +++ b/_data/icons/mono/solana.svg @@ -0,0 +1,3 @@ + + + diff --git a/_data/network_id.json b/_data/network_id.json deleted file mode 100644 index e05ebf0..0000000 --- a/_data/network_id.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mainnet": 1, - "arbitrum-one": 42161 -} \ No newline at end of file diff --git a/_data/web3icons_id.json b/_data/web3icons_id.json deleted file mode 100644 index 10fbb28..0000000 --- a/_data/web3icons_id.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "mainnet": "ethereum", - "arbitrum-one": "arbitrum-one", - "arbitrum-nova": "arbitrum-nova" -} \ No newline at end of file diff --git a/scripts/generate/icons.ts b/scripts/generate/icons.ts new file mode 100644 index 0000000..95e6f29 --- /dev/null +++ b/scripts/generate/icons.ts @@ -0,0 +1,52 @@ +import fs from "fs"; +import path from "path"; +import web3icons from '../download/web3icons.json'; + +const base = path.join(__dirname, "..", "..", "_data"); + +// read & parse chains +const ids: Set = new Set(); +const chain_ids: Map = new Map(); +const names: Map = new Map(); +for (const filename of fs.readdirSync(path.join(base, "chains"))) { + const id = path.parse(filename).name; + const json = JSON.parse(fs.readFileSync(path.join(base, "chains", filename), "utf-8")); + chain_ids.set(json.chain_id, id); + names.set(json.name, id); + ids.add(id); +} + +async function download(web3icon: typeof web3icons[0], id: string) { + for (const variant of web3icon.variants) { + const url = `https://raw.githubusercontent.com/0xa3k5/web3icons/refs/heads/main/packages/core/src/svgs/networks/${variant}/${web3icon.id}.svg`; + const filename = path.join(base, "icons", variant, `${id}.svg`); + if (fs.existsSync(filename)) continue; // skip if already exists + const response = await fetch(url); + if (response.ok) { + const svg = await response.text(); + fs.writeFileSync(filename, svg); + } + } +} + +function getId(web3icon: typeof web3icons[0]) { + if (ids.has(web3icon.id)) { + return web3icon.id; + } + // by chain_id + if (web3icon.chainId) { + const id = chain_ids.get(web3icon.chainId); + return id; + } + // by name + const id = names.get(web3icon.name); + return id; +} + +// download web3icons if match by chain_id or name +for (const web3icon of web3icons) { + const id = getId(web3icon); + if (id) { + await download(web3icon, id); + } +}