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