@1llet.xyz/erc4337-gasless-sdk 0.4.26 → 0.4.28

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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { optimism, gnosis, baseSepolia, base, avalanche, worldchain, monad, polygon, arbitrum, bsc, unichain } from 'viem/chains';
2
- import { createPublicClient, http, createWalletClient, decodeErrorResult, parseSignature, maxUint256, encodeFunctionData, encodeAbiParameters, keccak256, padHex } from 'viem';
2
+ import { createPublicClient, http, createWalletClient, decodeErrorResult, maxUint256, encodeFunctionData, encodeAbiParameters, keccak256, padHex } from 'viem';
3
3
  import { privateKeyToAccount } from 'viem/accounts';
4
4
  import axios from 'axios';
5
5
  import { Networks } from 'stellar-sdk';
@@ -51,7 +51,7 @@ var init_facilitator = __esm({
51
51
  rpcUrl: "https://opt-mainnet.g.alchemy.com/v2/49fUGmuW05ynCui0VEvDN"
52
52
  // Assuming same key works or public
53
53
  },
54
- GNOSIS: {
54
+ Gnosis: {
55
55
  chainId: 100,
56
56
  chain: gnosis,
57
57
  usdc: "0x2a22f9c3b48403ebD92cF06fF916b322a30dB834",
@@ -900,7 +900,17 @@ var CHAIN_CONFIGS = {
900
900
  [optimism.id]: OPTIMISM_MAINNET
901
901
  };
902
902
 
903
- // src/services/gasless.ts
903
+ // src/constants/chains.ts
904
+ var CHAIN_ID_TO_KEY = {
905
+ "8453": "Base",
906
+ "84532": "Base",
907
+ "100": "Gnosis",
908
+ "10": "Optimism",
909
+ "11155420": "Optimism",
910
+ "42161": "Arbitrum"
911
+ };
912
+
913
+ // src/services/cctp.ts
904
914
  init_facilitator();
905
915
  init_facilitator();
906
916
 
@@ -995,117 +1005,6 @@ var messageTransmitterAbi = [
995
1005
  type: "function"
996
1006
  }
997
1007
  ];
998
-
999
- // src/services/gasless.ts
1000
- var GaslessStrategy = class {
1001
- constructor() {
1002
- this.name = "Gasless";
1003
- }
1004
- canHandle(context) {
1005
- const { sourceChain, destChain, sourceToken, destToken } = context;
1006
- return sourceChain === destChain && (sourceToken === destToken || !destToken);
1007
- }
1008
- async execute(context) {
1009
- const { paymentPayload, sourceChain, amount, recipient } = context;
1010
- return processGaslessSettlement(
1011
- paymentPayload,
1012
- sourceChain,
1013
- amount,
1014
- context.facilitatorPrivateKey,
1015
- recipient
1016
- );
1017
- }
1018
- };
1019
- async function processGaslessSettlement(paymentPayload, sourceChain, amount, facilitatorPrivateKey, recipient) {
1020
- if (!facilitatorPrivateKey) {
1021
- return {
1022
- success: false,
1023
- errorReason: "Facilitator Private Key not provided in context"
1024
- };
1025
- }
1026
- const networkConfig = FACILITATOR_NETWORKS[sourceChain];
1027
- if (!networkConfig) {
1028
- return {
1029
- success: false,
1030
- errorReason: `Unsupported chain: ${sourceChain}`
1031
- };
1032
- }
1033
- const { authorization, signature } = paymentPayload;
1034
- if (!signature) {
1035
- return {
1036
- success: false,
1037
- errorReason: "Missing Signature in Payment Payload"
1038
- };
1039
- }
1040
- const publicClient = createPublicClient({
1041
- chain: networkConfig.chain,
1042
- transport: http(networkConfig.rpcUrl)
1043
- });
1044
- const walletClient = createWalletClient({
1045
- account: privateKeyToAccount(facilitatorPrivateKey),
1046
- chain: networkConfig.chain,
1047
- transport: http(networkConfig.rpcUrl)
1048
- });
1049
- const { v, r, s } = parseSignature(signature);
1050
- let transferHash;
1051
- try {
1052
- transferHash = await walletClient.writeContract({
1053
- chain: networkConfig.chain,
1054
- address: networkConfig.usdc,
1055
- abi: usdcErc3009Abi,
1056
- functionName: "transferWithAuthorization",
1057
- args: [
1058
- authorization.from,
1059
- authorization.to,
1060
- BigInt(authorization.value),
1061
- BigInt(authorization.validAfter),
1062
- BigInt(authorization.validBefore),
1063
- authorization.nonce,
1064
- Number(v),
1065
- r,
1066
- s
1067
- ]
1068
- });
1069
- const receipt = await publicClient.waitForTransactionReceipt({ hash: transferHash });
1070
- if (receipt.status !== "success") throw new Error("TransferWithAuthorization failed");
1071
- } catch (e) {
1072
- return {
1073
- success: false,
1074
- errorReason: e instanceof Error ? e.message : "Transfer failed"
1075
- };
1076
- }
1077
- const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
1078
- const fee = calculateFee();
1079
- try {
1080
- const finalTransferHash = await walletClient.writeContract({
1081
- chain: networkConfig.chain,
1082
- address: networkConfig.usdc,
1083
- abi: usdcErc3009Abi,
1084
- functionName: "transfer",
1085
- args: [recipient, amountBigInt - fee]
1086
- // Deduct Fee (0.01 or 0)
1087
- });
1088
- await publicClient.waitForTransactionReceipt({ hash: finalTransferHash });
1089
- } catch (e) {
1090
- console.error("Final transfer failed", e);
1091
- return {
1092
- success: false,
1093
- transactionHash: transferHash,
1094
- errorReason: "Final transfer to recipient failed. Funds are with facilitator."
1095
- };
1096
- }
1097
- return {
1098
- success: true,
1099
- transactionHash: transferHash,
1100
- payer: authorization.from,
1101
- fee: fee.toString(),
1102
- netAmount: amountBigInt.toString()
1103
- };
1104
- }
1105
-
1106
- // src/services/cctp.ts
1107
- init_facilitator();
1108
- init_facilitator();
1109
1008
  var createRetrieveAttestation = async (transactionHash, chainId, timeout = 6e4) => {
1110
1009
  const baseUrl = "https://iris-api.circle.com";
1111
1010
  const url = `${baseUrl}/v2/messages/${chainId}?transactionHash=${transactionHash}`;
@@ -1831,7 +1730,10 @@ async function processCCTPSettlement(context, crossChainConfig) {
1831
1730
  };
1832
1731
  }
1833
1732
  const facilitatorAccount = privateKeyToAccount(facilitatorPrivateKey);
1834
- const { authorization } = paymentPayload;
1733
+ const fromAddress = context.senderAddress || paymentPayload?.authorization?.from;
1734
+ if (!fromAddress) {
1735
+ return { success: false, errorReason: "Sender address is missing" };
1736
+ }
1835
1737
  const usdcAddress = networkConfig.usdc;
1836
1738
  const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
1837
1739
  const publicClient = createPublicClient({
@@ -1886,7 +1788,7 @@ async function processCCTPSettlement(context, crossChainConfig) {
1886
1788
  };
1887
1789
  }
1888
1790
  const transferHash = depositTxHash || "0x0000000000000000000000000000000000000000000000000000000000000000";
1889
- return executeCCTPBridge(sourceChain, amount, crossChainConfig, facilitatorPrivateKey, recipient, transferHash, authorization.from);
1791
+ return executeCCTPBridge(sourceChain, amount, crossChainConfig, facilitatorPrivateKey, recipient, transferHash, fromAddress);
1890
1792
  }
1891
1793
  async function executeCCTPBridge(sourceChain, amount, crossChainConfig, facilitatorPrivateKey, recipient, transferHash, payerAddress) {
1892
1794
  if (!facilitatorPrivateKey) {
@@ -2078,15 +1980,15 @@ var NearStrategy = class {
2078
1980
  const { sourceChain, destChain, amount, recipient, destToken, sourceToken, senderAddress, depositTxHash } = context;
2079
1981
  if (depositTxHash) {
2080
1982
  console.log(`[NearStrategy] Verifying deposit hash: ${depositTxHash}`);
2081
- const { createPublicClient: createPublicClient4, http: http4 } = await import('viem');
1983
+ const { createPublicClient: createPublicClient3, http: http3 } = await import('viem');
2082
1984
  const { FACILITATOR_NETWORKS: FACILITATOR_NETWORKS2 } = await Promise.resolve().then(() => (init_facilitator(), facilitator_exports));
2083
1985
  const networkConfig = FACILITATOR_NETWORKS2[sourceChain];
2084
1986
  if (!networkConfig) {
2085
1987
  return { success: false, errorReason: `Unsupported source chain for verification: ${sourceChain}` };
2086
1988
  }
2087
- const publicClient = createPublicClient4({
1989
+ const publicClient = createPublicClient3({
2088
1990
  chain: networkConfig.chain,
2089
- transport: http4(networkConfig.rpcUrl)
1991
+ transport: http3(networkConfig.rpcUrl)
2090
1992
  });
2091
1993
  try {
2092
1994
  console.log(`[NearStrategy] Waiting for receipt...`);
@@ -2206,65 +2108,46 @@ async function getNearQuote(sourceChain, destChain, amount, destToken, sourceTok
2206
2108
  };
2207
2109
  }
2208
2110
 
2209
- // src/services/standard.ts
2210
- var StandardBridgeStrategy = class {
2211
- constructor() {
2212
- this.name = "StandardBridge";
2213
- }
2214
- canHandle(context) {
2215
- const { paymentPayload } = context;
2216
- return paymentPayload?.type === "STANDARD";
2217
- }
2218
- async execute(context) {
2219
- return {
2220
- success: false,
2221
- errorReason: "Standard Bridge Strategy is deprecated. Please use Near Intents or CCTP."
2222
- };
2223
- }
2224
- };
2225
-
2226
- // src/services/BridgeManager.ts
2227
- var BridgeManager = class {
2111
+ // src/services/TransferManager.ts
2112
+ var TransferManager = class {
2228
2113
  constructor() {
2229
2114
  this.strategies = [
2230
- new StandardBridgeStrategy(),
2231
- new GaslessStrategy(),
2232
2115
  new CCTPStrategy(),
2233
2116
  new NearStrategy()
2234
2117
  ];
2235
2118
  }
2236
- getStrategy(context) {
2237
- return this.strategies.find((strategy) => strategy.canHandle(context));
2238
- }
2239
2119
  async execute(context) {
2240
2120
  if (context.sourceChain === context.destChain && context.sourceToken === context.destToken) {
2241
- console.log(`[BridgeManager] Same Chain detected. Strategy: Gasless`);
2242
- const gaslessStrategy2 = new GaslessStrategy();
2243
- return gaslessStrategy2.execute(context);
2121
+ console.log(`[TransferManager] Same Chain detected. Signal Direct Transfer.`);
2122
+ return {
2123
+ success: true,
2124
+ transactionHash: "DIRECT_TRANSFER_REQUIRED",
2125
+ data: {
2126
+ action: "DIRECT_TRANSFER",
2127
+ amount: context.amount,
2128
+ token: context.sourceToken,
2129
+ recipient: context.recipient
2130
+ }
2131
+ };
2244
2132
  }
2245
2133
  const strategies = this.strategies;
2246
2134
  const cctpStrategy = strategies.find((s) => s instanceof CCTPStrategy);
2247
2135
  if (cctpStrategy && cctpStrategy.canHandle(context)) {
2248
- console.log(`[BridgeManager] Routing to: ${cctpStrategy.name} (CCTP)`);
2136
+ console.log(`[TransferManager] Routing to: ${cctpStrategy.name} (CCTP)`);
2249
2137
  return cctpStrategy.execute(context);
2250
2138
  }
2251
2139
  const nearStrategy = strategies.find((s) => s instanceof NearStrategy);
2252
2140
  if (nearStrategy && nearStrategy.canHandle(context)) {
2253
- console.log(`[BridgeManager] Routing to: ${nearStrategy.name} (Near)`);
2141
+ console.log(`[TransferManager] Routing to: ${nearStrategy.name} (Near)`);
2254
2142
  return nearStrategy.execute(context);
2255
2143
  }
2256
- const gaslessStrategy = strategies.find((s) => s instanceof GaslessStrategy);
2257
- if (gaslessStrategy && gaslessStrategy.canHandle(context)) {
2258
- console.log(`[BridgeManager] Routing to: ${gaslessStrategy.name}`);
2259
- return gaslessStrategy.execute(context);
2260
- }
2261
2144
  return {
2262
2145
  success: false,
2263
- errorReason: `No suitable bridge strategy found for ${context.sourceChain} -> ${context.destChain}`
2146
+ errorReason: `No suitable transfer strategy found for ${context.sourceChain} -> ${context.destChain}`
2264
2147
  };
2265
2148
  }
2266
2149
  };
2267
2150
 
2268
- export { AccountAbstraction, BASE_MAINNET, BASE_SEPOLIA, BridgeManager, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, GNOSIS_MAINNET, GaslessStrategy, NearStrategy, OPTIMISM_MAINNET, StandardBridgeStrategy, entryPointAbi, erc20Abi, smartAccountAbi };
2151
+ export { AccountAbstraction, BASE_MAINNET, BASE_SEPOLIA, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, GNOSIS_MAINNET, NearStrategy, OPTIMISM_MAINNET, TransferManager, entryPointAbi, erc20Abi, smartAccountAbi };
2269
2152
  //# sourceMappingURL=index.mjs.map
2270
2153
  //# sourceMappingURL=index.mjs.map