@1llet.xyz/erc4337-gasless-sdk 0.4.27 → 0.4.29
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 +2 -15
- package/dist/index.d.ts +2 -15
- package/dist/index.js +21 -163
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -162
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { optimism, gnosis, baseSepolia, base, avalanche, worldchain, monad, polygon, arbitrum, bsc, unichain } from 'viem/chains';
|
|
2
|
-
import { createPublicClient, http, createWalletClient, decodeErrorResult,
|
|
2
|
+
import { createPublicClient, http, createWalletClient, decodeErrorResult, maxUint256, encodeFunctionData, encodeAbiParameters, keccak256, padHex } from 'viem';
|
|
3
3
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
4
4
|
import axios from 'axios';
|
|
5
5
|
import { Networks } from 'stellar-sdk';
|
|
@@ -910,7 +910,7 @@ var CHAIN_ID_TO_KEY = {
|
|
|
910
910
|
"42161": "Arbitrum"
|
|
911
911
|
};
|
|
912
912
|
|
|
913
|
-
// src/services/
|
|
913
|
+
// src/services/cctp.ts
|
|
914
914
|
init_facilitator();
|
|
915
915
|
init_facilitator();
|
|
916
916
|
|
|
@@ -1005,120 +1005,6 @@ var messageTransmitterAbi = [
|
|
|
1005
1005
|
type: "function"
|
|
1006
1006
|
}
|
|
1007
1007
|
];
|
|
1008
|
-
|
|
1009
|
-
// src/services/gasless.ts
|
|
1010
|
-
var GaslessStrategy = class {
|
|
1011
|
-
constructor() {
|
|
1012
|
-
this.name = "Gasless";
|
|
1013
|
-
}
|
|
1014
|
-
canHandle(context) {
|
|
1015
|
-
const { sourceChain, destChain, sourceToken, destToken } = context;
|
|
1016
|
-
return sourceChain === destChain && (sourceToken === destToken || !destToken);
|
|
1017
|
-
}
|
|
1018
|
-
async execute(context) {
|
|
1019
|
-
const { paymentPayload, sourceChain, amount, recipient } = context;
|
|
1020
|
-
if (!paymentPayload) {
|
|
1021
|
-
return { success: false, errorReason: "Payment payload is required for Gasless Strategy" };
|
|
1022
|
-
}
|
|
1023
|
-
return processGaslessSettlement(
|
|
1024
|
-
paymentPayload,
|
|
1025
|
-
sourceChain,
|
|
1026
|
-
amount,
|
|
1027
|
-
context.facilitatorPrivateKey,
|
|
1028
|
-
recipient
|
|
1029
|
-
);
|
|
1030
|
-
}
|
|
1031
|
-
};
|
|
1032
|
-
async function processGaslessSettlement(paymentPayload, sourceChain, amount, facilitatorPrivateKey, recipient) {
|
|
1033
|
-
if (!facilitatorPrivateKey) {
|
|
1034
|
-
return {
|
|
1035
|
-
success: false,
|
|
1036
|
-
errorReason: "Facilitator Private Key not provided in context"
|
|
1037
|
-
};
|
|
1038
|
-
}
|
|
1039
|
-
const networkConfig = FACILITATOR_NETWORKS[sourceChain];
|
|
1040
|
-
if (!networkConfig) {
|
|
1041
|
-
return {
|
|
1042
|
-
success: false,
|
|
1043
|
-
errorReason: `Unsupported chain: ${sourceChain}`
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
const { authorization, signature } = paymentPayload;
|
|
1047
|
-
if (!signature) {
|
|
1048
|
-
return {
|
|
1049
|
-
success: false,
|
|
1050
|
-
errorReason: "Missing Signature in Payment Payload"
|
|
1051
|
-
};
|
|
1052
|
-
}
|
|
1053
|
-
const publicClient = createPublicClient({
|
|
1054
|
-
chain: networkConfig.chain,
|
|
1055
|
-
transport: http(networkConfig.rpcUrl)
|
|
1056
|
-
});
|
|
1057
|
-
const walletClient = createWalletClient({
|
|
1058
|
-
account: privateKeyToAccount(facilitatorPrivateKey),
|
|
1059
|
-
chain: networkConfig.chain,
|
|
1060
|
-
transport: http(networkConfig.rpcUrl)
|
|
1061
|
-
});
|
|
1062
|
-
const { v, r, s } = parseSignature(signature);
|
|
1063
|
-
let transferHash;
|
|
1064
|
-
try {
|
|
1065
|
-
transferHash = await walletClient.writeContract({
|
|
1066
|
-
chain: networkConfig.chain,
|
|
1067
|
-
address: networkConfig.usdc,
|
|
1068
|
-
abi: usdcErc3009Abi,
|
|
1069
|
-
functionName: "transferWithAuthorization",
|
|
1070
|
-
args: [
|
|
1071
|
-
authorization.from,
|
|
1072
|
-
authorization.to,
|
|
1073
|
-
BigInt(authorization.value),
|
|
1074
|
-
BigInt(authorization.validAfter),
|
|
1075
|
-
BigInt(authorization.validBefore),
|
|
1076
|
-
authorization.nonce,
|
|
1077
|
-
Number(v),
|
|
1078
|
-
r,
|
|
1079
|
-
s
|
|
1080
|
-
]
|
|
1081
|
-
});
|
|
1082
|
-
const receipt = await publicClient.waitForTransactionReceipt({ hash: transferHash });
|
|
1083
|
-
if (receipt.status !== "success") throw new Error("TransferWithAuthorization failed");
|
|
1084
|
-
} catch (e) {
|
|
1085
|
-
return {
|
|
1086
|
-
success: false,
|
|
1087
|
-
errorReason: e instanceof Error ? e.message : "Transfer failed"
|
|
1088
|
-
};
|
|
1089
|
-
}
|
|
1090
|
-
const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
|
|
1091
|
-
const fee = calculateFee();
|
|
1092
|
-
try {
|
|
1093
|
-
const finalTransferHash = await walletClient.writeContract({
|
|
1094
|
-
chain: networkConfig.chain,
|
|
1095
|
-
address: networkConfig.usdc,
|
|
1096
|
-
abi: usdcErc3009Abi,
|
|
1097
|
-
functionName: "transfer",
|
|
1098
|
-
args: [recipient, amountBigInt - fee]
|
|
1099
|
-
// Deduct Fee (0.01 or 0)
|
|
1100
|
-
});
|
|
1101
|
-
await publicClient.waitForTransactionReceipt({ hash: finalTransferHash });
|
|
1102
|
-
} catch (e) {
|
|
1103
|
-
console.error("Final transfer failed", e);
|
|
1104
|
-
return {
|
|
1105
|
-
success: false,
|
|
1106
|
-
transactionHash: transferHash,
|
|
1107
|
-
errorReason: "Final transfer to recipient failed. Funds are with facilitator."
|
|
1108
|
-
};
|
|
1109
|
-
}
|
|
1110
|
-
return {
|
|
1111
|
-
success: true,
|
|
1112
|
-
transactionHash: transferHash,
|
|
1113
|
-
payer: authorization.from,
|
|
1114
|
-
fee: fee.toString(),
|
|
1115
|
-
netAmount: amountBigInt.toString()
|
|
1116
|
-
};
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
// src/services/cctp.ts
|
|
1120
|
-
init_facilitator();
|
|
1121
|
-
init_facilitator();
|
|
1122
1008
|
var createRetrieveAttestation = async (transactionHash, chainId, timeout = 6e4) => {
|
|
1123
1009
|
const baseUrl = "https://iris-api.circle.com";
|
|
1124
1010
|
const url = `${baseUrl}/v2/messages/${chainId}?transactionHash=${transactionHash}`;
|
|
@@ -2094,15 +1980,15 @@ var NearStrategy = class {
|
|
|
2094
1980
|
const { sourceChain, destChain, amount, recipient, destToken, sourceToken, senderAddress, depositTxHash } = context;
|
|
2095
1981
|
if (depositTxHash) {
|
|
2096
1982
|
console.log(`[NearStrategy] Verifying deposit hash: ${depositTxHash}`);
|
|
2097
|
-
const { createPublicClient:
|
|
1983
|
+
const { createPublicClient: createPublicClient3, http: http3 } = await import('viem');
|
|
2098
1984
|
const { FACILITATOR_NETWORKS: FACILITATOR_NETWORKS2 } = await Promise.resolve().then(() => (init_facilitator(), facilitator_exports));
|
|
2099
1985
|
const networkConfig = FACILITATOR_NETWORKS2[sourceChain];
|
|
2100
1986
|
if (!networkConfig) {
|
|
2101
1987
|
return { success: false, errorReason: `Unsupported source chain for verification: ${sourceChain}` };
|
|
2102
1988
|
}
|
|
2103
|
-
const publicClient =
|
|
1989
|
+
const publicClient = createPublicClient3({
|
|
2104
1990
|
chain: networkConfig.chain,
|
|
2105
|
-
transport:
|
|
1991
|
+
transport: http3(networkConfig.rpcUrl)
|
|
2106
1992
|
});
|
|
2107
1993
|
try {
|
|
2108
1994
|
console.log(`[NearStrategy] Waiting for receipt...`);
|
|
@@ -2142,14 +2028,7 @@ var NearStrategy = class {
|
|
|
2142
2028
|
return {
|
|
2143
2029
|
success: true,
|
|
2144
2030
|
transactionHash: "PENDING_USER_DEPOSIT",
|
|
2145
|
-
// Placeholder or null
|
|
2146
2031
|
netAmount: quoteResult.amountAtomicNet,
|
|
2147
|
-
// Or formatted
|
|
2148
|
-
// We might need to extend SettleResponse to include explicit instruction
|
|
2149
|
-
// For now, we reuse the existing type.
|
|
2150
|
-
// In a real scenario, we'd add `depositAddress` to the response type.
|
|
2151
|
-
// Assuming SettleResponse is flexible or we console log it for the user context.
|
|
2152
|
-
// To be safe and useful:
|
|
2153
2032
|
data: {
|
|
2154
2033
|
depositAddress: quoteResult.depositAddress,
|
|
2155
2034
|
amountToDeposit: quoteResult.amountAtomicNet,
|
|
@@ -2222,65 +2101,46 @@ async function getNearQuote(sourceChain, destChain, amount, destToken, sourceTok
|
|
|
2222
2101
|
};
|
|
2223
2102
|
}
|
|
2224
2103
|
|
|
2225
|
-
// src/services/
|
|
2226
|
-
var
|
|
2227
|
-
constructor() {
|
|
2228
|
-
this.name = "StandardBridge";
|
|
2229
|
-
}
|
|
2230
|
-
canHandle(context) {
|
|
2231
|
-
const { paymentPayload } = context;
|
|
2232
|
-
return paymentPayload?.type === "STANDARD";
|
|
2233
|
-
}
|
|
2234
|
-
async execute(context) {
|
|
2235
|
-
return {
|
|
2236
|
-
success: false,
|
|
2237
|
-
errorReason: "Standard Bridge Strategy is deprecated. Please use Near Intents or CCTP."
|
|
2238
|
-
};
|
|
2239
|
-
}
|
|
2240
|
-
};
|
|
2241
|
-
|
|
2242
|
-
// src/services/BridgeManager.ts
|
|
2243
|
-
var BridgeManager = class {
|
|
2104
|
+
// src/services/TransferManager.ts
|
|
2105
|
+
var TransferManager = class {
|
|
2244
2106
|
constructor() {
|
|
2245
2107
|
this.strategies = [
|
|
2246
|
-
new StandardBridgeStrategy(),
|
|
2247
|
-
new GaslessStrategy(),
|
|
2248
2108
|
new CCTPStrategy(),
|
|
2249
2109
|
new NearStrategy()
|
|
2250
2110
|
];
|
|
2251
2111
|
}
|
|
2252
|
-
getStrategy(context) {
|
|
2253
|
-
return this.strategies.find((strategy) => strategy.canHandle(context));
|
|
2254
|
-
}
|
|
2255
2112
|
async execute(context) {
|
|
2256
2113
|
if (context.sourceChain === context.destChain && context.sourceToken === context.destToken) {
|
|
2257
|
-
console.log(`[
|
|
2258
|
-
|
|
2259
|
-
|
|
2114
|
+
console.log(`[TransferManager] Same Chain detected. Signal Direct Transfer.`);
|
|
2115
|
+
return {
|
|
2116
|
+
success: true,
|
|
2117
|
+
transactionHash: "DIRECT_TRANSFER_REQUIRED",
|
|
2118
|
+
data: {
|
|
2119
|
+
action: "DIRECT_TRANSFER",
|
|
2120
|
+
amount: context.amount,
|
|
2121
|
+
token: context.sourceToken,
|
|
2122
|
+
recipient: context.recipient
|
|
2123
|
+
}
|
|
2124
|
+
};
|
|
2260
2125
|
}
|
|
2261
2126
|
const strategies = this.strategies;
|
|
2262
2127
|
const cctpStrategy = strategies.find((s) => s instanceof CCTPStrategy);
|
|
2263
2128
|
if (cctpStrategy && cctpStrategy.canHandle(context)) {
|
|
2264
|
-
console.log(`[
|
|
2129
|
+
console.log(`[TransferManager] Routing to: ${cctpStrategy.name} (CCTP)`);
|
|
2265
2130
|
return cctpStrategy.execute(context);
|
|
2266
2131
|
}
|
|
2267
2132
|
const nearStrategy = strategies.find((s) => s instanceof NearStrategy);
|
|
2268
2133
|
if (nearStrategy && nearStrategy.canHandle(context)) {
|
|
2269
|
-
console.log(`[
|
|
2134
|
+
console.log(`[TransferManager] Routing to: ${nearStrategy.name} (Near)`);
|
|
2270
2135
|
return nearStrategy.execute(context);
|
|
2271
2136
|
}
|
|
2272
|
-
const gaslessStrategy = strategies.find((s) => s instanceof GaslessStrategy);
|
|
2273
|
-
if (gaslessStrategy && gaslessStrategy.canHandle(context)) {
|
|
2274
|
-
console.log(`[BridgeManager] Routing to: ${gaslessStrategy.name}`);
|
|
2275
|
-
return gaslessStrategy.execute(context);
|
|
2276
|
-
}
|
|
2277
2137
|
return {
|
|
2278
2138
|
success: false,
|
|
2279
|
-
errorReason: `No suitable
|
|
2139
|
+
errorReason: `No suitable transfer strategy found for ${context.sourceChain} -> ${context.destChain}`
|
|
2280
2140
|
};
|
|
2281
2141
|
}
|
|
2282
2142
|
};
|
|
2283
2143
|
|
|
2284
|
-
export { AccountAbstraction, BASE_MAINNET, BASE_SEPOLIA,
|
|
2144
|
+
export { AccountAbstraction, BASE_MAINNET, BASE_SEPOLIA, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, GNOSIS_MAINNET, NearStrategy, OPTIMISM_MAINNET, TransferManager, entryPointAbi, erc20Abi, smartAccountAbi };
|
|
2285
2145
|
//# sourceMappingURL=index.mjs.map
|
|
2286
2146
|
//# sourceMappingURL=index.mjs.map
|