@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.mjs
CHANGED
|
@@ -1742,16 +1742,13 @@ var CCTPStrategy = class {
|
|
|
1742
1742
|
mintRecipient: recipient
|
|
1743
1743
|
};
|
|
1744
1744
|
return processCCTPSettlement(
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
amount,
|
|
1748
|
-
crossChainConfig,
|
|
1749
|
-
context.facilitatorPrivateKey,
|
|
1750
|
-
recipient
|
|
1745
|
+
context,
|
|
1746
|
+
crossChainConfig
|
|
1751
1747
|
);
|
|
1752
1748
|
}
|
|
1753
1749
|
};
|
|
1754
|
-
async function processCCTPSettlement(
|
|
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
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
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: "
|
|
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
|
-
|
|
1800
|
-
if (
|
|
1801
|
-
}
|
|
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:
|
|
1804
|
-
|
|
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) {
|
|
@@ -1826,8 +1834,16 @@ async function executeCCTPBridge(sourceChain, amount, crossChainConfig, facilita
|
|
|
1826
1834
|
});
|
|
1827
1835
|
const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
|
|
1828
1836
|
const fee = calculateFee();
|
|
1837
|
+
const minRequired = fee * BigInt(2);
|
|
1838
|
+
if (amountBigInt <= minRequired) {
|
|
1839
|
+
return {
|
|
1840
|
+
success: false,
|
|
1841
|
+
transactionHash: transferHash,
|
|
1842
|
+
errorReason: `Amount too small. Minimum required: ${Number(minRequired) / 1e6} USDC (to cover bridge fees)`
|
|
1843
|
+
};
|
|
1844
|
+
}
|
|
1829
1845
|
let facilitatorBalance = BigInt(0);
|
|
1830
|
-
const maxRetries =
|
|
1846
|
+
const maxRetries = 2;
|
|
1831
1847
|
for (let i = 0; i < maxRetries; i++) {
|
|
1832
1848
|
facilitatorBalance = await publicClient.readContract({
|
|
1833
1849
|
address: networkConfig.usdc,
|