Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
generate web3icons
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Oct 14, 2024
1 parent 2c55802 commit d9e2b87
Show file tree
Hide file tree
Showing 23 changed files with 167 additions and 36 deletions.
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand All @@ -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"
}
]
Expand Down Expand Up @@ -93,3 +94,12 @@ Provide token SVG to <https://tokenicons.io> and add matching Graph ID to `_data
- [Pinax Chains](https://github.com/pinax-network/chains)
- [Ethereum ChainID](https://github.com/ethereum-lists/chains) (<https://chainid.network/>)
- [DefiLlama ChainList](https://github.com/DefiLlama/chainlist/tree/main) (<https://chainlist.org/>)

## 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
7 changes: 7 additions & 0 deletions __tests__/caip2.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
2 changes: 1 addition & 1 deletion __tests__/typespec.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
Expand Down
7 changes: 7 additions & 0 deletions __tests__/web3icons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { expect, test, it } from "bun:test";

test("web3icons", async () => {
it("web3icons does not exists", async () => {
expect(true).toBeTrue();
});
});
4 changes: 0 additions & 4 deletions _data/chain_id.json

This file was deleted.

6 changes: 5 additions & 1 deletion _data/chains/arbitrum-one.json
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions _data/chains/bitcoin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "bitcoin",
"name": "Bitcoin",
"namespace": "bip122",
"block": "bitcoin",
"genesis_hash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
"chain_id": "000000000019d6689c085ae165831e93"
}
6 changes: 5 additions & 1 deletion _data/chains/mainnet.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"id": "mainnet",
"name": "Ethereum",
"block": "ethereum"
"namespace": "eip155",
"block": "ethereum",
"genesis_hash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
"chain_id": 1,
"network_id": 1
}
8 changes: 8 additions & 0 deletions _data/chains/solana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "solana",
"name": "Solana",
"namespace": "solana",
"block": "solana",
"genesis_hash": "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d",
"chain_id": "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
}
4 changes: 0 additions & 4 deletions _data/cmc_id.json

This file was deleted.

4 changes: 0 additions & 4 deletions _data/defillama_id.json

This file was deleted.

4 changes: 0 additions & 4 deletions _data/gecko_id.json

This file was deleted.

6 changes: 6 additions & 0 deletions _data/icons/branded/arbitrum-one.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions _data/icons/branded/bitcoin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions _data/icons/branded/mainnet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions _data/icons/branded/solana.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions _data/icons/mono/arbitrum-one.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions _data/icons/mono/bitcoin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions _data/icons/mono/mainnet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions _data/icons/mono/solana.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions _data/network_id.json

This file was deleted.

5 changes: 0 additions & 5 deletions _data/web3icons_id.json

This file was deleted.

52 changes: 52 additions & 0 deletions scripts/generate/icons.ts
Original file line number Diff line number Diff line change
@@ -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<string> = new Set();
const chain_ids: Map<number, string> = new Map();
const names: Map<string, string> = 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);
}
}

0 comments on commit d9e2b87

Please sign in to comment.