@typus/typus-perp-sdk 1.0.83 → 1.0.85
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.
- package/dist/src/pyth.d.ts +0 -0
- package/dist/src/pyth.js +1 -0
- package/dist/src/user/order.d.ts +3 -0
- package/dist/src/user/order.js +43 -48
- package/dist/src/user/orderWithBidReceipt.d.ts +2 -0
- package/dist/src/user/orderWithBidReceipt.js +10 -4
- package/dist/src/user/tlp.d.ts +5 -0
- package/dist/src/user/tlp.js +67 -55
- package/package.json +2 -2
|
File without changes
|
package/dist/src/pyth.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/src/user/order.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare function createTradingOrder(config: TypusConfig, tx: Transaction,
|
|
|
13
13
|
isStopOrder: boolean;
|
|
14
14
|
reduceOnly: boolean;
|
|
15
15
|
linkedPositionId: string | null;
|
|
16
|
+
suiCoins?: string[];
|
|
16
17
|
}): Promise<Transaction>;
|
|
17
18
|
export declare function zeroCoin(tx: Transaction, typeArgs: [string]): import("@mysten/sui/transactions").TransactionResult;
|
|
18
19
|
export declare function cancelTradingOrder(config: TypusConfig, tx: Transaction, input: {
|
|
@@ -23,8 +24,10 @@ export declare function increaseCollateral(config: TypusConfig, tx: Transaction,
|
|
|
23
24
|
coins: string[];
|
|
24
25
|
amount: string;
|
|
25
26
|
position: Position;
|
|
27
|
+
suiCoins?: string[];
|
|
26
28
|
}): Promise<Transaction>;
|
|
27
29
|
export declare function releaseCollateral(config: TypusConfig, tx: Transaction, pythClient: PythClient, input: {
|
|
28
30
|
position: Position;
|
|
29
31
|
amount: string;
|
|
32
|
+
suiCoins?: string[];
|
|
30
33
|
}): Promise<Transaction>;
|
package/dist/src/user/order.js
CHANGED
|
@@ -74,41 +74,31 @@ var utils_1 = require("@typus/typus-sdk/dist/src/utils");
|
|
|
74
74
|
var constants_1 = require("@typus/typus-sdk/dist/src/constants");
|
|
75
75
|
function createTradingOrder(config, tx, pythClient, input) {
|
|
76
76
|
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
-
var TOKEN, BASE_TOKEN, cToken, baseToken, coin,
|
|
78
|
-
var _a,
|
|
79
|
-
return __generator(this, function (
|
|
80
|
-
switch (
|
|
77
|
+
var TOKEN, BASE_TOKEN, tokens, cToken, baseToken, coin, suiCoin, tokens_1, tokens_1_1, token;
|
|
78
|
+
var _a, e_1, _b;
|
|
79
|
+
return __generator(this, function (_c) {
|
|
80
|
+
switch (_c.label) {
|
|
81
81
|
case 0:
|
|
82
82
|
TOKEN = input.cToken;
|
|
83
83
|
BASE_TOKEN = input.tradingToken;
|
|
84
|
+
tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
|
|
84
85
|
cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
85
86
|
baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
|
|
86
|
-
if (TOKEN ==
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
87
|
+
if (TOKEN == constants_1.tokenType.MAINNET.SUI && config.sponsored) {
|
|
88
|
+
// split together
|
|
89
|
+
_a = __read((0, utils_1.splitCoins)(tx, constants_1.tokenType.MAINNET.SUI, input.coins, [input.amount, tokens.length.toString()], config.sponsored), 2), coin = _a[0], suiCoin = _a[1];
|
|
90
|
+
}
|
|
91
|
+
else if (config.sponsored) {
|
|
92
|
+
coin = (0, utils_1.splitCoin)(tx, cToken, input.coins, input.amount, config.sponsored);
|
|
93
|
+
suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), config.sponsored);
|
|
94
94
|
}
|
|
95
95
|
else {
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
}
|
|
96
|
+
coin = (0, utils_1.splitCoin)(tx, cToken, input.coins, input.amount, config.sponsored);
|
|
97
|
+
// no suiCoin
|
|
107
98
|
}
|
|
108
|
-
|
|
109
|
-
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens)];
|
|
99
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens, suiCoin)];
|
|
110
100
|
case 1:
|
|
111
|
-
|
|
101
|
+
_c.sent();
|
|
112
102
|
try {
|
|
113
103
|
for (tokens_1 = __values(tokens), tokens_1_1 = tokens_1.next(); !tokens_1_1.done; tokens_1_1 = tokens_1.next()) {
|
|
114
104
|
token = tokens_1_1.value;
|
|
@@ -118,7 +108,7 @@ function createTradingOrder(config, tx, pythClient, input) {
|
|
|
118
108
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
119
109
|
finally {
|
|
120
110
|
try {
|
|
121
|
-
if (tokens_1_1 && !tokens_1_1.done && (
|
|
111
|
+
if (tokens_1_1 && !tokens_1_1.done && (_b = tokens_1.return)) _b.call(tokens_1);
|
|
122
112
|
}
|
|
123
113
|
finally { if (e_1) throw e_1.error; }
|
|
124
114
|
}
|
|
@@ -177,17 +167,31 @@ function cancelTradingOrder(config, tx, input) {
|
|
|
177
167
|
}
|
|
178
168
|
function increaseCollateral(config, tx, pythClient, input) {
|
|
179
169
|
return __awaiter(this, void 0, void 0, function () {
|
|
180
|
-
var TOKEN, BASE_TOKEN, tokens,
|
|
181
|
-
var
|
|
182
|
-
return __generator(this, function (
|
|
183
|
-
switch (
|
|
170
|
+
var TOKEN, BASE_TOKEN, tokens, cToken, baseToken, coin, suiCoin, tokens_2, tokens_2_1, token;
|
|
171
|
+
var _a, e_2, _b;
|
|
172
|
+
return __generator(this, function (_c) {
|
|
173
|
+
switch (_c.label) {
|
|
184
174
|
case 0:
|
|
185
175
|
TOKEN = (0, constants_1.typeArgToAsset)(input.position.collateralToken.name);
|
|
186
176
|
BASE_TOKEN = (0, constants_1.typeArgToAsset)(input.position.symbol.baseToken.name);
|
|
187
177
|
tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
|
|
188
|
-
|
|
178
|
+
cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
179
|
+
baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
|
|
180
|
+
if (TOKEN == constants_1.tokenType.MAINNET.SUI && config.sponsored) {
|
|
181
|
+
// split together
|
|
182
|
+
_a = __read((0, utils_1.splitCoins)(tx, constants_1.tokenType.MAINNET.SUI, input.coins, [input.amount, tokens.length.toString()], config.sponsored), 2), coin = _a[0], suiCoin = _a[1];
|
|
183
|
+
}
|
|
184
|
+
else if (config.sponsored) {
|
|
185
|
+
coin = (0, utils_1.splitCoin)(tx, cToken, input.coins, input.amount, config.sponsored);
|
|
186
|
+
suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), config.sponsored);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
coin = (0, utils_1.splitCoin)(tx, cToken, input.coins, input.amount, config.sponsored);
|
|
190
|
+
// no suiCoin
|
|
191
|
+
}
|
|
192
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens, suiCoin)];
|
|
189
193
|
case 1:
|
|
190
|
-
|
|
194
|
+
_c.sent();
|
|
191
195
|
try {
|
|
192
196
|
for (tokens_2 = __values(tokens), tokens_2_1 = tokens_2.next(); !tokens_2_1.done; tokens_2_1 = tokens_2.next()) {
|
|
193
197
|
token = tokens_2_1.value;
|
|
@@ -197,22 +201,10 @@ function increaseCollateral(config, tx, pythClient, input) {
|
|
|
197
201
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
198
202
|
finally {
|
|
199
203
|
try {
|
|
200
|
-
if (tokens_2_1 && !tokens_2_1.done && (
|
|
204
|
+
if (tokens_2_1 && !tokens_2_1.done && (_b = tokens_2.return)) _b.call(tokens_2);
|
|
201
205
|
}
|
|
202
206
|
finally { if (e_2) throw e_2.error; }
|
|
203
207
|
}
|
|
204
|
-
cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
205
|
-
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
|
-
}
|
|
216
208
|
(0, functions_1.increaseCollateral)(tx, [cToken, baseToken], {
|
|
217
209
|
version: __1.PERP_VERSION,
|
|
218
210
|
registry: __1.MARKET,
|
|
@@ -232,7 +224,7 @@ function increaseCollateral(config, tx, pythClient, input) {
|
|
|
232
224
|
}
|
|
233
225
|
function releaseCollateral(config, tx, pythClient, input) {
|
|
234
226
|
return __awaiter(this, void 0, void 0, function () {
|
|
235
|
-
var TOKEN, BASE_TOKEN, tokens, tokens_3, tokens_3_1, token, cToken, baseToken, coin;
|
|
227
|
+
var TOKEN, BASE_TOKEN, tokens, suiCoin, tokens_3, tokens_3_1, token, cToken, baseToken, coin;
|
|
236
228
|
var e_3, _a;
|
|
237
229
|
return __generator(this, function (_b) {
|
|
238
230
|
switch (_b.label) {
|
|
@@ -240,7 +232,10 @@ function releaseCollateral(config, tx, pythClient, input) {
|
|
|
240
232
|
TOKEN = (0, constants_1.typeArgToAsset)(input.position.collateralToken.name);
|
|
241
233
|
BASE_TOKEN = (0, constants_1.typeArgToAsset)(input.position.symbol.baseToken.name);
|
|
242
234
|
tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
|
|
243
|
-
|
|
235
|
+
if (config.sponsored) {
|
|
236
|
+
suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), config.sponsored);
|
|
237
|
+
}
|
|
238
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens, suiCoin)];
|
|
244
239
|
case 1:
|
|
245
240
|
_b.sent();
|
|
246
241
|
try {
|
|
@@ -10,6 +10,7 @@ export declare function createTradingOrderWithBidReceipt(config: TypusConfig, tx
|
|
|
10
10
|
bToken: TOKEN;
|
|
11
11
|
bidReceipts: string[];
|
|
12
12
|
share?: string;
|
|
13
|
+
suiCoins?: string[];
|
|
13
14
|
}): Promise<Transaction>;
|
|
14
15
|
export declare function reduceOptionCollateralPositionSize(config: TypusConfig, tx: Transaction, pythClient: PythClient, input: {
|
|
15
16
|
cToken: TOKEN;
|
|
@@ -17,4 +18,5 @@ export declare function reduceOptionCollateralPositionSize(config: TypusConfig,
|
|
|
17
18
|
bToken: string;
|
|
18
19
|
positionId: string;
|
|
19
20
|
orderSize: string | null;
|
|
21
|
+
suiCoins?: string[];
|
|
20
22
|
}): Promise<Transaction>;
|
|
@@ -56,7 +56,7 @@ var typus_dov_single_v2_1 = require("@typus/typus-sdk/dist/src/typus-dov-single-
|
|
|
56
56
|
var __1 = require("..");
|
|
57
57
|
function createTradingOrderWithBidReceipt(config, tx, pythClient, input) {
|
|
58
58
|
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
-
var TOKEN, BASE_TOKEN, tokens, tokens_1, tokens_1_1, token, collateralBidReceipt, cToken, bToken, baseToken;
|
|
59
|
+
var TOKEN, BASE_TOKEN, tokens, suiCoin, tokens_1, tokens_1_1, token, collateralBidReceipt, cToken, bToken, baseToken;
|
|
60
60
|
var e_1, _a;
|
|
61
61
|
return __generator(this, function (_b) {
|
|
62
62
|
switch (_b.label) {
|
|
@@ -64,7 +64,10 @@ function createTradingOrderWithBidReceipt(config, tx, pythClient, input) {
|
|
|
64
64
|
TOKEN = input.cToken;
|
|
65
65
|
BASE_TOKEN = input.tradingToken;
|
|
66
66
|
tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
|
|
67
|
-
|
|
67
|
+
if (config.sponsored) {
|
|
68
|
+
suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), config.sponsored);
|
|
69
|
+
}
|
|
70
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens, suiCoin)];
|
|
68
71
|
case 1:
|
|
69
72
|
_b.sent();
|
|
70
73
|
try {
|
|
@@ -115,7 +118,7 @@ function createTradingOrderWithBidReceipt(config, tx, pythClient, input) {
|
|
|
115
118
|
}
|
|
116
119
|
function reduceOptionCollateralPositionSize(config, tx, pythClient, input) {
|
|
117
120
|
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
-
var TOKEN, BASE_TOKEN, tokens, tokens_2, tokens_2_1, token, cToken, bToken, baseToken;
|
|
121
|
+
var TOKEN, BASE_TOKEN, tokens, suiCoin, tokens_2, tokens_2_1, token, cToken, bToken, baseToken;
|
|
119
122
|
var e_2, _a;
|
|
120
123
|
return __generator(this, function (_b) {
|
|
121
124
|
switch (_b.label) {
|
|
@@ -123,7 +126,10 @@ function reduceOptionCollateralPositionSize(config, tx, pythClient, input) {
|
|
|
123
126
|
TOKEN = input.cToken;
|
|
124
127
|
BASE_TOKEN = input.tradingToken;
|
|
125
128
|
tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
|
|
126
|
-
|
|
129
|
+
if (config.sponsored) {
|
|
130
|
+
suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), config.sponsored);
|
|
131
|
+
}
|
|
132
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens, suiCoin)];
|
|
127
133
|
case 1:
|
|
128
134
|
_b.sent();
|
|
129
135
|
try {
|
package/dist/src/user/tlp.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare function mintStakeLp(config: TypusConfig, tx: Transaction, pythCl
|
|
|
15
15
|
userShareId: string | null;
|
|
16
16
|
user: string;
|
|
17
17
|
stake: boolean;
|
|
18
|
+
suiCoins?: string[];
|
|
18
19
|
}): Promise<Transaction>;
|
|
19
20
|
export declare function stakeLp(config: TypusConfig, tx: Transaction, input: {
|
|
20
21
|
stakePool: StakePool;
|
|
@@ -36,18 +37,21 @@ export declare function unstakeRedeem(config: TypusConfig, tx: Transaction, pyth
|
|
|
36
37
|
userShareId: string;
|
|
37
38
|
share: string | null;
|
|
38
39
|
user: string;
|
|
40
|
+
suiCoins?: string[];
|
|
39
41
|
}): Promise<Transaction>;
|
|
40
42
|
export declare function redeemTlp(config: TypusConfig, tx: Transaction, pythClient: PythClient, input: {
|
|
41
43
|
lpPool: LiquidityPool;
|
|
42
44
|
lpCoins: string[];
|
|
43
45
|
share: string | null;
|
|
44
46
|
user: string;
|
|
47
|
+
suiCoins?: string[];
|
|
45
48
|
}): Promise<Transaction>;
|
|
46
49
|
export declare function claim(config: TypusConfig, tx: Transaction, pythClient: PythClient, input: {
|
|
47
50
|
lpPool: LiquidityPool;
|
|
48
51
|
stakePool: StakePool;
|
|
49
52
|
cTOKEN: TOKEN;
|
|
50
53
|
user: string;
|
|
54
|
+
suiCoins?: string[];
|
|
51
55
|
}): Promise<Transaction>;
|
|
52
56
|
export declare function swap(config: TypusConfig, tx: Transaction, pythClient: PythClient, input: {
|
|
53
57
|
coins: string[];
|
|
@@ -55,6 +59,7 @@ export declare function swap(config: TypusConfig, tx: Transaction, pythClient: P
|
|
|
55
59
|
TO_TOKEN: TOKEN;
|
|
56
60
|
amount: string;
|
|
57
61
|
user: string;
|
|
62
|
+
suiCoins?: string[];
|
|
58
63
|
}): Promise<Transaction>;
|
|
59
64
|
export declare function harvestStakeReward(config: TypusConfig, tx: Transaction, input: {
|
|
60
65
|
stakePool: StakePool;
|
package/dist/src/user/tlp.js
CHANGED
|
@@ -35,17 +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 __values = (this && this.__values) || function(o) {
|
|
39
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
-
if (m) return m.call(o);
|
|
41
|
-
if (o && typeof o.length === "number") return {
|
|
42
|
-
next: function () {
|
|
43
|
-
if (o && i >= o.length) o = void 0;
|
|
44
|
-
return { value: o && o[i++], done: !o };
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
-
};
|
|
49
38
|
var __read = (this && this.__read) || function (o, n) {
|
|
50
39
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
40
|
if (!m) return o;
|
|
@@ -62,6 +51,17 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
62
51
|
}
|
|
63
52
|
return ar;
|
|
64
53
|
};
|
|
54
|
+
var __values = (this && this.__values) || function(o) {
|
|
55
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
56
|
+
if (m) return m.call(o);
|
|
57
|
+
if (o && typeof o.length === "number") return {
|
|
58
|
+
next: function () {
|
|
59
|
+
if (o && i >= o.length) o = void 0;
|
|
60
|
+
return { value: o && o[i++], done: !o };
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
64
|
+
};
|
|
65
65
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
66
|
exports.snapshot = snapshot;
|
|
67
67
|
exports.mintStakeLp = mintStakeLp;
|
|
@@ -95,17 +95,28 @@ 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,
|
|
99
|
-
var
|
|
100
|
-
return __generator(this, function (
|
|
101
|
-
switch (
|
|
98
|
+
var tokens, cToken, coin, suiCoin, tokens_1, tokens_1_1, token, lpCoin;
|
|
99
|
+
var _a, e_1, _b;
|
|
100
|
+
return __generator(this, function (_c) {
|
|
101
|
+
switch (_c.label) {
|
|
102
102
|
case 0:
|
|
103
103
|
tokens = input.lpPool.tokenPools.map(function (p) { return (0, constants_1.typeArgToAsset)("0x" + p.tokenType.name); });
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
cToken = constants_1.tokenType[__1.NETWORK][input.cTOKEN];
|
|
105
|
+
if (input.cTOKEN == constants_1.tokenType.MAINNET.SUI && config.sponsored) {
|
|
106
|
+
// split together
|
|
107
|
+
_a = __read((0, utils_1.splitCoins)(tx, constants_1.tokenType.MAINNET.SUI, input.coins, [input.amount, tokens.length.toString()], config.sponsored), 2), coin = _a[0], suiCoin = _a[1];
|
|
108
|
+
}
|
|
109
|
+
else if (config.sponsored) {
|
|
110
|
+
coin = (0, utils_1.splitCoin)(tx, cToken, input.coins, input.amount, config.sponsored);
|
|
111
|
+
suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), config.sponsored);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
coin = (0, utils_1.splitCoin)(tx, cToken, input.coins, input.amount, config.sponsored);
|
|
115
|
+
// no suiCoin
|
|
116
|
+
}
|
|
117
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens, suiCoin)];
|
|
106
118
|
case 1:
|
|
107
|
-
|
|
108
|
-
_d.sent();
|
|
119
|
+
_c.sent();
|
|
109
120
|
try {
|
|
110
121
|
for (tokens_1 = __values(tokens), tokens_1_1 = tokens_1.next(); !tokens_1_1.done; tokens_1_1 = tokens_1.next()) {
|
|
111
122
|
token = tokens_1_1.value;
|
|
@@ -122,25 +133,14 @@ function mintStakeLp(config, tx, pythClient, input) {
|
|
|
122
133
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
123
134
|
finally {
|
|
124
135
|
try {
|
|
125
|
-
if (tokens_1_1 && !tokens_1_1.done && (
|
|
136
|
+
if (tokens_1_1 && !tokens_1_1.done && (_b = tokens_1.return)) _b.call(tokens_1);
|
|
126
137
|
}
|
|
127
138
|
finally { if (e_1) throw e_1.error; }
|
|
128
139
|
}
|
|
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
|
-
}
|
|
139
140
|
// console.log(iToken);
|
|
140
141
|
if (input.userShareId) {
|
|
141
142
|
harvestStakeReward(config, tx, { stakePool: input.stakePool, userShareId: input.userShareId, user: input.user });
|
|
142
143
|
}
|
|
143
|
-
cToken = constants_1.tokenType[__1.NETWORK][input.cTOKEN];
|
|
144
144
|
lpCoin = (0, functions_1.mintLp)(tx, [cToken, __1.TLP_TOKEN], {
|
|
145
145
|
version: __1.PERP_VERSION,
|
|
146
146
|
registry: __1.LP_POOL,
|
|
@@ -221,13 +221,16 @@ function unstake(config, tx, input) {
|
|
|
221
221
|
}
|
|
222
222
|
function unstakeRedeem(config, tx, pythClient, input) {
|
|
223
223
|
return __awaiter(this, void 0, void 0, function () {
|
|
224
|
-
var tokens, tokens_2, tokens_2_1, token, lpCoin, balance;
|
|
224
|
+
var tokens, suiCoin, tokens_2, tokens_2_1, token, lpCoin, balance;
|
|
225
225
|
var e_2, _a;
|
|
226
226
|
return __generator(this, function (_b) {
|
|
227
227
|
switch (_b.label) {
|
|
228
228
|
case 0:
|
|
229
229
|
tokens = input.lpPool.tokenPools.map(function (p) { return (0, constants_1.typeArgToAsset)("0x" + p.tokenType.name); });
|
|
230
|
-
|
|
230
|
+
if (config.sponsored) {
|
|
231
|
+
suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), config.sponsored);
|
|
232
|
+
}
|
|
233
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens, suiCoin)];
|
|
231
234
|
case 1:
|
|
232
235
|
_b.sent();
|
|
233
236
|
try {
|
|
@@ -285,13 +288,16 @@ function unstakeRedeem(config, tx, pythClient, input) {
|
|
|
285
288
|
}
|
|
286
289
|
function redeemTlp(config, tx, pythClient, input) {
|
|
287
290
|
return __awaiter(this, void 0, void 0, function () {
|
|
288
|
-
var tokens, tokens_3, tokens_3_1, token, destination, lpCoin, burnCoin, balance;
|
|
291
|
+
var tokens, suiCoin, tokens_3, tokens_3_1, token, destination, lpCoin, burnCoin, balance;
|
|
289
292
|
var e_3, _a;
|
|
290
293
|
return __generator(this, function (_b) {
|
|
291
294
|
switch (_b.label) {
|
|
292
295
|
case 0:
|
|
293
296
|
tokens = input.lpPool.tokenPools.map(function (p) { return (0, constants_1.typeArgToAsset)("0x" + p.tokenType.name); });
|
|
294
|
-
|
|
297
|
+
if (config.sponsored) {
|
|
298
|
+
suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), config.sponsored);
|
|
299
|
+
}
|
|
300
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens, suiCoin)];
|
|
295
301
|
case 1:
|
|
296
302
|
_b.sent();
|
|
297
303
|
try {
|
|
@@ -344,13 +350,16 @@ function redeemTlp(config, tx, pythClient, input) {
|
|
|
344
350
|
}
|
|
345
351
|
function claim(config, tx, pythClient, input) {
|
|
346
352
|
return __awaiter(this, void 0, void 0, function () {
|
|
347
|
-
var tokens, tokens_4, tokens_4_1, token_1, cToken, token;
|
|
353
|
+
var tokens, suiCoin, tokens_4, tokens_4_1, token_1, cToken, token;
|
|
348
354
|
var e_4, _a;
|
|
349
355
|
return __generator(this, function (_b) {
|
|
350
356
|
switch (_b.label) {
|
|
351
357
|
case 0:
|
|
352
358
|
tokens = input.lpPool.tokenPools.map(function (p) { return (0, constants_1.typeArgToAsset)("0x" + p.tokenType.name); });
|
|
353
|
-
|
|
359
|
+
if (config.sponsored) {
|
|
360
|
+
suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, tokens.length.toString(), config.sponsored);
|
|
361
|
+
}
|
|
362
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens, suiCoin)];
|
|
354
363
|
case 1:
|
|
355
364
|
_b.sent();
|
|
356
365
|
try {
|
|
@@ -390,27 +399,30 @@ function claim(config, tx, pythClient, input) {
|
|
|
390
399
|
}
|
|
391
400
|
function swap(config, tx, pythClient, input) {
|
|
392
401
|
return __awaiter(this, void 0, void 0, function () {
|
|
393
|
-
var
|
|
394
|
-
var _a
|
|
395
|
-
return __generator(this, function (
|
|
396
|
-
switch (
|
|
397
|
-
case 0:
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
(
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
402
|
+
var fromToken, toToken, coin, suiCoin, token;
|
|
403
|
+
var _a;
|
|
404
|
+
return __generator(this, function (_b) {
|
|
405
|
+
switch (_b.label) {
|
|
406
|
+
case 0:
|
|
407
|
+
fromToken = constants_1.tokenType[__1.NETWORK][input.FROM_TOKEN];
|
|
408
|
+
toToken = constants_1.tokenType[__1.NETWORK][input.TO_TOKEN];
|
|
409
|
+
if (input.FROM_TOKEN == constants_1.tokenType.MAINNET.SUI && config.sponsored) {
|
|
410
|
+
// split together
|
|
411
|
+
_a = __read((0, utils_1.splitCoins)(tx, constants_1.tokenType.MAINNET.SUI, input.coins, [input.amount, "2"], config.sponsored), 2), coin = _a[0], suiCoin = _a[1];
|
|
412
|
+
}
|
|
413
|
+
else if (config.sponsored) {
|
|
414
|
+
coin = (0, utils_1.splitCoin)(tx, fromToken, input.coins, input.amount, config.sponsored);
|
|
415
|
+
suiCoin = (0, utils_1.splitCoin)(tx, constants_1.tokenType.MAINNET.SUI, input.suiCoins, "2", config.sponsored);
|
|
404
416
|
}
|
|
405
417
|
else {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
tx.mergeCoins(destination, input.coins);
|
|
409
|
-
}
|
|
410
|
-
_b = __read(tx.splitCoins(destination, [input.amount]), 1), coin = _b[0];
|
|
418
|
+
coin = (0, utils_1.splitCoin)(tx, fromToken, input.coins, input.amount, config.sponsored);
|
|
419
|
+
// no suiCoin
|
|
411
420
|
}
|
|
412
|
-
|
|
413
|
-
|
|
421
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, [input.FROM_TOKEN, input.TO_TOKEN], suiCoin)];
|
|
422
|
+
case 1:
|
|
423
|
+
_b.sent();
|
|
424
|
+
(0, utils_1.updateOracleWithPythUsd)(pythClient, tx, config.package.oracle, input.FROM_TOKEN);
|
|
425
|
+
(0, utils_1.updateOracleWithPythUsd)(pythClient, tx, config.package.oracle, input.TO_TOKEN);
|
|
414
426
|
token = (0, functions_1.swap)(tx, [fromToken, toToken], {
|
|
415
427
|
version: __1.PERP_VERSION,
|
|
416
428
|
registry: __1.LP_POOL,
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typus/typus-perp-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.85",
|
|
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.
|
|
9
|
+
"@typus/typus-sdk": "1.7.17"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@types/bs58": "^4.0.1",
|