@b3dotfun/sdk 0.0.89-alpha.2 → 0.0.89-alpha.3
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.
- package/dist/cjs/anyspend/constants/rpc.d.ts +22 -0
- package/dist/cjs/anyspend/constants/rpc.js +38 -0
- package/dist/cjs/anyspend/utils/chain.d.ts +23 -0
- package/dist/cjs/anyspend/utils/chain.js +56 -12
- package/dist/cjs/global-account/react/hooks/useFirstEOA.d.ts +2 -2
- package/dist/esm/anyspend/constants/rpc.d.ts +22 -0
- package/dist/esm/anyspend/constants/rpc.js +35 -0
- package/dist/esm/anyspend/utils/chain.d.ts +23 -0
- package/dist/esm/anyspend/utils/chain.js +53 -12
- package/dist/esm/global-account/react/hooks/useFirstEOA.d.ts +2 -2
- package/dist/types/anyspend/constants/rpc.d.ts +22 -0
- package/dist/types/anyspend/utils/chain.d.ts +23 -0
- package/dist/types/global-account/react/hooks/useFirstEOA.d.ts +2 -2
- package/package.json +1 -1
- package/src/anyspend/constants/rpc.ts +38 -0
- package/src/anyspend/utils/chain.ts +70 -36
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public RPC endpoints for EVM chains.
|
|
3
|
+
* These are free, public endpoints that can be used without API keys.
|
|
4
|
+
*
|
|
5
|
+
* Sources:
|
|
6
|
+
* - https://publicnode.com
|
|
7
|
+
* - https://chainlist.org
|
|
8
|
+
*/
|
|
9
|
+
export declare const ETHEREUM_PUBLIC_RPC = "https://ethereum-rpc.publicnode.com";
|
|
10
|
+
export declare const ARBITRUM_PUBLIC_RPC = "https://arbitrum-one-rpc.publicnode.com";
|
|
11
|
+
export declare const BASE_PUBLIC_RPC = "https://base-rpc.publicnode.com";
|
|
12
|
+
export declare const OPTIMISM_PUBLIC_RPC = "https://optimism-rpc.publicnode.com";
|
|
13
|
+
export declare const POLYGON_PUBLIC_RPC = "https://polygon-bor-rpc.publicnode.com";
|
|
14
|
+
export declare const AVALANCHE_PUBLIC_RPC = "https://avalanche-c-chain-rpc.publicnode.com";
|
|
15
|
+
export declare const BSC_PUBLIC_RPC = "https://bsc-rpc.publicnode.com";
|
|
16
|
+
export declare const B3_PUBLIC_RPC = "https://mainnet-rpc.b3.fun/http";
|
|
17
|
+
export declare const ABSTRACT_PUBLIC_RPC = "https://api.mainnet.abs.xyz";
|
|
18
|
+
export declare const HYPEREVM_PUBLIC_RPC = "https://rpc.hyperliquid.xyz/evm";
|
|
19
|
+
/**
|
|
20
|
+
* Map of chain IDs to their default public RPC URLs.
|
|
21
|
+
*/
|
|
22
|
+
export declare const PUBLIC_RPC_URLS: Record<number, string>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Public RPC endpoints for EVM chains.
|
|
4
|
+
* These are free, public endpoints that can be used without API keys.
|
|
5
|
+
*
|
|
6
|
+
* Sources:
|
|
7
|
+
* - https://publicnode.com
|
|
8
|
+
* - https://chainlist.org
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.PUBLIC_RPC_URLS = exports.HYPEREVM_PUBLIC_RPC = exports.ABSTRACT_PUBLIC_RPC = exports.B3_PUBLIC_RPC = exports.BSC_PUBLIC_RPC = exports.AVALANCHE_PUBLIC_RPC = exports.POLYGON_PUBLIC_RPC = exports.OPTIMISM_PUBLIC_RPC = exports.BASE_PUBLIC_RPC = exports.ARBITRUM_PUBLIC_RPC = exports.ETHEREUM_PUBLIC_RPC = void 0;
|
|
12
|
+
// PublicNode endpoints
|
|
13
|
+
exports.ETHEREUM_PUBLIC_RPC = "https://ethereum-rpc.publicnode.com";
|
|
14
|
+
exports.ARBITRUM_PUBLIC_RPC = "https://arbitrum-one-rpc.publicnode.com";
|
|
15
|
+
exports.BASE_PUBLIC_RPC = "https://base-rpc.publicnode.com";
|
|
16
|
+
exports.OPTIMISM_PUBLIC_RPC = "https://optimism-rpc.publicnode.com";
|
|
17
|
+
exports.POLYGON_PUBLIC_RPC = "https://polygon-bor-rpc.publicnode.com";
|
|
18
|
+
exports.AVALANCHE_PUBLIC_RPC = "https://avalanche-c-chain-rpc.publicnode.com";
|
|
19
|
+
exports.BSC_PUBLIC_RPC = "https://bsc-rpc.publicnode.com";
|
|
20
|
+
// Chain-specific public endpoints
|
|
21
|
+
exports.B3_PUBLIC_RPC = "https://mainnet-rpc.b3.fun/http";
|
|
22
|
+
exports.ABSTRACT_PUBLIC_RPC = "https://api.mainnet.abs.xyz";
|
|
23
|
+
exports.HYPEREVM_PUBLIC_RPC = "https://rpc.hyperliquid.xyz/evm";
|
|
24
|
+
/**
|
|
25
|
+
* Map of chain IDs to their default public RPC URLs.
|
|
26
|
+
*/
|
|
27
|
+
exports.PUBLIC_RPC_URLS = {
|
|
28
|
+
1: exports.ETHEREUM_PUBLIC_RPC, // Ethereum Mainnet
|
|
29
|
+
42161: exports.ARBITRUM_PUBLIC_RPC, // Arbitrum One
|
|
30
|
+
8453: exports.BASE_PUBLIC_RPC, // Base
|
|
31
|
+
10: exports.OPTIMISM_PUBLIC_RPC, // Optimism
|
|
32
|
+
137: exports.POLYGON_PUBLIC_RPC, // Polygon
|
|
33
|
+
43114: exports.AVALANCHE_PUBLIC_RPC, // Avalanche C-Chain
|
|
34
|
+
56: exports.BSC_PUBLIC_RPC, // BNB Smart Chain
|
|
35
|
+
8333: exports.B3_PUBLIC_RPC, // B3
|
|
36
|
+
2741: exports.ABSTRACT_PUBLIC_RPC, // Abstract
|
|
37
|
+
999: exports.HYPEREVM_PUBLIC_RPC, // HyperEVM
|
|
38
|
+
};
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
import { components } from "../../anyspend/types/api";
|
|
2
2
|
import { Account, Chain, PublicClient, Transport, WalletClient } from "viem";
|
|
3
3
|
import { ChainType, IBaseChain, IEVMChain, IHyperliquidChain, ISolanaChain } from "../types/chain";
|
|
4
|
+
/**
|
|
5
|
+
* Set custom RPC URL overrides for specific chains.
|
|
6
|
+
* These overrides are used by chainIdToPublicClient and chainIdToWalletClient.
|
|
7
|
+
*
|
|
8
|
+
* @param overrides - A record mapping chain IDs to custom RPC URLs
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Set once at app initialization using environment variables
|
|
12
|
+
* setChainRpcOverrides({
|
|
13
|
+
* 1: process.env.ETHEREUM_RPC_URL,
|
|
14
|
+
* 8453: process.env.BASE_RPC_URL,
|
|
15
|
+
* 42161: process.env.ARBITRUM_RPC_URL,
|
|
16
|
+
* });
|
|
17
|
+
*/
|
|
18
|
+
export declare function setChainRpcOverrides(overrides: Record<number, string>): void;
|
|
19
|
+
/**
|
|
20
|
+
* Get the current RPC URL overrides.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getChainRpcOverrides(): Record<number, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Clear all RPC URL overrides.
|
|
25
|
+
*/
|
|
26
|
+
export declare function clearChainRpcOverrides(): void;
|
|
4
27
|
export declare const hyperEVM: {
|
|
5
28
|
blockExplorers: {
|
|
6
29
|
readonly default: {
|
|
@@ -4,6 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ALL_CHAINS = exports.HYPERLIQUID_CHAINS = exports.SOLANA_CHAINS = exports.EVM_CHAINS = exports.HYPERLIQUID_MAINNET = exports.SOLANA_MAINNET = exports.EVM_TESTNET = exports.EVM_MAINNET = exports.hyperEVM = void 0;
|
|
7
|
+
exports.setChainRpcOverrides = setChainRpcOverrides;
|
|
8
|
+
exports.getChainRpcOverrides = getChainRpcOverrides;
|
|
9
|
+
exports.clearChainRpcOverrides = clearChainRpcOverrides;
|
|
7
10
|
exports.getSolanaChains = getSolanaChains;
|
|
8
11
|
exports.getAllEvmChains = getAllEvmChains;
|
|
9
12
|
exports.getChainType = getChainType;
|
|
@@ -26,6 +29,7 @@ exports.isHyperliquidChain = isHyperliquidChain;
|
|
|
26
29
|
exports.getHyperliquidChain = getHyperliquidChain;
|
|
27
30
|
exports.getAvailableChainIds = getAvailableChainIds;
|
|
28
31
|
const constants_1 = require("../../anyspend/constants");
|
|
32
|
+
const rpc_1 = require("../../anyspend/constants/rpc");
|
|
29
33
|
const invariant_1 = __importDefault(require("invariant"));
|
|
30
34
|
const viem_1 = require("viem");
|
|
31
35
|
const chains_1 = require("viem/chains");
|
|
@@ -34,11 +38,45 @@ const token_1 = require("./token");
|
|
|
34
38
|
function getCustomEvmChain(chain, rpcUrl) {
|
|
35
39
|
return (0, viem_1.defineChain)({ ...chain, rpcUrls: { default: { http: [rpcUrl] } } });
|
|
36
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Global RPC URL overrides for EVM chains.
|
|
43
|
+
* Use setChainRpcOverrides() to configure custom RPC endpoints.
|
|
44
|
+
*/
|
|
45
|
+
let chainRpcOverrides = {};
|
|
46
|
+
/**
|
|
47
|
+
* Set custom RPC URL overrides for specific chains.
|
|
48
|
+
* These overrides are used by chainIdToPublicClient and chainIdToWalletClient.
|
|
49
|
+
*
|
|
50
|
+
* @param overrides - A record mapping chain IDs to custom RPC URLs
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* // Set once at app initialization using environment variables
|
|
54
|
+
* setChainRpcOverrides({
|
|
55
|
+
* 1: process.env.ETHEREUM_RPC_URL,
|
|
56
|
+
* 8453: process.env.BASE_RPC_URL,
|
|
57
|
+
* 42161: process.env.ARBITRUM_RPC_URL,
|
|
58
|
+
* });
|
|
59
|
+
*/
|
|
60
|
+
function setChainRpcOverrides(overrides) {
|
|
61
|
+
chainRpcOverrides = { ...overrides };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get the current RPC URL overrides.
|
|
65
|
+
*/
|
|
66
|
+
function getChainRpcOverrides() {
|
|
67
|
+
return { ...chainRpcOverrides };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Clear all RPC URL overrides.
|
|
71
|
+
*/
|
|
72
|
+
function clearChainRpcOverrides() {
|
|
73
|
+
chainRpcOverrides = {};
|
|
74
|
+
}
|
|
37
75
|
exports.hyperEVM = (0, viem_1.defineChain)({
|
|
38
76
|
id: token_1.HYPEREVM_CHAIN_ID,
|
|
39
77
|
name: "HyperEVM",
|
|
40
78
|
nativeCurrency: { name: "HyperEVM", symbol: "HYPE", decimals: 18 },
|
|
41
|
-
rpcUrls: { default: { http: [
|
|
79
|
+
rpcUrls: { default: { http: [rpc_1.HYPEREVM_PUBLIC_RPC] } },
|
|
42
80
|
blockExplorers: { default: { name: "HyperEVM Explorer", url: "https://hyperevmscan.io/" } },
|
|
43
81
|
});
|
|
44
82
|
// export const b4testnet = defineChain({
|
|
@@ -58,7 +96,7 @@ exports.EVM_MAINNET = {
|
|
|
58
96
|
canDepositNative: true,
|
|
59
97
|
defaultToken: (0, token_1.getEthToken)(chains_1.mainnet.id),
|
|
60
98
|
nativeToken: (0, token_1.getEthToken)(chains_1.mainnet.id),
|
|
61
|
-
viem: getCustomEvmChain(chains_1.mainnet,
|
|
99
|
+
viem: getCustomEvmChain(chains_1.mainnet, rpc_1.ETHEREUM_PUBLIC_RPC),
|
|
62
100
|
pollingInterval: 4000, // 4 seconds for Ethereum mainnet
|
|
63
101
|
zapperEnum: "ETHEREUM_MAINNET",
|
|
64
102
|
coingeckoName: "eth",
|
|
@@ -73,7 +111,7 @@ exports.EVM_MAINNET = {
|
|
|
73
111
|
canDepositNative: true,
|
|
74
112
|
defaultToken: (0, token_1.getEthToken)(chains_1.arbitrum.id),
|
|
75
113
|
nativeToken: (0, token_1.getEthToken)(chains_1.arbitrum.id),
|
|
76
|
-
viem: getCustomEvmChain(chains_1.arbitrum,
|
|
114
|
+
viem: getCustomEvmChain(chains_1.arbitrum, rpc_1.ARBITRUM_PUBLIC_RPC),
|
|
77
115
|
pollingInterval: 500, // 500ms for Arbitrum's fast blocks
|
|
78
116
|
zapperEnum: "ARBITRUM_MAINNET",
|
|
79
117
|
coingeckoName: "arbitrum",
|
|
@@ -88,7 +126,7 @@ exports.EVM_MAINNET = {
|
|
|
88
126
|
canDepositNative: true,
|
|
89
127
|
defaultToken: (0, token_1.getEthToken)(chains_1.base.id),
|
|
90
128
|
nativeToken: (0, token_1.getEthToken)(chains_1.base.id),
|
|
91
|
-
viem: getCustomEvmChain(chains_1.base,
|
|
129
|
+
viem: getCustomEvmChain(chains_1.base, rpc_1.BASE_PUBLIC_RPC),
|
|
92
130
|
pollingInterval: 1000, // 1 second for Base
|
|
93
131
|
zapperEnum: "BASE_MAINNET",
|
|
94
132
|
coingeckoName: "base",
|
|
@@ -103,7 +141,7 @@ exports.EVM_MAINNET = {
|
|
|
103
141
|
canDepositNative: true,
|
|
104
142
|
defaultToken: (0, token_1.getEthToken)(chains_1.optimism.id),
|
|
105
143
|
nativeToken: (0, token_1.getEthToken)(chains_1.optimism.id),
|
|
106
|
-
viem: getCustomEvmChain(chains_1.optimism,
|
|
144
|
+
viem: getCustomEvmChain(chains_1.optimism, rpc_1.OPTIMISM_PUBLIC_RPC),
|
|
107
145
|
pollingInterval: 1000, // 1 second for Optimism
|
|
108
146
|
zapperEnum: "OPTIMISM_MAINNET",
|
|
109
147
|
coingeckoName: "optimism",
|
|
@@ -118,7 +156,7 @@ exports.EVM_MAINNET = {
|
|
|
118
156
|
canDepositNative: true,
|
|
119
157
|
defaultToken: (0, token_1.getPolToken)(),
|
|
120
158
|
nativeToken: (0, token_1.getPolToken)(),
|
|
121
|
-
viem: getCustomEvmChain(chains_1.polygon,
|
|
159
|
+
viem: getCustomEvmChain(chains_1.polygon, rpc_1.POLYGON_PUBLIC_RPC),
|
|
122
160
|
pollingInterval: 1000, // 1 second for Polygon
|
|
123
161
|
zapperEnum: "POLYGON_MAINNET",
|
|
124
162
|
coingeckoName: "polygon_pos",
|
|
@@ -133,7 +171,7 @@ exports.EVM_MAINNET = {
|
|
|
133
171
|
canDepositNative: true,
|
|
134
172
|
defaultToken: (0, token_1.getAvaxToken)(),
|
|
135
173
|
nativeToken: (0, token_1.getAvaxToken)(),
|
|
136
|
-
viem: getCustomEvmChain(chains_1.avalanche,
|
|
174
|
+
viem: getCustomEvmChain(chains_1.avalanche, rpc_1.AVALANCHE_PUBLIC_RPC),
|
|
137
175
|
pollingInterval: 1000, // 1 second for Avalanche
|
|
138
176
|
zapperEnum: "AVALANCHE_MAINNET",
|
|
139
177
|
coingeckoName: "avax",
|
|
@@ -148,7 +186,7 @@ exports.EVM_MAINNET = {
|
|
|
148
186
|
canDepositNative: true,
|
|
149
187
|
defaultToken: (0, token_1.getBnbToken)(),
|
|
150
188
|
nativeToken: (0, token_1.getBnbToken)(),
|
|
151
|
-
viem: getCustomEvmChain(chains_1.bsc,
|
|
189
|
+
viem: getCustomEvmChain(chains_1.bsc, rpc_1.BSC_PUBLIC_RPC),
|
|
152
190
|
pollingInterval: 1000, // 1 second for BSC
|
|
153
191
|
zapperEnum: "BSC_MAINNET",
|
|
154
192
|
coingeckoName: "bsc",
|
|
@@ -163,7 +201,7 @@ exports.EVM_MAINNET = {
|
|
|
163
201
|
canDepositNative: true,
|
|
164
202
|
defaultToken: (0, token_1.getEthToken)(chains_1.b3.id),
|
|
165
203
|
nativeToken: (0, token_1.getEthToken)(chains_1.b3.id),
|
|
166
|
-
viem: getCustomEvmChain(chains_1.b3,
|
|
204
|
+
viem: getCustomEvmChain(chains_1.b3, rpc_1.B3_PUBLIC_RPC),
|
|
167
205
|
pollingInterval: 1000, // 1 second for B3
|
|
168
206
|
zapperEnum: "B3_MAINNET",
|
|
169
207
|
coingeckoName: "b3",
|
|
@@ -178,7 +216,7 @@ exports.EVM_MAINNET = {
|
|
|
178
216
|
canDepositNative: true,
|
|
179
217
|
defaultToken: (0, token_1.getEthToken)(chains_1.abstract.id),
|
|
180
218
|
nativeToken: (0, token_1.getEthToken)(chains_1.abstract.id),
|
|
181
|
-
viem: getCustomEvmChain(chains_1.abstract,
|
|
219
|
+
viem: getCustomEvmChain(chains_1.abstract, rpc_1.ABSTRACT_PUBLIC_RPC),
|
|
182
220
|
pollingInterval: 3000, // 3 seconds for Abstract
|
|
183
221
|
zapperEnum: "ABSTRACT_MAINNET",
|
|
184
222
|
coingeckoName: "abstract",
|
|
@@ -293,16 +331,22 @@ function getChainType(chainId) {
|
|
|
293
331
|
}
|
|
294
332
|
function chainIdToPublicClient(chainId) {
|
|
295
333
|
(0, invariant_1.default)(exports.EVM_CHAINS[chainId], `Chain ${chainId} is not an EVM chain`);
|
|
334
|
+
// Use override RPC if configured, otherwise use the default chain RPC
|
|
335
|
+
const rpcOverride = chainRpcOverrides[chainId];
|
|
336
|
+
const chain = rpcOverride ? getCustomEvmChain(exports.EVM_CHAINS[chainId].viem, rpcOverride) : exports.EVM_CHAINS[chainId].viem;
|
|
296
337
|
return (0, viem_1.createPublicClient)({
|
|
297
|
-
chain
|
|
338
|
+
chain,
|
|
298
339
|
transport: (0, viem_1.http)(),
|
|
299
340
|
pollingInterval: exports.EVM_CHAINS[chainId].pollingInterval,
|
|
300
341
|
});
|
|
301
342
|
}
|
|
302
343
|
function chainIdToWalletClient(chainId, account) {
|
|
303
344
|
(0, invariant_1.default)(exports.EVM_CHAINS[chainId], `Chain ${chainId} is not an EVM chain`);
|
|
345
|
+
// Use override RPC if configured, otherwise use the default chain RPC
|
|
346
|
+
const rpcOverride = chainRpcOverrides[chainId];
|
|
347
|
+
const chain = rpcOverride ? getCustomEvmChain(exports.EVM_CHAINS[chainId].viem, rpcOverride) : exports.EVM_CHAINS[chainId].viem;
|
|
304
348
|
return (0, viem_1.createWalletClient)({
|
|
305
|
-
chain
|
|
349
|
+
chain,
|
|
306
350
|
transport: (0, viem_1.http)(),
|
|
307
351
|
account,
|
|
308
352
|
pollingInterval: exports.EVM_CHAINS[chainId].pollingInterval,
|
|
@@ -7455,12 +7455,12 @@ export declare function useFirstEOA(chain?: {
|
|
|
7455
7455
|
[x: `bytes6[${string}]`]: undefined;
|
|
7456
7456
|
[x: `bytes9[${string}]`]: undefined;
|
|
7457
7457
|
[x: `bytes8[${string}]`]: undefined;
|
|
7458
|
+
[x: `bytes10[${string}]`]: undefined;
|
|
7458
7459
|
[x: `bytes2[${string}]`]: undefined;
|
|
7459
7460
|
[x: `bytes3[${string}]`]: undefined;
|
|
7460
7461
|
[x: `bytes4[${string}]`]: undefined;
|
|
7461
7462
|
[x: `bytes5[${string}]`]: undefined;
|
|
7462
7463
|
[x: `bytes7[${string}]`]: undefined;
|
|
7463
|
-
[x: `bytes10[${string}]`]: undefined;
|
|
7464
7464
|
[x: `bytes11[${string}]`]: undefined;
|
|
7465
7465
|
[x: `bytes12[${string}]`]: undefined;
|
|
7466
7466
|
[x: `bytes13[${string}]`]: undefined;
|
|
@@ -7557,12 +7557,12 @@ export declare function useFirstEOA(chain?: {
|
|
|
7557
7557
|
bytes6?: undefined;
|
|
7558
7558
|
bytes9?: undefined;
|
|
7559
7559
|
bytes8?: undefined;
|
|
7560
|
+
bytes10?: undefined;
|
|
7560
7561
|
bytes2?: undefined;
|
|
7561
7562
|
bytes3?: undefined;
|
|
7562
7563
|
bytes4?: undefined;
|
|
7563
7564
|
bytes5?: undefined;
|
|
7564
7565
|
bytes7?: undefined;
|
|
7565
|
-
bytes10?: undefined;
|
|
7566
7566
|
bytes11?: undefined;
|
|
7567
7567
|
bytes12?: undefined;
|
|
7568
7568
|
bytes13?: undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public RPC endpoints for EVM chains.
|
|
3
|
+
* These are free, public endpoints that can be used without API keys.
|
|
4
|
+
*
|
|
5
|
+
* Sources:
|
|
6
|
+
* - https://publicnode.com
|
|
7
|
+
* - https://chainlist.org
|
|
8
|
+
*/
|
|
9
|
+
export declare const ETHEREUM_PUBLIC_RPC = "https://ethereum-rpc.publicnode.com";
|
|
10
|
+
export declare const ARBITRUM_PUBLIC_RPC = "https://arbitrum-one-rpc.publicnode.com";
|
|
11
|
+
export declare const BASE_PUBLIC_RPC = "https://base-rpc.publicnode.com";
|
|
12
|
+
export declare const OPTIMISM_PUBLIC_RPC = "https://optimism-rpc.publicnode.com";
|
|
13
|
+
export declare const POLYGON_PUBLIC_RPC = "https://polygon-bor-rpc.publicnode.com";
|
|
14
|
+
export declare const AVALANCHE_PUBLIC_RPC = "https://avalanche-c-chain-rpc.publicnode.com";
|
|
15
|
+
export declare const BSC_PUBLIC_RPC = "https://bsc-rpc.publicnode.com";
|
|
16
|
+
export declare const B3_PUBLIC_RPC = "https://mainnet-rpc.b3.fun/http";
|
|
17
|
+
export declare const ABSTRACT_PUBLIC_RPC = "https://api.mainnet.abs.xyz";
|
|
18
|
+
export declare const HYPEREVM_PUBLIC_RPC = "https://rpc.hyperliquid.xyz/evm";
|
|
19
|
+
/**
|
|
20
|
+
* Map of chain IDs to their default public RPC URLs.
|
|
21
|
+
*/
|
|
22
|
+
export declare const PUBLIC_RPC_URLS: Record<number, string>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public RPC endpoints for EVM chains.
|
|
3
|
+
* These are free, public endpoints that can be used without API keys.
|
|
4
|
+
*
|
|
5
|
+
* Sources:
|
|
6
|
+
* - https://publicnode.com
|
|
7
|
+
* - https://chainlist.org
|
|
8
|
+
*/
|
|
9
|
+
// PublicNode endpoints
|
|
10
|
+
export const ETHEREUM_PUBLIC_RPC = "https://ethereum-rpc.publicnode.com";
|
|
11
|
+
export const ARBITRUM_PUBLIC_RPC = "https://arbitrum-one-rpc.publicnode.com";
|
|
12
|
+
export const BASE_PUBLIC_RPC = "https://base-rpc.publicnode.com";
|
|
13
|
+
export const OPTIMISM_PUBLIC_RPC = "https://optimism-rpc.publicnode.com";
|
|
14
|
+
export const POLYGON_PUBLIC_RPC = "https://polygon-bor-rpc.publicnode.com";
|
|
15
|
+
export const AVALANCHE_PUBLIC_RPC = "https://avalanche-c-chain-rpc.publicnode.com";
|
|
16
|
+
export const BSC_PUBLIC_RPC = "https://bsc-rpc.publicnode.com";
|
|
17
|
+
// Chain-specific public endpoints
|
|
18
|
+
export const B3_PUBLIC_RPC = "https://mainnet-rpc.b3.fun/http";
|
|
19
|
+
export const ABSTRACT_PUBLIC_RPC = "https://api.mainnet.abs.xyz";
|
|
20
|
+
export const HYPEREVM_PUBLIC_RPC = "https://rpc.hyperliquid.xyz/evm";
|
|
21
|
+
/**
|
|
22
|
+
* Map of chain IDs to their default public RPC URLs.
|
|
23
|
+
*/
|
|
24
|
+
export const PUBLIC_RPC_URLS = {
|
|
25
|
+
1: ETHEREUM_PUBLIC_RPC, // Ethereum Mainnet
|
|
26
|
+
42161: ARBITRUM_PUBLIC_RPC, // Arbitrum One
|
|
27
|
+
8453: BASE_PUBLIC_RPC, // Base
|
|
28
|
+
10: OPTIMISM_PUBLIC_RPC, // Optimism
|
|
29
|
+
137: POLYGON_PUBLIC_RPC, // Polygon
|
|
30
|
+
43114: AVALANCHE_PUBLIC_RPC, // Avalanche C-Chain
|
|
31
|
+
56: BSC_PUBLIC_RPC, // BNB Smart Chain
|
|
32
|
+
8333: B3_PUBLIC_RPC, // B3
|
|
33
|
+
2741: ABSTRACT_PUBLIC_RPC, // Abstract
|
|
34
|
+
999: HYPEREVM_PUBLIC_RPC, // HyperEVM
|
|
35
|
+
};
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
import { components } from "../../anyspend/types/api";
|
|
2
2
|
import { Account, Chain, PublicClient, Transport, WalletClient } from "viem";
|
|
3
3
|
import { ChainType, IBaseChain, IEVMChain, IHyperliquidChain, ISolanaChain } from "../types/chain";
|
|
4
|
+
/**
|
|
5
|
+
* Set custom RPC URL overrides for specific chains.
|
|
6
|
+
* These overrides are used by chainIdToPublicClient and chainIdToWalletClient.
|
|
7
|
+
*
|
|
8
|
+
* @param overrides - A record mapping chain IDs to custom RPC URLs
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Set once at app initialization using environment variables
|
|
12
|
+
* setChainRpcOverrides({
|
|
13
|
+
* 1: process.env.ETHEREUM_RPC_URL,
|
|
14
|
+
* 8453: process.env.BASE_RPC_URL,
|
|
15
|
+
* 42161: process.env.ARBITRUM_RPC_URL,
|
|
16
|
+
* });
|
|
17
|
+
*/
|
|
18
|
+
export declare function setChainRpcOverrides(overrides: Record<number, string>): void;
|
|
19
|
+
/**
|
|
20
|
+
* Get the current RPC URL overrides.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getChainRpcOverrides(): Record<number, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Clear all RPC URL overrides.
|
|
25
|
+
*/
|
|
26
|
+
export declare function clearChainRpcOverrides(): void;
|
|
4
27
|
export declare const hyperEVM: {
|
|
5
28
|
blockExplorers: {
|
|
6
29
|
readonly default: {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RELAY_SOLANA_MAINNET_CHAIN_ID } from "../../anyspend/constants/index.js";
|
|
2
|
+
import { ABSTRACT_PUBLIC_RPC, ARBITRUM_PUBLIC_RPC, AVALANCHE_PUBLIC_RPC, B3_PUBLIC_RPC, BASE_PUBLIC_RPC, BSC_PUBLIC_RPC, ETHEREUM_PUBLIC_RPC, HYPEREVM_PUBLIC_RPC, OPTIMISM_PUBLIC_RPC, POLYGON_PUBLIC_RPC, } from "../../anyspend/constants/rpc.js";
|
|
2
3
|
import invariant from "invariant";
|
|
3
4
|
import { createPublicClient, createWalletClient, defineChain, http, parseEther, } from "viem";
|
|
4
5
|
import { abstract, arbitrum, avalanche, b3, base, bsc, mainnet, optimism, polygon } from "viem/chains";
|
|
@@ -7,11 +8,45 @@ import { getAvaxToken, getBnbToken, getEthToken, getHyperEVMNativeToken, getHype
|
|
|
7
8
|
function getCustomEvmChain(chain, rpcUrl) {
|
|
8
9
|
return defineChain({ ...chain, rpcUrls: { default: { http: [rpcUrl] } } });
|
|
9
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Global RPC URL overrides for EVM chains.
|
|
13
|
+
* Use setChainRpcOverrides() to configure custom RPC endpoints.
|
|
14
|
+
*/
|
|
15
|
+
let chainRpcOverrides = {};
|
|
16
|
+
/**
|
|
17
|
+
* Set custom RPC URL overrides for specific chains.
|
|
18
|
+
* These overrides are used by chainIdToPublicClient and chainIdToWalletClient.
|
|
19
|
+
*
|
|
20
|
+
* @param overrides - A record mapping chain IDs to custom RPC URLs
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Set once at app initialization using environment variables
|
|
24
|
+
* setChainRpcOverrides({
|
|
25
|
+
* 1: process.env.ETHEREUM_RPC_URL,
|
|
26
|
+
* 8453: process.env.BASE_RPC_URL,
|
|
27
|
+
* 42161: process.env.ARBITRUM_RPC_URL,
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
export function setChainRpcOverrides(overrides) {
|
|
31
|
+
chainRpcOverrides = { ...overrides };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get the current RPC URL overrides.
|
|
35
|
+
*/
|
|
36
|
+
export function getChainRpcOverrides() {
|
|
37
|
+
return { ...chainRpcOverrides };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Clear all RPC URL overrides.
|
|
41
|
+
*/
|
|
42
|
+
export function clearChainRpcOverrides() {
|
|
43
|
+
chainRpcOverrides = {};
|
|
44
|
+
}
|
|
10
45
|
export const hyperEVM = defineChain({
|
|
11
46
|
id: HYPEREVM_CHAIN_ID,
|
|
12
47
|
name: "HyperEVM",
|
|
13
48
|
nativeCurrency: { name: "HyperEVM", symbol: "HYPE", decimals: 18 },
|
|
14
|
-
rpcUrls: { default: { http: [
|
|
49
|
+
rpcUrls: { default: { http: [HYPEREVM_PUBLIC_RPC] } },
|
|
15
50
|
blockExplorers: { default: { name: "HyperEVM Explorer", url: "https://hyperevmscan.io/" } },
|
|
16
51
|
});
|
|
17
52
|
// export const b4testnet = defineChain({
|
|
@@ -31,7 +66,7 @@ export const EVM_MAINNET = {
|
|
|
31
66
|
canDepositNative: true,
|
|
32
67
|
defaultToken: getEthToken(mainnet.id),
|
|
33
68
|
nativeToken: getEthToken(mainnet.id),
|
|
34
|
-
viem: getCustomEvmChain(mainnet,
|
|
69
|
+
viem: getCustomEvmChain(mainnet, ETHEREUM_PUBLIC_RPC),
|
|
35
70
|
pollingInterval: 4000, // 4 seconds for Ethereum mainnet
|
|
36
71
|
zapperEnum: "ETHEREUM_MAINNET",
|
|
37
72
|
coingeckoName: "eth",
|
|
@@ -46,7 +81,7 @@ export const EVM_MAINNET = {
|
|
|
46
81
|
canDepositNative: true,
|
|
47
82
|
defaultToken: getEthToken(arbitrum.id),
|
|
48
83
|
nativeToken: getEthToken(arbitrum.id),
|
|
49
|
-
viem: getCustomEvmChain(arbitrum,
|
|
84
|
+
viem: getCustomEvmChain(arbitrum, ARBITRUM_PUBLIC_RPC),
|
|
50
85
|
pollingInterval: 500, // 500ms for Arbitrum's fast blocks
|
|
51
86
|
zapperEnum: "ARBITRUM_MAINNET",
|
|
52
87
|
coingeckoName: "arbitrum",
|
|
@@ -61,7 +96,7 @@ export const EVM_MAINNET = {
|
|
|
61
96
|
canDepositNative: true,
|
|
62
97
|
defaultToken: getEthToken(base.id),
|
|
63
98
|
nativeToken: getEthToken(base.id),
|
|
64
|
-
viem: getCustomEvmChain(base,
|
|
99
|
+
viem: getCustomEvmChain(base, BASE_PUBLIC_RPC),
|
|
65
100
|
pollingInterval: 1000, // 1 second for Base
|
|
66
101
|
zapperEnum: "BASE_MAINNET",
|
|
67
102
|
coingeckoName: "base",
|
|
@@ -76,7 +111,7 @@ export const EVM_MAINNET = {
|
|
|
76
111
|
canDepositNative: true,
|
|
77
112
|
defaultToken: getEthToken(optimism.id),
|
|
78
113
|
nativeToken: getEthToken(optimism.id),
|
|
79
|
-
viem: getCustomEvmChain(optimism,
|
|
114
|
+
viem: getCustomEvmChain(optimism, OPTIMISM_PUBLIC_RPC),
|
|
80
115
|
pollingInterval: 1000, // 1 second for Optimism
|
|
81
116
|
zapperEnum: "OPTIMISM_MAINNET",
|
|
82
117
|
coingeckoName: "optimism",
|
|
@@ -91,7 +126,7 @@ export const EVM_MAINNET = {
|
|
|
91
126
|
canDepositNative: true,
|
|
92
127
|
defaultToken: getPolToken(),
|
|
93
128
|
nativeToken: getPolToken(),
|
|
94
|
-
viem: getCustomEvmChain(polygon,
|
|
129
|
+
viem: getCustomEvmChain(polygon, POLYGON_PUBLIC_RPC),
|
|
95
130
|
pollingInterval: 1000, // 1 second for Polygon
|
|
96
131
|
zapperEnum: "POLYGON_MAINNET",
|
|
97
132
|
coingeckoName: "polygon_pos",
|
|
@@ -106,7 +141,7 @@ export const EVM_MAINNET = {
|
|
|
106
141
|
canDepositNative: true,
|
|
107
142
|
defaultToken: getAvaxToken(),
|
|
108
143
|
nativeToken: getAvaxToken(),
|
|
109
|
-
viem: getCustomEvmChain(avalanche,
|
|
144
|
+
viem: getCustomEvmChain(avalanche, AVALANCHE_PUBLIC_RPC),
|
|
110
145
|
pollingInterval: 1000, // 1 second for Avalanche
|
|
111
146
|
zapperEnum: "AVALANCHE_MAINNET",
|
|
112
147
|
coingeckoName: "avax",
|
|
@@ -121,7 +156,7 @@ export const EVM_MAINNET = {
|
|
|
121
156
|
canDepositNative: true,
|
|
122
157
|
defaultToken: getBnbToken(),
|
|
123
158
|
nativeToken: getBnbToken(),
|
|
124
|
-
viem: getCustomEvmChain(bsc,
|
|
159
|
+
viem: getCustomEvmChain(bsc, BSC_PUBLIC_RPC),
|
|
125
160
|
pollingInterval: 1000, // 1 second for BSC
|
|
126
161
|
zapperEnum: "BSC_MAINNET",
|
|
127
162
|
coingeckoName: "bsc",
|
|
@@ -136,7 +171,7 @@ export const EVM_MAINNET = {
|
|
|
136
171
|
canDepositNative: true,
|
|
137
172
|
defaultToken: getEthToken(b3.id),
|
|
138
173
|
nativeToken: getEthToken(b3.id),
|
|
139
|
-
viem: getCustomEvmChain(b3,
|
|
174
|
+
viem: getCustomEvmChain(b3, B3_PUBLIC_RPC),
|
|
140
175
|
pollingInterval: 1000, // 1 second for B3
|
|
141
176
|
zapperEnum: "B3_MAINNET",
|
|
142
177
|
coingeckoName: "b3",
|
|
@@ -151,7 +186,7 @@ export const EVM_MAINNET = {
|
|
|
151
186
|
canDepositNative: true,
|
|
152
187
|
defaultToken: getEthToken(abstract.id),
|
|
153
188
|
nativeToken: getEthToken(abstract.id),
|
|
154
|
-
viem: getCustomEvmChain(abstract,
|
|
189
|
+
viem: getCustomEvmChain(abstract, ABSTRACT_PUBLIC_RPC),
|
|
155
190
|
pollingInterval: 3000, // 3 seconds for Abstract
|
|
156
191
|
zapperEnum: "ABSTRACT_MAINNET",
|
|
157
192
|
coingeckoName: "abstract",
|
|
@@ -266,16 +301,22 @@ export function getChainType(chainId) {
|
|
|
266
301
|
}
|
|
267
302
|
export function chainIdToPublicClient(chainId) {
|
|
268
303
|
invariant(EVM_CHAINS[chainId], `Chain ${chainId} is not an EVM chain`);
|
|
304
|
+
// Use override RPC if configured, otherwise use the default chain RPC
|
|
305
|
+
const rpcOverride = chainRpcOverrides[chainId];
|
|
306
|
+
const chain = rpcOverride ? getCustomEvmChain(EVM_CHAINS[chainId].viem, rpcOverride) : EVM_CHAINS[chainId].viem;
|
|
269
307
|
return createPublicClient({
|
|
270
|
-
chain
|
|
308
|
+
chain,
|
|
271
309
|
transport: http(),
|
|
272
310
|
pollingInterval: EVM_CHAINS[chainId].pollingInterval,
|
|
273
311
|
});
|
|
274
312
|
}
|
|
275
313
|
export function chainIdToWalletClient(chainId, account) {
|
|
276
314
|
invariant(EVM_CHAINS[chainId], `Chain ${chainId} is not an EVM chain`);
|
|
315
|
+
// Use override RPC if configured, otherwise use the default chain RPC
|
|
316
|
+
const rpcOverride = chainRpcOverrides[chainId];
|
|
317
|
+
const chain = rpcOverride ? getCustomEvmChain(EVM_CHAINS[chainId].viem, rpcOverride) : EVM_CHAINS[chainId].viem;
|
|
277
318
|
return createWalletClient({
|
|
278
|
-
chain
|
|
319
|
+
chain,
|
|
279
320
|
transport: http(),
|
|
280
321
|
account,
|
|
281
322
|
pollingInterval: EVM_CHAINS[chainId].pollingInterval,
|
|
@@ -7455,12 +7455,12 @@ export declare function useFirstEOA(chain?: {
|
|
|
7455
7455
|
[x: `bytes6[${string}]`]: undefined;
|
|
7456
7456
|
[x: `bytes9[${string}]`]: undefined;
|
|
7457
7457
|
[x: `bytes8[${string}]`]: undefined;
|
|
7458
|
+
[x: `bytes10[${string}]`]: undefined;
|
|
7458
7459
|
[x: `bytes2[${string}]`]: undefined;
|
|
7459
7460
|
[x: `bytes3[${string}]`]: undefined;
|
|
7460
7461
|
[x: `bytes4[${string}]`]: undefined;
|
|
7461
7462
|
[x: `bytes5[${string}]`]: undefined;
|
|
7462
7463
|
[x: `bytes7[${string}]`]: undefined;
|
|
7463
|
-
[x: `bytes10[${string}]`]: undefined;
|
|
7464
7464
|
[x: `bytes11[${string}]`]: undefined;
|
|
7465
7465
|
[x: `bytes12[${string}]`]: undefined;
|
|
7466
7466
|
[x: `bytes13[${string}]`]: undefined;
|
|
@@ -7557,12 +7557,12 @@ export declare function useFirstEOA(chain?: {
|
|
|
7557
7557
|
bytes6?: undefined;
|
|
7558
7558
|
bytes9?: undefined;
|
|
7559
7559
|
bytes8?: undefined;
|
|
7560
|
+
bytes10?: undefined;
|
|
7560
7561
|
bytes2?: undefined;
|
|
7561
7562
|
bytes3?: undefined;
|
|
7562
7563
|
bytes4?: undefined;
|
|
7563
7564
|
bytes5?: undefined;
|
|
7564
7565
|
bytes7?: undefined;
|
|
7565
|
-
bytes10?: undefined;
|
|
7566
7566
|
bytes11?: undefined;
|
|
7567
7567
|
bytes12?: undefined;
|
|
7568
7568
|
bytes13?: undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public RPC endpoints for EVM chains.
|
|
3
|
+
* These are free, public endpoints that can be used without API keys.
|
|
4
|
+
*
|
|
5
|
+
* Sources:
|
|
6
|
+
* - https://publicnode.com
|
|
7
|
+
* - https://chainlist.org
|
|
8
|
+
*/
|
|
9
|
+
export declare const ETHEREUM_PUBLIC_RPC = "https://ethereum-rpc.publicnode.com";
|
|
10
|
+
export declare const ARBITRUM_PUBLIC_RPC = "https://arbitrum-one-rpc.publicnode.com";
|
|
11
|
+
export declare const BASE_PUBLIC_RPC = "https://base-rpc.publicnode.com";
|
|
12
|
+
export declare const OPTIMISM_PUBLIC_RPC = "https://optimism-rpc.publicnode.com";
|
|
13
|
+
export declare const POLYGON_PUBLIC_RPC = "https://polygon-bor-rpc.publicnode.com";
|
|
14
|
+
export declare const AVALANCHE_PUBLIC_RPC = "https://avalanche-c-chain-rpc.publicnode.com";
|
|
15
|
+
export declare const BSC_PUBLIC_RPC = "https://bsc-rpc.publicnode.com";
|
|
16
|
+
export declare const B3_PUBLIC_RPC = "https://mainnet-rpc.b3.fun/http";
|
|
17
|
+
export declare const ABSTRACT_PUBLIC_RPC = "https://api.mainnet.abs.xyz";
|
|
18
|
+
export declare const HYPEREVM_PUBLIC_RPC = "https://rpc.hyperliquid.xyz/evm";
|
|
19
|
+
/**
|
|
20
|
+
* Map of chain IDs to their default public RPC URLs.
|
|
21
|
+
*/
|
|
22
|
+
export declare const PUBLIC_RPC_URLS: Record<number, string>;
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
import { components } from "@b3dotfun/sdk/anyspend/types/api";
|
|
2
2
|
import { Account, Chain, PublicClient, Transport, WalletClient } from "viem";
|
|
3
3
|
import { ChainType, IBaseChain, IEVMChain, IHyperliquidChain, ISolanaChain } from "../types/chain";
|
|
4
|
+
/**
|
|
5
|
+
* Set custom RPC URL overrides for specific chains.
|
|
6
|
+
* These overrides are used by chainIdToPublicClient and chainIdToWalletClient.
|
|
7
|
+
*
|
|
8
|
+
* @param overrides - A record mapping chain IDs to custom RPC URLs
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Set once at app initialization using environment variables
|
|
12
|
+
* setChainRpcOverrides({
|
|
13
|
+
* 1: process.env.ETHEREUM_RPC_URL,
|
|
14
|
+
* 8453: process.env.BASE_RPC_URL,
|
|
15
|
+
* 42161: process.env.ARBITRUM_RPC_URL,
|
|
16
|
+
* });
|
|
17
|
+
*/
|
|
18
|
+
export declare function setChainRpcOverrides(overrides: Record<number, string>): void;
|
|
19
|
+
/**
|
|
20
|
+
* Get the current RPC URL overrides.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getChainRpcOverrides(): Record<number, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Clear all RPC URL overrides.
|
|
25
|
+
*/
|
|
26
|
+
export declare function clearChainRpcOverrides(): void;
|
|
4
27
|
export declare const hyperEVM: {
|
|
5
28
|
blockExplorers: {
|
|
6
29
|
readonly default: {
|
|
@@ -7455,12 +7455,12 @@ export declare function useFirstEOA(chain?: {
|
|
|
7455
7455
|
[x: `bytes6[${string}]`]: undefined;
|
|
7456
7456
|
[x: `bytes9[${string}]`]: undefined;
|
|
7457
7457
|
[x: `bytes8[${string}]`]: undefined;
|
|
7458
|
+
[x: `bytes10[${string}]`]: undefined;
|
|
7458
7459
|
[x: `bytes2[${string}]`]: undefined;
|
|
7459
7460
|
[x: `bytes3[${string}]`]: undefined;
|
|
7460
7461
|
[x: `bytes4[${string}]`]: undefined;
|
|
7461
7462
|
[x: `bytes5[${string}]`]: undefined;
|
|
7462
7463
|
[x: `bytes7[${string}]`]: undefined;
|
|
7463
|
-
[x: `bytes10[${string}]`]: undefined;
|
|
7464
7464
|
[x: `bytes11[${string}]`]: undefined;
|
|
7465
7465
|
[x: `bytes12[${string}]`]: undefined;
|
|
7466
7466
|
[x: `bytes13[${string}]`]: undefined;
|
|
@@ -7557,12 +7557,12 @@ export declare function useFirstEOA(chain?: {
|
|
|
7557
7557
|
bytes6?: undefined;
|
|
7558
7558
|
bytes9?: undefined;
|
|
7559
7559
|
bytes8?: undefined;
|
|
7560
|
+
bytes10?: undefined;
|
|
7560
7561
|
bytes2?: undefined;
|
|
7561
7562
|
bytes3?: undefined;
|
|
7562
7563
|
bytes4?: undefined;
|
|
7563
7564
|
bytes5?: undefined;
|
|
7564
7565
|
bytes7?: undefined;
|
|
7565
|
-
bytes10?: undefined;
|
|
7566
7566
|
bytes11?: undefined;
|
|
7567
7567
|
bytes12?: undefined;
|
|
7568
7568
|
bytes13?: undefined;
|
package/package.json
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public RPC endpoints for EVM chains.
|
|
3
|
+
* These are free, public endpoints that can be used without API keys.
|
|
4
|
+
*
|
|
5
|
+
* Sources:
|
|
6
|
+
* - https://publicnode.com
|
|
7
|
+
* - https://chainlist.org
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// PublicNode endpoints
|
|
11
|
+
export const ETHEREUM_PUBLIC_RPC = "https://ethereum-rpc.publicnode.com";
|
|
12
|
+
export const ARBITRUM_PUBLIC_RPC = "https://arbitrum-one-rpc.publicnode.com";
|
|
13
|
+
export const BASE_PUBLIC_RPC = "https://base-rpc.publicnode.com";
|
|
14
|
+
export const OPTIMISM_PUBLIC_RPC = "https://optimism-rpc.publicnode.com";
|
|
15
|
+
export const POLYGON_PUBLIC_RPC = "https://polygon-bor-rpc.publicnode.com";
|
|
16
|
+
export const AVALANCHE_PUBLIC_RPC = "https://avalanche-c-chain-rpc.publicnode.com";
|
|
17
|
+
export const BSC_PUBLIC_RPC = "https://bsc-rpc.publicnode.com";
|
|
18
|
+
|
|
19
|
+
// Chain-specific public endpoints
|
|
20
|
+
export const B3_PUBLIC_RPC = "https://mainnet-rpc.b3.fun/http";
|
|
21
|
+
export const ABSTRACT_PUBLIC_RPC = "https://api.mainnet.abs.xyz";
|
|
22
|
+
export const HYPEREVM_PUBLIC_RPC = "https://rpc.hyperliquid.xyz/evm";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Map of chain IDs to their default public RPC URLs.
|
|
26
|
+
*/
|
|
27
|
+
export const PUBLIC_RPC_URLS: Record<number, string> = {
|
|
28
|
+
1: ETHEREUM_PUBLIC_RPC, // Ethereum Mainnet
|
|
29
|
+
42161: ARBITRUM_PUBLIC_RPC, // Arbitrum One
|
|
30
|
+
8453: BASE_PUBLIC_RPC, // Base
|
|
31
|
+
10: OPTIMISM_PUBLIC_RPC, // Optimism
|
|
32
|
+
137: POLYGON_PUBLIC_RPC, // Polygon
|
|
33
|
+
43114: AVALANCHE_PUBLIC_RPC, // Avalanche C-Chain
|
|
34
|
+
56: BSC_PUBLIC_RPC, // BNB Smart Chain
|
|
35
|
+
8333: B3_PUBLIC_RPC, // B3
|
|
36
|
+
2741: ABSTRACT_PUBLIC_RPC, // Abstract
|
|
37
|
+
999: HYPEREVM_PUBLIC_RPC, // HyperEVM
|
|
38
|
+
};
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { RELAY_SOLANA_MAINNET_CHAIN_ID } from "@b3dotfun/sdk/anyspend/constants";
|
|
2
|
+
import {
|
|
3
|
+
ABSTRACT_PUBLIC_RPC,
|
|
4
|
+
ARBITRUM_PUBLIC_RPC,
|
|
5
|
+
AVALANCHE_PUBLIC_RPC,
|
|
6
|
+
B3_PUBLIC_RPC,
|
|
7
|
+
BASE_PUBLIC_RPC,
|
|
8
|
+
BSC_PUBLIC_RPC,
|
|
9
|
+
ETHEREUM_PUBLIC_RPC,
|
|
10
|
+
HYPEREVM_PUBLIC_RPC,
|
|
11
|
+
OPTIMISM_PUBLIC_RPC,
|
|
12
|
+
POLYGON_PUBLIC_RPC,
|
|
13
|
+
} from "@b3dotfun/sdk/anyspend/constants/rpc";
|
|
2
14
|
import { components } from "@b3dotfun/sdk/anyspend/types/api";
|
|
3
15
|
import invariant from "invariant";
|
|
4
16
|
import {
|
|
@@ -31,11 +43,49 @@ function getCustomEvmChain(chain: Chain, rpcUrl: string): Chain {
|
|
|
31
43
|
return defineChain({ ...chain, rpcUrls: { default: { http: [rpcUrl] } } });
|
|
32
44
|
}
|
|
33
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Global RPC URL overrides for EVM chains.
|
|
48
|
+
* Use setChainRpcOverrides() to configure custom RPC endpoints.
|
|
49
|
+
*/
|
|
50
|
+
let chainRpcOverrides: Record<number, string> = {};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Set custom RPC URL overrides for specific chains.
|
|
54
|
+
* These overrides are used by chainIdToPublicClient and chainIdToWalletClient.
|
|
55
|
+
*
|
|
56
|
+
* @param overrides - A record mapping chain IDs to custom RPC URLs
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* // Set once at app initialization using environment variables
|
|
60
|
+
* setChainRpcOverrides({
|
|
61
|
+
* 1: process.env.ETHEREUM_RPC_URL,
|
|
62
|
+
* 8453: process.env.BASE_RPC_URL,
|
|
63
|
+
* 42161: process.env.ARBITRUM_RPC_URL,
|
|
64
|
+
* });
|
|
65
|
+
*/
|
|
66
|
+
export function setChainRpcOverrides(overrides: Record<number, string>): void {
|
|
67
|
+
chainRpcOverrides = { ...overrides };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Get the current RPC URL overrides.
|
|
72
|
+
*/
|
|
73
|
+
export function getChainRpcOverrides(): Record<number, string> {
|
|
74
|
+
return { ...chainRpcOverrides };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Clear all RPC URL overrides.
|
|
79
|
+
*/
|
|
80
|
+
export function clearChainRpcOverrides(): void {
|
|
81
|
+
chainRpcOverrides = {};
|
|
82
|
+
}
|
|
83
|
+
|
|
34
84
|
export const hyperEVM = defineChain({
|
|
35
85
|
id: HYPEREVM_CHAIN_ID,
|
|
36
86
|
name: "HyperEVM",
|
|
37
87
|
nativeCurrency: { name: "HyperEVM", symbol: "HYPE", decimals: 18 },
|
|
38
|
-
rpcUrls: { default: { http: [
|
|
88
|
+
rpcUrls: { default: { http: [HYPEREVM_PUBLIC_RPC] } },
|
|
39
89
|
blockExplorers: { default: { name: "HyperEVM Explorer", url: "https://hyperevmscan.io/" } },
|
|
40
90
|
});
|
|
41
91
|
|
|
@@ -57,10 +107,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
|
|
|
57
107
|
canDepositNative: true,
|
|
58
108
|
defaultToken: getEthToken(mainnet.id),
|
|
59
109
|
nativeToken: getEthToken(mainnet.id),
|
|
60
|
-
viem: getCustomEvmChain(
|
|
61
|
-
mainnet,
|
|
62
|
-
"https://quick-chaotic-film.quiknode.pro/39a7aae6a7078f9f36c435e6f34c071c641cf863/",
|
|
63
|
-
),
|
|
110
|
+
viem: getCustomEvmChain(mainnet, ETHEREUM_PUBLIC_RPC),
|
|
64
111
|
pollingInterval: 4000, // 4 seconds for Ethereum mainnet
|
|
65
112
|
zapperEnum: "ETHEREUM_MAINNET",
|
|
66
113
|
coingeckoName: "eth",
|
|
@@ -75,10 +122,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
|
|
|
75
122
|
canDepositNative: true,
|
|
76
123
|
defaultToken: getEthToken(arbitrum.id),
|
|
77
124
|
nativeToken: getEthToken(arbitrum.id),
|
|
78
|
-
viem: getCustomEvmChain(
|
|
79
|
-
arbitrum,
|
|
80
|
-
"https://proportionate-twilight-patina.arbitrum-mainnet.quiknode.pro/60e4825626515233a0f566f5915601af6043127b/",
|
|
81
|
-
),
|
|
125
|
+
viem: getCustomEvmChain(arbitrum, ARBITRUM_PUBLIC_RPC),
|
|
82
126
|
pollingInterval: 500, // 500ms for Arbitrum's fast blocks
|
|
83
127
|
zapperEnum: "ARBITRUM_MAINNET",
|
|
84
128
|
coingeckoName: "arbitrum",
|
|
@@ -93,10 +137,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
|
|
|
93
137
|
canDepositNative: true,
|
|
94
138
|
defaultToken: getEthToken(base.id),
|
|
95
139
|
nativeToken: getEthToken(base.id),
|
|
96
|
-
viem: getCustomEvmChain(
|
|
97
|
-
base,
|
|
98
|
-
"https://sly-indulgent-bird.base-mainnet.quiknode.pro/4e31fab6845eb29a2764723a43896999fe962e48/",
|
|
99
|
-
),
|
|
140
|
+
viem: getCustomEvmChain(base, BASE_PUBLIC_RPC),
|
|
100
141
|
pollingInterval: 1000, // 1 second for Base
|
|
101
142
|
zapperEnum: "BASE_MAINNET",
|
|
102
143
|
coingeckoName: "base",
|
|
@@ -111,10 +152,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
|
|
|
111
152
|
canDepositNative: true,
|
|
112
153
|
defaultToken: getEthToken(optimism.id),
|
|
113
154
|
nativeToken: getEthToken(optimism.id),
|
|
114
|
-
viem: getCustomEvmChain(
|
|
115
|
-
optimism,
|
|
116
|
-
"https://black-cosmopolitan-hexagon.optimism.quiknode.pro/18382925841f9d09f9e76eef954bf189aa234523/",
|
|
117
|
-
),
|
|
155
|
+
viem: getCustomEvmChain(optimism, OPTIMISM_PUBLIC_RPC),
|
|
118
156
|
pollingInterval: 1000, // 1 second for Optimism
|
|
119
157
|
zapperEnum: "OPTIMISM_MAINNET",
|
|
120
158
|
coingeckoName: "optimism",
|
|
@@ -129,10 +167,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
|
|
|
129
167
|
canDepositNative: true,
|
|
130
168
|
defaultToken: getPolToken(),
|
|
131
169
|
nativeToken: getPolToken(),
|
|
132
|
-
viem: getCustomEvmChain(
|
|
133
|
-
polygon,
|
|
134
|
-
"https://purple-young-field.matic.quiknode.pro/ca54f365c1a4c7f970223eb8087e0fc579feba12/",
|
|
135
|
-
),
|
|
170
|
+
viem: getCustomEvmChain(polygon, POLYGON_PUBLIC_RPC),
|
|
136
171
|
pollingInterval: 1000, // 1 second for Polygon
|
|
137
172
|
zapperEnum: "POLYGON_MAINNET",
|
|
138
173
|
coingeckoName: "polygon_pos",
|
|
@@ -147,7 +182,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
|
|
|
147
182
|
canDepositNative: true,
|
|
148
183
|
defaultToken: getAvaxToken(),
|
|
149
184
|
nativeToken: getAvaxToken(),
|
|
150
|
-
viem: getCustomEvmChain(avalanche,
|
|
185
|
+
viem: getCustomEvmChain(avalanche, AVALANCHE_PUBLIC_RPC),
|
|
151
186
|
pollingInterval: 1000, // 1 second for Avalanche
|
|
152
187
|
zapperEnum: "AVALANCHE_MAINNET",
|
|
153
188
|
coingeckoName: "avax",
|
|
@@ -162,10 +197,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
|
|
|
162
197
|
canDepositNative: true,
|
|
163
198
|
defaultToken: getBnbToken(),
|
|
164
199
|
nativeToken: getBnbToken(),
|
|
165
|
-
viem: getCustomEvmChain(
|
|
166
|
-
bsc,
|
|
167
|
-
"https://methodical-divine-flower.bsc.quiknode.pro/9fc7efd3c34cc016cceacc27ee95850629b7cd21/",
|
|
168
|
-
),
|
|
200
|
+
viem: getCustomEvmChain(bsc, BSC_PUBLIC_RPC),
|
|
169
201
|
pollingInterval: 1000, // 1 second for BSC
|
|
170
202
|
zapperEnum: "BSC_MAINNET",
|
|
171
203
|
coingeckoName: "bsc",
|
|
@@ -180,10 +212,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
|
|
|
180
212
|
canDepositNative: true,
|
|
181
213
|
defaultToken: getEthToken(b3.id),
|
|
182
214
|
nativeToken: getEthToken(b3.id),
|
|
183
|
-
viem: getCustomEvmChain(
|
|
184
|
-
b3,
|
|
185
|
-
"https://late-dimensional-yard.b3-mainnet.quiknode.pro/461dbdbd44158cd7a7a764a58ffb01a67eef77f2/",
|
|
186
|
-
),
|
|
215
|
+
viem: getCustomEvmChain(b3, B3_PUBLIC_RPC),
|
|
187
216
|
pollingInterval: 1000, // 1 second for B3
|
|
188
217
|
zapperEnum: "B3_MAINNET",
|
|
189
218
|
coingeckoName: "b3",
|
|
@@ -198,10 +227,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
|
|
|
198
227
|
canDepositNative: true,
|
|
199
228
|
defaultToken: getEthToken(abstract.id),
|
|
200
229
|
nativeToken: getEthToken(abstract.id),
|
|
201
|
-
viem: getCustomEvmChain(
|
|
202
|
-
abstract,
|
|
203
|
-
"https://cosmopolitan-nameless-mountain.abstract-mainnet.quiknode.pro/863853304b986b582bdacf625ce3350397c560f8/",
|
|
204
|
-
),
|
|
230
|
+
viem: getCustomEvmChain(abstract, ABSTRACT_PUBLIC_RPC),
|
|
205
231
|
pollingInterval: 3000, // 3 seconds for Abstract
|
|
206
232
|
zapperEnum: "ABSTRACT_MAINNET",
|
|
207
233
|
coingeckoName: "abstract",
|
|
@@ -328,8 +354,12 @@ export function getChainType(chainId: number): ChainType {
|
|
|
328
354
|
export function chainIdToPublicClient(chainId: number): PublicClient {
|
|
329
355
|
invariant(EVM_CHAINS[chainId], `Chain ${chainId} is not an EVM chain`);
|
|
330
356
|
|
|
357
|
+
// Use override RPC if configured, otherwise use the default chain RPC
|
|
358
|
+
const rpcOverride = chainRpcOverrides[chainId];
|
|
359
|
+
const chain = rpcOverride ? getCustomEvmChain(EVM_CHAINS[chainId].viem, rpcOverride) : EVM_CHAINS[chainId].viem;
|
|
360
|
+
|
|
331
361
|
return createPublicClient({
|
|
332
|
-
chain
|
|
362
|
+
chain,
|
|
333
363
|
transport: http(),
|
|
334
364
|
pollingInterval: EVM_CHAINS[chainId].pollingInterval,
|
|
335
365
|
});
|
|
@@ -338,8 +368,12 @@ export function chainIdToPublicClient(chainId: number): PublicClient {
|
|
|
338
368
|
export function chainIdToWalletClient(chainId: number, account?: Account): WalletClient<Transport, Chain> {
|
|
339
369
|
invariant(EVM_CHAINS[chainId], `Chain ${chainId} is not an EVM chain`);
|
|
340
370
|
|
|
371
|
+
// Use override RPC if configured, otherwise use the default chain RPC
|
|
372
|
+
const rpcOverride = chainRpcOverrides[chainId];
|
|
373
|
+
const chain = rpcOverride ? getCustomEvmChain(EVM_CHAINS[chainId].viem, rpcOverride) : EVM_CHAINS[chainId].viem;
|
|
374
|
+
|
|
341
375
|
return createWalletClient({
|
|
342
|
-
chain
|
|
376
|
+
chain,
|
|
343
377
|
transport: http(),
|
|
344
378
|
account,
|
|
345
379
|
pollingInterval: EVM_CHAINS[chainId].pollingInterval,
|