@clonegod/ttd-sol-common 2.0.12 → 2.0.13
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/common/subscribe_account_update.d.ts +4 -0
- package/dist/common/subscribe_account_update.js +22 -0
- package/dist/trade/SolanaTradeAppConfig.d.ts +1 -4
- package/dist/trade/SolanaTradeAppConfig.js +0 -18
- package/package.json +1 -1
- package/src/common/subscribe_account_update.ts +26 -0
- package/src/trade/SolanaTradeAppConfig.ts +1 -26
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { StandardPoolInfoType } from "@clonegod/ttd-core";
|
|
2
|
+
import { DEX_ID } from "@clonegod/ttd-core/dist";
|
|
3
|
+
import { SolanaPoolAccountUpdateEventData } from "../types";
|
|
4
|
+
export declare function subscribe_account_update(dex_id: DEX_ID, pool_list: StandardPoolInfoType[], callback: (eventData: SolanaPoolAccountUpdateEventData) => void): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subscribe_account_update = subscribe_account_update;
|
|
4
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
5
|
+
function subscribe_account_update(dex_id, pool_list, callback) {
|
|
6
|
+
const ws_url = process.env.SUBSCIBE_MULTIPLE_PROVIDERS_WS_URL || 'ws://127.0.0.1:10000';
|
|
7
|
+
const ws_client = new dist_1.WebSocketClient(ws_url);
|
|
8
|
+
ws_client.onOpen(() => {
|
|
9
|
+
pool_list.forEach(({ pair, pool_address }, _) => {
|
|
10
|
+
ws_client.send(JSON.stringify({ dex_id, pair, pool_address }));
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
ws_client.onMessage(((eventData) => {
|
|
14
|
+
if (!eventData.data) {
|
|
15
|
+
(0, dist_1.log_warn)(`[SolanaTradeAppConfig] subscribe_pool_events_from_multiple_providers: no data`, eventData);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
callback(eventData);
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
ws_client.connect();
|
|
22
|
+
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractTradeAppConfig, DEX_ID } from "@clonegod/ttd-core/dist";
|
|
1
|
+
import { AbstractTradeAppConfig } from "@clonegod/ttd-core/dist";
|
|
3
2
|
import { Connection, Keypair } from "@solana/web3.js";
|
|
4
|
-
import { SolanaPoolAccountUpdateEventData } from "../types";
|
|
5
3
|
export declare class SolanaTradeAppConfig extends AbstractTradeAppConfig {
|
|
6
4
|
connection: Connection;
|
|
7
5
|
keypair: Keypair;
|
|
8
6
|
constructor();
|
|
9
|
-
subscribe_pool_events_from_multiple_providers(dex_id: DEX_ID, pool_list: StandardPoolInfoType[], callback: (eventData: SolanaPoolAccountUpdateEventData) => void): void;
|
|
10
7
|
subscribe_wallet_raw_txn_event(): void;
|
|
11
8
|
}
|
|
@@ -6,24 +6,6 @@ class SolanaTradeAppConfig extends dist_1.AbstractTradeAppConfig {
|
|
|
6
6
|
constructor() {
|
|
7
7
|
super();
|
|
8
8
|
}
|
|
9
|
-
subscribe_pool_events_from_multiple_providers(dex_id, pool_list, callback) {
|
|
10
|
-
const ws_url = process.env.SUBSCIBE_MULTIPLE_PROVIDERS_WS_URL || 'ws://127.0.0.1:10000';
|
|
11
|
-
const ws_client = new dist_1.WebSocketClient(ws_url);
|
|
12
|
-
ws_client.onOpen(() => {
|
|
13
|
-
pool_list.forEach(({ pair, pool_address }, _) => {
|
|
14
|
-
ws_client.send(JSON.stringify({ dex_id, pair, pool_address }));
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
ws_client.onMessage(((eventData) => {
|
|
18
|
-
if (!eventData.data) {
|
|
19
|
-
(0, dist_1.log_warn)(`[SolanaTradeAppConfig] subscribe_pool_events_from_multiple_providers: no data`, eventData);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
callback(eventData);
|
|
23
|
-
}
|
|
24
|
-
}));
|
|
25
|
-
ws_client.connect();
|
|
26
|
-
}
|
|
27
9
|
subscribe_wallet_raw_txn_event() {
|
|
28
10
|
return;
|
|
29
11
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { StandardPoolInfoType } from "@clonegod/ttd-core";
|
|
2
|
+
import { DEX_ID, log_warn, WebSocketClient } from "@clonegod/ttd-core/dist";
|
|
3
|
+
import { SolanaPoolAccountUpdateEventData } from "../types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 集中订阅方式,丛 solana-stream 获取池子变化事件,获得poolRawData
|
|
7
|
+
* - 询价:基于池子数据计算价格
|
|
8
|
+
* - 交易使用:交易中需要池子的最新状态
|
|
9
|
+
*/
|
|
10
|
+
export function subscribe_account_update(dex_id: DEX_ID, pool_list: StandardPoolInfoType[], callback: (eventData: SolanaPoolAccountUpdateEventData) => void) {
|
|
11
|
+
const ws_url = process.env.SUBSCIBE_MULTIPLE_PROVIDERS_WS_URL || 'ws://127.0.0.1:10000';
|
|
12
|
+
const ws_client = new WebSocketClient(ws_url)
|
|
13
|
+
ws_client.onOpen(() => {
|
|
14
|
+
pool_list.forEach(({ pair, pool_address }, _) => {
|
|
15
|
+
ws_client.send(JSON.stringify({ dex_id, pair, pool_address }))
|
|
16
|
+
})
|
|
17
|
+
})
|
|
18
|
+
ws_client.onMessage(((eventData: SolanaPoolAccountUpdateEventData): void => {
|
|
19
|
+
if (!eventData.data) {
|
|
20
|
+
log_warn(`[SolanaTradeAppConfig] subscribe_pool_events_from_multiple_providers: no data`, eventData);
|
|
21
|
+
} else {
|
|
22
|
+
callback(eventData);
|
|
23
|
+
}
|
|
24
|
+
}));
|
|
25
|
+
ws_client.connect();
|
|
26
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractTradeAppConfig, DEX_ID, log_warn, WebSocketClient } from "@clonegod/ttd-core/dist";
|
|
1
|
+
import { AbstractTradeAppConfig } from "@clonegod/ttd-core/dist";
|
|
3
2
|
import { Connection, Keypair } from "@solana/web3.js";
|
|
4
|
-
import { SolanaPoolAccountUpdateEventData } from "../types";
|
|
5
3
|
|
|
6
4
|
export class SolanaTradeAppConfig extends AbstractTradeAppConfig {
|
|
7
5
|
|
|
@@ -13,29 +11,6 @@ export class SolanaTradeAppConfig extends AbstractTradeAppConfig {
|
|
|
13
11
|
super();
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
/**
|
|
17
|
-
* 集中订阅方式,丛 solana-stream 获取池子变化事件,获得poolRawData
|
|
18
|
-
* - 询价:基于池子数据计算价格
|
|
19
|
-
* - 交易使用:交易中需要池子的最新状态
|
|
20
|
-
*/
|
|
21
|
-
subscribe_pool_events_from_multiple_providers(dex_id:DEX_ID, pool_list:StandardPoolInfoType[], callback:(eventData:SolanaPoolAccountUpdateEventData)=>void) {
|
|
22
|
-
const ws_url = process.env.SUBSCIBE_MULTIPLE_PROVIDERS_WS_URL || 'ws://127.0.0.1:10000';
|
|
23
|
-
const ws_client = new WebSocketClient(ws_url)
|
|
24
|
-
ws_client.onOpen(() => {
|
|
25
|
-
pool_list.forEach(({ pair, pool_address }, _) => {
|
|
26
|
-
ws_client.send(JSON.stringify({ dex_id, pair, pool_address }))
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
ws_client.onMessage(((eventData: SolanaPoolAccountUpdateEventData): void => {
|
|
30
|
-
if (!eventData.data) {
|
|
31
|
-
log_warn(`[SolanaTradeAppConfig] subscribe_pool_events_from_multiple_providers: no data`, eventData);
|
|
32
|
-
} else {
|
|
33
|
-
callback(eventData);
|
|
34
|
-
}
|
|
35
|
-
}));
|
|
36
|
-
ws_client.connect();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
14
|
|
|
40
15
|
// 订阅 Wallet 在链上发生的tx data
|
|
41
16
|
subscribe_wallet_raw_txn_event(): void {
|