@gibs/bridge-client 1.13.1 → 1.18.0

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/README.md CHANGED
@@ -10,13 +10,13 @@ It sits between `@gibs/bridge-sdk`, which prices and builds transfers but does n
10
10
  npm install @gibs/bridge-client viem
11
11
  ```
12
12
 
13
- `viem` is a peer dependency. The supported range is `>=2.37.0 <3`.
13
+ `viem` is a peer dependency. The supported range is `>=2.35.0 <3`.
14
14
 
15
15
  ## Requirements
16
16
 
17
- - Node 20 or later, or a modern browser.
18
- - The package is ESM only. Use `import`, not `require`.
19
- - `@gibs/bridge-sdk` is a dependency, and it reaches TON code. A browser bundle needs a global `Buffer`. Install the `buffer` package and set `globalThis.Buffer` before you import this package. Node has it already.
17
+ - Node 20 or later, a modern browser, or React Native 0.77 or later under Hermes.
18
+ - `import` loads the ECMAScript module build (`dist/`). `require` loads the CommonJS build (`dist/cjs/`).
19
+ - React Native needs no change to `metro.config.js`, no `resolveRequest` hook, no jest `transformIgnorePatterns` and no polyfill. It runs on React Native's own `URL` and `URLSearchParams`, which React Native 0.77 implements only in part: no code in the package reads them. Metro in React Native 0.79 or later reads the `exports` map. Metro in 0.77 and 0.78 ignores it, and finds each subpath through a folder the package ships for it (for example `token-metadata/package.json`), which points at the CommonJS build.
20
20
 
21
21
  ## Example
22
22
 
@@ -0,0 +1,6 @@
1
+ {
2
+ "main": "../dist/cjs/cache.js",
3
+ "module": "../dist/cache.js",
4
+ "types": "../dist/cache.d.ts",
5
+ "react-native": "../dist/cjs/cache.js"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "main": "../dist/cjs/chain-read.js",
3
+ "module": "../dist/chain-read.js",
4
+ "types": "../dist/chain-read.d.ts",
5
+ "react-native": "../dist/cjs/chain-read.js"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "main": "../dist/cjs/client.js",
3
+ "module": "../dist/client.js",
4
+ "types": "../dist/client.d.ts",
5
+ "react-native": "../dist/cjs/client.js"
6
+ }
@@ -0,0 +1,9 @@
1
+ export declare class Cache {
2
+ protected ttl: number;
3
+ cache: Map<string, {
4
+ time: number;
5
+ value: unknown;
6
+ }>;
7
+ constructor(ttl?: number);
8
+ clearStale(): number;
9
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Cache = void 0;
4
+ class Cache {
5
+ ttl;
6
+ cache = new Map();
7
+ constructor(ttl = 1000 * 60) {
8
+ this.ttl = ttl;
9
+ }
10
+ clearStale() {
11
+ const now = Date.now();
12
+ for (const k of this.cache.keys()) {
13
+ const { time } = this.cache.get(k);
14
+ if (now - time > this.ttl) {
15
+ this.cache.delete(k);
16
+ }
17
+ }
18
+ return now;
19
+ }
20
+ }
21
+ exports.Cache = Cache;
@@ -0,0 +1,27 @@
1
+ import { type Hex } from 'viem';
2
+ /** Inputs identifying an ERC-20 allowance to read: which token, owner, and spender on which chain. */
3
+ export type ApprovalParameters = {
4
+ /** The ERC-20 token contract address. */
5
+ token: Hex;
6
+ /** The address allowed to spend the owner's tokens. */
7
+ spender: Hex;
8
+ /** The chain the token lives on. */
9
+ chainId: number;
10
+ /** The token owner whose allowance is being read. */
11
+ account: Hex;
12
+ };
13
+ /**
14
+ * Reads an ERC-20 allowance for the given owner/spender pair on a chain.
15
+ *
16
+ * The native asset (`zeroAddress`) has no allowance concept, so it returns
17
+ * `maxUint256` (always sufficient). A missing or malformed owner address throws,
18
+ * matching the Svelte source — callers that may lack an account must guard first.
19
+ *
20
+ * Ported verbatim from `chain-read.svelte.ts`; the only change is sourcing
21
+ * {@link clientFromChain} from the framework-agnostic `wallet/clientFromChain`
22
+ * module instead of the Svelte `input.svelte` rune store.
23
+ *
24
+ * @param params The token, spender, chain, and owner to read.
25
+ * @returns The allowance in token base units.
26
+ */
27
+ export declare const checkAllowance: ({ token, spender, chainId, account }: ApprovalParameters) => Promise<bigint>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkAllowance = void 0;
4
+ const viem_1 = require("viem");
5
+ const client_js_1 = require("./client.js");
6
+ /**
7
+ * Reads an ERC-20 allowance for the given owner/spender pair on a chain.
8
+ *
9
+ * The native asset (`zeroAddress`) has no allowance concept, so it returns
10
+ * `maxUint256` (always sufficient). A missing or malformed owner address throws,
11
+ * matching the Svelte source — callers that may lack an account must guard first.
12
+ *
13
+ * Ported verbatim from `chain-read.svelte.ts`; the only change is sourcing
14
+ * {@link clientFromChain} from the framework-agnostic `wallet/clientFromChain`
15
+ * module instead of the Svelte `input.svelte` rune store.
16
+ *
17
+ * @param params The token, spender, chain, and owner to read.
18
+ * @returns The allowance in token base units.
19
+ */
20
+ const checkAllowance = async ({ token, spender, chainId, account }) => {
21
+ if (token === viem_1.zeroAddress) {
22
+ return viem_1.maxUint256;
23
+ }
24
+ const client = (0, client_js_1.clientFromChain)(chainId);
25
+ if (!account || !(0, viem_1.isAddress)(account)) {
26
+ throw new Error('No account');
27
+ }
28
+ return await client.readContract({
29
+ address: token,
30
+ abi: viem_1.erc20Abi,
31
+ functionName: 'allowance',
32
+ args: [account, spender],
33
+ });
34
+ };
35
+ exports.checkAllowance = checkAllowance;
@@ -0,0 +1,18 @@
1
+ /** One chain, carrying only what this application reads. */
2
+ export type ChainTableEntry = {
3
+ readonly id: number;
4
+ readonly name: string;
5
+ readonly nativeCurrency: {
6
+ readonly name: string;
7
+ readonly symbol: string;
8
+ readonly decimals: number;
9
+ };
10
+ readonly http: readonly string[];
11
+ readonly explorer: string | null;
12
+ /** Whether this is a test network, which a production build must not offer. */
13
+ readonly isTestnet: boolean;
14
+ /** The chain's Multicall3 deployment, or null where it has none. */
15
+ readonly multicall3: string | null;
16
+ };
17
+ /** Every supported chain, the bridge's own first. */
18
+ export declare const chainTable: readonly ChainTableEntry[];
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.chainTable = void 0;
4
+ // GENERATED by scripts/generate-chain-table.mjs — do not edit by hand.
5
+ //
6
+ // The Ethereum Virtual Machine chains LI.FI or Relay will quote, plus the
7
+ // bridge's own, with the fields a public client needs. Regenerate when either
8
+ // service adds a chain; the generator's own doc comment explains why this is a
9
+ // table rather than viem imports.
10
+ //
11
+ // Chains those services list that viem does not ship, and which are therefore
12
+ // absent here: 1672, 4663, 5042, 42018, 69000, 97477, 685689, 3586256, 5064014.
13
+ // They have no endpoint to seed from, so naming them would produce a chain the
14
+ // picker offers and no read can reach.
15
+ /** Every supported chain, the bridge's own first. */
16
+ exports.chainTable = [
17
+ { id: 1, name: "Ethereum", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://eth.merkle.io"], explorer: "https://etherscan.io", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
18
+ { id: 369, name: "PulseChain", nativeCurrency: { "name": "Pulse", "symbol": "PLS", "decimals": 18 }, http: ["https://rpc.pulsechain.com"], explorer: "https://ipfs.scan.pulsechain.com", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
19
+ { id: 11155111, name: "Sepolia", nativeCurrency: { "name": "Sepolia Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://11155111.rpc.thirdweb.com"], explorer: "https://sepolia.etherscan.io", isTestnet: true, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
20
+ { id: 943, name: "PulseChain V4", nativeCurrency: { "name": "V4 Pulse", "symbol": "v4PLS", "decimals": 18 }, http: ["https://rpc.v4.testnet.pulsechain.com"], explorer: "https://scan.v4.testnet.pulsechain.com", isTestnet: true, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
21
+ { id: 56, name: "BNB Smart Chain", nativeCurrency: { "decimals": 18, "name": "BNB", "symbol": "BNB" }, http: ["https://56.rpc.thirdweb.com"], explorer: "https://bscscan.com", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
22
+ { id: 42161, name: "Arbitrum One", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://arb1.arbitrum.io/rpc"], explorer: "https://arbiscan.io", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
23
+ { id: 8453, name: "Base", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://mainnet-preconf.base.org"], explorer: "https://basescan.org", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
24
+ { id: 81457, name: "Blast", nativeCurrency: { "decimals": 18, "name": "Ether", "symbol": "ETH" }, http: ["https://rpc.blast.io"], explorer: "https://blastscan.io", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
25
+ { id: 43114, name: "Avalanche", nativeCurrency: { "decimals": 18, "name": "Avalanche", "symbol": "AVAX" }, http: ["https://api.avax.network/ext/bc/C/rpc"], explorer: "https://snowtrace.io", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
26
+ { id: 137, name: "Polygon", nativeCurrency: { "name": "POL", "symbol": "POL", "decimals": 18 }, http: ["https://polygon.drpc.org"], explorer: "https://polygonscan.com", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
27
+ { id: 534352, name: "Scroll", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://rpc.scroll.io"], explorer: "https://scrollscan.com", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
28
+ { id: 10, name: "OP Mainnet", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://mainnet.optimism.io"], explorer: "https://optimistic.etherscan.io", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
29
+ { id: 59144, name: "Linea Mainnet", nativeCurrency: { "name": "Linea Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://rpc.linea.build"], explorer: "https://lineascan.build", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
30
+ { id: 324, name: "ZKsync Era", nativeCurrency: { "decimals": 18, "name": "Ether", "symbol": "ETH" }, http: ["https://mainnet.era.zksync.io"], explorer: "https://explorer.zksync.io/", isTestnet: false, multicall3: "0xF9cda624FBC7e059355ce98a31693d299FACd963" },
31
+ { id: 100, name: "Gnosis", nativeCurrency: { "decimals": 18, "name": "xDAI", "symbol": "XDAI" }, http: ["https://rpc.gnosischain.com"], explorer: "https://gnosisscan.io", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
32
+ { id: 122, name: "Fuse", nativeCurrency: { "name": "Fuse", "symbol": "FUSE", "decimals": 18 }, http: ["https://rpc.fuse.io"], explorer: "https://explorer.fuse.io", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
33
+ { id: 288, name: "Boba Network", nativeCurrency: { "decimals": 18, "name": "Ether", "symbol": "ETH" }, http: ["https://mainnet.boba.network"], explorer: "https://bobascan.com", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
34
+ { id: 130, name: "Unichain", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://mainnet.unichain.org/"], explorer: "https://uniscan.xyz", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
35
+ { id: 1329, name: "Sei Network", nativeCurrency: { "name": "Sei", "symbol": "SEI", "decimals": 18 }, http: ["https://evm-rpc.sei-apis.com/"], explorer: "https://seiscan.io", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
36
+ { id: 13371, name: "Immutable zkEVM", nativeCurrency: { "decimals": 18, "name": "Immutable Coin", "symbol": "IMX" }, http: ["https://rpc.immutable.com"], explorer: "https://explorer.immutable.com", isTestnet: false, multicall3: "0x236bdA4589e44e6850f5aC6a74BfCa398a86c6c0" },
37
+ { id: 146, name: "Sonic", nativeCurrency: { "decimals": 18, "name": "Sonic", "symbol": "S" }, http: ["https://rpc.soniclabs.com"], explorer: "https://sonicscan.org", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
38
+ { id: 1625, name: "Gravity Alpha Mainnet", nativeCurrency: { "name": "G", "symbol": "G", "decimals": 18 }, http: ["https://rpc.gravity.xyz"], explorer: "https://explorer.gravity.xyz", isTestnet: false, multicall3: "0xf8ac4BEB2F75d2cFFb588c63251347fdD629B92c" },
39
+ { id: 25, name: "Cronos Mainnet", nativeCurrency: { "decimals": 18, "name": "Cronos", "symbol": "CRO" }, http: ["https://evm.cronos.org"], explorer: "https://explorer.cronos.org", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
40
+ { id: 252, name: "Fraxtal", nativeCurrency: { "name": "Frax", "symbol": "FRAX", "decimals": 18 }, http: ["https://rpc.frax.com"], explorer: "https://fraxscan.com", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
41
+ { id: 2741, name: "Abstract", nativeCurrency: { "decimals": 18, "name": "ETH", "symbol": "ETH" }, http: ["https://api.mainnet.abs.xyz"], explorer: "https://abscan.org", isTestnet: false, multicall3: "0xAa4De41dba0Ca5dCBb288b7cC6b708F3aaC759E7" },
42
+ { id: 30, name: "Rootstock Mainnet", nativeCurrency: { "decimals": 18, "name": "Rootstock Bitcoin", "symbol": "RBTC" }, http: ["https://public-node.rsk.co"], explorer: "https://explorer.rsk.co", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
43
+ { id: 42220, name: "Celo", nativeCurrency: { "decimals": 18, "name": "CELO", "symbol": "CELO" }, http: ["https://forno.celo.org"], explorer: "https://celoscan.io", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
44
+ { id: 480, name: "World Chain", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://worldchain-mainnet.g.alchemy.com/public"], explorer: "https://worldscan.org", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
45
+ { id: 5000, name: "Mantle", nativeCurrency: { "decimals": 18, "name": "MNT", "symbol": "MNT" }, http: ["https://rpc.mantle.xyz"], explorer: "https://mantlescan.xyz/", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
46
+ { id: 80094, name: "Berachain", nativeCurrency: { "decimals": 18, "name": "BERA Token", "symbol": "BERA" }, http: ["https://rpc.berachain.com"], explorer: "https://berascan.com", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
47
+ { id: 14, name: "Flare Mainnet", nativeCurrency: { "decimals": 18, "name": "Flare", "symbol": "FLR" }, http: ["https://flare-api.flare.network/ext/C/rpc"], explorer: "https://flare-explorer.flare.network", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
48
+ { id: 40, name: "Telos", nativeCurrency: { "decimals": 18, "name": "Telos", "symbol": "TLOS" }, http: ["https://rpc.telos.net"], explorer: "https://www.teloscan.io/", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
49
+ { id: 50, name: "XDC Network", nativeCurrency: { "decimals": 18, "name": "XDC", "symbol": "XDC" }, http: ["https://rpc.xdcrpc.com"], explorer: "https://xdcscan.com", isTestnet: false, multicall3: "0x0B1795ccA8E4eC4df02346a082df54D437F8D9aF" },
50
+ { id: 88, name: "Viction", nativeCurrency: { "name": "Viction", "symbol": "VIC", "decimals": 18 }, http: ["https://rpc.viction.xyz"], explorer: "https://vicscan.xyz", isTestnet: false, multicall3: null },
51
+ { id: 143, name: "Monad", nativeCurrency: { "name": "Monad", "symbol": "MON", "decimals": 18 }, http: ["https://rpc.monad.xyz", "https://rpc1.monad.xyz"], explorer: "https://monadvision.com", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
52
+ { id: 169, name: "Manta Pacific Mainnet", nativeCurrency: { "decimals": 18, "name": "ETH", "symbol": "ETH" }, http: ["https://pacific-rpc.manta.network/http"], explorer: "https://pacific-explorer.manta.network", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
53
+ { id: 196, name: "X Layer Mainnet", nativeCurrency: { "decimals": 18, "name": "OKB", "symbol": "OKB" }, http: ["https://rpc.xlayer.tech"], explorer: "https://www.oklink.com/xlayer", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
54
+ { id: 204, name: "opBNB", nativeCurrency: { "name": "BNB", "symbol": "BNB", "decimals": 18 }, http: ["https://opbnb-mainnet-rpc.bnbchain.org"], explorer: "https://opbnb.bscscan.com", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
55
+ { id: 232, name: "Lens", nativeCurrency: { "name": "GHO", "symbol": "GHO", "decimals": 18 }, http: ["https://rpc.lens.xyz"], explorer: "https://explorer.lens.xyz", isTestnet: false, multicall3: null },
56
+ { id: 360, name: "Shape", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://mainnet.shape.network"], explorer: "https://shapescan.xyz", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
57
+ { id: 747, name: "Flow EVM Mainnet", nativeCurrency: { "decimals": 18, "name": "Flow", "symbol": "FLOW" }, http: ["https://mainnet.evm.nodes.onflow.org"], explorer: "https://evm.flowscan.io", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
58
+ { id: 988, name: "Stable Mainnet", nativeCurrency: { "name": "USDT0", "symbol": "USDT0", "decimals": 18 }, http: ["https://rpc.stable.xyz"], explorer: "https://stablescan.xyz", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
59
+ { id: 999, name: "Zora Goerli Testnet", nativeCurrency: { "decimals": 18, "name": "Zora Goerli", "symbol": "ETH" }, http: ["https://testnet.rpc.zora.energy"], explorer: "https://testnet.explorer.zora.energy", isTestnet: true, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
60
+ { id: 1088, name: "Metis", nativeCurrency: { "decimals": 18, "name": "Metis", "symbol": "METIS" }, http: ["https://metis.rpc.hypersync.xyz", "https://metis-pokt.nodies.app", "https://api.blockeden.xyz/metis/67nCBdZQSH9z3YqDDjdm", "https://metis-andromeda.rpc.thirdweb.com", "https://metis-andromeda.gateway.tenderly.co", "https://metis.api.onfinality.io/public", "https://andromeda.metis.io/?owner=1088", "https://metis-mainnet.public.blastapi.io"], explorer: "https://explorer.metis.io", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
61
+ { id: 1135, name: "Lisk", nativeCurrency: { "decimals": 18, "name": "Ether", "symbol": "ETH" }, http: ["https://rpc.api.lisk.com"], explorer: "https://blockscout.lisk.com", isTestnet: false, multicall3: "0xA9d71E1dd7ca26F26e656E66d6AA81ed7f745bf0" },
62
+ { id: 1337, name: "Tempo", nativeCurrency: { "name": "USD", "symbol": "USD", "decimals": 6 }, http: ["http://localhost:8545"], explorer: null, isTestnet: false, multicall3: null },
63
+ { id: 1480, name: "Vana", nativeCurrency: { "decimals": 18, "name": "Vana", "symbol": "VANA" }, http: ["https://rpc.vana.org/"], explorer: "https://vanascan.io", isTestnet: false, multicall3: "0xD8d2dFca27E8797fd779F8547166A2d3B29d360E" },
64
+ { id: 1776, name: "Injective", nativeCurrency: { "decimals": 18, "name": "Injective", "symbol": "INJ" }, http: ["https://sentry.evm-rpc.injective.network"], explorer: "https://blockscout.injective.network", isTestnet: false, multicall3: null },
65
+ { id: 1868, name: "Soneium Mainnet", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://rpc.soneium.org"], explorer: "https://soneium.blockscout.com", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
66
+ { id: 2020, name: "Ronin", nativeCurrency: { "name": "RON", "symbol": "RON", "decimals": 18 }, http: ["https://api.roninchain.com/rpc"], explorer: "https://app.roninchain.com", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
67
+ { id: 2818, name: "Morph", nativeCurrency: { "decimals": 18, "name": "Ether", "symbol": "ETH" }, http: ["https://rpc.morphl2.io"], explorer: "https://explorer.morphl2.io", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
68
+ { id: 4217, name: "Tempo Mainnet", nativeCurrency: { "name": "USD", "symbol": "USD", "decimals": 6 }, http: ["https://rpc.presto.tempo.xyz"], explorer: "https://explore.mainnet.tempo.xyz", isTestnet: false, multicall3: null },
69
+ { id: 4326, name: "MegaETH", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://mainnet.megaeth.com/rpc"], explorer: "https://mega.etherscan.io", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
70
+ { id: 5031, name: "Somnia", nativeCurrency: { "name": "Somnia", "symbol": "SOMI", "decimals": 18 }, http: ["https://api.infra.mainnet.somnia.network"], explorer: "https://explorer.somnia.network", isTestnet: false, multicall3: null },
71
+ { id: 5330, name: "Superseed", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://mainnet.superseed.xyz"], explorer: "https://explorer.superseed.xyz", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
72
+ { id: 8217, name: "Klaytn", nativeCurrency: { "decimals": 18, "name": "Klaytn", "symbol": "KLAY" }, http: ["https://public-en-cypress.klaytn.net"], explorer: "https://scope.klaytn.com", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
73
+ { id: 8333, name: "B3", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://mainnet-rpc.b3.fun/http"], explorer: "https://explorer.b3.fun", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
74
+ { id: 9745, name: "Plasma", nativeCurrency: { "name": "Plasma", "symbol": "XPL", "decimals": 18 }, http: ["https://rpc.plasma.to"], explorer: "https://plasmascan.to", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
75
+ { id: 16661, name: "0G Mainnet", nativeCurrency: { "name": "0G", "symbol": "0G", "decimals": 18 }, http: ["https://evmrpc.0g.ai"], explorer: "https://chainscan.0g.ai", isTestnet: false, multicall3: null },
76
+ { id: 33139, name: "ApeChain", nativeCurrency: { "name": "ApeCoin", "symbol": "APE", "decimals": 18 }, http: ["https://rpc.apechain.com/http"], explorer: "https://apescan.io", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
77
+ { id: 34443, name: "Mode Mainnet", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://mainnet.mode.network"], explorer: "https://modescan.io", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
78
+ { id: 42170, name: "Arbitrum Nova", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://nova.arbitrum.io/rpc"], explorer: "https://nova.arbiscan.io", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
79
+ { id: 42793, name: "Etherlink", nativeCurrency: { "decimals": 18, "name": "Tez", "symbol": "XTZ" }, http: ["https://node.mainnet.etherlink.com"], explorer: "https://explorer.etherlink.com", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
80
+ { id: 43111, name: "Hemi", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://rpc.hemi.network/rpc"], explorer: "https://explorer.hemi.xyz", isTestnet: false, multicall3: null },
81
+ { id: 43419, name: "Gunz Mainnet", nativeCurrency: { "name": "GUN", "symbol": "GUN", "decimals": 18 }, http: ["https://rpc.gunzchain.io/ext/bc/2M47TxWHGnhNtq6pM5zPXdATBtuqubxn5EPFgFmEawCQr9WFML/rpc"], explorer: "https://gunzscan.io/", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
82
+ { id: 48900, name: "Zircuit Mainnet", nativeCurrency: { "decimals": 18, "name": "Ether", "symbol": "ETH" }, http: ["https://mainnet.zircuit.com", "https://zircuit1-mainnet.liquify.com", "https://zircuit1-mainnet.p2pify.com", "https://zircuit-mainnet.drpc.org"], explorer: "https://explorer.zircuit.com", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
83
+ { id: 57073, name: "Ink", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://rpc-gel.inkonchain.com", "https://rpc-qnd.inkonchain.com"], explorer: "https://explorer.inkonchain.com", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
84
+ { id: 60808, name: "BOB", nativeCurrency: { "decimals": 18, "name": "ETH", "symbol": "ETH" }, http: ["https://rpc.gobob.xyz"], explorer: "https://explorer.gobob.xyz", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
85
+ { id: 84532, name: "Base Sepolia", nativeCurrency: { "name": "Sepolia Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://sepolia-preconf.base.org"], explorer: "https://sepolia.basescan.org", isTestnet: true, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
86
+ { id: 98866, name: "Plume", nativeCurrency: { "name": "Plume", "symbol": "PLUME", "decimals": 18 }, http: ["https://rpc.plume.org"], explorer: "https://explorer.plume.org", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
87
+ { id: 421614, name: "Arbitrum Sepolia", nativeCurrency: { "name": "Arbitrum Sepolia Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://sepolia-rollup.arbitrum.io/rpc"], explorer: "https://sepolia.arbiscan.io", isTestnet: true, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
88
+ { id: 747474, name: "Katana", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://rpc.katana.network"], explorer: "https://katanascan.com", isTestnet: false, multicall3: null },
89
+ { id: 5042002, name: "Arc Testnet", nativeCurrency: { "name": "USDC", "symbol": "USDC", "decimals": 18 }, http: ["https://rpc.testnet.arc.network", "https://rpc.quicknode.testnet.arc.network", "https://rpc.blockdaemon.testnet.arc.network"], explorer: "https://testnet.arcscan.app", isTestnet: true, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
90
+ { id: 7777777, name: "Zora", nativeCurrency: { "decimals": 18, "name": "Ether", "symbol": "ETH" }, http: ["https://rpc.zora.energy"], explorer: "https://explorer.zora.energy", isTestnet: false, multicall3: "0xcA11bde05977b3631167028862bE2a173976CA11" },
91
+ { id: 11155420, name: "OP Sepolia", nativeCurrency: { "name": "Sepolia Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://sepolia.optimism.io"], explorer: "https://optimism-sepolia.blockscout.com", isTestnet: true, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
92
+ ];
@@ -0,0 +1,33 @@
1
+ import type { HttpTransportConfig, PublicClient } from 'viem';
2
+ /**
3
+ * The request-batching setting for a chain's client.
4
+ *
5
+ * `false` for chains whose nodes reject a batch body at all (see
6
+ * {@link chainsWithoutRpcBatching}). Otherwise batching stays on, capped at
7
+ * {@link MAX_SAME_METHOD_CALLS_PER_SECOND} so no single post can exceed the
8
+ * proxy's per-method budget on its own and lose every call in it.
9
+ *
10
+ * The `wait` of ten milliseconds is viem's own default, restated here because
11
+ * naming `batchSize` alone would otherwise drop it.
12
+ *
13
+ * @param chainId - the chain to resolve the batch setting for
14
+ * @returns `false` when batching must be disabled, otherwise the batch config
15
+ */
16
+ export declare const rpcBatchSetting: (chainId: number) => HttpTransportConfig["batch"];
17
+ /**
18
+ * Returns a viem {@link PublicClient} for a chain, reusing the cached instance
19
+ * while the chain's endpoint list is unchanged. The cache key is derived from the
20
+ * chain id plus its urls, so editing the list yields a fresh client and lets the
21
+ * previous transport be garbage collected.
22
+ *
23
+ * The url source is the user-editable endpoint table; when it has no entry — or
24
+ * an EMPTY one — the chain's own defaults are used instead. The empty case is not
25
+ * hypothetical: the endpoint editor lets a user delete every entry for a chain,
26
+ * and an empty array is truthy, so a `||` fallback here quietly built a client
27
+ * with no transports at all and every read on that chain failed until the list
28
+ * was restored.
29
+ *
30
+ * @param chainId - the chain to build a client for
31
+ * @returns the cached or freshly built public client
32
+ */
33
+ export declare const clientFromChain: (chainId: number) => PublicClient;
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.clientFromChain = exports.rpcBatchSetting = void 0;
37
+ const chains_1 = require("@gibs/bridge-sdk/chains");
38
+ const client_1 = require("@gibs/common/client");
39
+ const chains_2 = require("viem/chains");
40
+ const endpoints = __importStar(require("./endpoints.js"));
41
+ const networks_js_1 = require("./networks.js");
42
+ /**
43
+ * Chains whose public nodes reject BATCH remote procedure call requests (an
44
+ * array-wrapped body). viem otherwise wraps even a single request in an array
45
+ * when batching is on, which those nodes refuse — so every call fails and is
46
+ * retried, burning through requests. Their clients are built with batching
47
+ * disabled so requests go out as plain objects the node accepts. Binance Smart
48
+ * Chain's `publicnode` endpoint is the known offender.
49
+ */
50
+ const chainsWithoutRpcBatching = new Set([chains_2.bsc.id]);
51
+ /**
52
+ * The request-batching setting for a chain's client.
53
+ *
54
+ * `false` for chains whose nodes reject a batch body at all (see
55
+ * {@link chainsWithoutRpcBatching}). Otherwise batching stays on, capped at
56
+ * {@link MAX_SAME_METHOD_CALLS_PER_SECOND} so no single post can exceed the
57
+ * proxy's per-method budget on its own and lose every call in it.
58
+ *
59
+ * The `wait` of ten milliseconds is viem's own default, restated here because
60
+ * naming `batchSize` alone would otherwise drop it.
61
+ *
62
+ * @param chainId - the chain to resolve the batch setting for
63
+ * @returns `false` when batching must be disabled, otherwise the batch config
64
+ */
65
+ const rpcBatchSetting = (chainId) => chainsWithoutRpcBatching.has(chainId)
66
+ ? false
67
+ : { batchSize: client_1.MAX_SAME_METHOD_CALLS_PER_SECOND, wait: 10 };
68
+ exports.rpcBatchSetting = rpcBatchSetting;
69
+ /**
70
+ * A chain's own default endpoints, used when the editable table has no entry.
71
+ *
72
+ * @param chainId - the chain to look up
73
+ * @returns the chain's default endpoints (possibly empty)
74
+ */
75
+ const defaultUrlsFor = (chainId) => {
76
+ if (!chainId) {
77
+ throw new Error('chainId is required');
78
+ }
79
+ // The APPLICATION's metadata first, viem's chain object only for the chains it
80
+ // does not override.
81
+ //
82
+ // These are two different answers to the same question, and reading only the
83
+ // second is why demoting a rate-limited Sepolia endpoint in the demo list
84
+ // changed nothing: the seed built from that map, while THIS function — which
85
+ // decides what a client actually talks to when the stored table is empty —
86
+ // returned viem's own default and went on hitting the demoted host first.
87
+ //
88
+ // The bridge chains are overridden precisely because viem's defaults are not
89
+ // the ones this application wants; the wider list (Arbitrum, Base, and the
90
+ // rest) has no override and correctly falls through.
91
+ //
92
+ // THE DEMO LIST IS ASKED FOR BY NAME. `chainsMetadata` no longer carries the
93
+ // shared `vk_demo` key, so a third party who builds on it never inherits that
94
+ // key. This package is the Gibs interface's own client layer, so it opts in.
95
+ const demoUrls = (0, chains_1.demoRpcUrlsFor)(chainId);
96
+ if (demoUrls.length) {
97
+ return demoUrls;
98
+ }
99
+ const chain = networks_js_1.evmChainsById.get(chainId);
100
+ if (!chain) {
101
+ return [];
102
+ }
103
+ const { http } = chain.rpcUrls.default;
104
+ return [...(http ?? [])];
105
+ };
106
+ /**
107
+ * Returns a viem {@link PublicClient} for a chain, reusing the cached instance
108
+ * while the chain's endpoint list is unchanged. The cache key is derived from the
109
+ * chain id plus its urls, so editing the list yields a fresh client and lets the
110
+ * previous transport be garbage collected.
111
+ *
112
+ * The url source is the user-editable endpoint table; when it has no entry — or
113
+ * an EMPTY one — the chain's own defaults are used instead. The empty case is not
114
+ * hypothetical: the endpoint editor lets a user delete every entry for a chain,
115
+ * and an empty array is truthy, so a `||` fallback here quietly built a client
116
+ * with no transports at all and every read on that chain failed until the list
117
+ * was restored.
118
+ *
119
+ * @param chainId - the chain to build a client for
120
+ * @returns the cached or freshly built public client
121
+ */
122
+ const clientFromChain = (chainId) => {
123
+ const stored = endpoints.get(chainId);
124
+ const urls = (stored?.length ? stored : defaultUrlsFor(chainId)).filter((url) => Boolean(url));
125
+ const key = (0, client_1.chainKey)(chainId, urls);
126
+ const existing = client_1.clientCache.get(chainId);
127
+ if (existing && existing.key === key) {
128
+ return existing.client;
129
+ }
130
+ const chain = networks_js_1.evmChainsById.get(chainId);
131
+ if (!chain) {
132
+ // Previously this searched every chain viem ships and asserted a hit with a
133
+ // `!`. That answered for chains this application does not support, and did
134
+ // so badly: there are no endpoints for them, so the client was built with
135
+ // none and silently fell back to viem's own public node — or, for a chain
136
+ // viem had never heard of, died on an unreadable `undefined.id` several
137
+ // frames away. Both are worse than saying so here.
138
+ throw new Error(`Chain ${chainId} is not one of the supported networks.`);
139
+ }
140
+ const client = (0, client_1.clientFromChain)({ chain, urls, batch: (0, exports.rpcBatchSetting)(chainId) });
141
+ client_1.clientCache.set(chainId, { key, client });
142
+ return client;
143
+ };
144
+ exports.clientFromChain = clientFromChain;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * The user-editable table of remote procedure call endpoints, per chain.
3
+ *
4
+ * This is the single source every read in the application resolves through, so
5
+ * that replacing a blocked node in one place moves every balance read, every
6
+ * receipt poll and every contract call at once.
7
+ *
8
+ * It is a plain external store — `subscribe` plus `getSnapshot` — rather than a
9
+ * hook, so it can be consumed by React through `useSyncExternalStore`, by another
10
+ * framework, or by nothing at all. The React binding lives with the application;
11
+ * nothing here imports a rendering library.
12
+ */
13
+ /** One chain's identifier paired with its endpoint list. */
14
+ export type EndpointEntry = [chainId: number, urls: string[]];
15
+ /**
16
+ * The minimal shape of browser storage this module needs.
17
+ *
18
+ * Injectable rather than reaching for `localStorage` directly: the store then
19
+ * works under a test runner, on a server, and in a host that keeps preferences
20
+ * somewhere other than the browser — and a test can assert what was persisted
21
+ * without installing a global.
22
+ */
23
+ export type EndpointStorage = {
24
+ getItem(key: string): string | null;
25
+ setItem(key: string, value: string): void;
26
+ };
27
+ /**
28
+ * The storage key holding the endpoint table.
29
+ *
30
+ * The literal must not change: users have their own nodes saved under it, and a
31
+ * rename silently reverts every one of them to the defaults on the next load.
32
+ */
33
+ export declare const ENDPOINTS_STORAGE_KEY = "rpcs";
34
+ /**
35
+ * Every chain the application can reach, the bridge's own first.
36
+ *
37
+ * The bridge's three keep taking their urls from `demoRpcUrlsFor`, which is
38
+ * where the product's own node choices live and which must win over viem's
39
+ * generic default for them.
40
+ */
41
+ export declare const productionSeed: EndpointEntry[];
42
+ /** The bridge's test chains, for a build that is not production. */
43
+ export declare const testnetSeed: EndpointEntry[];
44
+ /**
45
+ * Replaces the seed table and the persistence target.
46
+ *
47
+ * Both fields are optional so a host can override one without restating the
48
+ * other. The loaded table is discarded either way, so the next read rebuilds
49
+ * from the new seed merged with whatever is stored — which means this is safe to
50
+ * call after something has already read, not only at startup.
51
+ *
52
+ * @param options.seed - the entries to start from when storage holds nothing
53
+ * @param options.storage - where the table is persisted, or null for nowhere
54
+ */
55
+ export declare const configureEndpoints: ({ seed: nextSeed, storage: nextStorage, }: {
56
+ seed?: EndpointEntry[];
57
+ storage?: EndpointStorage | null;
58
+ }) => void;
59
+ /** Serializes one chain's list the way it is persisted: `chainId,url,url`. */
60
+ export declare const key: (chain: number, list: string[]) => string;
61
+ /**
62
+ * Parses a stored blob back into a table, merged onto the seeded entries.
63
+ *
64
+ * @param entry - the persisted blob, or null when nothing is stored
65
+ * @returns the merged table, or null when there was nothing to parse
66
+ */
67
+ export declare const parse: (entry: string | null) => Map<number, string[]> | null;
68
+ /** Serializes every entry, one chain per line. */
69
+ export declare const stringify: () => string;
70
+ /**
71
+ * Subscribes to changes in the endpoint table.
72
+ *
73
+ * @param listener - called after any mutation
74
+ * @returns the unsubscribe function
75
+ */
76
+ export declare const subscribe: (listener: () => void) => (() => void);
77
+ /**
78
+ * The current table.
79
+ *
80
+ * The identity is stable until something changes it — every mutating accessor
81
+ * replaces the map rather than mutating in place — which is what lets a caller
82
+ * use this directly as a `useSyncExternalStore` snapshot without re-rendering
83
+ * forever.
84
+ */
85
+ export declare const getSnapshot: () => Map<number, string[]>;
86
+ /** The url list for a chain, or null when it has no entry. */
87
+ export declare const get: (chain: number) => string[] | null;
88
+ /** All `[chainId, urls]` entries as a fresh array. */
89
+ export declare const entries: () => [number, string[]][];
90
+ /** Replaces a chain's url list, persists it, and notifies subscribers. */
91
+ export declare const setEndpoints: (chain: number, list: string[]) => void;
92
+ /** Replaces the url at index `i`; a no-op when the value is unchanged. */
93
+ export declare const update: (chain: number, i: number, url: string) => void;
94
+ /** Removes the url at index `i`. */
95
+ export declare const remove: (chain: number, i: number) => void;
96
+ /**
97
+ * Applies `addition` to a chain's url list and stores the result, keeping only
98
+ * the first item if it is empty (the leading "add new" slot) and dropping every
99
+ * other empty. A no-op when the filtered list is unchanged.
100
+ */
101
+ export declare const add: (chain: number, addition?: (urls: string[]) => string[]) => void;
102
+ /** Whether `list` already contains the chain's canonical default endpoint. */
103
+ export declare const hasDefault: (chain: number, list: string[]) => boolean;
104
+ /** Appends the chain's canonical default endpoints back onto its list. */
105
+ export declare const restoreDefault: (chain: number) => void;