@typus/typus-sdk 1.5.9 → 1.6.1
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export declare function getVaultHistorySummary(): Promise<VaultHistorySummary[]>;
|
|
1
|
+
export declare function getVaultHistorySummary(startTimestamp?: number): Promise<VaultHistorySummary[]>;
|
|
2
|
+
export declare function getFilledSummary(startTimestamp?: number): Promise<VaultHistorySummary[]>;
|
|
2
3
|
interface VaultHistorySummary {
|
|
3
4
|
AverageDrawdown: number;
|
|
4
5
|
AverageFilled: number;
|
|
@@ -37,21 +37,65 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.getVaultHistorySummary = getVaultHistorySummary;
|
|
40
|
+
exports.getFilledSummary = getFilledSummary;
|
|
40
41
|
exports.getVaultHistory = getVaultHistory;
|
|
41
42
|
var headers = {
|
|
42
43
|
"api-key": "tz3JJ6stG7Fux6ueRSRA5mdpC9U0lozI3",
|
|
43
44
|
"Content-Type": "application/json",
|
|
44
45
|
};
|
|
45
|
-
function getVaultHistorySummary() {
|
|
46
|
+
function getVaultHistorySummary(startTimestamp) {
|
|
46
47
|
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var apiUrl, requestData, jsonData, response, data, result;
|
|
48
|
+
var apiUrl, timeFilter, requestData, jsonData, response, data, result;
|
|
49
|
+
return __generator(this, function (_a) {
|
|
50
|
+
switch (_a.label) {
|
|
51
|
+
case 0:
|
|
52
|
+
apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_v2/sql/execute";
|
|
53
|
+
if (startTimestamp) {
|
|
54
|
+
timeFilter = "WHERE timestamp >= ".concat(startTimestamp);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
timeFilter = "";
|
|
58
|
+
}
|
|
59
|
+
requestData = {
|
|
60
|
+
sqlQuery: {
|
|
61
|
+
sql: "\n WITH hourly_price_table AS (\n SELECT\n symbol,\n toStartOfHour(time) AS hour,\n argMax(price, time) AS hourly_price\n FROM\n token.prices\n GROUP BY\n symbol, hour\n ),\n\n vault_history AS (\n SELECT\n Settle.timestamp as timestamp,\n Settle.index as Index,\n Settle.round as Round,\n NewAuction.start_ts_ms as ActivationDate,\n COALESCE(NULLIF(UpdateStrike.strikes, ''), NewAuction.strikes) AS Strikes, -- \u5982\u679C UpdateStrike.strikes \u662F\u7A7A\u5B57\u7B26\u4E32\uFF0C\u5C31\u4F7F\u7528 NewAuction.strikes\n Settle.oracle_price as SettlePrice,\n -- Settle.share_price as share_price,\n -- Settle.settle_balance as SettleBalance,\n CAST(Activate.deposit_balance as Float64) as DepositAmount,\n DepositAmount * Settle.price_d_token as DepositAmountUSD,\n Delivery.max_size as MaxSize,\n (SafuOtc.delivery_size + Delivery.delivery_size) as TotalSell,\n CASE WHEN MaxSize != 0 THEN TotalSell / MaxSize ELSE 0 END AS Filled,\n Delivery.delivery_size as DeliverySize,\n Delivery.delivery_price as DeliveryPrice,\n SafuOtc.delivery_size as OtcSize,\n SafuOtc.delivery_price as OtcPrice,\n Delivery.bidder_bid_value as BidderPremium,\n BidderPremium * Delivery.price_b_token as BidderPremiumUSD,\n Delivery.incentive_bid_value as IncentivePremium,\n SafuOtc.bidder_bid_value as OtcPremium,\n (Delivery.bidder_bid_value + Delivery.incentive_bid_value + SafuOtc.bidder_bid_value) AS Premium, -- Total Premium b_token\n Premium * Delivery.price_b_token AS PremiumUSD,\n Delivery.depositor_incentive_value as BpIncentive, -- SUI or SCA based on o_token\n BpIncentive * Delivery.price_o_token as BpIncentiveUSD,\n Delivery.fixed_incentive_amount as FixedIncentive, -- SUI\n FixedIncentive * hourly_price_table.hourly_price as FixedIncentiveUSD,\n (1 - Settle.share_price) as LossPecentage,\n CAST((Settle.settle_balance - Settle.settled_balance) AS Float64) as OptionProfit, -- d_token\n OptionProfit * Settle.price_d_token as OptionProfitUSD,\n PremiumUSD + BpIncentiveUSD + FixedIncentiveUSD - OptionProfitUSD as DepositorPNL,\n -- CASE WHEN DepositAmountUSD != 0 THEN DepositorPNL / DepositAmountUSD ELSE 0 END AS DepositorROI,\n OptionProfitUSD - BidderPremiumUSD as BidderPNL,\n CASE WHEN BidderPremiumUSD != 0 THEN BidderPNL / BidderPremiumUSD ELSE 0 END AS BidderROI,\n Settle.d_token as d_token,\n Delivery.b_token as b_token,\n Delivery.o_token as o_token\n FROM Settle\n JOIN Activate ON Settle.index = Activate.index AND Settle.round = Activate.round\n JOIN NewAuction ON Settle.index = NewAuction.index AND Settle.round = NewAuction.round\n LEFT JOIN UpdateStrike ON Settle.index = UpdateStrike.index AND Settle.round = UpdateStrike.round\n JOIN Delivery ON Settle.index = Delivery.index AND Settle.round = Delivery.round\n LEFT JOIN SafuOtc ON Settle.index = SafuOtc.index AND Settle.round = SafuOtc.round\n LEFT JOIN hourly_price_table ON 'sui' = hourly_price_table.symbol AND toStartOfHour(Settle.timestamp) = hourly_price_table.hour\n ".concat(timeFilter, "\n ORDER BY ActivationDate DESC\n )\n\n SELECT\n vault_history.Index AS Index,\n SUM(vault_history.TotalSell) AS TotalSell, -- Total Sell Size\n AVG(vault_history.Filled) AS AverageFilled, -- Average Filled Rate\n AVG(vault_history.OptionProfit) AS AverageLoss, -- Average Option Profit\n SUM(vault_history.OptionProfit) AS TotalOptionProfit, -- Total Option Profit\n AVG(CASE -- Calculating Average Drawdown, ignoring DepositAmount == 0\n WHEN vault_history.DepositAmount > 0 THEN vault_history.OptionProfit / vault_history.DepositAmount ELSE NULL\n END) AS AverageDrawdown, -- Average Drawdown (based on Option Profit and TVL)\n SUM(CASE WHEN vault_history.BidderPNL > 0 THEN 1 ELSE 0 END) / COUNT(*) AS BidderWinRate, -- Calculating Bidder Win Rate (probability BidderPNL > 0)\n SUM(CASE WHEN vault_history.DepositorPNL > 0 THEN 1 ELSE 0 END) / COUNT(*) AS DepositorWinRate -- Calculating Depositor Win Rate (probability DepositorPNL > 0)\n FROM vault_history\n GROUP BY vault_history.Index\n ORDER BY Index ASC\n "),
|
|
62
|
+
size: 1000,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
jsonData = JSON.stringify(requestData);
|
|
66
|
+
return [4 /*yield*/, fetch(apiUrl, {
|
|
67
|
+
method: "POST",
|
|
68
|
+
headers: headers,
|
|
69
|
+
body: jsonData,
|
|
70
|
+
})];
|
|
71
|
+
case 1:
|
|
72
|
+
response = _a.sent();
|
|
73
|
+
return [4 /*yield*/, response.json()];
|
|
74
|
+
case 2:
|
|
75
|
+
data = _a.sent();
|
|
76
|
+
result = data.result.rows;
|
|
77
|
+
// console.log(result);
|
|
78
|
+
return [2 /*return*/, result];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function getFilledSummary(startTimestamp) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
+
var apiUrl, timeFilter, requestData, jsonData, response, data, result;
|
|
48
86
|
return __generator(this, function (_a) {
|
|
49
87
|
switch (_a.label) {
|
|
50
88
|
case 0:
|
|
51
89
|
apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_v2/sql/execute";
|
|
90
|
+
if (startTimestamp) {
|
|
91
|
+
timeFilter = "WHERE timestamp >= ".concat(startTimestamp);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
timeFilter = "";
|
|
95
|
+
}
|
|
52
96
|
requestData = {
|
|
53
97
|
sqlQuery: {
|
|
54
|
-
sql: "\n WITH hourly_price_table AS (\n SELECT\n symbol,\n toStartOfHour(time) AS hour,\n argMax(price, time) AS hourly_price\n FROM\n
|
|
98
|
+
sql: "\n WITH hourly_price_table AS (\n SELECT\n symbol,\n toStartOfHour(time) AS hour,\n argMax(price, time) AS hourly_price -- Get the most recent price before or at the hour\n FROM\n sui.coin_prices\n GROUP BY\n symbol, hour\n ),\n\n vault_history AS (\n SELECT\n Delivery.timestamp as timestamp,\n Delivery.index as Index,\n Delivery.round as Round,\n NewAuction.start_ts_ms as ActivationDate,\n COALESCE(NULLIF(UpdateStrike.strikes, ''), NewAuction.strikes) AS Strikes, -- \u5982\u679C UpdateStrike.strikes \u662F\u7A7A\u5B57\u7B26\u4E32\uFF0C\u5C31\u4F7F\u7528 NewAuction.strikes\n Activate.deposit_balance as DepositAmount,\n Delivery.max_size as MaxSize,\n (SafuOtc.delivery_size + Delivery.delivery_size) as TotalSell,\n CASE WHEN MaxSize != 0 THEN TotalSell / MaxSize ELSE 0 END AS Filled,\n Delivery.delivery_size as DeliverySize,\n Delivery.delivery_price as DeliveryPrice,\n SafuOtc.delivery_size as OtcSize,\n SafuOtc.delivery_price as OtcPrice,\n Delivery.bidder_bid_value as BidderPremium,\n BidderPremium * Delivery.price_b_token as BidderPremiumUSD,\n Delivery.incentive_bid_value as IncentivePremium,\n SafuOtc.bidder_bid_value as OtcPremium,\n (Delivery.bidder_bid_value + Delivery.incentive_bid_value + SafuOtc.bidder_bid_value) AS Premium, -- Total Premium b_token\n Premium * Delivery.price_b_token AS PremiumUSD,\n Delivery.depositor_incentive_value as BpIncentive, -- SUI or SCA based on o_token\n BpIncentive * Delivery.price_o_token as BpIncentiveUSD,\n Delivery.fixed_incentive_amount as FixedIncentive, -- SUI\n FixedIncentive * hourly_price_table.hourly_price as FixedIncentiveUSD,\n VaultInfo.d_token as d_token,\n Delivery.b_token as b_token,\n Delivery.o_token as o_token\n FROM Delivery\n JOIN Activate ON Delivery.index = Activate.index AND Delivery.round = Activate.round\n JOIN NewAuction ON Delivery.index = NewAuction.index AND Delivery.round = NewAuction.round\n JOIN VaultInfo ON Delivery.index = CAST(VaultInfo.id AS Decimal(76, 12))\n LEFT JOIN UpdateStrike ON Delivery.index = UpdateStrike.index AND Delivery.round = UpdateStrike.round\n LEFT JOIN SafuOtc ON Delivery.index = SafuOtc.index AND Delivery.round = SafuOtc.round\n LEFT JOIN hourly_price_table ON 'sui' = hourly_price_table.symbol AND toStartOfHour(Delivery.timestamp) = hourly_price_table.hour\n ".concat(timeFilter, "\n ORDER BY ActivationDate DESC\n )\n\n SELECT\n vault_history.Index AS Index,\n SUM(vault_history.BidderPremiumUSD) * 0.2 AS FeeUSD,\n SUM(vault_history.TotalSell) AS TotalSell, -- Total Sell Size\n AVG(vault_history.Filled) AS AverageFilled -- Average Filled Rate\n FROM vault_history\n GROUP BY vault_history.Index\n ORDER BY FeeUSD DESC\n "),
|
|
55
99
|
size: 1000,
|
|
56
100
|
},
|
|
57
101
|
};
|
|
@@ -105,5 +149,8 @@ function getVaultHistory(index_1) {
|
|
|
105
149
|
});
|
|
106
150
|
});
|
|
107
151
|
}
|
|
152
|
+
// let quarterly_timestamp = Math.round(new Date().setMonth(new Date().getMonth() - 3) / 1000);
|
|
153
|
+
// console.log(quarterly_timestamp);
|
|
108
154
|
// getVaultHistorySummary();
|
|
155
|
+
// getFilledSummary(quarterly_timestamp);
|
|
109
156
|
// getVaultHistory("78", 3);
|
|
@@ -9,6 +9,7 @@ export declare const priceIDs: {
|
|
|
9
9
|
CETUS: string;
|
|
10
10
|
NAVX: string;
|
|
11
11
|
SCA: string;
|
|
12
|
+
TURBOS: string;
|
|
12
13
|
};
|
|
13
14
|
TESTNET: {
|
|
14
15
|
SUI: string;
|
|
@@ -21,6 +22,7 @@ export declare const priceIDs: {
|
|
|
21
22
|
CETUS: string;
|
|
22
23
|
NAVX: string;
|
|
23
24
|
SCA: string;
|
|
25
|
+
TURBOS: string;
|
|
24
26
|
};
|
|
25
27
|
};
|
|
26
28
|
export declare const priceInfoObjectIds: {
|
|
@@ -35,6 +37,7 @@ export declare const priceInfoObjectIds: {
|
|
|
35
37
|
CETUS: string;
|
|
36
38
|
NAVX: string;
|
|
37
39
|
SCA: string;
|
|
40
|
+
TURBOS: string;
|
|
38
41
|
};
|
|
39
42
|
};
|
|
40
43
|
export declare const wormholeStateId: {
|
|
@@ -14,6 +14,7 @@ exports.priceIDs = {
|
|
|
14
14
|
CETUS: "0xe5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef", // CETUS/USD price ID
|
|
15
15
|
NAVX: "0x88250f854c019ef4f88a5c073d52a18bb1c6ac437033f5932cd017d24917ab46", // NAVX/USD price ID
|
|
16
16
|
SCA: "0x7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc", // SCA/USD price ID
|
|
17
|
+
TURBOS: "0xf9c2e890443dd995d0baafc08eea3358be1ffb874f93f99c30b3816c460bbac3", // TURBOS/USD price ID
|
|
17
18
|
},
|
|
18
19
|
TESTNET: {
|
|
19
20
|
// Pyth EVM Beta
|
|
@@ -27,6 +28,7 @@ exports.priceIDs = {
|
|
|
27
28
|
CETUS: "0xcb324dafd531712dd31c39969ae0246ee4c6ae167257bcf8ac27e28ca35e6a0c", // CETUS/USD price ID
|
|
28
29
|
NAVX: "0x946292ad3f481f36f5e558726cf4974e2a7a34598bf15d2abe3619e7b6a8db91", // NAVX/USD price ID
|
|
29
30
|
SCA: "0xeacabc6304d11fc10a757f63286ef44415d8e91b7a1a525ae94a7ec9398b73f3", // SCA/USD price ID
|
|
31
|
+
TURBOS: "0x3f545e3f4ec9fd8eb3b9d9d6071a1da361f6729fa1b93d1d1baca3379551d99e", // TURBOS/USD price ID
|
|
30
32
|
},
|
|
31
33
|
};
|
|
32
34
|
exports.priceInfoObjectIds = {
|
|
@@ -53,6 +55,7 @@ exports.priceInfoObjectIds = {
|
|
|
53
55
|
CETUS: "0xb0ba78106259b7ceefd288edc5f65b65f8b7bca0816e61dae5136616aac7d3da",
|
|
54
56
|
NAVX: "0x94905bdcaa656b0908aa8a3a42cf72b0e8e2e849f7d0a7e0e39bb9e1dc3c9cf6",
|
|
55
57
|
SCA: "0xf96e3c4b7d74efbde9df5b669188421196e6164adf6fbaaa92903c42569807c8",
|
|
58
|
+
TURBOS: "0xfe38289883c3afed692e5856f4896b3e094d4793e2ccf0a2715b890a718fa5c0",
|
|
56
59
|
},
|
|
57
60
|
};
|
|
58
61
|
// Get the state IDs of the Pyth and Wormhole contracts from
|