@t402/evm 2.2.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.
- package/dist/cjs/exact/client/index.d.ts +2 -2
- package/dist/cjs/exact/client/index.js +4 -2
- package/dist/cjs/exact/client/index.js.map +1 -1
- package/dist/cjs/exact/facilitator/index.d.ts +1 -1
- package/dist/cjs/exact/facilitator/index.js +40 -4
- package/dist/cjs/exact/facilitator/index.js.map +1 -1
- package/dist/cjs/exact/server/index.d.ts +1 -1
- package/dist/cjs/exact/server/index.js +301 -33
- package/dist/cjs/exact/server/index.js.map +1 -1
- package/dist/cjs/exact/v1/client/index.d.ts +1 -1
- package/dist/cjs/exact/v1/client/index.js +3 -1
- package/dist/cjs/exact/v1/client/index.js.map +1 -1
- package/dist/cjs/exact/v1/facilitator/index.d.ts +1 -1
- package/dist/cjs/exact/v1/facilitator/index.js +21 -2
- package/dist/cjs/exact/v1/facilitator/index.js.map +1 -1
- package/dist/cjs/index.d.ts +606 -352
- package/dist/cjs/index.js +1436 -268
- package/dist/cjs/index.js.map +1 -1
- package/dist/{esm/scheme-yqGaK9rK.d.mts → cjs/scheme-B4rXSKCN.d.ts} +18 -16
- package/dist/cjs/scheme-CIar5W2B.d.ts +200 -0
- package/dist/cjs/{scheme-OojTBKAz.d.ts → scheme-CjijeY7y.d.ts} +1 -1
- package/dist/{esm/signer-BkcAzwYi.d.mts → cjs/signer-DcavxxZt.d.ts} +1 -18
- package/dist/cjs/upto/client/index.d.ts +61 -0
- package/dist/cjs/upto/client/index.js +154 -0
- package/dist/cjs/upto/client/index.js.map +1 -0
- package/dist/cjs/upto/index.d.ts +111 -0
- package/dist/cjs/upto/index.js +1030 -0
- package/dist/cjs/upto/index.js.map +1 -0
- package/dist/cjs/v1/index.d.ts +1 -1
- package/dist/cjs/v1/index.js +3 -1
- package/dist/cjs/v1/index.js.map +1 -1
- package/dist/esm/{chunk-ACDQ5QNT.mjs → chunk-4FBTQTNM.mjs} +27 -5
- package/dist/esm/chunk-4FBTQTNM.mjs.map +1 -0
- package/dist/esm/chunk-IWSDEZKI.mjs +477 -0
- package/dist/esm/chunk-IWSDEZKI.mjs.map +1 -0
- package/dist/esm/{chunk-LGSG73NJ.mjs → chunk-LM5RZBVP.mjs} +9 -4
- package/dist/esm/{chunk-LGSG73NJ.mjs.map → chunk-LM5RZBVP.mjs.map} +1 -1
- package/dist/esm/chunk-NSSMTXJJ.mjs +8 -0
- package/dist/esm/chunk-NSSMTXJJ.mjs.map +1 -0
- package/dist/esm/chunk-SJ52GTJJ.mjs +411 -0
- package/dist/esm/chunk-SJ52GTJJ.mjs.map +1 -0
- package/dist/esm/chunk-SURTCHSX.mjs +129 -0
- package/dist/esm/chunk-SURTCHSX.mjs.map +1 -0
- package/dist/esm/chunk-SYVPLXYV.mjs +26 -0
- package/dist/esm/chunk-SYVPLXYV.mjs.map +1 -0
- package/dist/esm/{chunk-XYKAO6KJ.mjs → chunk-Y4U7Q543.mjs} +2 -25
- package/dist/esm/chunk-Y4U7Q543.mjs.map +1 -0
- package/dist/esm/{chunk-JBWWBRYY.mjs → chunk-ZWEYARER.mjs} +9 -4
- package/dist/esm/{chunk-JBWWBRYY.mjs.map → chunk-ZWEYARER.mjs.map} +1 -1
- package/dist/esm/exact/client/index.d.mts +2 -2
- package/dist/esm/exact/client/index.mjs +6 -4
- package/dist/esm/exact/client/index.mjs.map +1 -1
- package/dist/esm/exact/facilitator/index.d.mts +1 -1
- package/dist/esm/exact/facilitator/index.mjs +26 -5
- package/dist/esm/exact/facilitator/index.mjs.map +1 -1
- package/dist/esm/exact/server/index.d.mts +1 -1
- package/dist/esm/exact/server/index.mjs +29 -30
- package/dist/esm/exact/server/index.mjs.map +1 -1
- package/dist/esm/exact/v1/client/index.d.mts +1 -1
- package/dist/esm/exact/v1/client/index.mjs +4 -2
- package/dist/esm/exact/v1/facilitator/index.d.mts +1 -1
- package/dist/esm/exact/v1/facilitator/index.mjs +4 -2
- package/dist/esm/index.d.mts +606 -352
- package/dist/esm/index.mjs +626 -138
- package/dist/esm/index.mjs.map +1 -1
- package/dist/{cjs/scheme-yqGaK9rK.d.ts → esm/scheme-B4rXSKCN.d.mts} +18 -16
- package/dist/esm/scheme-DATfd6oM.d.mts +200 -0
- package/dist/esm/{scheme-D4mOqq9l.d.mts → scheme-Ddb0dG_F.d.mts} +1 -1
- package/dist/{cjs/signer-BkcAzwYi.d.ts → esm/signer-DcavxxZt.d.mts} +1 -18
- package/dist/esm/upto/client/index.d.mts +61 -0
- package/dist/esm/upto/client/index.mjs +11 -0
- package/dist/esm/upto/client/index.mjs.map +1 -0
- package/dist/esm/upto/index.d.mts +111 -0
- package/dist/esm/upto/index.mjs +26 -0
- package/dist/esm/upto/index.mjs.map +1 -0
- package/dist/esm/v1/index.d.mts +1 -1
- package/dist/esm/v1/index.mjs +5 -3
- package/package.json +30 -6
- package/dist/cjs/scheme-C6uD7PdY.d.ts +0 -130
- package/dist/esm/chunk-ACDQ5QNT.mjs.map +0 -1
- package/dist/esm/chunk-OEXW2OK2.mjs +0 -251
- package/dist/esm/chunk-OEXW2OK2.mjs.map +0 -1
- package/dist/esm/chunk-XYKAO6KJ.mjs.map +0 -1
package/dist/esm/index.mjs
CHANGED
|
@@ -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-
|
|
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
|
-
|
|
11
|
-
|
|
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-
|
|
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
|
|
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
|
|
114
|
-
this
|
|
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
|
|
255
|
-
this
|
|
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,17 +542,6 @@ 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
|
-
}
|
|
496
|
-
|
|
497
545
|
// src/bridge/client.ts
|
|
498
546
|
import { keccak256, toBytes } from "viem";
|
|
499
547
|
|
|
@@ -669,9 +717,7 @@ function supportsBridging(chain) {
|
|
|
669
717
|
return chain in USDT0_OFT_ADDRESSES && chain in LAYERZERO_ENDPOINT_IDS;
|
|
670
718
|
}
|
|
671
719
|
function getBridgeableChains() {
|
|
672
|
-
return Object.keys(USDT0_OFT_ADDRESSES).filter(
|
|
673
|
-
(chain) => chain in LAYERZERO_ENDPOINT_IDS
|
|
674
|
-
);
|
|
720
|
+
return Object.keys(USDT0_OFT_ADDRESSES).filter((chain) => chain in LAYERZERO_ENDPOINT_IDS);
|
|
675
721
|
}
|
|
676
722
|
function addressToBytes32(address) {
|
|
677
723
|
const cleanAddress = address.slice(2).toLowerCase();
|
|
@@ -682,9 +728,7 @@ function bytes32ToAddress(bytes32) {
|
|
|
682
728
|
}
|
|
683
729
|
|
|
684
730
|
// src/bridge/client.ts
|
|
685
|
-
var OFT_SENT_EVENT_TOPIC = keccak256(
|
|
686
|
-
toBytes("OFTSent(bytes32,uint32,address,uint256,uint256)")
|
|
687
|
-
);
|
|
731
|
+
var OFT_SENT_EVENT_TOPIC = keccak256(toBytes("OFTSent(bytes32,uint32,address,uint256,uint256)"));
|
|
688
732
|
var DEFAULT_SLIPPAGE = 0.5;
|
|
689
733
|
var ESTIMATED_BRIDGE_TIME = 300;
|
|
690
734
|
var Usdt0Bridge = class {
|
|
@@ -695,6 +739,8 @@ var Usdt0Bridge = class {
|
|
|
695
739
|
* @param chain - Source chain name (e.g., "arbitrum", "ethereum")
|
|
696
740
|
*/
|
|
697
741
|
constructor(signer, chain) {
|
|
742
|
+
__publicField(this, "signer");
|
|
743
|
+
__publicField(this, "chain");
|
|
698
744
|
if (!supportsBridging(chain)) {
|
|
699
745
|
throw new Error(
|
|
700
746
|
`Chain "${chain}" does not support USDT0 bridging. Supported chains: ${getBridgeableChains().join(", ")}`
|
|
@@ -768,6 +814,23 @@ var Usdt0Bridge = class {
|
|
|
768
814
|
estimatedTime: ESTIMATED_BRIDGE_TIME
|
|
769
815
|
};
|
|
770
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
|
+
}
|
|
771
834
|
/**
|
|
772
835
|
* Extract LayerZero message GUID from OFTSent event logs
|
|
773
836
|
*
|
|
@@ -786,6 +849,9 @@ var Usdt0Bridge = class {
|
|
|
786
849
|
}
|
|
787
850
|
/**
|
|
788
851
|
* Ensure sufficient token allowance for the OFT contract
|
|
852
|
+
*
|
|
853
|
+
* @param oftAddress - The OFT contract address
|
|
854
|
+
* @param amount - The amount to approve
|
|
789
855
|
*/
|
|
790
856
|
async ensureAllowance(oftAddress, amount) {
|
|
791
857
|
const allowance = await this.signer.readContract({
|
|
@@ -806,6 +872,9 @@ var Usdt0Bridge = class {
|
|
|
806
872
|
}
|
|
807
873
|
/**
|
|
808
874
|
* Build SendParam struct for LayerZero
|
|
875
|
+
*
|
|
876
|
+
* @param params - Bridge parameters
|
|
877
|
+
* @returns SendParam struct for the OFT contract
|
|
809
878
|
*/
|
|
810
879
|
buildSendParam(params) {
|
|
811
880
|
const dstEid = getEndpointId(params.toChain);
|
|
@@ -826,6 +895,8 @@ var Usdt0Bridge = class {
|
|
|
826
895
|
}
|
|
827
896
|
/**
|
|
828
897
|
* Validate bridge parameters
|
|
898
|
+
*
|
|
899
|
+
* @param params - Bridge parameters to validate
|
|
829
900
|
*/
|
|
830
901
|
validateBridgeParams(params) {
|
|
831
902
|
if (params.fromChain !== this.chain) {
|
|
@@ -846,21 +917,301 @@ var Usdt0Bridge = class {
|
|
|
846
917
|
throw new Error("Amount must be greater than 0");
|
|
847
918
|
}
|
|
848
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 {
|
|
930
|
+
/**
|
|
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
|
+
}
|
|
849
939
|
/**
|
|
850
|
-
* Get
|
|
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
|
|
851
1187
|
*/
|
|
852
1188
|
getSupportedDestinations() {
|
|
853
|
-
return
|
|
1189
|
+
return this.bridge.getSupportedDestinations();
|
|
854
1190
|
}
|
|
855
1191
|
/**
|
|
856
|
-
*
|
|
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
|
|
857
1196
|
*/
|
|
858
|
-
|
|
859
|
-
|
|
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
|
+
}
|
|
860
1211
|
}
|
|
861
1212
|
};
|
|
862
|
-
function
|
|
863
|
-
return new
|
|
1213
|
+
function createCrossChainPaymentRouter(signer, sourceChain) {
|
|
1214
|
+
return new CrossChainPaymentRouter(signer, sourceChain);
|
|
864
1215
|
}
|
|
865
1216
|
|
|
866
1217
|
// src/erc4337/constants.ts
|
|
@@ -1040,23 +1391,33 @@ function unpackGasFees(packed) {
|
|
|
1040
1391
|
// src/erc4337/builder.ts
|
|
1041
1392
|
import { concat, pad, toHex } from "viem";
|
|
1042
1393
|
var UserOpBuilder = class {
|
|
1394
|
+
/**
|
|
1395
|
+
* Create a new UserOpBuilder instance
|
|
1396
|
+
*
|
|
1397
|
+
* @param options - Optional configuration for the builder
|
|
1398
|
+
*/
|
|
1043
1399
|
constructor(options = {}) {
|
|
1400
|
+
__publicField(this, "entryPoint");
|
|
1401
|
+
__publicField(this, "gasMultiplier");
|
|
1044
1402
|
this.entryPoint = options.entryPoint ?? ENTRYPOINT_V07_ADDRESS;
|
|
1045
1403
|
this.gasMultiplier = options.gasMultiplier ?? 1.2;
|
|
1046
1404
|
}
|
|
1047
1405
|
/**
|
|
1048
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
|
|
1049
1414
|
*/
|
|
1050
1415
|
async buildUserOp(signer, intent, client, gasEstimate, paymaster) {
|
|
1051
1416
|
const sender = await signer.getAddress();
|
|
1052
1417
|
const nonce = await this.getNonce(client, sender);
|
|
1053
1418
|
const isDeployed = await signer.isDeployed();
|
|
1054
1419
|
const initCode = isDeployed ? "0x" : await signer.getInitCode();
|
|
1055
|
-
const callData = signer.encodeExecute(
|
|
1056
|
-
intent.to,
|
|
1057
|
-
intent.value ?? 0n,
|
|
1058
|
-
intent.data ?? "0x"
|
|
1059
|
-
);
|
|
1420
|
+
const callData = signer.encodeExecute(intent.to, intent.value ?? 0n, intent.data ?? "0x");
|
|
1060
1421
|
const { maxFeePerGas, maxPriorityFeePerGas } = await this.getGasPrices(client);
|
|
1061
1422
|
const gas = gasEstimate ?? DEFAULT_GAS_LIMITS;
|
|
1062
1423
|
const verificationGasLimit = this.applyMultiplier(gas.verificationGasLimit);
|
|
@@ -1080,6 +1441,13 @@ var UserOpBuilder = class {
|
|
|
1080
1441
|
}
|
|
1081
1442
|
/**
|
|
1082
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
|
|
1083
1451
|
*/
|
|
1084
1452
|
async buildBatchUserOp(signer, intents, client, gasEstimate, paymaster) {
|
|
1085
1453
|
const sender = await signer.getAddress();
|
|
@@ -1116,6 +1484,9 @@ var UserOpBuilder = class {
|
|
|
1116
1484
|
}
|
|
1117
1485
|
/**
|
|
1118
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
|
|
1119
1490
|
*/
|
|
1120
1491
|
packUserOp(userOp) {
|
|
1121
1492
|
return {
|
|
@@ -1123,10 +1494,7 @@ var UserOpBuilder = class {
|
|
|
1123
1494
|
nonce: userOp.nonce,
|
|
1124
1495
|
initCode: userOp.initCode,
|
|
1125
1496
|
callData: userOp.callData,
|
|
1126
|
-
accountGasLimits: packAccountGasLimits(
|
|
1127
|
-
userOp.verificationGasLimit,
|
|
1128
|
-
userOp.callGasLimit
|
|
1129
|
-
),
|
|
1497
|
+
accountGasLimits: packAccountGasLimits(userOp.verificationGasLimit, userOp.callGasLimit),
|
|
1130
1498
|
preVerificationGas: userOp.preVerificationGas,
|
|
1131
1499
|
gasFees: packGasFees(userOp.maxPriorityFeePerGas, userOp.maxFeePerGas),
|
|
1132
1500
|
paymasterAndData: userOp.paymasterAndData,
|
|
@@ -1135,8 +1503,13 @@ var UserOpBuilder = class {
|
|
|
1135
1503
|
}
|
|
1136
1504
|
/**
|
|
1137
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
|
|
1138
1511
|
*/
|
|
1139
|
-
async getUserOpHash(userOp, client,
|
|
1512
|
+
async getUserOpHash(userOp, client, _) {
|
|
1140
1513
|
const packed = this.packUserOp(userOp);
|
|
1141
1514
|
const userOpTuple = {
|
|
1142
1515
|
sender: packed.sender,
|
|
@@ -1159,6 +1532,12 @@ var UserOpBuilder = class {
|
|
|
1159
1532
|
}
|
|
1160
1533
|
/**
|
|
1161
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
|
|
1162
1541
|
*/
|
|
1163
1542
|
async signUserOp(userOp, signer, client, chainId) {
|
|
1164
1543
|
const userOpHash = await this.getUserOpHash(userOp, client, chainId);
|
|
@@ -1170,6 +1549,10 @@ var UserOpBuilder = class {
|
|
|
1170
1549
|
}
|
|
1171
1550
|
/**
|
|
1172
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
|
|
1173
1556
|
*/
|
|
1174
1557
|
async getNonce(client, sender) {
|
|
1175
1558
|
try {
|
|
@@ -1187,6 +1570,9 @@ var UserOpBuilder = class {
|
|
|
1187
1570
|
}
|
|
1188
1571
|
/**
|
|
1189
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
|
|
1190
1576
|
*/
|
|
1191
1577
|
async getGasPrices(client) {
|
|
1192
1578
|
const block = await client.getBlock({ blockTag: "latest" });
|
|
@@ -1197,12 +1583,18 @@ var UserOpBuilder = class {
|
|
|
1197
1583
|
}
|
|
1198
1584
|
/**
|
|
1199
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
|
|
1200
1589
|
*/
|
|
1201
1590
|
applyMultiplier(gas) {
|
|
1202
1591
|
return BigInt(Math.ceil(Number(gas) * this.gasMultiplier));
|
|
1203
1592
|
}
|
|
1204
1593
|
/**
|
|
1205
1594
|
* Encode paymaster data for the UserOperation
|
|
1595
|
+
*
|
|
1596
|
+
* @param paymaster - The paymaster configuration
|
|
1597
|
+
* @returns The encoded paymaster data
|
|
1206
1598
|
*/
|
|
1207
1599
|
encodePaymasterData(paymaster) {
|
|
1208
1600
|
const paymasterAddress = paymaster.paymaster;
|
|
@@ -1210,12 +1602,7 @@ var UserOpBuilder = class {
|
|
|
1210
1602
|
size: 16
|
|
1211
1603
|
});
|
|
1212
1604
|
const postOpGas = pad(toHex(paymaster.paymasterPostOpGasLimit), { size: 16 });
|
|
1213
|
-
return concat([
|
|
1214
|
-
paymasterAddress,
|
|
1215
|
-
verificationGas,
|
|
1216
|
-
postOpGas,
|
|
1217
|
-
paymaster.paymasterData
|
|
1218
|
-
]);
|
|
1605
|
+
return concat([paymasterAddress, verificationGas, postOpGas, paymaster.paymasterData]);
|
|
1219
1606
|
}
|
|
1220
1607
|
};
|
|
1221
1608
|
function createUserOpBuilder(options) {
|
|
@@ -1224,6 +1611,13 @@ function createUserOpBuilder(options) {
|
|
|
1224
1611
|
|
|
1225
1612
|
// src/erc4337/bundler.ts
|
|
1226
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
|
+
*/
|
|
1227
1621
|
constructor(message, code, data) {
|
|
1228
1622
|
super(message);
|
|
1229
1623
|
this.code = code;
|
|
@@ -1232,21 +1626,31 @@ var BundlerError = class extends Error {
|
|
|
1232
1626
|
}
|
|
1233
1627
|
};
|
|
1234
1628
|
var BundlerClient = class {
|
|
1629
|
+
/**
|
|
1630
|
+
* Create a new BundlerClient instance
|
|
1631
|
+
*
|
|
1632
|
+
* @param config - Configuration for the bundler client
|
|
1633
|
+
*/
|
|
1235
1634
|
constructor(config) {
|
|
1236
|
-
this
|
|
1635
|
+
__publicField(this, "bundlerUrl");
|
|
1636
|
+
__publicField(this, "entryPoint");
|
|
1637
|
+
__publicField(this, "requestId", 0);
|
|
1237
1638
|
this.bundlerUrl = config.bundlerUrl;
|
|
1238
1639
|
this.entryPoint = config.entryPoint ?? ENTRYPOINT_V07_ADDRESS;
|
|
1239
|
-
|
|
1640
|
+
void config.chainId;
|
|
1240
1641
|
}
|
|
1241
1642
|
/**
|
|
1242
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
|
|
1243
1647
|
*/
|
|
1244
1648
|
async sendUserOperation(userOp) {
|
|
1245
1649
|
const packed = this.packForRpc(userOp);
|
|
1246
|
-
const userOpHash = await this.rpcCall(
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
);
|
|
1650
|
+
const userOpHash = await this.rpcCall(BUNDLER_METHODS.sendUserOperation, [
|
|
1651
|
+
packed,
|
|
1652
|
+
this.entryPoint
|
|
1653
|
+
]);
|
|
1250
1654
|
return {
|
|
1251
1655
|
userOpHash,
|
|
1252
1656
|
wait: () => this.waitForReceipt(userOpHash)
|
|
@@ -1254,6 +1658,9 @@ var BundlerClient = class {
|
|
|
1254
1658
|
}
|
|
1255
1659
|
/**
|
|
1256
1660
|
* Estimate gas for a UserOperation
|
|
1661
|
+
*
|
|
1662
|
+
* @param userOp - Partial UserOperation with required sender and callData
|
|
1663
|
+
* @returns Gas estimates for the UserOperation
|
|
1257
1664
|
*/
|
|
1258
1665
|
async estimateUserOperationGas(userOp) {
|
|
1259
1666
|
const estimationOp = {
|
|
@@ -1282,6 +1689,9 @@ var BundlerClient = class {
|
|
|
1282
1689
|
}
|
|
1283
1690
|
/**
|
|
1284
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
|
|
1285
1695
|
*/
|
|
1286
1696
|
async getUserOperationByHash(userOpHash) {
|
|
1287
1697
|
const result = await this.rpcCall(BUNDLER_METHODS.getUserOperationByHash, [userOpHash]);
|
|
@@ -1289,6 +1699,9 @@ var BundlerClient = class {
|
|
|
1289
1699
|
}
|
|
1290
1700
|
/**
|
|
1291
1701
|
* Get UserOperation receipt
|
|
1702
|
+
*
|
|
1703
|
+
* @param userOpHash - The hash of the UserOperation
|
|
1704
|
+
* @returns The receipt, or null if not yet included
|
|
1292
1705
|
*/
|
|
1293
1706
|
async getUserOperationReceipt(userOpHash) {
|
|
1294
1707
|
const result = await this.rpcCall(BUNDLER_METHODS.getUserOperationReceipt, [userOpHash]);
|
|
@@ -1311,12 +1724,16 @@ var BundlerClient = class {
|
|
|
1311
1724
|
}
|
|
1312
1725
|
/**
|
|
1313
1726
|
* Get supported EntryPoints
|
|
1727
|
+
*
|
|
1728
|
+
* @returns Array of supported EntryPoint addresses
|
|
1314
1729
|
*/
|
|
1315
1730
|
async getSupportedEntryPoints() {
|
|
1316
1731
|
return this.rpcCall(BUNDLER_METHODS.supportedEntryPoints, []);
|
|
1317
1732
|
}
|
|
1318
1733
|
/**
|
|
1319
1734
|
* Get chain ID from bundler
|
|
1735
|
+
*
|
|
1736
|
+
* @returns The chain ID
|
|
1320
1737
|
*/
|
|
1321
1738
|
async getChainId() {
|
|
1322
1739
|
const result = await this.rpcCall(BUNDLER_METHODS.chainId, []);
|
|
@@ -1324,6 +1741,12 @@ var BundlerClient = class {
|
|
|
1324
1741
|
}
|
|
1325
1742
|
/**
|
|
1326
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
|
|
1327
1750
|
*/
|
|
1328
1751
|
async waitForReceipt(userOpHash, options = {}) {
|
|
1329
1752
|
const timeout = options.timeout ?? 6e4;
|
|
@@ -1336,12 +1759,13 @@ var BundlerClient = class {
|
|
|
1336
1759
|
}
|
|
1337
1760
|
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
1338
1761
|
}
|
|
1339
|
-
throw new BundlerError(
|
|
1340
|
-
`Timeout waiting for UserOperation receipt: ${userOpHash}`
|
|
1341
|
-
);
|
|
1762
|
+
throw new BundlerError(`Timeout waiting for UserOperation receipt: ${userOpHash}`);
|
|
1342
1763
|
}
|
|
1343
1764
|
/**
|
|
1344
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
|
|
1345
1769
|
*/
|
|
1346
1770
|
packForRpc(userOp) {
|
|
1347
1771
|
return {
|
|
@@ -1349,10 +1773,7 @@ var BundlerClient = class {
|
|
|
1349
1773
|
nonce: this.toHex(userOp.nonce),
|
|
1350
1774
|
initCode: userOp.initCode,
|
|
1351
1775
|
callData: userOp.callData,
|
|
1352
|
-
accountGasLimits: packAccountGasLimits(
|
|
1353
|
-
userOp.verificationGasLimit,
|
|
1354
|
-
userOp.callGasLimit
|
|
1355
|
-
),
|
|
1776
|
+
accountGasLimits: packAccountGasLimits(userOp.verificationGasLimit, userOp.callGasLimit),
|
|
1356
1777
|
preVerificationGas: this.toHex(userOp.preVerificationGas),
|
|
1357
1778
|
gasFees: packGasFees(userOp.maxPriorityFeePerGas, userOp.maxFeePerGas),
|
|
1358
1779
|
paymasterAndData: userOp.paymasterAndData,
|
|
@@ -1361,12 +1782,19 @@ var BundlerClient = class {
|
|
|
1361
1782
|
}
|
|
1362
1783
|
/**
|
|
1363
1784
|
* Convert bigint to hex string
|
|
1785
|
+
*
|
|
1786
|
+
* @param value - The bigint value to convert
|
|
1787
|
+
* @returns The hex string representation
|
|
1364
1788
|
*/
|
|
1365
1789
|
toHex(value) {
|
|
1366
1790
|
return `0x${value.toString(16)}`;
|
|
1367
1791
|
}
|
|
1368
1792
|
/**
|
|
1369
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
|
|
1370
1798
|
*/
|
|
1371
1799
|
async rpcCall(method, params) {
|
|
1372
1800
|
const request = {
|
|
@@ -1383,9 +1811,7 @@ var BundlerClient = class {
|
|
|
1383
1811
|
body: JSON.stringify(request)
|
|
1384
1812
|
});
|
|
1385
1813
|
if (!response.ok) {
|
|
1386
|
-
throw new BundlerError(
|
|
1387
|
-
`HTTP error: ${response.status} ${response.statusText}`
|
|
1388
|
-
);
|
|
1814
|
+
throw new BundlerError(`HTTP error: ${response.status} ${response.statusText}`);
|
|
1389
1815
|
}
|
|
1390
1816
|
const json = await response.json();
|
|
1391
1817
|
if (json.error) {
|
|
@@ -1401,23 +1827,30 @@ function createBundlerClient(config) {
|
|
|
1401
1827
|
// src/erc4337/paymaster.ts
|
|
1402
1828
|
import { concat as concat2, pad as pad2, toHex as toHex2 } from "viem";
|
|
1403
1829
|
var PaymasterClient = class {
|
|
1830
|
+
/**
|
|
1831
|
+
* Creates a new PaymasterClient instance
|
|
1832
|
+
*
|
|
1833
|
+
* @param config - Paymaster configuration including type, address, and optional URL
|
|
1834
|
+
*/
|
|
1404
1835
|
constructor(config) {
|
|
1836
|
+
__publicField(this, "config");
|
|
1405
1837
|
this.config = config;
|
|
1406
1838
|
}
|
|
1407
1839
|
/**
|
|
1408
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
|
|
1409
1847
|
*/
|
|
1410
1848
|
async getPaymasterData(userOp, chainId, entryPoint, context) {
|
|
1411
1849
|
switch (this.config.type) {
|
|
1412
1850
|
case "verifying":
|
|
1413
1851
|
return this.getVerifyingPaymasterData(userOp, chainId, entryPoint);
|
|
1414
1852
|
case "sponsoring":
|
|
1415
|
-
return this.getSponsoringPaymasterData(
|
|
1416
|
-
userOp,
|
|
1417
|
-
chainId,
|
|
1418
|
-
entryPoint,
|
|
1419
|
-
context
|
|
1420
|
-
);
|
|
1853
|
+
return this.getSponsoringPaymasterData(userOp, chainId, entryPoint, context);
|
|
1421
1854
|
case "token":
|
|
1422
1855
|
return this.getTokenPaymasterData(userOp, chainId, entryPoint);
|
|
1423
1856
|
default:
|
|
@@ -1426,8 +1859,12 @@ var PaymasterClient = class {
|
|
|
1426
1859
|
}
|
|
1427
1860
|
/**
|
|
1428
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
|
|
1429
1866
|
*/
|
|
1430
|
-
async estimatePaymasterGas(
|
|
1867
|
+
async estimatePaymasterGas(_userOp, _chainId) {
|
|
1431
1868
|
return {
|
|
1432
1869
|
verificationGasLimit: DEFAULT_GAS_LIMITS.verificationGasLimit,
|
|
1433
1870
|
callGasLimit: DEFAULT_GAS_LIMITS.callGasLimit,
|
|
@@ -1438,6 +1875,12 @@ var PaymasterClient = class {
|
|
|
1438
1875
|
}
|
|
1439
1876
|
/**
|
|
1440
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
|
|
1441
1884
|
*/
|
|
1442
1885
|
async willSponsor(userOp, chainId, entryPoint, context) {
|
|
1443
1886
|
if (!this.config.url) {
|
|
@@ -1463,6 +1906,11 @@ var PaymasterClient = class {
|
|
|
1463
1906
|
}
|
|
1464
1907
|
/**
|
|
1465
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
|
|
1466
1914
|
*/
|
|
1467
1915
|
async getVerifyingPaymasterData(userOp, chainId, entryPoint) {
|
|
1468
1916
|
if (this.config.url) {
|
|
@@ -1477,6 +1925,12 @@ var PaymasterClient = class {
|
|
|
1477
1925
|
}
|
|
1478
1926
|
/**
|
|
1479
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
|
|
1480
1934
|
*/
|
|
1481
1935
|
async getSponsoringPaymasterData(userOp, chainId, entryPoint, context) {
|
|
1482
1936
|
if (!this.config.url) {
|
|
@@ -1506,6 +1960,11 @@ var PaymasterClient = class {
|
|
|
1506
1960
|
}
|
|
1507
1961
|
/**
|
|
1508
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
|
|
1509
1968
|
*/
|
|
1510
1969
|
async getTokenPaymasterData(userOp, chainId, entryPoint) {
|
|
1511
1970
|
const tokenAddress = this.config.options?.tokenAddress;
|
|
@@ -1527,6 +1986,12 @@ var PaymasterClient = class {
|
|
|
1527
1986
|
}
|
|
1528
1987
|
/**
|
|
1529
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
|
|
1530
1995
|
*/
|
|
1531
1996
|
async callPaymasterService(userOp, chainId, entryPoint, context) {
|
|
1532
1997
|
if (!this.config.url) {
|
|
@@ -1556,12 +2021,14 @@ var PaymasterClient = class {
|
|
|
1556
2021
|
}
|
|
1557
2022
|
/**
|
|
1558
2023
|
* Serialize UserOperation for API calls
|
|
2024
|
+
*
|
|
2025
|
+
* @param userOp - Partial UserOperation to serialize
|
|
2026
|
+
* @returns Serialized UserOperation with hex-encoded values
|
|
1559
2027
|
*/
|
|
1560
2028
|
serializeUserOp(userOp) {
|
|
1561
2029
|
const result = {};
|
|
1562
2030
|
if (userOp.sender) result.sender = userOp.sender;
|
|
1563
|
-
if (userOp.nonce !== void 0)
|
|
1564
|
-
result.nonce = `0x${userOp.nonce.toString(16)}`;
|
|
2031
|
+
if (userOp.nonce !== void 0) result.nonce = `0x${userOp.nonce.toString(16)}`;
|
|
1565
2032
|
if (userOp.initCode) result.initCode = userOp.initCode;
|
|
1566
2033
|
if (userOp.callData) result.callData = userOp.callData;
|
|
1567
2034
|
if (userOp.verificationGasLimit !== void 0)
|
|
@@ -1595,9 +2062,7 @@ function decodePaymasterAndData(paymasterAndData) {
|
|
|
1595
2062
|
return null;
|
|
1596
2063
|
}
|
|
1597
2064
|
const paymaster = `0x${paymasterAndData.slice(2, 42)}`;
|
|
1598
|
-
const paymasterVerificationGasLimit = BigInt(
|
|
1599
|
-
`0x${paymasterAndData.slice(42, 74)}`
|
|
1600
|
-
);
|
|
2065
|
+
const paymasterVerificationGasLimit = BigInt(`0x${paymasterAndData.slice(42, 74)}`);
|
|
1601
2066
|
const paymasterPostOpGasLimit = BigInt(`0x${paymasterAndData.slice(74, 106)}`);
|
|
1602
2067
|
const paymasterData = `0x${paymasterAndData.slice(106)}`;
|
|
1603
2068
|
return {
|
|
@@ -1613,16 +2078,16 @@ import { concat as concat3, pad as pad3, toHex as toHex3 } from "viem";
|
|
|
1613
2078
|
|
|
1614
2079
|
// src/erc4337/accounts/safe.ts
|
|
1615
2080
|
import {
|
|
1616
|
-
encodeFunctionData
|
|
1617
|
-
encodeAbiParameters
|
|
2081
|
+
encodeFunctionData,
|
|
2082
|
+
encodeAbiParameters,
|
|
1618
2083
|
concat as concat4,
|
|
1619
|
-
keccak256 as
|
|
2084
|
+
keccak256 as keccak2562,
|
|
1620
2085
|
getContractAddress,
|
|
1621
2086
|
hexToBytes
|
|
1622
2087
|
} from "viem";
|
|
1623
2088
|
|
|
1624
2089
|
// src/erc4337/t402.ts
|
|
1625
|
-
import { encodeFunctionData as
|
|
2090
|
+
import { encodeFunctionData as encodeFunctionData2 } from "viem";
|
|
1626
2091
|
var ERC20_TRANSFER_ABI = [
|
|
1627
2092
|
{
|
|
1628
2093
|
inputs: [
|
|
@@ -1655,7 +2120,18 @@ var EIP3009_TRANSFER_ABI = [
|
|
|
1655
2120
|
}
|
|
1656
2121
|
];
|
|
1657
2122
|
var GaslessT402Client = class {
|
|
2123
|
+
/**
|
|
2124
|
+
* Creates a new GaslessT402Client instance
|
|
2125
|
+
*
|
|
2126
|
+
* @param config - Configuration including signer, bundler, paymaster, and chain settings
|
|
2127
|
+
*/
|
|
1658
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");
|
|
1659
2135
|
this.signer = config.signer;
|
|
1660
2136
|
this.builder = new UserOpBuilder();
|
|
1661
2137
|
this.bundler = new BundlerClient(config.bundler);
|
|
@@ -1669,6 +2145,9 @@ var GaslessT402Client = class {
|
|
|
1669
2145
|
* This submits the payment as a UserOperation which can be:
|
|
1670
2146
|
* - Sponsored by a paymaster (truly gasless)
|
|
1671
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
|
|
1672
2151
|
*/
|
|
1673
2152
|
async executePayment(params) {
|
|
1674
2153
|
const callData = params.authorization ? this.buildAuthorizedTransferCallData(params) : this.buildTransferCallData(params);
|
|
@@ -1696,6 +2175,9 @@ var GaslessT402Client = class {
|
|
|
1696
2175
|
}
|
|
1697
2176
|
/**
|
|
1698
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
|
|
1699
2181
|
*/
|
|
1700
2182
|
async executeBatchPayments(payments) {
|
|
1701
2183
|
const intents = payments.map((params) => ({
|
|
@@ -1722,6 +2204,9 @@ var GaslessT402Client = class {
|
|
|
1722
2204
|
}
|
|
1723
2205
|
/**
|
|
1724
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
|
|
1725
2210
|
*/
|
|
1726
2211
|
async canSponsor(params) {
|
|
1727
2212
|
if (!this.paymaster) return false;
|
|
@@ -1739,21 +2224,28 @@ var GaslessT402Client = class {
|
|
|
1739
2224
|
}
|
|
1740
2225
|
/**
|
|
1741
2226
|
* Get the smart account address
|
|
2227
|
+
*
|
|
2228
|
+
* @returns The address of the smart account
|
|
1742
2229
|
*/
|
|
1743
2230
|
async getAccountAddress() {
|
|
1744
2231
|
return this.signer.getAddress();
|
|
1745
2232
|
}
|
|
1746
2233
|
/**
|
|
1747
2234
|
* Check if the smart account is deployed
|
|
2235
|
+
*
|
|
2236
|
+
* @returns True if the smart account contract is deployed on-chain
|
|
1748
2237
|
*/
|
|
1749
2238
|
async isAccountDeployed() {
|
|
1750
2239
|
return this.signer.isDeployed();
|
|
1751
2240
|
}
|
|
1752
2241
|
/**
|
|
1753
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
|
|
1754
2246
|
*/
|
|
1755
2247
|
buildTransferCallData(params) {
|
|
1756
|
-
return
|
|
2248
|
+
return encodeFunctionData2({
|
|
1757
2249
|
abi: ERC20_TRANSFER_ABI,
|
|
1758
2250
|
functionName: "transfer",
|
|
1759
2251
|
args: [params.to, params.amount]
|
|
@@ -1761,6 +2253,9 @@ var GaslessT402Client = class {
|
|
|
1761
2253
|
}
|
|
1762
2254
|
/**
|
|
1763
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
|
|
1764
2259
|
*/
|
|
1765
2260
|
buildAuthorizedTransferCallData(params) {
|
|
1766
2261
|
if (!params.authorization) {
|
|
@@ -1770,7 +2265,7 @@ var GaslessT402Client = class {
|
|
|
1770
2265
|
const r = `0x${sig.slice(2, 66)}`;
|
|
1771
2266
|
const s = `0x${sig.slice(66, 130)}`;
|
|
1772
2267
|
const v = parseInt(sig.slice(130, 132), 16);
|
|
1773
|
-
return
|
|
2268
|
+
return encodeFunctionData2({
|
|
1774
2269
|
abi: EIP3009_TRANSFER_ABI,
|
|
1775
2270
|
functionName: "transferWithAuthorization",
|
|
1776
2271
|
args: [
|
|
@@ -1789,14 +2284,13 @@ var GaslessT402Client = class {
|
|
|
1789
2284
|
}
|
|
1790
2285
|
/**
|
|
1791
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
|
|
1792
2290
|
*/
|
|
1793
2291
|
async estimateGas(intent) {
|
|
1794
2292
|
const sender = await this.signer.getAddress();
|
|
1795
|
-
const callData = this.signer.encodeExecute(
|
|
1796
|
-
intent.to,
|
|
1797
|
-
intent.value ?? 0n,
|
|
1798
|
-
intent.data ?? "0x"
|
|
1799
|
-
);
|
|
2293
|
+
const callData = this.signer.encodeExecute(intent.to, intent.value ?? 0n, intent.data ?? "0x");
|
|
1800
2294
|
try {
|
|
1801
2295
|
return await this.bundler.estimateUserOperationGas({
|
|
1802
2296
|
sender,
|
|
@@ -1812,6 +2306,9 @@ var GaslessT402Client = class {
|
|
|
1812
2306
|
}
|
|
1813
2307
|
/**
|
|
1814
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
|
|
1815
2312
|
*/
|
|
1816
2313
|
async estimateBatchGas(intents) {
|
|
1817
2314
|
const sender = await this.signer.getAddress();
|
|
@@ -1835,15 +2332,14 @@ var GaslessT402Client = class {
|
|
|
1835
2332
|
}
|
|
1836
2333
|
/**
|
|
1837
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
|
|
1838
2338
|
*/
|
|
1839
|
-
async getPaymasterData(
|
|
2339
|
+
async getPaymasterData(_) {
|
|
1840
2340
|
if (!this.paymaster) return void 0;
|
|
1841
2341
|
const sender = await this.signer.getAddress();
|
|
1842
|
-
return this.paymaster.getPaymasterData(
|
|
1843
|
-
{ sender },
|
|
1844
|
-
this.chainId,
|
|
1845
|
-
ENTRYPOINT_V07_ADDRESS
|
|
1846
|
-
);
|
|
2342
|
+
return this.paymaster.getPaymasterData({ sender }, this.chainId, ENTRYPOINT_V07_ADDRESS);
|
|
1847
2343
|
}
|
|
1848
2344
|
};
|
|
1849
2345
|
function createGaslessT402Client(config) {
|
|
@@ -1854,6 +2350,7 @@ export {
|
|
|
1854
2350
|
BUNDLER_METHODS,
|
|
1855
2351
|
BundlerClient,
|
|
1856
2352
|
BundlerError,
|
|
2353
|
+
CrossChainPaymentRouter,
|
|
1857
2354
|
DEFAULT_GAS_LIMITS,
|
|
1858
2355
|
ENTRYPOINT_V06_ADDRESS,
|
|
1859
2356
|
ENTRYPOINT_V07_ABI,
|
|
@@ -1865,45 +2362,36 @@ export {
|
|
|
1865
2362
|
GaslessT402Client,
|
|
1866
2363
|
LAYERZERO_ENDPOINT_IDS,
|
|
1867
2364
|
LAYERZERO_ENDPOINT_V2,
|
|
2365
|
+
LAYERZERO_SCAN_BASE_URL,
|
|
2366
|
+
LayerZeroScanClient,
|
|
1868
2367
|
PaymasterClient,
|
|
1869
2368
|
PaymasterType,
|
|
1870
|
-
TOKEN_PRIORITY,
|
|
1871
|
-
TOKEN_REGISTRY,
|
|
1872
|
-
USDC_ADDRESSES,
|
|
1873
|
-
USDT0_ADDRESSES,
|
|
1874
2369
|
USDT0_OFT_ADDRESSES,
|
|
1875
|
-
|
|
2370
|
+
UptoEvmFacilitatorScheme,
|
|
2371
|
+
UptoEvmScheme,
|
|
2372
|
+
UptoEvmServerScheme,
|
|
1876
2373
|
Usdt0Bridge,
|
|
1877
2374
|
UserOpBuilder,
|
|
1878
2375
|
addressToBytes32,
|
|
1879
|
-
authorizationTypes,
|
|
1880
2376
|
bytes32ToAddress,
|
|
1881
2377
|
createBundlerClient,
|
|
2378
|
+
createCrossChainPaymentRouter,
|
|
1882
2379
|
createGaslessT402Client,
|
|
2380
|
+
createLayerZeroScanClient,
|
|
1883
2381
|
createPaymasterClient,
|
|
2382
|
+
createUptoEvmFacilitatorScheme,
|
|
2383
|
+
createUptoEvmScheme,
|
|
2384
|
+
createUptoEvmServerScheme,
|
|
1884
2385
|
createUsdt0Bridge,
|
|
1885
2386
|
createUserOpBuilder,
|
|
1886
2387
|
decodePaymasterAndData,
|
|
1887
|
-
eip3009ABI,
|
|
1888
2388
|
encodePaymasterAndData,
|
|
1889
|
-
erc20LegacyABI,
|
|
1890
2389
|
getBridgeableChains,
|
|
1891
|
-
getDefaultToken,
|
|
1892
|
-
getEIP712Domain,
|
|
1893
2390
|
getEndpointId,
|
|
1894
|
-
getNetworkTokens,
|
|
1895
|
-
getNetworksForToken,
|
|
1896
|
-
getTokenByAddress,
|
|
1897
|
-
getTokenConfig,
|
|
1898
|
-
getUsdt0Networks,
|
|
1899
2391
|
getUsdt0OftAddress,
|
|
1900
|
-
legacyAuthorizationTypes,
|
|
1901
2392
|
packAccountGasLimits,
|
|
1902
2393
|
packGasFees,
|
|
1903
2394
|
supportsBridging,
|
|
1904
|
-
supportsEIP3009,
|
|
1905
|
-
toClientEvmSigner,
|
|
1906
|
-
toFacilitatorEvmSigner,
|
|
1907
2395
|
unpackAccountGasLimits,
|
|
1908
2396
|
unpackGasFees
|
|
1909
2397
|
};
|