@typus/typus-sdk 1.2.54 → 1.2.55

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,5 +1,5 @@
1
1
  import { TxHistory } from "../../utils/typus-dov-single-v2/user-history";
2
- export declare function getDepositorCashFlows(userHistory: TxHistory[]): Promise<Map<string, DepositorCashFlow>>;
2
+ export declare function getDepositorCashFlows(userHistory: TxHistory[]): Map<string, DepositorCashFlow>;
3
3
  interface DepositorCashFlow {
4
4
  D_TOKEN: string | undefined;
5
5
  totalDeposit: number;
@@ -1,40 +1,4 @@
1
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
2
  var __values = (this && this.__values) || function(o) {
39
3
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
4
  if (m) return m.call(o);
@@ -65,156 +29,151 @@ var __read = (this && this.__read) || function (o, n) {
65
29
  Object.defineProperty(exports, "__esModule", { value: true });
66
30
  exports.getDepositorCashFlows = void 0;
67
31
  function getDepositorCashFlows(userHistory) {
68
- return __awaiter(this, void 0, void 0, function () {
69
- var depositorCashFlows, userHistory_1, userHistory_1_1, history_1, index, _a, amount, token, depositorCashFlow, totalHarvest, sum, totalHarvest, depositorCashFlow, _b, amount, token, depositorCashFlow, depositorCashFlow, _c, amount, token, depositorCashFlow, depositorCashFlow, _d, amount, token, depositorCashFlow, depositorCashFlow, _e, amount, token, depositorCashFlow, depositorCashFlow, _f, _g, _h, index, share;
70
- var e_1, _j, e_2, _k;
71
- var _l, _m, _o, _p, _q;
72
- return __generator(this, function (_r) {
73
- depositorCashFlows = new Map();
74
- try {
75
- for (userHistory_1 = __values(userHistory), userHistory_1_1 = userHistory_1.next(); !userHistory_1_1.done; userHistory_1_1 = userHistory_1.next()) {
76
- history_1 = userHistory_1_1.value;
77
- index = history_1.Index;
78
- if (history_1.Action.startsWith("Harvest")) {
79
- _a = __read((_l = history_1.Amount) === null || _l === void 0 ? void 0 : _l.split(" "), 2), amount = _a[0], token = _a[1];
80
- if (depositorCashFlows.has(index)) {
81
- depositorCashFlow = depositorCashFlows.get(index);
82
- totalHarvest = depositorCashFlow.totalHarvest;
83
- if (totalHarvest.has(token)) {
84
- sum = totalHarvest.get(token);
85
- totalHarvest.set(token, sum + Number(amount));
86
- }
87
- else {
88
- totalHarvest.set(token, Number(amount));
89
- }
90
- depositorCashFlow.totalHarvest = totalHarvest;
91
- depositorCashFlows.set(index, depositorCashFlow);
92
- }
93
- else {
94
- totalHarvest = new Map();
95
- totalHarvest.set(token, Number(amount));
96
- depositorCashFlow = {
97
- D_TOKEN: undefined,
98
- totalDeposit: 0,
99
- totalWithdraw: 0,
100
- totalClaim: 0,
101
- totalCompound: 0,
102
- netDeposit: undefined,
103
- totalHarvest: totalHarvest,
104
- };
105
- depositorCashFlows.set(index, depositorCashFlow);
106
- }
107
- }
108
- else if (history_1.Action.startsWith("Deposit")) {
109
- _b = __read((_m = history_1.Amount) === null || _m === void 0 ? void 0 : _m.split(" "), 2), amount = _b[0], token = _b[1];
110
- if (depositorCashFlows.has(index)) {
111
- depositorCashFlow = depositorCashFlows.get(index);
112
- depositorCashFlow.D_TOKEN = token;
113
- depositorCashFlow.totalDeposit += Number(amount);
114
- depositorCashFlows.set(index, depositorCashFlow);
115
- }
116
- else {
117
- depositorCashFlow = {
118
- D_TOKEN: token,
119
- totalDeposit: Number(amount),
120
- totalWithdraw: 0,
121
- totalClaim: 0,
122
- totalCompound: 0,
123
- netDeposit: undefined,
124
- totalHarvest: new Map(),
125
- };
126
- depositorCashFlows.set(index, depositorCashFlow);
127
- }
128
- }
129
- else if (history_1.Action.startsWith("Withdraw")) {
130
- _c = __read((_o = history_1.Amount) === null || _o === void 0 ? void 0 : _o.split(" "), 2), amount = _c[0], token = _c[1];
131
- if (depositorCashFlows.has(index)) {
132
- depositorCashFlow = depositorCashFlows.get(index);
133
- depositorCashFlow.D_TOKEN = token;
134
- depositorCashFlow.totalWithdraw += Number(amount);
135
- depositorCashFlows.set(index, depositorCashFlow);
136
- }
137
- else {
138
- depositorCashFlow = {
139
- D_TOKEN: token,
140
- totalDeposit: 0,
141
- totalWithdraw: Number(amount),
142
- totalClaim: 0,
143
- totalCompound: 0,
144
- netDeposit: undefined,
145
- totalHarvest: new Map(),
146
- };
147
- depositorCashFlows.set(index, depositorCashFlow);
148
- }
149
- }
150
- else if (history_1.Action == "Claim") {
151
- _d = __read((_p = history_1.Amount) === null || _p === void 0 ? void 0 : _p.split(" "), 2), amount = _d[0], token = _d[1];
152
- if (depositorCashFlows.has(index)) {
153
- depositorCashFlow = depositorCashFlows.get(index);
154
- depositorCashFlow.D_TOKEN = token;
155
- depositorCashFlow.totalClaim += Number(amount);
156
- depositorCashFlows.set(index, depositorCashFlow);
157
- }
158
- else {
159
- depositorCashFlow = {
160
- D_TOKEN: token,
161
- totalDeposit: 0,
162
- totalWithdraw: 0,
163
- totalClaim: Number(amount),
164
- totalCompound: 0,
165
- netDeposit: undefined,
166
- totalHarvest: new Map(),
167
- };
168
- depositorCashFlows.set(index, depositorCashFlow);
169
- }
32
+ var e_1, _a, e_2, _b;
33
+ var _c, _d, _e, _f, _g;
34
+ var depositorCashFlows = new Map();
35
+ try {
36
+ for (var userHistory_1 = __values(userHistory), userHistory_1_1 = userHistory_1.next(); !userHistory_1_1.done; userHistory_1_1 = userHistory_1.next()) {
37
+ var history_1 = userHistory_1_1.value;
38
+ var index = history_1.Index;
39
+ if (history_1.Action.startsWith("Harvest")) {
40
+ var _h = __read((_c = history_1.Amount) === null || _c === void 0 ? void 0 : _c.split(" "), 2), amount = _h[0], token = _h[1];
41
+ if (depositorCashFlows.has(index)) {
42
+ var depositorCashFlow = depositorCashFlows.get(index);
43
+ var totalHarvest = depositorCashFlow.totalHarvest;
44
+ if (totalHarvest.has(token)) {
45
+ var sum = totalHarvest.get(token);
46
+ totalHarvest.set(token, sum + Number(amount));
170
47
  }
171
- else if (history_1.Action == "Compound") {
172
- _e = __read((_q = history_1.Amount) === null || _q === void 0 ? void 0 : _q.split(" "), 2), amount = _e[0], token = _e[1];
173
- if (depositorCashFlows.has(index)) {
174
- depositorCashFlow = depositorCashFlows.get(index);
175
- depositorCashFlow.D_TOKEN = token;
176
- depositorCashFlow.totalCompound += Number(amount);
177
- depositorCashFlows.set(index, depositorCashFlow);
178
- }
179
- else {
180
- depositorCashFlow = {
181
- D_TOKEN: token,
182
- totalDeposit: 0,
183
- totalWithdraw: 0,
184
- totalClaim: 0,
185
- totalCompound: Number(amount),
186
- netDeposit: undefined,
187
- totalHarvest: new Map(),
188
- };
189
- depositorCashFlows.set(index, depositorCashFlow);
190
- }
48
+ else {
49
+ totalHarvest.set(token, Number(amount));
191
50
  }
51
+ depositorCashFlow.totalHarvest = totalHarvest;
52
+ depositorCashFlows.set(index, depositorCashFlow);
53
+ }
54
+ else {
55
+ var totalHarvest = new Map();
56
+ totalHarvest.set(token, Number(amount));
57
+ var depositorCashFlow = {
58
+ D_TOKEN: undefined,
59
+ totalDeposit: 0,
60
+ totalWithdraw: 0,
61
+ totalClaim: 0,
62
+ totalCompound: 0,
63
+ netDeposit: undefined,
64
+ totalHarvest: totalHarvest,
65
+ };
66
+ depositorCashFlows.set(index, depositorCashFlow);
192
67
  }
193
68
  }
194
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
195
- finally {
196
- try {
197
- if (userHistory_1_1 && !userHistory_1_1.done && (_j = userHistory_1.return)) _j.call(userHistory_1);
69
+ else if (history_1.Action.startsWith("Deposit")) {
70
+ var _j = __read((_d = history_1.Amount) === null || _d === void 0 ? void 0 : _d.split(" "), 2), amount = _j[0], token = _j[1];
71
+ if (depositorCashFlows.has(index)) {
72
+ var depositorCashFlow = depositorCashFlows.get(index);
73
+ depositorCashFlow.D_TOKEN = token;
74
+ depositorCashFlow.totalDeposit += Number(amount);
75
+ depositorCashFlows.set(index, depositorCashFlow);
76
+ }
77
+ else {
78
+ var depositorCashFlow = {
79
+ D_TOKEN: token,
80
+ totalDeposit: Number(amount),
81
+ totalWithdraw: 0,
82
+ totalClaim: 0,
83
+ totalCompound: 0,
84
+ netDeposit: undefined,
85
+ totalHarvest: new Map(),
86
+ };
87
+ depositorCashFlows.set(index, depositorCashFlow);
198
88
  }
199
- finally { if (e_1) throw e_1.error; }
200
89
  }
201
- try {
202
- // console.log(depositorCashFlows);
203
- for (_f = __values(depositorCashFlows.entries()), _g = _f.next(); !_g.done; _g = _f.next()) {
204
- _h = __read(_g.value, 2), index = _h[0], share = _h[1];
205
- share.netDeposit = share.totalDeposit + share.totalCompound - share.totalWithdraw - share.totalClaim;
206
- depositorCashFlows.set(index, share);
90
+ else if (history_1.Action.startsWith("Withdraw")) {
91
+ var _k = __read((_e = history_1.Amount) === null || _e === void 0 ? void 0 : _e.split(" "), 2), amount = _k[0], token = _k[1];
92
+ if (depositorCashFlows.has(index)) {
93
+ var depositorCashFlow = depositorCashFlows.get(index);
94
+ depositorCashFlow.D_TOKEN = token;
95
+ depositorCashFlow.totalWithdraw += Number(amount);
96
+ depositorCashFlows.set(index, depositorCashFlow);
97
+ }
98
+ else {
99
+ var depositorCashFlow = {
100
+ D_TOKEN: token,
101
+ totalDeposit: 0,
102
+ totalWithdraw: Number(amount),
103
+ totalClaim: 0,
104
+ totalCompound: 0,
105
+ netDeposit: undefined,
106
+ totalHarvest: new Map(),
107
+ };
108
+ depositorCashFlows.set(index, depositorCashFlow);
109
+ }
110
+ }
111
+ else if (history_1.Action == "Claim") {
112
+ var _l = __read((_f = history_1.Amount) === null || _f === void 0 ? void 0 : _f.split(" "), 2), amount = _l[0], token = _l[1];
113
+ if (depositorCashFlows.has(index)) {
114
+ var depositorCashFlow = depositorCashFlows.get(index);
115
+ depositorCashFlow.D_TOKEN = token;
116
+ depositorCashFlow.totalClaim += Number(amount);
117
+ depositorCashFlows.set(index, depositorCashFlow);
118
+ }
119
+ else {
120
+ var depositorCashFlow = {
121
+ D_TOKEN: token,
122
+ totalDeposit: 0,
123
+ totalWithdraw: 0,
124
+ totalClaim: Number(amount),
125
+ totalCompound: 0,
126
+ netDeposit: undefined,
127
+ totalHarvest: new Map(),
128
+ };
129
+ depositorCashFlows.set(index, depositorCashFlow);
207
130
  }
208
131
  }
209
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
210
- finally {
211
- try {
212
- if (_g && !_g.done && (_k = _f.return)) _k.call(_f);
132
+ else if (history_1.Action == "Compound") {
133
+ var _m = __read((_g = history_1.Amount) === null || _g === void 0 ? void 0 : _g.split(" "), 2), amount = _m[0], token = _m[1];
134
+ if (depositorCashFlows.has(index)) {
135
+ var depositorCashFlow = depositorCashFlows.get(index);
136
+ depositorCashFlow.D_TOKEN = token;
137
+ depositorCashFlow.totalCompound += Number(amount);
138
+ depositorCashFlows.set(index, depositorCashFlow);
139
+ }
140
+ else {
141
+ var depositorCashFlow = {
142
+ D_TOKEN: token,
143
+ totalDeposit: 0,
144
+ totalWithdraw: 0,
145
+ totalClaim: 0,
146
+ totalCompound: Number(amount),
147
+ netDeposit: undefined,
148
+ totalHarvest: new Map(),
149
+ };
150
+ depositorCashFlows.set(index, depositorCashFlow);
213
151
  }
214
- finally { if (e_2) throw e_2.error; }
215
152
  }
216
- return [2 /*return*/, depositorCashFlows];
217
- });
218
- });
153
+ }
154
+ }
155
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
156
+ finally {
157
+ try {
158
+ if (userHistory_1_1 && !userHistory_1_1.done && (_a = userHistory_1.return)) _a.call(userHistory_1);
159
+ }
160
+ finally { if (e_1) throw e_1.error; }
161
+ }
162
+ try {
163
+ // console.log(depositorCashFlows);
164
+ for (var _o = __values(depositorCashFlows.entries()), _p = _o.next(); !_p.done; _p = _o.next()) {
165
+ var _q = __read(_p.value, 2), index = _q[0], share = _q[1];
166
+ share.netDeposit = share.totalDeposit + share.totalCompound - share.totalWithdraw - share.totalClaim;
167
+ depositorCashFlows.set(index, share);
168
+ }
169
+ }
170
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
171
+ finally {
172
+ try {
173
+ if (_p && !_p.done && (_b = _o.return)) _b.call(_o);
174
+ }
175
+ finally { if (e_2) throw e_2.error; }
176
+ }
177
+ return depositorCashFlows;
219
178
  }
220
179
  exports.getDepositorCashFlows = getDepositorCashFlows;
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.2.54",
5
+ "version": "1.2.55",
6
6
  "dependencies": {
7
7
  "@mysten/bcs": "^0.7.3",
8
8
  "@mysten/kiosk": "0.7.12",