From fc9d73379627e06d6063e3d8cbdbeac5c72dff83 Mon Sep 17 00:00:00 2001 From: tate Date: Fri, 19 Jan 2024 11:50:27 +1100 Subject: [PATCH] add-chains: metis, base, zksync, mantle, linea, scr, boba, zora --- scripts/addEvmCoin.ts | 92 +++++++++++++++++++++++++++++++++ src/consts/coinTypeToNameMap.ts | 18 +++++++ 2 files changed, 110 insertions(+) create mode 100644 scripts/addEvmCoin.ts diff --git a/scripts/addEvmCoin.ts b/scripts/addEvmCoin.ts new file mode 100644 index 00000000..01dd94a9 --- /dev/null +++ b/scripts/addEvmCoin.ts @@ -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((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(); diff --git a/src/consts/coinTypeToNameMap.ts b/src/consts/coinTypeToNameMap.ts index f2f4cbc9..f0b0bf99 100644 --- a/src/consts/coinTypeToNameMap.ts +++ b/src/consts/coinTypeToNameMap.ts @@ -1,4 +1,6 @@ export const evmCoinTypeToNameMap = Object.freeze({ + /* Chain ID: 0 */ + "2147483648": ["metis", "1088"], /* Chain ID: 10 */ "2147483658": ["op", "Optimism"], /* Chain ID: 25 */ @@ -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 */ @@ -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({