@typus/typus-sdk 1.9.3 → 1.9.4

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,3 +1,4 @@
1
+ import { Event } from "../../src/utils";
1
2
  export interface TxHistory {
2
3
  Action: string;
3
4
  Index: string;
@@ -8,4 +9,4 @@ export interface TxHistory {
8
9
  txDigest: string;
9
10
  log: string[];
10
11
  }
11
- export declare function parseTxHistory(datas: Array<any>): Promise<Array<TxHistory>>;
12
+ export declare function parseTxHistory(datas: Array<Event>): Promise<Array<TxHistory>>;
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.parseTxHistory = parseTxHistory;
40
- var bcs_1 = require("@mysten/bcs");
40
+ var bcs_1 = require("@mysten/sui/bcs");
41
41
  var constants_1 = require("../../src/constants");
42
42
  function parseTxHistory(datas) {
43
43
  return __awaiter(this, void 0, void 0, function () {
@@ -47,27 +47,29 @@ function parseTxHistory(datas) {
47
47
  switch (_a.label) {
48
48
  case 0: return [4 /*yield*/, datas
49
49
  .filter(function (event) {
50
- return event.type == "0x15f0d9c093179f38ec90b20ac336750f82921730c25fed63e951d37a1a542bf0::event::UserEvent";
50
+ var _a, _b;
51
+ return ((_b = (_a = event.contents) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.repr) == "0x15f0d9c093179f38ec90b20ac336750f82921730c25fed63e951d37a1a542bf0::event::UserEvent";
51
52
  })
52
53
  .sort(function (a, b) {
53
54
  // From Old to New!
54
- if (a.timestampMs == b.timestampMs) {
55
- return Number(a.id.eventSeq) - Number(b.id.eventSeq);
55
+ if (a.timestamp == b.timestamp) {
56
+ return Number(a.sequenceNumber) - Number(b.sequenceNumber);
56
57
  }
57
58
  else {
58
- return Number(a.timestampMs) - Number(b.timestampMs);
59
+ return Number(a.timestamp) - Number(b.timestamp);
59
60
  }
60
61
  })
61
62
  .reduce(function (promise, event) { return __awaiter(_this, void 0, void 0, function () {
62
63
  var txHistory, action, log, bcs_padding, mainToken, mainTokenDecimal, hedgeToken, hedgeTokenDecimal, mainTokenAmount, hedgeTokenAmount, mainTokenWarmupAmount, hedgeTokenWarmupAmount, mainTokenActiveAmount, hedgeTokenActiveAmount;
63
- return __generator(this, function (_a) {
64
- switch (_a.label) {
64
+ var _a, _b, _c;
65
+ return __generator(this, function (_d) {
66
+ switch (_d.label) {
65
67
  case 0: return [4 /*yield*/, promise];
66
68
  case 1:
67
- txHistory = _a.sent();
68
- action = event.parsedJson.action;
69
- log = toMap(event.parsedJson.log.contents);
70
- bcs_padding = toMap(event.parsedJson.bcs_padding.contents);
69
+ txHistory = _d.sent();
70
+ action = event.contents.json.action;
71
+ log = toMap(event.contents.json.log.contents);
72
+ bcs_padding = toMap(event.contents.json.bcs_padding);
71
73
  // console.log(action, log, bcs_padding, bcs_padding.size);
72
74
  if (bcs_padding.size == 0) {
73
75
  return [2 /*return*/, txHistory];
@@ -87,8 +89,9 @@ function parseTxHistory(datas) {
87
89
  Amount: [mainTokenAmount, hedgeTokenAmount],
88
90
  Token: [mainToken, hedgeToken],
89
91
  Exp: log.get("exps"),
90
- Date: new Date(Number(event.timestampMs)),
91
- txDigest: event.id.txDigest,
92
+ Date: new Date(Number(event.timestamp)),
93
+ //@ts-ignore
94
+ txDigest: (_a = event.transaction) === null || _a === void 0 ? void 0 : _a.digest,
92
95
  log: [],
93
96
  });
94
97
  break;
@@ -102,8 +105,9 @@ function parseTxHistory(datas) {
102
105
  Amount: [mainTokenWarmupAmount, hedgeTokenWarmupAmount],
103
106
  Token: [mainToken, hedgeToken],
104
107
  Exp: log.get("exps"),
105
- Date: new Date(Number(event.timestampMs)),
106
- txDigest: event.id.txDigest,
108
+ Date: new Date(Number(event.timestamp)),
109
+ //@ts-ignore
110
+ txDigest: (_b = event.transaction) === null || _b === void 0 ? void 0 : _b.digest,
107
111
  log: [],
108
112
  });
109
113
  }
@@ -116,8 +120,9 @@ function parseTxHistory(datas) {
116
120
  Amount: [mainTokenActiveAmount, hedgeTokenActiveAmount],
117
121
  Token: [mainToken, hedgeToken],
118
122
  Exp: log["exps"],
119
- Date: new Date(Number(event.timestampMs)),
120
- txDigest: event.id.txDigest,
123
+ Date: new Date(Number(event.timestamp)),
124
+ //@ts-ignore
125
+ txDigest: (_c = event.transaction) === null || _c === void 0 ? void 0 : _c.digest,
121
126
  log: [],
122
127
  });
123
128
  }
@@ -1,3 +1,4 @@
1
+ import { Event } from "../../src/utils";
1
2
  export interface TxHistory {
2
3
  Action: string;
3
4
  Index: string;
@@ -8,7 +9,7 @@ export interface TxHistory {
8
9
  txDigest: string;
9
10
  log: string[];
10
11
  }
11
- export declare function parseTxHistory(datas: Array<any>): Promise<Array<TxHistory>>;
12
+ export declare function parseTxHistory(datas: Event[]): Promise<Array<TxHistory>>;
12
13
  export declare function getDepositorCashFlows(userHistory: TxHistory[]): Map<string, DepositorCashFlow>;
13
14
  export interface DepositorCashFlow {
14
15
  D_TOKEN: string | undefined;
@@ -69,6 +69,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
69
69
  exports.parseTxHistory = parseTxHistory;
70
70
  exports.getDepositorCashFlows = getDepositorCashFlows;
71
71
  var bcs_1 = require("@mysten/bcs");
72
+ var bcs_2 = require("@mysten/sui/bcs");
72
73
  var constants_1 = require("../../src/constants");
73
74
  var bignumber_js_1 = __importDefault(require("bignumber.js"));
74
75
  function parseTxHistory(datas) {
@@ -77,173 +78,190 @@ function parseTxHistory(datas) {
77
78
  var _this = this;
78
79
  return __generator(this, function (_a) {
79
80
  switch (_a.label) {
80
- case 0: return [4 /*yield*/, datas
81
- .filter(function (event) {
82
- return (event.type.includes("safu") ||
83
- event.type == "0x7dab89563066afa000ee154738aac2cc8e7d3e26cd0b470183db63630ee9f965::funding_vault::RaiseFundEvent");
84
- })
85
- .sort(function (a, b) {
86
- // From Old to New!
87
- if (a.timestampMs == b.timestampMs) {
88
- return Number(a.id.eventSeq) - Number(b.id.eventSeq);
89
- }
90
- else {
91
- return Number(a.timestampMs) - Number(b.timestampMs);
92
- }
93
- })
94
- .reduce(function (promise, event) { return __awaiter(_this, void 0, void 0, function () {
95
- var txHistory, log_1, action, log, reader, Token, asset, decimal, totalWithdrawAmount;
96
- return __generator(this, function (_a) {
97
- switch (_a.label) {
98
- case 0: return [4 /*yield*/, promise];
99
- case 1:
100
- txHistory = _a.sent();
101
- // console.log(event);
102
- if (event.type == "0x7dab89563066afa000ee154738aac2cc8e7d3e26cd0b470183db63630ee9f965::funding_vault::RaiseFundEvent") {
103
- log_1 = event.parsedJson.log;
104
- if (log_1.length > 1) {
105
- txHistory.push({
106
- Action: "Deposit",
107
- Index: "deepbook/".concat(log_1[0]),
108
- Amount: divByDecimal(Number(log_1[1]), 9),
109
- Token: event.parsedJson.token.name,
110
- Exp: undefined,
111
- Date: new Date(Number(event.timestampMs)),
112
- txDigest: event.id.txDigest,
113
- log: log_1,
114
- });
115
- }
116
- else {
117
- txHistory.push({
118
- Action: "Deposit",
119
- Index: "deepbook/0",
120
- Amount: divByDecimal(Number(log_1[0]), 9),
121
- Token: event.parsedJson.token.name,
122
- Exp: undefined,
123
- Date: new Date(Number(event.timestampMs)),
124
- txDigest: event.id.txDigest,
125
- log: log_1,
126
- });
81
+ case 0:
82
+ console.log(datas[0]);
83
+ return [4 /*yield*/, datas
84
+ .filter(function (event) {
85
+ var _a, _b, _c, _d;
86
+ return (((_b = (_a = event.contents) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.repr.includes("safu")) ||
87
+ ((_d = (_c = event.contents) === null || _c === void 0 ? void 0 : _c.type) === null || _d === void 0 ? void 0 : _d.repr) == "0x7dab89563066afa000ee154738aac2cc8e7d3e26cd0b470183db63630ee9f965::funding_vault::RaiseFundEvent");
88
+ })
89
+ .sort(function (a, b) {
90
+ // From Old to New!
91
+ if (a.timestamp == b.timestamp) {
92
+ return Number(a.sequenceNumber) - Number(b.sequenceNumber);
93
+ }
94
+ else {
95
+ return Number(a.timestamp) - Number(b.timestamp);
96
+ }
97
+ })
98
+ .reduce(function (promise, event) { return __awaiter(_this, void 0, void 0, function () {
99
+ var txHistory, log_1, action, log, reader, Token, asset, decimal, totalWithdrawAmount;
100
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
101
+ return __generator(this, function (_u) {
102
+ switch (_u.label) {
103
+ case 0: return [4 /*yield*/, promise];
104
+ case 1:
105
+ txHistory = _u.sent();
106
+ // console.log(event);
107
+ if (((_b = (_a = event.contents) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.repr) == "0x7dab89563066afa000ee154738aac2cc8e7d3e26cd0b470183db63630ee9f965::funding_vault::RaiseFundEvent") {
108
+ log_1 = (_d = (_c = event.contents) === null || _c === void 0 ? void 0 : _c.json) === null || _d === void 0 ? void 0 : _d.log;
109
+ if (log_1.length > 1) {
110
+ txHistory.push({
111
+ Action: "Deposit",
112
+ Index: "deepbook/".concat(log_1[0]),
113
+ Amount: divByDecimal(Number(log_1[1]), 9),
114
+ //@ts-ignore
115
+ Token: (_f = (_e = event.contents) === null || _e === void 0 ? void 0 : _e.json) === null || _f === void 0 ? void 0 : _f.token,
116
+ Exp: undefined,
117
+ Date: new Date(Number(event.timestamp)),
118
+ //@ts-ignore
119
+ txDigest: (_g = event.transaction) === null || _g === void 0 ? void 0 : _g.digest,
120
+ log: log_1,
121
+ });
122
+ }
123
+ else {
124
+ txHistory.push({
125
+ Action: "Deposit",
126
+ Index: "deepbook/0",
127
+ Amount: divByDecimal(Number(log_1[0]), 9),
128
+ //@ts-ignore
129
+ Token: (_j = (_h = event.contents) === null || _h === void 0 ? void 0 : _h.json) === null || _j === void 0 ? void 0 : _j.token,
130
+ Exp: undefined,
131
+ Date: new Date(Number(event.timestamp)),
132
+ //@ts-ignore
133
+ txDigest: (_k = event.transaction) === null || _k === void 0 ? void 0 : _k.digest,
134
+ log: log_1,
135
+ });
136
+ }
137
+ return [2 /*return*/, txHistory];
127
138
  }
128
- return [2 /*return*/, txHistory];
129
- }
130
- action = event.parsedJson.action;
131
- log = event.parsedJson.log;
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.readULEB())));
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
- // balance_value, deactivating_value, inactive_value,
142
- // Number(log[2]) + Number(log[3]) + Number(log[4])
143
- if (Number(log[2]) > 0) {
139
+ action = event.contents.json.action;
140
+ log = event.contents.json.log;
141
+ // skip the event without tokenType
142
+ //@ts-ignore
143
+ if (event.contents.json.bcs_padding.length > 0) {
144
+ reader = (0, bcs_1.fromBase64)(event.contents.json.bcs_padding[0]);
145
+ Token = bcs_2.bcs.string().parse(reader);
146
+ asset = (0, constants_1.typeArgToAsset)(Token);
147
+ decimal = (0, constants_1.assetToDecimal)(asset);
148
+ // console.log(asset, decimal);
149
+ switch (action) {
150
+ case "raise_fund":
151
+ // balance_value, deactivating_value, inactive_value,
152
+ // Number(log[2]) + Number(log[3]) + Number(log[4])
153
+ if (Number(log[2]) > 0) {
154
+ txHistory.push({
155
+ Action: "Deposit",
156
+ Index: log[0],
157
+ Amount: divByDecimal(Number(log[2]), decimal),
158
+ Token: Token,
159
+ Exp: log[6],
160
+ Date: new Date(Number(event.timestamp)),
161
+ //@ts-ignore
162
+ txDigest: (_l = event.transaction) === null || _l === void 0 ? void 0 : _l.digest,
163
+ log: log,
164
+ });
165
+ }
166
+ if (Number(log[3]) > 0) {
167
+ txHistory.push({
168
+ Action: "Subscribe",
169
+ Index: log[0],
170
+ Amount: divByDecimal(Number(log[3]), decimal),
171
+ Token: Token,
172
+ Exp: log[6],
173
+ Date: new Date(Number(event.timestamp)),
174
+ //@ts-ignore
175
+ txDigest: (_m = event.transaction) === null || _m === void 0 ? void 0 : _m.digest,
176
+ log: log,
177
+ });
178
+ }
179
+ if (Number(log[4]) > 0) {
180
+ txHistory.push({
181
+ Action: "Withdraw",
182
+ Index: log[0],
183
+ Amount: divByDecimal(Number(log[4]), decimal),
184
+ Token: Token,
185
+ Exp: log[6],
186
+ Date: new Date(Number(event.timestamp)),
187
+ //@ts-ignore
188
+ txDigest: (_o = event.transaction) === null || _o === void 0 ? void 0 : _o.digest,
189
+ log: log,
190
+ });
191
+ txHistory.push({
192
+ Action: "Deposit",
193
+ Index: log[0],
194
+ Amount: divByDecimal(Number(log[4]), decimal),
195
+ Token: Token,
196
+ Exp: undefined,
197
+ Date: new Date(Number(event.timestamp)),
198
+ //@ts-ignore
199
+ txDigest: (_p = event.transaction) === null || _p === void 0 ? void 0 : _p.digest,
200
+ log: log,
201
+ });
202
+ }
203
+ if (Number(log[5]) > 0) {
204
+ txHistory.push({
205
+ Action: "Compound",
206
+ Index: log[0],
207
+ Amount: divByDecimal(Number(log[5]), decimal),
208
+ Token: Token,
209
+ Exp: log[6],
210
+ Date: new Date(Number(event.timestamp)),
211
+ //@ts-ignore
212
+ txDigest: (_q = event.transaction) === null || _q === void 0 ? void 0 : _q.digest,
213
+ log: log,
214
+ });
215
+ }
216
+ break;
217
+ case "reduce_fund":
218
+ totalWithdrawAmount = (0, bignumber_js_1.default)(log[2]).plus(log[4]);
219
+ if (totalWithdrawAmount.gt(0)) {
220
+ txHistory.push({
221
+ Action: "Withdraw",
222
+ Index: log[0],
223
+ Amount: divByDecimal(totalWithdrawAmount.toNumber(), decimal),
224
+ Token: Token,
225
+ Exp: log[5],
226
+ Date: new Date(Number(event.timestamp)),
227
+ //@ts-ignore
228
+ txDigest: (_r = event.transaction) === null || _r === void 0 ? void 0 : _r.digest,
229
+ log: log,
230
+ });
231
+ }
232
+ if (Number(log[3]) > 0) {
233
+ txHistory.push({
234
+ Action: "Unsubscribe",
235
+ Index: log[0],
236
+ Amount: divByDecimal(Number(log[3]), decimal),
237
+ Token: Token,
238
+ Exp: log[5],
239
+ Date: new Date(Number(event.timestamp)),
240
+ //@ts-ignore
241
+ txDigest: (_s = event.transaction) === null || _s === void 0 ? void 0 : _s.digest,
242
+ log: log,
243
+ });
244
+ }
245
+ break;
246
+ case "claim_reward":
144
247
  txHistory.push({
145
- Action: "Deposit",
248
+ Action: "Harvest Options Profit",
146
249
  Index: log[0],
147
250
  Amount: divByDecimal(Number(log[2]), decimal),
148
251
  Token: Token,
149
- Exp: log[6],
150
- Date: new Date(Number(event.timestampMs)),
151
- txDigest: event.id.txDigest,
152
- log: log,
153
- });
154
- }
155
- if (Number(log[3]) > 0) {
156
- txHistory.push({
157
- Action: "Subscribe",
158
- Index: log[0],
159
- Amount: divByDecimal(Number(log[3]), decimal),
160
- Token: Token,
161
- Exp: log[6],
162
- Date: new Date(Number(event.timestampMs)),
163
- txDigest: event.id.txDigest,
164
- log: log,
165
- });
166
- }
167
- if (Number(log[4]) > 0) {
168
- txHistory.push({
169
- Action: "Withdraw",
170
- Index: log[0],
171
- Amount: divByDecimal(Number(log[4]), decimal),
172
- Token: Token,
173
- Exp: log[6],
174
- Date: new Date(Number(event.timestampMs)),
175
- txDigest: event.id.txDigest,
176
- log: log,
177
- });
178
- txHistory.push({
179
- Action: "Deposit",
180
- Index: log[0],
181
- Amount: divByDecimal(Number(log[4]), decimal),
182
- Token: Token,
183
252
  Exp: undefined,
184
- Date: new Date(Number(event.timestampMs)),
185
- txDigest: event.id.txDigest,
186
- log: log,
187
- });
188
- }
189
- if (Number(log[5]) > 0) {
190
- txHistory.push({
191
- Action: "Compound",
192
- Index: log[0],
193
- Amount: divByDecimal(Number(log[5]), decimal),
194
- Token: Token,
195
- Exp: log[6],
196
- Date: new Date(Number(event.timestampMs)),
197
- txDigest: event.id.txDigest,
198
- log: log,
199
- });
200
- }
201
- break;
202
- case "reduce_fund":
203
- totalWithdrawAmount = (0, bignumber_js_1.default)(log[2]).plus(log[4]);
204
- if (totalWithdrawAmount.gt(0)) {
205
- txHistory.push({
206
- Action: "Withdraw",
207
- Index: log[0],
208
- Amount: divByDecimal(totalWithdrawAmount.toNumber(), decimal),
209
- Token: Token,
210
- Exp: log[5],
211
- Date: new Date(Number(event.timestampMs)),
212
- txDigest: event.id.txDigest,
213
- log: log,
214
- });
215
- }
216
- if (Number(log[3]) > 0) {
217
- txHistory.push({
218
- Action: "Unsubscribe",
219
- Index: log[0],
220
- Amount: divByDecimal(Number(log[3]), decimal),
221
- Token: Token,
222
- Exp: log[5],
223
- Date: new Date(Number(event.timestampMs)),
224
- txDigest: event.id.txDigest,
253
+ Date: new Date(Number(event.timestamp)),
254
+ //@ts-ignore
255
+ txDigest: (_t = event.transaction) === null || _t === void 0 ? void 0 : _t.digest,
225
256
  log: log,
226
257
  });
227
- }
228
- break;
229
- case "claim_reward":
230
- txHistory.push({
231
- Action: "Harvest Options Profit",
232
- Index: log[0],
233
- Amount: divByDecimal(Number(log[2]), decimal),
234
- Token: Token,
235
- Exp: undefined,
236
- Date: new Date(Number(event.timestampMs)),
237
- txDigest: event.id.txDigest,
238
- log: log,
239
- });
240
- break;
258
+ break;
259
+ }
241
260
  }
242
- }
243
- return [2 /*return*/, txHistory];
244
- }
245
- });
246
- }); }, Promise.resolve(new Array()))];
261
+ return [2 /*return*/, txHistory];
262
+ }
263
+ });
264
+ }); }, Promise.resolve(new Array()))];
247
265
  case 1:
248
266
  results = _a.sent();
249
267
  return [2 /*return*/, results];
@@ -1,6 +1,7 @@
1
1
  import { SuiGraphQLClient } from "@mysten/sui/graphql";
2
2
  export declare function getDynamicObjectFields(graphQlClient: SuiGraphQLClient, parent: string, typeFilter?: string): Promise<any[] | undefined>;
3
3
  export interface Event {
4
+ sequenceNumber: number;
4
5
  transaction: {
5
6
  digest: string;
6
7
  } | null;
@@ -92,7 +92,7 @@ function getDynamicObjectFields(graphQlClient_1, parent_1) {
92
92
  });
93
93
  }
94
94
  var dynamicFieldsQuery = (0, schema_1.graphql)("\n query ($id: SuiAddress!) {\n address(address: $id) {\n dynamicFields {\n nodes {\n name {\n ...Value\n }\n value {\n ... on MoveValue {\n ...Value\n }\n ... on MoveObject {\n contents {\n ...Value\n }\n }\n }\n }\n }\n }\n }\n\n fragment Value on MoveValue {\n type {\n repr\n }\n json\n }\n");
95
- var eventsQuery = (0, schema_1.graphql)("\n query QueryEvents($type: String, $before: String, $sender: SuiAddress) {\n events(last: 50, before: $before, filter: { type: $type, sender: $sender }) {\n pageInfo {\n hasPreviousPage\n hasNextPage\n startCursor\n endCursor\n }\n edges {\n cursor\n }\n nodes {\n transaction {\n digest\n }\n transactionModule {\n name\n package {\n digest\n }\n }\n sender {\n address\n }\n timestamp\n contents {\n type {\n repr\n }\n json\n }\n }\n }\n }\n");
95
+ var eventsQuery = (0, schema_1.graphql)("\n query QueryEvents($type: String, $before: String, $sender: SuiAddress) {\n events(last: 50, before: $before, filter: { type: $type, sender: $sender }) {\n pageInfo {\n hasPreviousPage\n hasNextPage\n startCursor\n endCursor\n }\n edges {\n cursor\n }\n nodes {\n sequenceNumber\n transaction {\n digest\n }\n transactionModule {\n name\n package {\n digest\n }\n }\n sender {\n address\n }\n timestamp\n contents {\n type {\n repr\n }\n json\n }\n }\n }\n }\n");
96
96
  function getEvents(graphQlClient_1, module_1, sender_1) {
97
97
  return __awaiter(this, arguments, void 0, function (graphQlClient, module, sender, beforeCursor, getAll) {
98
98
  var hasPreviousPage, events, x;
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.9.3",
5
+ "version": "1.9.4",
6
6
  "dependencies": {
7
7
  "@mysten/bcs": "2.0.3",
8
8
  "@mysten/kiosk": "1.2.0",