@typus/typus-perp-sdk 1.1.32-codegen-exp14-profit-vault → 1.1.32-codegen-exp15-profit-vault

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.
@@ -423,6 +423,7 @@ export declare function getDeactivatingShares(client: TypusClient, input: {
423
423
  * @returns [liquidationPrice, pnl(in USD)]
424
424
  */
425
425
  export declare function getLiquidationPriceAndPnl(client: TypusClient, input: {
426
+ oracle?: string;
426
427
  positions: (typeof Position.$inferType)[];
427
428
  }): Promise<PositionInfo[]>;
428
429
  interface PositionInfo {
package/dist/src/fetch.js CHANGED
@@ -22,6 +22,7 @@ const client_1 = require("@mysten/sui/client");
22
22
  const bcs_1 = require("@mysten/bcs");
23
23
  const constants_1 = require("@typus/typus-sdk/dist/src/constants");
24
24
  const utils_1 = require("@typus/typus-sdk/dist/src/utils");
25
+ const utils_2 = require("@typus/typus-sdk/dist/src/utils");
25
26
  const _1 = require(".");
26
27
  const trading_1 = require("./generated/typus_perp/trading");
27
28
  const lp_pool_1 = require("./generated/typus_perp/lp_pool");
@@ -299,10 +300,16 @@ async function getLiquidationPriceAndPnl(client, input) {
299
300
  tokens.push(TOKEN);
300
301
  tokens.push(BASE_TOKEN);
301
302
  }
302
- await (0, utils_1.updatePyth)(client.pythClient, tx, Array.from(new Set(tokens)));
303
- for (let token of Array.from(new Set(tokens))) {
303
+ const tokensWithoutTypus = tokens.filter((token) => token !== "TYPUS");
304
+ await (0, utils_1.updatePyth)(client.pythClient, tx, Array.from(new Set(tokensWithoutTypus)));
305
+ for (let token of Array.from(new Set(tokensWithoutTypus))) {
304
306
  (0, utils_1.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
305
307
  }
308
+ if (tokens.includes("TYPUS")) {
309
+ // TODO: update oracle contract
310
+ const oracleContract = input.oracle ?? "0x51fc5517f5ba4e3ba8862cd74c345e7294193c693ab41376694d1c516033e2e8";
311
+ tx = await (0, utils_2.updateOracleWithSignatureTx)(_1.NETWORK, tx, oracleContract, constants_1.tokenType[_1.NETWORK]["TYPUS"]);
312
+ }
306
313
  for (let position of input.positions) {
307
314
  // parse from Position
308
315
  let TOKEN = (0, constants_1.typeArgToAsset)(position.collateral_token.name);
@@ -9,6 +9,7 @@ export declare function findMarketIndex(client: TypusClient, input: {
9
9
  }): number | undefined;
10
10
  export declare function createTradingOrder(client: TypusClient, tx: Transaction, input: {
11
11
  perpIndex: string;
12
+ poolIndex: string;
12
13
  coins: string[];
13
14
  cToken: TOKEN;
14
15
  amount: string;
@@ -19,6 +20,7 @@ export declare function createTradingOrder(client: TypusClient, tx: Transaction,
19
20
  isStopOrder: boolean;
20
21
  reduceOnly: boolean;
21
22
  linkedPositionId: string | null;
23
+ oracleContract?: string;
22
24
  suiCoins?: string[];
23
25
  }): Promise<Transaction>;
24
26
  export declare function zeroCoin(tx: Transaction, typeArgs: [string]): import("@mysten/sui/transactions").TransactionResult;
@@ -10,13 +10,14 @@ exports.collectPositionFundingFee = collectPositionFundingFee;
10
10
  const trading_1 = require("../../src/generated/typus_perp/trading");
11
11
  const __1 = require("..");
12
12
  const utils_1 = require("@typus/typus-sdk/dist/src/utils");
13
+ const utils_2 = require("@typus/typus-sdk/dist/src/utils");
13
14
  const constants_1 = require("@typus/typus-sdk/dist/src/constants");
14
- const utils_2 = require("@mysten/sui/utils");
15
+ const utils_3 = require("@mysten/sui/utils");
15
16
  function findMarketIndex(client, input) {
16
17
  let target = constants_1.tokenType[client.config.network][input.tradingToken];
17
18
  for (let i = 0; i < input.markets.length; i++) {
18
19
  for (let symbol of input.markets[i].symbols) {
19
- if ((0, utils_2.normalizeStructTag)(symbol.name) == target) {
20
+ if ((0, utils_3.normalizeStructTag)(symbol.name) == target) {
20
21
  return i;
21
22
  }
22
23
  }
@@ -33,19 +34,24 @@ async function createTradingOrder(client, tx, input) {
33
34
  let suiCoin;
34
35
  if (TOKEN == "SUI" && client.config.sponsored) {
35
36
  // split together
36
- [coin, suiCoin] = (0, utils_1.splitCoins)(tx, constants_1.tokenType.MAINNET.SUI, input.coins, [input.amount, tokens.length.toString()], client.config.sponsored);
37
+ [coin, suiCoin] = (0, utils_2.splitCoins)(tx, constants_1.tokenType.MAINNET.SUI, input.coins, [input.amount, tokens.length.toString()], client.config.sponsored);
37
38
  }
38
39
  else if (client.config.sponsored) {
39
- coin = (0, utils_1.splitCoin)(tx, cToken, input.coins, input.amount, client.config.sponsored);
40
- suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), client.config.sponsored);
40
+ coin = (0, utils_2.splitCoin)(tx, cToken, input.coins, input.amount, client.config.sponsored);
41
+ suiCoin = (0, utils_2.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), client.config.sponsored);
41
42
  }
42
43
  else {
43
- coin = (0, utils_1.splitCoin)(tx, cToken, input.coins, input.amount, client.config.sponsored);
44
+ coin = (0, utils_2.splitCoin)(tx, cToken, input.coins, input.amount, client.config.sponsored);
44
45
  // no suiCoin
45
46
  }
46
- await (0, utils_1.updatePyth)(client.pythClient, tx, tokens, suiCoin);
47
- for (let token of tokens) {
48
- (0, utils_1.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
47
+ const tokensWithoutTypus = Array.from(new Set([TOKEN])).filter((token) => token !== "TYPUS");
48
+ await (0, utils_2.updatePyth)(client.pythClient, tx, tokensWithoutTypus, suiCoin);
49
+ for (let token of tokensWithoutTypus) {
50
+ (0, utils_2.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
51
+ }
52
+ if (tokens.includes("TYPUS")) {
53
+ const oracleContract = input.oracleContract ?? "0x51fc5517f5ba4e3ba8862cd74c345e7294193c693ab41376694d1c516033e2e8";
54
+ tx = await (0, utils_1.updateOracleWithSignatureTx)(__1.NETWORK, tx, oracleContract, constants_1.tokenType[__1.NETWORK]["TYPUS"]);
49
55
  }
50
56
  tx.add((0, trading_1.createTradingOrder)({
51
57
  arguments: {
@@ -53,7 +59,7 @@ async function createTradingOrder(client, tx, input) {
53
59
  registry: __1.MARKET,
54
60
  poolRegistry: __1.LP_POOL,
55
61
  marketIndex: BigInt(input.perpIndex),
56
- poolIndex: BigInt(input.perpIndex),
62
+ poolIndex: BigInt(input.poolIndex),
57
63
  typusOracleCToken: constants_1.oracle[__1.NETWORK][TOKEN],
58
64
  typusOracleTradingSymbol: constants_1.oracle[__1.NETWORK][BASE_TOKEN],
59
65
  collateral: coin,
@@ -104,19 +110,19 @@ async function increaseCollateral(client, tx, input) {
104
110
  let suiCoin;
105
111
  if (TOKEN == "SUI" && client.config.sponsored) {
106
112
  // split together
107
- [coin, suiCoin] = (0, utils_1.splitCoins)(tx, constants_1.tokenType.MAINNET.SUI, input.coins, [input.amount, tokens.length.toString()], client.config.sponsored);
113
+ [coin, suiCoin] = (0, utils_2.splitCoins)(tx, constants_1.tokenType.MAINNET.SUI, input.coins, [input.amount, tokens.length.toString()], client.config.sponsored);
108
114
  }
109
115
  else if (client.config.sponsored) {
110
- coin = (0, utils_1.splitCoin)(tx, cToken, input.coins, input.amount, client.config.sponsored);
111
- suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), client.config.sponsored);
116
+ coin = (0, utils_2.splitCoin)(tx, cToken, input.coins, input.amount, client.config.sponsored);
117
+ suiCoin = (0, utils_2.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), client.config.sponsored);
112
118
  }
113
119
  else {
114
- coin = (0, utils_1.splitCoin)(tx, cToken, input.coins, input.amount, client.config.sponsored);
120
+ coin = (0, utils_2.splitCoin)(tx, cToken, input.coins, input.amount, client.config.sponsored);
115
121
  // no suiCoin
116
122
  }
117
- await (0, utils_1.updatePyth)(client.pythClient, tx, tokens, suiCoin);
123
+ await (0, utils_2.updatePyth)(client.pythClient, tx, tokens, suiCoin);
118
124
  for (let token of tokens) {
119
- (0, utils_1.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
125
+ (0, utils_2.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
120
126
  }
121
127
  // @ts-ignore
122
128
  let marketIndex = BigInt(input.position.marketIndex);
@@ -143,11 +149,11 @@ async function releaseCollateral(client, tx, input) {
143
149
  let tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
144
150
  let suiCoin;
145
151
  if (client.config.sponsored) {
146
- suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), client.config.sponsored);
152
+ suiCoin = (0, utils_2.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), client.config.sponsored);
147
153
  }
148
- await (0, utils_1.updatePyth)(client.pythClient, tx, tokens, suiCoin);
154
+ await (0, utils_2.updatePyth)(client.pythClient, tx, tokens, suiCoin);
149
155
  for (let token of tokens) {
150
- (0, utils_1.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
156
+ (0, utils_2.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
151
157
  }
152
158
  let cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
153
159
  let baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
@@ -177,11 +183,11 @@ async function collectPositionFundingFee(client, tx, input) {
177
183
  let tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
178
184
  let suiCoin;
179
185
  if (client.config.sponsored) {
180
- suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), client.config.sponsored);
186
+ suiCoin = (0, utils_2.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), client.config.sponsored);
181
187
  }
182
- await (0, utils_1.updatePyth)(client.pythClient, tx, tokens, suiCoin);
188
+ await (0, utils_2.updatePyth)(client.pythClient, tx, tokens, suiCoin);
183
189
  for (let token of tokens) {
184
- (0, utils_1.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
190
+ (0, utils_2.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
185
191
  }
186
192
  let cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
187
193
  let baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typus/typus-perp-sdk",
3
- "version": "1.1.32-codegen-exp14-profit-vault",
3
+ "version": "1.1.32-codegen-exp15-profit-vault",
4
4
  "repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
5
5
  "author": "Typus",
6
6
  "description": "typus perp sdk",
@@ -8,7 +8,7 @@
8
8
  "dependencies": {
9
9
  "@mysten/bcs": "1.9.2",
10
10
  "@mysten/sui": "1.44.0",
11
- "@typus/typus-sdk": "1.8.30"
11
+ "@typus/typus-sdk": "1.8.31"
12
12
  },
13
13
  "resolutions": {
14
14
  "@mysten/bcs": "1.9.2",