@typus/typus-sdk 1.1.23 → 1.1.25
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.
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { JsonRpcProvider } from "@mysten/sui.js";
|
|
2
|
+
export declare function getDb(startTs: any, endTs: any): Promise<any>;
|
|
3
|
+
export declare function getUsersTvl(startTs: any, endTs: any): Promise<Map<string, number>>;
|
|
4
|
+
export declare function getUsersBid(provider: JsonRpcProvider, originPackage: string, startTs?: number, endTs?: number): Promise<Map<string, number>>;
|
|
5
|
+
export declare function getUsersHarvestCompound(provider: JsonRpcProvider, originPackage: string, startTs?: number, endTs?: number): Promise<Map<string, number>>;
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.getUsersHarvestCompound = exports.getUsersBid = exports.getUsersTvl = exports.getDb = void 0;
|
|
40
|
+
var token_1 = require("../token");
|
|
41
|
+
var apiUrl = "https://us-central1-aqueous-freedom-378103.cloudfunctions.net/mongodb";
|
|
42
|
+
function getDb(startTs, endTs) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
+
var queryParams, apiUrlWithParams, response, data;
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
switch (_a.label) {
|
|
47
|
+
case 0:
|
|
48
|
+
queryParams = new URLSearchParams({
|
|
49
|
+
startTs: startTs,
|
|
50
|
+
endTs: endTs,
|
|
51
|
+
});
|
|
52
|
+
apiUrlWithParams = "".concat(apiUrl, "?").concat(queryParams.toString());
|
|
53
|
+
return [4 /*yield*/, fetch(apiUrlWithParams, {
|
|
54
|
+
method: "GET",
|
|
55
|
+
headers: { "Content-Type": "application/json" },
|
|
56
|
+
})];
|
|
57
|
+
case 1:
|
|
58
|
+
response = _a.sent();
|
|
59
|
+
if (!response.ok) return [3 /*break*/, 3];
|
|
60
|
+
return [4 /*yield*/, response.json()];
|
|
61
|
+
case 2:
|
|
62
|
+
data = _a.sent();
|
|
63
|
+
return [2 /*return*/, data];
|
|
64
|
+
case 3: return [2 /*return*/];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
exports.getDb = getDb;
|
|
70
|
+
function getUsersTvl(startTs, endTs) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
+
var result, result, firstTs, lastTs, length, usersTvl;
|
|
73
|
+
return __generator(this, function (_a) {
|
|
74
|
+
switch (_a.label) {
|
|
75
|
+
case 0: return [4 /*yield*/, getDb(startTs, endTs)];
|
|
76
|
+
case 1:
|
|
77
|
+
result = _a.sent();
|
|
78
|
+
result = result.sort(function (a, b) { return Number(a.timestamp) - Number(b.timestamp); });
|
|
79
|
+
firstTs = Number(result.at(0).timestamp);
|
|
80
|
+
lastTs = Number(result.at(-1).timestamp);
|
|
81
|
+
length = (lastTs - firstTs) / 3600;
|
|
82
|
+
usersTvl = result.reduce(function (prev, curr) {
|
|
83
|
+
var acc = 0;
|
|
84
|
+
if (prev.has(curr.address)) {
|
|
85
|
+
acc = prev.get(curr.address);
|
|
86
|
+
}
|
|
87
|
+
acc += Number(curr.usd) / length;
|
|
88
|
+
prev.set(curr.address, acc);
|
|
89
|
+
return prev;
|
|
90
|
+
}, new Map());
|
|
91
|
+
// console.log(usersTvl);
|
|
92
|
+
return [2 /*return*/, usersTvl];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
exports.getUsersTvl = getUsersTvl;
|
|
98
|
+
function getUsersBid(provider, originPackage, startTs, endTs) {
|
|
99
|
+
if (startTs === void 0) { startTs = 0; }
|
|
100
|
+
if (endTs === void 0) { endTs = Math.floor(new Date().getTime() / 1000); }
|
|
101
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
var senderFilter, usersPremium, hasNextPage, cursor, result, mapEntries;
|
|
103
|
+
return __generator(this, function (_a) {
|
|
104
|
+
switch (_a.label) {
|
|
105
|
+
case 0:
|
|
106
|
+
senderFilter = {
|
|
107
|
+
MoveEventType: "".concat(originPackage, "::typus_dov_single::NewBidEvent"),
|
|
108
|
+
};
|
|
109
|
+
usersPremium = new Map();
|
|
110
|
+
hasNextPage = true;
|
|
111
|
+
cursor = undefined;
|
|
112
|
+
_a.label = 1;
|
|
113
|
+
case 1:
|
|
114
|
+
if (!hasNextPage) return [3 /*break*/, 3];
|
|
115
|
+
return [4 /*yield*/, provider.queryEvents({ query: senderFilter, order: "descending", cursor: cursor })];
|
|
116
|
+
case 2:
|
|
117
|
+
result = _a.sent();
|
|
118
|
+
// console.log(result);
|
|
119
|
+
result.data.forEach(function (data) {
|
|
120
|
+
if (Number(data.timestampMs) / 1000 < endTs) {
|
|
121
|
+
var parsedJson = data.parsedJson;
|
|
122
|
+
var bidder_balance = Number(parsedJson.bidder_balance) / Math.pow(10, Number(parsedJson.decimal));
|
|
123
|
+
var price = 1;
|
|
124
|
+
if (parsedJson.b_token == parsedJson.o_token) {
|
|
125
|
+
price = Number(parsedJson.oracle_info.price) / Math.pow(10, Number(parsedJson.oracle_info.decimal));
|
|
126
|
+
}
|
|
127
|
+
var acc = 0;
|
|
128
|
+
if (usersPremium.has(parsedJson.signer)) {
|
|
129
|
+
acc = usersPremium.get(parsedJson.signer);
|
|
130
|
+
}
|
|
131
|
+
acc += bidder_balance * price;
|
|
132
|
+
usersPremium.set(parsedJson.signer, acc);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
if (result.hasNextPage && Number(result.data.at(-1).timestampMs) / 1000 < startTs) {
|
|
136
|
+
return [3 /*break*/, 3];
|
|
137
|
+
}
|
|
138
|
+
hasNextPage = result.hasNextPage;
|
|
139
|
+
cursor = result.nextCursor;
|
|
140
|
+
return [3 /*break*/, 1];
|
|
141
|
+
case 3:
|
|
142
|
+
mapEntries = Array.from(usersPremium.entries());
|
|
143
|
+
// Sort the array based on the values (second element in each entry)
|
|
144
|
+
mapEntries.sort(function (a, b) { return b[1] - a[1]; });
|
|
145
|
+
// Create a new Map from the sorted array
|
|
146
|
+
usersPremium = new Map(mapEntries);
|
|
147
|
+
// console.log(usersPremium);
|
|
148
|
+
return [2 /*return*/, usersPremium];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
exports.getUsersBid = getUsersBid;
|
|
154
|
+
function getUsersHarvestCompound(provider, originPackage, startTs, endTs) {
|
|
155
|
+
if (startTs === void 0) { startTs = 0; }
|
|
156
|
+
if (endTs === void 0) { endTs = Math.floor(new Date().getTime() / 1000); }
|
|
157
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
158
|
+
var usersHarvestCompound, hasNextPage, cursor, result, hasNextPage, cursor, result, mapEntries;
|
|
159
|
+
return __generator(this, function (_a) {
|
|
160
|
+
switch (_a.label) {
|
|
161
|
+
case 0:
|
|
162
|
+
usersHarvestCompound = new Map();
|
|
163
|
+
hasNextPage = true;
|
|
164
|
+
cursor = undefined;
|
|
165
|
+
_a.label = 1;
|
|
166
|
+
case 1:
|
|
167
|
+
if (!hasNextPage) return [3 /*break*/, 3];
|
|
168
|
+
return [4 /*yield*/, provider.queryEvents({
|
|
169
|
+
query: { MoveEventType: "".concat(originPackage, "::typus_dov_single::HarvestEvent") },
|
|
170
|
+
order: "descending",
|
|
171
|
+
cursor: cursor,
|
|
172
|
+
})];
|
|
173
|
+
case 2:
|
|
174
|
+
result = _a.sent();
|
|
175
|
+
// console.log(result);
|
|
176
|
+
result.data.forEach(function (data) {
|
|
177
|
+
if (Number(data.timestampMs) / 1000 < endTs) {
|
|
178
|
+
var parsedJson = data.parsedJson;
|
|
179
|
+
var amount = Number(parsedJson.amount) / Math.pow(10, Number(parsedJson.decimal));
|
|
180
|
+
var price = Number(parsedJson.oracle_info.price) / Math.pow(10, Number(parsedJson.oracle_info.decimal));
|
|
181
|
+
var asset = (0, token_1.typeArgToAsset)("0x" + parsedJson.token.name);
|
|
182
|
+
if (asset.startsWith("USD")) {
|
|
183
|
+
price = 1;
|
|
184
|
+
}
|
|
185
|
+
var acc = 0;
|
|
186
|
+
if (usersHarvestCompound.has(parsedJson.signer)) {
|
|
187
|
+
acc = usersHarvestCompound.get(parsedJson.signer);
|
|
188
|
+
}
|
|
189
|
+
acc += amount * price;
|
|
190
|
+
usersHarvestCompound.set(parsedJson.signer, acc);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
if (result.hasNextPage && Number(result.data.at(-1).timestampMs) / 1000 < startTs) {
|
|
194
|
+
return [3 /*break*/, 3];
|
|
195
|
+
}
|
|
196
|
+
hasNextPage = result.hasNextPage;
|
|
197
|
+
cursor = result.nextCursor;
|
|
198
|
+
return [3 /*break*/, 1];
|
|
199
|
+
case 3:
|
|
200
|
+
hasNextPage = true;
|
|
201
|
+
cursor = undefined;
|
|
202
|
+
_a.label = 4;
|
|
203
|
+
case 4:
|
|
204
|
+
if (!hasNextPage) return [3 /*break*/, 6];
|
|
205
|
+
return [4 /*yield*/, provider.queryEvents({
|
|
206
|
+
query: { MoveEventType: "".concat(originPackage, "::typus_dov_single::CompoundEvent") },
|
|
207
|
+
order: "descending",
|
|
208
|
+
cursor: cursor,
|
|
209
|
+
})];
|
|
210
|
+
case 5:
|
|
211
|
+
result = _a.sent();
|
|
212
|
+
// console.log(result);
|
|
213
|
+
result.data.forEach(function (data) {
|
|
214
|
+
if (Number(data.timestampMs) / 1000 < endTs) {
|
|
215
|
+
var parsedJson = data.parsedJson;
|
|
216
|
+
var amount = Number(parsedJson.amount) / Math.pow(10, Number(parsedJson.decimal));
|
|
217
|
+
var price = Number(parsedJson.oracle_info.price) / Math.pow(10, Number(parsedJson.oracle_info.decimal));
|
|
218
|
+
var asset = (0, token_1.typeArgToAsset)("0x" + parsedJson.token.name);
|
|
219
|
+
if (asset.startsWith("USD")) {
|
|
220
|
+
price = 1;
|
|
221
|
+
}
|
|
222
|
+
var acc = 0;
|
|
223
|
+
if (usersHarvestCompound.has(parsedJson.signer)) {
|
|
224
|
+
acc = usersHarvestCompound.get(parsedJson.signer);
|
|
225
|
+
}
|
|
226
|
+
acc += amount * price;
|
|
227
|
+
usersHarvestCompound.set(parsedJson.signer, acc);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
if (result.hasNextPage && Number(result.data.at(-1).timestampMs) / 1000 < startTs) {
|
|
231
|
+
return [3 /*break*/, 6];
|
|
232
|
+
}
|
|
233
|
+
hasNextPage = result.hasNextPage;
|
|
234
|
+
cursor = result.nextCursor;
|
|
235
|
+
return [3 /*break*/, 4];
|
|
236
|
+
case 6:
|
|
237
|
+
mapEntries = Array.from(usersHarvestCompound.entries());
|
|
238
|
+
// Sort the array based on the values (second element in each entry)
|
|
239
|
+
mapEntries.sort(function (a, b) { return b[1] - a[1]; });
|
|
240
|
+
// Create a new Map from the sorted array
|
|
241
|
+
usersHarvestCompound = new Map(mapEntries);
|
|
242
|
+
// console.log(usersHarvestCompound);
|
|
243
|
+
return [2 /*return*/, usersHarvestCompound];
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
exports.getUsersHarvestCompound = getUsersHarvestCompound;
|
|
@@ -4,7 +4,7 @@ export declare function getUserHistory(provider: JsonRpcProvider, originPackage:
|
|
|
4
4
|
[key: string]: Vault;
|
|
5
5
|
}, sender: string, startTimeMs: number): Promise<TxHistory[]>;
|
|
6
6
|
export interface TxHistory {
|
|
7
|
-
Index: string;
|
|
7
|
+
Index: string | undefined;
|
|
8
8
|
Action: string;
|
|
9
9
|
Period: string | undefined;
|
|
10
10
|
Amount: string | undefined;
|
|
@@ -89,15 +89,16 @@ function parseTxHistory(datas, originPackage, vaults) {
|
|
|
89
89
|
return type.startsWith(originPackage) || type.includes("typus_nft::First") || type.includes("typus_nft::ExpUpEvent");
|
|
90
90
|
})
|
|
91
91
|
.reduce(function (promise, event) { return __awaiter(_this, void 0, void 0, function () {
|
|
92
|
-
var txHistory, functionType, action, Action, Amount, Period, Vault, RiskLevel, Tails, Exp, o_token, v, period, optionType, i, i, token, amount, amount, token, amount, size, token, amount, i, b_token, size, bidder_balance;
|
|
93
|
-
var _a
|
|
94
|
-
return __generator(this, function (
|
|
95
|
-
switch (
|
|
92
|
+
var txHistory, functionType, action, Action, Amount, Index, Period, Vault, RiskLevel, Tails, Exp, o_token, v, period, optionType, i, i, token, amount, amount, token, amount, size, token, amount, i, b_token, size, bidder_balance;
|
|
93
|
+
var _a;
|
|
94
|
+
return __generator(this, function (_b) {
|
|
95
|
+
switch (_b.label) {
|
|
96
96
|
case 0: return [4 /*yield*/, promise];
|
|
97
97
|
case 1:
|
|
98
|
-
txHistory =
|
|
98
|
+
txHistory = _b.sent();
|
|
99
99
|
functionType = (_a = new RegExp("^([^::]+)::([^::]+)::([^<]+)").exec(event.type)) === null || _a === void 0 ? void 0 : _a.slice(1, 4);
|
|
100
100
|
action = functionType[2];
|
|
101
|
+
Index = event.parsedJson.index;
|
|
101
102
|
if (event.parsedJson.index) {
|
|
102
103
|
v = vaults[event.parsedJson.index];
|
|
103
104
|
if (v) {
|
|
@@ -244,11 +245,13 @@ function parseTxHistory(datas, originPackage, vaults) {
|
|
|
244
245
|
amount = Number(event.parsedJson.amount) / Math.pow(10, Number(event.parsedJson.decimal));
|
|
245
246
|
Action = action.slice(0, action.length - 5);
|
|
246
247
|
Amount = "".concat((0, bignumber_js_1.default)(amount).toFixed(), " ").concat(token);
|
|
248
|
+
Index = event.parsedJson.index;
|
|
247
249
|
if (i != -1) {
|
|
248
250
|
txHistory[i].Action = Action;
|
|
249
251
|
txHistory[i].Amount = Amount;
|
|
250
252
|
txHistory[i].Vault = Vault;
|
|
251
253
|
txHistory[i].RiskLevel = RiskLevel;
|
|
254
|
+
txHistory[i].Index = Index;
|
|
252
255
|
return [2 /*return*/, txHistory];
|
|
253
256
|
}
|
|
254
257
|
break;
|
|
@@ -293,7 +296,7 @@ function parseTxHistory(datas, originPackage, vaults) {
|
|
|
293
296
|
return [2 /*return*/, txHistory];
|
|
294
297
|
}
|
|
295
298
|
txHistory.push({
|
|
296
|
-
Index:
|
|
299
|
+
Index: Index,
|
|
297
300
|
Period: Period,
|
|
298
301
|
Action: Action,
|
|
299
302
|
Amount: Amount,
|