@typus/typus-perp-sdk 1.0.45 → 1.0.46

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.
@@ -27,4 +27,4 @@ export interface Event {
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
29
  export declare function getLiquidateFromSentio(userAddress: string, startTimestamp: number): Promise<Event[]>;
30
- export declare function getOrderMatchFromSentio(userAddress: string, startTimestamp: number): Promise<Event[]>;
30
+ export declare function getOrderMatchFromSentio(userAddress: string, startTimestamp: number, rawEvents: any): Promise<Event[]>;
@@ -443,7 +443,7 @@ function getLiquidateFromSentio(userAddress, startTimestamp) {
443
443
  });
444
444
  });
445
445
  }
446
- function getOrderMatchFromSentio(userAddress, startTimestamp) {
446
+ function getOrderMatchFromSentio(userAddress, startTimestamp, rawEvents) {
447
447
  return __awaiter(this, void 0, void 0, function () {
448
448
  var datas;
449
449
  return __generator(this, function (_a) {
@@ -451,17 +451,52 @@ function getOrderMatchFromSentio(userAddress, startTimestamp) {
451
451
  case 0: return [4 /*yield*/, (0, sentio_1.getFromSentio)("OrderFilled", userAddress, startTimestamp.toString())];
452
452
  case 1:
453
453
  datas = _a.sent();
454
- // console.log(datas);
455
454
  return [2 /*return*/, datas.map(function (x) {
455
+ var related;
456
+ if (x.order_type == "Open") {
457
+ related = rawEvents.findLast(function (e) {
458
+ var _a, _b;
459
+ var rawEventJson = e.contents.json;
460
+ var eventType = e.contents.type.repr.split("::")[2];
461
+ var createTradingOrderEvent = structs_2.CreateTradingOrderEvent.$typeName.split("::")[2];
462
+ var createTradingOrderWithBidReceiptsEvent = structs_2.CreateTradingOrderWithBidReceiptsEvent.$typeName.split("::")[2];
463
+ var checkEventType = eventType == createTradingOrderEvent || eventType == createTradingOrderWithBidReceiptsEvent;
464
+ return (((_a = rawEventJson === null || rawEventJson === void 0 ? void 0 : rawEventJson.base_token) === null || _a === void 0 ? void 0 : _a.name) &&
465
+ checkEventType &&
466
+ 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);
468
+ });
469
+ }
470
+ else {
471
+ var sourceFilledOrder_2 = rawEvents.findLast(function (e) {
472
+ var _a, _b;
473
+ 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) &&
475
+ 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);
477
+ });
478
+ related = rawEvents.findLast(function (e) {
479
+ var _a, _b, _c, _d;
480
+ var rawEventJson = e.contents.json;
481
+ return (rawEventJson.order_id == (sourceFilledOrder_2 === null || sourceFilledOrder_2 === void 0 ? void 0 : sourceFilledOrder_2.contents.json.order_id) &&
482
+ ((_a = rawEventJson === null || rawEventJson === void 0 ? void 0 : rawEventJson.base_token) === null || _a === void 0 ? void 0 : _a.name) == ((_d = (_c = (_b = sourceFilledOrder_2 === null || sourceFilledOrder_2 === void 0 ? void 0 : sourceFilledOrder_2.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));
483
+ });
484
+ }
456
485
  var realized_pnl = ((x.realized_amount - x.realized_trading_fee) * x.realized_fee_in_usd) / x.realized_trading_fee;
486
+ var typeName = "OrderFilledEvent";
487
+ if ((related === null || related === void 0 ? void 0 : related.contents.type.repr.split("::")[2]) == structs_2.CreateTradingOrderWithBidReceiptsEvent.$typeName.split("::")[2]) {
488
+ typeName = typeName + " (with bid receipts)";
489
+ }
457
490
  var txHistory = {
458
491
  action: x.order_type == "Open" ? "Order Filled (Open Position)" : "Order Filled (Close Position)",
459
- typeName: undefined,
492
+ typeName: typeName,
460
493
  order_id: x.order_id,
461
494
  position_id: x.position_id,
462
495
  market: "".concat(x.trading_token, "/USD"),
463
496
  side: x.side,
464
- order_type: undefined,
497
+ order_type: related
498
+ ? checkOrderType(related.contents.json.filled, related.contents.json.reduce_only, related.contents.json.is_stop_order)
499
+ : undefined,
465
500
  status: "Filled",
466
501
  size: x.filled_size,
467
502
  base_token: x.trading_token,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typus/typus-perp-sdk",
3
- "version": "1.0.45",
3
+ "version": "1.0.46",
4
4
  "repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
5
5
  "author": "Typus",
6
6
  "description": "typus perp sdk",