@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 +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +111 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1069,7 +1069,8 @@ var BASE = {
|
|
|
1069
1069
|
name: "USDC",
|
|
1070
1070
|
decimals: 6,
|
|
1071
1071
|
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
1072
|
-
coingeckoId: "usd-coin"
|
|
1072
|
+
coingeckoId: "usd-coin",
|
|
1073
|
+
supportsStargate: true
|
|
1073
1074
|
},
|
|
1074
1075
|
{
|
|
1075
1076
|
name: "ETH",
|
|
@@ -1112,6 +1113,9 @@ var BASE = {
|
|
|
1112
1113
|
}
|
|
1113
1114
|
],
|
|
1114
1115
|
needMemo: false
|
|
1116
|
+
},
|
|
1117
|
+
stargateInformation: {
|
|
1118
|
+
support: true
|
|
1115
1119
|
}
|
|
1116
1120
|
}
|
|
1117
1121
|
};
|
|
@@ -1316,7 +1320,8 @@ var AVALANCHE = {
|
|
|
1316
1320
|
name: "USDC",
|
|
1317
1321
|
decimals: 6,
|
|
1318
1322
|
address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
1319
|
-
coingeckoId: "usd-coin"
|
|
1323
|
+
coingeckoId: "usd-coin",
|
|
1324
|
+
supportsStargate: true
|
|
1320
1325
|
},
|
|
1321
1326
|
{
|
|
1322
1327
|
name: "AVAX",
|
|
@@ -1370,6 +1375,9 @@ var AVALANCHE = {
|
|
|
1370
1375
|
}
|
|
1371
1376
|
],
|
|
1372
1377
|
needMemo: false
|
|
1378
|
+
},
|
|
1379
|
+
stargateInformation: {
|
|
1380
|
+
support: true
|
|
1373
1381
|
}
|
|
1374
1382
|
}
|
|
1375
1383
|
};
|
|
@@ -2486,11 +2494,107 @@ async function getNearSimulation(sourceChain, destChain, amount, destToken, sour
|
|
|
2486
2494
|
}
|
|
2487
2495
|
}
|
|
2488
2496
|
|
|
2497
|
+
// src/services/stargate.ts
|
|
2498
|
+
var STARGATE_API_URL = "https://stargate.finance/api/v1/quotes";
|
|
2499
|
+
var StargateStrategy = class {
|
|
2500
|
+
constructor() {
|
|
2501
|
+
this.name = "StargateFinance";
|
|
2502
|
+
}
|
|
2503
|
+
canHandle(context) {
|
|
2504
|
+
const { sourceChain, destChain, sourceToken } = context;
|
|
2505
|
+
if (sourceChain === "Base" && destChain === "Avalanche" && sourceToken === "USDC") {
|
|
2506
|
+
return true;
|
|
2507
|
+
}
|
|
2508
|
+
const sourceConfig = NETWORKS[sourceChain];
|
|
2509
|
+
const destConfig = NETWORKS[destChain];
|
|
2510
|
+
if (!sourceConfig || !destConfig) return false;
|
|
2511
|
+
const sourceStargate = sourceConfig.crossChainInformation.stargateInformation?.support;
|
|
2512
|
+
const destStargate = destConfig.crossChainInformation.stargateInformation?.support;
|
|
2513
|
+
if (!sourceStargate || !destStargate) return false;
|
|
2514
|
+
const sourceAsset = sourceConfig.assets.find((a) => a.name === (sourceToken || "USDC"));
|
|
2515
|
+
const destAsset = destConfig.assets.find((a) => a.name === (context.destToken || "USDC"));
|
|
2516
|
+
return !!(sourceAsset?.supportsStargate && destAsset?.supportsStargate);
|
|
2517
|
+
}
|
|
2518
|
+
async execute(context) {
|
|
2519
|
+
const { sourceChain, destChain, amount, recipient, destToken, sourceToken, senderAddress } = context;
|
|
2520
|
+
console.log(`[StargateStrategy] Executing ${sourceChain} -> ${destChain} for ${amount} ${sourceToken}`);
|
|
2521
|
+
const sourceConfig = NETWORKS[sourceChain];
|
|
2522
|
+
const destConfig = NETWORKS[destChain];
|
|
2523
|
+
if (!sourceConfig || !destConfig) {
|
|
2524
|
+
return { success: false, errorReason: "Invalid chain configuration" };
|
|
2525
|
+
}
|
|
2526
|
+
const sourceAsset = sourceConfig.assets.find((a) => a.name === (sourceToken || "USDC"));
|
|
2527
|
+
const destAsset = destConfig.assets.find((a) => a.name === (destToken || "USDC"));
|
|
2528
|
+
if (!sourceAsset || !destAsset) {
|
|
2529
|
+
return { success: false, errorReason: "Invalid asset configuration" };
|
|
2530
|
+
}
|
|
2531
|
+
const decimals = sourceAsset.decimals;
|
|
2532
|
+
const amountAtomic = Math.floor(parseFloat(amount) * Math.pow(10, decimals)).toString();
|
|
2533
|
+
const minAmountAtomic = Math.floor(parseFloat(amountAtomic) * 0.995).toString();
|
|
2534
|
+
const srcChainKey = sourceChain.toLowerCase();
|
|
2535
|
+
const dstChainKey = destChain.toLowerCase();
|
|
2536
|
+
const url = new URL(STARGATE_API_URL);
|
|
2537
|
+
url.searchParams.append("srcToken", sourceAsset.address);
|
|
2538
|
+
url.searchParams.append("dstToken", destAsset.address);
|
|
2539
|
+
url.searchParams.append("srcAddress", senderAddress || recipient);
|
|
2540
|
+
url.searchParams.append("dstAddress", recipient);
|
|
2541
|
+
url.searchParams.append("srcChainKey", srcChainKey);
|
|
2542
|
+
url.searchParams.append("dstChainKey", dstChainKey);
|
|
2543
|
+
url.searchParams.append("srcAmount", amountAtomic);
|
|
2544
|
+
url.searchParams.append("dstAmountMin", minAmountAtomic);
|
|
2545
|
+
console.log(`[StargateStrategy] Fetching quote from: ${url.toString()}`);
|
|
2546
|
+
try {
|
|
2547
|
+
const response = await fetch(url.toString());
|
|
2548
|
+
const data = await response.json();
|
|
2549
|
+
if (!response.ok) {
|
|
2550
|
+
console.error("[StargateStrategy] API Error:", data);
|
|
2551
|
+
return { success: false, errorReason: `Stargate API Error: ${JSON.stringify(data)}` };
|
|
2552
|
+
}
|
|
2553
|
+
console.log("[StargateStrategy] Quote received:", JSON.stringify(data, null, 2));
|
|
2554
|
+
const quotes = data.quotes || [];
|
|
2555
|
+
if (quotes.length === 0) {
|
|
2556
|
+
return { success: false, errorReason: "No routes found from Stargate API" };
|
|
2557
|
+
}
|
|
2558
|
+
const selectedQuote = quotes.find((q) => q.route === "stargate/v2/taxi") || quotes[0];
|
|
2559
|
+
console.log(`[StargateStrategy] Selected Route: ${selectedQuote.route}`);
|
|
2560
|
+
const bridgeStep = selectedQuote.steps.find((s) => s.type === "bridge");
|
|
2561
|
+
if (!bridgeStep || !bridgeStep.transaction) {
|
|
2562
|
+
return { success: false, errorReason: "No bridge transaction found in quote" };
|
|
2563
|
+
}
|
|
2564
|
+
const txData = bridgeStep.transaction;
|
|
2565
|
+
const approvalTx = selectedQuote.steps.find((s) => s.type === "approve")?.transaction;
|
|
2566
|
+
return {
|
|
2567
|
+
success: true,
|
|
2568
|
+
transactionHash: "PENDING_USER_SIGNATURE",
|
|
2569
|
+
netAmount: amount,
|
|
2570
|
+
data: {
|
|
2571
|
+
strategy: "Stargate",
|
|
2572
|
+
quote: selectedQuote,
|
|
2573
|
+
// Normalized Transaction Data for execution
|
|
2574
|
+
txTarget: txData.to,
|
|
2575
|
+
txData: txData.data,
|
|
2576
|
+
txValue: txData.value,
|
|
2577
|
+
// Metadata
|
|
2578
|
+
approvalRequired: approvalTx ? {
|
|
2579
|
+
target: approvalTx.to,
|
|
2580
|
+
data: approvalTx.data,
|
|
2581
|
+
value: approvalTx.value
|
|
2582
|
+
} : null
|
|
2583
|
+
}
|
|
2584
|
+
};
|
|
2585
|
+
} catch (e) {
|
|
2586
|
+
console.error("[StargateStrategy] Execution Error:", e);
|
|
2587
|
+
return { success: false, errorReason: e.message };
|
|
2588
|
+
}
|
|
2589
|
+
}
|
|
2590
|
+
};
|
|
2591
|
+
|
|
2489
2592
|
// src/services/TransferManager.ts
|
|
2490
2593
|
var TransferManager = class {
|
|
2491
2594
|
constructor() {
|
|
2492
2595
|
this.strategies = [
|
|
2493
2596
|
new CCTPStrategy(),
|
|
2597
|
+
new StargateStrategy(),
|
|
2494
2598
|
new NearStrategy()
|
|
2495
2599
|
];
|
|
2496
2600
|
}
|
|
@@ -2509,6 +2613,11 @@ var TransferManager = class {
|
|
|
2509
2613
|
};
|
|
2510
2614
|
}
|
|
2511
2615
|
const strategies = this.strategies;
|
|
2616
|
+
const stargateStrategy = strategies.find((s) => s instanceof StargateStrategy);
|
|
2617
|
+
if (stargateStrategy && stargateStrategy.canHandle(context)) {
|
|
2618
|
+
console.log(`[TransferManager] Routing to: ${stargateStrategy.name} (Stargate)`);
|
|
2619
|
+
return stargateStrategy.execute(context);
|
|
2620
|
+
}
|
|
2512
2621
|
const cctpStrategy = strategies.find((s) => s instanceof CCTPStrategy);
|
|
2513
2622
|
if (cctpStrategy && cctpStrategy.canHandle(context)) {
|
|
2514
2623
|
console.log(`[TransferManager] Routing to: ${cctpStrategy.name} (CCTP)`);
|