@gibs/bridge-client 1.28.3 → 1.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/block-polling/package.json +6 -0
- package/dist/block-polling.d.ts +33 -0
- package/dist/block-polling.js +10 -0
- package/dist/cjs/block-polling.d.ts +33 -0
- package/dist/cjs/block-polling.js +15 -0
- package/dist/cjs/image.d.ts +18 -0
- package/dist/cjs/image.js +11 -9
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +9 -1
- package/dist/cjs/unlisted-token.d.ts +26 -0
- package/dist/cjs/unlisted-token.js +34 -0
- package/dist/image.d.ts +18 -0
- package/dist/image.js +8 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/unlisted-token.d.ts +26 -0
- package/dist/unlisted-token.js +30 -0
- package/llms.txt +1 -0
- package/package.json +61 -5
- package/unlisted-token/package.json +6 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** The shortest gap between two block reads, which is also what a fast chain gets. */
|
|
2
|
+
export declare const MINIMUM_BLOCK_POLL_MS = 4000;
|
|
3
|
+
/** The longest gap between two block reads, so a slow chain still looks live. */
|
|
4
|
+
export declare const MAXIMUM_BLOCK_POLL_MS = 12000;
|
|
5
|
+
/**
|
|
6
|
+
* Block time, in milliseconds, of the chains a bridge page watches most. The
|
|
7
|
+
* chain table carries no block time, so `client.chain` cannot answer. A chain
|
|
8
|
+
* missing here is read every four seconds.
|
|
9
|
+
*/
|
|
10
|
+
export declare const blockTimeMsByChainId: Readonly<Record<number, number>>;
|
|
11
|
+
/**
|
|
12
|
+
* How often to ask a chain for its latest block: once per block, kept between
|
|
13
|
+
* 4 and 12 seconds.
|
|
14
|
+
*
|
|
15
|
+
* WHY. viem polls at half the block time, capped at 4 seconds. PulseChain
|
|
16
|
+
* (10 seconds a block) and Ethereum (12 seconds) were read two to three times
|
|
17
|
+
* per block, and the extra reads were the largest share of the traffic a
|
|
18
|
+
* resting page sent to the shared nodes. These blocks feed the base fee shown
|
|
19
|
+
* in a fee estimate. A block that is one block old changes that figure by a
|
|
20
|
+
* few percent at most.
|
|
21
|
+
*
|
|
22
|
+
* @param blockTimeMs - the chain's block time in milliseconds, when known
|
|
23
|
+
* @returns the polling interval in milliseconds
|
|
24
|
+
*/
|
|
25
|
+
export declare const blockPollIntervalMs: (blockTimeMs: number | undefined) => number;
|
|
26
|
+
/**
|
|
27
|
+
* The block polling interval for a chain, from {@link blockTimeMsByChainId}.
|
|
28
|
+
* Pass it as viem's `pollingInterval` to `watchBlocks`.
|
|
29
|
+
*
|
|
30
|
+
* @param chainId - the decimal chain id
|
|
31
|
+
* @returns the polling interval in milliseconds
|
|
32
|
+
*/
|
|
33
|
+
export declare const blockPollIntervalForChain: (chainId: number) => number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const MINIMUM_BLOCK_POLL_MS = 4_000;
|
|
2
|
+
export const MAXIMUM_BLOCK_POLL_MS = 12_000;
|
|
3
|
+
export const blockTimeMsByChainId = Object.freeze({
|
|
4
|
+
1: 12_000,
|
|
5
|
+
369: 10_000,
|
|
6
|
+
943: 10_000,
|
|
7
|
+
11155111: 12_000,
|
|
8
|
+
});
|
|
9
|
+
export const blockPollIntervalMs = (blockTimeMs) => Math.min(Math.max(blockTimeMs ?? MINIMUM_BLOCK_POLL_MS, MINIMUM_BLOCK_POLL_MS), MAXIMUM_BLOCK_POLL_MS);
|
|
10
|
+
export const blockPollIntervalForChain = (chainId) => blockPollIntervalMs(blockTimeMsByChainId[chainId]);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** The shortest gap between two block reads, which is also what a fast chain gets. */
|
|
2
|
+
export declare const MINIMUM_BLOCK_POLL_MS = 4000;
|
|
3
|
+
/** The longest gap between two block reads, so a slow chain still looks live. */
|
|
4
|
+
export declare const MAXIMUM_BLOCK_POLL_MS = 12000;
|
|
5
|
+
/**
|
|
6
|
+
* Block time, in milliseconds, of the chains a bridge page watches most. The
|
|
7
|
+
* chain table carries no block time, so `client.chain` cannot answer. A chain
|
|
8
|
+
* missing here is read every four seconds.
|
|
9
|
+
*/
|
|
10
|
+
export declare const blockTimeMsByChainId: Readonly<Record<number, number>>;
|
|
11
|
+
/**
|
|
12
|
+
* How often to ask a chain for its latest block: once per block, kept between
|
|
13
|
+
* 4 and 12 seconds.
|
|
14
|
+
*
|
|
15
|
+
* WHY. viem polls at half the block time, capped at 4 seconds. PulseChain
|
|
16
|
+
* (10 seconds a block) and Ethereum (12 seconds) were read two to three times
|
|
17
|
+
* per block, and the extra reads were the largest share of the traffic a
|
|
18
|
+
* resting page sent to the shared nodes. These blocks feed the base fee shown
|
|
19
|
+
* in a fee estimate. A block that is one block old changes that figure by a
|
|
20
|
+
* few percent at most.
|
|
21
|
+
*
|
|
22
|
+
* @param blockTimeMs - the chain's block time in milliseconds, when known
|
|
23
|
+
* @returns the polling interval in milliseconds
|
|
24
|
+
*/
|
|
25
|
+
export declare const blockPollIntervalMs: (blockTimeMs: number | undefined) => number;
|
|
26
|
+
/**
|
|
27
|
+
* The block polling interval for a chain, from {@link blockTimeMsByChainId}.
|
|
28
|
+
* Pass it as viem's `pollingInterval` to `watchBlocks`.
|
|
29
|
+
*
|
|
30
|
+
* @param chainId - the decimal chain id
|
|
31
|
+
* @returns the polling interval in milliseconds
|
|
32
|
+
*/
|
|
33
|
+
export declare const blockPollIntervalForChain: (chainId: number) => number;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.blockPollIntervalForChain = exports.blockPollIntervalMs = exports.blockTimeMsByChainId = exports.MAXIMUM_BLOCK_POLL_MS = exports.MINIMUM_BLOCK_POLL_MS = void 0;
|
|
4
|
+
exports.MINIMUM_BLOCK_POLL_MS = 4_000;
|
|
5
|
+
exports.MAXIMUM_BLOCK_POLL_MS = 12_000;
|
|
6
|
+
exports.blockTimeMsByChainId = Object.freeze({
|
|
7
|
+
1: 12_000,
|
|
8
|
+
369: 10_000,
|
|
9
|
+
943: 10_000,
|
|
10
|
+
11155111: 12_000,
|
|
11
|
+
});
|
|
12
|
+
const blockPollIntervalMs = (blockTimeMs) => Math.min(Math.max(blockTimeMs ?? exports.MINIMUM_BLOCK_POLL_MS, exports.MINIMUM_BLOCK_POLL_MS), exports.MAXIMUM_BLOCK_POLL_MS);
|
|
13
|
+
exports.blockPollIntervalMs = blockPollIntervalMs;
|
|
14
|
+
const blockPollIntervalForChain = (chainId) => (0, exports.blockPollIntervalMs)(exports.blockTimeMsByChainId[chainId]);
|
|
15
|
+
exports.blockPollIntervalForChain = blockPollIntervalForChain;
|
package/dist/cjs/image.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as imageLinks from '@gibs/bridge-sdk/image-links';
|
|
1
2
|
/**
|
|
2
3
|
* Chain-logo resolution, in one place.
|
|
3
4
|
*
|
|
@@ -47,6 +48,23 @@ export declare const chainLogoUrl: ({ chainId, displayPx, }: {
|
|
|
47
48
|
chainId: number;
|
|
48
49
|
displayPx?: number;
|
|
49
50
|
}) => string;
|
|
51
|
+
/**
|
|
52
|
+
* The other chain a native coin comes from, or null when the coin is at home
|
|
53
|
+
* (or the chain is not in the table).
|
|
54
|
+
*
|
|
55
|
+
* @param chainId - the chain the coin is being shown on
|
|
56
|
+
* @returns the home chain id, or null
|
|
57
|
+
*/
|
|
58
|
+
export declare const nativeHomeChainOf: (chainId: number) => number | null;
|
|
59
|
+
/**
|
|
60
|
+
* The picture url of any token, for every surface that draws one: the single
|
|
61
|
+
* pure {@link imageLinks.tokenImageUrl} plus the one fact it cannot know itself,
|
|
62
|
+
* where a native coin comes from.
|
|
63
|
+
*
|
|
64
|
+
* @param token - what is known about the token
|
|
65
|
+
* @returns the image url
|
|
66
|
+
*/
|
|
67
|
+
export declare const tokenImage: (token: Omit<imageLinks.TokenImageInput, "nativeHomeChainId">) => string;
|
|
50
68
|
/**
|
|
51
69
|
* The gib.show sources for a chain's NATIVE COIN, best first.
|
|
52
70
|
*
|
package/dist/cjs/image.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.nativeCoinLogoUrl = exports.nativeCoinImageSources = exports.chainLogoUrl = exports.relayChainIconUrl = void 0;
|
|
36
|
+
exports.nativeCoinLogoUrl = exports.nativeCoinImageSources = exports.tokenImage = exports.nativeHomeChainOf = exports.chainLogoUrl = exports.relayChainIconUrl = void 0;
|
|
37
37
|
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");
|
|
@@ -64,16 +64,18 @@ const chainLogoUrl = ({ chainId, displayPx, }) => {
|
|
|
64
64
|
exports.chainLogoUrl = chainLogoUrl;
|
|
65
65
|
const homeChainOfSymbol = new Map([...chain_table_js_1.chainTable].reverse().map((entry) => [entry.nativeCurrency.symbol, entry.id]));
|
|
66
66
|
const symbolOfChain = new Map(chain_table_js_1.chainTable.map((entry) => [entry.id, entry.nativeCurrency.symbol]));
|
|
67
|
-
const
|
|
68
|
-
const sources = [`${chainId}/${viem_1.zeroAddress}`];
|
|
67
|
+
const nativeHomeChainOf = (chainId) => {
|
|
69
68
|
const symbol = symbolOfChain.get(chainId);
|
|
70
69
|
const home = symbol === undefined ? undefined : homeChainOfSymbol.get(symbol);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
return home === undefined || home === chainId ? null : home;
|
|
71
|
+
};
|
|
72
|
+
exports.nativeHomeChainOf = nativeHomeChainOf;
|
|
73
|
+
const tokenImage = (token) => imageLinks.tokenImageUrl({ ...token, nativeHomeChainId: (0, exports.nativeHomeChainOf)(Number(token.chainId)) });
|
|
74
|
+
exports.tokenImage = tokenImage;
|
|
75
|
+
const nativeCoinImageSources = (chainId) => {
|
|
76
|
+
const home = (0, exports.nativeHomeChainOf)(chainId);
|
|
77
|
+
return [`${chainId}/${viem_1.zeroAddress}`, ...(home === null ? [] : [`${home}/${viem_1.zeroAddress}`]), `${chainId}/`];
|
|
76
78
|
};
|
|
77
79
|
exports.nativeCoinImageSources = nativeCoinImageSources;
|
|
78
|
-
const nativeCoinLogoUrl = (chainId) =>
|
|
80
|
+
const nativeCoinLogoUrl = (chainId) => (0, exports.tokenImage)({ chainId, address: viem_1.zeroAddress });
|
|
79
81
|
exports.nativeCoinLogoUrl = nativeCoinLogoUrl;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* `/endpoints`, `/image` and so on — so that importing one does not pull the
|
|
14
14
|
* rest. This barrel exists for consumers that would rather not think about it.
|
|
15
15
|
*/
|
|
16
|
+
export { blockPollIntervalForChain, blockPollIntervalMs, blockTimeMsByChainId, MAXIMUM_BLOCK_POLL_MS, MINIMUM_BLOCK_POLL_MS, } from './block-polling.js';
|
|
16
17
|
export { Cache } from './cache.js';
|
|
17
18
|
export { checkAllowance, type ApprovalParameters } from './chain-read.js';
|
|
18
19
|
export { clientFromChain, rpcBatchSetting } from './client.js';
|
|
@@ -20,3 +21,4 @@ export { add, configureEndpoints, ENDPOINTS_STORAGE_KEY, entries, get, getSnapsh
|
|
|
20
21
|
export { chainLogoUrl, relayChainIconUrl } from './image.js';
|
|
21
22
|
export { evmChains, evmChainsById, isSupportedEvmChain } from './networks.js';
|
|
22
23
|
export { getBridgeTokenMetadata, getStoreKey, getStoreSize, getTokenAddressFromBridge, getTokenChainIdFromBridge, getTokenMetadata, loadTokenMetadata, parseChainScopedAddress, parseTokenKey, type ChainScopedAddress, } from './token-metadata.js';
|
|
24
|
+
export { readUnlistedToken } from './unlisted-token.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
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;
|
|
3
|
+
exports.readUnlistedToken = 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 = exports.MINIMUM_BLOCK_POLL_MS = exports.MAXIMUM_BLOCK_POLL_MS = exports.blockTimeMsByChainId = exports.blockPollIntervalMs = exports.blockPollIntervalForChain = void 0;
|
|
4
|
+
var block_polling_js_1 = require("./block-polling.js");
|
|
5
|
+
Object.defineProperty(exports, "blockPollIntervalForChain", { enumerable: true, get: function () { return block_polling_js_1.blockPollIntervalForChain; } });
|
|
6
|
+
Object.defineProperty(exports, "blockPollIntervalMs", { enumerable: true, get: function () { return block_polling_js_1.blockPollIntervalMs; } });
|
|
7
|
+
Object.defineProperty(exports, "blockTimeMsByChainId", { enumerable: true, get: function () { return block_polling_js_1.blockTimeMsByChainId; } });
|
|
8
|
+
Object.defineProperty(exports, "MAXIMUM_BLOCK_POLL_MS", { enumerable: true, get: function () { return block_polling_js_1.MAXIMUM_BLOCK_POLL_MS; } });
|
|
9
|
+
Object.defineProperty(exports, "MINIMUM_BLOCK_POLL_MS", { enumerable: true, get: function () { return block_polling_js_1.MINIMUM_BLOCK_POLL_MS; } });
|
|
4
10
|
var cache_js_1 = require("./cache.js");
|
|
5
11
|
Object.defineProperty(exports, "Cache", { enumerable: true, get: function () { return cache_js_1.Cache; } });
|
|
6
12
|
var chain_read_js_1 = require("./chain-read.js");
|
|
@@ -43,3 +49,5 @@ Object.defineProperty(exports, "getTokenMetadata", { enumerable: true, get: func
|
|
|
43
49
|
Object.defineProperty(exports, "loadTokenMetadata", { enumerable: true, get: function () { return token_metadata_js_1.loadTokenMetadata; } });
|
|
44
50
|
Object.defineProperty(exports, "parseChainScopedAddress", { enumerable: true, get: function () { return token_metadata_js_1.parseChainScopedAddress; } });
|
|
45
51
|
Object.defineProperty(exports, "parseTokenKey", { enumerable: true, get: function () { return token_metadata_js_1.parseTokenKey; } });
|
|
52
|
+
var unlisted_token_js_1 = require("./unlisted-token.js");
|
|
53
|
+
Object.defineProperty(exports, "readUnlistedToken", { enumerable: true, get: function () { return unlisted_token_js_1.readUnlistedToken; } });
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Token } from '@gibs/bridge-sdk/types';
|
|
2
|
+
import { type PublicClient } from 'viem';
|
|
3
|
+
/**
|
|
4
|
+
* Reads the name, symbol and decimals of a token that no token list carries.
|
|
5
|
+
* The read is one multicall on the token's own chain.
|
|
6
|
+
*
|
|
7
|
+
* The logo comes from the one image builder (`tokenImage`), never a hand-built
|
|
8
|
+
* url: the token's own picture first, then the token it pairs with. An
|
|
9
|
+
* unlisted bridged copy rarely has a picture of its own.
|
|
10
|
+
*
|
|
11
|
+
* @param params.chainId - the decimal chain id of the token
|
|
12
|
+
* @param params.address - the token address, or null
|
|
13
|
+
* @param params.counterpart - the token this one pairs with, used as the image
|
|
14
|
+
* fallback, or null
|
|
15
|
+
* @param params.client - a public client on the token's own chain
|
|
16
|
+
* @returns the token, or null when there is no address or the read fails
|
|
17
|
+
*/
|
|
18
|
+
export declare const readUnlistedToken: ({ chainId, address, counterpart, client, }: {
|
|
19
|
+
chainId: number;
|
|
20
|
+
address: string | null;
|
|
21
|
+
counterpart: {
|
|
22
|
+
chainId: number;
|
|
23
|
+
address: string;
|
|
24
|
+
} | null;
|
|
25
|
+
client: PublicClient;
|
|
26
|
+
}) => Promise<Token | null>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readUnlistedToken = void 0;
|
|
4
|
+
const chains_1 = require("@gibs/bridge-sdk/chains");
|
|
5
|
+
const config_1 = require("@gibs/bridge-sdk/config");
|
|
6
|
+
const erc20_1 = require("@gibs/common/erc20");
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const image_js_1 = require("./image.js");
|
|
9
|
+
const readUnlistedToken = async ({ chainId, address, counterpart, client, }) => {
|
|
10
|
+
if (!address)
|
|
11
|
+
return null;
|
|
12
|
+
const checksummed = (0, viem_1.getAddress)(address);
|
|
13
|
+
const metadata = await (0, erc20_1.multicallErc20)({
|
|
14
|
+
client,
|
|
15
|
+
chain: chains_1.chainsMetadata[(0, config_1.toChain)(chainId)],
|
|
16
|
+
target: checksummed,
|
|
17
|
+
}).catch(() => null);
|
|
18
|
+
if (!metadata)
|
|
19
|
+
return null;
|
|
20
|
+
const [name, symbol, decimals] = metadata;
|
|
21
|
+
return {
|
|
22
|
+
name,
|
|
23
|
+
symbol,
|
|
24
|
+
decimals,
|
|
25
|
+
chainId,
|
|
26
|
+
address: checksummed,
|
|
27
|
+
logoURI: (0, image_js_1.tokenImage)({
|
|
28
|
+
chainId,
|
|
29
|
+
address: checksummed,
|
|
30
|
+
counterparts: counterpart ? [counterpart] : null,
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
exports.readUnlistedToken = readUnlistedToken;
|
package/dist/image.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as imageLinks from '@gibs/bridge-sdk/image-links';
|
|
1
2
|
/**
|
|
2
3
|
* Chain-logo resolution, in one place.
|
|
3
4
|
*
|
|
@@ -47,6 +48,23 @@ export declare const chainLogoUrl: ({ chainId, displayPx, }: {
|
|
|
47
48
|
chainId: number;
|
|
48
49
|
displayPx?: number;
|
|
49
50
|
}) => string;
|
|
51
|
+
/**
|
|
52
|
+
* The other chain a native coin comes from, or null when the coin is at home
|
|
53
|
+
* (or the chain is not in the table).
|
|
54
|
+
*
|
|
55
|
+
* @param chainId - the chain the coin is being shown on
|
|
56
|
+
* @returns the home chain id, or null
|
|
57
|
+
*/
|
|
58
|
+
export declare const nativeHomeChainOf: (chainId: number) => number | null;
|
|
59
|
+
/**
|
|
60
|
+
* The picture url of any token, for every surface that draws one: the single
|
|
61
|
+
* pure {@link imageLinks.tokenImageUrl} plus the one fact it cannot know itself,
|
|
62
|
+
* where a native coin comes from.
|
|
63
|
+
*
|
|
64
|
+
* @param token - what is known about the token
|
|
65
|
+
* @returns the image url
|
|
66
|
+
*/
|
|
67
|
+
export declare const tokenImage: (token: Omit<imageLinks.TokenImageInput, "nativeHomeChainId">) => string;
|
|
50
68
|
/**
|
|
51
69
|
* The gib.show sources for a chain's NATIVE COIN, best first.
|
|
52
70
|
*
|
package/dist/image.js
CHANGED
|
@@ -26,14 +26,14 @@ export const chainLogoUrl = ({ chainId, displayPx, }) => {
|
|
|
26
26
|
};
|
|
27
27
|
const homeChainOfSymbol = new Map([...chainTable].reverse().map((entry) => [entry.nativeCurrency.symbol, entry.id]));
|
|
28
28
|
const symbolOfChain = new Map(chainTable.map((entry) => [entry.id, entry.nativeCurrency.symbol]));
|
|
29
|
-
export const
|
|
30
|
-
const sources = [`${chainId}/${zeroAddress}`];
|
|
29
|
+
export const nativeHomeChainOf = (chainId) => {
|
|
31
30
|
const symbol = symbolOfChain.get(chainId);
|
|
32
31
|
const home = symbol === undefined ? undefined : homeChainOfSymbol.get(symbol);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
return home === undefined || home === chainId ? null : home;
|
|
33
|
+
};
|
|
34
|
+
export const tokenImage = (token) => imageLinks.tokenImageUrl({ ...token, nativeHomeChainId: nativeHomeChainOf(Number(token.chainId)) });
|
|
35
|
+
export const nativeCoinImageSources = (chainId) => {
|
|
36
|
+
const home = nativeHomeChainOf(chainId);
|
|
37
|
+
return [`${chainId}/${zeroAddress}`, ...(home === null ? [] : [`${home}/${zeroAddress}`]), `${chainId}/`];
|
|
38
38
|
};
|
|
39
|
-
export const nativeCoinLogoUrl = (chainId) =>
|
|
39
|
+
export const nativeCoinLogoUrl = (chainId) => tokenImage({ chainId, address: zeroAddress });
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* `/endpoints`, `/image` and so on — so that importing one does not pull the
|
|
14
14
|
* rest. This barrel exists for consumers that would rather not think about it.
|
|
15
15
|
*/
|
|
16
|
+
export { blockPollIntervalForChain, blockPollIntervalMs, blockTimeMsByChainId, MAXIMUM_BLOCK_POLL_MS, MINIMUM_BLOCK_POLL_MS, } from './block-polling.js';
|
|
16
17
|
export { Cache } from './cache.js';
|
|
17
18
|
export { checkAllowance, type ApprovalParameters } from './chain-read.js';
|
|
18
19
|
export { clientFromChain, rpcBatchSetting } from './client.js';
|
|
@@ -20,3 +21,4 @@ export { add, configureEndpoints, ENDPOINTS_STORAGE_KEY, entries, get, getSnapsh
|
|
|
20
21
|
export { chainLogoUrl, relayChainIconUrl } from './image.js';
|
|
21
22
|
export { evmChains, evmChainsById, isSupportedEvmChain } from './networks.js';
|
|
22
23
|
export { getBridgeTokenMetadata, getStoreKey, getStoreSize, getTokenAddressFromBridge, getTokenChainIdFromBridge, getTokenMetadata, loadTokenMetadata, parseChainScopedAddress, parseTokenKey, type ChainScopedAddress, } from './token-metadata.js';
|
|
24
|
+
export { readUnlistedToken } from './unlisted-token.js';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { blockPollIntervalForChain, blockPollIntervalMs, blockTimeMsByChainId, MAXIMUM_BLOCK_POLL_MS, MINIMUM_BLOCK_POLL_MS, } from './block-polling.js';
|
|
1
2
|
export { Cache } from './cache.js';
|
|
2
3
|
export { checkAllowance } from './chain-read.js';
|
|
3
4
|
export { clientFromChain, rpcBatchSetting } from './client.js';
|
|
@@ -5,3 +6,4 @@ export { add, configureEndpoints, ENDPOINTS_STORAGE_KEY, entries, get, getSnapsh
|
|
|
5
6
|
export { chainLogoUrl, relayChainIconUrl } from './image.js';
|
|
6
7
|
export { evmChains, evmChainsById, isSupportedEvmChain } from './networks.js';
|
|
7
8
|
export { getBridgeTokenMetadata, getStoreKey, getStoreSize, getTokenAddressFromBridge, getTokenChainIdFromBridge, getTokenMetadata, loadTokenMetadata, parseChainScopedAddress, parseTokenKey, } from './token-metadata.js';
|
|
9
|
+
export { readUnlistedToken } from './unlisted-token.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Token } from '@gibs/bridge-sdk/types';
|
|
2
|
+
import { type PublicClient } from 'viem';
|
|
3
|
+
/**
|
|
4
|
+
* Reads the name, symbol and decimals of a token that no token list carries.
|
|
5
|
+
* The read is one multicall on the token's own chain.
|
|
6
|
+
*
|
|
7
|
+
* The logo comes from the one image builder (`tokenImage`), never a hand-built
|
|
8
|
+
* url: the token's own picture first, then the token it pairs with. An
|
|
9
|
+
* unlisted bridged copy rarely has a picture of its own.
|
|
10
|
+
*
|
|
11
|
+
* @param params.chainId - the decimal chain id of the token
|
|
12
|
+
* @param params.address - the token address, or null
|
|
13
|
+
* @param params.counterpart - the token this one pairs with, used as the image
|
|
14
|
+
* fallback, or null
|
|
15
|
+
* @param params.client - a public client on the token's own chain
|
|
16
|
+
* @returns the token, or null when there is no address or the read fails
|
|
17
|
+
*/
|
|
18
|
+
export declare const readUnlistedToken: ({ chainId, address, counterpart, client, }: {
|
|
19
|
+
chainId: number;
|
|
20
|
+
address: string | null;
|
|
21
|
+
counterpart: {
|
|
22
|
+
chainId: number;
|
|
23
|
+
address: string;
|
|
24
|
+
} | null;
|
|
25
|
+
client: PublicClient;
|
|
26
|
+
}) => Promise<Token | null>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { chainsMetadata } from '@gibs/bridge-sdk/chains';
|
|
2
|
+
import { toChain } from '@gibs/bridge-sdk/config';
|
|
3
|
+
import { multicallErc20 } from '@gibs/common/erc20';
|
|
4
|
+
import { getAddress } from 'viem';
|
|
5
|
+
import { tokenImage } from './image.js';
|
|
6
|
+
export const readUnlistedToken = async ({ chainId, address, counterpart, client, }) => {
|
|
7
|
+
if (!address)
|
|
8
|
+
return null;
|
|
9
|
+
const checksummed = getAddress(address);
|
|
10
|
+
const metadata = await multicallErc20({
|
|
11
|
+
client,
|
|
12
|
+
chain: chainsMetadata[toChain(chainId)],
|
|
13
|
+
target: checksummed,
|
|
14
|
+
}).catch(() => null);
|
|
15
|
+
if (!metadata)
|
|
16
|
+
return null;
|
|
17
|
+
const [name, symbol, decimals] = metadata;
|
|
18
|
+
return {
|
|
19
|
+
name,
|
|
20
|
+
symbol,
|
|
21
|
+
decimals,
|
|
22
|
+
chainId,
|
|
23
|
+
address: checksummed,
|
|
24
|
+
logoURI: tokenImage({
|
|
25
|
+
chainId,
|
|
26
|
+
address: checksummed,
|
|
27
|
+
counterparts: counterpart ? [counterpart] : null,
|
|
28
|
+
}),
|
|
29
|
+
};
|
|
30
|
+
};
|
package/llms.txt
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
- `@gibs/bridge-client/networks`: the supported viem chains.
|
|
23
23
|
- `@gibs/bridge-client/image`: chain logo URLs.
|
|
24
24
|
- `@gibs/bridge-client/token-metadata`: token metadata reads and caching.
|
|
25
|
+
- `@gibs/bridge-client/block-polling`: how often to ask a chain for its latest block, once per block.
|
|
25
26
|
- `@gibs/bridge-client/chain-read`: allowance reads.
|
|
26
27
|
- `@gibs/bridge-client/cache`: the `Cache` class.
|
|
27
28
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gibs/bridge-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.1",
|
|
4
4
|
"description": "Browser-side endpoints, clients, and caching for a Gibs Finance bridge interface.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ethereum",
|
|
@@ -273,7 +273,61 @@
|
|
|
273
273
|
"types": "./dist/token-metadata.d.ts",
|
|
274
274
|
"default": "./dist/token-metadata.js"
|
|
275
275
|
},
|
|
276
|
-
"./
|
|
276
|
+
"./unlisted-token": {
|
|
277
|
+
"gibs-source": "./src/unlisted-token.ts",
|
|
278
|
+
"react-native": {
|
|
279
|
+
"import": {
|
|
280
|
+
"types": "./dist/unlisted-token.d.ts",
|
|
281
|
+
"default": "./dist/unlisted-token.js"
|
|
282
|
+
},
|
|
283
|
+
"require": {
|
|
284
|
+
"types": "./dist/cjs/unlisted-token.d.ts",
|
|
285
|
+
"default": "./dist/cjs/unlisted-token.js"
|
|
286
|
+
},
|
|
287
|
+
"default": {
|
|
288
|
+
"types": "./dist/cjs/unlisted-token.d.ts",
|
|
289
|
+
"default": "./dist/cjs/unlisted-token.js"
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
"import": {
|
|
293
|
+
"types": "./dist/unlisted-token.d.ts",
|
|
294
|
+
"default": "./dist/unlisted-token.js"
|
|
295
|
+
},
|
|
296
|
+
"require": {
|
|
297
|
+
"types": "./dist/cjs/unlisted-token.d.ts",
|
|
298
|
+
"default": "./dist/cjs/unlisted-token.js"
|
|
299
|
+
},
|
|
300
|
+
"types": "./dist/unlisted-token.d.ts",
|
|
301
|
+
"default": "./dist/unlisted-token.js"
|
|
302
|
+
},
|
|
303
|
+
"./package.json": "./package.json",
|
|
304
|
+
"./block-polling": {
|
|
305
|
+
"gibs-source": "./src/block-polling.ts",
|
|
306
|
+
"react-native": {
|
|
307
|
+
"import": {
|
|
308
|
+
"types": "./dist/block-polling.d.ts",
|
|
309
|
+
"default": "./dist/block-polling.js"
|
|
310
|
+
},
|
|
311
|
+
"require": {
|
|
312
|
+
"types": "./dist/cjs/block-polling.d.ts",
|
|
313
|
+
"default": "./dist/cjs/block-polling.js"
|
|
314
|
+
},
|
|
315
|
+
"default": {
|
|
316
|
+
"types": "./dist/cjs/block-polling.d.ts",
|
|
317
|
+
"default": "./dist/cjs/block-polling.js"
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
"import": {
|
|
321
|
+
"types": "./dist/block-polling.d.ts",
|
|
322
|
+
"default": "./dist/block-polling.js"
|
|
323
|
+
},
|
|
324
|
+
"require": {
|
|
325
|
+
"types": "./dist/cjs/block-polling.d.ts",
|
|
326
|
+
"default": "./dist/cjs/block-polling.js"
|
|
327
|
+
},
|
|
328
|
+
"types": "./dist/block-polling.d.ts",
|
|
329
|
+
"default": "./dist/block-polling.js"
|
|
330
|
+
}
|
|
277
331
|
},
|
|
278
332
|
"files": [
|
|
279
333
|
"dist",
|
|
@@ -289,7 +343,9 @@
|
|
|
289
343
|
"endpoints",
|
|
290
344
|
"client",
|
|
291
345
|
"chain-read",
|
|
292
|
-
"token-metadata"
|
|
346
|
+
"token-metadata",
|
|
347
|
+
"block-polling",
|
|
348
|
+
"unlisted-token"
|
|
293
349
|
],
|
|
294
350
|
"scripts": {
|
|
295
351
|
"prepublishOnly": "npx tsc",
|
|
@@ -302,8 +358,8 @@
|
|
|
302
358
|
"test:watch": "vitest"
|
|
303
359
|
},
|
|
304
360
|
"dependencies": {
|
|
305
|
-
"@gibs/bridge-sdk": "^1.
|
|
306
|
-
"@gibs/common": "^1.
|
|
361
|
+
"@gibs/bridge-sdk": "^1.30.1",
|
|
362
|
+
"@gibs/common": "^1.30.1"
|
|
307
363
|
},
|
|
308
364
|
"peerDependencies": {
|
|
309
365
|
"viem": ">=2.35.0 <3"
|