@dhedge/backend-flatcoin-core 0.1.31 → 0.1.33

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.
@@ -1,5 +1,5 @@
1
1
  import { Logger } from '@nestjs/common';
2
- import { AnnouncedOrder, LeveragePositionEvent } from '../utils';
2
+ import { AnnouncedOrder, DepositEvent, LeveragePositionEvent, WithdrawEvent } from '../utils';
3
3
  import { GraphQLClient } from 'graphql-request';
4
4
  export declare class GraphQueryService {
5
5
  private readonly graphQLClient;
@@ -9,8 +9,16 @@ export declare class GraphQueryService {
9
9
  getLeverageOpens(blockFrom: number): Promise<LeveragePositionEvent[]>;
10
10
  getLeverageCloses(blockFrom: number): Promise<LeveragePositionEvent[]>;
11
11
  getPositionLiquidateds(blockFrom: number): Promise<LeveragePositionEvent[]>;
12
+ getDeposits(blockFrom: number): Promise<DepositEvent[]>;
13
+ getDepositsByDepositorAddress(account: string, blockFrom: number): Promise<DepositEvent[]>;
14
+ getWithdraws(blockFrom: number): Promise<WithdrawEvent[]>;
15
+ getWithdrawsByWithdrawerAddress(account: string, blockFrom: number): Promise<WithdrawEvent[]>;
12
16
  }
13
17
  export declare const getAnnouncedOrdersQuery: string;
14
18
  export declare const getLeverageOpensQuery: string;
15
19
  export declare const getLeverageClosesQuery: string;
16
20
  export declare const getPositionLiquidatedsQuery: string;
21
+ export declare const getDepositsQuery: string;
22
+ export declare const getDepositsByDepositorAddressQuery: string;
23
+ export declare const getWithdrawsQuery: string;
24
+ export declare const getWithdrawsByWithdrawerAddressQuery: 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.getPositionLiquidatedsQuery = exports.getLeverageClosesQuery = exports.getLeverageOpensQuery = exports.getAnnouncedOrdersQuery = exports.GraphQueryService = void 0;
12
+ 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");
@@ -69,6 +69,54 @@ let GraphQueryService = class GraphQueryService {
69
69
  throw error;
70
70
  }
71
71
  }
72
+ async getDeposits(blockFrom) {
73
+ const variables = { fromBlock: blockFrom };
74
+ try {
75
+ const response = await this.graphQLClient.request(exports.getDepositsQuery, variables);
76
+ this.logger.log(`Fetched ${response.deposits.length} deposits events from the graph`);
77
+ return response.deposits;
78
+ }
79
+ catch (error) {
80
+ this.logger.error('Error fetching deposits events from the graph:', error);
81
+ throw error;
82
+ }
83
+ }
84
+ async getDepositsByDepositorAddress(account, blockFrom) {
85
+ const variables = { account: account, fromBlock: blockFrom };
86
+ try {
87
+ const response = await this.graphQLClient.request(exports.getDepositsByDepositorAddressQuery, variables);
88
+ this.logger.log(`Fetched ${response.deposits.length} deposits events from the graph`);
89
+ return response.deposits;
90
+ }
91
+ catch (error) {
92
+ this.logger.error('Error fetching deposits events from the graph:', error);
93
+ throw error;
94
+ }
95
+ }
96
+ async getWithdraws(blockFrom) {
97
+ const variables = { fromBlock: blockFrom };
98
+ try {
99
+ const response = await this.graphQLClient.request(exports.getWithdrawsQuery, variables);
100
+ this.logger.log(`Fetched ${response.withdraws.length} withdraws events from the graph`);
101
+ return response.withdraws;
102
+ }
103
+ catch (error) {
104
+ this.logger.error('Error fetching withdraws events from the graph:', error);
105
+ throw error;
106
+ }
107
+ }
108
+ async getWithdrawsByWithdrawerAddress(account, blockFrom) {
109
+ const variables = { account: account, fromBlock: blockFrom };
110
+ try {
111
+ const response = await this.graphQLClient.request(exports.getWithdrawsByWithdrawerAddressQuery, variables);
112
+ this.logger.log(`Fetched ${response.withdraws.length} withdraws events from the graph`);
113
+ return response.withdraws;
114
+ }
115
+ catch (error) {
116
+ this.logger.error('Error fetching withdraws events from the graph:', error);
117
+ throw error;
118
+ }
119
+ }
72
120
  };
73
121
  exports.GraphQueryService = GraphQueryService;
74
122
  exports.GraphQueryService = GraphQueryService = __decorate([
@@ -115,3 +163,53 @@ exports.getPositionLiquidatedsQuery = (0, graphql_request_1.gql) `
115
163
  }
116
164
  }
117
165
  `;
166
+ exports.getDepositsQuery = (0, graphql_request_1.gql) `
167
+ query GetDeposits($fromBlock: Int) {
168
+ deposits(where: { blockNumber_gt: $fromBlock }, orderBy: blockTimestamp, orderDirection: asc, first: 1000) {
169
+ depositor
170
+ depositAmount
171
+ mintedAmount
172
+ blockNumber
173
+ }
174
+ }
175
+ `;
176
+ exports.getDepositsByDepositorAddressQuery = (0, graphql_request_1.gql) `
177
+ query GetDeposits($account: String, $fromBlock: Int) {
178
+ deposits(
179
+ where: { depositor: $account, blockNumber_gt: $fromBlock }
180
+ orderBy: blockTimestamp
181
+ orderDirection: asc
182
+ first: 1000
183
+ ) {
184
+ depositor
185
+ depositAmount
186
+ mintedAmount
187
+ blockNumber
188
+ }
189
+ }
190
+ `;
191
+ exports.getWithdrawsQuery = (0, graphql_request_1.gql) `
192
+ query GetWithdraws($fromBlock: Int) {
193
+ withdraws(where: { blockNumber_gt: $fromBlock }, orderBy: blockTimestamp, orderDirection: asc, first: 1000) {
194
+ blockNumber
195
+ withdrawer
196
+ withdrawAmount
197
+ burnedAmount
198
+ }
199
+ }
200
+ `;
201
+ exports.getWithdrawsByWithdrawerAddressQuery = (0, graphql_request_1.gql) `
202
+ query GetWithdraws($account: String, $fromBlock: Int) {
203
+ withdraws(
204
+ where: { withdrawer: $account, blockNumber_gt: $fromBlock }
205
+ orderBy: blockTimestamp
206
+ orderDirection: asc
207
+ first: 1000
208
+ ) {
209
+ blockNumber
210
+ withdrawer
211
+ withdrawAmount
212
+ burnedAmount
213
+ }
214
+ }
215
+ `;
@@ -11,7 +11,7 @@ export interface WithdrawEvent {
11
11
  withdrawAmount: string;
12
12
  burnedAmount: string;
13
13
  }
14
- export interface DepositWithdrawAction {
14
+ export declare class DepositWithdrawAction {
15
15
  isDeposit: boolean;
16
16
  blockNumber: number;
17
17
  unitAmount: BigNumber;
@@ -33,7 +33,7 @@ export interface LeveragePositionEvent {
33
33
  liquidator: string;
34
34
  eventType: string;
35
35
  }
36
- export interface DepositsEventsData {
36
+ export interface DepositEventsData {
37
37
  deposits: DepositEvent[];
38
38
  }
39
39
  export interface WithdrawEventsData {
@@ -1,2 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DepositWithdrawAction = void 0;
4
+ class DepositWithdrawAction {
5
+ }
6
+ exports.DepositWithdrawAction = DepositWithdrawAction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhedge/backend-flatcoin-core",
3
- "version": "0.1.31",
3
+ "version": "0.1.33",
4
4
  "description": "Backend Flatcoin Core",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",