@typus/typus-perp-sdk 1.1.32-codegen-exp18 → 1.1.32-codegen-exp20

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.
@@ -27,10 +27,10 @@ export declare function getAccumulatedUser(): Promise<number>;
27
27
  * Returns
28
28
  * { timestamp: string, value: number }[]
29
29
  */
30
- export declare function getTlpPriceFromSentio(fromTimestamp?: number, toTimestamp?: number): Promise<{
30
+ export declare function getTlpPriceFromSentio(fromTimestamp?: number, toTimestamp?: number): Promise<Map<string, {
31
31
  timestamp: string;
32
32
  value: number;
33
- }[]>;
33
+ }[]>>;
34
34
  export declare function getTlpComparisonFromSentio(startTimestamp: number, endTimestamp: number): Promise<tlpComparison[]>;
35
35
  interface tlpComparison {
36
36
  hour: string;
@@ -392,8 +392,9 @@ async function getAccumulatedUser() {
392
392
  * { timestamp: string, value: number }[]
393
393
  */
394
394
  async function getTlpPriceFromSentio(fromTimestamp, toTimestamp) {
395
- let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp/query";
395
+ let apiUrl = "https://api.sentio.xyz/v1/insights/typus/typus_perp/query";
396
396
  let requestData = {
397
+ version: 3,
397
398
  timeRange: {
398
399
  start: `${fromTimestamp ?? 0}`,
399
400
  end: `${toTimestamp ?? now()}`,
@@ -417,6 +418,11 @@ async function getTlpPriceFromSentio(fromTimestamp, toTimestamp) {
417
418
  },
418
419
  ],
419
420
  formulas: [],
421
+ cachePolicy: {
422
+ noCache: false,
423
+ cacheTtlSecs: 43200,
424
+ cacheRefreshTtlSecs: 1800,
425
+ },
420
426
  };
421
427
  let jsonData = JSON.stringify(requestData);
422
428
  let response = await fetch(apiUrl, {
@@ -425,10 +431,14 @@ async function getTlpPriceFromSentio(fromTimestamp, toTimestamp) {
425
431
  body: jsonData,
426
432
  });
427
433
  let data = await response.json();
428
- // console.log(data);
434
+ // console.dir(data, { depth: null });
429
435
  let samples = data.results[0].matrix.samples;
430
436
  // console.log(samples[0].values);
431
- return samples[0].values;
437
+ let map = new Map();
438
+ samples.forEach((sample) => {
439
+ map.set(sample.metric.labels.index, sample.values);
440
+ });
441
+ return map;
432
442
  }
433
443
  async function getTlpComparisonFromSentio(startTimestamp, endTimestamp) {
434
444
  let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp/sql/execute";
@@ -29,17 +29,20 @@ export declare function cancelTradingOrder(client: TypusClient, tx: Transaction,
29
29
  user: string;
30
30
  }): Promise<Transaction>;
31
31
  export declare function increaseCollateral(client: TypusClient, tx: Transaction, input: {
32
+ oracleContract?: string;
32
33
  coins: string[];
33
34
  amount: string;
34
35
  position: typeof Position.$inferType;
35
36
  suiCoins?: string[];
36
37
  }): Promise<Transaction>;
37
38
  export declare function releaseCollateral(client: TypusClient, tx: Transaction, input: {
39
+ oracleContract?: string;
38
40
  position: typeof Position.$inferType;
39
41
  amount: string;
40
42
  suiCoins?: string[];
41
43
  }): Promise<Transaction>;
42
44
  export declare function collectPositionFundingFee(client: TypusClient, tx: Transaction, input: {
45
+ oracleContract?: string;
43
46
  position: typeof Position.$inferType;
44
47
  suiCoins?: string[];
45
48
  }): Promise<Transaction>;
@@ -120,10 +120,15 @@ async function increaseCollateral(client, tx, input) {
120
120
  coin = (0, utils_2.splitCoin)(tx, cToken, input.coins, input.amount, client.config.sponsored);
121
121
  // no suiCoin
122
122
  }
123
- await (0, utils_2.updatePyth)(client.pythClient, tx, tokens, suiCoin);
124
- for (let token of tokens) {
123
+ const tokensWithoutTypus = Array.from(new Set([TOKEN, BASE_TOKEN])).filter((token) => token !== "TYPUS");
124
+ await (0, utils_2.updatePyth)(client.pythClient, tx, tokensWithoutTypus, suiCoin);
125
+ for (let token of tokensWithoutTypus) {
125
126
  (0, utils_2.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
126
127
  }
128
+ if (tokens.includes("TYPUS")) {
129
+ const oracleContract = input.oracleContract ?? client.config.package.oracle;
130
+ tx = await (0, utils_1.updateOracleWithSignatureTx)(__1.NETWORK, tx, oracleContract, constants_1.tokenType[__1.NETWORK]["TYPUS"]);
131
+ }
127
132
  // @ts-ignore
128
133
  let marketIndex = BigInt(input.position.marketIndex);
129
134
  tx.add((0, trading_1.increaseCollateral)({
@@ -151,10 +156,15 @@ async function releaseCollateral(client, tx, input) {
151
156
  if (client.config.sponsored) {
152
157
  suiCoin = (0, utils_2.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), client.config.sponsored);
153
158
  }
154
- await (0, utils_2.updatePyth)(client.pythClient, tx, tokens, suiCoin);
155
- for (let token of tokens) {
159
+ const tokensWithoutTypus = Array.from(new Set([TOKEN, BASE_TOKEN])).filter((token) => token !== "TYPUS");
160
+ await (0, utils_2.updatePyth)(client.pythClient, tx, tokensWithoutTypus, suiCoin);
161
+ for (let token of tokensWithoutTypus) {
156
162
  (0, utils_2.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
157
163
  }
164
+ if (tokens.includes("TYPUS")) {
165
+ const oracleContract = input.oracleContract ?? client.config.package.oracle;
166
+ tx = await (0, utils_1.updateOracleWithSignatureTx)(__1.NETWORK, tx, oracleContract, constants_1.tokenType[__1.NETWORK]["TYPUS"]);
167
+ }
158
168
  let cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
159
169
  let baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
160
170
  // @ts-ignore
@@ -185,10 +195,15 @@ async function collectPositionFundingFee(client, tx, input) {
185
195
  if (client.config.sponsored) {
186
196
  suiCoin = (0, utils_2.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), client.config.sponsored);
187
197
  }
188
- await (0, utils_2.updatePyth)(client.pythClient, tx, tokens, suiCoin);
189
- for (let token of tokens) {
198
+ const tokensWithoutTypus = Array.from(new Set([TOKEN, BASE_TOKEN])).filter((token) => token !== "TYPUS");
199
+ await (0, utils_2.updatePyth)(client.pythClient, tx, tokensWithoutTypus, suiCoin);
200
+ for (let token of tokensWithoutTypus) {
190
201
  (0, utils_2.updateOracleWithPythUsd)(client.pythClient, tx, client.config.package.oracle, token);
191
202
  }
203
+ if (tokens.includes("TYPUS")) {
204
+ const oracleContract = input.oracleContract ?? client.config.package.oracle;
205
+ tx = await (0, utils_1.updateOracleWithSignatureTx)(__1.NETWORK, tx, oracleContract, constants_1.tokenType[__1.NETWORK]["TYPUS"]);
206
+ }
192
207
  let cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
193
208
  let baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
194
209
  // @ts-ignore
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typus/typus-perp-sdk",
3
- "version": "1.1.32-codegen-exp18",
3
+ "version": "1.1.32-codegen-exp20",
4
4
  "repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
5
5
  "author": "Typus",
6
6
  "description": "typus perp sdk",