@typus/typus-perp-sdk 1.1.23 → 1.1.25

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/src/index.js CHANGED
@@ -36,7 +36,7 @@ transactions_1.Transaction.registerGlobalSerializationPlugin("namedPackagesPlugi
36
36
  exports.PERP_PACKAGE_ID = exports.NETWORK == "MAINNET"
37
37
  ? "0xe27969a70f93034de9ce16e6ad661b480324574e68d15a64b513fd90eb2423e5"
38
38
  : "0x585924f160f83ef16f8927ec117e4d740abb6f4e571ecfa89ff3e973042cb1b9";
39
- exports.PERP_PUBLISHED_AT = exports.NETWORK == "MAINNET" ? "0x8076683c7d36dc8dd2cf9bf08fb50d867a89145fe392447fb8a9cdbed0f4f5f1" : "@typus/perp";
39
+ exports.PERP_PUBLISHED_AT = exports.NETWORK == "MAINNET" ? "0x9eda9afa0b42bf908766c42d02a549c271d7d0ae02c8c58c5075858f8f4d3b69" : "@typus/perp";
40
40
  exports.PERP_PKG_V1 = exports.NETWORK == "MAINNET"
41
41
  ? "0xe27969a70f93034de9ce16e6ad661b480324574e68d15a64b513fd90eb2423e5"
42
42
  : "0x585924f160f83ef16f8927ec117e4d740abb6f4e571ecfa89ff3e973042cb1b9";
@@ -1,5 +1,5 @@
1
1
  import { TOKEN } from "@typus/typus-sdk/dist/src/constants";
2
- export type actionType = "Place Order" | "Cancel Order" | "Order Filled (Open Position)" | "Order Filled (Close Position)" | "Realized PnL" | "Modify Collateral" | "Exercise Position" | "Liquidation" | "Force Cancel Order" | "Force Close Position" | "Swap" | "Realize Funding";
2
+ export type actionType = "Place Order" | "Cancel Order" | "Order Filled (Open Position)" | "Order Filled (Increase Position)" | "Order Filled (Close Position)" | "Realized PnL" | "Modify Collateral" | "Exercise Position" | "Liquidation" | "Force Cancel Order" | "Force Close Position" | "Swap" | "Realize Funding";
3
3
  export type sideType = "Long" | "Short";
4
4
  export type orderType = "Market" | "Limit" | "Take Profit" | "Stop Loss";
5
5
  export type statusType = "Open" | "Filled" | "Canceled";
@@ -84,7 +84,7 @@ function parseUserHistory(raw_events) {
84
84
  return __generator(this, function (_a) {
85
85
  events = [];
86
86
  raw_events.forEach(function (event) {
87
- var _a, _b, _c, _d;
87
+ var _a, _b, _c, _d, _e, _f;
88
88
  var type = event.contents.type.repr;
89
89
  if (type.endsWith("PythPrice")) {
90
90
  return;
@@ -96,7 +96,7 @@ function parseUserHistory(raw_events) {
96
96
  // console.log(tx_digest);
97
97
  // console.log(json);
98
98
  // console.log(timestamp);
99
- var _e = __read(type.split("::"), 3), pkg = _e[0], mod = _e[1], name = _e[2];
99
+ var _g = __read(type.split("::"), 3), pkg = _g[0], mod = _g[1], name = _g[2];
100
100
  switch (name) {
101
101
  case structs_2.CreateTradingOrderEvent.$typeName.split("::")[2]:
102
102
  case structs_2.CreateTradingOrderWithBidReceiptsEvent.$typeName.split("::")[2]:
@@ -163,6 +163,14 @@ function parseUserHistory(raw_events) {
163
163
  action = "Order Filled (Close Position)";
164
164
  related = events.findLast(function (e) { return e.position_id === json.linked_position_id && e.market === market; });
165
165
  // the "Place Order" is emit after Order Filled if filled immediately
166
+ var relatedRawEvent = raw_events.find(function (e) {
167
+ var type = e.contents.type.repr;
168
+ var _a = __read(type.split("::"), 3), pkg = _a[0], mod = _a[1], name = _a[2];
169
+ return name === (related === null || related === void 0 ? void 0 : related.typeName) && e.transactionBlock.digest === (related === null || related === void 0 ? void 0 : related.tx_digest) && (related === null || related === void 0 ? void 0 : related.order_id) === json.order_id;
170
+ });
171
+ if (((_b = (_a = relatedRawEvent === null || relatedRawEvent === void 0 ? void 0 : relatedRawEvent.contents) === null || _a === void 0 ? void 0 : _a.json) === null || _b === void 0 ? void 0 : _b.reduce_only) === false) {
172
+ action = "Order Filled (Increase Position)";
173
+ }
166
174
  if (realized_pnl > 0) {
167
175
  collateral = (realized_amount - realized_trading_fee) / Math.pow(10, (0, constants_1.assetToDecimal)(collateral_token));
168
176
  }
@@ -176,7 +184,7 @@ function parseUserHistory(raw_events) {
176
184
  action: action,
177
185
  typeName: name,
178
186
  order_id: json.order_id,
179
- position_id: (_a = json.linked_position_id) !== null && _a !== void 0 ? _a : json.new_position_id,
187
+ position_id: (_c = json.linked_position_id) !== null && _c !== void 0 ? _c : json.new_position_id,
180
188
  market: market,
181
189
  side: json.position_side ? "Long" : "Short",
182
190
  order_type: related === null || related === void 0 ? void 0 : related.order_type,
@@ -201,7 +209,7 @@ function parseUserHistory(raw_events) {
201
209
  if (index !== -1) {
202
210
  // true => user paid to pool
203
211
  var remaining_collateral_amount = json.remaining_collateral_amount / Math.pow(10, (0, constants_1.assetToDecimal)(events[index].collateral_token));
204
- events[index] = __assign(__assign({}, events[index]), { collateral: remaining_collateral_amount + ((_b = events[index].collateral) !== null && _b !== void 0 ? _b : 0) });
212
+ events[index] = __assign(__assign({}, events[index]), { collateral: remaining_collateral_amount + ((_d = events[index].collateral) !== null && _d !== void 0 ? _d : 0) });
205
213
  }
206
214
  break;
207
215
  case structs_1.RealizeFundingEvent.$typeName.split("::")[2]:
@@ -221,7 +229,7 @@ function parseUserHistory(raw_events) {
221
229
  // console.log(index);
222
230
  if (index !== -1) {
223
231
  // true => user paid to pool
224
- events[index] = __assign(__assign({}, events[index]), { collateral: (_c = events[index].collateral) !== null && _c !== void 0 ? _c : 0 - realized_funding_fee, realized_pnl: (_d = events[index].realized_pnl) !== null && _d !== void 0 ? _d : 0 - realized_funding_fee_usd });
232
+ events[index] = __assign(__assign({}, events[index]), { collateral: (_e = events[index].collateral) !== null && _e !== void 0 ? _e : 0 - realized_funding_fee, realized_pnl: (_f = events[index].realized_pnl) !== null && _f !== void 0 ? _f : 0 - realized_funding_fee_usd });
225
233
  }
226
234
  var e = {
227
235
  action: "Realize Funding",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typus/typus-perp-sdk",
3
- "version": "1.1.23",
3
+ "version": "1.1.25",
4
4
  "repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
5
5
  "author": "Typus",
6
6
  "description": "typus perp sdk",
@@ -34,4 +34,4 @@
34
34
  "url": "https://github.com/Typus-Lab/typus-perp-sdk/issues"
35
35
  },
36
36
  "homepage": "https://github.com/Typus-Lab/typus-perp-sdk#readme"
37
- }
37
+ }