@dhedge/backend-flatcoin-core 0.1.28 → 0.1.29
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.
package/dist/constants/enum.d.ts
CHANGED
|
@@ -17,3 +17,11 @@ export declare enum LeveragePositionStatus {
|
|
|
17
17
|
CLOSED = "CLOSED",
|
|
18
18
|
LIQUIDATED = "LIQUIDATED"
|
|
19
19
|
}
|
|
20
|
+
export declare enum OrderType {
|
|
21
|
+
NONE = 0,
|
|
22
|
+
STABLE_DEPOSIT = 1,
|
|
23
|
+
STABLE_WITHDRAW = 2,
|
|
24
|
+
LEVERAGE_OPEN = 3,
|
|
25
|
+
LEVERAGE_CLOSE = 4,
|
|
26
|
+
LEVERAGE_ADJUST = 5
|
|
27
|
+
}
|
package/dist/constants/enum.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LeveragePositionStatus = exports.getChartPeriod = exports.HistoricalPeriod = exports.PERIOD_IN_SECONDS = void 0;
|
|
3
|
+
exports.OrderType = exports.LeveragePositionStatus = exports.getChartPeriod = exports.HistoricalPeriod = exports.PERIOD_IN_SECONDS = void 0;
|
|
4
4
|
var HistoricalPeriod;
|
|
5
5
|
(function (HistoricalPeriod) {
|
|
6
6
|
HistoricalPeriod["ONE_DAY"] = "1d";
|
|
@@ -30,3 +30,12 @@ var LeveragePositionStatus;
|
|
|
30
30
|
LeveragePositionStatus["CLOSED"] = "CLOSED";
|
|
31
31
|
LeveragePositionStatus["LIQUIDATED"] = "LIQUIDATED";
|
|
32
32
|
})(LeveragePositionStatus || (exports.LeveragePositionStatus = LeveragePositionStatus = {}));
|
|
33
|
+
var OrderType;
|
|
34
|
+
(function (OrderType) {
|
|
35
|
+
OrderType[OrderType["NONE"] = 0] = "NONE";
|
|
36
|
+
OrderType[OrderType["STABLE_DEPOSIT"] = 1] = "STABLE_DEPOSIT";
|
|
37
|
+
OrderType[OrderType["STABLE_WITHDRAW"] = 2] = "STABLE_WITHDRAW";
|
|
38
|
+
OrderType[OrderType["LEVERAGE_OPEN"] = 3] = "LEVERAGE_OPEN";
|
|
39
|
+
OrderType[OrderType["LEVERAGE_CLOSE"] = 4] = "LEVERAGE_CLOSE";
|
|
40
|
+
OrderType[OrderType["LEVERAGE_ADJUST"] = 5] = "LEVERAGE_ADJUST";
|
|
41
|
+
})(OrderType || (exports.OrderType = OrderType = {}));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Logger } from '@nestjs/common';
|
|
2
|
+
import { AnnouncedOrder, LeveragePositionEvent } from '../utils';
|
|
3
|
+
import { GraphQLClient } from 'graphql-request';
|
|
4
|
+
export declare class GraphQueryService {
|
|
5
|
+
private readonly graphQLClient;
|
|
6
|
+
private readonly logger;
|
|
7
|
+
constructor(graphQLClient: GraphQLClient, logger: Logger);
|
|
8
|
+
getAnnouncedOrders(timestampFrom: number): Promise<AnnouncedOrder[]>;
|
|
9
|
+
getLeverageOpens(blockFrom: number): Promise<LeveragePositionEvent[]>;
|
|
10
|
+
getLeverageCloses(blockFrom: number): Promise<LeveragePositionEvent[]>;
|
|
11
|
+
getPositionLiquidateds(blockFrom: number): Promise<LeveragePositionEvent[]>;
|
|
12
|
+
}
|
|
13
|
+
export declare const getAnnouncedOrdersQuery: string;
|
|
14
|
+
export declare const getLeverageOpensQuery: string;
|
|
15
|
+
export declare const getLeverageClosesQuery: string;
|
|
16
|
+
export declare const getPositionLiquidatedsQuery: string;
|
|
@@ -0,0 +1,117 @@
|
|
|
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.getPositionLiquidatedsQuery = exports.getLeverageClosesQuery = exports.getLeverageOpensQuery = exports.getAnnouncedOrdersQuery = exports.GraphQueryService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const graphql_request_1 = require("graphql-request");
|
|
15
|
+
const constants_1 = require("../constants");
|
|
16
|
+
let GraphQueryService = class GraphQueryService {
|
|
17
|
+
constructor(graphQLClient, logger) {
|
|
18
|
+
this.graphQLClient = graphQLClient;
|
|
19
|
+
this.logger = logger;
|
|
20
|
+
}
|
|
21
|
+
async getAnnouncedOrders(timestampFrom) {
|
|
22
|
+
const variables = { timestamp: timestampFrom.toString() };
|
|
23
|
+
try {
|
|
24
|
+
const response = await this.graphQLClient.request(exports.getAnnouncedOrdersQuery, variables);
|
|
25
|
+
this.logger.log(`Fetched ${response.orderAnnounceds.length} orderAnnounceds events from the graph`);
|
|
26
|
+
return response.orderAnnounceds;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
this.logger.error('Error fetching announced orders from the graph:', error);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async getLeverageOpens(blockFrom) {
|
|
34
|
+
const variables = { fromBlock: blockFrom };
|
|
35
|
+
try {
|
|
36
|
+
const response = await this.graphQLClient.request(exports.getLeverageOpensQuery, variables);
|
|
37
|
+
this.logger.log(`Fetched ${response.leverageOpens.length} leverageOpens events from the graph`);
|
|
38
|
+
response.leverageOpens.forEach((events) => (events.eventType = constants_1.LeveragePositionStatus.OPEN));
|
|
39
|
+
return response.leverageOpens;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
this.logger.error('Error fetching leverageOpens events from the graph:', error);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async getLeverageCloses(blockFrom) {
|
|
47
|
+
const variables = { fromBlock: blockFrom };
|
|
48
|
+
try {
|
|
49
|
+
const response = await this.graphQLClient.request(exports.getLeverageClosesQuery, variables);
|
|
50
|
+
this.logger.log(`Fetched ${response.leverageCloses.length} leverageCloses events from the graph`);
|
|
51
|
+
response.leverageCloses.forEach((events) => (events.eventType = constants_1.LeveragePositionStatus.CLOSED));
|
|
52
|
+
return response.leverageCloses;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
this.logger.error('Error fetching leverageCloses events from the graph:', error);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async getPositionLiquidateds(blockFrom) {
|
|
60
|
+
const variables = { fromBlock: blockFrom };
|
|
61
|
+
try {
|
|
62
|
+
const response = await this.graphQLClient.request(exports.getPositionLiquidatedsQuery, variables);
|
|
63
|
+
this.logger.log(`Fetched ${response.positionLiquidateds.length} positionLiquidateds events from the graph`);
|
|
64
|
+
response.positionLiquidateds.forEach((events) => (events.eventType = constants_1.LeveragePositionStatus.LIQUIDATED));
|
|
65
|
+
return response.positionLiquidateds;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
this.logger.error('Error fetching positionLiquidateds events from the graph:', error);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
exports.GraphQueryService = GraphQueryService;
|
|
74
|
+
exports.GraphQueryService = GraphQueryService = __decorate([
|
|
75
|
+
(0, common_1.Injectable)(),
|
|
76
|
+
__metadata("design:paramtypes", [graphql_request_1.GraphQLClient, common_1.Logger])
|
|
77
|
+
], GraphQueryService);
|
|
78
|
+
exports.getAnnouncedOrdersQuery = (0, graphql_request_1.gql) `
|
|
79
|
+
query GetAnnouncedOrders($timestamp: String) {
|
|
80
|
+
orderAnnounceds(where: { blockTimestamp_gte: $timestamp }) {
|
|
81
|
+
blockNumber
|
|
82
|
+
transactionHash
|
|
83
|
+
orderType
|
|
84
|
+
account
|
|
85
|
+
blockTimestamp
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
exports.getLeverageOpensQuery = (0, graphql_request_1.gql) `
|
|
90
|
+
query GetLeverageOpens($fromBlock: Int) {
|
|
91
|
+
leverageOpens(where: { blockNumber_gt: $fromBlock }) {
|
|
92
|
+
blockNumber
|
|
93
|
+
blockTimestamp
|
|
94
|
+
tokenId
|
|
95
|
+
account
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
exports.getLeverageClosesQuery = (0, graphql_request_1.gql) `
|
|
100
|
+
query GetLeverageCloses($fromBlock: Int) {
|
|
101
|
+
leverageCloses(where: { blockNumber_gt: $fromBlock }) {
|
|
102
|
+
blockNumber
|
|
103
|
+
blockTimestamp
|
|
104
|
+
tokenId
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
`;
|
|
108
|
+
exports.getPositionLiquidatedsQuery = (0, graphql_request_1.gql) `
|
|
109
|
+
query GetPositionLiquidateds($fromBlock: Int) {
|
|
110
|
+
positionLiquidateds(where: { blockNumber_gt: $fromBlock }) {
|
|
111
|
+
blockNumber
|
|
112
|
+
blockTimestamp
|
|
113
|
+
tokenId
|
|
114
|
+
liquidator
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
`;
|
|
@@ -5,20 +5,49 @@ export interface DepositEvent {
|
|
|
5
5
|
depositAmount: string;
|
|
6
6
|
mintedAmount: string;
|
|
7
7
|
}
|
|
8
|
-
export interface Deposits {
|
|
9
|
-
deposits: DepositEvent[];
|
|
10
|
-
}
|
|
11
8
|
export interface WithdrawEvent {
|
|
12
9
|
blockNumber: string;
|
|
13
10
|
withdrawer: string;
|
|
14
11
|
withdrawAmount: string;
|
|
15
12
|
burnedAmount: string;
|
|
16
13
|
}
|
|
17
|
-
export interface
|
|
18
|
-
withdraws: WithdrawEvent[];
|
|
19
|
-
}
|
|
20
|
-
export declare class DepositWithdrawAction {
|
|
14
|
+
export interface DepositWithdrawAction {
|
|
21
15
|
isDeposit: boolean;
|
|
22
16
|
blockNumber: number;
|
|
23
17
|
unitAmount: BigNumber;
|
|
24
18
|
}
|
|
19
|
+
export interface AnnouncedOrder {
|
|
20
|
+
blockNumber: number;
|
|
21
|
+
transactionHash: string;
|
|
22
|
+
orderType: string;
|
|
23
|
+
account: string;
|
|
24
|
+
blockTimestamp: number;
|
|
25
|
+
executeInTime: number;
|
|
26
|
+
expirationTime: number;
|
|
27
|
+
}
|
|
28
|
+
export interface LeveragePositionEvent {
|
|
29
|
+
blockNumber: number;
|
|
30
|
+
blockTimestamp: number;
|
|
31
|
+
tokenId: number;
|
|
32
|
+
account: string;
|
|
33
|
+
liquidator: string;
|
|
34
|
+
eventType: string;
|
|
35
|
+
}
|
|
36
|
+
export interface DepositsEventsData {
|
|
37
|
+
deposits: DepositEvent[];
|
|
38
|
+
}
|
|
39
|
+
export interface WithdrawEventsData {
|
|
40
|
+
withdraws: WithdrawEvent[];
|
|
41
|
+
}
|
|
42
|
+
export interface LeverageClosesData {
|
|
43
|
+
leverageCloses: LeveragePositionEvent[];
|
|
44
|
+
}
|
|
45
|
+
export interface LeverageOpensData {
|
|
46
|
+
leverageOpens: LeveragePositionEvent[];
|
|
47
|
+
}
|
|
48
|
+
export interface PositionLiquidatedsData {
|
|
49
|
+
positionLiquidateds: LeveragePositionEvent[];
|
|
50
|
+
}
|
|
51
|
+
export interface AnnouncedOrderData {
|
|
52
|
+
orderAnnounceds: AnnouncedOrder[];
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhedge/backend-flatcoin-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "Backend Flatcoin Core",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"ethers": "5.7.2",
|
|
24
24
|
"nest-winston": "1.9.3",
|
|
25
25
|
"typeorm": "^0.3.17",
|
|
26
|
-
"winston": "3.10.0"
|
|
26
|
+
"winston": "3.10.0",
|
|
27
|
+
"graphql-request": "6.1.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@nestjs/testing": "^9.4.3",
|