@typus/typus-sdk 1.4.29 → 1.4.30
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.
- package/dist/config-mainnet.json +1 -1
- package/dist/src/dice/fetch.js +1 -1
- package/dist/src/dice/user-entry.js +6 -6
- package/dist/src/dice/view-function.js +1 -1
- package/dist/src/typus-safu/user-history.d.ts +11 -0
- package/dist/src/typus-safu/user-history.js +256 -194
- package/dist/src/typus-safu/view-function.d.ts +2 -1
- package/dist/src/typus-safu/view-function.js +42 -11
- package/package.json +1 -1
package/dist/config-mainnet.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"ORACLE": "0x978f65df8570a075298598a9965c18de9087f9e888eb3430fe20334f5c554cfd",
|
|
21
21
|
"TYPUS": "0xea14501c603e8fcd907087d3aa7cb7adb4d7b3a7ea5e078cc9e8f05c67bc8034",
|
|
22
22
|
"PERP": "",
|
|
23
|
-
"SAFU": "
|
|
23
|
+
"SAFU": "0xee11b5672d83f474e1337d10b472dadc45ae827fb53843986a9d8a8b28c9dc77"
|
|
24
24
|
},
|
|
25
25
|
"VERSION": {
|
|
26
26
|
"TYPUS": "0xd2882b992e986250b3304b59530700bc3850939f9a77e9e9dfa9cf1656f84b3d",
|
package/dist/src/dice/fetch.js
CHANGED
|
@@ -151,7 +151,7 @@ function getHistory(config, input) {
|
|
|
151
151
|
break;
|
|
152
152
|
}
|
|
153
153
|
eventFilter = {
|
|
154
|
-
MoveEventType: "".concat(registry, "::").concat(module, "::Draw"),
|
|
154
|
+
MoveEventType: "".concat(registry, "::").concat(input.module, "::Draw"),
|
|
155
155
|
};
|
|
156
156
|
return [4 /*yield*/, provider.queryEvents({ query: eventFilter, order: "descending" })];
|
|
157
157
|
case 1:
|
|
@@ -82,7 +82,7 @@ function newGameTx(config, tx, input) {
|
|
|
82
82
|
break;
|
|
83
83
|
}
|
|
84
84
|
tx.moveCall({
|
|
85
|
-
target: "".concat(config.package.dice, "::").concat(module, "::new_game"),
|
|
85
|
+
target: "".concat(config.package.dice, "::").concat(input.module, "::new_game"),
|
|
86
86
|
typeArguments: input.typeArguments,
|
|
87
87
|
arguments: [
|
|
88
88
|
tx.object(registry),
|
|
@@ -123,7 +123,7 @@ function playGuessTx(config, tx, input) {
|
|
|
123
123
|
break;
|
|
124
124
|
}
|
|
125
125
|
tx.moveCall({
|
|
126
|
-
target: "".concat(config.package.dice, "::").concat(module, "::play_guess"),
|
|
126
|
+
target: "".concat(config.package.dice, "::").concat(input.module, "::play_guess"),
|
|
127
127
|
typeArguments: [],
|
|
128
128
|
arguments: [
|
|
129
129
|
tx.object(registry),
|
|
@@ -157,7 +157,7 @@ function newGamePlayGuessTx(config, tx, input) {
|
|
|
157
157
|
input.typeArguments[0] == "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI") {
|
|
158
158
|
_a = __read(tx.splitCoins(tx.gas, [tx.pure(input.amount)]), 1), coin = _a[0];
|
|
159
159
|
tx.moveCall({
|
|
160
|
-
target: "".concat(config.package.dice, "::").concat(module, "::new_game"),
|
|
160
|
+
target: "".concat(config.package.dice, "::").concat(input.module, "::new_game"),
|
|
161
161
|
typeArguments: input.typeArguments,
|
|
162
162
|
arguments: input.module == "combo_dice"
|
|
163
163
|
? [
|
|
@@ -172,7 +172,7 @@ function newGamePlayGuessTx(config, tx, input) {
|
|
|
172
172
|
}
|
|
173
173
|
else {
|
|
174
174
|
tx.moveCall({
|
|
175
|
-
target: "".concat(config.package.dice, "::").concat(module, "::new_game"),
|
|
175
|
+
target: "".concat(config.package.dice, "::").concat(input.module, "::new_game"),
|
|
176
176
|
typeArguments: input.typeArguments,
|
|
177
177
|
arguments: [
|
|
178
178
|
tx.object(registry),
|
|
@@ -183,7 +183,7 @@ function newGamePlayGuessTx(config, tx, input) {
|
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
185
|
tx.moveCall({
|
|
186
|
-
target: "".concat(config.package.dice, "::").concat(module, "::play_guess"),
|
|
186
|
+
target: "".concat(config.package.dice, "::").concat(input.module, "::play_guess"),
|
|
187
187
|
typeArguments: [],
|
|
188
188
|
arguments: [
|
|
189
189
|
tx.object(registry),
|
|
@@ -196,7 +196,7 @@ function newGamePlayGuessTx(config, tx, input) {
|
|
|
196
196
|
});
|
|
197
197
|
// TODO: waiting for upgrade
|
|
198
198
|
// tx.moveCall({
|
|
199
|
-
// target: `${packageId}::${module}::play_guess_with_random`,
|
|
199
|
+
// target: `${packageId}::${input.module}::play_guess_with_random`,
|
|
200
200
|
// typeArguments: module == "combo_dice" ? typeArguments : [],
|
|
201
201
|
// arguments: [
|
|
202
202
|
// tx.object(registry),
|
|
@@ -72,7 +72,7 @@ function simulateGame(config, input) {
|
|
|
72
72
|
break;
|
|
73
73
|
}
|
|
74
74
|
transactionBlock.moveCall({
|
|
75
|
-
target: "".concat(config.package.dice, "::").concat(module, "::simulate_game"),
|
|
75
|
+
target: "".concat(config.package.dice, "::").concat(input.module, "::simulate_game"),
|
|
76
76
|
typeArguments: [],
|
|
77
77
|
arguments: [
|
|
78
78
|
transactionBlock.object(registry),
|
|
@@ -4,9 +4,20 @@ export interface TxHistory {
|
|
|
4
4
|
Action: string;
|
|
5
5
|
Index: string;
|
|
6
6
|
Amount: string;
|
|
7
|
+
Token: string;
|
|
7
8
|
Exp: string | undefined;
|
|
8
9
|
Date: Date;
|
|
9
10
|
txDigest: string;
|
|
10
11
|
log: string[];
|
|
11
12
|
}
|
|
12
13
|
export declare function parseTxHistory(datas: Array<any>, originPackage: string): Promise<Array<TxHistory>>;
|
|
14
|
+
export declare function getDepositorCashFlows(userHistory: TxHistory[]): Map<string, DepositorCashFlow>;
|
|
15
|
+
export interface DepositorCashFlow {
|
|
16
|
+
D_TOKEN: string | undefined;
|
|
17
|
+
totalDeposit: number;
|
|
18
|
+
totalWithdraw: number;
|
|
19
|
+
totalClaim: number;
|
|
20
|
+
totalCompound: number;
|
|
21
|
+
netDeposit: number | undefined;
|
|
22
|
+
totalHarvest: Map<string, number>;
|
|
23
|
+
}
|
|
@@ -35,9 +35,39 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
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
|
+
};
|
|
38
65
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
66
|
exports.getUserEvents = getUserEvents;
|
|
40
67
|
exports.parseTxHistory = parseTxHistory;
|
|
68
|
+
exports.getDepositorCashFlows = getDepositorCashFlows;
|
|
69
|
+
var bcs_1 = require("@mysten/bcs");
|
|
70
|
+
var constants_1 = require("../../src/constants");
|
|
41
71
|
function getUserEvents(provider, sender, cursor) {
|
|
42
72
|
return __awaiter(this, void 0, void 0, function () {
|
|
43
73
|
var senderFilter, hasNextPage, datas, result;
|
|
@@ -91,7 +121,7 @@ function parseTxHistory(datas, originPackage // safu package
|
|
|
91
121
|
}
|
|
92
122
|
})
|
|
93
123
|
.reduce(function (promise, event) { return __awaiter(_this, void 0, void 0, function () {
|
|
94
|
-
var txHistory, action, log;
|
|
124
|
+
var txHistory, action, log, reader, Token, asset, decimal;
|
|
95
125
|
return __generator(this, function (_a) {
|
|
96
126
|
switch (_a.label) {
|
|
97
127
|
case 0: return [4 /*yield*/, promise];
|
|
@@ -99,77 +129,91 @@ function parseTxHistory(datas, originPackage // safu package
|
|
|
99
129
|
txHistory = _a.sent();
|
|
100
130
|
action = event.parsedJson.action;
|
|
101
131
|
log = event.parsedJson.log;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
132
|
+
// skip the event without tokenType
|
|
133
|
+
if (event.parsedJson.bcs_padding.length > 0) {
|
|
134
|
+
reader = new bcs_1.BcsReader(new Uint8Array(event.parsedJson.bcs_padding[0]));
|
|
135
|
+
Token = String.fromCharCode.apply(null, Array.from(reader.readBytes(reader.read8())));
|
|
136
|
+
asset = (0, constants_1.typeArgToAsset)(Token);
|
|
137
|
+
decimal = (0, constants_1.assetToDecimal)(asset);
|
|
138
|
+
// console.log(asset, decimal);
|
|
139
|
+
switch (action) {
|
|
140
|
+
case "raise_fund":
|
|
141
|
+
if (Number(log[2]) + Number(log[3]) + Number(log[4]) > 0) {
|
|
142
|
+
txHistory.push({
|
|
143
|
+
Action: "Deposit",
|
|
144
|
+
Index: log[0],
|
|
145
|
+
Amount: divByDecimal(Number(log[2]) + Number(log[3]) + Number(log[4]), decimal),
|
|
146
|
+
Token: Token,
|
|
147
|
+
Exp: log[6],
|
|
148
|
+
Date: new Date(Number(event.timestampMs)),
|
|
149
|
+
txDigest: event.id.txDigest,
|
|
150
|
+
log: log,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (Number(log[5]) > 0) {
|
|
154
|
+
txHistory.push({
|
|
155
|
+
Action: "Compound",
|
|
156
|
+
Index: log[0],
|
|
157
|
+
Amount: divByDecimal(Number(log[5]), decimal),
|
|
158
|
+
Token: Token,
|
|
159
|
+
Exp: log[6],
|
|
160
|
+
Date: new Date(Number(event.timestampMs)),
|
|
161
|
+
txDigest: event.id.txDigest,
|
|
162
|
+
log: log,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
break;
|
|
166
|
+
case "reduce_fund":
|
|
167
|
+
if (Number(log[2]) > 0) {
|
|
168
|
+
txHistory.push({
|
|
169
|
+
Action: "Withdraw",
|
|
170
|
+
Index: log[0],
|
|
171
|
+
Amount: divByDecimal(Number(log[2]), decimal),
|
|
172
|
+
Token: Token,
|
|
173
|
+
Exp: log[5],
|
|
174
|
+
Date: new Date(Number(event.timestampMs)),
|
|
175
|
+
txDigest: event.id.txDigest,
|
|
176
|
+
log: log,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
if (Number(log[3]) > 0) {
|
|
180
|
+
txHistory.push({
|
|
181
|
+
Action: "Unsubscribe",
|
|
182
|
+
Index: log[0],
|
|
183
|
+
Amount: divByDecimal(Number(log[3]), decimal),
|
|
184
|
+
Token: Token,
|
|
185
|
+
Exp: log[5],
|
|
186
|
+
Date: new Date(Number(event.timestampMs)),
|
|
187
|
+
txDigest: event.id.txDigest,
|
|
188
|
+
log: log,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
if (Number(log[4]) > 0) {
|
|
192
|
+
txHistory.push({
|
|
193
|
+
Action: "Claim",
|
|
194
|
+
Index: log[0],
|
|
195
|
+
Amount: divByDecimal(Number(log[4]), decimal),
|
|
196
|
+
Token: Token,
|
|
197
|
+
Exp: log[5],
|
|
198
|
+
Date: new Date(Number(event.timestampMs)),
|
|
199
|
+
txDigest: event.id.txDigest,
|
|
200
|
+
log: log,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
break;
|
|
204
|
+
case "claim_reward":
|
|
140
205
|
txHistory.push({
|
|
141
|
-
Action: "
|
|
206
|
+
Action: "Harvest Options Profit",
|
|
142
207
|
Index: log[0],
|
|
143
|
-
Amount: Number(log[
|
|
144
|
-
|
|
208
|
+
Amount: divByDecimal(Number(log[2]), decimal),
|
|
209
|
+
Token: Token,
|
|
210
|
+
Exp: undefined,
|
|
145
211
|
Date: new Date(Number(event.timestampMs)),
|
|
146
212
|
txDigest: event.id.txDigest,
|
|
147
213
|
log: log,
|
|
148
214
|
});
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
txHistory.push({
|
|
152
|
-
Action: "Claim",
|
|
153
|
-
Index: log[0],
|
|
154
|
-
Amount: Number(log[4]).toString(),
|
|
155
|
-
Exp: log[5],
|
|
156
|
-
Date: new Date(Number(event.timestampMs)),
|
|
157
|
-
txDigest: event.id.txDigest,
|
|
158
|
-
log: log,
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
break;
|
|
162
|
-
case "claim_reward":
|
|
163
|
-
txHistory.push({
|
|
164
|
-
Action: "Harvest Options Profit",
|
|
165
|
-
Index: log[0],
|
|
166
|
-
Amount: Number(log[2]).toString(),
|
|
167
|
-
Exp: undefined,
|
|
168
|
-
Date: new Date(Number(event.timestampMs)),
|
|
169
|
-
txDigest: event.id.txDigest,
|
|
170
|
-
log: log,
|
|
171
|
-
});
|
|
172
|
-
break;
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
173
217
|
}
|
|
174
218
|
return [2 /*return*/, txHistory];
|
|
175
219
|
}
|
|
@@ -182,131 +226,149 @@ function parseTxHistory(datas, originPackage // safu package
|
|
|
182
226
|
});
|
|
183
227
|
});
|
|
184
228
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
229
|
+
function divByDecimal(numerator, decimal) {
|
|
230
|
+
return (numerator / Math.pow(10, decimal)).toString();
|
|
231
|
+
}
|
|
232
|
+
function getDepositorCashFlows(userHistory) {
|
|
233
|
+
var e_1, _a, e_2, _b;
|
|
234
|
+
var depositorCashFlows = new Map();
|
|
235
|
+
try {
|
|
236
|
+
for (var userHistory_1 = __values(userHistory), userHistory_1_1 = userHistory_1.next(); !userHistory_1_1.done; userHistory_1_1 = userHistory_1.next()) {
|
|
237
|
+
var history_1 = userHistory_1_1.value;
|
|
238
|
+
var index = history_1.Index;
|
|
239
|
+
var _c = __read([history_1.Amount, history_1.Token], 2), amount = _c[0], token = _c[1];
|
|
240
|
+
if (history_1.Action == "Harvest Options Profit") {
|
|
241
|
+
if (depositorCashFlows.has(index)) {
|
|
242
|
+
var depositorCashFlow = depositorCashFlows.get(index);
|
|
243
|
+
var totalHarvest = depositorCashFlow.totalHarvest;
|
|
244
|
+
if (totalHarvest.has(token)) {
|
|
245
|
+
var sum = totalHarvest.get(token);
|
|
246
|
+
totalHarvest.set(token, sum + Number(amount));
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
totalHarvest.set(token, Number(amount));
|
|
250
|
+
}
|
|
251
|
+
depositorCashFlow.totalHarvest = totalHarvest;
|
|
252
|
+
depositorCashFlows.set(index, depositorCashFlow);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
var totalHarvest = new Map();
|
|
256
|
+
totalHarvest.set(token, Number(amount));
|
|
257
|
+
var depositorCashFlow = {
|
|
258
|
+
D_TOKEN: undefined,
|
|
259
|
+
totalDeposit: 0,
|
|
260
|
+
totalWithdraw: 0,
|
|
261
|
+
totalClaim: 0,
|
|
262
|
+
totalCompound: 0,
|
|
263
|
+
netDeposit: undefined,
|
|
264
|
+
totalHarvest: totalHarvest,
|
|
265
|
+
};
|
|
266
|
+
depositorCashFlows.set(index, depositorCashFlow);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else if (history_1.Action == "Deposit") {
|
|
270
|
+
if (depositorCashFlows.has(index)) {
|
|
271
|
+
var depositorCashFlow = depositorCashFlows.get(index);
|
|
272
|
+
depositorCashFlow.D_TOKEN = token;
|
|
273
|
+
depositorCashFlow.totalDeposit += Number(amount);
|
|
274
|
+
depositorCashFlows.set(index, depositorCashFlow);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
var depositorCashFlow = {
|
|
278
|
+
D_TOKEN: token,
|
|
279
|
+
totalDeposit: Number(amount),
|
|
280
|
+
totalWithdraw: 0,
|
|
281
|
+
totalClaim: 0,
|
|
282
|
+
totalCompound: 0,
|
|
283
|
+
netDeposit: undefined,
|
|
284
|
+
totalHarvest: new Map(),
|
|
285
|
+
};
|
|
286
|
+
depositorCashFlows.set(index, depositorCashFlow);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
else if (history_1.Action == "Withdraw") {
|
|
290
|
+
if (depositorCashFlows.has(index)) {
|
|
291
|
+
var depositorCashFlow = depositorCashFlows.get(index);
|
|
292
|
+
depositorCashFlow.D_TOKEN = token;
|
|
293
|
+
depositorCashFlow.totalWithdraw += Number(amount);
|
|
294
|
+
depositorCashFlows.set(index, depositorCashFlow);
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
var depositorCashFlow = {
|
|
298
|
+
D_TOKEN: token,
|
|
299
|
+
totalDeposit: 0,
|
|
300
|
+
totalWithdraw: Number(amount),
|
|
301
|
+
totalClaim: 0,
|
|
302
|
+
totalCompound: 0,
|
|
303
|
+
netDeposit: undefined,
|
|
304
|
+
totalHarvest: new Map(),
|
|
305
|
+
};
|
|
306
|
+
depositorCashFlows.set(index, depositorCashFlow);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else if (history_1.Action == "Claim") {
|
|
310
|
+
if (depositorCashFlows.has(index)) {
|
|
311
|
+
var depositorCashFlow = depositorCashFlows.get(index);
|
|
312
|
+
depositorCashFlow.D_TOKEN = token;
|
|
313
|
+
depositorCashFlow.totalClaim += Number(amount);
|
|
314
|
+
depositorCashFlows.set(index, depositorCashFlow);
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
var depositorCashFlow = {
|
|
318
|
+
D_TOKEN: token,
|
|
319
|
+
totalDeposit: 0,
|
|
320
|
+
totalWithdraw: 0,
|
|
321
|
+
totalClaim: Number(amount),
|
|
322
|
+
totalCompound: 0,
|
|
323
|
+
netDeposit: undefined,
|
|
324
|
+
totalHarvest: new Map(),
|
|
325
|
+
};
|
|
326
|
+
depositorCashFlows.set(index, depositorCashFlow);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
else if (history_1.Action == "Compound") {
|
|
330
|
+
if (depositorCashFlows.has(index)) {
|
|
331
|
+
var depositorCashFlow = depositorCashFlows.get(index);
|
|
332
|
+
depositorCashFlow.D_TOKEN = token;
|
|
333
|
+
depositorCashFlow.totalCompound += Number(amount);
|
|
334
|
+
depositorCashFlows.set(index, depositorCashFlow);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
var depositorCashFlow = {
|
|
338
|
+
D_TOKEN: token,
|
|
339
|
+
totalDeposit: 0,
|
|
340
|
+
totalWithdraw: 0,
|
|
341
|
+
totalClaim: 0,
|
|
342
|
+
totalCompound: Number(amount),
|
|
343
|
+
netDeposit: undefined,
|
|
344
|
+
totalHarvest: new Map(),
|
|
345
|
+
};
|
|
346
|
+
depositorCashFlows.set(index, depositorCashFlow);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
352
|
+
finally {
|
|
353
|
+
try {
|
|
354
|
+
if (userHistory_1_1 && !userHistory_1_1.done && (_a = userHistory_1.return)) _a.call(userHistory_1);
|
|
355
|
+
}
|
|
356
|
+
finally { if (e_1) throw e_1.error; }
|
|
357
|
+
}
|
|
358
|
+
try {
|
|
359
|
+
// console.log(depositorCashFlows);
|
|
360
|
+
for (var _d = __values(depositorCashFlows.entries()), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
361
|
+
var _f = __read(_e.value, 2), index = _f[0], share = _f[1];
|
|
362
|
+
share.netDeposit = share.totalDeposit + share.totalCompound - share.totalWithdraw - share.totalClaim;
|
|
363
|
+
depositorCashFlows.set(index, share);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
367
|
+
finally {
|
|
368
|
+
try {
|
|
369
|
+
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
370
|
+
}
|
|
371
|
+
finally { if (e_2) throw e_2.error; }
|
|
372
|
+
}
|
|
373
|
+
return depositorCashFlows;
|
|
374
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TypusConfig } from "../../src/utils";
|
|
2
|
+
import { TypusBidReceipt } from "../../src/auto-bid/view-function";
|
|
2
3
|
export interface Vault {
|
|
3
4
|
id: string;
|
|
4
5
|
depositToken: string;
|
|
@@ -42,7 +43,7 @@ export interface ShareSupply {
|
|
|
42
43
|
export declare function getVaultData(config: TypusConfig, input: {
|
|
43
44
|
indexes: string[];
|
|
44
45
|
}): Promise<{
|
|
45
|
-
[key: string]: Vault;
|
|
46
|
+
[key: string]: [Vault, TypusBidReceipt | null];
|
|
46
47
|
}>;
|
|
47
48
|
export interface Share {
|
|
48
49
|
user: string;
|
|
@@ -53,7 +53,9 @@ function getVaultData(config, input) {
|
|
|
53
53
|
transactionBlock = new transactions_1.TransactionBlock();
|
|
54
54
|
transactionBlock.moveCall({
|
|
55
55
|
target: "".concat(config.package.safu, "::view_function::get_vault_data_bcs"),
|
|
56
|
-
typeArguments: [
|
|
56
|
+
typeArguments: [
|
|
57
|
+
"".concat(config.package.framework, "::vault::TypusBidReceipt")
|
|
58
|
+
],
|
|
57
59
|
arguments: [transactionBlock.pure(config.registry.safu.safu), transactionBlock.pure(input.indexes)],
|
|
58
60
|
});
|
|
59
61
|
return [4 /*yield*/, provider.devInspectTransactionBlock({ sender: constants_1.SENDER, transactionBlock: transactionBlock })];
|
|
@@ -120,16 +122,45 @@ function getVaultData(config, input) {
|
|
|
120
122
|
var bcsPadding = reader.readVec(function (reader) {
|
|
121
123
|
return reader.read8();
|
|
122
124
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
125
|
+
var has_bid_receipt = reader.read8() > 0;
|
|
126
|
+
if (has_bid_receipt) {
|
|
127
|
+
result[info.index] = [
|
|
128
|
+
{
|
|
129
|
+
id: id,
|
|
130
|
+
depositToken: depositToken,
|
|
131
|
+
rewardToken: rewardToken,
|
|
132
|
+
info: info,
|
|
133
|
+
config: config,
|
|
134
|
+
shareSupply: shareSupply,
|
|
135
|
+
u64Padding: u64Padding,
|
|
136
|
+
bcsPadding: bcsPadding,
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: (0, utils_1.AddressFromBytes)(reader.readBytes(32)),
|
|
140
|
+
vid: (0, utils_1.AddressFromBytes)(reader.readBytes(32)),
|
|
141
|
+
index: reader.read64(),
|
|
142
|
+
metadata: String.fromCharCode.apply(null, Array.from(reader.readBytes(reader.read8()))),
|
|
143
|
+
u64_padding: reader.readVec(function (reader) {
|
|
144
|
+
return reader.read64();
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
];
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
result[info.index] = [
|
|
151
|
+
{
|
|
152
|
+
id: id,
|
|
153
|
+
depositToken: depositToken,
|
|
154
|
+
rewardToken: rewardToken,
|
|
155
|
+
info: info,
|
|
156
|
+
config: config,
|
|
157
|
+
shareSupply: shareSupply,
|
|
158
|
+
u64Padding: u64Padding,
|
|
159
|
+
bcsPadding: bcsPadding,
|
|
160
|
+
},
|
|
161
|
+
null
|
|
162
|
+
];
|
|
163
|
+
}
|
|
133
164
|
});
|
|
134
165
|
return [2 /*return*/, result];
|
|
135
166
|
}
|