@typus/typus-sdk 1.2.30 → 1.2.32

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.
@@ -137,23 +137,43 @@ registry, strategy_pool, vault_index, signal_index, strategy_index, coins, amoun
137
137
  // B_TOKEN
138
138
  typeArguments[1] == "0x2::sui::SUI" ||
139
139
  typeArguments[1] == "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI") {
140
- var _a = __read(amount ? tx.splitCoins(tx.gas, [tx.pure(amount)]) : [tx.pure([])], 1), input_coin = _a[0];
141
- tx.moveCall({
142
- target: "".concat(packageId, "::auto_bid::update_strategy"),
143
- typeArguments: typeArguments,
144
- arguments: [
145
- tx.object(registry),
146
- tx.object(strategy_pool),
147
- tx.pure(vault_index),
148
- tx.pure(signal_index),
149
- tx.pure(strategy_index),
150
- tx.pure(size ? [size] : []),
151
- tx.pure(price_percentage ? [price_percentage] : []),
152
- tx.pure(max_times ? [max_times] : []),
153
- tx.pure(target_rounds),
154
- input_coin,
155
- ],
156
- });
140
+ if (amount) {
141
+ var _a = __read(tx.splitCoins(tx.gas, [tx.pure(amount)]), 1), input_coin = _a[0];
142
+ tx.moveCall({
143
+ target: "".concat(packageId, "::auto_bid::update_strategy"),
144
+ typeArguments: typeArguments,
145
+ arguments: [
146
+ tx.object(registry),
147
+ tx.object(strategy_pool),
148
+ tx.pure(vault_index),
149
+ tx.pure(signal_index),
150
+ tx.pure(strategy_index),
151
+ tx.pure(size ? [size] : []),
152
+ tx.pure(price_percentage ? [price_percentage] : []),
153
+ tx.pure(max_times ? [max_times] : []),
154
+ tx.pure(target_rounds),
155
+ tx.makeMoveVec({ objects: [input_coin] }),
156
+ ],
157
+ });
158
+ }
159
+ else {
160
+ tx.moveCall({
161
+ target: "".concat(packageId, "::auto_bid::update_strategy"),
162
+ typeArguments: typeArguments,
163
+ arguments: [
164
+ tx.object(registry),
165
+ tx.object(strategy_pool),
166
+ tx.pure(vault_index),
167
+ tx.pure(signal_index),
168
+ tx.pure(strategy_index),
169
+ tx.pure(size ? [size] : []),
170
+ tx.pure(price_percentage ? [price_percentage] : []),
171
+ tx.pure(max_times ? [max_times] : []),
172
+ tx.pure(target_rounds),
173
+ tx.makeMoveVec({ objects: [] }),
174
+ ],
175
+ });
176
+ }
157
177
  }
158
178
  else {
159
179
  var coin = coins.pop();
@@ -89,7 +89,10 @@ function getLatestPrice(pair) {
89
89
  return [4 /*yield*/, getPairPrices(pair, minuteAgo.toString(), currentTimestampInSeconds.toString())];
90
90
  case 1:
91
91
  res = _a.sent();
92
- return [2 /*return*/, res.at(-1).price];
92
+ if (res.at(-1)) {
93
+ return [2 /*return*/, res.at(-1).price];
94
+ }
95
+ return [2 /*return*/, "0"];
93
96
  }
94
97
  });
95
98
  });
@@ -0,0 +1,12 @@
1
+ import { TxHistory } from "../../utils/typus-dov-single-v2/user-history";
2
+ export declare function getDepositorCashFlows(userHistory: TxHistory[]): Promise<Map<string, DepositorCashFlow>>;
3
+ interface DepositorCashFlow {
4
+ D_TOKEN: string | undefined;
5
+ totalDeposit: number;
6
+ totalWithdraw: number;
7
+ totalClaim: number;
8
+ totalCompound: number;
9
+ netDeposit: number | undefined;
10
+ totalHarvest: Map<string, number>;
11
+ }
12
+ export {};
@@ -0,0 +1,220 @@
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 __values = (this && this.__values) || function(o) {
39
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
+ if (m) return m.call(o);
41
+ if (o && typeof o.length === "number") return {
42
+ next: function () {
43
+ if (o && i >= o.length) o = void 0;
44
+ return { value: o && o[i++], done: !o };
45
+ }
46
+ };
47
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
+ };
49
+ var __read = (this && this.__read) || function (o, n) {
50
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
51
+ if (!m) return o;
52
+ var i = m.call(o), r, ar = [], e;
53
+ try {
54
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
55
+ }
56
+ catch (error) { e = { error: error }; }
57
+ finally {
58
+ try {
59
+ if (r && !r.done && (m = i["return"])) m.call(i);
60
+ }
61
+ finally { if (e) throw e.error; }
62
+ }
63
+ return ar;
64
+ };
65
+ Object.defineProperty(exports, "__esModule", { value: true });
66
+ exports.getDepositorCashFlows = void 0;
67
+ function getDepositorCashFlows(userHistory) {
68
+ var _a, _b, _c, _d, _e;
69
+ return __awaiter(this, void 0, void 0, function () {
70
+ var depositorCashFlows, userHistory_1, userHistory_1_1, history_1, index, _f, amount, token, depositorCashFlow, totalHarvest, sum, totalHarvest, depositorCashFlow, _g, amount, token, depositorCashFlow, depositorCashFlow, _h, amount, token, depositorCashFlow, depositorCashFlow, _j, amount, token, depositorCashFlow, depositorCashFlow, _k, amount, token, depositorCashFlow, depositorCashFlow, _l, _m, _o, index, share;
71
+ var e_1, _p, e_2, _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
+ _f = __read((_a = history_1.Amount) === null || _a === void 0 ? void 0 : _a.split(" "), 2), amount = _f[0], token = _f[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
+ _g = __read((_b = history_1.Amount) === null || _b === void 0 ? void 0 : _b.split(" "), 2), amount = _g[0], token = _g[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
+ _h = __read((_c = history_1.Amount) === null || _c === void 0 ? void 0 : _c.split(" "), 2), amount = _h[0], token = _h[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
+ _j = __read((_d = history_1.Amount) === null || _d === void 0 ? void 0 : _d.split(" "), 2), amount = _j[0], token = _j[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
+ }
170
+ }
171
+ else if (history_1.Action == "Compound") {
172
+ _k = __read((_e = history_1.Amount) === null || _e === void 0 ? void 0 : _e.split(" "), 2), amount = _k[0], token = _k[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
+ }
191
+ }
192
+ }
193
+ }
194
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
195
+ finally {
196
+ try {
197
+ if (userHistory_1_1 && !userHistory_1_1.done && (_p = userHistory_1.return)) _p.call(userHistory_1);
198
+ }
199
+ finally { if (e_1) throw e_1.error; }
200
+ }
201
+ try {
202
+ // console.log(depositorCashFlows);
203
+ for (_l = __values(depositorCashFlows.entries()), _m = _l.next(); !_m.done; _m = _l.next()) {
204
+ _o = __read(_m.value, 2), index = _o[0], share = _o[1];
205
+ share.netDeposit = share.totalDeposit + share.totalCompound - share.totalWithdraw - share.totalClaim;
206
+ depositorCashFlows.set(index, share);
207
+ }
208
+ }
209
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
210
+ finally {
211
+ try {
212
+ if (_m && !_m.done && (_q = _l.return)) _q.call(_l);
213
+ }
214
+ finally { if (e_2) throw e_2.error; }
215
+ }
216
+ return [2 /*return*/, depositorCashFlows];
217
+ });
218
+ });
219
+ }
220
+ 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.30",
5
+ "version": "1.2.32",
6
6
  "dependencies": {
7
7
  "@mysten/bcs": "^0.7.3",
8
8
  "@mysten/kiosk": "0.7.12",