From b2a680617d0c0d0750eb6577c6114aa6f59ee770 Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Wed, 19 Jul 2023 14:16:49 -0700 Subject: [PATCH 01/23] fix: bnb icon --- packages/swap/src/common/supportedNetworks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/swap/src/common/supportedNetworks.ts b/packages/swap/src/common/supportedNetworks.ts index bab22956d..5a0c620c4 100644 --- a/packages/swap/src/common/supportedNetworks.ts +++ b/packages/swap/src/common/supportedNetworks.ts @@ -31,7 +31,7 @@ const NetworkDetails: Record = { cgId: "binancecoin", decimals: 18, logoURI: - "https://tokens.1inch.io/0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c_1.png", + "https://tokens.1inch.io/0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c.png", name: "BNB", symbol: "BNB", rank: 3, From 105e4749c65df2df03959f14ac011d716bbbe66f Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Thu, 20 Jul 2023 11:06:29 -0700 Subject: [PATCH 02/23] devop: add nft support for few chains --- .../src/libs/nft-handlers/simplehash.ts | 3 ++ .../libs/assets-handlers/assetinfo-mew.ts | 20 ++++--- .../libs/assets-handlers/token-lists.ts | 3 +- .../assets-handlers/types/tokenbalance-mew.ts | 5 +- .../ethereum/libs/assets-handlers/zksync.ts | 54 ------------------- .../src/providers/ethereum/networks/goerli.ts | 2 + .../providers/ethereum/networks/zkgoerli.ts | 3 +- .../src/providers/ethereum/networks/zksync.ts | 3 ++ 8 files changed, 22 insertions(+), 71 deletions(-) delete mode 100644 packages/extension/src/providers/ethereum/libs/assets-handlers/zksync.ts diff --git a/packages/extension/src/libs/nft-handlers/simplehash.ts b/packages/extension/src/libs/nft-handlers/simplehash.ts index d20067ccd..aaf5e5eb0 100644 --- a/packages/extension/src/libs/nft-handlers/simplehash.ts +++ b/packages/extension/src/libs/nft-handlers/simplehash.ts @@ -15,6 +15,9 @@ export default async ( [NetworkNames.Arbitrum]: "arbitrum", [NetworkNames.Gnosis]: "gnosis", [NetworkNames.Avalanche]: "avalanche", + [NetworkNames.ZkSync]: "zksync-era", + [NetworkNames.ZkSyncGoerli]: "zksync-era-testnet", + [NetworkNames.Goerli]: "ethereum-goerli", }; if (!Object.keys(supportedNetworks).includes(network.name)) throw new Error("Simplehash: network not supported"); diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts index bbab36401..b51f6d31f 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts @@ -20,8 +20,8 @@ import { EvmNetwork } from "../../types/evm-network"; import { getKnownNetworkTokens } from "./token-lists"; import { CoingeckoPlatform, NetworkNames } from "@enkryptcom/types"; import { NATIVE_TOKEN_ADDRESS } from "../common"; -import getZKSyncBalances from "./zksync"; import getTomoBalances from "./tomochain"; +import { CoinGeckoTokenMarket } from "@/libs/market-data/types"; const API_ENPOINT = "https://tokenbalance.mewapi.io/"; const API_ENPOINT2 = "https://partners.mewapi.io/balances/"; @@ -95,25 +95,20 @@ const supportedNetworks: Record = { tbName: "aurora", cgPlatform: CoingeckoPlatform.Aurora, }, + [NetworkNames.ZkSync]: { + tbName: "era", + cgPlatform: CoingeckoPlatform.Zksync, + }, [NetworkNames.TomoChain]: { tbName: "", cgPlatform: CoingeckoPlatform.TomoChain, }, - [NetworkNames.ZkSyncGoerli]: { - tbName: "", - }, - [NetworkNames.ZkSync]: { - tbName: "", - }, }; const getTokens = ( chain: SupportedNetworkNames, address: string ): Promise => { - if (chain === NetworkNames.ZkSyncGoerli || chain === NetworkNames.ZkSync) { - return getZKSyncBalances(chain, address); - } if (chain === NetworkNames.TomoChain) { return getTomoBalances(chain, address); } @@ -165,7 +160,10 @@ export default ( ), supportedNetworks[networkName].cgPlatform as CoingeckoPlatform ) - : tokens.reduce((obj, cur) => ({ ...obj, [cur.contract]: null }), {}); + : tokens.reduce( + (obj, cur) => ({ ...obj, [cur.contract]: null }), + {} as Record + ); if (network.coingeckoID) { const nativeMarket = await marketData.getMarketData([ network.coingeckoID, diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts index bd5fc2b6e..195c508ec 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts @@ -14,8 +14,7 @@ const TokenList: Record = { [NetworkNames.ShidenEVM]: `https://tokens.coingecko.com/${CoingeckoPlatform.Shiden}/all.json`, [NetworkNames.Canto]: `https://tokens.coingecko.com/${CoingeckoPlatform.Canto}/all.json`, [NetworkNames.Rootstock]: `https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/tokenlists/rsk.json`, - [NetworkNames.ZkSyncGoerli]: `https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/tokenlists/zksyncgoerli.json`, - [NetworkNames.ZkSync]: `https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/tokenlists/zksync.json`, + [NetworkNames.ZkSync]: `https://tokens.coingecko.com/${CoingeckoPlatform.Zksync}/all.json`, [NetworkNames.Arbitrum]: `https://tokens.coingecko.com/${CoingeckoPlatform.Arbitrum}/all.json`, [NetworkNames.Gnosis]: `https://tokens.coingecko.com/${CoingeckoPlatform.Gnosis}/all.json`, [NetworkNames.Avalanche]: `https://tokens.coingecko.com/${CoingeckoPlatform.Avalanche}/all.json`, diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts index 7ce991ad5..30f3bedbd 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts @@ -43,6 +43,5 @@ export type SupportedNetworkNames = | NetworkNames.Fantom | NetworkNames.Klaytn | NetworkNames.Aurora - | NetworkNames.ZkSyncGoerli - | NetworkNames.ZkSync - | NetworkNames.TomoChain; + | NetworkNames.TomoChain + | NetworkNames.ZkSync; diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/zksync.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/zksync.ts deleted file mode 100644 index 92cf57f57..000000000 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/zksync.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { NetworkNames } from "@enkryptcom/types"; -import { - SupportedNetworkNames, - TokenBalance, - ZkSyncBalanceType, -} from "./types/tokenbalance-mew"; -import { NetworkEndpoints } from "../activity-handlers/providers/etherscan/configs"; -import { NATIVE_TOKEN_ADDRESS } from "../common"; -import { numberToHex, toBN } from "web3-utils"; - -const ZKGoerli_ENDPOINT = NetworkEndpoints[NetworkNames.ZkSyncGoerli]; -const ZKSync_ENDPOINT = NetworkEndpoints[NetworkNames.ZkSync]; - -const getBalances = (chain: SupportedNetworkNames, address: string) => { - const endpoint = - chain === NetworkNames.ZkSyncGoerli ? ZKGoerli_ENDPOINT : ZKSync_ENDPOINT; - return fetch( - `${endpoint}api?module=account&action=tokenlist&address=${address}` - ) - .then((res) => res.json()) - .then((json) => { - if (json.status === "0" && json.result === null) - return Promise.reject( - `TOKENBALANCE-MEW: ${JSON.stringify(json.message)}` - ); - else { - const results: ZkSyncBalanceType[] = json.result; - const retVal: TokenBalance[] = []; - const zksyncNativeAddress = - "0x000000000000000000000000000000000000800a"; - results.forEach((bal) => { - retVal.push({ - contract: - bal.contractAddress === zksyncNativeAddress - ? NATIVE_TOKEN_ADDRESS - : bal.contractAddress, - balance: numberToHex(toBN(bal.balance)), - }); - }); - const isNativeAvailable = json.result.length - ? json.result.find((i: any) => i.contract === NATIVE_TOKEN_ADDRESS) - : false; - if (!isNativeAvailable) { - retVal.push({ - contract: NATIVE_TOKEN_ADDRESS, - balance: "0x0", - }); - } - return retVal; - } - }); -}; - -export default getBalances; diff --git a/packages/extension/src/providers/ethereum/networks/goerli.ts b/packages/extension/src/providers/ethereum/networks/goerli.ts index b66ca0da0..c050bb3d1 100644 --- a/packages/extension/src/providers/ethereum/networks/goerli.ts +++ b/packages/extension/src/providers/ethereum/networks/goerli.ts @@ -2,6 +2,7 @@ import { NetworkNames } from "@enkryptcom/types"; import { EvmNetwork, EvmNetworkOptions } from "../types/evm-network"; import { RivetActivity } from "../libs/activity-handlers"; import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler"; +import shNFTHandler from "@/libs/nft-handlers/simplehash"; const goerliOptions: EvmNetworkOptions = { name: NetworkNames.Goerli, @@ -16,6 +17,7 @@ const goerliOptions: EvmNetworkOptions = { node: "wss://nodes.mewapi.io/ws/goerli", icon: require("./icons/eth.svg"), gradient: "linear-gradient(180deg, #C549FF 0%, #684CFF 100%)", + NFTHandler: shNFTHandler, activityHandler: wrapActivityHandler(RivetActivity), }; diff --git a/packages/extension/src/providers/ethereum/networks/zkgoerli.ts b/packages/extension/src/providers/ethereum/networks/zkgoerli.ts index ae6b084fc..d203f1a4d 100644 --- a/packages/extension/src/providers/ethereum/networks/zkgoerli.ts +++ b/packages/extension/src/providers/ethereum/networks/zkgoerli.ts @@ -3,6 +3,7 @@ import { EvmNetwork, EvmNetworkOptions } from "../types/evm-network"; import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler"; import { EtherscanActivity } from "../libs/activity-handlers"; import assetsInfoHandler from "@/providers/ethereum/libs/assets-handlers/assetinfo-mew"; +import shNFTHandler from "@/libs/nft-handlers/simplehash"; const zkgoerliOptions: EvmNetworkOptions = { name: NetworkNames.ZkSyncGoerli, @@ -17,7 +18,7 @@ const zkgoerliOptions: EvmNetworkOptions = { node: "wss://zksync2-testnet.zksync.dev/ws", icon: require("./icons/zksync.svg"), gradient: "linear-gradient(180deg, #C549FF 0%, #684CFF 100%)", - assetsInfoHandler, + NFTHandler: shNFTHandler, activityHandler: wrapActivityHandler(EtherscanActivity), }; diff --git a/packages/extension/src/providers/ethereum/networks/zksync.ts b/packages/extension/src/providers/ethereum/networks/zksync.ts index 60ef67622..2714b0a31 100644 --- a/packages/extension/src/providers/ethereum/networks/zksync.ts +++ b/packages/extension/src/providers/ethereum/networks/zksync.ts @@ -3,6 +3,7 @@ import { EvmNetwork, EvmNetworkOptions } from "../types/evm-network"; import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler"; import { EtherscanActivity } from "../libs/activity-handlers"; import assetsInfoHandler from "@/providers/ethereum/libs/assets-handlers/assetinfo-mew"; +import shNFTHandler from "@/libs/nft-handlers/simplehash"; const zkSyncOptions: EvmNetworkOptions = { name: NetworkNames.ZkSync, @@ -19,7 +20,9 @@ const zkSyncOptions: EvmNetworkOptions = { gradient: "linear-gradient(180deg, #C549FF 0%, #684CFF 100%)", coingeckoID: "ethereum", coingeckoPlatform: CoingeckoPlatform.Zksync, + NFTHandler: shNFTHandler, assetsInfoHandler, + activityHandler: wrapActivityHandler(EtherscanActivity), }; From e75d4cda2aebf6353c64365492bf2374e1a3336f Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Thu, 20 Jul 2023 11:36:05 -0700 Subject: [PATCH 03/23] devop: extend keyring timeout during action --- .../src/libs/nft-handlers/simplehash.ts | 1 + .../providers/etherscan/configs.ts | 1 + .../libs/assets-handlers/assetinfo-mew.ts | 4 +++ .../libs/assets-handlers/token-lists.ts | 1 + .../assets-handlers/types/tokenbalance-mew.ts | 1 + .../src/providers/ethereum/networks/index.ts | 2 ++ .../providers/ethereum/networks/maticzk.ts | 30 +++++++++++++++++++ .../providers/ethereum/networks/zkgoerli.ts | 1 - packages/keyring/src/index.ts | 23 +++++++++----- packages/types/src/networks.ts | 2 ++ 10 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 packages/extension/src/providers/ethereum/networks/maticzk.ts diff --git a/packages/extension/src/libs/nft-handlers/simplehash.ts b/packages/extension/src/libs/nft-handlers/simplehash.ts index aaf5e5eb0..9bed13237 100644 --- a/packages/extension/src/libs/nft-handlers/simplehash.ts +++ b/packages/extension/src/libs/nft-handlers/simplehash.ts @@ -15,6 +15,7 @@ export default async ( [NetworkNames.Arbitrum]: "arbitrum", [NetworkNames.Gnosis]: "gnosis", [NetworkNames.Avalanche]: "avalanche", + [NetworkNames.MaticZK]: "polygon-zkevm", [NetworkNames.ZkSync]: "zksync-era", [NetworkNames.ZkSyncGoerli]: "zksync-era-testnet", [NetworkNames.Goerli]: "ethereum-goerli", diff --git a/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts b/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts index be3a854cc..d2e0f1ed9 100644 --- a/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts +++ b/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts @@ -42,6 +42,7 @@ const NetworkEndpoints: Record = { [NetworkNames.Fantom]: "https://api.ftmscan.com/", [NetworkNames.Aurora]: "https://explorer.mainnet.aurora.dev/", [NetworkNames.PuppyNet]: "https://puppyscan.shib.io/", + [NetworkNames.MaticZK]: "https://api-zkevm.polygonscan.com/", }; export { NetworkEndpoints }; diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts index b51f6d31f..161ed0e32 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts @@ -99,6 +99,10 @@ const supportedNetworks: Record = { tbName: "era", cgPlatform: CoingeckoPlatform.Zksync, }, + [NetworkNames.MaticZK]: { + tbName: "pze", + cgPlatform: CoingeckoPlatform.MaticZK, + }, [NetworkNames.TomoChain]: { tbName: "", cgPlatform: CoingeckoPlatform.TomoChain, diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts index 195c508ec..36a61d11e 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts @@ -6,6 +6,7 @@ const TokenList: Record = { [NetworkNames.Binance]: `https://tokens.coingecko.com/${CoingeckoPlatform.Binance}/all.json`, [NetworkNames.Ethereum]: `https://tokens.coingecko.com/${CoingeckoPlatform.Ethereum}/all.json`, [NetworkNames.Matic]: `https://tokens.coingecko.com/${CoingeckoPlatform.Matic}/all.json`, + [NetworkNames.MaticZK]: `https://tokens.coingecko.com/${CoingeckoPlatform.MaticZK}/all.json`, [NetworkNames.AstarEVM]: `https://tokens.coingecko.com/${CoingeckoPlatform.Astar}/all.json`, [NetworkNames.Okc]: `https://tokens.coingecko.com/${CoingeckoPlatform.Okc}/all.json`, [NetworkNames.Optimism]: `https://tokens.coingecko.com/${CoingeckoPlatform.Optimism}/all.json`, diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts index 30f3bedbd..12fc0e775 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts @@ -44,4 +44,5 @@ export type SupportedNetworkNames = | NetworkNames.Klaytn | NetworkNames.Aurora | NetworkNames.TomoChain + | NetworkNames.MaticZK | NetworkNames.ZkSync; diff --git a/packages/extension/src/providers/ethereum/networks/index.ts b/packages/extension/src/providers/ethereum/networks/index.ts index f86617ea7..a9b7a19f1 100644 --- a/packages/extension/src/providers/ethereum/networks/index.ts +++ b/packages/extension/src/providers/ethereum/networks/index.ts @@ -2,6 +2,7 @@ import ethNode from "./eth"; import goerliNode from "./goerli"; import etcNode from "./etc"; import maticNode from "./matic"; +import maticZkNode from "./maticzk"; import bscNode from "./bsc"; import moonbeamNode from "./glmr"; import moonriverNode from "./movr"; @@ -33,6 +34,7 @@ export default { ethereum: ethNode, etc: etcNode, matic: maticNode, + maticzk: maticZkNode, bsc: bscNode, moonbeam: moonbeamNode, moonriver: moonriverNode, diff --git a/packages/extension/src/providers/ethereum/networks/maticzk.ts b/packages/extension/src/providers/ethereum/networks/maticzk.ts new file mode 100644 index 000000000..6c6ba2bc4 --- /dev/null +++ b/packages/extension/src/providers/ethereum/networks/maticzk.ts @@ -0,0 +1,30 @@ +import { CoingeckoPlatform, NetworkNames } from "@enkryptcom/types"; +import { EvmNetwork, EvmNetworkOptions } from "../types/evm-network"; +import assetsInfoHandler from "@/providers/ethereum/libs/assets-handlers/assetinfo-mew"; +import { EtherscanActivity } from "../libs/activity-handlers"; +import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler"; +import shNFTHandler from "@/libs/nft-handlers/simplehash"; + +const maticOptions: EvmNetworkOptions = { + name: NetworkNames.MaticZK, + name_long: "Polygon (Matic) | Zk EVM", + homePage: "https://zkevm.polygonscan.com/", + blockExplorerTX: "https://zkevm.polygonscan.com/tx/[[txHash]]", + blockExplorerAddr: "https://zkevm.polygonscan.com/address/[[address]]", + chainID: "0x44d", + isTestNetwork: false, + currencyName: "MATIC", + currencyNameLong: "Polygon Matic", + node: "wss://nodes.mewapi.io/ws/maticzk", + icon: require("./icons/matic.svg"), + gradient: "#7B3FE4", + coingeckoID: "matic-network", + coingeckoPlatform: CoingeckoPlatform.MaticZK, + NFTHandler: shNFTHandler, + assetsInfoHandler, + activityHandler: wrapActivityHandler(EtherscanActivity), +}; + +const matic = new EvmNetwork(maticOptions); + +export default matic; diff --git a/packages/extension/src/providers/ethereum/networks/zkgoerli.ts b/packages/extension/src/providers/ethereum/networks/zkgoerli.ts index d203f1a4d..10bc17e43 100644 --- a/packages/extension/src/providers/ethereum/networks/zkgoerli.ts +++ b/packages/extension/src/providers/ethereum/networks/zkgoerli.ts @@ -2,7 +2,6 @@ import { NetworkNames } from "@enkryptcom/types"; import { EvmNetwork, EvmNetworkOptions } from "../types/evm-network"; import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler"; import { EtherscanActivity } from "../libs/activity-handlers"; -import assetsInfoHandler from "@/providers/ethereum/libs/assets-handlers/assetinfo-mew"; import shNFTHandler from "@/libs/nft-handlers/simplehash"; const zkgoerliOptions: EvmNetworkOptions = { diff --git a/packages/keyring/src/index.ts b/packages/keyring/src/index.ts index 9ad187a35..23725c3ab 100644 --- a/packages/keyring/src/index.ts +++ b/packages/keyring/src/index.ts @@ -32,7 +32,7 @@ class KeyRing { #privkeys: Record; - #autoLock: number; + #autoLock: ReturnType; readonly autoLockTime: number; @@ -73,6 +73,15 @@ class KeyRing { return false; } + #resetTimeout(): void { + clearTimeout(this.#autoLock); + this.#autoLock = setTimeout(() => { + this.#mnemonic = null; + this.#isLocked = true; + this.#privkeys = {}; + }, this.autoLockTime); + } + async #getPathIndex(basePath: string): Promise { const pathIndexes = (await this.#storage.get(configs.STORAGE_KEYS.PATH_INDEXES)) || {}; @@ -97,12 +106,7 @@ class KeyRing { [this.#mnemonic, this.#privkeys] = results; this.#isLocked = false; if (this.autoLockTime !== 0) { - clearTimeout(this.#autoLock); - setTimeout(() => { - this.#mnemonic = null; - this.#isLocked = true; - this.#privkeys = {}; - }, this.autoLockTime); + this.#resetTimeout(); } }); } @@ -113,6 +117,7 @@ class KeyRing { async createKey(key: KeyRecordAdd): Promise { assert(!this.#isLocked, Errors.KeyringErrors.Locked); + this.#resetTimeout(); const nextIndex = await this.#getPathIndex(key.basePath); let keypair: KeyPair; if (key.walletType === WalletType.privkey) { @@ -161,6 +166,7 @@ class KeyRing { async sign(msgHash: string, options: SignOptions): Promise { assert(!this.#isLocked, Errors.KeyringErrors.Locked); + this.#resetTimeout(); assert( !Object.values(HWwalletType).includes( options.walletType as unknown as HWwalletType @@ -188,6 +194,7 @@ class KeyRing { async getEthereumEncryptionPublicKey(options: SignOptions): Promise { assert(!this.#isLocked, Errors.KeyringErrors.Locked); + this.#resetTimeout(); assert( !Object.values(HWwalletType).includes( options.walletType as unknown as HWwalletType @@ -212,6 +219,7 @@ class KeyRing { options: SignOptions ): Promise { assert(!this.#isLocked, Errors.KeyringErrors.Locked); + this.#resetTimeout(); assert( !Object.values(HWwalletType).includes( options.walletType as unknown as HWwalletType @@ -339,6 +347,7 @@ class KeyRing { lock(): void { clearTimeout(this.#autoLock); this.#mnemonic = null; + this.#privkeys = {}; this.#isLocked = true; } } diff --git a/packages/types/src/networks.ts b/packages/types/src/networks.ts index 5670b324b..2006de4e5 100644 --- a/packages/types/src/networks.ts +++ b/packages/types/src/networks.ts @@ -6,6 +6,7 @@ export enum NetworkNames { Goerli = "GOERLI", Sepolia = "SEPOLIA", Matic = "MATIC", + MaticZK = "MATICZK", Moonbeam = "GLMR", Moonriver = "MOVR", Rootstock = "Rootstock", @@ -61,6 +62,7 @@ export enum CoingeckoPlatform { Binance = "binance-smart-chain", EthereumClassic = "ethereum-classic", Matic = "polygon-pos", + MaticZK = "polygon-zkevm", Moonbeam = "moonbeam", Moonriver = "moonriver", Acala = "acala", From 7d89e21ab4c916ee7d5a9b1361e3643bf5fb46f3 Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Thu, 20 Jul 2023 14:09:24 -0700 Subject: [PATCH 04/23] devop: optmize injection --- .../src/providers/ethereum/inject.ts | 13 ++++-- .../ethereum/libs/transaction/index.ts | 27 +++++++----- .../ethereum/tests/ethereum.events.mocha.ts | 30 ++++++++----- .../ethereum/tests/ethereum.requests.mocha.ts | 30 ++++++++----- .../src/providers/polkadot/inject.ts | 16 +++++-- .../extension/src/scripts/contentscript.ts | 25 ++++------- packages/extension/src/scripts/inject.ts | 42 ++++++++++--------- 7 files changed, 107 insertions(+), 76 deletions(-) diff --git a/packages/extension/src/providers/ethereum/inject.ts b/packages/extension/src/providers/ethereum/inject.ts index 52085b56b..d8b47bb81 100644 --- a/packages/extension/src/providers/ethereum/inject.ts +++ b/packages/extension/src/providers/ethereum/inject.ts @@ -19,6 +19,7 @@ import { EXTENSION_VERSION } from "@/configs/constants"; import { SettingsType } from "@/libs/settings-state/types"; import { EnkryptWindow } from "@/types/globals"; import { v4 as randomUUID } from "uuid"; +import { InternalMethods } from "@/types/messenger"; export class Provider extends EventEmitter implements ProviderInterface { chainId: string | null; @@ -144,11 +145,17 @@ const injectDocument = ( options: ProviderOptions ): void => { const provider = new Provider(options); - const globalSettings: SettingsType = document.enkrypt.settings; const proxiedProvider = new Proxy(provider, ProxyHandler); - if (!globalSettings.evm.inject.disabled) - document[options.name] = proxiedProvider; //proxy is needed due to web3js 1.3.0 callbackify issue. Used in superrare document["enkrypt"]["providers"][options.name] = provider; + options + .sendMessageHandler( + ProviderName.enkrypt, + JSON.stringify({ method: InternalMethods.getSettings, params: [] }) + ) + .then((settings: SettingsType) => { + if (!settings.evm.inject.disabled) + document[options.name] = proxiedProvider; //proxy is needed due to web3js 1.3.0 callbackify issue. Used in superrare + }); const ENKRYPT_UUID_V4 = randomUUID(); // EIP-6963 const eip6963AnnounceProvider = () => { diff --git a/packages/extension/src/providers/ethereum/libs/transaction/index.ts b/packages/extension/src/providers/ethereum/libs/transaction/index.ts index bfb6343e8..d24a3014c 100644 --- a/packages/extension/src/providers/ethereum/libs/transaction/index.ts +++ b/packages/extension/src/providers/ethereum/libs/transaction/index.ts @@ -71,14 +71,26 @@ class Transaction { const { isFeeMarketNetwork, baseFeePerGas } = await this.web3 .getBlock("pending", false) .then((block) => { - return { - isFeeMarketNetwork: !!block.baseFeePerGas, - baseFeePerGas: block.baseFeePerGas?.toString(), - }; + if (block) { + return { + isFeeMarketNetwork: !!block.baseFeePerGas, + baseFeePerGas: block.baseFeePerGas?.toString(), + }; + } + // some networks such as zksync era pending block is null + return this.web3.getBlock("latest", false).then((block) => { + return { + isFeeMarketNetwork: !!block.baseFeePerGas, + baseFeePerGas: block.baseFeePerGas?.toString(), + }; + }); }); const gasPrice = await this.web3.getGasPrice(); const nonce = await this.web3.getTransactionCount(this.tx.from, "pending"); - if (!isFeeMarketNetwork) { + const feeHistory = await this.web3 + .getFeeHistory(6, "pending", [25, 50, 75, 90]) + .catch(() => null); + if (!isFeeMarketNetwork || !feeHistory) { const legacyTx: FinalizedLegacyEthereumTransaction = { to: this.tx.to || undefined, chainId: this.tx.chainId, @@ -99,11 +111,6 @@ class Transaction { gasLimit: legacyTx.gasLimit, }; } else { - const feeHistory = await this.web3.getFeeHistory( - 6, - "pending", - [25, 50, 75, 90] - ); const formattedFeeHistory = formatFeeHistory(feeHistory); const feeMarket = this.getFeeMarketGasInfo( baseFeePerGas!, diff --git a/packages/extension/src/providers/ethereum/tests/ethereum.events.mocha.ts b/packages/extension/src/providers/ethereum/tests/ethereum.events.mocha.ts index e65e439a7..aa98bc1ea 100644 --- a/packages/extension/src/providers/ethereum/tests/ethereum.events.mocha.ts +++ b/packages/extension/src/providers/ethereum/tests/ethereum.events.mocha.ts @@ -4,15 +4,32 @@ import EthereumInject from "../inject"; import { MessageMethod, EmitEvent } from "../types"; import { OnMessageResponse } from "@enkryptcom/types"; import { EnkryptWindow } from "@/types/globals"; +import { InternalMethods } from "@/types/messenger"; +const defaultSettings = { + evm: { + inject: { + disabled: false, + timestamp: 0, + }, + }, + substrate: { + injectPolkadotjs: false, + }, + manifestVersion: 3, +}; const providerSendMessage = async ( provider: ProviderName, message: string ): Promise => { + if (JSON.parse(message).method === InternalMethods.getSettings) { + return defaultSettings as unknown as OnMessageResponse; + } return { result: `dummy-response-${provider}-${message}`, }; }; + const options = { name: ProviderName.ethereum, type: ProviderType.evm, @@ -21,17 +38,7 @@ const options = { const tempWindow: EnkryptWindow = { enkrypt: { providers: {}, - settings: { - evm: { - inject: { - disabled: false, - timestamp: 0, - }, - }, - substrate: { - injectPolkadotjs: false, - }, - }, + settings: defaultSettings, }, // eslint-disable-next-line @typescript-eslint/no-empty-function addEventListener: () => {}, @@ -43,6 +50,7 @@ const tempWindow: EnkryptWindow = { describe("Test injected Ethereum", () => { it("should have default values", async () => { EthereumInject(tempWindow, options); + await new Promise((r) => setTimeout(r, 500)); const provider = tempWindow[ProviderName.ethereum] as EthereumProvider; expect(provider.name).to.equal(ProviderName.ethereum); expect(provider.chainId).to.equal(null); diff --git a/packages/extension/src/providers/ethereum/tests/ethereum.requests.mocha.ts b/packages/extension/src/providers/ethereum/tests/ethereum.requests.mocha.ts index 04b90bb52..588444f04 100644 --- a/packages/extension/src/providers/ethereum/tests/ethereum.requests.mocha.ts +++ b/packages/extension/src/providers/ethereum/tests/ethereum.requests.mocha.ts @@ -5,6 +5,20 @@ import { EthereumRequest } from "../types"; import { OnMessageResponse } from "@enkryptcom/types"; import { getError } from "@/libs/error"; import { EnkryptWindow } from "@/types/globals"; +import { InternalMethods } from "@/types/messenger"; + +const defaultSettings = { + evm: { + inject: { + disabled: false, + timestamp: 0, + }, + }, + substrate: { + injectPolkadotjs: false, + }, + manifestVersion: 3, +}; const requestHandler = (request: string): OnMessageResponse => { const req = JSON.parse(request) as EthereumRequest; @@ -28,6 +42,9 @@ const providerSendMessage = async ( provider: ProviderName, message: string ): Promise => { + if (JSON.parse(message).method === InternalMethods.getSettings) { + return defaultSettings as unknown as OnMessageResponse; + } if (provider === ProviderName.ethereum) { const res = requestHandler(message); if (res.error) return Promise.reject(JSON.parse(res.error)); @@ -42,17 +59,7 @@ const options = { const tempWindow: EnkryptWindow = { enkrypt: { providers: {}, - settings: { - evm: { - inject: { - disabled: false, - timestamp: 0, - }, - }, - substrate: { - injectPolkadotjs: false, - }, - }, + settings: defaultSettings, }, // eslint-disable-next-line @typescript-eslint/no-empty-function addEventListener: () => {}, @@ -64,6 +71,7 @@ const tempWindow: EnkryptWindow = { describe("Test Ethereum reponses", () => { it("should send proper responses", async () => { EthereumInject(tempWindow, options); + await new Promise((r) => setTimeout(r, 500)); const provider = tempWindow[ProviderName.ethereum] as EthereumProvider; expect(await provider.request({ method: "eth_chainId" })).to.equal("0x1"); await provider.request({ method: "eth_requestAccounts" }).catch((e) => { diff --git a/packages/extension/src/providers/polkadot/inject.ts b/packages/extension/src/providers/polkadot/inject.ts index 2a879c3ac..e661e3f87 100644 --- a/packages/extension/src/providers/polkadot/inject.ts +++ b/packages/extension/src/providers/polkadot/inject.ts @@ -15,6 +15,7 @@ import { InjectedSendMessageHandler } from "./types"; import { OnMessageResponse, RPCRequestType } from "@enkryptcom/types"; import { SettingsType } from "@/libs/settings-state/types"; import { EnkryptWindow } from "@/types/globals"; +import { InternalMethods } from "@/types/messenger"; let sendMessageHandler: InjectedSendMessageHandler; const messagerRouter = new MessageRouter(); export class Provider @@ -91,9 +92,18 @@ const injectDocument = ( const provider = new Provider(options); document.injectedWeb3 = document.injectedWeb3 || {}; document.injectedWeb3["enkrypt"] = new Proxy(provider, ProxyHandler); - const globalSettings: SettingsType = document.enkrypt.settings; - if (globalSettings.substrate.injectPolkadotjs) - document.injectedWeb3["polkadot-js"] = new Proxy(provider, ProxyHandler); + options + .sendMessageHandler( + ProviderName.enkrypt, + JSON.stringify({ method: InternalMethods.getSettings, params: [] }) + ) + .then((settings: SettingsType) => { + if (!settings.substrate.injectPolkadotjs) + document.injectedWeb3["polkadot-js"] = new Proxy( + provider, + ProxyHandler + ); + }); document["enkrypt"]["providers"][options.name] = provider; }; diff --git a/packages/extension/src/scripts/contentscript.ts b/packages/extension/src/scripts/contentscript.ts index 19d9f8d5f..a9380a190 100644 --- a/packages/extension/src/scripts/contentscript.ts +++ b/packages/extension/src/scripts/contentscript.ts @@ -1,22 +1,17 @@ import browser from "webextension-polyfill"; -import { - setContentScriptNamespace, - sendToBackgroundFromCS, -} from "@/libs/messenger/extension"; -import { InjectedIDs, InternalMethods } from "@/types/messenger"; -import { ProviderName } from "@/types/provider"; +import { setContentScriptNamespace } from "@/libs/messenger/extension"; +import { InjectedIDs } from "@/types/messenger"; setContentScriptNamespace(); -function injectScript(settings: string) { - settings = encodeURIComponent(settings); +function injectScript() { try { const injectURL = browser.runtime.getURL("scripts/inject.js"); const container = document.head || document.documentElement; const scriptTag = document.createElement("script"); scriptTag.setAttribute("async", "false"); - scriptTag.src = `${injectURL}?settings=${settings}`; + scriptTag.src = injectURL; scriptTag.id = InjectedIDs.main; scriptTag.onload = function () { - console.info("Hello from the content-script"); + console.info("Enkrypt: Hello from CS"); container.removeChild(scriptTag); }; container.insertBefore(scriptTag, container.children[0]); @@ -25,11 +20,5 @@ function injectScript(settings: string) { console.error("Enkrypt: Provider injection failed.", error); } } -sendToBackgroundFromCS({ - message: JSON.stringify({ method: InternalMethods.getSettings, params: [] }), - provider: ProviderName.enkrypt, -}).then((res) => { - if (res.result) { - injectScript(res.result); - } -}); + +injectScript(); diff --git a/packages/extension/src/scripts/inject.ts b/packages/extension/src/scripts/inject.ts index 6f6f3e835..cc1a98631 100644 --- a/packages/extension/src/scripts/inject.ts +++ b/packages/extension/src/scripts/inject.ts @@ -8,15 +8,32 @@ import EthereumProvider from "@/providers/ethereum/inject"; import PolkadotProvider from "@/providers/polkadot/inject"; import BitcoinProvider from "@/providers/bitcoin/inject"; -import { InternalMethods, InjectedIDs } from "@/types/messenger"; +import { InternalMethods } from "@/types/messenger"; + setWindowNamespace(); (window as Window).enkrypt = { providers: {}, settings: {}, }; -const script = document.getElementById(InjectedIDs.main) as HTMLScriptElement; -const scriptURL = new URL(script.src); -window.enkrypt.settings = JSON.parse(scriptURL.searchParams.get("settings")!); +const loadInjectedProviders = () => { + EthereumProvider(window, { + name: ProviderName.ethereum, + type: ProviderType.evm, + sendMessageHandler: providerSendMessage, + }); + PolkadotProvider(window, { + name: ProviderName.polkadot, + type: ProviderType.substrate, + sendMessageHandler: providerSendMessage, + }); + BitcoinProvider(window, { + name: ProviderName.bitcoin, + type: ProviderType.bitcoin, + sendMessageHandler: providerSendMessage, + }); +}; + +loadInjectedProviders(); windowOnMessage(async (msg): Promise => { window["enkrypt"]["providers"][msg.provider].handleMessage(msg.message); @@ -33,19 +50,4 @@ window.addEventListener("beforeunload", () => { JSON.stringify({ method: InternalMethods.newWindowUnload }) ); }); -console.info("hello from injected code"); -EthereumProvider(window, { - name: ProviderName.ethereum, - type: ProviderType.evm, - sendMessageHandler: providerSendMessage, -}); -PolkadotProvider(window, { - name: ProviderName.polkadot, - type: ProviderType.substrate, - sendMessageHandler: providerSendMessage, -}); -BitcoinProvider(window, { - name: ProviderName.bitcoin, - type: ProviderType.bitcoin, - sendMessageHandler: providerSendMessage, -}); +console.info("Enkrypt: Hello from IN"); From 983d50f228e8b564fbc48798d9871783fc1a284f Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Thu, 20 Jul 2023 14:32:14 -0700 Subject: [PATCH 05/23] devop: fix swap hw wallet ui --- .../src/ui/action/views/swap/components/swap-error/index.vue | 2 +- .../src/ui/action/views/swap/components/swap-loading/index.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/extension/src/ui/action/views/swap/components/swap-error/index.vue b/packages/extension/src/ui/action/views/swap/components/swap-error/index.vue index c8a18e979..140e45904 100644 --- a/packages/extension/src/ui/action/views/swap/components/swap-error/index.vue +++ b/packages/extension/src/ui/action/views/swap/components/swap-error/index.vue @@ -106,7 +106,7 @@ defineProps(); } &__container { - width: 800px; + width: 100%; height: 600px; left: 0px; top: 0px; diff --git a/packages/extension/src/ui/action/views/swap/components/swap-loading/index.vue b/packages/extension/src/ui/action/views/swap/components/swap-loading/index.vue index e6e97204c..b338e6b79 100644 --- a/packages/extension/src/ui/action/views/swap/components/swap-loading/index.vue +++ b/packages/extension/src/ui/action/views/swap/components/swap-loading/index.vue @@ -82,7 +82,7 @@ withDefaults(defineProps(), { } &__container { - width: 800px; + width: 100%; height: 600px; left: 0px; top: 0px; From 5e228da67b58d4b707697dc0bf1fd5a8332a10bb Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Thu, 20 Jul 2023 16:03:05 -0700 Subject: [PATCH 06/23] devop: add zksync swap --- packages/swap/src/common/supportedNetworks.ts | 12 +++++++++++ packages/swap/src/configs.ts | 1 + packages/swap/src/providers/oneInch/index.ts | 20 +++++++++++-------- packages/swap/src/providers/oneInch/types.ts | 3 +-- packages/swap/src/types/index.ts | 1 + 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/packages/swap/src/common/supportedNetworks.ts b/packages/swap/src/common/supportedNetworks.ts index 5a0c620c4..776339634 100644 --- a/packages/swap/src/common/supportedNetworks.ts +++ b/packages/swap/src/common/supportedNetworks.ts @@ -181,6 +181,18 @@ const NetworkDetails: Record = { rank: 15, symbol: "ETH", }, + [SupportedNetworkName.Zksync]: { + id: SupportedNetworkName.Zksync, + cgId: "ethereum", + decimals: 18, + logoURI: + "https://tokens.1inch.io/0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.png", + name: "ZkSync Era", + signerType: [SignerType.secp256k1], + type: NetworkType.EVM, + rank: 16, + symbol: "ETH", + }, }; export const isSupportedNetwork = (networkName: SupportedNetworkName) => !!NetworkDetails[networkName]; diff --git a/packages/swap/src/configs.ts b/packages/swap/src/configs.ts index 5be826f25..2ef953bfc 100644 --- a/packages/swap/src/configs.ts +++ b/packages/swap/src/configs.ts @@ -50,6 +50,7 @@ const TOKEN_LISTS: { [NetworkNames.Moonbeam]: `https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/swaplists/${SupportedNetworkName.Moonbeam}.json`, [NetworkNames.Gnosis]: `https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/swaplists/${SupportedNetworkName.Gnosis}.json`, [NetworkNames.Klaytn]: `https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/swaplists/${SupportedNetworkName.Klaytn}.json`, + [NetworkNames.ZkSync]: `https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/swaplists/${SupportedNetworkName.Zksync}.json`, }; const CHANGELLY_LIST = diff --git a/packages/swap/src/providers/oneInch/index.ts b/packages/swap/src/providers/oneInch/index.ts index 260481575..8361fdbce 100644 --- a/packages/swap/src/providers/oneInch/index.ts +++ b/packages/swap/src/providers/oneInch/index.ts @@ -78,9 +78,13 @@ const supportedNetworks: { approvalAddress: ONEINCH_APPROVAL_ADDRESS, chainId: "42161", }, + [SupportedNetworkName.Zksync]: { + approvalAddress: "0x6e2b76966cbd9cf4cc2fa0d76d24d5241e0abc2f", + chainId: "324", + }, }; -const BASE_URL = "https://api.1inch.io/v5.0/"; +const BASE_URL = "https://partners.mewapi.io/oneinch/v5.2/"; class OneInch extends ProviderClass { tokenList: TokenType[]; @@ -158,14 +162,14 @@ class OneInch extends ProviderClass { return Promise.resolve(null); const feeConfig = FEE_CONFIGS[this.name][meta.walletIdentifier]; const params = new URLSearchParams({ - fromTokenAddress: options.fromToken.address, - toTokenAddress: options.toToken.address, + src: options.fromToken.address, + dst: options.toToken.address, amount: options.amount.toString(), - fromAddress: options.fromAddress, - destReceiver: options.toAddress, + from: options.fromAddress, + receiver: options.toAddress, slippage: meta.slippage ? meta.slippage : DEFAULT_SLIPPAGE, fee: feeConfig ? (feeConfig.fee * 100).toFixed(3) : "0", - referrerAddress: feeConfig ? feeConfig.referrer : "", + referrer: feeConfig ? feeConfig.referrer : "", disableEstimate: "true", }); return fetch( @@ -214,8 +218,8 @@ class OneInch extends ProviderClass { } return { transactions, - toTokenAmount: toBN(response.toTokenAmount), - fromTokenAmount: toBN(response.fromTokenAmount), + toTokenAmount: toBN(response.toAmount), + fromTokenAmount: options.amount, }; }); } diff --git a/packages/swap/src/providers/oneInch/types.ts b/packages/swap/src/providers/oneInch/types.ts index 469b575a4..3984f0ee6 100644 --- a/packages/swap/src/providers/oneInch/types.ts +++ b/packages/swap/src/providers/oneInch/types.ts @@ -3,8 +3,7 @@ import { BN, EVMTransaction } from "../../types"; export interface OneInchResponseType { error?: string; description?: string; - toTokenAmount: string; - fromTokenAmount: string; + toAmount: string; tx: { from: string; to: string; diff --git a/packages/swap/src/types/index.ts b/packages/swap/src/types/index.ts index dac55969e..6ce99df8a 100644 --- a/packages/swap/src/types/index.ts +++ b/packages/swap/src/types/index.ts @@ -24,6 +24,7 @@ export enum SupportedNetworkName { Fantom = NetworkNames.Fantom, Klaytn = NetworkNames.Klaytn, Aurora = NetworkNames.Aurora, + Zksync = NetworkNames.ZkSync, } // eslint-disable-next-line no-shadow From b8143c59ebbe0f7c28242241b3b2f3da9de79376 Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Thu, 20 Jul 2023 16:57:36 -0700 Subject: [PATCH 07/23] feat: add base network --- .../src/libs/nft-handlers/simplehash.ts | 1 + .../providers/etherscan/configs.ts | 1 + .../src/providers/ethereum/networks/base.ts | 28 +++++++++++++++++++ .../src/providers/ethereum/networks/index.ts | 2 ++ packages/types/src/networks.ts | 2 ++ 5 files changed, 34 insertions(+) create mode 100644 packages/extension/src/providers/ethereum/networks/base.ts diff --git a/packages/extension/src/libs/nft-handlers/simplehash.ts b/packages/extension/src/libs/nft-handlers/simplehash.ts index 9bed13237..f472121bb 100644 --- a/packages/extension/src/libs/nft-handlers/simplehash.ts +++ b/packages/extension/src/libs/nft-handlers/simplehash.ts @@ -19,6 +19,7 @@ export default async ( [NetworkNames.ZkSync]: "zksync-era", [NetworkNames.ZkSyncGoerli]: "zksync-era-testnet", [NetworkNames.Goerli]: "ethereum-goerli", + [NetworkNames.Base]: "base", }; if (!Object.keys(supportedNetworks).includes(network.name)) throw new Error("Simplehash: network not supported"); diff --git a/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts b/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts index d2e0f1ed9..fdacb3bef 100644 --- a/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts +++ b/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts @@ -43,6 +43,7 @@ const NetworkEndpoints: Record = { [NetworkNames.Aurora]: "https://explorer.mainnet.aurora.dev/", [NetworkNames.PuppyNet]: "https://puppyscan.shib.io/", [NetworkNames.MaticZK]: "https://api-zkevm.polygonscan.com/", + [NetworkNames.Base]: "https://api.basescan.org/", }; export { NetworkEndpoints }; diff --git a/packages/extension/src/providers/ethereum/networks/base.ts b/packages/extension/src/providers/ethereum/networks/base.ts new file mode 100644 index 000000000..1ae332a0c --- /dev/null +++ b/packages/extension/src/providers/ethereum/networks/base.ts @@ -0,0 +1,28 @@ +import { CoingeckoPlatform, NetworkNames } from "@enkryptcom/types"; +import { EvmNetwork, EvmNetworkOptions } from "../types/evm-network"; +import shNFTHandler from "@/libs/nft-handlers/simplehash"; +import { EtherscanActivity } from "../libs/activity-handlers"; +import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler"; + +const ethOptions: EvmNetworkOptions = { + name: NetworkNames.Base, + name_long: "Base Mainnet", + homePage: "https://base.org", + blockExplorerTX: "https://basescan.org/tx/[[txHash]]", + blockExplorerAddr: "https://basescan.org/address/[[address]]", + chainID: "0x2105", + isTestNetwork: false, + currencyName: "ETH", + currencyNameLong: "Ethereum", + node: "wss://nodes.mewapi.io/ws/base", + icon: require("./icons/eth.svg"), + gradient: "linear-gradient(180deg, #C549FF 0%, #684CFF 100%)", + coingeckoID: "ethereum", + coingeckoPlatform: CoingeckoPlatform.Base, + NFTHandler: shNFTHandler, + activityHandler: wrapActivityHandler(EtherscanActivity), +}; + +const eth = new EvmNetwork(ethOptions); + +export default eth; diff --git a/packages/extension/src/providers/ethereum/networks/index.ts b/packages/extension/src/providers/ethereum/networks/index.ts index a9b7a19f1..13eadacba 100644 --- a/packages/extension/src/providers/ethereum/networks/index.ts +++ b/packages/extension/src/providers/ethereum/networks/index.ts @@ -27,6 +27,7 @@ import klayNode from "./klay"; import auroraNode from "./aurora"; import puppyNode from "./puppy"; import sepoliaNode from "./sepolia"; +import baseNode from "./base"; export default { goerli: goerliNode, @@ -67,4 +68,5 @@ export default { klaytn: klayNode, aurora: auroraNode, puppy: puppyNode, + base: baseNode, }; diff --git a/packages/types/src/networks.ts b/packages/types/src/networks.ts index 2006de4e5..349506d18 100644 --- a/packages/types/src/networks.ts +++ b/packages/types/src/networks.ts @@ -55,6 +55,7 @@ export enum NetworkNames { Pendulum = "pendulum", Amplitude = "amplitude", Vara = "VARA", + Base = "BASE", } export enum CoingeckoPlatform { @@ -91,4 +92,5 @@ export enum CoingeckoPlatform { Zksync = "zksync", Quartz = "quartz", Unique = "unique-network", + Base = "base", } From 2d73f14b27fb944f09a421cd0e7f141d48d4baab Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Thu, 20 Jul 2023 17:59:31 -0700 Subject: [PATCH 08/23] feat: add celo network and test network icons --- .../providers/etherscan/configs.ts | 1 + .../libs/assets-handlers/assetinfo-mew.ts | 4 + .../libs/assets-handlers/token-lists.ts | 1 + .../assets-handlers/types/tokenbalance-mew.ts | 1 + .../src/providers/ethereum/networks/base.ts | 10 +- .../src/providers/ethereum/networks/celo.ts | 28 + .../ethereum/networks/icons/base.svg | 531 ++++++++++++++++++ .../ethereum/networks/icons/celo.svg | 16 + .../providers/ethereum/networks/icons/eth.svg | 33 +- .../src/providers/ethereum/networks/index.ts | 2 + .../src/providers/ethereum/networks/matic.ts | 2 +- .../providers/ethereum/networks/maticzk.ts | 2 +- .../app-menu/components/app-menu-item.vue | 4 +- .../components/add-network-item.vue | 4 +- packages/types/src/networks.ts | 2 + 15 files changed, 604 insertions(+), 37 deletions(-) create mode 100644 packages/extension/src/providers/ethereum/networks/celo.ts create mode 100644 packages/extension/src/providers/ethereum/networks/icons/base.svg create mode 100644 packages/extension/src/providers/ethereum/networks/icons/celo.svg diff --git a/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts b/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts index fdacb3bef..ec3d6e760 100644 --- a/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts +++ b/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts @@ -44,6 +44,7 @@ const NetworkEndpoints: Record = { [NetworkNames.PuppyNet]: "https://puppyscan.shib.io/", [NetworkNames.MaticZK]: "https://api-zkevm.polygonscan.com/", [NetworkNames.Base]: "https://api.basescan.org/", + [NetworkNames.Celo]: "https://explorer.celo.org/mainnet/", }; export { NetworkEndpoints }; diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts index 161ed0e32..15520b763 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts @@ -103,6 +103,10 @@ const supportedNetworks: Record = { tbName: "pze", cgPlatform: CoingeckoPlatform.MaticZK, }, + [NetworkNames.Celo]: { + tbName: "celo", + cgPlatform: CoingeckoPlatform.Celo, + }, [NetworkNames.TomoChain]: { tbName: "", cgPlatform: CoingeckoPlatform.TomoChain, diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts index 36a61d11e..49da949bd 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts @@ -22,6 +22,7 @@ const TokenList: Record = { [NetworkNames.Fantom]: `https://tokens.coingecko.com/${CoingeckoPlatform.Fantom}/all.json`, [NetworkNames.Klaytn]: `https://tokens.coingecko.com/${CoingeckoPlatform.Klaytn}/all.json`, [NetworkNames.Aurora]: `https://tokens.coingecko.com/${CoingeckoPlatform.Aurora}/all.json`, + [NetworkNames.Celo]: `https://tokens.coingecko.com/${CoingeckoPlatform.Celo}/all.json`, [NetworkNames.TomoChain]: `https://tokens.coingecko.com/${CoingeckoPlatform.TomoChain}/all.json`, }; diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts index 12fc0e775..542e91097 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts @@ -45,4 +45,5 @@ export type SupportedNetworkNames = | NetworkNames.Aurora | NetworkNames.TomoChain | NetworkNames.MaticZK + | NetworkNames.Celo | NetworkNames.ZkSync; diff --git a/packages/extension/src/providers/ethereum/networks/base.ts b/packages/extension/src/providers/ethereum/networks/base.ts index 1ae332a0c..dbed46670 100644 --- a/packages/extension/src/providers/ethereum/networks/base.ts +++ b/packages/extension/src/providers/ethereum/networks/base.ts @@ -4,9 +4,9 @@ import shNFTHandler from "@/libs/nft-handlers/simplehash"; import { EtherscanActivity } from "../libs/activity-handlers"; import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler"; -const ethOptions: EvmNetworkOptions = { +const baseOptions: EvmNetworkOptions = { name: NetworkNames.Base, - name_long: "Base Mainnet", + name_long: "Base", homePage: "https://base.org", blockExplorerTX: "https://basescan.org/tx/[[txHash]]", blockExplorerAddr: "https://basescan.org/address/[[address]]", @@ -15,7 +15,7 @@ const ethOptions: EvmNetworkOptions = { currencyName: "ETH", currencyNameLong: "Ethereum", node: "wss://nodes.mewapi.io/ws/base", - icon: require("./icons/eth.svg"), + icon: require("./icons/base.svg"), gradient: "linear-gradient(180deg, #C549FF 0%, #684CFF 100%)", coingeckoID: "ethereum", coingeckoPlatform: CoingeckoPlatform.Base, @@ -23,6 +23,6 @@ const ethOptions: EvmNetworkOptions = { activityHandler: wrapActivityHandler(EtherscanActivity), }; -const eth = new EvmNetwork(ethOptions); +const base = new EvmNetwork(baseOptions); -export default eth; +export default base; diff --git a/packages/extension/src/providers/ethereum/networks/celo.ts b/packages/extension/src/providers/ethereum/networks/celo.ts new file mode 100644 index 000000000..81b62d73a --- /dev/null +++ b/packages/extension/src/providers/ethereum/networks/celo.ts @@ -0,0 +1,28 @@ +import { CoingeckoPlatform, NetworkNames } from "@enkryptcom/types"; +import { EvmNetwork, EvmNetworkOptions } from "../types/evm-network"; +import { EtherscanActivity } from "../libs/activity-handlers"; +import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler"; +import assetsInfoHandler from "@/providers/ethereum/libs/assets-handlers/assetinfo-mew"; + +const celoOptions: EvmNetworkOptions = { + name: NetworkNames.Celo, + name_long: "Celo", + homePage: "https://celo.org/", + blockExplorerTX: "https://explorer.celo.org/mainnet/tx/[[txHash]]", + blockExplorerAddr: "https://explorer.celo.org/mainnet/address/[[address]]", + chainID: "0xa4ec", + isTestNetwork: false, + currencyName: "CELO", + currencyNameLong: "Celo", + node: "https://forno.celo.org", + icon: require("./icons/celo.svg"), + gradient: "linear-gradient(180deg, #C549FF 0%, #684CFF 100%)", + coingeckoID: "celo", + coingeckoPlatform: CoingeckoPlatform.Celo, + assetsInfoHandler, + activityHandler: wrapActivityHandler(EtherscanActivity), +}; + +const celo = new EvmNetwork(celoOptions); + +export default celo; diff --git a/packages/extension/src/providers/ethereum/networks/icons/base.svg b/packages/extension/src/providers/ethereum/networks/icons/base.svg new file mode 100644 index 000000000..f9f6a5ca3 --- /dev/null +++ b/packages/extension/src/providers/ethereum/networks/icons/base.svg @@ -0,0 +1,531 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/extension/src/providers/ethereum/networks/icons/celo.svg b/packages/extension/src/providers/ethereum/networks/icons/celo.svg new file mode 100644 index 000000000..4a06f6f73 --- /dev/null +++ b/packages/extension/src/providers/ethereum/networks/icons/celo.svg @@ -0,0 +1,16 @@ + + +Artboard 1 + + + + diff --git a/packages/extension/src/providers/ethereum/networks/icons/eth.svg b/packages/extension/src/providers/ethereum/networks/icons/eth.svg index 8202464ea..abfff247e 100644 --- a/packages/extension/src/providers/ethereum/networks/icons/eth.svg +++ b/packages/extension/src/providers/ethereum/networks/icons/eth.svg @@ -1,29 +1,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/packages/extension/src/providers/ethereum/networks/index.ts b/packages/extension/src/providers/ethereum/networks/index.ts index 13eadacba..18ddb41c0 100644 --- a/packages/extension/src/providers/ethereum/networks/index.ts +++ b/packages/extension/src/providers/ethereum/networks/index.ts @@ -28,6 +28,7 @@ import auroraNode from "./aurora"; import puppyNode from "./puppy"; import sepoliaNode from "./sepolia"; import baseNode from "./base"; +import celoNode from "./celo"; export default { goerli: goerliNode, @@ -69,4 +70,5 @@ export default { aurora: auroraNode, puppy: puppyNode, base: baseNode, + celo: celoNode, }; diff --git a/packages/extension/src/providers/ethereum/networks/matic.ts b/packages/extension/src/providers/ethereum/networks/matic.ts index b5b9e8858..3586f3014 100644 --- a/packages/extension/src/providers/ethereum/networks/matic.ts +++ b/packages/extension/src/providers/ethereum/networks/matic.ts @@ -7,7 +7,7 @@ import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler"; const maticOptions: EvmNetworkOptions = { name: NetworkNames.Matic, - name_long: "Polygon (Matic)", + name_long: "Polygon", homePage: "https://polygonscan.com/", blockExplorerTX: "https://polygonscan.com/tx/[[txHash]]", blockExplorerAddr: "https://polygonscan.com/address/[[address]]", diff --git a/packages/extension/src/providers/ethereum/networks/maticzk.ts b/packages/extension/src/providers/ethereum/networks/maticzk.ts index 6c6ba2bc4..87307555a 100644 --- a/packages/extension/src/providers/ethereum/networks/maticzk.ts +++ b/packages/extension/src/providers/ethereum/networks/maticzk.ts @@ -7,7 +7,7 @@ import shNFTHandler from "@/libs/nft-handlers/simplehash"; const maticOptions: EvmNetworkOptions = { name: NetworkNames.MaticZK, - name_long: "Polygon (Matic) | Zk EVM", + name_long: "Polygon | zkEVM", homePage: "https://zkevm.polygonscan.com/", blockExplorerTX: "https://zkevm.polygonscan.com/tx/[[txHash]]", blockExplorerAddr: "https://zkevm.polygonscan.com/address/[[address]]", diff --git a/packages/extension/src/ui/action/components/app-menu/components/app-menu-item.vue b/packages/extension/src/ui/action/components/app-menu/components/app-menu-item.vue index e22a2b2cd..b49298368 100644 --- a/packages/extension/src/ui/action/components/app-menu/components/app-menu-item.vue +++ b/packages/extension/src/ui/action/components/app-menu/components/app-menu-item.vue @@ -1,7 +1,8 @@ - {{ network.name_long }} + {{ network.name_long }}