@typus/typus-sdk 1.2.82 → 1.2.83-tails-exp

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,634 +0,0 @@
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
- var __read = (this && this.__read) || function (o, n) {
39
- var m = typeof Symbol === "function" && o[Symbol.iterator];
40
- if (!m) return o;
41
- var i = m.call(o), r, ar = [], e;
42
- try {
43
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
44
- }
45
- catch (error) { e = { error: error }; }
46
- finally {
47
- try {
48
- if (r && !r.done && (m = i["return"])) m.call(i);
49
- }
50
- finally { if (e) throw e.error; }
51
- }
52
- return ar;
53
- };
54
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
55
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
56
- if (ar || !(i in from)) {
57
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
58
- ar[i] = from[i];
59
- }
60
- }
61
- return to.concat(ar || Array.prototype.slice.call(from));
62
- };
63
- var __values = (this && this.__values) || function(o) {
64
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
65
- if (m) return m.call(o);
66
- if (o && typeof o.length === "number") return {
67
- next: function () {
68
- if (o && i >= o.length) o = void 0;
69
- return { value: o && o[i++], done: !o };
70
- }
71
- };
72
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
73
- };
74
- var __importDefault = (this && this.__importDefault) || function (mod) {
75
- return (mod && mod.__esModule) ? mod : { "default": mod };
76
- };
77
- Object.defineProperty(exports, "__esModule", { value: true });
78
- exports.fetchUserBids = exports.getUserBidReceipts = exports.parseBid = exports.parseBidReceipt = exports.parseStrikes = exports.calcEstPnl = exports.calcBreakEvenPrice = exports.calcDeliveryPrice = exports.calcIncentiveRate = exports.IncentiveRateBp = exports.periodOrder = exports.optionTypeOrder = exports.tokenOrder = void 0;
79
- var bignumber_js_1 = __importDefault(require("bignumber.js"));
80
- var lodash_1 = require("lodash");
81
- var moment_1 = __importDefault(require("moment"));
82
- var view_function_1 = require("../view-function");
83
- var vault_1 = require("./vault");
84
- var token_1 = require("./token");
85
- var tools_1 = require("../../tools");
86
- var view_function_2 = require("../../auto-bid/view-function");
87
- var token_2 = require("../../token");
88
- var PriceDecimal = (0, bignumber_js_1.default)(10).pow(8);
89
- exports.tokenOrder = {
90
- // Basically it's a to z but put SUI at first
91
- SUI: 0,
92
- AFSUI: 1,
93
- APT: 2,
94
- WBTC: 3,
95
- BTC: 3,
96
- BUCK: 4,
97
- CETUS: 5,
98
- WETH: 6,
99
- ETH: 6,
100
- FUD: 7,
101
- INJ: 8,
102
- JUP: 9,
103
- NAVX: 10,
104
- SCA: 11,
105
- SEI: 12,
106
- WSOL: 13,
107
- SOL: 14,
108
- TURBOS: 15,
109
- USDC: 16,
110
- USDT: 17,
111
- USDY: 18,
112
- };
113
- exports.optionTypeOrder = {
114
- 0: 0,
115
- 1: 2,
116
- 2: 3,
117
- 4: 4,
118
- 6: 5,
119
- 5: 6,
120
- };
121
- exports.periodOrder = {
122
- 0: 1,
123
- 1: 2,
124
- 2: 3,
125
- 3: 0,
126
- };
127
- exports.IncentiveRateBp = 4;
128
- var calcIncentiveRate = function (incentiveBp) {
129
- var incentiveRateBp = (0, bignumber_js_1.default)(incentiveBp).div((0, bignumber_js_1.default)(10).pow(exports.IncentiveRateBp));
130
- var incentiveRate = 1;
131
- if (incentiveRateBp.gt(0)) {
132
- incentiveRate = 1 - Number(incentiveRateBp);
133
- }
134
- return incentiveRate;
135
- };
136
- exports.calcIncentiveRate = calcIncentiveRate;
137
- var calcDeliveryPrice = function (bidShare, vaultInfo) {
138
- var bTokenDecimal = vaultInfo.info.bTokenDecimal;
139
- var deliveryPrice = (0, bignumber_js_1.default)("0");
140
- // check if bid has settled already
141
- if (bidShare.bidVault.u64Padding[1]) {
142
- deliveryPrice = (0, bignumber_js_1.default)(bidShare.bidVault.u64Padding[1]);
143
- }
144
- else {
145
- var deliveryInfos = vaultInfo.info.deliveryInfos.deliveryInfo;
146
- var deliveryInfo = deliveryInfos[deliveryInfos.length - 1];
147
- deliveryPrice = deliveryInfo ? (0, bignumber_js_1.default)(deliveryInfo.deliveryPrice) : (0, bignumber_js_1.default)("0");
148
- }
149
- deliveryPrice = (0, bignumber_js_1.default)(deliveryPrice).div((0, bignumber_js_1.default)(10).pow((0, bignumber_js_1.default)(bTokenDecimal)));
150
- return deliveryPrice;
151
- };
152
- exports.calcDeliveryPrice = calcDeliveryPrice;
153
- var calcBreakEvenPrice = function (optionType, period, strikes, bToken, price, incentive) {
154
- var breakEvenPrice = 0;
155
- switch (optionType) {
156
- case "0":
157
- if (token_1.StableCoin.includes(bToken)) {
158
- breakEvenPrice = Number(strikes[0]) + Number(price) * 1.1 * incentive;
159
- }
160
- else {
161
- breakEvenPrice = Number(strikes[0]) / (1 - Number(price) * 1.1 * incentive);
162
- }
163
- break;
164
- case "1":
165
- if (token_1.StableCoin.includes(bToken)) {
166
- breakEvenPrice = Number(strikes[0]) - Number(price) * 1.1 * incentive;
167
- }
168
- else {
169
- breakEvenPrice = Number(strikes[0]) / (1 + Number(price) * 1.1 * incentive);
170
- }
171
- break;
172
- case "2":
173
- // Calculate with the lower one
174
- if (token_1.StableCoin.includes(bToken)) {
175
- breakEvenPrice = Number(strikes[0]) + Number(price) * 1.1 * incentive;
176
- }
177
- else {
178
- breakEvenPrice = Number(strikes[0]) / (1 - Number(price) * 1.1 * incentive);
179
- }
180
- break;
181
- case "4":
182
- // Calculate with the lower one
183
- if (token_1.StableCoin.includes(bToken)) {
184
- breakEvenPrice = Number(strikes[0]) + Number(price) * 1.1 * incentive;
185
- }
186
- else {
187
- breakEvenPrice = Number(strikes[0]) / (1 - Number(price) * 1.1 * incentive);
188
- }
189
- break;
190
- case "5":
191
- if (token_1.StableCoin.includes(bToken)) {
192
- breakEvenPrice = Number(strikes[1]) - Number(price) * 1.1 * incentive;
193
- }
194
- else {
195
- breakEvenPrice = Number(strikes[1]) / (1 + Number(price) * 1.1 * incentive);
196
- }
197
- break;
198
- case "6":
199
- // Calculate with the lower one
200
- if (token_1.StableCoin.includes(bToken)) {
201
- breakEvenPrice = Number(strikes[0]) + Number(price) * 1.1 * incentive;
202
- }
203
- else {
204
- breakEvenPrice = Number(strikes[0]) / (1 + Number(price) * 1.1 * incentive);
205
- }
206
- break;
207
- }
208
- return breakEvenPrice;
209
- };
210
- exports.calcBreakEvenPrice = calcBreakEvenPrice;
211
- var calcEstPnl = function (live, incentive, bidSize, optionType, assets, strikes, bidShare, deliveryPrice, oTokenPrice) {
212
- var profit = "0";
213
- var cost = "0";
214
- var _a = __read((0, token_2.typeArgsToAssets)(assets), 3), dToken = _a[0], bToken = _a[1], oToken = _a[2];
215
- var dTokenWrappedName = (0, token_1.getTokenName)({ token: dToken, wrapped: true });
216
- var bTokenWrappedName = (0, token_1.getTokenName)({ token: bToken, wrapped: true });
217
- var estPnls = [];
218
- var referencePrice = bidShare.bidVault.u64Padding.length > 0 ? (0, bignumber_js_1.default)(bidShare.bidVault.u64Padding[0]).div(PriceDecimal) : (0, bignumber_js_1.default)(oTokenPrice);
219
- if (optionType === "0") {
220
- profit = bignumber_js_1.default.max(0, (0, bignumber_js_1.default)(referencePrice.minus((0, bignumber_js_1.default)(strikes[0])))
221
- .div(referencePrice)
222
- .multipliedBy(bidSize)).toString();
223
- }
224
- else if (optionType === "1") {
225
- profit = bignumber_js_1.default.max(0, (0, bignumber_js_1.default)(strikes[0]).minus(referencePrice).multipliedBy(bidSize)).toString();
226
- }
227
- else if (optionType === "2" || optionType === "4") {
228
- profit = bignumber_js_1.default.max(0, (0, bignumber_js_1.default)(referencePrice.minus((0, bignumber_js_1.default)(strikes[0])))
229
- .div(referencePrice)
230
- .multipliedBy(bidSize))
231
- .minus(bignumber_js_1.default.max(0, (0, bignumber_js_1.default)(referencePrice.minus((0, bignumber_js_1.default)(strikes[1])))
232
- .div(referencePrice)
233
- .multipliedBy(bidSize)))
234
- .toString();
235
- }
236
- else if (optionType === "5") {
237
- profit = bignumber_js_1.default.max(0, (0, bignumber_js_1.default)((0, bignumber_js_1.default)(strikes[1]).minus(referencePrice)).multipliedBy(bidSize))
238
- .minus(bignumber_js_1.default.max(0, (0, bignumber_js_1.default)((0, bignumber_js_1.default)(strikes[0]).minus((0, bignumber_js_1.default)(referencePrice))).multipliedBy(bidSize)))
239
- .toString();
240
- }
241
- else if (optionType === "6") {
242
- profit = bignumber_js_1.default.max(0, (0, bignumber_js_1.default)(referencePrice.minus(strikes[0])).multipliedBy(bidSize))
243
- .minus(bignumber_js_1.default.max(0, (0, bignumber_js_1.default)(referencePrice.minus(strikes[1])).multipliedBy(bidSize)))
244
- .toString();
245
- }
246
- cost = (0, bignumber_js_1.default)(deliveryPrice).multipliedBy(bidSize).multipliedBy(1.1).multipliedBy(incentive).toString();
247
- if (dToken === bToken) {
248
- profit = (0, bignumber_js_1.default)(profit).minus(cost).toString();
249
- }
250
- if (!live) {
251
- estPnls.push({
252
- value: profit,
253
- token: assets[0],
254
- });
255
- if (dToken !== bToken) {
256
- estPnls.push({ value: "-" + cost, token: assets[1] });
257
- }
258
- }
259
- return estPnls;
260
- };
261
- exports.calcEstPnl = calcEstPnl;
262
- var parseStrikes = function (period, optionType, metadata) {
263
- var strikes = [period === "3" ? metadata.split("-")[3] : metadata.split("-")[2]];
264
- switch (optionType) {
265
- case "0":
266
- break;
267
- case "1":
268
- break;
269
- case "2":
270
- strikes = [metadata.split("-")[2], metadata.split("-")[3]];
271
- break;
272
- case "4":
273
- strikes = [metadata.split("-")[2], metadata.split("-")[3]];
274
- if (period == "3") {
275
- strikes = [metadata.split("-")[3], metadata.split("-")[4]];
276
- }
277
- strikes = strikes.sort(function (a, b) { return Number(a) - Number(b); });
278
- break;
279
- case "5":
280
- strikes = [metadata.split("-")[2], metadata.split("-")[3]];
281
- if (period == "3") {
282
- strikes = [metadata.split("-")[3], metadata.split("-")[4]];
283
- }
284
- strikes = strikes.sort(function (a, b) { return Number(a) - Number(b); });
285
- break;
286
- case "6":
287
- strikes = [metadata.split("-")[2], metadata.split("-")[3]];
288
- if (period == "3") {
289
- strikes = [metadata.split("-")[3], metadata.split("-")[4]];
290
- }
291
- strikes = strikes.sort(function (a, b) { return Number(a) - Number(b); });
292
- break;
293
- }
294
- strikes = (0, tools_1.checkNumber)(strikes[0]) ? strikes : [];
295
- strikes = strikes.sort(function (a, b) { return Number(a) - Number(b); });
296
- return strikes;
297
- };
298
- exports.parseStrikes = parseStrikes;
299
- var parseBidReceipt = function (vaults, bidReceipts) {
300
- var sortedBidReceipts = [];
301
- var bidVaultsInfo = [];
302
- var vidMap = new Map();
303
- vaults.forEach(function (v) {
304
- var curReceipts = bidReceipts[v.info.index];
305
- if (curReceipts) {
306
- curReceipts.map(function (receipt) {
307
- // ###### NOTE: #####
308
- // Bid receipts need to be sorted and put together
309
- // BY vid for SDK getMyBids to fetch the correct data.
310
- // ###########
311
- // Filer out autoBidReceiptsData receipts cuz it's wrapped in strategy and
312
- // SDK getMyBids can't retrieve it!
313
- var data = vidMap.get(receipt.vid);
314
- if (!data) {
315
- vidMap.set(receipt.vid, [receipt.id]);
316
- }
317
- else {
318
- data.push(receipt.id);
319
- vidMap.set(receipt.vid, data);
320
- }
321
- bidVaultsInfo.push({ vaultInfo: v, receipt: receipt });
322
- });
323
- var values = Array.from(vidMap.values());
324
- sortedBidReceipts = values.reduce(function (previousValue, currentValue, currentIndex, array) {
325
- return previousValue.concat(currentValue);
326
- }, []);
327
- }
328
- });
329
- return { sortedBidReceipts: sortedBidReceipts, bidVaultsInfo: bidVaultsInfo };
330
- };
331
- exports.parseBidReceipt = parseBidReceipt;
332
- var parseBid = function (bidVaultInfo, bidShare, auction, oTokenPrice, isAutoBid) {
333
- var _a, _b;
334
- var vaultInfo = bidVaultInfo.vaultInfo, _c = bidVaultInfo.vaultInfo, info = _c.info, _d = _c.info, index = _d.index, bTokenDecimal = _d.bTokenDecimal, oTokenDecimal = _d.oTokenDecimal, optionType = _d.optionType, period = _d.period, depositToken = _d.depositToken, bidToken = _d.bidToken, settlementBase = _d.settlementBase, _e = _c.config, lotSize = _e.bidLotSize, bidIncentiveBp = _e.bidIncentiveBp, u64Padding = _e.u64Padding, receipt = bidVaultInfo.receipt;
335
- var incentiveRate = (0, exports.calcIncentiveRate)(bidIncentiveBp);
336
- var _f = __read((0, vault_1.parseAssets)(info), 3), dToken = _f[0], bToken = _f[1], oToken = _f[2];
337
- var oTokenName = (0, token_1.getTokenName)({ token: oToken });
338
- var dTokenWrappedName = (0, token_1.getTokenName)({ token: dToken, wrapped: true });
339
- var bTokenWrappedName = (0, token_1.getTokenName)({ token: bToken, wrapped: true });
340
- var metadata = bidShare.bidVault.metadata;
341
- var tokenLabel = metadata.split("-")[0];
342
- var periodLabel = vault_1.Period[Number(period)].charAt(0).toUpperCase() + vault_1.Period[Number(period)].slice(1);
343
- var optionTypeLabel = vault_1.AbbrStrategyName[optionType];
344
- var bidsSize = Number(bidShare.share) / Math.pow(10, Number(oTokenDecimal));
345
- var expirationDate = (0, moment_1.default)(metadata.split("-")[1], "DDMMMYY").format("yyyy-MM-DD");
346
- expirationDate = moment_1.default
347
- .utc(period === "3" ? "".concat(expirationDate, " ").concat((0, tools_1.insertAt)(metadata.split("-")[2], ":", 2)) : "".concat(expirationDate, " 08:00"))
348
- .local()
349
- .format("DD MMM YY, HH:mm");
350
- var live = !auction
351
- ? false
352
- : moment_1.default.unix(Number(auction.endTsMs) / 1000).isAfter((0, moment_1.default)()) &&
353
- moment_1.default.unix(Number(auction.startTsMs) / 1000).isBefore((0, moment_1.default)()) &&
354
- (0, moment_1.default)(expirationDate, "DD MMM YY, HH:mm").isAfter(moment_1.default.unix(Number(auction.endTsMs) / 1000));
355
- var deliveryPrice = (0, exports.calcDeliveryPrice)(bidShare, vaultInfo);
356
- var initialPrice = (_a = auction === null || auction === void 0 ? void 0 : auction.initialPrice) !== null && _a !== void 0 ? _a : 0;
357
- initialPrice = (0, bignumber_js_1.default)(initialPrice).div((0, bignumber_js_1.default)(10).pow((0, bignumber_js_1.default)(bTokenDecimal)));
358
- var strikes = (0, exports.parseStrikes)(period, optionType, metadata);
359
- var breakEvenPriceReference = live ? initialPrice : deliveryPrice;
360
- var breakEvenPrice = (0, exports.calcBreakEvenPrice)(optionType, period, strikes, bToken, breakEvenPriceReference, incentiveRate);
361
- var defaultMinBidSize = (0, bignumber_js_1.default)(lotSize).div((0, bignumber_js_1.default)(10).pow(oTokenDecimal));
362
- var bidSize = bidsSize.toFixed((0, tools_1.countFloating)(defaultMinBidSize.toNumber()));
363
- var settlePrice = (0, bignumber_js_1.default)((_b = bidShare.bidVault.u64Padding[0]) !== null && _b !== void 0 ? _b : "0").div(PriceDecimal);
364
- var estPnls = (0, exports.calcEstPnl)(live, incentiveRate, bidSize, optionType, [depositToken, bidToken, settlementBase], strikes, bidShare, deliveryPrice.toString(), oTokenPrice);
365
- return {
366
- vaultIndex: index,
367
- auctionName: "".concat(tokenLabel, " ").concat(periodLabel, " ").concat(optionTypeLabel),
368
- expiry: expirationDate,
369
- strikes: strikes.map(function (s) {
370
- if (tokenLabel === "MFUD") {
371
- return (0, bignumber_js_1.default)(s).div(1000000).toString();
372
- }
373
- return s;
374
- }),
375
- bidSize: {
376
- value: (0, bignumber_js_1.default)(bidSize)
377
- .div((0, bignumber_js_1.default)(10).pow(oToken === "MFUD" ? 6 : 0))
378
- .toString(),
379
- token: settlementBase,
380
- },
381
- breakEvenPrice: (0, bignumber_js_1.default)(breakEvenPrice)
382
- .div((0, bignumber_js_1.default)(10).pow(oToken === "MFUD" ? 6 : 0))
383
- .toString(),
384
- settlePrice: (0, bignumber_js_1.default)(settlePrice)
385
- .div((0, bignumber_js_1.default)(10).pow(oToken === "MFUD" ? 6 : 0))
386
- .toString(),
387
- estPnls: estPnls,
388
- isAutoBid: isAutoBid,
389
- receiptsId: [receipt.id],
390
- receiptsVid: [receipt.vid],
391
- optionTypeOrder: exports.optionTypeOrder[optionType],
392
- periodOrder: exports.periodOrder[period],
393
- tokenOrder: exports.tokenOrder[oToken.toUpperCase()],
394
- };
395
- };
396
- exports.parseBid = parseBid;
397
- var getUserBidReceipts = function (provider, network, originFramworkAddress, userAddress) { return __awaiter(void 0, void 0, void 0, function () {
398
- var bidReceipts, result, hasNextPage, data, nextCursor, data_1, data_1_1, object, content, typeStringComponents, subtype, typeComponents, type, typePackage, vaultIndex, receipt;
399
- var e_1, _a;
400
- return __generator(this, function (_b) {
401
- switch (_b.label) {
402
- case 0:
403
- bidReceipts = {};
404
- return [4 /*yield*/, provider.getOwnedObjects({ owner: userAddress, options: { showType: true, showContent: true } })];
405
- case 1:
406
- result = _b.sent();
407
- hasNextPage = result.hasNextPage;
408
- data = result.data;
409
- nextCursor = result.nextCursor;
410
- _b.label = 2;
411
- case 2:
412
- if (!hasNextPage) return [3 /*break*/, 4];
413
- return [4 /*yield*/, provider.getOwnedObjects({ owner: userAddress, cursor: nextCursor, options: { showType: true, showContent: true } })];
414
- case 3:
415
- result = _b.sent();
416
- data = __spreadArray(__spreadArray([], __read(data), false), __read(result.data), false);
417
- hasNextPage = result.hasNextPage;
418
- nextCursor = result.nextCursor;
419
- return [3 /*break*/, 2];
420
- case 4:
421
- if (data.length === 0) {
422
- return [2 /*return*/, bidReceipts];
423
- }
424
- try {
425
- for (data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
426
- object = data_1_1.value;
427
- try {
428
- content = (object.data || {}).content;
429
- if (!content)
430
- continue;
431
- typeStringComponents = (content.type || "").split("<");
432
- subtype = (typeStringComponents[1] || "").replace(/>/, "");
433
- typeComponents = typeStringComponents[0].split("::");
434
- type = typeComponents[typeComponents.length - 1];
435
- typePackage = typeComponents[0];
436
- if (type === "TypusBidReceipt" && originFramworkAddress == typePackage) {
437
- vaultIndex = content.fields.index;
438
- receipt = {
439
- // @ts-ignore
440
- id: content.fields.id.id,
441
- // @ts-ignore
442
- index: vaultIndex,
443
- // @ts-ignore
444
- name: content.fields.name,
445
- // @ts-ignore
446
- description: content.fields.description,
447
- // @ts-ignore
448
- vid: content.fields.vid,
449
- // @ts-ignore
450
- metadata: content.fields.metadata,
451
- };
452
- bidReceipts[vaultIndex] || (bidReceipts[vaultIndex] = []);
453
- bidReceipts[vaultIndex].push(receipt);
454
- }
455
- }
456
- catch (e) {
457
- console.log("Error retrieving object", object, e);
458
- }
459
- }
460
- }
461
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
462
- finally {
463
- try {
464
- if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
465
- }
466
- finally { if (e_1) throw e_1.error; }
467
- }
468
- return [2 /*return*/, bidReceipts];
469
- }
470
- });
471
- }); };
472
- exports.getUserBidReceipts = getUserBidReceipts;
473
- /**
474
- * Fetch user's bids info
475
- *
476
- * @param provider - Sui Client instance.
477
- * @param network - network type in lowercase.
478
- * @param packageAddress - Typus main package address.
479
- * @param framworkAddress - Typus framwork package address.
480
- * @param originFramworkAddress - Typus intial framwork package address.
481
- * @param registryAddress - Typus registry package address.
482
- * @param strategyPoolAddress - strategy pool package address.
483
- * @param userAddress - user's wallet address.
484
- * @param prices - tokens prices (usd pair on Pyth)
485
- * @return User Bids.
486
- */
487
- var fetchUserBids = function (provider, network, packageAddress, framworkAddress, originFramworkAddress, registryAddress, strategyPoolAddress, userAddress, prices) { return __awaiter(void 0, void 0, void 0, function () {
488
- var vaultsInfo, userReceipts, userStrategies, auctions, _a, sortedBidReceipts, bidVaultsInfo, bidShares, bidsFromBidShares, _loop_1, bidVaultsInfo_1, bidVaultsInfo_1_1, bidVaultInfo, autoBidsShares, vaultAutoBidReceipts, userStrategies_1, userStrategies_1_1, strategy, receipts, receipts_1, receipts_1_1, receiptItem, vaultIndex, receipt, autoBidVaultInfos, bidsFromStrategies, _loop_2, autoBidVaultInfos_1, autoBidVaultInfos_1_1, autoBidVaultInfo, byOrdered;
489
- var e_2, _b, e_3, _c, e_4, _d, e_5, _e;
490
- return __generator(this, function (_f) {
491
- switch (_f.label) {
492
- case 0: return [4 /*yield*/, (0, view_function_1.getVaults)(provider, packageAddress, registryAddress, [])];
493
- case 1:
494
- vaultsInfo = _f.sent();
495
- return [4 /*yield*/, (0, exports.getUserBidReceipts)(provider, network, originFramworkAddress, userAddress)];
496
- case 2:
497
- userReceipts = _f.sent();
498
- return [4 /*yield*/, (0, view_function_2.getUserStrategies)(provider, packageAddress, registryAddress, strategyPoolAddress, userAddress)];
499
- case 3:
500
- userStrategies = _f.sent();
501
- return [4 /*yield*/, (0, view_function_1.getAuctions)(provider, packageAddress, registryAddress, [])];
502
- case 4:
503
- auctions = _f.sent();
504
- _a = (0, exports.parseBidReceipt)(Object.values(vaultsInfo), userReceipts), sortedBidReceipts = _a.sortedBidReceipts, bidVaultsInfo = _a.bidVaultsInfo;
505
- return [4 /*yield*/, (0, view_function_1.getMyBids)(provider, framworkAddress, packageAddress, registryAddress, sortedBidReceipts)];
506
- case 5:
507
- bidShares = _f.sent();
508
- bidsFromBidShares = [];
509
- _loop_1 = function (bidVaultInfo) {
510
- var bidShare = bidShares["".concat(bidVaultInfo.receipt.index, "-").concat(bidVaultInfo.receipt.vid)];
511
- var auction = auctions ? auctions[bidVaultInfo.vaultInfo.info.index] : null;
512
- var _g = __read((0, vault_1.parseAssets)(bidVaultInfo.vaultInfo.info), 3), dToken = _g[0], bToken = _g[1], oToken = _g[2];
513
- if (bidShare) {
514
- var data = (0, exports.parseBid)(bidVaultInfo, bidShare, auction, prices[oToken.toLowerCase()], false);
515
- var checkExistVault = bidsFromBidShares.find(function (p) { return p.vaultIndex === bidVaultInfo.vaultInfo.info.index && p.receiptsVid.includes(bidVaultInfo.receipt.vid); });
516
- if (checkExistVault) {
517
- // Merge the bid receipts into the same vault
518
- checkExistVault.receiptsId = __spreadArray(__spreadArray([], __read(checkExistVault.receiptsId), false), __read(data.receiptsId), false);
519
- }
520
- else {
521
- bidsFromBidShares.push(data);
522
- }
523
- }
524
- };
525
- try {
526
- for (bidVaultsInfo_1 = __values(bidVaultsInfo), bidVaultsInfo_1_1 = bidVaultsInfo_1.next(); !bidVaultsInfo_1_1.done; bidVaultsInfo_1_1 = bidVaultsInfo_1.next()) {
527
- bidVaultInfo = bidVaultsInfo_1_1.value;
528
- _loop_1(bidVaultInfo);
529
- }
530
- }
531
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
532
- finally {
533
- try {
534
- if (bidVaultsInfo_1_1 && !bidVaultsInfo_1_1.done && (_b = bidVaultsInfo_1.return)) _b.call(bidVaultsInfo_1);
535
- }
536
- finally { if (e_2) throw e_2.error; }
537
- }
538
- autoBidsShares = {};
539
- vaultAutoBidReceipts = {};
540
- try {
541
- for (userStrategies_1 = __values(userStrategies), userStrategies_1_1 = userStrategies_1.next(); !userStrategies_1_1.done; userStrategies_1_1 = userStrategies_1.next()) {
542
- strategy = userStrategies_1_1.value;
543
- receipts = strategy.receipts;
544
- try {
545
- for (receipts_1 = (e_4 = void 0, __values(receipts)), receipts_1_1 = receipts_1.next(); !receipts_1_1.done; receipts_1_1 = receipts_1.next()) {
546
- receiptItem = receipts_1_1.value;
547
- vaultIndex = receiptItem.index;
548
- receipt = {
549
- id: receiptItem.id,
550
- index: vaultIndex,
551
- name: "",
552
- description: "",
553
- vid: receiptItem.vid,
554
- metadata: receiptItem.metadata,
555
- };
556
- if (vaultAutoBidReceipts[vaultIndex]) {
557
- vaultAutoBidReceipts[vaultIndex] = __spreadArray(__spreadArray([], __read(vaultAutoBidReceipts[vaultIndex]), false), [receipt], false);
558
- }
559
- else {
560
- vaultAutoBidReceipts[vaultIndex] = [receipt];
561
- }
562
- if (autoBidsShares["".concat(vaultIndex, "-").concat(receiptItem.vid)]) {
563
- autoBidsShares["".concat(vaultIndex, "-").concat(receiptItem.vid)].share = (Number(autoBidsShares["".concat(vaultIndex, "-").concat(receiptItem.vid)].share) +
564
- Number(strategy.my_bids["".concat(vaultIndex, "-").concat(receiptItem.vid)].share)).toString();
565
- }
566
- else {
567
- autoBidsShares["".concat(vaultIndex, "-").concat(receiptItem.vid)] = {
568
- bidVault: strategy.my_bids["".concat(vaultIndex, "-").concat(receiptItem.vid)].bidVault,
569
- share: strategy.my_bids["".concat(vaultIndex, "-").concat(receiptItem.vid)].share,
570
- };
571
- }
572
- }
573
- }
574
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
575
- finally {
576
- try {
577
- if (receipts_1_1 && !receipts_1_1.done && (_d = receipts_1.return)) _d.call(receipts_1);
578
- }
579
- finally { if (e_4) throw e_4.error; }
580
- }
581
- }
582
- }
583
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
584
- finally {
585
- try {
586
- if (userStrategies_1_1 && !userStrategies_1_1.done && (_c = userStrategies_1.return)) _c.call(userStrategies_1);
587
- }
588
- finally { if (e_3) throw e_3.error; }
589
- }
590
- autoBidVaultInfos = [];
591
- Object.values(vaultsInfo).forEach(function (v) {
592
- var curReceipts = vaultAutoBidReceipts[v.info.index];
593
- if (curReceipts) {
594
- curReceipts.map(function (item) {
595
- autoBidVaultInfos.push({ vaultInfo: v, receipt: item });
596
- });
597
- }
598
- });
599
- bidsFromStrategies = [];
600
- _loop_2 = function (autoBidVaultInfo) {
601
- var bidShare = autoBidsShares["".concat(autoBidVaultInfo.receipt.index, "-").concat(autoBidVaultInfo.receipt.vid)];
602
- var auction = auctions ? auctions[autoBidVaultInfo.vaultInfo.info.index] : null;
603
- var _h = __read((0, vault_1.parseAssets)(autoBidVaultInfo.vaultInfo.info), 3), dToken = _h[0], bToken = _h[1], oToken = _h[2];
604
- if (bidShare) {
605
- var data = (0, exports.parseBid)(autoBidVaultInfo, bidShare, auction, prices[oToken.toLowerCase()], false);
606
- var checkExistVault = bidsFromStrategies.find(function (p) { return p.vaultIndex === autoBidVaultInfo.vaultInfo.info.index && p.receiptsVid.includes(autoBidVaultInfo.receipt.vid); });
607
- if (checkExistVault) {
608
- // Merge the bid receipts into the same vault
609
- checkExistVault.receiptsId = __spreadArray(__spreadArray([], __read(checkExistVault.receiptsId), false), __read(data.receiptsId), false);
610
- }
611
- else {
612
- bidsFromStrategies.push(data);
613
- }
614
- }
615
- };
616
- try {
617
- for (autoBidVaultInfos_1 = __values(autoBidVaultInfos), autoBidVaultInfos_1_1 = autoBidVaultInfos_1.next(); !autoBidVaultInfos_1_1.done; autoBidVaultInfos_1_1 = autoBidVaultInfos_1.next()) {
618
- autoBidVaultInfo = autoBidVaultInfos_1_1.value;
619
- _loop_2(autoBidVaultInfo);
620
- }
621
- }
622
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
623
- finally {
624
- try {
625
- if (autoBidVaultInfos_1_1 && !autoBidVaultInfos_1_1.done && (_e = autoBidVaultInfos_1.return)) _e.call(autoBidVaultInfos_1);
626
- }
627
- finally { if (e_5) throw e_5.error; }
628
- }
629
- byOrdered = (0, lodash_1.orderBy)(__spreadArray(__spreadArray([], __read(bidsFromBidShares), false), __read(bidsFromStrategies), false), ["expiry", "tokenOrder", "periodOrder", "optionTypeOrder"], ["asc", "asc", "asc", "asc"]);
630
- return [2 /*return*/, byOrdered];
631
- }
632
- });
633
- }); };
634
- exports.fetchUserBids = fetchUserBids;
@@ -1,21 +0,0 @@
1
- export declare const WrappedToken: {
2
- [key: string]: string;
3
- };
4
- export declare const UnwrappedToken: {
5
- [key: string]: string;
6
- };
7
- export declare const MillionToken: {
8
- [key: string]: string;
9
- };
10
- export declare const RemoveMillionToken: {
11
- [key: string]: string;
12
- };
13
- export declare const LST: {
14
- [key: string]: string;
15
- };
16
- export declare const StableCoin: string[];
17
- export declare const getTokenName: ({ token, wrapped, million }: {
18
- token: string;
19
- wrapped?: boolean | undefined;
20
- million?: boolean | undefined;
21
- }) => string;