@typus/typus-sdk 1.4.79 → 1.4.80
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.
|
@@ -62,12 +62,16 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
62
62
|
}
|
|
63
63
|
return ar;
|
|
64
64
|
};
|
|
65
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
66
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
67
|
+
};
|
|
65
68
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
69
|
exports.getUserEvents = getUserEvents;
|
|
67
70
|
exports.parseTxHistory = parseTxHistory;
|
|
68
71
|
exports.getDepositorCashFlows = getDepositorCashFlows;
|
|
69
72
|
var bcs_1 = require("@mysten/bcs");
|
|
70
73
|
var constants_1 = require("../../src/constants");
|
|
74
|
+
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
71
75
|
function getUserEvents(provider, sender, cursor) {
|
|
72
76
|
return __awaiter(this, void 0, void 0, function () {
|
|
73
77
|
var senderFilter, hasNextPage, datas, result;
|
|
@@ -121,7 +125,7 @@ function parseTxHistory(datas) {
|
|
|
121
125
|
}
|
|
122
126
|
})
|
|
123
127
|
.reduce(function (promise, event) { return __awaiter(_this, void 0, void 0, function () {
|
|
124
|
-
var txHistory, log_1, action, log, reader, Token, asset, decimal;
|
|
128
|
+
var txHistory, log_1, action, log, reader, Token, asset, decimal, totalWithdrawAmount;
|
|
125
129
|
return __generator(this, function (_a) {
|
|
126
130
|
switch (_a.label) {
|
|
127
131
|
case 0: return [4 /*yield*/, promise];
|
|
@@ -195,35 +199,12 @@ function parseTxHistory(datas) {
|
|
|
195
199
|
}
|
|
196
200
|
break;
|
|
197
201
|
case "reduce_fund":
|
|
198
|
-
|
|
202
|
+
totalWithdrawAmount = (0, bignumber_js_1.default)(log[2]).plus(log[3]).plus(log[4]);
|
|
203
|
+
if (totalWithdrawAmount.gt(0)) {
|
|
199
204
|
txHistory.push({
|
|
200
205
|
Action: "Withdraw",
|
|
201
206
|
Index: log[0],
|
|
202
|
-
Amount: divByDecimal(
|
|
203
|
-
Token: Token,
|
|
204
|
-
Exp: log[5],
|
|
205
|
-
Date: new Date(Number(event.timestampMs)),
|
|
206
|
-
txDigest: event.id.txDigest,
|
|
207
|
-
log: log,
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
if (Number(log[3]) > 0) {
|
|
211
|
-
txHistory.push({
|
|
212
|
-
Action: "Unsubscribe",
|
|
213
|
-
Index: log[0],
|
|
214
|
-
Amount: divByDecimal(Number(log[3]), decimal),
|
|
215
|
-
Token: Token,
|
|
216
|
-
Exp: log[5],
|
|
217
|
-
Date: new Date(Number(event.timestampMs)),
|
|
218
|
-
txDigest: event.id.txDigest,
|
|
219
|
-
log: log,
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
if (Number(log[4]) > 0) {
|
|
223
|
-
txHistory.push({
|
|
224
|
-
Action: "Claim",
|
|
225
|
-
Index: log[0],
|
|
226
|
-
Amount: divByDecimal(Number(log[4]), decimal),
|
|
207
|
+
Amount: divByDecimal(totalWithdrawAmount.toNumber(), decimal),
|
|
227
208
|
Token: Token,
|
|
228
209
|
Exp: log[5],
|
|
229
210
|
Date: new Date(Number(event.timestampMs)),
|
|
@@ -51,7 +51,7 @@ function getVaultHistorySummary() {
|
|
|
51
51
|
apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_v2/sql/execute";
|
|
52
52
|
requestData = {
|
|
53
53
|
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
|
|
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 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 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 ",
|
|
55
55
|
size: 1000,
|
|
56
56
|
},
|
|
57
57
|
};
|
|
@@ -67,7 +67,7 @@ function getVaultHistorySummary() {
|
|
|
67
67
|
case 2:
|
|
68
68
|
data = _a.sent();
|
|
69
69
|
result = data.result.rows;
|
|
70
|
-
console.log(
|
|
70
|
+
// console.log(result);
|
|
71
71
|
return [2 /*return*/, result];
|
|
72
72
|
}
|
|
73
73
|
});
|
|
@@ -83,7 +83,7 @@ function getVaultHistory(index_1) {
|
|
|
83
83
|
apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_v2/sql/execute";
|
|
84
84
|
requestData = {
|
|
85
85
|
sqlQuery: {
|
|
86
|
-
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
|
|
86
|
+
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 token.prices\n GROUP BY\n symbol, hour\n )\n\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 Activate.deposit_balance 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 (Settle.settle_balance - Settle.settled_balance) 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 LOWER(Settle.d_token) = hourly_price_table.symbol AND toStartOfHour(Settle.timestamp) = hourly_price_table.hour\n LEFT JOIN hourly_price_table ON 'sui' = hourly_price_table.symbol AND toStartOfHour(Settle.timestamp) = hourly_price_table.hour\n WHERE Settle.index = ".concat(index, "\n ORDER BY ActivationDate DESC;\n "),
|
|
87
87
|
size: limit,
|
|
88
88
|
},
|
|
89
89
|
};
|
|
@@ -99,11 +99,11 @@ function getVaultHistory(index_1) {
|
|
|
99
99
|
case 2:
|
|
100
100
|
data = _a.sent();
|
|
101
101
|
result = data.result.rows;
|
|
102
|
-
console.log(result);
|
|
102
|
+
// console.log(result);
|
|
103
103
|
return [2 /*return*/, result];
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
// getVaultHistorySummary();
|
|
109
|
-
// getVaultHistory("
|
|
109
|
+
// getVaultHistory("78", 3);
|