@anywalletkit/protocol-swap2-across 0.0.0-stage → 0.1.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 (100) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +177 -2
  3. package/dist/activity.cjs +142 -0
  4. package/dist/activity.cjs.map +1 -0
  5. package/dist/activity.d.cts +16 -0
  6. package/dist/activity.d.ts +16 -0
  7. package/dist/activity.js +10 -0
  8. package/dist/activity.js.map +1 -0
  9. package/dist/api.cjs +441 -0
  10. package/dist/api.cjs.map +1 -0
  11. package/dist/api.d.cts +207 -0
  12. package/dist/api.d.ts +207 -0
  13. package/dist/api.js +35 -0
  14. package/dist/api.js.map +1 -0
  15. package/dist/build.cjs +776 -0
  16. package/dist/build.cjs.map +1 -0
  17. package/dist/build.d.cts +93 -0
  18. package/dist/build.d.ts +93 -0
  19. package/dist/build.js +14 -0
  20. package/dist/build.js.map +1 -0
  21. package/dist/chunk-32YJEBZX.js +125 -0
  22. package/dist/chunk-32YJEBZX.js.map +1 -0
  23. package/dist/chunk-3UBRQ3ZE.js +255 -0
  24. package/dist/chunk-3UBRQ3ZE.js.map +1 -0
  25. package/dist/chunk-5BDZXOOP.js +21 -0
  26. package/dist/chunk-5BDZXOOP.js.map +1 -0
  27. package/dist/chunk-6Z4GXNLE.js +102 -0
  28. package/dist/chunk-6Z4GXNLE.js.map +1 -0
  29. package/dist/chunk-AWQT5S4V.js +101 -0
  30. package/dist/chunk-AWQT5S4V.js.map +1 -0
  31. package/dist/chunk-E5WFOPN2.js +16 -0
  32. package/dist/chunk-E5WFOPN2.js.map +1 -0
  33. package/dist/chunk-GX67FRPG.js +194 -0
  34. package/dist/chunk-GX67FRPG.js.map +1 -0
  35. package/dist/chunk-KATEONJQ.js +396 -0
  36. package/dist/chunk-KATEONJQ.js.map +1 -0
  37. package/dist/chunk-P32AW6XS.js +27 -0
  38. package/dist/chunk-P32AW6XS.js.map +1 -0
  39. package/dist/chunk-PPPZIG7S.js +265 -0
  40. package/dist/chunk-PPPZIG7S.js.map +1 -0
  41. package/dist/chunk-SJOFLM27.js +138 -0
  42. package/dist/chunk-SJOFLM27.js.map +1 -0
  43. package/dist/chunk-YGNP7KPL.js +311 -0
  44. package/dist/chunk-YGNP7KPL.js.map +1 -0
  45. package/dist/config.cjs +214 -0
  46. package/dist/config.cjs.map +1 -0
  47. package/dist/config.d.cts +119 -0
  48. package/dist/config.d.ts +119 -0
  49. package/dist/config.js +47 -0
  50. package/dist/config.js.map +1 -0
  51. package/dist/deposit.cjs +252 -0
  52. package/dist/deposit.cjs.map +1 -0
  53. package/dist/deposit.d.cts +95 -0
  54. package/dist/deposit.d.ts +95 -0
  55. package/dist/deposit.js +19 -0
  56. package/dist/deposit.js.map +1 -0
  57. package/dist/index.cjs +1789 -0
  58. package/dist/index.cjs.map +1 -0
  59. package/dist/index.d.cts +34 -0
  60. package/dist/index.d.ts +34 -0
  61. package/dist/index.js +242 -0
  62. package/dist/index.js.map +1 -0
  63. package/dist/pricing.cjs +132 -0
  64. package/dist/pricing.cjs.map +1 -0
  65. package/dist/pricing.d.cts +123 -0
  66. package/dist/pricing.d.ts +123 -0
  67. package/dist/pricing.js +42 -0
  68. package/dist/pricing.js.map +1 -0
  69. package/dist/protocol.cjs +1596 -0
  70. package/dist/protocol.cjs.map +1 -0
  71. package/dist/protocol.d.cts +20 -0
  72. package/dist/protocol.d.ts +20 -0
  73. package/dist/protocol.js +17 -0
  74. package/dist/protocol.js.map +1 -0
  75. package/dist/provider.cjs +1581 -0
  76. package/dist/provider.cjs.map +1 -0
  77. package/dist/provider.d.cts +45 -0
  78. package/dist/provider.d.ts +45 -0
  79. package/dist/provider.js +18 -0
  80. package/dist/provider.js.map +1 -0
  81. package/dist/remote.cjs +1659 -0
  82. package/dist/remote.cjs.map +1 -0
  83. package/dist/remote.d.cts +55 -0
  84. package/dist/remote.d.ts +55 -0
  85. package/dist/remote.js +17 -0
  86. package/dist/remote.js.map +1 -0
  87. package/dist/status.cjs +443 -0
  88. package/dist/status.cjs.map +1 -0
  89. package/dist/status.d.cts +109 -0
  90. package/dist/status.d.ts +109 -0
  91. package/dist/status.js +26 -0
  92. package/dist/status.js.map +1 -0
  93. package/dist/verify.cjs +690 -0
  94. package/dist/verify.cjs.map +1 -0
  95. package/dist/verify.d.cts +245 -0
  96. package/dist/verify.d.ts +245 -0
  97. package/dist/verify.js +69 -0
  98. package/dist/verify.js.map +1 -0
  99. package/module.json +32 -0
  100. package/package.json +124 -3
@@ -0,0 +1,55 @@
1
+ import { RemoteProviderOptions } from '@anywalletkit/protocol-swap2-core/remote';
2
+ import { CrossChainProvider } from '@anywalletkit/protocol-swap2-core/types';
3
+ import { AcrossPinsOptions } from './verify.cjs';
4
+ import 'viem';
5
+ import './config.cjs';
6
+ import './deposit.cjs';
7
+
8
+ /**
9
+ * The app's side of Across when the V5 key stays on a server.
10
+ *
11
+ * `acrossRemoteProvider({baseUrl})` forwards quotes and builds to your backend (which runs `acrossProvider({apiKey})`
12
+ * under `createSwap2Handler`) and checks, on the device, everything that comes back before the engine signs:
13
+ *
14
+ * - `acrossPinsWith({maxFeeBps})` holds every deposit to the request the app itself sent — the pinned SpokePool as the
15
+ * only call target and spender, depositor = the signing account, recipient, tokens, amounts, destination, empty
16
+ * message, no exclusive relayer, deadlines, the app's fee cap and the per-asset fee floor — and the numbers the
17
+ * quote shows (its amounts, its fee list and `feeUsd`, which the engine's fee caps and the router's scoring read)
18
+ * to the deposit's own;
19
+ * - Across's keyless relayer fee (`/suggested-fees`), read by the app itself for every quote, dry or live: a deposit
20
+ * leaving relayers more than 10 % under it is refused ({@link acrossCheckRelayerFee}) — so a backend cannot get a
21
+ * deposit signed that relayers would leave unfilled for two hours, nor win the router's comparison with one;
22
+ * - right before signing, the build once more by the device's clock (a quote time the SpokePool no longer takes is
23
+ * refused before the backend is asked).
24
+ *
25
+ * The backend chooses only the output amount within those bounds; it cannot get a deposit signed for anyone else.
26
+ * With `rpcUrls` the app also reads the deposit's status from the chains itself; without, it asks the backend.
27
+ */
28
+
29
+ interface AcrossRemoteOptions extends AcrossPinsOptions, Pick<RemoteProviderOptions, "baseUrl" | "enabled" | "fetchImpl" | "headers" | "timeoutMs" | "allowInsecureBaseUrl"> {
30
+ /**
31
+ * The app's own JSON-RPC URLs per CAIP-2 chain: with both chains of a deposit here, its status is read on the device
32
+ * (the source receipt and the destination's `fillStatuses`), not asked of the backend.
33
+ */
34
+ rpcUrls?: Readonly<Record<string, string>> | undefined;
35
+ /**
36
+ * Across's keyless relayer-fee quote, read by the app for every quote the backend sends (default
37
+ * `https://app.across.to/api/suggested-fees`, through `fetchImpl`; a browser app's CSP must allow it in
38
+ * `connect-src`). Nothing secret is sent: the deposit's tokens, chains, amount and recipient. `null` turns the read
39
+ * off: a route the pinned floor covers (Ethereum, Optimism, Base, Arbitrum to Optimism, Base, Arbitrum) is then held
40
+ * to the per-asset floor alone — a backend could get a deposit signed that pays relayers too little to fill, which
41
+ * waits for its deadline and the refund — and every other route is refused.
42
+ */
43
+ suggestedFeesUrl?: string | null | undefined;
44
+ }
45
+ /**
46
+ * Across through your backend: `remoteProvider` with {@link acrossPinsWith} (the app's fee cap), the routes this
47
+ * module prices, Across's relayer fee read on the device, and on-device status when `rpcUrls` names both chains.
48
+ *
49
+ * ```ts
50
+ * const across = acrossRemoteProvider({baseUrl: "https://api.example.com/swap2", rpcUrls});
51
+ * ```
52
+ */
53
+ declare function acrossRemoteProvider(options: AcrossRemoteOptions): CrossChainProvider;
54
+
55
+ export { type AcrossRemoteOptions, acrossRemoteProvider };
@@ -0,0 +1,55 @@
1
+ import { RemoteProviderOptions } from '@anywalletkit/protocol-swap2-core/remote';
2
+ import { CrossChainProvider } from '@anywalletkit/protocol-swap2-core/types';
3
+ import { AcrossPinsOptions } from './verify.js';
4
+ import 'viem';
5
+ import './config.js';
6
+ import './deposit.js';
7
+
8
+ /**
9
+ * The app's side of Across when the V5 key stays on a server.
10
+ *
11
+ * `acrossRemoteProvider({baseUrl})` forwards quotes and builds to your backend (which runs `acrossProvider({apiKey})`
12
+ * under `createSwap2Handler`) and checks, on the device, everything that comes back before the engine signs:
13
+ *
14
+ * - `acrossPinsWith({maxFeeBps})` holds every deposit to the request the app itself sent — the pinned SpokePool as the
15
+ * only call target and spender, depositor = the signing account, recipient, tokens, amounts, destination, empty
16
+ * message, no exclusive relayer, deadlines, the app's fee cap and the per-asset fee floor — and the numbers the
17
+ * quote shows (its amounts, its fee list and `feeUsd`, which the engine's fee caps and the router's scoring read)
18
+ * to the deposit's own;
19
+ * - Across's keyless relayer fee (`/suggested-fees`), read by the app itself for every quote, dry or live: a deposit
20
+ * leaving relayers more than 10 % under it is refused ({@link acrossCheckRelayerFee}) — so a backend cannot get a
21
+ * deposit signed that relayers would leave unfilled for two hours, nor win the router's comparison with one;
22
+ * - right before signing, the build once more by the device's clock (a quote time the SpokePool no longer takes is
23
+ * refused before the backend is asked).
24
+ *
25
+ * The backend chooses only the output amount within those bounds; it cannot get a deposit signed for anyone else.
26
+ * With `rpcUrls` the app also reads the deposit's status from the chains itself; without, it asks the backend.
27
+ */
28
+
29
+ interface AcrossRemoteOptions extends AcrossPinsOptions, Pick<RemoteProviderOptions, "baseUrl" | "enabled" | "fetchImpl" | "headers" | "timeoutMs" | "allowInsecureBaseUrl"> {
30
+ /**
31
+ * The app's own JSON-RPC URLs per CAIP-2 chain: with both chains of a deposit here, its status is read on the device
32
+ * (the source receipt and the destination's `fillStatuses`), not asked of the backend.
33
+ */
34
+ rpcUrls?: Readonly<Record<string, string>> | undefined;
35
+ /**
36
+ * Across's keyless relayer-fee quote, read by the app for every quote the backend sends (default
37
+ * `https://app.across.to/api/suggested-fees`, through `fetchImpl`; a browser app's CSP must allow it in
38
+ * `connect-src`). Nothing secret is sent: the deposit's tokens, chains, amount and recipient. `null` turns the read
39
+ * off: a route the pinned floor covers (Ethereum, Optimism, Base, Arbitrum to Optimism, Base, Arbitrum) is then held
40
+ * to the per-asset floor alone — a backend could get a deposit signed that pays relayers too little to fill, which
41
+ * waits for its deadline and the refund — and every other route is refused.
42
+ */
43
+ suggestedFeesUrl?: string | null | undefined;
44
+ }
45
+ /**
46
+ * Across through your backend: `remoteProvider` with {@link acrossPinsWith} (the app's fee cap), the routes this
47
+ * module prices, Across's relayer fee read on the device, and on-device status when `rpcUrls` names both chains.
48
+ *
49
+ * ```ts
50
+ * const across = acrossRemoteProvider({baseUrl: "https://api.example.com/swap2", rpcUrls});
51
+ * ```
52
+ */
53
+ declare function acrossRemoteProvider(options: AcrossRemoteOptions): CrossChainProvider;
54
+
55
+ export { type AcrossRemoteOptions, acrossRemoteProvider };
package/dist/remote.js ADDED
@@ -0,0 +1,17 @@
1
+ import {
2
+ acrossRemoteProvider
3
+ } from "./chunk-AWQT5S4V.js";
4
+ import "./chunk-PPPZIG7S.js";
5
+ import "./chunk-5BDZXOOP.js";
6
+ import "./chunk-SJOFLM27.js";
7
+ import "./chunk-KATEONJQ.js";
8
+ import "./chunk-3UBRQ3ZE.js";
9
+ import "./chunk-32YJEBZX.js";
10
+ import "./chunk-YGNP7KPL.js";
11
+ import "./chunk-GX67FRPG.js";
12
+ import "./chunk-6Z4GXNLE.js";
13
+ import "./chunk-E5WFOPN2.js";
14
+ export {
15
+ acrossRemoteProvider
16
+ };
17
+ //# sourceMappingURL=remote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,443 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/status.ts
21
+ var status_exports = {};
22
+ __export(status_exports, {
23
+ ACROSS_FILL_STATUS: () => ACROSS_FILL_STATUS,
24
+ acrossDepositIsIntent: () => acrossDepositIsIntent,
25
+ acrossDepositsInReceipt: () => acrossDepositsInReceipt,
26
+ acrossFillState: () => acrossFillState,
27
+ acrossFillStatusCall: () => acrossFillStatusCall,
28
+ acrossRelayHash: () => acrossRelayHash,
29
+ acrossRpc: () => acrossRpc,
30
+ parseAcrossFillStatus: () => parseAcrossFillStatus,
31
+ trackAcrossDeposit: () => trackAcrossDeposit
32
+ });
33
+ module.exports = __toCommonJS(status_exports);
34
+ var import_viem2 = require("viem");
35
+ var import_util = require("@anywalletkit/protocol-swap2-core/util");
36
+
37
+ // src/config.ts
38
+ var USDC = (address, symbol = "USDC") => Object.freeze({ asset: "USDC", address, symbol, decimals: 6 });
39
+ var USDT = (address, symbol = "USDT") => Object.freeze({ asset: "USDT", address, symbol, decimals: 6 });
40
+ var WETH = (address) => Object.freeze({ asset: "ETH", address, symbol: "WETH", decimals: 18 });
41
+ var WBTC = (address) => Object.freeze({ asset: "WBTC", address, symbol: "WBTC", decimals: 8 });
42
+ var OP_WETH = "0x4200000000000000000000000000000000000006";
43
+ function chain(chainId, key, name, spokePool, wrappedNative, nativeIsEth, tokens) {
44
+ return Object.freeze({ caip2: `eip155:${chainId}`, chainId, key, name, spokePool, wrappedNative, nativeIsEth, tokens: Object.freeze(tokens) });
45
+ }
46
+ var ACROSS_CHAINS = Object.freeze(Object.assign(/* @__PURE__ */ Object.create(null), Object.fromEntries([
47
+ chain(1, "ethereum", "Ethereum", "0x5c7bcd6e7de5423a257d81b442095a1a6ced35c5", "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", true, [
48
+ USDC("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"),
49
+ USDT("0xdac17f958d2ee523a2206206994597c13d831ec7"),
50
+ WETH("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"),
51
+ WBTC("0x2260fac5e5542a773aa44fbcfedf7c193bc2c599")
52
+ ]),
53
+ chain(10, "optimism", "Optimism", "0x6f26bf09b1c792e3228e5467807a900a503c0281", OP_WETH, true, [
54
+ USDC("0x0b2c639c533813f4aa9d7837caf62653d097ff85"),
55
+ USDT("0x94b008aa00579c1307b0ef2c499ad98a8ce58e58"),
56
+ WETH(OP_WETH)
57
+ ]),
58
+ chain(130, "unichain", "Unichain", "0x09aea4b2242abc8bb4bb78d537a67a245a7bec64", OP_WETH, true, [
59
+ USDC("0x078d782b760474a361dda0af3839290b0ef57ad6"),
60
+ USDT("0x9151434b16b9763660705744891fa906f660ecc5", "USDT0"),
61
+ WETH(OP_WETH)
62
+ ]),
63
+ chain(137, "polygon", "Polygon", "0x9295ee1d8c5b022be115a2ad3c30c72e34e7f096", "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270", false, [
64
+ USDC("0x3c499c542cef5e3811e1192ce70d8cc03d5c3359"),
65
+ USDT("0xc2132d05d31c914a87c6611c10748aeb04b58e8f"),
66
+ WBTC("0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6")
67
+ ]),
68
+ chain(143, "monad", "Monad", "0xd2ecb3afe598b746f8123cae365a598da831a449", "0x3bd359c1119da7da1d913d1c4d2b7c461115433a", false, [
69
+ USDC("0x754704bc059f8c67012fed69bc8a327a5aafb603"),
70
+ USDT("0xe7cd86e13ac4309349f30b3435a9d337750fc82d", "USDT0")
71
+ ]),
72
+ chain(324, "zksync", "zkSync Era", "0xe0b015e54d54fc84a6cb9b666099c46ade9335ff", "0x5aea5775959fbc2557cc8789bc1bf90a239d9a91", true, [
73
+ USDT("0x493257fd37edb34451f62edf8d2a0c418852ba4c"),
74
+ WETH("0x5aea5775959fbc2557cc8789bc1bf90a239d9a91"),
75
+ WBTC("0xbbeb516fb02a01611cbbe0453fe3c580d7281011")
76
+ ]),
77
+ chain(480, "worldchain", "World Chain", "0x09aea4b2242abc8bb4bb78d537a67a245a7bec64", OP_WETH, true, [
78
+ USDC("0x79a02482a880bce3f13e09da970dc34db4cd24d1"),
79
+ WETH(OP_WETH),
80
+ WBTC("0x03c7054bcb39f7b2e5b2c7acb37583e32d70cfa3")
81
+ ]),
82
+ chain(999, "hyperevm", "HyperEVM", "0x35e63ea3eb0fb7a3bc543c71fb66412e1f6b0e04", "0x5555555555555555555555555555555555555555", false, [
83
+ USDC("0xb88339cb7199b77e23db6e890353e22632ba630f"),
84
+ USDT("0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb", "USDT0")
85
+ ]),
86
+ chain(4326, "megaeth", "MegaETH", "0x3db06da8f0a24a525f314eec954fc5c6a973d40e", OP_WETH, true, [
87
+ USDT("0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb", "USDT0"),
88
+ WETH(OP_WETH)
89
+ ]),
90
+ chain(4663, "robinhood", "Robinhood Chain", "0xd29c85f15df544ba632c9e25829fd29d767d7978", "0x0bd7d308f8e1639fab988df18a8011f41eacad73", true, [
91
+ WETH("0x0bd7d308f8e1639fab988df18a8011f41eacad73")
92
+ ]),
93
+ // Arc's gas coin is USDC; 0x3600… is its 6-decimal ERC-20 interface, which is what Across moves. The SpokePool
94
+ // reports no wrapped native token, so no deposit or fill on Arc involves the native coin.
95
+ chain(5042, "arc", "Arc", "0x9b4a302a548c7e313c2b74c461db7b84d3074a84", null, false, [
96
+ USDC("0x3600000000000000000000000000000000000000")
97
+ ]),
98
+ chain(8453, "base", "Base", "0x09aea4b2242abc8bb4bb78d537a67a245a7bec64", OP_WETH, true, [
99
+ USDC("0x833589fcd6edb6e08f4c7c32d4f71b54bda02913"),
100
+ USDT("0xfde4c96c8593536e31f229ea8f37b2ada2699bb2"),
101
+ WETH(OP_WETH)
102
+ ]),
103
+ chain(9745, "plasma", "Plasma", "0x50039faefebef707cfd94d6d462fe6d10b39207a", "0x6100e367285b01f48d07953803a2d8dca5d19873", false, [
104
+ USDT("0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb", "USDT0")
105
+ ]),
106
+ chain(42161, "arbitrum", "Arbitrum", "0xe35e9842fceaca96570b734083f4a58e8f7c5f2a", "0x82af49447d8a07e3bd95bd0d56f35241523fbab1", true, [
107
+ USDC("0xaf88d065e77c8cc2239327c5edb3a432268e5831"),
108
+ USDT("0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9", "USDT0"),
109
+ WETH("0x82af49447d8a07e3bd95bd0d56f35241523fbab1"),
110
+ WBTC("0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f")
111
+ ]),
112
+ chain(43114, "avalanche", "Avalanche", "0xfe9d541c92e4e90437c7152a00244886de37a658", "0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7", false, [
113
+ USDC("0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e"),
114
+ USDT("0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7")
115
+ ]),
116
+ chain(57073, "ink", "Ink", "0xef684c38f94f48775959ecf2012d7e864ffb9dd4", OP_WETH, true, [
117
+ USDC("0x2d270e6886d130d724215a266106e6832161eaed"),
118
+ USDT("0x0200c29006150606b650577bbe7b6248f58470c1", "USDT0"),
119
+ WETH(OP_WETH)
120
+ ]),
121
+ chain(59144, "linea", "Linea", "0x7e63a5f1a8f0b4d0934b2f2327daed3f6bb2ee75", "0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f", true, [
122
+ USDC("0x176211869ca2b568f2a7d4ee941e073a821ee1ff"),
123
+ USDT("0xa219439258ca9da29e9cc4ce5596924745e12b93"),
124
+ WETH("0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f"),
125
+ WBTC("0x3aab2285ddcddad8edf438c1bab47e1a9d05a9b4")
126
+ ])
127
+ ].map((x) => [x.caip2, x]))));
128
+ var ACROSS_REFUSED_SELECTORS = Object.freeze({
129
+ "0x8b15788e": "unsafeDeposit",
130
+ "0xea86bd46": "depositNow",
131
+ "0x7aef642c": "depositV3Now",
132
+ "0xbabb6aac": "speedUpDeposit",
133
+ "0x577f51f8": "speedUpV3Deposit",
134
+ "0xac9650d8": "multicall"
135
+ });
136
+ var ACROSS_FUNDS_DEPOSITED = "0x32ed1a409ef04c7b0227189c3a103dc5ac10e775a15b785dcc510201f7c25ad3";
137
+ var ACROSS_FILL_STATUSES = "0xc35c83fc";
138
+ var ACROSS_MAX_EXCLUSIVITY_PERIOD_S = 31536e3;
139
+
140
+ // src/deposit.ts
141
+ var import_viem = require("viem");
142
+
143
+ // src/refusal.ts
144
+ var import_errors = require("@anywalletkit/protocol-swap2-core/errors");
145
+ var AcrossRefusal = class extends Error {
146
+ code;
147
+ constructor(code, detail, reason) {
148
+ super(`across: ${detail} [${code}]`);
149
+ this.name = "AcrossRefusal";
150
+ this.code = code;
151
+ if (reason !== void 0) (0, import_errors.withReason)(this, reason);
152
+ }
153
+ };
154
+
155
+ // src/deposit.ts
156
+ var SPOKE_POOL_ABI = (0, import_viem.parseAbi)([
157
+ "function deposit(bytes32 depositor, bytes32 recipient, bytes32 inputToken, bytes32 outputToken, uint256 inputAmount, uint256 outputAmount, uint256 destinationChainId, bytes32 exclusiveRelayer, uint32 quoteTimestamp, uint32 fillDeadline, uint32 exclusivityParameter, bytes message) payable"
158
+ ]);
159
+ var ADDRESS = /^0x[0-9a-fA-F]{40}$/;
160
+ var HEX = /^0x(?:[0-9a-fA-F]{2})*$/;
161
+ var U256_MAX = (1n << 256n) - 1n;
162
+ var U32_MAX = 4294967295;
163
+ var HEAD_WORDS = 12;
164
+ var MESSAGE_OFFSET = HEAD_WORDS * 32;
165
+ var ACROSS_MAX_MESSAGE_BYTES = 65536;
166
+ function acrossBytes32(address) {
167
+ if (typeof address !== "string" || !ADDRESS.test(address)) throw new AcrossRefusal("request-invalid", `${String(address)} is not an EVM address`);
168
+ return `0x${"0".repeat(24)}${address.slice(2).toLowerCase()}`;
169
+ }
170
+ function acrossAddressOf(word) {
171
+ const w = word.startsWith("0x") ? word.slice(2) : word;
172
+ if (!/^[0-9a-fA-F]{64}$/.test(w) || !/^0{24}/.test(w)) return null;
173
+ return `0x${w.slice(24).toLowerCase()}`;
174
+ }
175
+ function checkArgs(a) {
176
+ const bad = (what) => {
177
+ throw new AcrossRefusal("request-invalid", `the deposit's ${what}`);
178
+ };
179
+ if (a === null || typeof a !== "object") bad("arguments are missing");
180
+ for (const [k, v] of [["depositor", a.depositor], ["recipient", a.recipient], ["inputToken", a.inputToken], ["outputToken", a.outputToken], ["exclusiveRelayer", a.exclusiveRelayer]]) {
181
+ if (typeof v !== "string" || !ADDRESS.test(v)) bad(`${k} is not an EVM address`);
182
+ }
183
+ for (const [k, v] of [["inputAmount", a.inputAmount], ["outputAmount", a.outputAmount], ["destinationChainId", a.destinationChainId]]) {
184
+ if (typeof v !== "bigint" || v < 0n || v > U256_MAX) bad(`${k} is not a uint256`);
185
+ }
186
+ for (const [k, v] of [["quoteTimestamp", a.quoteTimestamp], ["fillDeadline", a.fillDeadline], ["exclusivityParameter", a.exclusivityParameter]]) {
187
+ if (!Number.isInteger(v) || v < 0 || v > U32_MAX) bad(`${k} is not a uint32`);
188
+ }
189
+ if (typeof a.message !== "string" || !HEX.test(a.message) || (a.message.length - 2) / 2 > ACROSS_MAX_MESSAGE_BYTES) bad("message is not bytes");
190
+ }
191
+ function encodeAcrossDeposit(a) {
192
+ checkArgs(a);
193
+ return (0, import_viem.encodeFunctionData)({
194
+ abi: SPOKE_POOL_ABI,
195
+ functionName: "deposit",
196
+ args: [
197
+ acrossBytes32(a.depositor),
198
+ acrossBytes32(a.recipient),
199
+ acrossBytes32(a.inputToken),
200
+ acrossBytes32(a.outputToken),
201
+ a.inputAmount,
202
+ a.outputAmount,
203
+ a.destinationChainId,
204
+ acrossBytes32(a.exclusiveRelayer),
205
+ a.quoteTimestamp,
206
+ a.fillDeadline,
207
+ a.exclusivityParameter,
208
+ a.message.toLowerCase()
209
+ ]
210
+ }).toLowerCase();
211
+ }
212
+
213
+ // src/status.ts
214
+ var ACROSS_FILL_STATUS = Object.freeze({ UNFILLED: 0, REQUESTED_SLOW_FILL: 1, FILLED: 2 });
215
+ var EVENT_DATA = [
216
+ { name: "inputToken", type: "bytes32" },
217
+ { name: "outputToken", type: "bytes32" },
218
+ { name: "inputAmount", type: "uint256" },
219
+ { name: "outputAmount", type: "uint256" },
220
+ { name: "quoteTimestamp", type: "uint32" },
221
+ { name: "fillDeadline", type: "uint32" },
222
+ { name: "exclusivityDeadline", type: "uint32" },
223
+ { name: "recipient", type: "bytes32" },
224
+ { name: "exclusiveRelayer", type: "bytes32" },
225
+ { name: "message", type: "bytes" }
226
+ ];
227
+ var RELAY_DATA = {
228
+ type: "tuple",
229
+ components: [
230
+ { name: "depositor", type: "bytes32" },
231
+ { name: "recipient", type: "bytes32" },
232
+ { name: "exclusiveRelayer", type: "bytes32" },
233
+ { name: "inputToken", type: "bytes32" },
234
+ { name: "outputToken", type: "bytes32" },
235
+ { name: "inputAmount", type: "uint256" },
236
+ { name: "outputAmount", type: "uint256" },
237
+ { name: "originChainId", type: "uint256" },
238
+ { name: "depositId", type: "uint256" },
239
+ { name: "fillDeadline", type: "uint32" },
240
+ { name: "exclusivityDeadline", type: "uint32" },
241
+ { name: "message", type: "bytes" }
242
+ ]
243
+ };
244
+ var WORD = /^0x[0-9a-fA-F]{64}$/;
245
+ var HEX2 = /^0x(?:[0-9a-fA-F]{2})*$/;
246
+ var DIGEST = /^[0-9a-f]{32}$/;
247
+ var QUANTITY = /^0x[0-9a-fA-F]{1,16}$/;
248
+ var lowerHex = (s) => s.toLowerCase();
249
+ function acrossDepositsInReceipt(receipt, source) {
250
+ const logs = receipt?.logs;
251
+ if (!Array.isArray(logs)) return [];
252
+ const out = [];
253
+ for (const log of logs) {
254
+ if (log === null || typeof log !== "object" || log.removed === true) continue;
255
+ if (typeof log.address !== "string" || log.address.toLowerCase() !== source.spokePool) continue;
256
+ const topics = log.topics;
257
+ if (!Array.isArray(topics) || topics.length !== 4 || !topics.every((t) => typeof t === "string" && WORD.test(t))) continue;
258
+ if (topics[0].toLowerCase() !== ACROSS_FUNDS_DEPOSITED) continue;
259
+ if (typeof log.data !== "string" || !HEX2.test(log.data)) continue;
260
+ let d;
261
+ try {
262
+ d = (0, import_viem2.decodeAbiParameters)(EVENT_DATA, log.data);
263
+ } catch {
264
+ continue;
265
+ }
266
+ out.push({
267
+ originChainId: source.chainId,
268
+ destinationChainId: BigInt(topics[1]),
269
+ depositId: BigInt(topics[2]),
270
+ depositor: lowerHex(topics[3]),
271
+ inputToken: lowerHex(d[0]),
272
+ outputToken: lowerHex(d[1]),
273
+ inputAmount: d[2],
274
+ outputAmount: d[3],
275
+ quoteTimestamp: d[4],
276
+ fillDeadline: d[5],
277
+ exclusivityDeadline: d[6],
278
+ recipient: lowerHex(d[7]),
279
+ exclusiveRelayer: lowerHex(d[8]),
280
+ message: lowerHex(d[9])
281
+ });
282
+ }
283
+ return out;
284
+ }
285
+ function depositDataOf(e, exclusivityParameter) {
286
+ const depositor = acrossAddressOf(e.depositor);
287
+ const recipient = acrossAddressOf(e.recipient);
288
+ const inputToken = acrossAddressOf(e.inputToken);
289
+ const outputToken = acrossAddressOf(e.outputToken);
290
+ const exclusiveRelayer = acrossAddressOf(e.exclusiveRelayer);
291
+ if (!depositor || !recipient || !inputToken || !outputToken || !exclusiveRelayer) return null;
292
+ try {
293
+ return encodeAcrossDeposit({
294
+ depositor,
295
+ recipient,
296
+ inputToken,
297
+ outputToken,
298
+ inputAmount: e.inputAmount,
299
+ outputAmount: e.outputAmount,
300
+ destinationChainId: e.destinationChainId,
301
+ exclusiveRelayer,
302
+ quoteTimestamp: e.quoteTimestamp,
303
+ fillDeadline: e.fillDeadline,
304
+ exclusivityParameter,
305
+ message: e.message
306
+ });
307
+ } catch {
308
+ return null;
309
+ }
310
+ }
311
+ function acrossDepositIsIntent(e, digest, sourceBlockTime) {
312
+ if (typeof digest !== "string" || !DIGEST.test(digest)) return false;
313
+ const d = e.exclusivityDeadline;
314
+ const candidates = [];
315
+ if (d === 0) candidates.push(0);
316
+ else {
317
+ if (d > ACROSS_MAX_EXCLUSIVITY_PERIOD_S) candidates.push(d);
318
+ if (sourceBlockTime !== void 0 && d - sourceBlockTime > 0 && d - sourceBlockTime <= ACROSS_MAX_EXCLUSIVITY_PERIOD_S) candidates.push(d - sourceBlockTime);
319
+ }
320
+ return candidates.some((p) => {
321
+ const data = depositDataOf(e, p);
322
+ return data !== null && (0, import_viem2.keccak256)(data).slice(2, 34) === digest;
323
+ });
324
+ }
325
+ function acrossRelayHash(e) {
326
+ return (0, import_viem2.keccak256)((0, import_viem2.encodeAbiParameters)([RELAY_DATA, { type: "uint256" }], [{
327
+ depositor: e.depositor,
328
+ recipient: e.recipient,
329
+ exclusiveRelayer: e.exclusiveRelayer,
330
+ inputToken: e.inputToken,
331
+ outputToken: e.outputToken,
332
+ inputAmount: e.inputAmount,
333
+ outputAmount: e.outputAmount,
334
+ originChainId: BigInt(e.originChainId),
335
+ depositId: e.depositId,
336
+ fillDeadline: e.fillDeadline,
337
+ exclusivityDeadline: e.exclusivityDeadline,
338
+ message: e.message
339
+ }, e.destinationChainId]));
340
+ }
341
+ function acrossFillStatusCall(relayHash) {
342
+ if (!WORD.test(relayHash)) throw new Error("across: a relay hash is 32 bytes");
343
+ return `${ACROSS_FILL_STATUSES}${relayHash.slice(2).toLowerCase()}`;
344
+ }
345
+ function parseAcrossFillStatus(answer) {
346
+ if (typeof answer !== "string" || !/^0x0{63}[0-2]$/i.test(answer)) return null;
347
+ return Number(answer.slice(-1));
348
+ }
349
+ function acrossFillState(status, fillDeadline, blockTime) {
350
+ if (status === ACROSS_FILL_STATUS.FILLED) return "filled";
351
+ if (blockTime > fillDeadline) return "expired";
352
+ return status === ACROSS_FILL_STATUS.REQUESTED_SLOW_FILL ? "slow-fill-requested" : "unfilled";
353
+ }
354
+ var MAX_RPC_BODY = 8 * 1024 * 1024;
355
+ function acrossRpc(url, fetchImpl, timeoutMs = 12e3) {
356
+ if (typeof url !== "string" || !/^https?:\/\//.test(url)) throw new Error("across: an RPC URL must use http or https");
357
+ let id = 0;
358
+ return async (method, params) => {
359
+ let text;
360
+ try {
361
+ const res = await (fetchImpl ?? fetch)(url, {
362
+ method: "POST",
363
+ headers: { "content-type": "application/json", accept: "application/json" },
364
+ body: JSON.stringify({ jsonrpc: "2.0", id: ++id, method, params }),
365
+ signal: (0, import_util.timeoutSignal)(timeoutMs)
366
+ });
367
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
368
+ text = await res.text();
369
+ } catch (err) {
370
+ throw new Error(`across: ${method} failed \u2014 ${(0, import_util.redactUrls)(err instanceof Error ? err.message : String(err)).slice(0, 160)}`);
371
+ }
372
+ if (text.length > MAX_RPC_BODY) throw new Error(`across: ${method} answered more than ${MAX_RPC_BODY} bytes`);
373
+ let body;
374
+ try {
375
+ body = JSON.parse(text);
376
+ } catch {
377
+ throw new Error(`across: ${method} answered something that is not JSON`);
378
+ }
379
+ if (body === null || typeof body !== "object") throw new Error(`across: ${method} answered something that is not JSON-RPC`);
380
+ if (body.error !== void 0) throw new Error(`across: ${method} failed \u2014 ${(0, import_util.redactUrls)(String(body.error?.message ?? "error")).slice(0, 160)}`);
381
+ if (!Object.prototype.hasOwnProperty.call(body, "result")) throw new Error(`across: ${method} answered no result`);
382
+ return body.result;
383
+ };
384
+ }
385
+ async function blockTimeOf(rpc, number) {
386
+ if (typeof number !== "string" || !QUANTITY.test(number)) return null;
387
+ try {
388
+ const block = await rpc("eth_getBlockByNumber", [number, false]);
389
+ const timestamp = block?.timestamp;
390
+ if (typeof block?.number !== "string" || block.number.toLowerCase() !== number.toLowerCase()) return null;
391
+ if (typeof timestamp !== "string" || !/^0x[0-9a-fA-F]{1,12}$/.test(timestamp)) return null;
392
+ return parseInt(timestamp, 16);
393
+ } catch {
394
+ return null;
395
+ }
396
+ }
397
+ async function trackAcrossDeposit(input) {
398
+ const { source, dest, sourceRpc, destRpc } = input;
399
+ if (typeof input.sourceTxHash !== "string" || !WORD.test(input.sourceTxHash) || !sourceRpc) return { status: { state: "pending" } };
400
+ if (typeof input.intentDigest !== "string" || !DIGEST.test(input.intentDigest)) return { status: { state: "pending" } };
401
+ let receipt;
402
+ try {
403
+ receipt = await sourceRpc("eth_getTransactionReceipt", [input.sourceTxHash]);
404
+ } catch {
405
+ return { status: { state: "pending" } };
406
+ }
407
+ if (receipt === null || receipt === void 0) return { status: { state: "pending" } };
408
+ if (typeof receipt !== "object") return { status: { state: "pending" } };
409
+ const status = receipt.status;
410
+ if (status === "0x0") return { status: { state: "failed" } };
411
+ if (status !== "0x1") return { status: { state: "pending" } };
412
+ const txHash = receipt.transactionHash;
413
+ if (txHash !== void 0 && (typeof txHash !== "string" || txHash.toLowerCase() !== input.sourceTxHash.toLowerCase())) return { status: { state: "pending" } };
414
+ const onRoute = acrossDepositsInReceipt(receipt, source).filter((d) => d.destinationChainId === BigInt(dest.chainId));
415
+ let mine = onRoute.filter((d) => acrossDepositIsIntent(d, input.intentDigest));
416
+ if (mine.length === 0 && onRoute.some((d) => d.exclusivityDeadline !== 0)) {
417
+ const blockTime = await blockTimeOf(sourceRpc, receipt.blockNumber);
418
+ if (blockTime === null) return { status: { state: "pending" } };
419
+ mine = onRoute.filter((d) => acrossDepositIsIntent(d, input.intentDigest, blockTime));
420
+ }
421
+ if (mine.length !== 1) return { status: { state: "pending" } };
422
+ const deposit = mine[0];
423
+ const relayHash = acrossRelayHash(deposit);
424
+ const seen = { status: { state: "pending", depositReceived: true }, deposit, relayHash };
425
+ if (!destRpc) return seen;
426
+ try {
427
+ const block = await destRpc("eth_getBlockByNumber", ["latest", false]);
428
+ const number = block?.number;
429
+ const timestamp = block?.timestamp;
430
+ if (typeof number !== "string" || !/^0x[0-9a-fA-F]{1,16}$/.test(number) || typeof timestamp !== "string" || !/^0x[0-9a-fA-F]{1,12}$/.test(timestamp)) return seen;
431
+ const blockTime = parseInt(timestamp, 16);
432
+ const fillStatus = parseAcrossFillStatus(await destRpc("eth_call", [{ to: dest.spokePool, data: acrossFillStatusCall(relayHash) }, number]));
433
+ if (fillStatus === null) return seen;
434
+ const fill = acrossFillState(fillStatus, deposit.fillDeadline, blockTime);
435
+ const destBlock = { number: number.toLowerCase(), timestamp: blockTime };
436
+ if (fill === "filled") return { status: { state: "completed", depositReceived: true }, deposit, relayHash, fill, destBlock };
437
+ if (fill === "expired") return { status: { state: "expired", depositReceived: true }, deposit, relayHash, fill, destBlock };
438
+ return { status: { state: "pending", depositReceived: true }, deposit, relayHash, fill, destBlock };
439
+ } catch {
440
+ return seen;
441
+ }
442
+ }
443
+ //# sourceMappingURL=status.cjs.map