@typus/typus-sdk 1.0.64 → 1.0.66
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,16 +1,19 @@
|
|
|
1
1
|
import { PortfolioVault } from "./portfolio-vault";
|
|
2
|
-
export declare function getDb(
|
|
3
|
-
export declare function getShowMap(
|
|
2
|
+
export declare function getDb(database: string, functionNames: string[], vaultIndex: string | undefined, startTsMs: string, limit: number): Promise<any>;
|
|
3
|
+
export declare function getShowMap(database: string, portfolioVaults: Map<string, PortfolioVault>, vaultIndex?: string | undefined, startTsMs?: string, limit?: number): Promise<Map<string, Map<string, Show>>>;
|
|
4
4
|
interface Show {
|
|
5
5
|
ProjectedAPY: number;
|
|
6
6
|
ActivationDate: Date;
|
|
7
7
|
SettlementTime: Date;
|
|
8
|
-
StrikePrice: number[];
|
|
8
|
+
StrikePrice: number[] | undefined;
|
|
9
9
|
SettlePrice: number;
|
|
10
10
|
Return: number;
|
|
11
11
|
Filled: number;
|
|
12
12
|
PaidToDepositors: number;
|
|
13
|
-
PaidToBidders:
|
|
14
|
-
EarnedByDepositors:
|
|
13
|
+
PaidToBidders: number;
|
|
14
|
+
EarnedByDepositors: number;
|
|
15
|
+
NewAuctionTx: string | undefined;
|
|
16
|
+
DeliveryTx: string | undefined;
|
|
17
|
+
SettleTx: string | undefined;
|
|
15
18
|
}
|
|
16
19
|
export {};
|
|
@@ -37,14 +37,20 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.getShowMap = exports.getDb = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
var apiUrl = "https://us-central1-aqueous-freedom-378103.cloudfunctions.net/mongodb";
|
|
41
|
+
function getDb(database, functionNames, vaultIndex, startTsMs, limit) {
|
|
42
42
|
return __awaiter(this, void 0, void 0, function () {
|
|
43
43
|
var jsonData, response, data;
|
|
44
44
|
return __generator(this, function (_a) {
|
|
45
45
|
switch (_a.label) {
|
|
46
46
|
case 0:
|
|
47
|
-
jsonData = JSON.stringify({
|
|
47
|
+
jsonData = JSON.stringify({
|
|
48
|
+
database: database,
|
|
49
|
+
functionNames: functionNames,
|
|
50
|
+
vaultIndex: vaultIndex,
|
|
51
|
+
startTsMs: startTsMs,
|
|
52
|
+
limit: limit,
|
|
53
|
+
});
|
|
48
54
|
return [4 /*yield*/, fetch(apiUrl, {
|
|
49
55
|
method: "POST",
|
|
50
56
|
headers: { "Content-Type": "application/json" },
|
|
@@ -63,14 +69,16 @@ function getDb(apiUrl, functionNames, vaultIndex) {
|
|
|
63
69
|
});
|
|
64
70
|
}
|
|
65
71
|
exports.getDb = getDb;
|
|
66
|
-
function getShowMap(
|
|
72
|
+
function getShowMap(database, portfolioVaults, vaultIndex, startTsMs, limit) {
|
|
67
73
|
if (vaultIndex === void 0) { vaultIndex = undefined; }
|
|
74
|
+
if (startTsMs === void 0) { startTsMs = "0"; }
|
|
75
|
+
if (limit === void 0) { limit = 1000; }
|
|
68
76
|
return __awaiter(this, void 0, void 0, function () {
|
|
69
77
|
var events, groupEventMap, showMap;
|
|
70
78
|
var _this = this;
|
|
71
79
|
return __generator(this, function (_a) {
|
|
72
80
|
switch (_a.label) {
|
|
73
|
-
case 0: return [4 /*yield*/, getDb(
|
|
81
|
+
case 0: return [4 /*yield*/, getDb(database, ["NewAuction", "Delivery", "Settle"], vaultIndex, startTsMs, limit)];
|
|
74
82
|
case 1:
|
|
75
83
|
events = _a.sent();
|
|
76
84
|
return [4 /*yield*/, events.reduce(function (promise, event) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -146,15 +154,12 @@ function getShowMap(apiUrl, portfolioVaults, vaultIndex) {
|
|
|
146
154
|
var show;
|
|
147
155
|
return __generator(this, function (_a) {
|
|
148
156
|
switch (_a.label) {
|
|
149
|
-
case 0:
|
|
150
|
-
if (!(groupEvent.settleEvent && groupEvent.newAuctionEvent)) return [3 /*break*/, 2];
|
|
151
|
-
return [4 /*yield*/, groupEventToShow(groupEvent, portfolioVaults[outerKey])];
|
|
157
|
+
case 0: return [4 /*yield*/, groupEventToShow(groupEvent, portfolioVaults[outerKey])];
|
|
152
158
|
case 1:
|
|
153
159
|
show = _a.sent();
|
|
154
160
|
// console.log(show);
|
|
155
161
|
newInnerMap_1.set(innerKey, show);
|
|
156
|
-
|
|
157
|
-
case 2: return [2 /*return*/];
|
|
162
|
+
return [2 /*return*/];
|
|
158
163
|
}
|
|
159
164
|
});
|
|
160
165
|
}); });
|
|
@@ -173,16 +178,14 @@ function getShowMap(apiUrl, portfolioVaults, vaultIndex) {
|
|
|
173
178
|
}
|
|
174
179
|
exports.getShowMap = getShowMap;
|
|
175
180
|
function groupEventToShow(groupEvent, portfolioVault) {
|
|
181
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
176
182
|
return __awaiter(this, void 0, void 0, function () {
|
|
177
|
-
var
|
|
178
|
-
return __generator(this, function (
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
portfolio_payoff = settleEvent.portfolio_payoff_is_neg
|
|
184
|
-
? Number(-settleEvent.portfolio_payoff)
|
|
185
|
-
: Number(settleEvent.portfolio_payoff);
|
|
183
|
+
var PaidToDepositors, portfolio_payoff, PaidToBidders, exp, result;
|
|
184
|
+
return __generator(this, function (_r) {
|
|
185
|
+
PaidToDepositors = Number((_a = groupEvent.deliveryEvent) === null || _a === void 0 ? void 0 : _a.premium_value) / Math.pow(10, Number(portfolioVault.config.bTokenDecimal));
|
|
186
|
+
portfolio_payoff = ((_b = groupEvent.settleEvent) === null || _b === void 0 ? void 0 : _b.portfolio_payoff_is_neg)
|
|
187
|
+
? Number(-((_c = groupEvent.settleEvent) === null || _c === void 0 ? void 0 : _c.portfolio_payoff))
|
|
188
|
+
: Number((_d = groupEvent.settleEvent) === null || _d === void 0 ? void 0 : _d.portfolio_payoff);
|
|
186
189
|
PaidToBidders = portfolio_payoff / Math.pow(10, Number(portfolioVault.config.oTokenDecimal));
|
|
187
190
|
switch (portfolioVault.config.period) {
|
|
188
191
|
case 0:
|
|
@@ -196,14 +199,20 @@ function groupEventToShow(groupEvent, portfolioVault) {
|
|
|
196
199
|
break;
|
|
197
200
|
}
|
|
198
201
|
result = {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
StrikePrice: newAuctionEvent.vault_config.payoffConfigs.map(function (payoffConfig) { return Number(payoffConfig.strike) / Math.pow(10, 8); }),
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
// newAuctionEvent
|
|
203
|
+
NewAuctionTx: (_e = groupEvent.newAuctionEvent) === null || _e === void 0 ? void 0 : _e.tx_digest,
|
|
204
|
+
ActivationDate: new Date(Number((_f = groupEvent.newAuctionEvent) === null || _f === void 0 ? void 0 : _f.timestamp_ms)),
|
|
205
|
+
StrikePrice: (_g = groupEvent.newAuctionEvent) === null || _g === void 0 ? void 0 : _g.vault_config.payoffConfigs.map(function (payoffConfig) { return Number(payoffConfig.strike) / Math.pow(10, 8); }),
|
|
206
|
+
// deliveryEvent
|
|
207
|
+
DeliveryTx: (_h = groupEvent.deliveryEvent) === null || _h === void 0 ? void 0 : _h.tx_digest,
|
|
208
|
+
ProjectedAPY: Math.pow((1 + (1.01 * Number((_j = groupEvent.deliveryEvent) === null || _j === void 0 ? void 0 : _j.delivery_price)) / Math.pow(10, Number(portfolioVault.config.bTokenDecimal))), exp) - 1,
|
|
209
|
+
Filled: Number((_k = groupEvent.deliveryEvent) === null || _k === void 0 ? void 0 : _k.delivery_size) / Number((_l = groupEvent.deliveryEvent) === null || _l === void 0 ? void 0 : _l.max_size),
|
|
206
210
|
PaidToDepositors: PaidToDepositors,
|
|
211
|
+
// settleEvent
|
|
212
|
+
SettleTx: (_m = groupEvent.settleEvent) === null || _m === void 0 ? void 0 : _m.tx_digest,
|
|
213
|
+
SettlementTime: new Date(Number((_o = groupEvent.settleEvent) === null || _o === void 0 ? void 0 : _o.timestamp_ms)),
|
|
214
|
+
SettlePrice: Number((_p = groupEvent.settleEvent) === null || _p === void 0 ? void 0 : _p.oracle_price) / Math.pow(10, 8),
|
|
215
|
+
Return: Number((_q = groupEvent.settleEvent) === null || _q === void 0 ? void 0 : _q.share_price) / Math.pow(10, 8) - 1,
|
|
207
216
|
PaidToBidders: PaidToBidders,
|
|
208
217
|
EarnedByDepositors: PaidToDepositors - PaidToBidders,
|
|
209
218
|
};
|