@1llet.xyz/erc4337-gasless-sdk 0.4.26 → 0.4.28
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 +5 -16
- package/dist/index.d.ts +5 -16
- package/dist/index.js +38 -156
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -155
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -279,6 +279,8 @@ declare const erc20Abi: readonly [{
|
|
|
279
279
|
readonly type: "function";
|
|
280
280
|
}];
|
|
281
281
|
|
|
282
|
+
declare const CHAIN_ID_TO_KEY: Record<string, string>;
|
|
283
|
+
|
|
282
284
|
declare const ChainKeyEnum: z.ZodEnum<{
|
|
283
285
|
Base: "Base";
|
|
284
286
|
Optimism: "Optimism";
|
|
@@ -322,7 +324,7 @@ interface SettleResponse {
|
|
|
322
324
|
data?: any;
|
|
323
325
|
}
|
|
324
326
|
interface BridgeContext {
|
|
325
|
-
paymentPayload
|
|
327
|
+
paymentPayload?: FacilitatorPaymentPayload;
|
|
326
328
|
sourceChain: ChainKey;
|
|
327
329
|
destChain: ChainKey;
|
|
328
330
|
sourceToken?: string;
|
|
@@ -340,10 +342,9 @@ interface BridgeStrategy {
|
|
|
340
342
|
execute(context: BridgeContext): Promise<SettleResponse>;
|
|
341
343
|
}
|
|
342
344
|
|
|
343
|
-
declare class
|
|
345
|
+
declare class TransferManager {
|
|
344
346
|
private strategies;
|
|
345
347
|
constructor();
|
|
346
|
-
private getStrategy;
|
|
347
348
|
execute(context: BridgeContext): Promise<SettleResponse>;
|
|
348
349
|
}
|
|
349
350
|
|
|
@@ -359,16 +360,4 @@ declare class CCTPStrategy implements BridgeStrategy {
|
|
|
359
360
|
execute(context: BridgeContext): Promise<SettleResponse>;
|
|
360
361
|
}
|
|
361
362
|
|
|
362
|
-
|
|
363
|
-
name: string;
|
|
364
|
-
canHandle(context: BridgeContext): boolean;
|
|
365
|
-
execute(context: BridgeContext): Promise<SettleResponse>;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
declare class StandardBridgeStrategy implements BridgeStrategy {
|
|
369
|
-
name: string;
|
|
370
|
-
canHandle(context: BridgeContext): boolean;
|
|
371
|
-
execute(context: BridgeContext): Promise<SettleResponse>;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
export { AccountAbstraction, type ApprovalSupportResult, BASE_MAINNET, BASE_SEPOLIA, BridgeManager, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, type ChainConfig, GNOSIS_MAINNET, type GasEstimate, GaslessStrategy, NearStrategy, OPTIMISM_MAINNET, StandardBridgeStrategy, type Token, type UserOpReceipt, type UserOperation, entryPointAbi, erc20Abi, smartAccountAbi };
|
|
363
|
+
export { AccountAbstraction, type ApprovalSupportResult, BASE_MAINNET, BASE_SEPOLIA, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, type ChainConfig, GNOSIS_MAINNET, type GasEstimate, NearStrategy, OPTIMISM_MAINNET, type Token, TransferManager, type UserOpReceipt, type UserOperation, entryPointAbi, erc20Abi, smartAccountAbi };
|
package/dist/index.d.ts
CHANGED
|
@@ -279,6 +279,8 @@ declare const erc20Abi: readonly [{
|
|
|
279
279
|
readonly type: "function";
|
|
280
280
|
}];
|
|
281
281
|
|
|
282
|
+
declare const CHAIN_ID_TO_KEY: Record<string, string>;
|
|
283
|
+
|
|
282
284
|
declare const ChainKeyEnum: z.ZodEnum<{
|
|
283
285
|
Base: "Base";
|
|
284
286
|
Optimism: "Optimism";
|
|
@@ -322,7 +324,7 @@ interface SettleResponse {
|
|
|
322
324
|
data?: any;
|
|
323
325
|
}
|
|
324
326
|
interface BridgeContext {
|
|
325
|
-
paymentPayload
|
|
327
|
+
paymentPayload?: FacilitatorPaymentPayload;
|
|
326
328
|
sourceChain: ChainKey;
|
|
327
329
|
destChain: ChainKey;
|
|
328
330
|
sourceToken?: string;
|
|
@@ -340,10 +342,9 @@ interface BridgeStrategy {
|
|
|
340
342
|
execute(context: BridgeContext): Promise<SettleResponse>;
|
|
341
343
|
}
|
|
342
344
|
|
|
343
|
-
declare class
|
|
345
|
+
declare class TransferManager {
|
|
344
346
|
private strategies;
|
|
345
347
|
constructor();
|
|
346
|
-
private getStrategy;
|
|
347
348
|
execute(context: BridgeContext): Promise<SettleResponse>;
|
|
348
349
|
}
|
|
349
350
|
|
|
@@ -359,16 +360,4 @@ declare class CCTPStrategy implements BridgeStrategy {
|
|
|
359
360
|
execute(context: BridgeContext): Promise<SettleResponse>;
|
|
360
361
|
}
|
|
361
362
|
|
|
362
|
-
|
|
363
|
-
name: string;
|
|
364
|
-
canHandle(context: BridgeContext): boolean;
|
|
365
|
-
execute(context: BridgeContext): Promise<SettleResponse>;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
declare class StandardBridgeStrategy implements BridgeStrategy {
|
|
369
|
-
name: string;
|
|
370
|
-
canHandle(context: BridgeContext): boolean;
|
|
371
|
-
execute(context: BridgeContext): Promise<SettleResponse>;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
export { AccountAbstraction, type ApprovalSupportResult, BASE_MAINNET, BASE_SEPOLIA, BridgeManager, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, type ChainConfig, GNOSIS_MAINNET, type GasEstimate, GaslessStrategy, NearStrategy, OPTIMISM_MAINNET, StandardBridgeStrategy, type Token, type UserOpReceipt, type UserOperation, entryPointAbi, erc20Abi, smartAccountAbi };
|
|
363
|
+
export { AccountAbstraction, type ApprovalSupportResult, BASE_MAINNET, BASE_SEPOLIA, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, type ChainConfig, GNOSIS_MAINNET, type GasEstimate, NearStrategy, OPTIMISM_MAINNET, type Token, TransferManager, type UserOpReceipt, type UserOperation, entryPointAbi, erc20Abi, smartAccountAbi };
|
package/dist/index.js
CHANGED
|
@@ -57,7 +57,7 @@ var init_facilitator = __esm({
|
|
|
57
57
|
rpcUrl: "https://opt-mainnet.g.alchemy.com/v2/49fUGmuW05ynCui0VEvDN"
|
|
58
58
|
// Assuming same key works or public
|
|
59
59
|
},
|
|
60
|
-
|
|
60
|
+
Gnosis: {
|
|
61
61
|
chainId: 100,
|
|
62
62
|
chain: chains.gnosis,
|
|
63
63
|
usdc: "0x2a22f9c3b48403ebD92cF06fF916b322a30dB834",
|
|
@@ -906,7 +906,17 @@ var CHAIN_CONFIGS = {
|
|
|
906
906
|
[chains.optimism.id]: OPTIMISM_MAINNET
|
|
907
907
|
};
|
|
908
908
|
|
|
909
|
-
// src/
|
|
909
|
+
// src/constants/chains.ts
|
|
910
|
+
var CHAIN_ID_TO_KEY = {
|
|
911
|
+
"8453": "Base",
|
|
912
|
+
"84532": "Base",
|
|
913
|
+
"100": "Gnosis",
|
|
914
|
+
"10": "Optimism",
|
|
915
|
+
"11155420": "Optimism",
|
|
916
|
+
"42161": "Arbitrum"
|
|
917
|
+
};
|
|
918
|
+
|
|
919
|
+
// src/services/cctp.ts
|
|
910
920
|
init_facilitator();
|
|
911
921
|
init_facilitator();
|
|
912
922
|
|
|
@@ -1001,117 +1011,6 @@ var messageTransmitterAbi = [
|
|
|
1001
1011
|
type: "function"
|
|
1002
1012
|
}
|
|
1003
1013
|
];
|
|
1004
|
-
|
|
1005
|
-
// src/services/gasless.ts
|
|
1006
|
-
var GaslessStrategy = class {
|
|
1007
|
-
constructor() {
|
|
1008
|
-
this.name = "Gasless";
|
|
1009
|
-
}
|
|
1010
|
-
canHandle(context) {
|
|
1011
|
-
const { sourceChain, destChain, sourceToken, destToken } = context;
|
|
1012
|
-
return sourceChain === destChain && (sourceToken === destToken || !destToken);
|
|
1013
|
-
}
|
|
1014
|
-
async execute(context) {
|
|
1015
|
-
const { paymentPayload, sourceChain, amount, recipient } = context;
|
|
1016
|
-
return processGaslessSettlement(
|
|
1017
|
-
paymentPayload,
|
|
1018
|
-
sourceChain,
|
|
1019
|
-
amount,
|
|
1020
|
-
context.facilitatorPrivateKey,
|
|
1021
|
-
recipient
|
|
1022
|
-
);
|
|
1023
|
-
}
|
|
1024
|
-
};
|
|
1025
|
-
async function processGaslessSettlement(paymentPayload, sourceChain, amount, facilitatorPrivateKey, recipient) {
|
|
1026
|
-
if (!facilitatorPrivateKey) {
|
|
1027
|
-
return {
|
|
1028
|
-
success: false,
|
|
1029
|
-
errorReason: "Facilitator Private Key not provided in context"
|
|
1030
|
-
};
|
|
1031
|
-
}
|
|
1032
|
-
const networkConfig = FACILITATOR_NETWORKS[sourceChain];
|
|
1033
|
-
if (!networkConfig) {
|
|
1034
|
-
return {
|
|
1035
|
-
success: false,
|
|
1036
|
-
errorReason: `Unsupported chain: ${sourceChain}`
|
|
1037
|
-
};
|
|
1038
|
-
}
|
|
1039
|
-
const { authorization, signature } = paymentPayload;
|
|
1040
|
-
if (!signature) {
|
|
1041
|
-
return {
|
|
1042
|
-
success: false,
|
|
1043
|
-
errorReason: "Missing Signature in Payment Payload"
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
const publicClient = viem.createPublicClient({
|
|
1047
|
-
chain: networkConfig.chain,
|
|
1048
|
-
transport: viem.http(networkConfig.rpcUrl)
|
|
1049
|
-
});
|
|
1050
|
-
const walletClient = viem.createWalletClient({
|
|
1051
|
-
account: accounts.privateKeyToAccount(facilitatorPrivateKey),
|
|
1052
|
-
chain: networkConfig.chain,
|
|
1053
|
-
transport: viem.http(networkConfig.rpcUrl)
|
|
1054
|
-
});
|
|
1055
|
-
const { v, r, s } = viem.parseSignature(signature);
|
|
1056
|
-
let transferHash;
|
|
1057
|
-
try {
|
|
1058
|
-
transferHash = await walletClient.writeContract({
|
|
1059
|
-
chain: networkConfig.chain,
|
|
1060
|
-
address: networkConfig.usdc,
|
|
1061
|
-
abi: usdcErc3009Abi,
|
|
1062
|
-
functionName: "transferWithAuthorization",
|
|
1063
|
-
args: [
|
|
1064
|
-
authorization.from,
|
|
1065
|
-
authorization.to,
|
|
1066
|
-
BigInt(authorization.value),
|
|
1067
|
-
BigInt(authorization.validAfter),
|
|
1068
|
-
BigInt(authorization.validBefore),
|
|
1069
|
-
authorization.nonce,
|
|
1070
|
-
Number(v),
|
|
1071
|
-
r,
|
|
1072
|
-
s
|
|
1073
|
-
]
|
|
1074
|
-
});
|
|
1075
|
-
const receipt = await publicClient.waitForTransactionReceipt({ hash: transferHash });
|
|
1076
|
-
if (receipt.status !== "success") throw new Error("TransferWithAuthorization failed");
|
|
1077
|
-
} catch (e) {
|
|
1078
|
-
return {
|
|
1079
|
-
success: false,
|
|
1080
|
-
errorReason: e instanceof Error ? e.message : "Transfer failed"
|
|
1081
|
-
};
|
|
1082
|
-
}
|
|
1083
|
-
const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
|
|
1084
|
-
const fee = calculateFee();
|
|
1085
|
-
try {
|
|
1086
|
-
const finalTransferHash = await walletClient.writeContract({
|
|
1087
|
-
chain: networkConfig.chain,
|
|
1088
|
-
address: networkConfig.usdc,
|
|
1089
|
-
abi: usdcErc3009Abi,
|
|
1090
|
-
functionName: "transfer",
|
|
1091
|
-
args: [recipient, amountBigInt - fee]
|
|
1092
|
-
// Deduct Fee (0.01 or 0)
|
|
1093
|
-
});
|
|
1094
|
-
await publicClient.waitForTransactionReceipt({ hash: finalTransferHash });
|
|
1095
|
-
} catch (e) {
|
|
1096
|
-
console.error("Final transfer failed", e);
|
|
1097
|
-
return {
|
|
1098
|
-
success: false,
|
|
1099
|
-
transactionHash: transferHash,
|
|
1100
|
-
errorReason: "Final transfer to recipient failed. Funds are with facilitator."
|
|
1101
|
-
};
|
|
1102
|
-
}
|
|
1103
|
-
return {
|
|
1104
|
-
success: true,
|
|
1105
|
-
transactionHash: transferHash,
|
|
1106
|
-
payer: authorization.from,
|
|
1107
|
-
fee: fee.toString(),
|
|
1108
|
-
netAmount: amountBigInt.toString()
|
|
1109
|
-
};
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
// src/services/cctp.ts
|
|
1113
|
-
init_facilitator();
|
|
1114
|
-
init_facilitator();
|
|
1115
1014
|
var createRetrieveAttestation = async (transactionHash, chainId, timeout = 6e4) => {
|
|
1116
1015
|
const baseUrl = "https://iris-api.circle.com";
|
|
1117
1016
|
const url = `${baseUrl}/v2/messages/${chainId}?transactionHash=${transactionHash}`;
|
|
@@ -1837,7 +1736,10 @@ async function processCCTPSettlement(context, crossChainConfig) {
|
|
|
1837
1736
|
};
|
|
1838
1737
|
}
|
|
1839
1738
|
const facilitatorAccount = accounts.privateKeyToAccount(facilitatorPrivateKey);
|
|
1840
|
-
const
|
|
1739
|
+
const fromAddress = context.senderAddress || paymentPayload?.authorization?.from;
|
|
1740
|
+
if (!fromAddress) {
|
|
1741
|
+
return { success: false, errorReason: "Sender address is missing" };
|
|
1742
|
+
}
|
|
1841
1743
|
const usdcAddress = networkConfig.usdc;
|
|
1842
1744
|
const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
|
|
1843
1745
|
const publicClient = viem.createPublicClient({
|
|
@@ -1892,7 +1794,7 @@ async function processCCTPSettlement(context, crossChainConfig) {
|
|
|
1892
1794
|
};
|
|
1893
1795
|
}
|
|
1894
1796
|
const transferHash = depositTxHash || "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
1895
|
-
return executeCCTPBridge(sourceChain, amount, crossChainConfig, facilitatorPrivateKey, recipient, transferHash,
|
|
1797
|
+
return executeCCTPBridge(sourceChain, amount, crossChainConfig, facilitatorPrivateKey, recipient, transferHash, fromAddress);
|
|
1896
1798
|
}
|
|
1897
1799
|
async function executeCCTPBridge(sourceChain, amount, crossChainConfig, facilitatorPrivateKey, recipient, transferHash, payerAddress) {
|
|
1898
1800
|
if (!facilitatorPrivateKey) {
|
|
@@ -2084,15 +1986,15 @@ var NearStrategy = class {
|
|
|
2084
1986
|
const { sourceChain, destChain, amount, recipient, destToken, sourceToken, senderAddress, depositTxHash } = context;
|
|
2085
1987
|
if (depositTxHash) {
|
|
2086
1988
|
console.log(`[NearStrategy] Verifying deposit hash: ${depositTxHash}`);
|
|
2087
|
-
const { createPublicClient:
|
|
1989
|
+
const { createPublicClient: createPublicClient3, http: http3 } = await import('viem');
|
|
2088
1990
|
const { FACILITATOR_NETWORKS: FACILITATOR_NETWORKS2 } = await Promise.resolve().then(() => (init_facilitator(), facilitator_exports));
|
|
2089
1991
|
const networkConfig = FACILITATOR_NETWORKS2[sourceChain];
|
|
2090
1992
|
if (!networkConfig) {
|
|
2091
1993
|
return { success: false, errorReason: `Unsupported source chain for verification: ${sourceChain}` };
|
|
2092
1994
|
}
|
|
2093
|
-
const publicClient =
|
|
1995
|
+
const publicClient = createPublicClient3({
|
|
2094
1996
|
chain: networkConfig.chain,
|
|
2095
|
-
transport:
|
|
1997
|
+
transport: http3(networkConfig.rpcUrl)
|
|
2096
1998
|
});
|
|
2097
1999
|
try {
|
|
2098
2000
|
console.log(`[NearStrategy] Waiting for receipt...`);
|
|
@@ -2212,61 +2114,42 @@ async function getNearQuote(sourceChain, destChain, amount, destToken, sourceTok
|
|
|
2212
2114
|
};
|
|
2213
2115
|
}
|
|
2214
2116
|
|
|
2215
|
-
// src/services/
|
|
2216
|
-
var
|
|
2217
|
-
constructor() {
|
|
2218
|
-
this.name = "StandardBridge";
|
|
2219
|
-
}
|
|
2220
|
-
canHandle(context) {
|
|
2221
|
-
const { paymentPayload } = context;
|
|
2222
|
-
return paymentPayload?.type === "STANDARD";
|
|
2223
|
-
}
|
|
2224
|
-
async execute(context) {
|
|
2225
|
-
return {
|
|
2226
|
-
success: false,
|
|
2227
|
-
errorReason: "Standard Bridge Strategy is deprecated. Please use Near Intents or CCTP."
|
|
2228
|
-
};
|
|
2229
|
-
}
|
|
2230
|
-
};
|
|
2231
|
-
|
|
2232
|
-
// src/services/BridgeManager.ts
|
|
2233
|
-
var BridgeManager = class {
|
|
2117
|
+
// src/services/TransferManager.ts
|
|
2118
|
+
var TransferManager = class {
|
|
2234
2119
|
constructor() {
|
|
2235
2120
|
this.strategies = [
|
|
2236
|
-
new StandardBridgeStrategy(),
|
|
2237
|
-
new GaslessStrategy(),
|
|
2238
2121
|
new CCTPStrategy(),
|
|
2239
2122
|
new NearStrategy()
|
|
2240
2123
|
];
|
|
2241
2124
|
}
|
|
2242
|
-
getStrategy(context) {
|
|
2243
|
-
return this.strategies.find((strategy) => strategy.canHandle(context));
|
|
2244
|
-
}
|
|
2245
2125
|
async execute(context) {
|
|
2246
2126
|
if (context.sourceChain === context.destChain && context.sourceToken === context.destToken) {
|
|
2247
|
-
console.log(`[
|
|
2248
|
-
|
|
2249
|
-
|
|
2127
|
+
console.log(`[TransferManager] Same Chain detected. Signal Direct Transfer.`);
|
|
2128
|
+
return {
|
|
2129
|
+
success: true,
|
|
2130
|
+
transactionHash: "DIRECT_TRANSFER_REQUIRED",
|
|
2131
|
+
data: {
|
|
2132
|
+
action: "DIRECT_TRANSFER",
|
|
2133
|
+
amount: context.amount,
|
|
2134
|
+
token: context.sourceToken,
|
|
2135
|
+
recipient: context.recipient
|
|
2136
|
+
}
|
|
2137
|
+
};
|
|
2250
2138
|
}
|
|
2251
2139
|
const strategies = this.strategies;
|
|
2252
2140
|
const cctpStrategy = strategies.find((s) => s instanceof CCTPStrategy);
|
|
2253
2141
|
if (cctpStrategy && cctpStrategy.canHandle(context)) {
|
|
2254
|
-
console.log(`[
|
|
2142
|
+
console.log(`[TransferManager] Routing to: ${cctpStrategy.name} (CCTP)`);
|
|
2255
2143
|
return cctpStrategy.execute(context);
|
|
2256
2144
|
}
|
|
2257
2145
|
const nearStrategy = strategies.find((s) => s instanceof NearStrategy);
|
|
2258
2146
|
if (nearStrategy && nearStrategy.canHandle(context)) {
|
|
2259
|
-
console.log(`[
|
|
2147
|
+
console.log(`[TransferManager] Routing to: ${nearStrategy.name} (Near)`);
|
|
2260
2148
|
return nearStrategy.execute(context);
|
|
2261
2149
|
}
|
|
2262
|
-
const gaslessStrategy = strategies.find((s) => s instanceof GaslessStrategy);
|
|
2263
|
-
if (gaslessStrategy && gaslessStrategy.canHandle(context)) {
|
|
2264
|
-
console.log(`[BridgeManager] Routing to: ${gaslessStrategy.name}`);
|
|
2265
|
-
return gaslessStrategy.execute(context);
|
|
2266
|
-
}
|
|
2267
2150
|
return {
|
|
2268
2151
|
success: false,
|
|
2269
|
-
errorReason: `No suitable
|
|
2152
|
+
errorReason: `No suitable transfer strategy found for ${context.sourceChain} -> ${context.destChain}`
|
|
2270
2153
|
};
|
|
2271
2154
|
}
|
|
2272
2155
|
};
|
|
@@ -2274,15 +2157,14 @@ var BridgeManager = class {
|
|
|
2274
2157
|
exports.AccountAbstraction = AccountAbstraction;
|
|
2275
2158
|
exports.BASE_MAINNET = BASE_MAINNET;
|
|
2276
2159
|
exports.BASE_SEPOLIA = BASE_SEPOLIA;
|
|
2277
|
-
exports.BridgeManager = BridgeManager;
|
|
2278
2160
|
exports.BundlerClient = BundlerClient;
|
|
2279
2161
|
exports.CCTPStrategy = CCTPStrategy;
|
|
2280
2162
|
exports.CHAIN_CONFIGS = CHAIN_CONFIGS;
|
|
2163
|
+
exports.CHAIN_ID_TO_KEY = CHAIN_ID_TO_KEY;
|
|
2281
2164
|
exports.GNOSIS_MAINNET = GNOSIS_MAINNET;
|
|
2282
|
-
exports.GaslessStrategy = GaslessStrategy;
|
|
2283
2165
|
exports.NearStrategy = NearStrategy;
|
|
2284
2166
|
exports.OPTIMISM_MAINNET = OPTIMISM_MAINNET;
|
|
2285
|
-
exports.
|
|
2167
|
+
exports.TransferManager = TransferManager;
|
|
2286
2168
|
exports.entryPointAbi = entryPointAbi;
|
|
2287
2169
|
exports.erc20Abi = erc20Abi;
|
|
2288
2170
|
exports.smartAccountAbi = smartAccountAbi;
|