@clonegod/ttd-sol-common 1.2.1 → 2.0.0
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/index.d.ts +0 -7
- package/dist/index.js +0 -23
- package/package.json +31 -32
- package/src/index.ts +0 -0
- package/tsconfig.json +22 -0
- package/dist/appconfig/app_config.d.ts +0 -23
- package/dist/appconfig/app_config.js +0 -134
- package/dist/appconfig/env_args.d.ts +0 -27
- package/dist/appconfig/env_args.js +0 -39
- package/dist/appconfig/index.d.ts +0 -2
- package/dist/appconfig/index.js +0 -18
- package/dist/common/constants.d.ts +0 -12
- package/dist/common/constants.js +0 -18
- package/dist/common/context.d.ts +0 -23
- package/dist/common/context.js +0 -51
- package/dist/common/index.d.ts +0 -2
- package/dist/common/index.js +0 -18
- package/dist/helius_geyser_ws/index.d.ts +0 -3
- package/dist/helius_geyser_ws/index.js +0 -19
- package/dist/helius_geyser_ws/subscribe_pool_change_by_geyser.d.ts +0 -3
- package/dist/helius_geyser_ws/subscribe_pool_change_by_geyser.js +0 -102
- package/dist/helius_geyser_ws/subscribe_txid.d.ts +0 -2
- package/dist/helius_geyser_ws/subscribe_txid.js +0 -109
- package/dist/helius_geyser_ws/subscribe_wallet_transaction.d.ts +0 -2
- package/dist/helius_geyser_ws/subscribe_wallet_transaction.js +0 -102
- package/dist/helius_sdk_v1.4.0/Helius.d.ts +0 -31
- package/dist/helius_sdk_v1.4.0/Helius.js +0 -450
- package/dist/helius_sdk_v1.4.0/RpcClient.d.ts +0 -70
- package/dist/helius_sdk_v1.4.0/RpcClient.js +0 -978
- package/dist/helius_sdk_v1.4.0/constants.d.ts +0 -1
- package/dist/helius_sdk_v1.4.0/constants.js +0 -4
- package/dist/helius_sdk_v1.4.0/index.d.ts +0 -5
- package/dist/helius_sdk_v1.4.0/index.js +0 -21
- package/dist/helius_sdk_v1.4.0/types/das-types.d.ts +0 -408
- package/dist/helius_sdk_v1.4.0/types/das-types.js +0 -2
- package/dist/helius_sdk_v1.4.0/types/enums.d.ts +0 -542
- package/dist/helius_sdk_v1.4.0/types/enums.js +0 -606
- package/dist/helius_sdk_v1.4.0/types/index.d.ts +0 -3
- package/dist/helius_sdk_v1.4.0/types/index.js +0 -19
- package/dist/helius_sdk_v1.4.0/types/types.d.ts +0 -305
- package/dist/helius_sdk_v1.4.0/types/types.js +0 -2
- package/dist/helius_sdk_v1.4.0/utils/get-helius-endpoints.d.ts +0 -2
- package/dist/helius_sdk_v1.4.0/utils/get-helius-endpoints.js +0 -19
- package/dist/helius_sdk_v1.4.0/utils/index.d.ts +0 -1
- package/dist/helius_sdk_v1.4.0/utils/index.js +0 -17
- package/dist/helius_sdk_v1.4.0/utils/mintApi.d.ts +0 -2
- package/dist/helius_sdk_v1.4.0/utils/mintApi.js +0 -14
- package/dist/jito/index.d.ts +0 -14
- package/dist/jito/index.js +0 -142
- package/dist/jito/jitodontfront.d.ts +0 -5
- package/dist/jito/jitodontfront.js +0 -41
- package/dist/quote/index.d.ts +0 -3
- package/dist/quote/index.js +0 -19
- package/dist/quote/log_quote_price.d.ts +0 -2
- package/dist/quote/log_quote_price.js +0 -29
- package/dist/quote/publish_quote_price.d.ts +0 -3
- package/dist/quote/publish_quote_price.js +0 -19
- package/dist/quote/to_price_message.d.ts +0 -5
- package/dist/quote/to_price_message.js +0 -103
- package/dist/send_tx/get_jito_tip_floor.d.ts +0 -1
- package/dist/send_tx/get_jito_tip_floor.js +0 -86
- package/dist/send_tx/get_signature.d.ts +0 -2
- package/dist/send_tx/get_signature.js +0 -17
- package/dist/send_tx/helius_client.d.ts +0 -16
- package/dist/send_tx/helius_client.js +0 -119
- package/dist/send_tx/index.d.ts +0 -4
- package/dist/send_tx/index.js +0 -20
- package/dist/send_tx/notify_new_txid.d.ts +0 -1
- package/dist/send_tx/notify_new_txid.js +0 -20
- package/dist/send_tx/sol_gas_cache.d.ts +0 -3
- package/dist/send_tx/sol_gas_cache.js +0 -15
- package/dist/send_tx/strategy_util.d.ts +0 -7
- package/dist/send_tx/strategy_util.js +0 -147
- package/dist/token/get_token_info.d.ts +0 -4
- package/dist/token/get_token_info.js +0 -136
- package/dist/token/get_token_price.d.ts +0 -6
- package/dist/token/get_token_price.js +0 -186
- package/dist/token/index.d.ts +0 -4
- package/dist/token/index.js +0 -20
- package/dist/token/types.d.ts +0 -17
- package/dist/token/types.js +0 -2
- package/dist/token/util.d.ts +0 -3
- package/dist/token/util.js +0 -33
- package/dist/trade/abstract_trade.d.ts +0 -5
- package/dist/trade/abstract_trade.js +0 -6
- package/dist/trade/handle_order_message.d.ts +0 -4
- package/dist/trade/handle_order_message.js +0 -118
- package/dist/trade/index.d.ts +0 -4
- package/dist/trade/index.js +0 -20
- package/dist/trade/tx_result_check.d.ts +0 -29
- package/dist/trade/tx_result_check.js +0 -232
- package/dist/trade/tx_result_parse.d.ts +0 -13
- package/dist/trade/tx_result_parse.js +0 -150
- package/grpc/transaction/LThcUp2D5p4JgRMnWEUVVSdNEHiq5YfN5HXPGRYeWBfypMT3aTa1CaC9XdPT69CyMdoJ32XAkjXAa2TmBYBeZAy.json +0 -1
- package/types/index.d.ts +0 -71
|
@@ -1,232 +0,0 @@
|
|
|
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.TransactionResultChecker = void 0;
|
|
13
|
-
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
14
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
15
|
-
const constants_1 = require("../common/constants");
|
|
16
|
-
const tx_result_parse_1 = require("./tx_result_parse");
|
|
17
|
-
class TransactionResultChecker {
|
|
18
|
-
constructor(env_args, event_emitter, context, txid) {
|
|
19
|
-
this.env_args = env_args;
|
|
20
|
-
this.event_emitter = event_emitter;
|
|
21
|
-
this.context = context;
|
|
22
|
-
this.group_id = context.group_id;
|
|
23
|
-
this.connection = context.solana_trade_runtime.connection;
|
|
24
|
-
this.wallet = new web3_js_1.PublicKey(context.trade_runtime.wallet.public_key);
|
|
25
|
-
this.txid = txid;
|
|
26
|
-
this.price_msg = context.price_msg;
|
|
27
|
-
this.order_msg = context.order_msg;
|
|
28
|
-
this.pool_info = context.pool_info;
|
|
29
|
-
this.trace_id = context.order_msg.order_trace_id;
|
|
30
|
-
this.check_count = 0;
|
|
31
|
-
this.transactionParser = new tx_result_parse_1.TransactionResultParser(this.env_args, this.wallet, this.event_emitter);
|
|
32
|
-
this.trade_result_already_processed = false;
|
|
33
|
-
}
|
|
34
|
-
init_tx_status() {
|
|
35
|
-
let empty_trade_result = JSON.parse(JSON.stringify({
|
|
36
|
-
group_id: this.context.group_id,
|
|
37
|
-
txid: this.txid
|
|
38
|
-
}));
|
|
39
|
-
this.event_emitter.emit(dist_1.TRANSACTION_STATE_PROCESSING, empty_trade_result);
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
check() {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
this.check_tx_result_interval();
|
|
45
|
-
this.on_subscibe_transaction();
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
on_subscibe_transaction() {
|
|
49
|
-
this.event_emitter.once(constants_1.LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + this.txid, (messageStr) => {
|
|
50
|
-
try {
|
|
51
|
-
this.trade_result_already_processed = true;
|
|
52
|
-
(0, dist_1.log_debug)('on events: EVENT_WALLET_TRANSACTION', messageStr);
|
|
53
|
-
let messageObj = messageStr;
|
|
54
|
-
if (typeof messageStr === 'string') {
|
|
55
|
-
messageObj = JSON.parse(messageStr);
|
|
56
|
-
}
|
|
57
|
-
const result = messageObj.params.result;
|
|
58
|
-
const _txid = result.signature;
|
|
59
|
-
const slot = result.slot;
|
|
60
|
-
(0, dist_1.log_info)('check txid:', { _txid, txid: this.txid, slot });
|
|
61
|
-
result.transaction.transaction.signatures = [_txid];
|
|
62
|
-
let tx_result = {
|
|
63
|
-
slot,
|
|
64
|
-
transaction: result.transaction.transaction,
|
|
65
|
-
meta: result.transaction.meta,
|
|
66
|
-
blockTime: Date.now() / 1000,
|
|
67
|
-
version: result.transaction.version
|
|
68
|
-
};
|
|
69
|
-
let swap_result = this.transactionParser.parse_transaction_data(tx_result, this.pool_info);
|
|
70
|
-
let trade_result = this.map_swap_result_to_tx_result(swap_result);
|
|
71
|
-
if (trade_result.success) {
|
|
72
|
-
this.event_emitter.emit(dist_1.TRANSACTION_STATE_SUCCESS, trade_result);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
this.event_emitter.emit(dist_1.TRANSACTION_STATE_FAILED, trade_result);
|
|
76
|
-
}
|
|
77
|
-
console.log('<----------------------------------------------------');
|
|
78
|
-
console.dir(trade_result, { depth: 8 });
|
|
79
|
-
console.log('---------------------------------------------------->');
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
(0, dist_1.log_error)('parse geyser stream message error!', err);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
check_tx_result_interval() {
|
|
88
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
-
const check_start_time = Date.now();
|
|
90
|
-
const check_interval = parseInt(process.env.CHECK_TX_RESULT_INTERVAL_MILLS || '3000');
|
|
91
|
-
const check_timeout = parseInt(process.env.CHECK_TX_RESULT_TIMEOUT_MILLS || '10000');
|
|
92
|
-
(0, dist_1.log_info)(`check transaction start: check_interval=${check_interval}, check_timeout=${check_timeout}`);
|
|
93
|
-
if (check_interval >= check_timeout) {
|
|
94
|
-
(0, dist_1.log_warn)(`check_interval=${check_interval} >= check_timeout=${check_timeout}, check_tx_result_interval failed!`);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
this.check_count += 1;
|
|
99
|
-
(0, dist_1.log_info)(`check transaction: seq=[${this.check_count}], txhash= ${this.txid}, trace_id=${this.trace_id}`);
|
|
100
|
-
try {
|
|
101
|
-
if (Date.now() - check_start_time < check_timeout) {
|
|
102
|
-
let tx_result = yield this.connection.getParsedTransaction(this.txid, {
|
|
103
|
-
commitment: constants_1.COMMITMENT_LEVEL.CONFIRMED,
|
|
104
|
-
maxSupportedTransactionVersion: 0,
|
|
105
|
-
});
|
|
106
|
-
if ((0, dist_1.isEmpty)(tx_result)) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
clearInterval(intervalId);
|
|
110
|
-
let swap_result = this.transactionParser.parse_transaction_data(tx_result, this.pool_info);
|
|
111
|
-
let trade_result = this.map_swap_result_to_tx_result(swap_result);
|
|
112
|
-
if (this.trade_result_already_processed) {
|
|
113
|
-
(0, dist_1.log_warn)(`trade_result_already_processed=${this.trade_result_already_processed}, ignore trade result fetch by interval check!`);
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
if (trade_result.success) {
|
|
117
|
-
this.event_emitter.emit(dist_1.TRANSACTION_STATE_SUCCESS, trade_result);
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
this.event_emitter.emit(dist_1.TRANSACTION_STATE_FAILED, trade_result);
|
|
121
|
-
}
|
|
122
|
-
console.log('<====================================================');
|
|
123
|
-
console.dir(trade_result, { depth: 8 });
|
|
124
|
-
console.log('====================================================>');
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
clearInterval(intervalId);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
catch (err) {
|
|
132
|
-
clearInterval(intervalId);
|
|
133
|
-
(0, dist_1.log_error)('parse transaction error!', err);
|
|
134
|
-
}
|
|
135
|
-
}), check_interval);
|
|
136
|
-
this.intervalId = intervalId;
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
map_swap_result_to_tx_result(swap_result) {
|
|
140
|
-
let { success, error_code, wallet, block_number, block_time: order_block_time, txid, tx_price, tokenA, tokenB, gas_fee } = swap_result;
|
|
141
|
-
let { pool_name, is_reverse_token } = this.pool_info;
|
|
142
|
-
let { chain_id, dex_id, unique_orderbook_id, pair, price_id, time: quote_time, ask, bid } = this.price_msg;
|
|
143
|
-
let { group_id, unique_order_msg_id, order_send_time, order_recv_time, order_submit_time, aToB } = this.order_msg;
|
|
144
|
-
let order_price = aToB ? bid.price : ask.price;
|
|
145
|
-
let server_info = (0, dist_1.getServerInfo)();
|
|
146
|
-
let order_end_time = Date.now();
|
|
147
|
-
let start_time = order_recv_time;
|
|
148
|
-
let end_time = order_end_time;
|
|
149
|
-
let total_time = end_time - start_time;
|
|
150
|
-
let total_order_time = total_time;
|
|
151
|
-
let time = {
|
|
152
|
-
block_time: quote_time.block_time,
|
|
153
|
-
stream_time: quote_time.stream_time,
|
|
154
|
-
quote_start_time: quote_time.quote_start_time,
|
|
155
|
-
quote_end_time: quote_time.quote_end_time,
|
|
156
|
-
price_time: quote_time.price_time,
|
|
157
|
-
total_quote_time: quote_time.total_quote_time,
|
|
158
|
-
order_send_time,
|
|
159
|
-
order_recv_time,
|
|
160
|
-
order_submit_time,
|
|
161
|
-
order_block_time,
|
|
162
|
-
order_end_time,
|
|
163
|
-
total_order_time,
|
|
164
|
-
};
|
|
165
|
-
let broadcast = [];
|
|
166
|
-
let trade_strategy = this.context.solana_trade_runtime.settings.strategy;
|
|
167
|
-
let send_type = trade_strategy.broadcast_type;
|
|
168
|
-
if (send_type === 'rpc') {
|
|
169
|
-
send_type = trade_strategy.speed === 'fast' ? 'mainnet' : 'mainnet-premium';
|
|
170
|
-
}
|
|
171
|
-
broadcast.push({
|
|
172
|
-
rpc: {
|
|
173
|
-
read: 'qn',
|
|
174
|
-
write: 'qn'
|
|
175
|
-
},
|
|
176
|
-
type: send_type,
|
|
177
|
-
fee: gas_fee
|
|
178
|
-
});
|
|
179
|
-
let trade_balance_change = {
|
|
180
|
-
tokenA: {
|
|
181
|
-
symbol: tokenA.symbol,
|
|
182
|
-
address: tokenA.address,
|
|
183
|
-
pre_bal: tokenA.pre_bal,
|
|
184
|
-
post_bal: tokenA.post_bal,
|
|
185
|
-
change: Number(tokenA.change),
|
|
186
|
-
decimals: tokenA.decimals,
|
|
187
|
-
},
|
|
188
|
-
tokenB: {
|
|
189
|
-
symbol: tokenB.symbol,
|
|
190
|
-
address: tokenB.address,
|
|
191
|
-
pre_bal: tokenB.pre_bal,
|
|
192
|
-
post_bal: tokenB.post_bal,
|
|
193
|
-
change: Number(tokenB.change),
|
|
194
|
-
decimals: tokenB.decimals,
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
if (is_reverse_token) {
|
|
198
|
-
let { tokenA, tokenB } = trade_balance_change;
|
|
199
|
-
trade_balance_change.tokenA = tokenB;
|
|
200
|
-
trade_balance_change.tokenB = tokenA;
|
|
201
|
-
}
|
|
202
|
-
let trade_extra_info = {
|
|
203
|
-
time,
|
|
204
|
-
broadcast,
|
|
205
|
-
server_info,
|
|
206
|
-
};
|
|
207
|
-
const c_id = this.order_msg.c_id || '';
|
|
208
|
-
const trade_result = {
|
|
209
|
-
success,
|
|
210
|
-
error_code,
|
|
211
|
-
start_time,
|
|
212
|
-
end_time,
|
|
213
|
-
total_time,
|
|
214
|
-
group_id,
|
|
215
|
-
wallet,
|
|
216
|
-
chain_id,
|
|
217
|
-
pair,
|
|
218
|
-
dex_id,
|
|
219
|
-
txid,
|
|
220
|
-
unique_orderbook_id,
|
|
221
|
-
unique_order_msg_id,
|
|
222
|
-
order_price,
|
|
223
|
-
aToB,
|
|
224
|
-
tx_price,
|
|
225
|
-
balance: trade_balance_change,
|
|
226
|
-
execution: trade_extra_info,
|
|
227
|
-
c_id
|
|
228
|
-
};
|
|
229
|
-
return trade_result;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
exports.TransactionResultChecker = TransactionResultChecker;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { StandardPoolInfoType } from '@clonegod/ttd-core';
|
|
2
|
-
import { ParsedTransactionWithMeta, PublicKey, TokenBalance } from '@solana/web3.js';
|
|
3
|
-
import { EventEmitter } from 'events';
|
|
4
|
-
import { StandardSwapDetailType } from '../../types';
|
|
5
|
-
export declare class TransactionResultParser {
|
|
6
|
-
env_args: any;
|
|
7
|
-
event_emitter: EventEmitter;
|
|
8
|
-
wallet_pubkey: PublicKey;
|
|
9
|
-
constructor(env_args: any, wallet_pubkey: PublicKey, event_emitter: EventEmitter);
|
|
10
|
-
parse_transaction_data(txData: ParsedTransactionWithMeta, pool_info: StandardPoolInfoType): StandardSwapDetailType;
|
|
11
|
-
getTokenBalance(owner: string, mint: string, tokenBalances: TokenBalance[]): number;
|
|
12
|
-
}
|
|
13
|
-
export declare const parse_tx_failed_error_code: (dex_id_list: string[], tx_failed_error_msg: string) => string;
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parse_tx_failed_error_code = exports.TransactionResultParser = void 0;
|
|
4
|
-
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
5
|
-
const send_tx_1 = require("../send_tx");
|
|
6
|
-
class TransactionResultParser {
|
|
7
|
-
constructor(env_args, wallet_pubkey, event_emitter) {
|
|
8
|
-
this.env_args = env_args;
|
|
9
|
-
this.wallet_pubkey = wallet_pubkey;
|
|
10
|
-
this.event_emitter = event_emitter;
|
|
11
|
-
}
|
|
12
|
-
parse_transaction_data(txData, pool_info) {
|
|
13
|
-
let success = true;
|
|
14
|
-
let error_code = undefined;
|
|
15
|
-
let { blockTime, meta, transaction, slot } = txData;
|
|
16
|
-
if (meta.err) {
|
|
17
|
-
success = false;
|
|
18
|
-
error_code = (0, exports.parse_tx_failed_error_code)(this.env_args.dex_id_list, JSON.stringify({
|
|
19
|
-
txid: transaction.signatures,
|
|
20
|
-
err: meta.err,
|
|
21
|
-
logMessages: meta.logMessages
|
|
22
|
-
}));
|
|
23
|
-
}
|
|
24
|
-
const { pool_address, tokenA, tokenB, is_reverse_token } = pool_info;
|
|
25
|
-
let txid = transaction.signatures[0];
|
|
26
|
-
const owner = this.wallet_pubkey.toBase58();
|
|
27
|
-
const { preTokenBalances, postTokenBalances, preBalances, postBalances } = meta;
|
|
28
|
-
const tokenA_PreBalance = this.getTokenBalance(owner, tokenA.address, preTokenBalances);
|
|
29
|
-
const tokenA_PostBalance = this.getTokenBalance(owner, tokenA.address, postTokenBalances);
|
|
30
|
-
const tokenB_PreBalance = this.getTokenBalance(owner, tokenB.address, preTokenBalances);
|
|
31
|
-
const tokenB_PostBalance = this.getTokenBalance(owner, tokenB.address, postTokenBalances);
|
|
32
|
-
blockTime = blockTime * 1000 || 0;
|
|
33
|
-
const tokenAChange = Number((tokenA_PostBalance - tokenA_PreBalance).toFixed(tokenA.decimals));
|
|
34
|
-
const tokenBChange = Number((tokenB_PostBalance - tokenB_PreBalance).toFixed(tokenB.decimals));
|
|
35
|
-
let price = "";
|
|
36
|
-
if (success) {
|
|
37
|
-
if (is_reverse_token) {
|
|
38
|
-
price = Math.abs(tokenAChange / tokenBChange).toFixed(tokenA.decimals);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
price = Math.abs(tokenBChange / tokenAChange).toFixed(tokenB.decimals);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
const base_fee = 5000;
|
|
45
|
-
let priority_fee = 0;
|
|
46
|
-
let total_fee = 0;
|
|
47
|
-
let sol_gas_fee = (0, send_tx_1.get_sol_gas_fee)(txid);
|
|
48
|
-
if (sol_gas_fee) {
|
|
49
|
-
priority_fee = sol_gas_fee.priority_fee + sol_gas_fee.jito_tip_fee;
|
|
50
|
-
total_fee = base_fee + priority_fee;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
total_fee = preBalances[0] - postBalances[0];
|
|
54
|
-
priority_fee = Math.abs(total_fee - base_fee);
|
|
55
|
-
}
|
|
56
|
-
let gas_fee = {
|
|
57
|
-
base_fee,
|
|
58
|
-
priority_fee,
|
|
59
|
-
total_fee
|
|
60
|
-
};
|
|
61
|
-
const tradeResult = {
|
|
62
|
-
success,
|
|
63
|
-
error_code,
|
|
64
|
-
wallet: owner,
|
|
65
|
-
block_time: blockTime,
|
|
66
|
-
block_number: slot,
|
|
67
|
-
txid,
|
|
68
|
-
pool_address,
|
|
69
|
-
tokenA: Object.assign(Object.assign({}, tokenA), { pre_bal: tokenA_PreBalance, post_bal: tokenA_PostBalance, change: tokenAChange.toString() }),
|
|
70
|
-
tokenB: Object.assign(Object.assign({}, tokenB), { pre_bal: tokenB_PreBalance, post_bal: tokenB_PostBalance, change: tokenBChange.toString() }),
|
|
71
|
-
tx_price: price,
|
|
72
|
-
gas_fee
|
|
73
|
-
};
|
|
74
|
-
return tradeResult;
|
|
75
|
-
}
|
|
76
|
-
getTokenBalance(owner, mint, tokenBalances) {
|
|
77
|
-
var _a, _b;
|
|
78
|
-
const balance = (_b = (_a = tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.find((e) => e.owner === owner && e.mint == mint)) === null || _a === void 0 ? void 0 : _a.uiTokenAmount) === null || _b === void 0 ? void 0 : _b.uiAmount;
|
|
79
|
-
if (typeof balance !== 'undefined' && balance !== null) {
|
|
80
|
-
return balance;
|
|
81
|
-
}
|
|
82
|
-
return 0;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.TransactionResultParser = TransactionResultParser;
|
|
86
|
-
const parse_tx_failed_error_code = (dex_id_list, tx_failed_error_msg) => {
|
|
87
|
-
(0, dist_1.log_info)(`parse_tx_failed_error_code`, {
|
|
88
|
-
dex_id_list,
|
|
89
|
-
tx_failed_error_msg
|
|
90
|
-
});
|
|
91
|
-
let err_code = "";
|
|
92
|
-
if (dex_id_list.includes(dist_1.DEX_ID.RAYDIUM_AMM)) {
|
|
93
|
-
err_code = parse_raydium_amm_failure(tx_failed_error_msg);
|
|
94
|
-
}
|
|
95
|
-
else if (dex_id_list.includes(dist_1.DEX_ID.RAYDIUM_CLMM)) {
|
|
96
|
-
err_code = parse_raydium_clmm_failure(tx_failed_error_msg);
|
|
97
|
-
}
|
|
98
|
-
else if (dex_id_list.includes(dist_1.DEX_ID.ORCA_CLMM)) {
|
|
99
|
-
err_code = parse_orca_failure(tx_failed_error_msg);
|
|
100
|
-
}
|
|
101
|
-
if (!err_code) {
|
|
102
|
-
if (tx_failed_error_msg.includes('exceeded CUs meter at BPF instruction')) {
|
|
103
|
-
err_code = dist_1.TradeErrorCodeType.ExceededCUsLimit;
|
|
104
|
-
}
|
|
105
|
-
if (tx_failed_error_msg.includes('insufficient funds')) {
|
|
106
|
-
return dist_1.TradeErrorCodeType.InsufficientFunds;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (!err_code) {
|
|
110
|
-
err_code = dist_1.TradeErrorCodeType.UNKOWN;
|
|
111
|
-
}
|
|
112
|
-
return err_code;
|
|
113
|
-
};
|
|
114
|
-
exports.parse_tx_failed_error_code = parse_tx_failed_error_code;
|
|
115
|
-
function parse_raydium_amm_failure(error_msg) {
|
|
116
|
-
if (error_msg.includes('0x28')) {
|
|
117
|
-
return dist_1.TradeErrorCodeType.InsufficientFunds;
|
|
118
|
-
}
|
|
119
|
-
if (error_msg.includes('0x1e') || error_msg.includes('exceeds desired slippage limit')) {
|
|
120
|
-
return dist_1.TradeErrorCodeType.AmountOutBelowMinimum;
|
|
121
|
-
}
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
function parse_raydium_clmm_failure(error_msg) {
|
|
125
|
-
if (error_msg.includes('Computational budget exceeded')) {
|
|
126
|
-
return dist_1.TradeErrorCodeType.ExceededCUsLimit;
|
|
127
|
-
}
|
|
128
|
-
if (error_msg.includes('0x1786') || error_msg.includes('Too little output received')) {
|
|
129
|
-
return dist_1.TradeErrorCodeType.AmountOutBelowMinimum;
|
|
130
|
-
}
|
|
131
|
-
if (error_msg.includes('0x178c') || error_msg.includes('Invaild first tick array account')) {
|
|
132
|
-
return dist_1.TradeErrorCodeType.InvalidTickArraySequence;
|
|
133
|
-
}
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
function parse_orca_failure(error_msg) {
|
|
137
|
-
if (error_msg.includes('0x1]') || error_msg.includes('insufficient funds')) {
|
|
138
|
-
return dist_1.TradeErrorCodeType.InsufficientFunds;
|
|
139
|
-
}
|
|
140
|
-
if (error_msg.includes('0x1794') || error_msg.includes('below minimum threshold')) {
|
|
141
|
-
return dist_1.TradeErrorCodeType.AmountOutBelowMinimum;
|
|
142
|
-
}
|
|
143
|
-
if (error_msg.includes('0xbc4') || error_msg.includes('expected this account to be already initialized')) {
|
|
144
|
-
return dist_1.TradeErrorCodeType.AccountNotInitialized;
|
|
145
|
-
}
|
|
146
|
-
if (error_msg.includes('0x1787') || error_msg.includes('Invalid tick array sequence')) {
|
|
147
|
-
return dist_1.TradeErrorCodeType.InvalidTickArraySequence;
|
|
148
|
-
}
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"txid":"LThcUp2D5p4JgRMnWEUVVSdNEHiq5YfN5HXPGRYeWBfypMT3aTa1CaC9XdPT69CyMdoJ32XAkjXAa2TmBYBeZAy","tx_data":{"transaction":{"signature":{"type":"Buffer","data":[16,200,40,89,141,41,183,98,147,57,1,87,41,149,214,16,175,82,193,82,165,56,77,110,141,91,60,201,155,230,174,58,18,41,245,133,174,58,19,223,250,226,160,136,30,114,91,185,148,117,131,9,56,28,141,128,214,181,22,92,178,181,156,10]},"isVote":false,"transaction":{"signatures":[{"type":"Buffer","data":[16,200,40,89,141,41,183,98,147,57,1,87,41,149,214,16,175,82,193,82,165,56,77,110,141,91,60,201,155,230,174,58,18,41,245,133,174,58,19,223,250,226,160,136,30,114,91,185,148,117,131,9,56,28,141,128,214,181,22,92,178,181,156,10]}],"message":{"header":{"numRequiredSignatures":1,"numReadonlySignedAccounts":0,"numReadonlyUnsignedAccounts":9},"accountKeys":[{"type":"Buffer","data":[21,168,223,201,100,91,51,204,64,225,198,249,160,96,246,185,169,192,171,55,210,185,203,199,218,7,74,5,197,199,28,102]},{"type":"Buffer","data":[35,15,221,235,196,66,135,19,27,253,157,252,117,232,177,135,13,242,61,171,69,181,33,97,225,110,182,179,90,52,75,165]},{"type":"Buffer","data":[61,189,108,237,94,164,238,217,4,165,173,170,205,221,223,73,19,7,33,191,177,94,115,142,189,23,69,240,197,214,155,6]},{"type":"Buffer","data":[66,142,7,8,168,214,201,214,101,235,178,223,185,21,210,54,170,122,213,100,227,116,32,97,144,214,65,145,194,207,116,23]},{"type":"Buffer","data":[85,164,104,186,181,200,66,198,159,69,58,88,99,75,220,67,166,129,150,73,181,188,188,130,199,225,67,11,146,251,182,85]},{"type":"Buffer","data":[79,241,157,230,132,140,160,191,33,109,21,175,127,19,12,206,53,149,234,68,179,148,217,216,246,1,45,146,142,17,222,45]},{"type":"Buffer","data":[116,231,0,156,19,31,133,106,48,98,218,28,178,94,236,27,181,24,145,115,95,223,71,86,219,253,124,39,245,102,47,128]},{"type":"Buffer","data":[121,168,114,186,49,158,162,43,2,239,186,238,20,251,23,169,192,206,193,3,199,240,124,177,85,1,245,201,164,50,160,138]},{"type":"Buffer","data":[124,70,148,31,239,161,196,29,154,187,79,20,139,58,51,81,91,185,151,12,31,56,49,53,137,93,2,112,231,195,28,2]},{"type":"Buffer","data":[188,43,87,6,94,241,221,102,84,48,190,96,107,166,89,108,2,149,48,27,173,239,139,90,252,65,1,65,80,244,18,116]},{"type":"Buffer","data":[190,46,221,15,121,214,61,54,4,16,223,171,173,221,46,30,214,132,42,198,65,191,141,41,55,227,214,28,35,210,244,176]},{"type":"Buffer","data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},{"type":"Buffer","data":[129,110,102,99,12,59,183,36,220,89,228,159,108,196,48,110,96,58,106,172,202,6,250,62,52,226,180,10,213,151,157,141]},{"type":"Buffer","data":[165,213,202,158,4,207,93,181,144,183,20,186,47,227,44,177,89,19,63,193,193,146,183,34,87,253,7,211,156,176,64,30]},{"type":"Buffer","data":[3,6,70,111,229,33,23,50,255,236,173,186,114,195,155,231,188,140,229,187,197,247,18,107,44,67,155,58,64,0,0,0]},{"type":"Buffer","data":[198,250,122,243,190,219,173,58,61,101,243,106,171,201,116,49,177,187,228,194,210,246,224,228,124,166,2,3,69,47,93,97]},{"type":"Buffer","data":[5,74,83,90,153,41,33,6,77,36,232,113,96,218,56,124,124,53,181,221,188,146,187,129,228,31,168,64,65,5,68,141]},{"type":"Buffer","data":[6,155,136,87,254,171,129,132,251,104,127,99,70,24,192,53,218,196,57,220,26,235,59,85,152,160,240,0,0,0,0,1]},{"type":"Buffer","data":[6,221,246,225,215,101,161,147,217,203,225,70,206,235,121,172,28,180,133,237,95,91,55,145,58,140,245,133,126,255,0,169]},{"type":"Buffer","data":[6,221,246,225,238,117,143,222,24,66,93,188,228,108,205,218,182,26,252,77,131,185,13,39,254,189,249,40,216,161,139,252]}],"recentBlockhash":{"type":"Buffer","data":[82,58,243,143,72,241,122,249,155,126,58,109,174,48,72,57,131,236,110,218,173,48,125,246,193,133,101,192,195,219,115,147]},"instructions":[{"programIdIndex":14,"accounts":{},"data":{"type":"Buffer","data":[2,192,212,1,0]}},{"programIdIndex":14,"accounts":{},"data":{"type":"Buffer","data":[3,1,0,0,0,0,0,0,0]}},{"programIdIndex":13,"accounts":{"type":"Buffer","data":[0,12,6,8,7,4,5,1,18,19,16,15,17,10,2,3]},"data":{"type":"Buffer","data":[43,4,237,11,26,201,30,98,232,3,0,0,0,0,0,0,147,26,0,0,0,0,0,0,154,87,105,78,169,26,92,132,177,196,254,255,0,0,0,0,1]}},{"programIdIndex":11,"accounts":{"type":"Buffer","data":[0,9]},"data":{"type":"Buffer","data":[2,0,0,0,32,191,2,0,0,0,0,0]}}],"versioned":false,"addressTableLookups":[]}},"meta":{"fee":"5001","preBalances":["77368771","32092760","72161280","72161280","2039480","22339146210826","1588677399","9876350","2039280","4445332","13641700","1","1705400","1141440","1","377950852239","521498880","994548950606","934087680","1141440"],"postBalances":["77183770","32092760","72161280","72161280","2039480","22339146203949","1588677399","9883227","2039280","4625332","13641700","1","1705400","1141440","1","377950852239","521498880","994548950606","934087680","1141440"],"innerInstructions":[{"index":2,"instructions":[{"programIdIndex":18,"accounts":{"type":"Buffer","data":[8,15,4,0]},"data":{"type":"Buffer","data":[12,232,3,0,0,0,0,0,0,6]},"stackHeight":2},{"programIdIndex":18,"accounts":{"type":"Buffer","data":[5,17,7,6]},"data":{"type":"Buffer","data":[12,221,26,0,0,0,0,0,0,9]},"stackHeight":2}]}],"innerInstructionsNone":false,"logMessages":["Program ComputeBudget111111111111111111111111111111 invoke [1]","Program ComputeBudget111111111111111111111111111111 success","Program ComputeBudget111111111111111111111111111111 invoke [1]","Program ComputeBudget111111111111111111111111111111 success","Program CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK invoke [1]","Program log: Instruction: SwapV2","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]","Program log: Instruction: TransferChecked","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 6200 of 65508 compute units","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]","Program log: Instruction: TransferChecked","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 6238 of 55335 compute units","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success","Program data: QMbN6CYIceJ05wCcEx+FajBi2hyyXuwbtRiRc1/fR1bb/Xwn9WYvgBWo38lkWzPMQOHG+aBg9rmpwKs30rnLx9oHSgXFxxxmeahyujGeoisC77ruFPsXqcDOwQPH8HyxVQH1yaQyoIp8RpQf76HEHZq7TxSLOjNRW7mXDB84MTWJXQJw58McAt0aAAAAAAAAAAAAAAAAAADoAwAAAAAAAAAAAAAAAAAAAEEJYi+uQZFhAAAAAAAAAACl8LhRdAsAAAAAAAAAAAAAorT//w==","Program CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK consumed 77126 of 119700 compute units","Program CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK success","Program 11111111111111111111111111111111 invoke [1]","Program 11111111111111111111111111111111 success"],"logMessagesNone":false,"preTokenBalances":[{"accountIndex":4,"mint":"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","uiTokenAmount":{"uiAmount":410438.861085,"decimals":6,"amount":"410438861085","uiAmountString":"410438.861085"},"owner":"8sLbNZoA1cfnvMJLPfp98ZLAnFSYCFApfJKMbiXNLwxj","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"accountIndex":5,"mint":"So11111111111111111111111111111111111111112","uiTokenAmount":{"uiAmount":22339.129336345,"decimals":9,"amount":"22339129336345","uiAmountString":"22339.129336345"},"owner":"8sLbNZoA1cfnvMJLPfp98ZLAnFSYCFApfJKMbiXNLwxj","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"accountIndex":7,"mint":"So11111111111111111111111111111111111111112","uiTokenAmount":{"uiAmount":0.00783707,"decimals":9,"amount":"7837070","uiAmountString":"0.00783707"},"owner":"2TYv4Tn9raGVs6peco6EkVRKVZt7WwMVNpn5mWEaP7fK","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"accountIndex":8,"mint":"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","uiTokenAmount":{"uiAmount":0.308573,"decimals":6,"amount":"308573","uiAmountString":"0.308573"},"owner":"2TYv4Tn9raGVs6peco6EkVRKVZt7WwMVNpn5mWEaP7fK","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"}],"postTokenBalances":[{"accountIndex":4,"mint":"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","uiTokenAmount":{"uiAmount":410438.862085,"decimals":6,"amount":"410438862085","uiAmountString":"410438.862085"},"owner":"8sLbNZoA1cfnvMJLPfp98ZLAnFSYCFApfJKMbiXNLwxj","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"accountIndex":5,"mint":"So11111111111111111111111111111111111111112","uiTokenAmount":{"uiAmount":22339.129329468,"decimals":9,"amount":"22339129329468","uiAmountString":"22339.129329468"},"owner":"8sLbNZoA1cfnvMJLPfp98ZLAnFSYCFApfJKMbiXNLwxj","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"accountIndex":7,"mint":"So11111111111111111111111111111111111111112","uiTokenAmount":{"uiAmount":0.007843947,"decimals":9,"amount":"7843947","uiAmountString":"0.007843947"},"owner":"2TYv4Tn9raGVs6peco6EkVRKVZt7WwMVNpn5mWEaP7fK","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"accountIndex":8,"mint":"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","uiTokenAmount":{"uiAmount":0.307573,"decimals":6,"amount":"307573","uiAmountString":"0.307573"},"owner":"2TYv4Tn9raGVs6peco6EkVRKVZt7WwMVNpn5mWEaP7fK","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"}],"rewards":[],"loadedWritableAddresses":[],"loadedReadonlyAddresses":[],"returnDataNone":true,"computeUnitsConsumed":"77576"},"index":"1568"},"slot":"324979626"}}
|
package/types/index.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { StandardTokenInfoType, TradeRuntimeType } from "@clonegod/ttd-core";
|
|
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
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface SolanaGasFeeType {
|
|
38
|
-
priority_fee: number
|
|
39
|
-
jito_tip_fee: number
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface SolanaTradeRuntimeType extends TradeRuntimeType {
|
|
43
|
-
// common connection
|
|
44
|
-
connection: Connection
|
|
45
|
-
|
|
46
|
-
// total pay gas for one tx
|
|
47
|
-
total_gas: number
|
|
48
|
-
|
|
49
|
-
// priority fee
|
|
50
|
-
priority_fee: number
|
|
51
|
-
|
|
52
|
-
// Compute Budget: SetComputeUnitPrice
|
|
53
|
-
cu_price: number
|
|
54
|
-
|
|
55
|
-
// Compute Budget: SetComputeUnitLimit
|
|
56
|
-
cu_limit: number
|
|
57
|
-
|
|
58
|
-
tip_amount: number
|
|
59
|
-
|
|
60
|
-
jito_use_separate_tx: boolean
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
export interface SolLastBlockAndSlot {
|
|
65
|
-
context_slot: number
|
|
66
|
-
slot: number
|
|
67
|
-
blockhash: string
|
|
68
|
-
blockHeight: number
|
|
69
|
-
blockTime: number
|
|
70
|
-
}
|
|
71
|
-
|