four-flap-meme-sdk 1.3.99 → 1.4.1
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/dex/direct-router.d.ts +4 -0
- package/dist/dex/direct-router.js +23 -19
- package/package.json +1 -1
|
@@ -55,6 +55,7 @@ export interface DirectV2BuyParams {
|
|
|
55
55
|
routerAddress: string;
|
|
56
56
|
quoteToken?: string;
|
|
57
57
|
quoteTokenDecimals?: number;
|
|
58
|
+
startNonces?: number[];
|
|
58
59
|
config: DirectRouterSignConfig;
|
|
59
60
|
}
|
|
60
61
|
export interface DirectV2SellParams {
|
|
@@ -62,6 +63,7 @@ export interface DirectV2SellParams {
|
|
|
62
63
|
privateKeys: string[];
|
|
63
64
|
sellPercentages?: number[];
|
|
64
65
|
sellAmounts?: string[];
|
|
66
|
+
startNonces?: number[];
|
|
65
67
|
tokenAddress: string;
|
|
66
68
|
tokenDecimals?: number;
|
|
67
69
|
routerAddress: string;
|
|
@@ -77,6 +79,7 @@ export interface DirectV3BuyParams {
|
|
|
77
79
|
fee: number;
|
|
78
80
|
quoteToken?: string;
|
|
79
81
|
quoteTokenDecimals?: number;
|
|
82
|
+
startNonces?: number[];
|
|
80
83
|
config: DirectRouterSignConfig;
|
|
81
84
|
}
|
|
82
85
|
export interface DirectV3SellParams {
|
|
@@ -89,6 +92,7 @@ export interface DirectV3SellParams {
|
|
|
89
92
|
routerAddress: string;
|
|
90
93
|
fee: number;
|
|
91
94
|
quoteToken?: string;
|
|
95
|
+
startNonces?: number[];
|
|
92
96
|
config: DirectRouterSignConfig;
|
|
93
97
|
}
|
|
94
98
|
export interface DirectRouterResult {
|
|
@@ -666,7 +666,7 @@ function isDYORSwap(chain, routerAddress) {
|
|
|
666
666
|
* V2 批量买入(直接调用 Router)
|
|
667
667
|
*/
|
|
668
668
|
export async function directV2BatchBuy(params) {
|
|
669
|
-
const { chain, privateKeys, buyAmounts, tokenAddress, routerAddress, quoteToken, quoteTokenDecimals = 18, config, } = params;
|
|
669
|
+
const { chain, privateKeys, buyAmounts, tokenAddress, routerAddress, quoteToken, quoteTokenDecimals = 18, startNonces, config, } = params;
|
|
670
670
|
if (privateKeys.length !== buyAmounts.length) {
|
|
671
671
|
throw new Error('privateKeys 和 buyAmounts 长度必须相同');
|
|
672
672
|
}
|
|
@@ -676,10 +676,11 @@ export async function directV2BatchBuy(params) {
|
|
|
676
676
|
const wrappedNative = getWrappedNative(chain);
|
|
677
677
|
// 创建钱包
|
|
678
678
|
const wallets = privateKeys.map(pk => new Wallet(pk, provider));
|
|
679
|
-
|
|
680
|
-
// ✅ 性能优化:并行获取 nonce 和 gasPrice(减少 2 轮串行 → 1 轮并行)
|
|
679
|
+
// ✅ 性能优化:如果前端已传入 nonces,则跳过 RPC 获取
|
|
681
680
|
const [nonces, gasPrice] = await Promise.all([
|
|
682
|
-
|
|
681
|
+
startNonces && startNonces.length === wallets.length
|
|
682
|
+
? Promise.resolve(startNonces)
|
|
683
|
+
: new NonceManager(provider).getNextNoncesForWallets(wallets),
|
|
683
684
|
getGasPrice(provider, config)
|
|
684
685
|
]);
|
|
685
686
|
const gasLimit = getGasLimit(config, 250000);
|
|
@@ -808,7 +809,7 @@ export async function directV2BatchBuy(params) {
|
|
|
808
809
|
* V2 批量卖出(直接调用 Router)
|
|
809
810
|
*/
|
|
810
811
|
export async function directV2BatchSell(params) {
|
|
811
|
-
const { chain, privateKeys, sellPercentages, sellAmounts, tokenAddress, tokenDecimals: inputDecimals, routerAddress, quoteToken, config, } = params;
|
|
812
|
+
const { chain, privateKeys, sellPercentages, sellAmounts, tokenAddress, tokenDecimals: inputDecimals, routerAddress, quoteToken, startNonces, config, } = params;
|
|
812
813
|
const chainId = config.chainId || CHAIN_IDS[chain.toUpperCase()] || 56;
|
|
813
814
|
const provider = new JsonRpcProvider(config.rpcUrl, { chainId, name: chain });
|
|
814
815
|
const useNativeOutput = isNativeToken(quoteToken);
|
|
@@ -817,9 +818,8 @@ export async function directV2BatchSell(params) {
|
|
|
817
818
|
const wallets = privateKeys.map(pk => new Wallet(pk, provider));
|
|
818
819
|
// 获取代币合约
|
|
819
820
|
const tokenContract = new Contract(tokenAddress, ERC20_ABI, provider);
|
|
820
|
-
|
|
821
|
-
// ✅
|
|
822
|
-
// ✅ 已移除授权检查(前端应确保已授权)
|
|
821
|
+
// ✅ 性能优化:并行获取所有独立的 RPC 数据
|
|
822
|
+
// ✅ 如果前端已传入 nonces,则跳过 RPC 获取
|
|
823
823
|
const [fetchedDecimals, balances, nonces, gasPrice] = await Promise.all([
|
|
824
824
|
// 1. 获取代币精度(如果未提供)
|
|
825
825
|
inputDecimals !== undefined
|
|
@@ -827,8 +827,10 @@ export async function directV2BatchSell(params) {
|
|
|
827
827
|
: tokenContract.decimals().then((d) => Number(d)).catch(() => 18),
|
|
828
828
|
// 2. 批量获取余额
|
|
829
829
|
Promise.all(wallets.map(w => tokenContract.balanceOf(w.address))),
|
|
830
|
-
// 3. 批量获取 nonce
|
|
831
|
-
|
|
830
|
+
// 3. 批量获取 nonce(如果前端已传入则跳过)
|
|
831
|
+
startNonces && startNonces.length === wallets.length
|
|
832
|
+
? Promise.resolve(startNonces)
|
|
833
|
+
: new NonceManager(provider).getNextNoncesForWallets(wallets),
|
|
832
834
|
// 4. 获取 gas price
|
|
833
835
|
getGasPrice(provider, config)
|
|
834
836
|
]);
|
|
@@ -969,7 +971,7 @@ export async function directV2BatchSell(params) {
|
|
|
969
971
|
* - SwapRouter (旧版 Uniswap V3): exactInputSingle 含 deadline,multicall 不含 deadline
|
|
970
972
|
*/
|
|
971
973
|
export async function directV3BatchBuy(params) {
|
|
972
|
-
const { chain, privateKeys, buyAmounts, tokenAddress, routerAddress, fee, quoteToken, quoteTokenDecimals = 18, config, } = params;
|
|
974
|
+
const { chain, privateKeys, buyAmounts, tokenAddress, routerAddress, fee, quoteToken, quoteTokenDecimals = 18, startNonces, config, } = params;
|
|
973
975
|
if (privateKeys.length !== buyAmounts.length) {
|
|
974
976
|
throw new Error('privateKeys 和 buyAmounts 长度必须相同');
|
|
975
977
|
}
|
|
@@ -981,10 +983,11 @@ export async function directV3BatchBuy(params) {
|
|
|
981
983
|
const useLegacyRouter = isLegacySwapRouter(chain, routerAddress);
|
|
982
984
|
const routerAbi = useLegacyRouter ? V3_ROUTER_LEGACY_ABI : V3_ROUTER02_ABI;
|
|
983
985
|
const wallets = privateKeys.map(pk => new Wallet(pk, provider));
|
|
984
|
-
|
|
985
|
-
// ✅ 性能优化:并行获取 nonce 和 gasPrice
|
|
986
|
+
// ✅ 性能优化:如果前端已传入 nonces,则跳过 RPC 获取
|
|
986
987
|
const [nonces, gasPrice] = await Promise.all([
|
|
987
|
-
|
|
988
|
+
startNonces && startNonces.length === wallets.length
|
|
989
|
+
? Promise.resolve(startNonces)
|
|
990
|
+
: new NonceManager(provider).getNextNoncesForWallets(wallets),
|
|
988
991
|
getGasPrice(provider, config)
|
|
989
992
|
]);
|
|
990
993
|
const gasLimit = getGasLimit(config, 300000);
|
|
@@ -1106,7 +1109,7 @@ export async function directV3BatchBuy(params) {
|
|
|
1106
1109
|
* - SwapRouter (旧版 Uniswap V3): exactInputSingle 含 deadline,multicall 不含 deadline
|
|
1107
1110
|
*/
|
|
1108
1111
|
export async function directV3BatchSell(params) {
|
|
1109
|
-
const { chain, privateKeys, sellPercentages, sellAmounts, tokenAddress, tokenDecimals = 18, routerAddress, fee, quoteToken, config, } = params;
|
|
1112
|
+
const { chain, privateKeys, sellPercentages, sellAmounts, tokenAddress, tokenDecimals = 18, routerAddress, fee, quoteToken, startNonces, config, } = params;
|
|
1110
1113
|
const chainId = config.chainId || CHAIN_IDS[chain.toUpperCase()] || 56;
|
|
1111
1114
|
const provider = new JsonRpcProvider(config.rpcUrl, { chainId, name: chain });
|
|
1112
1115
|
const useNativeOutput = isNativeToken(quoteToken);
|
|
@@ -1116,14 +1119,15 @@ export async function directV3BatchSell(params) {
|
|
|
1116
1119
|
const routerAbi = useLegacyRouter ? V3_ROUTER_LEGACY_ABI : V3_ROUTER02_ABI;
|
|
1117
1120
|
const wallets = privateKeys.map(pk => new Wallet(pk, provider));
|
|
1118
1121
|
const tokenContract = new Contract(tokenAddress, ERC20_ABI, provider);
|
|
1119
|
-
const nonceManager = new NonceManager(provider);
|
|
1120
1122
|
// ✅ 性能优化:并行获取所有独立的 RPC 数据
|
|
1121
|
-
// ✅
|
|
1123
|
+
// ✅ 如果前端已传入 nonces,则跳过 RPC 获取
|
|
1122
1124
|
const [balances, nonces, gasPrice] = await Promise.all([
|
|
1123
1125
|
// 1. 批量获取余额
|
|
1124
1126
|
Promise.all(wallets.map(w => tokenContract.balanceOf(w.address))),
|
|
1125
|
-
// 2. 批量获取 nonce
|
|
1126
|
-
|
|
1127
|
+
// 2. 批量获取 nonce(如果前端已传入则跳过)
|
|
1128
|
+
startNonces && startNonces.length === wallets.length
|
|
1129
|
+
? Promise.resolve(startNonces)
|
|
1130
|
+
: new NonceManager(provider).getNextNoncesForWallets(wallets),
|
|
1127
1131
|
// 3. 获取 gas price
|
|
1128
1132
|
getGasPrice(provider, config)
|
|
1129
1133
|
]);
|