@ultrade/shared 1.0.2 → 1.0.4

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 (38) hide show
  1. package/dist/common/index.d.ts +0 -6
  2. package/dist/common/index.js +0 -739
  3. package/dist/constants/index.d.ts +0 -1
  4. package/dist/constants/index.js +0 -78
  5. package/dist/helpers/assert.helper.js +0 -78
  6. package/dist/helpers/atomic.helper.js +0 -78
  7. package/dist/helpers/balance.helper.js +0 -78
  8. package/dist/helpers/codex/common.helper.js +0 -78
  9. package/dist/helpers/codex/index.js +0 -78
  10. package/dist/helpers/codex/mbr.helper.js +0 -78
  11. package/dist/helpers/codex/mna.helper.js +0 -78
  12. package/dist/helpers/codex/order.helper.js +0 -78
  13. package/dist/helpers/codex/setGlobal.helper.js +0 -78
  14. package/dist/helpers/codex/transfer.helper.js +0 -78
  15. package/dist/helpers/codex/txn.helper.js +0 -78
  16. package/dist/helpers/codex.helper.js +0 -78
  17. package/dist/helpers/eth.helper.js +0 -78
  18. package/dist/helpers/vaa.helper.js +0 -78
  19. package/dist/helpers/withdraw.helper.js +0 -78
  20. package/package.json +3 -11
  21. package/dist/common/awsKms.d.ts +0 -2
  22. package/dist/common/awsKms.js +0 -255
  23. package/dist/common/indexer.helper.d.ts +0 -2
  24. package/dist/common/indexer.helper.js +0 -377
  25. package/dist/common/logger.d.ts +0 -32
  26. package/dist/common/logger.js +0 -178
  27. package/dist/common/migration.helpers.d.ts +0 -4
  28. package/dist/common/migration.helpers.js +0 -33
  29. package/dist/common/redis.helper.d.ts +0 -27
  30. package/dist/common/redis.helper.js +0 -249
  31. package/dist/common/secret.helper.d.ts +0 -28
  32. package/dist/common/secret.helper.js +0 -129
  33. package/dist/constants/queue.d.ts +0 -39
  34. package/dist/helpers/email.helper.d.ts +0 -5
  35. package/dist/helpers/email.helper.js +0 -101
  36. package/dist/helpers/hummingbots.helper.d.ts +0 -2
  37. package/dist/helpers/hummingbots.helper.js +0 -152
  38. package/dist/interfaces/controller.interface.d.ts +0 -6
@@ -1,249 +0,0 @@
1
- /******/ (() => { // webpackBootstrap
2
- /******/ "use strict";
3
- /******/ var __webpack_modules__ = ({
4
-
5
- /***/ 657:
6
- /***/ ((module) => {
7
-
8
- module.exports = require("ioredis");
9
-
10
- /***/ }),
11
-
12
- /***/ 5281:
13
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
14
-
15
-
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", ({ value: true }));
20
- const ioredis_1 = __importDefault(__webpack_require__(657));
21
- class RedisHelper {
22
- host = process.env.REDIS_HOSTNAME;
23
- port = process.env.REDIS_PORT;
24
- client = new ioredis_1.default({
25
- host: this.host,
26
- port: Number(this.port),
27
- lazyConnect: true,
28
- });
29
- operationQueue = [];
30
- runningOperations = false;
31
- constructor() {
32
- this.client.on('connect', () => {
33
- });
34
- this.client.on('ready', () => {
35
- this.performPendingOperations();
36
- });
37
- this.client.on('error', (err) => {
38
- console.error('Redis error:', err.message);
39
- });
40
- this.client.on('close', () => {
41
- console.log('Redis connection closed');
42
- });
43
- }
44
- async performPendingOperations() {
45
- this.runningOperations = true;
46
- while (this.operationQueue.length > 0) {
47
- const operation = this.operationQueue.shift();
48
- if (operation) {
49
- try {
50
- await operation();
51
- }
52
- catch (err) {
53
- console.error('Error performing Redis operation:', err);
54
- }
55
- }
56
- }
57
- this.runningOperations = false;
58
- }
59
- async setString(key, value, expires = 0, database = '') {
60
- const operation = async () => {
61
- if (database !== '') {
62
- this.client.select(Number(database));
63
- }
64
- await this.client.set(key, value);
65
- if (expires !== 0) {
66
- await this.client.expire(key, expires * 60);
67
- }
68
- };
69
- await this.performOperation(operation);
70
- }
71
- async incrementKey(key, expires = 0, database = '') {
72
- const operation = async () => {
73
- if (database !== '') {
74
- this.client.select(Number(database));
75
- }
76
- await this.client.incr(key);
77
- if (expires !== 0) {
78
- const ttl = await this.client.ttl(key);
79
- if (ttl === -1) {
80
- await this.client.expire(key, expires * 60);
81
- }
82
- }
83
- };
84
- await this.performOperation(operation);
85
- }
86
- async scanKeys(pattern, database = '') {
87
- const matchedKeys = [];
88
- const operation = async () => {
89
- if (database !== '') {
90
- this.client.select(Number(database));
91
- }
92
- let cursor = '0';
93
- do {
94
- const [nextCursor, keys] = await this.client.scan(cursor, 'MATCH', pattern, 'COUNT', 100);
95
- cursor = nextCursor;
96
- matchedKeys.push(...keys);
97
- } while (cursor !== '0');
98
- };
99
- await this.performOperation(operation);
100
- return matchedKeys;
101
- }
102
- getString(key, database = '') {
103
- return new Promise(async (resolve, reject) => {
104
- const operation = async () => {
105
- try {
106
- if (database !== '') {
107
- await this.client.select(Number(database));
108
- }
109
- const value = await this.client.get(key);
110
- resolve(value);
111
- }
112
- catch (err) {
113
- reject(err);
114
- }
115
- };
116
- this.performOperation(operation);
117
- });
118
- }
119
- async deleteString(key, database = '') {
120
- const operation = async () => {
121
- if (database !== '') {
122
- this.client.select(Number(database));
123
- }
124
- await this.client.del(key);
125
- };
126
- await this.performOperation(operation);
127
- }
128
- async deleteByKeyPattern(pattern, database = '') {
129
- const operation = async () => {
130
- if (database !== '') {
131
- this.client.select(Number(database));
132
- }
133
- const keys = await this.client.keys(pattern);
134
- if (keys.length > 0) {
135
- await this.client.unlink(keys);
136
- console.log(`Deleted ${keys.length} keys`);
137
- }
138
- else {
139
- console.log('No keys for delete');
140
- }
141
- };
142
- await this.performOperation(operation);
143
- }
144
- async destroyDb(dbKey) {
145
- const response = await this.client.del(dbKey);
146
- return response === 1;
147
- }
148
- async performOperation(operation) {
149
- this.operationQueue.push(operation);
150
- if (!this.runningOperations) {
151
- try {
152
- await this.performPendingOperations();
153
- }
154
- catch (error) {
155
- console.error('Error during performing Redis operation', error);
156
- }
157
- }
158
- }
159
- async close() {
160
- console.log('Closing Redis client for graceful shutdown...');
161
- try {
162
- while (this.operationQueue.length > 0 || this.runningOperations) {
163
- await new Promise((resolve) => setTimeout(resolve, 100));
164
- }
165
- await this.client.quit();
166
- console.log('Redis client closed successfully');
167
- }
168
- catch (error) {
169
- console.error('Error during Redis client shutdown:', error);
170
- }
171
- }
172
- async createStream(key) {
173
- await this.client.xgroup('CREATE', key, 'group', '$', 'MKSTREAM');
174
- }
175
- async writeToStream(key, message) {
176
- try {
177
- if (await this.streamExists(key)) {
178
- await this.client.xadd(key, '*', 'message', JSON.stringify(message));
179
- }
180
- }
181
- catch (error) {
182
- console.log(`[Stream '${key}']`, 'Error while writing to stream', error);
183
- }
184
- }
185
- async readStream(key, timeout) {
186
- const results = await this.client.xreadgroup('GROUP', 'group', 'consumer', 'COUNT', 1, 'BLOCK', timeout * 1000, 'STREAMS', key, '>');
187
- if (results && results.length > 0) {
188
- const [, entries] = results[0];
189
- if (entries && entries.length > 0) {
190
- const [, [, message]] = entries[0];
191
- return JSON.parse(message);
192
- }
193
- }
194
- return null;
195
- }
196
- async deleteStream(key) {
197
- if (await this.streamExists(key)) {
198
- await this.client.del(key);
199
- }
200
- }
201
- async setTTL(key, ttlSeconds) {
202
- await this.client.expire(key, ttlSeconds);
203
- }
204
- async streamExists(key) {
205
- const exists = await this.client.exists(key);
206
- return exists === 1;
207
- }
208
- }
209
- exports["default"] = new RedisHelper();
210
-
211
-
212
- /***/ })
213
-
214
- /******/ });
215
- /************************************************************************/
216
- /******/ // The module cache
217
- /******/ var __webpack_module_cache__ = {};
218
- /******/
219
- /******/ // The require function
220
- /******/ function __webpack_require__(moduleId) {
221
- /******/ // Check if module is in cache
222
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
223
- /******/ if (cachedModule !== undefined) {
224
- /******/ return cachedModule.exports;
225
- /******/ }
226
- /******/ // Create a new module (and put it into the cache)
227
- /******/ var module = __webpack_module_cache__[moduleId] = {
228
- /******/ // no module.id needed
229
- /******/ // no module.loaded needed
230
- /******/ exports: {}
231
- /******/ };
232
- /******/
233
- /******/ // Execute the module function
234
- /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
235
- /******/
236
- /******/ // Return the exports of the module
237
- /******/ return module.exports;
238
- /******/ }
239
- /******/
240
- /************************************************************************/
241
- /******/
242
- /******/ // startup
243
- /******/ // Load entry module and return exports
244
- /******/ // This entry module is referenced by other modules so it can't be inlined
245
- /******/ var __webpack_exports__ = __webpack_require__(5281);
246
- /******/ module.exports = __webpack_exports__;
247
- /******/
248
- /******/ })()
249
- ;
@@ -1,28 +0,0 @@
1
- interface RelayerSecrets {
2
- algorand: string;
3
- polygon: string;
4
- solana: string;
5
- }
6
- export interface OndatoSecrets {
7
- clientId: string;
8
- clientSecret: string;
9
- hmacSecret: string;
10
- setupId: string;
11
- }
12
- declare class SecretHelper {
13
- private creatorMnemonicSecretName;
14
- private dispenserMnemonicSecretName;
15
- private transactionMnemonicSecretName;
16
- private relayerMnemonicSecretName;
17
- private ondatoCredentialsSecretName;
18
- getCreatorMnemonic(): Promise<string>;
19
- getDispenserMnemonic(): Promise<string>;
20
- getTransactionMnemonic(): Promise<string>;
21
- getRelayerMnemonics(): Promise<RelayerSecrets>;
22
- getOndatoSecrets(): Promise<OndatoSecrets>;
23
- private getClient;
24
- private getSecrets;
25
- saveSecret(secretName: string, secretValue: string): Promise<void>;
26
- }
27
- declare const _default: SecretHelper;
28
- export default _default;
@@ -1,129 +0,0 @@
1
- /******/ (() => { // webpackBootstrap
2
- /******/ "use strict";
3
- /******/ var __webpack_modules__ = ({
4
-
5
- /***/ 862:
6
- /***/ ((module) => {
7
-
8
- module.exports = require("@aws-sdk/client-secrets-manager");
9
-
10
- /***/ })
11
-
12
- /******/ });
13
- /************************************************************************/
14
- /******/ // The module cache
15
- /******/ var __webpack_module_cache__ = {};
16
- /******/
17
- /******/ // The require function
18
- /******/ function __webpack_require__(moduleId) {
19
- /******/ // Check if module is in cache
20
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
21
- /******/ if (cachedModule !== undefined) {
22
- /******/ return cachedModule.exports;
23
- /******/ }
24
- /******/ // Create a new module (and put it into the cache)
25
- /******/ var module = __webpack_module_cache__[moduleId] = {
26
- /******/ // no module.id needed
27
- /******/ // no module.loaded needed
28
- /******/ exports: {}
29
- /******/ };
30
- /******/
31
- /******/ // Execute the module function
32
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
33
- /******/
34
- /******/ // Return the exports of the module
35
- /******/ return module.exports;
36
- /******/ }
37
- /******/
38
- /************************************************************************/
39
- var __webpack_exports__ = {};
40
- // This entry needs to be wrapped in an IIFE because it uses a non-standard name for the exports (exports).
41
- (() => {
42
- var exports = __webpack_exports__;
43
-
44
- Object.defineProperty(exports, "__esModule", ({ value: true }));
45
- const client_secrets_manager_1 = __webpack_require__(862);
46
- class SecretHelper {
47
- creatorMnemonicSecretName = process.env.CreatorSecret;
48
- dispenserMnemonicSecretName = process.env.DispenserSecret;
49
- transactionMnemonicSecretName = process.env.TransactionSecret;
50
- relayerMnemonicSecretName = process.env.RelayerSecret;
51
- ondatoCredentialsSecretName = process.env.OndatoSecret;
52
- async getCreatorMnemonic() {
53
- const creatorMnemonic = await this.getSecrets(this.creatorMnemonicSecretName);
54
- return JSON.parse(creatorMnemonic).creator;
55
- }
56
- async getDispenserMnemonic() {
57
- const dispenserMnemonic = await this.getSecrets(this.dispenserMnemonicSecretName);
58
- return JSON.parse(dispenserMnemonic).dispenser;
59
- }
60
- async getTransactionMnemonic() {
61
- const transactionMnemonic = await this.getSecrets(this.transactionMnemonicSecretName);
62
- return JSON.parse(transactionMnemonic).txs;
63
- }
64
- async getRelayerMnemonics() {
65
- const relayerMnemonic = await this.getSecrets(this.relayerMnemonicSecretName);
66
- return JSON.parse(relayerMnemonic);
67
- }
68
- async getOndatoSecrets() {
69
- const ondatoSecrets = await this.getSecrets(this.ondatoCredentialsSecretName);
70
- return JSON.parse(ondatoSecrets);
71
- }
72
- getClient() {
73
- return new client_secrets_manager_1.SecretsManager({ region: 'us-east-1' });
74
- }
75
- getSecrets(secretName) {
76
- return new Promise((resolve, reject) => {
77
- try {
78
- const command = new client_secrets_manager_1.GetSecretValueCommand({ SecretId: secretName });
79
- const client = this.getClient();
80
- client.send(command, (err, data) => {
81
- if (err) {
82
- console.log('-----error in secrets---------', err);
83
- reject(err);
84
- }
85
- else {
86
- resolve(data.SecretString);
87
- }
88
- });
89
- }
90
- catch (error) {
91
- console.log('error curl', error);
92
- reject(error);
93
- }
94
- });
95
- }
96
- saveSecret(secretName, secretValue) {
97
- console.log(`Saving secret with name: ${secretName}`);
98
- return new Promise((resolve, reject) => {
99
- try {
100
- const command = new client_secrets_manager_1.PutSecretValueCommand({
101
- SecretId: secretName,
102
- SecretString: secretValue,
103
- });
104
- const client = this.getClient();
105
- client.send(command, (err, data) => {
106
- if (err) {
107
- console.log('-----error in saving secret---------', err);
108
- reject(err);
109
- }
110
- else {
111
- console.log('secret successfully saved');
112
- resolve();
113
- }
114
- });
115
- }
116
- catch (error) {
117
- console.log('error curl', error);
118
- reject(error);
119
- }
120
- });
121
- }
122
- }
123
- exports["default"] = new SecretHelper();
124
-
125
- })();
126
-
127
- module.exports = __webpack_exports__;
128
- /******/ })()
129
- ;
@@ -1,39 +0,0 @@
1
- import { Options } from 'amqplib';
2
- export declare enum QueueNames {
3
- CANCELLATION_TRADE = "cancellation_trade",
4
- CANCEL_ORDER = "cancelOrder",
5
- MAINTENANCE = "maintenance",
6
- SYSTEM = "system",
7
- NEW_ORDER = "newOrder",
8
- PROCESS_WALLET_TRANSACTION = "wallet_transaction",
9
- LAST_LOOK_TRADE = "last_look_trade",
10
- SEND_TRADE_TO_SETTLE = "send_trade_to_settle",
11
- TRADE_FIRE = "trade_fire",
12
- TRADE_CONFIRMED = "trade_confirmed",
13
- ORDER_OPERATION = "order_operation",
14
- ORDER_RESULT = "order_result",
15
- TRADES_QUEUE = "trades_q",
16
- OPEN_ORDER_BOOK = "open_order_book",
17
- SOCKET_WALLET_TRANSACTION = "socket_wallet_transaction",
18
- STREAM_UPDATE_QUOTE = "stream_update_quote",
19
- STREAM_UPDATE_LAST_PRICE = "stream_update_last_price",
20
- STREAM_UPDATE_DEPTH = "stream_update_depth",
21
- STREAM_UPDATE_LAST_CANDLESTICK = "stream_update_last_candlestick",
22
- STREAM_UPDATE_ORDERS = "stream_update_orders",
23
- STREAM_UPDATE_TRADES = "stream_update_trades",
24
- STREAM_UPDATE_ORDER_BOOK = "stream_update_order_book",
25
- CODEX_DEPOSIT = "codex_deposit",
26
- CODEX_TRANSFER = "codex_transfer",
27
- CODEX_WITHDRAWAL = "codex_withdrawal",
28
- CODEX_BALANCES = "codex_balances",
29
- CODEX_TRADE = "codex_trade",
30
- VAA_LOG = "vaa_log",
31
- SETTINGS_UPDATE = "settings_update",
32
- POINT_SYSTEM_SETTINGS_UPDATE = "point_system_settings_update",
33
- NEW_NOTIFICATION = "new_notification"
34
- }
35
- export declare const QueueOptions: {
36
- [key in QueueNames]: {
37
- options?: Options.AssertQueue;
38
- };
39
- };
@@ -1,5 +0,0 @@
1
- export declare const sendEmail: (email: string, subject: string, message: string, cc?: string[]) => Promise<import("@aws-sdk/client-ses").SendEmailCommandOutput>;
2
- export declare const sendEmailToAdmin: (subject: string, message: string, cc?: string[]) => Promise<void>;
3
- export declare const sendEmailAboutMaintenance: (subject: string, message: string) => Promise<void>;
4
- export declare const sendEmailAboutMaintenanceOnError: (service: string, error: string) => Promise<void>;
5
- export declare const sendEmailAboutLowGas: (dollarValue: number, chain: string, signerAddress: string) => Promise<void>;
@@ -1,101 +0,0 @@
1
- /******/ (() => { // webpackBootstrap
2
- /******/ "use strict";
3
- /******/ var __webpack_modules__ = ({
4
-
5
- /***/ 342:
6
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
7
-
8
-
9
- Object.defineProperty(exports, "__esModule", ({ value: true }));
10
- exports.sendEmailAboutLowGas = exports.sendEmailAboutMaintenanceOnError = exports.sendEmailAboutMaintenance = exports.sendEmailToAdmin = exports.sendEmail = void 0;
11
- const client_ses_1 = __webpack_require__(8484);
12
- const sendEmail = async (email, subject, message, cc) => {
13
- const ses = new client_ses_1.SESClient({ region: 'us-east-1' });
14
- const params = {
15
- Source: 'no-reply@ultrade.org',
16
- Destination: {
17
- ToAddresses: [email],
18
- CcAddresses: cc || [],
19
- },
20
- Message: {
21
- Body: {
22
- Text: { Data: message },
23
- },
24
- Subject: { Data: subject },
25
- },
26
- };
27
- const command = new client_ses_1.SendEmailCommand(params);
28
- return ses.send(command);
29
- };
30
- exports.sendEmail = sendEmail;
31
- const sendEmailToAdmin = async (subject, message, cc) => {
32
- await (0, exports.sendEmail)('dg@ultrade.org', subject, message, cc);
33
- };
34
- exports.sendEmailToAdmin = sendEmailToAdmin;
35
- const sendEmailAboutMaintenance = async (subject, message) => {
36
- if (process.env.ALGO_NETWORK !== 'MainNet') {
37
- return;
38
- }
39
- const cc = ['alexander.murzo@gmail.com', 'ruzhukov@gmail.com'];
40
- await (0, exports.sendEmailToAdmin)(subject, message, cc);
41
- };
42
- exports.sendEmailAboutMaintenance = sendEmailAboutMaintenance;
43
- const sendEmailAboutMaintenanceOnError = async (service, error) => {
44
- const subject = `Maintenance mode is turned on from ${service}`;
45
- const message = `Reason: '${error}'`;
46
- await (0, exports.sendEmailAboutMaintenance)(subject, message);
47
- };
48
- exports.sendEmailAboutMaintenanceOnError = sendEmailAboutMaintenanceOnError;
49
- const sendEmailAboutLowGas = async (dollarValue, chain, signerAddress) => {
50
- const subject = `Low gas on ${chain}`;
51
- const message = `Dollar value: ${dollarValue}, chainId: ${chain}, signerAddress: ${signerAddress}`;
52
- await (0, exports.sendEmailToAdmin)(subject, message);
53
- };
54
- exports.sendEmailAboutLowGas = sendEmailAboutLowGas;
55
-
56
-
57
- /***/ }),
58
-
59
- /***/ 8484:
60
- /***/ ((module) => {
61
-
62
- module.exports = require("@aws-sdk/client-ses");
63
-
64
- /***/ })
65
-
66
- /******/ });
67
- /************************************************************************/
68
- /******/ // The module cache
69
- /******/ var __webpack_module_cache__ = {};
70
- /******/
71
- /******/ // The require function
72
- /******/ function __webpack_require__(moduleId) {
73
- /******/ // Check if module is in cache
74
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
75
- /******/ if (cachedModule !== undefined) {
76
- /******/ return cachedModule.exports;
77
- /******/ }
78
- /******/ // Create a new module (and put it into the cache)
79
- /******/ var module = __webpack_module_cache__[moduleId] = {
80
- /******/ // no module.id needed
81
- /******/ // no module.loaded needed
82
- /******/ exports: {}
83
- /******/ };
84
- /******/
85
- /******/ // Execute the module function
86
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
87
- /******/
88
- /******/ // Return the exports of the module
89
- /******/ return module.exports;
90
- /******/ }
91
- /******/
92
- /************************************************************************/
93
- /******/
94
- /******/ // startup
95
- /******/ // Load entry module and return exports
96
- /******/ // This entry module is referenced by other modules so it can't be inlined
97
- /******/ var __webpack_exports__ = __webpack_require__(342);
98
- /******/ module.exports = __webpack_exports__;
99
- /******/
100
- /******/ })()
101
- ;
@@ -1,2 +0,0 @@
1
- export declare function encryptSecretValue(password: string, value: string): string;
2
- export declare function createStrategyHash(partnerId: number, yamlString: string): string;