@clonegod/ttd-sui-common 1.0.68 → 1.0.70

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.
Files changed (127) hide show
  1. package/dist/grpc/grpc-connection.js +15 -6
  2. package/dist/test/test_grpc.js +12 -2
  3. package/dist/trade/parse/sui_tx_parser.js +0 -13
  4. package/dist/trade/test/test_parse_sui_tx_result.js +24 -24
  5. package/package.json +1 -1
  6. package/dist/rpc/account-api.d.ts +0 -14
  7. package/dist/rpc/account-api.js +0 -113
  8. package/dist/rpc/coin-api.d.ts +0 -0
  9. package/dist/rpc/coin-api.js +0 -0
  10. package/dist/rpc/rpc-connection.d.ts +0 -8
  11. package/dist/rpc/rpc-connection.js +0 -54
  12. package/dist/test/test_checkpoint_processor.d.ts +0 -1
  13. package/dist/test/test_checkpoint_processor.js +0 -112
  14. package/dist/test/test_checkpoint_subscription.d.ts +0 -1
  15. package/dist/test/test_checkpoint_subscription.js +0 -132
  16. package/dist/test/test_checkpoint_with_schema.d.ts +0 -1
  17. package/dist/test/test_checkpoint_with_schema.js +0 -250
  18. package/dist/test/test_dynamic_bcs.d.ts +0 -1
  19. package/dist/test/test_dynamic_bcs.js +0 -82
  20. package/dist/test/test_github_extractor.d.ts +0 -1
  21. package/dist/test/test_github_extractor.js +0 -69
  22. package/dist/test/test_hybrid_bcs.d.ts +0 -1
  23. package/dist/test/test_hybrid_bcs.js +0 -98
  24. package/dist/test/test_momentum_events.d.ts +0 -1
  25. package/dist/test/test_momentum_events.js +0 -113
  26. package/dist/test/test_rpc.d.ts +0 -1
  27. package/dist/test/test_rpc.js +0 -34
  28. package/dist/test/test_schema_database.d.ts +0 -1
  29. package/dist/test/test_schema_database.js +0 -91
  30. package/dist/test/test_simple_schema.d.ts +0 -1
  31. package/dist/test/test_simple_schema.js +0 -78
  32. package/dist/test/test_single_momentum_event.d.ts +0 -1
  33. package/dist/test/test_single_momentum_event.js +0 -44
  34. package/dist/ttd-sui-common/src/constants/index.d.ts +0 -4
  35. package/dist/ttd-sui-common/src/constants/index.js +0 -8
  36. package/dist/ttd-sui-common/src/grpc/gas-price-cache.d.ts +0 -21
  37. package/dist/ttd-sui-common/src/grpc/gas-price-cache.js +0 -83
  38. package/dist/ttd-sui-common/src/grpc/grpc-connection.d.ts +0 -13
  39. package/dist/ttd-sui-common/src/grpc/grpc-connection.js +0 -99
  40. package/dist/ttd-sui-common/src/grpc/index.d.ts +0 -7
  41. package/dist/ttd-sui-common/src/grpc/index.js +0 -17
  42. package/dist/ttd-sui-common/src/grpc/ledger-service.d.ts +0 -12
  43. package/dist/ttd-sui-common/src/grpc/ledger-service.js +0 -161
  44. package/dist/ttd-sui-common/src/grpc/live-data-service.d.ts +0 -10
  45. package/dist/ttd-sui-common/src/grpc/live-data-service.js +0 -107
  46. package/dist/ttd-sui-common/src/grpc/subscription-service.d.ts +0 -7
  47. package/dist/ttd-sui-common/src/grpc/subscription-service.js +0 -69
  48. package/dist/ttd-sui-common/src/grpc/sui-grpc-client.d.ts +0 -16
  49. package/dist/ttd-sui-common/src/grpc/sui-grpc-client.js +0 -38
  50. package/dist/ttd-sui-common/src/grpc/transaction-service.d.ts +0 -7
  51. package/dist/ttd-sui-common/src/grpc/transaction-service.js +0 -49
  52. package/dist/ttd-sui-common/src/index.d.ts +0 -9
  53. package/dist/ttd-sui-common/src/index.js +0 -25
  54. package/dist/ttd-sui-common/src/quote/index.d.ts +0 -1
  55. package/dist/ttd-sui-common/src/quote/index.js +0 -17
  56. package/dist/ttd-sui-common/src/quote/pricing/index.d.ts +0 -1
  57. package/dist/ttd-sui-common/src/quote/pricing/index.js +0 -17
  58. package/dist/ttd-sui-common/src/quote/pricing/token_price_cache.d.ts +0 -9
  59. package/dist/ttd-sui-common/src/quote/pricing/token_price_cache.js +0 -42
  60. package/dist/ttd-sui-common/src/redis/index.d.ts +0 -1
  61. package/dist/ttd-sui-common/src/redis/index.js +0 -17
  62. package/dist/ttd-sui-common/src/redis/redis_client.d.ts +0 -21
  63. package/dist/ttd-sui-common/src/redis/redis_client.js +0 -155
  64. package/dist/ttd-sui-common/src/test/test.d.ts +0 -1
  65. package/dist/ttd-sui-common/src/test/test.js +0 -126
  66. package/dist/ttd-sui-common/src/test/test_checkpoint.d.ts +0 -1
  67. package/dist/ttd-sui-common/src/test/test_checkpoint.js +0 -64
  68. package/dist/ttd-sui-common/src/test/test_grpc.d.ts +0 -1
  69. package/dist/ttd-sui-common/src/test/test_grpc.js +0 -84
  70. package/dist/ttd-sui-common/src/trade/abstract_sui_dex_trade_plus.d.ts +0 -32
  71. package/dist/ttd-sui-common/src/trade/abstract_sui_dex_trade_plus.js +0 -216
  72. package/dist/ttd-sui-common/src/trade/check/index.d.ts +0 -1
  73. package/dist/ttd-sui-common/src/trade/check/index.js +0 -5
  74. package/dist/ttd-sui-common/src/trade/check/tx_result_checker.d.ts +0 -13
  75. package/dist/ttd-sui-common/src/trade/check/tx_result_checker.js +0 -111
  76. package/dist/ttd-sui-common/src/trade/index.d.ts +0 -4
  77. package/dist/ttd-sui-common/src/trade/index.js +0 -20
  78. package/dist/ttd-sui-common/src/trade/parse/index.d.ts +0 -1
  79. package/dist/ttd-sui-common/src/trade/parse/index.js +0 -5
  80. package/dist/ttd-sui-common/src/trade/parse/sui_tx_parser.d.ts +0 -13
  81. package/dist/ttd-sui-common/src/trade/parse/sui_tx_parser.js +0 -167
  82. package/dist/ttd-sui-common/src/trade/send_tx/index.d.ts +0 -10
  83. package/dist/ttd-sui-common/src/trade/send_tx/index.js +0 -48
  84. package/dist/ttd-sui-common/src/trade/test/test_parse_sui_tx_result.d.ts +0 -1
  85. package/dist/ttd-sui-common/src/trade/test/test_parse_sui_tx_result.js +0 -105
  86. package/dist/ttd-sui-common/src/type/index.d.ts +0 -18
  87. package/dist/ttd-sui-common/src/type/index.js +0 -2
  88. package/dist/ttd-sui-common/src/utils/checkpoint_parse.d.ts +0 -0
  89. package/dist/ttd-sui-common/src/utils/checkpoint_parse.js +0 -0
  90. package/dist/ttd-sui-common/src/utils/decode.d.ts +0 -2
  91. package/dist/ttd-sui-common/src/utils/decode.js +0 -43
  92. package/dist/ttd-sui-common/src/utils/format.d.ts +0 -1
  93. package/dist/ttd-sui-common/src/utils/format.js +0 -18
  94. package/dist/ttd-sui-common/src/utils/index.d.ts +0 -2
  95. package/dist/ttd-sui-common/src/utils/index.js +0 -18
  96. package/dist/ttd-sui-market-data/src/sui_objects/config_manager.d.ts +0 -22
  97. package/dist/ttd-sui-market-data/src/sui_objects/config_manager.js +0 -169
  98. package/dist/ttd-sui-market-data/src/sui_objects/example.d.ts +0 -1
  99. package/dist/ttd-sui-market-data/src/sui_objects/example.js +0 -72
  100. package/dist/ttd-sui-market-data/src/sui_objects/index.d.ts +0 -6
  101. package/dist/ttd-sui-market-data/src/sui_objects/index.js +0 -15
  102. package/dist/ttd-sui-market-data/src/sui_objects/object_mgt.d.ts +0 -47
  103. package/dist/ttd-sui-market-data/src/sui_objects/object_mgt.js +0 -483
  104. package/dist/ttd-sui-market-data/src/sui_objects/types.d.ts +0 -60
  105. package/dist/ttd-sui-market-data/src/sui_objects/types.js +0 -24
  106. package/dist/ttd-sui-market-data/src/sui_objects/version_checker.d.ts +0 -30
  107. package/dist/ttd-sui-market-data/src/sui_objects/version_checker.js +0 -207
  108. package/dist/utils/bcs-parser.d.ts +0 -8
  109. package/dist/utils/bcs-parser.js +0 -121
  110. package/dist/utils/checkpoint-processor.d.ts +0 -7
  111. package/dist/utils/checkpoint-processor.js +0 -123
  112. package/dist/utils/checkpoint.d.ts +0 -7
  113. package/dist/utils/checkpoint.js +0 -26
  114. package/dist/utils/dex-parser-manager.d.ts +0 -7
  115. package/dist/utils/dex-parser-manager.js +0 -138
  116. package/dist/utils/dex_event_parser.d.ts +0 -34
  117. package/dist/utils/dex_event_parser.js +0 -132
  118. package/dist/utils/dex_schema_database.d.ts +0 -206
  119. package/dist/utils/dex_schema_database.js +0 -169
  120. package/dist/utils/dynamic_bcs_parser.d.ts +0 -21
  121. package/dist/utils/dynamic_bcs_parser.js +0 -166
  122. package/dist/utils/github_schema_extractor.d.ts +0 -20
  123. package/dist/utils/github_schema_extractor.js +0 -153
  124. package/dist/utils/hybrid_bcs_parser.d.ts +0 -22
  125. package/dist/utils/hybrid_bcs_parser.js +0 -194
  126. package/dist/utils/simple_schema_parser.d.ts +0 -76
  127. package/dist/utils/simple_schema_parser.js +0 -193
@@ -1,4 +0,0 @@
1
- export * from './send_tx';
2
- export * from './check';
3
- export * from './parse';
4
- export * from './abstract_sui_dex_trade_plus';
@@ -1,20 +0,0 @@
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);
@@ -1 +0,0 @@
1
- export { SuiTransactionParser } from "./sui_tx_parser";
@@ -1,5 +0,0 @@
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; } });
@@ -1,13 +0,0 @@
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
- }
@@ -1,167 +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
- 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;
@@ -1,10 +0,0 @@
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
- }
@@ -1,48 +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.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;
@@ -1,105 +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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- require('dotenv').config();
16
- const fs_1 = __importDefault(require("fs"));
17
- const sui_tx_parser_1 = require("../parse/sui_tx_parser");
18
- const index_1 = require("../../index");
19
- const index_2 = require("../../index");
20
- function test_get_tx_result() {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const grpc_endpoint = process.env.SUI_GRPC_ENDPOINT || '';
23
- const grpc_token = process.env.SUI_GRPC_TOKEN || '';
24
- const grpcConnection = index_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
25
- const ledgerService = new index_1.LedgerService(grpcConnection);
26
- let wallet_address = '0x6367c8755b8c39cab7305bfa75cb17d050508d2e55f6862a7682377ad6d46ee7';
27
- let test_tx_success_buy = {
28
- txid: '',
29
- filename: './src/trade/test/receipt_buy_sui.json'
30
- };
31
- let test_tx_success_sell = {
32
- txid: '28FaeTYoctpP1VdWCuyPxNEBeaMm3ebj27kdF5umi9YL',
33
- filename: './src/trade/test/receipt_sell_sui.json'
34
- };
35
- let { txid, filename } = test_tx_success_sell;
36
- console.log('=== 测试 SUI 链交易结果查询 ===');
37
- console.log('交易哈希:', txid);
38
- try {
39
- const raw_tx_result = yield ledgerService.getTransaction(txid, ['*']);
40
- console.log('✅ 成功获取交易结果');
41
- const decoded_tx_result = (0, index_2.decodeBytes)(raw_tx_result);
42
- fs_1.default.writeFileSync(filename, JSON.stringify(decoded_tx_result, null, 2));
43
- let poolInfo = get_pool_info();
44
- const parser = new sui_tx_parser_1.SuiTransactionParser(wallet_address);
45
- const result = yield parser.parseTransaction(raw_tx_result, poolInfo);
46
- console.log('解析交易结果:', JSON.stringify(result, null, 2));
47
- }
48
- catch (error) {
49
- console.error('❌ 查询失败:', error);
50
- }
51
- });
52
- }
53
- function get_pool_info() {
54
- return {
55
- "program_id": "",
56
- "authority": "",
57
- "subscribe_type": "grpc",
58
- "pair": "SUI/USDT",
59
- "dex_id": "MOMENTUM-CLMM",
60
- "pool_name": "SUI/USDC",
61
- "pool_address": "0x455cf8d2ac91e7cb883f515874af750ed3cd18195c970b7a2d46235ac2b0c388",
62
- "pool_address_hex": "",
63
- "tokenA": {
64
- "symbol": "SUI",
65
- "address": "0x2::sui::SUI",
66
- "address_hex": "",
67
- "decimals": 9,
68
- "name": "Sui",
69
- "is_token2022": false,
70
- "market_price": "3.27",
71
- "update_time": "2025-09-01 20:25:48 469",
72
- "alias": "",
73
- "enable": true
74
- },
75
- "tokenB": {
76
- "symbol": "USDC",
77
- "address": "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
78
- "address_hex": "",
79
- "decimals": 6,
80
- "name": "USDC",
81
- "is_token2022": false,
82
- "market_price": "0.9992228892",
83
- "update_time": "2025-09-01 20:25:48 469",
84
- "alias": "",
85
- "enable": true
86
- },
87
- "vaultA": "",
88
- "vaultB": "",
89
- "router_id": null,
90
- "fee_rate": 25,
91
- "quote_token": "USDC",
92
- "quote_amount_usd": 200,
93
- "quote_price_decimals": 18,
94
- "is_reverse_token": false,
95
- "cu_limit": 200000,
96
- "tvl": 14160391.2697,
97
- "vol_24h": 21668306.2082508,
98
- "update_time": "2025-09-01 20:25:48 899",
99
- "enable": true,
100
- };
101
- }
102
- if (require.main === module) {
103
- test_get_tx_result()
104
- .catch(console.error);
105
- }
@@ -1,18 +0,0 @@
1
- export interface BlockUpdateEvent {
2
- blockHash: string;
3
- blockNumber: number;
4
- blockTime: number;
5
- transactions: TransactionData[];
6
- }
7
- export interface TransactionData {
8
- txHash: string;
9
- txIndex: number;
10
- txType: string;
11
- events: SimpleTxEventsType[];
12
- }
13
- export interface SimpleTxEventsType {
14
- pool_address: string;
15
- dex_id: string;
16
- pair: string;
17
- events: any[];
18
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
File without changes
@@ -1,2 +0,0 @@
1
- export declare function decodeBytes(obj: any): any;
2
- export declare function parseObjectAmount(objectResponse: any): string | null;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decodeBytes = decodeBytes;
4
- exports.parseObjectAmount = parseObjectAmount;
5
- function decodeBytes(obj) {
6
- if (Array.isArray(obj)) {
7
- return obj.map((item) => decodeBytes(item));
8
- }
9
- else if (obj && typeof obj === 'object') {
10
- const result = {};
11
- for (const key of Object.keys(obj)) {
12
- const val = obj[key];
13
- if (Buffer.isBuffer(val) || (Array.isArray(val) && typeof val[0] === 'number')) {
14
- result[key] = Buffer.from(val).toString('hex');
15
- }
16
- else {
17
- result[key] = decodeBytes(val);
18
- }
19
- }
20
- return result;
21
- }
22
- return obj;
23
- }
24
- function parseObjectAmount(objectResponse) {
25
- var _a, _b;
26
- try {
27
- if (!((_b = (_a = objectResponse === null || objectResponse === void 0 ? void 0 : objectResponse.object) === null || _a === void 0 ? void 0 : _a.contents) === null || _b === void 0 ? void 0 : _b.value)) {
28
- return null;
29
- }
30
- const contentsValue = objectResponse.object.contents.value;
31
- if (contentsValue.length < 80) {
32
- return null;
33
- }
34
- const balanceHex = contentsValue.substring(64, 80);
35
- const balanceBytes = Buffer.from(balanceHex, 'hex');
36
- const balance = balanceBytes.readBigUInt64LE(0).toString();
37
- return balance;
38
- }
39
- catch (error) {
40
- console.error('提取代币余额失败:', error);
41
- return null;
42
- }
43
- }
@@ -1 +0,0 @@
1
- export declare const normalizeSuiTokenAddress: (address: string, useLongAddress?: boolean) => string;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeSuiTokenAddress = void 0;
4
- const constants_1 = require("../constants");
5
- const normalizeSuiTokenAddress = (address, useLongAddress = true) => {
6
- if (useLongAddress) {
7
- if (address === constants_1.SUI_TOKEN_ADDRESS.SHORT) {
8
- return constants_1.SUI_TOKEN_ADDRESS.LONG;
9
- }
10
- }
11
- else {
12
- if (address === constants_1.SUI_TOKEN_ADDRESS.LONG) {
13
- return constants_1.SUI_TOKEN_ADDRESS.SHORT;
14
- }
15
- }
16
- return address;
17
- };
18
- exports.normalizeSuiTokenAddress = normalizeSuiTokenAddress;
@@ -1,2 +0,0 @@
1
- export * from './decode';
2
- export * from './format';
@@ -1,18 +0,0 @@
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("./decode"), exports);
18
- __exportStar(require("./format"), exports);
@@ -1,22 +0,0 @@
1
- import { TokenConfig } from './types';
2
- export declare class ConfigManager {
3
- private configs;
4
- private configPath;
5
- constructor(configPath?: string);
6
- private loadConfigFromFile;
7
- private initializeDefaultConfigs;
8
- getTokenConfig(tokenAddress: string): TokenConfig;
9
- addTokenConfig(config: TokenConfig): void;
10
- updateTokenConfig(tokenAddress: string, updates: Partial<TokenConfig>): void;
11
- removeTokenConfig(tokenAddress: string): void;
12
- getAllTokenConfigs(): TokenConfig[];
13
- getGasTokenConfigs(): TokenConfig[];
14
- getNonGasTokenConfigs(): TokenConfig[];
15
- needsMaintenance(tokenAddress: string, availableCount: number): {
16
- needsSplit: boolean;
17
- needsMerge: boolean;
18
- reason: string;
19
- };
20
- private extractTokenSymbol;
21
- printAllConfigs(): void;
22
- }