@clonegod/ttd-sol-common 1.0.34 → 1.0.35
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/context.d.ts +1 -1
- package/dist/common/index.d.ts +0 -1
- package/dist/common/index.js +0 -1
- package/dist/helius_sdk_v1.4.0/RpcClient.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/send_tx/send_transaction.d.ts +1 -1
- package/dist/send_tx/strategy_util.d.ts +1 -1
- package/dist/trade/abstract_trade.d.ts +2 -0
- package/dist/trade/handle_order_message.d.ts +4 -0
- package/dist/trade/handle_order_message.js +116 -0
- package/dist/trade/index.d.ts +1 -0
- package/dist/trade/index.js +1 -0
- package/dist/trade/tx_result_check.d.ts +1 -1
- package/dist/trade/tx_result_parse.d.ts +1 -1
- package/package.json +2 -2
- package/types/index.d.ts +49 -19
package/dist/common/context.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OrderMessageType, PriceMessageType, StandardPoolInfoType, TradeRuntimeType } from "@clonegod/ttd-common";
|
|
2
2
|
import { CHAIN_ID, DEX_ID } from "@clonegod/ttd-common/dist";
|
|
3
3
|
import { Connection } from "@solana/web3.js";
|
|
4
|
-
import { SolanaTradeRuntimeType } from "
|
|
4
|
+
import { SolanaTradeRuntimeType } from "../../types";
|
|
5
5
|
export declare class TradeContext {
|
|
6
6
|
connection: Connection;
|
|
7
7
|
trade_runtime: TradeRuntimeType;
|
package/dist/common/index.d.ts
CHANGED
package/dist/common/index.js
CHANGED
|
@@ -16,4 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./constants"), exports);
|
|
18
18
|
__exportStar(require("./context"), exports);
|
|
19
|
-
__exportStar(require("./types"), exports);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { BlockhashWithExpiryBlockHeight, VersionedTransaction, AddressLookupTableAccount, Transaction, TransactionInstruction, TransactionSignature, Commitment, PublicKey, AccountInfo, GetLatestBlockhashConfig, RpcResponseAndContext, SignatureResult, Blockhash, Connection, ParsedAccountData, SendOptions, Signer, SerializeConfig } from '@solana/web3.js';
|
|
4
4
|
import { DAS } from './types/das-types';
|
|
5
5
|
import { GetPriorityFeeEstimateRequest, GetPriorityFeeEstimateResponse, JitoRegion, PollTransactionOptions, SmartTransactionContext, HeliusSendOptions } from './types';
|
|
6
|
-
import { SolanaTradeRuntimeType } from '
|
|
6
|
+
import { SolanaTradeRuntimeType } from '../../types';
|
|
7
7
|
export type SendAndConfirmTransactionResponse = {
|
|
8
8
|
signature: TransactionSignature;
|
|
9
9
|
confirmResponse: RpcResponseAndContext<SignatureResult>;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./common"), exports);
|
|
18
|
+
__exportStar(require("./config"), exports);
|
|
18
19
|
__exportStar(require("./helius_geyser_ws"), exports);
|
|
19
20
|
__exportStar(require("./send_tx"), exports);
|
|
20
21
|
__exportStar(require("./trade"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SendOptions, Signer, TransactionInstruction } from "@solana/web3.js";
|
|
2
2
|
import { Helius } from "../helius_sdk_v1.4.0";
|
|
3
|
-
import { SolanaTradeRuntimeType } from '
|
|
3
|
+
import { SolanaTradeRuntimeType } from '../../types';
|
|
4
4
|
export declare class HeliusClient {
|
|
5
5
|
signers: Signer[];
|
|
6
6
|
sendOptions: SendOptions;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StandardPoolInfoType, TradeRuntimeType, TradeStrategyType } from "@clonegod/ttd-common";
|
|
2
2
|
import { JitoRegion } from "../helius_sdk_v1.4.0";
|
|
3
3
|
import { Connection } from "@solana/web3.js";
|
|
4
|
-
import { SolanaTradeRuntimeType } from "
|
|
4
|
+
import { SolanaTradeRuntimeType } from "../../types";
|
|
5
5
|
export declare function create_solana_trade_runtime(connection: Connection, trade_runtime: TradeRuntimeType, pool_info: StandardPoolInfoType): SolanaTradeRuntimeType;
|
|
6
6
|
export declare function calculate_gas_fee(trade_strategy: TradeStrategyType): number;
|
|
7
7
|
export declare function get_jito_region(): JitoRegion;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { StandardPoolInfoType } from "@clonegod/ttd-common";
|
|
1
2
|
import { TradeContext } from "../common/context";
|
|
2
3
|
export declare abstract class AbastrcatTrade {
|
|
4
|
+
abstract init(pool_list: StandardPoolInfoType[]): void;
|
|
3
5
|
abstract execute(context: TradeContext): Promise<string>;
|
|
4
6
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AppConfig } from "../config";
|
|
2
|
+
import { AbastrcatTrade } from "./abstract_trade";
|
|
3
|
+
export declare const try_lock_order_msg: (appConfig: AppConfig, order_msg: any) => Promise<boolean>;
|
|
4
|
+
export declare const handle_order_message: (appConfig: AppConfig, trade: AbastrcatTrade, message: string) => Promise<void>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.handle_order_message = exports.try_lock_order_msg = void 0;
|
|
13
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
14
|
+
const common_1 = require("../common");
|
|
15
|
+
const tx_result_check_1 = require("./tx_result_check");
|
|
16
|
+
const check_parse_order_msg = (appConfig, order_msg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
let { unique_orderbook_id, price_id, group_id, unique_order_msg_id } = order_msg;
|
|
18
|
+
const runtime_group_id = appConfig.trade_runtime.group.id;
|
|
19
|
+
if (group_id !== runtime_group_id) {
|
|
20
|
+
throw new Error(`group_id not match!!! ${(0, dist_1.to_json_str)({ group_id, runtime_group_id })}`);
|
|
21
|
+
}
|
|
22
|
+
if ((0, dist_1.isEmpty)(unique_order_msg_id)) {
|
|
23
|
+
throw new Error(`unique_order_msg_id is empty or null! unique_order_msg_id=${unique_order_msg_id}`);
|
|
24
|
+
}
|
|
25
|
+
let price_msg = yield appConfig.arb_cache.get_price_message(price_id);
|
|
26
|
+
if ((0, dist_1.isEmpty)(price_msg)) {
|
|
27
|
+
throw new Error(`price_msg not found in the cache! price_id=${price_id}`);
|
|
28
|
+
}
|
|
29
|
+
let id_parts = (0, dist_1.parse_unique_orderbook_id)(unique_orderbook_id);
|
|
30
|
+
if (id_parts.dex_id != price_msg.dex_id ||
|
|
31
|
+
id_parts.pool_id != price_msg.pool_id) {
|
|
32
|
+
(0, dist_1.log_warn)(`check data: order_msg VS price_msg, not match!!!`, {
|
|
33
|
+
order_msg,
|
|
34
|
+
uinique_orderbook: id_parts,
|
|
35
|
+
price_msg,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
price_msg,
|
|
40
|
+
id_parts
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
const try_lock_order_msg = (appConfig, order_msg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
let { chain_id, group_id, price_id, order_trace_id } = order_msg;
|
|
45
|
+
let lock_order_key = (0, dist_1.format_order_lock_key)(chain_id, group_id, price_id, order_trace_id);
|
|
46
|
+
(0, dist_1.log_info)(`try_lock_order_msg, key=${lock_order_key}`);
|
|
47
|
+
let is_lock_success = yield appConfig.arb_cache.redis_cmd.set_nx(lock_order_key, '');
|
|
48
|
+
if (is_lock_success) {
|
|
49
|
+
(0, dist_1.log_info)(`try_lock_order_msg, key=${lock_order_key}, success`);
|
|
50
|
+
appConfig.arb_cache.redis_cmd.expire(lock_order_key, 60)
|
|
51
|
+
.then(res => (0, dist_1.log_trace)(`expire lock: key=${lock_order_key}, success`))
|
|
52
|
+
.catch(err => (0, dist_1.log_error)(`expire lock: key=${lock_order_key}, error!`, err));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
(0, dist_1.log_info)(`try_lock_order_msg, key=${lock_order_key}, acquire lock failed!`);
|
|
56
|
+
}
|
|
57
|
+
return is_lock_success;
|
|
58
|
+
});
|
|
59
|
+
exports.try_lock_order_msg = try_lock_order_msg;
|
|
60
|
+
const handle_order_message = (appConfig, trade, message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
(0, dist_1.new_line)(3);
|
|
62
|
+
(0, dist_1.log_info)(`handle_order_message, on message: `, message);
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
console.log(`=================================================================================`);
|
|
65
|
+
console.log(`| NEW ORDER MESSAGE |`);
|
|
66
|
+
console.log(`=================================================================================`);
|
|
67
|
+
}, 0);
|
|
68
|
+
let order_event_message = JSON.parse(message);
|
|
69
|
+
if (dist_1.LOG.debug) {
|
|
70
|
+
(0, dist_1.log_debug)(`order_event_msg`, order_event_message);
|
|
71
|
+
}
|
|
72
|
+
let { event_time, event_type, group_id, data: order_msg } = order_event_message;
|
|
73
|
+
let { price_msg, id_parts } = yield check_parse_order_msg(appConfig, order_msg);
|
|
74
|
+
let { order_trace_id } = order_msg;
|
|
75
|
+
let { chain_id, dex_id, pool_id, fee_rate } = id_parts;
|
|
76
|
+
let lock_order = yield (0, exports.try_lock_order_msg)(appConfig, order_msg);
|
|
77
|
+
if (!lock_order) {
|
|
78
|
+
(0, dist_1.log_warn)(`try lock order failed!`, {
|
|
79
|
+
chain_id, group_id, order_trace_id
|
|
80
|
+
});
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
let context;
|
|
84
|
+
let txid = '';
|
|
85
|
+
let order_submit_result;
|
|
86
|
+
try {
|
|
87
|
+
let { env_args, trade_runtime } = appConfig;
|
|
88
|
+
context = new common_1.TradeContext(price_msg, order_msg);
|
|
89
|
+
yield context.init(trade_runtime);
|
|
90
|
+
txid = yield trade.execute(context);
|
|
91
|
+
order_msg.order_submit_time = Date.now();
|
|
92
|
+
order_submit_result = {
|
|
93
|
+
success: true,
|
|
94
|
+
msg: 'SUCCESS',
|
|
95
|
+
txid
|
|
96
|
+
};
|
|
97
|
+
new tx_result_check_1.TransactionResultChecker(env_args, appConfig, context, txid).init_tx_status().check();
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
(0, dist_1.log_error)(`handle_order_message error!`, err);
|
|
101
|
+
order_submit_result = {
|
|
102
|
+
success: false,
|
|
103
|
+
msg: (err === null || err === void 0 ? void 0 : err.message) || 'FAILED',
|
|
104
|
+
txid
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
appConfig.arb_cache.cache_order_message(Object.assign(Object.assign({}, order_msg), { order_submit_result })).then(res => {
|
|
109
|
+
(0, dist_1.log_info)(`cache order submit result, success`, { order_msg, order_submit_result, res });
|
|
110
|
+
}).catch(err => {
|
|
111
|
+
(0, dist_1.log_warn)('cache order submit result, error!', { order_msg, order_submit_result, err });
|
|
112
|
+
console.log(err);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
exports.handle_order_message = handle_order_message;
|
package/dist/trade/index.d.ts
CHANGED
package/dist/trade/index.js
CHANGED
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./abstract_trade"), exports);
|
|
18
18
|
__exportStar(require("./tx_result_check"), exports);
|
|
19
19
|
__exportStar(require("./tx_result_parse"), exports);
|
|
20
|
+
__exportStar(require("./handle_order_message"), exports);
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { OrderMessageType, PriceMessageType, StandardPoolInfoType, TradeResultType } from "@clonegod/ttd-common";
|
|
3
3
|
import { Connection, PublicKey } from "@solana/web3.js";
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
|
+
import { StandardSwapDetailType } from "../../types";
|
|
5
6
|
import { TradeContext } from "../common/context";
|
|
6
|
-
import { StandardSwapDetailType } from "../common/types";
|
|
7
7
|
import { TransactionResultParser } from "./tx_result_parse";
|
|
8
8
|
export declare class TransactionResultChecker {
|
|
9
9
|
env_args: any;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { StandardPoolInfoType } from '@clonegod/ttd-common';
|
|
3
3
|
import { ParsedTransactionWithMeta, PublicKey, TokenBalance } from '@solana/web3.js';
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
|
-
import { StandardSwapDetailType } from '
|
|
5
|
+
import { StandardSwapDetailType } from '../../types';
|
|
6
6
|
export declare class TransactionResultParser {
|
|
7
7
|
env_args: any;
|
|
8
8
|
event_emitter: EventEmitter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clonegod/ttd-sol-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.35",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"push": "npm run build && npm publish"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@clonegod/ttd-common": "1.0.
|
|
16
|
+
"@clonegod/ttd-common": "1.0.146",
|
|
17
17
|
"@solana/web3.js": "1.91.6",
|
|
18
18
|
"@irys/sdk": "^0.2.10",
|
|
19
19
|
"@metaplex-foundation/mpl-token-metadata": "^2.5.2",
|
package/types/index.d.ts
CHANGED
|
@@ -1,23 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { StandardTokenInfoType, TradeRuntimeType } from "@clonegod/ttd-common";
|
|
2
|
+
import { Connection } from "@solana/web3.js";
|
|
3
|
+
|
|
4
|
+
export interface StandardSwapDetailType {
|
|
5
|
+
success: boolean
|
|
6
|
+
error_code: string
|
|
7
|
+
|
|
8
|
+
wallet: string,
|
|
9
|
+
txid: string,
|
|
10
|
+
block_time: number
|
|
11
|
+
block_number: number
|
|
12
|
+
|
|
13
|
+
pool_address: string
|
|
14
|
+
tokenA: TokenBalChangeType
|
|
15
|
+
tokenB: TokenBalChangeType
|
|
16
|
+
tx_price: string
|
|
17
|
+
|
|
18
|
+
gas_fee: GasFeeType
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export interface TokenBalChangeType extends StandardTokenInfoType {
|
|
24
|
+
pre_bal: number
|
|
25
|
+
post_bal: number
|
|
26
|
+
change: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
export interface GasFeeType {
|
|
32
|
+
base_fee: number
|
|
33
|
+
priority_fee: number
|
|
34
|
+
total_fee: number
|
|
20
35
|
}
|
|
21
36
|
|
|
22
37
|
|
|
23
38
|
|
|
39
|
+
export interface SolanaTradeRuntimeType extends TradeRuntimeType {
|
|
40
|
+
// common connection
|
|
41
|
+
connection: Connection
|
|
42
|
+
|
|
43
|
+
// priority fee
|
|
44
|
+
priority_fee: number
|
|
45
|
+
|
|
46
|
+
// Compute Budget: SetComputeUnitPrice
|
|
47
|
+
cu_price: number
|
|
48
|
+
|
|
49
|
+
// Compute Budget: SetComputeUnitLimit
|
|
50
|
+
cu_limit: number
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|