Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge stage to main #73

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,7 @@ mongo
# Docker compose ganarated files
db-data

.env
.env

# Ignore macOS files
.DS_Store
30 changes: 28 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,33 @@
"Injectable",
"microservices",
"nestjs",
"postgres"
"postgres",
"typeorm"
],
"editor.detectIndentation": false
"editor.detectIndentation": false,
"typescript.tsdk": "node_modules/typescript/lib",
"editor.minimap.renderCharacters": true,
"workbench.editor.decorations.colors": true,
"git.allowNoVerifyCommit": true,
// Formatting
"editor.formatOnSave": true,
"prettier.eslintIntegration": true,
"eslint.run": "onType",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"editor.fontFamily": "Operator Mono, Menlo, Monaco, 'Courier New', monospace",
"terminal.integrated.fontFamily": "'Operator Mono', 'Inconsolata for Powerline', monospace",
// SOP's highlight matching tag setting.
"highlight-matching-tag.styles": {
"opening": {
"full": {
"highlight": "rgba(165, 153, 233, 0.3)"
}
}
},
// SOP's Import Cost Extension Settings.
"importCost.largePackageColor": "#EC3A37F5",
"importCost.mediumPackageColor": "#B362FF",
"importCost.smallPackageColor": "#B362FF"
}
12 changes: 12 additions & 0 deletions src/exceptions/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export class SSVLiquidatorException extends Error {
public data: any;
public hash: any;

constructor(message: string, data: any, hash?: string) {
super(message);
this.name = this.constructor.name;
this.data = data;
this.hash = hash;
Error.captureStackTrace(this, this.constructor);
}
}
4 changes: 3 additions & 1 deletion src/modules/clusters/cli/cluster.transformer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import TimeAgo from 'javascript-time-ago';
import en from 'javascript-time-ago/locale/en';
import { CustomLogger } from '@cli/shared/services/logger.service';

TimeAgo.addLocale(en);
const timeAgo = new TimeAgo('en-US');
Expand Down Expand Up @@ -45,6 +46,7 @@ const textStatus = (item, extra: any) => {
* @returns List of custom formatted pod data
*/
export const transformClusterData = (items, extra: any) => {
const logger = new CustomLogger('ClusterDataTransformer');
const clusters = [];
try {
for (let i = 0; i < items.length; i++) {
Expand Down Expand Up @@ -80,7 +82,7 @@ export const transformClusterData = (items, extra: any) => {
return order.indexOf(a.status.text) - order.indexOf(b.status.text);
});
} catch (e) {
console.log(e);
logger.error(`Failed to transform cluster data. ${e}`);
}
return clusters;
};
5 changes: 4 additions & 1 deletion src/modules/earnings/cli/earning.transformer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { CustomLogger } from '@cli/shared/services/logger.service';

/**
* It transforms the items object from sqlite into a custom format
* @param {Array<>} items list of clusters object from the sqlite
* @returns List of custom formatted pod data
*/
export const transformEarningData = items => {
const logger = new CustomLogger('EarningDataTransformer');
const earnings = [];
try {
for (let i = 0; i < items.length; i++) {
Expand All @@ -16,7 +19,7 @@ export const transformEarningData = items => {
});
}
} catch (e) {
console.log(e);
logger.error(`Failed to transform earning data. ${e}`);
}
return earnings;
};
2 changes: 1 addition & 1 deletion src/modules/webapp/metrics/metrics.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class MetricsController {
private async collectStats() {
const clustersActive = await this._clusterService.countActive();
const toLiquidate = await this._clusterService.countLiquidatable();
const liquidatorETHBalance = await this._web3Provider.getETHBalance();
const liquidatorETHBalance = await this._web3Provider.getLiquidatorETHBalance();
this._metricsService.totalActiveClusters.set(clustersActive);
this._metricsService.totalLiquidatableClusters.set(toLiquidate.total);
this._metricsService.burnt10LiquidatableClusters.set(toLiquidate.burnt10);
Expand Down
8 changes: 5 additions & 3 deletions src/services/worker/cron/burn-rates.cron.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { Injectable } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';
import { Cron, CronExpression } from '@nestjs/schedule';

import { BurnRatesTask } from '../tasks/burn-rates.task';
import { CustomLogger } from '@cli/shared/services/logger.service';

@Injectable()
export class BurnRateCron {
private readonly _logger = new CustomLogger(BurnRatesTask.name);
constructor(private _burnRatesTask: BurnRatesTask) {}

@Cron('*/10 * * * * *')
@Cron(CronExpression.EVERY_10_SECONDS)
async syncBurnRates(): Promise<void> {
try {
await this._burnRatesTask.syncBurnRates();
} catch (e) {
console.log('syncBurnRates', e);
this._logger.error(e);
}
}
}
8 changes: 5 additions & 3 deletions src/services/worker/cron/fetch.cron.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { Injectable } from '@nestjs/common';

import { Cron } from '@nestjs/schedule';
import { Cron, CronExpression } from '@nestjs/schedule';
import { FetchTask } from '../tasks/fetch.task';
import { CustomLogger } from '@cli/shared/services/logger.service';

@Injectable()
export class FetchCron {
private readonly _logger = new CustomLogger(FetchCron.name);
constructor(private _fetchTask: FetchTask) {}

@Cron('* * * * * *')
@Cron(CronExpression.EVERY_SECOND)
async fetchNewValidators(): Promise<void> {
try {
await this._fetchTask.fetchAllEvents();
} catch (e) {
console.log(e);
this._logger.error(`Fetching new validators cron task failed. ${e}`);
}
}
}
8 changes: 5 additions & 3 deletions src/services/worker/cron/liquidation.cron.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { Injectable } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';
import { Cron, CronExpression } from '@nestjs/schedule';

import { LiquidationTask } from '../tasks/liquidation.task';
import { CustomLogger } from '@cli/shared/services/logger.service';

@Injectable()
export class LiquidationCron {
private readonly _logger = new CustomLogger(LiquidationCron.name);
constructor(private _liquidationTask: LiquidationTask) {}

@Cron('*/10 * * * * *')
@Cron(CronExpression.EVERY_10_SECONDS)
async liquidate(): Promise<void> {
try {
await this._liquidationTask.liquidate();
} catch (e) {
console.log(e);
this._logger.error(e);
}
}
}
7 changes: 3 additions & 4 deletions src/services/worker/tasks/burn-rates.task.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { Injectable, Logger } from '@nestjs/common';
import { ConfService } from '@cli/shared/services/conf.service';
import { Injectable } from '@nestjs/common';
import {
Web3Provider,
ERROR_CLUSTER_LIQUIDATED,
} from '@cli/shared/services/web3.provider';
import { ClusterService } from '@cli/modules/clusters/cluster.service';
import { MetricsService } from '@cli/modules/webapp/metrics/services/metrics.service';
import { SystemService, SystemType } from '@cli/modules/system/system.service';
import { CustomLogger } from '@cli/shared/services/logger.service';

@Injectable()
export class BurnRatesTask {
private static CURRENT_BATCH_SIZE = 100;
private static BATCH_SIZE_RATIO = 0.9;
private static MINIMUM_BATCH_SIZE = 10;
private static isProcessLocked = false;
private readonly _logger = new Logger(BurnRatesTask.name);
private readonly _logger = new CustomLogger(BurnRatesTask.name);

constructor(
private _config: ConfService,
private _clusterService: ClusterService,
private _metricsService: MetricsService,
private _systemService: SystemService,
Expand Down
14 changes: 3 additions & 11 deletions src/services/worker/tasks/fetch.task.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Injectable, Logger } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { WorkerService } from '@cli/services/worker/worker.service';
import { SystemService, SystemType } from '@cli/modules/system/system.service';
import { MetricsService } from '@cli/modules/webapp/metrics/services/metrics.service';
import { Web3Provider } from '@cli/shared/services/web3.provider';
import { CustomLogger } from '@cli/shared/services/logger.service';

@Injectable()
export class FetchTask {
private static isProcessLocked = false;
private readonly _logger = new Logger(FetchTask.name);
private readonly _logger = new CustomLogger(FetchTask.name);

constructor(
private _systemService: SystemService,
Expand All @@ -33,15 +34,6 @@ export class FetchTask {
return;
}

try {
await this._web3Provider.getLiquidationThresholdPeriod();
// HERE we can validate the contract owner address
} catch (err) {
throw new Error(
`'The provided contract address is not valid. Error: ${err}`,
);
}

const latestSyncedBlockNumber = await this._systemService.get(
SystemType.GENERAL_LAST_BLOCK_NUMBER,
);
Expand Down
Loading