From 91e26414566c031082df1cae49981398f5e72b53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pr=C3=A9vost?= <998369+prevostc@users.noreply.github.com> Date: Fri, 10 May 2024 13:31:08 +0200 Subject: [PATCH] Add mode --- package.json | 2 +- src/lib/addressbook.ts | 14 +++++++------- src/lib/chain.ts | 4 ++-- src/lib/config.ts | 26 ++++++++++++++++++++++++++ src/lib/rpc-client.ts | 3 ++- yarn.lock | 8 ++++---- 6 files changed, 42 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 4cfdd57..97ff8eb 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@openzeppelin/contracts": "^4.9.3", "async-lock": "^1.4.0", "axios": "^1.5.0", - "blockchain-addressbook": "^0.46.56", + "blockchain-addressbook": "^0.46.105", "dotenv": "^16.3.1", "lodash": "^4.17.21", "pg": "^8.11.3", diff --git a/src/lib/addressbook.ts b/src/lib/addressbook.ts index b8cc09a..c5a0b4d 100644 --- a/src/lib/addressbook.ts +++ b/src/lib/addressbook.ts @@ -3,7 +3,7 @@ import { Chain } from './chain'; import { Hex } from 'viem'; export function getChainWNativeTokenDecimals(chain: Chain): number { - if (chain === 'fraxtal') { + if (chain === 'mode') { return 18; } const tokens = addressbook.addressBook[chain].tokens; @@ -11,24 +11,24 @@ export function getChainWNativeTokenDecimals(chain: Chain): number { } export function getChainWNativeTokenSymbol(chain: Chain): string { - if (chain === 'fraxtal') { - return 'frxETH'; + if (chain === 'mode') { + return 'ETH'; } const tokens = addressbook.addressBook[chain].tokens; return tokens.WNATIVE.symbol; } export function getChainWNativeTokenAddress(chain: Chain): Hex { - if (chain === 'fraxtal') { - return '0xFC00000000000000000000000000000000000006'; + if (chain === 'mode') { + return '0x4200000000000000000000000000000000000006'; } const tokens = addressbook.addressBook[chain].tokens; return tokens.WNATIVE.address as Hex; } export function getNetworkId(chain: Chain): number { - if (chain === 'fraxtal') { - return 252; + if (chain === 'mode') { + return 34443; } const tokens = addressbook.addressBook[chain].tokens; return tokens.WNATIVE.chainId; diff --git a/src/lib/chain.ts b/src/lib/chain.ts index 40fb14e..da7a112 100644 --- a/src/lib/chain.ts +++ b/src/lib/chain.ts @@ -1,5 +1,5 @@ import { addressBook } from 'blockchain-addressbook'; -export type Chain = keyof typeof addressBook | 'fraxtal'; +export type Chain = keyof typeof addressBook | 'mode'; -export const allChainIds: Chain[] = [...Object.keys(addressBook), 'fraxtal'] as Chain[]; +export const allChainIds: Chain[] = [...Object.keys(addressBook), 'mode'] as Chain[]; diff --git a/src/lib/config.ts b/src/lib/config.ts index 0d4dace..50e34d9 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -531,6 +531,25 @@ export const RPC_CONFIG: Record = { setTransactionGasLimit: false, }, }, + mode: { + ...defaultConfig, + url: RPC_FORCE_URL || process.env.MODE_RPC_URL || 'https://mainnet.mode.network', + transaction: { + ...defaultTransactionConfig, + type: 'eip1559', + maxNativePerTransactionWei: bigintMultiplyFloat(ONE_ETHER, 0.01), + }, + harvest: { + ...defaultHarvestConfig, + setTransactionGasLimit: false, + }, + unwrap: { + ...defaultUnwrapConfig, + minAmountOfWNativeWei: bigintMultiplyFloat(ONE_ETHER, 0.01), + maxAmountOfNativeWei: bigintMultiplyFloat(ONE_ETHER, 0.01), + setTransactionGasLimit: false, + }, + }, metis: { ...defaultConfig, url: RPC_FORCE_URL || process.env.METIS_RPC_URL || 'https://andromeda.metis.io/?owner=1088', @@ -837,6 +856,13 @@ export const EXPLORER_CONFIG: Record = { apiUrl: process.env.METIS_EXPLORER_API_URL || 'https://andromeda-explorer.metis.io/api?', type: 'blockscout', }, + mode: { + addressLinkTemplate: 'https://modescan.io//address/${address}', + transactionLinkTemplate: 'https://modescan.io/tx/${hash}', + apiUrl: process.env.AVAX_EXPLORER_API_URL || 'https://api.modescan.io/api', + apiKey: process.env.AVAX_EXPLORER_API_KEY || '', + type: 'etherscan', + }, moonbeam: { addressLinkTemplate: 'https://moonbeam.moonscan.io/address/${address}', transactionLinkTemplate: 'https://moonbeam.moonscan.io/tx/${hash}', diff --git a/src/lib/rpc-client.ts b/src/lib/rpc-client.ts index d6a9e79..939584a 100644 --- a/src/lib/rpc-client.ts +++ b/src/lib/rpc-client.ts @@ -2,7 +2,7 @@ import { createPublicClient, createWalletClient } from 'viem'; import { type Chain } from './chain'; import { privateKeyToAccount } from 'viem/accounts'; import { RPC_CONFIG } from './config'; -import { gnosis, linea, mantle, type Chain as ViemChain } from 'viem/chains'; +import { gnosis, linea, mantle, mode, type Chain as ViemChain } from 'viem/chains'; import { arbitrum, aurora, @@ -67,6 +67,7 @@ const VIEM_CHAINS: Record = { linea: applyConfig('linea', linea), mantle: applyConfig('mantle', mantle), metis: applyConfig('metis', metis), + mode: applyConfig('mode', mode), moonbeam: applyConfig('moonbeam', moonbeam), moonriver: applyConfig('moonriver', moonriver), one: applyConfig('one', harmonyOne), diff --git a/yarn.lock b/yarn.lock index 4e360fe..fba8329 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1228,10 +1228,10 @@ base64-js@^1.3.1: resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== -blockchain-addressbook@^0.46.56: - version "0.46.56" - resolved "https://registry.yarnpkg.com/blockchain-addressbook/-/blockchain-addressbook-0.46.56.tgz#87be25341df9068f891b8fa8850ce8a18beed388" - integrity sha512-BN+dAMAuE0YlCvtRStoIz0Q1vZEr6ldPKO3Bq7ksyTH2x/WGSTlwmICDm1Usp/bxPkEvL4VkIl68Fh5iUjSZvA== +blockchain-addressbook@^0.46.105: + version "0.46.105" + resolved "https://registry.yarnpkg.com/blockchain-addressbook/-/blockchain-addressbook-0.46.105.tgz#01ddeb1936119384accebc2c4ced28af11852059" + integrity sha512-dIQj1oozxddpPASS0A0tYQerHpxMIOC37NDcb7NOVzIjlb/xs8KugxgjBDiNEic8LvIICJp04x1ZXfnnb4w9ow== dependencies: "@types/node" "^20.9.0"