@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.
- package/dist/src/api/sentio.d.ts +1 -1
- package/dist/src/api/sentio.js +3 -3
- package/dist/src/client.d.ts +11 -12
- package/dist/src/client.js +16 -44
- package/dist/src/fetch.d.ts +15 -45
- package/dist/src/fetch.js +70 -69
- package/dist/src/generated/typus_perp/admin.d.ts +32 -42
- package/dist/src/generated/typus_perp/admin.js +41 -67
- package/dist/src/generated/typus_perp/competition.d.ts +22 -10
- package/dist/src/generated/typus_perp/competition.js +19 -54
- package/dist/src/generated/typus_perp/deps/std/type_name.d.ts +2 -2
- package/dist/src/generated/typus_perp/deps/std/type_name.js +2 -2
- package/dist/src/generated/typus_perp/deps/sui/balance.d.ts +3 -3
- package/dist/src/generated/typus_perp/deps/sui/balance.js +3 -3
- package/dist/src/generated/typus_perp/deps/sui/object_table.d.ts +4 -6
- package/dist/src/generated/typus_perp/deps/sui/object_table.js +4 -38
- package/dist/src/generated/typus_perp/deps/sui/table.d.ts +4 -6
- package/dist/src/generated/typus_perp/deps/sui/table.js +4 -38
- package/dist/src/generated/typus_perp/deps/sui/vec_set.d.ts +2 -2
- package/dist/src/generated/typus_perp/deps/sui/vec_set.js +2 -2
- package/dist/src/generated/typus_perp/deps/typus/keyed_big_vector.d.ts +7 -9
- package/dist/src/generated/typus_perp/deps/typus/keyed_big_vector.js +6 -6
- package/dist/src/generated/typus_perp/deps/typus/linked_object_table.d.ts +6 -10
- package/dist/src/generated/typus_perp/deps/typus/linked_object_table.js +5 -39
- package/dist/src/generated/typus_perp/deps/typus_framework/vault.d.ts +14 -8
- package/dist/src/generated/typus_perp/deps/typus_framework/vault.js +13 -39
- package/dist/src/generated/typus_perp/error.d.ts +97 -87
- package/dist/src/generated/typus_perp/error.js +18 -0
- package/dist/src/generated/typus_perp/escrow.d.ts +17 -21
- package/dist/src/generated/typus_perp/escrow.js +10 -22
- package/dist/src/generated/typus_perp/lending.d.ts +47 -0
- package/dist/src/generated/typus_perp/lending.js +40 -0
- package/dist/src/generated/typus_perp/lp_pool.d.ts +718 -397
- package/dist/src/generated/typus_perp/lp_pool.js +485 -365
- package/dist/src/generated/typus_perp/math.d.ts +18 -8
- package/dist/src/generated/typus_perp/math.js +24 -6
- package/dist/src/generated/typus_perp/position.d.ts +207 -185
- package/dist/src/generated/typus_perp/position.js +236 -277
- package/dist/src/generated/typus_perp/profit_vault.d.ts +64 -72
- package/dist/src/generated/typus_perp/profit_vault.js +48 -86
- package/dist/src/generated/typus_perp/symbol.d.ts +6 -6
- package/dist/src/generated/typus_perp/symbol.js +11 -13
- package/dist/src/generated/typus_perp/trading.d.ts +451 -558
- package/dist/src/generated/typus_perp/trading.js +429 -681
- package/dist/src/generated/typus_perp/treasury_caps.d.ts +5 -7
- package/dist/src/generated/typus_perp/treasury_caps.js +8 -45
- package/dist/src/generated/typus_stake_pool/admin.d.ts +13 -122
- package/dist/src/generated/typus_stake_pool/admin.js +19 -103
- package/dist/src/generated/typus_stake_pool/deps/std/type_name.d.ts +2 -2
- package/dist/src/generated/typus_stake_pool/deps/std/type_name.js +2 -2
- package/dist/src/generated/typus_stake_pool/deps/sui/vec_set.d.ts +2 -2
- package/dist/src/generated/typus_stake_pool/deps/sui/vec_set.js +2 -2
- package/dist/src/generated/typus_stake_pool/stake_pool.d.ts +249 -240
- package/dist/src/generated/typus_stake_pool/stake_pool.js +159 -246
- package/dist/src/generated/utils/index.d.ts +21 -2
- package/dist/src/generated/utils/index.js +34 -10
- package/dist/src/user/history.d.ts +3 -2
- package/dist/src/user/history.js +60 -18
- package/dist/src/user/order.d.ts +1 -1
- package/dist/src/user/orderWithBidReceipt.d.ts +1 -1
- package/package.json +8 -15
- package/dist/src/generated/typus_perp/deps/sui/object.d.ts +0 -8
- package/dist/src/generated/typus_perp/deps/sui/object.js +0 -16
- package/dist/src/generated/typus_perp/user_account.d.ts +0 -146
- package/dist/src/generated/typus_perp/user_account.js +0 -221
- package/dist/src/generated/typus_stake_pool/deps/sui/object.d.ts +0 -8
- package/dist/src/generated/typus_stake_pool/deps/sui/object.js +0 -16
- package/dist/src/generated/typus_stake_pool/deps/sui/vec_map.d.ts +0 -30
- package/dist/src/generated/typus_stake_pool/deps/sui/vec_map.js +0 -37
- package/dist/src/grpc/graphql.d.ts +0 -26
- package/dist/src/grpc/graphql.js +0 -126
- package/dist/src/grpc/grpc.d.ts +0 -1
- package/dist/src/grpc/grpc.js +0 -38
- package/dist/src/grpc/ledgerService.d.ts +0 -0
- package/dist/src/grpc/ledgerService.js +0 -64
- package/dist/src/grpc/liveDataService.d.ts +0 -0
- package/dist/src/grpc/liveDataService.js +0 -49
package/dist/src/api/sentio.d.ts
CHANGED
|
@@ -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:
|
package/dist/src/api/sentio.js
CHANGED
|
@@ -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);
|
package/dist/src/client.d.ts
CHANGED
|
@@ -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:
|
|
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:
|
|
15
|
-
getObject(params:
|
|
16
|
-
getOwnedObjects(params:
|
|
17
|
-
getDynamicFields(params:
|
|
18
|
-
multiGetObjects(params:
|
|
19
|
-
devInspectTransactionBlock(params:
|
|
20
|
-
executeTransactionBlock(params:
|
|
21
|
-
signAndExecuteTransaction(params:
|
|
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
|
}
|
package/dist/src/client.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TypusClient = void 0;
|
|
4
|
-
const
|
|
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
|
|
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
|
|
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
|
-
|
|
36
|
-
|
|
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.
|
|
45
|
+
return this.gRpcClient.listCoins(params);
|
|
50
46
|
}
|
|
51
47
|
getObject(params) {
|
|
52
|
-
return this.
|
|
48
|
+
return this.gRpcClient.getObject(params);
|
|
53
49
|
}
|
|
54
50
|
getOwnedObjects(params) {
|
|
55
|
-
return this.
|
|
51
|
+
return this.gRpcClient.listOwnedObjects(params);
|
|
56
52
|
}
|
|
57
53
|
getDynamicFields(params) {
|
|
58
|
-
return this.
|
|
54
|
+
return this.gRpcClient.listDynamicFields(params);
|
|
59
55
|
}
|
|
60
56
|
multiGetObjects(params) {
|
|
61
|
-
return this.
|
|
57
|
+
return this.gRpcClient.getObjects(params);
|
|
62
58
|
}
|
|
63
59
|
devInspectTransactionBlock(params) {
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
params.checksEnabled = false;
|
|
61
|
+
params.include = { commandResults: true };
|
|
62
|
+
return this.gRpcClient.simulateTransaction(params);
|
|
66
63
|
}
|
|
67
64
|
executeTransactionBlock(params) {
|
|
68
|
-
|
|
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.
|
|
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,
|
|
113
|
+
const dynamicFieldsQuery = (0, schema_1.graphql)(`
|
|
142
114
|
query ($id: SuiAddress!) {
|
|
143
115
|
address(address: $id) {
|
|
144
116
|
dynamicFields {
|
package/dist/src/fetch.d.ts
CHANGED
|
@@ -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
|
-
|
|
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({
|
|
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({
|
|
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.
|
|
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({
|
|
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.
|
|
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({
|
|
221
|
+
let res = await client.devInspectTransactionBlock({ transaction: tx });
|
|
223
222
|
// console.log(res);
|
|
224
|
-
if (res.
|
|
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.
|
|
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({
|
|
265
|
+
let res = await client.devInspectTransactionBlock({ transaction: tx });
|
|
267
266
|
// console.log(res);
|
|
268
|
-
if (res.
|
|
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.
|
|
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({
|
|
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.
|
|
343
|
-
?
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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
|
-
|
|
386
|
-
transactionBlock: tx,
|
|
385
|
+
transaction: tx,
|
|
387
386
|
});
|
|
388
|
-
|
|
387
|
+
// @ts-ignore
|
|
388
|
+
if (!res.commandResults?.[0]?.returnValues?.[0]?.[0]) {
|
|
389
389
|
return { positions: [], maxPage: 0 };
|
|
390
390
|
}
|
|
391
391
|
// -- 解析回傳值 -------------------------------------------------
|
|
392
|
-
|
|
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
|
-
|
|
456
|
-
transactionBlock: tx,
|
|
456
|
+
transaction: tx,
|
|
457
457
|
});
|
|
458
|
-
|
|
458
|
+
// @ts-ignore
|
|
459
|
+
if (!res.commandResults?.[0]?.returnValues?.[0]?.[0]) {
|
|
459
460
|
return [];
|
|
460
461
|
}
|
|
461
|
-
|
|
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
|
-
|
|
480
|
-
transactionBlock: tx,
|
|
481
|
+
transaction: tx,
|
|
481
482
|
});
|
|
482
|
-
|
|
483
|
+
// @ts-ignore
|
|
484
|
+
if (!res.commandResults?.[0]?.returnValues?.[0]?.[0]) {
|
|
483
485
|
return [];
|
|
484
486
|
}
|
|
485
|
-
|
|
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
|
|
501
|
-
|
|
502
|
-
|
|
502
|
+
const vaultResponse = await client.getObject({
|
|
503
|
+
objectId: profitVaultId,
|
|
504
|
+
include: { content: true },
|
|
503
505
|
});
|
|
504
|
-
if (!vaultResponse.
|
|
506
|
+
if (!vaultResponse.object.content) {
|
|
505
507
|
return [];
|
|
506
508
|
}
|
|
507
|
-
const fields = vaultResponse.
|
|
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
|
|
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.
|
|
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.
|
|
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
|
|
553
|
-
|
|
554
|
-
|
|
553
|
+
const vaultResponse = await client.getObject({
|
|
554
|
+
objectId: input?.lockVault ?? _1.LOCK_VAULT,
|
|
555
|
+
include: { content: true },
|
|
555
556
|
});
|
|
556
|
-
if (!vaultResponse.
|
|
557
|
+
if (!vaultResponse.object.content) {
|
|
557
558
|
return [];
|
|
558
559
|
}
|
|
559
|
-
const fields = vaultResponse.
|
|
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
|
|
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.
|
|
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.
|
|
583
|
+
cursor = dynamicFields.cursor ?? null;
|
|
583
584
|
}
|
|
584
585
|
// 3. For each user, fetch their locked profits
|
|
585
586
|
const fetchLockedUserProfitsPromises = [];
|