@typus/typus-perp-sdk 1.1.49 → 1.1.51-upgrade

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.
Files changed (77) hide show
  1. package/dist/src/api/sentio.d.ts +1 -1
  2. package/dist/src/api/sentio.js +3 -3
  3. package/dist/src/client.d.ts +11 -12
  4. package/dist/src/client.js +16 -44
  5. package/dist/src/fetch.d.ts +15 -45
  6. package/dist/src/fetch.js +70 -69
  7. package/dist/src/generated/typus_perp/admin.d.ts +32 -42
  8. package/dist/src/generated/typus_perp/admin.js +41 -67
  9. package/dist/src/generated/typus_perp/competition.d.ts +22 -10
  10. package/dist/src/generated/typus_perp/competition.js +19 -54
  11. package/dist/src/generated/typus_perp/deps/std/type_name.d.ts +2 -2
  12. package/dist/src/generated/typus_perp/deps/std/type_name.js +2 -2
  13. package/dist/src/generated/typus_perp/deps/sui/balance.d.ts +3 -3
  14. package/dist/src/generated/typus_perp/deps/sui/balance.js +3 -3
  15. package/dist/src/generated/typus_perp/deps/sui/object_table.d.ts +4 -6
  16. package/dist/src/generated/typus_perp/deps/sui/object_table.js +4 -38
  17. package/dist/src/generated/typus_perp/deps/sui/table.d.ts +4 -6
  18. package/dist/src/generated/typus_perp/deps/sui/table.js +4 -38
  19. package/dist/src/generated/typus_perp/deps/sui/vec_set.d.ts +2 -2
  20. package/dist/src/generated/typus_perp/deps/sui/vec_set.js +2 -2
  21. package/dist/src/generated/typus_perp/deps/typus/keyed_big_vector.d.ts +7 -9
  22. package/dist/src/generated/typus_perp/deps/typus/keyed_big_vector.js +6 -6
  23. package/dist/src/generated/typus_perp/deps/typus/linked_object_table.d.ts +6 -10
  24. package/dist/src/generated/typus_perp/deps/typus/linked_object_table.js +5 -39
  25. package/dist/src/generated/typus_perp/deps/typus_framework/vault.d.ts +14 -8
  26. package/dist/src/generated/typus_perp/deps/typus_framework/vault.js +13 -39
  27. package/dist/src/generated/typus_perp/error.d.ts +97 -87
  28. package/dist/src/generated/typus_perp/error.js +18 -0
  29. package/dist/src/generated/typus_perp/escrow.d.ts +17 -21
  30. package/dist/src/generated/typus_perp/escrow.js +10 -22
  31. package/dist/src/generated/typus_perp/lending.d.ts +47 -0
  32. package/dist/src/generated/typus_perp/lending.js +40 -0
  33. package/dist/src/generated/typus_perp/lp_pool.d.ts +718 -397
  34. package/dist/src/generated/typus_perp/lp_pool.js +485 -365
  35. package/dist/src/generated/typus_perp/math.d.ts +18 -8
  36. package/dist/src/generated/typus_perp/math.js +24 -6
  37. package/dist/src/generated/typus_perp/position.d.ts +207 -185
  38. package/dist/src/generated/typus_perp/position.js +236 -277
  39. package/dist/src/generated/typus_perp/profit_vault.d.ts +64 -72
  40. package/dist/src/generated/typus_perp/profit_vault.js +48 -86
  41. package/dist/src/generated/typus_perp/symbol.d.ts +6 -6
  42. package/dist/src/generated/typus_perp/symbol.js +11 -13
  43. package/dist/src/generated/typus_perp/trading.d.ts +451 -558
  44. package/dist/src/generated/typus_perp/trading.js +429 -681
  45. package/dist/src/generated/typus_perp/treasury_caps.d.ts +5 -7
  46. package/dist/src/generated/typus_perp/treasury_caps.js +8 -45
  47. package/dist/src/generated/typus_stake_pool/admin.d.ts +13 -122
  48. package/dist/src/generated/typus_stake_pool/admin.js +19 -103
  49. package/dist/src/generated/typus_stake_pool/deps/std/type_name.d.ts +2 -2
  50. package/dist/src/generated/typus_stake_pool/deps/std/type_name.js +2 -2
  51. package/dist/src/generated/typus_stake_pool/deps/sui/vec_set.d.ts +2 -2
  52. package/dist/src/generated/typus_stake_pool/deps/sui/vec_set.js +2 -2
  53. package/dist/src/generated/typus_stake_pool/stake_pool.d.ts +249 -240
  54. package/dist/src/generated/typus_stake_pool/stake_pool.js +159 -246
  55. package/dist/src/generated/utils/index.d.ts +21 -2
  56. package/dist/src/generated/utils/index.js +34 -10
  57. package/dist/src/user/history.d.ts +3 -2
  58. package/dist/src/user/history.js +60 -18
  59. package/dist/src/user/order.d.ts +1 -1
  60. package/dist/src/user/orderWithBidReceipt.d.ts +1 -1
  61. package/package.json +8 -15
  62. package/dist/src/generated/typus_perp/deps/sui/object.d.ts +0 -8
  63. package/dist/src/generated/typus_perp/deps/sui/object.js +0 -16
  64. package/dist/src/generated/typus_perp/user_account.d.ts +0 -146
  65. package/dist/src/generated/typus_perp/user_account.js +0 -221
  66. package/dist/src/generated/typus_stake_pool/deps/sui/object.d.ts +0 -8
  67. package/dist/src/generated/typus_stake_pool/deps/sui/object.js +0 -16
  68. package/dist/src/generated/typus_stake_pool/deps/sui/vec_map.d.ts +0 -30
  69. package/dist/src/generated/typus_stake_pool/deps/sui/vec_map.js +0 -37
  70. package/dist/src/grpc/graphql.d.ts +0 -26
  71. package/dist/src/grpc/graphql.js +0 -126
  72. package/dist/src/grpc/grpc.d.ts +0 -1
  73. package/dist/src/grpc/grpc.js +0 -38
  74. package/dist/src/grpc/ledgerService.d.ts +0 -0
  75. package/dist/src/grpc/ledgerService.js +0 -64
  76. package/dist/src/grpc/liveDataService.d.ts +0 -0
  77. package/dist/src/grpc/liveDataService.js +0 -49
@@ -1,5 +1,5 @@
1
1
  import { TOKEN } from "@typus/typus-sdk/dist/src/constants";
2
- export declare function getFromSentio(event: string, userAddress: string, startTimestamp: string, cranker?: boolean): Promise<any[]>;
2
+ export declare function getFromSentio(event: string, userAddress: string, startTimestamp: string, endTimestamp?: string, cranker?: boolean): Promise<any[]>;
3
3
  export declare function getRecentTradesFromSentio(base_token?: TOKEN): Promise<any[]>;
4
4
  /**
5
5
  * Inputs:
@@ -17,7 +17,7 @@ const headers = {
17
17
  "api-key": "hCsD8shJaUbbiNLMKBG3oKhr9PL3H5EJ5",
18
18
  "Content-Type": "application/json",
19
19
  };
20
- async function getFromSentio(event, userAddress, startTimestamp, cranker) {
20
+ async function getFromSentio(event, userAddress, startTimestamp, endTimestamp, cranker) {
21
21
  let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp/sql/execute";
22
22
  // add cranker fileter
23
23
  let crankerFilter = "";
@@ -29,7 +29,7 @@ async function getFromSentio(event, userAddress, startTimestamp, cranker) {
29
29
  sql: `
30
30
  SELECT *
31
31
  FROM ${event}
32
- WHERE distinct_id = '${userAddress}' AND timestamp >= ${startTimestamp} ${crankerFilter}
32
+ WHERE distinct_id = '${userAddress}' AND timestamp >= ${startTimestamp} ${endTimestamp ? `AND timestamp <= ${endTimestamp}` : ""} ${crankerFilter}
33
33
  ORDER BY timestamp DESC;
34
34
  `,
35
35
  size: 1000,
@@ -788,7 +788,7 @@ async function getLeaderboardFromSentio(startTs, endTs, type = LeaderboardType.C
788
788
  t.rk ASC
789
789
  `,
790
790
  size,
791
- }
791
+ },
792
792
  };
793
793
  }
794
794
  let jsonData = JSON.stringify(requestData);
@@ -1,28 +1,27 @@
1
1
  import { SuiGraphQLClient } from "@mysten/sui/graphql";
2
2
  import { SuiGrpcClient } from "@mysten/sui/grpc";
3
- import { DevInspectTransactionBlockParams, ExecuteTransactionBlockParams, GetCoinsParams, GetDynamicFieldsParams, GetObjectParams, GetOwnedObjectsParams, MultiGetObjectsParams, QueryEventsParams, SuiClient } from "@mysten/sui/client";
4
3
  import { PythClient, TypusConfig } from "@typus/typus-sdk/dist/src/utils";
5
4
  import type { RpcTransport } from "@protobuf-ts/runtime-rpc";
5
+ import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
6
+ import { SuiClientTypes } from "@mysten/sui/client";
6
7
  export type Network = "MAINNET" | "TESTNET";
7
8
  export declare class TypusClient {
8
- jsonRpcClient: SuiClient;
9
+ jsonRpcClient: SuiJsonRpcClient;
9
10
  gRpcClient: SuiGrpcClient;
10
11
  graphQLClient: SuiGraphQLClient;
11
12
  pythClient: PythClient;
12
13
  config: TypusConfig;
13
14
  constructor(config: TypusConfig, grpcTransport?: RpcTransport);
14
- getCoins(params: GetCoinsParams): Promise<import("@mysten/sui/client").PaginatedCoins>;
15
- getObject(params: GetObjectParams): Promise<import("@mysten/sui/client").SuiObjectResponse>;
16
- getOwnedObjects(params: GetOwnedObjectsParams): Promise<import("@mysten/sui/client").PaginatedObjectsResponse>;
17
- getDynamicFields(params: GetDynamicFieldsParams): Promise<import("@mysten/sui/client").DynamicFieldPage>;
18
- multiGetObjects(params: MultiGetObjectsParams): Promise<import("@mysten/sui/client").SuiObjectResponse[]>;
19
- devInspectTransactionBlock(params: DevInspectTransactionBlockParams): Promise<import("@mysten/sui/client").DevInspectResults>;
20
- executeTransactionBlock(params: ExecuteTransactionBlockParams): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
21
- signAndExecuteTransaction(params: any): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
22
- queryEvents(params: QueryEventsParams): Promise<import("@mysten/sui/client").PaginatedEvents>;
15
+ getCoins(params: SuiClientTypes.ListCoinsOptions): Promise<SuiClientTypes.ListCoinsResponse>;
16
+ getObject(params: SuiClientTypes.GetObjectOptions): Promise<SuiClientTypes.GetObjectResponse<{}>>;
17
+ getOwnedObjects(params: SuiClientTypes.ListOwnedObjectsOptions): Promise<SuiClientTypes.ListOwnedObjectsResponse<{}>>;
18
+ getDynamicFields(params: SuiClientTypes.ListDynamicFieldsOptions): Promise<SuiClientTypes.ListDynamicFieldsResponse>;
19
+ multiGetObjects(params: SuiClientTypes.GetObjectsOptions): Promise<SuiClientTypes.GetObjectsResponse<{}>>;
20
+ devInspectTransactionBlock(params: SuiClientTypes.SimulateTransactionOptions): Promise<SuiClientTypes.SimulateTransactionResult<{}>>;
21
+ executeTransactionBlock(params: SuiClientTypes.ExecuteTransactionOptions): Promise<SuiClientTypes.TransactionResult<{}>>;
22
+ signAndExecuteTransaction(params: SuiClientTypes.SignAndExecuteTransactionOptions): Promise<SuiClientTypes.TransactionResult<{}>>;
23
23
  getObjectBcs(objectId: string): Promise<Uint8Array<ArrayBufferLike> | undefined>;
24
24
  batchGetObjectsBcs(objectIds: string[]): Promise<(Uint8Array<ArrayBufferLike> | undefined)[]>;
25
25
  getDynamicFieldsBcs(parent: string): Promise<Uint8Array<ArrayBufferLike>[]>;
26
26
  getDynamicObjectFieldsBcs(parent: string): Promise<Uint8Array<ArrayBufferLike>[]>;
27
- simulateTransaction(transactionBcs: Uint8Array<ArrayBufferLike>): Promise<import("@mysten/sui/dist/cjs/experimental").Experimental_SuiClientTypes.DryRunTransactionResponse>;
28
27
  }
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TypusClient = void 0;
4
- const latest_1 = require("@mysten/sui/graphql/schemas/latest");
4
+ const schema_1 = require("@mysten/sui/graphql/schema");
5
5
  const graphql_1 = require("@mysten/sui/graphql");
6
6
  const grpc_1 = require("@mysten/sui/grpc");
7
- const client_1 = require("@mysten/sui/client");
8
7
  const utils_1 = require("@typus/typus-sdk/dist/src/utils");
9
- const grpcweb_transport_1 = require("@protobuf-ts/grpcweb-transport");
8
+ const jsonRpc_1 = require("@mysten/sui/jsonRpc");
10
9
  class TypusClient {
11
10
  // user: string;
12
11
  // mvr?: Experimental_SuiClientTypes.MvrOptions
@@ -25,18 +24,15 @@ class TypusClient {
25
24
  // },
26
25
  },
27
26
  };
28
- this.jsonRpcClient = new client_1.SuiClient({
27
+ this.jsonRpcClient = new jsonRpc_1.SuiJsonRpcClient({
29
28
  network: network,
30
29
  url: config.rpcEndpoint,
31
30
  mvr,
32
31
  });
33
32
  this.gRpcClient = new grpc_1.SuiGrpcClient({
34
33
  network: network,
35
- transport: grpcTransport ??
36
- new grpcweb_transport_1.GrpcWebFetchTransport({
37
- baseUrl: `https://fullnode.${network}.sui.io:443`,
38
- // Additional transport options
39
- }),
34
+ baseUrl: `https://fullnode.${network}.sui.io:443`,
35
+ mvr,
40
36
  });
41
37
  this.graphQLClient = new graphql_1.SuiGraphQLClient({
42
38
  network: network,
@@ -46,47 +42,30 @@ class TypusClient {
46
42
  this.pythClient = (0, utils_1.createPythClient)(this.jsonRpcClient, this.config.network);
47
43
  }
48
44
  getCoins(params) {
49
- return this.jsonRpcClient.getCoins(params);
45
+ return this.gRpcClient.listCoins(params);
50
46
  }
51
47
  getObject(params) {
52
- return this.jsonRpcClient.getObject(params);
48
+ return this.gRpcClient.getObject(params);
53
49
  }
54
50
  getOwnedObjects(params) {
55
- return this.jsonRpcClient.getOwnedObjects(params);
51
+ return this.gRpcClient.listOwnedObjects(params);
56
52
  }
57
53
  getDynamicFields(params) {
58
- return this.jsonRpcClient.getDynamicFields(params);
54
+ return this.gRpcClient.listDynamicFields(params);
59
55
  }
60
56
  multiGetObjects(params) {
61
- return this.jsonRpcClient.multiGetObjects(params);
57
+ return this.gRpcClient.getObjects(params);
62
58
  }
63
59
  devInspectTransactionBlock(params) {
64
- // this.gRpcClient.transactionExecutionService.simulateTransaction({ transaction: { bcs: { value: params.transactionBlock } } });
65
- return this.jsonRpcClient.devInspectTransactionBlock(params);
60
+ params.checksEnabled = false;
61
+ params.include = { commandResults: true };
62
+ return this.gRpcClient.simulateTransaction(params);
66
63
  }
67
64
  executeTransactionBlock(params) {
68
- // this.gRpcClient.transactionExecutionService.executeTransaction({
69
- // transaction: { bcs: { value: params.transactionBlock } },
70
- // signatures,
71
- // });
72
- // this.gRpcClient.transactionExecutionService.executeTransaction({
73
- // transaction: {
74
- // bcs: {
75
- // value: transactionBytes,
76
- // },
77
- // },
78
- // signatures: signatures.map((sig) => ({
79
- // bcs: { value: fromBase64(sig) },
80
- // signature: { oneofKind: undefined },
81
- // })),
82
- // });
83
- return this.jsonRpcClient.executeTransactionBlock(params);
65
+ return this.gRpcClient.executeTransaction(params);
84
66
  }
85
67
  signAndExecuteTransaction(params) {
86
- return this.jsonRpcClient.signAndExecuteTransaction(params);
87
- }
88
- queryEvents(params) {
89
- return this.jsonRpcClient.queryEvents(params);
68
+ return this.gRpcClient.signAndExecuteTransaction(params);
90
69
  }
91
70
  // gRPC
92
71
  async getObjectBcs(objectId) {
@@ -129,16 +108,9 @@ class TypusClient {
129
108
  return x_1.childObject?.contents?.value;
130
109
  });
131
110
  }
132
- simulateTransaction(transactionBcs) {
133
- return this.gRpcClient.core.dryRunTransaction({ transaction: transactionBcs });
134
- // return this.gRpcClient.transactionExecutionService.simulateTransaction({
135
- // transaction: { bcs: { value: transactionBcs } },
136
- // // checks: 1,
137
- // });
138
- }
139
111
  }
140
112
  exports.TypusClient = TypusClient;
141
- const dynamicFieldsQuery = (0, latest_1.graphql)(`
113
+ const dynamicFieldsQuery = (0, schema_1.graphql)(`
142
114
  query ($id: SuiAddress!) {
143
115
  address(address: $id) {
144
116
  dynamicFields {
@@ -2,9 +2,7 @@ import { TOKEN } from "@typus/typus-sdk/dist/src/constants";
2
2
  import { TradingOrder, Position } from "./generated/typus_perp/position";
3
3
  import { TypusClient } from "../src/client";
4
4
  export declare function getLpPools(client: TypusClient): Promise<{
5
- id: {
6
- id: string;
7
- };
5
+ id: string;
8
6
  index: string;
9
7
  lp_token_type: {
10
8
  name: string;
@@ -66,9 +64,7 @@ export declare function getLpPools(client: TypusClient): Promise<{
66
64
  };
67
65
  liquidated_unsettled_receipts: {
68
66
  receipt: {
69
- id: {
70
- id: string;
71
- };
67
+ id: string;
72
68
  vid: string;
73
69
  index: string;
74
70
  metadata: string;
@@ -91,9 +87,7 @@ export declare function getLpPools(client: TypusClient): Promise<{
91
87
  bcs_padding: number[];
92
88
  }[]>;
93
89
  export declare function getLpPool(client: TypusClient, objectId: string): Promise<{
94
- id: {
95
- id: string;
96
- };
90
+ id: string;
97
91
  index: string;
98
92
  lp_token_type: {
99
93
  name: string;
@@ -155,9 +149,7 @@ export declare function getLpPool(client: TypusClient, objectId: string): Promis
155
149
  };
156
150
  liquidated_unsettled_receipts: {
157
151
  receipt: {
158
- id: {
159
- id: string;
160
- };
152
+ id: string;
161
153
  vid: string;
162
154
  index: string;
163
155
  metadata: string;
@@ -180,9 +172,7 @@ export declare function getLpPool(client: TypusClient, objectId: string): Promis
180
172
  bcs_padding: number[];
181
173
  }>;
182
174
  export declare function getStakePools(client: TypusClient): Promise<{
183
- id: {
184
- id: string;
185
- };
175
+ id: string;
186
176
  pool_info: {
187
177
  stake_token: {
188
178
  name: string;
@@ -220,9 +210,7 @@ export declare function getStakePools(client: TypusClient): Promise<{
220
210
  u64_padding: string[];
221
211
  }[]>;
222
212
  export declare function getStakePool(client: TypusClient, objectId: string): Promise<{
223
- id: {
224
- id: string;
225
- };
213
+ id: string;
226
214
  pool_info: {
227
215
  stake_token: {
228
216
  name: string;
@@ -265,9 +253,7 @@ export declare function getStakePool(client: TypusClient, objectId: string): Pro
265
253
  export declare function getMarkets(client: TypusClient, input: {
266
254
  indexes: string[];
267
255
  }): Promise<[{
268
- id: {
269
- id: string;
270
- };
256
+ id: string;
271
257
  index: string;
272
258
  lp_token_type: {
273
259
  name: string;
@@ -281,20 +267,14 @@ export declare function getMarkets(client: TypusClient, input: {
281
267
  name: string;
282
268
  }[];
283
269
  symbol_markets: {
284
- id: {
285
- id: string;
286
- };
270
+ id: string;
287
271
  size: string;
288
272
  };
289
273
  u64_padding: string[];
290
274
  }, {
291
- id: {
292
- id: string;
293
- };
275
+ id: string;
294
276
  user_positions: {
295
- id: {
296
- id: string;
297
- };
277
+ id: string;
298
278
  key_type: {
299
279
  name: string;
300
280
  };
@@ -305,12 +285,8 @@ export declare function getMarkets(client: TypusClient, input: {
305
285
  slice_size: number;
306
286
  length: string;
307
287
  };
308
- token_collateral_orders: {
309
- id: string;
310
- };
311
- option_collateral_orders: {
312
- id: string;
313
- };
288
+ token_collateral_orders: string;
289
+ option_collateral_orders: string;
314
290
  market_info: {
315
291
  is_active: boolean;
316
292
  size_decimal: string;
@@ -359,9 +335,7 @@ export declare function getUserPositions(client: TypusClient, input: {
359
335
  indexes: string[];
360
336
  }): Promise<PositionWithMarketIndex[]>;
361
337
  export declare function parseOptionBidReceipts(positions: (typeof Position.$inferType)[]): ({
362
- id: {
363
- id: string;
364
- };
338
+ id: string;
365
339
  vid: string;
366
340
  index: string;
367
341
  metadata: string;
@@ -428,9 +402,7 @@ export declare function getAllPositions(client: TypusClient, input: {
428
402
  marketIndex: string;
429
403
  }): Promise<{
430
404
  positions: {
431
- id: {
432
- id: string;
433
- };
405
+ id: string;
434
406
  create_ts_ms: string;
435
407
  update_ts_ms: string;
436
408
  position_id: string;
@@ -479,9 +451,7 @@ export declare function getAllPositionsWithTradingSymbol(client: TypusClient, in
479
451
  baseToken: TOKEN;
480
452
  marketIndex: string;
481
453
  }): Promise<{
482
- id: {
483
- id: string;
484
- };
454
+ id: string;
485
455
  create_ts_ms: string;
486
456
  update_ts_ms: string;
487
457
  position_id: string;
package/dist/src/fetch.js CHANGED
@@ -18,7 +18,6 @@ exports.fetchLockedUserProfits = fetchLockedUserProfits;
18
18
  exports.fetchAllUserProfits = fetchAllUserProfits;
19
19
  exports.fetchAllLockedUserProfits = fetchAllLockedUserProfits;
20
20
  const transactions_1 = require("@mysten/sui/transactions");
21
- const client_1 = require("@mysten/sui/client");
22
21
  const bcs_1 = require("@mysten/bcs");
23
22
  const constants_1 = require("@typus/typus-sdk/dist/src/constants");
24
23
  const utils_1 = require("@typus/typus-sdk/dist/src/utils");
@@ -100,7 +99,7 @@ async function getMarkets(client, input) {
100
99
  // let bcs = await tx.build({ client: client.jsonRpcClient, onlyTransactionKind: true });
101
100
  // // console.log("bcs", bcs);
102
101
  // let res = await client.simulateTransaction(bcs);
103
- let devInspectTransactionBlockResult = await client.devInspectTransactionBlock({ sender: constants_1.SENDER, transactionBlock: tx });
102
+ let devInspectTransactionBlockResult = await client.devInspectTransactionBlock({ transaction: tx });
104
103
  // @ts-ignore
105
104
  let bytes = devInspectTransactionBlockResult.results[0].returnValues[0][0];
106
105
  let reader = new bcs_1.BcsReader(new Uint8Array(bytes));
@@ -135,12 +134,12 @@ async function getUserOrders(client, input) {
135
134
  },
136
135
  }));
137
136
  }
138
- let res = await client.devInspectTransactionBlock({ sender: input.user, transactionBlock: tx });
137
+ let res = await client.devInspectTransactionBlock({ transaction: tx });
139
138
  // console.log(res);
140
139
  let orders = [];
141
140
  for (var x = 0; x < input.indexes.length; x++) {
142
141
  // @ts-ignore
143
- let returnValues = res.results[x].returnValues[0][0];
142
+ let returnValues = res.commandResults[x].returnValues[0][0];
144
143
  // console.log(returnValues);
145
144
  let reader = new bcs_1.BcsReader(new Uint8Array(returnValues));
146
145
  reader.readVec((reader) => {
@@ -164,12 +163,12 @@ async function getUserPositions(client, input) {
164
163
  },
165
164
  }));
166
165
  }
167
- let res = await client.devInspectTransactionBlock({ sender: input.user, transactionBlock: tx });
166
+ let res = await client.devInspectTransactionBlock({ transaction: tx });
168
167
  // console.log(res);
169
168
  let positions = [];
170
169
  for (var x = 0; x < input.indexes.length; x++) {
171
170
  // @ts-ignore
172
- let returnValues = res.results[x].returnValues[0][0];
171
+ let returnValues = res.commandResults[x].returnValues[0][0];
173
172
  // console.log(returnValues);
174
173
  let reader = new bcs_1.BcsReader(new Uint8Array(returnValues));
175
174
  reader.readVec((reader) => {
@@ -219,13 +218,13 @@ async function getUserStake(client, input) {
219
218
  },
220
219
  }));
221
220
  }
222
- let res = await client.devInspectTransactionBlock({ sender: input.user, transactionBlock: tx });
221
+ let res = await client.devInspectTransactionBlock({ transaction: tx });
223
222
  // console.log(res);
224
- if (res.results) {
223
+ if (res.commandResults) {
225
224
  let results = [];
226
225
  for (var x = 0; x < input.indexes.length; x++) {
227
226
  // @ts-ignore
228
- var returnValues = res.results[2 * x + 1].returnValues[0][0];
227
+ var returnValues = res.commandResults[2 * x + 1].returnValues[0][0];
229
228
  // console.log(returnValues);
230
229
  var reader = new bcs_1.BcsReader(new Uint8Array(returnValues));
231
230
  let length = reader.readULEB();
@@ -263,13 +262,13 @@ async function getDeactivatingShares(client, input) {
263
262
  typeArguments: ["TLP_TOKEN"],
264
263
  }));
265
264
  }
266
- let res = await client.devInspectTransactionBlock({ sender: input.user, transactionBlock: tx });
265
+ let res = await client.devInspectTransactionBlock({ transaction: tx });
267
266
  // console.log(res);
268
- if (res.results) {
267
+ if (res.commandResults) {
269
268
  let deactivatingShares = [];
270
269
  for (var x = 0; x < input.indexes.length; x++) {
271
270
  // @ts-ignore
272
- var returnValues = res.results[0].returnValues[0][0];
271
+ var returnValues = res.commandResults[0].returnValues[0][0];
273
272
  // console.log(returnValues);
274
273
  var reader = new bcs_1.BcsReader(new Uint8Array(returnValues));
275
274
  reader.readVec((reader) => {
@@ -328,7 +327,7 @@ async function getLiquidationPriceAndPnl(client, input) {
328
327
  typeArguments: [position.collateral_token.name, position.symbol.base_token.name],
329
328
  }));
330
329
  }
331
- let res = await client.devInspectTransactionBlock({ sender: constants_1.SENDER, transactionBlock: tx });
330
+ let res = await client.devInspectTransactionBlock({ transaction: tx });
332
331
  // console.log(res);
333
332
  // 0 estimated_liquidation_price,
334
333
  // 1 has_profit,
@@ -339,32 +338,33 @@ async function getLiquidationPriceAndPnl(client, input) {
339
338
  // 6 unrealized_funding_fee_usd,
340
339
  // 7 unrealized_borrow_fee_usd,
341
340
  // 8 close_fee_usd
342
- let results = res.results
343
- ? res.results.slice(-input.positions.length).map((x) => {
344
- // console.log(x);
345
- let liquidationPrice = Number(bcs_1.bcs.u64().parse(Uint8Array.from(x.returnValues[0][0])));
346
- let isProfit = bcs_1.bcs.bool().parse(Uint8Array.from(x.returnValues[1][0]));
347
- var pnl = Number(bcs_1.bcs.u64().parse(Uint8Array.from(x.returnValues[2][0])));
348
- pnl = isProfit ? pnl : -pnl;
349
- // including closeFee
350
- let isCost = bcs_1.bcs.bool().parse(Uint8Array.from(x.returnValues[3][0]));
351
- var cost = Number(bcs_1.bcs.u64().parse(Uint8Array.from(x.returnValues[4][0])));
352
- cost = isCost ? cost : -cost;
353
- // cost = unrealized_loss + unrealized_trading_fee + unrealized_borrow_fee + unrealized_funding_fee;
354
- let fundingFeeSign = bcs_1.bcs.bool().parse(Uint8Array.from(x.returnValues[5][0]));
355
- var fundingFee = Number(bcs_1.bcs.u64().parse(Uint8Array.from(x.returnValues[6][0])));
356
- fundingFee = fundingFeeSign ? fundingFee : -fundingFee;
357
- let borrowFee = Number(bcs_1.bcs.u64().parse(Uint8Array.from(x.returnValues[7][0])));
358
- let closeFee = Number(bcs_1.bcs.u64().parse(Uint8Array.from(x.returnValues[8][0])));
359
- return {
360
- liquidationPrice,
361
- pnl: pnl + closeFee,
362
- fundingFee,
363
- borrowFee,
364
- closeFee,
365
- pnlAfterFee: pnl - cost,
366
- };
367
- })
341
+ let results = res.commandResults
342
+ ? // @ts-ignore
343
+ res.commandResults.slice(-input.positions.length).map((x) => {
344
+ // console.log(x);
345
+ let liquidationPrice = Number(bcs_1.bcs.u64().parse(Uint8Array.from(x.returnValues[0][0])));
346
+ let isProfit = bcs_1.bcs.bool().parse(Uint8Array.from(x.returnValues[1][0]));
347
+ var pnl = Number(bcs_1.bcs.u64().parse(Uint8Array.from(x.returnValues[2][0])));
348
+ pnl = isProfit ? pnl : -pnl;
349
+ // including closeFee
350
+ let isCost = bcs_1.bcs.bool().parse(Uint8Array.from(x.returnValues[3][0]));
351
+ var cost = Number(bcs_1.bcs.u64().parse(Uint8Array.from(x.returnValues[4][0])));
352
+ cost = isCost ? cost : -cost;
353
+ // cost = unrealized_loss + unrealized_trading_fee + unrealized_borrow_fee + unrealized_funding_fee;
354
+ let fundingFeeSign = bcs_1.bcs.bool().parse(Uint8Array.from(x.returnValues[5][0]));
355
+ var fundingFee = Number(bcs_1.bcs.u64().parse(Uint8Array.from(x.returnValues[6][0])));
356
+ fundingFee = fundingFeeSign ? fundingFee : -fundingFee;
357
+ let borrowFee = Number(bcs_1.bcs.u64().parse(Uint8Array.from(x.returnValues[7][0])));
358
+ let closeFee = Number(bcs_1.bcs.u64().parse(Uint8Array.from(x.returnValues[8][0])));
359
+ return {
360
+ liquidationPrice,
361
+ pnl: pnl + closeFee,
362
+ fundingFee,
363
+ borrowFee,
364
+ closeFee,
365
+ pnlAfterFee: pnl - cost,
366
+ };
367
+ })
368
368
  : [];
369
369
  // console.log(results);
370
370
  return results;
@@ -382,14 +382,15 @@ async function getAllPositions(client, input) {
382
382
  typeArguments: [constants_1.tokenType[_1.NETWORK][input.baseToken]],
383
383
  }));
384
384
  let res = await client.devInspectTransactionBlock({
385
- sender: constants_1.SENDER,
386
- transactionBlock: tx,
385
+ transaction: tx,
387
386
  });
388
- if (!res.results?.[0]?.returnValues?.[0]?.[0]) {
387
+ // @ts-ignore
388
+ if (!res.commandResults?.[0]?.returnValues?.[0]?.[0]) {
389
389
  return { positions: [], maxPage: 0 };
390
390
  }
391
391
  // -- 解析回傳值 -------------------------------------------------
392
- const raw = new Uint8Array(res.results[0].returnValues[0][0]);
392
+ // @ts-ignore
393
+ const raw = new Uint8Array(res.commandResults[0].returnValues[0][0]);
393
394
  // 1) 至少要有 8 bytes 的 max_page
394
395
  if (raw.length < 8)
395
396
  return { positions: [], maxPage: 0 };
@@ -452,13 +453,14 @@ async function fetchUserProfits(client, input) {
452
453
  arguments: [tx.object(input.version), tx.object(input.profitVault), tx.pure.address(input.user)],
453
454
  });
454
455
  const res = await client.devInspectTransactionBlock({
455
- sender: constants_1.SENDER,
456
- transactionBlock: tx,
456
+ transaction: tx,
457
457
  });
458
- if (!res.results?.[0]?.returnValues?.[0]?.[0]) {
458
+ // @ts-ignore
459
+ if (!res.commandResults?.[0]?.returnValues?.[0]?.[0]) {
459
460
  return [];
460
461
  }
461
- const returnValues = res.results[0].returnValues[0][0];
462
+ // @ts-ignore
463
+ const returnValues = res.commandResults[0].returnValues[0][0];
462
464
  const reader = new bcs_1.BcsReader(new Uint8Array(returnValues));
463
465
  const profits = [];
464
466
  reader.readVec((reader) => {
@@ -476,13 +478,14 @@ async function fetchLockedUserProfits(client, input) {
476
478
  arguments: [tx.object(_1.PERP_VERSION), tx.object(input.lockVault), tx.pure.address(input.user)],
477
479
  });
478
480
  const res = await client.devInspectTransactionBlock({
479
- sender: constants_1.SENDER,
480
- transactionBlock: tx,
481
+ transaction: tx,
481
482
  });
482
- if (!res.results?.[0]?.returnValues?.[0]?.[0]) {
483
+ // @ts-ignore
484
+ if (!res.commandResults?.[0]?.returnValues?.[0]?.[0]) {
483
485
  return [];
484
486
  }
485
- const returnValues = res.results[0].returnValues[0][0];
487
+ // @ts-ignore
488
+ const returnValues = res.commandResults[0].returnValues[0][0];
486
489
  const reader = new bcs_1.BcsReader(new Uint8Array(returnValues));
487
490
  const lockedUserProfits = [];
488
491
  reader.readVec((reader) => {
@@ -494,17 +497,16 @@ async function fetchLockedUserProfits(client, input) {
494
497
  return lockedUserProfits;
495
498
  }
496
499
  async function fetchAllUserProfits(client, input) {
497
- const provider = new client_1.SuiClient({ url: client.config.rpcEndpoint });
498
500
  const profitVaultId = input?.profitVault ?? _1.PROFIT_VAULT;
499
501
  // 1. Read ProfitVault object to get user_profits Table ID
500
- const vaultResponse = await provider.getObject({
501
- id: profitVaultId,
502
- options: { showContent: true },
502
+ const vaultResponse = await client.getObject({
503
+ objectId: profitVaultId,
504
+ include: { content: true },
503
505
  });
504
- if (!vaultResponse.data?.content || vaultResponse.data.content.dataType !== "moveObject") {
506
+ if (!vaultResponse.object.content) {
505
507
  return [];
506
508
  }
507
- const fields = vaultResponse.data.content.fields;
509
+ const fields = vaultResponse.object.content.fields;
508
510
  const tableId = fields?.user_profits?.fields?.id?.id;
509
511
  if (!tableId) {
510
512
  return [];
@@ -513,12 +515,12 @@ async function fetchAllUserProfits(client, input) {
513
515
  let cursor = null;
514
516
  const allUsers = [];
515
517
  while (true) {
516
- const dynamicFields = await provider.getDynamicFields({
518
+ const dynamicFields = await client.getDynamicFields({
517
519
  parentId: tableId,
518
520
  cursor,
519
521
  limit: 50,
520
522
  });
521
- for (const field of dynamicFields.data) {
523
+ for (const field of dynamicFields.dynamicFields) {
522
524
  const userAddress = field.name.value;
523
525
  if (userAddress) {
524
526
  allUsers.push(userAddress);
@@ -527,7 +529,7 @@ async function fetchAllUserProfits(client, input) {
527
529
  if (!dynamicFields.hasNextPage) {
528
530
  break;
529
531
  }
530
- cursor = dynamicFields.nextCursor ?? null;
532
+ cursor = dynamicFields.cursor ?? null;
531
533
  }
532
534
  // 3. For each user, fetch their profits
533
535
  const fetchUserProfitsPromises = [];
@@ -547,16 +549,15 @@ async function fetchAllUserProfits(client, input) {
547
549
  return results;
548
550
  }
549
551
  async function fetchAllLockedUserProfits(client, input) {
550
- const provider = new client_1.SuiClient({ url: client.config.rpcEndpoint });
551
552
  // 1. Read LockVault object to get locked_user_profits Table ID
552
- const vaultResponse = await provider.getObject({
553
- id: input?.lockVault ?? _1.LOCK_VAULT,
554
- options: { showContent: true },
553
+ const vaultResponse = await client.getObject({
554
+ objectId: input?.lockVault ?? _1.LOCK_VAULT,
555
+ include: { content: true },
555
556
  });
556
- if (!vaultResponse.data?.content || vaultResponse.data.content.dataType !== "moveObject") {
557
+ if (!vaultResponse.object.content) {
557
558
  return [];
558
559
  }
559
- const fields = vaultResponse.data.content.fields;
560
+ const fields = vaultResponse.object.content.fields;
560
561
  const tableId = fields?.locked_user_profits?.fields?.id?.id;
561
562
  if (!tableId) {
562
563
  return [];
@@ -565,12 +566,12 @@ async function fetchAllLockedUserProfits(client, input) {
565
566
  let cursor = null;
566
567
  const allUsers = [];
567
568
  while (true) {
568
- const dynamicFields = await provider.getDynamicFields({
569
+ const dynamicFields = await client.getDynamicFields({
569
570
  parentId: tableId,
570
571
  cursor,
571
572
  limit: 50,
572
573
  });
573
- for (const field of dynamicFields.data) {
574
+ for (const field of dynamicFields.dynamicFields) {
574
575
  const userAddress = field.name.value;
575
576
  if (userAddress) {
576
577
  allUsers.push(userAddress);
@@ -579,7 +580,7 @@ async function fetchAllLockedUserProfits(client, input) {
579
580
  if (!dynamicFields.hasNextPage) {
580
581
  break;
581
582
  }
582
- cursor = dynamicFields.nextCursor ?? null;
583
+ cursor = dynamicFields.cursor ?? null;
583
584
  }
584
585
  // 3. For each user, fetch their locked profits
585
586
  const fetchLockedUserProfitsPromises = [];