@typus/typus-sdk 1.0.74 → 1.0.76

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,4 @@
1
- export declare function getDepositorLeaderBoard(start?: string, end?: string, step?: number): Promise<void>;
1
+ export declare function getDepositorLeaderBoard(start?: string, end?: string, step?: number): Promise<LeaderBoard[]>;
2
2
  export declare function getBidderLeaderBoard(startTimestamp?: string, end?: string): Promise<LeaderBoard[]>;
3
3
  interface LeaderBoard {
4
4
  user: string;
@@ -55,64 +55,74 @@ Object.defineProperty(exports, "__esModule", { value: true });
55
55
  exports.getBidderLeaderBoard = exports.getDepositorLeaderBoard = void 0;
56
56
  var apiUrl = "https://app.sentio.xyz/api/v1/insights/wayne/typus/query";
57
57
  var headers = {
58
- "api-key": "UcELWyfhQjJcb26aSc59JvAYXU3x3eBGh",
58
+ "api-key": "oBOW8DsO1izVrINCy6Tmxga9YcWeOL87O",
59
59
  "Content-Type": "application/json",
60
60
  };
61
- var requestData = {
61
+ var depositorRequestData = {
62
62
  timeRange: {
63
- start: "-30d",
63
+ start: "-7d",
64
64
  end: "now",
65
- step: 86400,
66
- timezone: "UTC",
65
+ step: 3600,
67
66
  },
68
- limit: 20,
67
+ limit: 200,
69
68
  queries: [
70
69
  {
71
70
  metricsQuery: {
72
- query: "deliverySize_USD_",
71
+ query: "depositTvl",
72
+ alias: "",
73
73
  id: "a",
74
74
  labelSelector: {},
75
75
  aggregate: {
76
76
  op: "SUM",
77
- grouping: ["coin_symbol"],
77
+ grouping: ["user", "coin_symbol"],
78
78
  },
79
- functions: [
79
+ functions: [],
80
+ disabled: true,
81
+ },
82
+ dataSource: "METRICS",
83
+ },
84
+ {
85
+ priceQuery: {
86
+ id: "b",
87
+ alias: "",
88
+ coinId: [
80
89
  {
81
- name: "sum_over_time",
82
- arguments: [
83
- {
84
- durationValue: {
85
- value: 1,
86
- unit: "d",
87
- },
88
- },
89
- ],
90
+ symbol: "SUI",
91
+ },
92
+ {
93
+ symbol: "USDC",
90
94
  },
91
95
  ],
92
- disabled: false,
96
+ disabled: true,
93
97
  },
94
- dataSource: "METRICS",
95
- sourceName: "",
98
+ dataSource: "PRICE",
99
+ },
100
+ ],
101
+ formulas: [
102
+ {
103
+ expression: "a*b",
104
+ alias: "{{user}}",
105
+ id: "A",
106
+ disabled: false,
96
107
  },
97
108
  ],
98
- formulas: [],
99
109
  };
100
110
  function getDepositorLeaderBoard(start, end, step) {
101
111
  return __awaiter(this, void 0, void 0, function () {
102
- var jsonData, response, data, samples;
112
+ var jsonData, response, data, samples, len_1, leader_board, userScoreMap, result, e_1;
103
113
  return __generator(this, function (_a) {
104
114
  switch (_a.label) {
105
115
  case 0:
106
116
  if (start) {
107
- requestData.timeRange.start = start;
117
+ depositorRequestData.timeRange.start = start;
108
118
  }
109
119
  if (end) {
110
- requestData.timeRange.end = end;
120
+ depositorRequestData.timeRange.end = end;
111
121
  }
112
122
  if (step) {
113
- requestData.timeRange.step = step;
123
+ depositorRequestData.timeRange.step = step;
114
124
  }
115
- jsonData = JSON.stringify(requestData);
125
+ jsonData = JSON.stringify(depositorRequestData);
116
126
  return [4 /*yield*/, fetch(apiUrl, {
117
127
  method: "POST",
118
128
  headers: headers,
@@ -120,12 +130,45 @@ function getDepositorLeaderBoard(start, end, step) {
120
130
  })];
121
131
  case 1:
122
132
  response = _a.sent();
123
- return [4 /*yield*/, response.json()];
133
+ _a.label = 2;
124
134
  case 2:
135
+ _a.trys.push([2, 4, , 5]);
136
+ return [4 /*yield*/, response.json()];
137
+ case 3:
125
138
  data = _a.sent();
126
139
  samples = data.results[0].matrix.samples;
127
- console.log(samples[0].values);
128
- return [2 /*return*/];
140
+ len_1 = samples.reduce(function (acc, curr) { return (acc > curr.values.length ? acc : curr.values.length); }, 0) - 1;
141
+ leader_board = samples
142
+ .map(function (element) {
143
+ // console.log("metric:", element.metric, "values: ", element.values);
144
+ // console.log("user:", element.metric.labels.user, "score: ", element.values.at(-1).value);
145
+ var sum = element.values.reduce(function (acc, curr) { return acc + curr.value / len_1; }, 0);
146
+ return {
147
+ user: element.metric.labels.user,
148
+ score: sum,
149
+ };
150
+ })
151
+ .filter(function (element) { return element.score != 0; });
152
+ userScoreMap = leader_board.reduce(function (map, obj) {
153
+ if (map[obj.user]) {
154
+ map[obj.user] += obj.score;
155
+ }
156
+ else {
157
+ map[obj.user] = obj.score;
158
+ }
159
+ return map;
160
+ }, {});
161
+ result = Object.entries(userScoreMap).map(function (_a) {
162
+ var _b = __read(_a, 2), user = _b[0], score = _b[1];
163
+ return ({ user: user, score: score });
164
+ });
165
+ result.sort(function (a, b) { return b.score - a.score; });
166
+ // console.log(result);
167
+ return [2 /*return*/, result];
168
+ case 4:
169
+ e_1 = _a.sent();
170
+ return [2 /*return*/, []];
171
+ case 5: return [2 /*return*/];
129
172
  }
130
173
  });
131
174
  });
@@ -158,7 +201,7 @@ var bidderRequestData = {
158
201
  };
159
202
  function getBidderLeaderBoard(startTimestamp, end) {
160
203
  return __awaiter(this, void 0, void 0, function () {
161
- var jsonData, response, data, samples, leader_board, userScoreMap, result, e_1;
204
+ var jsonData, response, data, samples, leader_board, userScoreMap, result, e_2;
162
205
  return __generator(this, function (_a) {
163
206
  switch (_a.label) {
164
207
  case 0:
@@ -216,7 +259,7 @@ function getBidderLeaderBoard(startTimestamp, end) {
216
259
  // console.log(result);
217
260
  return [2 /*return*/, result];
218
261
  case 4:
219
- e_1 = _a.sent();
262
+ e_2 = _a.sent();
220
263
  return [2 /*return*/, []];
221
264
  case 5: return [2 /*return*/];
222
265
  }
@@ -225,15 +268,7 @@ function getBidderLeaderBoard(startTimestamp, end) {
225
268
  }
226
269
  exports.getBidderLeaderBoard = getBidderLeaderBoard;
227
270
  (function () { return __awaiter(void 0, void 0, void 0, function () {
228
- var _a, _b;
229
- return __generator(this, function (_c) {
230
- switch (_c.label) {
231
- case 0:
232
- _b = (_a = console).log;
233
- return [4 /*yield*/, getDepositorLeaderBoard("1684886400")];
234
- case 1:
235
- _b.apply(_a, [_c.sent()]);
236
- return [2 /*return*/];
237
- }
271
+ return __generator(this, function (_a) {
272
+ return [2 /*return*/];
238
273
  });
239
274
  }); })();
@@ -15,7 +15,7 @@ function typeArgsToAssets(typeArgs) {
15
15
  case "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5":
16
16
  return "WETH";
17
17
  case "0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8":
18
- return "WSOL";
18
+ return "SOL";
19
19
  case "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf":
20
20
  return "USDC";
21
21
  case "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c":
@@ -182,7 +182,7 @@ exports.getShowMap = getShowMap;
182
182
  function groupEventToShow(groupEvent, portfolioVault) {
183
183
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
184
184
  return __awaiter(this, void 0, void 0, function () {
185
- var PaidToDepositors, portfolio_payoff, PaidToBidders, exp, result;
185
+ var PaidToDepositors, portfolio_payoff, PaidToBidders, exp, ActivationTsMs, SettlementTsMs, result;
186
186
  return __generator(this, function (_r) {
187
187
  PaidToDepositors = Number((_a = groupEvent.deliveryEvent) === null || _a === void 0 ? void 0 : _a.premium_value) / Math.pow(10, Number(portfolioVault.config.bTokenDecimal));
188
188
  portfolio_payoff = ((_b = groupEvent.settleEvent) === null || _b === void 0 ? void 0 : _b.portfolio_payoff_is_neg)
@@ -200,19 +200,21 @@ function groupEventToShow(groupEvent, portfolioVault) {
200
200
  exp = 12;
201
201
  break;
202
202
  }
203
+ ActivationTsMs = Number((_e = groupEvent.newAuctionEvent) === null || _e === void 0 ? void 0 : _e.timestamp_ms);
204
+ SettlementTsMs = Number((_f = groupEvent.settleEvent) === null || _f === void 0 ? void 0 : _f.timestamp_ms);
203
205
  result = {
204
206
  // newAuctionEvent
205
- NewAuctionTx: (_e = groupEvent.newAuctionEvent) === null || _e === void 0 ? void 0 : _e.tx_digest,
206
- ActivationDate: new Date(Number((_f = groupEvent.newAuctionEvent) === null || _f === void 0 ? void 0 : _f.timestamp_ms)),
207
- 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); }),
207
+ NewAuctionTx: (_g = groupEvent.newAuctionEvent) === null || _g === void 0 ? void 0 : _g.tx_digest,
208
+ ActivationDate: new Date(ActivationTsMs - (ActivationTsMs % 3600000)),
209
+ StrikePrice: (_h = groupEvent.newAuctionEvent) === null || _h === void 0 ? void 0 : _h.vault_config.payoffConfigs.map(function (payoffConfig) { return Number(payoffConfig.strike) / Math.pow(10, 8); }),
208
210
  // deliveryEvent
209
- DeliveryTx: (_h = groupEvent.deliveryEvent) === null || _h === void 0 ? void 0 : _h.tx_digest,
210
- 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,
211
- 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),
211
+ DeliveryTx: (_j = groupEvent.deliveryEvent) === null || _j === void 0 ? void 0 : _j.tx_digest,
212
+ ProjectedAPY: Math.pow((1 + (1.01 * Number((_k = groupEvent.deliveryEvent) === null || _k === void 0 ? void 0 : _k.delivery_price)) / Math.pow(10, Number(portfolioVault.config.bTokenDecimal))), exp) - 1,
213
+ Filled: Number((_l = groupEvent.deliveryEvent) === null || _l === void 0 ? void 0 : _l.delivery_size) / Number((_m = groupEvent.deliveryEvent) === null || _m === void 0 ? void 0 : _m.max_size),
212
214
  PaidToDepositors: PaidToDepositors,
213
215
  // settleEvent
214
- SettleTx: (_m = groupEvent.settleEvent) === null || _m === void 0 ? void 0 : _m.tx_digest,
215
- SettlementTime: new Date(Number((_o = groupEvent.settleEvent) === null || _o === void 0 ? void 0 : _o.timestamp_ms)),
216
+ SettleTx: (_o = groupEvent.settleEvent) === null || _o === void 0 ? void 0 : _o.tx_digest,
217
+ SettlementTime: new Date(SettlementTsMs - (SettlementTsMs % 3600000)),
216
218
  SettlePrice: Number((_p = groupEvent.settleEvent) === null || _p === void 0 ? void 0 : _p.oracle_price) / Math.pow(10, 8),
217
219
  Return: Number((_q = groupEvent.settleEvent) === null || _q === void 0 ? void 0 : _q.share_price) / Math.pow(10, 8) - 1,
218
220
  PaidToBidders: PaidToBidders,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@typus/typus-sdk",
3
3
  "author": "Typus",
4
4
  "description": "typus sdk",
5
- "version": "1.0.74",
5
+ "version": "1.0.76",
6
6
  "dependencies": {
7
7
  "@mysten/bcs": "^0.7.3",
8
8
  "@mysten/sui.js": "^0.37.1",