@clonegod/ttd-sui-common 1.0.69 → 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 (126) hide show
  1. package/dist/grpc/grpc-connection.js +15 -6
  2. package/dist/test/test_grpc.js +12 -2
  3. package/dist/trade/test/test_parse_sui_tx_result.js +24 -24
  4. package/package.json +1 -1
  5. package/dist/rpc/account-api.d.ts +0 -14
  6. package/dist/rpc/account-api.js +0 -113
  7. package/dist/rpc/coin-api.d.ts +0 -0
  8. package/dist/rpc/coin-api.js +0 -0
  9. package/dist/rpc/rpc-connection.d.ts +0 -8
  10. package/dist/rpc/rpc-connection.js +0 -54
  11. package/dist/test/test_checkpoint_processor.d.ts +0 -1
  12. package/dist/test/test_checkpoint_processor.js +0 -112
  13. package/dist/test/test_checkpoint_subscription.d.ts +0 -1
  14. package/dist/test/test_checkpoint_subscription.js +0 -132
  15. package/dist/test/test_checkpoint_with_schema.d.ts +0 -1
  16. package/dist/test/test_checkpoint_with_schema.js +0 -250
  17. package/dist/test/test_dynamic_bcs.d.ts +0 -1
  18. package/dist/test/test_dynamic_bcs.js +0 -82
  19. package/dist/test/test_github_extractor.d.ts +0 -1
  20. package/dist/test/test_github_extractor.js +0 -69
  21. package/dist/test/test_hybrid_bcs.d.ts +0 -1
  22. package/dist/test/test_hybrid_bcs.js +0 -98
  23. package/dist/test/test_momentum_events.d.ts +0 -1
  24. package/dist/test/test_momentum_events.js +0 -113
  25. package/dist/test/test_rpc.d.ts +0 -1
  26. package/dist/test/test_rpc.js +0 -34
  27. package/dist/test/test_schema_database.d.ts +0 -1
  28. package/dist/test/test_schema_database.js +0 -91
  29. package/dist/test/test_simple_schema.d.ts +0 -1
  30. package/dist/test/test_simple_schema.js +0 -78
  31. package/dist/test/test_single_momentum_event.d.ts +0 -1
  32. package/dist/test/test_single_momentum_event.js +0 -44
  33. package/dist/ttd-sui-common/src/constants/index.d.ts +0 -4
  34. package/dist/ttd-sui-common/src/constants/index.js +0 -8
  35. package/dist/ttd-sui-common/src/grpc/gas-price-cache.d.ts +0 -21
  36. package/dist/ttd-sui-common/src/grpc/gas-price-cache.js +0 -83
  37. package/dist/ttd-sui-common/src/grpc/grpc-connection.d.ts +0 -13
  38. package/dist/ttd-sui-common/src/grpc/grpc-connection.js +0 -99
  39. package/dist/ttd-sui-common/src/grpc/index.d.ts +0 -7
  40. package/dist/ttd-sui-common/src/grpc/index.js +0 -17
  41. package/dist/ttd-sui-common/src/grpc/ledger-service.d.ts +0 -12
  42. package/dist/ttd-sui-common/src/grpc/ledger-service.js +0 -161
  43. package/dist/ttd-sui-common/src/grpc/live-data-service.d.ts +0 -10
  44. package/dist/ttd-sui-common/src/grpc/live-data-service.js +0 -107
  45. package/dist/ttd-sui-common/src/grpc/subscription-service.d.ts +0 -7
  46. package/dist/ttd-sui-common/src/grpc/subscription-service.js +0 -69
  47. package/dist/ttd-sui-common/src/grpc/sui-grpc-client.d.ts +0 -16
  48. package/dist/ttd-sui-common/src/grpc/sui-grpc-client.js +0 -38
  49. package/dist/ttd-sui-common/src/grpc/transaction-service.d.ts +0 -7
  50. package/dist/ttd-sui-common/src/grpc/transaction-service.js +0 -49
  51. package/dist/ttd-sui-common/src/index.d.ts +0 -9
  52. package/dist/ttd-sui-common/src/index.js +0 -25
  53. package/dist/ttd-sui-common/src/quote/index.d.ts +0 -1
  54. package/dist/ttd-sui-common/src/quote/index.js +0 -17
  55. package/dist/ttd-sui-common/src/quote/pricing/index.d.ts +0 -1
  56. package/dist/ttd-sui-common/src/quote/pricing/index.js +0 -17
  57. package/dist/ttd-sui-common/src/quote/pricing/token_price_cache.d.ts +0 -9
  58. package/dist/ttd-sui-common/src/quote/pricing/token_price_cache.js +0 -42
  59. package/dist/ttd-sui-common/src/redis/index.d.ts +0 -1
  60. package/dist/ttd-sui-common/src/redis/index.js +0 -17
  61. package/dist/ttd-sui-common/src/redis/redis_client.d.ts +0 -21
  62. package/dist/ttd-sui-common/src/redis/redis_client.js +0 -155
  63. package/dist/ttd-sui-common/src/test/test.d.ts +0 -1
  64. package/dist/ttd-sui-common/src/test/test.js +0 -126
  65. package/dist/ttd-sui-common/src/test/test_checkpoint.d.ts +0 -1
  66. package/dist/ttd-sui-common/src/test/test_checkpoint.js +0 -64
  67. package/dist/ttd-sui-common/src/test/test_grpc.d.ts +0 -1
  68. package/dist/ttd-sui-common/src/test/test_grpc.js +0 -84
  69. package/dist/ttd-sui-common/src/trade/abstract_sui_dex_trade_plus.d.ts +0 -32
  70. package/dist/ttd-sui-common/src/trade/abstract_sui_dex_trade_plus.js +0 -216
  71. package/dist/ttd-sui-common/src/trade/check/index.d.ts +0 -1
  72. package/dist/ttd-sui-common/src/trade/check/index.js +0 -5
  73. package/dist/ttd-sui-common/src/trade/check/tx_result_checker.d.ts +0 -13
  74. package/dist/ttd-sui-common/src/trade/check/tx_result_checker.js +0 -111
  75. package/dist/ttd-sui-common/src/trade/index.d.ts +0 -4
  76. package/dist/ttd-sui-common/src/trade/index.js +0 -20
  77. package/dist/ttd-sui-common/src/trade/parse/index.d.ts +0 -1
  78. package/dist/ttd-sui-common/src/trade/parse/index.js +0 -5
  79. package/dist/ttd-sui-common/src/trade/parse/sui_tx_parser.d.ts +0 -13
  80. package/dist/ttd-sui-common/src/trade/parse/sui_tx_parser.js +0 -167
  81. package/dist/ttd-sui-common/src/trade/send_tx/index.d.ts +0 -10
  82. package/dist/ttd-sui-common/src/trade/send_tx/index.js +0 -48
  83. package/dist/ttd-sui-common/src/trade/test/test_parse_sui_tx_result.d.ts +0 -1
  84. package/dist/ttd-sui-common/src/trade/test/test_parse_sui_tx_result.js +0 -105
  85. package/dist/ttd-sui-common/src/type/index.d.ts +0 -18
  86. package/dist/ttd-sui-common/src/type/index.js +0 -2
  87. package/dist/ttd-sui-common/src/utils/checkpoint_parse.d.ts +0 -0
  88. package/dist/ttd-sui-common/src/utils/checkpoint_parse.js +0 -0
  89. package/dist/ttd-sui-common/src/utils/decode.d.ts +0 -2
  90. package/dist/ttd-sui-common/src/utils/decode.js +0 -43
  91. package/dist/ttd-sui-common/src/utils/format.d.ts +0 -1
  92. package/dist/ttd-sui-common/src/utils/format.js +0 -18
  93. package/dist/ttd-sui-common/src/utils/index.d.ts +0 -2
  94. package/dist/ttd-sui-common/src/utils/index.js +0 -18
  95. package/dist/ttd-sui-market-data/src/sui_objects/config_manager.d.ts +0 -22
  96. package/dist/ttd-sui-market-data/src/sui_objects/config_manager.js +0 -169
  97. package/dist/ttd-sui-market-data/src/sui_objects/example.d.ts +0 -1
  98. package/dist/ttd-sui-market-data/src/sui_objects/example.js +0 -72
  99. package/dist/ttd-sui-market-data/src/sui_objects/index.d.ts +0 -6
  100. package/dist/ttd-sui-market-data/src/sui_objects/index.js +0 -15
  101. package/dist/ttd-sui-market-data/src/sui_objects/object_mgt.d.ts +0 -47
  102. package/dist/ttd-sui-market-data/src/sui_objects/object_mgt.js +0 -483
  103. package/dist/ttd-sui-market-data/src/sui_objects/types.d.ts +0 -60
  104. package/dist/ttd-sui-market-data/src/sui_objects/types.js +0 -24
  105. package/dist/ttd-sui-market-data/src/sui_objects/version_checker.d.ts +0 -30
  106. package/dist/ttd-sui-market-data/src/sui_objects/version_checker.js +0 -207
  107. package/dist/utils/bcs-parser.d.ts +0 -8
  108. package/dist/utils/bcs-parser.js +0 -121
  109. package/dist/utils/checkpoint-processor.d.ts +0 -7
  110. package/dist/utils/checkpoint-processor.js +0 -123
  111. package/dist/utils/checkpoint.d.ts +0 -7
  112. package/dist/utils/checkpoint.js +0 -26
  113. package/dist/utils/dex-parser-manager.d.ts +0 -7
  114. package/dist/utils/dex-parser-manager.js +0 -138
  115. package/dist/utils/dex_event_parser.d.ts +0 -34
  116. package/dist/utils/dex_event_parser.js +0 -132
  117. package/dist/utils/dex_schema_database.d.ts +0 -206
  118. package/dist/utils/dex_schema_database.js +0 -169
  119. package/dist/utils/dynamic_bcs_parser.d.ts +0 -21
  120. package/dist/utils/dynamic_bcs_parser.js +0 -166
  121. package/dist/utils/github_schema_extractor.d.ts +0 -20
  122. package/dist/utils/github_schema_extractor.js +0 -153
  123. package/dist/utils/hybrid_bcs_parser.d.ts +0 -22
  124. package/dist/utils/hybrid_bcs_parser.js +0 -194
  125. package/dist/utils/simple_schema_parser.d.ts +0 -76
  126. package/dist/utils/simple_schema_parser.js +0 -193
@@ -1,10 +0,0 @@
1
- import { GrpcConnection } from './grpc-connection';
2
- export declare class LiveDataService {
3
- private liveDataClient;
4
- private connection;
5
- constructor(connection: GrpcConnection);
6
- getBalance(owner: string, coinType: string): Promise<any>;
7
- listBalances(owner: string): Promise<unknown>;
8
- getCoinInfo(coinType: string): Promise<unknown>;
9
- listOwnedObjects(owner: string, coinType?: string, limit?: number, readMask?: string[]): Promise<unknown>;
10
- }
@@ -1,107 +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.LiveDataService = void 0;
13
- const utils_1 = require("../utils");
14
- class LiveDataService {
15
- constructor(connection) {
16
- this.connection = connection;
17
- this.liveDataClient = connection.createServiceClient('live_data_service.proto', 'LiveDataService');
18
- }
19
- getBalance(owner, coinType) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- if (!owner) {
22
- throw new Error('owner 参数是必需的');
23
- }
24
- if (!coinType) {
25
- coinType = '0x2::sui::SUI';
26
- }
27
- return new Promise((resolve, reject) => {
28
- const request = {
29
- owner: owner,
30
- coin_type: coinType
31
- };
32
- this.liveDataClient.GetBalance(request, this.connection.getMetadata(), (error, response) => {
33
- if (error)
34
- reject(error);
35
- else
36
- resolve(response);
37
- });
38
- });
39
- });
40
- }
41
- listBalances(owner) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- return new Promise((resolve, reject) => {
44
- this.liveDataClient.ListBalances({ owner }, this.connection.getMetadata(), (error, response) => {
45
- if (error)
46
- reject(error);
47
- else
48
- resolve(response);
49
- });
50
- });
51
- });
52
- }
53
- getCoinInfo(coinType) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- return new Promise((resolve, reject) => {
56
- this.liveDataClient.GetCoinInfo({ coin_type: coinType }, this.connection.getMetadata(), (error, response) => {
57
- if (error)
58
- reject(error);
59
- else
60
- resolve(response);
61
- });
62
- });
63
- });
64
- }
65
- listOwnedObjects(owner, coinType, limit, readMask) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- return new Promise((resolve, reject) => {
68
- const request = { owner };
69
- if (coinType) {
70
- const objectType = coinType.startsWith('0x2::coin::Coin<')
71
- ? coinType
72
- : `0x2::coin::Coin<${coinType}>`;
73
- request.object_type = objectType;
74
- }
75
- if (limit)
76
- request.page_size = limit;
77
- if (readMask && readMask.length > 0) {
78
- request.read_mask = {
79
- paths: readMask
80
- };
81
- }
82
- else {
83
- request.read_mask = {
84
- paths: [
85
- "object_id",
86
- "version",
87
- "digest",
88
- "owner",
89
- "object_type",
90
- "storage_rebate",
91
- "balance"
92
- ]
93
- };
94
- }
95
- this.liveDataClient.ListOwnedObjects(request, this.connection.getMetadata(), (error, response) => {
96
- if (error)
97
- reject(error);
98
- else {
99
- let res = (0, utils_1.decodeBytes)(response);
100
- resolve(res);
101
- }
102
- });
103
- });
104
- });
105
- }
106
- }
107
- exports.LiveDataService = LiveDataService;
@@ -1,7 +0,0 @@
1
- import { GrpcConnection } from './grpc-connection';
2
- export declare class SubscriptionService {
3
- private subscriptionClient;
4
- private connection;
5
- constructor(connection: GrpcConnection);
6
- subscribeCheckpoints(onCheckpoint: (response: any) => void, onError: (error: any) => void, readMask?: string[]): any;
7
- }
@@ -1,69 +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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.SubscriptionService = void 0;
37
- const dotenv = __importStar(require("dotenv"));
38
- dotenv.config();
39
- class SubscriptionService {
40
- constructor(connection) {
41
- this.connection = connection;
42
- this.subscriptionClient = connection.createServiceClient('subscription_service.proto', 'SubscriptionService');
43
- }
44
- subscribeCheckpoints(onCheckpoint, onError, readMask) {
45
- const request = {};
46
- if (!readMask || readMask.length === 0) {
47
- readMask = [
48
- 'sequence_number',
49
- 'digest',
50
- 'summary',
51
- 'transactions',
52
- ];
53
- }
54
- request.read_mask = { paths: readMask };
55
- const stream = this.subscriptionClient.SubscribeCheckpoints(request, this.connection.getMetadata());
56
- stream.on('data', (response) => {
57
- onCheckpoint(response);
58
- });
59
- stream.on('error', (error) => {
60
- console.error('订阅检查点流错误:', error);
61
- onError(error);
62
- });
63
- stream.on('end', () => {
64
- console.log('检查点流订阅结束');
65
- });
66
- return stream;
67
- }
68
- }
69
- exports.SubscriptionService = SubscriptionService;
@@ -1,16 +0,0 @@
1
- import { LedgerService } from "./ledger-service";
2
- import { LiveDataService } from "./live-data-service";
3
- import { SubscriptionService } from "./subscription-service";
4
- import { TransactionService } from "./transaction-service";
5
- import { GasPriceCache } from "./gas-price-cache";
6
- export declare class SuiGrpcClient {
7
- ledgerService: LedgerService;
8
- transactionService: TransactionService;
9
- liveDataService: LiveDataService;
10
- subscriptionService: SubscriptionService;
11
- gasPriceCache: GasPriceCache;
12
- gas_price: number;
13
- constructor();
14
- init(): void;
15
- get_gas_price(): Promise<number>;
16
- }
@@ -1,38 +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.SuiGrpcClient = void 0;
13
- const grpc_connection_1 = require("./grpc-connection");
14
- const ledger_service_1 = require("./ledger-service");
15
- const live_data_service_1 = require("./live-data-service");
16
- const subscription_service_1 = require("./subscription-service");
17
- const transaction_service_1 = require("./transaction-service");
18
- const gas_price_cache_1 = require("./gas-price-cache");
19
- class SuiGrpcClient {
20
- constructor() {
21
- this.gas_price = 0;
22
- this.init();
23
- }
24
- init() {
25
- const grpcClient = grpc_connection_1.GrpcConnection.getInstance(process.env.SUI_GRPC_ENDPOINT, process.env.SUI_GRPC_TOKEN);
26
- this.ledgerService = new ledger_service_1.LedgerService(grpcClient);
27
- this.transactionService = new transaction_service_1.TransactionService(grpcClient);
28
- this.liveDataService = new live_data_service_1.LiveDataService(grpcClient);
29
- this.subscriptionService = new subscription_service_1.SubscriptionService(grpcClient);
30
- this.gasPriceCache = gas_price_cache_1.GasPriceCache.getInstance(this.ledgerService);
31
- }
32
- get_gas_price() {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- return yield this.gasPriceCache.getGasPrice();
35
- });
36
- }
37
- }
38
- exports.SuiGrpcClient = SuiGrpcClient;
@@ -1,7 +0,0 @@
1
- import { GrpcConnection } from './grpc-connection';
2
- export declare class TransactionService {
3
- private transactionClient;
4
- private connection;
5
- constructor(connection: GrpcConnection);
6
- executeTransaction(transactionBytes: Uint8Array, signatureBytes: Uint8Array, fields?: string[]): Promise<unknown>;
7
- }
@@ -1,49 +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.TransactionService = void 0;
13
- class TransactionService {
14
- constructor(connection) {
15
- this.connection = connection;
16
- this.transactionClient = connection.createServiceClient('transaction_execution_service.proto', 'TransactionExecutionService');
17
- }
18
- executeTransaction(transactionBytes_1, signatureBytes_1) {
19
- return __awaiter(this, arguments, void 0, function* (transactionBytes, signatureBytes, fields = ['transaction', 'finality']) {
20
- return new Promise((resolve, reject) => {
21
- const request = {
22
- transaction: {
23
- bcs: {
24
- value: transactionBytes
25
- }
26
- },
27
- signatures: [
28
- {
29
- scheme: 0,
30
- bcs: {
31
- value: signatureBytes
32
- }
33
- }
34
- ],
35
- read_mask: {
36
- paths: fields
37
- }
38
- };
39
- this.transactionClient.ExecuteTransaction(request, this.connection.getMetadata(), (error, response) => {
40
- if (error)
41
- reject(error);
42
- else
43
- resolve(response);
44
- });
45
- });
46
- });
47
- }
48
- }
49
- exports.TransactionService = TransactionService;
@@ -1,9 +0,0 @@
1
- export * from './quote';
2
- export * from './grpc';
3
- export * from './utils';
4
- export * from './type';
5
- export * from './grpc';
6
- export * from './utils';
7
- export * from './constants';
8
- export * from './trade';
9
- export * from './redis';
@@ -1,25 +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("./quote"), exports);
18
- __exportStar(require("./grpc"), exports);
19
- __exportStar(require("./utils"), exports);
20
- __exportStar(require("./type"), exports);
21
- __exportStar(require("./grpc"), exports);
22
- __exportStar(require("./utils"), exports);
23
- __exportStar(require("./constants"), exports);
24
- __exportStar(require("./trade"), exports);
25
- __exportStar(require("./redis"), exports);
@@ -1 +0,0 @@
1
- export * from './pricing';
@@ -1,17 +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("./pricing"), exports);
@@ -1 +0,0 @@
1
- export * from './token_price_cache';
@@ -1,17 +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("./token_price_cache"), exports);
@@ -1,9 +0,0 @@
1
- export declare class TokenPriceCache {
2
- private tokenPriceCache;
3
- private readonly PRICE_CACHE_TIMEOUT_MILLS;
4
- constructor();
5
- getTokenPrice(tokenAddress: string): Promise<{
6
- price: string;
7
- timestamp: number;
8
- }>;
9
- }
@@ -1,42 +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.TokenPriceCache = void 0;
13
- const dist_1 = require("@clonegod/ttd-core/dist");
14
- class TokenPriceCache {
15
- constructor() {
16
- this.tokenPriceCache = new Map();
17
- this.PRICE_CACHE_TIMEOUT_MILLS = parseInt(process.env.PRICE_CACHE_TIMEOUT_MILLS || Number(1000 * 60 * 60 * 1).toString());
18
- (0, dist_1.log_info)(`代币价格缓存超时时间: ${this.PRICE_CACHE_TIMEOUT_MILLS} ms`);
19
- }
20
- getTokenPrice(tokenAddress) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- let tokenParts = tokenAddress.split('::');
23
- tokenParts[0] = tokenParts[0].toLowerCase();
24
- tokenAddress = tokenParts.join('::');
25
- const now = Date.now();
26
- const cachedData = this.tokenPriceCache.get(tokenAddress);
27
- if (cachedData && (now - cachedData.timestamp) < this.PRICE_CACHE_TIMEOUT_MILLS) {
28
- (0, dist_1.log_debug)(`use cached token price: ${tokenAddress}, price: ${cachedData.price}`, '');
29
- return cachedData;
30
- }
31
- const priceMap = yield (0, dist_1.get_sui_token_price_info)([tokenAddress]);
32
- const tokenPrice = priceMap.get(tokenAddress);
33
- if (!tokenPrice || !tokenPrice.price || Number(tokenPrice.price) <= 0) {
34
- throw new Error(`无法获取代币 ${tokenAddress} 的有效USD价格`);
35
- }
36
- const newPrice = { price: tokenPrice.price, timestamp: now };
37
- this.tokenPriceCache.set(tokenAddress, newPrice);
38
- return newPrice;
39
- });
40
- }
41
- }
42
- exports.TokenPriceCache = TokenPriceCache;
@@ -1 +0,0 @@
1
- export * from "./redis_client";
@@ -1,17 +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("./redis_client"), exports);
@@ -1,21 +0,0 @@
1
- import { RedisClientType } from "redis";
2
- export declare class SimpleRedisClient {
3
- private lock_prefix;
4
- private redisClient;
5
- private lockMaxRetries;
6
- private lockRetryDelayMs;
7
- private lockExpireSeconds;
8
- constructor(lock_prefix: string);
9
- getRedisClient(): Promise<RedisClientType>;
10
- private getLockKey;
11
- private acquireLock;
12
- private releaseLock;
13
- withLock<T>(lock_identifier: string, callback: () => Promise<T>, release_lock_delay_ms?: number): Promise<T>;
14
- getValue(key: string): Promise<string>;
15
- setValue(key: string, value: string, expireSeconds: number): Promise<any>;
16
- hsetValue(key: string, field: string, value: string, expireSeconds: number): Promise<any>;
17
- hgetvalue(key: string, field: string): Promise<any>;
18
- hkeys(key: string): Promise<any>;
19
- hgetall(key: string): Promise<any>;
20
- del(key: string, field?: string): Promise<any>;
21
- }
@@ -1,155 +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.SimpleRedisClient = void 0;
13
- const dist_1 = require("@clonegod/ttd-core/dist");
14
- class SimpleRedisClient {
15
- constructor(lock_prefix) {
16
- this.lock_prefix = lock_prefix;
17
- this.redisClient = null;
18
- this.lockMaxRetries = 10;
19
- this.lockRetryDelayMs = 300;
20
- this.lockExpireSeconds = 3;
21
- }
22
- getRedisClient() {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- if (!this.redisClient) {
25
- this.redisClient = yield (0, dist_1.getRedisCache)();
26
- }
27
- return this.redisClient;
28
- });
29
- }
30
- getLockKey(lock_identifier) {
31
- return `${this.lock_prefix}:lock:${lock_identifier}`;
32
- }
33
- acquireLock(lock_key_1, lock_value_1) {
34
- return __awaiter(this, arguments, void 0, function* (lock_key, lock_value, expireSeconds = this.lockExpireSeconds) {
35
- const redisClient = yield this.getRedisClient();
36
- const result = yield redisClient.set(lock_key, lock_value, {
37
- NX: true,
38
- EX: expireSeconds
39
- });
40
- (0, dist_1.log_info)(`try acquireLock: lock_key=${lock_key}, lock_value=${lock_value}, expireSeconds=${expireSeconds}, result=${result}`);
41
- const success = result === 'OK';
42
- if (success) {
43
- (0, dist_1.log_info)(`acquire lock success: lock_key=${lock_key}, lock_value=${lock_value}`);
44
- }
45
- return success;
46
- });
47
- }
48
- releaseLock(lock_key, lock_value) {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- const redisClient = yield this.getRedisClient();
51
- const script = `
52
- if redis.call('get', KEYS[1]) == ARGV[1] then
53
- return redis.call('del', KEYS[1])
54
- else
55
- return 0
56
- end
57
- `;
58
- const result = yield redisClient.eval(script, {
59
- keys: [lock_key],
60
- arguments: [lock_value]
61
- });
62
- const success = Number(result) === 1;
63
- if (success) {
64
- (0, dist_1.log_info)(`release lock success: lock_key=${lock_key}, lock_value=${lock_value}`);
65
- }
66
- else {
67
- (0, dist_1.log_info)(`release lock failed: lock_key=${lock_key}, lock_value=${lock_value}, maybe expired or locked by other process`);
68
- }
69
- return success;
70
- });
71
- }
72
- withLock(lock_identifier_1, callback_1) {
73
- return __awaiter(this, arguments, void 0, function* (lock_identifier, callback, release_lock_delay_ms = 2000) {
74
- const lock_key = this.getLockKey(lock_identifier);
75
- const lock_value = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
76
- let retries = 0;
77
- let acquired = false;
78
- let first_try_time = Date.now();
79
- let get_lock_time = 0;
80
- try {
81
- while (retries < this.lockMaxRetries) {
82
- acquired = yield this.acquireLock(lock_key, lock_value);
83
- if (acquired)
84
- break;
85
- yield new Promise(resolve => setTimeout(resolve, this.lockRetryDelayMs));
86
- retries++;
87
- }
88
- if (acquired) {
89
- get_lock_time = Date.now();
90
- return yield callback();
91
- }
92
- }
93
- finally {
94
- if (acquired) {
95
- const release_delay = parseInt(process.env.NONCE_LOCK_RELEASE_DELAY_MS || String(release_lock_delay_ms));
96
- yield (0, dist_1.sleep)(release_delay);
97
- yield this.releaseLock(lock_key, lock_value);
98
- (0, dist_1.log_info)(`withLock success: lock_key=${lock_key}, lock_value=${lock_value}, retry times=${retries}, get lock take ${get_lock_time - first_try_time}ms, release_delay=${release_delay}ms, hold lock ${Date.now() - get_lock_time}ms`);
99
- }
100
- else {
101
- (0, dist_1.log_warn)(`withLock failed: lock_key=${lock_key}, lock_value=${lock_value}, retry times=${retries}, took ${Date.now() - first_try_time}ms`);
102
- }
103
- }
104
- });
105
- }
106
- getValue(key) {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- const redisClient = yield this.getRedisClient();
109
- return yield redisClient.get(key);
110
- });
111
- }
112
- setValue(key, value, expireSeconds) {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- const redisClient = yield this.getRedisClient();
115
- return yield redisClient.set(key, value, {
116
- EX: expireSeconds
117
- });
118
- });
119
- }
120
- hsetValue(key, field, value, expireSeconds) {
121
- return __awaiter(this, void 0, void 0, function* () {
122
- const redisClient = yield this.getRedisClient();
123
- yield redisClient.hSet(key, field, value);
124
- yield redisClient.hExpire(key, field, expireSeconds);
125
- });
126
- }
127
- hgetvalue(key, field) {
128
- return __awaiter(this, void 0, void 0, function* () {
129
- const redisClient = yield this.getRedisClient();
130
- return yield redisClient.hGet(key, field);
131
- });
132
- }
133
- hkeys(key) {
134
- return __awaiter(this, void 0, void 0, function* () {
135
- const redisClient = yield this.getRedisClient();
136
- return yield redisClient.hKeys(key);
137
- });
138
- }
139
- hgetall(key) {
140
- return __awaiter(this, void 0, void 0, function* () {
141
- const redisClient = yield this.getRedisClient();
142
- return yield redisClient.hGetAll(key);
143
- });
144
- }
145
- del(key_1) {
146
- return __awaiter(this, arguments, void 0, function* (key, field = '') {
147
- const redisClient = yield this.getRedisClient();
148
- if (field) {
149
- return yield redisClient.hDel(key, field);
150
- }
151
- return yield redisClient.del(key);
152
- });
153
- }
154
- }
155
- exports.SimpleRedisClient = SimpleRedisClient;
@@ -1 +0,0 @@
1
- export {};