@1llet.xyz/erc4337-gasless-sdk 0.4.14 → 0.4.19
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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +53 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1748,16 +1748,13 @@ var CCTPStrategy = class {
|
|
|
1748
1748
|
mintRecipient: recipient
|
|
1749
1749
|
};
|
|
1750
1750
|
return processCCTPSettlement(
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
amount,
|
|
1754
|
-
crossChainConfig,
|
|
1755
|
-
context.facilitatorPrivateKey,
|
|
1756
|
-
recipient
|
|
1751
|
+
context,
|
|
1752
|
+
crossChainConfig
|
|
1757
1753
|
);
|
|
1758
1754
|
}
|
|
1759
1755
|
};
|
|
1760
|
-
async function processCCTPSettlement(
|
|
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
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
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: "
|
|
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
|
-
|
|
1806
|
-
if (
|
|
1807
|
-
}
|
|
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:
|
|
1810
|
-
|
|
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) {
|
|
@@ -1832,8 +1840,16 @@ async function executeCCTPBridge(sourceChain, amount, crossChainConfig, facilita
|
|
|
1832
1840
|
});
|
|
1833
1841
|
const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
|
|
1834
1842
|
const fee = calculateFee();
|
|
1843
|
+
const minRequired = fee * BigInt(2);
|
|
1844
|
+
if (amountBigInt <= minRequired) {
|
|
1845
|
+
return {
|
|
1846
|
+
success: false,
|
|
1847
|
+
transactionHash: transferHash,
|
|
1848
|
+
errorReason: `Amount too small. Minimum required: ${Number(minRequired) / 1e6} USDC (to cover bridge fees)`
|
|
1849
|
+
};
|
|
1850
|
+
}
|
|
1835
1851
|
let facilitatorBalance = BigInt(0);
|
|
1836
|
-
const maxRetries =
|
|
1852
|
+
const maxRetries = 2;
|
|
1837
1853
|
for (let i = 0; i < maxRetries; i++) {
|
|
1838
1854
|
facilitatorBalance = await publicClient.readContract({
|
|
1839
1855
|
address: networkConfig.usdc,
|