@gibs/bridge-client 1.30.1 → 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/coinbase-accept-list/package.json +6 -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/index.d.ts +2 -0
- package/dist/cjs/index.js +24 -1
- package/dist/cjs/kraken-accept-list.d.ts +70 -0
- package/dist/cjs/kraken-accept-list.js +24 -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/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/kraken-accept-list.d.ts +70 -0
- package/dist/kraken-accept-list.js +17 -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/package.json +429 -4
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;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decideCrossing = exports.gibsFeeOf = exports.requiredIncomeWei = exports.gasTableOf = exports.GAS_TABLES = exports.GAS_TABLE_NAMES = exports.ETHER_TOKEN = exports.CROSSING_SPEC_VERSION = void 0;
|
|
4
|
+
exports.CROSSING_SPEC_VERSION = '7.0.0';
|
|
5
|
+
exports.ETHER_TOKEN = '0x0000000000000000000000000000000000000000';
|
|
6
|
+
const WAD = 10n ** 18n;
|
|
7
|
+
const THOUSAND = 1000n;
|
|
8
|
+
const MAXIMUM_FEE_RATE_E18 = 10n ** 16n;
|
|
9
|
+
const SEARCH_LIMIT = 2n ** 192n;
|
|
10
|
+
exports.GAS_TABLE_NAMES = ['ethereum-prague', 'ethereum-glamsterdam', 'sepolia-glamsterdam'];
|
|
11
|
+
exports.GAS_TABLES = {
|
|
12
|
+
'ethereum-prague': {
|
|
13
|
+
chainId: 1n,
|
|
14
|
+
gasModel: {
|
|
15
|
+
paid: { tokenFlushGas: 295000n, etherFlushGas: 292000n },
|
|
16
|
+
beforeRefund: { tokenFlushGas: 340000n, etherFlushGas: 352000n },
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
'ethereum-glamsterdam': {
|
|
20
|
+
chainId: 1n,
|
|
21
|
+
gasModel: {
|
|
22
|
+
paid: { tokenFlushGas: 830000n, etherFlushGas: 645000n },
|
|
23
|
+
beforeRefund: { tokenFlushGas: 861000n, etherFlushGas: 675000n },
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
'sepolia-glamsterdam': {
|
|
27
|
+
chainId: 11155111n,
|
|
28
|
+
gasModel: {
|
|
29
|
+
paid: { tokenFlushGas: 832000n, etherFlushGas: 644000n },
|
|
30
|
+
beforeRefund: { tokenFlushGas: 863000n, etherFlushGas: 674000n },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const gasTableOf = (name, chainId) => {
|
|
35
|
+
if (!Object.hasOwn(exports.GAS_TABLES, name))
|
|
36
|
+
throw new Error(`unknown gas table ${name}`);
|
|
37
|
+
const table = exports.GAS_TABLES[name];
|
|
38
|
+
if (table.chainId !== chainId)
|
|
39
|
+
throw new Error(`gas table ${name} is for chain ${table.chainId}, not chain ${chainId}`);
|
|
40
|
+
return table;
|
|
41
|
+
};
|
|
42
|
+
exports.gasTableOf = gasTableOf;
|
|
43
|
+
const ceilDiv = (numerator, denominator) => (numerator + denominator - 1n) / denominator;
|
|
44
|
+
const requiredIncomeWei = ({ costWei, safetyMultipleThousandths, }) => ceilDiv(costWei * safetyMultipleThousandths, THOUSAND);
|
|
45
|
+
exports.requiredIncomeWei = requiredIncomeWei;
|
|
46
|
+
const gibsFeeOf = ({ amount, feeRateE18 }) => (amount * feeRateE18) / WAD;
|
|
47
|
+
exports.gibsFeeOf = gibsFeeOf;
|
|
48
|
+
const crossableOf = (deposit) => deposit.balance;
|
|
49
|
+
const incomeOf = (amount, deposit) => {
|
|
50
|
+
if (deposit.weiPerWholeToken === null)
|
|
51
|
+
return 0n;
|
|
52
|
+
const delivered = amount - ceilDiv(amount * deposit.entryFeeWad, WAD);
|
|
53
|
+
const fee = (0, exports.gibsFeeOf)({ amount: delivered, feeRateE18: deposit.feeRateE18 });
|
|
54
|
+
return (fee * deposit.weiPerWholeToken) / 10n ** deposit.decimals;
|
|
55
|
+
};
|
|
56
|
+
const flushGasOf = (deposit, figures) => deposit.token === exports.ETHER_TOKEN ? figures.etherFlushGas : figures.tokenFlushGas;
|
|
57
|
+
const feePerGasOf = (conditions) => conditions.baseFeeWei + conditions.priorityFeeWei;
|
|
58
|
+
const costOf = (deposit, conditions) => flushGasOf(deposit, conditions.gasModel.paid) * feePerGasOf(conditions);
|
|
59
|
+
const netOf = (incomeWei, costWei, conditions) => incomeWei * THOUSAND - costWei * conditions.safetyMultipleThousandths;
|
|
60
|
+
const breakEvenOf = (incomeWei, deposit, conditions) => {
|
|
61
|
+
if (incomeWei === null)
|
|
62
|
+
return 0n;
|
|
63
|
+
const paidGas = flushGasOf(deposit, conditions.gasModel.paid);
|
|
64
|
+
return (incomeWei * THOUSAND) / (paidGas * conditions.safetyMultipleThousandths);
|
|
65
|
+
};
|
|
66
|
+
const waits = (reason) => ({ outcome: 'wait', reason });
|
|
67
|
+
const cannot = (reason) => ({ outcome: 'cannot-cross-automatically', reason });
|
|
68
|
+
const refusalOf = (deposit, conditions, amount) => {
|
|
69
|
+
if (deposit.retired)
|
|
70
|
+
return cannot('address-retired');
|
|
71
|
+
if (deposit.crossingInFlight)
|
|
72
|
+
return waits('crossing-in-flight');
|
|
73
|
+
if (amount === 0n)
|
|
74
|
+
return waits('nothing-waiting');
|
|
75
|
+
if (deposit.feeRateE18 === 0n)
|
|
76
|
+
return cannot('zero-fee-rate');
|
|
77
|
+
if (conditions.maximumBaseFeeWei !== null && conditions.baseFeeWei > conditions.maximumBaseFeeWei) {
|
|
78
|
+
return waits('gas-price-above-ceiling');
|
|
79
|
+
}
|
|
80
|
+
if (!deposit.autoCrossAllowed)
|
|
81
|
+
return cannot('token-not-allowed');
|
|
82
|
+
if (deposit.minPerTx === null)
|
|
83
|
+
return waits('limits-unavailable');
|
|
84
|
+
if (amount > deposit.maxPerTx)
|
|
85
|
+
return cannot('above-per-transaction-maximum');
|
|
86
|
+
if (amount < deposit.minPerTx)
|
|
87
|
+
return waits('below-bridge-minimum');
|
|
88
|
+
if (amount > deposit.dailyRemaining)
|
|
89
|
+
return waits('daily-limit-reached');
|
|
90
|
+
if (deposit.weiPerWholeToken === null)
|
|
91
|
+
return waits('price-missing');
|
|
92
|
+
return null;
|
|
93
|
+
};
|
|
94
|
+
const thresholdOf = (deposit, conditions) => {
|
|
95
|
+
const none = { amount: null, aboveMaximum: false };
|
|
96
|
+
if (deposit.retired)
|
|
97
|
+
return none;
|
|
98
|
+
if (deposit.minPerTx === null || deposit.weiPerWholeToken === null)
|
|
99
|
+
return none;
|
|
100
|
+
if (deposit.feeRateE18 === 0n)
|
|
101
|
+
return none;
|
|
102
|
+
const minimum = deposit.minPerTx;
|
|
103
|
+
const costWei = costOf(deposit, conditions);
|
|
104
|
+
const pays = (amount) => netOf(incomeOf(amount, deposit), costWei, conditions) >= 0n;
|
|
105
|
+
const finish = (profitable) => {
|
|
106
|
+
const amount = profitable > minimum ? profitable : minimum;
|
|
107
|
+
return { amount, aboveMaximum: amount > deposit.maxPerTx };
|
|
108
|
+
};
|
|
109
|
+
if (pays(0n))
|
|
110
|
+
return finish(0n);
|
|
111
|
+
let high = 1n;
|
|
112
|
+
while (!pays(high)) {
|
|
113
|
+
high *= 2n;
|
|
114
|
+
if (high > SEARCH_LIMIT)
|
|
115
|
+
return none;
|
|
116
|
+
}
|
|
117
|
+
let low = high / 2n;
|
|
118
|
+
while (high - low > 1n) {
|
|
119
|
+
const middle = (low + high) / 2n;
|
|
120
|
+
if (pays(middle))
|
|
121
|
+
high = middle;
|
|
122
|
+
else
|
|
123
|
+
low = middle;
|
|
124
|
+
}
|
|
125
|
+
return finish(high);
|
|
126
|
+
};
|
|
127
|
+
const assertValid = (input) => {
|
|
128
|
+
if (input.specVersion !== exports.CROSSING_SPEC_VERSION) {
|
|
129
|
+
throw new Error(`the crossing spec is ${exports.CROSSING_SPEC_VERSION}, the input names ${input.specVersion}`);
|
|
130
|
+
}
|
|
131
|
+
const { conditions, deposit } = input;
|
|
132
|
+
if (conditions.safetyMultipleThousandths <= 0n)
|
|
133
|
+
throw new Error('the safety multiple must be above zero');
|
|
134
|
+
const { paid, beforeRefund } = conditions.gasModel;
|
|
135
|
+
const figures = [paid.tokenFlushGas, paid.etherFlushGas, beforeRefund.tokenFlushGas, beforeRefund.etherFlushGas];
|
|
136
|
+
if (figures.some((gas) => gas <= 0n))
|
|
137
|
+
throw new Error('every gas figure must be above zero');
|
|
138
|
+
if (deposit.feeRateE18 < 0n || deposit.feeRateE18 > MAXIMUM_FEE_RATE_E18) {
|
|
139
|
+
throw new Error(`the fee rate must be 0 to ${MAXIMUM_FEE_RATE_E18} (1e18 is 100 percent)`);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const decideCrossing = (input) => {
|
|
143
|
+
assertValid(input);
|
|
144
|
+
const { conditions, deposit } = input;
|
|
145
|
+
const amount = crossableOf(deposit);
|
|
146
|
+
const costWei = costOf(deposit, conditions);
|
|
147
|
+
const threshold = thresholdOf(deposit, conditions);
|
|
148
|
+
const describe = (outcome, reason, incomeWei) => ({
|
|
149
|
+
specVersion: exports.CROSSING_SPEC_VERSION,
|
|
150
|
+
outcome,
|
|
151
|
+
reason,
|
|
152
|
+
amount,
|
|
153
|
+
incomeWei,
|
|
154
|
+
gasLimit: flushGasOf(deposit, conditions.gasModel.beforeRefund),
|
|
155
|
+
paidGas: flushGasOf(deposit, conditions.gasModel.paid),
|
|
156
|
+
costWei,
|
|
157
|
+
breakEvenFeePerGasWei: breakEvenOf(incomeWei, deposit, conditions),
|
|
158
|
+
thresholdAmount: threshold.amount,
|
|
159
|
+
thresholdAboveMaximum: threshold.aboveMaximum,
|
|
160
|
+
});
|
|
161
|
+
const refusal = refusalOf(deposit, conditions, amount);
|
|
162
|
+
if (refusal !== null)
|
|
163
|
+
return describe(refusal.outcome, refusal.reason, null);
|
|
164
|
+
const incomeWei = incomeOf(amount, deposit);
|
|
165
|
+
if (netOf(incomeWei, costWei, conditions) >= 0n)
|
|
166
|
+
return describe('execute', null, incomeWei);
|
|
167
|
+
return describe('wait', 'below-cost', incomeWei);
|
|
168
|
+
};
|
|
169
|
+
exports.decideCrossing = decideCrossing;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A guard for the boundary vectors of `crossing-vectors.json`. A boundary vector's name says it sits on an edge:
|
|
3
|
+
* one base unit under the threshold, at it, one wei above a break-even fee. When a gas table moves, the edge moves,
|
|
4
|
+
* and a balance or a fee left behind keeps its name but tests nothing. This guard runs the reference decision on
|
|
5
|
+
* each named pair and fails when the pair does not sit on its edge.
|
|
6
|
+
*/
|
|
7
|
+
/** The fields of a vector that the guard reads. */
|
|
8
|
+
export type GuardVector = {
|
|
9
|
+
id: string;
|
|
10
|
+
input: unknown;
|
|
11
|
+
expectedError?: string;
|
|
12
|
+
};
|
|
13
|
+
/** The vectors file, as the guard reads it. */
|
|
14
|
+
export type GuardVectorFile = {
|
|
15
|
+
vectors: readonly GuardVector[];
|
|
16
|
+
};
|
|
17
|
+
/** Turns every string made only of digits into a bigint. Addresses start with 0x, so they are safe. */
|
|
18
|
+
export declare const reviveBigints: (value: unknown) => unknown;
|
|
19
|
+
/**
|
|
20
|
+
* The edge that a pair sits on.
|
|
21
|
+
* - `threshold`: the first amount that pays. The lower vector is one base unit under it, the upper one sits on it.
|
|
22
|
+
* - `break-even`: the highest fee per gas that pays. The upper vector is at it, the lower one is one wei above it.
|
|
23
|
+
* - `income`: the least income that pays. The upper vector earns exactly it, the lower one earns one wei less.
|
|
24
|
+
* - `edge`: a limit that is inclusive (a ceiling, a cap, a minimum). Only the outcome is checked.
|
|
25
|
+
*/
|
|
26
|
+
export type BoundaryKind = 'threshold' | 'break-even' | 'income' | 'edge';
|
|
27
|
+
/** Two vectors that sit on one edge. The first must execute, the second must not. */
|
|
28
|
+
export type BoundaryPair = {
|
|
29
|
+
kind: BoundaryKind;
|
|
30
|
+
/** The vector id that sits on the edge, as named, and must execute. */
|
|
31
|
+
mustExecute: string;
|
|
32
|
+
/** The vector id one step beyond the edge, which must wait or be refused. */
|
|
33
|
+
mustNotExecute: string;
|
|
34
|
+
};
|
|
35
|
+
/** Every boundary pair of the vectors file. A vector whose name says it is on an edge must appear here. */
|
|
36
|
+
export declare const BOUNDARY_PAIRS: readonly BoundaryPair[];
|
|
37
|
+
/**
|
|
38
|
+
* Every way the boundary vectors fail to sit on their named edges. An empty list means they all do.
|
|
39
|
+
* It fails when a vector named as a boundary is in no pair, when a pair names a vector that is not in the file,
|
|
40
|
+
* and when a pair does not decide as its name says.
|
|
41
|
+
* @param file the vectors file, as parsed from JSON
|
|
42
|
+
* @param pairs the boundary pairs to check, `BOUNDARY_PAIRS` by default
|
|
43
|
+
* @returns one message per failure, empty when none
|
|
44
|
+
*/
|
|
45
|
+
export declare const boundaryPairFailures: (file: GuardVectorFile, pairs?: readonly BoundaryPair[]) => string[];
|