@typus/typus-perp-sdk 1.0.76 → 1.0.78
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,4 +1,6 @@
|
|
|
1
|
+
import { TOKEN } from "@typus/typus-sdk/dist/src/constants";
|
|
1
2
|
export declare function getFromSentio(event: string, userAddress: string, startTimestamp: string): Promise<any[]>;
|
|
3
|
+
export declare function getRecentTradesFromSentio(base_token?: TOKEN): Promise<any[]>;
|
|
2
4
|
/**
|
|
3
5
|
* Inputs:
|
|
4
6
|
* day: number (at least 1)
|
package/dist/src/api/sentio.js
CHANGED
|
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.getFromSentio = getFromSentio;
|
|
40
|
+
exports.getRecentTradesFromSentio = getRecentTradesFromSentio;
|
|
40
41
|
exports.getTradingVolumeFromSentio = getTradingVolumeFromSentio;
|
|
41
42
|
exports.getTlpFeeFromSentio = getTlpFeeFromSentio;
|
|
42
43
|
exports.getTotalVolumeFromSentio = getTotalVolumeFromSentio;
|
|
@@ -53,9 +54,7 @@ function getFromSentio(event, userAddress, startTimestamp) {
|
|
|
53
54
|
return __generator(this, function (_a) {
|
|
54
55
|
switch (_a.label) {
|
|
55
56
|
case 0:
|
|
56
|
-
apiUrl =
|
|
57
|
-
? "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute"
|
|
58
|
-
: "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp/sql/execute";
|
|
57
|
+
apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
|
|
59
58
|
requestData = {
|
|
60
59
|
sqlQuery: {
|
|
61
60
|
sql: "\n SELECT *\n FROM ".concat(event, "\n WHERE distinct_id = '").concat(userAddress, "' AND timestamp >= ").concat(startTimestamp, "\n ORDER BY timestamp DESC;\n "),
|
|
@@ -85,6 +84,46 @@ function getFromSentio(event, userAddress, startTimestamp) {
|
|
|
85
84
|
});
|
|
86
85
|
});
|
|
87
86
|
}
|
|
87
|
+
function getRecentTradesFromSentio(base_token) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
+
var apiUrl, tokenFilter, requestData, jsonData, response, data;
|
|
90
|
+
return __generator(this, function (_a) {
|
|
91
|
+
switch (_a.label) {
|
|
92
|
+
case 0:
|
|
93
|
+
apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
|
|
94
|
+
tokenFilter = "";
|
|
95
|
+
if (base_token) {
|
|
96
|
+
tokenFilter = "WHERE base_token = '".concat((0, src_1.toSentioToken)(base_token), "'");
|
|
97
|
+
}
|
|
98
|
+
requestData = {
|
|
99
|
+
sqlQuery: {
|
|
100
|
+
sql: "\n SELECT\n timestamp,\n base_token,\n collateral_token,\n order_type,\n side,\n status,\n distinct_id,\n price,\n size,\n size_usd,\n realized_fee,\n realized_fee_in_usd,\n realized_pnl\n FROM PlaceOrder\n LEFT JOIN OrderFilled ON OrderFilled.transaction_hash == PlaceOrder.transaction_hash AND OrderFilled.position_id == PlaceOrder.position_id\n ".concat(tokenFilter, "\n ORDER BY timestamp DESC;\n "),
|
|
101
|
+
size: 100,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
jsonData = JSON.stringify(requestData);
|
|
105
|
+
return [4 /*yield*/, fetch(apiUrl, {
|
|
106
|
+
method: "POST",
|
|
107
|
+
headers: headers,
|
|
108
|
+
body: jsonData,
|
|
109
|
+
})];
|
|
110
|
+
case 1:
|
|
111
|
+
response = _a.sent();
|
|
112
|
+
return [4 /*yield*/, response.json()];
|
|
113
|
+
case 2:
|
|
114
|
+
data = _a.sent();
|
|
115
|
+
// console.log(data);
|
|
116
|
+
if (data.result) {
|
|
117
|
+
return [2 /*return*/, data.result.rows];
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
return [2 /*return*/, []];
|
|
121
|
+
}
|
|
122
|
+
return [2 /*return*/];
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
88
127
|
/**
|
|
89
128
|
* Inputs:
|
|
90
129
|
* day: number (at least 1)
|
|
@@ -401,7 +440,7 @@ function getTlpPriceFromSentio(fromTimestamp, toTimestamp) {
|
|
|
401
440
|
});
|
|
402
441
|
});
|
|
403
442
|
}
|
|
404
|
-
//
|
|
443
|
+
// getRecentTradesFromSentio().then((x) => console.log(x));
|
|
405
444
|
// getAccumulatedUser().then((x) => console.log(x));
|
|
406
445
|
// getTradingVolumeFromSentio(1747008000, 1, 1747011600);
|
|
407
446
|
// getTlpPriceFromSentio(0).then((x) => console.dir(x, { depth: null }));
|
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" ? "
|
|
39
|
+
exports.PERP_PUBLISHED_AT = exports.NETWORK == "MAINNET" ? "0xb52138bfce4e79d0d25c69b1d9dfe6ec81a821ed3ef03cdb1c077cb4ac9c9b9d" : "@typus/perp";
|
|
40
40
|
exports.PERP_PKG_V1 = exports.NETWORK == "MAINNET"
|
|
41
41
|
? "0xe27969a70f93034de9ce16e6ad661b480324574e68d15a64b513fd90eb2423e5"
|
|
42
42
|
: "0x585924f160f83ef16f8927ec117e4d740abb6f4e571ecfa89ff3e973042cb1b9";
|
|
@@ -24,7 +24,8 @@ export interface Event {
|
|
|
24
24
|
sender: "user" | "cranker";
|
|
25
25
|
}
|
|
26
26
|
export declare function parseUserHistory(raw_events: any): Promise<Event[]>;
|
|
27
|
-
export declare function getGraphQLEvents(module: string, sender: string, beforeCursor?: string | null): Promise<any>;
|
|
27
|
+
export declare function getGraphQLEvents(module: string, sender: string | null, beforeCursor?: string | null): Promise<any>;
|
|
28
28
|
export declare function getLiquidateFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
29
29
|
export declare function getOrderMatchFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
30
30
|
export declare function getRealizeOptionFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
31
|
+
export declare function toSentioToken(name: TOKEN): string;
|
package/dist/src/user/history.js
CHANGED
|
@@ -68,6 +68,7 @@ exports.getGraphQLEvents = getGraphQLEvents;
|
|
|
68
68
|
exports.getLiquidateFromSentio = getLiquidateFromSentio;
|
|
69
69
|
exports.getOrderMatchFromSentio = getOrderMatchFromSentio;
|
|
70
70
|
exports.getRealizeOptionFromSentio = getRealizeOptionFromSentio;
|
|
71
|
+
exports.toSentioToken = toSentioToken;
|
|
71
72
|
var constants_1 = require("@typus/typus-sdk/dist/src/constants");
|
|
72
73
|
var structs_1 = require("../typus_perp/position/structs");
|
|
73
74
|
var structs_2 = require("../typus_perp/trading/structs");
|
|
@@ -299,7 +300,7 @@ function parseUserHistory(raw_events) {
|
|
|
299
300
|
}
|
|
300
301
|
function getGraphQLEvents(module_1, sender_1) {
|
|
301
302
|
return __awaiter(this, arguments, void 0, function (module, sender, beforeCursor) {
|
|
302
|
-
var before, graphql, response, data;
|
|
303
|
+
var before, senderFilter, graphql, response, data;
|
|
303
304
|
if (beforeCursor === void 0) { beforeCursor = null; }
|
|
304
305
|
return __generator(this, function (_a) {
|
|
305
306
|
switch (_a.label) {
|
|
@@ -308,8 +309,12 @@ function getGraphQLEvents(module_1, sender_1) {
|
|
|
308
309
|
if (beforeCursor) {
|
|
309
310
|
before = "before: \"".concat(beforeCursor, "\",");
|
|
310
311
|
}
|
|
312
|
+
senderFilter = "";
|
|
313
|
+
if (sender) {
|
|
314
|
+
senderFilter = "sender: \"".concat(sender, "\"");
|
|
315
|
+
}
|
|
311
316
|
graphql = JSON.stringify({
|
|
312
|
-
query: "\n {\n events(\n last: 50,\n ".concat(before, "\n filter: {\n eventType: \"").concat(module, "\",\n
|
|
317
|
+
query: "\n {\n events(\n last: 50,\n ".concat(before, "\n filter: {\n eventType: \"").concat(module, "\",\n ").concat(senderFilter, "\n }\n ) {\n pageInfo {\n hasPreviousPage\n hasNextPage\n startCursor\n endCursor\n }\n edges { cursor }\n nodes {\n transactionBlock { digest }\n sendingModule {\n name\n package { digest }\n }\n sender { address }\n timestamp\n contents {\n type { repr }\n json\n }\n }\n }}\n "),
|
|
313
318
|
});
|
|
314
319
|
return [4 /*yield*/, fetch("https://sui-".concat(src_1.NETWORK.toLowerCase(), ".mystenlabs.com/graphql"), {
|
|
315
320
|
method: "POST",
|
|
@@ -499,6 +504,19 @@ function getRealizeOptionFromSentio(userAddress, startTimestamp, events) {
|
|
|
499
504
|
});
|
|
500
505
|
});
|
|
501
506
|
}
|
|
507
|
+
// export function toRecentTrades(events: Event[]): Event[] {
|
|
508
|
+
// let trades: Event[] = [];
|
|
509
|
+
// for (let event of events) {
|
|
510
|
+
// if (event.action == "Place Order") {
|
|
511
|
+
// trades.push(event);
|
|
512
|
+
// } else if (event.action == "Order Filled (Close Position)") {
|
|
513
|
+
// if (trades[trades.length - 1].tx_digest == event.tx_digest) {
|
|
514
|
+
// trades[trades.length - 1].realized_pnl = event.realized_pnl;
|
|
515
|
+
// }
|
|
516
|
+
// }
|
|
517
|
+
// }
|
|
518
|
+
// return trades;
|
|
519
|
+
// }
|
|
502
520
|
// getOrderMatchFromSentio("0x95f26ce574fc9ace2608807648d99a4dce17f1be8964613d5b972edc82849e9e", 0);
|
|
503
521
|
// getRealizeOptionFromSentio("0x95f26ce574fc9ace2608807648d99a4dce17f1be8964613d5b972edc82849e9e", 0);
|
|
504
522
|
function toToken(name) {
|
|
@@ -514,3 +532,19 @@ function toToken(name) {
|
|
|
514
532
|
return name;
|
|
515
533
|
}
|
|
516
534
|
}
|
|
535
|
+
function toSentioToken(name) {
|
|
536
|
+
switch (name) {
|
|
537
|
+
case "WBTC":
|
|
538
|
+
return "BTC";
|
|
539
|
+
case "wETH":
|
|
540
|
+
return "ETH";
|
|
541
|
+
case "wSOL":
|
|
542
|
+
return "SOL";
|
|
543
|
+
case "wAPT":
|
|
544
|
+
return "APT";
|
|
545
|
+
case "wUSDC":
|
|
546
|
+
return "USDC";
|
|
547
|
+
default:
|
|
548
|
+
return name;
|
|
549
|
+
}
|
|
550
|
+
}
|
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.78",
|
|
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.7.
|
|
9
|
+
"@typus/typus-sdk": "1.7.10"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@types/bs58": "^4.0.1",
|