@typus/typus-perp-sdk 1.0.21 → 1.0.23
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/api/sentio.js +1 -1
- package/dist/src/fetch.js +20 -27
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +16 -12
- package/dist/src/typus_perp/admin/structs.d.ts +5 -5
- package/dist/src/typus_perp/error/functions.d.ts +2 -2
- package/dist/src/typus_perp/error/functions.js +8 -8
- package/dist/src/typus_perp/escrow/structs.d.ts +1 -1
- package/dist/src/typus_perp/index.js +3 -3
- package/dist/src/typus_perp/init.js +0 -3
- package/dist/src/typus_perp/lp-pool/functions.d.ts +2 -10
- package/dist/src/typus_perp/lp-pool/functions.js +7 -27
- package/dist/src/typus_perp/lp-pool/structs.d.ts +26 -26
- package/dist/src/typus_perp/position/functions.d.ts +21 -6
- package/dist/src/typus_perp/position/functions.js +42 -6
- package/dist/src/typus_perp/position/structs.d.ts +6 -6
- package/dist/src/typus_perp/symbol/structs.d.ts +1 -1
- package/dist/src/typus_perp/tlp/structs.d.ts +2 -2
- package/dist/src/typus_perp/trading/functions.d.ts +50 -70
- package/dist/src/typus_perp/trading/functions.js +50 -70
- package/dist/src/typus_perp/trading/structs.d.ts +52 -30
- package/dist/src/typus_perp/trading/structs.js +6 -0
- package/dist/src/typus_perp/treasury-caps/structs.d.ts +1 -1
- package/dist/src/typus_stake_pool/admin/structs.d.ts +4 -4
- package/dist/src/typus_stake_pool/index.js +3 -3
- package/dist/src/typus_stake_pool/stake-pool/functions.d.ts +0 -1
- package/dist/src/typus_stake_pool/stake-pool/functions.js +0 -1
- package/dist/src/typus_stake_pool/stake-pool/structs.d.ts +22 -22
- package/dist/src/user/history.js +38 -20
- package/dist/src/user/order.js +87 -42
- package/dist/src/user/orderWithBidReceipt.js +58 -26
- package/dist/src/user/tlp.d.ts +4 -3
- package/dist/src/user/tlp.js +93 -60
- package/package.json +2 -2
- package/dist/src/typus_perp/oracle/functions.d.ts +0 -13
- package/dist/src/typus_perp/oracle/functions.js +0 -22
- package/dist/src/typus_perp/oracle/structs.d.ts +0 -111
- package/dist/src/typus_perp/oracle/structs.js +0 -389
|
@@ -35,6 +35,17 @@ 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
|
+
};
|
|
38
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
50
|
exports.createTradingOrderWithBidReceipt = createTradingOrderWithBidReceipt;
|
|
40
51
|
exports.reduceOptionCollateralPositionSize = reduceOptionCollateralPositionSize;
|
|
@@ -45,22 +56,30 @@ var typus_dov_single_v2_1 = require("@typus/typus-sdk/dist/src/typus-dov-single-
|
|
|
45
56
|
var __1 = require("..");
|
|
46
57
|
function createTradingOrderWithBidReceipt(config, tx, pythClient, input) {
|
|
47
58
|
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var TOKEN, BASE_TOKEN, cToken, bToken, baseToken
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
var TOKEN, BASE_TOKEN, tokens, tokens_1, tokens_1_1, token, collateralBidReceipt, cToken, bToken, baseToken;
|
|
60
|
+
var e_1, _a;
|
|
61
|
+
return __generator(this, function (_b) {
|
|
62
|
+
switch (_b.label) {
|
|
51
63
|
case 0:
|
|
52
64
|
TOKEN = input.cToken;
|
|
53
65
|
BASE_TOKEN = input.tradingToken;
|
|
54
|
-
|
|
55
|
-
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx,
|
|
66
|
+
tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
|
|
67
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens)];
|
|
56
68
|
case 1:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
_b.sent();
|
|
70
|
+
try {
|
|
71
|
+
for (tokens_1 = __values(tokens), tokens_1_1 = tokens_1.next(); !tokens_1_1.done; tokens_1_1 = tokens_1.next()) {
|
|
72
|
+
token = tokens_1_1.value;
|
|
73
|
+
(0, utils_1.updateOracleWithPythUsd)(pythClient, tx, config.package.oracle, token);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
77
|
+
finally {
|
|
78
|
+
try {
|
|
79
|
+
if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
|
|
80
|
+
}
|
|
81
|
+
finally { if (e_1) throw e_1.error; }
|
|
82
|
+
}
|
|
64
83
|
if (input.share) {
|
|
65
84
|
collateralBidReceipt = (0, typus_dov_single_v2_1.getSplitBidReceiptTx)(config, tx, {
|
|
66
85
|
index: input.index,
|
|
@@ -72,22 +91,23 @@ function createTradingOrderWithBidReceipt(config, tx, pythClient, input) {
|
|
|
72
91
|
else {
|
|
73
92
|
collateralBidReceipt = input.bidReceipt;
|
|
74
93
|
}
|
|
94
|
+
cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
95
|
+
bToken = constants_1.tokenType[__1.NETWORK][input.bToken];
|
|
96
|
+
baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
|
|
75
97
|
(0, functions_1.createTradingOrderWithBidReceipt)(tx, [cToken, bToken, baseToken], {
|
|
76
98
|
version: __1.PERP_VERSION,
|
|
77
99
|
registry: __1.MARKET,
|
|
78
100
|
poolRegistry: __1.LP_POOL,
|
|
79
101
|
marketIndex: BigInt(0),
|
|
80
102
|
poolIndex: BigInt(0),
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
oracleTradingSymbol: utils_1.priceInfoObjectIds[__1.NETWORK][BASE_TOKEN],
|
|
103
|
+
typusOracleCToken: constants_1.oracle[__1.NETWORK][TOKEN],
|
|
104
|
+
typusOracleTradingSymbol: constants_1.oracle[__1.NETWORK][BASE_TOKEN],
|
|
84
105
|
clock: constants_1.CLOCK,
|
|
85
106
|
typusEcosystemVersion: config.version.typus,
|
|
86
107
|
typusUserRegistry: config.registry.typus.user,
|
|
87
108
|
typusLeaderboardRegistry: config.registry.typus.leaderboard,
|
|
88
109
|
isLong: input.isLong,
|
|
89
110
|
dovRegistry: config.registry.dov.dovSingle,
|
|
90
|
-
typusOracle: config.oracle[BASE_TOKEN.toLocaleLowerCase()],
|
|
91
111
|
collateralBidReceipt: collateralBidReceipt,
|
|
92
112
|
user: input.user,
|
|
93
113
|
});
|
|
@@ -98,34 +118,46 @@ function createTradingOrderWithBidReceipt(config, tx, pythClient, input) {
|
|
|
98
118
|
}
|
|
99
119
|
function reduceOptionCollateralPositionSize(config, tx, pythClient, input) {
|
|
100
120
|
return __awaiter(this, void 0, void 0, function () {
|
|
101
|
-
var TOKEN, BASE_TOKEN, cToken, bToken, baseToken;
|
|
102
|
-
|
|
103
|
-
|
|
121
|
+
var TOKEN, BASE_TOKEN, tokens, tokens_2, tokens_2_1, token, cToken, bToken, baseToken;
|
|
122
|
+
var e_2, _a;
|
|
123
|
+
return __generator(this, function (_b) {
|
|
124
|
+
switch (_b.label) {
|
|
104
125
|
case 0:
|
|
105
126
|
TOKEN = input.cToken;
|
|
106
127
|
BASE_TOKEN = input.tradingToken;
|
|
107
|
-
|
|
128
|
+
tokens = Array.from(new Set([TOKEN, BASE_TOKEN]));
|
|
129
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens)];
|
|
108
130
|
case 1:
|
|
109
|
-
|
|
131
|
+
_b.sent();
|
|
132
|
+
try {
|
|
133
|
+
for (tokens_2 = __values(tokens), tokens_2_1 = tokens_2.next(); !tokens_2_1.done; tokens_2_1 = tokens_2.next()) {
|
|
134
|
+
token = tokens_2_1.value;
|
|
135
|
+
(0, utils_1.updateOracleWithPythUsd)(pythClient, tx, config.package.oracle, token);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
139
|
+
finally {
|
|
140
|
+
try {
|
|
141
|
+
if (tokens_2_1 && !tokens_2_1.done && (_a = tokens_2.return)) _a.call(tokens_2);
|
|
142
|
+
}
|
|
143
|
+
finally { if (e_2) throw e_2.error; }
|
|
144
|
+
}
|
|
110
145
|
cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
111
146
|
bToken = constants_1.tokenType[__1.NETWORK][input.bToken];
|
|
112
147
|
baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
|
|
113
|
-
(0, utils_1.updateOracleWithPyth)(pythClient, tx, config.package.oracle, config.oracle[BASE_TOKEN.toLocaleLowerCase()], BASE_TOKEN, "wUSDC");
|
|
114
148
|
(0, functions_1.reduceOptionCollateralPositionSize)(tx, [cToken, bToken, baseToken], {
|
|
115
149
|
version: __1.PERP_VERSION,
|
|
116
150
|
registry: __1.MARKET,
|
|
117
151
|
poolRegistry: __1.LP_POOL,
|
|
118
152
|
marketIndex: BigInt(0),
|
|
119
153
|
poolIndex: BigInt(0),
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
oracleTradingSymbol: utils_1.priceInfoObjectIds[__1.NETWORK][BASE_TOKEN],
|
|
154
|
+
typusOracleCToken: constants_1.oracle[__1.NETWORK][TOKEN],
|
|
155
|
+
typusOracleTradingSymbol: constants_1.oracle[__1.NETWORK][BASE_TOKEN],
|
|
123
156
|
clock: constants_1.CLOCK,
|
|
124
157
|
typusEcosystemVersion: config.version.typus,
|
|
125
158
|
typusUserRegistry: config.registry.typus.user,
|
|
126
159
|
typusLeaderboardRegistry: config.registry.typus.leaderboard,
|
|
127
160
|
dovRegistry: config.registry.dov.dovSingle,
|
|
128
|
-
typusOracle: config.oracle[BASE_TOKEN.toLocaleLowerCase()],
|
|
129
161
|
positionId: BigInt(input.positionId),
|
|
130
162
|
orderSize: input.orderSize ? BigInt(input.orderSize) : null,
|
|
131
163
|
});
|
package/dist/src/user/tlp.d.ts
CHANGED
|
@@ -2,19 +2,20 @@ import { Transaction } from "@mysten/sui/transactions";
|
|
|
2
2
|
import { LiquidityPool } from "../typus_perp/lp-pool/structs";
|
|
3
3
|
import { PythClient, TypusConfig } from "@typus/typus-sdk/dist/src/utils";
|
|
4
4
|
import { TOKEN } from "@typus/typus-sdk/dist/src/constants";
|
|
5
|
+
import { StakePool } from "../../src/typus_stake_pool/stake-pool/structs";
|
|
5
6
|
export declare function mintStakeLp(config: TypusConfig, tx: Transaction, pythClient: PythClient, input: {
|
|
6
7
|
lpPool: LiquidityPool;
|
|
8
|
+
stakePool: StakePool;
|
|
7
9
|
coins: string[];
|
|
8
10
|
cTOKEN: TOKEN;
|
|
9
|
-
iTOKEN: TOKEN;
|
|
10
11
|
amount: string;
|
|
11
12
|
userShareId: string | null;
|
|
12
13
|
user: string;
|
|
13
14
|
}): Promise<Transaction>;
|
|
14
15
|
export declare function unstakeBurn(config: TypusConfig, tx: Transaction, pythClient: PythClient, input: {
|
|
15
16
|
lpPool: LiquidityPool;
|
|
17
|
+
stakePool: StakePool;
|
|
16
18
|
cTOKEN: TOKEN;
|
|
17
|
-
iTOKEN: TOKEN;
|
|
18
19
|
userShareId: string;
|
|
19
20
|
share: string | null;
|
|
20
21
|
user: string;
|
|
@@ -31,7 +32,7 @@ export declare function unsubscribe(config: TypusConfig, tx: Transaction, input:
|
|
|
31
32
|
share: string | null;
|
|
32
33
|
}): Promise<Transaction>;
|
|
33
34
|
export declare function harvestStakeReward(config: TypusConfig, tx: Transaction, input: {
|
|
35
|
+
stakePool: StakePool;
|
|
34
36
|
userShareId: string;
|
|
35
37
|
user: string;
|
|
36
|
-
iTOKEN: TOKEN;
|
|
37
38
|
}): Promise<Transaction>;
|
package/dist/src/user/tlp.js
CHANGED
|
@@ -75,27 +75,26 @@ var constants_1 = require("@typus/typus-sdk/dist/src/constants");
|
|
|
75
75
|
var __1 = require("..");
|
|
76
76
|
function mintStakeLp(config, tx, pythClient, input) {
|
|
77
77
|
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
-
var tokens,
|
|
79
|
-
var e_1, _a, _b, _c;
|
|
80
|
-
return __generator(this, function (
|
|
81
|
-
switch (
|
|
78
|
+
var tokens, tokens_1, tokens_1_1, token, coin, destination, iTokens, iTokens_1, iTokens_1_1, iToken, iCoin, cToken, lpCoin;
|
|
79
|
+
var e_1, _a, _b, _c, e_2, _d;
|
|
80
|
+
return __generator(this, function (_e) {
|
|
81
|
+
switch (_e.label) {
|
|
82
82
|
case 0:
|
|
83
83
|
tokens = input.lpPool.tokenPools.map(function (p) { return (0, constants_1.typeArgToAsset)("0x" + p.tokenType.name); });
|
|
84
84
|
// console.log("tokens", tokens);
|
|
85
85
|
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens)];
|
|
86
86
|
case 1:
|
|
87
87
|
// console.log("tokens", tokens);
|
|
88
|
-
|
|
89
|
-
cToken = constants_1.tokenType[__1.NETWORK][input.cTOKEN];
|
|
88
|
+
_e.sent();
|
|
90
89
|
try {
|
|
91
90
|
for (tokens_1 = __values(tokens), tokens_1_1 = tokens_1.next(); !tokens_1_1.done; tokens_1_1 = tokens_1.next()) {
|
|
92
91
|
token = tokens_1_1.value;
|
|
92
|
+
(0, utils_1.updateOracleWithPythUsd)(pythClient, tx, config.package.oracle, token);
|
|
93
93
|
(0, functions_1.updateLiquidityValue)(tx, constants_1.tokenType[__1.NETWORK][token], {
|
|
94
94
|
version: __1.PERP_VERSION,
|
|
95
95
|
registry: __1.LP_POOL,
|
|
96
96
|
index: BigInt(0),
|
|
97
|
-
|
|
98
|
-
oracle: utils_1.priceInfoObjectIds[__1.NETWORK][token],
|
|
97
|
+
oracle: constants_1.oracle[__1.NETWORK][token],
|
|
99
98
|
clock: constants_1.CLOCK,
|
|
100
99
|
});
|
|
101
100
|
}
|
|
@@ -117,25 +116,37 @@ function mintStakeLp(config, tx, pythClient, input) {
|
|
|
117
116
|
}
|
|
118
117
|
_c = __read(tx.splitCoins(destination, [input.amount]), 1), coin = _c[0];
|
|
119
118
|
}
|
|
120
|
-
iToken = constants_1.tokenType[__1.NETWORK][input.iTOKEN];
|
|
121
119
|
// console.log(iToken);
|
|
122
120
|
if (input.userShareId) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
121
|
+
iTokens = input.stakePool.incentives.map(function (i) { return i.tokenType.name; });
|
|
122
|
+
try {
|
|
123
|
+
for (iTokens_1 = __values(iTokens), iTokens_1_1 = iTokens_1.next(); !iTokens_1_1.done; iTokens_1_1 = iTokens_1.next()) {
|
|
124
|
+
iToken = iTokens_1_1.value;
|
|
125
|
+
iCoin = (0, functions_2.harvestPerUserShare)(tx, iToken, {
|
|
126
|
+
version: __1.STAKE_POOL_VERSION,
|
|
127
|
+
registry: __1.STAKE_POOL,
|
|
128
|
+
index: BigInt(0),
|
|
129
|
+
userShareId: BigInt(input.userShareId),
|
|
130
|
+
clock: constants_1.CLOCK,
|
|
131
|
+
});
|
|
132
|
+
tx.transferObjects([iCoin], input.user);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
136
|
+
finally {
|
|
137
|
+
try {
|
|
138
|
+
if (iTokens_1_1 && !iTokens_1_1.done && (_d = iTokens_1.return)) _d.call(iTokens_1);
|
|
139
|
+
}
|
|
140
|
+
finally { if (e_2) throw e_2.error; }
|
|
141
|
+
}
|
|
131
142
|
}
|
|
143
|
+
cToken = constants_1.tokenType[__1.NETWORK][input.cTOKEN];
|
|
132
144
|
lpCoin = (0, functions_1.mintLp)(tx, [cToken, __1.TLP_TOKEN], {
|
|
133
145
|
version: __1.PERP_VERSION,
|
|
134
146
|
registry: __1.LP_POOL,
|
|
135
147
|
treasuryCaps: __1.TLP_TREASURY_CAP,
|
|
136
148
|
index: BigInt(0),
|
|
137
|
-
|
|
138
|
-
oracle: utils_1.priceInfoObjectIds[__1.NETWORK][input.cTOKEN],
|
|
149
|
+
oracle: constants_1.oracle[__1.NETWORK][input.cTOKEN],
|
|
139
150
|
coin: coin,
|
|
140
151
|
clock: constants_1.CLOCK,
|
|
141
152
|
});
|
|
@@ -154,48 +165,57 @@ function mintStakeLp(config, tx, pythClient, input) {
|
|
|
154
165
|
}
|
|
155
166
|
function unstakeBurn(config, tx, pythClient, input) {
|
|
156
167
|
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
-
var tokens,
|
|
158
|
-
var
|
|
159
|
-
return __generator(this, function (
|
|
160
|
-
switch (
|
|
168
|
+
var tokens, tokens_2, tokens_2_1, token, iTokens, iTokens_2, iTokens_2_1, iToken, iCoin, lpCoin, cToken, coin;
|
|
169
|
+
var e_3, _a, e_4, _b;
|
|
170
|
+
return __generator(this, function (_c) {
|
|
171
|
+
switch (_c.label) {
|
|
161
172
|
case 0:
|
|
162
173
|
tokens = input.lpPool.tokenPools.map(function (p) { return (0, constants_1.typeArgToAsset)("0x" + p.tokenType.name); });
|
|
163
174
|
return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, tokens)];
|
|
164
175
|
case 1:
|
|
165
|
-
|
|
166
|
-
cToken = constants_1.tokenType[__1.NETWORK][input.cTOKEN];
|
|
167
|
-
oracle = utils_1.priceInfoObjectIds[__1.NETWORK][input.cTOKEN];
|
|
176
|
+
_c.sent();
|
|
168
177
|
try {
|
|
169
178
|
for (tokens_2 = __values(tokens), tokens_2_1 = tokens_2.next(); !tokens_2_1.done; tokens_2_1 = tokens_2.next()) {
|
|
170
179
|
token = tokens_2_1.value;
|
|
180
|
+
(0, utils_1.updateOracleWithPythUsd)(pythClient, tx, config.package.oracle, token);
|
|
171
181
|
(0, functions_1.updateLiquidityValue)(tx, constants_1.tokenType[__1.NETWORK][token], {
|
|
172
182
|
version: __1.PERP_VERSION,
|
|
173
183
|
registry: __1.LP_POOL,
|
|
174
184
|
index: BigInt(0),
|
|
175
|
-
|
|
176
|
-
oracle: utils_1.priceInfoObjectIds[__1.NETWORK][token],
|
|
185
|
+
oracle: constants_1.oracle[__1.NETWORK][token],
|
|
177
186
|
clock: constants_1.CLOCK,
|
|
178
187
|
});
|
|
179
188
|
}
|
|
180
189
|
}
|
|
181
|
-
catch (
|
|
190
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
182
191
|
finally {
|
|
183
192
|
try {
|
|
184
193
|
if (tokens_2_1 && !tokens_2_1.done && (_a = tokens_2.return)) _a.call(tokens_2);
|
|
185
194
|
}
|
|
186
|
-
finally { if (
|
|
195
|
+
finally { if (e_3) throw e_3.error; }
|
|
187
196
|
}
|
|
188
|
-
iToken = constants_1.tokenType[__1.NETWORK][input.iTOKEN];
|
|
189
|
-
// console.log(iToken);
|
|
190
197
|
if (input.userShareId) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
198
|
+
iTokens = input.stakePool.incentives.map(function (i) { return i.tokenType.name; });
|
|
199
|
+
try {
|
|
200
|
+
for (iTokens_2 = __values(iTokens), iTokens_2_1 = iTokens_2.next(); !iTokens_2_1.done; iTokens_2_1 = iTokens_2.next()) {
|
|
201
|
+
iToken = iTokens_2_1.value;
|
|
202
|
+
iCoin = (0, functions_2.harvestPerUserShare)(tx, iToken, {
|
|
203
|
+
version: __1.STAKE_POOL_VERSION,
|
|
204
|
+
registry: __1.STAKE_POOL,
|
|
205
|
+
index: BigInt(0),
|
|
206
|
+
userShareId: BigInt(input.userShareId),
|
|
207
|
+
clock: constants_1.CLOCK,
|
|
208
|
+
});
|
|
209
|
+
tx.transferObjects([iCoin], input.user);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
213
|
+
finally {
|
|
214
|
+
try {
|
|
215
|
+
if (iTokens_2_1 && !iTokens_2_1.done && (_b = iTokens_2.return)) _b.call(iTokens_2);
|
|
216
|
+
}
|
|
217
|
+
finally { if (e_4) throw e_4.error; }
|
|
218
|
+
}
|
|
199
219
|
}
|
|
200
220
|
lpCoin = (0, functions_2.unstake)(tx, __1.TLP_TOKEN, {
|
|
201
221
|
version: __1.STAKE_POOL_VERSION,
|
|
@@ -203,15 +223,14 @@ function unstakeBurn(config, tx, pythClient, input) {
|
|
|
203
223
|
index: BigInt(0),
|
|
204
224
|
userShareId: BigInt(input.userShareId),
|
|
205
225
|
clock: constants_1.CLOCK,
|
|
206
|
-
unstakedShares: input.share ? BigInt(input.share) : null,
|
|
207
226
|
});
|
|
227
|
+
cToken = constants_1.tokenType[__1.NETWORK][input.cTOKEN];
|
|
208
228
|
coin = (0, functions_1.burnLp)(tx, [cToken, __1.TLP_TOKEN], {
|
|
209
229
|
version: __1.PERP_VERSION,
|
|
210
230
|
registry: __1.LP_POOL,
|
|
211
231
|
treasuryCaps: __1.TLP_TREASURY_CAP,
|
|
212
232
|
index: BigInt(0),
|
|
213
|
-
|
|
214
|
-
oracle: oracle,
|
|
233
|
+
oracle: constants_1.oracle[__1.NETWORK][input.cTOKEN],
|
|
215
234
|
coin: lpCoin,
|
|
216
235
|
clock: constants_1.CLOCK,
|
|
217
236
|
});
|
|
@@ -223,15 +242,15 @@ function unstakeBurn(config, tx, pythClient, input) {
|
|
|
223
242
|
}
|
|
224
243
|
function swap(config, tx, pythClient, input) {
|
|
225
244
|
return __awaiter(this, void 0, void 0, function () {
|
|
226
|
-
var
|
|
245
|
+
var coin, destination, fromToken, toToken, token;
|
|
227
246
|
var _a, _b;
|
|
228
247
|
return __generator(this, function (_c) {
|
|
229
248
|
switch (_c.label) {
|
|
230
249
|
case 0: return [4 /*yield*/, (0, utils_1.updatePyth)(pythClient, tx, [input.FROM_TOKEN, input.TO_TOKEN])];
|
|
231
250
|
case 1:
|
|
232
251
|
_c.sent();
|
|
233
|
-
|
|
234
|
-
|
|
252
|
+
(0, utils_1.updateOracleWithPythUsd)(pythClient, tx, config.package.oracle, input.FROM_TOKEN);
|
|
253
|
+
(0, utils_1.updateOracleWithPythUsd)(pythClient, tx, config.package.oracle, input.TO_TOKEN);
|
|
235
254
|
if (input.FROM_TOKEN == "SUI") {
|
|
236
255
|
_a = __read(tx.splitCoins(tx.gas, [input.amount]), 1), coin = _a[0];
|
|
237
256
|
}
|
|
@@ -242,14 +261,15 @@ function swap(config, tx, pythClient, input) {
|
|
|
242
261
|
}
|
|
243
262
|
_b = __read(tx.splitCoins(destination, [input.amount]), 1), coin = _b[0];
|
|
244
263
|
}
|
|
264
|
+
fromToken = constants_1.tokenType[__1.NETWORK][input.FROM_TOKEN];
|
|
265
|
+
toToken = constants_1.tokenType[__1.NETWORK][input.TO_TOKEN];
|
|
245
266
|
token = (0, functions_1.swap)(tx, [fromToken, toToken], {
|
|
246
267
|
version: __1.PERP_VERSION,
|
|
247
268
|
registry: __1.LP_POOL,
|
|
248
|
-
pythState: utils_1.pythStateId[__1.NETWORK],
|
|
249
269
|
clock: constants_1.CLOCK,
|
|
250
270
|
index: BigInt(0),
|
|
251
|
-
oracleFromToken:
|
|
252
|
-
oracleToToken:
|
|
271
|
+
oracleFromToken: constants_1.oracle[__1.NETWORK][input.FROM_TOKEN],
|
|
272
|
+
oracleToToken: constants_1.oracle[__1.NETWORK][input.TO_TOKEN],
|
|
253
273
|
fromCoin: coin,
|
|
254
274
|
minToAmount: BigInt(0),
|
|
255
275
|
});
|
|
@@ -276,17 +296,30 @@ function unsubscribe(config, tx, input) {
|
|
|
276
296
|
}
|
|
277
297
|
function harvestStakeReward(config, tx, input) {
|
|
278
298
|
return __awaiter(this, void 0, void 0, function () {
|
|
279
|
-
var iToken, iCoin;
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
299
|
+
var iTokens, iTokens_3, iTokens_3_1, iToken, iCoin;
|
|
300
|
+
var e_5, _a;
|
|
301
|
+
return __generator(this, function (_b) {
|
|
302
|
+
iTokens = input.stakePool.incentives.map(function (i) { return i.tokenType.name; });
|
|
303
|
+
try {
|
|
304
|
+
for (iTokens_3 = __values(iTokens), iTokens_3_1 = iTokens_3.next(); !iTokens_3_1.done; iTokens_3_1 = iTokens_3.next()) {
|
|
305
|
+
iToken = iTokens_3_1.value;
|
|
306
|
+
iCoin = (0, functions_2.harvestPerUserShare)(tx, iToken, {
|
|
307
|
+
version: __1.STAKE_POOL_VERSION,
|
|
308
|
+
registry: __1.STAKE_POOL,
|
|
309
|
+
index: BigInt(0),
|
|
310
|
+
userShareId: BigInt(input.userShareId),
|
|
311
|
+
clock: constants_1.CLOCK,
|
|
312
|
+
});
|
|
313
|
+
tx.transferObjects([iCoin], input.user);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
317
|
+
finally {
|
|
318
|
+
try {
|
|
319
|
+
if (iTokens_3_1 && !iTokens_3_1.done && (_a = iTokens_3.return)) _a.call(iTokens_3);
|
|
320
|
+
}
|
|
321
|
+
finally { if (e_5) throw e_5.error; }
|
|
322
|
+
}
|
|
290
323
|
return [2 /*return*/, tx];
|
|
291
324
|
});
|
|
292
325
|
});
|
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.23",
|
|
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.
|
|
9
|
+
"@typus/typus-sdk": "1.6.4-tk7"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@types/bs58": "^4.0.1",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Transaction, TransactionArgument, TransactionObjectInput } from "@mysten/sui/transactions";
|
|
2
|
-
export interface GetPriceArgs {
|
|
3
|
-
state: TransactionObjectInput;
|
|
4
|
-
priceInfoObject: TransactionObjectInput;
|
|
5
|
-
clock: TransactionObjectInput;
|
|
6
|
-
}
|
|
7
|
-
export declare function getPrice(tx: Transaction, args: GetPriceArgs): import("@mysten/sui/transactions").TransactionResult;
|
|
8
|
-
export declare function getEmaPrice(tx: Transaction, priceInfoObject: TransactionObjectInput): import("@mysten/sui/transactions").TransactionResult;
|
|
9
|
-
export interface GetPriceInfoObjectIdArgs {
|
|
10
|
-
state: TransactionObjectInput;
|
|
11
|
-
priceIdentifierBytes: Array<number | TransactionArgument> | TransactionArgument;
|
|
12
|
-
}
|
|
13
|
-
export declare function getPriceInfoObjectId(tx: Transaction, args: GetPriceInfoObjectIdArgs): import("@mysten/sui/transactions").TransactionResult;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPrice = getPrice;
|
|
4
|
-
exports.getEmaPrice = getEmaPrice;
|
|
5
|
-
exports.getPriceInfoObjectId = getPriceInfoObjectId;
|
|
6
|
-
var __1 = require("..");
|
|
7
|
-
var util_1 = require("../../_framework/util");
|
|
8
|
-
function getPrice(tx, args) {
|
|
9
|
-
return tx.moveCall({
|
|
10
|
-
target: "".concat(__1.PUBLISHED_AT, "::oracle::get_price"),
|
|
11
|
-
arguments: [(0, util_1.obj)(tx, args.state), (0, util_1.obj)(tx, args.priceInfoObject), (0, util_1.obj)(tx, args.clock)],
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
function getEmaPrice(tx, priceInfoObject) {
|
|
15
|
-
return tx.moveCall({ target: "".concat(__1.PUBLISHED_AT, "::oracle::get_ema_price"), arguments: [(0, util_1.obj)(tx, priceInfoObject)] });
|
|
16
|
-
}
|
|
17
|
-
function getPriceInfoObjectId(tx, args) {
|
|
18
|
-
return tx.moveCall({
|
|
19
|
-
target: "".concat(__1.PUBLISHED_AT, "::oracle::get_price_info_object_id"),
|
|
20
|
-
arguments: [(0, util_1.obj)(tx, args.state), (0, util_1.pure)(tx, args.priceIdentifierBytes, "vector<u8>")],
|
|
21
|
-
});
|
|
22
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { ID } from "../../_dependencies/source/0x2/object/structs";
|
|
2
|
-
import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from "../../_framework/reified";
|
|
3
|
-
import { FieldsWithTypes } from "../../_framework/util";
|
|
4
|
-
import { PKG_V1 } from "../index";
|
|
5
|
-
import { SuiClient, SuiObjectData, SuiParsedData } from "@mysten/sui/client";
|
|
6
|
-
export declare function isPythPrice(type: string): boolean;
|
|
7
|
-
export interface PythPriceFields {
|
|
8
|
-
price: ToField<"u64">;
|
|
9
|
-
conf: ToField<"u64">;
|
|
10
|
-
timestamp: ToField<"u64">;
|
|
11
|
-
decimal: ToField<"u64">;
|
|
12
|
-
}
|
|
13
|
-
export type PythPriceReified = Reified<PythPrice, PythPriceFields>;
|
|
14
|
-
export declare class PythPrice implements StructClass {
|
|
15
|
-
__StructClass: true;
|
|
16
|
-
static readonly $typeName: string;
|
|
17
|
-
static readonly $numTypeParams = 0;
|
|
18
|
-
static readonly $isPhantom: readonly [];
|
|
19
|
-
readonly $typeName: string;
|
|
20
|
-
readonly $fullTypeName: `${typeof PKG_V1}::oracle::PythPrice`;
|
|
21
|
-
readonly $typeArgs: [];
|
|
22
|
-
readonly $isPhantom: readonly [];
|
|
23
|
-
readonly price: ToField<"u64">;
|
|
24
|
-
readonly conf: ToField<"u64">;
|
|
25
|
-
readonly timestamp: ToField<"u64">;
|
|
26
|
-
readonly decimal: ToField<"u64">;
|
|
27
|
-
private constructor();
|
|
28
|
-
static reified(): PythPriceReified;
|
|
29
|
-
static get r(): import("../../_framework/reified").StructClassReified<PythPrice, PythPriceFields>;
|
|
30
|
-
static phantom(): PhantomReified<ToTypeStr<PythPrice>>;
|
|
31
|
-
static get p(): PhantomReified<"::oracle::PythPrice" | "0x7c19f81d9d411e78305d7af8dad25317c56bb449fede8a78b6021232478f0509::oracle::PythPrice">;
|
|
32
|
-
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
33
|
-
price: string;
|
|
34
|
-
conf: string;
|
|
35
|
-
timestamp: string;
|
|
36
|
-
decimal: string;
|
|
37
|
-
}, {
|
|
38
|
-
price: string | number | bigint;
|
|
39
|
-
conf: string | number | bigint;
|
|
40
|
-
timestamp: string | number | bigint;
|
|
41
|
-
decimal: string | number | bigint;
|
|
42
|
-
}>;
|
|
43
|
-
static fromFields(fields: Record<string, any>): PythPrice;
|
|
44
|
-
static fromFieldsWithTypes(item: FieldsWithTypes): PythPrice;
|
|
45
|
-
static fromBcs(data: Uint8Array): PythPrice;
|
|
46
|
-
toJSONField(): {
|
|
47
|
-
price: string;
|
|
48
|
-
conf: string;
|
|
49
|
-
timestamp: string;
|
|
50
|
-
decimal: string;
|
|
51
|
-
};
|
|
52
|
-
toJSON(): {
|
|
53
|
-
price: string;
|
|
54
|
-
conf: string;
|
|
55
|
-
timestamp: string;
|
|
56
|
-
decimal: string;
|
|
57
|
-
$typeName: string;
|
|
58
|
-
$typeArgs: [];
|
|
59
|
-
};
|
|
60
|
-
static fromJSONField(field: any): PythPrice;
|
|
61
|
-
static fromJSON(json: Record<string, any>): PythPrice;
|
|
62
|
-
static fromSuiParsedData(content: SuiParsedData): PythPrice;
|
|
63
|
-
static fromSuiObjectData(data: SuiObjectData): PythPrice;
|
|
64
|
-
static fetch(client: SuiClient, id: string): Promise<PythPrice>;
|
|
65
|
-
}
|
|
66
|
-
export declare function isPythPriceInfoObject(type: string): boolean;
|
|
67
|
-
export interface PythPriceInfoObjectFields {
|
|
68
|
-
id: ToField<ID>;
|
|
69
|
-
}
|
|
70
|
-
export type PythPriceInfoObjectReified = Reified<PythPriceInfoObject, PythPriceInfoObjectFields>;
|
|
71
|
-
export declare class PythPriceInfoObject implements StructClass {
|
|
72
|
-
__StructClass: true;
|
|
73
|
-
static readonly $typeName: string;
|
|
74
|
-
static readonly $numTypeParams = 0;
|
|
75
|
-
static readonly $isPhantom: readonly [];
|
|
76
|
-
readonly $typeName: string;
|
|
77
|
-
readonly $fullTypeName: `${typeof PKG_V1}::oracle::PythPriceInfoObject`;
|
|
78
|
-
readonly $typeArgs: [];
|
|
79
|
-
readonly $isPhantom: readonly [];
|
|
80
|
-
readonly id: ToField<ID>;
|
|
81
|
-
private constructor();
|
|
82
|
-
static reified(): PythPriceInfoObjectReified;
|
|
83
|
-
static get r(): import("../../_framework/reified").StructClassReified<PythPriceInfoObject, PythPriceInfoObjectFields>;
|
|
84
|
-
static phantom(): PhantomReified<ToTypeStr<PythPriceInfoObject>>;
|
|
85
|
-
static get p(): PhantomReified<"::oracle::PythPriceInfoObject" | "0x7c19f81d9d411e78305d7af8dad25317c56bb449fede8a78b6021232478f0509::oracle::PythPriceInfoObject">;
|
|
86
|
-
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
87
|
-
id: {
|
|
88
|
-
bytes: string;
|
|
89
|
-
};
|
|
90
|
-
}, {
|
|
91
|
-
id: {
|
|
92
|
-
bytes: string;
|
|
93
|
-
};
|
|
94
|
-
}>;
|
|
95
|
-
static fromFields(fields: Record<string, any>): PythPriceInfoObject;
|
|
96
|
-
static fromFieldsWithTypes(item: FieldsWithTypes): PythPriceInfoObject;
|
|
97
|
-
static fromBcs(data: Uint8Array): PythPriceInfoObject;
|
|
98
|
-
toJSONField(): {
|
|
99
|
-
id: string;
|
|
100
|
-
};
|
|
101
|
-
toJSON(): {
|
|
102
|
-
id: string;
|
|
103
|
-
$typeName: string;
|
|
104
|
-
$typeArgs: [];
|
|
105
|
-
};
|
|
106
|
-
static fromJSONField(field: any): PythPriceInfoObject;
|
|
107
|
-
static fromJSON(json: Record<string, any>): PythPriceInfoObject;
|
|
108
|
-
static fromSuiParsedData(content: SuiParsedData): PythPriceInfoObject;
|
|
109
|
-
static fromSuiObjectData(data: SuiObjectData): PythPriceInfoObject;
|
|
110
|
-
static fetch(client: SuiClient, id: string): Promise<PythPriceInfoObject>;
|
|
111
|
-
}
|