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 3 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
4 changes: 2 additions & 2 deletions src/services/worker/cron/burn-rates.cron.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Injectable } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';
import {Cron, CronExpression} from '@nestjs/schedule';

import { BurnRatesTask } from '../tasks/burn-rates.task';

@Injectable()
export class BurnRateCron {
constructor(private _burnRatesTask: BurnRatesTask) {}

@Cron('*/10 * * * * *')
@Cron(CronExpression.EVERY_10_SECONDS)
async syncBurnRates(): Promise<void> {
try {
await this._burnRatesTask.syncBurnRates();
Expand Down
4 changes: 2 additions & 2 deletions src/services/worker/cron/fetch.cron.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Injectable } from '@nestjs/common';

import { Cron } from '@nestjs/schedule';
import {Cron, CronExpression} from '@nestjs/schedule';
import { FetchTask } from '../tasks/fetch.task';

@Injectable()
export class FetchCron {
constructor(private _fetchTask: FetchTask) {}

@Cron('* * * * * *')
@Cron(CronExpression.EVERY_SECOND)
async fetchNewValidators(): Promise<void> {
try {
await this._fetchTask.fetchAllEvents();
Expand Down
4 changes: 2 additions & 2 deletions src/services/worker/cron/liquidation.cron.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Injectable } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';
import {Cron, CronExpression} from '@nestjs/schedule';

import { LiquidationTask } from '../tasks/liquidation.task';

@Injectable()
export class LiquidationCron {
constructor(private _liquidationTask: LiquidationTask) {}

@Cron('*/10 * * * * *')
@Cron(CronExpression.EVERY_10_SECONDS)
async liquidate(): Promise<void> {
try {
await this._liquidationTask.liquidate();
Expand Down
10 changes: 1 addition & 9 deletions src/services/worker/tasks/fetch.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@ export class FetchTask {
this._logger.debug(`Fetching new events is already locked`);
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
35 changes: 18 additions & 17 deletions src/shared/services/web3.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Injectable, Logger } from '@nestjs/common';
import { Retryable } from 'typescript-retry-decorator';

import { ConfService } from '@cli/shared/services/conf.service';
import {Contract} from "web3-eth-contract";

export type NetworkName = string;
export type ContractAddress = string;
Expand All @@ -26,10 +27,16 @@ export const ERROR_CLUSTER_LIQUIDATED = 'ClusterIsLiquidated';

@Injectable()
export class Web3Provider {

get contractCore(): any {
return this._contractCore;
}
private readonly _logger = new Logger(Web3Provider.name);

private contract: ContractData;
public web3: Web3;
private readonly _contractCore: Contract;
private readonly _contractViews: Contract;

private _errors: SolidityError[] = [];

Expand Down Expand Up @@ -127,6 +134,11 @@ export class Web3Provider {
}

this.web3 = new Web3(process.env.NODE_URL);
this._contractCore = new this.web3.eth.Contract(this.abiCore, this.contract.address);
this._contractViews = new this.web3.eth.Contract(
this.abiViews,
this.contract.addressViews,
);
}

get abiCore() {
Expand All @@ -137,25 +149,14 @@ export class Web3Provider {
return this.contract.abiViews as any;
}

get contractCore() {
return new this.web3.eth.Contract(this.abiCore, this.contract.address);
}

get contractViews() {
return new this.web3.eth.Contract(
this.abiViews,
this.contract.addressViews,
);
}

@Retryable(Web3Provider.RETRY_OPTIONS)
async currentBlockNumber(): Promise<number> {
return this.web3.eth.getBlockNumber();
}

@Retryable(Web3Provider.RETRY_OPTIONS)
async getLiquidationThresholdPeriod(): Promise<number> {
return this.contractViews.methods
return this._contractViews.methods
.getLiquidationThresholdPeriod()
.call()
.catch(err => {
Expand All @@ -169,7 +170,7 @@ export class Web3Provider {

@Retryable(Web3Provider.RETRY_OPTIONS)
async liquidatable(owner, operatorIds, clusterSnapshot): Promise<boolean> {
return this.contractViews.methods
return this._contractViews.methods
.isLiquidatable(
owner,
this.operatorIdsToArray(operatorIds),
Expand All @@ -187,7 +188,7 @@ export class Web3Provider {

@Retryable(Web3Provider.RETRY_OPTIONS)
async isLiquidated(owner, operatorIds, clusterSnapshot): Promise<boolean> {
return this.contractViews.methods
return this._contractViews.methods
.isLiquidated(
owner,
this.operatorIdsToArray(operatorIds),
Expand All @@ -205,7 +206,7 @@ export class Web3Provider {

@Retryable(Web3Provider.RETRY_OPTIONS)
async getBurnRate(owner, operatorIds, clusterSnapshot): Promise<string> {
return this.contractViews.methods
return this._contractViews.methods
.getBurnRate(owner, this.operatorIdsToArray(operatorIds), clusterSnapshot)
.call()
.catch(err => {
Expand All @@ -219,7 +220,7 @@ export class Web3Provider {

@Retryable(Web3Provider.RETRY_OPTIONS)
async getBalance(owner, operatorIds, clusterSnapshot): Promise<string> {
return this.contractViews.methods
return this._contractViews.methods
.getBalance(owner, this.operatorIdsToArray(operatorIds), clusterSnapshot)
.call()
.catch(err => {
Expand All @@ -233,7 +234,7 @@ export class Web3Provider {

@Retryable(Web3Provider.RETRY_OPTIONS)
async getMinimumLiquidationCollateral(): Promise<string> {
return this.contractViews.methods
return this._contractViews.methods
.getMinimumLiquidationCollateral()
.call()
.catch(err => {
Expand Down