@dhedge/backend-flatcoin-core 0.1.38 → 0.1.40

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.
@@ -0,0 +1,20 @@
1
+ export declare const ViewerGetPositionData: {
2
+ inputs: {
3
+ internalType: string;
4
+ name: string;
5
+ type: string;
6
+ }[];
7
+ name: string;
8
+ outputs: {
9
+ components: {
10
+ internalType: string;
11
+ name: string;
12
+ type: string;
13
+ }[];
14
+ internalType: string;
15
+ name: string;
16
+ type: string;
17
+ }[];
18
+ stateMutability: string;
19
+ type: string;
20
+ }[];
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ViewerGetPositionData = void 0;
4
+ exports.ViewerGetPositionData = [
5
+ {
6
+ inputs: [
7
+ {
8
+ internalType: 'uint256',
9
+ name: 'tokenId',
10
+ type: 'uint256',
11
+ },
12
+ ],
13
+ name: 'getPositionData',
14
+ outputs: [
15
+ {
16
+ components: [
17
+ {
18
+ internalType: 'uint256',
19
+ name: 'tokenId',
20
+ type: 'uint256',
21
+ },
22
+ {
23
+ internalType: 'uint256',
24
+ name: 'lastPrice',
25
+ type: 'uint256',
26
+ },
27
+ {
28
+ internalType: 'uint256',
29
+ name: 'marginDeposited',
30
+ type: 'uint256',
31
+ },
32
+ {
33
+ internalType: 'uint256',
34
+ name: 'additionalSize',
35
+ type: 'uint256',
36
+ },
37
+ {
38
+ internalType: 'int256',
39
+ name: 'entryCumulativeFunding',
40
+ type: 'int256',
41
+ },
42
+ {
43
+ internalType: 'int256',
44
+ name: 'profitLoss',
45
+ type: 'int256',
46
+ },
47
+ {
48
+ internalType: 'int256',
49
+ name: 'accruedFunding',
50
+ type: 'int256',
51
+ },
52
+ {
53
+ internalType: 'int256',
54
+ name: 'marginAfterSettlement',
55
+ type: 'int256',
56
+ },
57
+ {
58
+ internalType: 'uint256',
59
+ name: 'liquidationPrice',
60
+ type: 'uint256',
61
+ },
62
+ {
63
+ internalType: 'uint256',
64
+ name: 'limitOrderPriceLowerThreshold',
65
+ type: 'uint256',
66
+ },
67
+ {
68
+ internalType: 'uint256',
69
+ name: 'limitOrderPriceUpperThreshold',
70
+ type: 'uint256',
71
+ },
72
+ ],
73
+ internalType: 'struct FlatcoinStructs.LeveragePositionData',
74
+ name: 'positionData',
75
+ type: 'tuple',
76
+ },
77
+ ],
78
+ stateMutability: 'view',
79
+ type: 'function',
80
+ },
81
+ ];
@@ -75,6 +75,16 @@ exports.Viewer = [
75
75
  name: 'liquidationPrice',
76
76
  type: 'uint256',
77
77
  },
78
+ {
79
+ internalType: 'uint256',
80
+ name: 'limitOrderPriceLowerThreshold',
81
+ type: 'uint256',
82
+ },
83
+ {
84
+ internalType: 'uint256',
85
+ name: 'limitOrderPriceUpperThreshold',
86
+ type: 'uint256',
87
+ },
78
88
  ],
79
89
  internalType: 'struct FlatcoinStructs.LeveragePositionData[]',
80
90
  name: 'positionData',
@@ -1,5 +1,5 @@
1
1
  import { Repository } from 'typeorm';
2
- import { LimitOrderEntity } from '../entity/limit-order.entity';
2
+ import { LimitOrderEntity } from '../entity';
3
3
  export declare class LimitOrderRepository {
4
4
  private repository;
5
5
  constructor(repository: Repository<LimitOrderEntity>);
@@ -17,7 +17,7 @@ const common_1 = require("@nestjs/common");
17
17
  const typeorm_1 = require("@nestjs/typeorm");
18
18
  const typeorm_2 = require("typeorm");
19
19
  const constants_1 = require("../constants");
20
- const limit_order_entity_1 = require("../entity/limit-order.entity");
20
+ const entity_1 = require("../entity");
21
21
  let LimitOrderRepository = class LimitOrderRepository {
22
22
  constructor(repository) {
23
23
  this.repository = repository;
@@ -48,6 +48,6 @@ let LimitOrderRepository = class LimitOrderRepository {
48
48
  exports.LimitOrderRepository = LimitOrderRepository;
49
49
  exports.LimitOrderRepository = LimitOrderRepository = __decorate([
50
50
  (0, common_1.Injectable)(),
51
- __param(0, (0, typeorm_1.InjectRepository)(limit_order_entity_1.LimitOrderEntity)),
51
+ __param(0, (0, typeorm_1.InjectRepository)(entity_1.LimitOrderEntity)),
52
52
  __metadata("design:paramtypes", [typeorm_2.Repository])
53
53
  ], LimitOrderRepository);
@@ -1,6 +1,6 @@
1
1
  import { Repository } from 'typeorm';
2
2
  import { BigNumber } from 'ethers';
3
- import { PositionEntity } from '../entity/position-entity';
3
+ import { PositionEntity } from '../entity';
4
4
  export declare class PositionRepository {
5
5
  private repository;
6
6
  constructor(repository: Repository<PositionEntity>);
@@ -17,7 +17,7 @@ const common_1 = require("@nestjs/common");
17
17
  const typeorm_1 = require("@nestjs/typeorm");
18
18
  const typeorm_2 = require("typeorm");
19
19
  const constants_1 = require("../constants");
20
- const position_entity_1 = require("../entity/position-entity");
20
+ const entity_1 = require("../entity");
21
21
  let PositionRepository = class PositionRepository {
22
22
  constructor(repository) {
23
23
  this.repository = repository;
@@ -38,7 +38,7 @@ let PositionRepository = class PositionRepository {
38
38
  async updateLiquidationPrice(tokenId, liqPrice) {
39
39
  await this.repository
40
40
  .createQueryBuilder()
41
- .update(position_entity_1.PositionEntity)
41
+ .update(entity_1.PositionEntity)
42
42
  .set({ liquidationPrice: liqPrice })
43
43
  .where('token_id = :tokenId', { tokenId: tokenId })
44
44
  .execute();
@@ -63,6 +63,6 @@ let PositionRepository = class PositionRepository {
63
63
  exports.PositionRepository = PositionRepository;
64
64
  exports.PositionRepository = PositionRepository = __decorate([
65
65
  (0, common_1.Injectable)(),
66
- __param(0, (0, typeorm_1.InjectRepository)(position_entity_1.PositionEntity)),
66
+ __param(0, (0, typeorm_1.InjectRepository)(entity_1.PositionEntity)),
67
67
  __metadata("design:paramtypes", [typeorm_2.Repository])
68
68
  ], PositionRepository);
@@ -1,5 +1,5 @@
1
1
  import { Logger } from '@nestjs/common';
2
- import { AnnouncedOrder, DepositEvent, LeveragePositionEvent, WithdrawEvent } from '../utils';
2
+ import { AnnouncedLimitOrder, AnnouncedOrder, DepositEvent, LeveragePositionEvent, WithdrawEvent } from '../utils';
3
3
  import { GraphQLClient } from 'graphql-request';
4
4
  export declare class GraphQueryService {
5
5
  private readonly graphQLClient;
@@ -13,6 +13,7 @@ export declare class GraphQueryService {
13
13
  getDepositsByDepositorAddress(account: string, blockFrom: number): Promise<DepositEvent[]>;
14
14
  getWithdraws(blockFrom: number): Promise<WithdrawEvent[]>;
15
15
  getWithdrawsByWithdrawerAddress(account: string, blockFrom: number): Promise<WithdrawEvent[]>;
16
+ getLimitOrderAnnounceds(blockNumberFrom: number): Promise<AnnouncedLimitOrder[]>;
16
17
  }
17
18
  export declare const getAnnouncedOrdersQuery: string;
18
19
  export declare const getLeverageOpensQuery: string;
@@ -22,3 +23,4 @@ export declare const getDepositsQuery: string;
22
23
  export declare const getDepositsByDepositorAddressQuery: string;
23
24
  export declare const getWithdrawsQuery: string;
24
25
  export declare const getWithdrawsByWithdrawerAddressQuery: string;
26
+ export declare const getLimitOrderAnnouncedsQuery: 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.getWithdrawsByWithdrawerAddressQuery = exports.getWithdrawsQuery = exports.getDepositsByDepositorAddressQuery = exports.getDepositsQuery = exports.getPositionLiquidatedsQuery = exports.getLeverageClosesQuery = exports.getLeverageOpensQuery = exports.getAnnouncedOrdersQuery = exports.GraphQueryService = void 0;
12
+ 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");
@@ -117,6 +117,18 @@ let GraphQueryService = class GraphQueryService {
117
117
  throw error;
118
118
  }
119
119
  }
120
+ async getLimitOrderAnnounceds(blockNumberFrom) {
121
+ const variables = { blockFrom: blockNumberFrom.toString() };
122
+ try {
123
+ const response = await this.graphQLClient.request(exports.getLimitOrderAnnouncedsQuery, variables);
124
+ this.logger.log(`Fetched ${response.limitOrderAnnounceds.length} limitOrderAnnounceds events from the graph`);
125
+ return response.limitOrderAnnounceds;
126
+ }
127
+ catch (error) {
128
+ this.logger.error('Error fetching announced limit orders from the graph:', error);
129
+ throw error;
130
+ }
131
+ }
120
132
  };
121
133
  exports.GraphQueryService = GraphQueryService;
122
134
  exports.GraphQueryService = GraphQueryService = __decorate([
@@ -213,3 +225,17 @@ exports.getWithdrawsByWithdrawerAddressQuery = (0, graphql_request_1.gql) `
213
225
  }
214
226
  }
215
227
  `;
228
+ exports.getLimitOrderAnnouncedsQuery = (0, graphql_request_1.gql) `
229
+ query GetLimitOrderAnnounceds($blockFrom: Int) {
230
+ limitOrderAnnounceds(where: { blockNumber_gt: $blockFrom }, orderBy: blockNumber, orderDirection: acs) {
231
+ id
232
+ tokenId
233
+ account
234
+ blockNumber
235
+ blockTimestamp
236
+ priceLowerThreshold
237
+ priceUpperThreshold
238
+ transactionHash
239
+ }
240
+ }
241
+ `;
@@ -33,6 +33,16 @@ export interface LeveragePositionEvent {
33
33
  liquidator: string;
34
34
  eventType: string;
35
35
  }
36
+ export interface AnnouncedLimitOrder {
37
+ id: string;
38
+ tokenId: number;
39
+ account: string;
40
+ blockNumber: number;
41
+ blockTimestamp: number;
42
+ priceLowerThreshold: number;
43
+ priceUpperThreshold: number;
44
+ transactionHash: string;
45
+ }
36
46
  export interface DepositEventsData {
37
47
  deposits: DepositEvent[];
38
48
  }
@@ -51,3 +61,6 @@ export interface PositionLiquidatedsData {
51
61
  export interface AnnouncedOrderData {
52
62
  orderAnnounceds: AnnouncedOrder[];
53
63
  }
64
+ export interface AnnouncedLimitOrderData {
65
+ limitOrderAnnounceds: AnnouncedLimitOrder[];
66
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhedge/backend-flatcoin-core",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "description": "Backend Flatcoin Core",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",