@1llet.xyz/erc4337-gasless-sdk 0.4.13 → 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
@@ -812,24 +812,33 @@ var CHAIN_CONFIGS = {
812
812
  [gnosis.id]: GNOSIS_MAINNET,
813
813
  [optimism.id]: OPTIMISM_MAINNET
814
814
  };
815
-
816
- // src/constants/facilitator.ts
817
815
  var calculateFee = () => {
818
816
  return BigInt(1e4);
819
817
  };
820
818
  var FACILITATOR_NETWORKS = {
821
- // Example:
822
- // Base: {
823
- // chainId: 8453,
824
- // chain: undefined, // Need importing from viem/chains
825
- // usdc: "0x...",
826
- // usdcName: "USDC",
827
- // usdcVersion: "1",
828
- // domain: 6,
829
- // tokenMessenger: "0x...",
830
- // messageTransmitter: "0x...",
831
- // rpcUrl: "https://..."
832
- // }
819
+ Base: {
820
+ chainId: 8453,
821
+ chain: base,
822
+ usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
823
+ usdcName: "USD Coin",
824
+ usdcVersion: "2",
825
+ domain: 6,
826
+ tokenMessenger: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
827
+ messageTransmitter: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64",
828
+ rpcUrl: "https://base-mainnet.g.alchemy.com/v2/49fUGmuW05ynCui0VEvDN"
829
+ },
830
+ Optimism: {
831
+ chainId: 10,
832
+ chain: optimism,
833
+ usdc: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
834
+ usdcName: "USD Coin",
835
+ usdcVersion: "2",
836
+ domain: 2,
837
+ tokenMessenger: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
838
+ messageTransmitter: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64",
839
+ rpcUrl: "https://opt-mainnet.g.alchemy.com/v2/49fUGmuW05ynCui0VEvDN"
840
+ // Assuming same key works or public
841
+ }
833
842
  };
834
843
 
835
844
  // src/constants/abis.ts
@@ -1733,16 +1742,13 @@ var CCTPStrategy = class {
1733
1742
  mintRecipient: recipient
1734
1743
  };
1735
1744
  return processCCTPSettlement(
1736
- paymentPayload,
1737
- sourceChain,
1738
- amount,
1739
- crossChainConfig,
1740
- context.facilitatorPrivateKey,
1741
- recipient
1745
+ context,
1746
+ crossChainConfig
1742
1747
  );
1743
1748
  }
1744
1749
  };
1745
- async function processCCTPSettlement(paymentPayload, sourceChain, amount, crossChainConfig, facilitatorPrivateKey, recipient) {
1750
+ async function processCCTPSettlement(context, crossChainConfig) {
1751
+ const { paymentPayload, sourceChain, amount, recipient, facilitatorPrivateKey, depositTxHash } = context;
1746
1752
  if (!facilitatorPrivateKey) {
1747
1753
  return {
1748
1754
  success: false,
@@ -1756,45 +1762,56 @@ async function processCCTPSettlement(paymentPayload, sourceChain, amount, crossC
1756
1762
  errorReason: `Unsupported chain: ${sourceChain}`
1757
1763
  };
1758
1764
  }
1759
- const { authorization, signature } = paymentPayload;
1760
1765
  const facilitatorAccount = privateKeyToAccount(facilitatorPrivateKey);
1766
+ const { authorization } = paymentPayload;
1767
+ const usdcAddress = networkConfig.usdc;
1768
+ const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
1761
1769
  const publicClient = createPublicClient({
1762
1770
  chain: networkConfig.chain,
1763
1771
  transport: http(networkConfig.rpcUrl)
1764
1772
  });
1765
- const walletClient = createWalletClient({
1766
- account: facilitatorAccount,
1767
- chain: networkConfig.chain,
1768
- transport: http(networkConfig.rpcUrl)
1769
- });
1770
- const { v, r, s } = parseSignature(signature);
1771
- let transferHash;
1772
- try {
1773
- transferHash = await walletClient.writeContract({
1774
- chain: networkConfig.chain,
1775
- 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,
1776
1792
  abi: usdcErc3009Abi,
1777
- functionName: "transferWithAuthorization",
1778
- args: [
1779
- authorization.from,
1780
- authorization.to,
1781
- BigInt(authorization.value),
1782
- BigInt(authorization.validAfter),
1783
- BigInt(authorization.validBefore),
1784
- authorization.nonce,
1785
- Number(v),
1786
- r,
1787
- s
1788
- ]
1793
+ functionName: "balanceOf",
1794
+ args: [facilitatorAccount.address]
1789
1795
  });
1790
- const receipt = await publicClient.waitForTransactionReceipt({ hash: transferHash });
1791
- if (receipt.status !== "success") throw new Error("Transfer execution failed");
1792
- } catch (error) {
1796
+ if (facilitatorBalance >= amountBigInt) break;
1797
+ if (depositTxHash) await new Promise((r) => setTimeout(r, 2e3));
1798
+ }
1799
+ if (facilitatorBalance < amountBigInt) {
1793
1800
  return {
1794
- success: false,
1795
- 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"
1796
1812
  };
1797
1813
  }
1814
+ const transferHash = depositTxHash || "0x0000000000000000000000000000000000000000000000000000000000000000";
1798
1815
  return executeCCTPBridge(sourceChain, amount, crossChainConfig, facilitatorPrivateKey, recipient, transferHash, authorization.from);
1799
1816
  }
1800
1817
  async function executeCCTPBridge(sourceChain, amount, crossChainConfig, facilitatorPrivateKey, recipient, transferHash, payerAddress) {
@@ -1818,7 +1835,7 @@ async function executeCCTPBridge(sourceChain, amount, crossChainConfig, facilita
1818
1835
  const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
1819
1836
  const fee = calculateFee();
1820
1837
  let facilitatorBalance = BigInt(0);
1821
- const maxRetries = 10;
1838
+ const maxRetries = 2;
1822
1839
  for (let i = 0; i < maxRetries; i++) {
1823
1840
  facilitatorBalance = await publicClient.readContract({
1824
1841
  address: networkConfig.usdc,