@1llet.xyz/erc4337-gasless-sdk 0.4.14 → 0.4.18

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
@@ -332,6 +332,7 @@ interface BridgeContext {
332
332
  senderAddress?: string;
333
333
  facilitatorPrivateKey?: string;
334
334
  feeRecipient?: string;
335
+ depositTxHash?: string;
335
336
  }
336
337
  interface BridgeStrategy {
337
338
  name: string;
package/dist/index.d.ts CHANGED
@@ -332,6 +332,7 @@ interface BridgeContext {
332
332
  senderAddress?: string;
333
333
  facilitatorPrivateKey?: string;
334
334
  feeRecipient?: string;
335
+ depositTxHash?: string;
335
336
  }
336
337
  interface BridgeStrategy {
337
338
  name: string;
package/dist/index.js CHANGED
@@ -1748,16 +1748,13 @@ var CCTPStrategy = class {
1748
1748
  mintRecipient: recipient
1749
1749
  };
1750
1750
  return processCCTPSettlement(
1751
- paymentPayload,
1752
- sourceChain,
1753
- amount,
1754
- crossChainConfig,
1755
- context.facilitatorPrivateKey,
1756
- recipient
1751
+ context,
1752
+ crossChainConfig
1757
1753
  );
1758
1754
  }
1759
1755
  };
1760
- async function processCCTPSettlement(paymentPayload, sourceChain, amount, crossChainConfig, facilitatorPrivateKey, recipient) {
1756
+ async function processCCTPSettlement(context, crossChainConfig) {
1757
+ const { paymentPayload, sourceChain, amount, recipient, facilitatorPrivateKey, depositTxHash } = context;
1761
1758
  if (!facilitatorPrivateKey) {
1762
1759
  return {
1763
1760
  success: false,
@@ -1771,45 +1768,56 @@ async function processCCTPSettlement(paymentPayload, sourceChain, amount, crossC
1771
1768
  errorReason: `Unsupported chain: ${sourceChain}`
1772
1769
  };
1773
1770
  }
1774
- const { authorization, signature } = paymentPayload;
1775
1771
  const facilitatorAccount = accounts.privateKeyToAccount(facilitatorPrivateKey);
1772
+ const { authorization } = paymentPayload;
1773
+ const usdcAddress = networkConfig.usdc;
1774
+ const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
1776
1775
  const publicClient = viem.createPublicClient({
1777
1776
  chain: networkConfig.chain,
1778
1777
  transport: viem.http(networkConfig.rpcUrl)
1779
1778
  });
1780
- const walletClient = viem.createWalletClient({
1781
- account: facilitatorAccount,
1782
- chain: networkConfig.chain,
1783
- transport: viem.http(networkConfig.rpcUrl)
1784
- });
1785
- const { v, r, s } = viem.parseSignature(signature);
1786
- let transferHash;
1787
- try {
1788
- transferHash = await walletClient.writeContract({
1789
- chain: networkConfig.chain,
1790
- address: networkConfig.usdc,
1779
+ if (depositTxHash) {
1780
+ console.log(`[CCTP] Verifying deposit hash: ${depositTxHash}`);
1781
+ try {
1782
+ const receipt = await publicClient.waitForTransactionReceipt({ hash: depositTxHash });
1783
+ if (receipt.status !== "success") {
1784
+ throw new Error("Deposit transaction failed on-chain");
1785
+ }
1786
+ } catch (e) {
1787
+ return {
1788
+ success: false,
1789
+ errorReason: `Invalid deposit transaction: ${e instanceof Error ? e.message : "Unknown error"}`
1790
+ };
1791
+ }
1792
+ }
1793
+ let facilitatorBalance = BigInt(0);
1794
+ const maxRetries = depositTxHash ? 5 : 1;
1795
+ for (let i = 0; i < maxRetries; i++) {
1796
+ facilitatorBalance = await publicClient.readContract({
1797
+ address: usdcAddress,
1791
1798
  abi: usdcErc3009Abi,
1792
- functionName: "transferWithAuthorization",
1793
- args: [
1794
- authorization.from,
1795
- authorization.to,
1796
- BigInt(authorization.value),
1797
- BigInt(authorization.validAfter),
1798
- BigInt(authorization.validBefore),
1799
- authorization.nonce,
1800
- Number(v),
1801
- r,
1802
- s
1803
- ]
1799
+ functionName: "balanceOf",
1800
+ args: [facilitatorAccount.address]
1804
1801
  });
1805
- const receipt = await publicClient.waitForTransactionReceipt({ hash: transferHash });
1806
- if (receipt.status !== "success") throw new Error("Transfer execution failed");
1807
- } catch (error) {
1802
+ if (facilitatorBalance >= amountBigInt) break;
1803
+ if (depositTxHash) await new Promise((r) => setTimeout(r, 2e3));
1804
+ }
1805
+ if (facilitatorBalance < amountBigInt) {
1808
1806
  return {
1809
- success: false,
1810
- errorReason: error instanceof Error ? error.message : "Transfer failed"
1807
+ success: true,
1808
+ data: {
1809
+ depositAddress: facilitatorAccount.address,
1810
+ amountToDeposit: amountBigInt.toString(),
1811
+ chainId: networkConfig.chainId
1812
+ },
1813
+ attestation: {
1814
+ message: "PENDING_USER_DEPOSIT",
1815
+ attestation: "0x"
1816
+ },
1817
+ transactionHash: "PENDING_USER_DEPOSIT"
1811
1818
  };
1812
1819
  }
1820
+ const transferHash = depositTxHash || "0x0000000000000000000000000000000000000000000000000000000000000000";
1813
1821
  return executeCCTPBridge(sourceChain, amount, crossChainConfig, facilitatorPrivateKey, recipient, transferHash, authorization.from);
1814
1822
  }
1815
1823
  async function executeCCTPBridge(sourceChain, amount, crossChainConfig, facilitatorPrivateKey, recipient, transferHash, payerAddress) {
@@ -1833,7 +1841,7 @@ async function executeCCTPBridge(sourceChain, amount, crossChainConfig, facilita
1833
1841
  const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
1834
1842
  const fee = calculateFee();
1835
1843
  let facilitatorBalance = BigInt(0);
1836
- const maxRetries = 10;
1844
+ const maxRetries = 2;
1837
1845
  for (let i = 0; i < maxRetries; i++) {
1838
1846
  facilitatorBalance = await publicClient.readContract({
1839
1847
  address: networkConfig.usdc,