@typus/typus-perp-sdk 1.2.1 → 1.3.0
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/client.d.ts +22 -3
- package/dist/src/client.js +66 -8
- package/dist/src/fetch.d.ts +61 -20
- package/dist/src/fetch.js +20 -14
- package/dist/src/generated/typus_perp/admin.d.ts +65 -21
- package/dist/src/generated/typus_perp/admin.js +139 -123
- package/dist/src/generated/typus_perp/competition.d.ts +5 -17
- package/dist/src/generated/typus_perp/competition.js +63 -39
- package/dist/src/generated/typus_perp/deps/std/type_name.d.ts +9 -9
- package/dist/src/generated/typus_perp/deps/std/type_name.js +13 -16
- package/dist/src/generated/typus_perp/deps/sui/balance.d.ts +2 -2
- package/dist/src/generated/typus_perp/deps/sui/balance.js +5 -8
- package/dist/src/generated/typus_perp/deps/sui/object.d.ts +8 -0
- package/dist/src/generated/typus_perp/deps/sui/object.js +13 -0
- package/dist/src/generated/typus_perp/deps/sui/object_table.d.ts +5 -3
- package/dist/src/generated/typus_perp/deps/sui/object_table.js +40 -9
- package/dist/src/generated/typus_perp/deps/sui/table.d.ts +5 -3
- package/dist/src/generated/typus_perp/deps/sui/table.js +40 -9
- package/dist/src/generated/typus_perp/deps/sui/vec_set.d.ts +5 -3
- package/dist/src/generated/typus_perp/deps/sui/vec_set.js +5 -8
- package/dist/src/generated/typus_perp/deps/typus/keyed_big_vector.d.ts +4 -2
- package/dist/src/generated/typus_perp/deps/typus/keyed_big_vector.js +9 -12
- package/dist/src/generated/typus_perp/deps/typus/linked_object_table.d.ts +12 -6
- package/dist/src/generated/typus_perp/deps/typus/linked_object_table.js +41 -10
- package/dist/src/generated/typus_perp/deps/typus_framework/vault.d.ts +4 -2
- package/dist/src/generated/typus_perp/deps/typus_framework/vault.js +40 -9
- package/dist/src/generated/typus_perp/error.d.ts +201 -94
- package/dist/src/generated/typus_perp/error.js +300 -273
- package/dist/src/generated/typus_perp/escrow.d.ts +14 -6
- package/dist/src/generated/typus_perp/escrow.js +38 -37
- package/dist/src/generated/typus_perp/lending.d.ts +1 -1
- package/dist/src/generated/typus_perp/lending.js +3 -3
- package/dist/src/generated/typus_perp/lp_pool.d.ts +438 -392
- package/dist/src/generated/typus_perp/lp_pool.js +987 -934
- package/dist/src/generated/typus_perp/math.d.ts +13 -16
- package/dist/src/generated/typus_perp/math.js +51 -50
- package/dist/src/generated/typus_perp/position.d.ts +194 -106
- package/dist/src/generated/typus_perp/position.js +714 -733
- package/dist/src/generated/typus_perp/profit_vault.d.ts +62 -20
- package/dist/src/generated/typus_perp/profit_vault.js +162 -148
- package/dist/src/generated/typus_perp/symbol.d.ts +12 -5
- package/dist/src/generated/typus_perp/symbol.js +28 -25
- package/dist/src/generated/typus_perp/trading.d.ts +956 -139
- package/dist/src/generated/typus_perp/trading.js +1577 -1151
- package/dist/src/generated/typus_perp/treasury_caps.d.ts +16 -7
- package/dist/src/generated/typus_perp/treasury_caps.js +60 -24
- package/dist/src/generated/typus_perp/user_account.d.ts +40 -0
- package/dist/src/generated/typus_perp/user_account.js +66 -0
- package/dist/src/generated/typus_stake_pool/admin.d.ts +144 -10
- package/dist/src/generated/typus_stake_pool/admin.js +132 -49
- package/dist/src/generated/typus_stake_pool/deps/std/type_name.d.ts +9 -9
- package/dist/src/generated/typus_stake_pool/deps/std/type_name.js +13 -16
- package/dist/src/generated/typus_stake_pool/deps/sui/object.d.ts +8 -0
- package/dist/src/generated/typus_stake_pool/deps/sui/object.js +13 -0
- package/dist/src/generated/typus_stake_pool/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/typus_stake_pool/deps/sui/vec_map.js +31 -0
- package/dist/src/generated/typus_stake_pool/deps/sui/vec_set.d.ts +5 -3
- package/dist/src/generated/typus_stake_pool/deps/sui/vec_set.js +5 -8
- package/dist/src/generated/typus_stake_pool/stake_pool.d.ts +180 -79
- package/dist/src/generated/typus_stake_pool/stake_pool.js +446 -414
- package/dist/src/generated/utils/index.d.ts +4 -23
- package/dist/src/generated/utils/index.js +34 -54
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +35 -13
- package/dist/src/user/order.d.ts +0 -4
- package/dist/src/user/order.js +31 -74
- package/dist/src/user/orderWithBidReceipt.d.ts +0 -3
- package/dist/src/user/orderWithBidReceipt.js +24 -45
- package/dist/src/user/tlp.d.ts +0 -5
- package/dist/src/user/tlp.js +28 -73
- package/package.json +42 -40
package/dist/src/client.d.ts
CHANGED
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
import { SuiGraphQLClient } from "@mysten/sui/graphql";
|
|
2
2
|
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
3
|
-
import {
|
|
3
|
+
import { PythLazerSuiClient, TypusConfig } from "@typus/typus-sdk/dist/src/utils";
|
|
4
|
+
import type { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk";
|
|
4
5
|
import { SuiClientTypes } from "@mysten/sui/client";
|
|
5
6
|
export type Network = "MAINNET" | "TESTNET";
|
|
6
7
|
export declare class TypusClient {
|
|
7
8
|
gRpcClient: SuiGrpcClient;
|
|
8
9
|
graphQLClient: SuiGraphQLClient;
|
|
9
|
-
pythClient:
|
|
10
|
+
pythClient: PythLazerSuiClient;
|
|
10
11
|
config: TypusConfig;
|
|
11
|
-
|
|
12
|
+
/**
|
|
13
|
+
* `opts.getAccessToken` is the browser path: it returns a short-lived Pyth
|
|
14
|
+
* JWT per call, so no long-lived key is needed (and none can leak into a
|
|
15
|
+
* bundle). Omit it and we fall back to the WS client off `LAZER_TOKEN`,
|
|
16
|
+
* which is what node crankers and scripts use.
|
|
17
|
+
*/
|
|
18
|
+
static create(config: TypusConfig, opts?: {
|
|
19
|
+
getAccessToken?: () => string | Promise<string>;
|
|
20
|
+
}): Promise<TypusClient>;
|
|
21
|
+
/**
|
|
22
|
+
* Stays public: most call sites build a client only for read-only views and
|
|
23
|
+
* never touch the oracle, so requiring the async `create` (and a price
|
|
24
|
+
* source) everywhere would be noise. Fetching a price without a source
|
|
25
|
+
* throws at fetch time.
|
|
26
|
+
*/
|
|
27
|
+
constructor(config: TypusConfig, priceSource?: {
|
|
28
|
+
lazer?: PythLazerClient;
|
|
29
|
+
getAccessToken?: () => string | Promise<string>;
|
|
30
|
+
});
|
|
12
31
|
getCoins(params: SuiClientTypes.ListCoinsOptions): Promise<SuiClientTypes.ListCoinsResponse>;
|
|
13
32
|
getObject(params: SuiClientTypes.GetObjectOptions): Promise<SuiClientTypes.GetObjectResponse<{}>>;
|
|
14
33
|
getOwnedObjects(params: SuiClientTypes.ListOwnedObjectsOptions): Promise<SuiClientTypes.ListOwnedObjectsResponse<{}>>;
|
package/dist/src/client.js
CHANGED
|
@@ -6,10 +6,64 @@ const graphql_1 = require("@mysten/sui/graphql");
|
|
|
6
6
|
const grpc_1 = require("@mysten/sui/grpc");
|
|
7
7
|
const utils_1 = require("@typus/typus-sdk/dist/src/utils");
|
|
8
8
|
const jsonRpc_1 = require("@mysten/sui/jsonRpc");
|
|
9
|
+
const _1 = require(".");
|
|
9
10
|
class TypusClient {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* `opts.getAccessToken` is the browser path: it returns a short-lived Pyth
|
|
13
|
+
* JWT per call, so no long-lived key is needed (and none can leak into a
|
|
14
|
+
* bundle). Omit it and we fall back to the WS client off `LAZER_TOKEN`,
|
|
15
|
+
* which is what node crankers and scripts use.
|
|
16
|
+
*/
|
|
17
|
+
static async create(config, opts) {
|
|
18
|
+
if (opts?.getAccessToken) {
|
|
19
|
+
return new TypusClient(config, { getAccessToken: opts.getAccessToken });
|
|
20
|
+
}
|
|
21
|
+
const token = process.env.LAZER_TOKEN ?? process.env.PYTH_LAZER_TOKEN;
|
|
22
|
+
if (!token) {
|
|
23
|
+
throw new Error("LAZER_TOKEN (or PYTH_LAZER_TOKEN) env var is required for Pyth Lazer client");
|
|
24
|
+
}
|
|
25
|
+
// Cast at the boundary: the dynamic import resolves the ESM decls while the
|
|
26
|
+
// type-only import above resolves the CJS ones, and TS treats the two
|
|
27
|
+
// PythLazerClient declarations as distinct (separate private members).
|
|
28
|
+
const { PythLazerClient } = (await import(
|
|
29
|
+
// webpackIgnore: bundlers must not follow this. It is the node-only
|
|
30
|
+
// branch, and @pythnetwork/pyth-lazer-sdk@6.2.2 ships an exports map
|
|
31
|
+
// with "default" ahead of "types", which webpack 5 rejects outright
|
|
32
|
+
// ("Default condition should be last one") — so merely resolving it
|
|
33
|
+
// fails a browser build even though the branch is never taken there.
|
|
34
|
+
/* webpackIgnore: true */ "@pythnetwork/pyth-lazer-sdk"));
|
|
35
|
+
const lazer = await PythLazerClient.create({
|
|
36
|
+
token,
|
|
37
|
+
webSocketPoolConfig: { numConnections: 1 },
|
|
38
|
+
});
|
|
39
|
+
return new TypusClient(config, { lazer });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Stays public: most call sites build a client only for read-only views and
|
|
43
|
+
* never touch the oracle, so requiring the async `create` (and a price
|
|
44
|
+
* source) everywhere would be noise. Fetching a price without a source
|
|
45
|
+
* throws at fetch time.
|
|
46
|
+
*/
|
|
47
|
+
constructor(config, priceSource = {}) {
|
|
48
|
+
// typus-config@main is stale (advertises old oracle + old perp pkgs).
|
|
49
|
+
// Applied here rather than in `create` because most call sites use the
|
|
50
|
+
// constructor directly — overriding only in `create` left them on the
|
|
51
|
+
// pre-OracleV2 packages.
|
|
52
|
+
if (_1.ORACLE_PACKAGE_ID) {
|
|
53
|
+
config.package.oracle = _1.ORACLE_PACKAGE_ID;
|
|
54
|
+
}
|
|
55
|
+
if (_1.PERP_PACKAGE_ID) {
|
|
56
|
+
config.package.perp.perp = _1.PERP_PACKAGE_ID;
|
|
57
|
+
}
|
|
58
|
+
if (_1.STAKE_PACKAGE_ID) {
|
|
59
|
+
config.package.perp.stakePool = _1.STAKE_PACKAGE_ID;
|
|
60
|
+
}
|
|
61
|
+
// typus-config@main points at the old DOV registry; the new typus_perp links
|
|
62
|
+
// against the 0x02821e55 DOV family — override so bid-receipt / liquidation
|
|
63
|
+
// views pass the right &DovRegistry type.
|
|
64
|
+
if (_1.DOV_SINGLE_REGISTRY && config.registry?.dov) {
|
|
65
|
+
config.registry.dov.dovSingle = _1.DOV_SINGLE_REGISTRY;
|
|
66
|
+
}
|
|
13
67
|
this.config = config;
|
|
14
68
|
const network = config.network.toLowerCase();
|
|
15
69
|
const mvr = {
|
|
@@ -18,10 +72,6 @@ class TypusClient {
|
|
|
18
72
|
"@typus/perp": config.package.perp.perp,
|
|
19
73
|
"@typus/stake-pool": config.package.perp.stakePool,
|
|
20
74
|
},
|
|
21
|
-
// types: {
|
|
22
|
-
// "@typus/perp": PERP_PACKAGE_ID,
|
|
23
|
-
// "@typus/stake-pool": STAKE_PACKAGE_ID,
|
|
24
|
-
// },
|
|
25
75
|
},
|
|
26
76
|
};
|
|
27
77
|
this.gRpcClient = new grpc_1.SuiGrpcClient({
|
|
@@ -38,7 +88,15 @@ class TypusClient {
|
|
|
38
88
|
network: network,
|
|
39
89
|
transport: new jsonRpc_1.JsonRpcHTTPTransport({ url: config.rpcEndpoint }),
|
|
40
90
|
});
|
|
41
|
-
this.pythClient =
|
|
91
|
+
this.pythClient = new utils_1.PythLazerSuiClient({
|
|
92
|
+
...priceSource,
|
|
93
|
+
sui: jsonRpcClient,
|
|
94
|
+
network: config.network,
|
|
95
|
+
lazerPackage: _1.PYTH_LAZER_PACKAGE_ID,
|
|
96
|
+
oraclePackage: _1.ORACLE_PACKAGE_ID,
|
|
97
|
+
oracleV2Id: _1.ORACLE_V2_ID,
|
|
98
|
+
stateObjectId: _1.PYTH_LAZER_STATE_ID,
|
|
99
|
+
});
|
|
42
100
|
}
|
|
43
101
|
getCoins(params) {
|
|
44
102
|
return this.gRpcClient.listCoins(params);
|
package/dist/src/fetch.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ 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:
|
|
5
|
+
id: {
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
6
8
|
index: string;
|
|
7
9
|
lp_token_type: {
|
|
8
10
|
name: string;
|
|
@@ -64,7 +66,9 @@ export declare function getLpPools(client: TypusClient): Promise<{
|
|
|
64
66
|
};
|
|
65
67
|
liquidated_unsettled_receipts: {
|
|
66
68
|
receipt: {
|
|
67
|
-
id:
|
|
69
|
+
id: {
|
|
70
|
+
id: string;
|
|
71
|
+
};
|
|
68
72
|
vid: string;
|
|
69
73
|
index: string;
|
|
70
74
|
metadata: string;
|
|
@@ -87,7 +91,9 @@ export declare function getLpPools(client: TypusClient): Promise<{
|
|
|
87
91
|
bcs_padding: number[];
|
|
88
92
|
}[]>;
|
|
89
93
|
export declare function getLpPool(client: TypusClient, objectId: string): Promise<{
|
|
90
|
-
id:
|
|
94
|
+
id: {
|
|
95
|
+
id: string;
|
|
96
|
+
};
|
|
91
97
|
index: string;
|
|
92
98
|
lp_token_type: {
|
|
93
99
|
name: string;
|
|
@@ -149,7 +155,9 @@ export declare function getLpPool(client: TypusClient, objectId: string): Promis
|
|
|
149
155
|
};
|
|
150
156
|
liquidated_unsettled_receipts: {
|
|
151
157
|
receipt: {
|
|
152
|
-
id:
|
|
158
|
+
id: {
|
|
159
|
+
id: string;
|
|
160
|
+
};
|
|
153
161
|
vid: string;
|
|
154
162
|
index: string;
|
|
155
163
|
metadata: string;
|
|
@@ -172,7 +180,9 @@ export declare function getLpPool(client: TypusClient, objectId: string): Promis
|
|
|
172
180
|
bcs_padding: number[];
|
|
173
181
|
}>;
|
|
174
182
|
export declare function getStakePools(client: TypusClient): Promise<{
|
|
175
|
-
id:
|
|
183
|
+
id: {
|
|
184
|
+
id: string;
|
|
185
|
+
};
|
|
176
186
|
pool_info: {
|
|
177
187
|
stake_token: {
|
|
178
188
|
name: string;
|
|
@@ -210,7 +220,9 @@ export declare function getStakePools(client: TypusClient): Promise<{
|
|
|
210
220
|
u64_padding: string[];
|
|
211
221
|
}[]>;
|
|
212
222
|
export declare function getStakePool(client: TypusClient, objectId: string): Promise<{
|
|
213
|
-
id:
|
|
223
|
+
id: {
|
|
224
|
+
id: string;
|
|
225
|
+
};
|
|
214
226
|
pool_info: {
|
|
215
227
|
stake_token: {
|
|
216
228
|
name: string;
|
|
@@ -253,7 +265,9 @@ export declare function getStakePool(client: TypusClient, objectId: string): Pro
|
|
|
253
265
|
export declare function getMarkets(client: TypusClient, input: {
|
|
254
266
|
indexes: string[];
|
|
255
267
|
}): Promise<[{
|
|
256
|
-
id:
|
|
268
|
+
id: {
|
|
269
|
+
id: string;
|
|
270
|
+
};
|
|
257
271
|
index: string;
|
|
258
272
|
lp_token_type: {
|
|
259
273
|
name: string;
|
|
@@ -267,14 +281,20 @@ export declare function getMarkets(client: TypusClient, input: {
|
|
|
267
281
|
name: string;
|
|
268
282
|
}[];
|
|
269
283
|
symbol_markets: {
|
|
270
|
-
id:
|
|
284
|
+
id: {
|
|
285
|
+
id: string;
|
|
286
|
+
};
|
|
271
287
|
size: string;
|
|
272
288
|
};
|
|
273
289
|
u64_padding: string[];
|
|
274
290
|
}, {
|
|
275
|
-
id:
|
|
276
|
-
user_positions: {
|
|
291
|
+
id: {
|
|
277
292
|
id: string;
|
|
293
|
+
};
|
|
294
|
+
user_positions: {
|
|
295
|
+
id: {
|
|
296
|
+
id: string;
|
|
297
|
+
};
|
|
278
298
|
key_type: {
|
|
279
299
|
name: string;
|
|
280
300
|
};
|
|
@@ -285,8 +305,12 @@ export declare function getMarkets(client: TypusClient, input: {
|
|
|
285
305
|
slice_size: number;
|
|
286
306
|
length: string;
|
|
287
307
|
};
|
|
288
|
-
token_collateral_orders:
|
|
289
|
-
|
|
308
|
+
token_collateral_orders: {
|
|
309
|
+
id: string;
|
|
310
|
+
};
|
|
311
|
+
option_collateral_orders: {
|
|
312
|
+
id: string;
|
|
313
|
+
};
|
|
290
314
|
market_info: {
|
|
291
315
|
is_active: boolean;
|
|
292
316
|
size_decimal: string;
|
|
@@ -314,7 +338,6 @@ export declare function getMarkets(client: TypusClient, input: {
|
|
|
314
338
|
basic_funding_rate: string;
|
|
315
339
|
funding_interval_ts_ms: string;
|
|
316
340
|
exp_multiplier: string;
|
|
317
|
-
cool_down_threshold_ts_ms: string;
|
|
318
341
|
u64_padding: string[];
|
|
319
342
|
};
|
|
320
343
|
}[]][]>;
|
|
@@ -335,7 +358,9 @@ export declare function getUserPositions(client: TypusClient, input: {
|
|
|
335
358
|
indexes: string[];
|
|
336
359
|
}): Promise<PositionWithMarketIndex[]>;
|
|
337
360
|
export declare function parseOptionBidReceipts(positions: (typeof Position.$inferType)[]): ({
|
|
338
|
-
id:
|
|
361
|
+
id: {
|
|
362
|
+
id: string;
|
|
363
|
+
};
|
|
339
364
|
vid: string;
|
|
340
365
|
index: string;
|
|
341
366
|
metadata: string;
|
|
@@ -357,10 +382,24 @@ export declare function getUserStake(client: TypusClient, input: {
|
|
|
357
382
|
shares: string;
|
|
358
383
|
unsubscribed_ts_ms: string;
|
|
359
384
|
unlocked_ts_ms: string;
|
|
360
|
-
unsubscribed_incentive_price_index:
|
|
385
|
+
unsubscribed_incentive_price_index: {
|
|
386
|
+
contents: {
|
|
387
|
+
key: {
|
|
388
|
+
name: string;
|
|
389
|
+
};
|
|
390
|
+
value: string;
|
|
391
|
+
}[];
|
|
392
|
+
};
|
|
361
393
|
u64_padding: string[];
|
|
362
394
|
}[];
|
|
363
|
-
last_incentive_price_index:
|
|
395
|
+
last_incentive_price_index: {
|
|
396
|
+
contents: {
|
|
397
|
+
key: {
|
|
398
|
+
name: string;
|
|
399
|
+
};
|
|
400
|
+
value: string;
|
|
401
|
+
}[];
|
|
402
|
+
};
|
|
364
403
|
snapshot_ts_ms: string;
|
|
365
404
|
tlp_price: string;
|
|
366
405
|
harvested_amount: string;
|
|
@@ -402,9 +441,10 @@ export declare function getAllPositions(client: TypusClient, input: {
|
|
|
402
441
|
marketIndex: string;
|
|
403
442
|
}): Promise<{
|
|
404
443
|
positions: {
|
|
405
|
-
id:
|
|
444
|
+
id: {
|
|
445
|
+
id: string;
|
|
446
|
+
};
|
|
406
447
|
create_ts_ms: string;
|
|
407
|
-
update_ts_ms: string;
|
|
408
448
|
position_id: string;
|
|
409
449
|
linked_order_ids: string[];
|
|
410
450
|
linked_order_prices: string[];
|
|
@@ -451,9 +491,10 @@ export declare function getAllPositionsWithTradingSymbol(client: TypusClient, in
|
|
|
451
491
|
baseToken: TOKEN;
|
|
452
492
|
marketIndex: string;
|
|
453
493
|
}): Promise<{
|
|
454
|
-
id:
|
|
494
|
+
id: {
|
|
495
|
+
id: string;
|
|
496
|
+
};
|
|
455
497
|
create_ts_ms: string;
|
|
456
|
-
update_ts_ms: string;
|
|
457
498
|
position_id: string;
|
|
458
499
|
linked_order_ids: string[];
|
|
459
500
|
linked_order_prices: string[];
|
package/dist/src/fetch.js
CHANGED
|
@@ -19,7 +19,6 @@ const transactions_1 = require("@mysten/sui/transactions");
|
|
|
19
19
|
const bcs_1 = require("@mysten/bcs");
|
|
20
20
|
const constants_1 = require("@typus/typus-sdk/dist/src/constants");
|
|
21
21
|
const utils_1 = require("@typus/typus-sdk/dist/src/utils");
|
|
22
|
-
const utils_2 = require("@typus/typus-sdk/dist/src/utils");
|
|
23
22
|
const _1 = require(".");
|
|
24
23
|
const trading_1 = require("./generated/typus_perp/trading");
|
|
25
24
|
const lp_pool_1 = require("./generated/typus_perp/lp_pool");
|
|
@@ -28,7 +27,7 @@ const trading_2 = require("./generated/typus_perp/trading");
|
|
|
28
27
|
const lp_pool_2 = require("./generated/typus_perp/lp_pool");
|
|
29
28
|
const stake_pool_1 = require("./generated/typus_stake_pool/stake_pool");
|
|
30
29
|
const vault_1 = require("./generated/typus_perp/deps/typus_framework/vault");
|
|
31
|
-
const
|
|
30
|
+
const utils_2 = require("@mysten/sui/utils");
|
|
32
31
|
async function getLpPools(client) {
|
|
33
32
|
// let dynamicFields = await client.getDynamicFields({
|
|
34
33
|
// parentId: LIQUIDITY_POOL,
|
|
@@ -98,7 +97,12 @@ async function getMarkets(client, input) {
|
|
|
98
97
|
// let bcs = await tx.build({ client: client.gRpcClient, onlyTransactionKind: true });
|
|
99
98
|
// // console.log("bcs", bcs);
|
|
100
99
|
// let res = await client.simulateTransaction(bcs);
|
|
100
|
+
tx.setSender("0x0000000000000000000000000000000000000000000000000000000000000001");
|
|
101
101
|
let devInspectTransactionBlockResult = await client.devInspectTransactionBlock({ transaction: tx });
|
|
102
|
+
if (!devInspectTransactionBlockResult.commandResults || devInspectTransactionBlockResult.FailedTransaction) {
|
|
103
|
+
console.error("getMarkets devInspect failed:", JSON.stringify(devInspectTransactionBlockResult, null, 2));
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
102
106
|
// @ts-ignore
|
|
103
107
|
let bytes = devInspectTransactionBlockResult.commandResults[0].returnValues[0].bcs;
|
|
104
108
|
let reader = new bcs_1.BcsReader(new Uint8Array(bytes));
|
|
@@ -300,18 +304,14 @@ async function getLiquidationPriceAndPnl(client, input) {
|
|
|
300
304
|
tokens.push(TOKEN);
|
|
301
305
|
tokens.push(BASE_TOKEN);
|
|
302
306
|
}
|
|
303
|
-
const tokensWithoutTypus = tokens.filter((token) => token !== "TYPUS");
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
(0, utils_1.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
|
|
307
|
+
const tokensWithoutTypus = Array.from(new Set(tokens.filter((token) => token !== "TYPUS")));
|
|
308
|
+
if (tokensWithoutTypus.length > 0) {
|
|
309
|
+
await client.pythClient.updateOracleV2WithPythLazer(tx, tokensWithoutTypus);
|
|
307
310
|
}
|
|
308
311
|
if (tokens.includes("TYPUS")) {
|
|
309
|
-
tx = await (0,
|
|
312
|
+
tx = await (0, utils_1.updateOracleWithSignatureTx)(_1.NETWORK, tx, client.config.package.oracle, constants_1.tokenType[_1.NETWORK]["TYPUS"]);
|
|
310
313
|
}
|
|
311
314
|
for (let position of input.positions) {
|
|
312
|
-
// parse from Position
|
|
313
|
-
let TOKEN = (0, constants_1.typeArgToAsset)(position.collateral_token.name);
|
|
314
|
-
let BASE_TOKEN = (0, constants_1.typeArgToAsset)(position.symbol.base_token.name);
|
|
315
315
|
// @ts-ignore
|
|
316
316
|
let index = position.marketIndex;
|
|
317
317
|
tx.add((0, trading_2.getEstimatedLiquidationPriceAndPnl)({
|
|
@@ -319,17 +319,23 @@ async function getLiquidationPriceAndPnl(client, input) {
|
|
|
319
319
|
version: _1.PERP_VERSION,
|
|
320
320
|
registry: _1.MARKET,
|
|
321
321
|
poolRegistry: _1.LP_POOL,
|
|
322
|
+
dovRegistry: client.config.registry.dov.dovSingle,
|
|
323
|
+
oracleV2: _1.ORACLE_V2_ID,
|
|
322
324
|
marketIndex: BigInt(index),
|
|
323
325
|
poolIndex: BigInt(index),
|
|
324
|
-
typusOracleCToken: constants_1.oracle[_1.NETWORK][TOKEN],
|
|
325
|
-
typusOracleTradingSymbol: constants_1.oracle[_1.NETWORK][BASE_TOKEN],
|
|
326
326
|
positionId: BigInt(position.position_id),
|
|
327
|
-
dovRegistry: client.config.registry.dov.dovSingle,
|
|
328
327
|
},
|
|
329
|
-
typeArguments: [(0,
|
|
328
|
+
typeArguments: [(0, utils_2.normalizeStructTag)(position.collateral_token.name), (0, utils_2.normalizeStructTag)(position.symbol.base_token.name)],
|
|
330
329
|
}));
|
|
331
330
|
}
|
|
331
|
+
if (input.positions.length > 0) {
|
|
332
|
+
tx.setSender(input.positions[0].user);
|
|
333
|
+
}
|
|
332
334
|
let res = await client.devInspectTransactionBlock({ transaction: tx });
|
|
335
|
+
if (res.FailedTransaction) {
|
|
336
|
+
console.error("getLiquidationPriceAndPnl devInspect failed:", JSON.stringify(res.FailedTransaction.status.error, null, 2));
|
|
337
|
+
return [];
|
|
338
|
+
}
|
|
333
339
|
// console.log(res);
|
|
334
340
|
// 0 estimated_liquidation_price,
|
|
335
341
|
// 1 has_profit,
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* Perpetual Protocol. It includes version management, authority control, and fee
|
|
7
7
|
* handling.
|
|
8
8
|
*/
|
|
9
|
-
import { MoveStruct, type RawTransactionArgument } from
|
|
10
|
-
import { type Transaction } from
|
|
9
|
+
import { MoveStruct, type RawTransactionArgument } from '../utils/index';
|
|
10
|
+
import { type Transaction } from '@mysten/sui/transactions';
|
|
11
11
|
export declare const FeeInfo: MoveStruct<{
|
|
12
12
|
/** The type name of the token. */
|
|
13
13
|
token: MoveStruct<{
|
|
@@ -17,7 +17,9 @@ export declare const FeeInfo: MoveStruct<{
|
|
|
17
17
|
value: import("@mysten/sui/bcs", { with: { "resolution-mode": "import" } }).BcsType<string, string | number | bigint, "u64">;
|
|
18
18
|
}, "@typus/perp::admin::FeeInfo">;
|
|
19
19
|
export declare const FeePool: MoveStruct<{
|
|
20
|
-
id:
|
|
20
|
+
id: MoveStruct<{
|
|
21
|
+
id: import("@mysten/sui/bcs", { with: { "resolution-mode": "import" } }).BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
22
|
+
}, "0x2::object::UID">;
|
|
21
23
|
/** A vector of `FeeInfo` structs. */
|
|
22
24
|
fee_infos: import("@mysten/sui/bcs", { with: { "resolution-mode": "import" } }).BcsType<{
|
|
23
25
|
token: {
|
|
@@ -34,12 +36,16 @@ export declare const FeePool: MoveStruct<{
|
|
|
34
36
|
}, string>;
|
|
35
37
|
}, "@typus/perp::admin::FeePool">;
|
|
36
38
|
export declare const Version: MoveStruct<{
|
|
37
|
-
id:
|
|
39
|
+
id: MoveStruct<{
|
|
40
|
+
id: import("@mysten/sui/bcs", { with: { "resolution-mode": "import" } }).BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
41
|
+
}, "0x2::object::UID">;
|
|
38
42
|
/** The version number. */
|
|
39
43
|
value: import("@mysten/sui/bcs", { with: { "resolution-mode": "import" } }).BcsType<string, string | number | bigint, "u64">;
|
|
40
44
|
/** The fee pool for protocol fees. */
|
|
41
45
|
fee_pool: MoveStruct<{
|
|
42
|
-
id:
|
|
46
|
+
id: MoveStruct<{
|
|
47
|
+
id: import("@mysten/sui/bcs", { with: { "resolution-mode": "import" } }).BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
48
|
+
}, "0x2::object::UID">;
|
|
43
49
|
/** A vector of `FeeInfo` structs. */
|
|
44
50
|
fee_infos: import("@mysten/sui/bcs", { with: { "resolution-mode": "import" } }).BcsType<{
|
|
45
51
|
token: {
|
|
@@ -57,7 +63,9 @@ export declare const Version: MoveStruct<{
|
|
|
57
63
|
}, "@typus/perp::admin::FeePool">;
|
|
58
64
|
/** The fee pool for liquidator fees. */
|
|
59
65
|
liquidator_fee_pool: MoveStruct<{
|
|
60
|
-
id:
|
|
66
|
+
id: MoveStruct<{
|
|
67
|
+
id: import("@mysten/sui/bcs", { with: { "resolution-mode": "import" } }).BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
68
|
+
}, "0x2::object::UID">;
|
|
61
69
|
/** A vector of `FeeInfo` structs. */
|
|
62
70
|
fee_infos: import("@mysten/sui/bcs", { with: { "resolution-mode": "import" } }).BcsType<{
|
|
63
71
|
token: {
|
|
@@ -113,7 +121,9 @@ export interface VersionCheckArguments {
|
|
|
113
121
|
}
|
|
114
122
|
export interface VersionCheckOptions {
|
|
115
123
|
package?: string;
|
|
116
|
-
arguments: VersionCheckArguments | [
|
|
124
|
+
arguments: VersionCheckArguments | [
|
|
125
|
+
version: RawTransactionArgument<string>
|
|
126
|
+
];
|
|
117
127
|
}
|
|
118
128
|
/** Checks if the contract version is valid. */
|
|
119
129
|
export declare function versionCheck(options: VersionCheckOptions): (tx: Transaction) => import("@mysten/sui/transactions", { with: { "resolution-mode": "import" } }).TransactionResult;
|
|
@@ -122,13 +132,16 @@ export interface UpgradeArguments {
|
|
|
122
132
|
}
|
|
123
133
|
export interface UpgradeOptions {
|
|
124
134
|
package?: string;
|
|
125
|
-
arguments: UpgradeArguments | [
|
|
135
|
+
arguments: UpgradeArguments | [
|
|
136
|
+
version: RawTransactionArgument<string>
|
|
137
|
+
];
|
|
126
138
|
}
|
|
127
139
|
/** Upgrades the contract version. WARNING: no authority check inside */
|
|
128
140
|
export declare function upgrade(options: UpgradeOptions): (tx: Transaction) => import("@mysten/sui/transactions", { with: { "resolution-mode": "import" } }).TransactionResult;
|
|
129
141
|
export interface InitOptions {
|
|
130
142
|
package?: string;
|
|
131
|
-
arguments?: [
|
|
143
|
+
arguments?: [
|
|
144
|
+
];
|
|
132
145
|
}
|
|
133
146
|
export declare function init(options?: InitOptions): (tx: Transaction) => import("@mysten/sui/transactions", { with: { "resolution-mode": "import" } }).TransactionResult;
|
|
134
147
|
export interface VerifyArguments {
|
|
@@ -136,7 +149,9 @@ export interface VerifyArguments {
|
|
|
136
149
|
}
|
|
137
150
|
export interface VerifyOptions {
|
|
138
151
|
package?: string;
|
|
139
|
-
arguments: VerifyArguments | [
|
|
152
|
+
arguments: VerifyArguments | [
|
|
153
|
+
version: RawTransactionArgument<string>
|
|
154
|
+
];
|
|
140
155
|
}
|
|
141
156
|
/** [Authorized Function] Verifies if the sender is an authorized user. */
|
|
142
157
|
export declare function verify(options: VerifyOptions): (tx: Transaction) => import("@mysten/sui/transactions", { with: { "resolution-mode": "import" } }).TransactionResult;
|
|
@@ -146,8 +161,12 @@ export interface AddAuthorizedUserArguments {
|
|
|
146
161
|
}
|
|
147
162
|
export interface AddAuthorizedUserOptions {
|
|
148
163
|
package?: string;
|
|
149
|
-
arguments: AddAuthorizedUserArguments | [
|
|
164
|
+
arguments: AddAuthorizedUserArguments | [
|
|
165
|
+
version: RawTransactionArgument<string>,
|
|
166
|
+
userAddress: RawTransactionArgument<string>
|
|
167
|
+
];
|
|
150
168
|
}
|
|
169
|
+
/** [Authorized Function] Adds an authorized user. */
|
|
151
170
|
export declare function addAuthorizedUser(options: AddAuthorizedUserOptions): (tx: Transaction) => import("@mysten/sui/transactions", { with: { "resolution-mode": "import" } }).TransactionResult;
|
|
152
171
|
export interface RemoveAuthorizedUserArguments {
|
|
153
172
|
version: RawTransactionArgument<string>;
|
|
@@ -155,8 +174,12 @@ export interface RemoveAuthorizedUserArguments {
|
|
|
155
174
|
}
|
|
156
175
|
export interface RemoveAuthorizedUserOptions {
|
|
157
176
|
package?: string;
|
|
158
|
-
arguments: RemoveAuthorizedUserArguments | [
|
|
177
|
+
arguments: RemoveAuthorizedUserArguments | [
|
|
178
|
+
version: RawTransactionArgument<string>,
|
|
179
|
+
userAddress: RawTransactionArgument<string>
|
|
180
|
+
];
|
|
159
181
|
}
|
|
182
|
+
/** [Authorized Function] Removes an authorized user. */
|
|
160
183
|
export declare function removeAuthorizedUser(options: RemoveAuthorizedUserOptions): (tx: Transaction) => import("@mysten/sui/transactions", { with: { "resolution-mode": "import" } }).TransactionResult;
|
|
161
184
|
export interface InstallEcosystemManagerCapEntryArguments {
|
|
162
185
|
version: RawTransactionArgument<string>;
|
|
@@ -164,7 +187,10 @@ export interface InstallEcosystemManagerCapEntryArguments {
|
|
|
164
187
|
}
|
|
165
188
|
export interface InstallEcosystemManagerCapEntryOptions {
|
|
166
189
|
package?: string;
|
|
167
|
-
arguments: InstallEcosystemManagerCapEntryArguments | [
|
|
190
|
+
arguments: InstallEcosystemManagerCapEntryArguments | [
|
|
191
|
+
version: RawTransactionArgument<string>,
|
|
192
|
+
typusEcosystemVersion: RawTransactionArgument<string>
|
|
193
|
+
];
|
|
168
194
|
}
|
|
169
195
|
/**
|
|
170
196
|
* [Authorized Function] Installs the ecosystem manager cap. TODO: can be remove
|
|
@@ -219,8 +245,12 @@ export interface SendFeeArguments {
|
|
|
219
245
|
}
|
|
220
246
|
export interface SendFeeOptions {
|
|
221
247
|
package?: string;
|
|
222
|
-
arguments: SendFeeArguments | [
|
|
223
|
-
|
|
248
|
+
arguments: SendFeeArguments | [
|
|
249
|
+
version: RawTransactionArgument<string>
|
|
250
|
+
];
|
|
251
|
+
typeArguments: [
|
|
252
|
+
string
|
|
253
|
+
];
|
|
224
254
|
}
|
|
225
255
|
/**
|
|
226
256
|
* Sends the collected fees to the fee address. Safe with constant address as
|
|
@@ -233,8 +263,13 @@ export interface ChargeFeeArguments {
|
|
|
233
263
|
}
|
|
234
264
|
export interface ChargeFeeOptions {
|
|
235
265
|
package?: string;
|
|
236
|
-
arguments: ChargeFeeArguments | [
|
|
237
|
-
|
|
266
|
+
arguments: ChargeFeeArguments | [
|
|
267
|
+
version: RawTransactionArgument<string>,
|
|
268
|
+
balance: RawTransactionArgument<string>
|
|
269
|
+
];
|
|
270
|
+
typeArguments: [
|
|
271
|
+
string
|
|
272
|
+
];
|
|
238
273
|
}
|
|
239
274
|
/** Charges a protocol fee. */
|
|
240
275
|
export declare function chargeFee(options: ChargeFeeOptions): (tx: Transaction) => import("@mysten/sui/transactions", { with: { "resolution-mode": "import" } }).TransactionResult;
|
|
@@ -243,8 +278,12 @@ export interface SendLiquidatorFeeArguments {
|
|
|
243
278
|
}
|
|
244
279
|
export interface SendLiquidatorFeeOptions {
|
|
245
280
|
package?: string;
|
|
246
|
-
arguments: SendLiquidatorFeeArguments | [
|
|
247
|
-
|
|
281
|
+
arguments: SendLiquidatorFeeArguments | [
|
|
282
|
+
version: RawTransactionArgument<string>
|
|
283
|
+
];
|
|
284
|
+
typeArguments: [
|
|
285
|
+
string
|
|
286
|
+
];
|
|
248
287
|
}
|
|
249
288
|
/**
|
|
250
289
|
* Sends the liquidator fees to the fee address. Safe with constant address as
|
|
@@ -257,8 +296,13 @@ export interface ChargeLiquidatorFeeArguments {
|
|
|
257
296
|
}
|
|
258
297
|
export interface ChargeLiquidatorFeeOptions {
|
|
259
298
|
package?: string;
|
|
260
|
-
arguments: ChargeLiquidatorFeeArguments | [
|
|
261
|
-
|
|
299
|
+
arguments: ChargeLiquidatorFeeArguments | [
|
|
300
|
+
version: RawTransactionArgument<string>,
|
|
301
|
+
balance: RawTransactionArgument<string>
|
|
302
|
+
];
|
|
303
|
+
typeArguments: [
|
|
304
|
+
string
|
|
305
|
+
];
|
|
262
306
|
}
|
|
263
307
|
/** Charges a liquidator fee. */
|
|
264
308
|
export declare function chargeLiquidatorFee(options: ChargeLiquidatorFeeOptions): (tx: Transaction) => import("@mysten/sui/transactions", { with: { "resolution-mode": "import" } }).TransactionResult;
|