Skip to content

Commit

Permalink
add-chains: metis, base, zksync, mantle, linea, scr, boba, zora
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Jan 19, 2024
1 parent 372762a commit fc9d733
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
92 changes: 92 additions & 0 deletions scripts/addEvmCoin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import * as readline from "readline";
import { coinTypeToEvmChainId } from "../src/utils/evm.js";

const SLIP44_MSB = 0x80000000;
const evmChainIdToCoinType = (chainId: number) => {
if (chainId >= SLIP44_MSB) throw new Error("Invalid chainId");
return (SLIP44_MSB | chainId) >>> 0;
};

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const questionAsync = (question: string) =>
new Promise<string>((resolve) => {
rl.question(question, (answer) => {
resolve(answer);
});
});

let newCoins: [string, [string, string]][] = [];

async function addEvmCoin() {
const coinSymbol_ = await questionAsync("Coin Symbol: ");
const coinName_ = await questionAsync("Coin Name: ");
const chainId = await questionAsync("Chain ID: ").then((ans) =>
parseInt(ans)
);

const coinName = coinName_.trim();
const coinSymbol = coinSymbol_.toLowerCase().trim();

newCoins.push([`${evmChainIdToCoinType(chainId)}`, [coinSymbol, coinName]]);

const runAgain = await questionAsync("Add another coin? (y/n): ").then(
(ans) => ans.toLowerCase() === "y"
);

if (runAgain) return addEvmCoin();
}

await addEvmCoin();

console.log("Adding new coins:", newCoins.map(([, [c]]) => c).join(", "));

const { evmCoinTypeToNameMap, nonEvmCoinTypeToNameMap } = await import(
"../src/consts/coinTypeToNameMap.js"
);

const evmCoinsWithNew = [
...Object.entries(evmCoinTypeToNameMap),
...newCoins,
].sort(([a], [b]) => parseInt(a) - parseInt(b));

const evmCoinTypeToNameMapString = `export const evmCoinTypeToNameMap = Object.freeze({
${evmCoinsWithNew
.map(
([
coinType,
[coinSymbol, coinName],
]) => ` /* Chain ID: ${coinTypeToEvmChainId(parseInt(coinType))} */
"${coinType}": ["${coinSymbol}", "${coinName}"],`
)
.join("\n")}
} as const);`;

const nonEvmCoinTypeToNameMapString = `export const nonEvmCoinTypeToNameMap = Object.freeze({
${Object.entries(nonEvmCoinTypeToNameMap)
.map(
([coinType, [coinSymbol, coinName]]) =>
` "${coinType}": ["${coinSymbol}", "${coinName}"],`
)
.join("\n")}
} as const);`;

const coinTypeToNameMapString = `export const coinTypeToNameMap = Object.freeze({
...nonEvmCoinTypeToNameMap,
...evmCoinTypeToNameMap,
} as const);`;

const toWrite = `${evmCoinTypeToNameMapString}
${nonEvmCoinTypeToNameMapString}
${coinTypeToNameMapString}
`;

await Bun.write("./src/consts/coinTypeToNameMap.ts", toWrite);

console.log("Done!");

rl.close();
18 changes: 18 additions & 0 deletions src/consts/coinTypeToNameMap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const evmCoinTypeToNameMap = Object.freeze({
/* Chain ID: 0 */
"2147483648": ["metis", "1088"],
/* Chain ID: 10 */
"2147483658": ["op", "Optimism"],
/* Chain ID: 25 */
Expand All @@ -19,14 +21,24 @@ export const evmCoinTypeToNameMap = Object.freeze({
"2147483756": ["tt", "ThunderCore"],
/* Chain ID: 137 */
"2147483785": ["matic", "Polygon"],
/* Chain ID: 169 */
"2147483817": ["manta", "Manta Pacific"],
/* Chain ID: 246 */
"2147483894": ["ewt", "Energy Web"],
/* Chain ID: 250 */
"2147483898": ["ftm", "Fantom Opera"],
/* Chain ID: 288 */
"2147483936": ["boba", "Boba"],
/* Chain ID: 324 */
"2147483972": ["zksync", "zkSync"],
/* Chain ID: 361 */
"2147484009": ["theta", "Theta"],
/* Chain ID: 820 */
"2147484468": ["clo", "Callisto"],
/* Chain ID: 5000 */
"2147488648": ["mantle", "Mantle"],
/* Chain ID: 8453 */
"2147492101": ["base", "Base"],
/* Chain ID: 39797 */
"2147523445": ["nrg", "Energi"],
/* Chain ID: 42161 */
Expand All @@ -35,6 +47,12 @@ export const evmCoinTypeToNameMap = Object.freeze({
"2147525868": ["celo", "Celo"],
/* Chain ID: 43114 */
"2147526762": ["avaxc", "Avalanche C-Chain"],
/* Chain ID: 59144 */
"2147542792": ["linea", "Linea"],
/* Chain ID: 534352 */
"2148018000": ["scr", "Scroll"],
/* Chain ID: 7777777 */
"2155261425": ["zora", "Zora"],
} as const);

export const nonEvmCoinTypeToNameMap = Object.freeze({
Expand Down

0 comments on commit fc9d733

Please sign in to comment.