@clonegod/ttd-bsc-common 3.0.6 → 3.0.7
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/utils/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ethers } from "ethers";
|
|
|
2
2
|
import Decimal from "decimal.js";
|
|
3
3
|
export * from './gas_helper';
|
|
4
4
|
export * from './trade_direction';
|
|
5
|
+
export * from './pool_filter';
|
|
5
6
|
export declare const sleep: (ms: number) => Promise<void>;
|
|
6
7
|
export declare const formatPrice: (price: number, precision?: number) => string;
|
|
7
8
|
export declare const formatUnits: (value: ethers.BigNumber, decimals: number) => Decimal;
|
package/dist/utils/index.js
CHANGED
|
@@ -22,6 +22,7 @@ const ethers_1 = require("ethers");
|
|
|
22
22
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
23
23
|
__exportStar(require("./gas_helper"), exports);
|
|
24
24
|
__exportStar(require("./trade_direction"), exports);
|
|
25
|
+
__exportStar(require("./pool_filter"), exports);
|
|
25
26
|
const sleep = (ms) => {
|
|
26
27
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
27
28
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StandardPoolInfoType } from '@clonegod/ttd-core';
|
|
2
|
+
export interface PoolFilterParams {
|
|
3
|
+
poolAddress?: string;
|
|
4
|
+
poolName?: string;
|
|
5
|
+
feeRate?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function buildPoolFilterFromEnv(envArgs: any): PoolFilterParams;
|
|
8
|
+
export declare function filterPools(pools: StandardPoolInfoType[], filter: PoolFilterParams, label?: string): StandardPoolInfoType[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildPoolFilterFromEnv = buildPoolFilterFromEnv;
|
|
4
|
+
exports.filterPools = filterPools;
|
|
5
|
+
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
6
|
+
function buildPoolFilterFromEnv(envArgs) {
|
|
7
|
+
return {
|
|
8
|
+
poolAddress: envArgs.quote_pool_address || undefined,
|
|
9
|
+
poolName: envArgs.quote_pool_name || undefined,
|
|
10
|
+
feeRate: envArgs.quote_pool_fee_rate || undefined,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function filterPools(pools, filter, label = '') {
|
|
14
|
+
const prefix = label ? `[${label}] ` : '';
|
|
15
|
+
let result = pools;
|
|
16
|
+
if (filter.poolAddress) {
|
|
17
|
+
result = pools.filter(p => p.pool_address.toLowerCase() === filter.poolAddress.toLowerCase());
|
|
18
|
+
}
|
|
19
|
+
else if (filter.poolName || filter.feeRate) {
|
|
20
|
+
result = pools.filter(p => {
|
|
21
|
+
if (filter.poolName && p.pool_name !== filter.poolName)
|
|
22
|
+
return false;
|
|
23
|
+
if (filter.feeRate && p.fee_rate !== filter.feeRate)
|
|
24
|
+
return false;
|
|
25
|
+
return true;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (result.length === 0 && pools.length > 0) {
|
|
29
|
+
(0, ttd_core_1.log_warn)(`${prefix}Pool filter matched 0 pools from ${pools.length}`, {
|
|
30
|
+
filter,
|
|
31
|
+
available: pools.map(p => `${p.pool_name}(${p.pool_address}, fee=${p.fee_rate})`),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
(0, ttd_core_1.log_info)(`${prefix}Pool filter: ${pools.length} → ${result.length}`, result.map(p => `${p.pool_name}(${p.pool_address}, fee=${p.fee_rate})`));
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|