@1llet.xyz/erc4337-gasless-sdk 0.4.61 → 0.4.63
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 +8 -5
- package/dist/index.d.ts +8 -5
- package/dist/index.js +77 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -51
- 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, encodeFunctionData, createWalletClient, decodeErrorResult,
|
|
5
|
+
import { parseAbi, createPublicClient, http, encodeAbiParameters, parseAbiParameters, encodeFunctionData, createWalletClient, decodeErrorResult, 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,15 +2827,17 @@ init_TransferManager();
|
|
|
2827
2827
|
init_near();
|
|
2828
2828
|
init_cctp2();
|
|
2829
2829
|
init_stargate();
|
|
2830
|
-
var
|
|
2831
|
-
var
|
|
2830
|
+
var UNIVERSAL_ROUTER = "0x95273d871c8156636e114b63797d78D7E1720d81";
|
|
2831
|
+
var QUOTER_V4 = "0x0d5e0f97300c3b313360b376b539d48b121532048d";
|
|
2832
2832
|
var USDC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
2833
2833
|
var WETH_ADDRESS = "0x4200000000000000000000000000000000000006";
|
|
2834
|
-
var
|
|
2835
|
-
|
|
2834
|
+
var V4_SWAP_COMMAND = "0x10";
|
|
2835
|
+
var UNWRAP_WETH_COMMAND = "0x0c";
|
|
2836
|
+
var QUOTER_V4_ABI = parseAbi([
|
|
2837
|
+
"function quoteExactOutputSingle(tuple(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, tuple(bool zeroForOne, int128 amount, uint160 sqrtPriceLimitX96) params, bytes hookData) external returns (uint256 amountIn, uint256 gasEstimate)"
|
|
2836
2838
|
]);
|
|
2837
|
-
var
|
|
2838
|
-
"function
|
|
2839
|
+
var UNIVERSAL_ROUTER_ABI = parseAbi([
|
|
2840
|
+
"function execute(bytes calldata commands, bytes[] calldata inputs, uint256 deadline) external payable"
|
|
2839
2841
|
]);
|
|
2840
2842
|
var UniswapService = class {
|
|
2841
2843
|
constructor() {
|
|
@@ -2846,65 +2848,90 @@ var UniswapService = class {
|
|
|
2846
2848
|
});
|
|
2847
2849
|
}
|
|
2848
2850
|
/**
|
|
2849
|
-
* Get
|
|
2850
|
-
*
|
|
2851
|
+
* Get PoolKey for USDC/WETH on Base V4
|
|
2852
|
+
* Assuming standard fee tier 0.05% (500) and tickSpacing 10
|
|
2851
2853
|
*/
|
|
2852
|
-
|
|
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
|
|
2869
|
+
*/
|
|
2870
|
+
async quoteUSDCForETH(amountOutETH) {
|
|
2853
2871
|
try {
|
|
2854
|
-
const
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
fee: 500,
|
|
2859
|
-
sqrtPriceLimitX96: 0n
|
|
2860
|
-
};
|
|
2872
|
+
const key = this.getPoolKey();
|
|
2873
|
+
const isUSDC0 = USDC_ADDRESS.toLowerCase() < WETH_ADDRESS.toLowerCase();
|
|
2874
|
+
const zeroForOne = isUSDC0;
|
|
2875
|
+
const amountParam = -amountOutETH;
|
|
2861
2876
|
const result = await this.publicClient.readContract({
|
|
2862
|
-
address:
|
|
2863
|
-
abi:
|
|
2877
|
+
address: QUOTER_V4,
|
|
2878
|
+
abi: QUOTER_V4_ABI,
|
|
2864
2879
|
functionName: "quoteExactOutputSingle",
|
|
2865
|
-
args: [
|
|
2880
|
+
args: [
|
|
2881
|
+
key,
|
|
2882
|
+
{
|
|
2883
|
+
zeroForOne,
|
|
2884
|
+
amount: amountParam,
|
|
2885
|
+
// Negative for Exact Output
|
|
2886
|
+
sqrtPriceLimitX96: 0n
|
|
2887
|
+
},
|
|
2888
|
+
"0x"
|
|
2889
|
+
// No hook data
|
|
2890
|
+
]
|
|
2866
2891
|
});
|
|
2867
2892
|
const amountIn = result[0];
|
|
2868
|
-
return amountIn *
|
|
2893
|
+
return amountIn * 105n / 100n;
|
|
2869
2894
|
} catch (e) {
|
|
2870
|
-
console.error("Quote failed", e);
|
|
2871
|
-
throw new Error("Failed to quote USDC for ETH swap");
|
|
2895
|
+
console.error("V4 Quote failed", e);
|
|
2896
|
+
throw new Error("Failed to quote USDC for ETH swap on Uniswap V4");
|
|
2872
2897
|
}
|
|
2873
2898
|
}
|
|
2874
2899
|
/**
|
|
2875
|
-
* Build tx data for swapping USDC -> ETH
|
|
2876
|
-
* Uses SwapRouter02.exactOutputSingle + unwrapWETH9
|
|
2900
|
+
* Build tx data for swapping USDC -> ETH using Universal Router (V4)
|
|
2877
2901
|
*/
|
|
2878
2902
|
buildSwapData(recipient, amountOutETH, maxAmountInUSDC) {
|
|
2879
|
-
const
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
+
const key = this.getPoolKey();
|
|
2904
|
+
const isUSDC0 = USDC_ADDRESS.toLowerCase() < WETH_ADDRESS.toLowerCase();
|
|
2905
|
+
const zeroForOne = isUSDC0;
|
|
2906
|
+
const swapInput = encodeAbiParameters(
|
|
2907
|
+
parseAbiParameters("tuple(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);
|
|
2927
|
+
return encodeFunctionData({
|
|
2928
|
+
abi: UNIVERSAL_ROUTER_ABI,
|
|
2929
|
+
functionName: "execute",
|
|
2930
|
+
args: [commands, inputs, deadline]
|
|
2903
2931
|
});
|
|
2904
|
-
return multicallCalldata;
|
|
2905
2932
|
}
|
|
2906
2933
|
getRouterAddress() {
|
|
2907
|
-
return
|
|
2934
|
+
return UNIVERSAL_ROUTER;
|
|
2908
2935
|
}
|
|
2909
2936
|
getUSDCAddress() {
|
|
2910
2937
|
return USDC_ADDRESS;
|