flash-sdk 2.51.2 → 2.51.3
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/PerpetualsClient.d.ts +10 -2
- package/dist/PerpetualsClient.js +514 -540
- package/dist/ViewHelper.js +3 -3
- package/dist/backupOracle.js +3 -3
- package/dist/idl/perpetuals.d.ts +112 -1
- package/dist/idl/perpetuals.js +112 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/utils/alt.d.ts +1 -0
- package/dist/utils/rpc.js +50 -50
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -2148,40 +2148,36 @@ var PerpetualsClient = (function () {
|
|
2148
2148
|
}
|
2149
2149
|
});
|
2150
2150
|
}); };
|
2151
|
-
this.getAddLiquidityAmountAndFeeView = function (
|
2152
|
-
|
2153
|
-
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
var _e;
|
2159
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2160
|
-
return __generator(this, function (_f) {
|
2161
|
-
switch (_f.label) {
|
2151
|
+
this.getAddLiquidityAmountAndFeeView = function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
|
2152
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2153
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2154
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_5, token, _a, custodies_6, custody, _b, _c, market, depositCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
2155
|
+
var _d;
|
2156
|
+
return __generator(this, function (_e) {
|
2157
|
+
switch (_e.label) {
|
2162
2158
|
case 0:
|
2163
2159
|
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2164
2160
|
custodies = POOL_CONFIG.custodies;
|
2165
2161
|
custodyMetas = [];
|
2166
2162
|
marketMetas = [];
|
2167
|
-
for (
|
2168
|
-
token = custodies_5[
|
2163
|
+
for (_i = 0, custodies_5 = custodies; _i < custodies_5.length; _i++) {
|
2164
|
+
token = custodies_5[_i];
|
2169
2165
|
custodyMetas.push({
|
2170
2166
|
isSigner: false,
|
2171
2167
|
isWritable: false,
|
2172
2168
|
pubkey: token.custodyAccount,
|
2173
2169
|
});
|
2174
2170
|
}
|
2175
|
-
for (
|
2176
|
-
custody = custodies_6[
|
2171
|
+
for (_a = 0, custodies_6 = custodies; _a < custodies_6.length; _a++) {
|
2172
|
+
custody = custodies_6[_a];
|
2177
2173
|
custodyMetas.push({
|
2178
2174
|
isSigner: false,
|
2179
2175
|
isWritable: false,
|
2180
2176
|
pubkey: custody.intOracleAccount,
|
2181
2177
|
});
|
2182
2178
|
}
|
2183
|
-
for (
|
2184
|
-
market =
|
2179
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
2180
|
+
market = _c[_b];
|
2185
2181
|
marketMetas.push({
|
2186
2182
|
pubkey: market.marketAccount,
|
2187
2183
|
isSigner: false,
|
@@ -2204,14 +2200,14 @@ var PerpetualsClient = (function () {
|
|
2204
2200
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2205
2201
|
.transaction()];
|
2206
2202
|
case 1:
|
2207
|
-
transaction =
|
2203
|
+
transaction = _e.sent();
|
2208
2204
|
return [4, backUpOracleInstructionPromise];
|
2209
2205
|
case 2:
|
2210
|
-
backUpOracleInstruction =
|
2211
|
-
(
|
2206
|
+
backUpOracleInstruction = _e.sent();
|
2207
|
+
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
2212
2208
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2213
2209
|
case 3:
|
2214
|
-
result =
|
2210
|
+
result = _e.sent();
|
2215
2211
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddLiquidityAmountAndFee'; });
|
2216
2212
|
res = this.viewHelper.decodeLogs(result, index, 'getAddLiquidityAmountAndFee');
|
2217
2213
|
return [2, {
|
@@ -2222,40 +2218,36 @@ var PerpetualsClient = (function () {
|
|
2222
2218
|
});
|
2223
2219
|
});
|
2224
2220
|
};
|
2225
|
-
this.getRemoveLiquidityAmountAndFeeView = function (
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
|
2230
|
-
|
2231
|
-
|
2232
|
-
var _e;
|
2233
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2234
|
-
return __generator(this, function (_f) {
|
2235
|
-
switch (_f.label) {
|
2221
|
+
this.getRemoveLiquidityAmountAndFeeView = function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
|
2222
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2223
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2224
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_7, token, _a, custodies_8, custody, _b, _c, market, removeCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
2225
|
+
var _d;
|
2226
|
+
return __generator(this, function (_e) {
|
2227
|
+
switch (_e.label) {
|
2236
2228
|
case 0:
|
2237
2229
|
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2238
2230
|
custodies = POOL_CONFIG.custodies;
|
2239
2231
|
custodyMetas = [];
|
2240
2232
|
marketMetas = [];
|
2241
|
-
for (
|
2242
|
-
token = custodies_7[
|
2233
|
+
for (_i = 0, custodies_7 = custodies; _i < custodies_7.length; _i++) {
|
2234
|
+
token = custodies_7[_i];
|
2243
2235
|
custodyMetas.push({
|
2244
2236
|
isSigner: false,
|
2245
2237
|
isWritable: false,
|
2246
2238
|
pubkey: token.custodyAccount,
|
2247
2239
|
});
|
2248
2240
|
}
|
2249
|
-
for (
|
2250
|
-
custody = custodies_8[
|
2241
|
+
for (_a = 0, custodies_8 = custodies; _a < custodies_8.length; _a++) {
|
2242
|
+
custody = custodies_8[_a];
|
2251
2243
|
custodyMetas.push({
|
2252
2244
|
isSigner: false,
|
2253
2245
|
isWritable: false,
|
2254
2246
|
pubkey: custody.intOracleAccount,
|
2255
2247
|
});
|
2256
2248
|
}
|
2257
|
-
for (
|
2258
|
-
market =
|
2249
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
2250
|
+
market = _c[_b];
|
2259
2251
|
marketMetas.push({
|
2260
2252
|
pubkey: market.marketAccount,
|
2261
2253
|
isSigner: false,
|
@@ -2278,14 +2270,14 @@ var PerpetualsClient = (function () {
|
|
2278
2270
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2279
2271
|
.transaction()];
|
2280
2272
|
case 1:
|
2281
|
-
transaction =
|
2273
|
+
transaction = _e.sent();
|
2282
2274
|
return [4, backUpOracleInstructionPromise];
|
2283
2275
|
case 2:
|
2284
|
-
backUpOracleInstruction =
|
2285
|
-
(
|
2276
|
+
backUpOracleInstruction = _e.sent();
|
2277
|
+
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
2286
2278
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2287
2279
|
case 3:
|
2288
|
-
result =
|
2280
|
+
result = _e.sent();
|
2289
2281
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveLiquidityAmountAndFee'; });
|
2290
2282
|
if (result.value.err) {
|
2291
2283
|
return [2, {
|
@@ -2361,40 +2353,36 @@ var PerpetualsClient = (function () {
|
|
2361
2353
|
}
|
2362
2354
|
});
|
2363
2355
|
}); };
|
2364
|
-
this.getAddCompoundingLiquidityAmountAndFeeView = function (
|
2365
|
-
|
2366
|
-
|
2367
|
-
|
2368
|
-
|
2369
|
-
|
2370
|
-
|
2371
|
-
var _e;
|
2372
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2373
|
-
return __generator(this, function (_f) {
|
2374
|
-
switch (_f.label) {
|
2356
|
+
this.getAddCompoundingLiquidityAmountAndFeeView = function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
|
2357
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2358
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2359
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_11, token, _a, custodies_12, custody, _b, _c, market, depositCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
|
2360
|
+
var _d;
|
2361
|
+
return __generator(this, function (_e) {
|
2362
|
+
switch (_e.label) {
|
2375
2363
|
case 0:
|
2376
2364
|
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2377
2365
|
custodies = POOL_CONFIG.custodies;
|
2378
2366
|
custodyMetas = [];
|
2379
2367
|
marketMetas = [];
|
2380
|
-
for (
|
2381
|
-
token = custodies_11[
|
2368
|
+
for (_i = 0, custodies_11 = custodies; _i < custodies_11.length; _i++) {
|
2369
|
+
token = custodies_11[_i];
|
2382
2370
|
custodyMetas.push({
|
2383
2371
|
isSigner: false,
|
2384
2372
|
isWritable: false,
|
2385
2373
|
pubkey: token.custodyAccount,
|
2386
2374
|
});
|
2387
2375
|
}
|
2388
|
-
for (
|
2389
|
-
custody = custodies_12[
|
2376
|
+
for (_a = 0, custodies_12 = custodies; _a < custodies_12.length; _a++) {
|
2377
|
+
custody = custodies_12[_a];
|
2390
2378
|
custodyMetas.push({
|
2391
2379
|
isSigner: false,
|
2392
2380
|
isWritable: false,
|
2393
2381
|
pubkey: custody.intOracleAccount,
|
2394
2382
|
});
|
2395
2383
|
}
|
2396
|
-
for (
|
2397
|
-
market =
|
2384
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
2385
|
+
market = _c[_b];
|
2398
2386
|
marketMetas.push({
|
2399
2387
|
pubkey: market.marketAccount,
|
2400
2388
|
isSigner: false,
|
@@ -2405,7 +2393,7 @@ var PerpetualsClient = (function () {
|
|
2405
2393
|
rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
2406
2394
|
return [4, backUpOracleInstructionPromise];
|
2407
2395
|
case 1:
|
2408
|
-
backUpOracleInstruction =
|
2396
|
+
backUpOracleInstruction = _e.sent();
|
2409
2397
|
return [4, this.program.methods
|
2410
2398
|
.getAddCompoundingLiquidityAmountAndFee({
|
2411
2399
|
amountIn: amount,
|
@@ -2424,11 +2412,11 @@ var PerpetualsClient = (function () {
|
|
2424
2412
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2425
2413
|
.transaction()];
|
2426
2414
|
case 2:
|
2427
|
-
transaction =
|
2428
|
-
(
|
2415
|
+
transaction = _e.sent();
|
2416
|
+
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
2429
2417
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2430
2418
|
case 3:
|
2431
|
-
result =
|
2419
|
+
result = _e.sent();
|
2432
2420
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddCompoundingLiquidityAmountAndFee'; });
|
2433
2421
|
res = this.viewHelper.decodeLogs(result, index, 'getAddCompoundingLiquidityAmountAndFee');
|
2434
2422
|
return [2, {
|
@@ -2439,40 +2427,36 @@ var PerpetualsClient = (function () {
|
|
2439
2427
|
});
|
2440
2428
|
});
|
2441
2429
|
};
|
2442
|
-
this.getRemoveCompoundingLiquidityAmountAndFeeView = function (
|
2443
|
-
|
2444
|
-
|
2445
|
-
|
2446
|
-
|
2447
|
-
|
2448
|
-
|
2449
|
-
var _e;
|
2450
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2451
|
-
return __generator(this, function (_f) {
|
2452
|
-
switch (_f.label) {
|
2430
|
+
this.getRemoveCompoundingLiquidityAmountAndFeeView = function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
|
2431
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2432
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2433
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_13, token, _a, custodies_14, custody, _b, _c, market, removeCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
|
2434
|
+
var _d;
|
2435
|
+
return __generator(this, function (_e) {
|
2436
|
+
switch (_e.label) {
|
2453
2437
|
case 0:
|
2454
2438
|
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2455
2439
|
custodies = POOL_CONFIG.custodies;
|
2456
2440
|
custodyMetas = [];
|
2457
2441
|
marketMetas = [];
|
2458
|
-
for (
|
2459
|
-
token = custodies_13[
|
2442
|
+
for (_i = 0, custodies_13 = custodies; _i < custodies_13.length; _i++) {
|
2443
|
+
token = custodies_13[_i];
|
2460
2444
|
custodyMetas.push({
|
2461
2445
|
isSigner: false,
|
2462
2446
|
isWritable: false,
|
2463
2447
|
pubkey: token.custodyAccount,
|
2464
2448
|
});
|
2465
2449
|
}
|
2466
|
-
for (
|
2467
|
-
custody = custodies_14[
|
2450
|
+
for (_a = 0, custodies_14 = custodies; _a < custodies_14.length; _a++) {
|
2451
|
+
custody = custodies_14[_a];
|
2468
2452
|
custodyMetas.push({
|
2469
2453
|
isSigner: false,
|
2470
2454
|
isWritable: false,
|
2471
2455
|
pubkey: custody.intOracleAccount,
|
2472
2456
|
});
|
2473
2457
|
}
|
2474
|
-
for (
|
2475
|
-
market =
|
2458
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
2459
|
+
market = _c[_b];
|
2476
2460
|
marketMetas.push({
|
2477
2461
|
pubkey: market.marketAccount,
|
2478
2462
|
isSigner: false,
|
@@ -2483,7 +2467,7 @@ var PerpetualsClient = (function () {
|
|
2483
2467
|
rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
2484
2468
|
return [4, backUpOracleInstructionPromise];
|
2485
2469
|
case 1:
|
2486
|
-
backUpOracleInstruction =
|
2470
|
+
backUpOracleInstruction = _e.sent();
|
2487
2471
|
return [4, this.program.methods
|
2488
2472
|
.getRemoveCompoundingLiquidityAmountAndFee({
|
2489
2473
|
compoundingAmountIn: amount,
|
@@ -2502,11 +2486,11 @@ var PerpetualsClient = (function () {
|
|
2502
2486
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2503
2487
|
.transaction()];
|
2504
2488
|
case 2:
|
2505
|
-
transaction =
|
2506
|
-
(
|
2489
|
+
transaction = _e.sent();
|
2490
|
+
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
2507
2491
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2508
2492
|
case 3:
|
2509
|
-
result =
|
2493
|
+
result = _e.sent();
|
2510
2494
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveCompoundingLiquidityAmountAndFee'; });
|
2511
2495
|
if (result.value.err) {
|
2512
2496
|
return [2, {
|
@@ -2687,18 +2671,14 @@ var PerpetualsClient = (function () {
|
|
2687
2671
|
}
|
2688
2672
|
});
|
2689
2673
|
}); };
|
2690
|
-
this.openPosition = function (
|
2691
|
-
|
2692
|
-
|
2693
|
-
|
2694
|
-
}
|
2695
|
-
|
2674
|
+
this.openPosition = function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2675
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2676
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2677
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2678
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2679
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2680
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2696
2681
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
2697
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2698
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2699
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2700
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2701
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2702
2682
|
return __generator(this, function (_c) {
|
2703
2683
|
switch (_c.label) {
|
2704
2684
|
case 0:
|
@@ -2802,19 +2782,15 @@ var PerpetualsClient = (function () {
|
|
2802
2782
|
});
|
2803
2783
|
});
|
2804
2784
|
};
|
2805
|
-
this.closePosition = function (
|
2806
|
-
|
2807
|
-
|
2808
|
-
|
2809
|
-
}
|
2810
|
-
|
2785
|
+
this.closePosition = function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
2786
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2787
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2788
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2789
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
2790
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
2791
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2792
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2811
2793
|
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_2;
|
2812
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2813
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2814
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2815
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
2816
|
-
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
2817
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2818
2794
|
return __generator(this, function (_b) {
|
2819
2795
|
switch (_b.label) {
|
2820
2796
|
case 0:
|
@@ -2911,18 +2887,14 @@ var PerpetualsClient = (function () {
|
|
2911
2887
|
});
|
2912
2888
|
});
|
2913
2889
|
};
|
2914
|
-
this.swapAndOpen = function (
|
2915
|
-
|
2916
|
-
|
2917
|
-
|
2918
|
-
}
|
2919
|
-
|
2890
|
+
this.swapAndOpen = function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, minCollateralAmountOut, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2891
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2892
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2893
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2894
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2895
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2896
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2920
2897
|
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_3;
|
2921
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2922
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2923
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2924
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2925
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2926
2898
|
return __generator(this, function (_c) {
|
2927
2899
|
switch (_c.label) {
|
2928
2900
|
case 0:
|
@@ -3062,17 +3034,13 @@ var PerpetualsClient = (function () {
|
|
3062
3034
|
});
|
3063
3035
|
});
|
3064
3036
|
};
|
3065
|
-
this.closeAndSwap = function (
|
3066
|
-
|
3067
|
-
|
3068
|
-
|
3069
|
-
}
|
3070
|
-
return __awaiter(_this,
|
3037
|
+
this.closeAndSwap = function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, minSwapAmountOut, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, ephemeralSignerPubkey) {
|
3038
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3039
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3040
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3041
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3042
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3071
3043
|
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, inx, err_4;
|
3072
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3073
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3074
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3075
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3076
3044
|
return __generator(this, function (_a) {
|
3077
3045
|
switch (_a.label) {
|
3078
3046
|
case 0:
|
@@ -3186,20 +3154,16 @@ var PerpetualsClient = (function () {
|
|
3186
3154
|
});
|
3187
3155
|
});
|
3188
3156
|
};
|
3189
|
-
this.swap = function (
|
3190
|
-
|
3191
|
-
|
3192
|
-
|
3193
|
-
}
|
3194
|
-
|
3195
|
-
|
3196
|
-
|
3197
|
-
|
3198
|
-
|
3199
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3200
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3201
|
-
return __generator(this, function (_g) {
|
3202
|
-
switch (_g.label) {
|
3157
|
+
this.swap = function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey) {
|
3158
|
+
if (useFeesPool === void 0) { useFeesPool = false; }
|
3159
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
3160
|
+
if (unWrapSol === void 0) { unWrapSol = false; }
|
3161
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3162
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3163
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3164
|
+
var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount, wsolATAExist, unWrappedSolBalance, _a, wsolAssociatedTokenAccount, closeWsolATAIns, accCreationLamports, lamports, unWrappedSolBalance, _b, tokenAccountBalance, _c, lamports, _d, custodyAccountMetas, custodyOracleAccountMetas, _i, _e, custody, params, inx, closeWsolATAIns, err_5;
|
3165
|
+
return __generator(this, function (_f) {
|
3166
|
+
switch (_f.label) {
|
3203
3167
|
case 0:
|
3204
3168
|
userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
|
3205
3169
|
if (!userInputCustodyConfig) {
|
@@ -3217,10 +3181,10 @@ var PerpetualsClient = (function () {
|
|
3217
3181
|
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
|
3218
3182
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
|
3219
3183
|
case 1:
|
3220
|
-
wsolAssociatedTokenAccount =
|
3184
|
+
wsolAssociatedTokenAccount = _f.sent();
|
3221
3185
|
return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
|
3222
3186
|
case 2:
|
3223
|
-
wsolATAExist =
|
3187
|
+
wsolATAExist = _f.sent();
|
3224
3188
|
if (!wsolATAExist) {
|
3225
3189
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
3226
3190
|
}
|
@@ -3228,11 +3192,11 @@ var PerpetualsClient = (function () {
|
|
3228
3192
|
_a = anchor_1.BN.bind;
|
3229
3193
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3230
3194
|
case 3:
|
3231
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
3195
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
3232
3196
|
if (unWrappedSolBalance.lt(amountIn)) {
|
3233
3197
|
throw "Insufficient SOL Funds";
|
3234
3198
|
}
|
3235
|
-
|
3199
|
+
_f.label = 4;
|
3236
3200
|
case 4:
|
3237
3201
|
instructions.push(web3_js_1.SystemProgram.transfer({
|
3238
3202
|
fromPubkey: publicKey,
|
@@ -3254,20 +3218,20 @@ var PerpetualsClient = (function () {
|
|
3254
3218
|
additionalSigners: additionalSigners
|
3255
3219
|
}];
|
3256
3220
|
}
|
3257
|
-
|
3221
|
+
_f.label = 6;
|
3258
3222
|
case 6:
|
3259
|
-
|
3223
|
+
_f.trys.push([6, 19, , 20]);
|
3260
3224
|
if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
|
3261
3225
|
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
3262
3226
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
3263
3227
|
case 7:
|
3264
|
-
accCreationLamports = (
|
3228
|
+
accCreationLamports = (_f.sent());
|
3265
3229
|
console.log("accCreationLamports:", accCreationLamports);
|
3266
3230
|
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
3267
3231
|
_b = anchor_1.BN.bind;
|
3268
3232
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3269
3233
|
case 8:
|
3270
|
-
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0,
|
3234
|
+
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
3271
3235
|
if (unWrappedSolBalance.lt(amountIn)) {
|
3272
3236
|
throw "Insufficient SOL Funds";
|
3273
3237
|
}
|
@@ -3294,18 +3258,18 @@ var PerpetualsClient = (function () {
|
|
3294
3258
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
|
3295
3259
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3296
3260
|
case 10:
|
3297
|
-
if (!(
|
3261
|
+
if (!(_f.sent())) {
|
3298
3262
|
throw "Insufficient Funds , Token Account doesn't exist";
|
3299
3263
|
}
|
3300
3264
|
if (!!skipBalanceChecks) return [3, 12];
|
3301
3265
|
_c = anchor_1.BN.bind;
|
3302
3266
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3303
3267
|
case 11:
|
3304
|
-
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (
|
3268
|
+
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
3305
3269
|
if (tokenAccountBalance.lt(amountIn)) {
|
3306
3270
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3307
3271
|
}
|
3308
|
-
|
3272
|
+
_f.label = 12;
|
3309
3273
|
case 12:
|
3310
3274
|
if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
|
3311
3275
|
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
@@ -3330,23 +3294,23 @@ var PerpetualsClient = (function () {
|
|
3330
3294
|
return [3, 17];
|
3331
3295
|
case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
|
3332
3296
|
case 14:
|
3333
|
-
userOutputTokenAccount =
|
3297
|
+
userOutputTokenAccount = _f.sent();
|
3334
3298
|
_d = createUserATA;
|
3335
3299
|
if (!_d) return [3, 16];
|
3336
3300
|
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
3337
3301
|
case 15:
|
3338
|
-
_d = !(
|
3339
|
-
|
3302
|
+
_d = !(_f.sent());
|
3303
|
+
_f.label = 16;
|
3340
3304
|
case 16:
|
3341
3305
|
if (_d) {
|
3342
3306
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
|
3343
3307
|
}
|
3344
|
-
|
3308
|
+
_f.label = 17;
|
3345
3309
|
case 17:
|
3346
3310
|
custodyAccountMetas = [];
|
3347
3311
|
custodyOracleAccountMetas = [];
|
3348
|
-
for (
|
3349
|
-
custody =
|
3312
|
+
for (_i = 0, _e = poolConfig.custodies; _i < _e.length; _i++) {
|
3313
|
+
custody = _e[_i];
|
3350
3314
|
custodyAccountMetas.push({
|
3351
3315
|
pubkey: custody.custodyAccount,
|
3352
3316
|
isSigner: false,
|
@@ -3386,7 +3350,7 @@ var PerpetualsClient = (function () {
|
|
3386
3350
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
3387
3351
|
.instruction()];
|
3388
3352
|
case 18:
|
3389
|
-
inx =
|
3353
|
+
inx = _f.sent();
|
3390
3354
|
instructions.push(inx);
|
3391
3355
|
if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
|
3392
3356
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
|
@@ -3394,7 +3358,7 @@ var PerpetualsClient = (function () {
|
|
3394
3358
|
}
|
3395
3359
|
return [3, 20];
|
3396
3360
|
case 19:
|
3397
|
-
err_5 =
|
3361
|
+
err_5 = _f.sent();
|
3398
3362
|
console.error("perpClient Swap error:: ", err_5);
|
3399
3363
|
throw err_5;
|
3400
3364
|
case 20: return [2, {
|
@@ -3476,15 +3440,11 @@ var PerpetualsClient = (function () {
|
|
3476
3440
|
}
|
3477
3441
|
});
|
3478
3442
|
}); };
|
3479
|
-
this.addCollateral = function (
|
3480
|
-
|
3481
|
-
|
3482
|
-
|
3483
|
-
}
|
3484
|
-
return __awaiter(_this, __spreadArray([collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3443
|
+
this.addCollateral = function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3444
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3445
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3446
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3485
3447
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
|
3486
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3487
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3488
3448
|
return __generator(this, function (_c) {
|
3489
3449
|
switch (_c.label) {
|
3490
3450
|
case 0:
|
@@ -3578,15 +3538,11 @@ var PerpetualsClient = (function () {
|
|
3578
3538
|
});
|
3579
3539
|
});
|
3580
3540
|
};
|
3581
|
-
this.swapAndAddCollateral = function (
|
3582
|
-
|
3583
|
-
|
3584
|
-
|
3585
|
-
}
|
3586
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minCollateralAmountOut, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3541
|
+
this.swapAndAddCollateral = function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minCollateralAmountOut, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3542
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3543
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3544
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3587
3545
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
|
3588
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3589
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3590
3546
|
return __generator(this, function (_c) {
|
3591
3547
|
switch (_c.label) {
|
3592
3548
|
case 0:
|
@@ -3697,16 +3653,12 @@ var PerpetualsClient = (function () {
|
|
3697
3653
|
});
|
3698
3654
|
});
|
3699
3655
|
};
|
3700
|
-
this.removeCollateral = function (
|
3701
|
-
|
3702
|
-
|
3703
|
-
|
3704
|
-
|
3705
|
-
return __awaiter(_this, __spreadArray([collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
3656
|
+
this.removeCollateral = function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
3657
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
3658
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3659
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3660
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3706
3661
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns, error_3;
|
3707
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
3708
|
-
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3709
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3710
3662
|
return __generator(this, function (_b) {
|
3711
3663
|
switch (_b.label) {
|
3712
3664
|
case 0:
|
@@ -3807,14 +3759,10 @@ var PerpetualsClient = (function () {
|
|
3807
3759
|
});
|
3808
3760
|
});
|
3809
3761
|
};
|
3810
|
-
this.removeCollateralAndSwap = function (
|
3811
|
-
|
3812
|
-
|
3813
|
-
args_1[_i - 7] = arguments[_i];
|
3814
|
-
}
|
3815
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, outputSymbol_1, minSwapAmountOut_1, collateralDelta_1, side_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, outputSymbol, minSwapAmountOut, collateralDelta, side, poolConfig, ephemeralSignerPubkey) {
|
3762
|
+
this.removeCollateralAndSwap = function (targetSymbol, collateralSymbol, outputSymbol, minSwapAmountOut, collateralDelta, side, poolConfig, ephemeralSignerPubkey) {
|
3763
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3764
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3816
3765
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, instruction;
|
3817
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3818
3766
|
return __generator(this, function (_a) {
|
3819
3767
|
switch (_a.label) {
|
3820
3768
|
case 0:
|
@@ -3907,16 +3855,12 @@ var PerpetualsClient = (function () {
|
|
3907
3855
|
});
|
3908
3856
|
});
|
3909
3857
|
};
|
3910
|
-
this.increaseSize = function (
|
3911
|
-
|
3912
|
-
|
3913
|
-
|
3914
|
-
|
3915
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
3858
|
+
this.increaseSize = function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
3859
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3860
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3861
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3862
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3916
3863
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3917
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3918
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3919
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3920
3864
|
return __generator(this, function (_a) {
|
3921
3865
|
switch (_a.label) {
|
3922
3866
|
case 0:
|
@@ -3971,16 +3915,12 @@ var PerpetualsClient = (function () {
|
|
3971
3915
|
});
|
3972
3916
|
});
|
3973
3917
|
};
|
3974
|
-
this.decreaseSize = function (
|
3975
|
-
|
3976
|
-
|
3977
|
-
|
3978
|
-
|
3979
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
3918
|
+
this.decreaseSize = function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
3919
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3920
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3921
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3922
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3980
3923
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3981
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3982
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3983
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3984
3924
|
return __generator(this, function (_a) {
|
3985
3925
|
switch (_a.label) {
|
3986
3926
|
case 0:
|
@@ -4035,17 +3975,13 @@ var PerpetualsClient = (function () {
|
|
4035
3975
|
});
|
4036
3976
|
});
|
4037
3977
|
};
|
4038
|
-
this.addLiquidity = function (
|
4039
|
-
|
4040
|
-
|
4041
|
-
|
4042
|
-
|
4043
|
-
|
4044
|
-
|
4045
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4046
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4047
|
-
return __generator(this, function (_g) {
|
4048
|
-
switch (_g.label) {
|
3978
|
+
this.addLiquidity = function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3979
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3980
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3981
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3982
|
+
var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, tokenAccountBalance, _e, instruction, err_7;
|
3983
|
+
return __generator(this, function (_f) {
|
3984
|
+
switch (_f.label) {
|
4049
3985
|
case 0:
|
4050
3986
|
publicKey = this.provider.wallet.publicKey;
|
4051
3987
|
payTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey); });
|
@@ -4056,16 +3992,16 @@ var PerpetualsClient = (function () {
|
|
4056
3992
|
instructions = [];
|
4057
3993
|
postInstructions = [];
|
4058
3994
|
additionalSigners = [];
|
4059
|
-
|
3995
|
+
_f.label = 1;
|
4060
3996
|
case 1:
|
4061
|
-
|
3997
|
+
_f.trys.push([1, 10, , 11]);
|
4062
3998
|
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true);
|
4063
3999
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
4064
4000
|
custodyAccountMetas = [];
|
4065
4001
|
custodyOracleAccountMetas = [];
|
4066
4002
|
markets = [];
|
4067
|
-
for (
|
4068
|
-
custody =
|
4003
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
4004
|
+
custody = _a[_i];
|
4069
4005
|
custodyAccountMetas.push({
|
4070
4006
|
pubkey: custody.custodyAccount,
|
4071
4007
|
isSigner: false,
|
@@ -4077,8 +4013,8 @@ var PerpetualsClient = (function () {
|
|
4077
4013
|
isWritable: false,
|
4078
4014
|
});
|
4079
4015
|
}
|
4080
|
-
for (
|
4081
|
-
market =
|
4016
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
4017
|
+
market = _c[_b];
|
4082
4018
|
markets.push({
|
4083
4019
|
pubkey: market.marketAccount,
|
4084
4020
|
isSigner: false,
|
@@ -4087,21 +4023,21 @@ var PerpetualsClient = (function () {
|
|
4087
4023
|
}
|
4088
4024
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
4089
4025
|
case 2:
|
4090
|
-
if (!(
|
4026
|
+
if (!(_f.sent())) {
|
4091
4027
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
4092
4028
|
}
|
4093
4029
|
if (!(payTokenSymbol == 'SOL')) return [3, 5];
|
4094
4030
|
console.log("payTokenSymbol === SOL", payTokenSymbol);
|
4095
4031
|
lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
4096
4032
|
if (!!skipBalanceChecks) return [3, 4];
|
4097
|
-
|
4033
|
+
_d = anchor_1.BN.bind;
|
4098
4034
|
return [4, this.provider.connection.getBalance(publicKey)];
|
4099
4035
|
case 3:
|
4100
|
-
unWrappedSolBalance = new (
|
4036
|
+
unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
4101
4037
|
if (unWrappedSolBalance.lt(lamports)) {
|
4102
4038
|
throw "Insufficient SOL Funds";
|
4103
4039
|
}
|
4104
|
-
|
4040
|
+
_f.label = 4;
|
4105
4041
|
case 4:
|
4106
4042
|
if (!ephemeralSignerPubkey) {
|
4107
4043
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -4125,17 +4061,17 @@ var PerpetualsClient = (function () {
|
|
4125
4061
|
if (!!skipBalanceChecks) return [3, 8];
|
4126
4062
|
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
4127
4063
|
case 6:
|
4128
|
-
if (!(
|
4064
|
+
if (!(_f.sent())) {
|
4129
4065
|
throw "Insufficient Funds , token Account doesn't exist";
|
4130
4066
|
}
|
4131
|
-
|
4067
|
+
_e = anchor_1.BN.bind;
|
4132
4068
|
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
4133
4069
|
case 7:
|
4134
|
-
tokenAccountBalance = new (
|
4070
|
+
tokenAccountBalance = new (_e.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
4135
4071
|
if (tokenAccountBalance.lt(tokenAmountIn)) {
|
4136
4072
|
throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
|
4137
4073
|
}
|
4138
|
-
|
4074
|
+
_f.label = 8;
|
4139
4075
|
case 8: return [4, this.program.methods
|
4140
4076
|
.addLiquidity({
|
4141
4077
|
amountIn: tokenAmountIn,
|
@@ -4160,11 +4096,11 @@ var PerpetualsClient = (function () {
|
|
4160
4096
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4161
4097
|
.instruction()];
|
4162
4098
|
case 9:
|
4163
|
-
instruction =
|
4099
|
+
instruction = _f.sent();
|
4164
4100
|
instructions.push(instruction);
|
4165
4101
|
return [3, 11];
|
4166
4102
|
case 10:
|
4167
|
-
err_7 =
|
4103
|
+
err_7 = _f.sent();
|
4168
4104
|
console.error("perpClient addLiquidity error:: ", err_7);
|
4169
4105
|
throw err_7;
|
4170
4106
|
case 11: return [2, {
|
@@ -4175,18 +4111,14 @@ var PerpetualsClient = (function () {
|
|
4175
4111
|
});
|
4176
4112
|
});
|
4177
4113
|
};
|
4178
|
-
this.addLiquidityAndStake = function (
|
4179
|
-
|
4180
|
-
|
4181
|
-
|
4182
|
-
|
4183
|
-
|
4184
|
-
|
4185
|
-
|
4186
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4187
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4188
|
-
return __generator(this, function (_g) {
|
4189
|
-
switch (_g.label) {
|
4114
|
+
this.addLiquidityAndStake = function (inputSymbol, amountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
4115
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4116
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4117
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4118
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4119
|
+
var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, flpStakeAccount, poolStakedLpVault, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _c, custody, _d, _e, market, instruction;
|
4120
|
+
return __generator(this, function (_f) {
|
4121
|
+
switch (_f.label) {
|
4190
4122
|
case 0:
|
4191
4123
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4192
4124
|
preInstructions = [];
|
@@ -4206,14 +4138,14 @@ var PerpetualsClient = (function () {
|
|
4206
4138
|
_a = anchor_1.BN.bind;
|
4207
4139
|
return [4, this.provider.connection.getBalance(publicKey)];
|
4208
4140
|
case 1:
|
4209
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
4141
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
4210
4142
|
if (unWrappedSolBalance.lt(lamports)) {
|
4211
4143
|
throw "Insufficient SOL Funds";
|
4212
4144
|
}
|
4213
|
-
|
4145
|
+
_f.label = 2;
|
4214
4146
|
case 2: return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
4215
4147
|
case 3:
|
4216
|
-
if (!(
|
4148
|
+
if (!(_f.sent())) {
|
4217
4149
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
4218
4150
|
}
|
4219
4151
|
if (!ephemeralSignerPubkey) {
|
@@ -4239,23 +4171,23 @@ var PerpetualsClient = (function () {
|
|
4239
4171
|
if (!!skipBalanceChecks) return [3, 7];
|
4240
4172
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
4241
4173
|
case 5:
|
4242
|
-
if (!(
|
4174
|
+
if (!(_f.sent())) {
|
4243
4175
|
throw "Insufficient Funds , token Account doesn't exist";
|
4244
4176
|
}
|
4245
4177
|
_b = anchor_1.BN.bind;
|
4246
4178
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
4247
4179
|
case 6:
|
4248
|
-
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (
|
4180
|
+
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
4249
4181
|
if (tokenAccountBalance.lt(amountIn)) {
|
4250
4182
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
4251
4183
|
}
|
4252
|
-
|
4184
|
+
_f.label = 7;
|
4253
4185
|
case 7:
|
4254
4186
|
custodyAccountMetas = [];
|
4255
4187
|
custodyOracleAccountMetas = [];
|
4256
4188
|
markets = [];
|
4257
|
-
for (
|
4258
|
-
custody =
|
4189
|
+
for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
|
4190
|
+
custody = _c[_i];
|
4259
4191
|
custodyAccountMetas.push({
|
4260
4192
|
pubkey: custody.custodyAccount,
|
4261
4193
|
isSigner: false,
|
@@ -4267,8 +4199,8 @@ var PerpetualsClient = (function () {
|
|
4267
4199
|
isWritable: false,
|
4268
4200
|
});
|
4269
4201
|
}
|
4270
|
-
for (
|
4271
|
-
market =
|
4202
|
+
for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
|
4203
|
+
market = _e[_d];
|
4272
4204
|
markets.push({
|
4273
4205
|
pubkey: market.marketAccount,
|
4274
4206
|
isSigner: false,
|
@@ -4300,7 +4232,7 @@ var PerpetualsClient = (function () {
|
|
4300
4232
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4301
4233
|
.instruction()];
|
4302
4234
|
case 8:
|
4303
|
-
instruction =
|
4235
|
+
instruction = _f.sent();
|
4304
4236
|
instructions.push(instruction);
|
4305
4237
|
return [2, {
|
4306
4238
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4310,20 +4242,16 @@ var PerpetualsClient = (function () {
|
|
4310
4242
|
});
|
4311
4243
|
});
|
4312
4244
|
};
|
4313
|
-
this.removeLiquidity = function (
|
4314
|
-
|
4315
|
-
|
4316
|
-
|
4317
|
-
}
|
4318
|
-
|
4319
|
-
|
4320
|
-
|
4321
|
-
|
4322
|
-
|
4323
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4324
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4325
|
-
return __generator(this, function (_f) {
|
4326
|
-
switch (_f.label) {
|
4245
|
+
this.removeLiquidity = function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey, userPublicKey) {
|
4246
|
+
if (closeLpATA === void 0) { closeLpATA = false; }
|
4247
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
4248
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
4249
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4250
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4251
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4252
|
+
var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, _d, removeLiquidityTx, closeInx, closeWsolATAIns, err_8;
|
4253
|
+
return __generator(this, function (_e) {
|
4254
|
+
switch (_e.label) {
|
4327
4255
|
case 0:
|
4328
4256
|
recieveTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey); });
|
4329
4257
|
if (!recieveTokenCustodyConfig) {
|
@@ -4334,15 +4262,15 @@ var PerpetualsClient = (function () {
|
|
4334
4262
|
instructions = [];
|
4335
4263
|
postInstructions = [];
|
4336
4264
|
additionalSigners = [];
|
4337
|
-
|
4265
|
+
_e.label = 1;
|
4338
4266
|
case 1:
|
4339
|
-
|
4267
|
+
_e.trys.push([1, 7, , 8]);
|
4340
4268
|
stakedLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
4341
4269
|
custodyAccountMetas = [];
|
4342
4270
|
custodyOracleAccountMetas = [];
|
4343
4271
|
markets = [];
|
4344
|
-
for (
|
4345
|
-
custody =
|
4272
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
4273
|
+
custody = _a[_i];
|
4346
4274
|
custodyAccountMetas.push({
|
4347
4275
|
pubkey: custody.custodyAccount,
|
4348
4276
|
isSigner: false,
|
@@ -4354,8 +4282,8 @@ var PerpetualsClient = (function () {
|
|
4354
4282
|
isWritable: false,
|
4355
4283
|
});
|
4356
4284
|
}
|
4357
|
-
for (
|
4358
|
-
market =
|
4285
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
4286
|
+
market = _c[_b];
|
4359
4287
|
markets.push({
|
4360
4288
|
pubkey: market.marketAccount,
|
4361
4289
|
isSigner: false,
|
@@ -4384,17 +4312,17 @@ var PerpetualsClient = (function () {
|
|
4384
4312
|
return [3, 5];
|
4385
4313
|
case 2:
|
4386
4314
|
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true);
|
4387
|
-
|
4388
|
-
if (!
|
4315
|
+
_d = createUserATA;
|
4316
|
+
if (!_d) return [3, 4];
|
4389
4317
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
4390
4318
|
case 3:
|
4391
|
-
|
4392
|
-
|
4319
|
+
_d = !(_e.sent());
|
4320
|
+
_e.label = 4;
|
4393
4321
|
case 4:
|
4394
|
-
if (
|
4322
|
+
if (_d) {
|
4395
4323
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey));
|
4396
4324
|
}
|
4397
|
-
|
4325
|
+
_e.label = 5;
|
4398
4326
|
case 5: return [4, this.program.methods
|
4399
4327
|
.removeLiquidity({
|
4400
4328
|
lpAmountIn: liquidityAmountIn,
|
@@ -4419,7 +4347,7 @@ var PerpetualsClient = (function () {
|
|
4419
4347
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4420
4348
|
.instruction()];
|
4421
4349
|
case 6:
|
4422
|
-
removeLiquidityTx =
|
4350
|
+
removeLiquidityTx = _e.sent();
|
4423
4351
|
instructions.push(removeLiquidityTx);
|
4424
4352
|
if (closeLpATA) {
|
4425
4353
|
closeInx = (0, spl_token_1.createCloseAccountInstruction)(stakedLpTokenAccount, publicKey, publicKey);
|
@@ -4431,7 +4359,7 @@ var PerpetualsClient = (function () {
|
|
4431
4359
|
}
|
4432
4360
|
return [3, 8];
|
4433
4361
|
case 7:
|
4434
|
-
err_8 =
|
4362
|
+
err_8 = _e.sent();
|
4435
4363
|
console.log("perpClient removeLiquidity error:: ", err_8);
|
4436
4364
|
throw err_8;
|
4437
4365
|
case 8: return [2, {
|
@@ -4849,26 +4777,22 @@ var PerpetualsClient = (function () {
|
|
4849
4777
|
}
|
4850
4778
|
});
|
4851
4779
|
}); };
|
4852
|
-
this.refreshStakeWithTokenStake = function (
|
4853
|
-
|
4854
|
-
|
4855
|
-
|
4856
|
-
|
4857
|
-
|
4858
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_17;
|
4859
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4860
|
-
return __generator(this, function (_c) {
|
4861
|
-
switch (_c.label) {
|
4780
|
+
this.refreshStakeWithTokenStake = function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
|
4781
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4782
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4783
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_17;
|
4784
|
+
return __generator(this, function (_b) {
|
4785
|
+
switch (_b.label) {
|
4862
4786
|
case 0:
|
4863
|
-
|
4787
|
+
_b.trys.push([0, 2, , 3]);
|
4864
4788
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4865
4789
|
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
4866
4790
|
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
4867
4791
|
pool = poolConfig.poolAddress;
|
4868
4792
|
feeDistributionTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("custody_token_account"), pool.toBuffer(), rewardCustodyMint.toBuffer()], this.programId)[0];
|
4869
4793
|
custodyAccountMetas = [];
|
4870
|
-
for (
|
4871
|
-
custody =
|
4794
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
4795
|
+
custody = _a[_i];
|
4872
4796
|
custodyAccountMetas.push({
|
4873
4797
|
pubkey: custody.custodyAccount,
|
4874
4798
|
isSigner: false,
|
@@ -4900,10 +4824,10 @@ var PerpetualsClient = (function () {
|
|
4900
4824
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
|
4901
4825
|
.instruction()];
|
4902
4826
|
case 1:
|
4903
|
-
refreshStakeInstruction =
|
4827
|
+
refreshStakeInstruction = _b.sent();
|
4904
4828
|
return [2, refreshStakeInstruction];
|
4905
4829
|
case 2:
|
4906
|
-
err_17 =
|
4830
|
+
err_17 = _b.sent();
|
4907
4831
|
console.log("perpClient refreshStaking error:: ", err_17);
|
4908
4832
|
throw err_17;
|
4909
4833
|
case 3: return [2];
|
@@ -4911,14 +4835,10 @@ var PerpetualsClient = (function () {
|
|
4911
4835
|
});
|
4912
4836
|
});
|
4913
4837
|
};
|
4914
|
-
this.unstakeInstant = function (
|
4915
|
-
|
4916
|
-
|
4917
|
-
args_1[_i - 3] = arguments[_i];
|
4918
|
-
}
|
4919
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
|
4838
|
+
this.unstakeInstant = function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
|
4839
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4840
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4920
4841
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_18;
|
4921
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4922
4842
|
return __generator(this, function (_b) {
|
4923
4843
|
switch (_b.label) {
|
4924
4844
|
case 0:
|
@@ -5077,17 +4997,13 @@ var PerpetualsClient = (function () {
|
|
5077
4997
|
}
|
5078
4998
|
});
|
5079
4999
|
}); };
|
5080
|
-
this.withdrawStake = function (
|
5081
|
-
|
5082
|
-
|
5083
|
-
|
5084
|
-
}
|
5085
|
-
return __awaiter(_this,
|
5000
|
+
this.withdrawStake = function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
|
5001
|
+
if (pendingActivation === void 0) { pendingActivation = true; }
|
5002
|
+
if (deactivated === void 0) { deactivated = true; }
|
5003
|
+
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
5004
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
5005
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5086
5006
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_21;
|
5087
|
-
if (pendingActivation === void 0) { pendingActivation = true; }
|
5088
|
-
if (deactivated === void 0) { deactivated = true; }
|
5089
|
-
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
5090
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
5091
5007
|
return __generator(this, function (_b) {
|
5092
5008
|
switch (_b.label) {
|
5093
5009
|
case 0:
|
@@ -5149,14 +5065,10 @@ var PerpetualsClient = (function () {
|
|
5149
5065
|
});
|
5150
5066
|
});
|
5151
5067
|
};
|
5152
|
-
this.collectStakeFees = function (
|
5153
|
-
|
5154
|
-
|
5155
|
-
args_1[_i - 3] = arguments[_i];
|
5156
|
-
}
|
5157
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
5068
|
+
this.collectStakeFees = function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
5069
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5070
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5158
5071
|
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_22;
|
5159
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5160
5072
|
return __generator(this, function (_b) {
|
5161
5073
|
switch (_b.label) {
|
5162
5074
|
case 0:
|
@@ -5880,14 +5792,10 @@ var PerpetualsClient = (function () {
|
|
5880
5792
|
}
|
5881
5793
|
});
|
5882
5794
|
}); };
|
5883
|
-
this.collectTokenReward = function (
|
5884
|
-
|
5885
|
-
|
5886
|
-
args_1[_i - 2] = arguments[_i];
|
5887
|
-
}
|
5888
|
-
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
5795
|
+
this.collectTokenReward = function (owner, poolConfig, createUserATA) {
|
5796
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5797
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5889
5798
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_36;
|
5890
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5891
5799
|
return __generator(this, function (_b) {
|
5892
5800
|
switch (_b.label) {
|
5893
5801
|
case 0:
|
@@ -5942,14 +5850,10 @@ var PerpetualsClient = (function () {
|
|
5942
5850
|
});
|
5943
5851
|
});
|
5944
5852
|
};
|
5945
|
-
this.collectRevenue = function (
|
5946
|
-
|
5947
|
-
|
5948
|
-
args_1[_i - 3] = arguments[_i];
|
5949
|
-
}
|
5950
|
-
return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
|
5853
|
+
this.collectRevenue = function (owner, rewardSymbol, poolConfig, createUserATA) {
|
5854
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5855
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5951
5856
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_37;
|
5952
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5953
5857
|
return __generator(this, function (_b) {
|
5954
5858
|
switch (_b.label) {
|
5955
5859
|
case 0:
|
@@ -6134,14 +6038,10 @@ var PerpetualsClient = (function () {
|
|
6134
6038
|
}
|
6135
6039
|
});
|
6136
6040
|
}); };
|
6137
|
-
this.collectNftReward = function (
|
6138
|
-
|
6139
|
-
|
6140
|
-
args_1[_i - 3] = arguments[_i];
|
6141
|
-
}
|
6142
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
6041
|
+
this.collectNftReward = function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
6042
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6043
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6143
6044
|
var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_41;
|
6144
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
6145
6045
|
return __generator(this, function (_b) {
|
6146
6046
|
switch (_b.label) {
|
6147
6047
|
case 0:
|
@@ -6201,14 +6101,10 @@ var PerpetualsClient = (function () {
|
|
6201
6101
|
});
|
6202
6102
|
});
|
6203
6103
|
};
|
6204
|
-
this.collectAndDistributeFee = function (
|
6205
|
-
|
6206
|
-
|
6207
|
-
args_1[_i - 2] = arguments[_i];
|
6208
|
-
}
|
6209
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
6104
|
+
this.collectAndDistributeFee = function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
6105
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6106
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6210
6107
|
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_42;
|
6211
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
6212
6108
|
return __generator(this, function (_b) {
|
6213
6109
|
switch (_b.label) {
|
6214
6110
|
case 0:
|
@@ -6333,16 +6229,12 @@ var PerpetualsClient = (function () {
|
|
6333
6229
|
}
|
6334
6230
|
});
|
6335
6231
|
}); };
|
6336
|
-
this.forceClosePosition = function (
|
6337
|
-
|
6338
|
-
|
6339
|
-
|
6340
|
-
|
6341
|
-
return __awaiter(_this, __spreadArray([positionAccount_2, targetSymbol_1, collateralSymbol_1, side_1, isStopLoss_1, poolConfig_1], args_1, true), void 0, function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
6232
|
+
this.forceClosePosition = function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
6233
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6234
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
6235
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6236
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6342
6237
|
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_44;
|
6343
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
6344
|
-
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
6345
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6346
6238
|
return __generator(this, function (_b) {
|
6347
6239
|
switch (_b.label) {
|
6348
6240
|
case 0:
|
@@ -6414,15 +6306,11 @@ var PerpetualsClient = (function () {
|
|
6414
6306
|
});
|
6415
6307
|
});
|
6416
6308
|
};
|
6417
|
-
this.placeLimitOrder = function (
|
6418
|
-
|
6419
|
-
|
6420
|
-
|
6421
|
-
}
|
6422
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, limitPrice_1, reserveAmount_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
6309
|
+
this.placeLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
6310
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6311
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6312
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6423
6313
|
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_45;
|
6424
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6425
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6426
6314
|
return __generator(this, function (_c) {
|
6427
6315
|
switch (_c.label) {
|
6428
6316
|
case 0:
|
@@ -6538,15 +6426,11 @@ var PerpetualsClient = (function () {
|
|
6538
6426
|
});
|
6539
6427
|
});
|
6540
6428
|
};
|
6541
|
-
this.editLimitOrder = function (
|
6542
|
-
|
6543
|
-
|
6544
|
-
|
6545
|
-
}
|
6546
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, orderId_1, limitPrice_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
|
6429
|
+
this.editLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
|
6430
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6431
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6432
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6547
6433
|
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_46;
|
6548
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
6549
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6550
6434
|
return __generator(this, function (_b) {
|
6551
6435
|
switch (_b.label) {
|
6552
6436
|
case 0:
|
@@ -6645,16 +6529,12 @@ var PerpetualsClient = (function () {
|
|
6645
6529
|
});
|
6646
6530
|
});
|
6647
6531
|
};
|
6648
|
-
this.executeLimitOrder = function (
|
6649
|
-
|
6650
|
-
|
6651
|
-
|
6652
|
-
|
6653
|
-
return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6532
|
+
this.executeLimitOrder = function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6533
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6534
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6535
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6536
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6654
6537
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_47;
|
6655
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6656
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6657
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6658
6538
|
return __generator(this, function (_a) {
|
6659
6539
|
switch (_a.label) {
|
6660
6540
|
case 0:
|
@@ -6714,16 +6594,12 @@ var PerpetualsClient = (function () {
|
|
6714
6594
|
});
|
6715
6595
|
});
|
6716
6596
|
};
|
6717
|
-
this.executeLimitWithSwap = function (
|
6718
|
-
|
6719
|
-
|
6720
|
-
|
6721
|
-
|
6722
|
-
return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6597
|
+
this.executeLimitWithSwap = function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6598
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6599
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6600
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6601
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6723
6602
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_48;
|
6724
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6725
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6726
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6727
6603
|
return __generator(this, function (_a) {
|
6728
6604
|
switch (_a.label) {
|
6729
6605
|
case 0:
|
@@ -6989,20 +6865,16 @@ var PerpetualsClient = (function () {
|
|
6989
6865
|
}
|
6990
6866
|
});
|
6991
6867
|
}); };
|
6992
|
-
this.executeTriggerWithSwap = function (
|
6993
|
-
|
6994
|
-
|
6995
|
-
|
6996
|
-
}
|
6997
|
-
|
6998
|
-
|
6999
|
-
|
7000
|
-
|
7001
|
-
|
7002
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
7003
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
7004
|
-
return __generator(this, function (_e) {
|
7005
|
-
switch (_e.label) {
|
6868
|
+
this.executeTriggerWithSwap = function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6869
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6870
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6871
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6872
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6873
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6874
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6875
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, executeTriggerWithSwap, err_53;
|
6876
|
+
return __generator(this, function (_d) {
|
6877
|
+
switch (_d.label) {
|
7006
6878
|
case 0:
|
7007
6879
|
payerPubkey = this.provider.wallet.publicKey;
|
7008
6880
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
@@ -7013,9 +6885,9 @@ var PerpetualsClient = (function () {
|
|
7013
6885
|
instructions = [];
|
7014
6886
|
postInstructions = [];
|
7015
6887
|
additionalSigners = [];
|
7016
|
-
|
6888
|
+
_d.label = 1;
|
7017
6889
|
case 1:
|
7018
|
-
|
6890
|
+
_d.trys.push([1, 9, , 10]);
|
7019
6891
|
if (!false) return [3, 2];
|
7020
6892
|
return [3, 7];
|
7021
6893
|
case 2:
|
@@ -7024,8 +6896,8 @@ var PerpetualsClient = (function () {
|
|
7024
6896
|
if (!_a) return [3, 4];
|
7025
6897
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
7026
6898
|
case 3:
|
7027
|
-
_a = !(
|
7028
|
-
|
6899
|
+
_a = !(_d.sent());
|
6900
|
+
_d.label = 4;
|
7029
6901
|
case 4:
|
7030
6902
|
if (_a) {
|
7031
6903
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
|
@@ -7035,20 +6907,20 @@ var PerpetualsClient = (function () {
|
|
7035
6907
|
if (!_b) return [3, 6];
|
7036
6908
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
|
7037
6909
|
case 5:
|
7038
|
-
_b = !(
|
7039
|
-
|
6910
|
+
_b = !(_d.sent());
|
6911
|
+
_d.label = 6;
|
7040
6912
|
case 6:
|
7041
6913
|
if (_b) {
|
7042
6914
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
7043
6915
|
}
|
7044
|
-
|
6916
|
+
_d.label = 7;
|
7045
6917
|
case 7:
|
7046
6918
|
positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
|
7047
6919
|
orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
|
7048
6920
|
custodyAccountMetas = [];
|
7049
6921
|
custodyOracleAccountMetas = [];
|
7050
|
-
for (
|
7051
|
-
custody =
|
6922
|
+
for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
|
6923
|
+
custody = _c[_i];
|
7052
6924
|
custodyAccountMetas.push({
|
7053
6925
|
pubkey: custody.custodyAccount,
|
7054
6926
|
isSigner: false,
|
@@ -7093,11 +6965,11 @@ var PerpetualsClient = (function () {
|
|
7093
6965
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
|
7094
6966
|
.instruction()];
|
7095
6967
|
case 8:
|
7096
|
-
executeTriggerWithSwap =
|
6968
|
+
executeTriggerWithSwap = _d.sent();
|
7097
6969
|
instructions.push(executeTriggerWithSwap);
|
7098
6970
|
return [3, 10];
|
7099
6971
|
case 9:
|
7100
|
-
err_53 =
|
6972
|
+
err_53 = _d.sent();
|
7101
6973
|
console.log("perpClient executeTriggerWithSwap error:: ", err_53);
|
7102
6974
|
throw err_53;
|
7103
6975
|
case 10: return [2, {
|
@@ -7108,18 +6980,14 @@ var PerpetualsClient = (function () {
|
|
7108
6980
|
});
|
7109
6981
|
});
|
7110
6982
|
};
|
7111
|
-
this.executeTriggerOrder = function (
|
7112
|
-
|
7113
|
-
|
7114
|
-
|
7115
|
-
}
|
7116
|
-
|
6983
|
+
this.executeTriggerOrder = function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6984
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6985
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6986
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6987
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6988
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6989
|
+
return __awaiter(_this, void 0, void 0, function () {
|
7117
6990
|
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_54;
|
7118
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
7119
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7120
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
7121
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
7122
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
7123
6991
|
return __generator(this, function (_b) {
|
7124
6992
|
switch (_b.label) {
|
7125
6993
|
case 0:
|
@@ -7542,18 +7410,136 @@ var PerpetualsClient = (function () {
|
|
7542
7410
|
}
|
7543
7411
|
});
|
7544
7412
|
}); };
|
7545
|
-
this.
|
7546
|
-
var
|
7547
|
-
|
7548
|
-
|
7549
|
-
|
7550
|
-
|
7551
|
-
|
7552
|
-
|
7553
|
-
|
7554
|
-
|
7555
|
-
|
7556
|
-
|
7413
|
+
this.setInternalOraclePriceBatch = function (tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7414
|
+
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_63;
|
7415
|
+
return __generator(this, function (_a) {
|
7416
|
+
switch (_a.label) {
|
7417
|
+
case 0:
|
7418
|
+
if (tokenMintList.length !== tokenInternalPrices.length) {
|
7419
|
+
throw new Error("tokenMintList and tokenInternalPrices length mismatch");
|
7420
|
+
}
|
7421
|
+
ALL_CUSTODY_CONFIGS = POOL_CONFIGS.map(function (f) { return f.custodies; }).flat();
|
7422
|
+
accountMetas = [];
|
7423
|
+
_loop_1 = function (tokenMint) {
|
7424
|
+
var custody = ALL_CUSTODY_CONFIGS.find(function (i) { return i.mintKey.equals(tokenMint); });
|
7425
|
+
accountMetas.push({
|
7426
|
+
pubkey: custody.custodyAccount,
|
7427
|
+
isSigner: false,
|
7428
|
+
isWritable: false,
|
7429
|
+
});
|
7430
|
+
accountMetas.push({
|
7431
|
+
pubkey: custody.intOracleAccount,
|
7432
|
+
isSigner: false,
|
7433
|
+
isWritable: true,
|
7434
|
+
});
|
7435
|
+
accountMetas.push({
|
7436
|
+
pubkey: custody.extOracleAccount,
|
7437
|
+
isSigner: false,
|
7438
|
+
isWritable: false,
|
7439
|
+
});
|
7440
|
+
};
|
7441
|
+
for (_i = 0, tokenMintList_1 = tokenMintList; _i < tokenMintList_1.length; _i++) {
|
7442
|
+
tokenMint = tokenMintList_1[_i];
|
7443
|
+
_loop_1(tokenMint);
|
7444
|
+
}
|
7445
|
+
instructions = [];
|
7446
|
+
additionalSigners = [];
|
7447
|
+
_a.label = 1;
|
7448
|
+
case 1:
|
7449
|
+
_a.trys.push([1, 3, , 4]);
|
7450
|
+
return [4, this.program.methods
|
7451
|
+
.setInternalCurrentPrice({
|
7452
|
+
prices: tokenInternalPrices
|
7453
|
+
})
|
7454
|
+
.accounts({
|
7455
|
+
authority: POOL_CONFIGS[0].backupOracle,
|
7456
|
+
})
|
7457
|
+
.remainingAccounts(__spreadArray([], accountMetas, true))
|
7458
|
+
.instruction()];
|
7459
|
+
case 2:
|
7460
|
+
setInternalOraclePrice = _a.sent();
|
7461
|
+
instructions.push(setInternalOraclePrice);
|
7462
|
+
return [3, 4];
|
7463
|
+
case 3:
|
7464
|
+
err_63 = _a.sent();
|
7465
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_63);
|
7466
|
+
throw err_63;
|
7467
|
+
case 4: return [2, {
|
7468
|
+
instructions: __spreadArray([], instructions, true),
|
7469
|
+
additionalSigners: additionalSigners
|
7470
|
+
}];
|
7471
|
+
}
|
7472
|
+
});
|
7473
|
+
}); };
|
7474
|
+
this.setInternalOracleEmaPriceBatch = function (tokenMintList, tokenInternalEmaPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7475
|
+
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_64;
|
7476
|
+
return __generator(this, function (_a) {
|
7477
|
+
switch (_a.label) {
|
7478
|
+
case 0:
|
7479
|
+
if (tokenMintList.length !== tokenInternalEmaPrices.length) {
|
7480
|
+
throw new Error("tokenMintList and tokenInternalPrices length mismatch");
|
7481
|
+
}
|
7482
|
+
ALL_CUSTODY_CONFIGS = POOL_CONFIGS.map(function (f) { return f.custodies; }).flat();
|
7483
|
+
accountMetas = [];
|
7484
|
+
_loop_2 = function (tokenMint) {
|
7485
|
+
var custody = ALL_CUSTODY_CONFIGS.find(function (i) { return i.mintKey.equals(tokenMint); });
|
7486
|
+
accountMetas.push({
|
7487
|
+
pubkey: custody.custodyAccount,
|
7488
|
+
isSigner: false,
|
7489
|
+
isWritable: false,
|
7490
|
+
});
|
7491
|
+
accountMetas.push({
|
7492
|
+
pubkey: custody.intOracleAccount,
|
7493
|
+
isSigner: false,
|
7494
|
+
isWritable: true,
|
7495
|
+
});
|
7496
|
+
accountMetas.push({
|
7497
|
+
pubkey: custody.extOracleAccount,
|
7498
|
+
isSigner: false,
|
7499
|
+
isWritable: false,
|
7500
|
+
});
|
7501
|
+
};
|
7502
|
+
for (_i = 0, tokenMintList_2 = tokenMintList; _i < tokenMintList_2.length; _i++) {
|
7503
|
+
tokenMint = tokenMintList_2[_i];
|
7504
|
+
_loop_2(tokenMint);
|
7505
|
+
}
|
7506
|
+
instructions = [];
|
7507
|
+
additionalSigners = [];
|
7508
|
+
_a.label = 1;
|
7509
|
+
case 1:
|
7510
|
+
_a.trys.push([1, 3, , 4]);
|
7511
|
+
return [4, this.program.methods
|
7512
|
+
.setInternalEmaPrice({
|
7513
|
+
prices: tokenInternalEmaPrices
|
7514
|
+
})
|
7515
|
+
.accounts({
|
7516
|
+
authority: POOL_CONFIGS[0].backupOracle,
|
7517
|
+
})
|
7518
|
+
.remainingAccounts(__spreadArray([], accountMetas, true))
|
7519
|
+
.instruction()];
|
7520
|
+
case 2:
|
7521
|
+
setInternalOraclePrice = _a.sent();
|
7522
|
+
instructions.push(setInternalOraclePrice);
|
7523
|
+
return [3, 4];
|
7524
|
+
case 3:
|
7525
|
+
err_64 = _a.sent();
|
7526
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_64);
|
7527
|
+
throw err_64;
|
7528
|
+
case 4: return [2, {
|
7529
|
+
instructions: __spreadArray([], instructions, true),
|
7530
|
+
additionalSigners: additionalSigners
|
7531
|
+
}];
|
7532
|
+
}
|
7533
|
+
});
|
7534
|
+
}); };
|
7535
|
+
this.addCompoundingLiquidity = function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
7536
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
7537
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7538
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
7539
|
+
return __awaiter(_this, void 0, void 0, function () {
|
7540
|
+
var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, addCompoundingLiquidity, err_65;
|
7541
|
+
return __generator(this, function (_e) {
|
7542
|
+
switch (_e.label) {
|
7557
7543
|
case 0:
|
7558
7544
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
7559
7545
|
preInstructions = [];
|
@@ -7570,8 +7556,8 @@ var PerpetualsClient = (function () {
|
|
7570
7556
|
custodyAccountMetas = [];
|
7571
7557
|
custodyOracleAccountMetas = [];
|
7572
7558
|
markets = [];
|
7573
|
-
for (
|
7574
|
-
custody =
|
7559
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
7560
|
+
custody = _a[_i];
|
7575
7561
|
custodyAccountMetas.push({
|
7576
7562
|
pubkey: custody.custodyAccount,
|
7577
7563
|
isSigner: false,
|
@@ -7583,8 +7569,8 @@ var PerpetualsClient = (function () {
|
|
7583
7569
|
isWritable: false,
|
7584
7570
|
});
|
7585
7571
|
}
|
7586
|
-
for (
|
7587
|
-
market =
|
7572
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
7573
|
+
market = _c[_b];
|
7588
7574
|
markets.push({
|
7589
7575
|
pubkey: market.marketAccount,
|
7590
7576
|
isSigner: false,
|
@@ -7593,26 +7579,26 @@ var PerpetualsClient = (function () {
|
|
7593
7579
|
}
|
7594
7580
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
7595
7581
|
case 1:
|
7596
|
-
if (!(
|
7582
|
+
if (!(_e.sent())) {
|
7597
7583
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
7598
7584
|
}
|
7599
7585
|
return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
|
7600
7586
|
case 2:
|
7601
|
-
if (!(
|
7587
|
+
if (!(_e.sent())) {
|
7602
7588
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
|
7603
7589
|
}
|
7604
7590
|
if (!(inTokenSymbol == 'SOL')) return [3, 5];
|
7605
7591
|
console.log("inTokenSymbol === SOL", inTokenSymbol);
|
7606
7592
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
7607
7593
|
if (!!skipBalanceChecks) return [3, 4];
|
7608
|
-
|
7594
|
+
_d = anchor_1.BN.bind;
|
7609
7595
|
return [4, this.provider.connection.getBalance(publicKey)];
|
7610
7596
|
case 3:
|
7611
|
-
unWrappedSolBalance = new (
|
7597
|
+
unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _e.sent()]))();
|
7612
7598
|
if (unWrappedSolBalance.lt(lamports)) {
|
7613
7599
|
throw "Insufficient SOL Funds";
|
7614
7600
|
}
|
7615
|
-
|
7601
|
+
_e.label = 4;
|
7616
7602
|
case 4:
|
7617
7603
|
if (!ephemeralSignerPubkey) {
|
7618
7604
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -7636,12 +7622,12 @@ var PerpetualsClient = (function () {
|
|
7636
7622
|
if (!!skipBalanceChecks) return [3, 7];
|
7637
7623
|
return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
|
7638
7624
|
case 6:
|
7639
|
-
if (!(
|
7625
|
+
if (!(_e.sent())) {
|
7640
7626
|
throw "Insufficient Funds , token Account doesn't exist";
|
7641
7627
|
}
|
7642
|
-
|
7628
|
+
_e.label = 7;
|
7643
7629
|
case 7:
|
7644
|
-
|
7630
|
+
_e.trys.push([7, 9, , 10]);
|
7645
7631
|
return [4, this.program.methods
|
7646
7632
|
.addCompoundingLiquidity({
|
7647
7633
|
amountIn: amountIn,
|
@@ -7670,12 +7656,12 @@ var PerpetualsClient = (function () {
|
|
7670
7656
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
7671
7657
|
.instruction()];
|
7672
7658
|
case 8:
|
7673
|
-
addCompoundingLiquidity =
|
7659
|
+
addCompoundingLiquidity = _e.sent();
|
7674
7660
|
instructions.push(addCompoundingLiquidity);
|
7675
7661
|
return [3, 10];
|
7676
7662
|
case 9:
|
7677
|
-
|
7678
|
-
console.log("perpClient addCompoundingLiquidity error:: ",
|
7663
|
+
err_65 = _e.sent();
|
7664
|
+
console.log("perpClient addCompoundingLiquidity error:: ", err_65);
|
7679
7665
|
return [3, 10];
|
7680
7666
|
case 10: return [2, {
|
7681
7667
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -7685,18 +7671,14 @@ var PerpetualsClient = (function () {
|
|
7685
7671
|
});
|
7686
7672
|
});
|
7687
7673
|
};
|
7688
|
-
this.removeCompoundingLiquidity = function (
|
7689
|
-
|
7690
|
-
|
7691
|
-
|
7692
|
-
|
7693
|
-
|
7694
|
-
|
7695
|
-
|
7696
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7697
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
7698
|
-
return __generator(this, function (_f) {
|
7699
|
-
switch (_f.label) {
|
7674
|
+
this.removeCompoundingLiquidity = function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey, userPublicKey) {
|
7675
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
7676
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7677
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
7678
|
+
return __awaiter(_this, void 0, void 0, function () {
|
7679
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, compoundingTokenAccount, removeCompoundingLiquidity, err_66;
|
7680
|
+
return __generator(this, function (_e) {
|
7681
|
+
switch (_e.label) {
|
7700
7682
|
case 0:
|
7701
7683
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
7702
7684
|
preInstructions = [];
|
@@ -7733,19 +7715,19 @@ var PerpetualsClient = (function () {
|
|
7733
7715
|
if (!_a) return [3, 3];
|
7734
7716
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
7735
7717
|
case 2:
|
7736
|
-
_a = !(
|
7737
|
-
|
7718
|
+
_a = !(_e.sent());
|
7719
|
+
_e.label = 3;
|
7738
7720
|
case 3:
|
7739
7721
|
if (_a) {
|
7740
7722
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
|
7741
7723
|
}
|
7742
|
-
|
7724
|
+
_e.label = 4;
|
7743
7725
|
case 4:
|
7744
7726
|
custodyAccountMetas = [];
|
7745
7727
|
custodyOracleAccountMetas = [];
|
7746
7728
|
markets = [];
|
7747
|
-
for (
|
7748
|
-
custody =
|
7729
|
+
for (_i = 0, _b = poolConfig.custodies; _i < _b.length; _i++) {
|
7730
|
+
custody = _b[_i];
|
7749
7731
|
custodyAccountMetas.push({
|
7750
7732
|
pubkey: custody.custodyAccount,
|
7751
7733
|
isSigner: false,
|
@@ -7757,8 +7739,8 @@ var PerpetualsClient = (function () {
|
|
7757
7739
|
isWritable: false,
|
7758
7740
|
});
|
7759
7741
|
}
|
7760
|
-
for (
|
7761
|
-
market =
|
7742
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
7743
|
+
market = _d[_c];
|
7762
7744
|
markets.push({
|
7763
7745
|
pubkey: market.marketAccount,
|
7764
7746
|
isSigner: false,
|
@@ -7766,9 +7748,9 @@ var PerpetualsClient = (function () {
|
|
7766
7748
|
});
|
7767
7749
|
}
|
7768
7750
|
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
7769
|
-
|
7751
|
+
_e.label = 5;
|
7770
7752
|
case 5:
|
7771
|
-
|
7753
|
+
_e.trys.push([5, 7, , 8]);
|
7772
7754
|
return [4, this.program.methods
|
7773
7755
|
.removeCompoundingLiquidity({
|
7774
7756
|
compoundingAmountIn: compoundingAmountIn,
|
@@ -7797,12 +7779,12 @@ var PerpetualsClient = (function () {
|
|
7797
7779
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
7798
7780
|
.instruction()];
|
7799
7781
|
case 6:
|
7800
|
-
removeCompoundingLiquidity =
|
7782
|
+
removeCompoundingLiquidity = _e.sent();
|
7801
7783
|
instructions.push(removeCompoundingLiquidity);
|
7802
7784
|
return [3, 8];
|
7803
7785
|
case 7:
|
7804
|
-
|
7805
|
-
console.log("perpClient removeCompoundingLiquidity error:: ",
|
7786
|
+
err_66 = _e.sent();
|
7787
|
+
console.log("perpClient removeCompoundingLiquidity error:: ", err_66);
|
7806
7788
|
return [3, 8];
|
7807
7789
|
case 8: return [2, {
|
7808
7790
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -7812,16 +7794,12 @@ var PerpetualsClient = (function () {
|
|
7812
7794
|
});
|
7813
7795
|
});
|
7814
7796
|
};
|
7815
|
-
this.migrateStake = function (
|
7816
|
-
|
7817
|
-
|
7818
|
-
|
7819
|
-
|
7820
|
-
|
7821
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _b, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, migrateStake, err_65;
|
7822
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
7823
|
-
return __generator(this, function (_g) {
|
7824
|
-
switch (_g.label) {
|
7797
|
+
this.migrateStake = function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
7798
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
7799
|
+
return __awaiter(_this, void 0, void 0, function () {
|
7800
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _b, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _c, custody, _d, _e, market, migrateStake, err_67;
|
7801
|
+
return __generator(this, function (_f) {
|
7802
|
+
switch (_f.label) {
|
7825
7803
|
case 0:
|
7826
7804
|
publicKey = this.provider.wallet.publicKey;
|
7827
7805
|
preInstructions = [];
|
@@ -7836,8 +7814,8 @@ var PerpetualsClient = (function () {
|
|
7836
7814
|
if (!_a) return [3, 2];
|
7837
7815
|
return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
|
7838
7816
|
case 1:
|
7839
|
-
_a = !(
|
7840
|
-
|
7817
|
+
_a = !(_f.sent());
|
7818
|
+
_f.label = 2;
|
7841
7819
|
case 2:
|
7842
7820
|
if (_a) {
|
7843
7821
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
|
@@ -7849,8 +7827,8 @@ var PerpetualsClient = (function () {
|
|
7849
7827
|
if (!_b) return [3, 4];
|
7850
7828
|
return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
|
7851
7829
|
case 3:
|
7852
|
-
_b = (
|
7853
|
-
|
7830
|
+
_b = (_f.sent());
|
7831
|
+
_f.label = 4;
|
7854
7832
|
case 4:
|
7855
7833
|
if (_b) {
|
7856
7834
|
tokenStakeAccounts.push({
|
@@ -7863,8 +7841,8 @@ var PerpetualsClient = (function () {
|
|
7863
7841
|
custodyAccountMetas = [];
|
7864
7842
|
custodyOracleAccountMetas = [];
|
7865
7843
|
markets = [];
|
7866
|
-
for (
|
7867
|
-
custody =
|
7844
|
+
for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
|
7845
|
+
custody = _c[_i];
|
7868
7846
|
custodyAccountMetas.push({
|
7869
7847
|
pubkey: custody.custodyAccount,
|
7870
7848
|
isSigner: false,
|
@@ -7876,17 +7854,17 @@ var PerpetualsClient = (function () {
|
|
7876
7854
|
isWritable: false,
|
7877
7855
|
});
|
7878
7856
|
}
|
7879
|
-
for (
|
7880
|
-
market =
|
7857
|
+
for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
|
7858
|
+
market = _e[_d];
|
7881
7859
|
markets.push({
|
7882
7860
|
pubkey: market.marketAccount,
|
7883
7861
|
isSigner: false,
|
7884
7862
|
isWritable: false,
|
7885
7863
|
});
|
7886
7864
|
}
|
7887
|
-
|
7865
|
+
_f.label = 5;
|
7888
7866
|
case 5:
|
7889
|
-
|
7867
|
+
_f.trys.push([5, 7, , 8]);
|
7890
7868
|
return [4, this.program.methods
|
7891
7869
|
.migrateStake({
|
7892
7870
|
amount: amount
|
@@ -7912,12 +7890,12 @@ var PerpetualsClient = (function () {
|
|
7912
7890
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
|
7913
7891
|
.instruction()];
|
7914
7892
|
case 6:
|
7915
|
-
migrateStake =
|
7893
|
+
migrateStake = _f.sent();
|
7916
7894
|
instructions.push(migrateStake);
|
7917
7895
|
return [3, 8];
|
7918
7896
|
case 7:
|
7919
|
-
|
7920
|
-
console.log("perpClient migrateStake error:: ",
|
7897
|
+
err_67 = _f.sent();
|
7898
|
+
console.log("perpClient migrateStake error:: ", err_67);
|
7921
7899
|
return [3, 8];
|
7922
7900
|
case 8: return [2, {
|
7923
7901
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -7928,7 +7906,7 @@ var PerpetualsClient = (function () {
|
|
7928
7906
|
});
|
7929
7907
|
};
|
7930
7908
|
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7931
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp,
|
7909
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_68;
|
7932
7910
|
return __generator(this, function (_d) {
|
7933
7911
|
switch (_d.label) {
|
7934
7912
|
case 0:
|
@@ -8000,8 +7978,8 @@ var PerpetualsClient = (function () {
|
|
8000
7978
|
instructions.push(migrateFlp);
|
8001
7979
|
return [3, 4];
|
8002
7980
|
case 3:
|
8003
|
-
|
8004
|
-
console.log("perpClient migrateFlp error:: ",
|
7981
|
+
err_68 = _d.sent();
|
7982
|
+
console.log("perpClient migrateFlp error:: ", err_68);
|
8005
7983
|
return [3, 4];
|
8006
7984
|
case 4: return [2, {
|
8007
7985
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -8010,16 +7988,12 @@ var PerpetualsClient = (function () {
|
|
8010
7988
|
}
|
8011
7989
|
});
|
8012
7990
|
}); };
|
8013
|
-
this.compoundingFee = function (
|
8014
|
-
|
8015
|
-
|
8016
|
-
|
8017
|
-
|
8018
|
-
|
8019
|
-
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_67;
|
8020
|
-
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
8021
|
-
return __generator(this, function (_e) {
|
8022
|
-
switch (_e.label) {
|
7991
|
+
this.compoundingFee = function (poolConfig, rewardTokenSymbol) {
|
7992
|
+
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
7993
|
+
return __awaiter(_this, void 0, void 0, function () {
|
7994
|
+
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, compoundingFee, err_69;
|
7995
|
+
return __generator(this, function (_d) {
|
7996
|
+
switch (_d.label) {
|
8023
7997
|
case 0:
|
8024
7998
|
instructions = [];
|
8025
7999
|
additionalSigners = [];
|
@@ -8028,8 +8002,8 @@ var PerpetualsClient = (function () {
|
|
8028
8002
|
custodyAccountMetas = [];
|
8029
8003
|
custodyOracleAccountMetas = [];
|
8030
8004
|
markets = [];
|
8031
|
-
for (
|
8032
|
-
custody =
|
8005
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
8006
|
+
custody = _a[_i];
|
8033
8007
|
custodyAccountMetas.push({
|
8034
8008
|
pubkey: custody.custodyAccount,
|
8035
8009
|
isSigner: false,
|
@@ -8041,17 +8015,17 @@ var PerpetualsClient = (function () {
|
|
8041
8015
|
isWritable: false,
|
8042
8016
|
});
|
8043
8017
|
}
|
8044
|
-
for (
|
8045
|
-
market =
|
8018
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
8019
|
+
market = _c[_b];
|
8046
8020
|
markets.push({
|
8047
8021
|
pubkey: market.marketAccount,
|
8048
8022
|
isSigner: false,
|
8049
8023
|
isWritable: false,
|
8050
8024
|
});
|
8051
8025
|
}
|
8052
|
-
|
8026
|
+
_d.label = 1;
|
8053
8027
|
case 1:
|
8054
|
-
|
8028
|
+
_d.trys.push([1, 3, , 4]);
|
8055
8029
|
return [4, this.program.methods
|
8056
8030
|
.compoundFees({})
|
8057
8031
|
.accounts({
|
@@ -8070,12 +8044,12 @@ var PerpetualsClient = (function () {
|
|
8070
8044
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
8071
8045
|
.instruction()];
|
8072
8046
|
case 2:
|
8073
|
-
compoundingFee =
|
8047
|
+
compoundingFee = _d.sent();
|
8074
8048
|
instructions.push(compoundingFee);
|
8075
8049
|
return [3, 4];
|
8076
8050
|
case 3:
|
8077
|
-
|
8078
|
-
console.log("perpClient compoundingFee error:: ",
|
8051
|
+
err_69 = _d.sent();
|
8052
|
+
console.log("perpClient compoundingFee error:: ", err_69);
|
8079
8053
|
return [3, 4];
|
8080
8054
|
case 4: return [2, {
|
8081
8055
|
instructions: __spreadArray([], instructions, true),
|
@@ -8086,7 +8060,7 @@ var PerpetualsClient = (function () {
|
|
8086
8060
|
});
|
8087
8061
|
};
|
8088
8062
|
this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8089
|
-
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp,
|
8063
|
+
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_70;
|
8090
8064
|
return __generator(this, function (_a) {
|
8091
8065
|
switch (_a.label) {
|
8092
8066
|
case 0:
|
@@ -8124,8 +8098,8 @@ var PerpetualsClient = (function () {
|
|
8124
8098
|
instructions.push(renameFlp);
|
8125
8099
|
return [3, 4];
|
8126
8100
|
case 3:
|
8127
|
-
|
8128
|
-
console.log("perpClient renameFlp error:: ",
|
8101
|
+
err_70 = _a.sent();
|
8102
|
+
console.log("perpClient renameFlp error:: ", err_70);
|
8129
8103
|
return [3, 4];
|
8130
8104
|
case 4: return [2, {
|
8131
8105
|
instructions: __spreadArray([], instructions, true),
|
@@ -8235,9 +8209,9 @@ var PerpetualsClient = (function () {
|
|
8235
8209
|
}
|
8236
8210
|
}
|
8237
8211
|
};
|
8238
|
-
PerpetualsClient.prototype.sendTransaction = function (
|
8239
|
-
|
8240
|
-
|
8212
|
+
PerpetualsClient.prototype.sendTransaction = function (ixs, opts) {
|
8213
|
+
if (opts === void 0) { opts = {}; }
|
8214
|
+
return __awaiter(this, void 0, void 0, function () {
|
8241
8215
|
return __generator(this, function (_a) {
|
8242
8216
|
switch (_a.label) {
|
8243
8217
|
case 0: return [4, (0, rpc_1.sendTransaction)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
|
@@ -8246,9 +8220,9 @@ var PerpetualsClient = (function () {
|
|
8246
8220
|
});
|
8247
8221
|
});
|
8248
8222
|
};
|
8249
|
-
PerpetualsClient.prototype.sendTransactionV3 = function (
|
8250
|
-
|
8251
|
-
|
8223
|
+
PerpetualsClient.prototype.sendTransactionV3 = function (ixs, opts) {
|
8224
|
+
if (opts === void 0) { opts = {}; }
|
8225
|
+
return __awaiter(this, void 0, void 0, function () {
|
8252
8226
|
return __generator(this, function (_a) {
|
8253
8227
|
switch (_a.label) {
|
8254
8228
|
case 0: return [4, (0, rpc_1.sendTransactionV3)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
|