@1llet.xyz/erc4337-gasless-sdk 0.4.40 → 0.4.43

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
@@ -459,6 +459,23 @@ declare class NearStrategy implements BridgeStrategy {
459
459
  canHandle(context: BridgeContext): boolean;
460
460
  execute(context: BridgeContext): Promise<SettleResponse>;
461
461
  }
462
+ declare function getNearSimulation(sourceChain: ChainKey, destChain: ChainKey, amount: string, destToken?: string, sourceToken?: string): Promise<{
463
+ success: boolean;
464
+ amountSent: number;
465
+ protocolFee: number;
466
+ netAmountBridged: number;
467
+ estimatedReceived: any;
468
+ minAmount: number;
469
+ error?: undefined;
470
+ } | {
471
+ success: boolean;
472
+ error: any;
473
+ minAmount: number;
474
+ amountSent?: undefined;
475
+ protocolFee?: undefined;
476
+ netAmountBridged?: undefined;
477
+ estimatedReceived?: undefined;
478
+ }>;
462
479
 
463
480
  declare class CCTPStrategy implements BridgeStrategy {
464
481
  name: string;
@@ -466,4 +483,4 @@ declare class CCTPStrategy implements BridgeStrategy {
466
483
  execute(context: BridgeContext): Promise<SettleResponse>;
467
484
  }
468
485
 
469
- export { AccountAbstraction, type ApprovalSupportResult, BASE_MAINNET, BASE_SEPOLIA, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, type ChainConfig$1 as ChainConfig, GNOSIS_MAINNET, type GasEstimate, NearStrategy, OPTIMISM_MAINNET, STELLAR, STELLAR_MAINNET, StellarService, type Token, TransferManager, type UserOpReceipt, type UserOperation, entryPointAbi, erc20Abi, smartAccountAbi };
486
+ export { AccountAbstraction, type ApprovalSupportResult, BASE_MAINNET, BASE_SEPOLIA, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, type ChainConfig$1 as ChainConfig, GNOSIS_MAINNET, type GasEstimate, NearStrategy, OPTIMISM_MAINNET, STELLAR, STELLAR_MAINNET, StellarService, type Token, TransferManager, type UserOpReceipt, type UserOperation, entryPointAbi, erc20Abi, getNearSimulation, smartAccountAbi };
package/dist/index.d.ts CHANGED
@@ -459,6 +459,23 @@ declare class NearStrategy implements BridgeStrategy {
459
459
  canHandle(context: BridgeContext): boolean;
460
460
  execute(context: BridgeContext): Promise<SettleResponse>;
461
461
  }
462
+ declare function getNearSimulation(sourceChain: ChainKey, destChain: ChainKey, amount: string, destToken?: string, sourceToken?: string): Promise<{
463
+ success: boolean;
464
+ amountSent: number;
465
+ protocolFee: number;
466
+ netAmountBridged: number;
467
+ estimatedReceived: any;
468
+ minAmount: number;
469
+ error?: undefined;
470
+ } | {
471
+ success: boolean;
472
+ error: any;
473
+ minAmount: number;
474
+ amountSent?: undefined;
475
+ protocolFee?: undefined;
476
+ netAmountBridged?: undefined;
477
+ estimatedReceived?: undefined;
478
+ }>;
462
479
 
463
480
  declare class CCTPStrategy implements BridgeStrategy {
464
481
  name: string;
@@ -466,4 +483,4 @@ declare class CCTPStrategy implements BridgeStrategy {
466
483
  execute(context: BridgeContext): Promise<SettleResponse>;
467
484
  }
468
485
 
469
- export { AccountAbstraction, type ApprovalSupportResult, BASE_MAINNET, BASE_SEPOLIA, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, type ChainConfig$1 as ChainConfig, GNOSIS_MAINNET, type GasEstimate, NearStrategy, OPTIMISM_MAINNET, STELLAR, STELLAR_MAINNET, StellarService, type Token, TransferManager, type UserOpReceipt, type UserOperation, entryPointAbi, erc20Abi, smartAccountAbi };
486
+ export { AccountAbstraction, type ApprovalSupportResult, BASE_MAINNET, BASE_SEPOLIA, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, type ChainConfig$1 as ChainConfig, GNOSIS_MAINNET, type GasEstimate, NearStrategy, OPTIMISM_MAINNET, STELLAR, STELLAR_MAINNET, StellarService, type Token, TransferManager, type UserOpReceipt, type UserOperation, entryPointAbi, erc20Abi, getNearSimulation, smartAccountAbi };
package/dist/index.js CHANGED
@@ -186,14 +186,24 @@ var init_StellarService = __esm({
186
186
  // src/constants/facilitator.ts
187
187
  var facilitator_exports = {};
188
188
  __export(facilitator_exports, {
189
+ DUMMY_EVM_ADDRESS: () => DUMMY_EVM_ADDRESS,
190
+ DUMMY_STELLAR_ADDRESS: () => DUMMY_STELLAR_ADDRESS,
189
191
  FACILITATOR_NETWORKS: () => FACILITATOR_NETWORKS,
192
+ PlatformFees: () => PlatformFees,
190
193
  calculateFee: () => calculateFee
191
194
  });
192
- var calculateFee, FACILITATOR_NETWORKS;
195
+ var PlatformFees, DUMMY_EVM_ADDRESS, DUMMY_STELLAR_ADDRESS, calculateFee, FACILITATOR_NETWORKS;
193
196
  var init_facilitator = __esm({
194
197
  "src/constants/facilitator.ts"() {
195
- calculateFee = () => {
196
- return BigInt(1e4);
198
+ PlatformFees = {
199
+ DEV: 0,
200
+ EVM_TO_OTHER: 0.02,
201
+ DEFAULT: 0.02
202
+ };
203
+ DUMMY_EVM_ADDRESS = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
204
+ DUMMY_STELLAR_ADDRESS = "GB7BDSZU2Y27LYNLJLVEGW5TIVYQ6362DS5QZ5F6S27S227227227AAA";
205
+ calculateFee = (isDev = false) => {
206
+ return isDev ? PlatformFees.DEV : PlatformFees.DEFAULT;
197
207
  };
198
208
  FACILITATOR_NETWORKS = {
199
209
  Base: {
@@ -1983,7 +1993,8 @@ async function executeCCTPBridge(sourceChain, amount, crossChainConfig, facilita
1983
1993
  transport: viem.http(networkConfig.rpcUrl)
1984
1994
  });
1985
1995
  const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
1986
- const fee = calculateFee();
1996
+ const feeRaw = calculateFee();
1997
+ const fee = BigInt(Math.floor(feeRaw * 1e6));
1987
1998
  const minRequired = fee * BigInt(2);
1988
1999
  if (amountBigInt <= minRequired) {
1989
2000
  return {
@@ -2137,6 +2148,7 @@ async function executeCCTPBridge(sourceChain, amount, crossChainConfig, facilita
2137
2148
  };
2138
2149
  }
2139
2150
  init_StellarService();
2151
+ init_facilitator();
2140
2152
  oneClickSdkTypescript.OpenAPI.BASE = "https://1click.chaindefuser.com";
2141
2153
  var NearStrategy = class {
2142
2154
  constructor() {
@@ -2296,7 +2308,7 @@ var NearStrategy = class {
2296
2308
  }
2297
2309
  }
2298
2310
  };
2299
- async function getNearQuote(sourceChain, destChain, amount, destToken, sourceToken, recipient, senderAddress) {
2311
+ async function getNearQuote(sourceChain, destChain, amount, destToken, sourceToken, recipient, senderAddress, options) {
2300
2312
  const sourceConfig = NETWORKS[sourceChain];
2301
2313
  const destConfig = NETWORKS[destChain];
2302
2314
  if (!sourceConfig || !destConfig) {
@@ -2326,9 +2338,9 @@ async function getNearQuote(sourceChain, destChain, amount, destToken, sourceTok
2326
2338
  throw new Error("Recipient address is required for NEAR Quote");
2327
2339
  }
2328
2340
  const refundAddress = senderAddress || recipient;
2329
- console.log(`[NearService] Requesting Quote: ${sourceChain} -> ${destChain}`, { amount, sourceAsset, destAsset });
2341
+ console.log(`[NearService] Requesting Quote: ${sourceChain} -> ${destChain}`, JSON.stringify({ amount, sourceAsset, destAsset, options }, null, 2));
2330
2342
  const quoteRequest = {
2331
- dry: false,
2343
+ dry: options?.dry || false,
2332
2344
  swapType: oneClickSdkTypescript.QuoteRequest.swapType.EXACT_INPUT,
2333
2345
  slippageTolerance: 100,
2334
2346
  originAsset: sourceAsset,
@@ -2355,6 +2367,59 @@ async function getNearQuote(sourceChain, destChain, amount, destToken, sourceTok
2355
2367
  amountAtomicNet
2356
2368
  };
2357
2369
  }
2370
+ async function getNearSimulation(sourceChain, destChain, amount, destToken, sourceToken) {
2371
+ console.log(">>> [Bridge Quote] Simulation Request:", { sourceChain, destChain, amount, destToken, sourceToken });
2372
+ if (!amount || isNaN(parseFloat(amount))) {
2373
+ throw new Error("Invalid amount");
2374
+ }
2375
+ const amountNum = parseFloat(amount);
2376
+ const isDev = process.env.NEXT_PUBLIC_ENVIROMENT === "development" || process.env.NODE_ENV === "development";
2377
+ const usedFee = isDev ? PlatformFees.DEV : PlatformFees.EVM_TO_OTHER;
2378
+ const MIN_AMOUNT = usedFee;
2379
+ const sourceConfig = NETWORKS[sourceChain];
2380
+ const sourceAssetInfo = sourceConfig?.crossChainInformation?.nearIntentInformation?.assetsId.find(
2381
+ (a) => a.name === (sourceToken || "USDC")
2382
+ ) || sourceConfig?.crossChainInformation?.nearIntentInformation?.assetsId[0];
2383
+ const decimals = sourceAssetInfo?.decimals || (sourceChain === "Stellar" ? 7 : 6);
2384
+ const netAmountBridged = (amountNum - usedFee).toFixed(decimals);
2385
+ if (parseFloat(netAmountBridged) <= 0) {
2386
+ return {
2387
+ success: false,
2388
+ error: `Insufficient amount (${amountNum}) to cover fee (${usedFee})`,
2389
+ minAmount: MIN_AMOUNT
2390
+ };
2391
+ }
2392
+ const sender = sourceChain === "Stellar" ? DUMMY_STELLAR_ADDRESS : DUMMY_EVM_ADDRESS;
2393
+ const recipient = destChain === "Stellar" ? DUMMY_STELLAR_ADDRESS : DUMMY_EVM_ADDRESS;
2394
+ try {
2395
+ const quoteResult = await getNearQuote(
2396
+ sourceChain,
2397
+ destChain,
2398
+ netAmountBridged.toString(),
2399
+ destToken,
2400
+ sourceToken,
2401
+ recipient,
2402
+ sender,
2403
+ { dry: true }
2404
+ );
2405
+ return {
2406
+ success: true,
2407
+ amountSent: amountNum,
2408
+ protocolFee: usedFee,
2409
+ netAmountBridged: parseFloat(netAmountBridged),
2410
+ // @ts-ignore - access safe property
2411
+ estimatedReceived: quoteResult.quote?.quote?.estimatedOutput || "0",
2412
+ minAmount: MIN_AMOUNT
2413
+ };
2414
+ } catch (error) {
2415
+ console.error(">>> [Bridge Quote] Error:", error);
2416
+ return {
2417
+ success: false,
2418
+ error: error.message || "Unknown quote error",
2419
+ minAmount: MIN_AMOUNT
2420
+ };
2421
+ }
2422
+ }
2358
2423
 
2359
2424
  // src/services/TransferManager.ts
2360
2425
  var TransferManager = class {
@@ -2410,6 +2475,7 @@ exports.STELLAR_MAINNET = STELLAR_MAINNET;
2410
2475
  exports.TransferManager = TransferManager;
2411
2476
  exports.entryPointAbi = entryPointAbi;
2412
2477
  exports.erc20Abi = erc20Abi;
2478
+ exports.getNearSimulation = getNearSimulation;
2413
2479
  exports.smartAccountAbi = smartAccountAbi;
2414
2480
  //# sourceMappingURL=index.js.map
2415
2481
  //# sourceMappingURL=index.js.map