@dhedge/backend-flatcoin-core 0.1.24 → 0.1.26

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.
@@ -12,3 +12,8 @@ export declare const PERIOD_IN_SECONDS: {
12
12
  };
13
13
  export { HistoricalPeriod };
14
14
  export declare const getChartPeriod: (value: string) => HistoricalPeriod;
15
+ export declare enum LeveragePositionStatus {
16
+ OPEN = "OPEN",
17
+ CLOSED = "CLOSED",
18
+ LIQUIDATED = "LIQUIDATED"
19
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getChartPeriod = exports.HistoricalPeriod = exports.PERIOD_IN_SECONDS = void 0;
3
+ 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";
@@ -24,3 +24,9 @@ const getChartPeriod = (value) => {
24
24
  }
25
25
  };
26
26
  exports.getChartPeriod = getChartPeriod;
27
+ var LeveragePositionStatus;
28
+ (function (LeveragePositionStatus) {
29
+ LeveragePositionStatus["OPEN"] = "OPEN";
30
+ LeveragePositionStatus["CLOSED"] = "CLOSED";
31
+ LeveragePositionStatus["LIQUIDATED"] = "LIQUIDATED";
32
+ })(LeveragePositionStatus || (exports.LeveragePositionStatus = LeveragePositionStatus = {}));
@@ -436,4 +436,128 @@ exports.FlatcoinErrors = [
436
436
  name: 'PriceImpactDuringWithdraw',
437
437
  type: 'error',
438
438
  },
439
+ {
440
+ inputs: [
441
+ {
442
+ internalType: 'uint256',
443
+ name: 'executableTime',
444
+ type: 'uint256',
445
+ },
446
+ ],
447
+ name: 'ExecutableTimeNotReached',
448
+ type: 'error',
449
+ },
450
+ {
451
+ inputs: [
452
+ {
453
+ internalType: 'uint256',
454
+ name: 'priceLowerThreshold',
455
+ type: 'uint256',
456
+ },
457
+ {
458
+ internalType: 'uint256',
459
+ name: 'priceUpperThreshold',
460
+ type: 'uint256',
461
+ },
462
+ ],
463
+ name: 'InvalidThresholds',
464
+ type: 'error',
465
+ },
466
+ {
467
+ inputs: [
468
+ {
469
+ internalType: 'string',
470
+ name: 'variableName',
471
+ type: 'string',
472
+ },
473
+ ],
474
+ name: 'InvariantViolation',
475
+ type: 'error',
476
+ },
477
+ {
478
+ inputs: [
479
+ {
480
+ internalType: 'uint256',
481
+ name: 'tokenId',
482
+ type: 'uint256',
483
+ },
484
+ ],
485
+ name: 'LimitOrderInvalid',
486
+ type: 'error',
487
+ },
488
+ {
489
+ inputs: [
490
+ {
491
+ internalType: 'uint256',
492
+ name: 'price',
493
+ type: 'uint256',
494
+ },
495
+ {
496
+ internalType: 'uint256',
497
+ name: 'priceLowerThreshold',
498
+ type: 'uint256',
499
+ },
500
+ {
501
+ internalType: 'uint256',
502
+ name: 'priceUpperThreshold',
503
+ type: 'uint256',
504
+ },
505
+ ],
506
+ name: 'LimitOrderPriceNotInRange',
507
+ type: 'error',
508
+ },
509
+ {
510
+ inputs: [],
511
+ name: 'ModuleKeyEmpty',
512
+ type: 'error',
513
+ },
514
+ {
515
+ inputs: [
516
+ {
517
+ internalType: 'uint256',
518
+ name: 'tokenId',
519
+ type: 'uint256',
520
+ },
521
+ {
522
+ internalType: 'address',
523
+ name: 'msgSender',
524
+ type: 'address',
525
+ },
526
+ ],
527
+ name: 'NotTokenOwner',
528
+ type: 'error',
529
+ },
530
+ {
531
+ inputs: [
532
+ {
533
+ internalType: 'address',
534
+ name: 'msgSender',
535
+ type: 'address',
536
+ },
537
+ ],
538
+ name: 'OnlyAuthorizedModule',
539
+ type: 'error',
540
+ },
541
+ {
542
+ inputs: [
543
+ {
544
+ internalType: 'address',
545
+ name: 'msgSender',
546
+ type: 'address',
547
+ },
548
+ ],
549
+ name: 'OnlyOwner',
550
+ type: 'error',
551
+ },
552
+ {
553
+ inputs: [
554
+ {
555
+ internalType: 'string',
556
+ name: 'variableName',
557
+ type: 'string',
558
+ },
559
+ ],
560
+ name: 'ZeroAddress',
561
+ type: 'error',
562
+ },
439
563
  ];
@@ -0,0 +1,48 @@
1
+ export declare const LimitOrder: ({
2
+ anonymous: boolean;
3
+ inputs: {
4
+ indexed: boolean;
5
+ internalType: string;
6
+ name: string;
7
+ type: string;
8
+ }[];
9
+ name: string;
10
+ type: string;
11
+ outputs?: undefined;
12
+ stateMutability?: undefined;
13
+ } | {
14
+ inputs: {
15
+ internalType: string;
16
+ name: string;
17
+ type: string;
18
+ }[];
19
+ name: string;
20
+ outputs: {
21
+ internalType: string;
22
+ name: string;
23
+ type: string;
24
+ }[];
25
+ stateMutability: string;
26
+ type: string;
27
+ anonymous?: undefined;
28
+ } | {
29
+ inputs: {
30
+ internalType: string;
31
+ name: string;
32
+ type: string;
33
+ }[];
34
+ name: string;
35
+ outputs: {
36
+ components: {
37
+ internalType: string;
38
+ name: string;
39
+ type: string;
40
+ }[];
41
+ internalType: string;
42
+ name: string;
43
+ type: string;
44
+ }[];
45
+ stateMutability: string;
46
+ type: string;
47
+ anonymous?: undefined;
48
+ })[][];
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LimitOrder = void 0;
4
+ exports.LimitOrder = [
5
+ [
6
+ {
7
+ anonymous: false,
8
+ inputs: [
9
+ {
10
+ indexed: false,
11
+ internalType: 'uint8',
12
+ name: 'version',
13
+ type: 'uint8',
14
+ },
15
+ ],
16
+ name: 'Initialized',
17
+ type: 'event',
18
+ },
19
+ {
20
+ inputs: [],
21
+ name: 'MODULE_KEY',
22
+ outputs: [
23
+ {
24
+ internalType: 'bytes32',
25
+ name: '',
26
+ type: 'bytes32',
27
+ },
28
+ ],
29
+ stateMutability: 'view',
30
+ type: 'function',
31
+ },
32
+ {
33
+ inputs: [
34
+ {
35
+ internalType: 'uint256',
36
+ name: 'tokenId',
37
+ type: 'uint256',
38
+ },
39
+ {
40
+ internalType: 'uint256',
41
+ name: 'priceLowerThreshold',
42
+ type: 'uint256',
43
+ },
44
+ {
45
+ internalType: 'uint256',
46
+ name: 'priceUpperThreshold',
47
+ type: 'uint256',
48
+ },
49
+ ],
50
+ name: 'announceLimitOrder',
51
+ outputs: [],
52
+ stateMutability: 'nonpayable',
53
+ type: 'function',
54
+ },
55
+ {
56
+ inputs: [
57
+ {
58
+ internalType: 'uint256',
59
+ name: 'tokenId',
60
+ type: 'uint256',
61
+ },
62
+ ],
63
+ name: 'cancelExistingLimitOrder',
64
+ outputs: [
65
+ {
66
+ internalType: 'bool',
67
+ name: 'cancelled',
68
+ type: 'bool',
69
+ },
70
+ ],
71
+ stateMutability: 'nonpayable',
72
+ type: 'function',
73
+ },
74
+ {
75
+ inputs: [
76
+ {
77
+ internalType: 'uint256',
78
+ name: 'tokenId',
79
+ type: 'uint256',
80
+ },
81
+ ],
82
+ name: 'cancelLimitOrder',
83
+ outputs: [],
84
+ stateMutability: 'nonpayable',
85
+ type: 'function',
86
+ },
87
+ {
88
+ inputs: [
89
+ {
90
+ internalType: 'uint256',
91
+ name: 'tokenId',
92
+ type: 'uint256',
93
+ },
94
+ {
95
+ internalType: 'bytes[]',
96
+ name: 'priceUpdateData',
97
+ type: 'bytes[]',
98
+ },
99
+ ],
100
+ name: 'executeLimitOrder',
101
+ outputs: [],
102
+ stateMutability: 'payable',
103
+ type: 'function',
104
+ },
105
+ {
106
+ inputs: [
107
+ {
108
+ internalType: 'uint256',
109
+ name: 'tokenId',
110
+ type: 'uint256',
111
+ },
112
+ ],
113
+ name: 'getLimitOrder',
114
+ outputs: [
115
+ {
116
+ components: [
117
+ {
118
+ internalType: 'enum FlatcoinStructs.OrderType',
119
+ name: 'orderType',
120
+ type: 'uint8',
121
+ },
122
+ {
123
+ internalType: 'uint256',
124
+ name: 'keeperFee',
125
+ type: 'uint256',
126
+ },
127
+ {
128
+ internalType: 'uint64',
129
+ name: 'executableAtTime',
130
+ type: 'uint64',
131
+ },
132
+ {
133
+ internalType: 'bytes',
134
+ name: 'orderData',
135
+ type: 'bytes',
136
+ },
137
+ ],
138
+ internalType: 'struct FlatcoinStructs.Order',
139
+ name: 'order',
140
+ type: 'tuple',
141
+ },
142
+ ],
143
+ stateMutability: 'view',
144
+ type: 'function',
145
+ },
146
+ {
147
+ inputs: [
148
+ {
149
+ internalType: 'contract IFlatcoinVault',
150
+ name: '_vault',
151
+ type: 'address',
152
+ },
153
+ ],
154
+ name: 'initialize',
155
+ outputs: [],
156
+ stateMutability: 'nonpayable',
157
+ type: 'function',
158
+ },
159
+ {
160
+ inputs: [
161
+ {
162
+ internalType: 'contract IFlatcoinVault',
163
+ name: '_vault',
164
+ type: 'address',
165
+ },
166
+ ],
167
+ name: 'setVault',
168
+ outputs: [],
169
+ stateMutability: 'nonpayable',
170
+ type: 'function',
171
+ },
172
+ {
173
+ inputs: [],
174
+ name: 'vault',
175
+ outputs: [
176
+ {
177
+ internalType: 'contract IFlatcoinVault',
178
+ name: '',
179
+ type: 'address',
180
+ },
181
+ ],
182
+ stateMutability: 'view',
183
+ type: 'function',
184
+ },
185
+ ],
186
+ ];
@@ -26,3 +26,25 @@ export declare const LiquidationModule: ({
26
26
  type: string;
27
27
  anonymous?: undefined;
28
28
  })[];
29
+ export declare const Liquidate: {
30
+ inputs: {
31
+ internalType: string;
32
+ name: string;
33
+ type: string;
34
+ }[];
35
+ name: string;
36
+ outputs: never[];
37
+ stateMutability: string;
38
+ type: string;
39
+ }[];
40
+ export declare const LiquidateWithoutPriceFeeds: {
41
+ inputs: {
42
+ internalType: string;
43
+ name: string;
44
+ type: string;
45
+ }[];
46
+ name: string;
47
+ outputs: never[];
48
+ stateMutability: string;
49
+ type: string;
50
+ }[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LiquidationModule = void 0;
3
+ exports.LiquidateWithoutPriceFeeds = exports.Liquidate = exports.LiquidationModule = void 0;
4
4
  exports.LiquidationModule = [
5
5
  {
6
6
  anonymous: false,
@@ -35,27 +35,15 @@ exports.LiquidationModule = [
35
35
  type: 'uint256',
36
36
  },
37
37
  ],
38
- name: 'liquidate',
39
- outputs: [],
40
- stateMutability: 'nonpayable',
41
- type: 'function',
42
- },
43
- {
44
- inputs: [
45
- {
46
- internalType: 'uint256',
47
- name: 'tokenID',
48
- type: 'uint256',
49
- },
38
+ name: 'canLiquidate',
39
+ outputs: [
50
40
  {
51
- internalType: 'bytes[]',
52
- name: 'priceUpdateData',
53
- type: 'bytes[]',
41
+ internalType: 'bool',
42
+ name: 'liquidatable',
43
+ type: 'bool',
54
44
  },
55
45
  ],
56
- name: 'liquidate',
57
- outputs: [],
58
- stateMutability: 'payable',
46
+ stateMutability: 'view',
59
47
  type: 'function',
60
48
  },
61
49
  {
@@ -66,34 +54,50 @@ exports.LiquidationModule = [
66
54
  type: 'uint256',
67
55
  },
68
56
  ],
69
- name: 'canLiquidate',
57
+ name: 'liquidationPrice',
70
58
  outputs: [
71
59
  {
72
- internalType: 'bool',
73
- name: 'liquidatable',
74
- type: 'bool',
60
+ internalType: 'uint256',
61
+ name: 'liqPrice',
62
+ type: 'uint256',
75
63
  },
76
64
  ],
77
65
  stateMutability: 'view',
78
66
  type: 'function',
79
67
  },
68
+ ];
69
+ exports.Liquidate = [
80
70
  {
81
71
  inputs: [
82
72
  {
83
73
  internalType: 'uint256',
84
- name: 'tokenId',
74
+ name: 'tokenID',
85
75
  type: 'uint256',
86
76
  },
77
+ {
78
+ internalType: 'bytes[]',
79
+ name: 'priceUpdateData',
80
+ type: 'bytes[]',
81
+ },
87
82
  ],
88
- name: 'liquidationPrice',
89
- outputs: [
83
+ name: 'liquidate',
84
+ outputs: [],
85
+ stateMutability: 'payable',
86
+ type: 'function',
87
+ },
88
+ ];
89
+ exports.LiquidateWithoutPriceFeeds = [
90
+ {
91
+ inputs: [
90
92
  {
91
93
  internalType: 'uint256',
92
- name: 'liqPrice',
94
+ name: 'tokenId',
93
95
  type: 'uint256',
94
96
  },
95
97
  ],
96
- stateMutability: 'view',
98
+ name: 'liquidate',
99
+ outputs: [],
100
+ stateMutability: 'nonpayable',
97
101
  type: 'function',
98
102
  },
99
103
  ];
@@ -3,4 +3,6 @@ export { Viewer } from './abi/viewer';
3
3
  export { FlatcoinErrors } from './abi/flatcoin-errors';
4
4
  export { LeverageModule } from './abi/leverage-module';
5
5
  export { LiquidationModule } from './abi/liquidation-module';
6
+ export { Liquidate } from './abi/liquidation-module';
7
+ export { LiquidateWithoutPriceFeeds } from './abi/liquidation-module';
6
8
  export * from './helpers';
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.LiquidationModule = exports.LeverageModule = exports.FlatcoinErrors = exports.Viewer = exports.FlatcoinV1 = void 0;
17
+ exports.LiquidateWithoutPriceFeeds = exports.Liquidate = exports.LiquidationModule = exports.LeverageModule = exports.FlatcoinErrors = exports.Viewer = exports.FlatcoinV1 = void 0;
18
18
  var flatcoin_v1_1 = require("./abi/flatcoin-v1");
19
19
  Object.defineProperty(exports, "FlatcoinV1", { enumerable: true, get: function () { return flatcoin_v1_1.FlatcoinV1; } });
20
20
  var viewer_1 = require("./abi/viewer");
@@ -25,4 +25,8 @@ var leverage_module_1 = require("./abi/leverage-module");
25
25
  Object.defineProperty(exports, "LeverageModule", { enumerable: true, get: function () { return leverage_module_1.LeverageModule; } });
26
26
  var liquidation_module_1 = require("./abi/liquidation-module");
27
27
  Object.defineProperty(exports, "LiquidationModule", { enumerable: true, get: function () { return liquidation_module_1.LiquidationModule; } });
28
+ var liquidation_module_2 = require("./abi/liquidation-module");
29
+ Object.defineProperty(exports, "Liquidate", { enumerable: true, get: function () { return liquidation_module_2.Liquidate; } });
30
+ var liquidation_module_3 = require("./abi/liquidation-module");
31
+ Object.defineProperty(exports, "LiquidateWithoutPriceFeeds", { enumerable: true, get: function () { return liquidation_module_3.LiquidateWithoutPriceFeeds; } });
28
32
  __exportStar(require("./helpers"), exports);
@@ -0,0 +1,14 @@
1
+ import { BigNumber } from 'ethers';
2
+ export declare class PositionEntity {
3
+ id: number;
4
+ tokenId: number;
5
+ account: string;
6
+ status: string;
7
+ liquidationPrice: BigNumber;
8
+ liquidatorAddress: string;
9
+ liquidatedAtPrice: BigNumber;
10
+ blockCreatedAt: number;
11
+ blockUpdatedAt: number;
12
+ createdAt: number;
13
+ updatedAt: number;
14
+ }
@@ -0,0 +1,72 @@
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.PositionEntity = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ const ethers_1 = require("ethers");
15
+ const utils_1 = require("../utils");
16
+ let PositionEntity = class PositionEntity {
17
+ };
18
+ exports.PositionEntity = PositionEntity;
19
+ __decorate([
20
+ (0, typeorm_1.PrimaryGeneratedColumn)({ name: 'id' }),
21
+ __metadata("design:type", Number)
22
+ ], PositionEntity.prototype, "id", void 0);
23
+ __decorate([
24
+ (0, typeorm_1.Column)({
25
+ name: 'token_id',
26
+ type: 'numeric',
27
+ precision: 25,
28
+ unique: true,
29
+ nullable: false,
30
+ transformer: utils_1.numericTransformer,
31
+ }),
32
+ __metadata("design:type", Number)
33
+ ], PositionEntity.prototype, "tokenId", void 0);
34
+ __decorate([
35
+ (0, typeorm_1.Column)({ name: 'account', nullable: false }),
36
+ __metadata("design:type", String)
37
+ ], PositionEntity.prototype, "account", void 0);
38
+ __decorate([
39
+ (0, typeorm_1.Column)({ name: 'status', nullable: false }),
40
+ __metadata("design:type", String)
41
+ ], PositionEntity.prototype, "status", void 0);
42
+ __decorate([
43
+ (0, typeorm_1.Column)({ name: 'liquidation_price', type: 'bigint', precision: 30, transformer: utils_1.bigNumberTransformer }),
44
+ __metadata("design:type", ethers_1.BigNumber)
45
+ ], PositionEntity.prototype, "liquidationPrice", void 0);
46
+ __decorate([
47
+ (0, typeorm_1.Column)({ name: 'liquidator_address' }),
48
+ __metadata("design:type", String)
49
+ ], PositionEntity.prototype, "liquidatorAddress", void 0);
50
+ __decorate([
51
+ (0, typeorm_1.Column)({ name: 'liquidated_at_price', type: 'bigint', precision: 30, transformer: utils_1.bigNumberTransformer }),
52
+ __metadata("design:type", ethers_1.BigNumber)
53
+ ], PositionEntity.prototype, "liquidatedAtPrice", void 0);
54
+ __decorate([
55
+ (0, typeorm_1.Column)({ name: 'block_created_at', type: 'numeric', precision: 25, transformer: utils_1.numericTransformer }),
56
+ __metadata("design:type", Number)
57
+ ], PositionEntity.prototype, "blockCreatedAt", void 0);
58
+ __decorate([
59
+ (0, typeorm_1.Column)({ name: 'block_updated_at', type: 'numeric', precision: 25, transformer: utils_1.numericTransformer }),
60
+ __metadata("design:type", Number)
61
+ ], PositionEntity.prototype, "blockUpdatedAt", void 0);
62
+ __decorate([
63
+ (0, typeorm_1.Column)({ name: 'created_at', type: 'numeric', precision: 25, transformer: utils_1.numericTransformer }),
64
+ __metadata("design:type", Number)
65
+ ], PositionEntity.prototype, "createdAt", void 0);
66
+ __decorate([
67
+ (0, typeorm_1.Column)({ name: 'updated_at', type: 'numeric', precision: 25, transformer: utils_1.numericTransformer }),
68
+ __metadata("design:type", Number)
69
+ ], PositionEntity.prototype, "updatedAt", void 0);
70
+ exports.PositionEntity = PositionEntity = __decorate([
71
+ (0, typeorm_1.Entity)({ name: 'positions' })
72
+ ], PositionEntity);
@@ -0,0 +1,13 @@
1
+ import { Repository } from 'typeorm';
2
+ import { BigNumber } from 'ethers';
3
+ import { PositionEntity } from '../entity/position-entity';
4
+ export declare class PositionRepository {
5
+ private repository;
6
+ constructor(repository: Repository<PositionEntity>);
7
+ save(position: PositionEntity): Promise<PositionEntity>;
8
+ saveAll(positions: PositionEntity[]): Promise<PositionEntity[]>;
9
+ getAllByStatusOpen(): Promise<PositionEntity[]>;
10
+ updateLiquidationPrice(tokenId: number, liqPrice: BigNumber): Promise<void>;
11
+ getOneByTokenId(tokenId: number): Promise<PositionEntity | null>;
12
+ getLatestUpdateAtBlock(): Promise<number>;
13
+ }
@@ -0,0 +1,68 @@
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
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.PositionRepository = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const typeorm_1 = require("@nestjs/typeorm");
18
+ const typeorm_2 = require("typeorm");
19
+ const constants_1 = require("../constants");
20
+ const position_entity_1 = require("../entity/position-entity");
21
+ let PositionRepository = class PositionRepository {
22
+ constructor(repository) {
23
+ this.repository = repository;
24
+ }
25
+ async save(position) {
26
+ return this.repository.save(position);
27
+ }
28
+ async saveAll(positions) {
29
+ return this.repository.save(positions);
30
+ }
31
+ async getAllByStatusOpen() {
32
+ return this.repository
33
+ .createQueryBuilder()
34
+ .where('status = :status', { status: constants_1.LeveragePositionStatus.OPEN })
35
+ .orderBy('liquidation_price', 'DESC')
36
+ .getMany();
37
+ }
38
+ async updateLiquidationPrice(tokenId, liqPrice) {
39
+ await this.repository
40
+ .createQueryBuilder()
41
+ .update(position_entity_1.PositionEntity)
42
+ .set({ liquidationPrice: liqPrice })
43
+ .where('token_id = :tokenId', { tokenId: tokenId })
44
+ .execute();
45
+ }
46
+ async getOneByTokenId(tokenId) {
47
+ return await this.repository
48
+ .createQueryBuilder()
49
+ .where('token_id = :tokenId')
50
+ .setParameter('tokenId', tokenId)
51
+ .take(1)
52
+ .getOne();
53
+ }
54
+ async getLatestUpdateAtBlock() {
55
+ const p = await this.repository
56
+ .createQueryBuilder('position')
57
+ .select(['position.block_updated_at'])
58
+ .orderBy('block_updated_at', 'DESC')
59
+ .getRawOne();
60
+ return p ? parseInt(p.block_updated_at) : 0;
61
+ }
62
+ };
63
+ exports.PositionRepository = PositionRepository;
64
+ exports.PositionRepository = PositionRepository = __decorate([
65
+ (0, common_1.Injectable)(),
66
+ __param(0, (0, typeorm_1.InjectRepository)(position_entity_1.PositionEntity)),
67
+ __metadata("design:paramtypes", [typeorm_2.Repository])
68
+ ], PositionRepository);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhedge/backend-flatcoin-core",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "description": "Backend Flatcoin Core",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",