@1llet.xyz/erc4337-gasless-sdk 0.4.27 → 0.4.29

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/index.d.mts CHANGED
@@ -342,10 +342,9 @@ interface BridgeStrategy {
342
342
  execute(context: BridgeContext): Promise<SettleResponse>;
343
343
  }
344
344
 
345
- declare class BridgeManager {
345
+ declare class TransferManager {
346
346
  private strategies;
347
347
  constructor();
348
- private getStrategy;
349
348
  execute(context: BridgeContext): Promise<SettleResponse>;
350
349
  }
351
350
 
@@ -361,16 +360,4 @@ declare class CCTPStrategy implements BridgeStrategy {
361
360
  execute(context: BridgeContext): Promise<SettleResponse>;
362
361
  }
363
362
 
364
- declare class GaslessStrategy implements BridgeStrategy {
365
- name: string;
366
- canHandle(context: BridgeContext): boolean;
367
- execute(context: BridgeContext): Promise<SettleResponse>;
368
- }
369
-
370
- declare class StandardBridgeStrategy implements BridgeStrategy {
371
- name: string;
372
- canHandle(context: BridgeContext): boolean;
373
- execute(context: BridgeContext): Promise<SettleResponse>;
374
- }
375
-
376
- export { AccountAbstraction, type ApprovalSupportResult, BASE_MAINNET, BASE_SEPOLIA, BridgeManager, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, type ChainConfig, GNOSIS_MAINNET, type GasEstimate, GaslessStrategy, NearStrategy, OPTIMISM_MAINNET, StandardBridgeStrategy, type Token, type UserOpReceipt, type UserOperation, entryPointAbi, erc20Abi, smartAccountAbi };
363
+ export { AccountAbstraction, type ApprovalSupportResult, BASE_MAINNET, BASE_SEPOLIA, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, type ChainConfig, GNOSIS_MAINNET, type GasEstimate, NearStrategy, OPTIMISM_MAINNET, type Token, TransferManager, type UserOpReceipt, type UserOperation, entryPointAbi, erc20Abi, smartAccountAbi };
package/dist/index.d.ts CHANGED
@@ -342,10 +342,9 @@ interface BridgeStrategy {
342
342
  execute(context: BridgeContext): Promise<SettleResponse>;
343
343
  }
344
344
 
345
- declare class BridgeManager {
345
+ declare class TransferManager {
346
346
  private strategies;
347
347
  constructor();
348
- private getStrategy;
349
348
  execute(context: BridgeContext): Promise<SettleResponse>;
350
349
  }
351
350
 
@@ -361,16 +360,4 @@ declare class CCTPStrategy implements BridgeStrategy {
361
360
  execute(context: BridgeContext): Promise<SettleResponse>;
362
361
  }
363
362
 
364
- declare class GaslessStrategy implements BridgeStrategy {
365
- name: string;
366
- canHandle(context: BridgeContext): boolean;
367
- execute(context: BridgeContext): Promise<SettleResponse>;
368
- }
369
-
370
- declare class StandardBridgeStrategy implements BridgeStrategy {
371
- name: string;
372
- canHandle(context: BridgeContext): boolean;
373
- execute(context: BridgeContext): Promise<SettleResponse>;
374
- }
375
-
376
- export { AccountAbstraction, type ApprovalSupportResult, BASE_MAINNET, BASE_SEPOLIA, BridgeManager, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, type ChainConfig, GNOSIS_MAINNET, type GasEstimate, GaslessStrategy, NearStrategy, OPTIMISM_MAINNET, StandardBridgeStrategy, type Token, type UserOpReceipt, type UserOperation, entryPointAbi, erc20Abi, smartAccountAbi };
363
+ export { AccountAbstraction, type ApprovalSupportResult, BASE_MAINNET, BASE_SEPOLIA, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, type ChainConfig, GNOSIS_MAINNET, type GasEstimate, NearStrategy, OPTIMISM_MAINNET, type Token, TransferManager, type UserOpReceipt, type UserOperation, entryPointAbi, erc20Abi, smartAccountAbi };
package/dist/index.js CHANGED
@@ -916,7 +916,7 @@ var CHAIN_ID_TO_KEY = {
916
916
  "42161": "Arbitrum"
917
917
  };
918
918
 
919
- // src/services/gasless.ts
919
+ // src/services/cctp.ts
920
920
  init_facilitator();
921
921
  init_facilitator();
922
922
 
@@ -1011,120 +1011,6 @@ var messageTransmitterAbi = [
1011
1011
  type: "function"
1012
1012
  }
1013
1013
  ];
1014
-
1015
- // src/services/gasless.ts
1016
- var GaslessStrategy = class {
1017
- constructor() {
1018
- this.name = "Gasless";
1019
- }
1020
- canHandle(context) {
1021
- const { sourceChain, destChain, sourceToken, destToken } = context;
1022
- return sourceChain === destChain && (sourceToken === destToken || !destToken);
1023
- }
1024
- async execute(context) {
1025
- const { paymentPayload, sourceChain, amount, recipient } = context;
1026
- if (!paymentPayload) {
1027
- return { success: false, errorReason: "Payment payload is required for Gasless Strategy" };
1028
- }
1029
- return processGaslessSettlement(
1030
- paymentPayload,
1031
- sourceChain,
1032
- amount,
1033
- context.facilitatorPrivateKey,
1034
- recipient
1035
- );
1036
- }
1037
- };
1038
- async function processGaslessSettlement(paymentPayload, sourceChain, amount, facilitatorPrivateKey, recipient) {
1039
- if (!facilitatorPrivateKey) {
1040
- return {
1041
- success: false,
1042
- errorReason: "Facilitator Private Key not provided in context"
1043
- };
1044
- }
1045
- const networkConfig = FACILITATOR_NETWORKS[sourceChain];
1046
- if (!networkConfig) {
1047
- return {
1048
- success: false,
1049
- errorReason: `Unsupported chain: ${sourceChain}`
1050
- };
1051
- }
1052
- const { authorization, signature } = paymentPayload;
1053
- if (!signature) {
1054
- return {
1055
- success: false,
1056
- errorReason: "Missing Signature in Payment Payload"
1057
- };
1058
- }
1059
- const publicClient = viem.createPublicClient({
1060
- chain: networkConfig.chain,
1061
- transport: viem.http(networkConfig.rpcUrl)
1062
- });
1063
- const walletClient = viem.createWalletClient({
1064
- account: accounts.privateKeyToAccount(facilitatorPrivateKey),
1065
- chain: networkConfig.chain,
1066
- transport: viem.http(networkConfig.rpcUrl)
1067
- });
1068
- const { v, r, s } = viem.parseSignature(signature);
1069
- let transferHash;
1070
- try {
1071
- transferHash = await walletClient.writeContract({
1072
- chain: networkConfig.chain,
1073
- address: networkConfig.usdc,
1074
- abi: usdcErc3009Abi,
1075
- functionName: "transferWithAuthorization",
1076
- args: [
1077
- authorization.from,
1078
- authorization.to,
1079
- BigInt(authorization.value),
1080
- BigInt(authorization.validAfter),
1081
- BigInt(authorization.validBefore),
1082
- authorization.nonce,
1083
- Number(v),
1084
- r,
1085
- s
1086
- ]
1087
- });
1088
- const receipt = await publicClient.waitForTransactionReceipt({ hash: transferHash });
1089
- if (receipt.status !== "success") throw new Error("TransferWithAuthorization failed");
1090
- } catch (e) {
1091
- return {
1092
- success: false,
1093
- errorReason: e instanceof Error ? e.message : "Transfer failed"
1094
- };
1095
- }
1096
- const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
1097
- const fee = calculateFee();
1098
- try {
1099
- const finalTransferHash = await walletClient.writeContract({
1100
- chain: networkConfig.chain,
1101
- address: networkConfig.usdc,
1102
- abi: usdcErc3009Abi,
1103
- functionName: "transfer",
1104
- args: [recipient, amountBigInt - fee]
1105
- // Deduct Fee (0.01 or 0)
1106
- });
1107
- await publicClient.waitForTransactionReceipt({ hash: finalTransferHash });
1108
- } catch (e) {
1109
- console.error("Final transfer failed", e);
1110
- return {
1111
- success: false,
1112
- transactionHash: transferHash,
1113
- errorReason: "Final transfer to recipient failed. Funds are with facilitator."
1114
- };
1115
- }
1116
- return {
1117
- success: true,
1118
- transactionHash: transferHash,
1119
- payer: authorization.from,
1120
- fee: fee.toString(),
1121
- netAmount: amountBigInt.toString()
1122
- };
1123
- }
1124
-
1125
- // src/services/cctp.ts
1126
- init_facilitator();
1127
- init_facilitator();
1128
1014
  var createRetrieveAttestation = async (transactionHash, chainId, timeout = 6e4) => {
1129
1015
  const baseUrl = "https://iris-api.circle.com";
1130
1016
  const url = `${baseUrl}/v2/messages/${chainId}?transactionHash=${transactionHash}`;
@@ -2100,15 +1986,15 @@ var NearStrategy = class {
2100
1986
  const { sourceChain, destChain, amount, recipient, destToken, sourceToken, senderAddress, depositTxHash } = context;
2101
1987
  if (depositTxHash) {
2102
1988
  console.log(`[NearStrategy] Verifying deposit hash: ${depositTxHash}`);
2103
- const { createPublicClient: createPublicClient4, http: http4 } = await import('viem');
1989
+ const { createPublicClient: createPublicClient3, http: http3 } = await import('viem');
2104
1990
  const { FACILITATOR_NETWORKS: FACILITATOR_NETWORKS2 } = await Promise.resolve().then(() => (init_facilitator(), facilitator_exports));
2105
1991
  const networkConfig = FACILITATOR_NETWORKS2[sourceChain];
2106
1992
  if (!networkConfig) {
2107
1993
  return { success: false, errorReason: `Unsupported source chain for verification: ${sourceChain}` };
2108
1994
  }
2109
- const publicClient = createPublicClient4({
1995
+ const publicClient = createPublicClient3({
2110
1996
  chain: networkConfig.chain,
2111
- transport: http4(networkConfig.rpcUrl)
1997
+ transport: http3(networkConfig.rpcUrl)
2112
1998
  });
2113
1999
  try {
2114
2000
  console.log(`[NearStrategy] Waiting for receipt...`);
@@ -2148,14 +2034,7 @@ var NearStrategy = class {
2148
2034
  return {
2149
2035
  success: true,
2150
2036
  transactionHash: "PENDING_USER_DEPOSIT",
2151
- // Placeholder or null
2152
2037
  netAmount: quoteResult.amountAtomicNet,
2153
- // Or formatted
2154
- // We might need to extend SettleResponse to include explicit instruction
2155
- // For now, we reuse the existing type.
2156
- // In a real scenario, we'd add `depositAddress` to the response type.
2157
- // Assuming SettleResponse is flexible or we console log it for the user context.
2158
- // To be safe and useful:
2159
2038
  data: {
2160
2039
  depositAddress: quoteResult.depositAddress,
2161
2040
  amountToDeposit: quoteResult.amountAtomicNet,
@@ -2228,61 +2107,42 @@ async function getNearQuote(sourceChain, destChain, amount, destToken, sourceTok
2228
2107
  };
2229
2108
  }
2230
2109
 
2231
- // src/services/standard.ts
2232
- var StandardBridgeStrategy = class {
2233
- constructor() {
2234
- this.name = "StandardBridge";
2235
- }
2236
- canHandle(context) {
2237
- const { paymentPayload } = context;
2238
- return paymentPayload?.type === "STANDARD";
2239
- }
2240
- async execute(context) {
2241
- return {
2242
- success: false,
2243
- errorReason: "Standard Bridge Strategy is deprecated. Please use Near Intents or CCTP."
2244
- };
2245
- }
2246
- };
2247
-
2248
- // src/services/BridgeManager.ts
2249
- var BridgeManager = class {
2110
+ // src/services/TransferManager.ts
2111
+ var TransferManager = class {
2250
2112
  constructor() {
2251
2113
  this.strategies = [
2252
- new StandardBridgeStrategy(),
2253
- new GaslessStrategy(),
2254
2114
  new CCTPStrategy(),
2255
2115
  new NearStrategy()
2256
2116
  ];
2257
2117
  }
2258
- getStrategy(context) {
2259
- return this.strategies.find((strategy) => strategy.canHandle(context));
2260
- }
2261
2118
  async execute(context) {
2262
2119
  if (context.sourceChain === context.destChain && context.sourceToken === context.destToken) {
2263
- console.log(`[BridgeManager] Same Chain detected. Strategy: Gasless`);
2264
- const gaslessStrategy2 = new GaslessStrategy();
2265
- return gaslessStrategy2.execute(context);
2120
+ console.log(`[TransferManager] Same Chain detected. Signal Direct Transfer.`);
2121
+ return {
2122
+ success: true,
2123
+ transactionHash: "DIRECT_TRANSFER_REQUIRED",
2124
+ data: {
2125
+ action: "DIRECT_TRANSFER",
2126
+ amount: context.amount,
2127
+ token: context.sourceToken,
2128
+ recipient: context.recipient
2129
+ }
2130
+ };
2266
2131
  }
2267
2132
  const strategies = this.strategies;
2268
2133
  const cctpStrategy = strategies.find((s) => s instanceof CCTPStrategy);
2269
2134
  if (cctpStrategy && cctpStrategy.canHandle(context)) {
2270
- console.log(`[BridgeManager] Routing to: ${cctpStrategy.name} (CCTP)`);
2135
+ console.log(`[TransferManager] Routing to: ${cctpStrategy.name} (CCTP)`);
2271
2136
  return cctpStrategy.execute(context);
2272
2137
  }
2273
2138
  const nearStrategy = strategies.find((s) => s instanceof NearStrategy);
2274
2139
  if (nearStrategy && nearStrategy.canHandle(context)) {
2275
- console.log(`[BridgeManager] Routing to: ${nearStrategy.name} (Near)`);
2140
+ console.log(`[TransferManager] Routing to: ${nearStrategy.name} (Near)`);
2276
2141
  return nearStrategy.execute(context);
2277
2142
  }
2278
- const gaslessStrategy = strategies.find((s) => s instanceof GaslessStrategy);
2279
- if (gaslessStrategy && gaslessStrategy.canHandle(context)) {
2280
- console.log(`[BridgeManager] Routing to: ${gaslessStrategy.name}`);
2281
- return gaslessStrategy.execute(context);
2282
- }
2283
2143
  return {
2284
2144
  success: false,
2285
- errorReason: `No suitable bridge strategy found for ${context.sourceChain} -> ${context.destChain}`
2145
+ errorReason: `No suitable transfer strategy found for ${context.sourceChain} -> ${context.destChain}`
2286
2146
  };
2287
2147
  }
2288
2148
  };
@@ -2290,16 +2150,14 @@ var BridgeManager = class {
2290
2150
  exports.AccountAbstraction = AccountAbstraction;
2291
2151
  exports.BASE_MAINNET = BASE_MAINNET;
2292
2152
  exports.BASE_SEPOLIA = BASE_SEPOLIA;
2293
- exports.BridgeManager = BridgeManager;
2294
2153
  exports.BundlerClient = BundlerClient;
2295
2154
  exports.CCTPStrategy = CCTPStrategy;
2296
2155
  exports.CHAIN_CONFIGS = CHAIN_CONFIGS;
2297
2156
  exports.CHAIN_ID_TO_KEY = CHAIN_ID_TO_KEY;
2298
2157
  exports.GNOSIS_MAINNET = GNOSIS_MAINNET;
2299
- exports.GaslessStrategy = GaslessStrategy;
2300
2158
  exports.NearStrategy = NearStrategy;
2301
2159
  exports.OPTIMISM_MAINNET = OPTIMISM_MAINNET;
2302
- exports.StandardBridgeStrategy = StandardBridgeStrategy;
2160
+ exports.TransferManager = TransferManager;
2303
2161
  exports.entryPointAbi = entryPointAbi;
2304
2162
  exports.erc20Abi = erc20Abi;
2305
2163
  exports.smartAccountAbi = smartAccountAbi;