@typus/typus-perp-sdk 1.0.33 → 1.0.35

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.
@@ -120,12 +120,11 @@ function getTlpAPRFromSentio() {
120
120
  return [4 /*yield*/, response.json()];
121
121
  case 2:
122
122
  data = _a.sent();
123
- console.log(data);
124
123
  first = data.results[0].matrix.samples[0].values[0];
125
124
  last = data.results[0].matrix.samples[0].values.at(-1);
126
125
  r = last.value / first.value - 1;
127
126
  apr = (365 / 7) * r;
128
- console.log(apr);
127
+ // console.log(apr);
129
128
  return [2 /*return*/, apr];
130
129
  }
131
130
  });
@@ -191,4 +190,3 @@ function getVolumeFromSentio() {
191
190
  });
192
191
  });
193
192
  }
194
- getTlpAPRFromSentio();
@@ -18,6 +18,9 @@ export declare function getMarkets(config: TypusConfig, input: {
18
18
  export declare function getUserOrders(config: TypusConfig, user: string): Promise<TradingOrder[]>;
19
19
  export declare function getUserPositions(config: TypusConfig, user: string): Promise<Position[]>;
20
20
  export declare function parseOptionBidReceipts(positions: Position[]): (TypusBidReceipt | null)[];
21
+ /**
22
+ * @returns [lpShare, incentives]
23
+ */
21
24
  export declare function getUserStake(config: TypusConfig, user: string): Promise<[LpUserShare, string[]][]>;
22
25
  /**
23
26
  * @returns [liquidationPrice, pnl(in USD)]
package/dist/src/fetch.js CHANGED
@@ -345,6 +345,9 @@ function parseOptionBidReceipts(positions) {
345
345
  }
346
346
  });
347
347
  }
348
+ /**
349
+ * @returns [lpShare, incentives]
350
+ */
348
351
  function getUserStake(config, user) {
349
352
  return __awaiter(this, void 0, void 0, function () {
350
353
  var provider, tx, res, returnValues, reader, lpShares_1;
@@ -20,6 +20,14 @@ export declare function unstakeBurn(config: TypusConfig, tx: Transaction, pythCl
20
20
  share: string | null;
21
21
  user: string;
22
22
  }): Promise<Transaction>;
23
+ export declare function burnTlp(config: TypusConfig, tx: Transaction, pythClient: PythClient, input: {
24
+ lpPool: LiquidityPool;
25
+ stakePool: StakePool;
26
+ cTOKEN: TOKEN;
27
+ lpCoin: string;
28
+ share: string | null;
29
+ user: string;
30
+ }): Promise<Transaction>;
23
31
  export declare function swap(config: TypusConfig, tx: Transaction, pythClient: PythClient, input: {
24
32
  coins: string[];
25
33
  FROM_TOKEN: TOKEN;
@@ -65,6 +65,7 @@ var __read = (this && this.__read) || function (o, n) {
65
65
  Object.defineProperty(exports, "__esModule", { value: true });
66
66
  exports.mintStakeLp = mintStakeLp;
67
67
  exports.unstakeBurn = unstakeBurn;
68
+ exports.burnTlp = burnTlp;
68
69
  exports.swap = swap;
69
70
  exports.unsubscribe = unsubscribe;
70
71
  exports.harvestStakeReward = harvestStakeReward;
@@ -165,7 +166,7 @@ function mintStakeLp(config, tx, pythClient, input) {
165
166
  }
166
167
  function unstakeBurn(config, tx, pythClient, input) {
167
168
  return __awaiter(this, void 0, void 0, function () {
168
- var tokens, tokens_2, tokens_2_1, token, iTokens, iTokens_2, iTokens_2_1, iToken, iCoin, lpCoin, cToken, coin;
169
+ var tokens, tokens_2, tokens_2_1, token, iTokens, iTokens_2, iTokens_2_1, iToken, iCoin, lpCoin, burnCoin, cToken, coin;
169
170
  var e_3, _a, e_4, _b;
170
171
  return __generator(this, function (_c) {
171
172
  switch (_c.label) {
@@ -224,6 +225,13 @@ function unstakeBurn(config, tx, pythClient, input) {
224
225
  userShareId: BigInt(input.userShareId),
225
226
  clock: constants_1.CLOCK,
226
227
  });
228
+ if (input.share) {
229
+ burnCoin = tx.splitCoins(lpCoin, [input.share]);
230
+ tx.transferObjects([lpCoin], input.user);
231
+ }
232
+ else {
233
+ burnCoin = lpCoin;
234
+ }
227
235
  cToken = constants_1.tokenType[__1.NETWORK][input.cTOKEN];
228
236
  coin = (0, functions_1.burnLp)(tx, [cToken, __1.TLP_TOKEN], {
229
237
  version: __1.PERP_VERSION,
@@ -231,7 +239,61 @@ function unstakeBurn(config, tx, pythClient, input) {
231
239
  treasuryCaps: __1.TLP_TREASURY_CAP,
232
240
  index: BigInt(0),
233
241
  oracle: constants_1.oracle[__1.NETWORK][input.cTOKEN],
234
- coin: lpCoin,
242
+ coin: burnCoin,
243
+ clock: constants_1.CLOCK,
244
+ });
245
+ tx.transferObjects([coin], input.user);
246
+ return [2 /*return*/, tx];
247
+ }
248
+ });
249
+ });
250
+ }
251
+ function burnTlp(config, tx, pythClient, input) {
252
+ return __awaiter(this, void 0, void 0, function () {
253
+ var tokens, tokens_3, tokens_3_1, token, lpCoin, burnCoin, cToken, coin;
254
+ var e_5, _a;
255
+ return __generator(this, function (_b) {
256
+ switch (_b.label) {
257
+ case 0:
258
+ tokens = input.lpPool.tokenPools.map(function (p) { return (0, constants_1.typeArgToAsset)("0x" + p.tokenType.name); });
259
+ return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens)];
260
+ case 1:
261
+ _b.sent();
262
+ try {
263
+ for (tokens_3 = __values(tokens), tokens_3_1 = tokens_3.next(); !tokens_3_1.done; tokens_3_1 = tokens_3.next()) {
264
+ token = tokens_3_1.value;
265
+ (0, utils_1.updateOracleWithPythUsd)(pythClient, tx, config.package.oracle, token);
266
+ (0, functions_1.updateLiquidityValue)(tx, constants_1.tokenType[__1.NETWORK][token], {
267
+ version: __1.PERP_VERSION,
268
+ registry: __1.LP_POOL,
269
+ index: BigInt(0),
270
+ oracle: constants_1.oracle[__1.NETWORK][token],
271
+ clock: constants_1.CLOCK,
272
+ });
273
+ }
274
+ }
275
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
276
+ finally {
277
+ try {
278
+ if (tokens_3_1 && !tokens_3_1.done && (_a = tokens_3.return)) _a.call(tokens_3);
279
+ }
280
+ finally { if (e_5) throw e_5.error; }
281
+ }
282
+ lpCoin = tx.object(input.lpCoin);
283
+ if (input.share) {
284
+ burnCoin = tx.splitCoins(lpCoin, [input.share]);
285
+ }
286
+ else {
287
+ burnCoin = lpCoin;
288
+ }
289
+ cToken = constants_1.tokenType[__1.NETWORK][input.cTOKEN];
290
+ coin = (0, functions_1.burnLp)(tx, [cToken, __1.TLP_TOKEN], {
291
+ version: __1.PERP_VERSION,
292
+ registry: __1.LP_POOL,
293
+ treasuryCaps: __1.TLP_TREASURY_CAP,
294
+ index: BigInt(0),
295
+ oracle: constants_1.oracle[__1.NETWORK][input.cTOKEN],
296
+ coin: burnCoin,
235
297
  clock: constants_1.CLOCK,
236
298
  });
237
299
  tx.transferObjects([coin], input.user);
@@ -297,7 +359,7 @@ function unsubscribe(config, tx, input) {
297
359
  function harvestStakeReward(config, tx, input) {
298
360
  return __awaiter(this, void 0, void 0, function () {
299
361
  var iTokens, iTokens_3, iTokens_3_1, iToken, iCoin;
300
- var e_5, _a;
362
+ var e_6, _a;
301
363
  return __generator(this, function (_b) {
302
364
  iTokens = input.stakePool.incentives.map(function (i) { return i.tokenType.name; });
303
365
  try {
@@ -310,15 +372,28 @@ function harvestStakeReward(config, tx, input) {
310
372
  userShareId: BigInt(input.userShareId),
311
373
  clock: constants_1.CLOCK,
312
374
  });
313
- tx.transferObjects([iCoin], input.user);
375
+ if (iToken.endsWith("TLP")) {
376
+ // stake
377
+ (0, functions_2.stake)(tx, __1.TLP_TOKEN, {
378
+ version: __1.STAKE_POOL_VERSION,
379
+ registry: __1.STAKE_POOL,
380
+ index: BigInt(0),
381
+ lpToken: iCoin,
382
+ clock: constants_1.CLOCK,
383
+ userShareId: input.userShareId ? BigInt(input.userShareId) : null,
384
+ });
385
+ }
386
+ else {
387
+ tx.transferObjects([iCoin], input.user);
388
+ }
314
389
  }
315
390
  }
316
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
391
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
317
392
  finally {
318
393
  try {
319
394
  if (iTokens_3_1 && !iTokens_3_1.done && (_a = iTokens_3.return)) _a.call(iTokens_3);
320
395
  }
321
- finally { if (e_5) throw e_5.error; }
396
+ finally { if (e_6) throw e_6.error; }
322
397
  }
323
398
  return [2 /*return*/, tx];
324
399
  });
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@typus/typus-perp-sdk",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
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
- "@typus/typus-sdk": "1.6.13"
9
+ "@typus/typus-sdk": "1.6.14"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@types/bs58": "^4.0.1",