@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.
Files changed (119) hide show
  1. package/block-polling/package.json +6 -0
  2. package/coinbase-accept-list/package.json +6 -0
  3. package/dist/block-polling.d.ts +33 -0
  4. package/dist/block-polling.js +10 -0
  5. package/dist/cjs/block-polling.d.ts +33 -0
  6. package/dist/cjs/block-polling.js +15 -0
  7. package/dist/cjs/client.d.ts +9 -1
  8. package/dist/cjs/client.js +8 -5
  9. package/dist/cjs/coinbase-accept-list.d.ts +101 -0
  10. package/dist/cjs/coinbase-accept-list.js +97 -0
  11. package/dist/cjs/crossing-decision.d.ts +166 -0
  12. package/dist/cjs/crossing-decision.js +169 -0
  13. package/dist/cjs/crossing-vector-guard.d.ts +45 -0
  14. package/dist/cjs/crossing-vector-guard.js +139 -0
  15. package/dist/cjs/exchange-deposit-board.d.ts +50 -0
  16. package/dist/cjs/exchange-deposit-board.js +70 -0
  17. package/dist/cjs/exchange-deposit-chain.d.ts +146 -0
  18. package/dist/cjs/exchange-deposit-chain.js +228 -0
  19. package/dist/cjs/exchange-deposit-constants.d.ts +10 -0
  20. package/dist/cjs/exchange-deposit-constants.js +6 -0
  21. package/dist/cjs/exchange-deposit-factory-calls.d.ts +245 -0
  22. package/dist/cjs/exchange-deposit-factory-calls.js +103 -0
  23. package/dist/cjs/exchange-deposit-factory.d.ts +87 -0
  24. package/dist/cjs/exchange-deposit-factory.js +110 -0
  25. package/dist/cjs/exchange-deposit-fake.d.ts +67 -0
  26. package/dist/cjs/exchange-deposit-fake.js +179 -0
  27. package/dist/cjs/exchange-deposit-index.d.ts +77 -0
  28. package/dist/cjs/exchange-deposit-index.js +40 -0
  29. package/dist/cjs/exchange-deposit-issuance.d.ts +327 -0
  30. package/dist/cjs/exchange-deposit-issuance.js +244 -0
  31. package/dist/cjs/exchange-deposit-path.d.ts +16 -0
  32. package/dist/cjs/exchange-deposit-path.js +15 -0
  33. package/dist/cjs/exchange-deposit-pow.d.ts +163 -0
  34. package/dist/cjs/exchange-deposit-pow.js +101 -0
  35. package/dist/cjs/exchange-deposit-recipient.d.ts +66 -0
  36. package/dist/cjs/exchange-deposit-recipient.js +35 -0
  37. package/dist/cjs/exchange-deposit-self-cross.d.ts +163 -0
  38. package/dist/cjs/exchange-deposit-self-cross.js +60 -0
  39. package/dist/cjs/exchange-deposit-signin.d.ts +275 -0
  40. package/dist/cjs/exchange-deposit-signin.js +166 -0
  41. package/dist/cjs/exchange-deposit-watch.d.ts +133 -0
  42. package/dist/cjs/exchange-deposit-watch.js +58 -0
  43. package/dist/cjs/exchange-deposit.d.ts +440 -0
  44. package/dist/cjs/exchange-deposit.js +154 -0
  45. package/dist/cjs/exchange-sender-guides.d.ts +29 -0
  46. package/dist/cjs/exchange-sender-guides.js +25 -0
  47. package/dist/cjs/image.d.ts +18 -0
  48. package/dist/cjs/image.js +11 -9
  49. package/dist/cjs/index.d.ts +4 -0
  50. package/dist/cjs/index.js +32 -1
  51. package/dist/cjs/kraken-accept-list.d.ts +70 -0
  52. package/dist/cjs/kraken-accept-list.js +24 -0
  53. package/dist/cjs/unlisted-token.d.ts +26 -0
  54. package/dist/cjs/unlisted-token.js +34 -0
  55. package/dist/client.d.ts +9 -1
  56. package/dist/client.js +8 -5
  57. package/dist/coinbase-accept-list.d.ts +101 -0
  58. package/dist/coinbase-accept-list.js +89 -0
  59. package/dist/crossing-decision.d.ts +166 -0
  60. package/dist/crossing-decision.js +162 -0
  61. package/dist/crossing-vector-guard.d.ts +45 -0
  62. package/dist/crossing-vector-guard.js +134 -0
  63. package/dist/exchange-deposit-board.d.ts +50 -0
  64. package/dist/exchange-deposit-board.js +28 -0
  65. package/dist/exchange-deposit-chain.d.ts +146 -0
  66. package/dist/exchange-deposit-chain.js +218 -0
  67. package/dist/exchange-deposit-constants.d.ts +10 -0
  68. package/dist/exchange-deposit-constants.js +3 -0
  69. package/dist/exchange-deposit-factory-calls.d.ts +245 -0
  70. package/dist/exchange-deposit-factory-calls.js +97 -0
  71. package/dist/exchange-deposit-factory.d.ts +87 -0
  72. package/dist/exchange-deposit-factory.js +104 -0
  73. package/dist/exchange-deposit-fake.d.ts +67 -0
  74. package/dist/exchange-deposit-fake.js +171 -0
  75. package/dist/exchange-deposit-index.d.ts +77 -0
  76. package/dist/exchange-deposit-index.js +34 -0
  77. package/dist/exchange-deposit-issuance.d.ts +327 -0
  78. package/dist/exchange-deposit-issuance.js +224 -0
  79. package/dist/exchange-deposit-path.d.ts +16 -0
  80. package/dist/exchange-deposit-path.js +11 -0
  81. package/dist/exchange-deposit-pow.d.ts +163 -0
  82. package/dist/exchange-deposit-pow.js +93 -0
  83. package/dist/exchange-deposit-recipient.d.ts +66 -0
  84. package/dist/exchange-deposit-recipient.js +28 -0
  85. package/dist/exchange-deposit-self-cross.d.ts +163 -0
  86. package/dist/exchange-deposit-self-cross.js +46 -0
  87. package/dist/exchange-deposit-signin.d.ts +275 -0
  88. package/dist/exchange-deposit-signin.js +147 -0
  89. package/dist/exchange-deposit-watch.d.ts +133 -0
  90. package/dist/exchange-deposit-watch.js +44 -0
  91. package/dist/exchange-deposit.d.ts +440 -0
  92. package/dist/exchange-deposit.js +138 -0
  93. package/dist/exchange-sender-guides.d.ts +29 -0
  94. package/dist/exchange-sender-guides.js +21 -0
  95. package/dist/image.d.ts +18 -0
  96. package/dist/image.js +8 -8
  97. package/dist/index.d.ts +4 -0
  98. package/dist/index.js +4 -0
  99. package/dist/kraken-accept-list.d.ts +70 -0
  100. package/dist/kraken-accept-list.js +17 -0
  101. package/dist/unlisted-token.d.ts +26 -0
  102. package/dist/unlisted-token.js +30 -0
  103. package/exchange-deposit/package.json +6 -0
  104. package/exchange-deposit-board/package.json +6 -0
  105. package/exchange-deposit-chain/package.json +6 -0
  106. package/exchange-deposit-factory/package.json +6 -0
  107. package/exchange-deposit-fake/package.json +6 -0
  108. package/exchange-deposit-issuance/package.json +6 -0
  109. package/exchange-deposit-path/package.json +6 -0
  110. package/exchange-deposit-pow/package.json +6 -0
  111. package/exchange-deposit-recipient/package.json +6 -0
  112. package/exchange-deposit-self-cross/package.json +6 -0
  113. package/exchange-deposit-signin/package.json +6 -0
  114. package/exchange-deposit-watch/package.json +6 -0
  115. package/exchange-sender-guides/package.json +6 -0
  116. package/kraken-accept-list/package.json +6 -0
  117. package/llms.txt +1 -0
  118. package/package.json +487 -6
  119. package/unlisted-token/package.json +6 -0
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exchangeDepositNetworkViewOf = exports.exchangeDepositSourceFor = exports.exchangeDepositEntryOf = exports.FAKE_EXCHANGE_DEPOSIT_NETWORK_NAME = exports.sepoliaExchangeDepositSource = exports.chainExchangeDepositSource = exports.codeKindOf = exports.EXCHANGE_DEPOSIT_READ_ATTEMPT_TIMEOUT_MS = exports.exchangeDepositFlushRequest = void 0;
4
+ const viem_1 = require("viem");
5
+ const client_js_1 = require("./client.js");
6
+ const exchange_deposit_js_1 = require("./exchange-deposit.js");
7
+ const exchange_deposit_factory_js_1 = require("./exchange-deposit-factory.js");
8
+ const exchange_deposit_factory_calls_js_1 = require("./exchange-deposit-factory-calls.js");
9
+ const exchange_deposit_index_js_1 = require("./exchange-deposit-index.js");
10
+ var exchange_deposit_factory_calls_js_2 = require("./exchange-deposit-factory-calls.js");
11
+ Object.defineProperty(exports, "exchangeDepositFlushRequest", { enumerable: true, get: function () { return exchange_deposit_factory_calls_js_2.exchangeDepositFlushRequest; } });
12
+ exports.EXCHANGE_DEPOSIT_READ_ATTEMPT_TIMEOUT_MS = 4_000;
13
+ const readClientOfChain = (chainId) => (0, client_js_1.clientFromChain)(Number(chainId), { attemptTimeoutMs: exports.EXCHANGE_DEPOSIT_READ_ATTEMPT_TIMEOUT_MS });
14
+ const SAFETY_MULTIPLE_THOUSANDTHS = 2000n;
15
+ const DELEGATION_CODE_PATTERN = /^0xef0100[0-9a-f]{40}$/i;
16
+ const codeKindOf = (code) => {
17
+ if (code === undefined || code === '0x')
18
+ return 'no-code';
19
+ if (DELEGATION_CODE_PATTERN.test(code))
20
+ return 'delegation';
21
+ return 'contract';
22
+ };
23
+ exports.codeKindOf = codeKindOf;
24
+ const chainExchangeDepositSource = ({ chainId, client, clientOfChain, }) => {
25
+ const factory = (0, exchange_deposit_factory_js_1.exchangeDepositFactoryOf)(chainId);
26
+ const tokenOf = (tokenAddress) => {
27
+ const found = factory.tokens.find((candidate) => candidate.address.toLowerCase() === tokenAddress.toLowerCase());
28
+ if (found === undefined)
29
+ throw new Error(`token ${tokenAddress} is not offered on chain ${chainId}`);
30
+ return found;
31
+ };
32
+ const feeLimits = async () => {
33
+ try {
34
+ const [maximumFeeRateE18, maximumPartnerRateE18] = await Promise.all([
35
+ client.readContract({
36
+ address: factory.address,
37
+ abi: exchange_deposit_factory_calls_js_1.EXCHANGE_DEPOSIT_FACTORY_ABI,
38
+ functionName: 'MAXIMUM_FEE_RATE_E18',
39
+ }),
40
+ client.readContract({
41
+ address: factory.address,
42
+ abi: exchange_deposit_factory_calls_js_1.EXCHANGE_DEPOSIT_FACTORY_ABI,
43
+ functionName: 'MAXIMUM_PARTNER_RATE_E18',
44
+ }),
45
+ ]);
46
+ return { maximumFeeRateE18, maximumPartnerRateE18 };
47
+ }
48
+ catch (error) {
49
+ throw new Error(`${exchange_deposit_js_1.EXCHANGE_DEPOSIT_FEE_LIMITS_UNREADABLE} Cause: ${error.message}`);
50
+ }
51
+ };
52
+ const minimumKeyOf = (token) => token.contractGroup === 'ether' ? factory.wrappedEtherAddress : token.address;
53
+ const minimumPerTxByAddressOf = async () => {
54
+ const mediator = await client.readContract({
55
+ address: factory.address,
56
+ abi: exchange_deposit_factory_calls_js_1.EXCHANGE_DEPOSIT_FACTORY_ABI,
57
+ functionName: 'mediator',
58
+ });
59
+ const minimums = await Promise.all(factory.tokens.map((token) => client.readContract({
60
+ address: mediator,
61
+ abi: exchange_deposit_factory_calls_js_1.EXCHANGE_DEPOSIT_MEDIATOR_ABI,
62
+ functionName: 'minPerTx',
63
+ args: [minimumKeyOf(token)],
64
+ })));
65
+ return Object.fromEntries(factory.tokens.map((token, index) => [token.address.toLowerCase(), minimums[index]]));
66
+ };
67
+ const readBalance = (token, address) => token.contractGroup === 'ether'
68
+ ? client.getBalance({ address })
69
+ : client.readContract({ address: token.address, abi: viem_1.erc20Abi, functionName: 'balanceOf', args: [address] });
70
+ const hasFactoryEventOf = async (factoryEntry, address) => {
71
+ const logs = await Promise.all(exchange_deposit_factory_calls_js_1.EXCHANGE_DEPOSIT_FACTORY_USAGE_EVENTS.map((event) => client.getLogs({
72
+ address: factoryEntry.address,
73
+ event,
74
+ args: { depositAddress: address },
75
+ fromBlock: factoryEntry.deployedBlock,
76
+ toBlock: 'latest',
77
+ })));
78
+ return logs.some((found) => found.length > 0);
79
+ };
80
+ const probeWithLimits = async (request, limits) => {
81
+ const token = tokenOf(request.tokenAddress);
82
+ (0, exchange_deposit_js_1.assertFeeRatesWithinLimits)({
83
+ feeRateE18: request.feeRateE18,
84
+ partnerRateE18: 0n,
85
+ limits,
86
+ });
87
+ const settings = {
88
+ recipient: request.recipient,
89
+ tokenAddress: request.tokenAddress,
90
+ feeRateE18: request.feeRateE18,
91
+ unwrapToNativePls: false,
92
+ counter: request.counter,
93
+ index: (0, exchange_deposit_index_js_1.factoryIndexOf)({
94
+ seed: request.seed,
95
+ tokenAddress: request.tokenAddress,
96
+ feeRateE18: request.feeRateE18,
97
+ counter: request.counter,
98
+ }),
99
+ };
100
+ const address = await client.readContract({
101
+ address: factory.address,
102
+ abi: exchange_deposit_factory_calls_js_1.EXCHANGE_DEPOSIT_FACTORY_ABI,
103
+ functionName: 'depositAddress',
104
+ args: [(0, exchange_deposit_factory_calls_js_1.factorySettingsTupleOf)({ settings, token })],
105
+ });
106
+ const balance = await readBalance(token, address);
107
+ return { address, token, balance, settings };
108
+ };
109
+ const probe = async (request) => probeWithLimits(request, await feeLimits());
110
+ return {
111
+ listTokens: async () => factory.tokens,
112
+ feeLimits,
113
+ addressFor: async (request) => {
114
+ const { address, token, settings, balance } = await probe(request);
115
+ const result = {
116
+ origin: 'derived',
117
+ address,
118
+ settings,
119
+ token,
120
+ waiting: balance,
121
+ crossing: null,
122
+ };
123
+ return result;
124
+ },
125
+ nextCounterFor: async ({ startCounter, ...request }) => {
126
+ const limits = await feeLimits();
127
+ return (0, exchange_deposit_index_js_1.firstUnusedIndexFrom)({
128
+ start: startCounter,
129
+ isUsed: async (counter) => {
130
+ const { address, balance } = await probeWithLimits({ ...request, counter }, limits);
131
+ const hasFactoryEvent = await hasFactoryEventOf(factory, address);
132
+ return (0, exchange_deposit_index_js_1.exchangeDepositAddressIsUsed)({ balance, hasFactoryEvent });
133
+ },
134
+ });
135
+ },
136
+ crossingConditions: async () => {
137
+ const [block, fees, minimumPerTxByAddress] = await Promise.all([
138
+ client.getBlock({ blockTag: 'latest' }),
139
+ client.estimateFeesPerGas(),
140
+ minimumPerTxByAddressOf(),
141
+ ]);
142
+ if (block.baseFeePerGas === null)
143
+ throw new Error(`chain ${chainId} reports no base fee`);
144
+ return {
145
+ gasTable: (0, exchange_deposit_js_1.exchangeDepositGasTableOf)(chainId),
146
+ baseFeeWei: block.baseFeePerGas,
147
+ priorityFeeWei: fees.maxPriorityFeePerGas,
148
+ multipleThousandths: SAFETY_MULTIPLE_THOUSANDTHS,
149
+ weiPerWholeTokenByAddress: factory.weiPerWholeTokenByAddress,
150
+ minimumPerTxByAddress,
151
+ };
152
+ },
153
+ signerCodeKind: async (signer) => (0, exports.codeKindOf)(await client.getCode({ address: signer })),
154
+ recipientHasCode: async (recipient) => {
155
+ const destination = clientOfChain(factory.destinationChainId);
156
+ return (0, exports.codeKindOf)(await destination.getCode({ address: recipient })) === 'contract';
157
+ },
158
+ };
159
+ };
160
+ exports.chainExchangeDepositSource = chainExchangeDepositSource;
161
+ const sepoliaExchangeDepositSource = () => (0, exports.chainExchangeDepositSource)({
162
+ chainId: exchange_deposit_js_1.SEPOLIA_CHAIN_ID,
163
+ client: readClientOfChain(exchange_deposit_js_1.SEPOLIA_CHAIN_ID),
164
+ clientOfChain: readClientOfChain,
165
+ });
166
+ exports.sepoliaExchangeDepositSource = sepoliaExchangeDepositSource;
167
+ exports.FAKE_EXCHANGE_DEPOSIT_NETWORK_NAME = 'fake';
168
+ const chainIdOfAddressBarName = ({ name, factories, }) => {
169
+ if (name === null)
170
+ return null;
171
+ const match = [...factories].find(([, entry]) => entry.addressBarName === name);
172
+ return match === undefined ? null : match[0];
173
+ };
174
+ const exchangeDepositEntryOf = (options) => {
175
+ const { requestedNetwork, connectedChainId, fakeSource, factories = exchange_deposit_factory_js_1.EXCHANGE_DEPOSIT_FACTORY_BY_CHAIN } = options;
176
+ const fakeOrNothing = fakeSource === 'offered' ? { kind: 'fake' } : { kind: 'unavailable' };
177
+ if (requestedNetwork === exports.FAKE_EXCHANGE_DEPOSIT_NETWORK_NAME)
178
+ return { kind: 'ready', network: fakeOrNothing };
179
+ const namedChainId = chainIdOfAddressBarName({ name: requestedNetwork, factories });
180
+ if (namedChainId !== null && namedChainId !== exchange_deposit_js_1.ETHEREUM_MAINNET_CHAIN_ID) {
181
+ return { kind: 'ready', network: namedChainIdOrNothing({ namedChainId, connectedChainId }) };
182
+ }
183
+ if (namedChainId === null && connectedChainId === null && fakeSource === 'offered') {
184
+ return { kind: 'ready', network: { kind: 'fake' } };
185
+ }
186
+ return mainnetEntryOf({ connectedChainId, factories });
187
+ };
188
+ exports.exchangeDepositEntryOf = exchangeDepositEntryOf;
189
+ const mainnetEntryOf = ({ connectedChainId, factories, }) => {
190
+ if (!factories.has(exchange_deposit_js_1.ETHEREUM_MAINNET_CHAIN_ID))
191
+ return { kind: 'ready', network: { kind: 'unavailable' } };
192
+ if (connectedChainId === null)
193
+ return { kind: 'needs-connect', chainId: exchange_deposit_js_1.ETHEREUM_MAINNET_CHAIN_ID };
194
+ if (BigInt(connectedChainId) !== exchange_deposit_js_1.ETHEREUM_MAINNET_CHAIN_ID)
195
+ return { kind: 'needs-switch', chainId: exchange_deposit_js_1.ETHEREUM_MAINNET_CHAIN_ID };
196
+ return { kind: 'ready', network: { kind: 'factory', chainId: exchange_deposit_js_1.ETHEREUM_MAINNET_CHAIN_ID } };
197
+ };
198
+ const namedChainIdOrNothing = ({ namedChainId, connectedChainId, }) => {
199
+ if (connectedChainId === null)
200
+ return { kind: 'unavailable' };
201
+ if (BigInt(connectedChainId) !== namedChainId)
202
+ return { kind: 'unavailable' };
203
+ return { kind: 'factory', chainId: namedChainId };
204
+ };
205
+ const exchangeDepositSourceFor = ({ network, scenario, fakeSourceOf, }) => {
206
+ if (network.kind === 'factory') {
207
+ return (0, exports.chainExchangeDepositSource)({
208
+ chainId: network.chainId,
209
+ client: readClientOfChain(network.chainId),
210
+ clientOfChain: readClientOfChain,
211
+ });
212
+ }
213
+ if (network.kind === 'fake' && fakeSourceOf !== null)
214
+ return fakeSourceOf(scenario);
215
+ throw new Error('no deposit source is available for this network');
216
+ };
217
+ exports.exchangeDepositSourceFor = exchangeDepositSourceFor;
218
+ const exchangeDepositNetworkViewOf = (network, factories = exchange_deposit_factory_js_1.EXCHANGE_DEPOSIT_FACTORY_BY_CHAIN) => {
219
+ if (network.kind === 'unavailable')
220
+ return null;
221
+ if (network.kind === 'fake')
222
+ return { chainId: exchange_deposit_js_1.SEPOLIA_CHAIN_ID, chainName: 'Sepolia', isTestNetwork: true };
223
+ const entry = factories.get(network.chainId);
224
+ if (entry === undefined)
225
+ return null;
226
+ return { chainId: network.chainId, chainName: entry.chainName, isTestNetwork: entry.isTestNetwork };
227
+ };
228
+ exports.exchangeDepositNetworkViewOf = exchangeDepositNetworkViewOf;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Two numbers the deposit modules share. They live in their own module, so the factory map and the bridge entry can
3
+ * read them without loading the whole deposit module into the first load. `exchange-deposit.ts` re-exports both.
4
+ */
5
+ /** Wei in one ether. */
6
+ export declare const WEI_PER_ETHER: bigint;
7
+ /** The chain id of the Sepolia test network. */
8
+ export declare const SEPOLIA_CHAIN_ID = 11155111n;
9
+ /** The chain id of Ethereum mainnet. */
10
+ export declare const ETHEREUM_MAINNET_CHAIN_ID = 1n;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ETHEREUM_MAINNET_CHAIN_ID = exports.SEPOLIA_CHAIN_ID = exports.WEI_PER_ETHER = void 0;
4
+ exports.WEI_PER_ETHER = 10n ** 18n;
5
+ exports.SEPOLIA_CHAIN_ID = 11155111n;
6
+ exports.ETHEREUM_MAINNET_CHAIN_ID = 1n;
@@ -0,0 +1,245 @@
1
+ import { type Address, type Hex } from 'viem';
2
+ import { type ExchangeDepositAddress, type ExchangeDepositContractGroup, type ExchangeDepositSettings, type ExchangeDepositToken } from './exchange-deposit.js';
3
+ /**
4
+ * The factory's calls: its contract interface, the events that record a use of an address, and the pure encoding of a flush.
5
+ *
6
+ * Kept apart from `exchange-deposit-factory.ts`, which the entry chunk reads on every load. Only the page's chain
7
+ * reader and its flush hook reach this file, so the contract interface and the event definitions load with the page.
8
+ */
9
+ /** The group number the factory takes: 0 for ether, 2 for a single token. Group 1 is retired and never sent. */
10
+ export declare const factoryGroupOf: (contractGroup: ExchangeDepositContractGroup) => number;
11
+ /** The settings tuple of the factory's functions, with the field names of its contract interface. */
12
+ export interface FactorySettingsTuple {
13
+ readonly recipient: Address;
14
+ readonly unwrap: boolean;
15
+ readonly feeRateE18: bigint;
16
+ readonly partner: Address;
17
+ readonly partnerRateE18: bigint;
18
+ readonly group: number;
19
+ readonly token: Address;
20
+ readonly index: bigint;
21
+ }
22
+ /**
23
+ * The factory's settings tuple for an address. The interface sends no partner: the partner is the zero address with
24
+ * a zero rate.
25
+ *
26
+ * @param input.settings - the settings that define the address
27
+ * @param input.token - the token of the address, resolved
28
+ */
29
+ export declare const factorySettingsTupleOf: ({ settings, token, }: {
30
+ settings: ExchangeDepositSettings;
31
+ token: ExchangeDepositToken;
32
+ }) => FactorySettingsTuple;
33
+ export declare const SETTINGS_COMPONENTS: readonly [{
34
+ readonly name: "recipient";
35
+ readonly type: "address";
36
+ }, {
37
+ readonly name: "unwrap";
38
+ readonly type: "bool";
39
+ }, {
40
+ readonly name: "feeRateE18";
41
+ readonly type: "uint256";
42
+ }, {
43
+ readonly name: "partner";
44
+ readonly type: "address";
45
+ }, {
46
+ readonly name: "partnerRateE18";
47
+ readonly type: "uint256";
48
+ }, {
49
+ readonly name: "group";
50
+ readonly type: "uint8";
51
+ }, {
52
+ readonly name: "token";
53
+ readonly type: "address";
54
+ }, {
55
+ readonly name: "index";
56
+ readonly type: "uint256";
57
+ }];
58
+ /**
59
+ * The events the factory emits for a deposit address, from its source. After a flush the address has no balance and
60
+ * no code, so these events are the only record that it was used. Each one names the address as `depositAddress`.
61
+ */
62
+ export declare const EXCHANGE_DEPOSIT_FACTORY_USAGE_EVENTS: readonly [{
63
+ readonly name: "Flushed";
64
+ readonly type: "event";
65
+ readonly inputs: readonly [{
66
+ readonly type: "bytes32";
67
+ readonly name: "settingsHash";
68
+ readonly indexed: true;
69
+ }, {
70
+ readonly type: "address";
71
+ readonly name: "depositAddress";
72
+ readonly indexed: true;
73
+ }];
74
+ }, {
75
+ readonly name: "Rescued";
76
+ readonly type: "event";
77
+ readonly inputs: readonly [{
78
+ readonly type: "bytes32";
79
+ readonly name: "settingsHash";
80
+ readonly indexed: true;
81
+ }, {
82
+ readonly type: "address";
83
+ readonly name: "depositAddress";
84
+ readonly indexed: true;
85
+ }, {
86
+ readonly type: "address";
87
+ readonly name: "to";
88
+ readonly indexed: true;
89
+ }];
90
+ }, {
91
+ readonly name: "Retired";
92
+ readonly type: "event";
93
+ readonly inputs: readonly [{
94
+ readonly type: "bytes32";
95
+ readonly name: "settingsHash";
96
+ readonly indexed: true;
97
+ }, {
98
+ readonly type: "address";
99
+ readonly name: "depositAddress";
100
+ readonly indexed: true;
101
+ }, {
102
+ readonly type: "address";
103
+ readonly name: "recipient";
104
+ readonly indexed: true;
105
+ }];
106
+ }];
107
+ /** The functions of the deposit factory the interface uses: its two maximums, its two address functions and its mediator. */
108
+ export declare const EXCHANGE_DEPOSIT_FACTORY_ABI: readonly [{
109
+ readonly type: "function";
110
+ readonly name: "mediator";
111
+ readonly stateMutability: "view";
112
+ readonly inputs: readonly [];
113
+ readonly outputs: readonly [{
114
+ readonly name: "";
115
+ readonly type: "address";
116
+ }];
117
+ }, {
118
+ readonly type: "function";
119
+ readonly name: "MAXIMUM_FEE_RATE_E18";
120
+ readonly stateMutability: "view";
121
+ readonly inputs: readonly [];
122
+ readonly outputs: readonly [{
123
+ readonly name: "";
124
+ readonly type: "uint256";
125
+ }];
126
+ }, {
127
+ readonly type: "function";
128
+ readonly name: "MAXIMUM_PARTNER_RATE_E18";
129
+ readonly stateMutability: "view";
130
+ readonly inputs: readonly [];
131
+ readonly outputs: readonly [{
132
+ readonly name: "";
133
+ readonly type: "uint256";
134
+ }];
135
+ }, {
136
+ readonly type: "function";
137
+ readonly name: "depositAddress";
138
+ readonly stateMutability: "view";
139
+ readonly inputs: readonly [{
140
+ readonly name: "settings";
141
+ readonly type: "tuple";
142
+ readonly components: readonly [{
143
+ readonly name: "recipient";
144
+ readonly type: "address";
145
+ }, {
146
+ readonly name: "unwrap";
147
+ readonly type: "bool";
148
+ }, {
149
+ readonly name: "feeRateE18";
150
+ readonly type: "uint256";
151
+ }, {
152
+ readonly name: "partner";
153
+ readonly type: "address";
154
+ }, {
155
+ readonly name: "partnerRateE18";
156
+ readonly type: "uint256";
157
+ }, {
158
+ readonly name: "group";
159
+ readonly type: "uint8";
160
+ }, {
161
+ readonly name: "token";
162
+ readonly type: "address";
163
+ }, {
164
+ readonly name: "index";
165
+ readonly type: "uint256";
166
+ }];
167
+ }];
168
+ readonly outputs: readonly [{
169
+ readonly name: "";
170
+ readonly type: "address";
171
+ }];
172
+ }, {
173
+ readonly type: "function";
174
+ readonly name: "flush";
175
+ readonly stateMutability: "payable";
176
+ readonly inputs: readonly [{
177
+ readonly name: "settings";
178
+ readonly type: "tuple";
179
+ readonly components: readonly [{
180
+ readonly name: "recipient";
181
+ readonly type: "address";
182
+ }, {
183
+ readonly name: "unwrap";
184
+ readonly type: "bool";
185
+ }, {
186
+ readonly name: "feeRateE18";
187
+ readonly type: "uint256";
188
+ }, {
189
+ readonly name: "partner";
190
+ readonly type: "address";
191
+ }, {
192
+ readonly name: "partnerRateE18";
193
+ readonly type: "uint256";
194
+ }, {
195
+ readonly name: "group";
196
+ readonly type: "uint8";
197
+ }, {
198
+ readonly name: "token";
199
+ readonly type: "address";
200
+ }, {
201
+ readonly name: "index";
202
+ readonly type: "uint256";
203
+ }];
204
+ }, {
205
+ readonly name: "tokens";
206
+ readonly type: "address[]";
207
+ }];
208
+ readonly outputs: readonly [];
209
+ }];
210
+ /**
211
+ * The one function of the bridge's mediator the interface reads: the smallest transfer it accepts for a token. The
212
+ * factory's `mediator()` names the mediator, and the mediator keeps the minimum per token.
213
+ */
214
+ export declare const EXCHANGE_DEPOSIT_MEDIATOR_ABI: readonly [{
215
+ readonly type: "function";
216
+ readonly name: "minPerTx";
217
+ readonly stateMutability: "view";
218
+ readonly inputs: readonly [{
219
+ readonly name: "token";
220
+ readonly type: "address";
221
+ }];
222
+ readonly outputs: readonly [{
223
+ readonly name: "";
224
+ readonly type: "uint256";
225
+ }];
226
+ }];
227
+ /** A transaction a wallet can send. `value` is always zero: a flush moves the address's own funds, not the reader's. */
228
+ export interface ExchangeDepositFlushRequest {
229
+ readonly to: Address;
230
+ readonly data: Hex;
231
+ readonly value: 0n;
232
+ }
233
+ /**
234
+ * The transaction that finishes the job for one address: a `flush` of the address's token. Anyone may send it, and
235
+ * the funds still reach the recipient the settings name. For ether the token is the zero address, so the flush lists
236
+ * the zero address, as the factory expects.
237
+ *
238
+ * @param input.chainId - the chain the address lives on
239
+ * @param input.address - a derived address. A placeholder has no factory behind it, so it has no flush.
240
+ * @throws when the address is a placeholder, or the chain has no factory
241
+ */
242
+ export declare const exchangeDepositFlushRequest: ({ chainId, address, }: {
243
+ chainId: bigint;
244
+ address: ExchangeDepositAddress;
245
+ }) => ExchangeDepositFlushRequest;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exchangeDepositFlushRequest = exports.EXCHANGE_DEPOSIT_MEDIATOR_ABI = exports.EXCHANGE_DEPOSIT_FACTORY_ABI = exports.EXCHANGE_DEPOSIT_FACTORY_USAGE_EVENTS = exports.SETTINGS_COMPONENTS = exports.factorySettingsTupleOf = exports.factoryGroupOf = void 0;
4
+ const viem_1 = require("viem");
5
+ const exchange_deposit_factory_js_1 = require("./exchange-deposit-factory.js");
6
+ const factoryGroupOf = (contractGroup) => {
7
+ if (contractGroup === 'ether')
8
+ return 0;
9
+ if (contractGroup === 'single')
10
+ return 2;
11
+ throw new Error(`the ${String(contractGroup)} group is not one the factory takes`);
12
+ };
13
+ exports.factoryGroupOf = factoryGroupOf;
14
+ const factorySettingsTupleOf = ({ settings, token, }) => ({
15
+ recipient: settings.recipient,
16
+ unwrap: settings.unwrapToNativePls,
17
+ feeRateE18: settings.feeRateE18,
18
+ partner: viem_1.zeroAddress,
19
+ partnerRateE18: 0n,
20
+ group: (0, exports.factoryGroupOf)(token.contractGroup),
21
+ token: token.address,
22
+ index: settings.index,
23
+ });
24
+ exports.factorySettingsTupleOf = factorySettingsTupleOf;
25
+ exports.SETTINGS_COMPONENTS = [
26
+ { name: 'recipient', type: 'address' },
27
+ { name: 'unwrap', type: 'bool' },
28
+ { name: 'feeRateE18', type: 'uint256' },
29
+ { name: 'partner', type: 'address' },
30
+ { name: 'partnerRateE18', type: 'uint256' },
31
+ { name: 'group', type: 'uint8' },
32
+ { name: 'token', type: 'address' },
33
+ { name: 'index', type: 'uint256' },
34
+ ];
35
+ exports.EXCHANGE_DEPOSIT_FACTORY_USAGE_EVENTS = [
36
+ (0, viem_1.parseAbiItem)('event Flushed(bytes32 indexed settingsHash, address indexed depositAddress)'),
37
+ (0, viem_1.parseAbiItem)('event Rescued(bytes32 indexed settingsHash, address indexed depositAddress, address indexed to)'),
38
+ (0, viem_1.parseAbiItem)('event Retired(bytes32 indexed settingsHash, address indexed depositAddress, address indexed recipient)'),
39
+ ];
40
+ exports.EXCHANGE_DEPOSIT_FACTORY_ABI = [
41
+ {
42
+ type: 'function',
43
+ name: 'mediator',
44
+ stateMutability: 'view',
45
+ inputs: [],
46
+ outputs: [{ name: '', type: 'address' }],
47
+ },
48
+ {
49
+ type: 'function',
50
+ name: 'MAXIMUM_FEE_RATE_E18',
51
+ stateMutability: 'view',
52
+ inputs: [],
53
+ outputs: [{ name: '', type: 'uint256' }],
54
+ },
55
+ {
56
+ type: 'function',
57
+ name: 'MAXIMUM_PARTNER_RATE_E18',
58
+ stateMutability: 'view',
59
+ inputs: [],
60
+ outputs: [{ name: '', type: 'uint256' }],
61
+ },
62
+ {
63
+ type: 'function',
64
+ name: 'depositAddress',
65
+ stateMutability: 'view',
66
+ inputs: [{ name: 'settings', type: 'tuple', components: exports.SETTINGS_COMPONENTS }],
67
+ outputs: [{ name: '', type: 'address' }],
68
+ },
69
+ {
70
+ type: 'function',
71
+ name: 'flush',
72
+ stateMutability: 'payable',
73
+ inputs: [
74
+ { name: 'settings', type: 'tuple', components: exports.SETTINGS_COMPONENTS },
75
+ { name: 'tokens', type: 'address[]' },
76
+ ],
77
+ outputs: [],
78
+ },
79
+ ];
80
+ exports.EXCHANGE_DEPOSIT_MEDIATOR_ABI = [
81
+ {
82
+ type: 'function',
83
+ name: 'minPerTx',
84
+ stateMutability: 'view',
85
+ inputs: [{ name: 'token', type: 'address' }],
86
+ outputs: [{ name: '', type: 'uint256' }],
87
+ },
88
+ ];
89
+ const exchangeDepositFlushRequest = ({ chainId, address, }) => {
90
+ if (address.origin !== 'derived')
91
+ throw new Error('a placeholder address has no flush');
92
+ const { address: factory } = (0, exchange_deposit_factory_js_1.exchangeDepositFactoryOf)(chainId);
93
+ return {
94
+ to: factory,
95
+ value: 0n,
96
+ data: (0, viem_1.encodeFunctionData)({
97
+ abi: exports.EXCHANGE_DEPOSIT_FACTORY_ABI,
98
+ functionName: 'flush',
99
+ args: [(0, exports.factorySettingsTupleOf)({ settings: address.settings, token: address.token }), [address.token.address]],
100
+ }),
101
+ };
102
+ };
103
+ exports.exchangeDepositFlushRequest = exchangeDepositFlushRequest;
@@ -0,0 +1,87 @@
1
+ import { type Address } from 'viem';
2
+ import type { ExchangeDepositToken } from './exchange-deposit.js';
3
+ /**
4
+ * The deposit factory: its address per chain, and the tokens and prices each chain offers.
5
+ *
6
+ * THE ONE PLACE THE FACTORY ADDRESS LIVES. The factory is redeployed with a simpler constructor. When that happens,
7
+ * change the entry of its chain in {@link EXCHANGE_DEPOSIT_FACTORY_BY_CHAIN} and nothing else. No other file names
8
+ * the address.
9
+ *
10
+ * Nothing here reads the chain. Addresses are derived by calling the factory (`depositAddress`), never by a local
11
+ * CREATE2 copy, so a change to the factory's derivation cannot leave this code behind.
12
+ *
13
+ * THIS FILE IS LIGHT ON PURPOSE. It holds only the map, the route checks and the link names, because the bridge's
14
+ * entry chunk reads it on every load. The contract interface, the events and the flush encoding live in `exchange-deposit-factory-calls.ts`.
15
+ */
16
+ /** One deployment of the deposit factory, and the tokens the interface offers on its chain. */
17
+ export interface ExchangeDepositFactoryEntry {
18
+ /** The factory contract. */
19
+ readonly address: Address;
20
+ /** The chain's proper name as a reader sees it, such as `Sepolia`. It is never translated. */
21
+ readonly chainName: string;
22
+ /** Whether the chain is a test network. A test network's addresses take test funds only, and the page says so. */
23
+ readonly isTestNetwork: boolean;
24
+ /** The PulseChain chain the funds arrive on when a deposit from an exchange crosses. */
25
+ readonly destinationChainId: bigint;
26
+ /** The destination chain's proper name as a reader sees it, such as `PulseChain testnet`. It is never translated. */
27
+ readonly destinationChainName: string;
28
+ /** The name the address bar uses for this chain, such as `sepolia`, in `?network=`. */
29
+ readonly addressBarName: string;
30
+ /** The block the factory was deployed at. Read it before scanning logs for the factory. */
31
+ readonly deployedBlock: bigint;
32
+ /**
33
+ * The wrapped ether token of this chain. The factory wraps ether before it crosses, so the mediator keeps the
34
+ * minimum of ether under this address (crossing spec, section 3.2), and the minimum of ether is read from here.
35
+ */
36
+ readonly wrappedEtherAddress: Address;
37
+ /**
38
+ * Whether the Glamsterdam upgrade is active on this chain. It turns on the warning that a plain ether send of 21,000
39
+ * gas fails (see `exchangeDepositNeedsGasLimitWarning`). It does not choose the gas table, which is a separate choice
40
+ * (`EXCHANGE_DEPOSIT_GAS_TABLE_NAME_BY_CHAIN`).
41
+ */
42
+ readonly glamsterdamActive: boolean;
43
+ /** The tokens the interface offers on this chain, in the order to show them. */
44
+ readonly tokens: readonly ExchangeDepositToken[];
45
+ /**
46
+ * The price the interface assumes for each token, by lower case address, in wei of ether per whole token. A test
47
+ * network has no market, so this is a stated assumption and not a feed. A token with no entry has no threshold.
48
+ */
49
+ readonly weiPerWholeTokenByAddress: Readonly<Record<string, bigint>>;
50
+ }
51
+ /**
52
+ * The factory per chain. There is ONE entry per deployment; a chain without an entry has no real deposit addresses.
53
+ */
54
+ export declare const EXCHANGE_DEPOSIT_FACTORY_BY_CHAIN: ReadonlyMap<bigint, ExchangeDepositFactoryEntry>;
55
+ /**
56
+ * Whether a bridge route is one a deposit from an exchange serves: its origin chain has a factory, and the route ends
57
+ * on the chain that factory's deposits arrive on. The factories are read from the map, never named here, so a factory
58
+ * added to the map turns its route on with no other change.
59
+ *
60
+ * @param input.originChainId - the chain the bridge sends from
61
+ * @param input.destinationChainId - the chain the bridge sends to
62
+ * @param input.factories - the factories to read. Defaults to the deployed ones.
63
+ */
64
+ export declare const isExchangeDepositRoute: ({ originChainId, destinationChainId, factories, }: {
65
+ originChainId: number;
66
+ destinationChainId: number;
67
+ factories?: ReadonlyMap<bigint, ExchangeDepositFactoryEntry>;
68
+ }) => boolean;
69
+ /**
70
+ * The address-bar name of the factory on a chain, for a link that must open that chain's deposits. A chain with no
71
+ * factory has no name, so a link to it carries no network.
72
+ *
73
+ * @param input.chainId - the chain the deposit starts on
74
+ * @param input.factories - the factories to read. Defaults to the deployed ones.
75
+ * @returns the name, or null when the chain has no factory
76
+ */
77
+ export declare const addressBarNetworkOf: ({ chainId, factories, }: {
78
+ chainId: number;
79
+ factories?: ReadonlyMap<bigint, ExchangeDepositFactoryEntry>;
80
+ }) => string | null;
81
+ /**
82
+ * The factory entry of a chain. It never falls back to another chain's factory.
83
+ *
84
+ * @param chainId - the Ethereum chain the deposit runs on
85
+ * @throws when no factory is deployed for the chain in this repository
86
+ */
87
+ export declare const exchangeDepositFactoryOf: (chainId: bigint) => ExchangeDepositFactoryEntry;