@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.
Files changed (104) hide show
  1. package/coinbase-accept-list/package.json +6 -0
  2. package/dist/cjs/client.d.ts +9 -1
  3. package/dist/cjs/client.js +8 -5
  4. package/dist/cjs/coinbase-accept-list.d.ts +101 -0
  5. package/dist/cjs/coinbase-accept-list.js +97 -0
  6. package/dist/cjs/crossing-decision.d.ts +166 -0
  7. package/dist/cjs/crossing-decision.js +169 -0
  8. package/dist/cjs/crossing-vector-guard.d.ts +45 -0
  9. package/dist/cjs/crossing-vector-guard.js +139 -0
  10. package/dist/cjs/exchange-deposit-board.d.ts +50 -0
  11. package/dist/cjs/exchange-deposit-board.js +70 -0
  12. package/dist/cjs/exchange-deposit-chain.d.ts +146 -0
  13. package/dist/cjs/exchange-deposit-chain.js +228 -0
  14. package/dist/cjs/exchange-deposit-constants.d.ts +10 -0
  15. package/dist/cjs/exchange-deposit-constants.js +6 -0
  16. package/dist/cjs/exchange-deposit-factory-calls.d.ts +245 -0
  17. package/dist/cjs/exchange-deposit-factory-calls.js +103 -0
  18. package/dist/cjs/exchange-deposit-factory.d.ts +87 -0
  19. package/dist/cjs/exchange-deposit-factory.js +110 -0
  20. package/dist/cjs/exchange-deposit-fake.d.ts +67 -0
  21. package/dist/cjs/exchange-deposit-fake.js +179 -0
  22. package/dist/cjs/exchange-deposit-index.d.ts +77 -0
  23. package/dist/cjs/exchange-deposit-index.js +40 -0
  24. package/dist/cjs/exchange-deposit-issuance.d.ts +327 -0
  25. package/dist/cjs/exchange-deposit-issuance.js +244 -0
  26. package/dist/cjs/exchange-deposit-path.d.ts +16 -0
  27. package/dist/cjs/exchange-deposit-path.js +15 -0
  28. package/dist/cjs/exchange-deposit-pow.d.ts +163 -0
  29. package/dist/cjs/exchange-deposit-pow.js +101 -0
  30. package/dist/cjs/exchange-deposit-recipient.d.ts +66 -0
  31. package/dist/cjs/exchange-deposit-recipient.js +35 -0
  32. package/dist/cjs/exchange-deposit-self-cross.d.ts +163 -0
  33. package/dist/cjs/exchange-deposit-self-cross.js +60 -0
  34. package/dist/cjs/exchange-deposit-signin.d.ts +275 -0
  35. package/dist/cjs/exchange-deposit-signin.js +166 -0
  36. package/dist/cjs/exchange-deposit-watch.d.ts +133 -0
  37. package/dist/cjs/exchange-deposit-watch.js +58 -0
  38. package/dist/cjs/exchange-deposit.d.ts +440 -0
  39. package/dist/cjs/exchange-deposit.js +154 -0
  40. package/dist/cjs/exchange-sender-guides.d.ts +29 -0
  41. package/dist/cjs/exchange-sender-guides.js +25 -0
  42. package/dist/cjs/index.d.ts +2 -0
  43. package/dist/cjs/index.js +24 -1
  44. package/dist/cjs/kraken-accept-list.d.ts +70 -0
  45. package/dist/cjs/kraken-accept-list.js +24 -0
  46. package/dist/client.d.ts +9 -1
  47. package/dist/client.js +8 -5
  48. package/dist/coinbase-accept-list.d.ts +101 -0
  49. package/dist/coinbase-accept-list.js +89 -0
  50. package/dist/crossing-decision.d.ts +166 -0
  51. package/dist/crossing-decision.js +162 -0
  52. package/dist/crossing-vector-guard.d.ts +45 -0
  53. package/dist/crossing-vector-guard.js +134 -0
  54. package/dist/exchange-deposit-board.d.ts +50 -0
  55. package/dist/exchange-deposit-board.js +28 -0
  56. package/dist/exchange-deposit-chain.d.ts +146 -0
  57. package/dist/exchange-deposit-chain.js +218 -0
  58. package/dist/exchange-deposit-constants.d.ts +10 -0
  59. package/dist/exchange-deposit-constants.js +3 -0
  60. package/dist/exchange-deposit-factory-calls.d.ts +245 -0
  61. package/dist/exchange-deposit-factory-calls.js +97 -0
  62. package/dist/exchange-deposit-factory.d.ts +87 -0
  63. package/dist/exchange-deposit-factory.js +104 -0
  64. package/dist/exchange-deposit-fake.d.ts +67 -0
  65. package/dist/exchange-deposit-fake.js +171 -0
  66. package/dist/exchange-deposit-index.d.ts +77 -0
  67. package/dist/exchange-deposit-index.js +34 -0
  68. package/dist/exchange-deposit-issuance.d.ts +327 -0
  69. package/dist/exchange-deposit-issuance.js +224 -0
  70. package/dist/exchange-deposit-path.d.ts +16 -0
  71. package/dist/exchange-deposit-path.js +11 -0
  72. package/dist/exchange-deposit-pow.d.ts +163 -0
  73. package/dist/exchange-deposit-pow.js +93 -0
  74. package/dist/exchange-deposit-recipient.d.ts +66 -0
  75. package/dist/exchange-deposit-recipient.js +28 -0
  76. package/dist/exchange-deposit-self-cross.d.ts +163 -0
  77. package/dist/exchange-deposit-self-cross.js +46 -0
  78. package/dist/exchange-deposit-signin.d.ts +275 -0
  79. package/dist/exchange-deposit-signin.js +147 -0
  80. package/dist/exchange-deposit-watch.d.ts +133 -0
  81. package/dist/exchange-deposit-watch.js +44 -0
  82. package/dist/exchange-deposit.d.ts +440 -0
  83. package/dist/exchange-deposit.js +138 -0
  84. package/dist/exchange-sender-guides.d.ts +29 -0
  85. package/dist/exchange-sender-guides.js +21 -0
  86. package/dist/index.d.ts +2 -0
  87. package/dist/index.js +2 -0
  88. package/dist/kraken-accept-list.d.ts +70 -0
  89. package/dist/kraken-accept-list.js +17 -0
  90. package/exchange-deposit/package.json +6 -0
  91. package/exchange-deposit-board/package.json +6 -0
  92. package/exchange-deposit-chain/package.json +6 -0
  93. package/exchange-deposit-factory/package.json +6 -0
  94. package/exchange-deposit-fake/package.json +6 -0
  95. package/exchange-deposit-issuance/package.json +6 -0
  96. package/exchange-deposit-path/package.json +6 -0
  97. package/exchange-deposit-pow/package.json +6 -0
  98. package/exchange-deposit-recipient/package.json +6 -0
  99. package/exchange-deposit-self-cross/package.json +6 -0
  100. package/exchange-deposit-signin/package.json +6 -0
  101. package/exchange-deposit-watch/package.json +6 -0
  102. package/exchange-sender-guides/package.json +6 -0
  103. package/kraken-accept-list/package.json +6 -0
  104. package/package.json +429 -4
@@ -0,0 +1,440 @@
1
+ import { ETHEREUM_MAINNET_CHAIN_ID, SEPOLIA_CHAIN_ID, WEI_PER_ETHER } from './exchange-deposit-constants.js';
2
+ export { ETHEREUM_MAINNET_CHAIN_ID, SEPOLIA_CHAIN_ID, WEI_PER_ETHER };
3
+ import { type Address, type Hex } from 'viem';
4
+ import { type CrossingDecision, type GasTable, type GasTableName } from './crossing-decision.js';
5
+ import { type ExchangeDepositFactoryEntry } from './exchange-deposit-factory.js';
6
+ import { type ExchangeDepositSeed } from './exchange-deposit-index.js';
7
+ export type { ExchangeDepositSeed };
8
+ /**
9
+ * Types and pure functions for the "deposit from an exchange" feature.
10
+ *
11
+ * THE SHAPE OF THE FEATURE. A reader withdraws from an exchange to an Ethereum
12
+ * address this feature shows. The address has no private key. Nobody, Gibs
13
+ * included, can redirect what arrives there: it can only be crossed to the
14
+ * recipient PulseChain address it was made for. A validator (or the reader, or
15
+ * anyone) triggers the crossing and pays the Ethereum gas.
16
+ *
17
+ * AN ADDRESS IS REUSABLE (owner decision, 2026-11-19). It is for one token and
18
+ * one fee. Its fee is set when the address is first issued, and the address
19
+ * commits to it. The forwarder is recreated on every flush, so a used address may
20
+ * take another deposit. The page offers a new address only when the reader asks
21
+ * for one, which moves to the next counter and retires the earlier ones for that
22
+ * token and fee.
23
+ *
24
+ * An address is DEFINED by its settings ({@link ExchangeDepositSettings}), so the
25
+ * same settings always give the same address. A reader can save one in an
26
+ * exchange address book, and a new `index` gives a fresh address.
27
+ *
28
+ * WHO OWNS WHAT. The types here are the contract between the interface and the
29
+ * code that talks to the chain. The interface builds against
30
+ * {@link ExchangeDepositSource}; the real source replaces the fake one without a
31
+ * change to any screen. Address derivation, the real balances and the real
32
+ * crossing are not in this file.
33
+ */
34
+ /** The scale of a fee rate: 1e18 is 100 percent, 1e16 is 1 percent (the largest fee the factory issues an address for). */
35
+ export declare const FEE_RATE_SCALE: bigint;
36
+ /**
37
+ * The fee rates the interface offers, in 1e18 fixed point: "No fee" (0, the reader crosses it alone), then 1%, 0.5%
38
+ * and 0.25%. ONE constant: change it here to change every list. The validators never cross a 0% address.
39
+ */
40
+ export declare const EXCHANGE_DEPOSIT_FEE_RATES: readonly bigint[];
41
+ /** The fee rate chosen before the reader picks one: the highest preset, which crosses the smallest balance. */
42
+ export declare const EXCHANGE_DEPOSIT_DEFAULT_FEE_RATE_E18: bigint;
43
+ /**
44
+ * The maximums the deployed factory enforces, read from the factory when the interface starts. The interface keeps
45
+ * no copy of them. A rate above a maximum is never offered and never built into settings.
46
+ */
47
+ export interface ExchangeDepositFeeLimits {
48
+ /** The highest gibs fee rate the factory issues an address for, in 1e18 fixed point. */
49
+ readonly maximumFeeRateE18: bigint;
50
+ /** The highest partner fee rate the factory issues an address for, in 1e18 fixed point. */
51
+ readonly maximumPartnerRateE18: bigint;
52
+ }
53
+ /** What the reader sees when the factory's maximums cannot be read. No fee is offered and no address is built. */
54
+ export declare const EXCHANGE_DEPOSIT_FEE_LIMITS_UNREADABLE = "The deposit factory's fee limits could not be read. No fee can be chosen and no address can be built until they can.";
55
+ /**
56
+ * The fee rates the menu may offer: the presets at or below the factory's maximum fee. Without limits it offers none,
57
+ * because the interface never guesses a maximum.
58
+ *
59
+ * @param input.presets - the rates the interface knows, highest first
60
+ * @param input.limits - the factory's maximums, or null when they could not be read
61
+ */
62
+ export declare const feeRateOptionsOf: ({ presets, limits, }: {
63
+ presets: readonly bigint[];
64
+ limits: ExchangeDepositFeeLimits | null;
65
+ }) => readonly bigint[];
66
+ /**
67
+ * Refuses settings the factory would not issue: a rate below zero or above its maximum. Without limits, every rate is
68
+ * refused. The interface never builds an address from a guessed maximum.
69
+ *
70
+ * @param input.feeRateE18 - the gibs fee of the address, in 1e18 fixed point
71
+ * @param input.partnerRateE18 - the partner fee of the address, in 1e18 fixed point (zero: the interface sends none)
72
+ * @param input.limits - the factory's maximums, or null when they could not be read
73
+ * @throws when the limits are unknown, or a rate is out of range
74
+ */
75
+ export declare const assertFeeRatesWithinLimits: ({ feeRateE18, partnerRateE18, limits, }: {
76
+ feeRateE18: bigint;
77
+ partnerRateE18: bigint;
78
+ limits: ExchangeDepositFeeLimits | null;
79
+ }) => void;
80
+ /** Wei in one ether. Defined in `exchange-deposit-constants.ts` and re-exported here. */
81
+ /**
82
+ * The groups of the deposit factory. Ether takes an `ether` address, and every token takes a `single` address that
83
+ * holds that one token. The stablecoins group is retired: the factory no longer takes it (crossing spec, section 9).
84
+ */
85
+ export type ExchangeDepositContractGroup = 'ether' | 'single';
86
+ /** One token on Ethereum that a reader can deposit. */
87
+ export interface ExchangeDepositToken {
88
+ /** The ticker shown to a reader. */
89
+ readonly symbol: string;
90
+ /** The name shown to a reader, such as "USD Coin". */
91
+ readonly name: string;
92
+ /** The token contract on Ethereum. The zero address stands for ether itself. */
93
+ readonly address: Address;
94
+ /** Decimal places of the token's base unit. */
95
+ readonly decimals: number;
96
+ /** The factory group the token's address belongs to. */
97
+ readonly contractGroup: ExchangeDepositContractGroup;
98
+ }
99
+ /**
100
+ * Everything that defines one deposit address. Same settings, same address.
101
+ */
102
+ export interface ExchangeDepositSettings {
103
+ /** The PulseChain address the funds reach. Usually the connected wallet. */
104
+ readonly recipient: Address;
105
+ /** The token of the deposit: {@link ExchangeDepositToken.address}. */
106
+ readonly tokenAddress: Address;
107
+ /**
108
+ * The exact fee of the address, in 1e18 fixed point (1e18 is 100 percent). The address commits
109
+ * to it, and the ledger on PulseChain takes exactly this share of what crosses. A higher fee
110
+ * means the crossing pays for itself with a smaller balance, so it runs sooner.
111
+ */
112
+ readonly feeRateE18: bigint;
113
+ /** Whether wrapped PLS arrives as PLS. */
114
+ readonly unwrapToNativePls: boolean;
115
+ /**
116
+ * Which of the recipient's addresses for these settings: 0 is the first, and each new deposit takes the next one.
117
+ * It is a counter, not the factory index. {@link ExchangeDepositSettings.index} is what the factory takes.
118
+ */
119
+ readonly counter: number;
120
+ /**
121
+ * The uint256 the factory takes as its `index`: derived from the recipient's seed and the counter, so no reader can
122
+ * guess it (see {@link factoryIndexOf}). Settings with the same seed and counter give the same address.
123
+ */
124
+ readonly index: bigint;
125
+ }
126
+ /** A crossing that has been sent and has not arrived yet. */
127
+ export interface ExchangeDepositCrossing {
128
+ /** The Ethereum transaction that carries the balance across. */
129
+ readonly transactionHash: Hex;
130
+ /** When it was sent, in milliseconds since the epoch. */
131
+ readonly startedAtMs: number;
132
+ }
133
+ /**
134
+ * Where an address came from.
135
+ *
136
+ * - `derived`: the real keyless address, safe to show with copy and a code.
137
+ * - `placeholder`: a stand-in from the fake source. NOBODY CONTROLS IT, so a
138
+ * screen must not offer to copy it or scan it.
139
+ */
140
+ export type ExchangeDepositAddressOrigin = 'derived' | 'placeholder';
141
+ /** One deposit address, with what is waiting at it. */
142
+ export interface ExchangeDepositAddress {
143
+ /** Whether the address is real or a placeholder. See {@link ExchangeDepositAddressOrigin}. */
144
+ readonly origin: ExchangeDepositAddressOrigin;
145
+ /** The Ethereum address to withdraw to. */
146
+ readonly address: Address;
147
+ /** The settings that define it. */
148
+ readonly settings: ExchangeDepositSettings;
149
+ /** The token those settings name, resolved. */
150
+ readonly token: ExchangeDepositToken;
151
+ /**
152
+ * The deposit waiting, in the token's own base units. Zero when nothing waits. For ether this is the whole ether
153
+ * balance, because a flush keeps nothing.
154
+ */
155
+ readonly waiting: bigint;
156
+ /** The crossing in progress, or null when none is. */
157
+ readonly crossing: ExchangeDepositCrossing | null;
158
+ }
159
+ /**
160
+ * What an executor looks at to decide when to cross: the cost of one crossing on
161
+ * Ethereum, and what each token is worth in ether.
162
+ */
163
+ export interface ExchangeDepositCrossingConditions {
164
+ /** The gas figures of the network the crossing runs on. Choose it with {@link exchangeDepositGasTableOf}. */
165
+ readonly gasTable: GasTable;
166
+ /** The current Ethereum base fee, in wei per gas. */
167
+ readonly baseFeeWei: bigint;
168
+ /** The tip on top of the base fee, in wei per gas. */
169
+ readonly priorityFeeWei: bigint;
170
+ /** The crossing runs once the fee covers this many times the cost, in thousandths (2000 is two times). */
171
+ readonly multipleThousandths: bigint;
172
+ /**
173
+ * Wei of ether that one whole token is worth, at the moment of the conditions, by lower case token address
174
+ * (ether is the zero address). A token with no entry has no price, so no threshold.
175
+ */
176
+ readonly weiPerWholeTokenByAddress: Readonly<Record<string, bigint>>;
177
+ /**
178
+ * The smallest transfer the entry mediator accepts for each token, in base units, by lower case token address (ether
179
+ * is the zero address, and its minimum is the minimum of wrapped ether). A token with no entry has no known minimum,
180
+ * so its deposit waits (crossing spec, section 3.2, R08). Every value is read from the chain, never guessed.
181
+ */
182
+ readonly minimumPerTxByAddress: Readonly<Record<string, bigint>>;
183
+ }
184
+ /**
185
+ * What the code at an address is. `no-code` is an ordinary account. `delegation` is an ordinary key delegated to a
186
+ * contract by Ethereum Improvement Proposal 7702: the key still signs for itself. `contract` is any other code.
187
+ */
188
+ export type ExchangeDepositCodeKind = 'no-code' | 'delegation' | 'contract';
189
+ /**
190
+ * Where the interface gets its data. The fake source and the real one both
191
+ * satisfy this, so a screen never knows which it has.
192
+ */
193
+ export interface ExchangeDepositSource {
194
+ /** The tokens a reader can deposit, in the order to show them. */
195
+ listTokens(): Promise<readonly ExchangeDepositToken[]>;
196
+ /**
197
+ * The maximums the factory enforces. It rejects when they cannot be read, and the interface then offers no fee and
198
+ * builds no address. It never answers with a guessed value.
199
+ */
200
+ feeLimits(): Promise<ExchangeDepositFeeLimits>;
201
+ /**
202
+ * The address of this request, with what waits at it. The same request always gives the same address, so asking
203
+ * again reads the balance of the same address. A new `index` issues the next address.
204
+ */
205
+ addressFor(request: ExchangeDepositRequest): Promise<ExchangeDepositAddress>;
206
+ /**
207
+ * The lowest counter at or after `startCounter` whose address has no use on the chain (a balance or a factory event).
208
+ * The page starts from 0 to find the highest counter in use, so it reads one or two addresses in the usual case.
209
+ */
210
+ nextCounterFor(request: Omit<ExchangeDepositRequest, 'counter'> & {
211
+ readonly startCounter: number;
212
+ }): Promise<number>;
213
+ /**
214
+ * The kind of code on the signer, on the factory's chain. A smart-contract wallet ('contract') cannot give the same
215
+ * signature twice, so its sign-in uses a random seed. A delegated ordinary key ('delegation', Ethereum Improvement
216
+ * Proposal 7702) still signs for itself, so it signs as an ordinary wallet. A read that fails rejects; nothing
217
+ * substitutes an answer.
218
+ */
219
+ signerCodeKind(signer: Address): Promise<ExchangeDepositCodeKind>;
220
+ /** What the executor weighs when it decides to cross. */
221
+ crossingConditions(): Promise<ExchangeDepositCrossingConditions>;
222
+ /**
223
+ * Whether the recipient has contract code on PulseChain. A contract wallet
224
+ * that exists only on PulseChain cannot use rescue or retire, and refunded
225
+ * ether would land at the same address on Ethereum, where nobody may own it.
226
+ * A delegated ordinary key (Ethereum Improvement Proposal 7702) is not a
227
+ * contract here: its owner holds the key, and it receives funds as any account
228
+ * does, so it does not count.
229
+ */
230
+ recipientHasCode(recipient: Address): Promise<boolean>;
231
+ }
232
+ /** What the interface asks the source for: one address. The source derives the factory index from the seed. */
233
+ export interface ExchangeDepositRequest {
234
+ /** The PulseChain address the funds reach. */
235
+ readonly recipient: Address;
236
+ /** The token of the deposit. */
237
+ readonly tokenAddress: Address;
238
+ /** The exact fee, in 1e18 fixed point. */
239
+ readonly feeRateE18: bigint;
240
+ /** Which address of those settings: 0 is the first, and each new deposit takes the next one. */
241
+ readonly counter: number;
242
+ /** The seed of the signed-in reader. Without one no address exists, so the interface never asks without it. */
243
+ readonly seed: ExchangeDepositSeed;
244
+ }
245
+ /** The reader's choices for the one address on screen. */
246
+ export interface ExchangeDepositSelection {
247
+ /** The token of the deposit, or null for the first token the source lists. */
248
+ readonly tokenAddress: Address | null;
249
+ /** The exact fee, in 1e18 fixed point. */
250
+ readonly feeRateE18: bigint;
251
+ /**
252
+ * Which address of those settings, or null when the reader has not chosen one. Null means the page offers the first
253
+ * free address, from the records and the chain (see `counterOnLoadOf`); a counter is never guessed at 0.
254
+ */
255
+ readonly counter: number | null;
256
+ }
257
+ /**
258
+ * The selection before the reader has chosen anything: the first token, the default fee, and no counter yet. The page
259
+ * offers the first free address for it, once the records and the chain answer.
260
+ */
261
+ export declare const EXCHANGE_DEPOSIT_INITIAL_SELECTION: ExchangeDepositSelection;
262
+ /** What a reader can do to the selection. */
263
+ export type ExchangeDepositSelectionAction = {
264
+ readonly kind: 'choose-token';
265
+ readonly tokenAddress: Address;
266
+ } | {
267
+ readonly kind: 'choose-fee';
268
+ readonly feeRateE18: bigint;
269
+ } | {
270
+ readonly kind: 'choose-counter';
271
+ readonly counter: number;
272
+ };
273
+ /**
274
+ * The selection after a reader's action. Choosing another token or fee clears the counter, because it names another
275
+ * address, so the first free address of the new settings is offered again. Choosing an index names that address.
276
+ *
277
+ * @param selection - the selection now
278
+ * @param action - what the reader did
279
+ */
280
+ export declare const exchangeDepositSelectionReducer: (selection: ExchangeDepositSelection, action: ExchangeDepositSelectionAction) => ExchangeDepositSelection;
281
+ /** How close the one deposit is to being crossed. */
282
+ export interface CrossingCoverage {
283
+ /** The shared decision of the crossing spec for this deposit. */
284
+ readonly decision: CrossingDecision;
285
+ /**
286
+ * The amount of the token at which a crossing first pays, in the token's base units. Null when the fee rate
287
+ * is zero or the token has no price: no balance ever pays.
288
+ */
289
+ readonly thresholdAmount: bigint | null;
290
+ /** The deposit waiting, in the token's base units. Echoes the input. */
291
+ readonly waitingAmount: bigint;
292
+ /** Waiting over threshold. 1 or more means the crossing pays. 0 when nothing waits or no threshold exists. */
293
+ readonly ratio: number;
294
+ /** What one crossing costs in Ethereum gas, in wei. */
295
+ readonly costInEther: bigint;
296
+ /** Whether the crossing pays for itself now: the decision is `execute`. */
297
+ readonly covered: boolean;
298
+ /** The smallest transfer the entry mediator accepts for the token, in base units. Null when it is unknown. */
299
+ readonly minimumAmount: bigint | null;
300
+ /**
301
+ * Whether something waits and it is below {@link CrossingCoverage.minimumAmount}. The mediator refuses such a flush,
302
+ * so the reader cannot finish it now. False when nothing waits or the minimum is unknown.
303
+ */
304
+ readonly belowBridgeMinimum: boolean;
305
+ }
306
+ /** Inputs to {@link crossingCoverage}. */
307
+ export interface CrossingCoverageInput {
308
+ /** The token of the deposit. */
309
+ readonly token: ExchangeDepositToken;
310
+ /** The deposit waiting, in the token's base units (for ether, the whole ether balance). */
311
+ readonly waiting: bigint;
312
+ /** The exact fee of the address, in 1e18 fixed point. */
313
+ readonly feeRateE18: bigint;
314
+ /** What the executor weighs. */
315
+ readonly conditions: ExchangeDepositCrossingConditions;
316
+ }
317
+ /** The chain id of the Sepolia test network. Defined in `exchange-deposit-constants.ts` and re-exported here. */
318
+ /**
319
+ * The gas table the interface uses on each Ethereum chain it can show (crossing spec, section 3.3). The choice is
320
+ * written out here so that it is one reviewed line. Switch mainnet to `ethereum-glamsterdam` before Glamsterdam
321
+ * has a date on mainnet: the Prague table under-counts after the fork. There is no entry for any other chain.
322
+ */
323
+ export declare const EXCHANGE_DEPOSIT_GAS_TABLE_NAME_BY_CHAIN: ReadonlyMap<bigint, GasTableName>;
324
+ /**
325
+ * The gas table for a chain. It never falls back to another chain's table.
326
+ *
327
+ * @param chainId - the Ethereum chain the crossing runs on
328
+ * @returns the table, whose own chain id equals `chainId`
329
+ * @throws when the interface chose no table for the chain
330
+ */
331
+ export declare const exchangeDepositGasTableOf: (chainId: bigint) => GasTable;
332
+ /**
333
+ * How close one waiting deposit is to being crossed.
334
+ *
335
+ * This follows the crossing spec (version 6.0.0) with all integer math. It builds the one-deposit input of the
336
+ * spec and asks the shared reference, {@link decideCrossing}, for the decision and the threshold. The multiple
337
+ * is an integer in thousandths. The threshold is the least amount whose fee income, rounded down at each step,
338
+ * reaches the cost times the multiple (rounded up). Only `ratio` is a floating point figure, and it is for display.
339
+ *
340
+ * With no price for the token the decision waits and no threshold exists, as with a zero fee rate.
341
+ *
342
+ * @param input - the token, the deposit, the fee rate and the conditions
343
+ * @returns the decision, the cost, the threshold and the ratio
344
+ * @throws when `multipleThousandths` is zero or below
345
+ */
346
+ export declare const crossingCoverage: ({ token, waiting, feeRateE18, conditions }: CrossingCoverageInput) => CrossingCoverage;
347
+ /** What a reader sees an address doing. */
348
+ export type ExchangeDepositStage = 'empty' | 'partway' | 'ready' | 'crossing';
349
+ /**
350
+ * The stage an address is in.
351
+ *
352
+ * - `crossing`: a crossing is sent and has not arrived.
353
+ * - `ready`: the deposit pays for its crossing, so the crossing runs soon.
354
+ * - `partway`: something waits, below the threshold.
355
+ * - `empty`: nothing waits.
356
+ *
357
+ * @param input.coverage - from {@link crossingCoverage}
358
+ * @param input.crossing - the crossing in progress, or null
359
+ */
360
+ export declare const exchangeDepositStage: ({ coverage, crossing, }: {
361
+ coverage: CrossingCoverage;
362
+ crossing: ExchangeDepositCrossing | null;
363
+ }) => ExchangeDepositStage;
364
+ /**
365
+ * The coverage of one address under the current crossing conditions.
366
+ *
367
+ * @param input.address - the address
368
+ * @param input.conditions - what the executor weighs
369
+ */
370
+ export declare const coverageOfAddress: ({ address, conditions, }: {
371
+ address: ExchangeDepositAddress;
372
+ conditions: ExchangeDepositCrossingConditions;
373
+ }) => CrossingCoverage;
374
+ /**
375
+ * A fee rate as a percentage figure for display: 1e16 is `1`. It keeps two decimals of a percent.
376
+ *
377
+ * @param feeRateE18 - the rate in 1e18 fixed point
378
+ */
379
+ export declare const feeRatePercent: (feeRateE18: bigint) => number;
380
+ /**
381
+ * The token the deposit page preselects for a token named in its address bar. A name that matches none of the tokens
382
+ * the page offers gives null, so an unknown or mistyped token never reaches the source. The match ignores case.
383
+ *
384
+ * @param input.tokens - the tokens the source offers
385
+ * @param input.preferredAddress - the token the address bar names, or null when it names none
386
+ * @returns the offered token's address, or null when there is no match
387
+ */
388
+ export declare const preferredExchangeDepositToken: ({ tokens, preferredAddress, }: {
389
+ tokens: readonly ExchangeDepositToken[];
390
+ preferredAddress: string | null;
391
+ }) => Address | null;
392
+ /** The selection an address must match: the recipient and token as read, and the fee and counter the reader chose. */
393
+ export interface ExchangeDepositSelectionMatch {
394
+ /** The recipient the reader chose. */
395
+ readonly recipient: Address;
396
+ /** The token address the reader chose, resolved. */
397
+ readonly tokenAddress: Address;
398
+ /** The exact fee the reader chose, in 1e18 fixed point. */
399
+ readonly feeRateE18: bigint;
400
+ /** The counter the reader chose. */
401
+ readonly counter: number;
402
+ /** The seed of the signed-in reader. The factory index the address must hold is derived from it. */
403
+ readonly seed: ExchangeDepositSeed;
404
+ }
405
+ /**
406
+ * Whether an address was made for the selection now on screen. An address made for an earlier selection is never
407
+ * shown as the current one: a reader could copy it and send funds to the wrong recipient, token, fee or address. The
408
+ * recipient and token compare without case, the fee and counter exactly, and the factory index is derived again from
409
+ * the seed, so a re-sign that changes the seed never shows the old address.
410
+ *
411
+ * @param input.address - the address to test, with the settings it was made for
412
+ * @param input.recipient - the recipient now selected
413
+ * @param input.tokenAddress - the token now selected
414
+ * @param input.feeRateE18 - the fee now selected
415
+ * @param input.counter - the counter now selected
416
+ * @param input.seed - the seed now signed in
417
+ * @returns true only when every setting of the address equals the selection
418
+ */
419
+ export declare const exchangeDepositAddressMatchesSelection: ({ address, recipient, tokenAddress, feeRateE18, counter, seed, }: ExchangeDepositSelectionMatch & {
420
+ readonly address: ExchangeDepositAddress;
421
+ }) => boolean;
422
+ /**
423
+ * Whether a deposit of this token needs the 21,000-gas warning. Once the Glamsterdam upgrade is active on the chain, a
424
+ * plain send of ether (21,000 gas) to an address that holds nothing fails. A deposit address is always new, and nobody
425
+ * seeds it, so an exchange that sends ether with only the basic gas leaves the withdrawal failed. Wrapped ether is an
426
+ * ordinary token contract call, not a plain send, so it does not need the warning. Before the upgrade on a chain, a
427
+ * plain send is still fine, so the warning stays off there (`glamsterdamActive` of the chain's factory entry).
428
+ *
429
+ * @param input - the token of the deposit, and the chain it is deposited on
430
+ * @param input.token - the token, whose address is the zero address for ether itself
431
+ * @param input.chainId - the Ethereum chain the deposit runs on. Its factory entry says whether Glamsterdam is active.
432
+ * @param input.factories - the factories to read. Defaults to the deployed ones.
433
+ * @returns true only when the token is ether and Glamsterdam is active on the chain
434
+ * @throws when no factory is configured for the chain
435
+ */
436
+ export declare const exchangeDepositNeedsGasLimitWarning: ({ token, chainId, factories, }: {
437
+ readonly token: ExchangeDepositToken;
438
+ readonly chainId: bigint;
439
+ readonly factories?: ReadonlyMap<bigint, ExchangeDepositFactoryEntry>;
440
+ }) => boolean;
@@ -0,0 +1,138 @@
1
+ import { ETHEREUM_MAINNET_CHAIN_ID, SEPOLIA_CHAIN_ID, WEI_PER_ETHER } from './exchange-deposit-constants.js';
2
+ export { ETHEREUM_MAINNET_CHAIN_ID, SEPOLIA_CHAIN_ID, WEI_PER_ETHER };
3
+ import { zeroAddress } from 'viem';
4
+ import { CROSSING_SPEC_VERSION, decideCrossing, gasTableOf, } from './crossing-decision.js';
5
+ import { EXCHANGE_DEPOSIT_FACTORY_BY_CHAIN } from './exchange-deposit-factory.js';
6
+ import { factoryIndexOf } from './exchange-deposit-index.js';
7
+ import { sameAddress } from './exchange-deposit-recipient.js';
8
+ export const FEE_RATE_SCALE = 10n ** 18n;
9
+ export const EXCHANGE_DEPOSIT_FEE_RATES = [0n, 10n ** 16n, 5n * 10n ** 15n, 25n * 10n ** 14n];
10
+ export const EXCHANGE_DEPOSIT_DEFAULT_FEE_RATE_E18 = 10n ** 16n;
11
+ export const EXCHANGE_DEPOSIT_FEE_LIMITS_UNREADABLE = "The deposit factory's fee limits could not be read. No fee can be chosen and no address can be built until they can.";
12
+ export const feeRateOptionsOf = ({ presets, limits, }) => {
13
+ if (limits === null)
14
+ return [];
15
+ return presets.filter((rate) => rate <= limits.maximumFeeRateE18);
16
+ };
17
+ export const assertFeeRatesWithinLimits = ({ feeRateE18, partnerRateE18, limits, }) => {
18
+ if (limits === null)
19
+ throw new Error(EXCHANGE_DEPOSIT_FEE_LIMITS_UNREADABLE);
20
+ if (feeRateE18 < 0n || feeRateE18 > limits.maximumFeeRateE18) {
21
+ throw new Error(`the fee rate must be 0 to ${limits.maximumFeeRateE18}, the factory maximum`);
22
+ }
23
+ if (partnerRateE18 < 0n || partnerRateE18 > limits.maximumPartnerRateE18) {
24
+ throw new Error(`the partner rate must be 0 to ${limits.maximumPartnerRateE18}, the factory maximum`);
25
+ }
26
+ };
27
+ const RATIO_SCALE = 10000n;
28
+ export const EXCHANGE_DEPOSIT_INITIAL_SELECTION = {
29
+ tokenAddress: null,
30
+ feeRateE18: EXCHANGE_DEPOSIT_DEFAULT_FEE_RATE_E18,
31
+ counter: null,
32
+ };
33
+ export const exchangeDepositSelectionReducer = (selection, action) => {
34
+ if (action.kind === 'choose-token')
35
+ return { ...selection, tokenAddress: action.tokenAddress, counter: null };
36
+ if (action.kind === 'choose-fee')
37
+ return { ...selection, feeRateE18: action.feeRateE18, counter: null };
38
+ return { ...selection, counter: action.counter };
39
+ };
40
+ const LIMIT_WITHOUT_BRIDGE_READ = 2n ** 192n;
41
+ export const EXCHANGE_DEPOSIT_GAS_TABLE_NAME_BY_CHAIN = new Map([
42
+ [ETHEREUM_MAINNET_CHAIN_ID, 'ethereum-prague'],
43
+ [SEPOLIA_CHAIN_ID, 'sepolia-glamsterdam'],
44
+ ]);
45
+ export const exchangeDepositGasTableOf = (chainId) => {
46
+ const name = EXCHANGE_DEPOSIT_GAS_TABLE_NAME_BY_CHAIN.get(chainId);
47
+ if (name === undefined)
48
+ throw new Error(`no gas table is chosen for chain ${chainId}`);
49
+ return gasTableOf(name, chainId);
50
+ };
51
+ export const crossingCoverage = ({ token, waiting, feeRateE18, conditions }) => {
52
+ const minimumAmount = conditions.minimumPerTxByAddress[token.address.toLowerCase()] ?? null;
53
+ const decision = decideCrossing({
54
+ specVersion: CROSSING_SPEC_VERSION,
55
+ conditions: {
56
+ baseFeeWei: conditions.baseFeeWei,
57
+ priorityFeeWei: conditions.priorityFeeWei,
58
+ maximumBaseFeeWei: null,
59
+ safetyMultipleThousandths: conditions.multipleThousandths,
60
+ gasModel: conditions.gasTable.gasModel,
61
+ },
62
+ deposit: {
63
+ retired: false,
64
+ crossingInFlight: false,
65
+ feeRateE18,
66
+ token: token.address.toLowerCase(),
67
+ decimals: BigInt(token.decimals),
68
+ balance: waiting,
69
+ autoCrossAllowed: true,
70
+ weiPerWholeToken: conditions.weiPerWholeTokenByAddress[token.address.toLowerCase()] ?? null,
71
+ entryFeeWad: 0n,
72
+ minPerTx: minimumAmount,
73
+ maxPerTx: LIMIT_WITHOUT_BRIDGE_READ,
74
+ dailyRemaining: LIMIT_WITHOUT_BRIDGE_READ,
75
+ },
76
+ });
77
+ const { thresholdAmount, costWei } = decision;
78
+ const covered = decision.outcome === 'execute';
79
+ const belowBridgeMinimum = minimumAmount !== null && waiting > 0n && waiting < minimumAmount;
80
+ return {
81
+ decision,
82
+ thresholdAmount,
83
+ waitingAmount: waiting,
84
+ ratio: ratioOf({ waiting, thresholdAmount }),
85
+ costInEther: costWei,
86
+ covered,
87
+ minimumAmount,
88
+ belowBridgeMinimum,
89
+ };
90
+ };
91
+ const ratioOf = ({ waiting, thresholdAmount }) => {
92
+ if (thresholdAmount === null)
93
+ return 0;
94
+ if (thresholdAmount === 0n)
95
+ return 1;
96
+ return Number((waiting * RATIO_SCALE) / thresholdAmount) / Number(RATIO_SCALE);
97
+ };
98
+ export const exchangeDepositStage = ({ coverage, crossing, }) => {
99
+ if (crossing !== null)
100
+ return 'crossing';
101
+ if (coverage.waitingAmount === 0n)
102
+ return 'empty';
103
+ if (coverage.covered)
104
+ return 'ready';
105
+ return 'partway';
106
+ };
107
+ export const coverageOfAddress = ({ address, conditions, }) => crossingCoverage({
108
+ token: address.token,
109
+ waiting: address.waiting,
110
+ feeRateE18: address.settings.feeRateE18,
111
+ conditions,
112
+ });
113
+ export const feeRatePercent = (feeRateE18) => Number(feeRateE18 / 10n ** 14n) / 100;
114
+ export const preferredExchangeDepositToken = ({ tokens, preferredAddress, }) => {
115
+ if (preferredAddress === null)
116
+ return null;
117
+ const match = tokens.find((token) => token.address.toLowerCase() === preferredAddress.toLowerCase());
118
+ return match?.address ?? null;
119
+ };
120
+ export const exchangeDepositAddressMatchesSelection = ({ address, recipient, tokenAddress, feeRateE18, counter, seed, }) => {
121
+ const { settings } = address;
122
+ if (!sameAddress(settings.recipient, recipient))
123
+ return false;
124
+ if (!sameAddress(settings.tokenAddress, tokenAddress))
125
+ return false;
126
+ if (settings.feeRateE18 !== feeRateE18)
127
+ return false;
128
+ if (settings.counter !== counter)
129
+ return false;
130
+ const expectedIndex = factoryIndexOf({ seed, tokenAddress: settings.tokenAddress, feeRateE18, counter });
131
+ return settings.index === expectedIndex;
132
+ };
133
+ export const exchangeDepositNeedsGasLimitWarning = ({ token, chainId, factories = EXCHANGE_DEPOSIT_FACTORY_BY_CHAIN, }) => {
134
+ const factory = factories.get(chainId);
135
+ if (factory === undefined)
136
+ throw new Error(`no deposit factory is configured for chain ${chainId}`);
137
+ return sameAddress(token.address, zeroAddress) && factory.glamsterdamActive;
138
+ };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The cheapest way to send from each exchange, as a dated table. Every figure lives here and nowhere in a view. A
3
+ * figure is a fact of the exchange's own page on the day named in its `feeAsOf`, so a reader can check it.
4
+ */
5
+ /** One exchange's sending guide. */
6
+ export type ExchangeSenderGuide = {
7
+ /** A stable key for the exchange. */
8
+ readonly id: 'kraken' | 'coinbase';
9
+ /** The exchange's proper name. */
10
+ readonly name: string;
11
+ /** The network to choose on the exchange's send screen. */
12
+ readonly network: 'Ethereum';
13
+ /** The withdrawal fee figures, one per asset. An empty list means the exchange shows its fee on the send screen. */
14
+ readonly feeFigures: readonly string[];
15
+ /** The date the fee figures were last updated, as `YYYY-MM-DD`, or null when there are no figures. */
16
+ readonly feeAsOf: string | null;
17
+ /** The exchange's documented minimum withdrawal, or null when none is recorded here. */
18
+ readonly minimumNote: string | null;
19
+ /** The page the figures come from, or null when the exchange shows its fee on the send screen. */
20
+ readonly sourceUrl: string | null;
21
+ };
22
+ /** The exchange senders the deposit page names, in the order it lists them. */
23
+ export declare const EXCHANGE_SENDER_GUIDES: readonly ExchangeSenderGuide[];
24
+ /**
25
+ * The guide of one exchange, or null when the table has none.
26
+ *
27
+ * @param id - the exchange's key
28
+ */
29
+ export declare const exchangeSenderGuideOf: (id: ExchangeSenderGuide["id"]) => ExchangeSenderGuide | null;
@@ -0,0 +1,21 @@
1
+ export const EXCHANGE_SENDER_GUIDES = [
2
+ {
3
+ id: 'kraken',
4
+ name: 'Kraken',
5
+ network: 'Ethereum',
6
+ feeFigures: ['0.45 USDC', '0.00014 ETH', '0.4446 USDT'],
7
+ feeAsOf: '2025-12-31',
8
+ minimumNote: '0.000168 ETH, 0.54 USDC, or 0.53352 USDT (the fee is included)',
9
+ sourceUrl: 'https://support.kraken.com/articles/360000767986-cryptocurrency-withdrawal-fees-and-minimums',
10
+ },
11
+ {
12
+ id: 'coinbase',
13
+ name: 'Coinbase',
14
+ network: 'Ethereum',
15
+ feeFigures: [],
16
+ feeAsOf: null,
17
+ minimumNote: null,
18
+ sourceUrl: null,
19
+ },
20
+ ];
21
+ export const exchangeSenderGuideOf = (id) => EXCHANGE_SENDER_GUIDES.find((guide) => guide.id === id) ?? null;
package/dist/index.d.ts CHANGED
@@ -18,6 +18,8 @@ export { Cache } from './cache.js';
18
18
  export { checkAllowance, type ApprovalParameters } from './chain-read.js';
19
19
  export { clientFromChain, rpcBatchSetting } from './client.js';
20
20
  export { add, configureEndpoints, ENDPOINTS_STORAGE_KEY, entries, get, getSnapshot, hasDefault, key, parse, productionSeed, remove, restoreDefault, setEndpoints, stringify, subscribe, testnetSeed, update, type EndpointEntry, type EndpointStorage, } from './endpoints.js';
21
+ export { FEE_RATE_SCALE, coverageOfAddress, crossingCoverage, ETHEREUM_MAINNET_CHAIN_ID, EXCHANGE_DEPOSIT_DEFAULT_FEE_RATE_E18, EXCHANGE_DEPOSIT_FEE_LIMITS_UNREADABLE, EXCHANGE_DEPOSIT_FEE_RATES, EXCHANGE_DEPOSIT_INITIAL_SELECTION, EXCHANGE_DEPOSIT_GAS_TABLE_NAME_BY_CHAIN, exchangeDepositGasTableOf, exchangeDepositSelectionReducer, assertFeeRatesWithinLimits, exchangeDepositStage, feeRateOptionsOf, feeRatePercent, SEPOLIA_CHAIN_ID, WEI_PER_ETHER, type CrossingCoverage, type CrossingCoverageInput, type ExchangeDepositAddress, type ExchangeDepositAddressOrigin, type ExchangeDepositContractGroup, type ExchangeDepositCrossing, type ExchangeDepositCrossingConditions, type ExchangeDepositRequest, type ExchangeDepositSelection, type ExchangeDepositSelectionAction, type ExchangeDepositSettings, type ExchangeDepositFeeLimits, type ExchangeDepositSource, type ExchangeDepositStage, type ExchangeDepositToken, } from './exchange-deposit.js';
22
+ export { readRecipient, recipientIdenticon, sameAddress, type RecipientIdenticon, type RecipientReading, } from './exchange-deposit-recipient.js';
21
23
  export { chainLogoUrl, relayChainIconUrl } from './image.js';
22
24
  export { evmChains, evmChainsById, isSupportedEvmChain } from './networks.js';
23
25
  export { getBridgeTokenMetadata, getStoreKey, getStoreSize, getTokenAddressFromBridge, getTokenChainIdFromBridge, getTokenMetadata, loadTokenMetadata, parseChainScopedAddress, parseTokenKey, type ChainScopedAddress, } from './token-metadata.js';
package/dist/index.js CHANGED
@@ -3,6 +3,8 @@ export { Cache } from './cache.js';
3
3
  export { checkAllowance } from './chain-read.js';
4
4
  export { clientFromChain, rpcBatchSetting } from './client.js';
5
5
  export { add, configureEndpoints, ENDPOINTS_STORAGE_KEY, entries, get, getSnapshot, hasDefault, key, parse, productionSeed, remove, restoreDefault, setEndpoints, stringify, subscribe, testnetSeed, update, } from './endpoints.js';
6
+ export { FEE_RATE_SCALE, coverageOfAddress, crossingCoverage, ETHEREUM_MAINNET_CHAIN_ID, EXCHANGE_DEPOSIT_DEFAULT_FEE_RATE_E18, EXCHANGE_DEPOSIT_FEE_LIMITS_UNREADABLE, EXCHANGE_DEPOSIT_FEE_RATES, EXCHANGE_DEPOSIT_INITIAL_SELECTION, EXCHANGE_DEPOSIT_GAS_TABLE_NAME_BY_CHAIN, exchangeDepositGasTableOf, exchangeDepositSelectionReducer, assertFeeRatesWithinLimits, exchangeDepositStage, feeRateOptionsOf, feeRatePercent, SEPOLIA_CHAIN_ID, WEI_PER_ETHER, } from './exchange-deposit.js';
7
+ export { readRecipient, recipientIdenticon, sameAddress, } from './exchange-deposit-recipient.js';
6
8
  export { chainLogoUrl, relayChainIconUrl } from './image.js';
7
9
  export { evmChains, evmChainsById, isSupportedEvmChain } from './networks.js';
8
10
  export { getBridgeTokenMetadata, getStoreKey, getStoreSize, getTokenAddressFromBridge, getTokenChainIdFromBridge, getTokenMetadata, loadTokenMetadata, parseChainScopedAddress, parseTokenKey, } from './token-metadata.js';