@gibs/bridge-client 1.19.0 → 1.26.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/crossing-simulator/package.json +6 -0
- package/dist/chain-read.js +0 -14
- package/dist/chain-table.js +0 -12
- package/dist/cjs/chain-read.js +0 -14
- package/dist/cjs/chain-table.js +0 -12
- package/dist/cjs/client.js +0 -66
- package/dist/cjs/crossing-simulator.d.ts +32 -0
- package/dist/cjs/crossing-simulator.js +28 -0
- package/dist/cjs/endpoints.js +1 -109
- package/dist/cjs/image.js +0 -117
- package/dist/cjs/index.js +0 -15
- package/dist/cjs/networks.js +0 -61
- package/dist/cjs/token-metadata.d.ts +48 -1
- package/dist/cjs/token-metadata.js +35 -59
- package/dist/client.js +0 -66
- package/dist/crossing-simulator.d.ts +32 -0
- package/dist/crossing-simulator.js +23 -0
- package/dist/endpoints.js +1 -109
- package/dist/image.js +0 -117
- package/dist/index.js +0 -15
- package/dist/networks.js +0 -61
- package/dist/token-metadata.d.ts +48 -1
- package/dist/token-metadata.js +32 -60
- package/package.json +31 -3
package/dist/chain-read.js
CHANGED
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
import { erc20Abi, isAddress, maxUint256, zeroAddress } from 'viem';
|
|
2
2
|
import { clientFromChain } from './client.js';
|
|
3
|
-
/**
|
|
4
|
-
* Reads an ERC-20 allowance for the given owner/spender pair on a chain.
|
|
5
|
-
*
|
|
6
|
-
* The native asset (`zeroAddress`) has no allowance concept, so it returns
|
|
7
|
-
* `maxUint256` (always sufficient). A missing or malformed owner address throws,
|
|
8
|
-
* matching the Svelte source — callers that may lack an account must guard first.
|
|
9
|
-
*
|
|
10
|
-
* Ported verbatim from `chain-read.svelte.ts`; the only change is sourcing
|
|
11
|
-
* {@link clientFromChain} from the framework-agnostic `wallet/clientFromChain`
|
|
12
|
-
* module instead of the Svelte `input.svelte` rune store.
|
|
13
|
-
*
|
|
14
|
-
* @param params The token, spender, chain, and owner to read.
|
|
15
|
-
* @returns The allowance in token base units.
|
|
16
|
-
*/
|
|
17
3
|
export const checkAllowance = async ({ token, spender, chainId, account }) => {
|
|
18
4
|
if (token === zeroAddress) {
|
|
19
5
|
return maxUint256;
|
package/dist/chain-table.js
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
// GENERATED by scripts/generate-chain-table.mjs — do not edit by hand.
|
|
2
|
-
//
|
|
3
|
-
// The Ethereum Virtual Machine chains LI.FI or Relay will quote, plus the
|
|
4
|
-
// bridge's own, with the fields a public client needs. Regenerate when either
|
|
5
|
-
// service adds a chain; the generator's own doc comment explains why this is a
|
|
6
|
-
// table rather than viem imports.
|
|
7
|
-
//
|
|
8
|
-
// Chains those services list that viem does not ship, and which are therefore
|
|
9
|
-
// absent here: 1672, 4663, 5042, 42018, 69000, 97477, 685689, 3586256, 5064014.
|
|
10
|
-
// They have no endpoint to seed from, so naming them would produce a chain the
|
|
11
|
-
// picker offers and no read can reach.
|
|
12
|
-
/** Every supported chain, the bridge's own first. */
|
|
13
1
|
export const chainTable = [
|
|
14
2
|
{ id: 1, name: "Ethereum", nativeCurrency: { "name": "Ether", "symbol": "ETH", "decimals": 18 }, http: ["https://eth.merkle.io"], explorer: "https://etherscan.io", isTestnet: false, multicall3: "0xca11bde05977b3631167028862be2a173976ca11" },
|
|
15
3
|
{ 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" },
|
package/dist/cjs/chain-read.js
CHANGED
|
@@ -3,20 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.checkAllowance = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
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
6
|
const checkAllowance = async ({ token, spender, chainId, account }) => {
|
|
21
7
|
if (token === viem_1.zeroAddress) {
|
|
22
8
|
return viem_1.maxUint256;
|
package/dist/cjs/chain-table.js
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
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
4
|
exports.chainTable = [
|
|
17
5
|
{ 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
6
|
{ 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" },
|
package/dist/cjs/client.js
CHANGED
|
@@ -39,59 +39,15 @@ const client_1 = require("@gibs/common/client");
|
|
|
39
39
|
const chains_2 = require("viem/chains");
|
|
40
40
|
const endpoints = __importStar(require("./endpoints.js"));
|
|
41
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
42
|
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
43
|
const rpcBatchSetting = (chainId) => chainsWithoutRpcBatching.has(chainId)
|
|
66
44
|
? false
|
|
67
45
|
: { batchSize: client_1.MAX_SAME_METHOD_CALLS_PER_SECOND, wait: 10 };
|
|
68
46
|
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
47
|
const defaultUrlsFor = (chainId) => {
|
|
76
48
|
if (!chainId) {
|
|
77
49
|
throw new Error('chainId is required');
|
|
78
50
|
}
|
|
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
51
|
const demoUrls = (0, chains_1.demoRpcUrlsFor)(chainId);
|
|
96
52
|
if (demoUrls.length) {
|
|
97
53
|
return demoUrls;
|
|
@@ -103,22 +59,6 @@ const defaultUrlsFor = (chainId) => {
|
|
|
103
59
|
const { http } = chain.rpcUrls.default;
|
|
104
60
|
return [...(http ?? [])];
|
|
105
61
|
};
|
|
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
62
|
const clientFromChain = (chainId) => {
|
|
123
63
|
const stored = endpoints.get(chainId);
|
|
124
64
|
const urls = (stored?.length ? stored : defaultUrlsFor(chainId)).filter((url) => Boolean(url));
|
|
@@ -129,12 +69,6 @@ const clientFromChain = (chainId) => {
|
|
|
129
69
|
}
|
|
130
70
|
const chain = networks_js_1.evmChainsById.get(chainId);
|
|
131
71
|
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
72
|
throw new Error(`Chain ${chainId} is not one of the supported networks.`);
|
|
139
73
|
}
|
|
140
74
|
const client = (0, client_1.clientFromChain)({ chain, urls, batch: (0, exports.rpcBatchSetting)(chainId) });
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createCrossingSimulator } from '@gibs/bridge-sdk/crossing-simulation';
|
|
2
|
+
import type { PublicClient } from 'viem';
|
|
3
|
+
/**
|
|
4
|
+
* The node that answers a crossing simulation, by chain id.
|
|
5
|
+
*
|
|
6
|
+
* WHY NOT THE CHAIN'S NORMAL NODES. A simulation needs `eth_simulateV1`, and
|
|
7
|
+
* the nodes this application reads with are chosen for plain reads. A node that
|
|
8
|
+
* lacks the method answers an error, and the simulator then reports
|
|
9
|
+
* "unavailable": no tax check, and no first crossing. A node that is known to
|
|
10
|
+
* serve the method keeps the check working. `ethereum-rpc.publicnode.com` was
|
|
11
|
+
* measured to serve it on 2026-10-21.
|
|
12
|
+
*
|
|
13
|
+
* Only Ethereum is listed because only the Ethereum entry can make a first
|
|
14
|
+
* crossing. A chain with no entry here has no simulation.
|
|
15
|
+
*/
|
|
16
|
+
export declare const simulationEndpoints: Readonly<Record<number, string>>;
|
|
17
|
+
/**
|
|
18
|
+
* A client on the simulation node for one chain, built once.
|
|
19
|
+
*
|
|
20
|
+
* @param chainId - the chain whose entry mediator is simulated
|
|
21
|
+
* @returns the client, or null when no simulation node is listed for the chain
|
|
22
|
+
*/
|
|
23
|
+
export declare const simulationClientOrNull: (chainId: number) => PublicClient | null;
|
|
24
|
+
/**
|
|
25
|
+
* The one simulator the whole interface shares. The route search and the
|
|
26
|
+
* warning beside the Output ask the same question for the same token and
|
|
27
|
+
* amount. A shared cache answers the second asker without a second request,
|
|
28
|
+
* and the shared pacing keeps the node from being asked in a burst.
|
|
29
|
+
*
|
|
30
|
+
* @returns the shared simulator
|
|
31
|
+
*/
|
|
32
|
+
export declare const sharedCrossingSimulator: () => ReturnType<typeof createCrossingSimulator>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sharedCrossingSimulator = exports.simulationClientOrNull = exports.simulationEndpoints = void 0;
|
|
4
|
+
const crossing_simulation_1 = require("@gibs/bridge-sdk/crossing-simulation");
|
|
5
|
+
const client_1 = require("@gibs/common/client");
|
|
6
|
+
const client_js_1 = require("./client.js");
|
|
7
|
+
const networks_js_1 = require("./networks.js");
|
|
8
|
+
exports.simulationEndpoints = {
|
|
9
|
+
1: 'https://ethereum-rpc.publicnode.com',
|
|
10
|
+
};
|
|
11
|
+
const simulationClients = new Map();
|
|
12
|
+
const simulationClientOrNull = (chainId) => {
|
|
13
|
+
const cached = simulationClients.get(chainId);
|
|
14
|
+
if (cached !== undefined)
|
|
15
|
+
return cached;
|
|
16
|
+
const url = exports.simulationEndpoints[chainId];
|
|
17
|
+
const chain = networks_js_1.evmChainsById.get(chainId);
|
|
18
|
+
const client = url === undefined || chain === undefined ? null : (0, client_1.clientFromChain)({ chain, urls: [url], batch: (0, client_js_1.rpcBatchSetting)(chainId) });
|
|
19
|
+
simulationClients.set(chainId, client);
|
|
20
|
+
return client;
|
|
21
|
+
};
|
|
22
|
+
exports.simulationClientOrNull = simulationClientOrNull;
|
|
23
|
+
let sharedSimulator;
|
|
24
|
+
const sharedCrossingSimulator = () => {
|
|
25
|
+
sharedSimulator ??= (0, crossing_simulation_1.createCrossingSimulator)({ clientForChain: exports.simulationClientOrNull });
|
|
26
|
+
return sharedSimulator;
|
|
27
|
+
};
|
|
28
|
+
exports.sharedCrossingSimulator = sharedCrossingSimulator;
|
package/dist/cjs/endpoints.js
CHANGED
|
@@ -4,75 +4,23 @@ exports.restoreDefault = exports.hasDefault = exports.add = exports.remove = exp
|
|
|
4
4
|
const chains_1 = require("@gibs/bridge-sdk/chains");
|
|
5
5
|
const config_1 = require("@gibs/bridge-sdk/config");
|
|
6
6
|
const chain_table_js_1 = require("./chain-table.js");
|
|
7
|
-
/**
|
|
8
|
-
* The storage key holding the endpoint table.
|
|
9
|
-
*
|
|
10
|
-
* The literal must not change: users have their own nodes saved under it, and a
|
|
11
|
-
* rename silently reverts every one of them to the defaults on the next load.
|
|
12
|
-
*/
|
|
13
7
|
exports.ENDPOINTS_STORAGE_KEY = 'rpcs';
|
|
14
|
-
/**
|
|
15
|
-
* EVERY SUPPORTED CHAIN GETS AN ENTRY, and the entry comes from viem.
|
|
16
|
-
*
|
|
17
|
-
* This used to seed three chains — PulseChain, Ethereum and Binance Smart Chain
|
|
18
|
-
* — while the aggregators quote routes from seventy-odd. A chain absent from
|
|
19
|
-
* this table is not refused; `clientFromChain` falls through to viem's own
|
|
20
|
-
* public nodes for it. So every read on an aggregator origin went to a node
|
|
21
|
-
* nobody chose, which is where the rate limiting came from, and the endpoint
|
|
22
|
-
* editor could not show the chain at all: a reader whose Base node was throttled
|
|
23
|
-
* had no way to replace it, because Base was not in the list they were editing.
|
|
24
|
-
*
|
|
25
|
-
* Seeding from `chainTable` fixes both at once. The urls are viem's own
|
|
26
|
-
* defaults, which is what the three seeded chains always used — the change is
|
|
27
|
-
* the breadth, not the source.
|
|
28
|
-
*/
|
|
29
8
|
const seedFor = (chains) => chains.map((chain) => [Number(chain), (0, chains_1.demoRpcUrlsFor)(Number(chain))]);
|
|
30
|
-
/** The bridge's own chains, kept first so a picker built from this reads well. */
|
|
31
9
|
const BRIDGE_CHAIN_IDS = [
|
|
32
10
|
Number(config_1.Chains.PLS),
|
|
33
11
|
Number(config_1.Chains.ETH),
|
|
34
12
|
Number(config_1.Chains.BNB),
|
|
35
13
|
];
|
|
36
|
-
/**
|
|
37
|
-
* Every chain the application can reach, the bridge's own first.
|
|
38
|
-
*
|
|
39
|
-
* The bridge's three keep taking their urls from `demoRpcUrlsFor`, which is
|
|
40
|
-
* where the product's own node choices live and which must win over viem's
|
|
41
|
-
* generic default for them.
|
|
42
|
-
*/
|
|
43
14
|
exports.productionSeed = [
|
|
44
15
|
...seedFor([config_1.Chains.PLS, config_1.Chains.ETH, config_1.Chains.BNB]),
|
|
45
16
|
...chain_table_js_1.chainTable
|
|
46
|
-
.filter((entry) =>
|
|
47
|
-
// The bridge's own three are seeded above, from `demoRpcUrlsFor`, and
|
|
48
|
-
// must not be seeded twice. That map is where the product's node
|
|
49
|
-
// choices live — demoting a rate-limited host there has to take effect,
|
|
50
|
-
// and a table entry added after it would silently win.
|
|
51
|
-
!BRIDGE_CHAIN_IDS.includes(entry.id) &&
|
|
52
|
-
// A PRODUCTION BUILD PROMISES NOT TO OFFER A TEST NETWORK, and the
|
|
53
|
-
// endpoint table is one of the places that promise can be broken: the
|
|
54
|
-
// chains seeded here are the chains the endpoint editor lists. The
|
|
55
|
-
// table carries test networks deliberately, because a client still has
|
|
56
|
-
// to be buildable for them on a testnet build; this is where they are
|
|
57
|
-
// held back.
|
|
17
|
+
.filter((entry) => !BRIDGE_CHAIN_IDS.includes(entry.id) &&
|
|
58
18
|
!entry.isTestnet)
|
|
59
19
|
.map((entry) => [entry.id, [...entry.http]]),
|
|
60
20
|
];
|
|
61
|
-
/** The bridge's test chains, for a build that is not production. */
|
|
62
21
|
exports.testnetSeed = seedFor([config_1.Chains.V4PLS, config_1.Chains.SEP]);
|
|
63
|
-
/** The seed the next load starts from. */
|
|
64
22
|
let seed = exports.productionSeed;
|
|
65
|
-
/**
|
|
66
|
-
* Where the table is persisted. `undefined` means "use the browser default,
|
|
67
|
-
* resolved on first use"; null means "nowhere".
|
|
68
|
-
*/
|
|
69
23
|
let storage;
|
|
70
|
-
/**
|
|
71
|
-
* Resolves the browser's `localStorage` without letting a failure escape.
|
|
72
|
-
*
|
|
73
|
-
* Touching the global can throw (private windows, Node 22 without a storage
|
|
74
|
-
* file) or print a warning, so nothing calls this at import time.
|
|
75
|
-
*/
|
|
76
24
|
const browserStorage = () => {
|
|
77
25
|
try {
|
|
78
26
|
return typeof globalThis.localStorage === 'undefined'
|
|
@@ -83,14 +31,12 @@ const browserStorage = () => {
|
|
|
83
31
|
return null;
|
|
84
32
|
}
|
|
85
33
|
};
|
|
86
|
-
/** The persistence target in effect, resolving the default on first call. */
|
|
87
34
|
const activeStorage = () => {
|
|
88
35
|
if (storage === undefined) {
|
|
89
36
|
storage = browserStorage();
|
|
90
37
|
}
|
|
91
38
|
return storage;
|
|
92
39
|
};
|
|
93
|
-
/** The live table, or null while it has not been loaded yet. */
|
|
94
40
|
let value = null;
|
|
95
41
|
const listeners = new Set();
|
|
96
42
|
const emit = () => {
|
|
@@ -98,17 +44,6 @@ const emit = () => {
|
|
|
98
44
|
listener();
|
|
99
45
|
}
|
|
100
46
|
};
|
|
101
|
-
/**
|
|
102
|
-
* Replaces the seed table and the persistence target.
|
|
103
|
-
*
|
|
104
|
-
* Both fields are optional so a host can override one without restating the
|
|
105
|
-
* other. The loaded table is discarded either way, so the next read rebuilds
|
|
106
|
-
* from the new seed merged with whatever is stored — which means this is safe to
|
|
107
|
-
* call after something has already read, not only at startup.
|
|
108
|
-
*
|
|
109
|
-
* @param options.seed - the entries to start from when storage holds nothing
|
|
110
|
-
* @param options.storage - where the table is persisted, or null for nowhere
|
|
111
|
-
*/
|
|
112
47
|
const configureEndpoints = ({ seed: nextSeed, storage: nextStorage, }) => {
|
|
113
48
|
if (nextSeed !== undefined) {
|
|
114
49
|
seed = nextSeed;
|
|
@@ -120,15 +55,8 @@ const configureEndpoints = ({ seed: nextSeed, storage: nextStorage, }) => {
|
|
|
120
55
|
emit();
|
|
121
56
|
};
|
|
122
57
|
exports.configureEndpoints = configureEndpoints;
|
|
123
|
-
/** Serializes one chain's list the way it is persisted: `chainId,url,url`. */
|
|
124
58
|
const key = (chain, list) => `${chain},${list.join(',')}`;
|
|
125
59
|
exports.key = key;
|
|
126
|
-
/**
|
|
127
|
-
* Parses a stored blob back into a table, merged onto the seeded entries.
|
|
128
|
-
*
|
|
129
|
-
* @param entry - the persisted blob, or null when nothing is stored
|
|
130
|
-
* @returns the merged table, or null when there was nothing to parse
|
|
131
|
-
*/
|
|
132
60
|
const parse = (entry) => {
|
|
133
61
|
if (!entry) {
|
|
134
62
|
return null;
|
|
@@ -140,13 +68,6 @@ const parse = (entry) => {
|
|
|
140
68
|
return new Map([...seed, ...stored]);
|
|
141
69
|
};
|
|
142
70
|
exports.parse = parse;
|
|
143
|
-
/**
|
|
144
|
-
* Reads the persisted table, or null when there is nothing usable to read.
|
|
145
|
-
*
|
|
146
|
-
* Any failure falls back to the seeded defaults rather than propagating: a
|
|
147
|
-
* corrupt or unreadable entry must not be the reason the application cannot
|
|
148
|
-
* reach a chain at all.
|
|
149
|
-
*/
|
|
150
71
|
const readStored = () => {
|
|
151
72
|
const target = activeStorage();
|
|
152
73
|
if (!target) {
|
|
@@ -160,22 +81,14 @@ const readStored = () => {
|
|
|
160
81
|
return null;
|
|
161
82
|
}
|
|
162
83
|
};
|
|
163
|
-
/** The table, loaded from storage the first time it is asked for. */
|
|
164
84
|
const loaded = () => {
|
|
165
85
|
if (!value) {
|
|
166
86
|
value = readStored() ?? new Map(seed);
|
|
167
87
|
}
|
|
168
88
|
return value;
|
|
169
89
|
};
|
|
170
|
-
/** Serializes every entry, one chain per line. */
|
|
171
90
|
const stringify = () => [...loaded().entries()].map(([chainId, list]) => (0, exports.key)(chainId, list)).join('\n');
|
|
172
91
|
exports.stringify = stringify;
|
|
173
|
-
/**
|
|
174
|
-
* Subscribes to changes in the endpoint table.
|
|
175
|
-
*
|
|
176
|
-
* @param listener - called after any mutation
|
|
177
|
-
* @returns the unsubscribe function
|
|
178
|
-
*/
|
|
179
92
|
const subscribe = (listener) => {
|
|
180
93
|
listeners.add(listener);
|
|
181
94
|
return () => {
|
|
@@ -183,23 +96,12 @@ const subscribe = (listener) => {
|
|
|
183
96
|
};
|
|
184
97
|
};
|
|
185
98
|
exports.subscribe = subscribe;
|
|
186
|
-
/**
|
|
187
|
-
* The current table.
|
|
188
|
-
*
|
|
189
|
-
* The identity is stable until something changes it — every mutating accessor
|
|
190
|
-
* replaces the map rather than mutating in place — which is what lets a caller
|
|
191
|
-
* use this directly as a `useSyncExternalStore` snapshot without re-rendering
|
|
192
|
-
* forever.
|
|
193
|
-
*/
|
|
194
99
|
const getSnapshot = () => loaded();
|
|
195
100
|
exports.getSnapshot = getSnapshot;
|
|
196
|
-
/** The url list for a chain, or null when it has no entry. */
|
|
197
101
|
const get = (chain) => loaded().get(chain) ?? null;
|
|
198
102
|
exports.get = get;
|
|
199
|
-
/** All `[chainId, urls]` entries as a fresh array. */
|
|
200
103
|
const entries = () => [...loaded().entries()];
|
|
201
104
|
exports.entries = entries;
|
|
202
|
-
/** Replaces a chain's url list, persists it, and notifies subscribers. */
|
|
203
105
|
const setEndpoints = (chain, list) => {
|
|
204
106
|
const next = new Map(loaded());
|
|
205
107
|
next.set(chain, list);
|
|
@@ -208,7 +110,6 @@ const setEndpoints = (chain, list) => {
|
|
|
208
110
|
emit();
|
|
209
111
|
};
|
|
210
112
|
exports.setEndpoints = setEndpoints;
|
|
211
|
-
/** Replaces the url at index `i`; a no-op when the value is unchanged. */
|
|
212
113
|
const update = (chain, i, url) => {
|
|
213
114
|
const list = (0, exports.get)(chain) ?? [];
|
|
214
115
|
if (list[i] === url) {
|
|
@@ -219,23 +120,16 @@ const update = (chain, i, url) => {
|
|
|
219
120
|
(0, exports.setEndpoints)(chain, next);
|
|
220
121
|
};
|
|
221
122
|
exports.update = update;
|
|
222
|
-
/** Removes the url at index `i`. */
|
|
223
123
|
const remove = (chain, i) => {
|
|
224
124
|
const next = ((0, exports.get)(chain) ?? []).slice(0);
|
|
225
125
|
next.splice(i, 1);
|
|
226
126
|
(0, exports.setEndpoints)(chain, next);
|
|
227
127
|
};
|
|
228
128
|
exports.remove = remove;
|
|
229
|
-
/**
|
|
230
|
-
* Applies `addition` to a chain's url list and stores the result, keeping only
|
|
231
|
-
* the first item if it is empty (the leading "add new" slot) and dropping every
|
|
232
|
-
* other empty. A no-op when the filtered list is unchanged.
|
|
233
|
-
*/
|
|
234
129
|
const add = (chain, addition = (urls) => [''].concat(urls)) => {
|
|
235
130
|
const before = (0, exports.get)(chain) ?? [];
|
|
236
131
|
const list = addition(before.slice(0));
|
|
237
132
|
const filteredList = list.filter((val, i) => {
|
|
238
|
-
// only the first item in the list may be empty
|
|
239
133
|
if (!val && !i) {
|
|
240
134
|
return true;
|
|
241
135
|
}
|
|
@@ -248,7 +142,6 @@ const add = (chain, addition = (urls) => [''].concat(urls)) => {
|
|
|
248
142
|
(0, exports.setEndpoints)(chain, filteredList);
|
|
249
143
|
};
|
|
250
144
|
exports.add = add;
|
|
251
|
-
/** Whether `list` already contains the chain's canonical default endpoint. */
|
|
252
145
|
const hasDefault = (chain, list) => {
|
|
253
146
|
const defaultUrl = (0, chains_1.demoRpcUrlsFor)(chain)[0];
|
|
254
147
|
if (!defaultUrl)
|
|
@@ -256,7 +149,6 @@ const hasDefault = (chain, list) => {
|
|
|
256
149
|
return list.includes(defaultUrl);
|
|
257
150
|
};
|
|
258
151
|
exports.hasDefault = hasDefault;
|
|
259
|
-
/** Appends the chain's canonical default endpoints back onto its list. */
|
|
260
152
|
const restoreDefault = (chain) => {
|
|
261
153
|
(0, exports.add)(chain, (l) => l.concat((0, chains_1.demoRpcUrlsFor)(chain)));
|
|
262
154
|
};
|
package/dist/cjs/image.js
CHANGED
|
@@ -38,63 +38,8 @@ const imageLinks = __importStar(require("@gibs/bridge-sdk/image-links"));
|
|
|
38
38
|
const relay_quote_1 = require("@gibs/bridge-sdk/relay-quote");
|
|
39
39
|
const viem_1 = require("viem");
|
|
40
40
|
const chain_table_js_1 = require("./chain-table.js");
|
|
41
|
-
/**
|
|
42
|
-
* Chain-logo resolution, in one place.
|
|
43
|
-
*
|
|
44
|
-
* gib.show serves almost every chain a route can start from — including the
|
|
45
|
-
* non-Ethereum ones — but it keys them by a CAIP-2 style identifier rather than
|
|
46
|
-
* by Relay's invented decimal ids, so the two have to be mapped. Only Eclipse
|
|
47
|
-
* and Hyperliquid are genuinely absent from it, and those alone fall back to
|
|
48
|
-
* Relay's own icon service.
|
|
49
|
-
*
|
|
50
|
-
* This is a module rather than an inline template string because getting the
|
|
51
|
-
* key wrong is invisible: a 404 in an `<img src>` is drawn by the browser as a
|
|
52
|
-
* broken-image glyph, so the mistake surfaces as a blemish on a token pill
|
|
53
|
-
* rather than as an error anyone would go looking for.
|
|
54
|
-
*/
|
|
55
|
-
/**
|
|
56
|
-
* Relay's public chain-icon service, keyed on Relay's own chain identifiers —
|
|
57
|
-
* the authority for the ids it invented.
|
|
58
|
-
*
|
|
59
|
-
* The `light` variant is the full-colour brand mark (the pair is light/dark
|
|
60
|
-
* BACKGROUND, not a monochrome inversion), so one variant serves both of our
|
|
61
|
-
* themes. Not every id is populated — The Open Network answers 403, which is
|
|
62
|
-
* what the bundled asset used to exist for — so callers must still tolerate a
|
|
63
|
-
* badge that fails to load. Only Eclipse and Hyperliquid reach this now.
|
|
64
|
-
*
|
|
65
|
-
* @param chainId - a Relay chain identifier
|
|
66
|
-
* @returns the icon url
|
|
67
|
-
*/
|
|
68
41
|
const relayChainIconUrl = (chainId) => `https://assets.relay.link/icons/${chainId}/light.png`;
|
|
69
42
|
exports.relayChainIconUrl = relayChainIconUrl;
|
|
70
|
-
/**
|
|
71
|
-
* gib.show's own key for a chain that Relay reaches us under a pseudo id.
|
|
72
|
-
*
|
|
73
|
-
* THE SERVICE WAS NEVER MISSING THESE CHAINS — WE WERE ASKING BY THE WRONG KEY.
|
|
74
|
-
* gib.show keys every chain by a CAIP-2 style identifier: `eip155-1`,
|
|
75
|
-
* `solana-501`, `bip122-0`. Relay invented its own decimal ids for the
|
|
76
|
-
* non-Ethereum origins (Solana is 792703809, Bitcoin 8253038), and asking
|
|
77
|
-
* gib.show for one of those 404s — which read as "gib.show does not serve
|
|
78
|
-
* Solana" and sent every non-Ethereum badge to a second service. It serves them
|
|
79
|
-
* all, under its own key.
|
|
80
|
-
*
|
|
81
|
-
* Each entry below was verified twice: the url returns 200 with a real PNG, and
|
|
82
|
-
* the picture was LOOKED AT and is the chain's genuine mark. A 200 alone proves
|
|
83
|
-
* nothing here — `/image/999` returns 200 and hands back a completely different
|
|
84
|
-
* chain's logo, which is why an identifier is only listed once someone has seen
|
|
85
|
-
* what comes back.
|
|
86
|
-
*
|
|
87
|
-
* ECLIPSE AND HYPERLIQUID ARE ABSENT ON PURPOSE. Neither appears anywhere in
|
|
88
|
-
* gib.show's network list under any key, so they keep Relay's service. Guessing
|
|
89
|
-
* a plausible identifier for them would be worse than falling back: Hyperliquid
|
|
90
|
-
* in particular collides with an unrelated chain at id 999, so a guess renders
|
|
91
|
-
* the wrong company's logo rather than none at all.
|
|
92
|
-
*
|
|
93
|
-
* The pay-by-hand chains (Zcash and, later, its siblings) are NOT listed by
|
|
94
|
-
* hand here. `bridge-sdk`'s `image-links.ts` is the one place that key is
|
|
95
|
-
* declared — see its `pseudoChainGibShowIdentifier` — and this table spreads
|
|
96
|
-
* that map in, so a pay-by-hand chain added there needs no matching edit here.
|
|
97
|
-
*/
|
|
98
43
|
const gibShowChainIdentifier = {
|
|
99
44
|
[relay_quote_1.relayChainIds.solana]: 'solana-501',
|
|
100
45
|
[relay_quote_1.relayChainIds.bitcoin]: 'bip122-0',
|
|
@@ -102,29 +47,9 @@ const gibShowChainIdentifier = {
|
|
|
102
47
|
[relay_quote_1.relayChainIds.ton]: 'ton-607',
|
|
103
48
|
...imageLinks.pseudoChainGibShowIdentifier,
|
|
104
49
|
};
|
|
105
|
-
/**
|
|
106
|
-
* Resolves the logo url for a chain, choosing the service that can serve it.
|
|
107
|
-
*
|
|
108
|
-
* A chain gib.show knows under its own identifier wins outright
|
|
109
|
-
* ({@link gibShowChainIdentifier}). Otherwise an Ethereum-Virtual-Machine chain
|
|
110
|
-
* goes to gib.show by number, honouring the configured image root so a
|
|
111
|
-
* self-hosted deployment is respected rather than hard-coding the public host.
|
|
112
|
-
* What remains is Eclipse and Hyperliquid, which gib.show does not carry, and
|
|
113
|
-
* they go to Relay.
|
|
114
|
-
*
|
|
115
|
-
* @param chainId - the decimal chain id, Relay's pseudo identifiers included
|
|
116
|
-
* @param displayPx - the CSS pixel size the logo renders at; when supplied,
|
|
117
|
-
* gib.show is asked for twice that in webp per its retina guidance. Ignored
|
|
118
|
-
* for a Relay-served icon and for an identifier-keyed mark, neither of which
|
|
119
|
-
* takes sizing parameters.
|
|
120
|
-
* @returns an image url for the chain
|
|
121
|
-
*/
|
|
122
50
|
const chainLogoUrl = ({ chainId, displayPx, }) => {
|
|
123
51
|
const identifier = gibShowChainIdentifier[chainId];
|
|
124
52
|
if (identifier !== undefined) {
|
|
125
|
-
// gib.show serves this chain, just not under Relay's number. No sizing
|
|
126
|
-
// parameters: these are fixed-size marks rather than the resizable images
|
|
127
|
-
// the numeric endpoint serves.
|
|
128
53
|
return `${imageLinks.getImageRoot()}/image/${identifier}`;
|
|
129
54
|
}
|
|
130
55
|
if ((0, relay_quote_1.ecosystemByChainId)(chainId) !== 'evm') {
|
|
@@ -137,44 +62,8 @@ const chainLogoUrl = ({ chainId, displayPx, }) => {
|
|
|
137
62
|
return `${base}?w=${displayPx * 2}&h=${displayPx * 2}&format=webp`;
|
|
138
63
|
};
|
|
139
64
|
exports.chainLogoUrl = chainLogoUrl;
|
|
140
|
-
/**
|
|
141
|
-
* The chain a native coin actually belongs to, found by its symbol.
|
|
142
|
-
*
|
|
143
|
-
* WHY THIS IS NEEDED. gib.show serves a coin's own picture under
|
|
144
|
-
* `<chain>/<zero address>`, and it carries that picture only for the chain the
|
|
145
|
-
* coin is native to — not for every chain the coin has been bridged onto. Ether
|
|
146
|
-
* on Base is the case that exposed it: `8453/<zero address>` is a 404, so the
|
|
147
|
-
* lookup fell through to the chain mark and drew Base's blue disc where the
|
|
148
|
-
* ether diamond belongs. The same picture is one source away under `1/<zero
|
|
149
|
-
* address>`, and gib.show's multi-source lookup will cross chains to reach it.
|
|
150
|
-
*
|
|
151
|
-
* READ FROM THE TABLE, NOT FROM A LIST WRITTEN HERE. The generated chain table
|
|
152
|
-
* orders the bridge's own chains first and the rest in the order the product
|
|
153
|
-
* chose, so the EARLIEST entry carrying a symbol is the chain that coin came
|
|
154
|
-
* from: ether resolves to Ethereum ahead of the dozen chains that also call
|
|
155
|
-
* their coin ETH, and the mapping stays right as the table grows. The table is
|
|
156
|
-
* reversed before the map is built because a later `set` wins — reversing makes
|
|
157
|
-
* the earliest entry the last one written.
|
|
158
|
-
*
|
|
159
|
-
* A coin whose home chain has no dedicated picture — Binance Coin, Polygon
|
|
160
|
-
* Ecosystem Token, Avalanche — loses nothing. Their home chain IS the chain
|
|
161
|
-
* they are asked about, so the list collapses to what it already was, and for
|
|
162
|
-
* a chain's own coin the chain mark is the coin mark.
|
|
163
|
-
*/
|
|
164
65
|
const homeChainOfSymbol = new Map([...chain_table_js_1.chainTable].reverse().map((entry) => [entry.nativeCurrency.symbol, entry.id]));
|
|
165
|
-
/** Every chain's own native symbol, for resolving a coin from its chain alone. */
|
|
166
66
|
const symbolOfChain = new Map(chain_table_js_1.chainTable.map((entry) => [entry.id, entry.nativeCurrency.symbol]));
|
|
167
|
-
/**
|
|
168
|
-
* The gib.show sources for a chain's NATIVE COIN, best first.
|
|
169
|
-
*
|
|
170
|
-
* The service serves the first source that resolves: the coin as this chain
|
|
171
|
-
* keys it, then the coin as its home chain keys it, then the chain's own mark.
|
|
172
|
-
* The last is an honest fallback rather than a mistake — for a chain's own coin
|
|
173
|
-
* the two marks are the same picture.
|
|
174
|
-
*
|
|
175
|
-
* @param chainId - the chain the coin is being shown on
|
|
176
|
-
* @returns the ordered source list, for {@link imageLinks.images}
|
|
177
|
-
*/
|
|
178
67
|
const nativeCoinImageSources = (chainId) => {
|
|
179
68
|
const sources = [`${chainId}/${viem_1.zeroAddress}`];
|
|
180
69
|
const symbol = symbolOfChain.get(chainId);
|
|
@@ -186,11 +75,5 @@ const nativeCoinImageSources = (chainId) => {
|
|
|
186
75
|
return sources;
|
|
187
76
|
};
|
|
188
77
|
exports.nativeCoinImageSources = nativeCoinImageSources;
|
|
189
|
-
/**
|
|
190
|
-
* Resolves the picture of a chain's native coin, as opposed to of the chain.
|
|
191
|
-
*
|
|
192
|
-
* @param chainId - the chain the coin is being shown on
|
|
193
|
-
* @returns an image url
|
|
194
|
-
*/
|
|
195
78
|
const nativeCoinLogoUrl = (chainId) => imageLinks.images((0, exports.nativeCoinImageSources)(chainId));
|
|
196
79
|
exports.nativeCoinLogoUrl = nativeCoinLogoUrl;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseTokenKey = exports.parseChainScopedAddress = exports.loadTokenMetadata = exports.getTokenMetadata = exports.getTokenChainIdFromBridge = exports.getTokenAddressFromBridge = exports.getStoreSize = exports.getStoreKey = exports.getBridgeTokenMetadata = exports.isSupportedEvmChain = exports.evmChainsById = exports.evmChains = exports.relayChainIconUrl = exports.chainLogoUrl = exports.update = exports.testnetSeed = exports.subscribe = exports.stringify = exports.setEndpoints = exports.restoreDefault = exports.remove = exports.productionSeed = exports.parse = exports.key = exports.hasDefault = exports.getSnapshot = exports.get = exports.entries = exports.ENDPOINTS_STORAGE_KEY = exports.configureEndpoints = exports.add = exports.rpcBatchSetting = exports.clientFromChain = exports.checkAllowance = exports.Cache = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Browser-side machinery for talking to the chains the bridge supports.
|
|
6
|
-
*
|
|
7
|
-
* Everything here is framework-free. It is the layer between `@gibs/bridge-sdk`,
|
|
8
|
-
* which knows about pathways, quotes and fees but performs no input or output,
|
|
9
|
-
* and an application, which renders. Endpoint resolution, public clients, chain
|
|
10
|
-
* reads, token metadata, caching and logo resolution all live here so that a
|
|
11
|
-
* second application does not have to rebuild them — and so that the rules they
|
|
12
|
-
* encode (which node answers for a chain, which image service knows a chain's
|
|
13
|
-
* mark) have exactly one home.
|
|
14
|
-
*
|
|
15
|
-
* Subpath exports are the intended way in — `@gibs/bridge-client/client`,
|
|
16
|
-
* `/endpoints`, `/image` and so on — so that importing one does not pull the
|
|
17
|
-
* rest. This barrel exists for consumers that would rather not think about it.
|
|
18
|
-
*/
|
|
19
4
|
var cache_js_1 = require("./cache.js");
|
|
20
5
|
Object.defineProperty(exports, "Cache", { enumerable: true, get: function () { return cache_js_1.Cache; } });
|
|
21
6
|
var chain_read_js_1 = require("./chain-read.js");
|