@typus/typus-perp-sdk 1.1.53 → 1.2.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/api/sentio.js +2 -2
- package/dist/src/client.d.ts +13 -12
- package/dist/src/client.js +24 -49
- package/dist/src/fetch.d.ts +15 -61
- package/dist/src/fetch.js +63 -163
- 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/index.js +4 -4
- package/dist/src/user/history.js +39 -23
- package/dist/src/user/order.d.ts +1 -1
- package/dist/src/user/orderWithBidReceipt.d.ts +1 -1
- package/package.json +8 -14
- 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
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
import { BcsType, TypeTag, BcsStruct, BcsEnum, BcsTuple } from "@mysten/sui/bcs";
|
|
2
2
|
import { TransactionArgument } from "@mysten/sui/transactions";
|
|
3
|
+
import { ClientWithCoreApi, SuiClientTypes } from "@mysten/sui/client";
|
|
3
4
|
export type RawTransactionArgument<T> = T | TransactionArgument;
|
|
5
|
+
export interface GetOptions<Include extends Omit<SuiClientTypes.ObjectInclude, "content"> = {}> extends SuiClientTypes.GetObjectOptions<Include> {
|
|
6
|
+
client: ClientWithCoreApi;
|
|
7
|
+
}
|
|
8
|
+
export interface GetManyOptions<Include extends Omit<SuiClientTypes.ObjectInclude, "content"> = {}> extends SuiClientTypes.GetObjectsOptions<Include> {
|
|
9
|
+
client: ClientWithCoreApi;
|
|
10
|
+
}
|
|
4
11
|
export declare function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null;
|
|
5
|
-
export declare function normalizeMoveArguments(args: unknown[] | object, argTypes: string[], parameterNames?: string[]): TransactionArgument[];
|
|
12
|
+
export declare function normalizeMoveArguments(args: unknown[] | object, argTypes: readonly (string | null)[], parameterNames?: string[]): TransactionArgument[];
|
|
6
13
|
export declare class MoveStruct<T extends Record<string, BcsType<any>>, const Name extends string = string> extends BcsStruct<T, Name> {
|
|
14
|
+
get<Include extends Omit<SuiClientTypes.ObjectInclude, "content" | "json"> = {}>({ objectId, ...options }: GetOptions<Include>): Promise<SuiClientTypes.Object<Include & {
|
|
15
|
+
content: true;
|
|
16
|
+
json: true;
|
|
17
|
+
}> & {
|
|
18
|
+
json: BcsStruct<T>["$inferType"];
|
|
19
|
+
}>;
|
|
20
|
+
getMany<Include extends Omit<SuiClientTypes.ObjectInclude, "content" | "json"> = {}>({ client, ...options }: GetManyOptions<Include>): Promise<Array<SuiClientTypes.Object<Include & {
|
|
21
|
+
content: true;
|
|
22
|
+
json: true;
|
|
23
|
+
}> & {
|
|
24
|
+
json: BcsStruct<T>["$inferType"];
|
|
25
|
+
}>>;
|
|
7
26
|
}
|
|
8
27
|
export declare class MoveEnum<T extends Record<string, BcsType<any> | null>, const Name extends string> extends BcsEnum<T, Name> {
|
|
9
28
|
}
|
|
10
|
-
export declare class MoveTuple<T extends readonly BcsType<any>[], const Name extends string> extends BcsTuple<T, Name> {
|
|
29
|
+
export declare class MoveTuple<const T extends readonly BcsType<any>[], const Name extends string> extends BcsTuple<T, Name> {
|
|
11
30
|
}
|
|
@@ -8,7 +8,6 @@ const utils_1 = require("@mysten/sui/utils");
|
|
|
8
8
|
const transactions_1 = require("@mysten/sui/transactions");
|
|
9
9
|
const MOVE_STDLIB_ADDRESS = (0, utils_1.normalizeSuiAddress)("0x1");
|
|
10
10
|
const SUI_FRAMEWORK_ADDRESS = (0, utils_1.normalizeSuiAddress)("0x2");
|
|
11
|
-
const SUI_SYSTEM_ADDRESS = (0, utils_1.normalizeSuiAddress)("0x3");
|
|
12
11
|
function getPureBcsSchema(typeTag) {
|
|
13
12
|
const parsedTag = typeof typeTag === "string" ? bcs_1.TypeTagSerializer.parseFromStr(typeTag) : typeTag;
|
|
14
13
|
if ("u8" in parsedTag) {
|
|
@@ -41,7 +40,7 @@ function getPureBcsSchema(typeTag) {
|
|
|
41
40
|
}
|
|
42
41
|
else if ("struct" in parsedTag) {
|
|
43
42
|
const structTag = parsedTag.struct;
|
|
44
|
-
const pkg = (0, utils_1.normalizeSuiAddress)(
|
|
43
|
+
const pkg = (0, utils_1.normalizeSuiAddress)(structTag.address);
|
|
45
44
|
if (pkg === MOVE_STDLIB_ADDRESS) {
|
|
46
45
|
if ((structTag.module === "ascii" || structTag.module === "string") && structTag.name === "String") {
|
|
47
46
|
return bcs_1.bcs.String;
|
|
@@ -51,7 +50,7 @@ function getPureBcsSchema(typeTag) {
|
|
|
51
50
|
return type ? bcs_1.bcs.option(type) : null;
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
|
-
if (pkg === SUI_FRAMEWORK_ADDRESS && structTag.module === "
|
|
53
|
+
if (pkg === SUI_FRAMEWORK_ADDRESS && structTag.module === "object" && (structTag.name === "ID" || structTag.name === "UID")) {
|
|
55
54
|
return bcs_1.bcs.Address;
|
|
56
55
|
}
|
|
57
56
|
}
|
|
@@ -65,19 +64,19 @@ function normalizeMoveArguments(args, argTypes, parameterNames) {
|
|
|
65
64
|
const normalizedArgs = [];
|
|
66
65
|
let index = 0;
|
|
67
66
|
for (const [i, argType] of argTypes.entries()) {
|
|
68
|
-
if (argType ===
|
|
69
|
-
normalizedArgs.push((tx) => tx.object.
|
|
67
|
+
if (argType === "0x2::clock::Clock") {
|
|
68
|
+
normalizedArgs.push((tx) => tx.object.clock());
|
|
70
69
|
continue;
|
|
71
70
|
}
|
|
72
|
-
if (argType ===
|
|
71
|
+
if (argType === "0x2::random::Random") {
|
|
73
72
|
normalizedArgs.push((tx) => tx.object.random());
|
|
74
73
|
continue;
|
|
75
74
|
}
|
|
76
|
-
if (argType ===
|
|
77
|
-
normalizedArgs.push((tx) => tx.object.
|
|
75
|
+
if (argType === "0x2::deny_list::DenyList") {
|
|
76
|
+
normalizedArgs.push((tx) => tx.object.denyList());
|
|
78
77
|
continue;
|
|
79
78
|
}
|
|
80
|
-
if (argType ===
|
|
79
|
+
if (argType === "0x3::sui_system::SuiSystemState") {
|
|
81
80
|
normalizedArgs.push((tx) => tx.object.system());
|
|
82
81
|
continue;
|
|
83
82
|
}
|
|
@@ -104,7 +103,7 @@ function normalizeMoveArguments(args, argTypes, parameterNames) {
|
|
|
104
103
|
continue;
|
|
105
104
|
}
|
|
106
105
|
const type = argTypes[i];
|
|
107
|
-
const bcsType = getPureBcsSchema(type);
|
|
106
|
+
const bcsType = type === null ? null : getPureBcsSchema(type);
|
|
108
107
|
if (bcsType) {
|
|
109
108
|
const bytes = bcsType.serialize(arg);
|
|
110
109
|
normalizedArgs.push((tx) => tx.pure(bytes));
|
|
@@ -119,6 +118,31 @@ function normalizeMoveArguments(args, argTypes, parameterNames) {
|
|
|
119
118
|
return normalizedArgs;
|
|
120
119
|
}
|
|
121
120
|
class MoveStruct extends bcs_1.BcsStruct {
|
|
121
|
+
async get({ objectId, ...options }) {
|
|
122
|
+
const [res] = await this.getMany({
|
|
123
|
+
...options,
|
|
124
|
+
objectIds: [objectId],
|
|
125
|
+
});
|
|
126
|
+
return res;
|
|
127
|
+
}
|
|
128
|
+
async getMany({ client, ...options }) {
|
|
129
|
+
const response = (await client.core.getObjects({
|
|
130
|
+
...options,
|
|
131
|
+
include: {
|
|
132
|
+
...options.include,
|
|
133
|
+
content: true,
|
|
134
|
+
},
|
|
135
|
+
}));
|
|
136
|
+
return response.objects.map((obj) => {
|
|
137
|
+
if (obj instanceof Error) {
|
|
138
|
+
throw obj;
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
...obj,
|
|
142
|
+
json: this.parse(obj.content),
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
}
|
|
122
146
|
}
|
|
123
147
|
exports.MoveStruct = MoveStruct;
|
|
124
148
|
class MoveEnum extends bcs_1.BcsEnum {
|
package/dist/src/index.js
CHANGED
|
@@ -60,8 +60,8 @@ exports.COMPETITION_CONFIG = exports.NETWORK == "MAINNET"
|
|
|
60
60
|
? "0xe896530a778adedc1b38e4fc31059a6557146caa7b1da56950b671a433de5f08"
|
|
61
61
|
: "0x2b811b120177839555aabdc2c28b28078170e663e855d29aa9072013d4fc918d";
|
|
62
62
|
exports.PROFIT_VAULT = exports.NETWORK == "MAINNET"
|
|
63
|
-
? "0xd24222307ba17ee1a08fe46ac587b1106e585e53f314ffffb525a4d4158b64c3"
|
|
64
|
-
: "0xb1d603139b24db2c46f6a423c8613ce677f329a0b159ff6e57672f3b663aec47";
|
|
63
|
+
? "0xd24222307ba17ee1a08fe46ac587b1106e585e53f314ffffb525a4d4158b64c3"
|
|
64
|
+
: "0xb1d603139b24db2c46f6a423c8613ce677f329a0b159ff6e57672f3b663aec47";
|
|
65
65
|
exports.LOCK_VAULT = exports.NETWORK == "MAINNET"
|
|
66
|
-
? "0x585355900351dd1915b77f31c06ae9e6d58b187de848d4e6e6a55d3789e281d6"
|
|
67
|
-
: "0x25dd9540f031b9a62b83784a727e1ef410f9aa91ecf7e3bb27a0c61f8ceecbfb";
|
|
66
|
+
? "0x585355900351dd1915b77f31c06ae9e6d58b187de848d4e6e6a55d3789e281d6"
|
|
67
|
+
: "0x25dd9540f031b9a62b83784a727e1ef410f9aa91ecf7e3bb27a0c61f8ceecbfb";
|
package/dist/src/user/history.js
CHANGED
|
@@ -36,12 +36,16 @@ async function parseUserHistory(raw_events, matchingDatas) {
|
|
|
36
36
|
// console.log(json);
|
|
37
37
|
// console.log(timestamp);
|
|
38
38
|
const [pkg, mod, name] = type.split("::");
|
|
39
|
+
let baseTokenAddress;
|
|
40
|
+
let collateralTokenAddress;
|
|
39
41
|
if (mod == "trading") {
|
|
40
42
|
switch (name) {
|
|
41
43
|
case trading_1.CreateTradingOrderEvent.name.split("::")[2]:
|
|
42
44
|
case trading_1.CreateTradingOrderWithBidReceiptsEvent.name.split("::")[2]:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
baseTokenAddress = json.base_token.name ?? json.base_token;
|
|
46
|
+
collateralTokenAddress = json.collateral_token.name ?? json.collateral_token;
|
|
47
|
+
var base_token = (0, constants_1.typeArgToAsset)(baseTokenAddress);
|
|
48
|
+
var collateral_token = (0, constants_1.typeArgToAsset)(collateralTokenAddress);
|
|
45
49
|
var market = `${base_token}/USD`;
|
|
46
50
|
var size = Number(json.size) / 10 ** (0, constants_1.assetToDecimal)(base_token);
|
|
47
51
|
var collateral;
|
|
@@ -52,8 +56,8 @@ async function parseUserHistory(raw_events, matchingDatas) {
|
|
|
52
56
|
collateral = Number(json.collateral_in_deposit_token) / 10 ** (0, constants_1.assetToDecimal)(collateral_token);
|
|
53
57
|
}
|
|
54
58
|
const marketOrderRation = json.is_long ? 1.02 : 0.9;
|
|
55
|
-
const isMarketOrder = Number(json.trigger_price) / Number(json.trading_pair_oracle_price) <=
|
|
56
|
-
|
|
59
|
+
const isMarketOrder = Number(json.trigger_price) / Number(json.trading_pair_oracle_price) <= marketOrderRation + 0.005 &&
|
|
60
|
+
Number(json.trigger_price) / Number(json.trading_pair_oracle_price) >= marketOrderRation - 0.005;
|
|
57
61
|
var order_type = "Limit";
|
|
58
62
|
var price = json.trigger_price;
|
|
59
63
|
if (json.filled || isMarketOrder) {
|
|
@@ -66,19 +70,18 @@ async function parseUserHistory(raw_events, matchingDatas) {
|
|
|
66
70
|
else if (json.reduce_only && json.is_stop_order) {
|
|
67
71
|
order_type = "Stop Loss";
|
|
68
72
|
if (json.linked_position_id != undefined) {
|
|
69
|
-
const related = matchingDatas.findLast((e) => e.position_id === json.linked_position_id &&
|
|
70
|
-
e.base_token === base_token);
|
|
73
|
+
const related = matchingDatas.findLast((e) => e.position_id === json.linked_position_id && e.base_token === base_token);
|
|
71
74
|
if (related) {
|
|
72
75
|
const positionFilledPrice = related.filled_price;
|
|
73
76
|
const orderTriggerPrice = (0, bignumber_js_1.default)(json.trigger_price).div((0, bignumber_js_1.default)(10).pow(8));
|
|
74
77
|
if (related.side === "Long") {
|
|
75
78
|
if ((0, bignumber_js_1.default)(orderTriggerPrice).gt(positionFilledPrice)) {
|
|
76
|
-
order_type =
|
|
79
|
+
order_type = "Take Profit";
|
|
77
80
|
}
|
|
78
81
|
}
|
|
79
82
|
else {
|
|
80
83
|
if ((0, bignumber_js_1.default)(orderTriggerPrice).lt(positionFilledPrice)) {
|
|
81
|
-
order_type =
|
|
84
|
+
order_type = "Take Profit";
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
}
|
|
@@ -109,8 +112,10 @@ async function parseUserHistory(raw_events, matchingDatas) {
|
|
|
109
112
|
events.push(e);
|
|
110
113
|
break;
|
|
111
114
|
case position_1.OrderFilledEvent.name.split("::")[2]:
|
|
112
|
-
|
|
113
|
-
|
|
115
|
+
baseTokenAddress = json.symbol.base_token.name ?? json.symbol.base_token;
|
|
116
|
+
collateralTokenAddress = json.collateral_token.name ?? json.collateral_token;
|
|
117
|
+
var base_token = (0, constants_1.typeArgToAsset)(baseTokenAddress);
|
|
118
|
+
var collateral_token = (0, constants_1.typeArgToAsset)(collateralTokenAddress);
|
|
114
119
|
var market = `${base_token}/USD`;
|
|
115
120
|
var size = Number(json.filled_size) / 10 ** (0, constants_1.assetToDecimal)(base_token);
|
|
116
121
|
var price = json.filled_price;
|
|
@@ -183,6 +188,8 @@ async function parseUserHistory(raw_events, matchingDatas) {
|
|
|
183
188
|
}
|
|
184
189
|
break;
|
|
185
190
|
case position_1.RealizeFundingEvent.name.split("::")[2]:
|
|
191
|
+
baseTokenAddress = json.symbol.base_token.name ?? json.symbol.base_token;
|
|
192
|
+
collateralTokenAddress = json.collateral_token.name ?? json.collateral_token;
|
|
186
193
|
var base_token = (0, constants_1.typeArgToAsset)(json.symbol.base_token.name);
|
|
187
194
|
var collateral_token = (0, constants_1.typeArgToAsset)(json.collateral_token.name);
|
|
188
195
|
var market = `${base_token}/USD`;
|
|
@@ -228,8 +235,10 @@ async function parseUserHistory(raw_events, matchingDatas) {
|
|
|
228
235
|
events.push(e);
|
|
229
236
|
break;
|
|
230
237
|
case trading_1.CancelTradingOrderEvent.name.split("::")[2]:
|
|
231
|
-
|
|
232
|
-
|
|
238
|
+
baseTokenAddress = json.base_token.name ?? json.base_token;
|
|
239
|
+
collateralTokenAddress = json.collateral_token.name ?? json.collateral_token;
|
|
240
|
+
var base_token = (0, constants_1.typeArgToAsset)(baseTokenAddress);
|
|
241
|
+
var collateral_token = (0, constants_1.typeArgToAsset)(collateralTokenAddress);
|
|
233
242
|
var market = `${base_token}/USD`;
|
|
234
243
|
var related = events.findLast((e) => e.order_id === json.order_id && e.market === market);
|
|
235
244
|
var e = {
|
|
@@ -256,8 +265,10 @@ async function parseUserHistory(raw_events, matchingDatas) {
|
|
|
256
265
|
break;
|
|
257
266
|
case trading_1.IncreaseCollateralEvent.name.split("::")[2]:
|
|
258
267
|
case trading_1.ReleaseCollateralEvent.name.split("::")[2]:
|
|
259
|
-
|
|
260
|
-
|
|
268
|
+
baseTokenAddress = json.base_token.name ?? json.base_token;
|
|
269
|
+
collateralTokenAddress = json.collateral_token.name ?? json.collateral_token;
|
|
270
|
+
var base_token = (0, constants_1.typeArgToAsset)(baseTokenAddress);
|
|
271
|
+
var collateral_token = (0, constants_1.typeArgToAsset)(collateralTokenAddress);
|
|
261
272
|
var market = `${base_token}/USD`;
|
|
262
273
|
var related = events.find((e) => e.position_id === json.position_id && e.market === market);
|
|
263
274
|
var collateral;
|
|
@@ -296,8 +307,10 @@ async function parseUserHistory(raw_events, matchingDatas) {
|
|
|
296
307
|
events.push(e);
|
|
297
308
|
break;
|
|
298
309
|
case lp_pool_1.SwapEvent.name.split("::")[2]:
|
|
299
|
-
|
|
300
|
-
|
|
310
|
+
let fromTokenAddress = json.from_token_type.name ?? json.from_token_type;
|
|
311
|
+
let toTokenAddress = json.to_token_type.name ?? json.to_token_type;
|
|
312
|
+
var from_token = (0, constants_1.typeArgToAsset)(fromTokenAddress);
|
|
313
|
+
var to_token = (0, constants_1.typeArgToAsset)(toTokenAddress);
|
|
301
314
|
var from_price = Number(json.oracle_price_from_token);
|
|
302
315
|
var to_price = Number(json.oracle_price_to_token);
|
|
303
316
|
var e = {
|
|
@@ -327,7 +340,8 @@ async function parseUserHistory(raw_events, matchingDatas) {
|
|
|
327
340
|
if (mod === "profit_vault") {
|
|
328
341
|
switch (name) {
|
|
329
342
|
case profit_vault_1.WithdrawProfitEvent.name.split("::")[2]:
|
|
330
|
-
|
|
343
|
+
let profitTokenAddress = json.token_type.name ?? json.token_type;
|
|
344
|
+
const profit_token = (0, constants_1.typeArgToAsset)(profitTokenAddress);
|
|
331
345
|
const profit_token_decimal = (0, constants_1.assetToDecimal)(profit_token);
|
|
332
346
|
const profit = Number(json.withdraw_amount) / 10 ** profit_token_decimal;
|
|
333
347
|
const e = {
|
|
@@ -335,12 +349,12 @@ async function parseUserHistory(raw_events, matchingDatas) {
|
|
|
335
349
|
typeName: name,
|
|
336
350
|
order_id: undefined,
|
|
337
351
|
position_id: undefined,
|
|
338
|
-
market:
|
|
352
|
+
market: "TYPUS/USD",
|
|
339
353
|
side: undefined,
|
|
340
354
|
order_type: undefined,
|
|
341
|
-
status:
|
|
355
|
+
status: "Filled",
|
|
342
356
|
size: undefined,
|
|
343
|
-
base_token:
|
|
357
|
+
base_token: "TYPUS",
|
|
344
358
|
collateral: profit,
|
|
345
359
|
collateral_token: profit_token,
|
|
346
360
|
price: undefined,
|
|
@@ -659,16 +673,18 @@ async function getOrderMatchFromSentio(userAddress, startTimestamp, events, remo
|
|
|
659
673
|
if (related) {
|
|
660
674
|
x.order_type = related.order_type;
|
|
661
675
|
if (related?.position_id !== null) {
|
|
662
|
-
const origin_order_filled_event = order_match.findLast(e => e.market == x.market && e.position_id == related?.position_id);
|
|
676
|
+
const origin_order_filled_event = order_match.findLast((e) => e.market == x.market && e.position_id == related?.position_id);
|
|
663
677
|
if (origin_order_filled_event) {
|
|
664
678
|
let origin_order_place_event = events.findLast((e) => e.order_id == origin_order_filled_event?.order_id && e.market == origin_order_filled_event.market);
|
|
665
679
|
if (!origin_order_place_event && archiveDatas) {
|
|
666
680
|
origin_order_place_event = archiveDatas.findLast((e) => e.order_id == origin_order_filled_event?.order_id && e.base_token == origin_order_filled_event.base_token);
|
|
667
681
|
}
|
|
668
682
|
const related_collateral = origin_order_place_event?.collateral ?? 0;
|
|
669
|
-
const isPartialClose = removeEventDatas.findIndex(r => r.transaction_hash === x.tx_digest);
|
|
683
|
+
const isPartialClose = removeEventDatas.findIndex((r) => r.transaction_hash === x.tx_digest);
|
|
670
684
|
if (isPartialClose !== -1) {
|
|
671
|
-
x.collateral = (0, bignumber_js_1.default)(x.collateral ?? 0)
|
|
685
|
+
x.collateral = (0, bignumber_js_1.default)(x.collateral ?? 0)
|
|
686
|
+
.plus(related_collateral)
|
|
687
|
+
.toNumber();
|
|
672
688
|
}
|
|
673
689
|
else if (x.collateral) {
|
|
674
690
|
if (x.collateral < 0) {
|
package/dist/src/user/order.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare function createTradingOrder(client: TypusClient, tx: Transaction,
|
|
|
22
22
|
linkedPositionId: string | null;
|
|
23
23
|
suiCoins?: string[];
|
|
24
24
|
}): Promise<Transaction>;
|
|
25
|
-
export declare function zeroCoin(tx: Transaction, typeArgs: [string]): import("@mysten/sui/transactions").TransactionResult;
|
|
25
|
+
export declare function zeroCoin(tx: Transaction, typeArgs: [string]): import("@mysten/sui/transactions", { with: { "resolution-mode": "import" } }).TransactionResult;
|
|
26
26
|
export declare function cancelTradingOrder(client: TypusClient, tx: Transaction, input: {
|
|
27
27
|
order: typeof TradingOrder.$inferType;
|
|
28
28
|
user: string;
|
|
@@ -6,7 +6,7 @@ export declare function splitBidReceiptTx(client: TypusClient, tx: Transaction,
|
|
|
6
6
|
receipts: TransactionObjectArgument[];
|
|
7
7
|
share?: string;
|
|
8
8
|
recipient: string;
|
|
9
|
-
}): import("@mysten/sui/transactions").TransactionResult;
|
|
9
|
+
}): import("@mysten/sui/transactions", { with: { "resolution-mode": "import" } }).TransactionResult;
|
|
10
10
|
export declare function createTradingOrderWithBidReceiptByAutoBid(client: TypusClient, tx: Transaction, input: {
|
|
11
11
|
perpIndex: string;
|
|
12
12
|
poolIndex: string;
|
package/package.json
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typus/typus-perp-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
|
|
5
5
|
"author": "Typus",
|
|
6
6
|
"description": "typus perp sdk",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@mysten/bcs": "
|
|
10
|
-
"@mysten/sui": "
|
|
11
|
-
"@typus/typus-sdk": "1.
|
|
9
|
+
"@mysten/bcs": "2.0.3",
|
|
10
|
+
"@mysten/sui": "2.13.2",
|
|
11
|
+
"@typus/typus-sdk": "1.9.0"
|
|
12
12
|
},
|
|
13
13
|
"resolutions": {
|
|
14
|
-
"@mysten/bcs": "
|
|
15
|
-
"@mysten/sui": "
|
|
14
|
+
"@mysten/bcs": "2.0.3",
|
|
15
|
+
"@mysten/sui": "2.13.2",
|
|
16
16
|
"@pythnetwork/pyth-sui-js": "2.3.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@types/
|
|
20
|
-
"@types/camelcase-keys-deep": "^0.1.2",
|
|
21
|
-
"@types/expect": "^24.3.0",
|
|
22
|
-
"@types/mocha": "^10.0.1",
|
|
23
|
-
"@types/node": "^24.10.1",
|
|
24
|
-
"@types/rx": "^4.1.2",
|
|
25
|
-
"axios": "^1.13.2",
|
|
19
|
+
"@types/node": "^25.6.0",
|
|
26
20
|
"bignumber.js": "9.1.2",
|
|
27
21
|
"prettier": "^3.0.0",
|
|
28
22
|
"ts-node": "^10.9.2",
|
|
@@ -45,4 +39,4 @@
|
|
|
45
39
|
},
|
|
46
40
|
"homepage": "https://github.com/Typus-Lab/typus-perp-sdk#readme",
|
|
47
41
|
"packageManager": "yarn@4.10.3+sha512.c38cafb5c7bb273f3926d04e55e1d8c9dfa7d9c3ea1f36a4868fa028b9e5f72298f0b7f401ad5eb921749eb012eb1c3bb74bf7503df3ee43fd600d14a018266f"
|
|
48
|
-
}
|
|
42
|
+
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**************************************************************
|
|
2
|
-
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
3
|
-
**************************************************************/
|
|
4
|
-
/** Sui object identifiers */
|
|
5
|
-
import { MoveStruct } from "../../../utils/index";
|
|
6
|
-
export declare const UID: MoveStruct<{
|
|
7
|
-
id: import("@mysten/sui/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
8
|
-
}, "0x2::object::UID">;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**************************************************************
|
|
3
|
-
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
4
|
-
**************************************************************/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.UID = void 0;
|
|
7
|
-
/** Sui object identifiers */
|
|
8
|
-
const index_1 = require("../../../utils/index");
|
|
9
|
-
const bcs_1 = require("@mysten/sui/bcs");
|
|
10
|
-
const $moduleName = "0x2::object";
|
|
11
|
-
exports.UID = new index_1.MoveStruct({
|
|
12
|
-
name: `${$moduleName}::UID`,
|
|
13
|
-
fields: {
|
|
14
|
-
id: bcs_1.bcs.Address,
|
|
15
|
-
},
|
|
16
|
-
});
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/**************************************************************
|
|
2
|
-
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
3
|
-
**************************************************************/
|
|
4
|
-
/**
|
|
5
|
-
* The `user_account` module defines the `UserAccount` and `UserAccountCap`
|
|
6
|
-
* structs, and the logic for creating, updating, and using them.
|
|
7
|
-
*/
|
|
8
|
-
import { MoveStruct, type RawTransactionArgument } from "../utils/index";
|
|
9
|
-
import { type Transaction } from "@mysten/sui/transactions";
|
|
10
|
-
export declare const UserAccount: MoveStruct<{
|
|
11
|
-
id: MoveStruct<{
|
|
12
|
-
id: import("@mysten/sui/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
13
|
-
}, "0x2::object::UID">;
|
|
14
|
-
/** The address of the owner of the user account. */
|
|
15
|
-
owner: import("@mysten/sui/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
16
|
-
/** A vector of the delegate users. */
|
|
17
|
-
delegate_user: import("@mysten/sui/bcs").BcsType<string[], Iterable<string | Uint8Array<ArrayBufferLike>> & {
|
|
18
|
-
length: number;
|
|
19
|
-
}, string>;
|
|
20
|
-
/** A vector of the symbols of the tokens in the user account. */
|
|
21
|
-
symbols: import("@mysten/sui/bcs").BcsType<{
|
|
22
|
-
name: string;
|
|
23
|
-
}[], Iterable<{
|
|
24
|
-
name: string;
|
|
25
|
-
}> & {
|
|
26
|
-
length: number;
|
|
27
|
-
}, string>;
|
|
28
|
-
/** Padding for future use. */
|
|
29
|
-
u64_padding: import("@mysten/sui/bcs").BcsType<string[], Iterable<string | number | bigint> & {
|
|
30
|
-
length: number;
|
|
31
|
-
}, string>;
|
|
32
|
-
}, "@typus/perp::user_account::UserAccount">;
|
|
33
|
-
export declare const UserAccountCap: MoveStruct<{
|
|
34
|
-
id: MoveStruct<{
|
|
35
|
-
id: import("@mysten/sui/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
36
|
-
}, "0x2::object::UID">;
|
|
37
|
-
/** The address of the owner of the user account. */
|
|
38
|
-
owner: import("@mysten/sui/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
39
|
-
/** The ID of the user account. */
|
|
40
|
-
user_account_id: import("@mysten/sui/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
41
|
-
}, "@typus/perp::user_account::UserAccountCap">;
|
|
42
|
-
export interface NewUserAccountOptions {
|
|
43
|
-
package?: string;
|
|
44
|
-
arguments?: [];
|
|
45
|
-
}
|
|
46
|
-
/** Creates a new user account and capability. */
|
|
47
|
-
export declare function newUserAccount(options?: NewUserAccountOptions): (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
48
|
-
export interface RemoveUserAccountArguments {
|
|
49
|
-
marketId: RawTransactionArgument<string>;
|
|
50
|
-
user: RawTransactionArgument<string>;
|
|
51
|
-
userAccountCap: RawTransactionArgument<string>;
|
|
52
|
-
}
|
|
53
|
-
export interface RemoveUserAccountOptions {
|
|
54
|
-
package?: string;
|
|
55
|
-
arguments: RemoveUserAccountArguments | [marketId: RawTransactionArgument<string>, user: RawTransactionArgument<string>, userAccountCap: RawTransactionArgument<string>];
|
|
56
|
-
}
|
|
57
|
-
/** Removes a user account. WARNING: no authority check inside */
|
|
58
|
-
export declare function removeUserAccount(options: RemoveUserAccountOptions): (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
59
|
-
export interface HasUserAccountArguments {
|
|
60
|
-
marketId: RawTransactionArgument<string>;
|
|
61
|
-
user: RawTransactionArgument<string>;
|
|
62
|
-
}
|
|
63
|
-
export interface HasUserAccountOptions {
|
|
64
|
-
package?: string;
|
|
65
|
-
arguments: HasUserAccountArguments | [marketId: RawTransactionArgument<string>, user: RawTransactionArgument<string>];
|
|
66
|
-
}
|
|
67
|
-
/** Checks if a user has an account. */
|
|
68
|
-
export declare function hasUserAccount(options: HasUserAccountOptions): (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
69
|
-
export interface GetMutUserAccountArguments {
|
|
70
|
-
marketId: RawTransactionArgument<string>;
|
|
71
|
-
user: RawTransactionArgument<string>;
|
|
72
|
-
}
|
|
73
|
-
export interface GetMutUserAccountOptions {
|
|
74
|
-
package?: string;
|
|
75
|
-
arguments: GetMutUserAccountArguments | [marketId: RawTransactionArgument<string>, user: RawTransactionArgument<string>];
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Gets a mutable reference to a user account. WARNING: no security check, only
|
|
79
|
-
* delegate_user or cranker can access
|
|
80
|
-
*/
|
|
81
|
-
export declare function getMutUserAccount(options: GetMutUserAccountOptions): (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
82
|
-
export interface CheckOwnerArguments {
|
|
83
|
-
userAccount: RawTransactionArgument<string>;
|
|
84
|
-
}
|
|
85
|
-
export interface CheckOwnerOptions {
|
|
86
|
-
package?: string;
|
|
87
|
-
arguments: CheckOwnerArguments | [userAccount: RawTransactionArgument<string>];
|
|
88
|
-
}
|
|
89
|
-
/** Checks if the sender is the owner of the user account. Abort if not owner */
|
|
90
|
-
export declare function checkOwner(options: CheckOwnerOptions): (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
91
|
-
export interface AddDelegateUserArguments {
|
|
92
|
-
userAccount: RawTransactionArgument<string>;
|
|
93
|
-
user: RawTransactionArgument<string>;
|
|
94
|
-
}
|
|
95
|
-
export interface AddDelegateUserOptions {
|
|
96
|
-
package?: string;
|
|
97
|
-
arguments: AddDelegateUserArguments | [userAccount: RawTransactionArgument<string>, user: RawTransactionArgument<string>];
|
|
98
|
-
}
|
|
99
|
-
/** Adds a delegate user to a user account. WARNING: no authority check inside */
|
|
100
|
-
export declare function addDelegateUser(options: AddDelegateUserOptions): (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
101
|
-
export interface RemoveDelegateUserArguments {
|
|
102
|
-
userAccount: RawTransactionArgument<string>;
|
|
103
|
-
user: RawTransactionArgument<string>;
|
|
104
|
-
}
|
|
105
|
-
export interface RemoveDelegateUserOptions {
|
|
106
|
-
package?: string;
|
|
107
|
-
arguments: RemoveDelegateUserArguments | [userAccount: RawTransactionArgument<string>, user: RawTransactionArgument<string>];
|
|
108
|
-
}
|
|
109
|
-
/** Remove a delegate user from a user account. WARNING: no authority check inside */
|
|
110
|
-
export declare function removeDelegateUser(options: RemoveDelegateUserOptions): (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
111
|
-
export interface DepositArguments {
|
|
112
|
-
userAccount: RawTransactionArgument<string>;
|
|
113
|
-
balance: RawTransactionArgument<string>;
|
|
114
|
-
}
|
|
115
|
-
export interface DepositOptions {
|
|
116
|
-
package?: string;
|
|
117
|
-
arguments: DepositArguments | [userAccount: RawTransactionArgument<string>, balance: RawTransactionArgument<string>];
|
|
118
|
-
typeArguments: [string];
|
|
119
|
-
}
|
|
120
|
-
/** Deposits collateral into a user account. WARNING: no authority check inside */
|
|
121
|
-
export declare function deposit(options: DepositOptions): (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
122
|
-
export interface WithdrawArguments {
|
|
123
|
-
userAccount: RawTransactionArgument<string>;
|
|
124
|
-
amount: RawTransactionArgument<number | bigint | null>;
|
|
125
|
-
userAccountCap: RawTransactionArgument<string>;
|
|
126
|
-
}
|
|
127
|
-
export interface WithdrawOptions {
|
|
128
|
-
package?: string;
|
|
129
|
-
arguments: WithdrawArguments | [
|
|
130
|
-
userAccount: RawTransactionArgument<string>,
|
|
131
|
-
amount: RawTransactionArgument<number | bigint | null>,
|
|
132
|
-
userAccountCap: RawTransactionArgument<string>
|
|
133
|
-
];
|
|
134
|
-
typeArguments: [string];
|
|
135
|
-
}
|
|
136
|
-
/** Withdraws collateral from a user account. WARNING: no authority check inside */
|
|
137
|
-
export declare function withdraw(options: WithdrawOptions): (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
138
|
-
export interface GetUserAccountOwnerArguments {
|
|
139
|
-
userAccountCap: RawTransactionArgument<string>;
|
|
140
|
-
}
|
|
141
|
-
export interface GetUserAccountOwnerOptions {
|
|
142
|
-
package?: string;
|
|
143
|
-
arguments: GetUserAccountOwnerArguments | [userAccountCap: RawTransactionArgument<string>];
|
|
144
|
-
}
|
|
145
|
-
/** Gets the owner of a user account from a capability. */
|
|
146
|
-
export declare function getUserAccountOwner(options: GetUserAccountOwnerOptions): (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
|