@1llet.xyz/erc4337-gasless-sdk 0.4.62 → 0.4.64
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 +76 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -512,13 +512,16 @@ declare class UniswapService {
|
|
|
512
512
|
private publicClient;
|
|
513
513
|
constructor();
|
|
514
514
|
/**
|
|
515
|
-
* Get
|
|
516
|
-
*
|
|
515
|
+
* Get PoolKey for USDC/WETH on Base V4
|
|
516
|
+
* Assuming standard fee tier 0.05% (500) and tickSpacing 10
|
|
517
517
|
*/
|
|
518
|
-
|
|
518
|
+
private getPoolKey;
|
|
519
519
|
/**
|
|
520
|
-
*
|
|
521
|
-
|
|
520
|
+
* Quote USDC needed for exact ETH output using Uniswap V4
|
|
521
|
+
*/
|
|
522
|
+
quoteUSDCForETH(amountOutETH: bigint): Promise<bigint>;
|
|
523
|
+
/**
|
|
524
|
+
* Build tx data for swapping USDC -> ETH using Universal Router (V4)
|
|
522
525
|
*/
|
|
523
526
|
buildSwapData(recipient: Address, amountOutETH: bigint, maxAmountInUSDC: bigint): Hex;
|
|
524
527
|
getRouterAddress(): Address;
|
package/dist/index.d.ts
CHANGED
|
@@ -512,13 +512,16 @@ declare class UniswapService {
|
|
|
512
512
|
private publicClient;
|
|
513
513
|
constructor();
|
|
514
514
|
/**
|
|
515
|
-
* Get
|
|
516
|
-
*
|
|
515
|
+
* Get PoolKey for USDC/WETH on Base V4
|
|
516
|
+
* Assuming standard fee tier 0.05% (500) and tickSpacing 10
|
|
517
517
|
*/
|
|
518
|
-
|
|
518
|
+
private getPoolKey;
|
|
519
519
|
/**
|
|
520
|
-
*
|
|
521
|
-
|
|
520
|
+
* Quote USDC needed for exact ETH output using Uniswap V4
|
|
521
|
+
*/
|
|
522
|
+
quoteUSDCForETH(amountOutETH: bigint): Promise<bigint>;
|
|
523
|
+
/**
|
|
524
|
+
* Build tx data for swapping USDC -> ETH using Universal Router (V4)
|
|
522
525
|
*/
|
|
523
526
|
buildSwapData(recipient: Address, amountOutETH: bigint, maxAmountInUSDC: bigint): Hex;
|
|
524
527
|
getRouterAddress(): Address;
|
package/dist/index.js
CHANGED
|
@@ -2851,15 +2851,17 @@ init_TransferManager();
|
|
|
2851
2851
|
init_near();
|
|
2852
2852
|
init_cctp2();
|
|
2853
2853
|
init_stargate();
|
|
2854
|
-
var
|
|
2855
|
-
var
|
|
2854
|
+
var UNIVERSAL_ROUTER = "0x95273d871c8156636e114b63797d78D7E1720d81";
|
|
2855
|
+
var QUOTER_V4 = "0x0d5e0f97300c3b313360b376b539d48b121532048d";
|
|
2856
2856
|
var USDC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
2857
2857
|
var WETH_ADDRESS = "0x4200000000000000000000000000000000000006";
|
|
2858
|
-
var
|
|
2859
|
-
|
|
2858
|
+
var V4_SWAP_COMMAND = "0x10";
|
|
2859
|
+
var UNWRAP_WETH_COMMAND = "0x0c";
|
|
2860
|
+
var QUOTER_V4_ABI = viem.parseAbi([
|
|
2861
|
+
"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)"
|
|
2860
2862
|
]);
|
|
2861
|
-
var
|
|
2862
|
-
"function
|
|
2863
|
+
var UNIVERSAL_ROUTER_ABI = viem.parseAbi([
|
|
2864
|
+
"function execute(bytes calldata commands, bytes[] calldata inputs, uint256 deadline) external payable"
|
|
2863
2865
|
]);
|
|
2864
2866
|
var UniswapService = class {
|
|
2865
2867
|
constructor() {
|
|
@@ -2870,65 +2872,90 @@ var UniswapService = class {
|
|
|
2870
2872
|
});
|
|
2871
2873
|
}
|
|
2872
2874
|
/**
|
|
2873
|
-
* Get
|
|
2874
|
-
*
|
|
2875
|
+
* Get PoolKey for USDC/WETH on Base V4
|
|
2876
|
+
* Assuming standard fee tier 0.05% (500) and tickSpacing 10
|
|
2875
2877
|
*/
|
|
2876
|
-
|
|
2878
|
+
getPoolKey() {
|
|
2879
|
+
const isUSDC0 = USDC_ADDRESS.toLowerCase() < WETH_ADDRESS.toLowerCase();
|
|
2880
|
+
const currency0 = isUSDC0 ? USDC_ADDRESS : WETH_ADDRESS;
|
|
2881
|
+
const currency1 = isUSDC0 ? WETH_ADDRESS : USDC_ADDRESS;
|
|
2882
|
+
return {
|
|
2883
|
+
currency0,
|
|
2884
|
+
currency1,
|
|
2885
|
+
fee: 500,
|
|
2886
|
+
// 0.05%
|
|
2887
|
+
tickSpacing: 10,
|
|
2888
|
+
hooks: "0x0000000000000000000000000000000000000000"
|
|
2889
|
+
};
|
|
2890
|
+
}
|
|
2891
|
+
/**
|
|
2892
|
+
* Quote USDC needed for exact ETH output using Uniswap V4
|
|
2893
|
+
*/
|
|
2894
|
+
async quoteUSDCForETH(amountOutETH) {
|
|
2877
2895
|
try {
|
|
2878
|
-
const
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
fee: 500,
|
|
2883
|
-
sqrtPriceLimitX96: 0n
|
|
2884
|
-
};
|
|
2896
|
+
const key = this.getPoolKey();
|
|
2897
|
+
const isUSDC0 = USDC_ADDRESS.toLowerCase() < WETH_ADDRESS.toLowerCase();
|
|
2898
|
+
const zeroForOne = isUSDC0;
|
|
2899
|
+
const amountParam = -amountOutETH;
|
|
2885
2900
|
const result = await this.publicClient.readContract({
|
|
2886
|
-
address:
|
|
2887
|
-
abi:
|
|
2901
|
+
address: QUOTER_V4,
|
|
2902
|
+
abi: QUOTER_V4_ABI,
|
|
2888
2903
|
functionName: "quoteExactOutputSingle",
|
|
2889
|
-
args: [
|
|
2904
|
+
args: [
|
|
2905
|
+
key,
|
|
2906
|
+
{
|
|
2907
|
+
zeroForOne,
|
|
2908
|
+
amount: amountParam,
|
|
2909
|
+
// Negative for Exact Output
|
|
2910
|
+
sqrtPriceLimitX96: 0n
|
|
2911
|
+
},
|
|
2912
|
+
"0x"
|
|
2913
|
+
// No hook data
|
|
2914
|
+
]
|
|
2890
2915
|
});
|
|
2891
2916
|
const amountIn = result[0];
|
|
2892
2917
|
return amountIn * 105n / 100n;
|
|
2893
2918
|
} catch (e) {
|
|
2894
|
-
console.error("Quote failed", e);
|
|
2895
|
-
throw new Error("Failed to quote USDC for ETH swap");
|
|
2919
|
+
console.error("V4 Quote failed", e);
|
|
2920
|
+
throw new Error("Failed to quote USDC for ETH swap on Uniswap V4");
|
|
2896
2921
|
}
|
|
2897
2922
|
}
|
|
2898
2923
|
/**
|
|
2899
|
-
* Build tx data for swapping USDC -> ETH
|
|
2900
|
-
* Uses SwapRouter02.exactOutputSingle + unwrapWETH9
|
|
2924
|
+
* Build tx data for swapping USDC -> ETH using Universal Router (V4)
|
|
2901
2925
|
*/
|
|
2902
2926
|
buildSwapData(recipient, amountOutETH, maxAmountInUSDC) {
|
|
2903
|
-
const
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
+
const key = this.getPoolKey();
|
|
2928
|
+
const isUSDC0 = USDC_ADDRESS.toLowerCase() < WETH_ADDRESS.toLowerCase();
|
|
2929
|
+
const zeroForOne = isUSDC0;
|
|
2930
|
+
const swapInput = viem.encodeAbiParameters(
|
|
2931
|
+
viem.parseAbiParameters("((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, bool zeroForOne, int128 amountSpecified, uint160 sqrtPriceLimitX96, bytes hookData)"),
|
|
2932
|
+
[
|
|
2933
|
+
key,
|
|
2934
|
+
zeroForOne,
|
|
2935
|
+
-amountOutETH,
|
|
2936
|
+
// exact output
|
|
2937
|
+
0n,
|
|
2938
|
+
// no price limit
|
|
2939
|
+
"0x"
|
|
2940
|
+
// no hook data
|
|
2941
|
+
]
|
|
2942
|
+
);
|
|
2943
|
+
const unwrapInput = viem.encodeAbiParameters(
|
|
2944
|
+
viem.parseAbiParameters("address, uint256"),
|
|
2945
|
+
[recipient, amountOutETH]
|
|
2946
|
+
// Unwrap at least the output amount.
|
|
2947
|
+
);
|
|
2948
|
+
const commands = V4_SWAP_COMMAND + UNWRAP_WETH_COMMAND.substring(2);
|
|
2949
|
+
const inputs = [swapInput, unwrapInput];
|
|
2950
|
+
const deadline = BigInt(Math.floor(Date.now() / 1e3) + 300);
|
|
2951
|
+
return viem.encodeFunctionData({
|
|
2952
|
+
abi: UNIVERSAL_ROUTER_ABI,
|
|
2953
|
+
functionName: "execute",
|
|
2954
|
+
args: [commands, inputs, deadline]
|
|
2927
2955
|
});
|
|
2928
|
-
return multicallCalldata;
|
|
2929
2956
|
}
|
|
2930
2957
|
getRouterAddress() {
|
|
2931
|
-
return
|
|
2958
|
+
return UNIVERSAL_ROUTER;
|
|
2932
2959
|
}
|
|
2933
2960
|
getUSDCAddress() {
|
|
2934
2961
|
return USDC_ADDRESS;
|