@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,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exchangeDepositFactoryOf = exports.addressBarNetworkOf = exports.isExchangeDepositRoute = exports.EXCHANGE_DEPOSIT_FACTORY_BY_CHAIN = void 0;
4
+ const viem_1 = require("viem");
5
+ const exchange_deposit_constants_js_1 = require("./exchange-deposit-constants.js");
6
+ const SEPOLIA_USDC_ADDRESS = (0, viem_1.getAddress)('0xda9d4f9b69ac6C22e444eD9aF0CfC043b7a7f53f');
7
+ const SEPOLIA_TOKENS = [
8
+ {
9
+ symbol: 'ETH',
10
+ name: 'Sepolia Ether',
11
+ address: viem_1.zeroAddress,
12
+ decimals: 18,
13
+ contractGroup: 'ether',
14
+ },
15
+ {
16
+ symbol: 'USDC',
17
+ name: 'USD Coin',
18
+ address: SEPOLIA_USDC_ADDRESS,
19
+ decimals: 6,
20
+ contractGroup: 'single',
21
+ },
22
+ ];
23
+ const SEPOLIA_WEI_PER_WHOLE_TOKEN_BY_ADDRESS = {
24
+ [viem_1.zeroAddress]: exchange_deposit_constants_js_1.WEI_PER_ETHER,
25
+ [SEPOLIA_USDC_ADDRESS.toLowerCase()]: exchange_deposit_constants_js_1.WEI_PER_ETHER / 3200n,
26
+ };
27
+ const MAINNET_USDC_ADDRESS = (0, viem_1.getAddress)('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48');
28
+ const MAINNET_USDT_ADDRESS = (0, viem_1.getAddress)('0xdAC17F958D2ee523a2206206994597C13D831ec7');
29
+ const MAINNET_DAI_ADDRESS = (0, viem_1.getAddress)('0x6B175474E89094C44Da98b954EedeAC495271d0F');
30
+ const MAINNET_TOKENS = [
31
+ {
32
+ symbol: 'ETH',
33
+ name: 'Ether',
34
+ address: viem_1.zeroAddress,
35
+ decimals: 18,
36
+ contractGroup: 'ether',
37
+ },
38
+ {
39
+ symbol: 'USDC',
40
+ name: 'USD Coin',
41
+ address: MAINNET_USDC_ADDRESS,
42
+ decimals: 6,
43
+ contractGroup: 'single',
44
+ },
45
+ {
46
+ symbol: 'USDT',
47
+ name: 'Tether',
48
+ address: MAINNET_USDT_ADDRESS,
49
+ decimals: 6,
50
+ contractGroup: 'single',
51
+ },
52
+ {
53
+ symbol: 'DAI',
54
+ name: 'Dai',
55
+ address: MAINNET_DAI_ADDRESS,
56
+ decimals: 18,
57
+ contractGroup: 'single',
58
+ },
59
+ ];
60
+ const MAINNET_WEI_PER_WHOLE_TOKEN_BY_ADDRESS = {
61
+ [viem_1.zeroAddress]: exchange_deposit_constants_js_1.WEI_PER_ETHER,
62
+ };
63
+ exports.EXCHANGE_DEPOSIT_FACTORY_BY_CHAIN = new Map([
64
+ [
65
+ exchange_deposit_constants_js_1.SEPOLIA_CHAIN_ID,
66
+ {
67
+ address: (0, viem_1.getAddress)('0xE66877Cfe4CEc10ffBbBB3092B7001321AB5809D'),
68
+ chainName: 'Sepolia',
69
+ isTestNetwork: true,
70
+ destinationChainId: 943n,
71
+ destinationChainName: 'PulseChain testnet',
72
+ addressBarName: 'sepolia',
73
+ deployedBlock: 12144436n,
74
+ wrappedEtherAddress: (0, viem_1.getAddress)('0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9'),
75
+ glamsterdamActive: true,
76
+ tokens: SEPOLIA_TOKENS,
77
+ weiPerWholeTokenByAddress: SEPOLIA_WEI_PER_WHOLE_TOKEN_BY_ADDRESS,
78
+ },
79
+ ],
80
+ [
81
+ exchange_deposit_constants_js_1.ETHEREUM_MAINNET_CHAIN_ID,
82
+ {
83
+ address: (0, viem_1.getAddress)('0x2cf3A381Ae662A06E478491D73bf5D7fD4ebCa0e'),
84
+ chainName: 'Ethereum',
85
+ isTestNetwork: false,
86
+ destinationChainId: 369n,
87
+ destinationChainName: 'PulseChain',
88
+ addressBarName: 'ethereum',
89
+ deployedBlock: 26439236n,
90
+ wrappedEtherAddress: (0, viem_1.getAddress)('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
91
+ glamsterdamActive: false,
92
+ tokens: MAINNET_TOKENS,
93
+ weiPerWholeTokenByAddress: MAINNET_WEI_PER_WHOLE_TOKEN_BY_ADDRESS,
94
+ },
95
+ ],
96
+ ]);
97
+ const isExchangeDepositRoute = ({ originChainId, destinationChainId, factories = exports.EXCHANGE_DEPOSIT_FACTORY_BY_CHAIN, }) => {
98
+ const factory = factories.get(BigInt(originChainId));
99
+ return factory !== undefined && factory.destinationChainId === BigInt(destinationChainId);
100
+ };
101
+ exports.isExchangeDepositRoute = isExchangeDepositRoute;
102
+ const addressBarNetworkOf = ({ chainId, factories = exports.EXCHANGE_DEPOSIT_FACTORY_BY_CHAIN, }) => factories.get(BigInt(chainId))?.addressBarName ?? null;
103
+ exports.addressBarNetworkOf = addressBarNetworkOf;
104
+ const exchangeDepositFactoryOf = (chainId) => {
105
+ const entry = exports.EXCHANGE_DEPOSIT_FACTORY_BY_CHAIN.get(chainId);
106
+ if (entry === undefined)
107
+ throw new Error(`no deposit factory is configured for chain ${chainId}`);
108
+ return entry;
109
+ };
110
+ exports.exchangeDepositFactoryOf = exchangeDepositFactoryOf;
@@ -0,0 +1,67 @@
1
+ import { type Address } from 'viem';
2
+ import { type ExchangeDepositAddress, type ExchangeDepositFeeLimits, type ExchangeDepositCrossingConditions, type ExchangeDepositRequest, type ExchangeDepositSettings, type ExchangeDepositSource, type ExchangeDepositToken } from './exchange-deposit.js';
3
+ import { type ExchangeDepositSeed } from './exchange-deposit-index.js';
4
+ /** The tokens the fake source offers, in the order a reader sees them. */
5
+ export declare const FAKE_EXCHANGE_DEPOSIT_TOKENS: readonly ExchangeDepositToken[];
6
+ /** Which situations the fake source can act out. */
7
+ export type FakeExchangeDepositScenario = 'empty' | 'partway' | 'ready' | 'crossing';
8
+ /** Every scenario, for a screen that lets a reviewer pick one. */
9
+ export declare const FAKE_EXCHANGE_DEPOSIT_SCENARIOS: readonly FakeExchangeDepositScenario[];
10
+ /**
11
+ * Whether a string names a scenario.
12
+ *
13
+ * @param value - text from an address bar, or null
14
+ */
15
+ export declare const isFakeExchangeDepositScenario: (value: string | null) => value is FakeExchangeDepositScenario;
16
+ /**
17
+ * One fake address from its settings. NOT the real derivation (TODO-real): it
18
+ * hashes the settings so the same settings give the same address and a new index
19
+ * gives another, which is the only property the screens need. Like the factory,
20
+ * it gives ether one address (the `ether` group) and every token its own address
21
+ * (the `single` group).
22
+ *
23
+ * @param settings - the settings that define the address
24
+ */
25
+ export declare const fakeDeriveExchangeDepositAddress: (settings: ExchangeDepositSettings) => Address;
26
+ /**
27
+ * What the fake executor weighs: a crossing on Ethereum mainnet at the paid gas of its table, at a base fee of
28
+ * 1.2 gwei plus a tip of 0.1 gwei, times 2, with ether at 3,200 dollars.
29
+ */
30
+ export declare const FAKE_EXCHANGE_DEPOSIT_CONDITIONS: ExchangeDepositCrossingConditions;
31
+ /**
32
+ * Builds the fake address of a set of settings, in the state a scenario describes.
33
+ *
34
+ * @param input.settings - the settings that define the address
35
+ * @param input.scenario - the situation to act out
36
+ * @throws when the fake source does not offer the token of the settings
37
+ */
38
+ export declare const fakeExchangeDepositAddress: ({ settings, scenario, }: {
39
+ settings: ExchangeDepositSettings;
40
+ scenario: FakeExchangeDepositScenario;
41
+ }) => ExchangeDepositAddress;
42
+ /**
43
+ * The settings of a request. Wrapped PLS arrives as PLS: the only token that asks for the unwrap. The factory index is
44
+ * derived from the request's seed, the same way the real source derives it.
45
+ *
46
+ * @param request - the recipient, the token, the fee, the counter and the seed
47
+ */
48
+ export declare const settingsOfRequest: (request: ExchangeDepositRequest) => ExchangeDepositSettings;
49
+ /**
50
+ * The seed the fake source uses. A development build that acts out a scenario skips the sign-in, so the fake addresses
51
+ * need a fixed seed rather than a signature. It is not a secret: the fake addresses hold nothing.
52
+ */
53
+ export declare const FAKE_EXCHANGE_DEPOSIT_SEED: ExchangeDepositSeed;
54
+ /** The recipient the fake source reports as a contract: any address ending in `c0de`. */
55
+ export declare const FAKE_CONTRACT_RECIPIENT: Address;
56
+ /**
57
+ * The maximums the fake factory reports: the same 1e16 (1 percent) for each rate as the deployed factory. A test or a
58
+ * draft reads these in place of the chain.
59
+ */
60
+ export declare const FAKE_EXCHANGE_DEPOSIT_FEE_LIMITS: ExchangeDepositFeeLimits;
61
+ /**
62
+ * A source that acts out one scenario. TODO-real: replace with the source the
63
+ * contract work provides.
64
+ *
65
+ * @param scenario - the situation to act out
66
+ */
67
+ export declare const fakeExchangeDepositSource: (scenario: FakeExchangeDepositScenario) => ExchangeDepositSource;
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fakeExchangeDepositSource = exports.FAKE_EXCHANGE_DEPOSIT_FEE_LIMITS = exports.FAKE_CONTRACT_RECIPIENT = exports.FAKE_EXCHANGE_DEPOSIT_SEED = exports.settingsOfRequest = exports.fakeExchangeDepositAddress = exports.FAKE_EXCHANGE_DEPOSIT_CONDITIONS = exports.fakeDeriveExchangeDepositAddress = exports.isFakeExchangeDepositScenario = exports.FAKE_EXCHANGE_DEPOSIT_SCENARIOS = exports.FAKE_EXCHANGE_DEPOSIT_TOKENS = void 0;
4
+ const viem_1 = require("viem");
5
+ const exchange_deposit_js_1 = require("./exchange-deposit.js");
6
+ const exchange_deposit_index_js_1 = require("./exchange-deposit-index.js");
7
+ const USDC = {
8
+ symbol: 'USDC',
9
+ name: 'USD Coin',
10
+ address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
11
+ decimals: 6,
12
+ contractGroup: 'single',
13
+ };
14
+ const USDT = {
15
+ symbol: 'USDT',
16
+ name: 'Tether',
17
+ address: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
18
+ decimals: 6,
19
+ contractGroup: 'single',
20
+ };
21
+ const DAI = {
22
+ symbol: 'DAI',
23
+ name: 'Dai',
24
+ address: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
25
+ decimals: 18,
26
+ contractGroup: 'single',
27
+ };
28
+ const ETHER = {
29
+ symbol: 'ETH',
30
+ name: 'Ether',
31
+ address: viem_1.zeroAddress,
32
+ decimals: 18,
33
+ contractGroup: 'ether',
34
+ };
35
+ const WBTC = {
36
+ symbol: 'WBTC',
37
+ name: 'Wrapped Bitcoin',
38
+ address: '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599',
39
+ decimals: 8,
40
+ contractGroup: 'single',
41
+ };
42
+ const PLS = {
43
+ symbol: 'PLS',
44
+ name: 'Pulse',
45
+ address: '0xA882606494D86804B5514E07e6Bd2D6a6eE6d68A',
46
+ decimals: 18,
47
+ contractGroup: 'single',
48
+ };
49
+ exports.FAKE_EXCHANGE_DEPOSIT_TOKENS = [USDC, USDT, DAI, ETHER, WBTC, PLS];
50
+ exports.FAKE_EXCHANGE_DEPOSIT_SCENARIOS = [
51
+ 'empty',
52
+ 'partway',
53
+ 'ready',
54
+ 'crossing',
55
+ ];
56
+ const isFakeExchangeDepositScenario = (value) => exports.FAKE_EXCHANGE_DEPOSIT_SCENARIOS.includes(value);
57
+ exports.isFakeExchangeDepositScenario = isFakeExchangeDepositScenario;
58
+ const tokenOfSettings = (settings) => exports.FAKE_EXCHANGE_DEPOSIT_TOKENS.find((candidate) => candidate.address.toLowerCase() === settings.tokenAddress.toLowerCase());
59
+ const fakeDeriveExchangeDepositAddress = (settings) => {
60
+ const token = tokenOfSettings(settings);
61
+ const group = token?.contractGroup ?? 'single';
62
+ const singleToken = group === 'single' ? settings.tokenAddress.toLowerCase() : viem_1.zeroAddress;
63
+ const hash = (0, viem_1.keccak256)((0, viem_1.encodePacked)(['address', 'string', 'address', 'uint256', 'bool', 'uint256'], [
64
+ settings.recipient,
65
+ group,
66
+ singleToken,
67
+ settings.feeRateE18,
68
+ settings.unwrapToNativePls,
69
+ settings.index,
70
+ ]));
71
+ return (0, viem_1.getAddress)(`0x${hash.slice(-40)}`);
72
+ };
73
+ exports.fakeDeriveExchangeDepositAddress = fakeDeriveExchangeDepositAddress;
74
+ exports.FAKE_EXCHANGE_DEPOSIT_CONDITIONS = {
75
+ gasTable: (0, exchange_deposit_js_1.exchangeDepositGasTableOf)(exchange_deposit_js_1.ETHEREUM_MAINNET_CHAIN_ID),
76
+ baseFeeWei: 1200000000n,
77
+ priorityFeeWei: 100000000n,
78
+ multipleThousandths: 2000n,
79
+ weiPerWholeTokenByAddress: {
80
+ [USDC.address.toLowerCase()]: exchange_deposit_js_1.WEI_PER_ETHER / 3200n,
81
+ [USDT.address.toLowerCase()]: exchange_deposit_js_1.WEI_PER_ETHER / 3200n,
82
+ [DAI.address.toLowerCase()]: exchange_deposit_js_1.WEI_PER_ETHER / 3200n,
83
+ [ETHER.address.toLowerCase()]: exchange_deposit_js_1.WEI_PER_ETHER,
84
+ [WBTC.address.toLowerCase()]: 20n * exchange_deposit_js_1.WEI_PER_ETHER,
85
+ [PLS.address.toLowerCase()]: exchange_deposit_js_1.WEI_PER_ETHER / 300000n,
86
+ },
87
+ minimumPerTxByAddress: {
88
+ [USDC.address.toLowerCase()]: 0n,
89
+ [USDT.address.toLowerCase()]: 0n,
90
+ [DAI.address.toLowerCase()]: 0n,
91
+ [ETHER.address.toLowerCase()]: 0n,
92
+ [WBTC.address.toLowerCase()]: 0n,
93
+ [PLS.address.toLowerCase()]: 0n,
94
+ },
95
+ };
96
+ const situationKey = (symbol, feeRateE18) => `${symbol}:${feeRateE18}`;
97
+ const [, ONE_PERCENT, HALF_PERCENT] = exchange_deposit_js_1.EXCHANGE_DEPOSIT_FEE_RATES;
98
+ const situationsByScenario = {
99
+ empty: {},
100
+ partway: {
101
+ [situationKey('USDC', ONE_PERCENT)]: { balance: '120' },
102
+ [situationKey('USDT', HALF_PERCENT)]: { balance: '90' },
103
+ [situationKey('ETH', ONE_PERCENT)]: { balance: '0.03' },
104
+ },
105
+ ready: {
106
+ [situationKey('USDC', ONE_PERCENT)]: { balance: '300' },
107
+ [situationKey('USDT', HALF_PERCENT)]: { balance: '600' },
108
+ [situationKey('ETH', ONE_PERCENT)]: { balance: '0.09' },
109
+ },
110
+ crossing: {
111
+ [situationKey('USDC', ONE_PERCENT)]: { balance: '300', crossing: true },
112
+ [situationKey('USDT', HALF_PERCENT)]: { balance: '600' },
113
+ [situationKey('ETH', ONE_PERCENT)]: { balance: '0.09' },
114
+ },
115
+ };
116
+ const FAKE_CROSSING_HASH = `0x${'ab'.repeat(32)}`;
117
+ const crossingOf = (situation) => situation?.crossing === true
118
+ ? { transactionHash: FAKE_CROSSING_HASH, startedAtMs: Date.now() - 45_000 }
119
+ : null;
120
+ const fakeExchangeDepositAddress = ({ settings, scenario, }) => {
121
+ const token = tokenOfSettings(settings);
122
+ if (token === undefined)
123
+ throw new Error(`the fake source has no token ${settings.tokenAddress}`);
124
+ const situation = settings.counter === 0 ? situationsByScenario[scenario][situationKey(token.symbol, settings.feeRateE18)] : undefined;
125
+ return {
126
+ origin: 'placeholder',
127
+ address: (0, exports.fakeDeriveExchangeDepositAddress)(settings),
128
+ settings,
129
+ token,
130
+ waiting: situation === undefined ? 0n : (0, viem_1.parseUnits)(situation.balance, token.decimals),
131
+ crossing: crossingOf(situation),
132
+ };
133
+ };
134
+ exports.fakeExchangeDepositAddress = fakeExchangeDepositAddress;
135
+ const settingsOfRequest = (request) => ({
136
+ recipient: request.recipient,
137
+ tokenAddress: request.tokenAddress,
138
+ feeRateE18: request.feeRateE18,
139
+ counter: request.counter,
140
+ index: (0, exchange_deposit_index_js_1.factoryIndexOf)({
141
+ seed: request.seed,
142
+ tokenAddress: request.tokenAddress,
143
+ feeRateE18: request.feeRateE18,
144
+ counter: request.counter,
145
+ }),
146
+ unwrapToNativePls: request.tokenAddress.toLowerCase() === PLS.address.toLowerCase(),
147
+ });
148
+ exports.settingsOfRequest = settingsOfRequest;
149
+ exports.FAKE_EXCHANGE_DEPOSIT_SEED = (0, viem_1.keccak256)((0, viem_1.toHex)('fake-exchange-deposit-seed'));
150
+ exports.FAKE_CONTRACT_RECIPIENT = (0, viem_1.getAddress)('0x000000000000000000000000000000000000c0de');
151
+ exports.FAKE_EXCHANGE_DEPOSIT_FEE_LIMITS = {
152
+ maximumFeeRateE18: 10n ** 16n,
153
+ maximumPartnerRateE18: 10n ** 16n,
154
+ };
155
+ const fakeExchangeDepositSource = (scenario) => ({
156
+ listTokens: async () => exports.FAKE_EXCHANGE_DEPOSIT_TOKENS,
157
+ feeLimits: async () => exports.FAKE_EXCHANGE_DEPOSIT_FEE_LIMITS,
158
+ addressFor: async (request) => {
159
+ (0, exchange_deposit_js_1.assertFeeRatesWithinLimits)({ feeRateE18: request.feeRateE18, partnerRateE18: 0n, limits: exports.FAKE_EXCHANGE_DEPOSIT_FEE_LIMITS });
160
+ return (0, exports.fakeExchangeDepositAddress)({ settings: (0, exports.settingsOfRequest)(request), scenario });
161
+ },
162
+ nextCounterFor: ({ startCounter, ...request }) => {
163
+ (0, exchange_deposit_js_1.assertFeeRatesWithinLimits)({ feeRateE18: request.feeRateE18, partnerRateE18: 0n, limits: exports.FAKE_EXCHANGE_DEPOSIT_FEE_LIMITS });
164
+ return (0, exchange_deposit_index_js_1.firstUnusedIndexFrom)({
165
+ start: startCounter,
166
+ isUsed: async (counter) => {
167
+ const address = await (0, exports.fakeExchangeDepositAddress)({
168
+ settings: (0, exports.settingsOfRequest)({ ...request, counter }),
169
+ scenario,
170
+ });
171
+ return address.waiting > 0n || address.crossing !== null;
172
+ },
173
+ });
174
+ },
175
+ signerCodeKind: async () => 'no-code',
176
+ crossingConditions: async () => exports.FAKE_EXCHANGE_DEPOSIT_CONDITIONS,
177
+ recipientHasCode: async (recipient) => recipient.toLowerCase().endsWith('c0de'),
178
+ });
179
+ exports.fakeExchangeDepositSource = fakeExchangeDepositSource;
@@ -0,0 +1,77 @@
1
+ import { type Address, type Hex } from 'viem';
2
+ /**
3
+ * The index of the next free deposit address.
4
+ *
5
+ * An address is for one deposit (single-use, owner decision 2026-11-13). A new deposit takes the LOWEST index whose
6
+ * address is free: it holds no balance and the factory has not recorded a use of it. The caller decides what
7
+ * "used" means for an address (see {@link exchangeDepositAddressIsUsed}); this file only scans.
8
+ */
9
+ /** How many addresses are read at once. A walk reads two, so the wait stays short on a slow node and few reads are in flight. */
10
+ export declare const EXCHANGE_DEPOSIT_INDEX_SCAN_BATCH_SIZE = 2;
11
+ /** How many indexes a walk checks from its start before it gives up. A reader who uses a thousand addresses needs a new design. */
12
+ export declare const EXCHANGE_DEPOSIT_INDEX_SCAN_LIMIT = 1000;
13
+ /** What the facts of one address say about whether it is in use. */
14
+ export interface ExchangeDepositAddressFacts {
15
+ /** The balance of the address's token, in base units. For ether, the whole ether balance. */
16
+ readonly balance: bigint;
17
+ /**
18
+ * Whether the factory logged a flush, a rescue or a retirement of the address. A flushed address ends with no
19
+ * balance and no code, so this event is the only record of the use.
20
+ */
21
+ readonly hasFactoryEvent: boolean;
22
+ }
23
+ /**
24
+ * Whether an address is used: it holds a balance now, or the factory has logged a use of it. A flushed address
25
+ * with no balance is still used, because its flush is logged.
26
+ *
27
+ * @param facts - the balance of the address and whether the factory logged a use of it
28
+ */
29
+ export declare const exchangeDepositAddressIsUsed: ({ balance, hasFactoryEvent }: ExchangeDepositAddressFacts) => boolean;
30
+ /** The options of {@link firstUnusedIndexFrom}. */
31
+ export interface FirstUnusedIndexOptions {
32
+ /** The first index the walk checks. */
33
+ readonly start: number;
34
+ /** Whether the address at an index is used. Called once per index, in batches. */
35
+ readonly isUsed: (index: number) => Promise<boolean>;
36
+ /** How many indexes are read at once. */
37
+ readonly batchSize?: number;
38
+ /** How many indexes, counted from the start, the walk checks before it gives up. */
39
+ readonly limit?: number;
40
+ }
41
+ /**
42
+ * The first free index at or after a start index, walking forward in small batches. The walk never reads below its
43
+ * start, so it never rescans indexes the caller already knows about. The caller decides where the start is: a
44
+ * recovery walk starts at 0, and a new address starts after the highest address already issued.
45
+ *
46
+ * @param options - the start, the used check, the batch size and the limit
47
+ * @returns the first index at or after the start for which `isUsed` is false
48
+ * @throws when every index in the walk's window is used, or when the start is not a whole number from 0
49
+ */
50
+ export declare const firstUnusedIndexFrom: ({ start, isUsed, batchSize, limit, }: FirstUnusedIndexOptions) => Promise<number>;
51
+ /**
52
+ * The 32-byte seed an address family grows from. It is the same for every address of one recipient on one chain and
53
+ * factory: an ordinary wallet gives it through {@link exchangeDepositSeedOfSignature}, and a smart-contract wallet
54
+ * through a random 32 bytes. Nobody can compute it from public facts.
55
+ */
56
+ export type ExchangeDepositSeed = Hex;
57
+ /**
58
+ * The factory index of one address: the uint256 the factory takes as `index`. It is a keccak256 hash of the seed and
59
+ * the settings that vary, with the counter last. A reader who does not hold the seed cannot compute it, so nobody can
60
+ * guess an address, pre-draw it or burn a scan range (threat analysis, section 6 (ii)).
61
+ *
62
+ * The hash uses `abi.encode`, so every field has a fixed width and no two inputs share an encoding. The counter is
63
+ * the number of the address within the settings: 0 is the first, and each new deposit takes the next counter.
64
+ *
65
+ * @param input.seed - the 32-byte seed of the recipient on this chain and factory
66
+ * @param input.tokenAddress - the token of the address
67
+ * @param input.feeRateE18 - the exact fee of the address, in 1e18 fixed point
68
+ * @param input.counter - the position of the address among those of the same settings, from 0
69
+ * @returns the factory index, a uint256 that is 256 bits wide in practice
70
+ * @throws when the counter is negative or not a safe integer
71
+ */
72
+ export declare const factoryIndexOf: ({ seed, tokenAddress, feeRateE18, counter, }: {
73
+ seed: ExchangeDepositSeed;
74
+ tokenAddress: Address;
75
+ feeRateE18: bigint;
76
+ counter: number;
77
+ }) => bigint;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.factoryIndexOf = exports.firstUnusedIndexFrom = exports.exchangeDepositAddressIsUsed = exports.EXCHANGE_DEPOSIT_INDEX_SCAN_LIMIT = exports.EXCHANGE_DEPOSIT_INDEX_SCAN_BATCH_SIZE = void 0;
4
+ const viem_1 = require("viem");
5
+ exports.EXCHANGE_DEPOSIT_INDEX_SCAN_BATCH_SIZE = 2;
6
+ exports.EXCHANGE_DEPOSIT_INDEX_SCAN_LIMIT = 1000;
7
+ const exchangeDepositAddressIsUsed = ({ balance, hasFactoryEvent }) => balance > 0n || hasFactoryEvent;
8
+ exports.exchangeDepositAddressIsUsed = exchangeDepositAddressIsUsed;
9
+ const firstUnusedIndexFrom = async ({ start, isUsed, batchSize = exports.EXCHANGE_DEPOSIT_INDEX_SCAN_BATCH_SIZE, limit = exports.EXCHANGE_DEPOSIT_INDEX_SCAN_LIMIT, }) => {
10
+ if (!Number.isSafeInteger(start) || start < 0)
11
+ throw new Error(`the walk must start at a whole number from 0, not ${start}`);
12
+ const end = start + limit;
13
+ for (let batchStart = start; batchStart < end; batchStart += batchSize) {
14
+ const indexes = Array.from({ length: Math.min(batchSize, end - batchStart) }, (_, offset) => batchStart + offset);
15
+ const usedFlags = await Promise.all(indexes.map((index) => isUsed(index)));
16
+ const firstFree = usedFlags.indexOf(false);
17
+ if (firstFree !== -1)
18
+ return indexes[firstFree];
19
+ }
20
+ throw new Error(`every deposit address from index ${start} to ${end - 1} is in use`);
21
+ };
22
+ exports.firstUnusedIndexFrom = firstUnusedIndexFrom;
23
+ const INDEX_DOMAIN_TAG = (0, viem_1.keccak256)((0, viem_1.toHex)('gibs-deposit-index-v1'));
24
+ const NO_PARTNER_ADDRESS = viem_1.zeroAddress;
25
+ const NO_PARTNER_RATE_E18 = 0n;
26
+ const factoryIndexOf = ({ seed, tokenAddress, feeRateE18, counter, }) => {
27
+ if (!Number.isSafeInteger(counter) || counter < 0)
28
+ throw new Error(`the address counter must be a whole number from 0, not ${counter}`);
29
+ const encoded = (0, viem_1.encodeAbiParameters)([
30
+ { type: 'bytes32' },
31
+ { type: 'bytes32' },
32
+ { type: 'address' },
33
+ { type: 'uint256' },
34
+ { type: 'address' },
35
+ { type: 'uint256' },
36
+ { type: 'uint256' },
37
+ ], [INDEX_DOMAIN_TAG, seed, tokenAddress, feeRateE18, NO_PARTNER_ADDRESS, NO_PARTNER_RATE_E18, BigInt(counter)]);
38
+ return BigInt((0, viem_1.keccak256)(encoded));
39
+ };
40
+ exports.factoryIndexOf = factoryIndexOf;