@clonegod/ttd-bsc-common 3.0.1 → 3.0.4
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.
|
@@ -52,7 +52,8 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
52
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
53
|
this.provider = new ethers_1.ethers.providers.JsonRpcProvider(this.chainConfig.rpcEndpoint);
|
|
54
54
|
this.transactionSender = new ttd_bsc_send_tx_1.TransactionSender(this.appConfig);
|
|
55
|
-
const
|
|
55
|
+
const defaultCallerId = `${this.chainNameLower.toUpperCase()}-CALLER`;
|
|
56
|
+
const callerGroupIds = (process.env.CALLER_GROUP_IDS || defaultCallerId).trim().split(',').filter(Boolean);
|
|
56
57
|
this.callerManager = new caller_manager_1.CallerManager({
|
|
57
58
|
chainName: this.chainNameLower,
|
|
58
59
|
provider: this.provider,
|
|
@@ -164,17 +165,14 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
164
165
|
});
|
|
165
166
|
}
|
|
166
167
|
subscribeTradeMonitor() {
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
(0, ttd_core_1.log_warn)('TRADE_MONITOR_WS_URL not configured, trade result nonce correction disabled');
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
168
|
+
const host = process.env.STREAM_TRADE_HOST || '127.0.0.1';
|
|
169
|
+
const wsUrl = `ws://${host}:${ttd_core_1.SERVICE_PORT.STREAM_TRADE_WS}`;
|
|
172
170
|
const wsClient = new ttd_core_1.WebSocketClient(wsUrl);
|
|
173
171
|
wsClient.onOpen(() => {
|
|
174
172
|
wsClient.send(JSON.stringify({
|
|
175
|
-
|
|
173
|
+
address: this.tradeConfig.vaultAddress,
|
|
176
174
|
}));
|
|
177
|
-
(0, ttd_core_1.log_info)(`Subscribed to trade-monitor for
|
|
175
|
+
(0, ttd_core_1.log_info)(`Subscribed to trade-monitor for ${this.tradeConfig.vaultAddress}`);
|
|
178
176
|
});
|
|
179
177
|
wsClient.onMessage((event) => {
|
|
180
178
|
if (event.type === 'TradeResult' && event.data) {
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
symbol: string;
|
|
3
|
-
address: string;
|
|
4
|
-
decimals: number;
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
}
|
|
7
|
-
export interface TradeDirectionResult {
|
|
1
|
+
export interface TradeDirectionResult<T = any> {
|
|
8
2
|
isBuy: boolean;
|
|
9
|
-
inputToken:
|
|
10
|
-
outputToken:
|
|
11
|
-
baseToken:
|
|
12
|
-
quoteToken:
|
|
3
|
+
inputToken: T;
|
|
4
|
+
outputToken: T;
|
|
5
|
+
baseToken: T;
|
|
6
|
+
quoteToken: T;
|
|
13
7
|
}
|
|
14
|
-
export declare function resolveTradeDirection(poolInfo:
|
|
8
|
+
export declare function resolveTradeDirection<T = any>(poolInfo: {
|
|
9
|
+
tokenA: T;
|
|
10
|
+
tokenB: T;
|
|
11
|
+
quote_token: string;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}, isBuy: boolean): TradeDirectionResult<T>;
|
|
15
14
|
export declare function calculateStandardPrice(inputAmount: number, outputAmount: number, isBuy: boolean): string;
|
|
@@ -4,8 +4,8 @@ exports.resolveTradeDirection = resolveTradeDirection;
|
|
|
4
4
|
exports.calculateStandardPrice = calculateStandardPrice;
|
|
5
5
|
function resolveTradeDirection(poolInfo, isBuy) {
|
|
6
6
|
const { tokenA, tokenB, quote_token } = poolInfo;
|
|
7
|
-
const quoteToken = [tokenA, tokenB].find(
|
|
8
|
-
const baseToken = [tokenA, tokenB].find(
|
|
7
|
+
const quoteToken = [tokenA, tokenB].find(t => t.symbol === quote_token);
|
|
8
|
+
const baseToken = [tokenA, tokenB].find(t => t.symbol !== quote_token);
|
|
9
9
|
if (!quoteToken || !baseToken) {
|
|
10
10
|
throw new Error(`Cannot resolve tokens: tokenA=${tokenA === null || tokenA === void 0 ? void 0 : tokenA.symbol}, tokenB=${tokenB === null || tokenB === void 0 ? void 0 : tokenB.symbol}, quote_token=${quote_token}`);
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clonegod/ttd-bsc-common",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "BSC common library",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"push": "npm run build && npm publish"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@clonegod/ttd-core": "3.0.
|
|
17
|
+
"@clonegod/ttd-core": "3.0.4",
|
|
18
18
|
"@clonegod/ttd-bsc-send-tx": "1.0.0",
|
|
19
19
|
"axios": "^1.12.0",
|
|
20
20
|
"dotenv": "^16.4.7",
|