@typus/typus-perp-sdk 1.0.4 → 1.0.5
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/fetch.js +12 -12
- package/dist/src/index.d.ts +0 -8
- package/dist/src/index.js +2 -12
- package/dist/src/user/order.js +11 -11
- package/dist/src/user/orderWithBidReceipt.js +6 -6
- package/dist/src/user/tlp.js +18 -18
- package/package.json +1 -1
package/dist/src/fetch.js
CHANGED
|
@@ -78,7 +78,7 @@ function getLpPools(config) {
|
|
|
78
78
|
case 0:
|
|
79
79
|
provider = new client_1.SuiClient({ url: config.rpcEndpoint });
|
|
80
80
|
return [4 /*yield*/, provider.getDynamicFields({
|
|
81
|
-
parentId:
|
|
81
|
+
parentId: config.registry.perp.liquidityPool,
|
|
82
82
|
})];
|
|
83
83
|
case 1:
|
|
84
84
|
dynamicFields = _d.sent();
|
|
@@ -125,7 +125,7 @@ function getStakePools(config) {
|
|
|
125
125
|
case 0:
|
|
126
126
|
provider = new client_1.SuiClient({ url: config.rpcEndpoint });
|
|
127
127
|
return [4 /*yield*/, provider.getDynamicFields({
|
|
128
|
-
parentId:
|
|
128
|
+
parentId: config.registry.perp.stakePool,
|
|
129
129
|
})];
|
|
130
130
|
case 1:
|
|
131
131
|
dynamicFields = _d.sent();
|
|
@@ -173,7 +173,7 @@ function getMarkets(config, input) {
|
|
|
173
173
|
transaction = new transactions_1.Transaction();
|
|
174
174
|
transaction.moveCall({
|
|
175
175
|
target: "".concat(typus_perp_1.PUBLISHED_AT, "::trading::get_markets_bcs"),
|
|
176
|
-
arguments: [transaction.object(
|
|
176
|
+
arguments: [transaction.object(config.registry.perp.market), transaction.pure.vector("u64", input.indexes)],
|
|
177
177
|
});
|
|
178
178
|
return [4 /*yield*/, provider.devInspectTransactionBlock({ sender: constants_1.SENDER, transactionBlock: transaction })];
|
|
179
179
|
case 1:
|
|
@@ -204,7 +204,7 @@ function getMarkets(config, input) {
|
|
|
204
204
|
}
|
|
205
205
|
// export async function getMarkets(config: TypusConfig): Promise<Markets[]> {
|
|
206
206
|
// let provider = new SuiClient({ url: config.rpcEndpoint });
|
|
207
|
-
// // const marketRegistry = await MarketRegistry.fetch(provider,
|
|
207
|
+
// // const marketRegistry = await MarketRegistry.fetch(provider, config.registry.perp.market);
|
|
208
208
|
// // console.log(marketRegistry.markets.vid);
|
|
209
209
|
// let dynamicFields = await provider.getDynamicFields({
|
|
210
210
|
// // @ts-ignore
|
|
@@ -242,8 +242,8 @@ function getUserOrders(config, user) {
|
|
|
242
242
|
provider = new client_1.SuiClient({ url: config.rpcEndpoint });
|
|
243
243
|
tx = new transactions_1.Transaction();
|
|
244
244
|
(0, functions_1.getUserOrders)(tx, {
|
|
245
|
-
version:
|
|
246
|
-
registry:
|
|
245
|
+
version: config.version.perp.perp,
|
|
246
|
+
registry: config.registry.perp.market,
|
|
247
247
|
marketIndex: BigInt(0),
|
|
248
248
|
user: user,
|
|
249
249
|
});
|
|
@@ -275,8 +275,8 @@ function getUserPositions(config, user) {
|
|
|
275
275
|
provider = new client_1.SuiClient({ url: config.rpcEndpoint });
|
|
276
276
|
tx = new transactions_1.Transaction();
|
|
277
277
|
(0, functions_1.getUserPositions)(tx, {
|
|
278
|
-
version:
|
|
279
|
-
registry:
|
|
278
|
+
version: config.version.perp.perp,
|
|
279
|
+
registry: config.registry.perp.market,
|
|
280
280
|
marketIndex: BigInt(0),
|
|
281
281
|
user: user,
|
|
282
282
|
});
|
|
@@ -320,7 +320,7 @@ function getUserStake(config, user) {
|
|
|
320
320
|
provider = new client_1.SuiClient({ url: config.rpcEndpoint });
|
|
321
321
|
tx = new transactions_1.Transaction();
|
|
322
322
|
(0, functions_2.getUserShares)(tx, {
|
|
323
|
-
registry:
|
|
323
|
+
registry: config.registry.perp.stakePool,
|
|
324
324
|
index: BigInt(0),
|
|
325
325
|
user: user,
|
|
326
326
|
});
|
|
@@ -388,9 +388,9 @@ function getLiquidationPrice(config, pythClient, input) {
|
|
|
388
388
|
TOKEN = (0, constants_1.typeArgToToken)(position.collateralToken.name);
|
|
389
389
|
BASE_TOKEN = (0, constants_1.typeArgToToken)(position.symbol.baseToken.name);
|
|
390
390
|
(0, functions_1.getEstimatedLiquidationPrice)(tx, [position.collateralToken.name, position.symbol.baseToken.name], {
|
|
391
|
-
version:
|
|
392
|
-
registry:
|
|
393
|
-
poolRegistry:
|
|
391
|
+
version: config.version.perp.perp,
|
|
392
|
+
registry: config.registry.perp.market,
|
|
393
|
+
poolRegistry: config.registry.perp.lpPool,
|
|
394
394
|
marketIndex: BigInt(0),
|
|
395
395
|
poolIndex: BigInt(0),
|
|
396
396
|
pythState: utils_1.pythStateId[_1.NETWORK],
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
1
|
export * from "./fetch";
|
|
2
2
|
export * from "./user";
|
|
3
3
|
export declare const NETWORK: string;
|
|
4
|
-
export declare const LP_POOL: string;
|
|
5
|
-
export declare const LIQUIDITY_POOL: string;
|
|
6
|
-
export declare const MARKET: string;
|
|
7
|
-
export declare const TLP: string;
|
|
8
|
-
export declare const TLP_TREASURY_CAP: string;
|
|
9
|
-
export declare const STAKE_POOL: string;
|
|
10
|
-
export declare const PERP_VERSION: string;
|
|
11
|
-
export declare const STAKE_POOL_VERSION: string;
|
package/dist/src/index.js
CHANGED
|
@@ -17,21 +17,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.NETWORK = void 0;
|
|
21
21
|
__exportStar(require("./fetch"), exports);
|
|
22
22
|
__exportStar(require("./user"), exports);
|
|
23
23
|
var dotenv_1 = __importDefault(require("dotenv"));
|
|
24
24
|
// import .env file if exists
|
|
25
25
|
dotenv_1.default.config();
|
|
26
|
-
exports.NETWORK = process.env.
|
|
27
|
-
console.log("Load .env NEXT_PUBLIC_CLUSTER: ".concat(process.env.NEXT_PUBLIC_CLUSTER));
|
|
26
|
+
exports.NETWORK = process.env.CLUSTER == "mainnet" ? "MAINNET" : "TESTNET";
|
|
28
27
|
console.log("Initializing Typus Perp SDK for ".concat(exports.NETWORK));
|
|
29
|
-
exports.LP_POOL = exports.NETWORK == "MAINNET" ? "" : "0xf85bb9b6bbe877e43e9a79f9c59d57331884f7519825f1116d8634806cd167e1";
|
|
30
|
-
exports.LIQUIDITY_POOL = exports.NETWORK == "MAINNET" ? "" : "0x93bc498e59e97c93820c14687a9a340bc794eada7f7ce0f458bb25190bdd395e";
|
|
31
|
-
exports.MARKET = exports.NETWORK == "MAINNET" ? "" : "0xb73983f279effad13b455846c192a2eb402ed453f84a1e627c9e34cfd329bf92";
|
|
32
|
-
exports.TLP = exports.NETWORK == "MAINNET" ? "" : "0x7c19f81d9d411e78305d7af8dad25317c56bb449fede8a78b6021232478f0509";
|
|
33
|
-
exports.TLP_TREASURY_CAP = exports.NETWORK == "MAINNET" ? "" : "0x7d9c6f9dfceb4788c21388f77e4ccf83e1b3f10282ae272b379402e92c97bbf6";
|
|
34
|
-
exports.STAKE_POOL = exports.NETWORK == "MAINNET" ? "" : "0x27efed0157eea40aa1a8483622edeb48ca8c3fa3073f9e662503280a22a4e51b";
|
|
35
|
-
exports.PERP_VERSION = exports.NETWORK == "MAINNET" ? "" : "0xa3066f440d0e2fa74b1c98e55c316ce63b208be87b018b089bf39d5dd11e8dfd";
|
|
36
|
-
exports.STAKE_POOL_VERSION = exports.NETWORK == "MAINNET" ? "" : "0x25868624d2254a14eb513ae2b276fb56ca355ffd6cdd8ee05c5a51620f3f1bf3";
|
|
37
|
-
// "TLP_TOKEN": "0x7c19f81d9d411e78305d7af8dad25317c56bb449fede8a78b6021232478f0509::tlp::TLP",
|
package/dist/src/user/order.js
CHANGED
|
@@ -85,9 +85,9 @@ function createTradingOrder(config, tx, pythClient, input) {
|
|
|
85
85
|
_b = __read(tx.splitCoins(destination, [input.amount]), 1), coin = _b[0];
|
|
86
86
|
}
|
|
87
87
|
(0, functions_1.createTradingOrder)(tx, [cToken, baseToken], {
|
|
88
|
-
version:
|
|
89
|
-
registry:
|
|
90
|
-
poolRegistry:
|
|
88
|
+
version: config.version.perp.perp,
|
|
89
|
+
registry: config.registry.perp.market,
|
|
90
|
+
poolRegistry: config.registry.perp.lpPool,
|
|
91
91
|
marketIndex: BigInt(0),
|
|
92
92
|
poolIndex: BigInt(0),
|
|
93
93
|
pythState: utils_1.pythStateId[__1.NETWORK],
|
|
@@ -117,8 +117,8 @@ function cancelTradingOrder(config, tx, input) {
|
|
|
117
117
|
cToken = "0x" + input.order.collateralToken.name;
|
|
118
118
|
BASE_TOKEN = "0x" + input.order.symbol.baseToken.name;
|
|
119
119
|
coin = (0, functions_1.cancelTradingOrder)(tx, [cToken, BASE_TOKEN], {
|
|
120
|
-
version:
|
|
121
|
-
registry:
|
|
120
|
+
version: config.version.perp.perp,
|
|
121
|
+
registry: config.registry.perp.market,
|
|
122
122
|
marketIndex: BigInt(0),
|
|
123
123
|
orderId: input.order.orderId,
|
|
124
124
|
triggerPrice: input.order.triggerPrice,
|
|
@@ -157,9 +157,9 @@ function increaseCollateral(config, tx, pythClient, input) {
|
|
|
157
157
|
_b = __read(tx.splitCoins(destination, [input.amount]), 1), coin = _b[0];
|
|
158
158
|
}
|
|
159
159
|
(0, functions_1.increaseCollateral)(tx, [cToken, baseToken], {
|
|
160
|
-
version:
|
|
161
|
-
registry:
|
|
162
|
-
poolRegistry:
|
|
160
|
+
version: config.version.perp.perp,
|
|
161
|
+
registry: config.registry.perp.market,
|
|
162
|
+
poolRegistry: config.registry.perp.lpPool,
|
|
163
163
|
marketIndex: BigInt(0),
|
|
164
164
|
poolIndex: BigInt(0),
|
|
165
165
|
pythState: utils_1.pythStateId[__1.NETWORK],
|
|
@@ -191,9 +191,9 @@ function releaseCollateral(config, tx, pythClient, input) {
|
|
|
191
191
|
cToken = constants_1.tokenType[__1.NETWORK][TOKEN];
|
|
192
192
|
baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
|
|
193
193
|
coin = (0, functions_1.releaseCollateral)(tx, [cToken, baseToken], {
|
|
194
|
-
version:
|
|
195
|
-
registry:
|
|
196
|
-
poolRegistry:
|
|
194
|
+
version: config.version.perp.perp,
|
|
195
|
+
registry: config.registry.perp.market,
|
|
196
|
+
poolRegistry: config.registry.perp.lpPool,
|
|
197
197
|
marketIndex: BigInt(0),
|
|
198
198
|
poolIndex: BigInt(0),
|
|
199
199
|
pythState: utils_1.pythStateId[__1.NETWORK],
|
|
@@ -70,9 +70,9 @@ function createTradingOrderWithBidReceipt(config, tx, pythClient, input) {
|
|
|
70
70
|
collateralBidReceipt = input.bidReceipt;
|
|
71
71
|
}
|
|
72
72
|
(0, functions_1.createTradingOrderWithBidReceipt)(tx, [cToken, bToken, baseToken], {
|
|
73
|
-
version:
|
|
74
|
-
registry:
|
|
75
|
-
poolRegistry:
|
|
73
|
+
version: config.version.perp.perp,
|
|
74
|
+
registry: config.registry.perp.market,
|
|
75
|
+
poolRegistry: config.registry.perp.lpPool,
|
|
76
76
|
marketIndex: BigInt(0),
|
|
77
77
|
poolIndex: BigInt(0),
|
|
78
78
|
pythState: utils_1.pythStateId[__1.NETWORK],
|
|
@@ -109,9 +109,9 @@ function reduceOptionCollateralPositionSize(config, tx, pythClient, input) {
|
|
|
109
109
|
baseToken = constants_1.tokenType[__1.NETWORK][BASE_TOKEN];
|
|
110
110
|
(0, utils_1.updateOracleWithPyth)(pythClient, tx, config.package.oracle, config.oracle[BASE_TOKEN.toLocaleLowerCase()], BASE_TOKEN, "USDC");
|
|
111
111
|
(0, functions_1.reduceOptionCollateralPositionSize)(tx, [cToken, bToken, baseToken], {
|
|
112
|
-
version:
|
|
113
|
-
registry:
|
|
114
|
-
poolRegistry:
|
|
112
|
+
version: config.version.perp.perp,
|
|
113
|
+
registry: config.registry.perp.market,
|
|
114
|
+
poolRegistry: config.registry.perp.lpPool,
|
|
115
115
|
marketIndex: BigInt(0),
|
|
116
116
|
poolIndex: BigInt(0),
|
|
117
117
|
pythState: utils_1.pythStateId[__1.NETWORK],
|
package/dist/src/user/tlp.js
CHANGED
|
@@ -91,8 +91,8 @@ function mintStakeLp(config, tx, pythClient, input) {
|
|
|
91
91
|
for (tokens_1 = __values(tokens), tokens_1_1 = tokens_1.next(); !tokens_1_1.done; tokens_1_1 = tokens_1.next()) {
|
|
92
92
|
token = tokens_1_1.value;
|
|
93
93
|
(0, functions_1.updateLiquidityValue)(tx, constants_1.tokenType[__1.NETWORK][token], {
|
|
94
|
-
version:
|
|
95
|
-
registry:
|
|
94
|
+
version: config.version.perp.perp,
|
|
95
|
+
registry: config.registry.perp.lpPool,
|
|
96
96
|
index: BigInt(0),
|
|
97
97
|
pythState: utils_1.pythStateId[__1.NETWORK],
|
|
98
98
|
oracle: utils_1.priceInfoObjectIds[__1.NETWORK][token],
|
|
@@ -118,8 +118,8 @@ function mintStakeLp(config, tx, pythClient, input) {
|
|
|
118
118
|
_c = __read(tx.splitCoins(destination, [input.amount]), 1), coin = _c[0];
|
|
119
119
|
}
|
|
120
120
|
lpCoin = (0, functions_1.mintLp)(tx, [cToken, config.token.tlp], {
|
|
121
|
-
version:
|
|
122
|
-
registry:
|
|
121
|
+
version: config.version.perp.perp,
|
|
122
|
+
registry: config.registry.perp.lpPool,
|
|
123
123
|
treasuryCaps: config.object.tlpTreasuryCap,
|
|
124
124
|
index: BigInt(0),
|
|
125
125
|
pythState: utils_1.pythStateId[__1.NETWORK],
|
|
@@ -128,8 +128,8 @@ function mintStakeLp(config, tx, pythClient, input) {
|
|
|
128
128
|
clock: constants_1.CLOCK,
|
|
129
129
|
});
|
|
130
130
|
(0, functions_2.stake)(tx, config.token.tlp, {
|
|
131
|
-
version:
|
|
132
|
-
registry:
|
|
131
|
+
version: config.version.perp.stakePool,
|
|
132
|
+
registry: config.registry.perp.stakePool,
|
|
133
133
|
index: BigInt(0),
|
|
134
134
|
lpToken: lpCoin,
|
|
135
135
|
clock: constants_1.CLOCK,
|
|
@@ -157,8 +157,8 @@ function unstakeBurn(config, tx, pythClient, input) {
|
|
|
157
157
|
for (tokens_2 = __values(tokens), tokens_2_1 = tokens_2.next(); !tokens_2_1.done; tokens_2_1 = tokens_2.next()) {
|
|
158
158
|
token = tokens_2_1.value;
|
|
159
159
|
(0, functions_1.updateLiquidityValue)(tx, constants_1.tokenType[__1.NETWORK][token], {
|
|
160
|
-
version:
|
|
161
|
-
registry:
|
|
160
|
+
version: config.version.perp.perp,
|
|
161
|
+
registry: config.registry.perp.lpPool,
|
|
162
162
|
index: BigInt(0),
|
|
163
163
|
pythState: utils_1.pythStateId[__1.NETWORK],
|
|
164
164
|
oracle: utils_1.priceInfoObjectIds[__1.NETWORK][token],
|
|
@@ -174,16 +174,16 @@ function unstakeBurn(config, tx, pythClient, input) {
|
|
|
174
174
|
finally { if (e_2) throw e_2.error; }
|
|
175
175
|
}
|
|
176
176
|
lpCoin = (0, functions_2.unstake)(tx, config.token.tlp, {
|
|
177
|
-
version:
|
|
178
|
-
registry:
|
|
177
|
+
version: config.version.perp.stakePool,
|
|
178
|
+
registry: config.registry.perp.stakePool,
|
|
179
179
|
index: BigInt(0),
|
|
180
180
|
userShareId: BigInt(input.userShareId),
|
|
181
181
|
clock: constants_1.CLOCK,
|
|
182
182
|
unstakedShares: input.share ? BigInt(input.share) : null,
|
|
183
183
|
});
|
|
184
184
|
coin = (0, functions_1.burnLp)(tx, [cToken, config.token.tlp], {
|
|
185
|
-
version:
|
|
186
|
-
registry:
|
|
185
|
+
version: config.version.perp.perp,
|
|
186
|
+
registry: config.registry.perp.lpPool,
|
|
187
187
|
treasuryCaps: config.object.tlpTreasuryCap,
|
|
188
188
|
index: BigInt(0),
|
|
189
189
|
pythState: utils_1.pythStateId[__1.NETWORK],
|
|
@@ -219,8 +219,8 @@ function swap(config, tx, pythClient, input) {
|
|
|
219
219
|
_b = __read(tx.splitCoins(destination, [input.amount]), 1), coin = _b[0];
|
|
220
220
|
}
|
|
221
221
|
token = (0, functions_1.swap)(tx, [fromToken, toToken], {
|
|
222
|
-
version:
|
|
223
|
-
registry:
|
|
222
|
+
version: config.version.perp.perp,
|
|
223
|
+
registry: config.registry.perp.lpPool,
|
|
224
224
|
pythState: utils_1.pythStateId[__1.NETWORK],
|
|
225
225
|
clock: constants_1.CLOCK,
|
|
226
226
|
index: BigInt(0),
|
|
@@ -239,8 +239,8 @@ function unsubscribe(config, tx, input) {
|
|
|
239
239
|
return __awaiter(this, void 0, void 0, function () {
|
|
240
240
|
return __generator(this, function (_a) {
|
|
241
241
|
(0, functions_2.unsubscribe)(tx, config.token.tlp, {
|
|
242
|
-
version:
|
|
243
|
-
registry:
|
|
242
|
+
version: config.version.perp.stakePool,
|
|
243
|
+
registry: config.registry.perp.stakePool,
|
|
244
244
|
index: BigInt(0),
|
|
245
245
|
userShareId: BigInt(input.userShareId),
|
|
246
246
|
clock: constants_1.CLOCK,
|
|
@@ -254,8 +254,8 @@ function harvest(config, tx, input) {
|
|
|
254
254
|
return __awaiter(this, void 0, void 0, function () {
|
|
255
255
|
return __generator(this, function (_a) {
|
|
256
256
|
(0, functions_2.harvestPerUserShare)(tx, "0x2::sui::SUI", {
|
|
257
|
-
version:
|
|
258
|
-
registry:
|
|
257
|
+
version: config.version.perp.stakePool,
|
|
258
|
+
registry: config.registry.perp.stakePool,
|
|
259
259
|
index: BigInt(0),
|
|
260
260
|
userShareId: BigInt(input.userShareId),
|
|
261
261
|
clock: constants_1.CLOCK,
|