@1llet.xyz/erc4337-gasless-sdk 0.4.39 → 0.4.41
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 +18 -1
- package/dist/index.d.ts +18 -1
- package/dist/index.js +108 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +109 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { gnosis, optimism, baseSepolia, base, avalanche, worldchain, monad, poly
|
|
|
4
4
|
import { createPublicClient, http, createWalletClient, decodeErrorResult, maxUint256, encodeFunctionData, encodeAbiParameters, keccak256, padHex } from 'viem';
|
|
5
5
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
6
6
|
import axios from 'axios';
|
|
7
|
-
import { OpenAPI,
|
|
7
|
+
import { OpenAPI, OneClickService, QuoteRequest } from '@defuse-protocol/one-click-sdk-typescript';
|
|
8
8
|
|
|
9
9
|
var __defProp = Object.defineProperty;
|
|
10
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -162,14 +162,24 @@ var init_StellarService = __esm({
|
|
|
162
162
|
// src/constants/facilitator.ts
|
|
163
163
|
var facilitator_exports = {};
|
|
164
164
|
__export(facilitator_exports, {
|
|
165
|
+
DUMMY_EVM_ADDRESS: () => DUMMY_EVM_ADDRESS,
|
|
166
|
+
DUMMY_STELLAR_ADDRESS: () => DUMMY_STELLAR_ADDRESS,
|
|
165
167
|
FACILITATOR_NETWORKS: () => FACILITATOR_NETWORKS,
|
|
168
|
+
PlatformFees: () => PlatformFees,
|
|
166
169
|
calculateFee: () => calculateFee
|
|
167
170
|
});
|
|
168
|
-
var calculateFee, FACILITATOR_NETWORKS;
|
|
171
|
+
var PlatformFees, DUMMY_EVM_ADDRESS, DUMMY_STELLAR_ADDRESS, calculateFee, FACILITATOR_NETWORKS;
|
|
169
172
|
var init_facilitator = __esm({
|
|
170
173
|
"src/constants/facilitator.ts"() {
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
PlatformFees = {
|
|
175
|
+
DEV: 0,
|
|
176
|
+
EVM_TO_OTHER: 0.02,
|
|
177
|
+
DEFAULT: 0.02
|
|
178
|
+
};
|
|
179
|
+
DUMMY_EVM_ADDRESS = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
180
|
+
DUMMY_STELLAR_ADDRESS = "GB7BDSZU2Y27LYNLJLVEGW5TIVYQ6362DS5QZ5F6S27S227227227AAA";
|
|
181
|
+
calculateFee = (isDev = false) => {
|
|
182
|
+
return isDev ? PlatformFees.DEV : PlatformFees.DEFAULT;
|
|
173
183
|
};
|
|
174
184
|
FACILITATOR_NETWORKS = {
|
|
175
185
|
Base: {
|
|
@@ -1959,7 +1969,8 @@ async function executeCCTPBridge(sourceChain, amount, crossChainConfig, facilita
|
|
|
1959
1969
|
transport: http(networkConfig.rpcUrl)
|
|
1960
1970
|
});
|
|
1961
1971
|
const amountBigInt = BigInt(Math.floor(parseFloat(amount) * 1e6));
|
|
1962
|
-
const
|
|
1972
|
+
const feeRaw = calculateFee();
|
|
1973
|
+
const fee = BigInt(Math.floor(feeRaw * 1e6));
|
|
1963
1974
|
const minRequired = fee * BigInt(2);
|
|
1964
1975
|
if (amountBigInt <= minRequired) {
|
|
1965
1976
|
return {
|
|
@@ -2113,6 +2124,7 @@ async function executeCCTPBridge(sourceChain, amount, crossChainConfig, facilita
|
|
|
2113
2124
|
};
|
|
2114
2125
|
}
|
|
2115
2126
|
init_StellarService();
|
|
2127
|
+
init_facilitator();
|
|
2116
2128
|
OpenAPI.BASE = "https://1click.chaindefuser.com";
|
|
2117
2129
|
var NearStrategy = class {
|
|
2118
2130
|
constructor() {
|
|
@@ -2158,6 +2170,31 @@ var NearStrategy = class {
|
|
|
2158
2170
|
const stellarService = new StellarService2();
|
|
2159
2171
|
const tx = await stellarService.server.transactions().transaction(depositTxHash).call();
|
|
2160
2172
|
if (tx.successful) {
|
|
2173
|
+
const operations = await stellarService.server.operations().forTransaction(depositTxHash).call();
|
|
2174
|
+
const paymentOp = operations.records.find((op) => op.type === "payment" || op.type === "path_payment_strict_send" || op.type === "path_payment_strict_receive");
|
|
2175
|
+
let depositAddress = "";
|
|
2176
|
+
let memo = "";
|
|
2177
|
+
if (paymentOp) {
|
|
2178
|
+
depositAddress = paymentOp.to || paymentOp.funder || "";
|
|
2179
|
+
}
|
|
2180
|
+
if (tx.memo_type === "text" || tx.memo_type === "id") {
|
|
2181
|
+
memo = tx.memo || "";
|
|
2182
|
+
}
|
|
2183
|
+
if (depositAddress) {
|
|
2184
|
+
console.log(`[NearStrategy] Submitting deposit to 1-Click: ${depositTxHash} -> ${depositAddress} (Memo: ${memo})`);
|
|
2185
|
+
try {
|
|
2186
|
+
await OneClickService.submitDepositTx({
|
|
2187
|
+
txHash: depositTxHash,
|
|
2188
|
+
depositAddress,
|
|
2189
|
+
memo: memo || void 0
|
|
2190
|
+
});
|
|
2191
|
+
console.log("[NearStrategy] Deposit submitted successfully.");
|
|
2192
|
+
} catch (e) {
|
|
2193
|
+
console.error("[NearStrategy] Failed to submit deposit to 1-Click:", e.message);
|
|
2194
|
+
}
|
|
2195
|
+
} else {
|
|
2196
|
+
console.error("[NearStrategy] Could not determine deposit address from Stellar operations.");
|
|
2197
|
+
}
|
|
2161
2198
|
return {
|
|
2162
2199
|
success: true,
|
|
2163
2200
|
transactionHash: depositTxHash,
|
|
@@ -2187,6 +2224,20 @@ var NearStrategy = class {
|
|
|
2187
2224
|
const receipt = await publicClient.waitForTransactionReceipt({ hash: depositTxHash });
|
|
2188
2225
|
console.log(`[NearStrategy] Receipt found. Status: ${receipt.status}`);
|
|
2189
2226
|
if (receipt.status === "success") {
|
|
2227
|
+
const tx = await publicClient.getTransaction({ hash: depositTxHash });
|
|
2228
|
+
const depositAddress = tx.to;
|
|
2229
|
+
if (depositAddress) {
|
|
2230
|
+
console.log(`[NearStrategy] Submitting deposit to 1-Click: ${depositTxHash} -> ${depositAddress}`);
|
|
2231
|
+
try {
|
|
2232
|
+
await OneClickService.submitDepositTx({
|
|
2233
|
+
txHash: depositTxHash,
|
|
2234
|
+
depositAddress
|
|
2235
|
+
});
|
|
2236
|
+
console.log("[NearStrategy] Deposit submitted successfully.");
|
|
2237
|
+
} catch (e) {
|
|
2238
|
+
console.error("[NearStrategy] Failed to submit deposit to 1-Click:", e.message);
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2190
2241
|
return {
|
|
2191
2242
|
success: true,
|
|
2192
2243
|
transactionHash: depositTxHash,
|
|
@@ -2233,7 +2284,7 @@ var NearStrategy = class {
|
|
|
2233
2284
|
}
|
|
2234
2285
|
}
|
|
2235
2286
|
};
|
|
2236
|
-
async function getNearQuote(sourceChain, destChain, amount, destToken, sourceToken, recipient, senderAddress) {
|
|
2287
|
+
async function getNearQuote(sourceChain, destChain, amount, destToken, sourceToken, recipient, senderAddress, options) {
|
|
2237
2288
|
const sourceConfig = NETWORKS[sourceChain];
|
|
2238
2289
|
const destConfig = NETWORKS[destChain];
|
|
2239
2290
|
if (!sourceConfig || !destConfig) {
|
|
@@ -2263,9 +2314,9 @@ async function getNearQuote(sourceChain, destChain, amount, destToken, sourceTok
|
|
|
2263
2314
|
throw new Error("Recipient address is required for NEAR Quote");
|
|
2264
2315
|
}
|
|
2265
2316
|
const refundAddress = senderAddress || recipient;
|
|
2266
|
-
console.log(`[NearService] Requesting Quote: ${sourceChain} -> ${destChain}`, { amount, sourceAsset, destAsset });
|
|
2317
|
+
console.log(`[NearService] Requesting Quote: ${sourceChain} -> ${destChain}`, { amount, sourceAsset, destAsset, options });
|
|
2267
2318
|
const quoteRequest = {
|
|
2268
|
-
dry: false,
|
|
2319
|
+
dry: options?.dry || false,
|
|
2269
2320
|
swapType: QuoteRequest.swapType.EXACT_INPUT,
|
|
2270
2321
|
slippageTolerance: 100,
|
|
2271
2322
|
originAsset: sourceAsset,
|
|
@@ -2277,7 +2328,7 @@ async function getNearQuote(sourceChain, destChain, amount, destToken, sourceTok
|
|
|
2277
2328
|
refundType: QuoteRequest.refundType.ORIGIN_CHAIN,
|
|
2278
2329
|
recipient,
|
|
2279
2330
|
recipientType: QuoteRequest.recipientType.DESTINATION_CHAIN,
|
|
2280
|
-
deadline: new Date(Date.now() +
|
|
2331
|
+
deadline: new Date(Date.now() + 3 * 60 * 1e3).toISOString(),
|
|
2281
2332
|
referral: "1llet",
|
|
2282
2333
|
quoteWaitingTimeMs: 1e4
|
|
2283
2334
|
};
|
|
@@ -2292,6 +2343,54 @@ async function getNearQuote(sourceChain, destChain, amount, destToken, sourceTok
|
|
|
2292
2343
|
amountAtomicNet
|
|
2293
2344
|
};
|
|
2294
2345
|
}
|
|
2346
|
+
async function getNearSimulation(sourceChain, destChain, amount, destToken, sourceToken) {
|
|
2347
|
+
console.log(">>> [Bridge Quote] Simulation Request:", { sourceChain, destChain, amount, destToken, sourceToken });
|
|
2348
|
+
if (!amount || isNaN(parseFloat(amount))) {
|
|
2349
|
+
throw new Error("Invalid amount");
|
|
2350
|
+
}
|
|
2351
|
+
const amountNum = parseFloat(amount);
|
|
2352
|
+
const isDev = process.env.NEXT_PUBLIC_ENVIROMENT === "development" || process.env.NODE_ENV === "development";
|
|
2353
|
+
const usedFee = isDev ? PlatformFees.DEV : PlatformFees.EVM_TO_OTHER;
|
|
2354
|
+
const MIN_AMOUNT = usedFee;
|
|
2355
|
+
const netAmountBridged = (amountNum - usedFee).toFixed(6);
|
|
2356
|
+
if (parseFloat(netAmountBridged) <= 0) {
|
|
2357
|
+
return {
|
|
2358
|
+
success: false,
|
|
2359
|
+
error: `Insufficient amount (${amountNum}) to cover fee (${usedFee})`,
|
|
2360
|
+
minAmount: MIN_AMOUNT
|
|
2361
|
+
};
|
|
2362
|
+
}
|
|
2363
|
+
const sender = sourceChain === "Stellar" ? DUMMY_STELLAR_ADDRESS : DUMMY_EVM_ADDRESS;
|
|
2364
|
+
const recipient = destChain === "Stellar" ? DUMMY_STELLAR_ADDRESS : DUMMY_EVM_ADDRESS;
|
|
2365
|
+
try {
|
|
2366
|
+
const quoteResult = await getNearQuote(
|
|
2367
|
+
sourceChain,
|
|
2368
|
+
destChain,
|
|
2369
|
+
netAmountBridged.toString(),
|
|
2370
|
+
destToken,
|
|
2371
|
+
sourceToken,
|
|
2372
|
+
recipient,
|
|
2373
|
+
sender,
|
|
2374
|
+
{ dry: true }
|
|
2375
|
+
);
|
|
2376
|
+
return {
|
|
2377
|
+
success: true,
|
|
2378
|
+
amountSent: amountNum,
|
|
2379
|
+
protocolFee: usedFee,
|
|
2380
|
+
netAmountBridged: parseFloat(netAmountBridged),
|
|
2381
|
+
// @ts-ignore - access safe property
|
|
2382
|
+
estimatedReceived: quoteResult.quote?.quote?.estimatedOutput || "0",
|
|
2383
|
+
minAmount: MIN_AMOUNT
|
|
2384
|
+
};
|
|
2385
|
+
} catch (error) {
|
|
2386
|
+
console.error(">>> [Bridge Quote] Error:", error);
|
|
2387
|
+
return {
|
|
2388
|
+
success: false,
|
|
2389
|
+
error: error.message || "Unknown quote error",
|
|
2390
|
+
minAmount: MIN_AMOUNT
|
|
2391
|
+
};
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2295
2394
|
|
|
2296
2395
|
// src/services/TransferManager.ts
|
|
2297
2396
|
var TransferManager = class {
|
|
@@ -2333,6 +2432,6 @@ var TransferManager = class {
|
|
|
2333
2432
|
}
|
|
2334
2433
|
};
|
|
2335
2434
|
|
|
2336
|
-
export { AccountAbstraction, BASE_MAINNET, BASE_SEPOLIA2 as BASE_SEPOLIA, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, GNOSIS_MAINNET, NearStrategy, OPTIMISM_MAINNET, STELLAR, STELLAR_MAINNET, StellarService, TransferManager, entryPointAbi, erc20Abi, smartAccountAbi };
|
|
2435
|
+
export { AccountAbstraction, BASE_MAINNET, BASE_SEPOLIA2 as BASE_SEPOLIA, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, GNOSIS_MAINNET, NearStrategy, OPTIMISM_MAINNET, STELLAR, STELLAR_MAINNET, StellarService, TransferManager, entryPointAbi, erc20Abi, getNearSimulation, smartAccountAbi };
|
|
2337
2436
|
//# sourceMappingURL=index.mjs.map
|
|
2338
2437
|
//# sourceMappingURL=index.mjs.map
|