@gibs/bridge-client 1.13.1 → 1.17.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 +4 -4
- package/cache/package.json +6 -0
- package/chain-read/package.json +6 -0
- package/client/package.json +6 -0
- package/dist/cjs/cache.d.ts +9 -0
- package/dist/cjs/cache.js +21 -0
- package/dist/cjs/chain-read.d.ts +27 -0
- package/dist/cjs/chain-read.js +35 -0
- package/dist/cjs/chain-table.d.ts +18 -0
- package/dist/cjs/chain-table.js +92 -0
- package/dist/cjs/client.d.ts +33 -0
- package/dist/cjs/client.js +144 -0
- package/dist/cjs/endpoints.d.ts +105 -0
- package/dist/cjs/endpoints.js +263 -0
- package/dist/cjs/image.d.ts +68 -0
- package/dist/cjs/image.js +196 -0
- package/dist/cjs/index.d.ts +22 -0
- package/dist/cjs/index.js +60 -0
- package/dist/cjs/networks.d.ts +30 -0
- package/dist/cjs/networks.js +83 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/token-metadata.d.ts +21 -0
- package/dist/cjs/token-metadata.js +285 -0
- package/dist/client.js +10 -9
- package/dist/endpoints.d.ts +1 -1
- package/dist/endpoints.js +42 -15
- package/dist/token-metadata.js +15 -8
- package/endpoints/package.json +6 -0
- package/image/package.json +6 -0
- package/llms.txt +8 -7
- package/networks/package.json +6 -0
- package/package.json +197 -9
- package/token-metadata/package.json +6 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.restoreDefault = exports.hasDefault = exports.add = exports.remove = exports.update = exports.setEndpoints = exports.entries = exports.get = exports.getSnapshot = exports.subscribe = exports.stringify = exports.parse = exports.key = exports.configureEndpoints = exports.testnetSeed = exports.productionSeed = exports.ENDPOINTS_STORAGE_KEY = void 0;
|
|
4
|
+
const chains_1 = require("@gibs/bridge-sdk/chains");
|
|
5
|
+
const config_1 = require("@gibs/bridge-sdk/config");
|
|
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
|
+
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
|
+
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
|
+
const BRIDGE_CHAIN_IDS = [
|
|
32
|
+
Number(config_1.Chains.PLS),
|
|
33
|
+
Number(config_1.Chains.ETH),
|
|
34
|
+
Number(config_1.Chains.BNB),
|
|
35
|
+
];
|
|
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
|
+
exports.productionSeed = [
|
|
44
|
+
...seedFor([config_1.Chains.PLS, config_1.Chains.ETH, config_1.Chains.BNB]),
|
|
45
|
+
...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.
|
|
58
|
+
!entry.isTestnet)
|
|
59
|
+
.map((entry) => [entry.id, [...entry.http]]),
|
|
60
|
+
];
|
|
61
|
+
/** The bridge's test chains, for a build that is not production. */
|
|
62
|
+
exports.testnetSeed = seedFor([config_1.Chains.V4PLS, config_1.Chains.SEP]);
|
|
63
|
+
/** The seed the next load starts from. */
|
|
64
|
+
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
|
+
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
|
+
const browserStorage = () => {
|
|
77
|
+
try {
|
|
78
|
+
return typeof globalThis.localStorage === 'undefined'
|
|
79
|
+
? null
|
|
80
|
+
: globalThis.localStorage;
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
/** The persistence target in effect, resolving the default on first call. */
|
|
87
|
+
const activeStorage = () => {
|
|
88
|
+
if (storage === undefined) {
|
|
89
|
+
storage = browserStorage();
|
|
90
|
+
}
|
|
91
|
+
return storage;
|
|
92
|
+
};
|
|
93
|
+
/** The live table, or null while it has not been loaded yet. */
|
|
94
|
+
let value = null;
|
|
95
|
+
const listeners = new Set();
|
|
96
|
+
const emit = () => {
|
|
97
|
+
for (const listener of listeners) {
|
|
98
|
+
listener();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
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
|
+
const configureEndpoints = ({ seed: nextSeed, storage: nextStorage, }) => {
|
|
113
|
+
if (nextSeed !== undefined) {
|
|
114
|
+
seed = nextSeed;
|
|
115
|
+
}
|
|
116
|
+
if (nextStorage !== undefined) {
|
|
117
|
+
storage = nextStorage;
|
|
118
|
+
}
|
|
119
|
+
value = null;
|
|
120
|
+
emit();
|
|
121
|
+
};
|
|
122
|
+
exports.configureEndpoints = configureEndpoints;
|
|
123
|
+
/** Serializes one chain's list the way it is persisted: `chainId,url,url`. */
|
|
124
|
+
const key = (chain, list) => `${chain},${list.join(',')}`;
|
|
125
|
+
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
|
+
const parse = (entry) => {
|
|
133
|
+
if (!entry) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
const stored = entry.split('\n').map((row) => {
|
|
137
|
+
const [chain, ...list] = row.split(',');
|
|
138
|
+
return [Number(chain), list.filter((url) => url !== '')];
|
|
139
|
+
});
|
|
140
|
+
return new Map([...seed, ...stored]);
|
|
141
|
+
};
|
|
142
|
+
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
|
+
const readStored = () => {
|
|
151
|
+
const target = activeStorage();
|
|
152
|
+
if (!target) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
return (0, exports.parse)(target.getItem(exports.ENDPOINTS_STORAGE_KEY));
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
console.error('unable to read the stored endpoint list', error);
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
/** The table, loaded from storage the first time it is asked for. */
|
|
164
|
+
const loaded = () => {
|
|
165
|
+
if (!value) {
|
|
166
|
+
value = readStored() ?? new Map(seed);
|
|
167
|
+
}
|
|
168
|
+
return value;
|
|
169
|
+
};
|
|
170
|
+
/** Serializes every entry, one chain per line. */
|
|
171
|
+
const stringify = () => [...loaded().entries()].map(([chainId, list]) => (0, exports.key)(chainId, list)).join('\n');
|
|
172
|
+
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
|
+
const subscribe = (listener) => {
|
|
180
|
+
listeners.add(listener);
|
|
181
|
+
return () => {
|
|
182
|
+
listeners.delete(listener);
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
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
|
+
const getSnapshot = () => loaded();
|
|
195
|
+
exports.getSnapshot = getSnapshot;
|
|
196
|
+
/** The url list for a chain, or null when it has no entry. */
|
|
197
|
+
const get = (chain) => loaded().get(chain) ?? null;
|
|
198
|
+
exports.get = get;
|
|
199
|
+
/** All `[chainId, urls]` entries as a fresh array. */
|
|
200
|
+
const entries = () => [...loaded().entries()];
|
|
201
|
+
exports.entries = entries;
|
|
202
|
+
/** Replaces a chain's url list, persists it, and notifies subscribers. */
|
|
203
|
+
const setEndpoints = (chain, list) => {
|
|
204
|
+
const next = new Map(loaded());
|
|
205
|
+
next.set(chain, list);
|
|
206
|
+
value = next;
|
|
207
|
+
activeStorage()?.setItem(exports.ENDPOINTS_STORAGE_KEY, (0, exports.stringify)());
|
|
208
|
+
emit();
|
|
209
|
+
};
|
|
210
|
+
exports.setEndpoints = setEndpoints;
|
|
211
|
+
/** Replaces the url at index `i`; a no-op when the value is unchanged. */
|
|
212
|
+
const update = (chain, i, url) => {
|
|
213
|
+
const list = (0, exports.get)(chain) ?? [];
|
|
214
|
+
if (list[i] === url) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const next = list.slice(0);
|
|
218
|
+
next[i] = url;
|
|
219
|
+
(0, exports.setEndpoints)(chain, next);
|
|
220
|
+
};
|
|
221
|
+
exports.update = update;
|
|
222
|
+
/** Removes the url at index `i`. */
|
|
223
|
+
const remove = (chain, i) => {
|
|
224
|
+
const next = ((0, exports.get)(chain) ?? []).slice(0);
|
|
225
|
+
next.splice(i, 1);
|
|
226
|
+
(0, exports.setEndpoints)(chain, next);
|
|
227
|
+
};
|
|
228
|
+
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
|
+
const add = (chain, addition = (urls) => [''].concat(urls)) => {
|
|
235
|
+
const before = (0, exports.get)(chain) ?? [];
|
|
236
|
+
const list = addition(before.slice(0));
|
|
237
|
+
const filteredList = list.filter((val, i) => {
|
|
238
|
+
// only the first item in the list may be empty
|
|
239
|
+
if (!val && !i) {
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
return !!val;
|
|
243
|
+
});
|
|
244
|
+
const unchanged = before.length === filteredList.length && before.every((url, index) => url === filteredList[index]);
|
|
245
|
+
if (unchanged) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
(0, exports.setEndpoints)(chain, filteredList);
|
|
249
|
+
};
|
|
250
|
+
exports.add = add;
|
|
251
|
+
/** Whether `list` already contains the chain's canonical default endpoint. */
|
|
252
|
+
const hasDefault = (chain, list) => {
|
|
253
|
+
const defaultUrl = (0, chains_1.demoRpcUrlsFor)(chain)[0];
|
|
254
|
+
if (!defaultUrl)
|
|
255
|
+
return false;
|
|
256
|
+
return list.includes(defaultUrl);
|
|
257
|
+
};
|
|
258
|
+
exports.hasDefault = hasDefault;
|
|
259
|
+
/** Appends the chain's canonical default endpoints back onto its list. */
|
|
260
|
+
const restoreDefault = (chain) => {
|
|
261
|
+
(0, exports.add)(chain, (l) => l.concat((0, chains_1.demoRpcUrlsFor)(chain)));
|
|
262
|
+
};
|
|
263
|
+
exports.restoreDefault = restoreDefault;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chain-logo resolution, in one place.
|
|
3
|
+
*
|
|
4
|
+
* gib.show serves almost every chain a route can start from — including the
|
|
5
|
+
* non-Ethereum ones — but it keys them by a CAIP-2 style identifier rather than
|
|
6
|
+
* by Relay's invented decimal ids, so the two have to be mapped. Only Eclipse
|
|
7
|
+
* and Hyperliquid are genuinely absent from it, and those alone fall back to
|
|
8
|
+
* Relay's own icon service.
|
|
9
|
+
*
|
|
10
|
+
* This is a module rather than an inline template string because getting the
|
|
11
|
+
* key wrong is invisible: a 404 in an `<img src>` is drawn by the browser as a
|
|
12
|
+
* broken-image glyph, so the mistake surfaces as a blemish on a token pill
|
|
13
|
+
* rather than as an error anyone would go looking for.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Relay's public chain-icon service, keyed on Relay's own chain identifiers —
|
|
17
|
+
* the authority for the ids it invented.
|
|
18
|
+
*
|
|
19
|
+
* The `light` variant is the full-colour brand mark (the pair is light/dark
|
|
20
|
+
* BACKGROUND, not a monochrome inversion), so one variant serves both of our
|
|
21
|
+
* themes. Not every id is populated — The Open Network answers 403, which is
|
|
22
|
+
* what the bundled asset used to exist for — so callers must still tolerate a
|
|
23
|
+
* badge that fails to load. Only Eclipse and Hyperliquid reach this now.
|
|
24
|
+
*
|
|
25
|
+
* @param chainId - a Relay chain identifier
|
|
26
|
+
* @returns the icon url
|
|
27
|
+
*/
|
|
28
|
+
export declare const relayChainIconUrl: (chainId: number) => string;
|
|
29
|
+
/**
|
|
30
|
+
* Resolves the logo url for a chain, choosing the service that can serve it.
|
|
31
|
+
*
|
|
32
|
+
* A chain gib.show knows under its own identifier wins outright
|
|
33
|
+
* ({@link gibShowChainIdentifier}). Otherwise an Ethereum-Virtual-Machine chain
|
|
34
|
+
* goes to gib.show by number, honouring the configured image root so a
|
|
35
|
+
* self-hosted deployment is respected rather than hard-coding the public host.
|
|
36
|
+
* What remains is Eclipse and Hyperliquid, which gib.show does not carry, and
|
|
37
|
+
* they go to Relay.
|
|
38
|
+
*
|
|
39
|
+
* @param chainId - the decimal chain id, Relay's pseudo identifiers included
|
|
40
|
+
* @param displayPx - the CSS pixel size the logo renders at; when supplied,
|
|
41
|
+
* gib.show is asked for twice that in webp per its retina guidance. Ignored
|
|
42
|
+
* for a Relay-served icon and for an identifier-keyed mark, neither of which
|
|
43
|
+
* takes sizing parameters.
|
|
44
|
+
* @returns an image url for the chain
|
|
45
|
+
*/
|
|
46
|
+
export declare const chainLogoUrl: ({ chainId, displayPx, }: {
|
|
47
|
+
chainId: number;
|
|
48
|
+
displayPx?: number;
|
|
49
|
+
}) => string;
|
|
50
|
+
/**
|
|
51
|
+
* The gib.show sources for a chain's NATIVE COIN, best first.
|
|
52
|
+
*
|
|
53
|
+
* The service serves the first source that resolves: the coin as this chain
|
|
54
|
+
* keys it, then the coin as its home chain keys it, then the chain's own mark.
|
|
55
|
+
* The last is an honest fallback rather than a mistake — for a chain's own coin
|
|
56
|
+
* the two marks are the same picture.
|
|
57
|
+
*
|
|
58
|
+
* @param chainId - the chain the coin is being shown on
|
|
59
|
+
* @returns the ordered source list, for {@link imageLinks.images}
|
|
60
|
+
*/
|
|
61
|
+
export declare const nativeCoinImageSources: (chainId: number) => string[];
|
|
62
|
+
/**
|
|
63
|
+
* Resolves the picture of a chain's native coin, as opposed to of the chain.
|
|
64
|
+
*
|
|
65
|
+
* @param chainId - the chain the coin is being shown on
|
|
66
|
+
* @returns an image url
|
|
67
|
+
*/
|
|
68
|
+
export declare const nativeCoinLogoUrl: (chainId: number) => string;
|
|
@@ -0,0 +1,196 @@
|
|
|
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.nativeCoinLogoUrl = exports.nativeCoinImageSources = exports.chainLogoUrl = exports.relayChainIconUrl = void 0;
|
|
37
|
+
const imageLinks = __importStar(require("@gibs/bridge-sdk/image-links"));
|
|
38
|
+
const relay_quote_1 = require("@gibs/bridge-sdk/relay-quote");
|
|
39
|
+
const viem_1 = require("viem");
|
|
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
|
+
const relayChainIconUrl = (chainId) => `https://assets.relay.link/icons/${chainId}/light.png`;
|
|
69
|
+
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
|
+
const gibShowChainIdentifier = {
|
|
99
|
+
[relay_quote_1.relayChainIds.solana]: 'solana-501',
|
|
100
|
+
[relay_quote_1.relayChainIds.bitcoin]: 'bip122-0',
|
|
101
|
+
[relay_quote_1.relayChainIds.tron]: 'tvm-195',
|
|
102
|
+
[relay_quote_1.relayChainIds.ton]: 'ton-607',
|
|
103
|
+
...imageLinks.pseudoChainGibShowIdentifier,
|
|
104
|
+
};
|
|
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
|
+
const chainLogoUrl = ({ chainId, displayPx, }) => {
|
|
123
|
+
const identifier = gibShowChainIdentifier[chainId];
|
|
124
|
+
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
|
+
return `${imageLinks.getImageRoot()}/image/${identifier}`;
|
|
129
|
+
}
|
|
130
|
+
if ((0, relay_quote_1.ecosystemByChainId)(chainId) !== 'evm') {
|
|
131
|
+
return (0, exports.relayChainIconUrl)(chainId);
|
|
132
|
+
}
|
|
133
|
+
const base = imageLinks.network(chainId);
|
|
134
|
+
if (displayPx === undefined) {
|
|
135
|
+
return base;
|
|
136
|
+
}
|
|
137
|
+
return `${base}?w=${displayPx * 2}&h=${displayPx * 2}&format=webp`;
|
|
138
|
+
};
|
|
139
|
+
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
|
+
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
|
+
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
|
+
const nativeCoinImageSources = (chainId) => {
|
|
179
|
+
const sources = [`${chainId}/${viem_1.zeroAddress}`];
|
|
180
|
+
const symbol = symbolOfChain.get(chainId);
|
|
181
|
+
const home = symbol === undefined ? undefined : homeChainOfSymbol.get(symbol);
|
|
182
|
+
if (home !== undefined && home !== chainId) {
|
|
183
|
+
sources.push(`${home}/${viem_1.zeroAddress}`);
|
|
184
|
+
}
|
|
185
|
+
sources.push(`${chainId}/`);
|
|
186
|
+
return sources;
|
|
187
|
+
};
|
|
188
|
+
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
|
+
const nativeCoinLogoUrl = (chainId) => imageLinks.images((0, exports.nativeCoinImageSources)(chainId));
|
|
196
|
+
exports.nativeCoinLogoUrl = nativeCoinLogoUrl;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-side machinery for talking to the chains the bridge supports.
|
|
3
|
+
*
|
|
4
|
+
* Everything here is framework-free. It is the layer between `@gibs/bridge-sdk`,
|
|
5
|
+
* which knows about pathways, quotes and fees but performs no input or output,
|
|
6
|
+
* and an application, which renders. Endpoint resolution, public clients, chain
|
|
7
|
+
* reads, token metadata, caching and logo resolution all live here so that a
|
|
8
|
+
* second application does not have to rebuild them — and so that the rules they
|
|
9
|
+
* encode (which node answers for a chain, which image service knows a chain's
|
|
10
|
+
* mark) have exactly one home.
|
|
11
|
+
*
|
|
12
|
+
* Subpath exports are the intended way in — `@gibs/bridge-client/client`,
|
|
13
|
+
* `/endpoints`, `/image` and so on — so that importing one does not pull the
|
|
14
|
+
* rest. This barrel exists for consumers that would rather not think about it.
|
|
15
|
+
*/
|
|
16
|
+
export { Cache } from './cache.js';
|
|
17
|
+
export { checkAllowance, type ApprovalParameters } from './chain-read.js';
|
|
18
|
+
export { clientFromChain, rpcBatchSetting } from './client.js';
|
|
19
|
+
export { add, configureEndpoints, ENDPOINTS_STORAGE_KEY, entries, get, getSnapshot, hasDefault, key, parse, productionSeed, remove, restoreDefault, setEndpoints, stringify, subscribe, testnetSeed, update, type EndpointEntry, type EndpointStorage, } from './endpoints.js';
|
|
20
|
+
export { chainLogoUrl, relayChainIconUrl } from './image.js';
|
|
21
|
+
export { evmChains, evmChainsById, isSupportedEvmChain } from './networks.js';
|
|
22
|
+
export { getBridgeTokenMetadata, getStoreKey, getStoreSize, getTokenAddressFromBridge, getTokenChainIdFromBridge, getTokenMetadata, loadTokenMetadata, parseChainScopedAddress, parseTokenKey, type ChainScopedAddress, } from './token-metadata.js';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
+
var cache_js_1 = require("./cache.js");
|
|
20
|
+
Object.defineProperty(exports, "Cache", { enumerable: true, get: function () { return cache_js_1.Cache; } });
|
|
21
|
+
var chain_read_js_1 = require("./chain-read.js");
|
|
22
|
+
Object.defineProperty(exports, "checkAllowance", { enumerable: true, get: function () { return chain_read_js_1.checkAllowance; } });
|
|
23
|
+
var client_js_1 = require("./client.js");
|
|
24
|
+
Object.defineProperty(exports, "clientFromChain", { enumerable: true, get: function () { return client_js_1.clientFromChain; } });
|
|
25
|
+
Object.defineProperty(exports, "rpcBatchSetting", { enumerable: true, get: function () { return client_js_1.rpcBatchSetting; } });
|
|
26
|
+
var endpoints_js_1 = require("./endpoints.js");
|
|
27
|
+
Object.defineProperty(exports, "add", { enumerable: true, get: function () { return endpoints_js_1.add; } });
|
|
28
|
+
Object.defineProperty(exports, "configureEndpoints", { enumerable: true, get: function () { return endpoints_js_1.configureEndpoints; } });
|
|
29
|
+
Object.defineProperty(exports, "ENDPOINTS_STORAGE_KEY", { enumerable: true, get: function () { return endpoints_js_1.ENDPOINTS_STORAGE_KEY; } });
|
|
30
|
+
Object.defineProperty(exports, "entries", { enumerable: true, get: function () { return endpoints_js_1.entries; } });
|
|
31
|
+
Object.defineProperty(exports, "get", { enumerable: true, get: function () { return endpoints_js_1.get; } });
|
|
32
|
+
Object.defineProperty(exports, "getSnapshot", { enumerable: true, get: function () { return endpoints_js_1.getSnapshot; } });
|
|
33
|
+
Object.defineProperty(exports, "hasDefault", { enumerable: true, get: function () { return endpoints_js_1.hasDefault; } });
|
|
34
|
+
Object.defineProperty(exports, "key", { enumerable: true, get: function () { return endpoints_js_1.key; } });
|
|
35
|
+
Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return endpoints_js_1.parse; } });
|
|
36
|
+
Object.defineProperty(exports, "productionSeed", { enumerable: true, get: function () { return endpoints_js_1.productionSeed; } });
|
|
37
|
+
Object.defineProperty(exports, "remove", { enumerable: true, get: function () { return endpoints_js_1.remove; } });
|
|
38
|
+
Object.defineProperty(exports, "restoreDefault", { enumerable: true, get: function () { return endpoints_js_1.restoreDefault; } });
|
|
39
|
+
Object.defineProperty(exports, "setEndpoints", { enumerable: true, get: function () { return endpoints_js_1.setEndpoints; } });
|
|
40
|
+
Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return endpoints_js_1.stringify; } });
|
|
41
|
+
Object.defineProperty(exports, "subscribe", { enumerable: true, get: function () { return endpoints_js_1.subscribe; } });
|
|
42
|
+
Object.defineProperty(exports, "testnetSeed", { enumerable: true, get: function () { return endpoints_js_1.testnetSeed; } });
|
|
43
|
+
Object.defineProperty(exports, "update", { enumerable: true, get: function () { return endpoints_js_1.update; } });
|
|
44
|
+
var image_js_1 = require("./image.js");
|
|
45
|
+
Object.defineProperty(exports, "chainLogoUrl", { enumerable: true, get: function () { return image_js_1.chainLogoUrl; } });
|
|
46
|
+
Object.defineProperty(exports, "relayChainIconUrl", { enumerable: true, get: function () { return image_js_1.relayChainIconUrl; } });
|
|
47
|
+
var networks_js_1 = require("./networks.js");
|
|
48
|
+
Object.defineProperty(exports, "evmChains", { enumerable: true, get: function () { return networks_js_1.evmChains; } });
|
|
49
|
+
Object.defineProperty(exports, "evmChainsById", { enumerable: true, get: function () { return networks_js_1.evmChainsById; } });
|
|
50
|
+
Object.defineProperty(exports, "isSupportedEvmChain", { enumerable: true, get: function () { return networks_js_1.isSupportedEvmChain; } });
|
|
51
|
+
var token_metadata_js_1 = require("./token-metadata.js");
|
|
52
|
+
Object.defineProperty(exports, "getBridgeTokenMetadata", { enumerable: true, get: function () { return token_metadata_js_1.getBridgeTokenMetadata; } });
|
|
53
|
+
Object.defineProperty(exports, "getStoreKey", { enumerable: true, get: function () { return token_metadata_js_1.getStoreKey; } });
|
|
54
|
+
Object.defineProperty(exports, "getStoreSize", { enumerable: true, get: function () { return token_metadata_js_1.getStoreSize; } });
|
|
55
|
+
Object.defineProperty(exports, "getTokenAddressFromBridge", { enumerable: true, get: function () { return token_metadata_js_1.getTokenAddressFromBridge; } });
|
|
56
|
+
Object.defineProperty(exports, "getTokenChainIdFromBridge", { enumerable: true, get: function () { return token_metadata_js_1.getTokenChainIdFromBridge; } });
|
|
57
|
+
Object.defineProperty(exports, "getTokenMetadata", { enumerable: true, get: function () { return token_metadata_js_1.getTokenMetadata; } });
|
|
58
|
+
Object.defineProperty(exports, "loadTokenMetadata", { enumerable: true, get: function () { return token_metadata_js_1.loadTokenMetadata; } });
|
|
59
|
+
Object.defineProperty(exports, "parseChainScopedAddress", { enumerable: true, get: function () { return token_metadata_js_1.parseChainScopedAddress; } });
|
|
60
|
+
Object.defineProperty(exports, "parseTokenKey", { enumerable: true, get: function () { return token_metadata_js_1.parseTokenKey; } });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Chain } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Every Ethereum-Virtual-Machine chain this client can build a public client for.
|
|
4
|
+
*
|
|
5
|
+
* The leading entries are the bridge's own chains; the rest are the routing
|
|
6
|
+
* destinations reachable through the aggregators. Ordering is preserved because
|
|
7
|
+
* chain pickers render it directly.
|
|
8
|
+
*
|
|
9
|
+
* Solana and Bitcoin are deliberately absent. They are supported ORIGINS, but
|
|
10
|
+
* they are not Ethereum-style chains: they are keyed by a genesis hash and by
|
|
11
|
+
* their own string rather than by a number, and nothing here can build a client
|
|
12
|
+
* for them. Anything wallet-facing that needs them keys off the aggregator's
|
|
13
|
+
* chain identifiers instead.
|
|
14
|
+
*/
|
|
15
|
+
export declare const evmChains: readonly Chain[];
|
|
16
|
+
/**
|
|
17
|
+
* Lookup from a chain id to its viem chain definition, for supported chains only.
|
|
18
|
+
*
|
|
19
|
+
* Keyed as `string | number` because callers hold ids that have been through a
|
|
20
|
+
* url, a wallet, or a quote response, and a lookup that silently misses on a
|
|
21
|
+
* numeric-versus-string mismatch reads as "chain not supported".
|
|
22
|
+
*/
|
|
23
|
+
export declare const evmChainsById: Map<string | number, Chain>;
|
|
24
|
+
/**
|
|
25
|
+
* Whether this client can reach a chain over Ethereum-style remote procedure calls.
|
|
26
|
+
*
|
|
27
|
+
* @param chainId - the chain id to test
|
|
28
|
+
* @returns true when the chain has a definition here
|
|
29
|
+
*/
|
|
30
|
+
export declare const isSupportedEvmChain: (chainId: number) => boolean;
|