@dhedge/backend-flatcoin-core 0.2.14 → 0.2.17
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/dto/index.d.ts +1 -0
- package/dist/dto/index.js +1 -0
- package/dist/dto/token-transfer.d.ts +9 -0
- package/dist/dto/token-transfer.js +6 -0
- package/dist/service/blockscan.service.d.ts +8 -0
- package/dist/service/blockscan.service.js +53 -0
- package/dist/service/graph-query.service.d.ts +4 -1
- package/dist/service/graph-query.service.js +35 -1
- package/dist/service/index.d.ts +1 -0
- package/dist/service/index.js +1 -0
- 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
|
+
];
|
package/dist/dto/index.d.ts
CHANGED
package/dist/dto/index.js
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Logger } from '@nestjs/common';
|
|
2
|
+
import { TokenTransfer } from '../dto';
|
|
3
|
+
export declare class BlockscanService {
|
|
4
|
+
private readonly logger;
|
|
5
|
+
private readonly blockscanUri;
|
|
6
|
+
constructor(logger: Logger);
|
|
7
|
+
getTokenTransfers(contractAddress: string, startBlock: number, endBlock: number): Promise<TokenTransfer[]>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.BlockscanService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const ethers_1 = require("ethers");
|
|
19
|
+
const dto_1 = require("../dto");
|
|
20
|
+
let BlockscanService = class BlockscanService {
|
|
21
|
+
constructor(logger) {
|
|
22
|
+
this.logger = logger;
|
|
23
|
+
if (process.env.BASE_BLOCKSCAN_URI) {
|
|
24
|
+
this.blockscanUri = process.env.BASE_BLOCKSCAN_URI;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async getTokenTransfers(contractAddress, startBlock, endBlock) {
|
|
28
|
+
try {
|
|
29
|
+
const response = await axios_1.default.get(`${this.blockscanUri}&module=account&action=tokentx&contractaddress=${contractAddress}&startblock=${startBlock}&endblock=${endBlock}&page=1&offset=10000&sort=asc`);
|
|
30
|
+
const result = response.data.result.map((r) => {
|
|
31
|
+
const tokenTransfer = new dto_1.TokenTransfer();
|
|
32
|
+
tokenTransfer.blockNumber = +r.blockNumber;
|
|
33
|
+
tokenTransfer.to = r.to;
|
|
34
|
+
tokenTransfer.from = r.from;
|
|
35
|
+
tokenTransfer.txHash = r.hash;
|
|
36
|
+
tokenTransfer.contractAddress = r.contractAddress;
|
|
37
|
+
tokenTransfer.value = ethers_1.BigNumber.from(r.value);
|
|
38
|
+
return tokenTransfer;
|
|
39
|
+
});
|
|
40
|
+
this.logger.log(`fetched ${result.length} unit direct transfers`);
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
this.logger.error('failed to fetch unit direct transfers', error);
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.BlockscanService = BlockscanService;
|
|
50
|
+
exports.BlockscanService = BlockscanService = __decorate([
|
|
51
|
+
(0, common_1.Injectable)(),
|
|
52
|
+
__metadata("design:paramtypes", [common_1.Logger])
|
|
53
|
+
], BlockscanService);
|
|
@@ -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
|
+
`;
|
package/dist/service/index.d.ts
CHANGED
package/dist/service/index.js
CHANGED
|
@@ -18,3 +18,4 @@ __exportStar(require("./app-price.service"), exports);
|
|
|
18
18
|
__exportStar(require("./graph-query.service"), exports);
|
|
19
19
|
__exportStar(require("./error.handler"), exports);
|
|
20
20
|
__exportStar(require("./notification.service"), exports);
|
|
21
|
+
__exportStar(require("./blockscan.service"), exports);
|
|
@@ -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
|
+
}
|