@1llet.xyz/erc4337-gasless-sdk 0.4.55 → 0.4.56

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
@@ -366,9 +366,13 @@ interface CircleInformation {
366
366
  cCTPInformation?: CCTPInformation;
367
367
  aproxFromFee: number;
368
368
  }
369
+ interface StargateInformation {
370
+ support: boolean;
371
+ }
369
372
  interface CrossChainInformation {
370
373
  circleInformation?: CircleInformation;
371
374
  nearIntentInformation: NearIntentInformation | null;
375
+ stargateInformation?: StargateInformation;
372
376
  }
373
377
  interface EvmInformation {
374
378
  chain: any;
@@ -389,6 +393,7 @@ interface Asset {
389
393
  decimals: number;
390
394
  address?: Address$1 | string;
391
395
  coingeckoId?: string;
396
+ supportsStargate?: boolean;
392
397
  }
393
398
  interface ChainConfig {
394
399
  assets: Asset[];
package/dist/index.d.ts CHANGED
@@ -366,9 +366,13 @@ interface CircleInformation {
366
366
  cCTPInformation?: CCTPInformation;
367
367
  aproxFromFee: number;
368
368
  }
369
+ interface StargateInformation {
370
+ support: boolean;
371
+ }
369
372
  interface CrossChainInformation {
370
373
  circleInformation?: CircleInformation;
371
374
  nearIntentInformation: NearIntentInformation | null;
375
+ stargateInformation?: StargateInformation;
372
376
  }
373
377
  interface EvmInformation {
374
378
  chain: any;
@@ -389,6 +393,7 @@ interface Asset {
389
393
  decimals: number;
390
394
  address?: Address$1 | string;
391
395
  coingeckoId?: string;
396
+ supportsStargate?: boolean;
392
397
  }
393
398
  interface ChainConfig {
394
399
  assets: Asset[];
package/dist/index.js CHANGED
@@ -1093,7 +1093,8 @@ var BASE = {
1093
1093
  name: "USDC",
1094
1094
  decimals: 6,
1095
1095
  address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
1096
- coingeckoId: "usd-coin"
1096
+ coingeckoId: "usd-coin",
1097
+ supportsStargate: true
1097
1098
  },
1098
1099
  {
1099
1100
  name: "ETH",
@@ -1136,6 +1137,9 @@ var BASE = {
1136
1137
  }
1137
1138
  ],
1138
1139
  needMemo: false
1140
+ },
1141
+ stargateInformation: {
1142
+ support: true
1139
1143
  }
1140
1144
  }
1141
1145
  };
@@ -1340,7 +1344,8 @@ var AVALANCHE = {
1340
1344
  name: "USDC",
1341
1345
  decimals: 6,
1342
1346
  address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
1343
- coingeckoId: "usd-coin"
1347
+ coingeckoId: "usd-coin",
1348
+ supportsStargate: true
1344
1349
  },
1345
1350
  {
1346
1351
  name: "AVAX",
@@ -1394,6 +1399,9 @@ var AVALANCHE = {
1394
1399
  }
1395
1400
  ],
1396
1401
  needMemo: false
1402
+ },
1403
+ stargateInformation: {
1404
+ support: true
1397
1405
  }
1398
1406
  }
1399
1407
  };
@@ -2510,11 +2518,107 @@ async function getNearSimulation(sourceChain, destChain, amount, destToken, sour
2510
2518
  }
2511
2519
  }
2512
2520
 
2521
+ // src/services/stargate.ts
2522
+ var STARGATE_API_URL = "https://stargate.finance/api/v1/quotes";
2523
+ var StargateStrategy = class {
2524
+ constructor() {
2525
+ this.name = "StargateFinance";
2526
+ }
2527
+ canHandle(context) {
2528
+ const { sourceChain, destChain, sourceToken } = context;
2529
+ if (sourceChain === "Base" && destChain === "Avalanche" && sourceToken === "USDC") {
2530
+ return true;
2531
+ }
2532
+ const sourceConfig = NETWORKS[sourceChain];
2533
+ const destConfig = NETWORKS[destChain];
2534
+ if (!sourceConfig || !destConfig) return false;
2535
+ const sourceStargate = sourceConfig.crossChainInformation.stargateInformation?.support;
2536
+ const destStargate = destConfig.crossChainInformation.stargateInformation?.support;
2537
+ if (!sourceStargate || !destStargate) return false;
2538
+ const sourceAsset = sourceConfig.assets.find((a) => a.name === (sourceToken || "USDC"));
2539
+ const destAsset = destConfig.assets.find((a) => a.name === (context.destToken || "USDC"));
2540
+ return !!(sourceAsset?.supportsStargate && destAsset?.supportsStargate);
2541
+ }
2542
+ async execute(context) {
2543
+ const { sourceChain, destChain, amount, recipient, destToken, sourceToken, senderAddress } = context;
2544
+ console.log(`[StargateStrategy] Executing ${sourceChain} -> ${destChain} for ${amount} ${sourceToken}`);
2545
+ const sourceConfig = NETWORKS[sourceChain];
2546
+ const destConfig = NETWORKS[destChain];
2547
+ if (!sourceConfig || !destConfig) {
2548
+ return { success: false, errorReason: "Invalid chain configuration" };
2549
+ }
2550
+ const sourceAsset = sourceConfig.assets.find((a) => a.name === (sourceToken || "USDC"));
2551
+ const destAsset = destConfig.assets.find((a) => a.name === (destToken || "USDC"));
2552
+ if (!sourceAsset || !destAsset) {
2553
+ return { success: false, errorReason: "Invalid asset configuration" };
2554
+ }
2555
+ const decimals = sourceAsset.decimals;
2556
+ const amountAtomic = Math.floor(parseFloat(amount) * Math.pow(10, decimals)).toString();
2557
+ const minAmountAtomic = Math.floor(parseFloat(amountAtomic) * 0.995).toString();
2558
+ const srcChainKey = sourceChain.toLowerCase();
2559
+ const dstChainKey = destChain.toLowerCase();
2560
+ const url = new URL(STARGATE_API_URL);
2561
+ url.searchParams.append("srcToken", sourceAsset.address);
2562
+ url.searchParams.append("dstToken", destAsset.address);
2563
+ url.searchParams.append("srcAddress", senderAddress || recipient);
2564
+ url.searchParams.append("dstAddress", recipient);
2565
+ url.searchParams.append("srcChainKey", srcChainKey);
2566
+ url.searchParams.append("dstChainKey", dstChainKey);
2567
+ url.searchParams.append("srcAmount", amountAtomic);
2568
+ url.searchParams.append("dstAmountMin", minAmountAtomic);
2569
+ console.log(`[StargateStrategy] Fetching quote from: ${url.toString()}`);
2570
+ try {
2571
+ const response = await fetch(url.toString());
2572
+ const data = await response.json();
2573
+ if (!response.ok) {
2574
+ console.error("[StargateStrategy] API Error:", data);
2575
+ return { success: false, errorReason: `Stargate API Error: ${JSON.stringify(data)}` };
2576
+ }
2577
+ console.log("[StargateStrategy] Quote received:", JSON.stringify(data, null, 2));
2578
+ const quotes = data.quotes || [];
2579
+ if (quotes.length === 0) {
2580
+ return { success: false, errorReason: "No routes found from Stargate API" };
2581
+ }
2582
+ const selectedQuote = quotes.find((q) => q.route === "stargate/v2/taxi") || quotes[0];
2583
+ console.log(`[StargateStrategy] Selected Route: ${selectedQuote.route}`);
2584
+ const bridgeStep = selectedQuote.steps.find((s) => s.type === "bridge");
2585
+ if (!bridgeStep || !bridgeStep.transaction) {
2586
+ return { success: false, errorReason: "No bridge transaction found in quote" };
2587
+ }
2588
+ const txData = bridgeStep.transaction;
2589
+ const approvalTx = selectedQuote.steps.find((s) => s.type === "approve")?.transaction;
2590
+ return {
2591
+ success: true,
2592
+ transactionHash: "PENDING_USER_SIGNATURE",
2593
+ netAmount: amount,
2594
+ data: {
2595
+ strategy: "Stargate",
2596
+ quote: selectedQuote,
2597
+ // Normalized Transaction Data for execution
2598
+ txTarget: txData.to,
2599
+ txData: txData.data,
2600
+ txValue: txData.value,
2601
+ // Metadata
2602
+ approvalRequired: approvalTx ? {
2603
+ target: approvalTx.to,
2604
+ data: approvalTx.data,
2605
+ value: approvalTx.value
2606
+ } : null
2607
+ }
2608
+ };
2609
+ } catch (e) {
2610
+ console.error("[StargateStrategy] Execution Error:", e);
2611
+ return { success: false, errorReason: e.message };
2612
+ }
2613
+ }
2614
+ };
2615
+
2513
2616
  // src/services/TransferManager.ts
2514
2617
  var TransferManager = class {
2515
2618
  constructor() {
2516
2619
  this.strategies = [
2517
2620
  new CCTPStrategy(),
2621
+ new StargateStrategy(),
2518
2622
  new NearStrategy()
2519
2623
  ];
2520
2624
  }
@@ -2533,6 +2637,11 @@ var TransferManager = class {
2533
2637
  };
2534
2638
  }
2535
2639
  const strategies = this.strategies;
2640
+ const stargateStrategy = strategies.find((s) => s instanceof StargateStrategy);
2641
+ if (stargateStrategy && stargateStrategy.canHandle(context)) {
2642
+ console.log(`[TransferManager] Routing to: ${stargateStrategy.name} (Stargate)`);
2643
+ return stargateStrategy.execute(context);
2644
+ }
2536
2645
  const cctpStrategy = strategies.find((s) => s instanceof CCTPStrategy);
2537
2646
  if (cctpStrategy && cctpStrategy.canHandle(context)) {
2538
2647
  console.log(`[TransferManager] Routing to: ${cctpStrategy.name} (CCTP)`);