@clonegod/ttd-sui-common 1.0.34 → 1.0.36
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 +1 -0
- package/dist/index.js +1 -0
- package/dist/trade/abstract_sui_dex_trade_plus.d.ts +32 -0
- package/dist/trade/abstract_sui_dex_trade_plus.js +216 -0
- package/dist/trade/index.d.ts +1 -0
- package/dist/trade/index.js +1 -0
- package/dist/ttd-sui-common/src/constants/index.d.ts +4 -0
- package/dist/ttd-sui-common/src/constants/index.js +8 -0
- package/dist/ttd-sui-common/src/grpc/gas-price-cache.d.ts +21 -0
- package/dist/ttd-sui-common/src/grpc/gas-price-cache.js +83 -0
- package/dist/ttd-sui-common/src/grpc/grpc-connection.d.ts +13 -0
- package/dist/ttd-sui-common/src/grpc/grpc-connection.js +99 -0
- package/dist/ttd-sui-common/src/grpc/index.d.ts +7 -0
- package/dist/ttd-sui-common/src/grpc/index.js +17 -0
- package/dist/ttd-sui-common/src/grpc/ledger-service.d.ts +12 -0
- package/dist/ttd-sui-common/src/grpc/ledger-service.js +161 -0
- package/dist/ttd-sui-common/src/grpc/live-data-service.d.ts +10 -0
- package/dist/ttd-sui-common/src/grpc/live-data-service.js +107 -0
- package/dist/ttd-sui-common/src/grpc/subscription-service.d.ts +7 -0
- package/dist/ttd-sui-common/src/grpc/subscription-service.js +69 -0
- package/dist/ttd-sui-common/src/grpc/sui-grpc-client.d.ts +16 -0
- package/dist/ttd-sui-common/src/grpc/sui-grpc-client.js +38 -0
- package/dist/ttd-sui-common/src/grpc/transaction-service.d.ts +7 -0
- package/dist/ttd-sui-common/src/grpc/transaction-service.js +49 -0
- package/dist/ttd-sui-common/src/index.d.ts +9 -0
- package/dist/ttd-sui-common/src/index.js +25 -0
- package/dist/ttd-sui-common/src/quote/index.d.ts +1 -0
- package/dist/ttd-sui-common/src/quote/index.js +17 -0
- package/dist/ttd-sui-common/src/quote/pricing/index.d.ts +1 -0
- package/dist/ttd-sui-common/src/quote/pricing/index.js +17 -0
- package/dist/ttd-sui-common/src/quote/pricing/token_price_cache.d.ts +9 -0
- package/dist/ttd-sui-common/src/quote/pricing/token_price_cache.js +42 -0
- package/dist/ttd-sui-common/src/redis/index.d.ts +1 -0
- package/dist/ttd-sui-common/src/redis/index.js +17 -0
- package/dist/ttd-sui-common/src/redis/redis_client.d.ts +21 -0
- package/dist/ttd-sui-common/src/redis/redis_client.js +155 -0
- package/dist/ttd-sui-common/src/test/test.d.ts +1 -0
- package/dist/ttd-sui-common/src/test/test.js +126 -0
- package/dist/ttd-sui-common/src/test/test_checkpoint.d.ts +1 -0
- package/dist/ttd-sui-common/src/test/test_checkpoint.js +64 -0
- package/dist/ttd-sui-common/src/test/test_grpc.d.ts +1 -0
- package/dist/ttd-sui-common/src/test/test_grpc.js +84 -0
- package/dist/ttd-sui-common/src/trade/abstract_sui_dex_trade_plus.d.ts +32 -0
- package/dist/ttd-sui-common/src/trade/abstract_sui_dex_trade_plus.js +216 -0
- package/dist/ttd-sui-common/src/trade/check/index.d.ts +1 -0
- package/dist/ttd-sui-common/src/trade/check/index.js +5 -0
- package/dist/ttd-sui-common/src/trade/check/tx_result_checker.d.ts +13 -0
- package/dist/ttd-sui-common/src/trade/check/tx_result_checker.js +111 -0
- package/dist/ttd-sui-common/src/trade/index.d.ts +4 -0
- package/dist/ttd-sui-common/src/trade/index.js +20 -0
- package/dist/ttd-sui-common/src/trade/parse/index.d.ts +1 -0
- package/dist/ttd-sui-common/src/trade/parse/index.js +5 -0
- package/dist/ttd-sui-common/src/trade/parse/sui_tx_parser.d.ts +13 -0
- package/dist/ttd-sui-common/src/trade/parse/sui_tx_parser.js +167 -0
- package/dist/ttd-sui-common/src/trade/send_tx/index.d.ts +10 -0
- package/dist/ttd-sui-common/src/trade/send_tx/index.js +48 -0
- package/dist/ttd-sui-common/src/trade/test/test_parse_sui_tx_result.d.ts +1 -0
- package/dist/ttd-sui-common/src/trade/test/test_parse_sui_tx_result.js +105 -0
- package/dist/ttd-sui-common/src/type/index.d.ts +18 -0
- package/dist/ttd-sui-common/src/type/index.js +2 -0
- package/dist/ttd-sui-common/src/utils/checkpoint_parse.d.ts +0 -0
- package/dist/ttd-sui-common/src/utils/checkpoint_parse.js +0 -0
- package/dist/ttd-sui-common/src/utils/decode.d.ts +2 -0
- package/dist/ttd-sui-common/src/utils/decode.js +43 -0
- package/dist/ttd-sui-common/src/utils/format.d.ts +1 -0
- package/dist/ttd-sui-common/src/utils/format.js +18 -0
- package/dist/ttd-sui-common/src/utils/index.d.ts +2 -0
- package/dist/ttd-sui-common/src/utils/index.js +18 -0
- package/dist/ttd-sui-market-data/src/sui_objects/config_manager.d.ts +22 -0
- package/dist/ttd-sui-market-data/src/sui_objects/config_manager.js +169 -0
- package/dist/ttd-sui-market-data/src/sui_objects/example.d.ts +1 -0
- package/dist/ttd-sui-market-data/src/sui_objects/example.js +72 -0
- package/dist/ttd-sui-market-data/src/sui_objects/index.d.ts +6 -0
- package/dist/ttd-sui-market-data/src/sui_objects/index.js +15 -0
- package/dist/ttd-sui-market-data/src/sui_objects/object_mgt.d.ts +47 -0
- package/dist/ttd-sui-market-data/src/sui_objects/object_mgt.js +483 -0
- package/dist/ttd-sui-market-data/src/sui_objects/types.d.ts +60 -0
- package/dist/ttd-sui-market-data/src/sui_objects/types.js +24 -0
- package/dist/ttd-sui-market-data/src/sui_objects/version_checker.d.ts +30 -0
- package/dist/ttd-sui-market-data/src/sui_objects/version_checker.js +207 -0
- package/package.json +1 -1
|
@@ -0,0 +1,216 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AbstractSuiDexTradePlus = void 0;
|
|
16
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
17
|
+
const ed25519_1 = require("@mysten/sui/keypairs/ed25519");
|
|
18
|
+
const client_1 = require("@mysten/sui/client");
|
|
19
|
+
const index_1 = require("../index");
|
|
20
|
+
const redis_1 = require("../redis");
|
|
21
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
22
|
+
class AbstractSuiDexTradePlus extends dist_1.AbastrcatTrade {
|
|
23
|
+
constructor(appConfig, grpcClient) {
|
|
24
|
+
super();
|
|
25
|
+
this.appConfig = appConfig;
|
|
26
|
+
this.walletMode = 'multi';
|
|
27
|
+
this.walletAddresses = [];
|
|
28
|
+
this.currentWalletAddress = '';
|
|
29
|
+
this.grpcClient = grpcClient;
|
|
30
|
+
this.initConfigs();
|
|
31
|
+
this.chainNameLower = this.appConfig.env_args.chain_id.toLowerCase();
|
|
32
|
+
this.redisClient = new redis_1.SimpleRedisClient(`${this.chainNameLower}:tx`);
|
|
33
|
+
}
|
|
34
|
+
initSuiClient() {
|
|
35
|
+
const sui_rpc_url = process.env.SUI_RPC_URL || 'https://fullnode.mainnet.sui.io:443';
|
|
36
|
+
this.sui_client = new client_1.SuiClient({ url: sui_rpc_url });
|
|
37
|
+
(0, dist_1.log_info)(`Sui客户端已初始化: ${sui_rpc_url}`);
|
|
38
|
+
}
|
|
39
|
+
init() {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
this.initSuiClient();
|
|
42
|
+
const walletGroupIds = process.env.SUI_WALLET_GROUP_IDS || '';
|
|
43
|
+
this.walletMode = walletGroupIds && walletGroupIds.trim().split(',').length > 0 ? 'multi' : 'single';
|
|
44
|
+
if (this.walletMode === 'multi') {
|
|
45
|
+
let wallet_infos = (0, dist_1.load_wallet_multi)(walletGroupIds.split(','), false);
|
|
46
|
+
this.group_wallets = wallet_infos.map(info => ed25519_1.Ed25519Keypair.fromSecretKey(info.private_key));
|
|
47
|
+
this.walletAddresses = this.group_wallets.map(keypair => keypair.getPublicKey().toSuiAddress());
|
|
48
|
+
(0, dist_1.log_info)(`组钱包已初始化,数量: ${this.group_wallets.length}`, this.walletAddresses);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const { private_key } = this.appConfig.trade_runtime.wallet;
|
|
52
|
+
this.wallet = ed25519_1.Ed25519Keypair.fromSecretKey(private_key);
|
|
53
|
+
this.currentWalletAddress = this.wallet.getPublicKey().toSuiAddress();
|
|
54
|
+
this.walletAddresses = [this.currentWalletAddress];
|
|
55
|
+
(0, dist_1.log_info)(`单钱包已初始化,walletAddress= ${this.currentWalletAddress}`);
|
|
56
|
+
}
|
|
57
|
+
this.transactionSender = new index_1.SuiTxSender(this.appConfig, this.sui_client, this.grpcClient);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
getWalletMode() {
|
|
61
|
+
return this.walletMode;
|
|
62
|
+
}
|
|
63
|
+
getSingleWallet() {
|
|
64
|
+
if (this.walletMode !== 'single' || !this.wallet) {
|
|
65
|
+
throw new Error('Single wallet not available in multi-wallet mode or not initialized');
|
|
66
|
+
}
|
|
67
|
+
return this.wallet;
|
|
68
|
+
}
|
|
69
|
+
getGroupWallets() {
|
|
70
|
+
if (this.walletMode !== 'multi' || !this.group_wallets) {
|
|
71
|
+
throw new Error('Group wallets not available in single-wallet mode or not initialized');
|
|
72
|
+
}
|
|
73
|
+
return this.group_wallets;
|
|
74
|
+
}
|
|
75
|
+
getWalletAddresses() {
|
|
76
|
+
return this.walletAddresses;
|
|
77
|
+
}
|
|
78
|
+
chooseWallet(context) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
var _a, _b;
|
|
81
|
+
if (this.getWalletMode() === 'single') {
|
|
82
|
+
return this.getSingleWallet();
|
|
83
|
+
}
|
|
84
|
+
const { inputToken } = this.determineInputOutputTokens(context.order_msg, context.pool_info);
|
|
85
|
+
console.log('inputToken', inputToken);
|
|
86
|
+
const requiredAmount = new decimal_js_1.default(context.order_msg.amount);
|
|
87
|
+
const wallet_assets = yield this.redisClient.hgetall('sui:wallet:assets');
|
|
88
|
+
if (!wallet_assets || Object.keys(wallet_assets).length === 0) {
|
|
89
|
+
throw new Error('没有找到钱包资产信息,请确保钱包监控服务正在运行');
|
|
90
|
+
}
|
|
91
|
+
const wallet_assets_map = {};
|
|
92
|
+
for (const [walletAddress, assetsJson] of Object.entries(wallet_assets)) {
|
|
93
|
+
try {
|
|
94
|
+
wallet_assets_map[walletAddress] = JSON.parse(assetsJson);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
console.warn(`解析钱包资产数据失败: ${walletAddress}`, error);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const availableWallets = [];
|
|
101
|
+
const allWallets = [];
|
|
102
|
+
for (const [walletAddress, assets] of Object.entries(wallet_assets_map)) {
|
|
103
|
+
try {
|
|
104
|
+
const wallet = (_a = this.group_wallets) === null || _a === void 0 ? void 0 : _a.find(w => w.getPublicKey().toSuiAddress().toLowerCase() === walletAddress.toLowerCase());
|
|
105
|
+
if (!wallet) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const tokenAsset = (_b = assets.tokens) === null || _b === void 0 ? void 0 : _b.find((token) => token.tokenaddr.toLowerCase() === inputToken.address.toLowerCase());
|
|
109
|
+
let tokenBalance = (tokenAsset === null || tokenAsset === void 0 ? void 0 : tokenAsset.balance) || '0';
|
|
110
|
+
const balanceDecimal = new decimal_js_1.default(tokenBalance);
|
|
111
|
+
if (balanceDecimal.gte(requiredAmount)) {
|
|
112
|
+
availableWallets.push({
|
|
113
|
+
wallet,
|
|
114
|
+
balance: tokenBalance
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
console.log(`钱包 ${walletAddress} 余额不足: ${tokenBalance} ${inputToken.symbol} < ${requiredAmount} ${inputToken.symbol}`);
|
|
119
|
+
}
|
|
120
|
+
allWallets.push({
|
|
121
|
+
wallet,
|
|
122
|
+
balance: tokenBalance
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
console.warn(`处理钱包资产时出错: ${walletAddress}`, error);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (availableWallets.length === 0) {
|
|
130
|
+
let error_msg = `all wallets are insufficient, required: ${requiredAmount} ${inputToken.symbol}`;
|
|
131
|
+
(0, dist_1.log_warn)(error_msg);
|
|
132
|
+
allWallets.forEach((walletInfo, index) => {
|
|
133
|
+
const walletAddress = walletInfo.wallet.getPublicKey().toSuiAddress();
|
|
134
|
+
const shortAddress = walletAddress.substring(0, 6) + '...' + walletAddress.substring(walletAddress.length - 4);
|
|
135
|
+
console.log(`${index + 1}. ${shortAddress}: ${walletInfo.balance} ${inputToken.symbol}`);
|
|
136
|
+
});
|
|
137
|
+
throw new Error(error_msg);
|
|
138
|
+
}
|
|
139
|
+
console.log('availableWallets', availableWallets.map(w => w.wallet.getPublicKey().toSuiAddress()));
|
|
140
|
+
const wallet_last_used = yield this.redisClient.hgetall('sui:wallet:last_used');
|
|
141
|
+
for (const availableWallet of availableWallets) {
|
|
142
|
+
const walletAddress = availableWallet.wallet.getPublicKey().toSuiAddress();
|
|
143
|
+
const lastUsedData = wallet_last_used === null || wallet_last_used === void 0 ? void 0 : wallet_last_used[walletAddress];
|
|
144
|
+
if (lastUsedData) {
|
|
145
|
+
try {
|
|
146
|
+
const lastUsedInfo = JSON.parse(lastUsedData);
|
|
147
|
+
availableWallet.lastUsedAt = lastUsedInfo.lastUsedAt;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
console.warn(`解析钱包最后使用时间失败: ${walletAddress}`, error);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
yield this.redisClient.hsetValue('sui:wallet:last_used', walletAddress, JSON.stringify({
|
|
155
|
+
lastUsedAt: 0,
|
|
156
|
+
lastUsedTime: new Date(0).toISOString()
|
|
157
|
+
}), 24 * 60 * 60);
|
|
158
|
+
availableWallet.lastUsedAt = 0;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
let selectedWallet;
|
|
162
|
+
let selectionStrategy;
|
|
163
|
+
if (availableWallets.length === 1) {
|
|
164
|
+
selectedWallet = availableWallets[0].wallet;
|
|
165
|
+
selectionStrategy = 'OnlyOne';
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
const hasUsageHistory = wallet_last_used && Object.keys(wallet_last_used).length > 0;
|
|
169
|
+
if (hasUsageHistory) {
|
|
170
|
+
availableWallets.sort((a, b) => {
|
|
171
|
+
const aTime = a.lastUsedAt || 0;
|
|
172
|
+
const bTime = b.lastUsedAt || 0;
|
|
173
|
+
return aTime - bTime;
|
|
174
|
+
});
|
|
175
|
+
selectedWallet = availableWallets[0].wallet;
|
|
176
|
+
selectionStrategy = 'MaxLastUsed';
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
availableWallets.sort((a, b) => {
|
|
180
|
+
const aBalance = new decimal_js_1.default(a.balance);
|
|
181
|
+
const bBalance = new decimal_js_1.default(b.balance);
|
|
182
|
+
return bBalance.cmp(aBalance);
|
|
183
|
+
});
|
|
184
|
+
selectedWallet = availableWallets[0].wallet;
|
|
185
|
+
selectionStrategy = 'MaxBalance';
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const selectedWalletAddress = selectedWallet.getPublicKey().toSuiAddress();
|
|
189
|
+
yield this.redisClient.hsetValue('sui:wallet:last_used', selectedWalletAddress, JSON.stringify({
|
|
190
|
+
lastUsedAt: Date.now(),
|
|
191
|
+
lastUsedTime: new Date().toISOString()
|
|
192
|
+
}), 24 * 60 * 60);
|
|
193
|
+
const selectedWalletInfo = availableWallets.find(w => w.wallet.getPublicKey().toSuiAddress() === selectedWalletAddress);
|
|
194
|
+
(0, dist_1.log_info)(`Choose wallet: ${selectionStrategy} -> ${selectedWalletAddress}, balance: ${selectedWalletInfo === null || selectedWalletInfo === void 0 ? void 0 : selectedWalletInfo.balance} ${inputToken.symbol}, required: ${requiredAmount} ${inputToken.symbol}`);
|
|
195
|
+
return selectedWallet;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
determineInputOutputTokens(order_msg, pool_info) {
|
|
199
|
+
const { aToB } = order_msg;
|
|
200
|
+
const { tokenA, tokenB, quote_token } = pool_info;
|
|
201
|
+
const quoteToken = [tokenA, tokenB].find(token => token.symbol === quote_token);
|
|
202
|
+
const nonQuoteToken = [tokenA, tokenB].find(token => token.symbol !== quote_token);
|
|
203
|
+
const inputToken = aToB ? nonQuoteToken : quoteToken;
|
|
204
|
+
const outputToken = aToB ? quoteToken : nonQuoteToken;
|
|
205
|
+
if (!inputToken || !outputToken) {
|
|
206
|
+
throw new Error(`无法确定输入/输出代币: ${JSON.stringify({
|
|
207
|
+
tokenA: tokenA.symbol,
|
|
208
|
+
tokenB: tokenB.symbol,
|
|
209
|
+
quote: quote_token,
|
|
210
|
+
aToB
|
|
211
|
+
})}`);
|
|
212
|
+
}
|
|
213
|
+
return { inputToken, outputToken };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
exports.AbstractSuiDexTradePlus = AbstractSuiDexTradePlus;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TransactionResultChecker } from "./tx_result_checker";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionResultChecker = void 0;
|
|
4
|
+
var tx_result_checker_1 = require("./tx_result_checker");
|
|
5
|
+
Object.defineProperty(exports, "TransactionResultChecker", { enumerable: true, get: function () { return tx_result_checker_1.TransactionResultChecker; } });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EnvArgs } from "@clonegod/ttd-core/dist";
|
|
2
|
+
import { AbstractTransactionResultCheck } from "@clonegod/ttd-core/dist/trade";
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
|
+
import { SuiTransactionParser } from "../parse/sui_tx_parser";
|
|
5
|
+
import { LedgerService } from "../../index";
|
|
6
|
+
export declare class TransactionResultChecker extends AbstractTransactionResultCheck {
|
|
7
|
+
transactionParser: SuiTransactionParser;
|
|
8
|
+
leadgerService: LedgerService;
|
|
9
|
+
constructor(env_args: EnvArgs, event_emitter: EventEmitter, wallet_address: string, ledgerService: LedgerService);
|
|
10
|
+
check_tx_result_interval(): Promise<void>;
|
|
11
|
+
on_subscibe_transaction(): void;
|
|
12
|
+
private processTransactionResult;
|
|
13
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
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 trade_1 = require("@clonegod/ttd-core/dist/trade");
|
|
15
|
+
const sui_tx_parser_1 = require("../parse/sui_tx_parser");
|
|
16
|
+
const index_1 = require("../../index");
|
|
17
|
+
class TransactionResultChecker extends trade_1.AbstractTransactionResultCheck {
|
|
18
|
+
constructor(env_args, event_emitter, wallet_address, ledgerService) {
|
|
19
|
+
super(env_args, event_emitter);
|
|
20
|
+
this.transactionParser = new sui_tx_parser_1.SuiTransactionParser(wallet_address);
|
|
21
|
+
this.leadgerService = ledgerService;
|
|
22
|
+
}
|
|
23
|
+
check_tx_result_interval() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const check_start_time = Date.now();
|
|
26
|
+
const check_interval = parseInt(process.env.CHECK_TX_RESULT_INTERVAL_MILLS || '3000');
|
|
27
|
+
const check_timeout = parseInt(process.env.CHECK_TX_RESULT_TIMEOUT_MILLS || '30000');
|
|
28
|
+
if (check_interval >= check_timeout) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
this.check_count += 1;
|
|
33
|
+
(0, dist_1.log_info)(`check transaction start: seq=[${this.check_count}], txhash= ${this.txid}, trace_id=${this.trace_id}`);
|
|
34
|
+
try {
|
|
35
|
+
if (Date.now() - check_start_time < check_timeout) {
|
|
36
|
+
let txReceipt = yield this.leadgerService.getTransaction(this.txid, ['*']);
|
|
37
|
+
if (!txReceipt || (0, dist_1.isEmpty)(txReceipt)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
txReceipt['transaction']['signatures'] = [];
|
|
41
|
+
txReceipt = (0, index_1.decodeBytes)(txReceipt);
|
|
42
|
+
(0, dist_1.log_info)(`Received transaction result via polling: ${this.txid}`);
|
|
43
|
+
clearInterval(intervalId);
|
|
44
|
+
yield this.processTransactionResult(txReceipt, 'interval');
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
clearInterval(intervalId);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
clearInterval(intervalId);
|
|
52
|
+
(0, dist_1.log_error)('parse transaction error!', err);
|
|
53
|
+
}
|
|
54
|
+
}), check_interval);
|
|
55
|
+
this.intervalId = intervalId;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
on_subscibe_transaction() {
|
|
59
|
+
this.event_emitter.once(`SUI_TX_RESULT_${this.txid}`, (response) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
(0, dist_1.log_info)(`receive tx result notification, txid=${this.txid}`);
|
|
61
|
+
if (response.transaction) {
|
|
62
|
+
this.processTransactionResult(response, 'grpc');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
for (let i = 1; i <= 6; i++) {
|
|
66
|
+
(0, dist_1.log_info)(`re-fetch tx result by ledgerService start, i=${i}, txid=${this.txid}`);
|
|
67
|
+
try {
|
|
68
|
+
let txReceipt = yield this.leadgerService.getTransaction(this.txid, ['*']);
|
|
69
|
+
if (txReceipt) {
|
|
70
|
+
this.processTransactionResult(txReceipt, 'grpc2');
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
(0, dist_1.log_warn)(`re-fetch tx result by ledgerService failed, i=${i}, txid=${this.txid}, error=${error.message}`);
|
|
76
|
+
}
|
|
77
|
+
yield (0, dist_1.sleep)(1000);
|
|
78
|
+
}
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
processTransactionResult(txReceipt, source) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
if (this.trade_result_already_processed) {
|
|
84
|
+
(0, dist_1.log_warn)(`trade_result_already_processed=${this.trade_result_already_processed}, ignore trade result fetch by ${source} check!`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const swap_detail = yield this.transactionParser.parseTransaction(txReceipt, this.pool_info);
|
|
88
|
+
let trade_result = this.map_swap_result_to_tx_result(swap_detail);
|
|
89
|
+
this.trade_result_already_processed = true;
|
|
90
|
+
if (this.intervalId) {
|
|
91
|
+
clearInterval(this.intervalId);
|
|
92
|
+
this.intervalId = null;
|
|
93
|
+
}
|
|
94
|
+
if (trade_result.success) {
|
|
95
|
+
this.event_emitter.emit(dist_1.TRANSACTION_STATE_SUCCESS, trade_result);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
this.event_emitter.emit(dist_1.TRANSACTION_STATE_FAILED, trade_result);
|
|
99
|
+
}
|
|
100
|
+
if (source === 'interval') {
|
|
101
|
+
console.log('--------------------- Transaction Result from Polling ---------------------');
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
console.log('--------------------- Transaction Result from GRPC ---------------------');
|
|
105
|
+
}
|
|
106
|
+
console.log(JSON.stringify(trade_result, null, 2));
|
|
107
|
+
console.log('-----------------------------------------------------------------------------');
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.TransactionResultChecker = TransactionResultChecker;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./send_tx"), exports);
|
|
18
|
+
__exportStar(require("./check"), exports);
|
|
19
|
+
__exportStar(require("./parse"), exports);
|
|
20
|
+
__exportStar(require("./abstract_sui_dex_trade_plus"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SuiTransactionParser } from "./sui_tx_parser";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SuiTransactionParser = void 0;
|
|
4
|
+
var sui_tx_parser_1 = require("./sui_tx_parser");
|
|
5
|
+
Object.defineProperty(exports, "SuiTransactionParser", { enumerable: true, get: function () { return sui_tx_parser_1.SuiTransactionParser; } });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { StandardPoolInfoType, StandardSwapDetailType } from "@clonegod/ttd-core";
|
|
2
|
+
export declare class SuiTransactionParser {
|
|
3
|
+
private walletAddress;
|
|
4
|
+
constructor(walletAddress: string);
|
|
5
|
+
parseTransaction(receipt: any, poolInfo: StandardPoolInfoType): Promise<StandardSwapDetailType>;
|
|
6
|
+
parse_transaction_result(tx_receipt: any, pool_info: StandardPoolInfoType): Promise<StandardSwapDetailType>;
|
|
7
|
+
private calculateGasFee;
|
|
8
|
+
private calc_tx_price;
|
|
9
|
+
private create_failed_result;
|
|
10
|
+
private parseErrorMsgToErrorCode;
|
|
11
|
+
private extractTimestamp;
|
|
12
|
+
private extractCheckpoint;
|
|
13
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SuiTransactionParser = void 0;
|
|
16
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
17
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
18
|
+
const index_1 = require("../../index");
|
|
19
|
+
class SuiTransactionParser {
|
|
20
|
+
constructor(walletAddress) {
|
|
21
|
+
this.walletAddress = walletAddress;
|
|
22
|
+
}
|
|
23
|
+
parseTransaction(receipt, poolInfo) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
26
|
+
try {
|
|
27
|
+
if (((_c = (_b = (_a = receipt.transaction) === null || _a === void 0 ? void 0 : _a.effects) === null || _b === void 0 ? void 0 : _b.status) === null || _c === void 0 ? void 0 : _c.success) !== true || ((_e = (_d = receipt.transaction) === null || _d === void 0 ? void 0 : _d.balance_changes) === null || _e === void 0 ? void 0 : _e.length) === 0) {
|
|
28
|
+
console.log('Transaction failed', {
|
|
29
|
+
txid: (_f = receipt.transaction) === null || _f === void 0 ? void 0 : _f.digest,
|
|
30
|
+
success: (_j = (_h = (_g = receipt.transaction) === null || _g === void 0 ? void 0 : _g.effects) === null || _h === void 0 ? void 0 : _h.status) === null || _j === void 0 ? void 0 : _j.success,
|
|
31
|
+
balance_changes: (_l = (_k = receipt.transaction) === null || _k === void 0 ? void 0 : _k.balance_changes) === null || _l === void 0 ? void 0 : _l.length,
|
|
32
|
+
reason: (_q = (_p = (_o = (_m = receipt.transaction) === null || _m === void 0 ? void 0 : _m.effects) === null || _o === void 0 ? void 0 : _o.status) === null || _p === void 0 ? void 0 : _p.error) === null || _q === void 0 ? void 0 : _q.kind
|
|
33
|
+
});
|
|
34
|
+
throw new Error('Transaction failed');
|
|
35
|
+
}
|
|
36
|
+
return yield this.parse_transaction_result(receipt, poolInfo);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error('Error parsing transaction:', error);
|
|
40
|
+
return this.create_failed_result(receipt, poolInfo, error.message);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
parse_transaction_result(tx_receipt, pool_info) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
var _a, _b, _c, _d, _e, _f;
|
|
47
|
+
const txid = ((_a = tx_receipt.transaction) === null || _a === void 0 ? void 0 : _a.digest) || '';
|
|
48
|
+
let swap_detail = null;
|
|
49
|
+
let tokenAChangeAmount = new decimal_js_1.default(0);
|
|
50
|
+
let tokenBChangeAmount = new decimal_js_1.default(0);
|
|
51
|
+
const balanceChanges = ((_b = tx_receipt.transaction) === null || _b === void 0 ? void 0 : _b.balance_changes) || [];
|
|
52
|
+
console.dir({ txid, balance_changes: balanceChanges }, { depth: 4 });
|
|
53
|
+
for (const change of balanceChanges) {
|
|
54
|
+
if (change.address.toLowerCase() !== this.walletAddress.toLowerCase()) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const amount = new decimal_js_1.default(change.amount);
|
|
58
|
+
const coinType = change.coin_type;
|
|
59
|
+
const normalizedCoinType = (0, index_1.normalizeSuiTokenAddress)(coinType);
|
|
60
|
+
const poolTokenAAddress = (0, index_1.normalizeSuiTokenAddress)(pool_info.tokenA.address);
|
|
61
|
+
const poolTokenBAddress = (0, index_1.normalizeSuiTokenAddress)(pool_info.tokenB.address);
|
|
62
|
+
if (normalizedCoinType === poolTokenAAddress) {
|
|
63
|
+
tokenAChangeAmount = amount.div(Math.pow(10, pool_info.tokenA.decimals));
|
|
64
|
+
}
|
|
65
|
+
if (normalizedCoinType === poolTokenBAddress) {
|
|
66
|
+
tokenBChangeAmount = amount.div(Math.pow(10, pool_info.tokenB.decimals));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
let tx_price = this.calc_tx_price(tokenAChangeAmount, tokenBChangeAmount, pool_info);
|
|
70
|
+
swap_detail = {
|
|
71
|
+
tokenA: Object.assign(Object.assign({}, pool_info.tokenA), { pre_bal: 0, post_bal: 0, change: tokenAChangeAmount }),
|
|
72
|
+
tokenB: Object.assign(Object.assign({}, pool_info.tokenB), { pre_bal: 0, post_bal: 0, change: tokenBChangeAmount }),
|
|
73
|
+
tx_price,
|
|
74
|
+
};
|
|
75
|
+
const gasFee = this.calculateGasFee(tx_receipt);
|
|
76
|
+
return {
|
|
77
|
+
success: true,
|
|
78
|
+
error_code: '',
|
|
79
|
+
wallet: this.walletAddress,
|
|
80
|
+
txid,
|
|
81
|
+
block_time: this.extractTimestamp(tx_receipt),
|
|
82
|
+
block_number: this.extractCheckpoint(tx_receipt),
|
|
83
|
+
pool_address: pool_info.pool_address,
|
|
84
|
+
tokenA: Object.assign(Object.assign({}, pool_info.tokenA), { pre_bal: 0, post_bal: 0, change: ((_d = (_c = swap_detail === null || swap_detail === void 0 ? void 0 : swap_detail.tokenA) === null || _c === void 0 ? void 0 : _c.change) === null || _d === void 0 ? void 0 : _d.toNumber()) || 0 }),
|
|
85
|
+
tokenB: Object.assign(Object.assign({}, pool_info.tokenB), { pre_bal: 0, post_bal: 0, change: ((_f = (_e = swap_detail === null || swap_detail === void 0 ? void 0 : swap_detail.tokenB) === null || _e === void 0 ? void 0 : _e.change) === null || _f === void 0 ? void 0 : _f.toNumber()) || 0 }),
|
|
86
|
+
tx_price: (swap_detail === null || swap_detail === void 0 ? void 0 : swap_detail.tx_price) || '0',
|
|
87
|
+
gas_fee: gasFee
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
calculateGasFee(receipt) {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
const gasUsed = (_b = (_a = receipt.transaction) === null || _a === void 0 ? void 0 : _a.effects) === null || _b === void 0 ? void 0 : _b.gas_used;
|
|
94
|
+
if (!gasUsed) {
|
|
95
|
+
return {
|
|
96
|
+
base_fee: 0,
|
|
97
|
+
priority_fee: 0,
|
|
98
|
+
total_fee: 0
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const computationCost = new decimal_js_1.default(gasUsed.computation_cost || 0);
|
|
102
|
+
const storageCost = new decimal_js_1.default(gasUsed.storage_cost || 0);
|
|
103
|
+
const storageRebate = new decimal_js_1.default(gasUsed.storage_rebate || 0);
|
|
104
|
+
const nonRefundableStorageFee = new decimal_js_1.default(gasUsed.non_refundable_storage_fee || 0);
|
|
105
|
+
const totalCost = computationCost.plus(storageCost).minus(storageRebate).plus(nonRefundableStorageFee);
|
|
106
|
+
const totalCostInSui = totalCost.div(Math.pow(10, 9));
|
|
107
|
+
return {
|
|
108
|
+
base_fee: computationCost.div(Math.pow(10, 9)).toNumber(),
|
|
109
|
+
priority_fee: storageCost.div(Math.pow(10, 9)).toNumber(),
|
|
110
|
+
total_fee: totalCostInSui.toNumber()
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
calc_tx_price(tokenAChange, tokenBChange, pool_info) {
|
|
114
|
+
if (tokenAChange.eq(0) || tokenBChange.eq(0)) {
|
|
115
|
+
return '0';
|
|
116
|
+
}
|
|
117
|
+
if (pool_info.quote_token === pool_info.tokenA.symbol) {
|
|
118
|
+
return tokenAChange.abs().div(tokenBChange.abs()).toFixed(12);
|
|
119
|
+
}
|
|
120
|
+
if (pool_info.quote_token === pool_info.tokenB.symbol) {
|
|
121
|
+
return tokenBChange.abs().div(tokenAChange.abs()).toFixed(12);
|
|
122
|
+
}
|
|
123
|
+
return '0';
|
|
124
|
+
}
|
|
125
|
+
create_failed_result(txReceipt, poolInfo, errorMessage) {
|
|
126
|
+
var _a;
|
|
127
|
+
const gasFee = this.calculateGasFee(txReceipt);
|
|
128
|
+
return {
|
|
129
|
+
success: false,
|
|
130
|
+
error_code: this.parseErrorMsgToErrorCode(errorMessage),
|
|
131
|
+
wallet: this.walletAddress,
|
|
132
|
+
txid: ((_a = txReceipt.transaction) === null || _a === void 0 ? void 0 : _a.digest) || '',
|
|
133
|
+
block_time: this.extractTimestamp(txReceipt),
|
|
134
|
+
block_number: this.extractCheckpoint(txReceipt),
|
|
135
|
+
pool_address: poolInfo.pool_address,
|
|
136
|
+
tokenA: Object.assign(Object.assign({}, poolInfo.tokenA), { pre_bal: 0, post_bal: 0, change: 0 }),
|
|
137
|
+
tokenB: Object.assign(Object.assign({}, poolInfo.tokenB), { pre_bal: 0, post_bal: 0, change: 0 }),
|
|
138
|
+
tx_price: '0',
|
|
139
|
+
gas_fee: gasFee
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
parseErrorMsgToErrorCode(errorMessage) {
|
|
143
|
+
(0, dist_1.log_info)(`parseErrorMsgToErrorCode: errorMessage=${errorMessage}`);
|
|
144
|
+
if (errorMessage.includes('Insufficient funds')) {
|
|
145
|
+
return dist_1.TradeErrorCodeType.InsufficientFunds;
|
|
146
|
+
}
|
|
147
|
+
if (errorMessage.includes('Amount out below minimum')) {
|
|
148
|
+
return dist_1.TradeErrorCodeType.AmountOutBelowMinimum;
|
|
149
|
+
}
|
|
150
|
+
if (errorMessage.includes('Slippage tolerance exceeded')) {
|
|
151
|
+
return dist_1.TradeErrorCodeType.AmountOutBelowMinimum;
|
|
152
|
+
}
|
|
153
|
+
return dist_1.TradeErrorCodeType.UNKOWN;
|
|
154
|
+
}
|
|
155
|
+
extractTimestamp(receipt) {
|
|
156
|
+
var _a;
|
|
157
|
+
const timestamp = (_a = receipt.transaction) === null || _a === void 0 ? void 0 : _a.timestamp;
|
|
158
|
+
if (timestamp === null || timestamp === void 0 ? void 0 : timestamp.seconds) {
|
|
159
|
+
return parseInt(timestamp.seconds) * 1000;
|
|
160
|
+
}
|
|
161
|
+
return Date.now();
|
|
162
|
+
}
|
|
163
|
+
extractCheckpoint(receipt) {
|
|
164
|
+
return parseInt(receipt.checkpoint || '0');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.SuiTransactionParser = SuiTransactionParser;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AppConfig } from "@clonegod/ttd-core/dist";
|
|
2
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
3
|
+
import { SuiGrpcClient } from "../../index";
|
|
4
|
+
export declare class SuiTxSender {
|
|
5
|
+
appConfig: AppConfig;
|
|
6
|
+
sui_client: SuiClient;
|
|
7
|
+
grpcClient: SuiGrpcClient;
|
|
8
|
+
constructor(appConfig: AppConfig, sui_client: SuiClient, grpcClient: SuiGrpcClient);
|
|
9
|
+
send_tx: (signedTxBytes: string, signature: string, txDigest: string) => Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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.SuiTxSender = void 0;
|
|
13
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
14
|
+
class SuiTxSender {
|
|
15
|
+
constructor(appConfig, sui_client, grpcClient) {
|
|
16
|
+
this.send_tx = (signedTxBytes, signature, txDigest) => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const bcsBytes = Buffer.from(signedTxBytes, 'base64');
|
|
18
|
+
const signatureBytes = Buffer.from(signature, 'base64');
|
|
19
|
+
try {
|
|
20
|
+
let _response = yield this.sui_client.executeTransactionBlock({
|
|
21
|
+
transactionBlock: signedTxBytes,
|
|
22
|
+
signature: signature,
|
|
23
|
+
options: {
|
|
24
|
+
showEvents: true,
|
|
25
|
+
showBalanceChanges: true,
|
|
26
|
+
showObjectChanges: true,
|
|
27
|
+
showEffects: true
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
this.appConfig.emit(`SUI_TX_RESULT_${txDigest}`, txDigest);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
(0, dist_1.log_error)(`send tx by rpc failed!!! txid=${txDigest}`, error);
|
|
34
|
+
try {
|
|
35
|
+
let response = yield this.grpcClient.transactionService.executeTransaction(bcsBytes, signatureBytes);
|
|
36
|
+
this.appConfig.emit(`SUI_TX_RESULT_${txDigest}`, response);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
(0, dist_1.log_error)(`send tx by grpc failed!!! txid=${txDigest}`, error);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
this.appConfig = appConfig;
|
|
44
|
+
this.sui_client = sui_client;
|
|
45
|
+
this.grpcClient = grpcClient;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.SuiTxSender = SuiTxSender;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|