@1llet.xyz/erc4337-gasless-sdk 0.4.66 → 0.4.68
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 +4 -9
- package/dist/index.d.ts +4 -9
- package/dist/index.js +38 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -82
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { monad, unichain, arbitrum, polygon, bsc, avalanche, optimism, gnosis, b
|
|
|
2
2
|
import * as StellarSdk from 'stellar-sdk';
|
|
3
3
|
import { Networks } from 'stellar-sdk';
|
|
4
4
|
import axios from 'axios';
|
|
5
|
-
import { parseAbi, createPublicClient, http,
|
|
5
|
+
import { parseAbi, createPublicClient, http, encodeFunctionData, createWalletClient, decodeErrorResult, encodeAbiParameters, keccak256, maxUint256, padHex } from 'viem';
|
|
6
6
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
7
7
|
import { OpenAPI, OneClickService, QuoteRequest } from '@defuse-protocol/one-click-sdk-typescript';
|
|
8
8
|
|
|
@@ -2827,117 +2827,74 @@ init_TransferManager();
|
|
|
2827
2827
|
init_near();
|
|
2828
2828
|
init_cctp2();
|
|
2829
2829
|
init_stargate();
|
|
2830
|
-
var
|
|
2831
|
-
var
|
|
2830
|
+
var SWAP_ROUTER_02 = "0x2626664c2603336E57B271c5C0b26F421741e481";
|
|
2831
|
+
var QUOTER_V2 = "0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a";
|
|
2832
2832
|
var USDC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
2833
2833
|
var WETH_ADDRESS = "0x4200000000000000000000000000000000000006";
|
|
2834
|
-
var
|
|
2835
|
-
|
|
2836
|
-
var QUOTER_V4_ABI = parseAbi([
|
|
2837
|
-
"function quoteExactOutputSingle((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, (bool zeroForOne, int128 amount, uint160 sqrtPriceLimitX96) params, bytes hookData) external returns (uint256 amountIn, uint256 gasEstimate)"
|
|
2834
|
+
var QUOTER_ABI = parseAbi([
|
|
2835
|
+
"function quoteExactOutputSingle(tuple(address tokenIn, address tokenOut, uint256 amount, uint24 fee, uint160 sqrtPriceLimitX96) params) external returns (uint256 amountIn, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)"
|
|
2838
2836
|
]);
|
|
2839
|
-
var
|
|
2840
|
-
"function
|
|
2837
|
+
var ROUTER_ABI = parseAbi([
|
|
2838
|
+
"function exactOutputSingle(tuple(address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 amountOut, uint256 amountInMaximum, uint160 sqrtPriceLimitX96) params) external payable returns (uint256 amountIn)"
|
|
2841
2839
|
]);
|
|
2842
2840
|
var UniswapService = class {
|
|
2843
|
-
constructor() {
|
|
2841
|
+
constructor(rpcUrl) {
|
|
2844
2842
|
this.publicClient = createPublicClient({
|
|
2845
|
-
|
|
2846
|
-
transport: http("https://mainnet.base.org")
|
|
2847
|
-
// Default public RPC
|
|
2843
|
+
transport: http(rpcUrl)
|
|
2848
2844
|
});
|
|
2849
2845
|
}
|
|
2850
2846
|
/**
|
|
2851
|
-
*
|
|
2852
|
-
* Assuming standard fee tier 0.05% (500) and tickSpacing 10
|
|
2853
|
-
*/
|
|
2854
|
-
getPoolKey() {
|
|
2855
|
-
const isUSDC0 = USDC_ADDRESS.toLowerCase() < WETH_ADDRESS.toLowerCase();
|
|
2856
|
-
const currency0 = isUSDC0 ? USDC_ADDRESS : WETH_ADDRESS;
|
|
2857
|
-
const currency1 = isUSDC0 ? WETH_ADDRESS : USDC_ADDRESS;
|
|
2858
|
-
return {
|
|
2859
|
-
currency0,
|
|
2860
|
-
currency1,
|
|
2861
|
-
fee: 500,
|
|
2862
|
-
// 0.05%
|
|
2863
|
-
tickSpacing: 10,
|
|
2864
|
-
hooks: "0x0000000000000000000000000000000000000000"
|
|
2865
|
-
};
|
|
2866
|
-
}
|
|
2867
|
-
/**
|
|
2868
|
-
* Quote USDC needed for exact ETH output using Uniswap V4
|
|
2847
|
+
* Quote USDC needed for exact ETH output using Uniswap V3
|
|
2869
2848
|
*/
|
|
2870
2849
|
async quoteUSDCForETH(amountOutETH) {
|
|
2871
2850
|
try {
|
|
2872
|
-
const key = this.getPoolKey();
|
|
2873
|
-
const isUSDC0 = USDC_ADDRESS.toLowerCase() < WETH_ADDRESS.toLowerCase();
|
|
2874
|
-
const zeroForOne = isUSDC0;
|
|
2875
|
-
const amountParam = -amountOutETH;
|
|
2876
2851
|
const result = await this.publicClient.readContract({
|
|
2877
|
-
address:
|
|
2878
|
-
abi:
|
|
2852
|
+
address: QUOTER_V2,
|
|
2853
|
+
abi: QUOTER_ABI,
|
|
2879
2854
|
functionName: "quoteExactOutputSingle",
|
|
2880
|
-
args: [
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
"0x"
|
|
2889
|
-
// No hook data
|
|
2890
|
-
]
|
|
2855
|
+
args: [{
|
|
2856
|
+
tokenIn: USDC_ADDRESS,
|
|
2857
|
+
tokenOut: WETH_ADDRESS,
|
|
2858
|
+
amount: amountOutETH,
|
|
2859
|
+
fee: 500,
|
|
2860
|
+
// 0.05%
|
|
2861
|
+
sqrtPriceLimitX96: 0n
|
|
2862
|
+
}]
|
|
2891
2863
|
});
|
|
2892
2864
|
const amountIn = result[0];
|
|
2893
2865
|
return amountIn * 105n / 100n;
|
|
2894
|
-
} catch (
|
|
2895
|
-
console.error("
|
|
2896
|
-
throw new Error(
|
|
2866
|
+
} catch (error) {
|
|
2867
|
+
console.error("Failed to quote USDC for ETH swap on Uniswap V3", error);
|
|
2868
|
+
throw new Error(`Failed to quote USDC for ETH swap on Uniswap V3`);
|
|
2897
2869
|
}
|
|
2898
2870
|
}
|
|
2899
2871
|
/**
|
|
2900
|
-
* Build tx data for swapping USDC -> ETH using
|
|
2872
|
+
* Build tx data for swapping USDC -> ETH using Uniswap V3 SwapRouter02
|
|
2901
2873
|
*/
|
|
2902
|
-
buildSwapData(recipient,
|
|
2903
|
-
const key = this.getPoolKey();
|
|
2904
|
-
const isUSDC0 = USDC_ADDRESS.toLowerCase() < WETH_ADDRESS.toLowerCase();
|
|
2905
|
-
const zeroForOne = isUSDC0;
|
|
2906
|
-
const swapInput = encodeAbiParameters(
|
|
2907
|
-
parseAbiParameters("((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, bool zeroForOne, int128 amountSpecified, uint160 sqrtPriceLimitX96, bytes hookData)"),
|
|
2908
|
-
[
|
|
2909
|
-
key,
|
|
2910
|
-
zeroForOne,
|
|
2911
|
-
-amountOutETH,
|
|
2912
|
-
// exact output
|
|
2913
|
-
0n,
|
|
2914
|
-
// no price limit
|
|
2915
|
-
"0x"
|
|
2916
|
-
// no hook data
|
|
2917
|
-
]
|
|
2918
|
-
);
|
|
2919
|
-
const unwrapInput = encodeAbiParameters(
|
|
2920
|
-
parseAbiParameters("address, uint256"),
|
|
2921
|
-
[recipient, amountOutETH]
|
|
2922
|
-
// Unwrap at least the output amount.
|
|
2923
|
-
);
|
|
2924
|
-
const commands = V4_SWAP_COMMAND + UNWRAP_WETH_COMMAND.substring(2);
|
|
2925
|
-
const inputs = [swapInput, unwrapInput];
|
|
2926
|
-
const deadline = BigInt(Math.floor(Date.now() / 1e3) + 300);
|
|
2874
|
+
buildSwapData(recipient, amountInMax, amountOutETH) {
|
|
2927
2875
|
return encodeFunctionData({
|
|
2928
|
-
abi:
|
|
2929
|
-
functionName: "
|
|
2930
|
-
args: [
|
|
2876
|
+
abi: ROUTER_ABI,
|
|
2877
|
+
functionName: "exactOutputSingle",
|
|
2878
|
+
args: [{
|
|
2879
|
+
tokenIn: USDC_ADDRESS,
|
|
2880
|
+
tokenOut: WETH_ADDRESS,
|
|
2881
|
+
fee: 500,
|
|
2882
|
+
// 0.05%
|
|
2883
|
+
recipient,
|
|
2884
|
+
amountOut: amountOutETH,
|
|
2885
|
+
amountInMaximum: amountInMax,
|
|
2886
|
+
sqrtPriceLimitX96: 0n
|
|
2887
|
+
}]
|
|
2931
2888
|
});
|
|
2932
2889
|
}
|
|
2933
2890
|
getRouterAddress() {
|
|
2934
|
-
return
|
|
2891
|
+
return SWAP_ROUTER_02;
|
|
2935
2892
|
}
|
|
2936
2893
|
getUSDCAddress() {
|
|
2937
2894
|
return USDC_ADDRESS;
|
|
2938
2895
|
}
|
|
2939
2896
|
};
|
|
2940
|
-
var uniswapService = new UniswapService();
|
|
2897
|
+
var uniswapService = new UniswapService("https://mainnet.base.org");
|
|
2941
2898
|
|
|
2942
2899
|
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, StargateStrategy, StellarService, TransferManager, UniswapService, entryPointAbi, erc20Abi, getNearSimulation, getStargateSimulation, smartAccountAbi, uniswapService };
|
|
2943
2900
|
//# sourceMappingURL=index.mjs.map
|