@typus/typus-perp-sdk 1.1.49 → 1.1.51
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.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TOKEN } from "@typus/typus-sdk/dist/src/constants";
|
|
2
|
-
export declare function getFromSentio(event: string, userAddress: string, startTimestamp: string, cranker?: boolean): Promise<any[]>;
|
|
2
|
+
export declare function getFromSentio(event: string, userAddress: string, startTimestamp: string, endTimestamp?: string, cranker?: boolean): Promise<any[]>;
|
|
3
3
|
export declare function getRecentTradesFromSentio(base_token?: TOKEN): Promise<any[]>;
|
|
4
4
|
/**
|
|
5
5
|
* Inputs:
|
package/dist/src/api/sentio.js
CHANGED
|
@@ -17,7 +17,7 @@ const headers = {
|
|
|
17
17
|
"api-key": "hCsD8shJaUbbiNLMKBG3oKhr9PL3H5EJ5",
|
|
18
18
|
"Content-Type": "application/json",
|
|
19
19
|
};
|
|
20
|
-
async function getFromSentio(event, userAddress, startTimestamp, cranker) {
|
|
20
|
+
async function getFromSentio(event, userAddress, startTimestamp, endTimestamp, cranker) {
|
|
21
21
|
let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp/sql/execute";
|
|
22
22
|
// add cranker fileter
|
|
23
23
|
let crankerFilter = "";
|
|
@@ -29,7 +29,7 @@ async function getFromSentio(event, userAddress, startTimestamp, cranker) {
|
|
|
29
29
|
sql: `
|
|
30
30
|
SELECT *
|
|
31
31
|
FROM ${event}
|
|
32
|
-
WHERE distinct_id = '${userAddress}' AND timestamp >= ${startTimestamp} ${crankerFilter}
|
|
32
|
+
WHERE distinct_id = '${userAddress}' AND timestamp >= ${startTimestamp} ${endTimestamp ? `AND timestamp <= ${endTimestamp}` : ''} ${crankerFilter}
|
|
33
33
|
ORDER BY timestamp DESC;
|
|
34
34
|
`,
|
|
35
35
|
size: 1000,
|
|
@@ -27,10 +27,11 @@ export interface Event {
|
|
|
27
27
|
}
|
|
28
28
|
export declare function parseUserHistory(raw_events: any, matchingDatas: any): Promise<Event[]>;
|
|
29
29
|
export declare function getGraphQLEvents(module: string, sender: string | null, beforeCursor?: string | null): Promise<any>;
|
|
30
|
+
export declare function getArchivePlaceOrderEvents(userAddress: string, startTimestamp: number, endTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
30
31
|
export declare function getLiquidateFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
31
32
|
export declare function getRealizeFundingFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
32
|
-
export declare function getRemovePositionFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
33
|
+
export declare function getRemovePositionFromSentio(userAddress: string, startTimestamp: number, events: Event[], datas?: any[]): Promise<Event[]>;
|
|
33
34
|
export declare function getCancelOrderFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
34
|
-
export declare function getOrderMatchFromSentio(userAddress: string, startTimestamp: number, events: Event[], datas?: any[]): Promise<Event[]>;
|
|
35
|
+
export declare function getOrderMatchFromSentio(userAddress: string, startTimestamp: number, events: Event[], removeEventDatas: any[], datas?: any[], archiveDatas?: Event[]): Promise<Event[]>;
|
|
35
36
|
export declare function getRealizeOptionFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
36
37
|
export declare function toSentioToken(name: TOKEN): string;
|
package/dist/src/user/history.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.parseUserHistory = parseUserHistory;
|
|
7
7
|
exports.getGraphQLEvents = getGraphQLEvents;
|
|
8
|
+
exports.getArchivePlaceOrderEvents = getArchivePlaceOrderEvents;
|
|
8
9
|
exports.getLiquidateFromSentio = getLiquidateFromSentio;
|
|
9
10
|
exports.getRealizeFundingFromSentio = getRealizeFundingFromSentio;
|
|
10
11
|
exports.getRemovePositionFromSentio = getRemovePositionFromSentio;
|
|
@@ -424,6 +425,34 @@ async function getGraphQLEvents(module, sender, beforeCursor = null) {
|
|
|
424
425
|
return data.data.events;
|
|
425
426
|
}
|
|
426
427
|
}
|
|
428
|
+
async function getArchivePlaceOrderEvents(userAddress, startTimestamp, endTimestamp, events) {
|
|
429
|
+
const datas = await (0, sentio_1.getFromSentio)("PlaceOrder", userAddress, startTimestamp.toString(), endTimestamp.toString(), false);
|
|
430
|
+
let placeOrders = datas.map((x) => {
|
|
431
|
+
let base_token = toToken(x.base_token);
|
|
432
|
+
let txHistory = {
|
|
433
|
+
action: "Place Order",
|
|
434
|
+
typeName: "PlaceOrderEvent",
|
|
435
|
+
order_id: x.order_id,
|
|
436
|
+
position_id: x.position_id,
|
|
437
|
+
market: `${base_token}/USD`,
|
|
438
|
+
side: undefined,
|
|
439
|
+
order_type: x.order_type,
|
|
440
|
+
status: x.status,
|
|
441
|
+
size: Number(x.position_size),
|
|
442
|
+
base_token,
|
|
443
|
+
collateral: x.collateral,
|
|
444
|
+
collateral_token: x.collateral_token,
|
|
445
|
+
price: Number(x.trading_price),
|
|
446
|
+
realized_pnl: undefined,
|
|
447
|
+
timestamp: x.timestamp,
|
|
448
|
+
tx_digest: x.transaction_hash,
|
|
449
|
+
dov_index: undefined,
|
|
450
|
+
sender: "user",
|
|
451
|
+
};
|
|
452
|
+
return txHistory;
|
|
453
|
+
});
|
|
454
|
+
return placeOrders;
|
|
455
|
+
}
|
|
427
456
|
async function getLiquidateFromSentio(userAddress, startTimestamp, events) {
|
|
428
457
|
const datas = await (0, sentio_1.getFromSentio)("Liquidate", userAddress, startTimestamp.toString());
|
|
429
458
|
// console.log(datas);
|
|
@@ -524,8 +553,9 @@ async function getRealizeFundingFromSentio(userAddress, startTimestamp, events)
|
|
|
524
553
|
events = events.sort((a, b) => Number(new Date(a.timestamp)) - Number(new Date(b.timestamp)));
|
|
525
554
|
return events;
|
|
526
555
|
}
|
|
527
|
-
async function getRemovePositionFromSentio(userAddress, startTimestamp, events) {
|
|
528
|
-
|
|
556
|
+
async function getRemovePositionFromSentio(userAddress, startTimestamp, events, datas) {
|
|
557
|
+
if (!datas)
|
|
558
|
+
datas = await (0, sentio_1.getFromSentio)("RemovePosition", userAddress, startTimestamp.toString());
|
|
529
559
|
// console.log(datas);
|
|
530
560
|
datas.forEach((x) => {
|
|
531
561
|
// console.log(x);
|
|
@@ -544,7 +574,7 @@ async function getRemovePositionFromSentio(userAddress, startTimestamp, events)
|
|
|
544
574
|
return events;
|
|
545
575
|
}
|
|
546
576
|
async function getCancelOrderFromSentio(userAddress, startTimestamp, events) {
|
|
547
|
-
const datas = await (0, sentio_1.getFromSentio)("CancelOrder", userAddress, startTimestamp.toString(), true);
|
|
577
|
+
const datas = await (0, sentio_1.getFromSentio)("CancelOrder", userAddress, startTimestamp.toString(), undefined, true);
|
|
548
578
|
// console.log(datas);
|
|
549
579
|
let cancelOrder = datas.map((x) => {
|
|
550
580
|
let collateral = Number(x.released_collateral_amount);
|
|
@@ -590,9 +620,9 @@ async function getCancelOrderFromSentio(userAddress, startTimestamp, events) {
|
|
|
590
620
|
events = events.sort((a, b) => Number(new Date(a.timestamp)) - Number(new Date(b.timestamp)));
|
|
591
621
|
return events;
|
|
592
622
|
}
|
|
593
|
-
async function getOrderMatchFromSentio(userAddress, startTimestamp, events, datas) {
|
|
623
|
+
async function getOrderMatchFromSentio(userAddress, startTimestamp, events, removeEventDatas, datas, archiveDatas) {
|
|
594
624
|
if (!datas)
|
|
595
|
-
datas = await (0, sentio_1.getFromSentio)("OrderFilled", userAddress, startTimestamp.toString(), true);
|
|
625
|
+
datas = await (0, sentio_1.getFromSentio)("OrderFilled", userAddress, startTimestamp.toString(), undefined, true);
|
|
596
626
|
let order_match = datas.map((x) => {
|
|
597
627
|
let base_token = toToken(x.base_token);
|
|
598
628
|
let txHistory = {
|
|
@@ -626,14 +656,25 @@ async function getOrderMatchFromSentio(userAddress, startTimestamp, events, data
|
|
|
626
656
|
order_match = order_match.map((x) => {
|
|
627
657
|
// find related order
|
|
628
658
|
let related = events.findLast((e) => e.order_id == x.order_id && e.market == x.market);
|
|
629
|
-
// console.log(x, related);
|
|
630
659
|
if (related) {
|
|
631
660
|
x.order_type = related.order_type;
|
|
632
661
|
if (related?.position_id !== null) {
|
|
633
662
|
const origin_order_filled_event = order_match.findLast(e => e.market == x.market && e.position_id == related?.position_id);
|
|
634
663
|
if (origin_order_filled_event) {
|
|
635
|
-
|
|
636
|
-
|
|
664
|
+
let origin_order_place_event = events.findLast((e) => e.order_id == origin_order_filled_event?.order_id && e.market == origin_order_filled_event.market);
|
|
665
|
+
if (!origin_order_place_event && archiveDatas) {
|
|
666
|
+
origin_order_place_event = archiveDatas.findLast((e) => e.order_id == origin_order_filled_event?.order_id && e.base_token == origin_order_filled_event.base_token);
|
|
667
|
+
}
|
|
668
|
+
const related_collateral = origin_order_place_event?.collateral ?? 0;
|
|
669
|
+
const isPartialClose = removeEventDatas.findIndex(r => r.transaction_hash === x.tx_digest);
|
|
670
|
+
if (isPartialClose !== -1) {
|
|
671
|
+
x.collateral = (0, bignumber_js_1.default)(x.collateral ?? 0).plus(related_collateral).toNumber();
|
|
672
|
+
}
|
|
673
|
+
else if (x.collateral) {
|
|
674
|
+
if (x.collateral < 0) {
|
|
675
|
+
x.collateral = undefined;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
637
678
|
}
|
|
638
679
|
}
|
|
639
680
|
x.dov_index = related.dov_index;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typus/typus-perp-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.51",
|
|
4
4
|
"repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
|
|
5
5
|
"author": "Typus",
|
|
6
6
|
"description": "typus perp sdk",
|
|
@@ -45,4 +45,4 @@
|
|
|
45
45
|
},
|
|
46
46
|
"homepage": "https://github.com/Typus-Lab/typus-perp-sdk#readme",
|
|
47
47
|
"packageManager": "yarn@4.10.3+sha512.c38cafb5c7bb273f3926d04e55e1d8c9dfa7d9c3ea1f36a4868fa028b9e5f72298f0b7f401ad5eb921749eb012eb1c3bb74bf7503df3ee43fd600d14a018266f"
|
|
48
|
-
}
|
|
48
|
+
}
|