@t402/evm 2.1.0 → 2.3.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 (83) hide show
  1. package/dist/cjs/exact/client/index.d.ts +2 -2
  2. package/dist/cjs/exact/client/index.js +4 -2
  3. package/dist/cjs/exact/client/index.js.map +1 -1
  4. package/dist/cjs/exact/facilitator/index.d.ts +1 -1
  5. package/dist/cjs/exact/facilitator/index.js +40 -4
  6. package/dist/cjs/exact/facilitator/index.js.map +1 -1
  7. package/dist/cjs/exact/server/index.d.ts +1 -1
  8. package/dist/cjs/exact/server/index.js +301 -33
  9. package/dist/cjs/exact/server/index.js.map +1 -1
  10. package/dist/cjs/exact/v1/client/index.d.ts +1 -1
  11. package/dist/cjs/exact/v1/client/index.js +3 -1
  12. package/dist/cjs/exact/v1/client/index.js.map +1 -1
  13. package/dist/cjs/exact/v1/facilitator/index.d.ts +1 -1
  14. package/dist/cjs/exact/v1/facilitator/index.js +21 -2
  15. package/dist/cjs/exact/v1/facilitator/index.js.map +1 -1
  16. package/dist/cjs/index.d.ts +636 -355
  17. package/dist/cjs/index.js +1451 -261
  18. package/dist/cjs/index.js.map +1 -1
  19. package/dist/{esm/scheme-yqGaK9rK.d.mts → cjs/scheme-B4rXSKCN.d.ts} +18 -16
  20. package/dist/cjs/scheme-CIar5W2B.d.ts +200 -0
  21. package/dist/cjs/{scheme-OojTBKAz.d.ts → scheme-CjijeY7y.d.ts} +1 -1
  22. package/dist/{esm/signer-BkcAzwYi.d.mts → cjs/signer-DcavxxZt.d.ts} +1 -18
  23. package/dist/cjs/upto/client/index.d.ts +61 -0
  24. package/dist/cjs/upto/client/index.js +154 -0
  25. package/dist/cjs/upto/client/index.js.map +1 -0
  26. package/dist/cjs/upto/index.d.ts +111 -0
  27. package/dist/cjs/upto/index.js +1030 -0
  28. package/dist/cjs/upto/index.js.map +1 -0
  29. package/dist/cjs/v1/index.d.ts +1 -1
  30. package/dist/cjs/v1/index.js +3 -1
  31. package/dist/cjs/v1/index.js.map +1 -1
  32. package/dist/esm/{chunk-ACDQ5QNT.mjs → chunk-4FBTQTNM.mjs} +27 -5
  33. package/dist/esm/chunk-4FBTQTNM.mjs.map +1 -0
  34. package/dist/esm/chunk-IWSDEZKI.mjs +477 -0
  35. package/dist/esm/chunk-IWSDEZKI.mjs.map +1 -0
  36. package/dist/esm/{chunk-LGSG73NJ.mjs → chunk-LM5RZBVP.mjs} +9 -4
  37. package/dist/esm/{chunk-LGSG73NJ.mjs.map → chunk-LM5RZBVP.mjs.map} +1 -1
  38. package/dist/esm/chunk-NSSMTXJJ.mjs +8 -0
  39. package/dist/esm/chunk-NSSMTXJJ.mjs.map +1 -0
  40. package/dist/esm/chunk-SJ52GTJJ.mjs +411 -0
  41. package/dist/esm/chunk-SJ52GTJJ.mjs.map +1 -0
  42. package/dist/esm/chunk-SURTCHSX.mjs +129 -0
  43. package/dist/esm/chunk-SURTCHSX.mjs.map +1 -0
  44. package/dist/esm/chunk-SYVPLXYV.mjs +26 -0
  45. package/dist/esm/chunk-SYVPLXYV.mjs.map +1 -0
  46. package/dist/esm/{chunk-XYKAO6KJ.mjs → chunk-Y4U7Q543.mjs} +2 -25
  47. package/dist/esm/chunk-Y4U7Q543.mjs.map +1 -0
  48. package/dist/esm/{chunk-JBWWBRYY.mjs → chunk-ZWEYARER.mjs} +9 -4
  49. package/dist/esm/{chunk-JBWWBRYY.mjs.map → chunk-ZWEYARER.mjs.map} +1 -1
  50. package/dist/esm/exact/client/index.d.mts +2 -2
  51. package/dist/esm/exact/client/index.mjs +6 -4
  52. package/dist/esm/exact/client/index.mjs.map +1 -1
  53. package/dist/esm/exact/facilitator/index.d.mts +1 -1
  54. package/dist/esm/exact/facilitator/index.mjs +26 -5
  55. package/dist/esm/exact/facilitator/index.mjs.map +1 -1
  56. package/dist/esm/exact/server/index.d.mts +1 -1
  57. package/dist/esm/exact/server/index.mjs +29 -30
  58. package/dist/esm/exact/server/index.mjs.map +1 -1
  59. package/dist/esm/exact/v1/client/index.d.mts +1 -1
  60. package/dist/esm/exact/v1/client/index.mjs +4 -2
  61. package/dist/esm/exact/v1/facilitator/index.d.mts +1 -1
  62. package/dist/esm/exact/v1/facilitator/index.mjs +4 -2
  63. package/dist/esm/index.d.mts +636 -355
  64. package/dist/esm/index.mjs +645 -135
  65. package/dist/esm/index.mjs.map +1 -1
  66. package/dist/{cjs/scheme-yqGaK9rK.d.ts → esm/scheme-B4rXSKCN.d.mts} +18 -16
  67. package/dist/esm/scheme-DATfd6oM.d.mts +200 -0
  68. package/dist/esm/{scheme-D4mOqq9l.d.mts → scheme-Ddb0dG_F.d.mts} +1 -1
  69. package/dist/{cjs/signer-BkcAzwYi.d.ts → esm/signer-DcavxxZt.d.mts} +1 -18
  70. package/dist/esm/upto/client/index.d.mts +61 -0
  71. package/dist/esm/upto/client/index.mjs +11 -0
  72. package/dist/esm/upto/client/index.mjs.map +1 -0
  73. package/dist/esm/upto/index.d.mts +111 -0
  74. package/dist/esm/upto/index.mjs +26 -0
  75. package/dist/esm/upto/index.mjs.map +1 -0
  76. package/dist/esm/v1/index.d.mts +1 -1
  77. package/dist/esm/v1/index.mjs +5 -3
  78. package/package.json +30 -6
  79. package/dist/cjs/scheme-C6uD7PdY.d.ts +0 -130
  80. package/dist/esm/chunk-ACDQ5QNT.mjs.map +0 -1
  81. package/dist/esm/chunk-OEXW2OK2.mjs +0 -251
  82. package/dist/esm/chunk-OEXW2OK2.mjs.map +0 -1
  83. package/dist/esm/chunk-XYKAO6KJ.mjs.map +0 -1
@@ -1,28 +1,34 @@
1
+ import {
2
+ UptoEvmFacilitatorScheme,
3
+ UptoEvmServerScheme,
4
+ createUptoEvmFacilitatorScheme,
5
+ createUptoEvmServerScheme
6
+ } from "./chunk-SJ52GTJJ.mjs";
1
7
  import {
2
8
  ExactEvmScheme
3
- } from "./chunk-LGSG73NJ.mjs";
9
+ } from "./chunk-LM5RZBVP.mjs";
4
10
  import {
5
- TOKEN_PRIORITY,
6
11
  TOKEN_REGISTRY,
7
- USDC_ADDRESSES,
8
- USDT0_ADDRESSES,
9
12
  USDT_LEGACY_ADDRESSES,
10
- getDefaultToken,
11
- getEIP712Domain,
12
- getNetworkTokens,
13
- getNetworksForToken,
14
- getTokenByAddress,
15
- getTokenConfig,
16
- getUsdt0Networks,
17
- supportsEIP3009
18
- } from "./chunk-OEXW2OK2.mjs";
13
+ getTokenConfig
14
+ } from "./chunk-IWSDEZKI.mjs";
19
15
  import {
20
- authorizationTypes,
21
- createNonce,
22
- eip3009ABI,
23
16
  erc20LegacyABI,
24
17
  legacyAuthorizationTypes
25
- } from "./chunk-XYKAO6KJ.mjs";
18
+ } from "./chunk-Y4U7Q543.mjs";
19
+ import {
20
+ UptoEvmScheme,
21
+ createUptoEvmScheme
22
+ } from "./chunk-SURTCHSX.mjs";
23
+ import {
24
+ createNonce
25
+ } from "./chunk-SYVPLXYV.mjs";
26
+ import {
27
+ __publicField
28
+ } from "./chunk-NSSMTXJJ.mjs";
29
+
30
+ // src/index.ts
31
+ export * from "@t402/evm-core";
26
32
 
27
33
  // src/exact-legacy/client/scheme.ts
28
34
  import { getAddress } from "viem";
@@ -34,7 +40,7 @@ var ExactLegacyEvmScheme = class {
34
40
  */
35
41
  constructor(signer) {
36
42
  this.signer = signer;
37
- this.scheme = "exact-legacy";
43
+ __publicField(this, "scheme", "exact-legacy");
38
44
  }
39
45
  /**
40
46
  * Creates a payment payload for the exact-legacy scheme.
@@ -109,13 +115,39 @@ var ExactLegacyEvmScheme = class {
109
115
 
110
116
  // src/exact-legacy/server/scheme.ts
111
117
  var ExactLegacyEvmScheme2 = class {
118
+ /**
119
+ * Creates a new ExactLegacyEvmScheme instance.
120
+ *
121
+ * @param config - Optional configuration options for the scheme
122
+ */
112
123
  constructor(config = {}) {
113
- this.scheme = "exact-legacy";
114
- this.moneyParsers = [];
124
+ __publicField(this, "scheme", "exact-legacy");
125
+ __publicField(this, "moneyParsers", []);
126
+ __publicField(this, "config");
115
127
  this.config = config;
116
128
  }
129
+ /**
130
+ * Get all supported networks that have legacy tokens
131
+ *
132
+ * @returns Array of network identifiers with legacy token support
133
+ */
134
+ static getSupportedNetworks() {
135
+ return Object.keys(USDT_LEGACY_ADDRESSES);
136
+ }
137
+ /**
138
+ * Check if a network has legacy token support
139
+ *
140
+ * @param network - The network identifier to check
141
+ * @returns True if the network has legacy token support
142
+ */
143
+ static isNetworkSupported(network) {
144
+ return network in USDT_LEGACY_ADDRESSES;
145
+ }
117
146
  /**
118
147
  * Register a custom money parser in the parser chain.
148
+ *
149
+ * @param parser - Custom function to convert amount to AssetAmount
150
+ * @returns The scheme instance for method chaining
119
151
  */
120
152
  registerMoneyParser(parser) {
121
153
  this.moneyParsers.push(parser);
@@ -123,6 +155,10 @@ var ExactLegacyEvmScheme2 = class {
123
155
  }
124
156
  /**
125
157
  * Parses a price into an asset amount for legacy tokens.
158
+ *
159
+ * @param price - The price to parse (Money or AssetAmount)
160
+ * @param network - The network identifier in CAIP-2 format
161
+ * @returns Promise resolving to the parsed asset amount
126
162
  */
127
163
  async parsePrice(price, network) {
128
164
  if (typeof price === "object" && price !== null && "amount" in price) {
@@ -150,6 +186,15 @@ var ExactLegacyEvmScheme2 = class {
150
186
  /**
151
187
  * Build payment requirements for this scheme/network combination.
152
188
  * Adds the spender (facilitator) address to the extra field.
189
+ *
190
+ * @param paymentRequirements - The base payment requirements to enhance
191
+ * @param supportedKind - The supported kind from facilitator
192
+ * @param supportedKind.t402Version - The t402 protocol version
193
+ * @param supportedKind.scheme - The logical payment scheme identifier
194
+ * @param supportedKind.network - The network identifier in CAIP-2 format
195
+ * @param supportedKind.extra - Optional extra metadata with spender address
196
+ * @param extensionKeys - Extension keys supported by the facilitator (unused)
197
+ * @returns Promise resolving to enhanced payment requirements
153
198
  */
154
199
  enhancePaymentRequirements(paymentRequirements, supportedKind, extensionKeys) {
155
200
  void extensionKeys;
@@ -165,6 +210,9 @@ var ExactLegacyEvmScheme2 = class {
165
210
  }
166
211
  /**
167
212
  * Parse Money (string | number) to a decimal number.
213
+ *
214
+ * @param money - The money value to parse (e.g., "$1.50" or 1.50)
215
+ * @returns The decimal number representation
168
216
  */
169
217
  parseMoneyToDecimal(money) {
170
218
  if (typeof money === "number") {
@@ -179,6 +227,10 @@ var ExactLegacyEvmScheme2 = class {
179
227
  }
180
228
  /**
181
229
  * Default money conversion implementation for legacy tokens.
230
+ *
231
+ * @param amount - The decimal amount to convert (e.g., 1.50)
232
+ * @param network - The network identifier in CAIP-2 format
233
+ * @returns The asset amount in token units
182
234
  */
183
235
  defaultMoneyConversion(amount, network) {
184
236
  const token = this.getDefaultAsset(network);
@@ -196,6 +248,10 @@ var ExactLegacyEvmScheme2 = class {
196
248
  }
197
249
  /**
198
250
  * Convert decimal amount to token units
251
+ *
252
+ * @param decimalAmount - The decimal amount as a string (e.g., "1.50")
253
+ * @param decimals - The number of decimal places for the token
254
+ * @returns The token amount as a string in smallest units
199
255
  */
200
256
  convertToTokenAmount(decimalAmount, decimals) {
201
257
  const amount = parseFloat(decimalAmount);
@@ -207,6 +263,9 @@ var ExactLegacyEvmScheme2 = class {
207
263
  }
208
264
  /**
209
265
  * Get the default legacy token for a network.
266
+ *
267
+ * @param network - The network identifier in CAIP-2 format
268
+ * @returns The token configuration for the default legacy token
210
269
  */
211
270
  getDefaultAsset(network) {
212
271
  if (this.config.preferredToken) {
@@ -226,18 +285,6 @@ var ExactLegacyEvmScheme2 = class {
226
285
  }
227
286
  throw new Error(`No legacy tokens configured for network ${network}`);
228
287
  }
229
- /**
230
- * Get all supported networks that have legacy tokens
231
- */
232
- static getSupportedNetworks() {
233
- return Object.keys(USDT_LEGACY_ADDRESSES);
234
- }
235
- /**
236
- * Check if a network has legacy token support
237
- */
238
- static isNetworkSupported(network) {
239
- return network in USDT_LEGACY_ADDRESSES;
240
- }
241
288
  };
242
289
 
243
290
  // src/exact-legacy/facilitator/scheme.ts
@@ -251,8 +298,9 @@ var ExactLegacyEvmScheme3 = class {
251
298
  */
252
299
  constructor(signer, config) {
253
300
  this.signer = signer;
254
- this.scheme = "exact-legacy";
255
- this.caipFamily = "eip155:*";
301
+ __publicField(this, "scheme", "exact-legacy");
302
+ __publicField(this, "caipFamily", "eip155:*");
303
+ __publicField(this, "config");
256
304
  this.config = {
257
305
  minAllowanceRatio: config?.minAllowanceRatio ?? 1
258
306
  };
@@ -277,6 +325,9 @@ var ExactLegacyEvmScheme3 = class {
277
325
  }
278
326
  /**
279
327
  * Get signer addresses used by this facilitator.
328
+ *
329
+ * @param network - The network identifier (unused, returns same addresses for all networks)
330
+ * @returns Array of signer addresses
280
331
  */
281
332
  getSigners(network) {
282
333
  void network;
@@ -284,6 +335,10 @@ var ExactLegacyEvmScheme3 = class {
284
335
  }
285
336
  /**
286
337
  * Verifies a payment payload.
338
+ *
339
+ * @param payload - The payment payload to verify
340
+ * @param requirements - The payment requirements to verify against
341
+ * @returns Promise resolving to verification response with validity status
287
342
  */
288
343
  async verify(payload, requirements) {
289
344
  const legacyPayload = payload.payload;
@@ -430,6 +485,10 @@ var ExactLegacyEvmScheme3 = class {
430
485
  }
431
486
  /**
432
487
  * Settles a payment by executing transferFrom.
488
+ *
489
+ * @param payload - The payment payload containing transfer authorization
490
+ * @param requirements - The payment requirements specifying amount and recipient
491
+ * @returns Promise resolving to settlement response with transaction hash
433
492
  */
434
493
  async settle(payload, requirements) {
435
494
  const legacyPayload = payload.payload;
@@ -483,16 +542,8 @@ var ExactLegacyEvmScheme3 = class {
483
542
  }
484
543
  };
485
544
 
486
- // src/signer.ts
487
- function toClientEvmSigner(signer) {
488
- return signer;
489
- }
490
- function toFacilitatorEvmSigner(client) {
491
- return {
492
- ...client,
493
- getAddresses: () => [client.address]
494
- };
495
- }
545
+ // src/bridge/client.ts
546
+ import { keccak256, toBytes } from "viem";
496
547
 
497
548
  // src/bridge/constants.ts
498
549
  var LAYERZERO_ENDPOINT_IDS = {
@@ -666,9 +717,7 @@ function supportsBridging(chain) {
666
717
  return chain in USDT0_OFT_ADDRESSES && chain in LAYERZERO_ENDPOINT_IDS;
667
718
  }
668
719
  function getBridgeableChains() {
669
- return Object.keys(USDT0_OFT_ADDRESSES).filter(
670
- (chain) => chain in LAYERZERO_ENDPOINT_IDS
671
- );
720
+ return Object.keys(USDT0_OFT_ADDRESSES).filter((chain) => chain in LAYERZERO_ENDPOINT_IDS);
672
721
  }
673
722
  function addressToBytes32(address) {
674
723
  const cleanAddress = address.slice(2).toLowerCase();
@@ -679,6 +728,7 @@ function bytes32ToAddress(bytes32) {
679
728
  }
680
729
 
681
730
  // src/bridge/client.ts
731
+ var OFT_SENT_EVENT_TOPIC = keccak256(toBytes("OFTSent(bytes32,uint32,address,uint256,uint256)"));
682
732
  var DEFAULT_SLIPPAGE = 0.5;
683
733
  var ESTIMATED_BRIDGE_TIME = 300;
684
734
  var Usdt0Bridge = class {
@@ -689,6 +739,8 @@ var Usdt0Bridge = class {
689
739
  * @param chain - Source chain name (e.g., "arbitrum", "ethereum")
690
740
  */
691
741
  constructor(signer, chain) {
742
+ __publicField(this, "signer");
743
+ __publicField(this, "chain");
692
744
  if (!supportsBridging(chain)) {
693
745
  throw new Error(
694
746
  `Chain "${chain}" does not support USDT0 bridging. Supported chains: ${getBridgeableChains().join(", ")}`
@@ -751,10 +803,10 @@ var Usdt0Bridge = class {
751
803
  if (receipt.status !== "success") {
752
804
  throw new Error(`Bridge transaction failed: ${txHash}`);
753
805
  }
806
+ const messageGuid = this.extractMessageGuid(receipt);
754
807
  return {
755
808
  txHash,
756
- messageGuid: "0x" + "0".repeat(64),
757
- // Would be extracted from event logs
809
+ messageGuid,
758
810
  amountSent: params.amount,
759
811
  amountToReceive: sendParam.minAmountLD,
760
812
  fromChain: params.fromChain,
@@ -762,8 +814,44 @@ var Usdt0Bridge = class {
762
814
  estimatedTime: ESTIMATED_BRIDGE_TIME
763
815
  };
764
816
  }
817
+ /**
818
+ * Get all supported destination chains from current chain
819
+ *
820
+ * @returns Array of supported destination chain names
821
+ */
822
+ getSupportedDestinations() {
823
+ return getBridgeableChains().filter((chain) => chain !== this.chain);
824
+ }
825
+ /**
826
+ * Check if a destination chain is supported
827
+ *
828
+ * @param toChain - The destination chain to check
829
+ * @returns True if the destination chain is supported
830
+ */
831
+ supportsDestination(toChain) {
832
+ return toChain !== this.chain && supportsBridging(toChain);
833
+ }
834
+ /**
835
+ * Extract LayerZero message GUID from OFTSent event logs
836
+ *
837
+ * @param receipt - Transaction receipt with logs
838
+ * @returns Message GUID as hex string
839
+ */
840
+ extractMessageGuid(receipt) {
841
+ for (const log of receipt.logs) {
842
+ if (log.topics[0] === OFT_SENT_EVENT_TOPIC && log.topics[1]) {
843
+ return log.topics[1];
844
+ }
845
+ }
846
+ throw new Error(
847
+ "Failed to extract message GUID from transaction logs. The OFTSent event was not found in the transaction receipt."
848
+ );
849
+ }
765
850
  /**
766
851
  * Ensure sufficient token allowance for the OFT contract
852
+ *
853
+ * @param oftAddress - The OFT contract address
854
+ * @param amount - The amount to approve
767
855
  */
768
856
  async ensureAllowance(oftAddress, amount) {
769
857
  const allowance = await this.signer.readContract({
@@ -784,6 +872,9 @@ var Usdt0Bridge = class {
784
872
  }
785
873
  /**
786
874
  * Build SendParam struct for LayerZero
875
+ *
876
+ * @param params - Bridge parameters
877
+ * @returns SendParam struct for the OFT contract
787
878
  */
788
879
  buildSendParam(params) {
789
880
  const dstEid = getEndpointId(params.toChain);
@@ -804,6 +895,8 @@ var Usdt0Bridge = class {
804
895
  }
805
896
  /**
806
897
  * Validate bridge parameters
898
+ *
899
+ * @param params - Bridge parameters to validate
807
900
  */
808
901
  validateBridgeParams(params) {
809
902
  if (params.fromChain !== this.chain) {
@@ -824,21 +917,301 @@ var Usdt0Bridge = class {
824
917
  throw new Error("Amount must be greater than 0");
825
918
  }
826
919
  }
920
+ };
921
+ function createUsdt0Bridge(signer, chain) {
922
+ return new Usdt0Bridge(signer, chain);
923
+ }
924
+
925
+ // src/bridge/scan.ts
926
+ var LAYERZERO_SCAN_BASE_URL = "https://scan.layerzero-api.com/v1";
927
+ var DEFAULT_TIMEOUT = 6e5;
928
+ var DEFAULT_POLL_INTERVAL = 1e4;
929
+ var LayerZeroScanClient = class {
827
930
  /**
828
- * Get all supported destination chains from current chain
931
+ * Create a new LayerZero Scan client
932
+ *
933
+ * @param baseUrl - API base URL (default: production endpoint)
934
+ */
935
+ constructor(baseUrl = LAYERZERO_SCAN_BASE_URL) {
936
+ __publicField(this, "baseUrl");
937
+ this.baseUrl = baseUrl;
938
+ }
939
+ /**
940
+ * Get message by GUID
941
+ *
942
+ * @param guid - LayerZero message GUID
943
+ * @returns Message details including status
944
+ * @throws Error if message not found or API error
945
+ */
946
+ async getMessage(guid) {
947
+ const url = `${this.baseUrl}/messages/guid/${guid}`;
948
+ const response = await fetch(url, {
949
+ method: "GET",
950
+ headers: {
951
+ Accept: "application/json"
952
+ }
953
+ });
954
+ if (!response.ok) {
955
+ if (response.status === 404) {
956
+ throw new Error(`Message not found: ${guid}`);
957
+ }
958
+ throw new Error(`LayerZero Scan API error: ${response.status} ${response.statusText}`);
959
+ }
960
+ const data = await response.json();
961
+ return this.mapApiResponse(data);
962
+ }
963
+ /**
964
+ * Get messages by wallet address
965
+ *
966
+ * @param address - Wallet address that initiated messages
967
+ * @param limit - Maximum number of messages to return (default: 20)
968
+ * @returns Array of messages
969
+ */
970
+ async getMessagesByWallet(address, limit = 20) {
971
+ const url = `${this.baseUrl}/messages/wallet/${address}?limit=${limit}`;
972
+ const response = await fetch(url, {
973
+ method: "GET",
974
+ headers: {
975
+ Accept: "application/json"
976
+ }
977
+ });
978
+ if (!response.ok) {
979
+ throw new Error(`LayerZero Scan API error: ${response.status} ${response.statusText}`);
980
+ }
981
+ const data = await response.json();
982
+ const messages = data.messages ?? data.data ?? [];
983
+ return messages.map((msg) => this.mapApiResponse(msg));
984
+ }
985
+ /**
986
+ * Poll message status until delivered or failed
987
+ *
988
+ * @param guid - LayerZero message GUID
989
+ * @param options - Wait configuration options
990
+ * @returns Final message state (DELIVERED)
991
+ * @throws Error if message fails, is blocked, or times out
992
+ */
993
+ async waitForDelivery(guid, options = {}) {
994
+ const {
995
+ timeout = DEFAULT_TIMEOUT,
996
+ pollInterval = DEFAULT_POLL_INTERVAL,
997
+ onStatusChange
998
+ } = options;
999
+ const startTime = Date.now();
1000
+ let lastStatus = null;
1001
+ while (Date.now() - startTime < timeout) {
1002
+ try {
1003
+ const message = await this.getMessage(guid);
1004
+ if (lastStatus !== message.status) {
1005
+ lastStatus = message.status;
1006
+ onStatusChange?.(message.status);
1007
+ }
1008
+ if (message.status === "DELIVERED") {
1009
+ return message;
1010
+ }
1011
+ if (message.status === "FAILED") {
1012
+ throw new Error(`Bridge message failed: ${guid}`);
1013
+ }
1014
+ if (message.status === "BLOCKED") {
1015
+ throw new Error(`Bridge message blocked by DVN: ${guid}`);
1016
+ }
1017
+ await this.sleep(pollInterval);
1018
+ } catch (error) {
1019
+ if (error.message.includes("not found")) {
1020
+ await this.sleep(pollInterval);
1021
+ continue;
1022
+ }
1023
+ throw error;
1024
+ }
1025
+ }
1026
+ throw new Error(`Timeout waiting for message delivery: ${guid}`);
1027
+ }
1028
+ /**
1029
+ * Check if a message has been delivered
1030
+ *
1031
+ * @param guid - LayerZero message GUID
1032
+ * @returns True if delivered, false otherwise
1033
+ */
1034
+ async isDelivered(guid) {
1035
+ try {
1036
+ const message = await this.getMessage(guid);
1037
+ return message.status === "DELIVERED";
1038
+ } catch {
1039
+ return false;
1040
+ }
1041
+ }
1042
+ /**
1043
+ * Map API response to our interface
1044
+ *
1045
+ * @param data - The raw API response data
1046
+ * @returns The mapped LayerZeroMessage object
1047
+ */
1048
+ mapApiResponse(data) {
1049
+ const msg = data;
1050
+ return {
1051
+ guid: msg.guid ?? msg.messageGuid ?? "",
1052
+ srcEid: msg.srcEid ?? msg.srcChainId ?? 0,
1053
+ dstEid: msg.dstEid ?? msg.dstChainId ?? 0,
1054
+ srcUaAddress: msg.srcUaAddress ?? msg.srcAddress ?? "",
1055
+ dstUaAddress: msg.dstUaAddress ?? msg.dstAddress ?? "",
1056
+ srcTxHash: msg.srcTxHash ?? "",
1057
+ dstTxHash: msg.dstTxHash ?? void 0,
1058
+ status: msg.status ?? "INFLIGHT",
1059
+ srcBlockNumber: msg.srcBlockNumber ?? 0,
1060
+ dstBlockNumber: msg.dstBlockNumber ?? void 0,
1061
+ created: msg.created ?? msg.createdAt ?? "",
1062
+ updated: msg.updated ?? msg.updatedAt ?? ""
1063
+ };
1064
+ }
1065
+ /**
1066
+ * Sleep helper
1067
+ *
1068
+ * @param ms - The number of milliseconds to sleep
1069
+ * @returns A promise that resolves after the specified delay
1070
+ */
1071
+ sleep(ms) {
1072
+ return new Promise((resolve) => setTimeout(resolve, ms));
1073
+ }
1074
+ };
1075
+ function createLayerZeroScanClient(baseUrl) {
1076
+ return new LayerZeroScanClient(baseUrl);
1077
+ }
1078
+
1079
+ // src/bridge/router.ts
1080
+ var CrossChainPaymentRouter = class {
1081
+ /**
1082
+ * Create a cross-chain payment router
1083
+ *
1084
+ * @param signer - Wallet signer for bridge operations
1085
+ * @param sourceChain - Chain where user's funds are located
1086
+ */
1087
+ constructor(signer, sourceChain) {
1088
+ __publicField(this, "bridge");
1089
+ __publicField(this, "scanClient");
1090
+ __publicField(this, "sourceChain");
1091
+ this.bridge = new Usdt0Bridge(signer, sourceChain);
1092
+ this.scanClient = new LayerZeroScanClient();
1093
+ this.sourceChain = sourceChain;
1094
+ }
1095
+ /**
1096
+ * Get all bridgeable chains
1097
+ *
1098
+ * @returns Array of all chain names that support USDT0 bridging
1099
+ */
1100
+ static getBridgeableChains() {
1101
+ return getBridgeableChains();
1102
+ }
1103
+ /**
1104
+ * Route payment across chains
1105
+ *
1106
+ * This method:
1107
+ * 1. Bridges USDT0 from source chain to destination chain
1108
+ * 2. Sends funds to the payer's address on destination chain
1109
+ * 3. Returns tracking info for monitoring delivery
1110
+ *
1111
+ * After delivery, the payer can use the bridged funds to pay on the destination chain.
1112
+ *
1113
+ * @param params - Payment routing parameters
1114
+ * @returns Result with transaction hash and tracking info
1115
+ */
1116
+ async routePayment(params) {
1117
+ this.validateParams(params);
1118
+ const result = await this.bridge.send({
1119
+ fromChain: params.sourceChain,
1120
+ toChain: params.destinationChain,
1121
+ amount: params.amount,
1122
+ recipient: params.payer,
1123
+ slippageTolerance: params.slippageTolerance
1124
+ });
1125
+ return {
1126
+ bridgeTxHash: result.txHash,
1127
+ messageGuid: result.messageGuid,
1128
+ amountBridged: result.amountSent,
1129
+ estimatedReceiveAmount: result.amountToReceive,
1130
+ sourceChain: params.sourceChain,
1131
+ destinationChain: params.destinationChain,
1132
+ estimatedDeliveryTime: result.estimatedTime
1133
+ };
1134
+ }
1135
+ /**
1136
+ * Get estimated fees for routing a payment
1137
+ *
1138
+ * @param params - Payment parameters
1139
+ * @returns Quote with native fee and estimated receive amount
1140
+ */
1141
+ async estimateFees(params) {
1142
+ const quote = await this.bridge.quote({
1143
+ fromChain: params.sourceChain,
1144
+ toChain: params.destinationChain,
1145
+ amount: params.amount,
1146
+ recipient: params.payer
1147
+ });
1148
+ return {
1149
+ nativeFee: quote.nativeFee,
1150
+ estimatedReceiveAmount: quote.minAmountToReceive,
1151
+ estimatedTime: quote.estimatedTime
1152
+ };
1153
+ }
1154
+ /**
1155
+ * Track message delivery status
1156
+ *
1157
+ * @param messageGuid - LayerZero message GUID from routePayment result
1158
+ * @returns Current message status
1159
+ */
1160
+ async trackMessage(messageGuid) {
1161
+ return this.scanClient.getMessage(messageGuid);
1162
+ }
1163
+ /**
1164
+ * Wait for payment to be delivered on destination chain
1165
+ *
1166
+ * @param messageGuid - LayerZero message GUID from routePayment result
1167
+ * @param options - Wait options (timeout, poll interval, callbacks)
1168
+ * @returns Final message state when delivered
1169
+ */
1170
+ async waitForDelivery(messageGuid, options) {
1171
+ return this.scanClient.waitForDelivery(messageGuid, options);
1172
+ }
1173
+ /**
1174
+ * Check if routing between two chains is supported
1175
+ *
1176
+ * @param sourceChain - Source chain name
1177
+ * @param destinationChain - Destination chain name
1178
+ * @returns True if routing is supported
1179
+ */
1180
+ canRoute(sourceChain, destinationChain) {
1181
+ return sourceChain !== destinationChain && supportsBridging(sourceChain) && supportsBridging(destinationChain);
1182
+ }
1183
+ /**
1184
+ * Get all supported destination chains from source chain
1185
+ *
1186
+ * @returns Array of chain names that can receive bridged funds
829
1187
  */
830
1188
  getSupportedDestinations() {
831
- return getBridgeableChains().filter((chain) => chain !== this.chain);
1189
+ return this.bridge.getSupportedDestinations();
832
1190
  }
833
1191
  /**
834
- * Check if a destination chain is supported
1192
+ * Validate routing parameters
1193
+ *
1194
+ * @param params - The cross-chain payment parameters to validate
1195
+ * @throws Error if parameters are invalid or routing is not supported
835
1196
  */
836
- supportsDestination(toChain) {
837
- return toChain !== this.chain && supportsBridging(toChain);
1197
+ validateParams(params) {
1198
+ if (params.sourceChain !== this.sourceChain) {
1199
+ throw new Error(
1200
+ `Source chain mismatch: router initialized for "${this.sourceChain}" but got "${params.sourceChain}"`
1201
+ );
1202
+ }
1203
+ if (!this.canRoute(params.sourceChain, params.destinationChain)) {
1204
+ throw new Error(
1205
+ `Cannot route payment from "${params.sourceChain}" to "${params.destinationChain}". Supported chains: ${getBridgeableChains().join(", ")}`
1206
+ );
1207
+ }
1208
+ if (params.amount <= 0n) {
1209
+ throw new Error("Amount must be greater than 0");
1210
+ }
838
1211
  }
839
1212
  };
840
- function createUsdt0Bridge(signer, chain) {
841
- return new Usdt0Bridge(signer, chain);
1213
+ function createCrossChainPaymentRouter(signer, sourceChain) {
1214
+ return new CrossChainPaymentRouter(signer, sourceChain);
842
1215
  }
843
1216
 
844
1217
  // src/erc4337/constants.ts
@@ -1018,23 +1391,33 @@ function unpackGasFees(packed) {
1018
1391
  // src/erc4337/builder.ts
1019
1392
  import { concat, pad, toHex } from "viem";
1020
1393
  var UserOpBuilder = class {
1394
+ /**
1395
+ * Create a new UserOpBuilder instance
1396
+ *
1397
+ * @param options - Optional configuration for the builder
1398
+ */
1021
1399
  constructor(options = {}) {
1400
+ __publicField(this, "entryPoint");
1401
+ __publicField(this, "gasMultiplier");
1022
1402
  this.entryPoint = options.entryPoint ?? ENTRYPOINT_V07_ADDRESS;
1023
1403
  this.gasMultiplier = options.gasMultiplier ?? 1.2;
1024
1404
  }
1025
1405
  /**
1026
1406
  * Build a UserOperation from a transaction intent
1407
+ *
1408
+ * @param signer - The smart account signer
1409
+ * @param intent - The transaction intent to execute
1410
+ * @param client - The public client for chain interaction
1411
+ * @param gasEstimate - Optional gas estimates (uses defaults if not provided)
1412
+ * @param paymaster - Optional paymaster data for sponsored transactions
1413
+ * @returns A UserOperation ready for signing
1027
1414
  */
1028
1415
  async buildUserOp(signer, intent, client, gasEstimate, paymaster) {
1029
1416
  const sender = await signer.getAddress();
1030
1417
  const nonce = await this.getNonce(client, sender);
1031
1418
  const isDeployed = await signer.isDeployed();
1032
1419
  const initCode = isDeployed ? "0x" : await signer.getInitCode();
1033
- const callData = signer.encodeExecute(
1034
- intent.to,
1035
- intent.value ?? 0n,
1036
- intent.data ?? "0x"
1037
- );
1420
+ const callData = signer.encodeExecute(intent.to, intent.value ?? 0n, intent.data ?? "0x");
1038
1421
  const { maxFeePerGas, maxPriorityFeePerGas } = await this.getGasPrices(client);
1039
1422
  const gas = gasEstimate ?? DEFAULT_GAS_LIMITS;
1040
1423
  const verificationGasLimit = this.applyMultiplier(gas.verificationGasLimit);
@@ -1058,6 +1441,13 @@ var UserOpBuilder = class {
1058
1441
  }
1059
1442
  /**
1060
1443
  * Build a batch UserOperation from multiple transaction intents
1444
+ *
1445
+ * @param signer - The smart account signer
1446
+ * @param intents - Array of transaction intents to execute
1447
+ * @param client - The public client for chain interaction
1448
+ * @param gasEstimate - Optional gas estimates (uses defaults if not provided)
1449
+ * @param paymaster - Optional paymaster data for sponsored transactions
1450
+ * @returns A UserOperation ready for signing
1061
1451
  */
1062
1452
  async buildBatchUserOp(signer, intents, client, gasEstimate, paymaster) {
1063
1453
  const sender = await signer.getAddress();
@@ -1094,6 +1484,9 @@ var UserOpBuilder = class {
1094
1484
  }
1095
1485
  /**
1096
1486
  * Pack a UserOperation for on-chain submission (v0.7 format)
1487
+ *
1488
+ * @param userOp - The UserOperation to pack
1489
+ * @returns The packed UserOperation for on-chain submission
1097
1490
  */
1098
1491
  packUserOp(userOp) {
1099
1492
  return {
@@ -1101,10 +1494,7 @@ var UserOpBuilder = class {
1101
1494
  nonce: userOp.nonce,
1102
1495
  initCode: userOp.initCode,
1103
1496
  callData: userOp.callData,
1104
- accountGasLimits: packAccountGasLimits(
1105
- userOp.verificationGasLimit,
1106
- userOp.callGasLimit
1107
- ),
1497
+ accountGasLimits: packAccountGasLimits(userOp.verificationGasLimit, userOp.callGasLimit),
1108
1498
  preVerificationGas: userOp.preVerificationGas,
1109
1499
  gasFees: packGasFees(userOp.maxPriorityFeePerGas, userOp.maxFeePerGas),
1110
1500
  paymasterAndData: userOp.paymasterAndData,
@@ -1113,8 +1503,13 @@ var UserOpBuilder = class {
1113
1503
  }
1114
1504
  /**
1115
1505
  * Compute the UserOperation hash for signing
1506
+ *
1507
+ * @param userOp - The UserOperation to hash
1508
+ * @param client - The public client for chain interaction
1509
+ * @param _ - The chain ID (reserved for future use)
1510
+ * @returns The UserOperation hash
1116
1511
  */
1117
- async getUserOpHash(userOp, client, chainId) {
1512
+ async getUserOpHash(userOp, client, _) {
1118
1513
  const packed = this.packUserOp(userOp);
1119
1514
  const userOpTuple = {
1120
1515
  sender: packed.sender,
@@ -1137,6 +1532,12 @@ var UserOpBuilder = class {
1137
1532
  }
1138
1533
  /**
1139
1534
  * Sign a UserOperation
1535
+ *
1536
+ * @param userOp - The UserOperation to sign
1537
+ * @param signer - The smart account signer
1538
+ * @param client - The public client for chain interaction
1539
+ * @param chainId - The chain ID for the signature
1540
+ * @returns The UserOperation with signature attached
1140
1541
  */
1141
1542
  async signUserOp(userOp, signer, client, chainId) {
1142
1543
  const userOpHash = await this.getUserOpHash(userOp, client, chainId);
@@ -1148,6 +1549,10 @@ var UserOpBuilder = class {
1148
1549
  }
1149
1550
  /**
1150
1551
  * Get the nonce for an account from EntryPoint
1552
+ *
1553
+ * @param client - The public client for chain interaction
1554
+ * @param sender - The smart account address
1555
+ * @returns The current nonce for the account
1151
1556
  */
1152
1557
  async getNonce(client, sender) {
1153
1558
  try {
@@ -1165,6 +1570,9 @@ var UserOpBuilder = class {
1165
1570
  }
1166
1571
  /**
1167
1572
  * Get current gas prices from the chain
1573
+ *
1574
+ * @param client - The public client for chain interaction
1575
+ * @returns The current gas prices for EIP-1559 transactions
1168
1576
  */
1169
1577
  async getGasPrices(client) {
1170
1578
  const block = await client.getBlock({ blockTag: "latest" });
@@ -1175,12 +1583,18 @@ var UserOpBuilder = class {
1175
1583
  }
1176
1584
  /**
1177
1585
  * Apply gas multiplier for safety margin
1586
+ *
1587
+ * @param gas - The gas amount to multiply
1588
+ * @returns The gas amount with safety margin applied
1178
1589
  */
1179
1590
  applyMultiplier(gas) {
1180
1591
  return BigInt(Math.ceil(Number(gas) * this.gasMultiplier));
1181
1592
  }
1182
1593
  /**
1183
1594
  * Encode paymaster data for the UserOperation
1595
+ *
1596
+ * @param paymaster - The paymaster configuration
1597
+ * @returns The encoded paymaster data
1184
1598
  */
1185
1599
  encodePaymasterData(paymaster) {
1186
1600
  const paymasterAddress = paymaster.paymaster;
@@ -1188,12 +1602,7 @@ var UserOpBuilder = class {
1188
1602
  size: 16
1189
1603
  });
1190
1604
  const postOpGas = pad(toHex(paymaster.paymasterPostOpGasLimit), { size: 16 });
1191
- return concat([
1192
- paymasterAddress,
1193
- verificationGas,
1194
- postOpGas,
1195
- paymaster.paymasterData
1196
- ]);
1605
+ return concat([paymasterAddress, verificationGas, postOpGas, paymaster.paymasterData]);
1197
1606
  }
1198
1607
  };
1199
1608
  function createUserOpBuilder(options) {
@@ -1202,6 +1611,13 @@ function createUserOpBuilder(options) {
1202
1611
 
1203
1612
  // src/erc4337/bundler.ts
1204
1613
  var BundlerError = class extends Error {
1614
+ /**
1615
+ * Create a new BundlerError
1616
+ *
1617
+ * @param message - The error message
1618
+ * @param code - Optional JSON-RPC error code
1619
+ * @param data - Optional additional error data
1620
+ */
1205
1621
  constructor(message, code, data) {
1206
1622
  super(message);
1207
1623
  this.code = code;
@@ -1210,21 +1626,31 @@ var BundlerError = class extends Error {
1210
1626
  }
1211
1627
  };
1212
1628
  var BundlerClient = class {
1629
+ /**
1630
+ * Create a new BundlerClient instance
1631
+ *
1632
+ * @param config - Configuration for the bundler client
1633
+ */
1213
1634
  constructor(config) {
1214
- this.requestId = 0;
1635
+ __publicField(this, "bundlerUrl");
1636
+ __publicField(this, "entryPoint");
1637
+ __publicField(this, "requestId", 0);
1215
1638
  this.bundlerUrl = config.bundlerUrl;
1216
1639
  this.entryPoint = config.entryPoint ?? ENTRYPOINT_V07_ADDRESS;
1217
- this.chainId = config.chainId;
1640
+ void config.chainId;
1218
1641
  }
1219
1642
  /**
1220
1643
  * Send a UserOperation to the bundler
1644
+ *
1645
+ * @param userOp - The UserOperation to send
1646
+ * @returns The result containing the userOpHash and a wait function
1221
1647
  */
1222
1648
  async sendUserOperation(userOp) {
1223
1649
  const packed = this.packForRpc(userOp);
1224
- const userOpHash = await this.rpcCall(
1225
- BUNDLER_METHODS.sendUserOperation,
1226
- [packed, this.entryPoint]
1227
- );
1650
+ const userOpHash = await this.rpcCall(BUNDLER_METHODS.sendUserOperation, [
1651
+ packed,
1652
+ this.entryPoint
1653
+ ]);
1228
1654
  return {
1229
1655
  userOpHash,
1230
1656
  wait: () => this.waitForReceipt(userOpHash)
@@ -1232,6 +1658,9 @@ var BundlerClient = class {
1232
1658
  }
1233
1659
  /**
1234
1660
  * Estimate gas for a UserOperation
1661
+ *
1662
+ * @param userOp - Partial UserOperation with required sender and callData
1663
+ * @returns Gas estimates for the UserOperation
1235
1664
  */
1236
1665
  async estimateUserOperationGas(userOp) {
1237
1666
  const estimationOp = {
@@ -1260,6 +1689,9 @@ var BundlerClient = class {
1260
1689
  }
1261
1690
  /**
1262
1691
  * Get UserOperation by hash
1692
+ *
1693
+ * @param userOpHash - The hash of the UserOperation to retrieve
1694
+ * @returns The UserOperation and EntryPoint, or null if not found
1263
1695
  */
1264
1696
  async getUserOperationByHash(userOpHash) {
1265
1697
  const result = await this.rpcCall(BUNDLER_METHODS.getUserOperationByHash, [userOpHash]);
@@ -1267,6 +1699,9 @@ var BundlerClient = class {
1267
1699
  }
1268
1700
  /**
1269
1701
  * Get UserOperation receipt
1702
+ *
1703
+ * @param userOpHash - The hash of the UserOperation
1704
+ * @returns The receipt, or null if not yet included
1270
1705
  */
1271
1706
  async getUserOperationReceipt(userOpHash) {
1272
1707
  const result = await this.rpcCall(BUNDLER_METHODS.getUserOperationReceipt, [userOpHash]);
@@ -1289,12 +1724,16 @@ var BundlerClient = class {
1289
1724
  }
1290
1725
  /**
1291
1726
  * Get supported EntryPoints
1727
+ *
1728
+ * @returns Array of supported EntryPoint addresses
1292
1729
  */
1293
1730
  async getSupportedEntryPoints() {
1294
1731
  return this.rpcCall(BUNDLER_METHODS.supportedEntryPoints, []);
1295
1732
  }
1296
1733
  /**
1297
1734
  * Get chain ID from bundler
1735
+ *
1736
+ * @returns The chain ID
1298
1737
  */
1299
1738
  async getChainId() {
1300
1739
  const result = await this.rpcCall(BUNDLER_METHODS.chainId, []);
@@ -1302,6 +1741,12 @@ var BundlerClient = class {
1302
1741
  }
1303
1742
  /**
1304
1743
  * Wait for UserOperation receipt with polling
1744
+ *
1745
+ * @param userOpHash - The hash of the UserOperation to wait for
1746
+ * @param options - Polling options
1747
+ * @param options.timeout - Maximum time to wait in milliseconds (default: 60000)
1748
+ * @param options.pollingInterval - Interval between polls in milliseconds (default: 2000)
1749
+ * @returns The UserOperation receipt
1305
1750
  */
1306
1751
  async waitForReceipt(userOpHash, options = {}) {
1307
1752
  const timeout = options.timeout ?? 6e4;
@@ -1314,12 +1759,13 @@ var BundlerClient = class {
1314
1759
  }
1315
1760
  await new Promise((resolve) => setTimeout(resolve, pollingInterval));
1316
1761
  }
1317
- throw new BundlerError(
1318
- `Timeout waiting for UserOperation receipt: ${userOpHash}`
1319
- );
1762
+ throw new BundlerError(`Timeout waiting for UserOperation receipt: ${userOpHash}`);
1320
1763
  }
1321
1764
  /**
1322
1765
  * Pack UserOperation for RPC (convert bigints to hex strings)
1766
+ *
1767
+ * @param userOp - The UserOperation to pack
1768
+ * @returns The packed UserOperation for RPC transmission
1323
1769
  */
1324
1770
  packForRpc(userOp) {
1325
1771
  return {
@@ -1327,10 +1773,7 @@ var BundlerClient = class {
1327
1773
  nonce: this.toHex(userOp.nonce),
1328
1774
  initCode: userOp.initCode,
1329
1775
  callData: userOp.callData,
1330
- accountGasLimits: packAccountGasLimits(
1331
- userOp.verificationGasLimit,
1332
- userOp.callGasLimit
1333
- ),
1776
+ accountGasLimits: packAccountGasLimits(userOp.verificationGasLimit, userOp.callGasLimit),
1334
1777
  preVerificationGas: this.toHex(userOp.preVerificationGas),
1335
1778
  gasFees: packGasFees(userOp.maxPriorityFeePerGas, userOp.maxFeePerGas),
1336
1779
  paymasterAndData: userOp.paymasterAndData,
@@ -1339,12 +1782,19 @@ var BundlerClient = class {
1339
1782
  }
1340
1783
  /**
1341
1784
  * Convert bigint to hex string
1785
+ *
1786
+ * @param value - The bigint value to convert
1787
+ * @returns The hex string representation
1342
1788
  */
1343
1789
  toHex(value) {
1344
1790
  return `0x${value.toString(16)}`;
1345
1791
  }
1346
1792
  /**
1347
1793
  * Make a JSON-RPC call to the bundler
1794
+ *
1795
+ * @param method - The JSON-RPC method name
1796
+ * @param params - The method parameters
1797
+ * @returns The result from the bundler
1348
1798
  */
1349
1799
  async rpcCall(method, params) {
1350
1800
  const request = {
@@ -1361,9 +1811,7 @@ var BundlerClient = class {
1361
1811
  body: JSON.stringify(request)
1362
1812
  });
1363
1813
  if (!response.ok) {
1364
- throw new BundlerError(
1365
- `HTTP error: ${response.status} ${response.statusText}`
1366
- );
1814
+ throw new BundlerError(`HTTP error: ${response.status} ${response.statusText}`);
1367
1815
  }
1368
1816
  const json = await response.json();
1369
1817
  if (json.error) {
@@ -1379,23 +1827,30 @@ function createBundlerClient(config) {
1379
1827
  // src/erc4337/paymaster.ts
1380
1828
  import { concat as concat2, pad as pad2, toHex as toHex2 } from "viem";
1381
1829
  var PaymasterClient = class {
1830
+ /**
1831
+ * Creates a new PaymasterClient instance
1832
+ *
1833
+ * @param config - Paymaster configuration including type, address, and optional URL
1834
+ */
1382
1835
  constructor(config) {
1836
+ __publicField(this, "config");
1383
1837
  this.config = config;
1384
1838
  }
1385
1839
  /**
1386
1840
  * Get paymaster data for a UserOperation
1841
+ *
1842
+ * @param userOp - Partial UserOperation to get paymaster data for
1843
+ * @param chainId - The chain ID for the operation
1844
+ * @param entryPoint - The EntryPoint contract address
1845
+ * @param context - Optional context data for the paymaster
1846
+ * @returns Paymaster data including address and gas limits
1387
1847
  */
1388
1848
  async getPaymasterData(userOp, chainId, entryPoint, context) {
1389
1849
  switch (this.config.type) {
1390
1850
  case "verifying":
1391
1851
  return this.getVerifyingPaymasterData(userOp, chainId, entryPoint);
1392
1852
  case "sponsoring":
1393
- return this.getSponsoringPaymasterData(
1394
- userOp,
1395
- chainId,
1396
- entryPoint,
1397
- context
1398
- );
1853
+ return this.getSponsoringPaymasterData(userOp, chainId, entryPoint, context);
1399
1854
  case "token":
1400
1855
  return this.getTokenPaymasterData(userOp, chainId, entryPoint);
1401
1856
  default:
@@ -1404,8 +1859,12 @@ var PaymasterClient = class {
1404
1859
  }
1405
1860
  /**
1406
1861
  * Get gas estimates including paymaster gas
1862
+ *
1863
+ * @param _userOp - Partial UserOperation to estimate gas for (reserved for future use)
1864
+ * @param _chainId - The chain ID for the operation (reserved for future use)
1865
+ * @returns Gas estimates including paymaster verification and postOp gas
1407
1866
  */
1408
- async estimatePaymasterGas(userOp, _chainId) {
1867
+ async estimatePaymasterGas(_userOp, _chainId) {
1409
1868
  return {
1410
1869
  verificationGasLimit: DEFAULT_GAS_LIMITS.verificationGasLimit,
1411
1870
  callGasLimit: DEFAULT_GAS_LIMITS.callGasLimit,
@@ -1416,6 +1875,12 @@ var PaymasterClient = class {
1416
1875
  }
1417
1876
  /**
1418
1877
  * Check if the paymaster will sponsor this operation
1878
+ *
1879
+ * @param userOp - Partial UserOperation to check sponsorship for
1880
+ * @param chainId - The chain ID for the operation
1881
+ * @param entryPoint - The EntryPoint contract address
1882
+ * @param context - Optional context data for policy validation
1883
+ * @returns True if the paymaster will sponsor the operation
1419
1884
  */
1420
1885
  async willSponsor(userOp, chainId, entryPoint, context) {
1421
1886
  if (!this.config.url) {
@@ -1441,6 +1906,11 @@ var PaymasterClient = class {
1441
1906
  }
1442
1907
  /**
1443
1908
  * Get verifying paymaster data (off-chain signature)
1909
+ *
1910
+ * @param userOp - Partial UserOperation to get paymaster data for
1911
+ * @param chainId - The chain ID for the operation
1912
+ * @param entryPoint - The EntryPoint contract address
1913
+ * @returns Paymaster data with verification signature
1444
1914
  */
1445
1915
  async getVerifyingPaymasterData(userOp, chainId, entryPoint) {
1446
1916
  if (this.config.url) {
@@ -1455,6 +1925,12 @@ var PaymasterClient = class {
1455
1925
  }
1456
1926
  /**
1457
1927
  * Get sponsoring paymaster data (third-party pays)
1928
+ *
1929
+ * @param userOp - Partial UserOperation to get sponsorship for
1930
+ * @param chainId - The chain ID for the operation
1931
+ * @param entryPoint - The EntryPoint contract address
1932
+ * @param context - Optional context data for sponsorship validation
1933
+ * @returns Paymaster data for sponsored operation
1458
1934
  */
1459
1935
  async getSponsoringPaymasterData(userOp, chainId, entryPoint, context) {
1460
1936
  if (!this.config.url) {
@@ -1484,6 +1960,11 @@ var PaymasterClient = class {
1484
1960
  }
1485
1961
  /**
1486
1962
  * Get token paymaster data (pay gas with ERC20)
1963
+ *
1964
+ * @param userOp - Partial UserOperation to get token paymaster data for
1965
+ * @param chainId - The chain ID for the operation
1966
+ * @param entryPoint - The EntryPoint contract address
1967
+ * @returns Paymaster data for ERC20 token payment
1487
1968
  */
1488
1969
  async getTokenPaymasterData(userOp, chainId, entryPoint) {
1489
1970
  const tokenAddress = this.config.options?.tokenAddress;
@@ -1505,6 +1986,12 @@ var PaymasterClient = class {
1505
1986
  }
1506
1987
  /**
1507
1988
  * Call paymaster service API
1989
+ *
1990
+ * @param userOp - Partial UserOperation to send to the service
1991
+ * @param chainId - The chain ID for the operation
1992
+ * @param entryPoint - The EntryPoint contract address
1993
+ * @param context - Optional context data for the service
1994
+ * @returns Paymaster data from the service response
1508
1995
  */
1509
1996
  async callPaymasterService(userOp, chainId, entryPoint, context) {
1510
1997
  if (!this.config.url) {
@@ -1534,12 +2021,14 @@ var PaymasterClient = class {
1534
2021
  }
1535
2022
  /**
1536
2023
  * Serialize UserOperation for API calls
2024
+ *
2025
+ * @param userOp - Partial UserOperation to serialize
2026
+ * @returns Serialized UserOperation with hex-encoded values
1537
2027
  */
1538
2028
  serializeUserOp(userOp) {
1539
2029
  const result = {};
1540
2030
  if (userOp.sender) result.sender = userOp.sender;
1541
- if (userOp.nonce !== void 0)
1542
- result.nonce = `0x${userOp.nonce.toString(16)}`;
2031
+ if (userOp.nonce !== void 0) result.nonce = `0x${userOp.nonce.toString(16)}`;
1543
2032
  if (userOp.initCode) result.initCode = userOp.initCode;
1544
2033
  if (userOp.callData) result.callData = userOp.callData;
1545
2034
  if (userOp.verificationGasLimit !== void 0)
@@ -1573,9 +2062,7 @@ function decodePaymasterAndData(paymasterAndData) {
1573
2062
  return null;
1574
2063
  }
1575
2064
  const paymaster = `0x${paymasterAndData.slice(2, 42)}`;
1576
- const paymasterVerificationGasLimit = BigInt(
1577
- `0x${paymasterAndData.slice(42, 74)}`
1578
- );
2065
+ const paymasterVerificationGasLimit = BigInt(`0x${paymasterAndData.slice(42, 74)}`);
1579
2066
  const paymasterPostOpGasLimit = BigInt(`0x${paymasterAndData.slice(74, 106)}`);
1580
2067
  const paymasterData = `0x${paymasterAndData.slice(106)}`;
1581
2068
  return {
@@ -1591,8 +2078,8 @@ import { concat as concat3, pad as pad3, toHex as toHex3 } from "viem";
1591
2078
 
1592
2079
  // src/erc4337/accounts/safe.ts
1593
2080
  import {
1594
- encodeFunctionData as encodeFunctionData2,
1595
- encodeAbiParameters as encodeAbiParameters2,
2081
+ encodeFunctionData,
2082
+ encodeAbiParameters,
1596
2083
  concat as concat4,
1597
2084
  keccak256 as keccak2562,
1598
2085
  getContractAddress,
@@ -1600,7 +2087,7 @@ import {
1600
2087
  } from "viem";
1601
2088
 
1602
2089
  // src/erc4337/t402.ts
1603
- import { encodeFunctionData as encodeFunctionData3 } from "viem";
2090
+ import { encodeFunctionData as encodeFunctionData2 } from "viem";
1604
2091
  var ERC20_TRANSFER_ABI = [
1605
2092
  {
1606
2093
  inputs: [
@@ -1633,7 +2120,18 @@ var EIP3009_TRANSFER_ABI = [
1633
2120
  }
1634
2121
  ];
1635
2122
  var GaslessT402Client = class {
2123
+ /**
2124
+ * Creates a new GaslessT402Client instance
2125
+ *
2126
+ * @param config - Configuration including signer, bundler, paymaster, and chain settings
2127
+ */
1636
2128
  constructor(config) {
2129
+ __publicField(this, "signer");
2130
+ __publicField(this, "builder");
2131
+ __publicField(this, "bundler");
2132
+ __publicField(this, "paymaster");
2133
+ __publicField(this, "chainId");
2134
+ __publicField(this, "publicClient");
1637
2135
  this.signer = config.signer;
1638
2136
  this.builder = new UserOpBuilder();
1639
2137
  this.bundler = new BundlerClient(config.bundler);
@@ -1647,6 +2145,9 @@ var GaslessT402Client = class {
1647
2145
  * This submits the payment as a UserOperation which can be:
1648
2146
  * - Sponsored by a paymaster (truly gasless)
1649
2147
  * - Paid from the smart account's balance
2148
+ *
2149
+ * @param params - Payment parameters including token, recipient, and amount
2150
+ * @returns Result containing the user operation hash and wait function
1650
2151
  */
1651
2152
  async executePayment(params) {
1652
2153
  const callData = params.authorization ? this.buildAuthorizedTransferCallData(params) : this.buildTransferCallData(params);
@@ -1674,6 +2175,9 @@ var GaslessT402Client = class {
1674
2175
  }
1675
2176
  /**
1676
2177
  * Execute multiple T402 payments in a single UserOperation
2178
+ *
2179
+ * @param payments - Array of payment parameters to batch together
2180
+ * @returns Result containing the user operation hash and wait function
1677
2181
  */
1678
2182
  async executeBatchPayments(payments) {
1679
2183
  const intents = payments.map((params) => ({
@@ -1700,6 +2204,9 @@ var GaslessT402Client = class {
1700
2204
  }
1701
2205
  /**
1702
2206
  * Check if a payment can be sponsored (gasless)
2207
+ *
2208
+ * @param params - Payment parameters to check for sponsorship eligibility
2209
+ * @returns True if the payment can be sponsored by the paymaster
1703
2210
  */
1704
2211
  async canSponsor(params) {
1705
2212
  if (!this.paymaster) return false;
@@ -1717,21 +2224,28 @@ var GaslessT402Client = class {
1717
2224
  }
1718
2225
  /**
1719
2226
  * Get the smart account address
2227
+ *
2228
+ * @returns The address of the smart account
1720
2229
  */
1721
2230
  async getAccountAddress() {
1722
2231
  return this.signer.getAddress();
1723
2232
  }
1724
2233
  /**
1725
2234
  * Check if the smart account is deployed
2235
+ *
2236
+ * @returns True if the smart account contract is deployed on-chain
1726
2237
  */
1727
2238
  async isAccountDeployed() {
1728
2239
  return this.signer.isDeployed();
1729
2240
  }
1730
2241
  /**
1731
2242
  * Build call data for a simple ERC20 transfer
2243
+ *
2244
+ * @param params - Payment parameters including recipient and amount
2245
+ * @returns Encoded call data for ERC20 transfer function
1732
2246
  */
1733
2247
  buildTransferCallData(params) {
1734
- return encodeFunctionData3({
2248
+ return encodeFunctionData2({
1735
2249
  abi: ERC20_TRANSFER_ABI,
1736
2250
  functionName: "transfer",
1737
2251
  args: [params.to, params.amount]
@@ -1739,6 +2253,9 @@ var GaslessT402Client = class {
1739
2253
  }
1740
2254
  /**
1741
2255
  * Build call data for an authorized transfer (EIP-3009)
2256
+ *
2257
+ * @param params - Payment parameters including authorization signature
2258
+ * @returns Encoded call data for transferWithAuthorization function
1742
2259
  */
1743
2260
  buildAuthorizedTransferCallData(params) {
1744
2261
  if (!params.authorization) {
@@ -1748,7 +2265,7 @@ var GaslessT402Client = class {
1748
2265
  const r = `0x${sig.slice(2, 66)}`;
1749
2266
  const s = `0x${sig.slice(66, 130)}`;
1750
2267
  const v = parseInt(sig.slice(130, 132), 16);
1751
- return encodeFunctionData3({
2268
+ return encodeFunctionData2({
1752
2269
  abi: EIP3009_TRANSFER_ABI,
1753
2270
  functionName: "transferWithAuthorization",
1754
2271
  args: [
@@ -1767,14 +2284,13 @@ var GaslessT402Client = class {
1767
2284
  }
1768
2285
  /**
1769
2286
  * Estimate gas for a single transaction
2287
+ *
2288
+ * @param intent - Transaction intent with target, value, and data
2289
+ * @returns Gas estimates for the UserOperation
1770
2290
  */
1771
2291
  async estimateGas(intent) {
1772
2292
  const sender = await this.signer.getAddress();
1773
- const callData = this.signer.encodeExecute(
1774
- intent.to,
1775
- intent.value ?? 0n,
1776
- intent.data ?? "0x"
1777
- );
2293
+ const callData = this.signer.encodeExecute(intent.to, intent.value ?? 0n, intent.data ?? "0x");
1778
2294
  try {
1779
2295
  return await this.bundler.estimateUserOperationGas({
1780
2296
  sender,
@@ -1790,6 +2306,9 @@ var GaslessT402Client = class {
1790
2306
  }
1791
2307
  /**
1792
2308
  * Estimate gas for a batch transaction
2309
+ *
2310
+ * @param intents - Array of transaction intents to batch
2311
+ * @returns Gas estimates for the batched UserOperation
1793
2312
  */
1794
2313
  async estimateBatchGas(intents) {
1795
2314
  const sender = await this.signer.getAddress();
@@ -1813,15 +2332,14 @@ var GaslessT402Client = class {
1813
2332
  }
1814
2333
  /**
1815
2334
  * Get paymaster data if configured
2335
+ *
2336
+ * @param _ - Gas estimates (unused but kept for potential future use)
2337
+ * @returns Paymaster data or undefined if no paymaster configured
1816
2338
  */
1817
- async getPaymasterData(_gasEstimate) {
2339
+ async getPaymasterData(_) {
1818
2340
  if (!this.paymaster) return void 0;
1819
2341
  const sender = await this.signer.getAddress();
1820
- return this.paymaster.getPaymasterData(
1821
- { sender },
1822
- this.chainId,
1823
- ENTRYPOINT_V07_ADDRESS
1824
- );
2342
+ return this.paymaster.getPaymasterData({ sender }, this.chainId, ENTRYPOINT_V07_ADDRESS);
1825
2343
  }
1826
2344
  };
1827
2345
  function createGaslessT402Client(config) {
@@ -1832,6 +2350,7 @@ export {
1832
2350
  BUNDLER_METHODS,
1833
2351
  BundlerClient,
1834
2352
  BundlerError,
2353
+ CrossChainPaymentRouter,
1835
2354
  DEFAULT_GAS_LIMITS,
1836
2355
  ENTRYPOINT_V06_ADDRESS,
1837
2356
  ENTRYPOINT_V07_ABI,
@@ -1843,45 +2362,36 @@ export {
1843
2362
  GaslessT402Client,
1844
2363
  LAYERZERO_ENDPOINT_IDS,
1845
2364
  LAYERZERO_ENDPOINT_V2,
2365
+ LAYERZERO_SCAN_BASE_URL,
2366
+ LayerZeroScanClient,
1846
2367
  PaymasterClient,
1847
2368
  PaymasterType,
1848
- TOKEN_PRIORITY,
1849
- TOKEN_REGISTRY,
1850
- USDC_ADDRESSES,
1851
- USDT0_ADDRESSES,
1852
2369
  USDT0_OFT_ADDRESSES,
1853
- USDT_LEGACY_ADDRESSES,
2370
+ UptoEvmFacilitatorScheme,
2371
+ UptoEvmScheme,
2372
+ UptoEvmServerScheme,
1854
2373
  Usdt0Bridge,
1855
2374
  UserOpBuilder,
1856
2375
  addressToBytes32,
1857
- authorizationTypes,
1858
2376
  bytes32ToAddress,
1859
2377
  createBundlerClient,
2378
+ createCrossChainPaymentRouter,
1860
2379
  createGaslessT402Client,
2380
+ createLayerZeroScanClient,
1861
2381
  createPaymasterClient,
2382
+ createUptoEvmFacilitatorScheme,
2383
+ createUptoEvmScheme,
2384
+ createUptoEvmServerScheme,
1862
2385
  createUsdt0Bridge,
1863
2386
  createUserOpBuilder,
1864
2387
  decodePaymasterAndData,
1865
- eip3009ABI,
1866
2388
  encodePaymasterAndData,
1867
- erc20LegacyABI,
1868
2389
  getBridgeableChains,
1869
- getDefaultToken,
1870
- getEIP712Domain,
1871
2390
  getEndpointId,
1872
- getNetworkTokens,
1873
- getNetworksForToken,
1874
- getTokenByAddress,
1875
- getTokenConfig,
1876
- getUsdt0Networks,
1877
2391
  getUsdt0OftAddress,
1878
- legacyAuthorizationTypes,
1879
2392
  packAccountGasLimits,
1880
2393
  packGasFees,
1881
2394
  supportsBridging,
1882
- supportsEIP3009,
1883
- toClientEvmSigner,
1884
- toFacilitatorEvmSigner,
1885
2395
  unpackAccountGasLimits,
1886
2396
  unpackGasFees
1887
2397
  };