@typus/typus-perp-sdk 1.0.39 → 1.0.40-fix-history
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/api/sentio.js +1 -1
- package/dist/src/user/history.d.ts +4 -3
- package/dist/src/user/history.js +146 -51
- package/package.json +2 -2
package/dist/src/api/sentio.js
CHANGED
|
@@ -41,7 +41,7 @@ exports.getTlpAPRFromSentio = getTlpAPRFromSentio;
|
|
|
41
41
|
exports.getVolumeFromSentio = getVolumeFromSentio;
|
|
42
42
|
var src_1 = require("../../src");
|
|
43
43
|
var headers = {
|
|
44
|
-
"api-key": "
|
|
44
|
+
"api-key": "ffJa6FwxeJNrQP8NZ5doEMXqdSA7XM6mT",
|
|
45
45
|
"Content-Type": "application/json",
|
|
46
46
|
};
|
|
47
47
|
function getFromSentio(event, userAddress, startTimestamp) {
|
|
@@ -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 Close Position
|
|
2
|
+
export type actionType = "Place Order" | "Cancel Order" | "Order Filled (Open Position)" | "Order Filled (Close Position)" | "Realized PnL" | "Modify Collateral" | "Exercise Position" | "Liquidation" | "Force Close Position" | "Swap";
|
|
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";
|
|
@@ -23,5 +23,6 @@ export interface Event {
|
|
|
23
23
|
}
|
|
24
24
|
export declare function parseUserHistory(raw_events: any): Promise<Event[]>;
|
|
25
25
|
export declare function getGraphQLEvents(module: string, sender: string, beforeCursor?: string | null): Promise<any>;
|
|
26
|
-
export declare function getLiquidateFromSentio(userAddress: string, startTimestamp: number): Promise<Event[]>;
|
|
27
|
-
export declare function getOrderMatchFromSentio(userAddress: string, startTimestamp: number): Promise<Event[]>;
|
|
26
|
+
export declare function getLiquidateFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
27
|
+
export declare function getOrderMatchFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
28
|
+
export declare function getRealizeOptionFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
package/dist/src/user/history.js
CHANGED
|
@@ -67,6 +67,7 @@ exports.parseUserHistory = parseUserHistory;
|
|
|
67
67
|
exports.getGraphQLEvents = getGraphQLEvents;
|
|
68
68
|
exports.getLiquidateFromSentio = getLiquidateFromSentio;
|
|
69
69
|
exports.getOrderMatchFromSentio = getOrderMatchFromSentio;
|
|
70
|
+
exports.getRealizeOptionFromSentio = getRealizeOptionFromSentio;
|
|
70
71
|
var constants_1 = require("@typus/typus-sdk/dist/src/constants");
|
|
71
72
|
var structs_1 = require("../typus_perp/position/structs");
|
|
72
73
|
var structs_2 = require("../typus_perp/trading/structs");
|
|
@@ -158,7 +159,7 @@ function parseUserHistory(raw_events) {
|
|
|
158
159
|
var realized_trading_fee = Number(json.realized_trading_fee) + Number(json.realized_borrow_fee);
|
|
159
160
|
var realized_fee_in_usd = Number(json.realized_fee_in_usd) / Math.pow(10, 9);
|
|
160
161
|
var realized_amount = json.realized_amount_sign ? Number(json.realized_amount) : -Number(json.realized_amount);
|
|
161
|
-
var realized_pnl = ((realized_amount - realized_trading_fee) * realized_fee_in_usd) / realized_trading_fee;
|
|
162
|
+
var realized_pnl = realized_trading_fee > 0 ? ((realized_amount - realized_trading_fee) * realized_fee_in_usd) / realized_trading_fee : 0;
|
|
162
163
|
var e = {
|
|
163
164
|
action: action,
|
|
164
165
|
typeName: name,
|
|
@@ -311,74 +312,168 @@ function getGraphQLEvents(module_1, sender_1) {
|
|
|
311
312
|
});
|
|
312
313
|
});
|
|
313
314
|
}
|
|
314
|
-
function getLiquidateFromSentio(userAddress, startTimestamp) {
|
|
315
|
+
function getLiquidateFromSentio(userAddress, startTimestamp, events) {
|
|
315
316
|
return __awaiter(this, void 0, void 0, function () {
|
|
316
|
-
var datas;
|
|
317
|
+
var datas, liquidate;
|
|
317
318
|
return __generator(this, function (_a) {
|
|
318
319
|
switch (_a.label) {
|
|
319
320
|
case 0: return [4 /*yield*/, (0, sentio_1.getFromSentio)("Liquidate", userAddress, startTimestamp.toString())];
|
|
320
321
|
case 1:
|
|
321
322
|
datas = _a.sent();
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
323
|
+
liquidate = datas.map(function (x) {
|
|
324
|
+
var collateral = Number(x.liquidator_fee) + Number(x.value_for_lp_pool);
|
|
325
|
+
var base_token = toToken(x.trading_token);
|
|
326
|
+
var txHistory = {
|
|
327
|
+
action: "Liquidation",
|
|
328
|
+
typeName: "LiquidateEvent",
|
|
329
|
+
order_id: x.order_id,
|
|
330
|
+
position_id: x.position_id,
|
|
331
|
+
market: "".concat(base_token, "/USD"),
|
|
332
|
+
side: undefined,
|
|
333
|
+
order_type: "Market",
|
|
334
|
+
status: "Filled",
|
|
335
|
+
size: undefined,
|
|
336
|
+
base_token: base_token,
|
|
337
|
+
collateral: collateral,
|
|
338
|
+
collateral_token: x.collateral_token,
|
|
339
|
+
price: x.trading_price,
|
|
340
|
+
realized_pnl: -collateral * Number(x.collateral_price),
|
|
341
|
+
timestamp: x.timestamp,
|
|
342
|
+
tx_digest: x.transaction_hash,
|
|
343
|
+
};
|
|
344
|
+
return txHistory;
|
|
345
|
+
});
|
|
346
|
+
liquidate = liquidate.map(function (x) {
|
|
347
|
+
var related = events.findLast(function (e) { return e.position_id == x.position_id && e.market == x.market; });
|
|
348
|
+
// console.log(x);
|
|
349
|
+
// console.log(related);
|
|
350
|
+
if (related) {
|
|
351
|
+
x.side = related.side == "Long" ? "Short" : "Long";
|
|
352
|
+
x.size = related.size;
|
|
353
|
+
}
|
|
354
|
+
return x;
|
|
355
|
+
});
|
|
356
|
+
// console.log(liquidate);
|
|
357
|
+
events = events.concat(liquidate);
|
|
358
|
+
events = events.sort(function (a, b) { return Number(new Date(a.timestamp)) - Number(new Date(b.timestamp)); });
|
|
359
|
+
return [2 /*return*/, events];
|
|
345
360
|
}
|
|
346
361
|
});
|
|
347
362
|
});
|
|
348
363
|
}
|
|
349
|
-
function getOrderMatchFromSentio(userAddress, startTimestamp) {
|
|
364
|
+
function getOrderMatchFromSentio(userAddress, startTimestamp, events) {
|
|
350
365
|
return __awaiter(this, void 0, void 0, function () {
|
|
351
|
-
var datas;
|
|
366
|
+
var datas, order_match;
|
|
352
367
|
return __generator(this, function (_a) {
|
|
353
368
|
switch (_a.label) {
|
|
354
369
|
case 0: return [4 /*yield*/, (0, sentio_1.getFromSentio)("OrderFilled", userAddress, startTimestamp.toString())];
|
|
355
370
|
case 1:
|
|
356
371
|
datas = _a.sent();
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
372
|
+
order_match = datas.map(function (x) {
|
|
373
|
+
var base_token = toToken(x.trading_token);
|
|
374
|
+
var txHistory = {
|
|
375
|
+
action: x.order_type == "Open" ? "Order Filled (Open Position)" : "Order Filled (Close Position)",
|
|
376
|
+
typeName: "OrderFilledEvent",
|
|
377
|
+
order_id: x.order_id,
|
|
378
|
+
position_id: x.position_id,
|
|
379
|
+
market: "".concat(base_token, "/USD"),
|
|
380
|
+
side: x.side,
|
|
381
|
+
order_type: undefined,
|
|
382
|
+
status: "Filled",
|
|
383
|
+
size: x.filled_size,
|
|
384
|
+
base_token: base_token,
|
|
385
|
+
collateral: undefined,
|
|
386
|
+
collateral_token: x.collateral_token,
|
|
387
|
+
price: x.filled_price,
|
|
388
|
+
realized_pnl: x.realized_pnl,
|
|
389
|
+
timestamp: x.timestamp,
|
|
390
|
+
tx_digest: x.transaction_hash,
|
|
391
|
+
};
|
|
392
|
+
return txHistory;
|
|
393
|
+
});
|
|
394
|
+
// deduplicate
|
|
395
|
+
order_match = order_match.filter(function (x) { return events.findIndex(function (y) { return y.tx_digest == x.tx_digest; }) == -1; });
|
|
396
|
+
order_match = order_match.map(function (x) {
|
|
397
|
+
var related = events.findLast(function (e) { return e.order_id == x.order_id && e.market == x.market; });
|
|
398
|
+
// console.log(x, related);
|
|
399
|
+
if (related) {
|
|
400
|
+
x.order_type = related.order_type;
|
|
401
|
+
x.collateral = related.collateral;
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
x.order_type = "Market";
|
|
405
|
+
}
|
|
406
|
+
return x;
|
|
407
|
+
});
|
|
408
|
+
// console.log(order_match);
|
|
409
|
+
events = events.concat(order_match);
|
|
410
|
+
events = events.sort(function (a, b) { return Number(new Date(a.timestamp)) - Number(new Date(b.timestamp)); });
|
|
411
|
+
return [2 /*return*/, events];
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
function getRealizeOptionFromSentio(userAddress, startTimestamp, events) {
|
|
417
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
418
|
+
var datas, exercise;
|
|
419
|
+
return __generator(this, function (_a) {
|
|
420
|
+
switch (_a.label) {
|
|
421
|
+
case 0: return [4 /*yield*/, (0, sentio_1.getFromSentio)("RealizeOption", userAddress, startTimestamp.toString())];
|
|
422
|
+
case 1:
|
|
423
|
+
datas = _a.sent();
|
|
424
|
+
exercise = datas.map(function (x) {
|
|
425
|
+
var base_token = toToken(x.base_token);
|
|
426
|
+
var txHistory = {
|
|
427
|
+
action: "Exercise Position",
|
|
428
|
+
typeName: "RealizeOptionPositionEvent",
|
|
429
|
+
order_id: undefined,
|
|
430
|
+
position_id: x.position_id,
|
|
431
|
+
market: "".concat(base_token, "/USD"),
|
|
432
|
+
side: undefined,
|
|
433
|
+
order_type: "Market",
|
|
434
|
+
status: "Filled",
|
|
435
|
+
size: undefined,
|
|
436
|
+
base_token: base_token,
|
|
437
|
+
collateral: Number(x.exercise_balance_value),
|
|
438
|
+
collateral_token: x.collateral_token,
|
|
439
|
+
price: undefined,
|
|
440
|
+
realized_pnl: Number(x.user_remaining_in_usd),
|
|
441
|
+
timestamp: x.timestamp,
|
|
442
|
+
tx_digest: x.transaction_hash,
|
|
443
|
+
};
|
|
444
|
+
// console.log(txHistory);
|
|
445
|
+
return txHistory;
|
|
446
|
+
});
|
|
447
|
+
exercise = exercise.map(function (x) {
|
|
448
|
+
var related = events.findLast(function (e) { return e.position_id == x.position_id && e.market == x.market; });
|
|
449
|
+
// console.log(x);
|
|
450
|
+
// console.log(related);
|
|
451
|
+
if (related) {
|
|
452
|
+
x.side = related.side;
|
|
453
|
+
x.size = related.size;
|
|
454
|
+
}
|
|
455
|
+
return x;
|
|
456
|
+
});
|
|
457
|
+
// console.log(exercise);
|
|
458
|
+
events = events.concat(exercise);
|
|
459
|
+
events = events.sort(function (a, b) { return Number(new Date(a.timestamp)) - Number(new Date(b.timestamp)); });
|
|
460
|
+
return [2 /*return*/, events];
|
|
380
461
|
}
|
|
381
462
|
});
|
|
382
463
|
});
|
|
383
464
|
}
|
|
384
465
|
// getOrderMatchFromSentio("0x95f26ce574fc9ace2608807648d99a4dce17f1be8964613d5b972edc82849e9e", 0);
|
|
466
|
+
// getRealizeOptionFromSentio("0x95f26ce574fc9ace2608807648d99a4dce17f1be8964613d5b972edc82849e9e", 0);
|
|
467
|
+
function toToken(name) {
|
|
468
|
+
switch (name) {
|
|
469
|
+
case "BTC":
|
|
470
|
+
case "ETH":
|
|
471
|
+
case "SOL":
|
|
472
|
+
case "APT":
|
|
473
|
+
return "w".concat(name);
|
|
474
|
+
case "WUSDC":
|
|
475
|
+
return "wUSDC";
|
|
476
|
+
default:
|
|
477
|
+
return name;
|
|
478
|
+
}
|
|
479
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typus/typus-perp-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.40-fix-history",
|
|
4
4
|
"repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
|
|
5
5
|
"author": "Typus",
|
|
6
6
|
"description": "typus perp sdk",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@typus/typus-sdk": "1.6.
|
|
9
|
+
"@typus/typus-sdk": "1.6.16"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@types/bs58": "^4.0.1",
|