@dhedge/backend-flatcoin-core 0.1.29 → 0.1.30

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.
@@ -436,17 +436,6 @@ exports.FlatcoinErrors = [
436
436
  name: 'PriceImpactDuringWithdraw',
437
437
  type: 'error',
438
438
  },
439
- {
440
- inputs: [
441
- {
442
- internalType: 'uint256',
443
- name: 'executableTime',
444
- type: 'uint256',
445
- },
446
- ],
447
- name: 'ExecutableTimeNotReached',
448
- type: 'error',
449
- },
450
439
  {
451
440
  inputs: [
452
441
  {
@@ -463,17 +452,6 @@ exports.FlatcoinErrors = [
463
452
  name: 'InvalidThresholds',
464
453
  type: 'error',
465
454
  },
466
- {
467
- inputs: [
468
- {
469
- internalType: 'string',
470
- name: 'variableName',
471
- type: 'string',
472
- },
473
- ],
474
- name: 'InvariantViolation',
475
- type: 'error',
476
- },
477
455
  {
478
456
  inputs: [
479
457
  {
@@ -511,53 +489,4 @@ exports.FlatcoinErrors = [
511
489
  name: 'ModuleKeyEmpty',
512
490
  type: 'error',
513
491
  },
514
- {
515
- inputs: [
516
- {
517
- internalType: 'uint256',
518
- name: 'tokenId',
519
- type: 'uint256',
520
- },
521
- {
522
- internalType: 'address',
523
- name: 'msgSender',
524
- type: 'address',
525
- },
526
- ],
527
- name: 'NotTokenOwner',
528
- type: 'error',
529
- },
530
- {
531
- inputs: [
532
- {
533
- internalType: 'address',
534
- name: 'msgSender',
535
- type: 'address',
536
- },
537
- ],
538
- name: 'OnlyAuthorizedModule',
539
- type: 'error',
540
- },
541
- {
542
- inputs: [
543
- {
544
- internalType: 'address',
545
- name: 'msgSender',
546
- type: 'address',
547
- },
548
- ],
549
- name: 'OnlyOwner',
550
- type: 'error',
551
- },
552
- {
553
- inputs: [
554
- {
555
- internalType: 'string',
556
- name: 'variableName',
557
- type: 'string',
558
- },
559
- ],
560
- name: 'ZeroAddress',
561
- type: 'error',
562
- },
563
492
  ];
@@ -0,0 +1,10 @@
1
+ import { Logger } from '@nestjs/common';
2
+ import { NotificationService } from './notification.service';
3
+ export declare class ErrorHandler {
4
+ private readonly notificationService;
5
+ private readonly logger;
6
+ private readonly errorInterface;
7
+ constructor(notificationService: NotificationService, logger: Logger);
8
+ handleError(message: string, error: any): Promise<void>;
9
+ getGasEstimateErrorName(gasEstimateError: string): string;
10
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ErrorHandler = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const notification_service_1 = require("./notification.service");
15
+ const ethers_1 = require("ethers");
16
+ const contracts_1 = require("../contracts");
17
+ let ErrorHandler = class ErrorHandler {
18
+ constructor(notificationService, logger) {
19
+ this.notificationService = notificationService;
20
+ this.logger = logger;
21
+ this.errorInterface = new ethers_1.ethers.utils.Interface(contracts_1.FlatcoinErrors);
22
+ }
23
+ async handleError(message, error) {
24
+ const messageToSlack = `${message}, error ${error?.message}`;
25
+ this.logger.error(messageToSlack, error);
26
+ this.logger.error(error.stack);
27
+ if (process.env.SLACK_NOTIFICATIONS_ENABLED === 'true') {
28
+ await this.notificationService.sendNotification(messageToSlack);
29
+ }
30
+ }
31
+ getGasEstimateErrorName(gasEstimateError) {
32
+ if (!gasEstimateError)
33
+ return '';
34
+ try {
35
+ const jsonStartIndex = gasEstimateError.toString().indexOf('error=') + 6;
36
+ const jsonEndIndex = gasEstimateError.toString().indexOf(', code=');
37
+ if (jsonStartIndex > 0) {
38
+ const errorJSON = JSON.parse(gasEstimateError.toString().slice(jsonStartIndex, jsonEndIndex));
39
+ return this.errorInterface.parseError(errorJSON.error.data).name;
40
+ }
41
+ else {
42
+ return gasEstimateError;
43
+ }
44
+ }
45
+ catch (error) {
46
+ this.logger.error("can't get gas estimate error", error);
47
+ return '';
48
+ }
49
+ }
50
+ };
51
+ exports.ErrorHandler = ErrorHandler;
52
+ exports.ErrorHandler = ErrorHandler = __decorate([
53
+ (0, common_1.Injectable)(),
54
+ __metadata("design:paramtypes", [notification_service_1.NotificationService, common_1.Logger])
55
+ ], ErrorHandler);
@@ -1 +1,4 @@
1
1
  export * from './app-price.service';
2
+ export * from './graph-query.service';
3
+ export * from './error.handler';
4
+ export * from './notification.service';
@@ -15,3 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./app-price.service"), exports);
18
+ __exportStar(require("./graph-query.service"), exports);
19
+ __exportStar(require("./error.handler"), exports);
20
+ __exportStar(require("./notification.service"), exports);
@@ -0,0 +1,7 @@
1
+ import { Logger } from '@nestjs/common';
2
+ export declare class NotificationService {
3
+ private readonly logger;
4
+ private readonly slackUri;
5
+ constructor(logger: Logger);
6
+ sendNotification(message: string): Promise<void>;
7
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
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.NotificationService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const axios_1 = __importDefault(require("axios"));
18
+ let NotificationService = class NotificationService {
19
+ constructor(logger) {
20
+ this.logger = logger;
21
+ if (process.env.SLACK_CHANNEL) {
22
+ this.slackUri = process.env.SLACK_CHANNEL;
23
+ }
24
+ else {
25
+ throw new Error('NotificationService -> env property SLACK_CHANNEL is not provided');
26
+ }
27
+ }
28
+ async sendNotification(message) {
29
+ try {
30
+ await axios_1.default.post(this.slackUri, { text: message });
31
+ }
32
+ catch (error) {
33
+ this.logger.error(`Error sending notification '${message}' to slack channel ${process.env.SLACK_CHANNEL}`, error);
34
+ }
35
+ }
36
+ };
37
+ exports.NotificationService = NotificationService;
38
+ exports.NotificationService = NotificationService = __decorate([
39
+ (0, common_1.Injectable)(),
40
+ __metadata("design:paramtypes", [common_1.Logger])
41
+ ], NotificationService);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhedge/backend-flatcoin-core",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "description": "Backend Flatcoin Core",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",