@typus/typus-sdk 1.8.43-upgrade → 1.8.43-upgrade-0.2

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.
@@ -39,6 +39,10 @@ export interface Game {
39
39
  larger_than_2: boolean | null;
40
40
  vrf_input_2: number[] | null;
41
41
  }
42
+ export declare function getHistory(config: TypusConfig, input: {
43
+ module: "tails_exp" | "combo_dice";
44
+ playgrounds: Playground[];
45
+ }): Promise<DrawDisplay[]>;
42
46
  export declare function parseHistory(datas: any, playgrounds: Playground[]): Promise<DrawDisplay[]>;
43
47
  export interface DrawEvent {
44
48
  answer_1: string;
@@ -57,7 +61,7 @@ export interface DrawEvent {
57
61
  signature_2: number[];
58
62
  signer: string;
59
63
  stake_amount: string;
60
- timestampMs: string;
64
+ timestamp: string;
61
65
  exp?: string;
62
66
  exp_amount?: string;
63
67
  reward?: string;
@@ -71,6 +75,6 @@ export interface DrawDisplay {
71
75
  result_2: string;
72
76
  bet_amount: string;
73
77
  exp: string;
74
- timestampMs: string;
78
+ timestamp: string;
75
79
  reward?: string;
76
80
  }
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.getPlaygrounds = getPlaygrounds;
40
+ exports.getHistory = getHistory;
40
41
  exports.parseHistory = parseHistory;
41
42
  // import { SuiClient, SuiEventFilter } from "@mysten/sui/client";
42
43
  var constants_1 = require("../../src/constants");
@@ -87,49 +88,48 @@ function getPlaygrounds(config, input) {
87
88
  });
88
89
  });
89
90
  }
90
- // export async function getHistory(
91
- // config: TypusConfig,
92
- // input: {
93
- // module: "tails_exp" | "combo_dice";
94
- // playgrounds: Playground[];
95
- // }
96
- // ): Promise<DrawDisplay[]> {
97
- // const provider = config.gRpcClient();
98
- // let MoveEventType = "";
99
- // switch (input.module) {
100
- // case "tails_exp":
101
- // MoveEventType = `${config.packageOrigin.dice}::tails_exp::Draw`;
102
- // break;
103
- // case "combo_dice":
104
- // if (config.rpcEndpoint.includes("mainnet")) {
105
- // MoveEventType = `${config.packageOrigin.dice}::combo_dice::Draw`;
106
- // } else {
107
- // MoveEventType = `0xf1d628b4f14f9dae42d73a6cdee9b5f80567fee323166c4ecfb124de7d4ff254::combo_dice::Draw`;
108
- // }
109
- // break;
110
- // default:
111
- // break;
112
- // }
113
- // let eventFilter: SuiEventFilter = {
114
- // MoveEventType,
115
- // };
116
- // var result = await provider.queryEvents({ query: eventFilter, order: "descending" });
117
- // // console.log(result);
118
- // var history = await parseHistory(result.data, input.playgrounds);
119
- // while (result.hasNextPage && history.length <= 60) {
120
- // result = await provider.queryEvents({ query: eventFilter, order: "descending", cursor: result.cursor });
121
- // let nextPage = await parseHistory(result.data, input.playgrounds);
122
- // history = history.concat(nextPage);
123
- // }
124
- // return history;
125
- // }
91
+ function getHistory(config, input) {
92
+ return __awaiter(this, void 0, void 0, function () {
93
+ var graphQlClient, MoveEventType, events, history;
94
+ return __generator(this, function (_a) {
95
+ switch (_a.label) {
96
+ case 0:
97
+ graphQlClient = config.graphQlClient();
98
+ MoveEventType = "";
99
+ switch (input.module) {
100
+ case "tails_exp":
101
+ MoveEventType = "".concat(config.packageOrigin.dice, "::tails_exp::Draw");
102
+ break;
103
+ case "combo_dice":
104
+ if (config.rpcEndpoint.includes("mainnet")) {
105
+ MoveEventType = "".concat(config.packageOrigin.dice, "::combo_dice::Draw");
106
+ }
107
+ else {
108
+ MoveEventType = "0xf1d628b4f14f9dae42d73a6cdee9b5f80567fee323166c4ecfb124de7d4ff254::combo_dice::Draw";
109
+ }
110
+ break;
111
+ default:
112
+ break;
113
+ }
114
+ return [4 /*yield*/, (0, graphQl_1.getEvents)(graphQlClient, MoveEventType, null, null, false)];
115
+ case 1:
116
+ events = _a.sent();
117
+ return [4 /*yield*/, parseHistory(events, input.playgrounds)];
118
+ case 2:
119
+ history = _a.sent();
120
+ return [2 /*return*/, history];
121
+ }
122
+ });
123
+ });
124
+ }
126
125
  function parseHistory(datas, playgrounds) {
127
126
  return __awaiter(this, void 0, void 0, function () {
128
127
  var result;
129
128
  return __generator(this, function (_a) {
130
129
  result = datas.map(function (event) {
131
- var drawEvent = event.parsedJson;
132
- drawEvent.timestampMs = event.timestampMs;
130
+ // console.log(event);
131
+ var drawEvent = event.contents.json;
132
+ drawEvent.timestamp = event.timestamp;
133
133
  var playground = playgrounds[Number(drawEvent.index)];
134
134
  var coinType = "0x" + playground.stake_token;
135
135
  var asset = (0, constants_1.typeArgToAsset)(coinType);
@@ -179,7 +179,7 @@ function parseHistory(datas, playgrounds) {
179
179
  result_2: result_2,
180
180
  bet_amount: "".concat(amount, " ").concat(asset),
181
181
  exp: "".concat(exp, " EXP"),
182
- timestampMs: drawEvent.timestampMs,
182
+ timestamp: drawEvent.timestamp,
183
183
  };
184
184
  if (drawEvent.reward) {
185
185
  var reward = Number(drawEvent.reward) / Math.pow(10, decimal);
@@ -2,7 +2,10 @@ import { Vault } from "../../../src/typus-dov-single-v2";
2
2
  import { TOKEN } from "../../../src/constants";
3
3
  export { getNewBidFromSentio, getExerciseFromSentio } from "../../../src/utils/api/sentio/events";
4
4
  import { SuiGraphQLClient } from "@mysten/sui/graphql";
5
- export declare function getUserEvents(graphQlClient: SuiGraphQLClient, sender: string, cursor?: string | null): Promise<import("../../../src/utils/graphQl").Event[]>;
5
+ export declare function getUserEvents(graphQlClient: SuiGraphQLClient, sender: string, cursor?: string | null): Promise<{
6
+ events: import("../../../src/utils/graphQl").Event[];
7
+ beforeCursor: string | null;
8
+ }>;
6
9
  export interface TxHistory {
7
10
  Index: string | undefined;
8
11
  Action: string | undefined;
@@ -81,14 +81,14 @@ var valut_1 = require("../../../src/constants/valut");
81
81
  var graphQl_1 = require("../../../src/utils/graphQl");
82
82
  function getUserEvents(graphQlClient, sender, cursor) {
83
83
  return __awaiter(this, void 0, void 0, function () {
84
- var events;
85
- return __generator(this, function (_a) {
86
- switch (_a.label) {
84
+ var _a, events, beforeCursor;
85
+ return __generator(this, function (_b) {
86
+ switch (_b.label) {
87
87
  case 0: return [4 /*yield*/, (0, graphQl_1.getEvents)(graphQlClient, null, sender, cursor)];
88
88
  case 1:
89
- events = _a.sent();
89
+ _a = _b.sent(), events = _a.events, beforeCursor = _a.beforeCursor;
90
90
  // console.log(events.map(x => x.timestamp))
91
- return [2 /*return*/, events.reverse()];
91
+ return [2 /*return*/, { events: events.reverse(), beforeCursor: beforeCursor }];
92
92
  }
93
93
  });
94
94
  });
@@ -417,8 +417,7 @@ function parseTxHistory(datas, vaults) {
417
417
  case "CloseStrategyEventV2":
418
418
  Action = "Close Strategy";
419
419
  if (b_token == d_token) {
420
- balance = (Number(json.u64_padding[0]) + Number(json.u64_padding[1])) /
421
- Math.pow(10, (0, constants_1.assetToDecimal)(b_token));
420
+ balance = (Number(json.u64_padding[0]) + Number(json.u64_padding[1])) / Math.pow(10, (0, constants_1.assetToDecimal)(b_token));
422
421
  Amount = "".concat((0, bignumber_js_1.default)(balance).toFixed(), " ").concat(b_token);
423
422
  }
424
423
  else {
@@ -21,4 +21,7 @@ export interface Event {
21
21
  json: unknown;
22
22
  } | null;
23
23
  }
24
- export declare function getEvents(graphQlClient: SuiGraphQLClient, module: string | null, sender: string | null, beforeCursor?: string | null): Promise<Event[]>;
24
+ export declare function getEvents(graphQlClient: SuiGraphQLClient, module: string | null, sender: string | null, beforeCursor?: string | null, getAll?: boolean): Promise<{
25
+ events: Event[];
26
+ beforeCursor: string | null;
27
+ }>;
@@ -80,25 +80,25 @@ function getDynamicObjectFields(graphQlClient_1, parent_1) {
80
80
  case 1:
81
81
  x = _d.sent();
82
82
  // @ts-ignore
83
- return [2 /*return*/, (_c = (_b = (_a = x.data) === null || _a === void 0 ? void 0 : _a.address) === null || _b === void 0 ? void 0 : _b.dynamicFields) === null || _c === void 0 ? void 0 : _c.nodes.filter(function (a) { var _a, _b; return ((_a = a.value) === null || _a === void 0 ? void 0 : _a.contents) && ((_b = a.value) === null || _b === void 0 ? void 0 : _b.contents.type.repr.endsWith(typeFilter)); }).sort(function (a, b) { var _a, _b; return Number((_a = a.name) === null || _a === void 0 ? void 0 : _a.json) - Number((_b = b.name) === null || _b === void 0 ? void 0 : _b.json); }).map(function (x_1) {
83
+ return [2 /*return*/, ((_c = (_b = (_a = x.data) === null || _a === void 0 ? void 0 : _a.address) === null || _b === void 0 ? void 0 : _b.dynamicFields) === null || _c === void 0 ? void 0 : _c.nodes.filter(function (a) { var _a, _b; return ((_a = a.value) === null || _a === void 0 ? void 0 : _a.contents) && ((_b = a.value) === null || _b === void 0 ? void 0 : _b.contents.type.repr.endsWith(typeFilter)); }).sort(function (a, b) { var _a, _b; return Number((_a = a.name) === null || _a === void 0 ? void 0 : _a.json) - Number((_b = b.name) === null || _b === void 0 ? void 0 : _b.json); }).map(function (x_1) {
84
84
  var _a;
85
85
  // @ts-ignore
86
86
  var json = (_a = x_1.value) === null || _a === void 0 ? void 0 : _a.contents.json;
87
87
  // console.dir(json, { depth: null });
88
88
  return json;
89
- })];
89
+ }))];
90
90
  }
91
91
  });
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(\n last: 50,\n before: $before\n filter: { type: $type, sender: $sender }\n ) {\n pageInfo {\n hasPreviousPage\n hasNextPage\n startCursor\n endCursor\n }\n edges { cursor }\n nodes {\n transaction { digest }\n transactionModule {\n name\n package { digest }\n }\n sender { address }\n timestamp\n contents {\n type { repr }\n json\n }\n }\n }\n }\n");
96
- ;
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");
97
96
  function getEvents(graphQlClient_1, module_1, sender_1) {
98
- return __awaiter(this, arguments, void 0, function (graphQlClient, module, sender, beforeCursor) {
97
+ return __awaiter(this, arguments, void 0, function (graphQlClient, module, sender, beforeCursor, getAll) {
99
98
  var hasPreviousPage, events, x;
100
99
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
101
100
  if (beforeCursor === void 0) { beforeCursor = null; }
101
+ if (getAll === void 0) { getAll = true; }
102
102
  return __generator(this, function (_k) {
103
103
  switch (_k.label) {
104
104
  case 0:
@@ -119,10 +119,13 @@ function getEvents(graphQlClient_1, module_1, sender_1) {
119
119
  x = _k.sent();
120
120
  // console.dir(x.data?.events?.nodes, { depth: null })
121
121
  events.push.apply(events, __spreadArray([], __read(((_c = (_b = (_a = x.data) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.nodes.reverse()) !== null && _c !== void 0 ? _c : [])), false));
122
+ if (!getAll) {
123
+ return [3 /*break*/, 3];
124
+ }
122
125
  hasPreviousPage = (_f = (_e = (_d = x.data) === null || _d === void 0 ? void 0 : _d.events) === null || _e === void 0 ? void 0 : _e.pageInfo.hasPreviousPage) !== null && _f !== void 0 ? _f : false;
123
126
  beforeCursor = (_j = (_h = (_g = x.data) === null || _g === void 0 ? void 0 : _g.events) === null || _h === void 0 ? void 0 : _h.pageInfo.startCursor) !== null && _j !== void 0 ? _j : null;
124
127
  return [3 /*break*/, 1];
125
- case 3: return [2 /*return*/, events];
128
+ case 3: return [2 /*return*/, { events: events, beforeCursor: beforeCursor }];
126
129
  }
127
130
  });
128
131
  });
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.8.43-upgrade",
5
+ "version": "1.8.43-upgrade-0.2",
6
6
  "dependencies": {
7
7
  "@mysten/bcs": "2.0.3",
8
8
  "@mysten/kiosk": "1.2.0",