@t402/evm 2.6.1 → 2.7.1

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 (37) hide show
  1. package/dist/cjs/constants-05D7IZJA.d.ts +136 -0
  2. package/dist/cjs/permit2/index.d.ts +1 -137
  3. package/dist/cjs/permit2-proxy/client/index.d.ts +83 -0
  4. package/dist/cjs/permit2-proxy/client/index.js +182 -0
  5. package/dist/cjs/permit2-proxy/client/index.js.map +1 -0
  6. package/dist/cjs/permit2-proxy/facilitator/index.d.ts +93 -0
  7. package/dist/cjs/permit2-proxy/facilitator/index.js +368 -0
  8. package/dist/cjs/permit2-proxy/facilitator/index.js.map +1 -0
  9. package/dist/cjs/permit2-proxy/index.d.ts +344 -0
  10. package/dist/cjs/permit2-proxy/index.js +1274 -0
  11. package/dist/cjs/permit2-proxy/index.js.map +1 -0
  12. package/dist/cjs/permit2-proxy/server/index.d.ts +130 -0
  13. package/dist/cjs/permit2-proxy/server/index.js +695 -0
  14. package/dist/cjs/permit2-proxy/server/index.js.map +1 -0
  15. package/dist/esm/chunk-A2U6NWHQ.mjs +199 -0
  16. package/dist/esm/chunk-A2U6NWHQ.mjs.map +1 -0
  17. package/dist/esm/chunk-HUUYTNV2.mjs +138 -0
  18. package/dist/esm/chunk-HUUYTNV2.mjs.map +1 -0
  19. package/dist/esm/chunk-THXENBBU.mjs +251 -0
  20. package/dist/esm/chunk-THXENBBU.mjs.map +1 -0
  21. package/dist/esm/chunk-UK2POASM.mjs +204 -0
  22. package/dist/esm/chunk-UK2POASM.mjs.map +1 -0
  23. package/dist/esm/constants-05D7IZJA.d.mts +136 -0
  24. package/dist/esm/permit2/index.d.mts +1 -137
  25. package/dist/esm/permit2-proxy/client/index.d.mts +83 -0
  26. package/dist/esm/permit2-proxy/client/index.mjs +12 -0
  27. package/dist/esm/permit2-proxy/client/index.mjs.map +1 -0
  28. package/dist/esm/permit2-proxy/facilitator/index.d.mts +93 -0
  29. package/dist/esm/permit2-proxy/facilitator/index.mjs +12 -0
  30. package/dist/esm/permit2-proxy/facilitator/index.mjs.map +1 -0
  31. package/dist/esm/permit2-proxy/index.d.mts +344 -0
  32. package/dist/esm/permit2-proxy/index.mjs +45 -0
  33. package/dist/esm/permit2-proxy/index.mjs.map +1 -0
  34. package/dist/esm/permit2-proxy/server/index.d.mts +130 -0
  35. package/dist/esm/permit2-proxy/server/index.mjs +13 -0
  36. package/dist/esm/permit2-proxy/server/index.mjs.map +1 -0
  37. package/package.json +43 -3
@@ -0,0 +1,1274 @@
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+
22
+ // src/permit2-proxy/index.ts
23
+ var permit2_proxy_exports = {};
24
+ __export(permit2_proxy_exports, {
25
+ PERMIT2_ADDRESS: () => PERMIT2_ADDRESS,
26
+ Permit2ProxyEvmClientScheme: () => Permit2ProxyEvmScheme,
27
+ Permit2ProxyEvmFacilitatorScheme: () => Permit2ProxyEvmScheme3,
28
+ Permit2ProxyEvmServerScheme: () => Permit2ProxyEvmScheme2,
29
+ SCHEME_PERMIT2_PROXY: () => SCHEME_PERMIT2_PROXY,
30
+ T402_EXACT_PERMIT2_PROXY: () => T402_EXACT_PERMIT2_PROXY,
31
+ T402_UPTO_PERMIT2_PROXY: () => T402_UPTO_PERMIT2_PROXY,
32
+ WITNESS_TYPEHASH: () => WITNESS_TYPEHASH,
33
+ WITNESS_TYPE_STRING: () => WITNESS_TYPE_STRING,
34
+ permit2ProxyExactABI: () => permit2ProxyExactABI,
35
+ permit2ProxyUptoABI: () => permit2ProxyUptoABI,
36
+ permit2WitnessTypes: () => permit2WitnessTypes,
37
+ registerPermit2ProxyEvmClientScheme: () => registerPermit2ProxyEvmScheme,
38
+ registerPermit2ProxyEvmFacilitatorScheme: () => registerPermit2ProxyEvmScheme3,
39
+ registerPermit2ProxyEvmServerScheme: () => registerPermit2ProxyEvmScheme2
40
+ });
41
+ module.exports = __toCommonJS(permit2_proxy_exports);
42
+
43
+ // src/permit2-proxy/client/scheme.ts
44
+ var import_viem = require("viem");
45
+
46
+ // src/permit2/constants.ts
47
+ var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
48
+ var erc20BalanceABI = [
49
+ {
50
+ inputs: [{ name: "account", type: "address" }],
51
+ name: "balanceOf",
52
+ outputs: [{ name: "", type: "uint256" }],
53
+ stateMutability: "view",
54
+ type: "function"
55
+ }
56
+ ];
57
+
58
+ // src/permit2-proxy/constants.ts
59
+ var SCHEME_PERMIT2_PROXY = "permit2-proxy";
60
+ var T402_EXACT_PERMIT2_PROXY = "0x0000000000000000000000000000000000000000";
61
+ var T402_UPTO_PERMIT2_PROXY = "0x0000000000000000000000000000000000000000";
62
+ var WITNESS_TYPEHASH = "0x5e3bbbe812684a9a24e1e1b7fe7c5b763bfb791ee8423aed3b4e1a5a9e25c255";
63
+ var WITNESS_TYPE_STRING = "Witness witness)TokenPermissions(address token,uint256 amount)Witness(address to,address facilitator,uint256 validAfter)";
64
+ var permit2WitnessTypes = {
65
+ PermitWitnessTransferFrom: [
66
+ { name: "permitted", type: "TokenPermissions" },
67
+ { name: "spender", type: "address" },
68
+ { name: "nonce", type: "uint256" },
69
+ { name: "deadline", type: "uint256" },
70
+ { name: "witness", type: "Witness" }
71
+ ],
72
+ TokenPermissions: [
73
+ { name: "token", type: "address" },
74
+ { name: "amount", type: "uint256" }
75
+ ],
76
+ Witness: [
77
+ { name: "to", type: "address" },
78
+ { name: "facilitator", type: "address" },
79
+ { name: "validAfter", type: "uint256" }
80
+ ]
81
+ };
82
+ var permit2ProxyExactABI = [
83
+ {
84
+ inputs: [
85
+ {
86
+ components: [
87
+ {
88
+ components: [
89
+ { name: "token", type: "address" },
90
+ { name: "amount", type: "uint256" }
91
+ ],
92
+ name: "permitted",
93
+ type: "tuple"
94
+ },
95
+ { name: "nonce", type: "uint256" },
96
+ { name: "deadline", type: "uint256" }
97
+ ],
98
+ name: "permit",
99
+ type: "tuple"
100
+ },
101
+ { name: "owner", type: "address" },
102
+ {
103
+ components: [
104
+ { name: "to", type: "address" },
105
+ { name: "facilitator", type: "address" },
106
+ { name: "validAfter", type: "uint256" }
107
+ ],
108
+ name: "witness",
109
+ type: "tuple"
110
+ },
111
+ { name: "signature", type: "bytes" }
112
+ ],
113
+ name: "settle",
114
+ outputs: [],
115
+ stateMutability: "nonpayable",
116
+ type: "function"
117
+ },
118
+ {
119
+ inputs: [
120
+ {
121
+ components: [
122
+ { name: "value", type: "uint256" },
123
+ { name: "deadline", type: "uint256" },
124
+ { name: "v", type: "uint8" },
125
+ { name: "r", type: "bytes32" },
126
+ { name: "s", type: "bytes32" }
127
+ ],
128
+ name: "permit2612",
129
+ type: "tuple"
130
+ },
131
+ {
132
+ components: [
133
+ {
134
+ components: [
135
+ { name: "token", type: "address" },
136
+ { name: "amount", type: "uint256" }
137
+ ],
138
+ name: "permitted",
139
+ type: "tuple"
140
+ },
141
+ { name: "nonce", type: "uint256" },
142
+ { name: "deadline", type: "uint256" }
143
+ ],
144
+ name: "permit",
145
+ type: "tuple"
146
+ },
147
+ { name: "owner", type: "address" },
148
+ {
149
+ components: [
150
+ { name: "to", type: "address" },
151
+ { name: "facilitator", type: "address" },
152
+ { name: "validAfter", type: "uint256" }
153
+ ],
154
+ name: "witness",
155
+ type: "tuple"
156
+ },
157
+ { name: "signature", type: "bytes" }
158
+ ],
159
+ name: "settleWithPermit",
160
+ outputs: [],
161
+ stateMutability: "nonpayable",
162
+ type: "function"
163
+ }
164
+ ];
165
+ var permit2ProxyUptoABI = [
166
+ {
167
+ inputs: [
168
+ {
169
+ components: [
170
+ {
171
+ components: [
172
+ { name: "token", type: "address" },
173
+ { name: "amount", type: "uint256" }
174
+ ],
175
+ name: "permitted",
176
+ type: "tuple"
177
+ },
178
+ { name: "nonce", type: "uint256" },
179
+ { name: "deadline", type: "uint256" }
180
+ ],
181
+ name: "permit",
182
+ type: "tuple"
183
+ },
184
+ { name: "amount", type: "uint256" },
185
+ { name: "owner", type: "address" },
186
+ {
187
+ components: [
188
+ { name: "to", type: "address" },
189
+ { name: "facilitator", type: "address" },
190
+ { name: "validAfter", type: "uint256" }
191
+ ],
192
+ name: "witness",
193
+ type: "tuple"
194
+ },
195
+ { name: "signature", type: "bytes" }
196
+ ],
197
+ name: "settle",
198
+ outputs: [],
199
+ stateMutability: "nonpayable",
200
+ type: "function"
201
+ },
202
+ {
203
+ inputs: [
204
+ {
205
+ components: [
206
+ { name: "value", type: "uint256" },
207
+ { name: "deadline", type: "uint256" },
208
+ { name: "v", type: "uint8" },
209
+ { name: "r", type: "bytes32" },
210
+ { name: "s", type: "bytes32" }
211
+ ],
212
+ name: "permit2612",
213
+ type: "tuple"
214
+ },
215
+ {
216
+ components: [
217
+ {
218
+ components: [
219
+ { name: "token", type: "address" },
220
+ { name: "amount", type: "uint256" }
221
+ ],
222
+ name: "permitted",
223
+ type: "tuple"
224
+ },
225
+ { name: "nonce", type: "uint256" },
226
+ { name: "deadline", type: "uint256" }
227
+ ],
228
+ name: "permit",
229
+ type: "tuple"
230
+ },
231
+ { name: "amount", type: "uint256" },
232
+ { name: "owner", type: "address" },
233
+ {
234
+ components: [
235
+ { name: "to", type: "address" },
236
+ { name: "facilitator", type: "address" },
237
+ { name: "validAfter", type: "uint256" }
238
+ ],
239
+ name: "witness",
240
+ type: "tuple"
241
+ },
242
+ { name: "signature", type: "bytes" }
243
+ ],
244
+ name: "settleWithPermit",
245
+ outputs: [],
246
+ stateMutability: "nonpayable",
247
+ type: "function"
248
+ }
249
+ ];
250
+
251
+ // src/permit2-proxy/client/scheme.ts
252
+ var Permit2ProxyEvmScheme = class {
253
+ /**
254
+ * Creates a new Permit2ProxyEvmScheme instance.
255
+ *
256
+ * @param signer - The EVM signer for client operations
257
+ */
258
+ constructor(signer) {
259
+ this.signer = signer;
260
+ __publicField(this, "scheme", SCHEME_PERMIT2_PROXY);
261
+ }
262
+ /**
263
+ * Creates a payment payload for the Permit2 Proxy scheme.
264
+ *
265
+ * @param t402Version - The t402 protocol version
266
+ * @param paymentRequirements - The payment requirements
267
+ * @returns Promise resolving to a payment payload
268
+ */
269
+ async createPaymentPayload(t402Version, paymentRequirements) {
270
+ const now = Math.floor(Date.now() / 1e3);
271
+ const deadline = now + paymentRequirements.maxTimeoutSeconds;
272
+ const nonce = BigInt(
273
+ "0x" + Array.from(globalThis.crypto.getRandomValues(new Uint8Array(32))).map((b) => b.toString(16).padStart(2, "0")).join("")
274
+ ).toString();
275
+ const proxyAddress = paymentRequirements.extra?.exactProxyAddress || paymentRequirements.extra?.uptoProxyAddress;
276
+ if (!proxyAddress) {
277
+ throw new Error(
278
+ "Missing proxy address in payment requirements extra (exactProxyAddress or uptoProxyAddress)"
279
+ );
280
+ }
281
+ const facilitatorAddress = paymentRequirements.extra?.facilitator;
282
+ if (!facilitatorAddress) {
283
+ throw new Error("Missing facilitator address in payment requirements extra");
284
+ }
285
+ const permit = {
286
+ permitted: {
287
+ token: (0, import_viem.getAddress)(paymentRequirements.asset),
288
+ amount: paymentRequirements.amount
289
+ },
290
+ nonce,
291
+ deadline: deadline.toString()
292
+ };
293
+ const witness = {
294
+ to: (0, import_viem.getAddress)(paymentRequirements.payTo),
295
+ facilitator: (0, import_viem.getAddress)(facilitatorAddress),
296
+ validAfter: "0"
297
+ // Immediate validity
298
+ };
299
+ const signature = await this.signPermit2Witness(
300
+ permit,
301
+ witness,
302
+ proxyAddress,
303
+ paymentRequirements
304
+ );
305
+ const payload = {
306
+ permit,
307
+ witness,
308
+ signature,
309
+ owner: this.signer.address
310
+ };
311
+ return {
312
+ t402Version,
313
+ payload
314
+ };
315
+ }
316
+ /**
317
+ * Sign the Permit2 PermitWitnessTransferFrom using EIP-712.
318
+ *
319
+ * @param permit - The permit transfer data
320
+ * @param witness - The witness data
321
+ * @param spender - The proxy contract address (spender in Permit2)
322
+ * @param requirements - The payment requirements
323
+ * @returns Signed typed data hex string
324
+ */
325
+ async signPermit2Witness(permit, witness, spender, requirements) {
326
+ const chainId = parseInt(requirements.network.split(":")[1]);
327
+ const domain = {
328
+ name: "Permit2",
329
+ chainId,
330
+ verifyingContract: PERMIT2_ADDRESS
331
+ };
332
+ const message = {
333
+ permitted: {
334
+ token: permit.permitted.token,
335
+ amount: BigInt(permit.permitted.amount)
336
+ },
337
+ spender: (0, import_viem.getAddress)(spender),
338
+ nonce: BigInt(permit.nonce),
339
+ deadline: BigInt(permit.deadline),
340
+ witness: {
341
+ to: witness.to,
342
+ facilitator: witness.facilitator,
343
+ validAfter: BigInt(witness.validAfter)
344
+ }
345
+ };
346
+ return await this.signer.signTypedData({
347
+ domain,
348
+ types: permit2WitnessTypes,
349
+ primaryType: "PermitWitnessTransferFrom",
350
+ message
351
+ });
352
+ }
353
+ };
354
+
355
+ // src/permit2-proxy/client/register.ts
356
+ function registerPermit2ProxyEvmScheme(client, config) {
357
+ if (config.networks && config.networks.length > 0) {
358
+ config.networks.forEach((network) => {
359
+ client.register(network, new Permit2ProxyEvmScheme(config.signer));
360
+ });
361
+ } else {
362
+ client.register("eip155:*", new Permit2ProxyEvmScheme(config.signer));
363
+ }
364
+ if (config.policies) {
365
+ config.policies.forEach((policy) => {
366
+ client.registerPolicy(policy);
367
+ });
368
+ }
369
+ return client;
370
+ }
371
+
372
+ // src/tokens.ts
373
+ var USDT0_ADDRESSES = {
374
+ // === Existing Networks ===
375
+ // Ethereum Mainnet - OFT Adapter (bridge endpoint)
376
+ "eip155:1": "0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee",
377
+ // Arbitrum One - Native USDT0
378
+ "eip155:42161": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
379
+ // Ink Mainnet
380
+ "eip155:57073": "0x0200C29006150606B650577BBE7B6248F58470c1",
381
+ // Berachain Mainnet
382
+ "eip155:80094": "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
383
+ // Unichain Mainnet (updated address)
384
+ "eip155:130": "0x9151434b16b9763660705744891fA906F660EcC5",
385
+ // === Phase 1: High Priority Networks ===
386
+ // Polygon PoS
387
+ "eip155:137": "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
388
+ // Mantle
389
+ "eip155:5000": "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
390
+ // Optimism
391
+ "eip155:10": "0x01bFF41798a0BcF287b996046Ca68b395DbC1071",
392
+ // Plasma
393
+ "eip155:9745": "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb",
394
+ // Sei
395
+ "eip155:1329": "0x9151434b16b9763660705744891fA906F660EcC5",
396
+ // Conflux eSpace
397
+ "eip155:1030": "0xaf37E8B6C9ED7f6318979f56Fc287d76c30847ff",
398
+ // Monad
399
+ "eip155:143": "0xe7cd86e13AC4309349F30B3435a9d337750fC82D",
400
+ // === Phase 2: Medium Priority Networks ===
401
+ // Rootstock (Bitcoin sidechain)
402
+ "eip155:30": "0x779dED0C9e1022225F8e0630b35A9B54Be713736",
403
+ // XLayer (OKX L2)
404
+ "eip155:196": "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
405
+ // Flare
406
+ "eip155:14": "0xe7cd86e13AC4309349F30B3435a9d337750fC82D",
407
+ // Corn
408
+ "eip155:21000000": "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb",
409
+ // HyperEVM
410
+ "eip155:999": "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb",
411
+ // MegaETH
412
+ "eip155:4326": "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
413
+ // Stable
414
+ "eip155:988": "0x779Ded0c9e1022225f8E0630b35a9b54bE713736"
415
+ };
416
+ var USDC_ADDRESSES = {
417
+ // Ethereum Mainnet
418
+ "eip155:1": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
419
+ // Base Mainnet
420
+ "eip155:8453": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
421
+ // Base Sepolia (testnet)
422
+ "eip155:84532": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
423
+ // Sepolia (testnet)
424
+ "eip155:11155111": "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
425
+ // Arbitrum One
426
+ "eip155:42161": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
427
+ // Polygon Mainnet
428
+ "eip155:137": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359"
429
+ };
430
+ var USAT_ADDRESSES = {
431
+ // Ethereum Mainnet
432
+ "eip155:1": "0x07041776f5007aca2a54844f50503a18a72a8b68"
433
+ };
434
+ var USDT_LEGACY_ADDRESSES = {
435
+ // Ethereum Mainnet
436
+ "eip155:1": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
437
+ // Polygon Mainnet (native USDT, not USDT0)
438
+ "eip155:137": "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
439
+ // BNB Chain (BSC) - BEP-20 USDT
440
+ "eip155:56": "0x55d398326f99059fF775485246999027B3197955",
441
+ // Avalanche C-Chain
442
+ "eip155:43114": "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
443
+ // Fantom
444
+ "eip155:250": "0x049d68029688eabf473097a2fc38ef61633a3c7a",
445
+ // Celo
446
+ "eip155:42220": "0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e",
447
+ // Kaia (formerly Klaytn)
448
+ "eip155:8217": "0xcee8faf64bb97a73bb51e115aa89c17ffa8dd167"
449
+ };
450
+ var TOKEN_REGISTRY = {
451
+ // Ethereum Mainnet
452
+ "eip155:1": {
453
+ USDT0: {
454
+ address: USDT0_ADDRESSES["eip155:1"],
455
+ symbol: "USDT0",
456
+ name: "TetherToken",
457
+ version: "1",
458
+ decimals: 6,
459
+ tokenType: "eip3009",
460
+ priority: 1
461
+ },
462
+ USDC: {
463
+ address: USDC_ADDRESSES["eip155:1"],
464
+ symbol: "USDC",
465
+ name: "USD Coin",
466
+ version: "2",
467
+ decimals: 6,
468
+ tokenType: "eip3009",
469
+ priority: 2
470
+ },
471
+ USAT: {
472
+ address: USAT_ADDRESSES["eip155:1"],
473
+ symbol: "USAT",
474
+ name: "Tether America USD",
475
+ version: "1",
476
+ decimals: 6,
477
+ tokenType: "legacy",
478
+ priority: 3
479
+ },
480
+ USDT: {
481
+ address: USDT_LEGACY_ADDRESSES["eip155:1"],
482
+ symbol: "USDT",
483
+ name: "TetherUSD",
484
+ version: "1",
485
+ decimals: 6,
486
+ tokenType: "legacy",
487
+ priority: 10
488
+ // Lower priority due to legacy flow
489
+ }
490
+ },
491
+ // Arbitrum One
492
+ "eip155:42161": {
493
+ USDT0: {
494
+ address: USDT0_ADDRESSES["eip155:42161"],
495
+ symbol: "USDT0",
496
+ name: "TetherToken",
497
+ version: "1",
498
+ decimals: 6,
499
+ tokenType: "eip3009",
500
+ priority: 1
501
+ },
502
+ USDC: {
503
+ address: USDC_ADDRESSES["eip155:42161"],
504
+ symbol: "USDC",
505
+ name: "USD Coin",
506
+ version: "2",
507
+ decimals: 6,
508
+ tokenType: "eip3009",
509
+ priority: 2
510
+ }
511
+ },
512
+ // Ink Mainnet
513
+ "eip155:57073": {
514
+ USDT0: {
515
+ address: USDT0_ADDRESSES["eip155:57073"],
516
+ symbol: "USDT0",
517
+ name: "TetherToken",
518
+ version: "1",
519
+ decimals: 6,
520
+ tokenType: "eip3009",
521
+ priority: 1
522
+ }
523
+ },
524
+ // Berachain Mainnet
525
+ "eip155:80094": {
526
+ USDT0: {
527
+ address: USDT0_ADDRESSES["eip155:80094"],
528
+ symbol: "USDT0",
529
+ name: "TetherToken",
530
+ version: "1",
531
+ decimals: 6,
532
+ tokenType: "eip3009",
533
+ priority: 1
534
+ }
535
+ },
536
+ // Unichain Mainnet
537
+ "eip155:130": {
538
+ USDT0: {
539
+ address: USDT0_ADDRESSES["eip155:130"],
540
+ symbol: "USDT0",
541
+ name: "TetherToken",
542
+ version: "1",
543
+ decimals: 6,
544
+ tokenType: "eip3009",
545
+ priority: 1
546
+ }
547
+ },
548
+ // Base Mainnet
549
+ "eip155:8453": {
550
+ USDC: {
551
+ address: USDC_ADDRESSES["eip155:8453"],
552
+ symbol: "USDC",
553
+ name: "USD Coin",
554
+ version: "2",
555
+ decimals: 6,
556
+ tokenType: "eip3009",
557
+ priority: 2
558
+ }
559
+ },
560
+ // Base Sepolia (testnet)
561
+ "eip155:84532": {
562
+ USDC: {
563
+ address: USDC_ADDRESSES["eip155:84532"],
564
+ symbol: "USDC",
565
+ name: "USDC",
566
+ version: "2",
567
+ decimals: 6,
568
+ tokenType: "eip3009",
569
+ priority: 2
570
+ }
571
+ },
572
+ // Sepolia (testnet)
573
+ "eip155:11155111": {
574
+ USDC: {
575
+ address: USDC_ADDRESSES["eip155:11155111"],
576
+ symbol: "USDC",
577
+ name: "USDC",
578
+ version: "2",
579
+ decimals: 6,
580
+ tokenType: "eip3009",
581
+ priority: 2
582
+ }
583
+ },
584
+ // Polygon Mainnet
585
+ "eip155:137": {
586
+ USDT0: {
587
+ address: USDT0_ADDRESSES["eip155:137"],
588
+ symbol: "USDT0",
589
+ name: "TetherToken",
590
+ version: "1",
591
+ decimals: 6,
592
+ tokenType: "eip3009",
593
+ priority: 1
594
+ },
595
+ USDC: {
596
+ address: USDC_ADDRESSES["eip155:137"],
597
+ symbol: "USDC",
598
+ name: "USD Coin",
599
+ version: "2",
600
+ decimals: 6,
601
+ tokenType: "eip3009",
602
+ priority: 2
603
+ },
604
+ USDT: {
605
+ address: USDT_LEGACY_ADDRESSES["eip155:137"],
606
+ symbol: "USDT",
607
+ name: "TetherUSD",
608
+ version: "1",
609
+ decimals: 6,
610
+ tokenType: "legacy",
611
+ priority: 10
612
+ }
613
+ },
614
+ // === Phase 1: High Priority USDT0 Networks ===
615
+ // Optimism Mainnet
616
+ "eip155:10": {
617
+ USDT0: {
618
+ address: USDT0_ADDRESSES["eip155:10"],
619
+ symbol: "USDT0",
620
+ name: "TetherToken",
621
+ version: "1",
622
+ decimals: 6,
623
+ tokenType: "eip3009",
624
+ priority: 1
625
+ }
626
+ },
627
+ // Mantle Mainnet
628
+ "eip155:5000": {
629
+ USDT0: {
630
+ address: USDT0_ADDRESSES["eip155:5000"],
631
+ symbol: "USDT0",
632
+ name: "TetherToken",
633
+ version: "1",
634
+ decimals: 6,
635
+ tokenType: "eip3009",
636
+ priority: 1
637
+ }
638
+ },
639
+ // Plasma Mainnet
640
+ "eip155:9745": {
641
+ USDT0: {
642
+ address: USDT0_ADDRESSES["eip155:9745"],
643
+ symbol: "USDT0",
644
+ name: "TetherToken",
645
+ version: "1",
646
+ decimals: 6,
647
+ tokenType: "eip3009",
648
+ priority: 1
649
+ }
650
+ },
651
+ // Sei Mainnet
652
+ "eip155:1329": {
653
+ USDT0: {
654
+ address: USDT0_ADDRESSES["eip155:1329"],
655
+ symbol: "USDT0",
656
+ name: "TetherToken",
657
+ version: "1",
658
+ decimals: 6,
659
+ tokenType: "eip3009",
660
+ priority: 1
661
+ }
662
+ },
663
+ // Conflux eSpace Mainnet
664
+ "eip155:1030": {
665
+ USDT0: {
666
+ address: USDT0_ADDRESSES["eip155:1030"],
667
+ symbol: "USDT0",
668
+ name: "TetherToken",
669
+ version: "1",
670
+ decimals: 6,
671
+ tokenType: "eip3009",
672
+ priority: 1
673
+ }
674
+ },
675
+ // Monad Mainnet
676
+ "eip155:143": {
677
+ USDT0: {
678
+ address: USDT0_ADDRESSES["eip155:143"],
679
+ symbol: "USDT0",
680
+ name: "TetherToken",
681
+ version: "1",
682
+ decimals: 6,
683
+ tokenType: "eip3009",
684
+ priority: 1
685
+ }
686
+ },
687
+ // === Phase 2: Medium Priority USDT0 Networks ===
688
+ // Flare Mainnet
689
+ "eip155:14": {
690
+ USDT0: {
691
+ address: USDT0_ADDRESSES["eip155:14"],
692
+ symbol: "USDT0",
693
+ name: "TetherToken",
694
+ version: "1",
695
+ decimals: 6,
696
+ tokenType: "eip3009",
697
+ priority: 1
698
+ }
699
+ },
700
+ // Rootstock Mainnet (Bitcoin sidechain)
701
+ "eip155:30": {
702
+ USDT0: {
703
+ address: USDT0_ADDRESSES["eip155:30"],
704
+ symbol: "USDT0",
705
+ name: "TetherToken",
706
+ version: "1",
707
+ decimals: 6,
708
+ tokenType: "eip3009",
709
+ priority: 1
710
+ }
711
+ },
712
+ // XLayer Mainnet (OKX L2)
713
+ "eip155:196": {
714
+ USDT0: {
715
+ address: USDT0_ADDRESSES["eip155:196"],
716
+ symbol: "USDT0",
717
+ name: "TetherToken",
718
+ version: "1",
719
+ decimals: 6,
720
+ tokenType: "eip3009",
721
+ priority: 1
722
+ }
723
+ },
724
+ // Stable Mainnet
725
+ "eip155:988": {
726
+ USDT0: {
727
+ address: USDT0_ADDRESSES["eip155:988"],
728
+ symbol: "USDT0",
729
+ name: "TetherToken",
730
+ version: "1",
731
+ decimals: 6,
732
+ tokenType: "eip3009",
733
+ priority: 1
734
+ }
735
+ },
736
+ // HyperEVM Mainnet
737
+ "eip155:999": {
738
+ USDT0: {
739
+ address: USDT0_ADDRESSES["eip155:999"],
740
+ symbol: "USDT0",
741
+ name: "TetherToken",
742
+ version: "1",
743
+ decimals: 6,
744
+ tokenType: "eip3009",
745
+ priority: 1
746
+ }
747
+ },
748
+ // MegaETH Mainnet
749
+ "eip155:4326": {
750
+ USDT0: {
751
+ address: USDT0_ADDRESSES["eip155:4326"],
752
+ symbol: "USDT0",
753
+ name: "TetherToken",
754
+ version: "1",
755
+ decimals: 6,
756
+ tokenType: "eip3009",
757
+ priority: 1
758
+ }
759
+ },
760
+ // Corn Mainnet
761
+ "eip155:21000000": {
762
+ USDT0: {
763
+ address: USDT0_ADDRESSES["eip155:21000000"],
764
+ symbol: "USDT0",
765
+ name: "TetherToken",
766
+ version: "1",
767
+ decimals: 6,
768
+ tokenType: "eip3009",
769
+ priority: 1
770
+ }
771
+ },
772
+ // === Legacy USDT Networks (no EIP-3009 support) ===
773
+ // BNB Chain (BSC) - BEP-20 USDT
774
+ "eip155:56": {
775
+ USDT: {
776
+ address: USDT_LEGACY_ADDRESSES["eip155:56"],
777
+ symbol: "USDT",
778
+ name: "Tether USD",
779
+ version: "1",
780
+ decimals: 18,
781
+ // BSC USDT uses 18 decimals
782
+ tokenType: "legacy",
783
+ priority: 10
784
+ }
785
+ },
786
+ // Avalanche C-Chain
787
+ "eip155:43114": {
788
+ USDT: {
789
+ address: USDT_LEGACY_ADDRESSES["eip155:43114"],
790
+ symbol: "USDT",
791
+ name: "TetherToken",
792
+ version: "1",
793
+ decimals: 6,
794
+ tokenType: "legacy",
795
+ priority: 10
796
+ }
797
+ },
798
+ // Fantom
799
+ "eip155:250": {
800
+ USDT: {
801
+ address: USDT_LEGACY_ADDRESSES["eip155:250"],
802
+ symbol: "USDT",
803
+ name: "Frapped USDT",
804
+ version: "1",
805
+ decimals: 6,
806
+ tokenType: "legacy",
807
+ priority: 10
808
+ }
809
+ },
810
+ // Celo
811
+ "eip155:42220": {
812
+ USDT: {
813
+ address: USDT_LEGACY_ADDRESSES["eip155:42220"],
814
+ symbol: "USDT",
815
+ name: "Tether USD",
816
+ version: "1",
817
+ decimals: 18,
818
+ tokenType: "legacy",
819
+ priority: 10
820
+ }
821
+ },
822
+ // Kaia (formerly Klaytn)
823
+ "eip155:8217": {
824
+ USDT: {
825
+ address: USDT_LEGACY_ADDRESSES["eip155:8217"],
826
+ symbol: "USDT",
827
+ name: "Tether USD",
828
+ version: "1",
829
+ decimals: 6,
830
+ tokenType: "legacy",
831
+ priority: 10
832
+ }
833
+ }
834
+ };
835
+ function getTokenConfig(network, symbol) {
836
+ return TOKEN_REGISTRY[network]?.[symbol.toUpperCase()];
837
+ }
838
+ function getNetworkTokens(network) {
839
+ const tokens = TOKEN_REGISTRY[network];
840
+ if (!tokens) return [];
841
+ return Object.values(tokens).sort((a, b) => a.priority - b.priority);
842
+ }
843
+ function getDefaultToken(network) {
844
+ const tokens = getNetworkTokens(network);
845
+ return tokens[0];
846
+ }
847
+
848
+ // src/permit2-proxy/server/scheme.ts
849
+ var Permit2ProxyEvmScheme2 = class {
850
+ /**
851
+ * Creates a new Permit2ProxyEvmScheme server instance.
852
+ *
853
+ * @param config - Server configuration options
854
+ */
855
+ constructor(config = {}) {
856
+ __publicField(this, "scheme", SCHEME_PERMIT2_PROXY);
857
+ __publicField(this, "moneyParsers", []);
858
+ __publicField(this, "config");
859
+ this.config = config;
860
+ }
861
+ /**
862
+ * Get the list of supported EVM networks.
863
+ *
864
+ * @returns Array of supported network identifiers
865
+ */
866
+ static getSupportedNetworks() {
867
+ return Object.keys(TOKEN_REGISTRY);
868
+ }
869
+ /**
870
+ * Check if a network is supported.
871
+ *
872
+ * @param network - Network identifier to check
873
+ * @returns Whether the network is supported
874
+ */
875
+ static isNetworkSupported(network) {
876
+ return network in TOKEN_REGISTRY;
877
+ }
878
+ /**
879
+ * Register a custom money parser for price conversion.
880
+ *
881
+ * @param parser - The money parser to register
882
+ * @returns This instance for chaining
883
+ */
884
+ registerMoneyParser(parser) {
885
+ this.moneyParsers.push(parser);
886
+ return this;
887
+ }
888
+ /**
889
+ * Parse a price into an AssetAmount for the given network.
890
+ *
891
+ * @param price - The price to parse
892
+ * @param network - The target network
893
+ * @returns The parsed asset amount
894
+ */
895
+ async parsePrice(price, network) {
896
+ if (typeof price === "object" && price !== null && "amount" in price) {
897
+ if (!price.asset) {
898
+ throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);
899
+ }
900
+ return {
901
+ amount: price.amount,
902
+ asset: price.asset,
903
+ extra: price.extra || {}
904
+ };
905
+ }
906
+ const amount = this.parseMoneyToDecimal(price);
907
+ for (const parser of this.moneyParsers) {
908
+ const result = await parser(amount, network);
909
+ if (result !== null) {
910
+ return result;
911
+ }
912
+ }
913
+ return this.defaultMoneyConversion(amount, network);
914
+ }
915
+ /**
916
+ * Enhance payment requirements with Permit2 Proxy-specific data.
917
+ *
918
+ * @param paymentRequirements - The base payment requirements
919
+ * @param supportedKind - The supported kind metadata
920
+ * @param supportedKind.t402Version - Protocol version
921
+ * @param supportedKind.scheme - Payment scheme
922
+ * @param supportedKind.network - Target network
923
+ * @param supportedKind.extra - Extra metadata
924
+ * @param extensionKeys - Active extension keys
925
+ * @returns Enhanced payment requirements
926
+ */
927
+ enhancePaymentRequirements(paymentRequirements, supportedKind, extensionKeys) {
928
+ void extensionKeys;
929
+ if (!paymentRequirements.extra) {
930
+ paymentRequirements.extra = {};
931
+ }
932
+ paymentRequirements.extra.permit2Address = PERMIT2_ADDRESS;
933
+ paymentRequirements.extra.exactProxyAddress = this.config.exactProxyAddress || T402_EXACT_PERMIT2_PROXY;
934
+ paymentRequirements.extra.uptoProxyAddress = this.config.uptoProxyAddress || T402_UPTO_PERMIT2_PROXY;
935
+ if (supportedKind.extra?.facilitator) {
936
+ paymentRequirements.extra.facilitator = supportedKind.extra.facilitator;
937
+ }
938
+ return Promise.resolve(paymentRequirements);
939
+ }
940
+ /**
941
+ * Parse a money value into a decimal number.
942
+ *
943
+ * @param money - The money value to parse
944
+ * @returns The decimal amount
945
+ */
946
+ parseMoneyToDecimal(money) {
947
+ if (typeof money === "number") {
948
+ if (!Number.isFinite(money)) {
949
+ throw new Error(`Invalid money value: ${money} (must be a finite number)`);
950
+ }
951
+ return money;
952
+ }
953
+ const cleanMoney = money.replace(/^\$/, "").trim();
954
+ const amount = parseFloat(cleanMoney);
955
+ if (!Number.isFinite(amount)) {
956
+ throw new Error(`Invalid money format: ${money}`);
957
+ }
958
+ return amount;
959
+ }
960
+ /**
961
+ * Convert a decimal amount to a token amount using default network token.
962
+ *
963
+ * @param amount - The decimal amount
964
+ * @param network - The target network
965
+ * @returns The asset amount with token details
966
+ */
967
+ defaultMoneyConversion(amount, network) {
968
+ const token = this.getDefaultAsset(network);
969
+ const tokenAmount = this.convertToTokenAmount(amount.toString(), token.decimals);
970
+ return {
971
+ amount: tokenAmount,
972
+ asset: token.address,
973
+ extra: {
974
+ symbol: token.symbol,
975
+ permit2Address: PERMIT2_ADDRESS
976
+ }
977
+ };
978
+ }
979
+ /**
980
+ * Convert a decimal amount string to token smallest units.
981
+ *
982
+ * @param decimalAmount - The decimal amount as a string
983
+ * @param decimals - The token's decimal places
984
+ * @returns The amount in smallest units
985
+ */
986
+ convertToTokenAmount(decimalAmount, decimals) {
987
+ if (!/^-?\d+(\.\d+)?$/.test(decimalAmount)) {
988
+ throw new Error(`Invalid amount format: ${decimalAmount}`);
989
+ }
990
+ const [wholePart, fracPart = ""] = decimalAmount.split(".");
991
+ const paddedFrac = fracPart.padEnd(decimals, "0").slice(0, decimals);
992
+ const combined = wholePart + paddedFrac;
993
+ const result = combined.replace(/^0+/, "") || "0";
994
+ return result;
995
+ }
996
+ /**
997
+ * Get the default token asset for a network.
998
+ *
999
+ * @param network - The target network
1000
+ * @returns The token configuration
1001
+ */
1002
+ getDefaultAsset(network) {
1003
+ if (this.config.preferredToken) {
1004
+ const preferred = getTokenConfig(network, this.config.preferredToken);
1005
+ if (preferred) return preferred;
1006
+ }
1007
+ const defaultToken = getDefaultToken(network);
1008
+ if (defaultToken) return defaultToken;
1009
+ throw new Error(`No tokens configured for network ${network}`);
1010
+ }
1011
+ };
1012
+
1013
+ // src/permit2-proxy/server/register.ts
1014
+ function registerPermit2ProxyEvmScheme2(server, config = {}) {
1015
+ if (config.networks && config.networks.length > 0) {
1016
+ config.networks.forEach((network) => {
1017
+ server.register(network, new Permit2ProxyEvmScheme2(config.schemeConfig));
1018
+ });
1019
+ } else {
1020
+ server.register("eip155:*", new Permit2ProxyEvmScheme2(config.schemeConfig));
1021
+ }
1022
+ return server;
1023
+ }
1024
+
1025
+ // src/permit2-proxy/facilitator/scheme.ts
1026
+ var import_viem2 = require("viem");
1027
+ var Permit2ProxyEvmScheme3 = class {
1028
+ /**
1029
+ * Creates a new Permit2 Proxy facilitator instance.
1030
+ *
1031
+ * @param signer - The facilitator EVM signer
1032
+ * @param config - Optional configuration
1033
+ */
1034
+ constructor(signer, config = {}) {
1035
+ this.signer = signer;
1036
+ __publicField(this, "scheme", SCHEME_PERMIT2_PROXY);
1037
+ __publicField(this, "caipFamily", "eip155:*");
1038
+ __publicField(this, "exactProxyAddress");
1039
+ __publicField(this, "uptoProxyAddress");
1040
+ this.exactProxyAddress = config.exactProxyAddress || T402_EXACT_PERMIT2_PROXY;
1041
+ this.uptoProxyAddress = config.uptoProxyAddress || T402_UPTO_PERMIT2_PROXY;
1042
+ }
1043
+ /**
1044
+ * Get mechanism-specific extra data for supported kinds.
1045
+ *
1046
+ * @param _ - The network identifier
1047
+ * @returns Extra data including proxy contract addresses
1048
+ */
1049
+ getExtra(_) {
1050
+ return {
1051
+ permit2Address: PERMIT2_ADDRESS,
1052
+ exactProxyAddress: this.exactProxyAddress,
1053
+ uptoProxyAddress: this.uptoProxyAddress
1054
+ };
1055
+ }
1056
+ /**
1057
+ * Get signer addresses for this facilitator.
1058
+ *
1059
+ * @param _ - The network identifier
1060
+ * @returns Array of signer addresses
1061
+ */
1062
+ getSigners(_) {
1063
+ return [...this.signer.getAddresses()];
1064
+ }
1065
+ /**
1066
+ * Verify a Permit2 Proxy payment payload.
1067
+ *
1068
+ * @param payload - The payment payload to verify
1069
+ * @param requirements - The payment requirements
1070
+ * @returns Verification result
1071
+ */
1072
+ async verify(payload, requirements) {
1073
+ const proxyPayload = payload.payload;
1074
+ if (!proxyPayload?.permit?.permitted?.token || !proxyPayload?.owner || !proxyPayload?.witness) {
1075
+ return {
1076
+ isValid: false,
1077
+ invalidReason: "invalid_payload_structure",
1078
+ payer: void 0
1079
+ };
1080
+ }
1081
+ if (payload.accepted.scheme !== SCHEME_PERMIT2_PROXY || requirements.scheme !== SCHEME_PERMIT2_PROXY) {
1082
+ return {
1083
+ isValid: false,
1084
+ invalidReason: "unsupported_scheme",
1085
+ payer: proxyPayload.owner
1086
+ };
1087
+ }
1088
+ if (payload.accepted.network !== requirements.network) {
1089
+ return {
1090
+ isValid: false,
1091
+ invalidReason: "network_mismatch",
1092
+ payer: proxyPayload.owner
1093
+ };
1094
+ }
1095
+ if ((0, import_viem2.getAddress)(proxyPayload.permit.permitted.token) !== (0, import_viem2.getAddress)(requirements.asset)) {
1096
+ return {
1097
+ isValid: false,
1098
+ invalidReason: "token_mismatch",
1099
+ payer: proxyPayload.owner
1100
+ };
1101
+ }
1102
+ if ((0, import_viem2.getAddress)(proxyPayload.witness.to) !== (0, import_viem2.getAddress)(requirements.payTo)) {
1103
+ return {
1104
+ isValid: false,
1105
+ invalidReason: "recipient_mismatch",
1106
+ payer: proxyPayload.owner
1107
+ };
1108
+ }
1109
+ const signerAddresses = this.signer.getAddresses().map((a) => (0, import_viem2.getAddress)(a));
1110
+ if (!signerAddresses.includes((0, import_viem2.getAddress)(proxyPayload.witness.facilitator))) {
1111
+ return {
1112
+ isValid: false,
1113
+ invalidReason: "facilitator_mismatch",
1114
+ payer: proxyPayload.owner
1115
+ };
1116
+ }
1117
+ const now = Math.floor(Date.now() / 1e3);
1118
+ if (BigInt(proxyPayload.permit.deadline) < BigInt(now + 6)) {
1119
+ return {
1120
+ isValid: false,
1121
+ invalidReason: "permit_expired",
1122
+ payer: proxyPayload.owner
1123
+ };
1124
+ }
1125
+ if (BigInt(proxyPayload.witness.validAfter) > BigInt(now)) {
1126
+ return {
1127
+ isValid: false,
1128
+ invalidReason: "payment_too_early",
1129
+ payer: proxyPayload.owner
1130
+ };
1131
+ }
1132
+ if (BigInt(proxyPayload.permit.permitted.amount) < BigInt(requirements.amount)) {
1133
+ return {
1134
+ isValid: false,
1135
+ invalidReason: "insufficient_permitted_amount",
1136
+ payer: proxyPayload.owner
1137
+ };
1138
+ }
1139
+ try {
1140
+ const balance = await this.signer.readContract({
1141
+ address: (0, import_viem2.getAddress)(requirements.asset),
1142
+ abi: erc20BalanceABI,
1143
+ functionName: "balanceOf",
1144
+ args: [(0, import_viem2.getAddress)(proxyPayload.owner)]
1145
+ });
1146
+ if (BigInt(balance) < BigInt(requirements.amount)) {
1147
+ return {
1148
+ isValid: false,
1149
+ invalidReason: "insufficient_funds",
1150
+ payer: proxyPayload.owner
1151
+ };
1152
+ }
1153
+ } catch (error) {
1154
+ const errorMessage = error instanceof Error ? error.message : String(error);
1155
+ return {
1156
+ isValid: false,
1157
+ invalidReason: `balance_check_failed: ${errorMessage}`,
1158
+ payer: proxyPayload.owner
1159
+ };
1160
+ }
1161
+ return {
1162
+ isValid: true,
1163
+ invalidReason: void 0,
1164
+ payer: proxyPayload.owner
1165
+ };
1166
+ }
1167
+ /**
1168
+ * Settle a Permit2 Proxy payment by calling settle() on the proxy contract.
1169
+ *
1170
+ * @param payload - The payment payload
1171
+ * @param requirements - The payment requirements
1172
+ * @returns Settlement result
1173
+ */
1174
+ async settle(payload, requirements) {
1175
+ const proxyPayload = payload.payload;
1176
+ if (!proxyPayload?.permit?.permitted?.token || !proxyPayload?.owner || !proxyPayload?.witness) {
1177
+ return {
1178
+ success: false,
1179
+ network: payload.accepted.network,
1180
+ transaction: "",
1181
+ errorReason: "invalid_payload_structure",
1182
+ payer: void 0
1183
+ };
1184
+ }
1185
+ const valid = await this.verify(payload, requirements);
1186
+ if (!valid.isValid) {
1187
+ return {
1188
+ success: false,
1189
+ network: payload.accepted.network,
1190
+ transaction: "",
1191
+ errorReason: valid.invalidReason ?? "invalid_scheme",
1192
+ payer: proxyPayload.owner
1193
+ };
1194
+ }
1195
+ try {
1196
+ const proxyAddress = requirements.extra?.exactProxyAddress || this.exactProxyAddress;
1197
+ const tx = await this.signer.writeContract({
1198
+ address: proxyAddress,
1199
+ abi: permit2ProxyExactABI,
1200
+ functionName: "settle",
1201
+ args: [
1202
+ {
1203
+ permitted: {
1204
+ token: (0, import_viem2.getAddress)(proxyPayload.permit.permitted.token),
1205
+ amount: BigInt(proxyPayload.permit.permitted.amount)
1206
+ },
1207
+ nonce: BigInt(proxyPayload.permit.nonce),
1208
+ deadline: BigInt(proxyPayload.permit.deadline)
1209
+ },
1210
+ (0, import_viem2.getAddress)(proxyPayload.owner),
1211
+ {
1212
+ to: (0, import_viem2.getAddress)(proxyPayload.witness.to),
1213
+ facilitator: (0, import_viem2.getAddress)(proxyPayload.witness.facilitator),
1214
+ validAfter: BigInt(proxyPayload.witness.validAfter)
1215
+ },
1216
+ proxyPayload.signature
1217
+ ]
1218
+ });
1219
+ const receipt = await this.signer.waitForTransactionReceipt({ hash: tx });
1220
+ if (receipt.status !== "success") {
1221
+ return {
1222
+ success: false,
1223
+ errorReason: "invalid_transaction_state",
1224
+ transaction: tx,
1225
+ network: payload.accepted.network,
1226
+ payer: proxyPayload.owner
1227
+ };
1228
+ }
1229
+ return {
1230
+ success: true,
1231
+ transaction: tx,
1232
+ network: payload.accepted.network,
1233
+ payer: proxyPayload.owner
1234
+ };
1235
+ } catch (error) {
1236
+ console.error("Failed to settle Permit2 Proxy transaction:", error);
1237
+ return {
1238
+ success: false,
1239
+ errorReason: "transaction_failed",
1240
+ transaction: "",
1241
+ network: payload.accepted.network,
1242
+ payer: proxyPayload.owner
1243
+ };
1244
+ }
1245
+ }
1246
+ };
1247
+
1248
+ // src/permit2-proxy/facilitator/register.ts
1249
+ function registerPermit2ProxyEvmScheme3(facilitator, config) {
1250
+ facilitator.register(
1251
+ config.networks,
1252
+ new Permit2ProxyEvmScheme3(config.signer, config.schemeConfig)
1253
+ );
1254
+ return facilitator;
1255
+ }
1256
+ // Annotate the CommonJS export names for ESM import in node:
1257
+ 0 && (module.exports = {
1258
+ PERMIT2_ADDRESS,
1259
+ Permit2ProxyEvmClientScheme,
1260
+ Permit2ProxyEvmFacilitatorScheme,
1261
+ Permit2ProxyEvmServerScheme,
1262
+ SCHEME_PERMIT2_PROXY,
1263
+ T402_EXACT_PERMIT2_PROXY,
1264
+ T402_UPTO_PERMIT2_PROXY,
1265
+ WITNESS_TYPEHASH,
1266
+ WITNESS_TYPE_STRING,
1267
+ permit2ProxyExactABI,
1268
+ permit2ProxyUptoABI,
1269
+ permit2WitnessTypes,
1270
+ registerPermit2ProxyEvmClientScheme,
1271
+ registerPermit2ProxyEvmFacilitatorScheme,
1272
+ registerPermit2ProxyEvmServerScheme
1273
+ });
1274
+ //# sourceMappingURL=index.js.map