@coin-voyage/crypto 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ import { HttpTransportConfig } from "viem";
1
2
  import type { Config, CreateConnectorFn } from "wagmi";
2
3
  import { type CoinbaseWalletParameters, type MetaMaskParameters, type WalletConnectParameters } from "wagmi/connectors";
3
4
  /**
@@ -27,6 +28,16 @@ export interface EVMConfiguration {
27
28
  * Load Wallet SDKs only if the wallet is the most recently connected wallet
28
29
  */
29
30
  lazy?: boolean;
31
+ /**
32
+ * RPC configuration per chain
33
+ * Key is chain ID, value is a single URL or an array of URLs
34
+ */
35
+ rpcConfig?: {
36
+ [chainId: number]: {
37
+ url?: string | undefined;
38
+ config?: HttpTransportConfig;
39
+ };
40
+ };
30
41
  }
31
42
  export interface DefaultWagmiConfigResult {
32
43
  config: Config;
@@ -1,5 +1,5 @@
1
1
  import { getValue } from "@coin-voyage/shared/common";
2
- import { createClient, http } from "viem";
2
+ import { fallback, http } from "viem";
3
3
  import { createConfig, injected } from "wagmi";
4
4
  import { safe, } from "wagmi/connectors";
5
5
  import { DEFAULT_CHAINS } from "../lib/config/chain";
@@ -7,7 +7,7 @@ import { createCoinbaseConnector } from "../lib/connectors/coinbase";
7
7
  import { createMetaMaskConnector } from "../lib/connectors/metaMask";
8
8
  import { createWalletConnectConnector } from "../lib/connectors/walletConnect";
9
9
  import { isWalletInstalled } from "../lib/utils/is-wallet-installed";
10
- import { extendConnector } from "./utils";
10
+ import { extendConnector, fallbackRPCUrls } from "./utils";
11
11
  export function createDefaultEVMConfig(props) {
12
12
  const connectors = [...(props?.connectors ?? [])];
13
13
  const anyWindow = typeof window !== "undefined" ? window : undefined;
@@ -57,9 +57,14 @@ export function createDefaultEVMConfig(props) {
57
57
  const config = createConfig({
58
58
  ...props?.additionalConfigOptions,
59
59
  chains: DEFAULT_CHAINS,
60
- client({ chain }) {
61
- return createClient({ chain, transport: http() });
62
- },
60
+ transports: Object.fromEntries(DEFAULT_CHAINS.map((chain) => {
61
+ const chainRpcConfig = props?.rpcConfig?.[chain.id];
62
+ let config = fallbackRPCUrls(chain.id).map((url) => http(url));
63
+ if (chainRpcConfig) {
64
+ config = [http(chainRpcConfig.url, chainRpcConfig.config), http()];
65
+ }
66
+ return [chain.id, fallback(config)];
67
+ })),
63
68
  connectors,
64
69
  multiInjectedProviderDiscovery,
65
70
  });
@@ -1,5 +1,8 @@
1
+ import { ChainId } from "@coin-voyage/shared/common";
1
2
  import type { Connector, CreateConnectorFn } from "wagmi";
2
- import type { CreateConnectorFnExtended } from "./types";
3
3
  import { BaseConnector } from "../types/base-connector";
4
+ import type { CreateConnectorFnExtended } from "./types";
5
+ export declare const ALCHEMY_KEY = "kikl1LthkvlPnpk8Y2eY3vqGSKVoRGFj";
4
6
  export declare const extendConnector: (connector: CreateConnectorFn, id: string, name: string) => CreateConnectorFnExtended;
5
7
  export declare const toBaseConnector: (connector: CreateConnectorFnExtended | Connector) => BaseConnector;
8
+ export declare const fallbackRPCUrls: (chainID: ChainId) => string[];
package/dist/evm/utils.js CHANGED
@@ -1,4 +1,6 @@
1
+ import { ChainId } from "@coin-voyage/shared/common";
1
2
  import { getWalletIcon } from "../assets/icons";
3
+ export const ALCHEMY_KEY = "kikl1LthkvlPnpk8Y2eY3vqGSKVoRGFj";
2
4
  export const extendConnector = (connector, id, name) => {
3
5
  const extendedConnector = connector;
4
6
  extendedConnector.id = id;
@@ -13,3 +15,26 @@ export const toBaseConnector = (connector) => {
13
15
  icon: getWalletIcon(connector.id) || connector.icon,
14
16
  };
15
17
  };
18
+ export const fallbackRPCUrls = (chainID) => {
19
+ switch (chainID) {
20
+ case ChainId.ARB:
21
+ return ["https://arbitrum.drpc.org", `https://arb-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`];
22
+ case ChainId.BASE: {
23
+ return ["https://base.drpc.org", `https://base-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`];
24
+ }
25
+ case ChainId.BSC: {
26
+ return ["https://bsc.drpc.org", `https://bnb-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`];
27
+ }
28
+ case ChainId.ETH: {
29
+ return ["https://mainnet.gateway.tenderly.co", `https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`];
30
+ }
31
+ case ChainId.OP: {
32
+ return ["https://optimism.drpc.org", `https://opt-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`];
33
+ }
34
+ case ChainId.POL: {
35
+ return ["https://polygon.drpc.org", `https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`];
36
+ }
37
+ default:
38
+ return [];
39
+ }
40
+ };
@@ -1,23 +1,4 @@
1
- import { defineChain } from "viem";
2
1
  import { arbitrum, base, bsc, mainnet, optimism, polygon } from "viem/chains";
3
- const stableTestnet = defineChain({
4
- id: 2201,
5
- name: "Stable Testnet",
6
- nativeCurrency: {
7
- decimals: 18,
8
- name: "Tether",
9
- symbol: "USDT",
10
- },
11
- rpcUrls: {
12
- default: {
13
- http: ["https://stable-jsonrpc.testnet.chain0.dev"],
14
- webSocket: ["wss://stable-ws.testnet.chain0.dev"],
15
- },
16
- },
17
- blockExplorers: {
18
- default: { name: "Explorer", url: "https://stable-explorer.testnet.chain0.dev" },
19
- },
20
- });
21
2
  export const DEFAULT_CHAINS = [
22
3
  mainnet,
23
4
  arbitrum,
@@ -25,5 +6,4 @@ export const DEFAULT_CHAINS = [
25
6
  bsc,
26
7
  optimism,
27
8
  polygon,
28
- stableTestnet,
29
9
  ];
@@ -1,4 +1,5 @@
1
1
  import { type Config, CreateConnectorFn } from "@bigmi/client";
2
+ import { HttpTransportConfig } from "@bigmi/core";
2
3
  /**
3
4
  * UTXO Configuration for Wallets and Connectors
4
5
  * Includes options for Bigmi-specific configurations
@@ -17,6 +18,14 @@ export interface UTXOConfiguration {
17
18
  * Load Wallet SDKs only if the wallet is the most recently connected wallet
18
19
  */
19
20
  lazy?: boolean;
21
+ /**
22
+ * RPC configuration per chain
23
+ * Key is chain ID, value is a single URL or an array of URLs
24
+ */
25
+ rpcConfig?: {
26
+ url?: string | undefined;
27
+ config?: HttpTransportConfig;
28
+ };
20
29
  }
21
30
  export interface DefaultBigmiConfigResult {
22
31
  config: Config;
@@ -1,5 +1,6 @@
1
1
  import { createConfig, leather, magicEden, okx, onekey, phantom, unisat, xverse, } from "@bigmi/client";
2
2
  import { bitcoin, createClient, http } from "@bigmi/core";
3
+ import { ALCHEMY_KEY } from "../evm/utils";
3
4
  export function createDefaultBigmiConfig(props = {
4
5
  additionalConfigOptions: { multiInjectedProviderDiscovery: false },
5
6
  }) {
@@ -17,7 +18,12 @@ export function createDefaultBigmiConfig(props = {
17
18
  chains: [bitcoin],
18
19
  connectors,
19
20
  client({ chain }) {
20
- return createClient({ chain, transport: http() });
21
+ const chainRpcConfig = props?.rpcConfig;
22
+ let config = [http(), http(`https://bitcoin-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`)];
23
+ if (chainRpcConfig) {
24
+ config = [http(chainRpcConfig.url, chainRpcConfig.config), http()];
25
+ }
26
+ return createClient({ chain, transport: config[0] });
21
27
  },
22
28
  ...props?.additionalConfigOptions,
23
29
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coin-voyage/crypto",
3
3
  "description": "Crypto utilities for Coin Voyage",
4
- "version": "2.2.0",
4
+ "version": "2.2.1",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "author": "Lars <lars@coinvoyage.io>",