@typus/typus-perp-sdk 1.1.5-pnl → 1.1.6
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 +7 -3
- package/dist/src/index.js +1 -1
- package/dist/src/typus_perp/trading/functions.d.ts +41 -8
- package/dist/src/typus_perp/trading/functions.js +61 -15
- package/dist/src/user/history.d.ts +4 -1
- package/dist/src/user/history.js +145 -3
- package/dist/src/user/order.d.ts +4 -0
- package/dist/src/user/order.js +48 -0
- package/dist/src/user/orderWithBidReceipt.js +2 -4
- package/package.json +1 -1
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): Promise<any[]>;
|
|
2
|
+
export declare function getFromSentio(event: string, userAddress: string, startTimestamp: 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
|
@@ -51,16 +51,20 @@ var headers = {
|
|
|
51
51
|
"api-key": "ffJa6FwxeJNrQP8NZ5doEMXqdSA7XM6mT",
|
|
52
52
|
"Content-Type": "application/json",
|
|
53
53
|
};
|
|
54
|
-
function getFromSentio(event, userAddress, startTimestamp) {
|
|
54
|
+
function getFromSentio(event, userAddress, startTimestamp, cranker) {
|
|
55
55
|
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var apiUrl, requestData, jsonData, response, data;
|
|
56
|
+
var apiUrl, crankerFilter, requestData, jsonData, response, data;
|
|
57
57
|
return __generator(this, function (_a) {
|
|
58
58
|
switch (_a.label) {
|
|
59
59
|
case 0:
|
|
60
60
|
apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
|
|
61
|
+
crankerFilter = "";
|
|
62
|
+
if (cranker) {
|
|
63
|
+
crankerFilter = "AND is_cranker == true";
|
|
64
|
+
}
|
|
61
65
|
requestData = {
|
|
62
66
|
sqlQuery: {
|
|
63
|
-
sql: "\n SELECT *\n FROM ".concat(event, "\n WHERE distinct_id = '").concat(userAddress, "' AND timestamp >= ").concat(startTimestamp, "\n ORDER BY timestamp DESC;\n "),
|
|
67
|
+
sql: "\n SELECT *\n FROM ".concat(event, "\n WHERE distinct_id = '").concat(userAddress, "' AND timestamp >= ").concat(startTimestamp, " ").concat(crankerFilter, "\n ORDER BY timestamp DESC;\n "),
|
|
64
68
|
size: 1000,
|
|
65
69
|
},
|
|
66
70
|
};
|
package/dist/src/index.js
CHANGED
|
@@ -36,7 +36,7 @@ transactions_1.Transaction.registerGlobalSerializationPlugin("namedPackagesPlugi
|
|
|
36
36
|
exports.PERP_PACKAGE_ID = exports.NETWORK == "MAINNET"
|
|
37
37
|
? "0xe27969a70f93034de9ce16e6ad661b480324574e68d15a64b513fd90eb2423e5"
|
|
38
38
|
: "0x585924f160f83ef16f8927ec117e4d740abb6f4e571ecfa89ff3e973042cb1b9";
|
|
39
|
-
exports.PERP_PUBLISHED_AT = exports.NETWORK == "MAINNET" ? "
|
|
39
|
+
exports.PERP_PUBLISHED_AT = exports.NETWORK == "MAINNET" ? "0x5687fc97b7a4adc65c282f1e4d7d1154c30a27cfdbbb9571481dcbacb50dd754" : "@typus/perp";
|
|
40
40
|
exports.PERP_PKG_V1 = exports.NETWORK == "MAINNET"
|
|
41
41
|
? "0xe27969a70f93034de9ce16e6ad661b480324574e68d15a64b513fd90eb2423e5"
|
|
42
42
|
: "0x585924f160f83ef16f8927ec117e4d740abb6f4e571ecfa89ff3e973042cb1b9";
|
|
@@ -106,6 +106,11 @@ export interface CheckOptionCollateralEnoughArgs {
|
|
|
106
106
|
clock: TransactionObjectInput;
|
|
107
107
|
}
|
|
108
108
|
export declare function checkOptionCollateralEnough(tx: Transaction, typeArg: string, args: CheckOptionCollateralEnoughArgs, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
|
|
109
|
+
export interface CheckPositionUserMatchedArgs {
|
|
110
|
+
position: TransactionObjectInput;
|
|
111
|
+
user: string | TransactionArgument;
|
|
112
|
+
}
|
|
113
|
+
export declare function checkPositionUserMatched(tx: Transaction, args: CheckPositionUserMatchedArgs, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
|
|
109
114
|
export interface CheckReserveEnoughArgs {
|
|
110
115
|
symbolMarket: TransactionObjectInput;
|
|
111
116
|
liquidityPool: TransactionObjectInput;
|
|
@@ -116,6 +121,18 @@ export interface CheckReserveEnoughArgs {
|
|
|
116
121
|
tradingPairOraclePriceDecimal: bigint | TransactionArgument;
|
|
117
122
|
}
|
|
118
123
|
export declare function checkReserveEnough(tx: Transaction, typeArg: string, args: CheckReserveEnoughArgs, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
|
|
124
|
+
export interface CollectPositionFundingFeeArgs {
|
|
125
|
+
version: TransactionObjectInput;
|
|
126
|
+
registry: TransactionObjectInput;
|
|
127
|
+
poolRegistry: TransactionObjectInput;
|
|
128
|
+
typusOracleCToken: TransactionObjectInput;
|
|
129
|
+
typusOracleTradingSymbol: TransactionObjectInput;
|
|
130
|
+
clock: TransactionObjectInput;
|
|
131
|
+
marketIndex: bigint | TransactionArgument;
|
|
132
|
+
poolIndex: bigint | TransactionArgument;
|
|
133
|
+
positionId: bigint | TransactionArgument;
|
|
134
|
+
}
|
|
135
|
+
export declare function collectPositionFundingFee(tx: Transaction, typeArgs: [string, string], args: CollectPositionFundingFeeArgs, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
|
|
119
136
|
export interface CreateTradingOrderArgs {
|
|
120
137
|
version: TransactionObjectInput;
|
|
121
138
|
registry: TransactionObjectInput;
|
|
@@ -198,6 +215,25 @@ export interface CreateTradingOrderWithBidReceiptV2Args {
|
|
|
198
215
|
user: string | TransactionArgument;
|
|
199
216
|
}
|
|
200
217
|
export declare function createTradingOrderWithBidReceiptV2(tx: Transaction, typeArgs: [string, string, string], args: CreateTradingOrderWithBidReceiptV2Args, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
|
|
218
|
+
export interface CreateTradingOrderWithBidReceiptV3Args {
|
|
219
|
+
version: TransactionObjectInput;
|
|
220
|
+
registry: TransactionObjectInput;
|
|
221
|
+
poolRegistry: TransactionObjectInput;
|
|
222
|
+
dovRegistry: TransactionObjectInput;
|
|
223
|
+
typusOracleCToken: TransactionObjectInput;
|
|
224
|
+
typusOracleTradingSymbol: TransactionObjectInput;
|
|
225
|
+
clock: TransactionObjectInput;
|
|
226
|
+
marketIndex: bigint | TransactionArgument;
|
|
227
|
+
poolIndex: bigint | TransactionArgument;
|
|
228
|
+
typusEcosystemVersion: TransactionObjectInput;
|
|
229
|
+
typusUserRegistry: TransactionObjectInput;
|
|
230
|
+
typusLeaderboardRegistry: TransactionObjectInput;
|
|
231
|
+
tailsStakingRegistry: TransactionObjectInput;
|
|
232
|
+
competitionConfig: TransactionObjectInput;
|
|
233
|
+
collateralBidReceipt: TransactionObjectInput;
|
|
234
|
+
isLong: boolean | TransactionArgument;
|
|
235
|
+
}
|
|
236
|
+
export declare function createTradingOrderWithBidReceiptV3(tx: Transaction, typeArgs: [string, string, string], args: CreateTradingOrderWithBidReceiptV3Args, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
|
|
201
237
|
export interface CreateUserAccountArgs {
|
|
202
238
|
version: TransactionObjectInput;
|
|
203
239
|
registry: TransactionObjectInput;
|
|
@@ -245,7 +281,6 @@ export interface ExecuteOrder_Args {
|
|
|
245
281
|
collateralOraclePriceDecimal: bigint | TransactionArgument;
|
|
246
282
|
tradingPairOraclePrice: bigint | TransactionArgument;
|
|
247
283
|
tradingPairOraclePriceDecimal: bigint | TransactionArgument;
|
|
248
|
-
tradingFeeMbp: bigint | TransactionArgument;
|
|
249
284
|
typusEcosystemVersion: TransactionObjectInput;
|
|
250
285
|
typusUserRegistry: TransactionObjectInput;
|
|
251
286
|
typusLeaderboardRegistry: TransactionObjectInput;
|
|
@@ -356,6 +391,11 @@ export interface GetOrdersArgs {
|
|
|
356
391
|
orderTypeTag: number | TransactionArgument;
|
|
357
392
|
}
|
|
358
393
|
export declare function getOrders(tx: Transaction, args: GetOrdersArgs, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
|
|
394
|
+
export interface GetTradingFeeConfigArgs {
|
|
395
|
+
marketConfig: TransactionObjectInput;
|
|
396
|
+
isOptionPosition: boolean | TransactionArgument;
|
|
397
|
+
}
|
|
398
|
+
export declare function getTradingFeeConfig(tx: Transaction, args: GetTradingFeeConfigArgs, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
|
|
359
399
|
export interface GetUserOrdersArgs {
|
|
360
400
|
version: TransactionObjectInput;
|
|
361
401
|
registry: TransactionObjectInput;
|
|
@@ -383,7 +423,6 @@ export interface IncreaseCollateralArgs {
|
|
|
383
423
|
collateral: TransactionObjectInput;
|
|
384
424
|
}
|
|
385
425
|
export declare function increaseCollateral(tx: Transaction, typeArgs: [string, string], args: IncreaseCollateralArgs, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
|
|
386
|
-
export declare function init(tx: Transaction, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
|
|
387
426
|
export interface InitUserAccountTableArgs {
|
|
388
427
|
version: TransactionObjectInput;
|
|
389
428
|
registry: TransactionObjectInput;
|
|
@@ -449,12 +488,6 @@ export interface ManagerCloseOptionPositionV2Args {
|
|
|
449
488
|
positionId: bigint | TransactionArgument;
|
|
450
489
|
}
|
|
451
490
|
export declare function managerCloseOptionPositionV2(tx: Transaction, typeArgs: [string, string, string], args: ManagerCloseOptionPositionV2Args, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
|
|
452
|
-
export interface ManagerHotfixRemoveMarketSymbolArgs {
|
|
453
|
-
version: TransactionObjectInput;
|
|
454
|
-
registry: TransactionObjectInput;
|
|
455
|
-
marketIndex: bigint | TransactionArgument;
|
|
456
|
-
}
|
|
457
|
-
export declare function managerHotfixRemoveMarketSymbol(tx: Transaction, typeArg: string, args: ManagerHotfixRemoveMarketSymbolArgs, published_at?: string): import("@mysten/sui/transactions").TransactionResult;
|
|
458
491
|
export interface ManagerReducePositionArgs {
|
|
459
492
|
version: TransactionObjectInput;
|
|
460
493
|
registry: TransactionObjectInput;
|
|
@@ -10,11 +10,14 @@ exports.cancelTradingOrder = cancelTradingOrder;
|
|
|
10
10
|
exports.checkCollateralEnoughWhenAddingPosition = checkCollateralEnoughWhenAddingPosition;
|
|
11
11
|
exports.checkCollateralEnoughWhenReducingPosition = checkCollateralEnoughWhenReducingPosition;
|
|
12
12
|
exports.checkOptionCollateralEnough = checkOptionCollateralEnough;
|
|
13
|
+
exports.checkPositionUserMatched = checkPositionUserMatched;
|
|
13
14
|
exports.checkReserveEnough = checkReserveEnough;
|
|
15
|
+
exports.collectPositionFundingFee = collectPositionFundingFee;
|
|
14
16
|
exports.createTradingOrder = createTradingOrder;
|
|
15
17
|
exports.createTradingOrderV2 = createTradingOrderV2;
|
|
16
18
|
exports.createTradingOrderWithBidReceipt = createTradingOrderWithBidReceipt;
|
|
17
19
|
exports.createTradingOrderWithBidReceiptV2 = createTradingOrderWithBidReceiptV2;
|
|
20
|
+
exports.createTradingOrderWithBidReceiptV3 = createTradingOrderWithBidReceiptV3;
|
|
18
21
|
exports.createUserAccount = createUserAccount;
|
|
19
22
|
exports.depositUserAccount = depositUserAccount;
|
|
20
23
|
exports.deprecated = deprecated;
|
|
@@ -33,16 +36,15 @@ exports.getMaxReleasingCollateralAmount = getMaxReleasingCollateralAmount;
|
|
|
33
36
|
exports.getMutMarketId = getMutMarketId;
|
|
34
37
|
exports.getMutOrders = getMutOrders;
|
|
35
38
|
exports.getOrders = getOrders;
|
|
39
|
+
exports.getTradingFeeConfig = getTradingFeeConfig;
|
|
36
40
|
exports.getUserOrders = getUserOrders;
|
|
37
41
|
exports.getUserPositions = getUserPositions;
|
|
38
42
|
exports.increaseCollateral = increaseCollateral;
|
|
39
|
-
exports.init = init;
|
|
40
43
|
exports.initUserAccountTable = initUserAccountTable;
|
|
41
44
|
exports.liquidate = liquidate;
|
|
42
45
|
exports.managerCancelOrderByOpenInterestLimit = managerCancelOrderByOpenInterestLimit;
|
|
43
46
|
exports.managerCloseOptionPosition = managerCloseOptionPosition;
|
|
44
47
|
exports.managerCloseOptionPositionV2 = managerCloseOptionPositionV2;
|
|
45
|
-
exports.managerHotfixRemoveMarketSymbol = managerHotfixRemoveMarketSymbol;
|
|
46
48
|
exports.managerReducePosition = managerReducePosition;
|
|
47
49
|
exports.managerReducePositionV2 = managerReducePositionV2;
|
|
48
50
|
exports.managerRemoveOrder = managerRemoveOrder;
|
|
@@ -234,6 +236,13 @@ function checkOptionCollateralEnough(tx, typeArg, args, published_at) {
|
|
|
234
236
|
],
|
|
235
237
|
});
|
|
236
238
|
}
|
|
239
|
+
function checkPositionUserMatched(tx, args, published_at) {
|
|
240
|
+
if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
|
|
241
|
+
return tx.moveCall({
|
|
242
|
+
target: "".concat(published_at, "::trading::check_position_user_matched"),
|
|
243
|
+
arguments: [(0, util_1.obj)(tx, args.position), (0, util_1.pure)(tx, args.user, "address")],
|
|
244
|
+
});
|
|
245
|
+
}
|
|
237
246
|
function checkReserveEnough(tx, typeArg, args, published_at) {
|
|
238
247
|
if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
|
|
239
248
|
return tx.moveCall({
|
|
@@ -250,6 +259,24 @@ function checkReserveEnough(tx, typeArg, args, published_at) {
|
|
|
250
259
|
],
|
|
251
260
|
});
|
|
252
261
|
}
|
|
262
|
+
function collectPositionFundingFee(tx, typeArgs, args, published_at) {
|
|
263
|
+
if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
|
|
264
|
+
return tx.moveCall({
|
|
265
|
+
target: "".concat(published_at, "::trading::collect_position_funding_fee"),
|
|
266
|
+
typeArguments: typeArgs,
|
|
267
|
+
arguments: [
|
|
268
|
+
(0, util_1.obj)(tx, args.version),
|
|
269
|
+
(0, util_1.obj)(tx, args.registry),
|
|
270
|
+
(0, util_1.obj)(tx, args.poolRegistry),
|
|
271
|
+
(0, util_1.obj)(tx, args.typusOracleCToken),
|
|
272
|
+
(0, util_1.obj)(tx, args.typusOracleTradingSymbol),
|
|
273
|
+
(0, util_1.obj)(tx, args.clock),
|
|
274
|
+
(0, util_1.pure)(tx, args.marketIndex, "u64"),
|
|
275
|
+
(0, util_1.pure)(tx, args.poolIndex, "u64"),
|
|
276
|
+
(0, util_1.pure)(tx, args.positionId, "u64"),
|
|
277
|
+
],
|
|
278
|
+
});
|
|
279
|
+
}
|
|
253
280
|
function createTradingOrder(tx, typeArgs, args, published_at) {
|
|
254
281
|
if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
|
|
255
282
|
return tx.moveCall({
|
|
@@ -356,6 +383,31 @@ function createTradingOrderWithBidReceiptV2(tx, typeArgs, args, published_at) {
|
|
|
356
383
|
],
|
|
357
384
|
});
|
|
358
385
|
}
|
|
386
|
+
function createTradingOrderWithBidReceiptV3(tx, typeArgs, args, published_at) {
|
|
387
|
+
if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
|
|
388
|
+
return tx.moveCall({
|
|
389
|
+
target: "".concat(published_at, "::trading::create_trading_order_with_bid_receipt_v3"),
|
|
390
|
+
typeArguments: typeArgs,
|
|
391
|
+
arguments: [
|
|
392
|
+
(0, util_1.obj)(tx, args.version),
|
|
393
|
+
(0, util_1.obj)(tx, args.registry),
|
|
394
|
+
(0, util_1.obj)(tx, args.poolRegistry),
|
|
395
|
+
(0, util_1.obj)(tx, args.dovRegistry),
|
|
396
|
+
(0, util_1.obj)(tx, args.typusOracleCToken),
|
|
397
|
+
(0, util_1.obj)(tx, args.typusOracleTradingSymbol),
|
|
398
|
+
(0, util_1.obj)(tx, args.clock),
|
|
399
|
+
(0, util_1.pure)(tx, args.marketIndex, "u64"),
|
|
400
|
+
(0, util_1.pure)(tx, args.poolIndex, "u64"),
|
|
401
|
+
(0, util_1.obj)(tx, args.typusEcosystemVersion),
|
|
402
|
+
(0, util_1.obj)(tx, args.typusUserRegistry),
|
|
403
|
+
(0, util_1.obj)(tx, args.typusLeaderboardRegistry),
|
|
404
|
+
(0, util_1.obj)(tx, args.tailsStakingRegistry),
|
|
405
|
+
(0, util_1.obj)(tx, args.competitionConfig),
|
|
406
|
+
(0, util_1.obj)(tx, args.collateralBidReceipt),
|
|
407
|
+
(0, util_1.pure)(tx, args.isLong, "bool"),
|
|
408
|
+
],
|
|
409
|
+
});
|
|
410
|
+
}
|
|
359
411
|
function createUserAccount(tx, args, published_at) {
|
|
360
412
|
if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
|
|
361
413
|
return tx.moveCall({
|
|
@@ -419,7 +471,6 @@ function executeOrder_(tx, typeArg, args, published_at) {
|
|
|
419
471
|
(0, util_1.pure)(tx, args.collateralOraclePriceDecimal, "u64"),
|
|
420
472
|
(0, util_1.pure)(tx, args.tradingPairOraclePrice, "u64"),
|
|
421
473
|
(0, util_1.pure)(tx, args.tradingPairOraclePriceDecimal, "u64"),
|
|
422
|
-
(0, util_1.pure)(tx, args.tradingFeeMbp, "u64"),
|
|
423
474
|
(0, util_1.obj)(tx, args.typusEcosystemVersion),
|
|
424
475
|
(0, util_1.obj)(tx, args.typusUserRegistry),
|
|
425
476
|
(0, util_1.obj)(tx, args.typusLeaderboardRegistry),
|
|
@@ -576,6 +627,13 @@ function getOrders(tx, args, published_at) {
|
|
|
576
627
|
arguments: [(0, util_1.obj)(tx, args.symbolMarket), (0, util_1.pure)(tx, args.isTokenCollateral, "bool"), (0, util_1.pure)(tx, args.orderTypeTag, "u8")],
|
|
577
628
|
});
|
|
578
629
|
}
|
|
630
|
+
function getTradingFeeConfig(tx, args, published_at) {
|
|
631
|
+
if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
|
|
632
|
+
return tx.moveCall({
|
|
633
|
+
target: "".concat(published_at, "::trading::get_trading_fee_config"),
|
|
634
|
+
arguments: [(0, util_1.obj)(tx, args.marketConfig), (0, util_1.pure)(tx, args.isOptionPosition, "bool")],
|
|
635
|
+
});
|
|
636
|
+
}
|
|
579
637
|
function getUserOrders(tx, args, published_at) {
|
|
580
638
|
if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
|
|
581
639
|
return tx.moveCall({
|
|
@@ -609,10 +667,6 @@ function increaseCollateral(tx, typeArgs, args, published_at) {
|
|
|
609
667
|
],
|
|
610
668
|
});
|
|
611
669
|
}
|
|
612
|
-
function init(tx, published_at) {
|
|
613
|
-
if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
|
|
614
|
-
return tx.moveCall({ target: "".concat(published_at, "::trading::init"), arguments: [] });
|
|
615
|
-
}
|
|
616
670
|
function initUserAccountTable(tx, args, published_at) {
|
|
617
671
|
if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
|
|
618
672
|
return tx.moveCall({
|
|
@@ -703,14 +757,6 @@ function managerCloseOptionPositionV2(tx, typeArgs, args, published_at) {
|
|
|
703
757
|
],
|
|
704
758
|
});
|
|
705
759
|
}
|
|
706
|
-
function managerHotfixRemoveMarketSymbol(tx, typeArg, args, published_at) {
|
|
707
|
-
if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
|
|
708
|
-
return tx.moveCall({
|
|
709
|
-
target: "".concat(published_at, "::trading::manager_hotfix_remove_market_symbol"),
|
|
710
|
-
typeArguments: [typeArg],
|
|
711
|
-
arguments: [(0, util_1.obj)(tx, args.version), (0, util_1.obj)(tx, args.registry), (0, util_1.pure)(tx, args.marketIndex, "u64")],
|
|
712
|
-
});
|
|
713
|
-
}
|
|
714
760
|
function managerReducePosition(tx, typeArgs, args, published_at) {
|
|
715
761
|
if (published_at === void 0) { published_at = __1.PUBLISHED_AT; }
|
|
716
762
|
return tx.moveCall({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TOKEN } from "@typus/typus-sdk/dist/src/constants";
|
|
2
|
-
export type actionType = "Place Order" | "Cancel Order" | "Order Filled (Open Position)" | "Order Filled (Close Position)" | "Realized PnL" | "Modify Collateral" | "Exercise Position" | "Liquidation" | "Force Close Position" | "Swap" | "Realized Funding";
|
|
2
|
+
export type actionType = "Place Order" | "Cancel Order" | "Order Filled (Open Position)" | "Order Filled (Close Position)" | "Realized PnL" | "Modify Collateral" | "Exercise Position" | "Liquidation" | "Force Cancel Order" | "Force Close Position" | "Swap" | "Realized Funding";
|
|
3
3
|
export type sideType = "Long" | "Short";
|
|
4
4
|
export type orderType = "Market" | "Limit" | "Take Profit" | "Stop Loss";
|
|
5
5
|
export type statusType = "Open" | "Filled" | "Canceled";
|
|
@@ -26,6 +26,9 @@ export interface Event {
|
|
|
26
26
|
export declare function parseUserHistory(raw_events: any): Promise<Event[]>;
|
|
27
27
|
export declare function getGraphQLEvents(module: string, sender: string | null, beforeCursor?: string | null): Promise<any>;
|
|
28
28
|
export declare function getLiquidateFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
29
|
+
export declare function getRealizeFundingFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
30
|
+
export declare function getRemovePositionFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
31
|
+
export declare function getCancelOrderFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
29
32
|
export declare function getOrderMatchFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
30
33
|
export declare function getRealizeOptionFromSentio(userAddress: string, startTimestamp: number, events: Event[]): Promise<Event[]>;
|
|
31
34
|
export declare function toSentioToken(name: TOKEN): string;
|
package/dist/src/user/history.js
CHANGED
|
@@ -66,6 +66,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
66
66
|
exports.parseUserHistory = parseUserHistory;
|
|
67
67
|
exports.getGraphQLEvents = getGraphQLEvents;
|
|
68
68
|
exports.getLiquidateFromSentio = getLiquidateFromSentio;
|
|
69
|
+
exports.getRealizeFundingFromSentio = getRealizeFundingFromSentio;
|
|
70
|
+
exports.getRemovePositionFromSentio = getRemovePositionFromSentio;
|
|
71
|
+
exports.getCancelOrderFromSentio = getCancelOrderFromSentio;
|
|
69
72
|
exports.getOrderMatchFromSentio = getOrderMatchFromSentio;
|
|
70
73
|
exports.getRealizeOptionFromSentio = getRealizeOptionFromSentio;
|
|
71
74
|
exports.toSentioToken = toSentioToken;
|
|
@@ -430,18 +433,156 @@ function getLiquidateFromSentio(userAddress, startTimestamp, events) {
|
|
|
430
433
|
});
|
|
431
434
|
});
|
|
432
435
|
}
|
|
436
|
+
function getRealizeFundingFromSentio(userAddress, startTimestamp, events) {
|
|
437
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
438
|
+
var datas, realizeFunding;
|
|
439
|
+
return __generator(this, function (_a) {
|
|
440
|
+
switch (_a.label) {
|
|
441
|
+
case 0: return [4 /*yield*/, (0, sentio_1.getFromSentio)("RealizeFunding", userAddress, startTimestamp.toString())];
|
|
442
|
+
case 1:
|
|
443
|
+
datas = _a.sent();
|
|
444
|
+
realizeFunding = datas.map(function (x) {
|
|
445
|
+
var base_token = toToken(x.base_token);
|
|
446
|
+
var txHistory = {
|
|
447
|
+
action: "Realized Funding",
|
|
448
|
+
typeName: "RealizeFundingEvent",
|
|
449
|
+
order_id: undefined,
|
|
450
|
+
position_id: x.position_id,
|
|
451
|
+
market: "".concat(base_token, "/USD"),
|
|
452
|
+
side: undefined,
|
|
453
|
+
order_type: undefined,
|
|
454
|
+
status: "Filled",
|
|
455
|
+
size: undefined,
|
|
456
|
+
base_token: base_token,
|
|
457
|
+
collateral: Number(x.realized_funding_fee),
|
|
458
|
+
collateral_token: x.collateral_token,
|
|
459
|
+
price: undefined,
|
|
460
|
+
realized_pnl: Number(x.realized_funding_fee_usd),
|
|
461
|
+
timestamp: x.timestamp,
|
|
462
|
+
tx_digest: x.transaction_hash,
|
|
463
|
+
dov_index: undefined,
|
|
464
|
+
sender: "cranker",
|
|
465
|
+
};
|
|
466
|
+
return txHistory;
|
|
467
|
+
});
|
|
468
|
+
// deduplicate
|
|
469
|
+
realizeFunding = realizeFunding.filter(function (x) { return events.findIndex(function (y) { return y.tx_digest == x.tx_digest && y.action == "Realized Funding"; }) == -1; });
|
|
470
|
+
realizeFunding = realizeFunding.map(function (x) {
|
|
471
|
+
// find related position
|
|
472
|
+
var related = events.find(function (e) { return e.position_id === x.position_id && e.market === x.market; });
|
|
473
|
+
// console.log(x, related);
|
|
474
|
+
if (related) {
|
|
475
|
+
x.side = related.side;
|
|
476
|
+
x.order_type = related.order_type;
|
|
477
|
+
x.size = related.size;
|
|
478
|
+
x.dov_index = related.dov_index;
|
|
479
|
+
}
|
|
480
|
+
return x;
|
|
481
|
+
});
|
|
482
|
+
// console.log(realizeFunding);
|
|
483
|
+
events = events.concat(realizeFunding);
|
|
484
|
+
events = events.sort(function (a, b) { return Number(new Date(a.timestamp)) - Number(new Date(b.timestamp)); });
|
|
485
|
+
return [2 /*return*/, events];
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
function getRemovePositionFromSentio(userAddress, startTimestamp, events) {
|
|
491
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
492
|
+
var datas;
|
|
493
|
+
return __generator(this, function (_a) {
|
|
494
|
+
switch (_a.label) {
|
|
495
|
+
case 0: return [4 /*yield*/, (0, sentio_1.getFromSentio)("RemovePosition", userAddress, startTimestamp.toString())];
|
|
496
|
+
case 1:
|
|
497
|
+
datas = _a.sent();
|
|
498
|
+
// console.log(datas);
|
|
499
|
+
datas.forEach(function (x) {
|
|
500
|
+
// console.log(x);
|
|
501
|
+
// same tx with order filled
|
|
502
|
+
var index = events.findLastIndex(function (e) { return e.tx_digest == x.transaction_hash && e.action == "Force Close Position"; });
|
|
503
|
+
// console.log(index);
|
|
504
|
+
if (index !== -1) {
|
|
505
|
+
// true => user paid to pool
|
|
506
|
+
var remaining_collateral_amount = x.remaining_collateral_amount;
|
|
507
|
+
events[index] = __assign(__assign({}, events[index]), { collateral: remaining_collateral_amount + Math.max(0, events[index].realized_pnl) });
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
return [2 /*return*/, events];
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
function getCancelOrderFromSentio(userAddress, startTimestamp, events) {
|
|
516
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
517
|
+
var datas, cancelOrder;
|
|
518
|
+
return __generator(this, function (_a) {
|
|
519
|
+
switch (_a.label) {
|
|
520
|
+
case 0: return [4 /*yield*/, (0, sentio_1.getFromSentio)("CancelOrder", userAddress, startTimestamp.toString(), true)];
|
|
521
|
+
case 1:
|
|
522
|
+
datas = _a.sent();
|
|
523
|
+
cancelOrder = datas.map(function (x) {
|
|
524
|
+
var collateral = Number(x.released_collateral_amount);
|
|
525
|
+
var base_token = toToken(x.base_token);
|
|
526
|
+
var txHistory = {
|
|
527
|
+
action: "Force Cancel Order",
|
|
528
|
+
typeName: "CancelTradingOrderEvent",
|
|
529
|
+
order_id: x.order_id,
|
|
530
|
+
position_id: undefined,
|
|
531
|
+
market: "".concat(base_token, "/USD"),
|
|
532
|
+
side: undefined,
|
|
533
|
+
order_type: undefined,
|
|
534
|
+
status: "Canceled",
|
|
535
|
+
size: undefined,
|
|
536
|
+
base_token: base_token,
|
|
537
|
+
collateral: collateral,
|
|
538
|
+
collateral_token: x.collateral_token,
|
|
539
|
+
price: undefined,
|
|
540
|
+
realized_pnl: undefined,
|
|
541
|
+
timestamp: x.timestamp,
|
|
542
|
+
tx_digest: x.transaction_hash,
|
|
543
|
+
dov_index: undefined,
|
|
544
|
+
sender: "cranker",
|
|
545
|
+
};
|
|
546
|
+
return txHistory;
|
|
547
|
+
});
|
|
548
|
+
// no duplicate
|
|
549
|
+
cancelOrder = cancelOrder.map(function (x) {
|
|
550
|
+
// find related order
|
|
551
|
+
var related = events.findLast(function (e) { return e.order_id == x.order_id && e.market == x.market; });
|
|
552
|
+
// console.log(x, related);
|
|
553
|
+
if (related) {
|
|
554
|
+
x.position_id = related.position_id;
|
|
555
|
+
x.side = related.side;
|
|
556
|
+
x.order_type = related.order_type;
|
|
557
|
+
x.size = related.size;
|
|
558
|
+
x.price = related.price;
|
|
559
|
+
}
|
|
560
|
+
return x;
|
|
561
|
+
});
|
|
562
|
+
// console.log(cancelOrder);
|
|
563
|
+
events = events.concat(cancelOrder);
|
|
564
|
+
events = events.sort(function (a, b) { return Number(new Date(a.timestamp)) - Number(new Date(b.timestamp)); });
|
|
565
|
+
return [2 /*return*/, events];
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
}
|
|
433
570
|
function getOrderMatchFromSentio(userAddress, startTimestamp, events) {
|
|
434
571
|
return __awaiter(this, void 0, void 0, function () {
|
|
435
572
|
var datas, order_match;
|
|
436
573
|
return __generator(this, function (_a) {
|
|
437
574
|
switch (_a.label) {
|
|
438
|
-
case 0: return [4 /*yield*/, (0, sentio_1.getFromSentio)("OrderFilled", userAddress, startTimestamp.toString())];
|
|
575
|
+
case 0: return [4 /*yield*/, (0, sentio_1.getFromSentio)("OrderFilled", userAddress, startTimestamp.toString(), true)];
|
|
439
576
|
case 1:
|
|
440
577
|
datas = _a.sent();
|
|
441
578
|
order_match = datas.map(function (x) {
|
|
442
579
|
var base_token = toToken(x.base_token);
|
|
443
580
|
var txHistory = {
|
|
444
|
-
action: x.order_type == "Open"
|
|
581
|
+
action: x.order_type == "Open"
|
|
582
|
+
? "Order Filled (Open Position)"
|
|
583
|
+
: x.sender == "0x978f65df8570a075298598a9965c18de9087f9e888eb3430fe20334f5c554cfd"
|
|
584
|
+
? "Force Close Position"
|
|
585
|
+
: "Order Filled (Close Position)",
|
|
445
586
|
typeName: "OrderFilledEvent",
|
|
446
587
|
order_id: x.order_id,
|
|
447
588
|
position_id: x.position_id,
|
|
@@ -458,13 +599,14 @@ function getOrderMatchFromSentio(userAddress, startTimestamp, events) {
|
|
|
458
599
|
timestamp: x.timestamp,
|
|
459
600
|
tx_digest: x.transaction_hash,
|
|
460
601
|
dov_index: undefined,
|
|
461
|
-
sender: "cranker",
|
|
602
|
+
sender: x.is_cranker ? "cranker" : "user",
|
|
462
603
|
};
|
|
463
604
|
return txHistory;
|
|
464
605
|
});
|
|
465
606
|
// deduplicate
|
|
466
607
|
order_match = order_match.filter(function (x) { return events.findIndex(function (y) { return y.tx_digest == x.tx_digest; }) == -1; });
|
|
467
608
|
order_match = order_match.map(function (x) {
|
|
609
|
+
// find related order
|
|
468
610
|
var related = events.findLast(function (e) { return e.order_id == x.order_id && e.market == x.market; });
|
|
469
611
|
// console.log(x, related);
|
|
470
612
|
if (related) {
|
package/dist/src/user/order.d.ts
CHANGED
|
@@ -31,3 +31,7 @@ export declare function releaseCollateral(config: TypusConfig, tx: Transaction,
|
|
|
31
31
|
amount: string;
|
|
32
32
|
suiCoins?: string[];
|
|
33
33
|
}): Promise<Transaction>;
|
|
34
|
+
export declare function collectPositionFundingFee(config: TypusConfig, tx: Transaction, pythClient: PythClient, input: {
|
|
35
|
+
position: Position;
|
|
36
|
+
suiCoins?: string[];
|
|
37
|
+
}): Promise<Transaction>;
|
package/dist/src/user/order.js
CHANGED
|
@@ -68,6 +68,7 @@ exports.zeroCoin = zeroCoin;
|
|
|
68
68
|
exports.cancelTradingOrder = cancelTradingOrder;
|
|
69
69
|
exports.increaseCollateral = increaseCollateral;
|
|
70
70
|
exports.releaseCollateral = releaseCollateral;
|
|
71
|
+
exports.collectPositionFundingFee = collectPositionFundingFee;
|
|
71
72
|
var functions_1 = require("../typus_perp/trading/functions");
|
|
72
73
|
var __1 = require("..");
|
|
73
74
|
var utils_1 = require("@typus/typus-sdk/dist/src/utils");
|
|
@@ -271,3 +272,50 @@ function releaseCollateral(config, tx, pythClient, input) {
|
|
|
271
272
|
});
|
|
272
273
|
});
|
|
273
274
|
}
|
|
275
|
+
function collectPositionFundingFee(config, tx, pythClient, input) {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
277
|
+
var TOKEN, BASE_TOKEN, tokens, suiCoin, tokens_4, tokens_4_1, token, cToken, baseToken;
|
|
278
|
+
var e_4, _a;
|
|
279
|
+
return __generator(this, function (_b) {
|
|
280
|
+
switch (_b.label) {
|
|
281
|
+
case 0:
|
|
282
|
+
TOKEN = (0, constants_1.typeArgToAsset)(input.position.collateralToken.name);
|
|
283
|
+
BASE_TOKEN = (0, constants_1.typeArgToAsset)(input.position.symbol.baseToken.name);
|
|
284
|
+
tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
|
|
285
|
+
if (config.sponsored) {
|
|
286
|
+
suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), config.sponsored);
|
|
287
|
+
}
|
|
288
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens, suiCoin)];
|
|
289
|
+
case 1:
|
|
290
|
+
_b.sent();
|
|
291
|
+
try {
|
|
292
|
+
for (tokens_4 = __values(tokens), tokens_4_1 = tokens_4.next(); !tokens_4_1.done; tokens_4_1 = tokens_4.next()) {
|
|
293
|
+
token = tokens_4_1.value;
|
|
294
|
+
(0, utils_1.updateOracleWithPythUsd)(pythClient, tx, config.package.oracle, token);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
298
|
+
finally {
|
|
299
|
+
try {
|
|
300
|
+
if (tokens_4_1 && !tokens_4_1.done && (_a = tokens_4.return)) _a.call(tokens_4);
|
|
301
|
+
}
|
|
302
|
+
finally { if (e_4) throw e_4.error; }
|
|
303
|
+
}
|
|
304
|
+
cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
305
|
+
baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
|
|
306
|
+
(0, functions_1.collectPositionFundingFee)(tx, [cToken, baseToken], {
|
|
307
|
+
version: __1.PERP_VERSION,
|
|
308
|
+
registry: __1.MARKET,
|
|
309
|
+
poolRegistry: __1.LP_POOL,
|
|
310
|
+
marketIndex: BigInt(0),
|
|
311
|
+
poolIndex: BigInt(0),
|
|
312
|
+
typusOracleCToken: constants_1.oracle[__1.NETWORK][TOKEN],
|
|
313
|
+
typusOracleTradingSymbol: constants_1.oracle[__1.NETWORK][BASE_TOKEN],
|
|
314
|
+
clock: constants_1.CLOCK,
|
|
315
|
+
positionId: BigInt(input.position.positionId),
|
|
316
|
+
});
|
|
317
|
+
return [2 /*return*/, tx];
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
}
|
|
@@ -94,7 +94,7 @@ function createTradingOrderWithBidReceiptByAutoBid(config, tx, pythClient, input
|
|
|
94
94
|
cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
95
95
|
bToken = constants_1.tokenType[__1.NETWORK][input.bToken];
|
|
96
96
|
baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
|
|
97
|
-
(0, functions_1.
|
|
97
|
+
(0, functions_1.createTradingOrderWithBidReceiptV3)(tx, [cToken, bToken, baseToken], {
|
|
98
98
|
version: __1.PERP_VERSION,
|
|
99
99
|
registry: __1.MARKET,
|
|
100
100
|
poolRegistry: __1.LP_POOL,
|
|
@@ -109,7 +109,6 @@ function createTradingOrderWithBidReceiptByAutoBid(config, tx, pythClient, input
|
|
|
109
109
|
isLong: input.isLong,
|
|
110
110
|
dovRegistry: config.registry.dov.dovSingle,
|
|
111
111
|
collateralBidReceipt: collateralBidReceipt,
|
|
112
|
-
user: input.user,
|
|
113
112
|
tailsStakingRegistry: config.registry.typus.tailsStaking,
|
|
114
113
|
competitionConfig: __1.COMPETITION_CONFIG,
|
|
115
114
|
});
|
|
@@ -156,7 +155,7 @@ function createTradingOrderWithBidReceipt(config, tx, pythClient, input) {
|
|
|
156
155
|
cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
157
156
|
bToken = constants_1.tokenType[__1.NETWORK][input.bToken];
|
|
158
157
|
baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
|
|
159
|
-
(0, functions_1.
|
|
158
|
+
(0, functions_1.createTradingOrderWithBidReceiptV3)(tx, [cToken, bToken, baseToken], {
|
|
160
159
|
version: __1.PERP_VERSION,
|
|
161
160
|
registry: __1.MARKET,
|
|
162
161
|
poolRegistry: __1.LP_POOL,
|
|
@@ -171,7 +170,6 @@ function createTradingOrderWithBidReceipt(config, tx, pythClient, input) {
|
|
|
171
170
|
isLong: input.isLong,
|
|
172
171
|
dovRegistry: config.registry.dov.dovSingle,
|
|
173
172
|
collateralBidReceipt: collateralBidReceipt,
|
|
174
|
-
user: input.user,
|
|
175
173
|
tailsStakingRegistry: config.registry.typus.tailsStaking,
|
|
176
174
|
competitionConfig: __1.COMPETITION_CONFIG,
|
|
177
175
|
});
|