@gibs/bridge-client 1.29.0 → 1.32.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/block-polling/package.json +6 -0
- package/coinbase-accept-list/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/client.d.ts +9 -1
- package/dist/cjs/client.js +8 -5
- package/dist/cjs/coinbase-accept-list.d.ts +101 -0
- package/dist/cjs/coinbase-accept-list.js +97 -0
- package/dist/cjs/crossing-decision.d.ts +166 -0
- package/dist/cjs/crossing-decision.js +169 -0
- package/dist/cjs/crossing-vector-guard.d.ts +45 -0
- package/dist/cjs/crossing-vector-guard.js +139 -0
- package/dist/cjs/exchange-deposit-board.d.ts +50 -0
- package/dist/cjs/exchange-deposit-board.js +70 -0
- package/dist/cjs/exchange-deposit-chain.d.ts +146 -0
- package/dist/cjs/exchange-deposit-chain.js +228 -0
- package/dist/cjs/exchange-deposit-constants.d.ts +10 -0
- package/dist/cjs/exchange-deposit-constants.js +6 -0
- package/dist/cjs/exchange-deposit-factory-calls.d.ts +245 -0
- package/dist/cjs/exchange-deposit-factory-calls.js +103 -0
- package/dist/cjs/exchange-deposit-factory.d.ts +87 -0
- package/dist/cjs/exchange-deposit-factory.js +110 -0
- package/dist/cjs/exchange-deposit-fake.d.ts +67 -0
- package/dist/cjs/exchange-deposit-fake.js +179 -0
- package/dist/cjs/exchange-deposit-index.d.ts +77 -0
- package/dist/cjs/exchange-deposit-index.js +40 -0
- package/dist/cjs/exchange-deposit-issuance.d.ts +327 -0
- package/dist/cjs/exchange-deposit-issuance.js +244 -0
- package/dist/cjs/exchange-deposit-path.d.ts +16 -0
- package/dist/cjs/exchange-deposit-path.js +15 -0
- package/dist/cjs/exchange-deposit-pow.d.ts +163 -0
- package/dist/cjs/exchange-deposit-pow.js +101 -0
- package/dist/cjs/exchange-deposit-recipient.d.ts +66 -0
- package/dist/cjs/exchange-deposit-recipient.js +35 -0
- package/dist/cjs/exchange-deposit-self-cross.d.ts +163 -0
- package/dist/cjs/exchange-deposit-self-cross.js +60 -0
- package/dist/cjs/exchange-deposit-signin.d.ts +275 -0
- package/dist/cjs/exchange-deposit-signin.js +166 -0
- package/dist/cjs/exchange-deposit-watch.d.ts +133 -0
- package/dist/cjs/exchange-deposit-watch.js +58 -0
- package/dist/cjs/exchange-deposit.d.ts +440 -0
- package/dist/cjs/exchange-deposit.js +154 -0
- package/dist/cjs/exchange-sender-guides.d.ts +29 -0
- package/dist/cjs/exchange-sender-guides.js +25 -0
- package/dist/cjs/image.d.ts +18 -0
- package/dist/cjs/image.js +11 -9
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +32 -1
- package/dist/cjs/kraken-accept-list.d.ts +70 -0
- package/dist/cjs/kraken-accept-list.js +24 -0
- package/dist/cjs/unlisted-token.d.ts +26 -0
- package/dist/cjs/unlisted-token.js +34 -0
- package/dist/client.d.ts +9 -1
- package/dist/client.js +8 -5
- package/dist/coinbase-accept-list.d.ts +101 -0
- package/dist/coinbase-accept-list.js +89 -0
- package/dist/crossing-decision.d.ts +166 -0
- package/dist/crossing-decision.js +162 -0
- package/dist/crossing-vector-guard.d.ts +45 -0
- package/dist/crossing-vector-guard.js +134 -0
- package/dist/exchange-deposit-board.d.ts +50 -0
- package/dist/exchange-deposit-board.js +28 -0
- package/dist/exchange-deposit-chain.d.ts +146 -0
- package/dist/exchange-deposit-chain.js +218 -0
- package/dist/exchange-deposit-constants.d.ts +10 -0
- package/dist/exchange-deposit-constants.js +3 -0
- package/dist/exchange-deposit-factory-calls.d.ts +245 -0
- package/dist/exchange-deposit-factory-calls.js +97 -0
- package/dist/exchange-deposit-factory.d.ts +87 -0
- package/dist/exchange-deposit-factory.js +104 -0
- package/dist/exchange-deposit-fake.d.ts +67 -0
- package/dist/exchange-deposit-fake.js +171 -0
- package/dist/exchange-deposit-index.d.ts +77 -0
- package/dist/exchange-deposit-index.js +34 -0
- package/dist/exchange-deposit-issuance.d.ts +327 -0
- package/dist/exchange-deposit-issuance.js +224 -0
- package/dist/exchange-deposit-path.d.ts +16 -0
- package/dist/exchange-deposit-path.js +11 -0
- package/dist/exchange-deposit-pow.d.ts +163 -0
- package/dist/exchange-deposit-pow.js +93 -0
- package/dist/exchange-deposit-recipient.d.ts +66 -0
- package/dist/exchange-deposit-recipient.js +28 -0
- package/dist/exchange-deposit-self-cross.d.ts +163 -0
- package/dist/exchange-deposit-self-cross.js +46 -0
- package/dist/exchange-deposit-signin.d.ts +275 -0
- package/dist/exchange-deposit-signin.js +147 -0
- package/dist/exchange-deposit-watch.d.ts +133 -0
- package/dist/exchange-deposit-watch.js +44 -0
- package/dist/exchange-deposit.d.ts +440 -0
- package/dist/exchange-deposit.js +138 -0
- package/dist/exchange-sender-guides.d.ts +29 -0
- package/dist/exchange-sender-guides.js +21 -0
- package/dist/image.d.ts +18 -0
- package/dist/image.js +8 -8
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/kraken-accept-list.d.ts +70 -0
- package/dist/kraken-accept-list.js +17 -0
- package/dist/unlisted-token.d.ts +26 -0
- package/dist/unlisted-token.js +30 -0
- package/exchange-deposit/package.json +6 -0
- package/exchange-deposit-board/package.json +6 -0
- package/exchange-deposit-chain/package.json +6 -0
- package/exchange-deposit-factory/package.json +6 -0
- package/exchange-deposit-fake/package.json +6 -0
- package/exchange-deposit-issuance/package.json +6 -0
- package/exchange-deposit-path/package.json +6 -0
- package/exchange-deposit-pow/package.json +6 -0
- package/exchange-deposit-recipient/package.json +6 -0
- package/exchange-deposit-self-cross/package.json +6 -0
- package/exchange-deposit-signin/package.json +6 -0
- package/exchange-deposit-watch/package.json +6 -0
- package/exchange-sender-guides/package.json +6 -0
- package/kraken-accept-list/package.json +6 -0
- package/llms.txt +1 -0
- package/package.json +487 -6
- 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/client.d.ts
CHANGED
|
@@ -14,6 +14,14 @@ import type { HttpTransportConfig, PublicClient } from 'viem';
|
|
|
14
14
|
* @returns `false` when batching must be disabled, otherwise the batch config
|
|
15
15
|
*/
|
|
16
16
|
export declare const rpcBatchSetting: (chainId: number) => HttpTransportConfig["batch"];
|
|
17
|
+
/** The options of {@link clientFromChain}. */
|
|
18
|
+
export interface ClientFromChainOptions {
|
|
19
|
+
/**
|
|
20
|
+
* The longest one endpoint may take to answer a request before the next endpoint is asked. A reader that must not
|
|
21
|
+
* wait on a dead endpoint sets it. The client is then cached apart from the shared one.
|
|
22
|
+
*/
|
|
23
|
+
readonly attemptTimeoutMs?: number;
|
|
24
|
+
}
|
|
17
25
|
/**
|
|
18
26
|
* Returns a viem {@link PublicClient} for a chain, reusing the cached instance
|
|
19
27
|
* while the chain's endpoint list is unchanged. The cache key is derived from the
|
|
@@ -30,4 +38,4 @@ export declare const rpcBatchSetting: (chainId: number) => HttpTransportConfig["
|
|
|
30
38
|
* @param chainId - the chain to build a client for
|
|
31
39
|
* @returns the cached or freshly built public client
|
|
32
40
|
*/
|
|
33
|
-
export declare const clientFromChain: (chainId: number) => PublicClient;
|
|
41
|
+
export declare const clientFromChain: (chainId: number, options?: ClientFromChainOptions) => PublicClient;
|
package/dist/cjs/client.js
CHANGED
|
@@ -59,18 +59,21 @@ const defaultUrlsFor = (chainId) => {
|
|
|
59
59
|
const { http } = chain.rpcUrls.default;
|
|
60
60
|
return [...(http ?? [])];
|
|
61
61
|
};
|
|
62
|
-
const clientFromChain = (chainId) => {
|
|
62
|
+
const clientFromChain = (chainId, options = {}) => {
|
|
63
63
|
const stored = endpoints.get(chainId);
|
|
64
64
|
const urls = (stored?.length ? stored : defaultUrlsFor(chainId)).filter((url) => Boolean(url));
|
|
65
65
|
const key = (0, client_1.chainKey)(chainId, urls);
|
|
66
|
-
const existing = client_1.clientCache.get(chainId);
|
|
67
|
-
if (existing && existing.key === key) {
|
|
68
|
-
return existing.client;
|
|
69
|
-
}
|
|
70
66
|
const chain = networks_js_1.evmChainsById.get(chainId);
|
|
71
67
|
if (!chain) {
|
|
72
68
|
throw new Error(`Chain ${chainId} is not one of the supported networks.`);
|
|
73
69
|
}
|
|
70
|
+
if (options.attemptTimeoutMs !== undefined) {
|
|
71
|
+
return (0, client_1.clientFromChain)({ chain, urls, batch: (0, exports.rpcBatchSetting)(chainId), attemptTimeoutMs: options.attemptTimeoutMs });
|
|
72
|
+
}
|
|
73
|
+
const existing = client_1.clientCache.get(chainId);
|
|
74
|
+
if (existing && existing.key === key) {
|
|
75
|
+
return existing.client;
|
|
76
|
+
}
|
|
74
77
|
const client = (0, client_1.clientFromChain)({ chain, urls, batch: (0, exports.rpcBatchSetting)(chainId) });
|
|
75
78
|
client_1.clientCache.set(chainId, { key, client });
|
|
76
79
|
return client;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The public currency list of Coinbase's institutional exchange (not the retail Coinbase app). It needs no key and
|
|
3
|
+
* allows any origin. The list says which assets the exchange credits on which networks.
|
|
4
|
+
*/
|
|
5
|
+
export declare const COINBASE_EXCHANGE_CURRENCIES_URL = "https://api.exchange.coinbase.com/currencies";
|
|
6
|
+
/** How long a fetched accept list stays fresh, in milliseconds. */
|
|
7
|
+
export declare const COINBASE_ACCEPT_LIST_TIME_TO_LIVE_MILLISECONDS: number;
|
|
8
|
+
/**
|
|
9
|
+
* One Coinbase exchange network id mapped to the EVM chain it names, and to the currency id that is that chain's
|
|
10
|
+
* gas asset. Only networks checked by hand belong here. Any other network is refused.
|
|
11
|
+
*/
|
|
12
|
+
export interface CoinbaseExchangeNetworkMapping {
|
|
13
|
+
readonly chainId: number;
|
|
14
|
+
readonly nativeCurrencyId: string | null;
|
|
15
|
+
}
|
|
16
|
+
/** The verified Coinbase exchange network ids. Chain 369 (PulseChain) is absent on purpose: the exchange does not list it. */
|
|
17
|
+
export declare const COINBASE_EXCHANGE_NETWORK_MAPPINGS: Readonly<Record<string, CoinbaseExchangeNetworkMapping>>;
|
|
18
|
+
/** One network entry inside a Coinbase exchange currency. Only the fields this module reads are typed. */
|
|
19
|
+
export interface CoinbaseExchangeNetwork {
|
|
20
|
+
readonly id: string;
|
|
21
|
+
readonly status: string;
|
|
22
|
+
readonly contract_address: string | null;
|
|
23
|
+
readonly is_evm_network: boolean;
|
|
24
|
+
readonly destination_tag_regex: string | null;
|
|
25
|
+
}
|
|
26
|
+
/** One currency from the Coinbase exchange currency list. */
|
|
27
|
+
export interface CoinbaseExchangeCurrency {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly status: string;
|
|
30
|
+
readonly supported_networks: readonly CoinbaseExchangeNetwork[];
|
|
31
|
+
}
|
|
32
|
+
/** An asset the exchange credits on one EVM chain. A native asset has no contract address. */
|
|
33
|
+
export type CoinbaseAcceptedAsset = {
|
|
34
|
+
readonly kind: 'native';
|
|
35
|
+
readonly chainId: number;
|
|
36
|
+
readonly currencyId: string;
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: 'token';
|
|
39
|
+
readonly chainId: number;
|
|
40
|
+
readonly currencyId: string;
|
|
41
|
+
/** The contract address in lower case. Matching is by this address, never by symbol. */
|
|
42
|
+
readonly address: string;
|
|
43
|
+
};
|
|
44
|
+
/** The accept list: every asset the exchange credits on a network this interface can route to. */
|
|
45
|
+
export interface CoinbaseAcceptList {
|
|
46
|
+
readonly assets: readonly CoinbaseAcceptedAsset[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Turns one network of one currency into an accepted asset, or `null` when the exchange does not credit it on a
|
|
50
|
+
* network we can route to. Every refusal is a guard clause, in this order: unknown network, non-EVM network, network
|
|
51
|
+
* or currency not online, destination tag required, and an empty address on a currency that is not the chain's gas
|
|
52
|
+
* asset (USDC on Base reports an empty address, but it is an ERC-20 and has no address this module can match).
|
|
53
|
+
*
|
|
54
|
+
* @param currency - One currency from the exchange list.
|
|
55
|
+
* @param network - One network entry of that currency.
|
|
56
|
+
* @returns The accepted asset, or `null` when refused.
|
|
57
|
+
*/
|
|
58
|
+
export declare const acceptedAssetFromExchangeNetwork: (currency: CoinbaseExchangeCurrency, network: CoinbaseExchangeNetwork) => CoinbaseAcceptedAsset | null;
|
|
59
|
+
/**
|
|
60
|
+
* Builds the accept list from a parsed exchange currency list.
|
|
61
|
+
*
|
|
62
|
+
* @param currencies - The currencies from the exchange list.
|
|
63
|
+
* @returns The accept list with every accepted asset.
|
|
64
|
+
*/
|
|
65
|
+
export declare const buildCoinbaseAcceptList: (currencies: readonly CoinbaseExchangeCurrency[]) => CoinbaseAcceptList;
|
|
66
|
+
/**
|
|
67
|
+
* Says whether the exchange credits a route's final asset. The asset is named by chain and contract address, never by
|
|
68
|
+
* symbol. A `null` address means the chain's native asset.
|
|
69
|
+
*
|
|
70
|
+
* @param acceptList - The accept list.
|
|
71
|
+
* @param target - The route's final chain and token address (`null` for native).
|
|
72
|
+
* @returns `true` when the exchange credits exactly that asset on that chain.
|
|
73
|
+
*/
|
|
74
|
+
export declare const isCoinbaseAcceptedDestination: (acceptList: CoinbaseAcceptList, target: {
|
|
75
|
+
readonly chainId: number;
|
|
76
|
+
readonly tokenAddress: string | null;
|
|
77
|
+
}) => boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Reads the exchange response body. It must be an array; anything else throws.
|
|
80
|
+
*
|
|
81
|
+
* @param body - The parsed JSON body.
|
|
82
|
+
* @returns The currency list.
|
|
83
|
+
*/
|
|
84
|
+
export declare const parseCoinbaseExchangeCurrencies: (body: unknown) => readonly CoinbaseExchangeCurrency[];
|
|
85
|
+
/** Options for {@link createCoinbaseAcceptListLoader}. */
|
|
86
|
+
export interface CoinbaseAcceptListLoaderOptions {
|
|
87
|
+
/** The fetch to use. Defaults to the global `fetch`. */
|
|
88
|
+
readonly fetchImplementation?: typeof fetch;
|
|
89
|
+
/** How long a loaded list stays fresh. Defaults to {@link COINBASE_ACCEPT_LIST_TIME_TO_LIVE_MILLISECONDS}. */
|
|
90
|
+
readonly timeToLiveMilliseconds?: number;
|
|
91
|
+
/** The clock. Defaults to `Date.now`. */
|
|
92
|
+
readonly now?: () => number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Makes a loader that fetches the accept list once, then reuses it until it goes stale. Concurrent calls share one
|
|
96
|
+
* request. A failed request is not cached, so the next call retries.
|
|
97
|
+
*
|
|
98
|
+
* @param options - The fetch, the time to live, and the clock.
|
|
99
|
+
* @returns A function that resolves the accept list.
|
|
100
|
+
*/
|
|
101
|
+
export declare const createCoinbaseAcceptListLoader: (options?: CoinbaseAcceptListLoaderOptions) => () => Promise<CoinbaseAcceptList>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCoinbaseAcceptListLoader = exports.parseCoinbaseExchangeCurrencies = exports.isCoinbaseAcceptedDestination = exports.buildCoinbaseAcceptList = exports.acceptedAssetFromExchangeNetwork = exports.COINBASE_EXCHANGE_NETWORK_MAPPINGS = exports.COINBASE_ACCEPT_LIST_TIME_TO_LIVE_MILLISECONDS = exports.COINBASE_EXCHANGE_CURRENCIES_URL = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
exports.COINBASE_EXCHANGE_CURRENCIES_URL = 'https://api.exchange.coinbase.com/currencies';
|
|
6
|
+
exports.COINBASE_ACCEPT_LIST_TIME_TO_LIVE_MILLISECONDS = 10 * 60 * 1000;
|
|
7
|
+
exports.COINBASE_EXCHANGE_NETWORK_MAPPINGS = {
|
|
8
|
+
ethereum: { chainId: 1, nativeCurrencyId: 'ETH' },
|
|
9
|
+
optimism: { chainId: 10, nativeCurrencyId: 'ETH' },
|
|
10
|
+
bsc: { chainId: 56, nativeCurrencyId: 'BNB' },
|
|
11
|
+
polygon: { chainId: 137, nativeCurrencyId: null },
|
|
12
|
+
base: { chainId: 8453, nativeCurrencyId: 'ETH' },
|
|
13
|
+
arbitrum: { chainId: 42161, nativeCurrencyId: 'ETH' },
|
|
14
|
+
};
|
|
15
|
+
const acceptedAssetFromExchangeNetwork = (currency, network) => {
|
|
16
|
+
const mapping = exports.COINBASE_EXCHANGE_NETWORK_MAPPINGS[network.id];
|
|
17
|
+
if (mapping === undefined)
|
|
18
|
+
return null;
|
|
19
|
+
if (!network.is_evm_network)
|
|
20
|
+
return null;
|
|
21
|
+
if (network.status !== 'online' || currency.status !== 'online')
|
|
22
|
+
return null;
|
|
23
|
+
if (network.destination_tag_regex)
|
|
24
|
+
return null;
|
|
25
|
+
const rawAddress = (network.contract_address ?? '').trim();
|
|
26
|
+
const isGasCurrency = mapping.nativeCurrencyId === currency.id;
|
|
27
|
+
if (rawAddress === '') {
|
|
28
|
+
if (!isGasCurrency)
|
|
29
|
+
return null;
|
|
30
|
+
return { kind: 'native', chainId: mapping.chainId, currencyId: currency.id };
|
|
31
|
+
}
|
|
32
|
+
if (!(0, viem_1.isAddress)(rawAddress, { strict: false }))
|
|
33
|
+
return null;
|
|
34
|
+
return {
|
|
35
|
+
kind: 'token',
|
|
36
|
+
chainId: mapping.chainId,
|
|
37
|
+
currencyId: currency.id,
|
|
38
|
+
address: rawAddress.toLowerCase(),
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
exports.acceptedAssetFromExchangeNetwork = acceptedAssetFromExchangeNetwork;
|
|
42
|
+
const buildCoinbaseAcceptList = (currencies) => ({
|
|
43
|
+
assets: currencies.flatMap((currency) => currency.supported_networks.flatMap((network) => {
|
|
44
|
+
const asset = (0, exports.acceptedAssetFromExchangeNetwork)(currency, network);
|
|
45
|
+
return asset === null ? [] : [asset];
|
|
46
|
+
})),
|
|
47
|
+
});
|
|
48
|
+
exports.buildCoinbaseAcceptList = buildCoinbaseAcceptList;
|
|
49
|
+
const isCoinbaseAcceptedDestination = (acceptList, target) => {
|
|
50
|
+
const lowerAddress = target.tokenAddress?.toLowerCase() ?? null;
|
|
51
|
+
return acceptList.assets.some((asset) => {
|
|
52
|
+
if (asset.chainId !== target.chainId)
|
|
53
|
+
return false;
|
|
54
|
+
if (lowerAddress === null)
|
|
55
|
+
return asset.kind === 'native';
|
|
56
|
+
return asset.kind === 'token' && asset.address === lowerAddress;
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
exports.isCoinbaseAcceptedDestination = isCoinbaseAcceptedDestination;
|
|
60
|
+
const parseCoinbaseExchangeCurrencies = (body) => {
|
|
61
|
+
if (!Array.isArray(body))
|
|
62
|
+
throw new Error('Coinbase exchange currency list is not an array');
|
|
63
|
+
return body;
|
|
64
|
+
};
|
|
65
|
+
exports.parseCoinbaseExchangeCurrencies = parseCoinbaseExchangeCurrencies;
|
|
66
|
+
const createCoinbaseAcceptListLoader = (options = {}) => {
|
|
67
|
+
const fetchImplementation = options.fetchImplementation ?? fetch;
|
|
68
|
+
const timeToLiveMilliseconds = options.timeToLiveMilliseconds ?? exports.COINBASE_ACCEPT_LIST_TIME_TO_LIVE_MILLISECONDS;
|
|
69
|
+
const now = options.now ?? Date.now;
|
|
70
|
+
let cached = null;
|
|
71
|
+
let inFlight = null;
|
|
72
|
+
const fetchAcceptList = async () => {
|
|
73
|
+
const response = await fetchImplementation(exports.COINBASE_EXCHANGE_CURRENCIES_URL, {
|
|
74
|
+
headers: { accept: 'application/json' },
|
|
75
|
+
});
|
|
76
|
+
if (!response.ok)
|
|
77
|
+
throw new Error(`Coinbase exchange currency list returned ${response.status}`);
|
|
78
|
+
const currencies = (0, exports.parseCoinbaseExchangeCurrencies)(await response.json());
|
|
79
|
+
return (0, exports.buildCoinbaseAcceptList)(currencies);
|
|
80
|
+
};
|
|
81
|
+
return async () => {
|
|
82
|
+
if (cached !== null && now() - cached.loadedAt < timeToLiveMilliseconds)
|
|
83
|
+
return cached.acceptList;
|
|
84
|
+
if (inFlight !== null)
|
|
85
|
+
return inFlight;
|
|
86
|
+
inFlight = fetchAcceptList().then((acceptList) => {
|
|
87
|
+
cached = { loadedAt: now(), acceptList };
|
|
88
|
+
inFlight = null;
|
|
89
|
+
return acceptList;
|
|
90
|
+
}, (error) => {
|
|
91
|
+
inFlight = null;
|
|
92
|
+
throw error;
|
|
93
|
+
});
|
|
94
|
+
return inFlight;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
exports.createCoinbaseAcceptListLoader = createCoinbaseAcceptListLoader;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crossing decision, spec version 7.0.0. Pure: inputs in, decision out. No input or output, no clock,
|
|
3
|
+
* no floating point. Every integer is a bigint. Every address is lower case 0x hex.
|
|
4
|
+
* One deposit address holds one deposit of one token. The function decides whether to cross it now.
|
|
5
|
+
*/
|
|
6
|
+
/** The spec version this code implements. A vector file with another version must not be run against it. */
|
|
7
|
+
export declare const CROSSING_SPEC_VERSION = "7.0.0";
|
|
8
|
+
/** A lower case 0x hex address, 42 characters. */
|
|
9
|
+
export type Address = string;
|
|
10
|
+
/** The token entry that stands for ether itself. */
|
|
11
|
+
export declare const ETHER_TOKEN: Address;
|
|
12
|
+
/** The gas of one whole flush transaction of one deposit address, 21,000 base gas included. */
|
|
13
|
+
export type GasFigures = {
|
|
14
|
+
/** A flush of a token (USD Coin is the typical one), the first flush of the day, cold: the figure includes the first-flush surcharge (spec, section 3.3). */
|
|
15
|
+
tokenFlushGas: bigint;
|
|
16
|
+
/** A flush of ether, the first flush of the day, cold. It crosses through the wrap router (spec, section 3.3). */
|
|
17
|
+
etherFlushGas: bigint;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The gas model, in two sets. `paid` is the gas after the refund of the cleared storage: use it for income
|
|
21
|
+
* and profit. `beforeRefund` is the gas before that refund: use it for the gas limit and for any check that
|
|
22
|
+
* the sender can afford the transaction, because the node needs that much available while the transaction runs.
|
|
23
|
+
*/
|
|
24
|
+
export type GasModel = {
|
|
25
|
+
paid: GasFigures;
|
|
26
|
+
beforeRefund: GasFigures;
|
|
27
|
+
};
|
|
28
|
+
/** The names of the gas tables. There is one table for each network under each fork of the rules. */
|
|
29
|
+
export declare const GAS_TABLE_NAMES: readonly ["ethereum-prague", "ethereum-glamsterdam", "sepolia-glamsterdam"];
|
|
30
|
+
/** The name of one gas table. */
|
|
31
|
+
export type GasTableName = (typeof GAS_TABLE_NAMES)[number];
|
|
32
|
+
/** One gas table: the figures of one network under one fork of the rules. */
|
|
33
|
+
export type GasTable = {
|
|
34
|
+
/** The only chain id the table may run on. The Ethereum tables are for chain 1, the Sepolia table for 11155111. */
|
|
35
|
+
chainId: bigint;
|
|
36
|
+
gasModel: GasModel;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The gas tables, measured on forks of the real chains (spec, section 3.3) with `measure-gas-anvil.sh`.
|
|
40
|
+
* `ethereum-prague` is the table of today's mainnet; the other two ran under the Amsterdam rules.
|
|
41
|
+
* `ethereum-glamsterdam` is a projection: Glamsterdam is not live on Ethereum yet. Every figure is the
|
|
42
|
+
* worst of the warm and the cold measurement, rounded up to a multiple of 1,000, plus the first-flush surcharge
|
|
43
|
+
* of the network (spec, section 3.3). The token figure is the first flush of an address that was never seeded (the
|
|
44
|
+
* account does not exist when the flush runs CREATE2), the worst case of a single-use address.
|
|
45
|
+
*
|
|
46
|
+
* The surcharge is the cost of the first write of the day to the mediator's daily limit slot. It is measured on
|
|
47
|
+
* `sepolia-glamsterdam`: 97,920 gas (the cold minus the warm USD Coin flush). The Sepolia token figure already contains
|
|
48
|
+
* it, because its cold measurement was taken with an empty slot. Its ether figure did not (the slot was already
|
|
49
|
+
* written when measured), so the surcharge is added to it.
|
|
50
|
+
*
|
|
51
|
+
* The mainnet tables have no direct measurement of a token's surcharge. Their ether figures already hold the cold
|
|
52
|
+
* cost, because the mainnet fork's ether slot was empty when measured. Their token figures add a derived surcharge: the
|
|
53
|
+
* ether cold minus warm delta of the same fork run (17,100 under Prague, 97,920 under Glamsterdam). TODO: confirm on a fork.
|
|
54
|
+
*/
|
|
55
|
+
export declare const GAS_TABLES: Record<GasTableName, GasTable>;
|
|
56
|
+
/**
|
|
57
|
+
* Picks a gas table by name for a chain. There is no default: a caller must name its table. It throws when the
|
|
58
|
+
* name is unknown, and when the table is for another chain than `chainId`, so a Sepolia run can never price
|
|
59
|
+
* with a mainnet table, or the other way round.
|
|
60
|
+
*/
|
|
61
|
+
export declare const gasTableOf: (name: string, chainId: bigint) => GasTable;
|
|
62
|
+
/** The conditions of the moment, set by the executor. */
|
|
63
|
+
export type CrossingConditions = {
|
|
64
|
+
baseFeeWei: bigint;
|
|
65
|
+
priorityFeeWei: bigint;
|
|
66
|
+
/** Wait when the base fee is above this. Null for no ceiling. */
|
|
67
|
+
maximumBaseFeeWei: bigint | null;
|
|
68
|
+
/** The safety multiple in thousandths: 2000 is two times. Must be above zero. */
|
|
69
|
+
safetyMultipleThousandths: bigint;
|
|
70
|
+
/** The `gasModel` of the gas table of the network: take it from `GAS_TABLES`, never from a default. */
|
|
71
|
+
gasModel: GasModel;
|
|
72
|
+
};
|
|
73
|
+
/** One deposit address and the one deposit that waits at it, as read from the chain at one moment. */
|
|
74
|
+
export type DepositInput = {
|
|
75
|
+
/** True when the recipient retired the address. */
|
|
76
|
+
retired: boolean;
|
|
77
|
+
/** True when a crossing of this address is sent and not yet confirmed (ours or seen in the pool). */
|
|
78
|
+
crossingInFlight: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* The gibs fee rate the address committed to, on the 1e18 scale (1e18 is all of it). The ledger takes exactly this
|
|
81
|
+
* share from the delivery. The partner fee is not input: it is never the executor's and it does not change the gibs fee.
|
|
82
|
+
*/
|
|
83
|
+
feeRateE18: bigint;
|
|
84
|
+
/** The token of the deposit. Use ETHER_TOKEN for ether. */
|
|
85
|
+
token: Address;
|
|
86
|
+
/** Decimal places of the token. Use 18 for ether. */
|
|
87
|
+
decimals: bigint;
|
|
88
|
+
/** The balance of the token at the address at the balance block, in base units. For ether, the whole ether balance. */
|
|
89
|
+
balance: bigint;
|
|
90
|
+
/** True when the executor may cross this token on its own. Anyone can send a worthless token to an address. */
|
|
91
|
+
autoCrossAllowed: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Wei of ether that one whole token is worth, at the moment of the decision, from the executor's price
|
|
94
|
+
* source. 10^18 for ether and wrapped ether. Null when no price is known. No price is read on chain.
|
|
95
|
+
*/
|
|
96
|
+
weiPerWholeToken: bigint | null;
|
|
97
|
+
/** The mediator's fee on entering PulseChain, on the 1e18 scale (1e18 is all of it). 0 today. */
|
|
98
|
+
entryFeeWad: bigint;
|
|
99
|
+
/** Mediator minimum per transaction. Null when it could not be read. */
|
|
100
|
+
minPerTx: bigint | null;
|
|
101
|
+
/** Mediator maximum per transaction. */
|
|
102
|
+
maxPerTx: bigint;
|
|
103
|
+
/** What is left of the mediator's daily limit for this token. */
|
|
104
|
+
dailyRemaining: bigint;
|
|
105
|
+
};
|
|
106
|
+
/** The whole input. */
|
|
107
|
+
export type CrossingInput = {
|
|
108
|
+
specVersion: string;
|
|
109
|
+
conditions: CrossingConditions;
|
|
110
|
+
deposit: DepositInput;
|
|
111
|
+
};
|
|
112
|
+
export type WaitReason = 'nothing-waiting' | 'crossing-in-flight' | 'below-cost' | 'below-bridge-minimum' | 'daily-limit-reached' | 'price-missing' | 'gas-price-above-ceiling' | 'limits-unavailable';
|
|
113
|
+
export type CannotReason = 'address-retired' | 'zero-fee-rate' | 'above-per-transaction-maximum' | 'token-not-allowed';
|
|
114
|
+
/** What happens to the deposit. */
|
|
115
|
+
export type CrossingDecision = {
|
|
116
|
+
specVersion: string;
|
|
117
|
+
outcome: 'execute' | 'wait' | 'cannot-cross-automatically';
|
|
118
|
+
/** Null when the outcome is `execute`. */
|
|
119
|
+
reason: WaitReason | CannotReason | null;
|
|
120
|
+
/** The amount in base units that a flush would cross: the whole balance, ether included. */
|
|
121
|
+
amount: bigint;
|
|
122
|
+
/** The fee income of the crossing in wei of ether. Null when the deposit did not pass the checks before the cost test. */
|
|
123
|
+
incomeWei: bigint | null;
|
|
124
|
+
/** The flush gas before the refund. Use it as the gas limit. */
|
|
125
|
+
gasLimit: bigint;
|
|
126
|
+
/** The flush gas after the refund. This is what the cost is built from. */
|
|
127
|
+
paidGas: bigint;
|
|
128
|
+
/** The paid gas at the fee per gas (base plus priority), in wei. */
|
|
129
|
+
costWei: bigint;
|
|
130
|
+
/** The highest fee per gas (base plus priority) at which the crossing would still execute. 0 when there is no income. */
|
|
131
|
+
breakEvenFeePerGasWei: bigint;
|
|
132
|
+
/** The amount of the token at which a crossing first pays. Null when none exists. For display only. */
|
|
133
|
+
thresholdAmount: bigint | null;
|
|
134
|
+
/** True when the threshold is above the bridge's per-transaction maximum, so it can never be reached. */
|
|
135
|
+
thresholdAboveMaximum: boolean;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* The rounding rule in one place. Income rounds down (every fee, every conversion to wei). Cost rounds up:
|
|
139
|
+
* the income that a crossing must earn is `ceil(costWei * multiple / 1000)`. A crossing pays exactly when
|
|
140
|
+
* `incomeWei >= requiredIncomeWei`, which is the same test as `incomeWei * 1000 >= costWei * multiple`.
|
|
141
|
+
* @param costWei the cost of the crossing, in wei
|
|
142
|
+
* @param safetyMultipleThousandths the safety multiple in thousandths (2000 is two times)
|
|
143
|
+
* @returns the least income, in wei, at which the crossing executes
|
|
144
|
+
*/
|
|
145
|
+
export declare const requiredIncomeWei: ({ costWei, safetyMultipleThousandths, }: {
|
|
146
|
+
costWei: bigint;
|
|
147
|
+
safetyMultipleThousandths: bigint;
|
|
148
|
+
}) => bigint;
|
|
149
|
+
/**
|
|
150
|
+
* The gibs fee HomeFeeLedger takes from a delivered amount: `amount * feeRateE18 / 1e18`, rounded down. The rate
|
|
151
|
+
* is read from the call data, so it is the address's own. The partner fee is left out: it is never the executor's.
|
|
152
|
+
* @param amount the amount delivered to the ledger, in base units
|
|
153
|
+
* @param feeRateE18 the address's committed gibs fee rate, 1e18 is all of it
|
|
154
|
+
* @returns the gibs fee, in base units
|
|
155
|
+
*/
|
|
156
|
+
export declare const gibsFeeOf: ({ amount, feeRateE18 }: {
|
|
157
|
+
amount: bigint;
|
|
158
|
+
feeRateE18: bigint;
|
|
159
|
+
}) => bigint;
|
|
160
|
+
/**
|
|
161
|
+
* Decides whether to cross one deposit now, and what the crossing is worth. Pure: the same input always
|
|
162
|
+
* gives the same decision.
|
|
163
|
+
* @param input the conditions and the deposit, all read at one moment
|
|
164
|
+
* @returns the decision, with the gas limit, the cost, the income and the amount at which a crossing first pays
|
|
165
|
+
*/
|
|
166
|
+
export declare const decideCrossing: (input: CrossingInput) => CrossingDecision;
|