@typus/typus-perp-sdk 1.1.32-codegen-exp1 → 1.1.32-codegen-exp3

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.
@@ -1,31 +1,346 @@
1
1
  import { TOKEN } from "@typus/typus-sdk/dist/src/constants";
2
- import { Markets, SymbolMarket } from "./generated/typus_perp/trading";
3
- import { DeactivatingShares } from "./generated/typus_perp/lp_pool";
4
- import { TradingOrder, Position } from "./generated/typus_perp/position";
5
- import { LiquidityPool } from "./generated/typus_perp/lp_pool";
6
- import { LpUserShare, StakePool } from "./generated/typus_stake_pool/stake_pool";
7
- import { TypusBidReceipt } from "./generated/typus_perp/deps/typus_framework/vault";
2
+ import { Position } from "./generated/typus_perp/position";
8
3
  import { TypusClient } from "../src/client";
9
- export type LiquidityPoolType = typeof LiquidityPool.$inferType;
10
- export type StakePoolType = typeof StakePool.$inferType;
11
- export type MarketsType = typeof Markets.$inferType;
12
- export type SymbolMarketType = typeof SymbolMarket.$inferType;
13
- export type TradingOrderType = typeof TradingOrder.$inferType;
14
- export type PositionType = typeof Position.$inferType;
15
- export type TypusBidReceiptType = typeof TypusBidReceipt.$inferType;
16
- export type LpUserShareType = typeof LpUserShare.$inferType;
17
- export type DeactivatingSharesType = typeof DeactivatingShares.$inferType;
18
- export declare function getLpPools(client: TypusClient): Promise<LiquidityPoolType[]>;
19
- export declare function getLpPool(client: TypusClient, objectId: string): Promise<LiquidityPoolType>;
20
- export declare function getStakePools(client: TypusClient): Promise<StakePoolType[]>;
21
- export declare function getStakePool(client: TypusClient, objectId: string): Promise<StakePoolType>;
22
- export interface MarketsData {
23
- markets: MarketsType;
24
- symbolMarkets: SymbolMarketType[];
25
- }
4
+ export declare function getLpPools(client: TypusClient): Promise<{
5
+ id: {
6
+ id: string;
7
+ };
8
+ index: string;
9
+ lp_token_type: {
10
+ name: string;
11
+ };
12
+ liquidity_tokens: {
13
+ name: string;
14
+ }[];
15
+ token_pools: {
16
+ token_type: {
17
+ name: string;
18
+ };
19
+ config: {
20
+ oracle_id: string;
21
+ liquidity_token_decimal: string;
22
+ spot_config: {
23
+ min_deposit: string;
24
+ max_capacity: string;
25
+ target_weight_bp: string;
26
+ basic_mint_fee_bp: string;
27
+ additional_mint_fee_bp: string;
28
+ basic_burn_fee_bp: string;
29
+ additional_burn_fee_bp: string;
30
+ swap_fee_bp: string;
31
+ swap_fee_protocol_share_bp: string;
32
+ lending_protocol_share_bp: string;
33
+ u64_padding: string[];
34
+ };
35
+ margin_config: {
36
+ basic_borrow_rate_0: string;
37
+ basic_borrow_rate_1: string;
38
+ basic_borrow_rate_2: string;
39
+ utilization_threshold_bp_0: string;
40
+ utilization_threshold_bp_1: string;
41
+ borrow_interval_ts_ms: string;
42
+ max_order_reserve_ratio_bp: string;
43
+ u64_padding: string[];
44
+ };
45
+ u64_padding: string[];
46
+ };
47
+ state: {
48
+ liquidity_amount: string;
49
+ value_in_usd: string;
50
+ reserved_amount: string;
51
+ update_ts_ms: string;
52
+ is_active: boolean;
53
+ last_borrow_rate_ts_ms: string;
54
+ cumulative_borrow_rate: string;
55
+ previous_last_borrow_rate_ts_ms: string;
56
+ previous_cumulative_borrow_rate: string;
57
+ current_lending_amount: string[];
58
+ u64_padding: string[];
59
+ };
60
+ }[];
61
+ pool_info: {
62
+ lp_token_decimal: string;
63
+ total_share_supply: string;
64
+ tvl_usd: string;
65
+ is_active: boolean;
66
+ };
67
+ liquidated_unsettled_receipts: {
68
+ receipt: {
69
+ id: {
70
+ id: string;
71
+ };
72
+ vid: string;
73
+ index: string;
74
+ metadata: string;
75
+ u64_padding: string[];
76
+ }[];
77
+ position_id: string;
78
+ user: string;
79
+ token_types: {
80
+ name: string;
81
+ }[];
82
+ unrealized_pnl_sign: boolean;
83
+ unrealized_pnl: string;
84
+ unrealized_trading_fee: string;
85
+ unrealized_borrow_fee: string;
86
+ unrealized_funding_fee_sign: boolean;
87
+ unrealized_funding_fee: string;
88
+ unrealized_liquidator_fee: string;
89
+ }[];
90
+ u64_padding: string[];
91
+ bcs_padding: number[];
92
+ }[]>;
93
+ export declare function getLpPool(client: TypusClient, objectId: string): Promise<{
94
+ id: {
95
+ id: string;
96
+ };
97
+ index: string;
98
+ lp_token_type: {
99
+ name: string;
100
+ };
101
+ liquidity_tokens: {
102
+ name: string;
103
+ }[];
104
+ token_pools: {
105
+ token_type: {
106
+ name: string;
107
+ };
108
+ config: {
109
+ oracle_id: string;
110
+ liquidity_token_decimal: string;
111
+ spot_config: {
112
+ min_deposit: string;
113
+ max_capacity: string;
114
+ target_weight_bp: string;
115
+ basic_mint_fee_bp: string;
116
+ additional_mint_fee_bp: string;
117
+ basic_burn_fee_bp: string;
118
+ additional_burn_fee_bp: string;
119
+ swap_fee_bp: string;
120
+ swap_fee_protocol_share_bp: string;
121
+ lending_protocol_share_bp: string;
122
+ u64_padding: string[];
123
+ };
124
+ margin_config: {
125
+ basic_borrow_rate_0: string;
126
+ basic_borrow_rate_1: string;
127
+ basic_borrow_rate_2: string;
128
+ utilization_threshold_bp_0: string;
129
+ utilization_threshold_bp_1: string;
130
+ borrow_interval_ts_ms: string;
131
+ max_order_reserve_ratio_bp: string;
132
+ u64_padding: string[];
133
+ };
134
+ u64_padding: string[];
135
+ };
136
+ state: {
137
+ liquidity_amount: string;
138
+ value_in_usd: string;
139
+ reserved_amount: string;
140
+ update_ts_ms: string;
141
+ is_active: boolean;
142
+ last_borrow_rate_ts_ms: string;
143
+ cumulative_borrow_rate: string;
144
+ previous_last_borrow_rate_ts_ms: string;
145
+ previous_cumulative_borrow_rate: string;
146
+ current_lending_amount: string[];
147
+ u64_padding: string[];
148
+ };
149
+ }[];
150
+ pool_info: {
151
+ lp_token_decimal: string;
152
+ total_share_supply: string;
153
+ tvl_usd: string;
154
+ is_active: boolean;
155
+ };
156
+ liquidated_unsettled_receipts: {
157
+ receipt: {
158
+ id: {
159
+ id: string;
160
+ };
161
+ vid: string;
162
+ index: string;
163
+ metadata: string;
164
+ u64_padding: string[];
165
+ }[];
166
+ position_id: string;
167
+ user: string;
168
+ token_types: {
169
+ name: string;
170
+ }[];
171
+ unrealized_pnl_sign: boolean;
172
+ unrealized_pnl: string;
173
+ unrealized_trading_fee: string;
174
+ unrealized_borrow_fee: string;
175
+ unrealized_funding_fee_sign: boolean;
176
+ unrealized_funding_fee: string;
177
+ unrealized_liquidator_fee: string;
178
+ }[];
179
+ u64_padding: string[];
180
+ bcs_padding: number[];
181
+ }>;
182
+ export declare function getStakePools(client: TypusClient): Promise<{
183
+ id: {
184
+ id: string;
185
+ };
186
+ pool_info: {
187
+ stake_token: {
188
+ name: string;
189
+ };
190
+ index: string;
191
+ next_user_share_id: string;
192
+ total_share: string;
193
+ active: boolean;
194
+ new_tlp_price: string;
195
+ depositors_count: string;
196
+ u64_padding: string[];
197
+ };
198
+ config: {
199
+ unlock_countdown_ts_ms: string;
200
+ usd_per_exp: string;
201
+ u64_padding: string[];
202
+ };
203
+ incentives: {
204
+ token_type: {
205
+ name: string;
206
+ };
207
+ config: {
208
+ period_incentive_amount: string;
209
+ incentive_interval_ts_ms: string;
210
+ u64_padding: string[];
211
+ };
212
+ info: {
213
+ active: boolean;
214
+ last_allocate_ts_ms: string;
215
+ incentive_price_index: string;
216
+ unallocated_amount: string;
217
+ u64_padding: string[];
218
+ };
219
+ }[];
220
+ u64_padding: string[];
221
+ }[]>;
222
+ export declare function getStakePool(client: TypusClient, objectId: string): Promise<{
223
+ id: {
224
+ id: string;
225
+ };
226
+ pool_info: {
227
+ stake_token: {
228
+ name: string;
229
+ };
230
+ index: string;
231
+ next_user_share_id: string;
232
+ total_share: string;
233
+ active: boolean;
234
+ new_tlp_price: string;
235
+ depositors_count: string;
236
+ u64_padding: string[];
237
+ };
238
+ config: {
239
+ unlock_countdown_ts_ms: string;
240
+ usd_per_exp: string;
241
+ u64_padding: string[];
242
+ };
243
+ incentives: {
244
+ token_type: {
245
+ name: string;
246
+ };
247
+ config: {
248
+ period_incentive_amount: string;
249
+ incentive_interval_ts_ms: string;
250
+ u64_padding: string[];
251
+ };
252
+ info: {
253
+ active: boolean;
254
+ last_allocate_ts_ms: string;
255
+ incentive_price_index: string;
256
+ unallocated_amount: string;
257
+ u64_padding: string[];
258
+ };
259
+ }[];
260
+ u64_padding: string[];
261
+ }>;
262
+ /**
263
+ * @returns [Markets, SymbolMarket[]][]
264
+ */
26
265
  export declare function getMarkets(client: TypusClient, input: {
27
266
  indexes: string[];
28
- }): Promise<MarketsData[]>;
267
+ }): Promise<[{
268
+ id: {
269
+ id: string;
270
+ };
271
+ index: string;
272
+ lp_token_type: {
273
+ name: string;
274
+ };
275
+ quote_token_type: {
276
+ name: string;
277
+ };
278
+ is_active: boolean;
279
+ protocol_fee_share_bp: string;
280
+ symbols: {
281
+ name: string;
282
+ }[];
283
+ symbol_markets: {
284
+ id: {
285
+ id: string;
286
+ };
287
+ size: string;
288
+ };
289
+ u64_padding: string[];
290
+ }, {
291
+ id: {
292
+ id: string;
293
+ };
294
+ user_positions: {
295
+ id: {
296
+ id: string;
297
+ };
298
+ key_type: {
299
+ name: string;
300
+ };
301
+ value_type: {
302
+ name: string;
303
+ };
304
+ slice_idx: number;
305
+ slice_size: number;
306
+ length: string;
307
+ };
308
+ token_collateral_orders: {
309
+ id: string;
310
+ };
311
+ option_collateral_orders: {
312
+ id: string;
313
+ };
314
+ market_info: {
315
+ is_active: boolean;
316
+ size_decimal: string;
317
+ user_long_position_size: string;
318
+ user_short_position_size: string;
319
+ next_position_id: string;
320
+ user_long_order_size: string;
321
+ user_short_order_size: string;
322
+ next_order_id: string;
323
+ last_funding_ts_ms: string;
324
+ cumulative_funding_rate_index_sign: boolean;
325
+ cumulative_funding_rate_index: string;
326
+ previous_last_funding_ts_ms: string;
327
+ previous_cumulative_funding_rate_index_sign: boolean;
328
+ previous_cumulative_funding_rate_index: string;
329
+ u64_padding: string[];
330
+ };
331
+ market_config: {
332
+ oracle_id: string;
333
+ max_leverage_mbp: string;
334
+ option_collateral_max_leverage_mbp: string;
335
+ min_size: string;
336
+ lot_size: string;
337
+ trading_fee_config: string[];
338
+ basic_funding_rate: string;
339
+ funding_interval_ts_ms: string;
340
+ exp_multiplier: string;
341
+ u64_padding: string[];
342
+ };
343
+ }[]][]>;
29
344
  export declare function getUserOrders(client: TypusClient, input: {
30
345
  user: string;
31
346
  indexes: string[];
@@ -107,26 +422,73 @@ export declare function getUserPositions(client: TypusClient, input: {
107
422
  } | null;
108
423
  u64_padding: string[];
109
424
  }[]>;
110
- export declare function parseOptionBidReceipts(positions: PositionType[]): (TypusBidReceiptType | null)[];
425
+ export declare function parseOptionBidReceipts(positions: (typeof Position.$inferType)[]): ({
426
+ id: {
427
+ id: string;
428
+ };
429
+ vid: string;
430
+ index: string;
431
+ metadata: string;
432
+ u64_padding: string[];
433
+ } | null)[];
111
434
  /**
112
435
  * @returns [lpShare, incentives][]
113
436
  */
114
437
  export declare function getUserStake(client: TypusClient, input: {
115
438
  user: string;
116
439
  indexes: string[];
117
- }): Promise<[LpUserShareType, string[]][]>;
440
+ }): Promise<[{
441
+ user: string;
442
+ user_share_id: string;
443
+ stake_ts_ms: string;
444
+ total_shares: string;
445
+ active_shares: string;
446
+ deactivating_shares: {
447
+ shares: string;
448
+ unsubscribed_ts_ms: string;
449
+ unlocked_ts_ms: string;
450
+ unsubscribed_incentive_price_index: {
451
+ contents: {
452
+ key: {
453
+ name: string;
454
+ };
455
+ value: string;
456
+ }[];
457
+ };
458
+ u64_padding: string[];
459
+ }[];
460
+ last_incentive_price_index: {
461
+ contents: {
462
+ key: {
463
+ name: string;
464
+ };
465
+ value: string;
466
+ }[];
467
+ };
468
+ snapshot_ts_ms: string;
469
+ tlp_price: string;
470
+ harvested_amount: string;
471
+ u64_padding: string[];
472
+ } | null, string[]][]>;
118
473
  /**
119
474
  * @returns deactivatingShares[]
120
475
  */
121
476
  export declare function getDeactivatingShares(client: TypusClient, input: {
122
477
  user: string;
123
478
  indexes: string[];
124
- }): Promise<DeactivatingSharesType[]>;
479
+ }): Promise<{
480
+ balance: {
481
+ value: string;
482
+ };
483
+ redeem_ts_ms: string;
484
+ unlock_ts_ms: string;
485
+ u64_padding: string[];
486
+ }[]>;
125
487
  /**
126
488
  * @returns [liquidationPrice, pnl(in USD)]
127
489
  */
128
490
  export declare function getLiquidationPriceAndPnl(client: TypusClient, input: {
129
- positions: PositionType[];
491
+ positions: (typeof Position.$inferType)[];
130
492
  }): Promise<PositionInfo[]>;
131
493
  interface PositionInfo {
132
494
  liquidationPrice: number;
@@ -192,5 +554,49 @@ export declare function getAllPositions(client: TypusClient, input: {
192
554
  export declare function getAllPositionsWithTradingSymbol(client: TypusClient, input: {
193
555
  baseToken: TOKEN;
194
556
  marketIndex: string;
195
- }): Promise<PositionType[]>;
557
+ }): Promise<{
558
+ id: {
559
+ id: string;
560
+ };
561
+ create_ts_ms: string;
562
+ position_id: string;
563
+ linked_order_ids: string[];
564
+ linked_order_prices: string[];
565
+ user: string;
566
+ is_long: boolean;
567
+ size: string;
568
+ size_decimal: string;
569
+ collateral_token: {
570
+ name: string;
571
+ };
572
+ collateral_token_decimal: string;
573
+ symbol: {
574
+ base_token: {
575
+ name: string;
576
+ };
577
+ quote_token: {
578
+ name: string;
579
+ };
580
+ };
581
+ collateral_amount: string;
582
+ reserve_amount: string;
583
+ average_price: string;
584
+ entry_borrow_index: string;
585
+ entry_funding_rate_index_sign: boolean;
586
+ entry_funding_rate_index: string;
587
+ unrealized_loss: string;
588
+ unrealized_funding_sign: boolean;
589
+ unrealized_funding_fee: string;
590
+ unrealized_trading_fee: string;
591
+ unrealized_borrow_fee: string;
592
+ unrealized_rebate: string;
593
+ option_collateral_info: {
594
+ index: string;
595
+ bid_token: {
596
+ name: string;
597
+ };
598
+ bid_receipts_bcs: number[][];
599
+ } | null;
600
+ u64_padding: string[];
601
+ }[]>;
196
602
  export {};
package/dist/src/fetch.js CHANGED
@@ -29,7 +29,7 @@ async function getLpPools(client) {
29
29
  // let dynamicFields = await client.getDynamicFields({
30
30
  // parentId: LIQUIDITY_POOL,
31
31
  // });
32
- // let lpPools: (LiquidityPoolType)[] = [];
32
+ // let lpPools: (typeof LiquidityPool.$inferType)[] = [];
33
33
  // for (const field of dynamicFields.data) {
34
34
  // let lpPool = await getLpPool(client, field.objectId);
35
35
  // // console.log(lpPool);
@@ -59,7 +59,7 @@ async function getStakePools(client) {
59
59
  // let dynamicFields = await client.getDynamicFields({
60
60
  // parentId: STAKE_POOL,
61
61
  // });
62
- // let stakePools: (StakePoolType)[] = [];
62
+ // let stakePools: (typeof StakePool.$inferType)[] = [];
63
63
  // for (const field of dynamicFields.data) {
64
64
  // let stakePool = await getStakePool(client, field.objectId);
65
65
  // // console.log(stakePool);
@@ -84,6 +84,9 @@ async function getStakePool(client, objectId) {
84
84
  const bcs = await client.getObjectBcs(objectId);
85
85
  return stake_pool_1.StakePool.parse(bcs);
86
86
  }
87
+ /**
88
+ * @returns [Markets, SymbolMarket[]][]
89
+ */
87
90
  async function getMarkets(client, input) {
88
91
  let tx = new transactions_1.Transaction();
89
92
  tx.add((0, trading_1.getMarketsBcs)({ arguments: { registry: _1.MARKET, indexes: input.indexes.map((x) => BigInt(x)) } }));
@@ -98,14 +101,14 @@ async function getMarkets(client, input) {
98
101
  let length = reader.readULEB();
99
102
  let bytes = reader.readBytes(length);
100
103
  let markets = trading_1.Markets.parse(bytes);
101
- results.push({ markets, symbolMarkets: [] });
104
+ results.push([markets, []]);
102
105
  marketIndex = i + markets.symbols.length + 1;
103
106
  }
104
107
  else {
105
108
  let length = reader.readULEB();
106
109
  let bytes = reader.readBytes(length);
107
110
  let symbolMarket = trading_1.SymbolMarket.parse(bytes);
108
- results[results.length - 1].symbolMarkets.push(symbolMarket);
111
+ results[results.length - 1][1].push(symbolMarket);
109
112
  }
110
113
  });
111
114
  return results;
@@ -217,7 +220,7 @@ async function getUserStake(client, input) {
217
220
  let length = reader.readULEB();
218
221
  console.log(length);
219
222
  if (length == 0) {
220
- results.push([]);
223
+ results.push([null, []]);
221
224
  continue;
222
225
  }
223
226
  // let lpShare = LpUserShare.fromFields(LpUserShare.bcs.read(reader));
@@ -393,7 +396,6 @@ async function getAllPositions(client, input) {
393
396
  }
394
397
  const SLICE = 100;
395
398
  async function getAllPositionsWithTradingSymbol(client, input) {
396
- var positions = [];
397
399
  var { positions: pos, maxPage } = await getAllPositions(client, {
398
400
  baseToken: input.baseToken,
399
401
  slice: SLICE.toString(),
@@ -401,7 +403,7 @@ async function getAllPositionsWithTradingSymbol(client, input) {
401
403
  marketIndex: input.marketIndex,
402
404
  });
403
405
  // console.log(maxPage);
404
- positions = positions.concat(pos);
406
+ var positions = pos;
405
407
  for (let page = 2; page <= maxPage; page++) {
406
408
  console.log(page);
407
409
  var { positions: pos, maxPage } = await getAllPositions(client, {