Skip to content

Commit

Permalink
supported-cryptocurrencies generation script
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Feb 4, 2024
1 parent 8151b1a commit 401c38a
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 167 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ const decodedAddress = decodeBtcAddress("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa");
const encodedAddress = encodeBtcAddress(decodedAddress);
```

### EVM Chains

There are a variety of EVM chains supported, however none of them (except for ETH) are exported from `coins` or `coders`. If you want to individually import for an EVM chain, you can just use the `eth` import as a replacement.

## Contribution Guide

To add a coin to this library, or if you're interested in contributing in any other way, read the [contribution guide](https://github.com/ensdomains/address-encoder/blob/master/docs/contribution-guide.md) before submitting a PR.
Binary file modified bun.lockb
Binary file not shown.
293 changes: 166 additions & 127 deletions docs/supported-cryptocurrencies.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"fs-extra": "^11.1.1",
"mitata": "^0.1.6",
"ts-arithmetic": "^0.1.1",
"ts-markdown": "^1.0.0",
"typescript": "^5.1.6"
},
"dependencies": {
Expand Down
95 changes: 95 additions & 0 deletions scripts/formatSupportedCoins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { TableEntry, tsMarkdown } from "ts-markdown";
import {
evmCoinNameToTypeMap,
evmCoinTypeToNameMap,
nonEvmCoinNameToTypeMap,
nonEvmCoinTypeToNameMap,
} from "../src/index.js";
import { coinTypeToEvmChainId } from "../src/utils/evm.js";

const supportedCryptocurrenciesMd = Bun.file(
"./docs/supported-cryptocurrencies.md"
);
const supportedText = await supportedCryptocurrenciesMd.text();
const supLine = supportedText.split("\n");

const evmCoins = Object.entries(evmCoinTypeToNameMap);

const evmTableData: TableEntry = {
table: {
columns: ["Chain ID", "Name", "Full Name", "Coin Type"],
rows: evmCoins.map(([coinType, [coinName, coinFullName]]) => {
return [
coinTypeToEvmChainId(parseInt(coinType)),
coinName,
coinFullName,
coinType,
];
}),
},
};

const legacyCoins = Object.entries(nonEvmCoinTypeToNameMap).filter(
([, [coinName]]) => coinName.endsWith("Legacy")
);

const legacyTableData: TableEntry = {
table: {
columns: [
"Coin Type",
"Name",
"Full Name",
"Replacement Name",
"Replacement Coin Type",
],
rows: legacyCoins.map(([coinType, [coinName, coinFullName]]) => {
const replacementName = coinName.slice(0, -6);
const replacement =
nonEvmCoinNameToTypeMap[replacementName] ??
evmCoinNameToTypeMap[replacementName];
return [
coinType,
coinName,
coinFullName.replace(/^\[LEGACY\] /, ""),
replacementName,
replacement,
];
}),
},
};

const mainCoins = Object.entries(nonEvmCoinTypeToNameMap).filter(
([, [coinName]]) => !coinName.endsWith("Legacy")
);
const mainCoinsIndex = supLine.findIndex((l) => l.startsWith("### Coins"));
const mainCoinsLines = supLine.slice(mainCoinsIndex);

const mainTableData: TableEntry = {
table: {
columns: ["Coin Type", "Name", "Full Name", "Encoding Type"],
rows: mainCoins.map(([coinType, [coinName, coinFullName]]) => {
const existingLine = mainCoinsLines.find((l) =>
l.startsWith(`| ${coinType} `)
);
const encodingType = existingLine
? existingLine.split("|")[4].trim()
: "[UNKNOWN ENCODING TYPE, PLEASE ADD BEFORE MERGING]";
return [coinType, coinName, coinFullName, encodingType];
}),
},
};

const md = tsMarkdown([
{ h2: "Supported Cryptocurrencies" },
{ h3: "EVM Chains" },
{ p: "The following EVM chains are supported:" },
evmTableData,
{ h3: "Legacy Coins" },
{ p: "The following legacy coins are supported:" },
legacyTableData,
{ h3: "Coins" },
{ p: "The following coins are supported:" },
mainTableData,
]);

await Bun.write(supportedCryptocurrenciesMd, md);
38 changes: 0 additions & 38 deletions src/coin/btc.bench.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/consts/coinTypeToNameMap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export const evmCoinTypeToNameMap = Object.freeze({
/* Chain ID: 0 */
"2147483648": ["metis", "1088"],
/* Chain ID: 10 */
"2147483658": ["op", "Optimism"],
/* Chain ID: 25 */
Expand Down Expand Up @@ -35,6 +33,8 @@ export const evmCoinTypeToNameMap = Object.freeze({
"2147484009": ["theta", "Theta"],
/* Chain ID: 820 */
"2147484468": ["clo", "Callisto"],
/* Chain ID: 1088 */
"2147484736": ["metis", "Metis"],
/* Chain ID: 5000 */
"2147488648": ["mantle", "Mantle"],
/* Chain ID: 8453 */
Expand Down

0 comments on commit 401c38a

Please sign in to comment.