@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.mjs CHANGED
@@ -1742,16 +1742,13 @@ var CCTPStrategy = class {
1742
1742
  mintRecipient: recipient
1743
1743
  };
1744
1744
  return processCCTPSettlement(
1745
- paymentPayload,
1746
- sourceChain,
1747
- amount,
1748
- crossChainConfig,
1749
- context.facilitatorPrivateKey,
1750
- recipient
1745
+ context,
1746
+ crossChainConfig
1751
1747
  );
1752
1748
  }
1753
1749
  };
1754
- async function processCCTPSettlement(paymentPayload, sourceChain, amount, crossChainConfig, facilitatorPrivateKey, recipient) {
1750
+ async function processCCTPSettlement(context, crossChainConfig) {
1751
+ const { paymentPayload, sourceChain, amount, recipient, facilitatorPrivateKey, depositTxHash } = context;
1755
1752
  if (!facilitatorPrivateKey) {
1756
1753
  return {
1757
1754
  success: false,
@@ -1765,45 +1762,56 @@ async function processCCTPSettlement(paymentPayload, sourceChain, amount, crossC
1765
1762
  errorReason: `Unsupported chain: ${sourceChain}`
1766
1763
  };
1767
1764
  }
1768
- const { authorization, signature } = paymentPayload;
1769
1765
  const facilitatorAccount = privateKeyToAccount(facilitatorPrivateKey);
1766
+ const { authorization } = paymentPayload;
1767
+ const usdcAddress = networkConfig.usdc;
1768
+ const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
1770
1769
  const publicClient = createPublicClient({
1771
1770
  chain: networkConfig.chain,
1772
1771
  transport: http(networkConfig.rpcUrl)
1773
1772
  });
1774
- const walletClient = createWalletClient({
1775
- account: facilitatorAccount,
1776
- chain: networkConfig.chain,
1777
- transport: http(networkConfig.rpcUrl)
1778
- });
1779
- const { v, r, s } = parseSignature(signature);
1780
- let transferHash;
1781
- try {
1782
- transferHash = await walletClient.writeContract({
1783
- chain: networkConfig.chain,
1784
- address: networkConfig.usdc,
1773
+ if (depositTxHash) {
1774
+ console.log(`[CCTP] Verifying deposit hash: ${depositTxHash}`);
1775
+ try {
1776
+ const receipt = await publicClient.waitForTransactionReceipt({ hash: depositTxHash });
1777
+ if (receipt.status !== "success") {
1778
+ throw new Error("Deposit transaction failed on-chain");
1779
+ }
1780
+ } catch (e) {
1781
+ return {
1782
+ success: false,
1783
+ errorReason: `Invalid deposit transaction: ${e instanceof Error ? e.message : "Unknown error"}`
1784
+ };
1785
+ }
1786
+ }
1787
+ let facilitatorBalance = BigInt(0);
1788
+ const maxRetries = depositTxHash ? 5 : 1;
1789
+ for (let i = 0; i < maxRetries; i++) {
1790
+ facilitatorBalance = await publicClient.readContract({
1791
+ address: usdcAddress,
1785
1792
  abi: usdcErc3009Abi,
1786
- functionName: "transferWithAuthorization",
1787
- args: [
1788
- authorization.from,
1789
- authorization.to,
1790
- BigInt(authorization.value),
1791
- BigInt(authorization.validAfter),
1792
- BigInt(authorization.validBefore),
1793
- authorization.nonce,
1794
- Number(v),
1795
- r,
1796
- s
1797
- ]
1793
+ functionName: "balanceOf",
1794
+ args: [facilitatorAccount.address]
1798
1795
  });
1799
- const receipt = await publicClient.waitForTransactionReceipt({ hash: transferHash });
1800
- if (receipt.status !== "success") throw new Error("Transfer execution failed");
1801
- } catch (error) {
1796
+ if (facilitatorBalance >= amountBigInt) break;
1797
+ if (depositTxHash) await new Promise((r) => setTimeout(r, 2e3));
1798
+ }
1799
+ if (facilitatorBalance < amountBigInt) {
1802
1800
  return {
1803
- success: false,
1804
- errorReason: error instanceof Error ? error.message : "Transfer failed"
1801
+ success: true,
1802
+ data: {
1803
+ depositAddress: facilitatorAccount.address,
1804
+ amountToDeposit: amountBigInt.toString(),
1805
+ chainId: networkConfig.chainId
1806
+ },
1807
+ attestation: {
1808
+ message: "PENDING_USER_DEPOSIT",
1809
+ attestation: "0x"
1810
+ },
1811
+ transactionHash: "PENDING_USER_DEPOSIT"
1805
1812
  };
1806
1813
  }
1814
+ const transferHash = depositTxHash || "0x0000000000000000000000000000000000000000000000000000000000000000";
1807
1815
  return executeCCTPBridge(sourceChain, amount, crossChainConfig, facilitatorPrivateKey, recipient, transferHash, authorization.from);
1808
1816
  }
1809
1817
  async function executeCCTPBridge(sourceChain, amount, crossChainConfig, facilitatorPrivateKey, recipient, transferHash, payerAddress) {
@@ -1827,7 +1835,7 @@ async function executeCCTPBridge(sourceChain, amount, crossChainConfig, facilita
1827
1835
  const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
1828
1836
  const fee = calculateFee();
1829
1837
  let facilitatorBalance = BigInt(0);
1830
- const maxRetries = 10;
1838
+ const maxRetries = 2;
1831
1839
  for (let i = 0; i < maxRetries; i++) {
1832
1840
  facilitatorBalance = await publicClient.readContract({
1833
1841
  address: networkConfig.usdc,