@typus/typus-perp-sdk 1.0.83 → 1.0.84

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.
@@ -35,22 +35,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
- var __read = (this && this.__read) || function (o, n) {
39
- var m = typeof Symbol === "function" && o[Symbol.iterator];
40
- if (!m) return o;
41
- var i = m.call(o), r, ar = [], e;
42
- try {
43
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
44
- }
45
- catch (error) { e = { error: error }; }
46
- finally {
47
- try {
48
- if (r && !r.done && (m = i["return"])) m.call(i);
49
- }
50
- finally { if (e) throw e.error; }
51
- }
52
- return ar;
53
- };
54
38
  var __values = (this && this.__values) || function(o) {
55
39
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
56
40
  if (m) return m.call(o);
@@ -74,41 +58,20 @@ var utils_1 = require("@typus/typus-sdk/dist/src/utils");
74
58
  var constants_1 = require("@typus/typus-sdk/dist/src/constants");
75
59
  function createTradingOrder(config, tx, pythClient, input) {
76
60
  return __awaiter(this, void 0, void 0, function () {
77
- var TOKEN, BASE_TOKEN, cToken, baseToken, coin, destination, tokens, tokens_1, tokens_1_1, token;
78
- var _a, _b, _c, _d, e_1, _e;
79
- return __generator(this, function (_f) {
80
- switch (_f.label) {
61
+ var TOKEN, BASE_TOKEN, cToken, baseToken, coin, tokens, tokens_1, tokens_1_1, token;
62
+ var e_1, _a;
63
+ return __generator(this, function (_b) {
64
+ switch (_b.label) {
81
65
  case 0:
82
66
  TOKEN = input.cToken;
83
67
  BASE_TOKEN = input.tradingToken;
84
68
  cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
85
69
  baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
86
- if (TOKEN == "SUI") {
87
- if (input.coins.length == 0) {
88
- // support zero coin input for closing position
89
- _a = __read(zeroCoin(tx, [cToken]), 1), coin = _a[0];
90
- }
91
- else {
92
- _b = __read(tx.splitCoins(tx.gas, [input.amount]), 1), coin = _b[0];
93
- }
94
- }
95
- else {
96
- if (input.coins.length == 0) {
97
- // support zero coin input for closing position
98
- _c = __read(zeroCoin(tx, [cToken]), 1), coin = _c[0];
99
- }
100
- else {
101
- destination = input.coins.pop();
102
- if (input.coins.length > 0) {
103
- tx.mergeCoins(destination, input.coins);
104
- }
105
- _d = __read(tx.splitCoins(destination, [input.amount]), 1), coin = _d[0];
106
- }
107
- }
70
+ coin = (0, utils_1.splitCoins)(tx, cToken, input.coins, input.amount, config.sponsored);
108
71
  tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
109
72
  return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens)];
110
73
  case 1:
111
- _f.sent();
74
+ _b.sent();
112
75
  try {
113
76
  for (tokens_1 = __values(tokens), tokens_1_1 = tokens_1.next(); !tokens_1_1.done; tokens_1_1 = tokens_1.next()) {
114
77
  token = tokens_1_1.value;
@@ -118,7 +81,7 @@ function createTradingOrder(config, tx, pythClient, input) {
118
81
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
119
82
  finally {
120
83
  try {
121
- if (tokens_1_1 && !tokens_1_1.done && (_e = tokens_1.return)) _e.call(tokens_1);
84
+ if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
122
85
  }
123
86
  finally { if (e_1) throw e_1.error; }
124
87
  }
@@ -177,17 +140,17 @@ function cancelTradingOrder(config, tx, input) {
177
140
  }
178
141
  function increaseCollateral(config, tx, pythClient, input) {
179
142
  return __awaiter(this, void 0, void 0, function () {
180
- var TOKEN, BASE_TOKEN, tokens, tokens_2, tokens_2_1, token, cToken, baseToken, coin, destination;
181
- var e_2, _a, _b, _c;
182
- return __generator(this, function (_d) {
183
- switch (_d.label) {
143
+ var TOKEN, BASE_TOKEN, tokens, tokens_2, tokens_2_1, token, cToken, baseToken, coin;
144
+ var e_2, _a;
145
+ return __generator(this, function (_b) {
146
+ switch (_b.label) {
184
147
  case 0:
185
148
  TOKEN = (0, constants_1.typeArgToAsset)(input.position.collateralToken.name);
186
149
  BASE_TOKEN = (0, constants_1.typeArgToAsset)(input.position.symbol.baseToken.name);
187
150
  tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
188
151
  return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens)];
189
152
  case 1:
190
- _d.sent();
153
+ _b.sent();
191
154
  try {
192
155
  for (tokens_2 = __values(tokens), tokens_2_1 = tokens_2.next(); !tokens_2_1.done; tokens_2_1 = tokens_2.next()) {
193
156
  token = tokens_2_1.value;
@@ -203,16 +166,7 @@ function increaseCollateral(config, tx, pythClient, input) {
203
166
  }
204
167
  cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
205
168
  baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
206
- if (TOKEN == "SUI") {
207
- _b = __read(tx.splitCoins(tx.gas, [input.amount]), 1), coin = _b[0];
208
- }
209
- else {
210
- destination = input.coins.pop();
211
- if (input.coins.length > 0) {
212
- tx.mergeCoins(destination, input.coins);
213
- }
214
- _c = __read(tx.splitCoins(destination, [input.amount]), 1), coin = _c[0];
215
- }
169
+ coin = (0, utils_1.splitCoins)(tx, cToken, input.coins, input.amount, config.sponsored);
216
170
  (0, functions_1.increaseCollateral)(tx, [cToken, baseToken], {
217
171
  version: __1.PERP_VERSION,
218
172
  registry: __1.MARKET,
@@ -95,17 +95,17 @@ function snapshot(config, tx, input) {
95
95
  }
96
96
  function mintStakeLp(config, tx, pythClient, input) {
97
97
  return __awaiter(this, void 0, void 0, function () {
98
- var tokens, tokens_1, tokens_1_1, token, coin, destination, cToken, lpCoin;
99
- var e_1, _a, _b, _c;
100
- return __generator(this, function (_d) {
101
- switch (_d.label) {
98
+ var tokens, tokens_1, tokens_1_1, token, cToken, coin, lpCoin;
99
+ var e_1, _a;
100
+ return __generator(this, function (_b) {
101
+ switch (_b.label) {
102
102
  case 0:
103
103
  tokens = input.lpPool.tokenPools.map(function (p) { return (0, constants_1.typeArgToAsset)("0x" + p.tokenType.name); });
104
104
  // console.log("tokens", tokens);
105
105
  return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens)];
106
106
  case 1:
107
107
  // console.log("tokens", tokens);
108
- _d.sent();
108
+ _b.sent();
109
109
  try {
110
110
  for (tokens_1 = __values(tokens), tokens_1_1 = tokens_1.next(); !tokens_1_1.done; tokens_1_1 = tokens_1.next()) {
111
111
  token = tokens_1_1.value;
@@ -126,21 +126,12 @@ function mintStakeLp(config, tx, pythClient, input) {
126
126
  }
127
127
  finally { if (e_1) throw e_1.error; }
128
128
  }
129
- if (input.cTOKEN == "SUI") {
130
- _b = __read(tx.splitCoins(tx.gas, [input.amount]), 1), coin = _b[0];
131
- }
132
- else {
133
- destination = input.coins.pop();
134
- if (input.coins.length > 0) {
135
- tx.mergeCoins(destination, input.coins);
136
- }
137
- _c = __read(tx.splitCoins(destination, [input.amount]), 1), coin = _c[0];
138
- }
129
+ cToken = constants_1.tokenType[__1.NETWORK][input.cTOKEN];
130
+ coin = (0, utils_1.splitCoins)(tx, cToken, input.coins, input.amount, config.sponsored);
139
131
  // console.log(iToken);
140
132
  if (input.userShareId) {
141
133
  harvestStakeReward(config, tx, { stakePool: input.stakePool, userShareId: input.userShareId, user: input.user });
142
134
  }
143
- cToken = constants_1.tokenType[__1.NETWORK][input.cTOKEN];
144
135
  lpCoin = (0, functions_1.mintLp)(tx, [cToken, __1.TLP_TOKEN], {
145
136
  version: __1.PERP_VERSION,
146
137
  registry: __1.LP_POOL,
@@ -390,26 +381,16 @@ function claim(config, tx, pythClient, input) {
390
381
  }
391
382
  function swap(config, tx, pythClient, input) {
392
383
  return __awaiter(this, void 0, void 0, function () {
393
- var coin, destination, fromToken, toToken, token;
394
- var _a, _b;
395
- return __generator(this, function (_c) {
396
- switch (_c.label) {
384
+ var fromToken, coin, toToken, token;
385
+ return __generator(this, function (_a) {
386
+ switch (_a.label) {
397
387
  case 0: return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, [input.FROM_TOKEN, input.TO_TOKEN])];
398
388
  case 1:
399
- _c.sent();
389
+ _a.sent();
400
390
  (0, utils_1.updateOracleWithPythUsd)(pythClient, tx, config.package.oracle, input.FROM_TOKEN);
401
391
  (0, utils_1.updateOracleWithPythUsd)(pythClient, tx, config.package.oracle, input.TO_TOKEN);
402
- if (input.FROM_TOKEN == "SUI") {
403
- _a = __read(tx.splitCoins(tx.gas, [input.amount]), 1), coin = _a[0];
404
- }
405
- else {
406
- destination = input.coins.pop();
407
- if (input.coins.length > 0) {
408
- tx.mergeCoins(destination, input.coins);
409
- }
410
- _b = __read(tx.splitCoins(destination, [input.amount]), 1), coin = _b[0];
411
- }
412
392
  fromToken = constants_1.tokenType[__1.NETWORK][input.FROM_TOKEN];
393
+ coin = (0, utils_1.splitCoins)(tx, fromToken, input.coins, input.amount, config.sponsored);
413
394
  toToken = constants_1.tokenType[__1.NETWORK][input.TO_TOKEN];
414
395
  token = (0, functions_1.swap)(tx, [fromToken, toToken], {
415
396
  version: __1.PERP_VERSION,
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@typus/typus-perp-sdk",
3
- "version": "1.0.83",
3
+ "version": "1.0.84",
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.7.11"
9
+ "@typus/typus-sdk": "1.7.14"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@types/bs58": "^4.0.1",