@1llet.xyz/erc4337-gasless-sdk 0.4.27 → 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 +2 -15
- package/dist/index.d.ts +2 -15
- package/dist/index.js +21 -156
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -155
- 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...`);
|
|
@@ -2222,65 +2108,46 @@ async function getNearQuote(sourceChain, destChain, amount, destToken, sourceTok
|
|
|
2222
2108
|
};
|
|
2223
2109
|
}
|
|
2224
2110
|
|
|
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 {
|
|
2111
|
+
// src/services/TransferManager.ts
|
|
2112
|
+
var TransferManager = class {
|
|
2244
2113
|
constructor() {
|
|
2245
2114
|
this.strategies = [
|
|
2246
|
-
new StandardBridgeStrategy(),
|
|
2247
|
-
new GaslessStrategy(),
|
|
2248
2115
|
new CCTPStrategy(),
|
|
2249
2116
|
new NearStrategy()
|
|
2250
2117
|
];
|
|
2251
2118
|
}
|
|
2252
|
-
getStrategy(context) {
|
|
2253
|
-
return this.strategies.find((strategy) => strategy.canHandle(context));
|
|
2254
|
-
}
|
|
2255
2119
|
async execute(context) {
|
|
2256
2120
|
if (context.sourceChain === context.destChain && context.sourceToken === context.destToken) {
|
|
2257
|
-
console.log(`[
|
|
2258
|
-
|
|
2259
|
-
|
|
2121
|
+
console.log(`[TransferManager] Same Chain detected. Signal Direct Transfer.`);
|
|
2122
|
+
return {
|
|
2123
|
+
success: true,
|
|
2124
|
+
transactionHash: "DIRECT_TRANSFER_REQUIRED",
|
|
2125
|
+
data: {
|
|
2126
|
+
action: "DIRECT_TRANSFER",
|
|
2127
|
+
amount: context.amount,
|
|
2128
|
+
token: context.sourceToken,
|
|
2129
|
+
recipient: context.recipient
|
|
2130
|
+
}
|
|
2131
|
+
};
|
|
2260
2132
|
}
|
|
2261
2133
|
const strategies = this.strategies;
|
|
2262
2134
|
const cctpStrategy = strategies.find((s) => s instanceof CCTPStrategy);
|
|
2263
2135
|
if (cctpStrategy && cctpStrategy.canHandle(context)) {
|
|
2264
|
-
console.log(`[
|
|
2136
|
+
console.log(`[TransferManager] Routing to: ${cctpStrategy.name} (CCTP)`);
|
|
2265
2137
|
return cctpStrategy.execute(context);
|
|
2266
2138
|
}
|
|
2267
2139
|
const nearStrategy = strategies.find((s) => s instanceof NearStrategy);
|
|
2268
2140
|
if (nearStrategy && nearStrategy.canHandle(context)) {
|
|
2269
|
-
console.log(`[
|
|
2141
|
+
console.log(`[TransferManager] Routing to: ${nearStrategy.name} (Near)`);
|
|
2270
2142
|
return nearStrategy.execute(context);
|
|
2271
2143
|
}
|
|
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
2144
|
return {
|
|
2278
2145
|
success: false,
|
|
2279
|
-
errorReason: `No suitable
|
|
2146
|
+
errorReason: `No suitable transfer strategy found for ${context.sourceChain} -> ${context.destChain}`
|
|
2280
2147
|
};
|
|
2281
2148
|
}
|
|
2282
2149
|
};
|
|
2283
2150
|
|
|
2284
|
-
export { AccountAbstraction, BASE_MAINNET, BASE_SEPOLIA,
|
|
2151
|
+
export { AccountAbstraction, BASE_MAINNET, BASE_SEPOLIA, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, GNOSIS_MAINNET, NearStrategy, OPTIMISM_MAINNET, TransferManager, entryPointAbi, erc20Abi, smartAccountAbi };
|
|
2285
2152
|
//# sourceMappingURL=index.mjs.map
|
|
2286
2153
|
//# sourceMappingURL=index.mjs.map
|