@dhedge/backend-flatcoin-core 0.2.13 → 0.2.16
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/contracts/abi/liquidation-module.d.ts +15 -0
- package/dist/contracts/abi/liquidation-module.js +27 -1
- package/dist/repository/flatcoin-pnl.repository.d.ts +2 -1
- package/dist/repository/flatcoin-pnl.repository.js +4 -1
- package/dist/service/graph-query.service.d.ts +4 -1
- package/dist/service/graph-query.service.js +35 -1
- package/dist/utils/shared-types.d.ts +6 -0
- package/package.json +1 -1
|
@@ -59,3 +59,18 @@ export declare const LiquidateWithoutPriceFeeds: {
|
|
|
59
59
|
stateMutability: string;
|
|
60
60
|
type: string;
|
|
61
61
|
}[];
|
|
62
|
+
export declare const CanLiquidateWithPriceFeeds: {
|
|
63
|
+
inputs: {
|
|
64
|
+
internalType: string;
|
|
65
|
+
name: string;
|
|
66
|
+
type: string;
|
|
67
|
+
}[];
|
|
68
|
+
name: string;
|
|
69
|
+
outputs: {
|
|
70
|
+
internalType: string;
|
|
71
|
+
name: string;
|
|
72
|
+
type: string;
|
|
73
|
+
}[];
|
|
74
|
+
stateMutability: string;
|
|
75
|
+
type: string;
|
|
76
|
+
}[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LiquidateWithoutPriceFeeds = exports.Liquidate = exports.LiquidationModule = void 0;
|
|
3
|
+
exports.CanLiquidateWithPriceFeeds = exports.LiquidateWithoutPriceFeeds = exports.Liquidate = exports.LiquidationModule = void 0;
|
|
4
4
|
exports.LiquidationModule = [
|
|
5
5
|
{
|
|
6
6
|
anonymous: false,
|
|
@@ -130,3 +130,29 @@ exports.LiquidateWithoutPriceFeeds = [
|
|
|
130
130
|
type: 'function',
|
|
131
131
|
},
|
|
132
132
|
];
|
|
133
|
+
exports.CanLiquidateWithPriceFeeds = [
|
|
134
|
+
{
|
|
135
|
+
inputs: [
|
|
136
|
+
{
|
|
137
|
+
internalType: 'uint256',
|
|
138
|
+
name: 'tokenId',
|
|
139
|
+
type: 'uint256',
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
internalType: 'uint256',
|
|
143
|
+
name: 'price',
|
|
144
|
+
type: 'uint256',
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
name: 'canLiquidate',
|
|
148
|
+
outputs: [
|
|
149
|
+
{
|
|
150
|
+
internalType: 'bool',
|
|
151
|
+
name: 'liquidatable',
|
|
152
|
+
type: 'bool',
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
stateMutability: 'view',
|
|
156
|
+
type: 'function',
|
|
157
|
+
},
|
|
158
|
+
];
|
|
@@ -6,7 +6,8 @@ export declare class FlatcoinPnlRepository {
|
|
|
6
6
|
private readonly logger;
|
|
7
7
|
constructor(repository: Repository<FlatcoinPnl>, logger: Logger);
|
|
8
8
|
getAll(): Promise<FlatcoinPnl[]>;
|
|
9
|
-
save(
|
|
9
|
+
save(flatcoinPnl: FlatcoinPnl): void;
|
|
10
|
+
saveAll(flatcoinPnls: FlatcoinPnl[]): void;
|
|
10
11
|
getLastUpdatedAt(): Promise<FlatcoinPnl | null>;
|
|
11
12
|
findByAccount(account: string): Promise<FlatcoinPnl | null>;
|
|
12
13
|
}
|
|
@@ -25,7 +25,10 @@ let FlatcoinPnlRepository = class FlatcoinPnlRepository {
|
|
|
25
25
|
async getAll() {
|
|
26
26
|
return this.repository.createQueryBuilder().getMany();
|
|
27
27
|
}
|
|
28
|
-
save(
|
|
28
|
+
save(flatcoinPnl) {
|
|
29
|
+
this.repository.save(flatcoinPnl).catch((error) => this.logger.error('Error while saving flatcoin pnl', error));
|
|
30
|
+
}
|
|
31
|
+
saveAll(flatcoinPnls) {
|
|
29
32
|
this.repository.save(flatcoinPnls).catch((error) => this.logger.error('Error while saving flatcoin pnl', error));
|
|
30
33
|
}
|
|
31
34
|
async getLastUpdatedAt() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Logger } from '@nestjs/common';
|
|
2
|
-
import { AnnouncedLimitOrder, AnnouncedOrder, DepositEvent, LeveragePositionEvent, WithdrawEvent } from '../utils';
|
|
2
|
+
import { AnnouncedLimitOrder, AnnouncedOrder, DepositEvent, LeveragePositionEvent, Position, WithdrawEvent } from '../utils';
|
|
3
3
|
import { GraphQLClient } from 'graphql-request';
|
|
4
4
|
export declare class GraphQueryService {
|
|
5
5
|
private readonly graphQLClient;
|
|
@@ -14,6 +14,8 @@ export declare class GraphQueryService {
|
|
|
14
14
|
getWithdraws(blockFrom: number): Promise<WithdrawEvent[]>;
|
|
15
15
|
getWithdrawsByWithdrawerAddress(account: string, blockFrom: number): Promise<WithdrawEvent[]>;
|
|
16
16
|
getLimitOrderAnnounceds(blockNumberFrom: number): Promise<AnnouncedLimitOrder[]>;
|
|
17
|
+
getAllOpenPositions(): Promise<Position[]>;
|
|
18
|
+
getOpenPositions(skip: number, first: number): Promise<Position[]>;
|
|
17
19
|
}
|
|
18
20
|
export declare const getAnnouncedOrdersQuery: string;
|
|
19
21
|
export declare const getLeverageOpensQuery: string;
|
|
@@ -24,3 +26,4 @@ export declare const getDepositsByDepositorAddressQuery: string;
|
|
|
24
26
|
export declare const getWithdrawsQuery: string;
|
|
25
27
|
export declare const getWithdrawsByWithdrawerAddressQuery: string;
|
|
26
28
|
export declare const getLimitOrderAnnouncedsQuery: string;
|
|
29
|
+
export declare const getOpenPositionsQuery: string;
|
|
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getLimitOrderAnnouncedsQuery = exports.getWithdrawsByWithdrawerAddressQuery = exports.getWithdrawsQuery = exports.getDepositsByDepositorAddressQuery = exports.getDepositsQuery = exports.getPositionLiquidatedsQuery = exports.getLeverageClosesQuery = exports.getLeverageOpensQuery = exports.getAnnouncedOrdersQuery = exports.GraphQueryService = void 0;
|
|
12
|
+
exports.getOpenPositionsQuery = exports.getLimitOrderAnnouncedsQuery = exports.getWithdrawsByWithdrawerAddressQuery = exports.getWithdrawsQuery = exports.getDepositsByDepositorAddressQuery = exports.getDepositsQuery = exports.getPositionLiquidatedsQuery = exports.getLeverageClosesQuery = exports.getLeverageOpensQuery = exports.getAnnouncedOrdersQuery = exports.GraphQueryService = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const graphql_request_1 = require("graphql-request");
|
|
15
15
|
const constants_1 = require("../constants");
|
|
@@ -129,6 +129,33 @@ let GraphQueryService = class GraphQueryService {
|
|
|
129
129
|
throw error;
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
+
async getAllOpenPositions() {
|
|
133
|
+
const allPositions = [];
|
|
134
|
+
const first = 1000;
|
|
135
|
+
let skip = 0;
|
|
136
|
+
// currently thegraph allows to get only 10_000 entities
|
|
137
|
+
while (skip < 10000) {
|
|
138
|
+
const fetchedPositions = await this.getOpenPositions(first, skip);
|
|
139
|
+
if (fetchedPositions.length === 0) {
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
allPositions.push(...fetchedPositions);
|
|
143
|
+
skip += first;
|
|
144
|
+
}
|
|
145
|
+
return allPositions;
|
|
146
|
+
}
|
|
147
|
+
async getOpenPositions(skip, first) {
|
|
148
|
+
const variables = { skip, first };
|
|
149
|
+
try {
|
|
150
|
+
const response = await this.graphQLClient.request(exports.getOpenPositionsQuery, variables);
|
|
151
|
+
this.logger.log(`Fetched ${response.positions.length} open positions from the graph`);
|
|
152
|
+
return response.positions;
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
this.logger.error('Error fetching open positions from the graph:', error);
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
132
159
|
};
|
|
133
160
|
exports.GraphQueryService = GraphQueryService;
|
|
134
161
|
exports.GraphQueryService = GraphQueryService = __decorate([
|
|
@@ -240,3 +267,10 @@ exports.getLimitOrderAnnouncedsQuery = (0, graphql_request_1.gql) `
|
|
|
240
267
|
}
|
|
241
268
|
}
|
|
242
269
|
`;
|
|
270
|
+
exports.getOpenPositionsQuery = (0, graphql_request_1.gql) `
|
|
271
|
+
query GetOpenPositions($skip: Int, $first: Int) {
|
|
272
|
+
positions(where: { status: 0 }, skip: $skip, first: $first) {
|
|
273
|
+
tokenId
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
`;
|
|
@@ -44,6 +44,9 @@ export interface AnnouncedLimitOrder {
|
|
|
44
44
|
priceUpperThreshold: number;
|
|
45
45
|
transactionHash: string;
|
|
46
46
|
}
|
|
47
|
+
export interface Position {
|
|
48
|
+
tokenId: number;
|
|
49
|
+
}
|
|
47
50
|
export interface DepositEventsData {
|
|
48
51
|
deposits: DepositEvent[];
|
|
49
52
|
}
|
|
@@ -65,3 +68,6 @@ export interface AnnouncedOrderData {
|
|
|
65
68
|
export interface AnnouncedLimitOrderData {
|
|
66
69
|
limitOrderAnnounceds: AnnouncedLimitOrder[];
|
|
67
70
|
}
|
|
71
|
+
export interface PositionData {
|
|
72
|
+
positions: Position[];
|
|
73
|
+
}
|