@typus/typus-perp-sdk 1.0.47 → 1.0.49

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.
@@ -26,5 +26,5 @@ export interface Event {
26
26
  }
27
27
  export declare function parseUserHistory(raw_events: any): Promise<Event[]>;
28
28
  export declare function getGraphQLEvents(module: string, sender: string, beforeCursor?: string | null): Promise<any>;
29
- export declare function getLiquidateFromSentio(userAddress: string, startTimestamp: number): Promise<Event[]>;
29
+ export declare function getLiquidateFromSentio(userAddress: string, startTimestamp: number, rawEvents: any, orderMatchEventsFromSentio: any): Promise<Event[]>;
30
30
  export declare function getOrderMatchFromSentio(userAddress: string, startTimestamp: number, rawEvents: any): Promise<Event[]>;
@@ -74,15 +74,15 @@ var structs_3 = require("../../src/typus_perp/lp-pool/structs");
74
74
  var sentio_1 = require("../../src/api/sentio");
75
75
  var src_1 = require("../../src");
76
76
  var checkOrderType = function (filled, reduceOnly, isStopOrder) {
77
- if (filled) {
78
- return "Market";
79
- }
80
77
  if (reduceOnly && !isStopOrder) {
81
78
  return "Take Profit";
82
79
  }
83
80
  if (reduceOnly && isStopOrder) {
84
81
  return "Stop Loss";
85
82
  }
83
+ if (filled) {
84
+ return "Market";
85
+ }
86
86
  return "Limit";
87
87
  };
88
88
  var parseCollateralAmount = function (collateral_amount, collateral_token, collateral_in_deposit_token, deposit_token) {
@@ -408,7 +408,7 @@ function getGraphQLEvents(module_1, sender_1) {
408
408
  });
409
409
  });
410
410
  }
411
- function getLiquidateFromSentio(userAddress, startTimestamp) {
411
+ function getLiquidateFromSentio(userAddress, startTimestamp, rawEvents, orderMatchEventsFromSentio) {
412
412
  return __awaiter(this, void 0, void 0, function () {
413
413
  var datas;
414
414
  return __generator(this, function (_a) {
@@ -419,16 +419,30 @@ function getLiquidateFromSentio(userAddress, startTimestamp) {
419
419
  // console.log(datas);
420
420
  return [2 /*return*/, datas.map(function (x) {
421
421
  var collateral = Number(x.liquidator_fee) + Number(x.value_for_lp_pool);
422
+ var sourceFilledOrder = rawEvents.findLast(function (e) {
423
+ var _a, _b, _c, _d, _e, _f;
424
+ var rawEventJson = e.contents.json;
425
+ return (((_b = (_a = rawEventJson === null || rawEventJson === void 0 ? void 0 : rawEventJson.symbol) === null || _a === void 0 ? void 0 : _a.base_token) === null || _b === void 0 ? void 0 : _b.name) &&
426
+ rawEventJson.new_position_id == x.position_id &&
427
+ ((0, constants_1.typeArgToAsset)((_d = (_c = rawEventJson === null || rawEventJson === void 0 ? void 0 : rawEventJson.symbol) === null || _c === void 0 ? void 0 : _c.base_token) === null || _d === void 0 ? void 0 : _d.name) == x.trading_token ||
428
+ ((_f = (_e = rawEventJson === null || rawEventJson === void 0 ? void 0 : rawEventJson.symbol) === null || _e === void 0 ? void 0 : _e.base_token) === null || _f === void 0 ? void 0 : _f.name.split("::")[2]) == x.trading_token));
429
+ });
430
+ var related = rawEvents.findLast(function (e) {
431
+ var _a, _b, _c, _d;
432
+ var rawEventJson = e.contents.json;
433
+ return (rawEventJson.order_id == (sourceFilledOrder === null || sourceFilledOrder === void 0 ? void 0 : sourceFilledOrder.contents.json.order_id) &&
434
+ ((_a = rawEventJson === null || rawEventJson === void 0 ? void 0 : rawEventJson.base_token) === null || _a === void 0 ? void 0 : _a.name) == ((_d = (_c = (_b = sourceFilledOrder === null || sourceFilledOrder === void 0 ? void 0 : sourceFilledOrder.contents.json) === null || _b === void 0 ? void 0 : _b.symbol) === null || _c === void 0 ? void 0 : _c.base_token) === null || _d === void 0 ? void 0 : _d.name));
435
+ });
422
436
  var txHistory = {
423
437
  action: "Liquidation",
424
438
  typeName: undefined,
425
439
  order_id: x.order_id,
426
440
  position_id: x.position_id,
427
441
  market: "".concat(x.trading_token, "/USD"),
428
- side: undefined,
442
+ side: (related === null || related === void 0 ? void 0 : related.contents.json.is_long) ? "Long" : "Short",
429
443
  order_type: "Market",
430
444
  status: "Filled",
431
- size: undefined,
445
+ size: related === null || related === void 0 ? void 0 : related.contents.json.size,
432
446
  base_token: x.trading_token,
433
447
  collateral: collateral,
434
448
  collateral_token: x.collateral_token,
@@ -455,7 +469,7 @@ function getOrderMatchFromSentio(userAddress, startTimestamp, rawEvents) {
455
469
  var related;
456
470
  if (x.order_type == "Open") {
457
471
  related = rawEvents.findLast(function (e) {
458
- var _a, _b;
472
+ var _a, _b, _c;
459
473
  var rawEventJson = e.contents.json;
460
474
  var eventType = e.contents.type.repr.split("::")[2];
461
475
  var createTradingOrderEvent = structs_2.CreateTradingOrderEvent.$typeName.split("::")[2];
@@ -464,16 +478,18 @@ function getOrderMatchFromSentio(userAddress, startTimestamp, rawEvents) {
464
478
  return (((_a = rawEventJson === null || rawEventJson === void 0 ? void 0 : rawEventJson.base_token) === null || _a === void 0 ? void 0 : _a.name) &&
465
479
  checkEventType &&
466
480
  rawEventJson.order_id == x.order_id &&
467
- (0, constants_1.typeArgToAsset)((_b = rawEventJson === null || rawEventJson === void 0 ? void 0 : rawEventJson.base_token) === null || _b === void 0 ? void 0 : _b.name) == x.trading_token);
481
+ ((0, constants_1.typeArgToAsset)((_b = rawEventJson === null || rawEventJson === void 0 ? void 0 : rawEventJson.base_token) === null || _b === void 0 ? void 0 : _b.name) == x.trading_token ||
482
+ ((_c = rawEventJson === null || rawEventJson === void 0 ? void 0 : rawEventJson.base_token) === null || _c === void 0 ? void 0 : _c.name.split("::")[2]) == x.trading_token));
468
483
  });
469
484
  }
470
485
  else {
471
486
  var sourceFilledOrder_2 = rawEvents.findLast(function (e) {
472
- var _a, _b;
487
+ var _a, _b, _c, _d, _e, _f;
473
488
  var rawEventJson = e.contents.json;
474
- return (((_a = rawEventJson === null || rawEventJson === void 0 ? void 0 : rawEventJson.base_token) === null || _a === void 0 ? void 0 : _a.name) &&
489
+ return (((_b = (_a = rawEventJson === null || rawEventJson === void 0 ? void 0 : rawEventJson.symbol) === null || _a === void 0 ? void 0 : _a.base_token) === null || _b === void 0 ? void 0 : _b.name) &&
475
490
  rawEventJson.new_position_id == x.position_id &&
476
- (0, constants_1.typeArgToAsset)((_b = rawEventJson === null || rawEventJson === void 0 ? void 0 : rawEventJson.base_token) === null || _b === void 0 ? void 0 : _b.name) == x.trading_token);
491
+ ((0, constants_1.typeArgToAsset)((_d = (_c = rawEventJson === null || rawEventJson === void 0 ? void 0 : rawEventJson.symbol) === null || _c === void 0 ? void 0 : _c.base_token) === null || _d === void 0 ? void 0 : _d.name) == x.trading_token ||
492
+ ((_f = (_e = rawEventJson === null || rawEventJson === void 0 ? void 0 : rawEventJson.symbol) === null || _e === void 0 ? void 0 : _e.base_token) === null || _f === void 0 ? void 0 : _f.name.split("::")[2]) == x.trading_token));
477
493
  });
478
494
  related = rawEvents.findLast(function (e) {
479
495
  var _a, _b, _c, _d;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typus/typus-perp-sdk",
3
- "version": "1.0.47",
3
+ "version": "1.0.49",
4
4
  "repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
5
5
  "author": "Typus",
6
6
  "description": "typus perp sdk",