flash-sdk 2.15.3 → 2.16.0
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 +2 -1
- package/dist/PerpetualsClient.js +355 -417
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -89,7 +89,7 @@ var PerpetualsClient = (function () {
|
|
89
89
|
_this.prioritizationFee = fee;
|
90
90
|
};
|
91
91
|
this.loadAddressLookupTable = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
92
|
-
var addresses, _i, _a, address, addressLookupTable;
|
92
|
+
var addresses, _i, _a, address, addressLookupTable, accCreationLamports;
|
93
93
|
return __generator(this, function (_b) {
|
94
94
|
switch (_b.label) {
|
95
95
|
case 0:
|
@@ -111,6 +111,12 @@ var PerpetualsClient = (function () {
|
|
111
111
|
return [3, 1];
|
112
112
|
case 4:
|
113
113
|
this.addressLookupTables = addresses;
|
114
|
+
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
115
|
+
case 5:
|
116
|
+
accCreationLamports = (_b.sent());
|
117
|
+
if (accCreationLamports) {
|
118
|
+
this.minimumBalanceForRentExemptAccountLamports = accCreationLamports;
|
119
|
+
}
|
114
120
|
return [2];
|
115
121
|
}
|
116
122
|
});
|
@@ -2227,7 +2233,7 @@ var PerpetualsClient = (function () {
|
|
2227
2233
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2228
2234
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2229
2235
|
return __awaiter(_this, void 0, void 0, function () {
|
2230
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners,
|
2236
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
2231
2237
|
return __generator(this, function (_c) {
|
2232
2238
|
switch (_c.label) {
|
2233
2239
|
case 0:
|
@@ -2244,18 +2250,17 @@ var PerpetualsClient = (function () {
|
|
2244
2250
|
additionalSigners = [];
|
2245
2251
|
if (!(collateralSymbol == 'SOL')) return [3, 4];
|
2246
2252
|
console.log("collateralSymbol === SOL", collateralSymbol);
|
2247
|
-
|
2248
|
-
|
2249
|
-
accCreationLamports = (_c.sent());
|
2250
|
-
console.log("accCreationLamports:", accCreationLamports);
|
2251
|
-
lamports = collateralWithfee.add(new anchor_1.BN(accCreationLamports));
|
2253
|
+
lamports = collateralWithfee.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
2254
|
+
if (!!skipBalanceChecks) return [3, 3];
|
2252
2255
|
_a = anchor_1.BN.bind;
|
2253
2256
|
return [4, this.provider.connection.getBalance(publicKey)];
|
2254
|
-
case
|
2257
|
+
case 2:
|
2255
2258
|
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
|
2256
2259
|
if (unWrappedSolBalance.lt(lamports)) {
|
2257
2260
|
throw "Insufficient SOL Funds";
|
2258
2261
|
}
|
2262
|
+
_c.label = 3;
|
2263
|
+
case 3:
|
2259
2264
|
if (!ephemeralSignerPubkey) {
|
2260
2265
|
wrappedSolAccount = new web3_js_1.Keypair();
|
2261
2266
|
additionalSigners.push(wrappedSolAccount);
|
@@ -2274,12 +2279,13 @@ var PerpetualsClient = (function () {
|
|
2274
2279
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2275
2280
|
];
|
2276
2281
|
return [3, 7];
|
2277
|
-
case 4:
|
2282
|
+
case 4:
|
2283
|
+
if (!!skipBalanceChecks) return [3, 7];
|
2284
|
+
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
2278
2285
|
case 5:
|
2279
2286
|
if (!(_c.sent())) {
|
2280
2287
|
throw "Insufficient Funds , token Account doesn't exist";
|
2281
2288
|
}
|
2282
|
-
if (!!skipBalanceChecks) return [3, 7];
|
2283
2289
|
_b = anchor_1.BN.bind;
|
2284
2290
|
return [4, this.provider.connection.getTokenAccountBalance(userCollateralTokenAccount)];
|
2285
2291
|
case 6:
|
@@ -2338,7 +2344,7 @@ var PerpetualsClient = (function () {
|
|
2338
2344
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2339
2345
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2340
2346
|
return __awaiter(_this, void 0, void 0, function () {
|
2341
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, swapOutCustodyConfig, swapInCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount,
|
2347
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, swapOutCustodyConfig, swapInCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userOutputTokenAccount, marketAccount, positionAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, instruction;
|
2342
2348
|
return __generator(this, function (_d) {
|
2343
2349
|
switch (_d.label) {
|
2344
2350
|
case 0:
|
@@ -2356,18 +2362,17 @@ var PerpetualsClient = (function () {
|
|
2356
2362
|
additionalSigners = [];
|
2357
2363
|
if (!(inputSymbol == 'SOL')) return [3, 3];
|
2358
2364
|
console.log("inputSymbol === SOL", inputSymbol);
|
2359
|
-
|
2360
|
-
|
2361
|
-
accCreationLamports = (_d.sent());
|
2362
|
-
console.log("accCreationLamports:", accCreationLamports);
|
2363
|
-
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
2365
|
+
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
2366
|
+
if (!!skipBalanceChecks) return [3, 2];
|
2364
2367
|
_a = anchor_1.BN.bind;
|
2365
2368
|
return [4, this.provider.connection.getBalance(publicKey)];
|
2366
|
-
case
|
2369
|
+
case 1:
|
2367
2370
|
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _d.sent()]))();
|
2368
2371
|
if (unWrappedSolBalance.lt(lamports)) {
|
2369
2372
|
throw "Insufficient SOL Funds";
|
2370
2373
|
}
|
2374
|
+
_d.label = 2;
|
2375
|
+
case 2:
|
2371
2376
|
if (!ephemeralSignerPubkey) {
|
2372
2377
|
wrappedSolAccount = new web3_js_1.Keypair();
|
2373
2378
|
additionalSigners.push(wrappedSolAccount);
|
@@ -2388,12 +2393,12 @@ var PerpetualsClient = (function () {
|
|
2388
2393
|
return [3, 6];
|
2389
2394
|
case 3:
|
2390
2395
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(inputSymbol).mintKey, publicKey, true);
|
2396
|
+
if (!!skipBalanceChecks) return [3, 6];
|
2391
2397
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
2392
2398
|
case 4:
|
2393
2399
|
if (!(_d.sent())) {
|
2394
2400
|
throw "Insufficient Funds , Token Account doesn't exist";
|
2395
2401
|
}
|
2396
|
-
if (!!skipBalanceChecks) return [3, 6];
|
2397
2402
|
_b = anchor_1.BN.bind;
|
2398
2403
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
2399
2404
|
case 5:
|
@@ -2410,7 +2415,6 @@ var PerpetualsClient = (function () {
|
|
2410
2415
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).mintKey));
|
2411
2416
|
}
|
2412
2417
|
marketAccount = positionPoolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
2413
|
-
console.log('marketAccount :>> ', marketAccount.toBase58(), targetCustodyConfig.custodyAccount.toBase58(), collateralCustodyConfig.custodyAccount.toBase58());
|
2414
2418
|
positionAccount = positionPoolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
2415
2419
|
custodyAccountMetas = [];
|
2416
2420
|
custodyOracleAccountMetas = [];
|
@@ -2495,11 +2499,9 @@ var PerpetualsClient = (function () {
|
|
2495
2499
|
additionalSigners = [];
|
2496
2500
|
_b.label = 1;
|
2497
2501
|
case 1:
|
2498
|
-
_b.trys.push([1,
|
2499
|
-
if (!(collateralSymbol == 'SOL')) return [3,
|
2500
|
-
|
2501
|
-
case 2:
|
2502
|
-
lamports = (_b.sent());
|
2502
|
+
_b.trys.push([1, 7, , 8]);
|
2503
|
+
if (!(collateralSymbol == 'SOL')) return [3, 2];
|
2504
|
+
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
2503
2505
|
if (!ephemeralSignerPubkey) {
|
2504
2506
|
wrappedSolAccount = new web3_js_1.Keypair();
|
2505
2507
|
additionalSigners.push(wrappedSolAccount);
|
@@ -2517,22 +2519,21 @@ var PerpetualsClient = (function () {
|
|
2517
2519
|
postInstructions = [
|
2518
2520
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2519
2521
|
];
|
2520
|
-
return [3,
|
2521
|
-
case
|
2522
|
-
|
2523
|
-
userReceivingTokenAccount = _b.sent();
|
2522
|
+
return [3, 5];
|
2523
|
+
case 2:
|
2524
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
2524
2525
|
_a = createUserATA;
|
2525
|
-
if (!_a) return [3,
|
2526
|
+
if (!_a) return [3, 4];
|
2526
2527
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
2527
|
-
case
|
2528
|
+
case 3:
|
2528
2529
|
_a = !(_b.sent());
|
2529
|
-
_b.label =
|
2530
|
-
case
|
2530
|
+
_b.label = 4;
|
2531
|
+
case 4:
|
2531
2532
|
if (_a) {
|
2532
2533
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
2533
2534
|
}
|
2534
|
-
_b.label =
|
2535
|
-
case
|
2535
|
+
_b.label = 5;
|
2536
|
+
case 5:
|
2536
2537
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
2537
2538
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(marketSymbol).mintKey); });
|
2538
2539
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
@@ -2563,19 +2564,19 @@ var PerpetualsClient = (function () {
|
|
2563
2564
|
})
|
2564
2565
|
.remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
|
2565
2566
|
.instruction()];
|
2566
|
-
case
|
2567
|
+
case 6:
|
2567
2568
|
instruction = _b.sent();
|
2568
2569
|
instructions.push(instruction);
|
2569
2570
|
if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
|
2570
2571
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
|
2571
2572
|
postInstructions.push(closeWsolATAIns);
|
2572
2573
|
}
|
2573
|
-
return [3,
|
2574
|
-
case
|
2574
|
+
return [3, 8];
|
2575
|
+
case 7:
|
2575
2576
|
error_2 = _b.sent();
|
2576
2577
|
console.error("perpclient closePosition error:", error_2);
|
2577
|
-
return [3,
|
2578
|
-
case
|
2578
|
+
return [3, 8];
|
2579
|
+
case 8: return [2, {
|
2579
2580
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
2580
2581
|
additionalSigners: additionalSigners
|
2581
2582
|
}];
|
@@ -2605,11 +2606,9 @@ var PerpetualsClient = (function () {
|
|
2605
2606
|
instructions = [];
|
2606
2607
|
postInstructions = [];
|
2607
2608
|
additionalSigners = [];
|
2608
|
-
if (!(outputSymbol == 'SOL')) return [3,
|
2609
|
+
if (!(outputSymbol == 'SOL')) return [3, 1];
|
2609
2610
|
console.log("outputSymbol === SOL", outputSymbol);
|
2610
|
-
|
2611
|
-
case 1:
|
2612
|
-
lamports = (_b.sent());
|
2611
|
+
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
2613
2612
|
if (!ephemeralSignerPubkey) {
|
2614
2613
|
wrappedSolAccount = new web3_js_1.Keypair();
|
2615
2614
|
additionalSigners.push(wrappedSolAccount);
|
@@ -2628,20 +2627,20 @@ var PerpetualsClient = (function () {
|
|
2628
2627
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2629
2628
|
];
|
2630
2629
|
additionalSigners.push(wrappedSolAccount);
|
2631
|
-
return [3,
|
2632
|
-
case
|
2633
|
-
case
|
2630
|
+
return [3, 4];
|
2631
|
+
case 1: return [4, (0, spl_token_1.getAssociatedTokenAddress)(swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true)];
|
2632
|
+
case 2:
|
2634
2633
|
userReceivingTokenAccount = _b.sent();
|
2635
2634
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
2636
|
-
case
|
2635
|
+
case 3:
|
2637
2636
|
if (!(_b.sent())) {
|
2638
2637
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey));
|
2639
2638
|
}
|
2640
|
-
_b.label =
|
2641
|
-
case
|
2639
|
+
_b.label = 4;
|
2640
|
+
case 4:
|
2642
2641
|
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
2643
2642
|
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
2644
|
-
case
|
2643
|
+
case 5:
|
2645
2644
|
if (!(_b.sent())) {
|
2646
2645
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
2647
2646
|
}
|
@@ -2696,7 +2695,7 @@ var PerpetualsClient = (function () {
|
|
2696
2695
|
})
|
2697
2696
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
2698
2697
|
.instruction()];
|
2699
|
-
case
|
2698
|
+
case 6:
|
2700
2699
|
instruction = _b.sent();
|
2701
2700
|
instructions.push(instruction);
|
2702
2701
|
return [2, {
|
@@ -2731,7 +2730,7 @@ var PerpetualsClient = (function () {
|
|
2731
2730
|
instructions = [];
|
2732
2731
|
postInstructions = [];
|
2733
2732
|
additionalSigners = [];
|
2734
|
-
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3,
|
2733
|
+
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
|
2735
2734
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
|
2736
2735
|
case 1:
|
2737
2736
|
wsolAssociatedTokenAccount = _f.sent();
|
@@ -2741,6 +2740,7 @@ var PerpetualsClient = (function () {
|
|
2741
2740
|
if (!wsolATAExist) {
|
2742
2741
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
2743
2742
|
}
|
2743
|
+
if (!!skipBalanceChecks) return [3, 4];
|
2744
2744
|
_a = anchor_1.BN.bind;
|
2745
2745
|
return [4, this.provider.connection.getBalance(publicKey)];
|
2746
2746
|
case 3:
|
@@ -2748,6 +2748,8 @@ var PerpetualsClient = (function () {
|
|
2748
2748
|
if (unWrappedSolBalance.lt(amountIn)) {
|
2749
2749
|
throw "Insufficient SOL Funds";
|
2750
2750
|
}
|
2751
|
+
_f.label = 4;
|
2752
|
+
case 4:
|
2751
2753
|
instructions.push(web3_js_1.SystemProgram.transfer({
|
2752
2754
|
fromPubkey: publicKey,
|
2753
2755
|
toPubkey: wsolAssociatedTokenAccount,
|
@@ -2757,20 +2759,20 @@ var PerpetualsClient = (function () {
|
|
2757
2759
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
2758
2760
|
additionalSigners: additionalSigners
|
2759
2761
|
}];
|
2760
|
-
case 4:
|
2761
|
-
if (!(userInputTokenSymbol == 'WSOL' && userOutputTokenSymbol == 'SOL')) return [3, 6];
|
2762
|
-
console.log("WSOL=> SOL : NOTE : ONLY WAY IS TO CLOSE THE WSOL ATA and GET ALL SOL ");
|
2763
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
|
2764
2762
|
case 5:
|
2765
|
-
|
2766
|
-
|
2767
|
-
|
2768
|
-
|
2769
|
-
|
2770
|
-
|
2771
|
-
|
2763
|
+
if (userInputTokenSymbol == 'WSOL' && userOutputTokenSymbol == 'SOL') {
|
2764
|
+
console.log("WSOL=> SOL : NOTE : ONLY WAY IS TO CLOSE THE WSOL ATA and GET ALL SOL ");
|
2765
|
+
wsolAssociatedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, publicKey, true);
|
2766
|
+
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(wsolAssociatedTokenAccount, publicKey, publicKey);
|
2767
|
+
instructions.push(closeWsolATAIns);
|
2768
|
+
return [2, {
|
2769
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
2770
|
+
additionalSigners: additionalSigners
|
2771
|
+
}];
|
2772
|
+
}
|
2773
|
+
_f.label = 6;
|
2772
2774
|
case 6:
|
2773
|
-
_f.trys.push([6,
|
2775
|
+
_f.trys.push([6, 19, , 20]);
|
2774
2776
|
if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
|
2775
2777
|
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
2776
2778
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
@@ -2803,29 +2805,26 @@ var PerpetualsClient = (function () {
|
|
2803
2805
|
postInstructions = [
|
2804
2806
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2805
2807
|
];
|
2806
|
-
return [3,
|
2807
|
-
case 9:
|
2808
|
-
|
2809
|
-
userInputTokenAccount = _f.sent();
|
2808
|
+
return [3, 12];
|
2809
|
+
case 9:
|
2810
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
|
2810
2811
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
2811
|
-
case
|
2812
|
+
case 10:
|
2812
2813
|
if (!(_f.sent())) {
|
2813
2814
|
throw "Insufficient Funds , Token Account doesn't exist";
|
2814
2815
|
}
|
2815
|
-
if (!!skipBalanceChecks) return [3,
|
2816
|
+
if (!!skipBalanceChecks) return [3, 12];
|
2816
2817
|
_c = anchor_1.BN.bind;
|
2817
2818
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
2818
|
-
case
|
2819
|
+
case 11:
|
2819
2820
|
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
2820
2821
|
if (tokenAccountBalance.lt(amountIn)) {
|
2821
2822
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
2822
2823
|
}
|
2823
|
-
_f.label =
|
2824
|
-
case
|
2825
|
-
if (!(userOutputTokenSymbol == 'SOL')) return [3,
|
2826
|
-
|
2827
|
-
case 14:
|
2828
|
-
lamports = (_f.sent());
|
2824
|
+
_f.label = 12;
|
2825
|
+
case 12:
|
2826
|
+
if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
|
2827
|
+
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
2829
2828
|
if (!ephemeralSignerPubkey) {
|
2830
2829
|
wrappedSolAccount = new web3_js_1.Keypair();
|
2831
2830
|
additionalSigners.push(wrappedSolAccount);
|
@@ -2844,22 +2843,22 @@ var PerpetualsClient = (function () {
|
|
2844
2843
|
postInstructions = [
|
2845
2844
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2846
2845
|
];
|
2847
|
-
return [3,
|
2848
|
-
case
|
2849
|
-
case
|
2846
|
+
return [3, 17];
|
2847
|
+
case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
|
2848
|
+
case 14:
|
2850
2849
|
userOutputTokenAccount = _f.sent();
|
2851
2850
|
_d = createUserATA;
|
2852
|
-
if (!_d) return [3,
|
2851
|
+
if (!_d) return [3, 16];
|
2853
2852
|
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
2854
|
-
case
|
2853
|
+
case 15:
|
2855
2854
|
_d = !(_f.sent());
|
2856
|
-
_f.label =
|
2857
|
-
case
|
2855
|
+
_f.label = 16;
|
2856
|
+
case 16:
|
2858
2857
|
if (_d) {
|
2859
2858
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
|
2860
2859
|
}
|
2861
|
-
_f.label =
|
2862
|
-
case
|
2860
|
+
_f.label = 17;
|
2861
|
+
case 17:
|
2863
2862
|
custodyAccountMetas = [];
|
2864
2863
|
custodyOracleAccountMetas = [];
|
2865
2864
|
for (_i = 0, _e = poolConfig.custodies; _i < _e.length; _i++) {
|
@@ -2902,19 +2901,19 @@ var PerpetualsClient = (function () {
|
|
2902
2901
|
})
|
2903
2902
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
2904
2903
|
.instruction()];
|
2905
|
-
case
|
2904
|
+
case 18:
|
2906
2905
|
inx = _f.sent();
|
2907
2906
|
instructions.push(inx);
|
2908
2907
|
if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
|
2909
2908
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
|
2910
2909
|
instructions.push(closeWsolATAIns);
|
2911
2910
|
}
|
2912
|
-
return [3,
|
2913
|
-
case
|
2911
|
+
return [3, 20];
|
2912
|
+
case 19:
|
2914
2913
|
err_2 = _f.sent();
|
2915
2914
|
console.error("perpClient Swap error:: ", err_2);
|
2916
2915
|
throw err_2;
|
2917
|
-
case
|
2916
|
+
case 20: return [2, {
|
2918
2917
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
2919
2918
|
additionalSigners: additionalSigners
|
2920
2919
|
}];
|
@@ -2997,7 +2996,7 @@ var PerpetualsClient = (function () {
|
|
2997
2996
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2998
2997
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2999
2998
|
return __awaiter(_this, void 0, void 0, function () {
|
3000
|
-
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners,
|
2999
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
|
3001
3000
|
return __generator(this, function (_c) {
|
3002
3001
|
switch (_c.label) {
|
3003
3002
|
case 0:
|
@@ -3013,25 +3012,20 @@ var PerpetualsClient = (function () {
|
|
3013
3012
|
instructions = [];
|
3014
3013
|
postInstructions = [];
|
3015
3014
|
additionalSigners = [];
|
3016
|
-
if (!(collateralSymbol == 'SOL')) return [3,
|
3015
|
+
if (!(collateralSymbol == 'SOL')) return [3, 3];
|
3017
3016
|
console.log("collateralSymbol === SOL", collateralSymbol);
|
3018
|
-
|
3019
|
-
case 1:
|
3020
|
-
accCreationLamports = (_c.sent());
|
3021
|
-
console.log("accCreationLamports:", accCreationLamports);
|
3022
|
-
lamports = collateralWithFee.add(new anchor_1.BN(accCreationLamports));
|
3017
|
+
lamports = collateralWithFee.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3023
3018
|
console.log("lamports:", lamports.toNumber());
|
3019
|
+
if (!!skipBalanceChecks) return [3, 2];
|
3024
3020
|
_a = anchor_1.BN.bind;
|
3025
3021
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3026
|
-
case
|
3022
|
+
case 1:
|
3027
3023
|
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
|
3028
3024
|
if (unWrappedSolBalance.lt(lamports)) {
|
3029
3025
|
throw "Insufficient SOL Funds";
|
3030
3026
|
}
|
3031
|
-
|
3032
|
-
case
|
3033
|
-
solBal = _c.sent();
|
3034
|
-
console.log("solBal>>:", solBal);
|
3027
|
+
_c.label = 2;
|
3028
|
+
case 2:
|
3035
3029
|
if (!ephemeralSignerPubkey) {
|
3036
3030
|
wrappedSolAccount = new web3_js_1.Keypair();
|
3037
3031
|
additionalSigners.push(wrappedSolAccount);
|
@@ -3049,22 +3043,23 @@ var PerpetualsClient = (function () {
|
|
3049
3043
|
postInstructions = [
|
3050
3044
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3051
3045
|
];
|
3052
|
-
return [3,
|
3053
|
-
case
|
3054
|
-
|
3046
|
+
return [3, 6];
|
3047
|
+
case 3:
|
3048
|
+
if (!!skipBalanceChecks) return [3, 6];
|
3049
|
+
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
3050
|
+
case 4:
|
3055
3051
|
if (!(_c.sent())) {
|
3056
3052
|
throw "Insufficient Funds , token Account doesn't exist";
|
3057
3053
|
}
|
3058
|
-
if (!!skipBalanceChecks) return [3, 7];
|
3059
3054
|
_b = anchor_1.BN.bind;
|
3060
3055
|
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
3061
|
-
case
|
3056
|
+
case 5:
|
3062
3057
|
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
3063
3058
|
if (tokenAccountBalance.lt(collateralWithFee)) {
|
3064
3059
|
throw "Insufficient Funds need more ".concat(collateralWithFee.sub(tokenAccountBalance), " tokens");
|
3065
3060
|
}
|
3066
|
-
_c.label =
|
3067
|
-
case
|
3061
|
+
_c.label = 6;
|
3062
|
+
case 6: return [4, this.program.methods.addCollateral({
|
3068
3063
|
collateralDelta: collateralWithFee
|
3069
3064
|
}).accounts({
|
3070
3065
|
owner: publicKey,
|
@@ -3084,7 +3079,7 @@ var PerpetualsClient = (function () {
|
|
3084
3079
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3085
3080
|
})
|
3086
3081
|
.instruction()];
|
3087
|
-
case
|
3082
|
+
case 7:
|
3088
3083
|
instruction = _c.sent();
|
3089
3084
|
instructions.push(instruction);
|
3090
3085
|
return [2, {
|
@@ -3099,7 +3094,7 @@ var PerpetualsClient = (function () {
|
|
3099
3094
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3100
3095
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3101
3096
|
return __awaiter(_this, void 0, void 0, function () {
|
3102
|
-
var publicKey, collateralCustodyConfig, targetCustodyConfig, outputCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount,
|
3097
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, outputCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, marketAccount, instruction;
|
3103
3098
|
return __generator(this, function (_d) {
|
3104
3099
|
switch (_d.label) {
|
3105
3100
|
case 0:
|
@@ -3120,19 +3115,18 @@ var PerpetualsClient = (function () {
|
|
3120
3115
|
additionalSigners = [];
|
3121
3116
|
if (!(inputSymbol == 'SOL')) return [3, 3];
|
3122
3117
|
console.log("inputSymbol === SOL", inputSymbol);
|
3123
|
-
|
3124
|
-
case 1:
|
3125
|
-
accCreationLamports = (_d.sent());
|
3126
|
-
console.log("accCreationLamports:", accCreationLamports);
|
3127
|
-
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
3118
|
+
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3128
3119
|
console.log("lamports:", lamports.toNumber());
|
3120
|
+
if (!!skipBalanceChecks) return [3, 2];
|
3129
3121
|
_a = anchor_1.BN.bind;
|
3130
3122
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3131
|
-
case
|
3123
|
+
case 1:
|
3132
3124
|
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _d.sent()]))();
|
3133
3125
|
if (unWrappedSolBalance.lt(lamports)) {
|
3134
3126
|
throw "Insufficient SOL Funds";
|
3135
3127
|
}
|
3128
|
+
_d.label = 2;
|
3129
|
+
case 2:
|
3136
3130
|
if (!ephemeralSignerPubkey) {
|
3137
3131
|
wrappedSolAccount = new web3_js_1.Keypair();
|
3138
3132
|
additionalSigners.push(wrappedSolAccount);
|
@@ -3153,12 +3147,12 @@ var PerpetualsClient = (function () {
|
|
3153
3147
|
return [3, 6];
|
3154
3148
|
case 3:
|
3155
3149
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
3150
|
+
if (!!skipBalanceChecks) return [3, 6];
|
3156
3151
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3157
3152
|
case 4:
|
3158
3153
|
if (!(_d.sent())) {
|
3159
3154
|
throw "Insufficient Funds , token Account doesn't exist";
|
3160
3155
|
}
|
3161
|
-
if (!!skipBalanceChecks) return [3, 6];
|
3162
3156
|
_b = anchor_1.BN.bind;
|
3163
3157
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3164
3158
|
case 5:
|
@@ -3257,14 +3251,12 @@ var PerpetualsClient = (function () {
|
|
3257
3251
|
additionalSigners = [];
|
3258
3252
|
_b.label = 1;
|
3259
3253
|
case 1:
|
3260
|
-
_b.trys.push([1,
|
3254
|
+
_b.trys.push([1, 7, , 8]);
|
3261
3255
|
console.log("removeCollateral -- collateralSymbol:", collateralSymbol);
|
3262
|
-
if (!(collateralSymbol == 'SOL')) return [3,
|
3256
|
+
if (!(collateralSymbol == 'SOL')) return [3, 2];
|
3263
3257
|
console.log("remove collateral in SOL ...create WSOL temp and close it ");
|
3264
3258
|
userReceivingTokenAccount = wrappedSolAccount.publicKey;
|
3265
|
-
|
3266
|
-
case 2:
|
3267
|
-
lamports = (_b.sent());
|
3259
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
3268
3260
|
if (!ephemeralSignerPubkey) {
|
3269
3261
|
wrappedSolAccount = new web3_js_1.Keypair();
|
3270
3262
|
additionalSigners.push(wrappedSolAccount);
|
@@ -3282,22 +3274,21 @@ var PerpetualsClient = (function () {
|
|
3282
3274
|
postInstructions = [
|
3283
3275
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3284
3276
|
];
|
3285
|
-
return [3,
|
3286
|
-
case
|
3287
|
-
|
3288
|
-
userReceivingTokenAccount = _b.sent();
|
3277
|
+
return [3, 5];
|
3278
|
+
case 2:
|
3279
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
3289
3280
|
_a = createUserATA;
|
3290
|
-
if (!_a) return [3,
|
3281
|
+
if (!_a) return [3, 4];
|
3291
3282
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
3292
|
-
case
|
3283
|
+
case 3:
|
3293
3284
|
_a = !(_b.sent());
|
3294
|
-
_b.label =
|
3295
|
-
case
|
3285
|
+
_b.label = 4;
|
3286
|
+
case 4:
|
3296
3287
|
if (_a) {
|
3297
3288
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
3298
3289
|
}
|
3299
|
-
_b.label =
|
3300
|
-
case
|
3290
|
+
_b.label = 5;
|
3291
|
+
case 5:
|
3301
3292
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3302
3293
|
return [4, this.program.methods
|
3303
3294
|
.removeCollateral({
|
@@ -3322,19 +3313,19 @@ var PerpetualsClient = (function () {
|
|
3322
3313
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3323
3314
|
})
|
3324
3315
|
.instruction()];
|
3325
|
-
case
|
3316
|
+
case 6:
|
3326
3317
|
instruction = _b.sent();
|
3327
3318
|
instructions.push(instruction);
|
3328
3319
|
if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
|
3329
3320
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
|
3330
3321
|
postInstructions.push(closeWsolATAIns);
|
3331
3322
|
}
|
3332
|
-
return [3,
|
3333
|
-
case
|
3323
|
+
return [3, 8];
|
3324
|
+
case 7:
|
3334
3325
|
error_3 = _b.sent();
|
3335
3326
|
console.error("perpclient removeCollateral error:", error_3);
|
3336
|
-
return [3,
|
3337
|
-
case
|
3327
|
+
return [3, 8];
|
3328
|
+
case 8: return [2, {
|
3338
3329
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3339
3330
|
additionalSigners: additionalSigners
|
3340
3331
|
}];
|
@@ -3361,11 +3352,9 @@ var PerpetualsClient = (function () {
|
|
3361
3352
|
instructions = [];
|
3362
3353
|
postInstructions = [];
|
3363
3354
|
additionalSigners = [];
|
3364
|
-
if (!(outputSymbol == 'SOL')) return [3,
|
3355
|
+
if (!(outputSymbol == 'SOL')) return [3, 1];
|
3365
3356
|
console.log("outputSymbol === SOL", outputSymbol);
|
3366
|
-
|
3367
|
-
case 1:
|
3368
|
-
lamports = (_b.sent());
|
3357
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
3369
3358
|
if (!ephemeralSignerPubkey) {
|
3370
3359
|
wrappedSolAccount = new web3_js_1.Keypair();
|
3371
3360
|
additionalSigners.push(wrappedSolAccount);
|
@@ -3383,20 +3372,19 @@ var PerpetualsClient = (function () {
|
|
3383
3372
|
postInstructions = [
|
3384
3373
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3385
3374
|
];
|
3386
|
-
return [3,
|
3387
|
-
case
|
3388
|
-
|
3389
|
-
userReceivingTokenAccount = _b.sent();
|
3375
|
+
return [3, 3];
|
3376
|
+
case 1:
|
3377
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true);
|
3390
3378
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
3391
|
-
case
|
3379
|
+
case 2:
|
3392
3380
|
if (!(_b.sent())) {
|
3393
3381
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey));
|
3394
3382
|
}
|
3395
|
-
_b.label =
|
3396
|
-
case
|
3383
|
+
_b.label = 3;
|
3384
|
+
case 3:
|
3397
3385
|
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
3398
3386
|
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3399
|
-
case
|
3387
|
+
case 4:
|
3400
3388
|
if (!(_b.sent())) {
|
3401
3389
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey));
|
3402
3390
|
}
|
@@ -3450,7 +3438,7 @@ var PerpetualsClient = (function () {
|
|
3450
3438
|
})
|
3451
3439
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
3452
3440
|
.instruction()];
|
3453
|
-
case
|
3441
|
+
case 5:
|
3454
3442
|
instruction = _b.sent();
|
3455
3443
|
instructions.push(instruction);
|
3456
3444
|
return [2, {
|
@@ -3585,7 +3573,7 @@ var PerpetualsClient = (function () {
|
|
3585
3573
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3586
3574
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3587
3575
|
return __awaiter(_this, void 0, void 0, function () {
|
3588
|
-
var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market,
|
3576
|
+
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_4;
|
3589
3577
|
return __generator(this, function (_f) {
|
3590
3578
|
switch (_f.label) {
|
3591
3579
|
case 0:
|
@@ -3600,13 +3588,9 @@ var PerpetualsClient = (function () {
|
|
3600
3588
|
additionalSigners = [];
|
3601
3589
|
_f.label = 1;
|
3602
3590
|
case 1:
|
3603
|
-
_f.trys.push([1,
|
3604
|
-
|
3605
|
-
|
3606
|
-
userPayingTokenAccount = _f.sent();
|
3607
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.stakedLpTokenMint, publicKey, true)];
|
3608
|
-
case 3:
|
3609
|
-
lpTokenAccount = _f.sent();
|
3591
|
+
_f.trys.push([1, 10, , 11]);
|
3592
|
+
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true);
|
3593
|
+
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
3610
3594
|
custodyAccountMetas = [];
|
3611
3595
|
custodyOracleAccountMetas = [];
|
3612
3596
|
markets = [];
|
@@ -3632,24 +3616,23 @@ var PerpetualsClient = (function () {
|
|
3632
3616
|
});
|
3633
3617
|
}
|
3634
3618
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
3635
|
-
case
|
3619
|
+
case 2:
|
3636
3620
|
if (!(_f.sent())) {
|
3637
3621
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
3638
3622
|
}
|
3639
|
-
if (!(payTokenSymbol == 'SOL')) return [3,
|
3623
|
+
if (!(payTokenSymbol == 'SOL')) return [3, 5];
|
3640
3624
|
console.log("payTokenSymbol === SOL", payTokenSymbol);
|
3641
|
-
|
3642
|
-
|
3643
|
-
accCreationLamports = (_f.sent());
|
3644
|
-
console.log("accCreationLamports:", accCreationLamports);
|
3645
|
-
lamports = tokenAmountIn.add(new anchor_1.BN(accCreationLamports));
|
3625
|
+
lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3626
|
+
if (!!skipBalanceChecks) return [3, 4];
|
3646
3627
|
_d = anchor_1.BN.bind;
|
3647
3628
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3648
|
-
case
|
3629
|
+
case 3:
|
3649
3630
|
unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
3650
3631
|
if (unWrappedSolBalance.lt(lamports)) {
|
3651
3632
|
throw "Insufficient SOL Funds";
|
3652
3633
|
}
|
3634
|
+
_f.label = 4;
|
3635
|
+
case 4:
|
3653
3636
|
if (!ephemeralSignerPubkey) {
|
3654
3637
|
wrappedSolAccount = new web3_js_1.Keypair();
|
3655
3638
|
additionalSigners.push(wrappedSolAccount);
|
@@ -3667,22 +3650,23 @@ var PerpetualsClient = (function () {
|
|
3667
3650
|
postInstructions = [
|
3668
3651
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3669
3652
|
];
|
3670
|
-
return [3,
|
3671
|
-
case
|
3672
|
-
|
3653
|
+
return [3, 8];
|
3654
|
+
case 5:
|
3655
|
+
if (!!skipBalanceChecks) return [3, 8];
|
3656
|
+
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
3657
|
+
case 6:
|
3673
3658
|
if (!(_f.sent())) {
|
3674
3659
|
throw "Insufficient Funds , token Account doesn't exist";
|
3675
3660
|
}
|
3676
|
-
if (!!skipBalanceChecks) return [3, 10];
|
3677
3661
|
_e = anchor_1.BN.bind;
|
3678
3662
|
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
3679
|
-
case
|
3663
|
+
case 7:
|
3680
3664
|
tokenAccountBalance = new (_e.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
3681
3665
|
if (tokenAccountBalance.lt(tokenAmountIn)) {
|
3682
3666
|
throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
|
3683
3667
|
}
|
3684
|
-
_f.label =
|
3685
|
-
case
|
3668
|
+
_f.label = 8;
|
3669
|
+
case 8: return [4, this.program.methods
|
3686
3670
|
.addLiquidity({
|
3687
3671
|
amountIn: tokenAmountIn,
|
3688
3672
|
minLpAmountOut: minLpAmountOut
|
@@ -3705,15 +3689,15 @@ var PerpetualsClient = (function () {
|
|
3705
3689
|
})
|
3706
3690
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
3707
3691
|
.instruction()];
|
3708
|
-
case
|
3692
|
+
case 9:
|
3709
3693
|
instruction = _f.sent();
|
3710
3694
|
instructions.push(instruction);
|
3711
|
-
return [3,
|
3712
|
-
case
|
3695
|
+
return [3, 11];
|
3696
|
+
case 10:
|
3713
3697
|
err_4 = _f.sent();
|
3714
3698
|
console.error("perpClient addLiquidity error:: ", err_4);
|
3715
3699
|
throw err_4;
|
3716
|
-
case
|
3700
|
+
case 11: return [2, {
|
3717
3701
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3718
3702
|
additionalSigners: additionalSigners
|
3719
3703
|
}];
|
@@ -3725,7 +3709,7 @@ var PerpetualsClient = (function () {
|
|
3725
3709
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3726
3710
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3727
3711
|
return __awaiter(_this, void 0, void 0, function () {
|
3728
|
-
var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, flpStakeAccount, poolStakedLpVault,
|
3712
|
+
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;
|
3729
3713
|
return __generator(this, function (_f) {
|
3730
3714
|
switch (_f.label) {
|
3731
3715
|
case 0:
|
@@ -3736,28 +3720,24 @@ var PerpetualsClient = (function () {
|
|
3736
3720
|
additionalSigners = [];
|
3737
3721
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
3738
3722
|
inputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inputSymbol).mintKey); });
|
3739
|
-
|
3740
|
-
case 1:
|
3741
|
-
lpTokenAccount = _f.sent();
|
3723
|
+
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(lpTokenMint, publicKey, true);
|
3742
3724
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
3743
3725
|
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
3744
|
-
if (!(inputSymbol == 'SOL')) return [3,
|
3726
|
+
if (!(inputSymbol == 'SOL')) return [3, 4];
|
3745
3727
|
console.log("inputSymbol === SOL", inputSymbol);
|
3746
|
-
|
3747
|
-
case 2:
|
3748
|
-
accCreationLamports = (_f.sent());
|
3749
|
-
console.log("accCreationLamports:", accCreationLamports);
|
3750
|
-
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
3728
|
+
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3751
3729
|
console.log("lamports:", lamports.toNumber());
|
3730
|
+
if (!!skipBalanceChecks) return [3, 2];
|
3752
3731
|
_a = anchor_1.BN.bind;
|
3753
3732
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3754
|
-
case
|
3733
|
+
case 1:
|
3755
3734
|
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
3756
3735
|
if (unWrappedSolBalance.lt(lamports)) {
|
3757
3736
|
throw "Insufficient SOL Funds";
|
3758
3737
|
}
|
3759
|
-
|
3760
|
-
case 4
|
3738
|
+
_f.label = 2;
|
3739
|
+
case 2: return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
3740
|
+
case 3:
|
3761
3741
|
if (!(_f.sent())) {
|
3762
3742
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
3763
3743
|
}
|
@@ -3778,24 +3758,24 @@ var PerpetualsClient = (function () {
|
|
3778
3758
|
postInstructions = [
|
3779
3759
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3780
3760
|
];
|
3781
|
-
return [3,
|
3782
|
-
case
|
3761
|
+
return [3, 7];
|
3762
|
+
case 4:
|
3783
3763
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
3764
|
+
if (!!skipBalanceChecks) return [3, 7];
|
3784
3765
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3785
|
-
case
|
3766
|
+
case 5:
|
3786
3767
|
if (!(_f.sent())) {
|
3787
3768
|
throw "Insufficient Funds , token Account doesn't exist";
|
3788
3769
|
}
|
3789
|
-
if (!!skipBalanceChecks) return [3, 8];
|
3790
3770
|
_b = anchor_1.BN.bind;
|
3791
3771
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3792
|
-
case
|
3772
|
+
case 6:
|
3793
3773
|
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
3794
3774
|
if (tokenAccountBalance.lt(amountIn)) {
|
3795
3775
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3796
3776
|
}
|
3797
|
-
_f.label =
|
3798
|
-
case
|
3777
|
+
_f.label = 7;
|
3778
|
+
case 7:
|
3799
3779
|
custodyAccountMetas = [];
|
3800
3780
|
custodyOracleAccountMetas = [];
|
3801
3781
|
markets = [];
|
@@ -3844,7 +3824,7 @@ var PerpetualsClient = (function () {
|
|
3844
3824
|
})
|
3845
3825
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
3846
3826
|
.instruction()];
|
3847
|
-
case
|
3827
|
+
case 8:
|
3848
3828
|
instruction = _f.sent();
|
3849
3829
|
instructions.push(instruction);
|
3850
3830
|
return [2, {
|
@@ -3876,10 +3856,8 @@ var PerpetualsClient = (function () {
|
|
3876
3856
|
additionalSigners = [];
|
3877
3857
|
_e.label = 1;
|
3878
3858
|
case 1:
|
3879
|
-
_e.trys.push([1,
|
3880
|
-
|
3881
|
-
case 2:
|
3882
|
-
stakedLpTokenAccount = _e.sent();
|
3859
|
+
_e.trys.push([1, 7, , 8]);
|
3860
|
+
stakedLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
3883
3861
|
custodyAccountMetas = [];
|
3884
3862
|
custodyOracleAccountMetas = [];
|
3885
3863
|
markets = [];
|
@@ -3904,10 +3882,8 @@ var PerpetualsClient = (function () {
|
|
3904
3882
|
isWritable: false,
|
3905
3883
|
});
|
3906
3884
|
}
|
3907
|
-
if (!(recieveTokenSymbol == 'SOL')) return [3,
|
3908
|
-
|
3909
|
-
case 3:
|
3910
|
-
lamports = (_e.sent());
|
3885
|
+
if (!(recieveTokenSymbol == 'SOL')) return [3, 2];
|
3886
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
3911
3887
|
if (!ephemeralSignerPubkey) {
|
3912
3888
|
wrappedSolAccount = new web3_js_1.Keypair();
|
3913
3889
|
additionalSigners.push(wrappedSolAccount);
|
@@ -3925,47 +3901,44 @@ var PerpetualsClient = (function () {
|
|
3925
3901
|
postInstructions = [
|
3926
3902
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3927
3903
|
];
|
3928
|
-
return [3,
|
3929
|
-
case
|
3930
|
-
|
3931
|
-
userReceivingTokenAccount = _e.sent();
|
3904
|
+
return [3, 5];
|
3905
|
+
case 2:
|
3906
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true);
|
3932
3907
|
_d = createUserATA;
|
3933
|
-
if (!_d) return [3,
|
3908
|
+
if (!_d) return [3, 4];
|
3934
3909
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
3935
|
-
case
|
3910
|
+
case 3:
|
3936
3911
|
_d = !(_e.sent());
|
3937
|
-
_e.label =
|
3938
|
-
case
|
3912
|
+
_e.label = 4;
|
3913
|
+
case 4:
|
3939
3914
|
if (_d) {
|
3940
3915
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey));
|
3941
3916
|
}
|
3942
|
-
_e.label =
|
3943
|
-
case
|
3944
|
-
|
3945
|
-
|
3946
|
-
|
3947
|
-
|
3948
|
-
|
3949
|
-
|
3950
|
-
|
3951
|
-
|
3952
|
-
|
3953
|
-
|
3954
|
-
|
3955
|
-
|
3956
|
-
|
3957
|
-
|
3958
|
-
|
3959
|
-
|
3960
|
-
|
3961
|
-
|
3962
|
-
|
3963
|
-
|
3964
|
-
|
3965
|
-
|
3966
|
-
|
3967
|
-
.instruction()];
|
3968
|
-
case 9:
|
3917
|
+
_e.label = 5;
|
3918
|
+
case 5: return [4, this.program.methods
|
3919
|
+
.removeLiquidity({
|
3920
|
+
lpAmountIn: liquidityAmountIn,
|
3921
|
+
minAmountOut: minTokenAmountOut
|
3922
|
+
})
|
3923
|
+
.accounts({
|
3924
|
+
owner: publicKey,
|
3925
|
+
receivingAccount: recieveTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
3926
|
+
lpTokenAccount: stakedLpTokenAccount,
|
3927
|
+
transferAuthority: poolConfig.transferAuthority,
|
3928
|
+
perpetuals: poolConfig.perpetuals,
|
3929
|
+
pool: poolConfig.poolAddress,
|
3930
|
+
custody: recieveTokenCustodyConfig.custodyAccount,
|
3931
|
+
custodyOracleAccount: this.useExtOracleAccount ? recieveTokenCustodyConfig.extOracleAccount : recieveTokenCustodyConfig.intOracleAccount,
|
3932
|
+
custodyTokenAccount: recieveTokenCustodyConfig.tokenAccount,
|
3933
|
+
lpTokenMint: poolConfig.stakedLpTokenMint,
|
3934
|
+
eventAuthority: this.eventAuthority.publicKey,
|
3935
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3936
|
+
program: this.programId,
|
3937
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3938
|
+
})
|
3939
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
3940
|
+
.instruction()];
|
3941
|
+
case 6:
|
3969
3942
|
removeLiquidityTx = _e.sent();
|
3970
3943
|
instructions.push(removeLiquidityTx);
|
3971
3944
|
if (closeLpATA) {
|
@@ -3976,12 +3949,12 @@ var PerpetualsClient = (function () {
|
|
3976
3949
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
|
3977
3950
|
postInstructions.push(closeWsolATAIns);
|
3978
3951
|
}
|
3979
|
-
return [3,
|
3980
|
-
case
|
3952
|
+
return [3, 8];
|
3953
|
+
case 7:
|
3981
3954
|
err_5 = _e.sent();
|
3982
3955
|
console.log("perpClient removeLiquidity error:: ", err_5);
|
3983
3956
|
throw err_5;
|
3984
|
-
case
|
3957
|
+
case 8: return [2, {
|
3985
3958
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3986
3959
|
additionalSigners: additionalSigners
|
3987
3960
|
}];
|
@@ -4039,15 +4012,13 @@ var PerpetualsClient = (function () {
|
|
4039
4012
|
additionalSigners = [];
|
4040
4013
|
_a.label = 1;
|
4041
4014
|
case 1:
|
4042
|
-
_a.trys.push([1,
|
4015
|
+
_a.trys.push([1, 3, , 4]);
|
4043
4016
|
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4044
4017
|
Buffer.from("trading"),
|
4045
4018
|
nftMint.toBuffer(),
|
4046
4019
|
], this.programId)[0];
|
4047
4020
|
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
4048
|
-
|
4049
|
-
case 2:
|
4050
|
-
nftTokenAccount = _a.sent();
|
4021
|
+
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, owner, true);
|
4051
4022
|
return [4, this.program.methods
|
4052
4023
|
.createTradingAccount({
|
4053
4024
|
collectionIndex: 0
|
@@ -4063,15 +4034,15 @@ var PerpetualsClient = (function () {
|
|
4063
4034
|
systemProgram: web3_js_1.SystemProgram.programId
|
4064
4035
|
})
|
4065
4036
|
.instruction()];
|
4066
|
-
case
|
4037
|
+
case 2:
|
4067
4038
|
createNftTradingAccountInstruction = _a.sent();
|
4068
4039
|
instructions.push(createNftTradingAccountInstruction);
|
4069
|
-
return [3,
|
4070
|
-
case
|
4040
|
+
return [3, 4];
|
4041
|
+
case 3:
|
4071
4042
|
err_7 = _a.sent();
|
4072
4043
|
console.log("perpClient createNftAccount error:: ", err_7);
|
4073
4044
|
throw err_7;
|
4074
|
-
case
|
4045
|
+
case 4: return [2, {
|
4075
4046
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4076
4047
|
additionalSigners: additionalSigners
|
4077
4048
|
}];
|
@@ -4436,7 +4407,7 @@ var PerpetualsClient = (function () {
|
|
4436
4407
|
});
|
4437
4408
|
}); };
|
4438
4409
|
this.unstakeInstant = function (rewardSymbol, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4439
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners,
|
4410
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, unstakeInstantInstruction, err_14;
|
4440
4411
|
return __generator(this, function (_a) {
|
4441
4412
|
switch (_a.label) {
|
4442
4413
|
case 0:
|
@@ -4448,10 +4419,8 @@ var PerpetualsClient = (function () {
|
|
4448
4419
|
_a.label = 1;
|
4449
4420
|
case 1:
|
4450
4421
|
_a.trys.push([1, 3, , 4]);
|
4451
|
-
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
4452
4422
|
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
4453
4423
|
pool = poolConfig.poolAddress;
|
4454
|
-
feeDistributionTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("custody_token_account"), pool.toBuffer(), rewardCustodyMint.toBuffer()], this.programId)[0];
|
4455
4424
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.programId)[0];
|
4456
4425
|
return [4, this.program.methods
|
4457
4426
|
.unstakeInstant({
|
@@ -4595,21 +4564,19 @@ var PerpetualsClient = (function () {
|
|
4595
4564
|
additionalSigners = [];
|
4596
4565
|
_b.label = 1;
|
4597
4566
|
case 1:
|
4598
|
-
_b.trys.push([1,
|
4567
|
+
_b.trys.push([1, 5, , 6]);
|
4599
4568
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
4600
4569
|
pool = poolConfig.poolAddress;
|
4601
4570
|
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), pool.toBuffer(), lpTokenMint.toBuffer()], this.program.programId)[0];
|
4602
4571
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
|
4603
|
-
|
4604
|
-
case 2:
|
4605
|
-
userLpTokenAccount = _b.sent();
|
4572
|
+
userLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
4606
4573
|
_a = createUserLPTA;
|
4607
|
-
if (!_a) return [3,
|
4574
|
+
if (!_a) return [3, 3];
|
4608
4575
|
return [4, (0, utils_1.checkIfAccountExists)(userLpTokenAccount, this.provider.connection)];
|
4609
|
-
case
|
4576
|
+
case 2:
|
4610
4577
|
_a = !(_b.sent());
|
4611
|
-
_b.label =
|
4612
|
-
case
|
4578
|
+
_b.label = 3;
|
4579
|
+
case 3:
|
4613
4580
|
if (_a) {
|
4614
4581
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userLpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
4615
4582
|
}
|
@@ -4632,15 +4599,15 @@ var PerpetualsClient = (function () {
|
|
4632
4599
|
program: this.program.programId,
|
4633
4600
|
})
|
4634
4601
|
.instruction()];
|
4635
|
-
case
|
4602
|
+
case 4:
|
4636
4603
|
withdrawStakeInstruction = _b.sent();
|
4637
4604
|
instructions.push(withdrawStakeInstruction);
|
4638
|
-
return [3,
|
4639
|
-
case
|
4605
|
+
return [3, 6];
|
4606
|
+
case 5:
|
4640
4607
|
err_17 = _b.sent();
|
4641
4608
|
console.log("perpClient withdrawStake error:: ", err_17);
|
4642
4609
|
throw err_17;
|
4643
|
-
case
|
4610
|
+
case 6: return [2, {
|
4644
4611
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4645
4612
|
additionalSigners: additionalSigners
|
4646
4613
|
}];
|
@@ -4788,10 +4755,8 @@ var PerpetualsClient = (function () {
|
|
4788
4755
|
additionalSigners = [];
|
4789
4756
|
_a.label = 1;
|
4790
4757
|
case 1:
|
4791
|
-
_a.trys.push([1,
|
4792
|
-
|
4793
|
-
case 2:
|
4794
|
-
fundingAccount = _a.sent();
|
4758
|
+
_a.trys.push([1, 3, , 4]);
|
4759
|
+
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
4795
4760
|
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
4796
4761
|
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
4797
4762
|
return [4, this.programFbnftReward.methods
|
@@ -4806,15 +4771,15 @@ var PerpetualsClient = (function () {
|
|
4806
4771
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4807
4772
|
})
|
4808
4773
|
.instruction()];
|
4809
|
-
case
|
4774
|
+
case 2:
|
4810
4775
|
distributeReward = _a.sent();
|
4811
4776
|
instructions.push(distributeReward);
|
4812
|
-
return [3,
|
4813
|
-
case
|
4777
|
+
return [3, 4];
|
4778
|
+
case 3:
|
4814
4779
|
err_20 = _a.sent();
|
4815
4780
|
console.log("perpClient distributeReward error:: ", err_20);
|
4816
4781
|
throw err_20;
|
4817
|
-
case
|
4782
|
+
case 4: return [2, {
|
4818
4783
|
instructions: __spreadArray([], instructions, true),
|
4819
4784
|
additionalSigners: additionalSigners
|
4820
4785
|
}];
|
@@ -4834,21 +4799,17 @@ var PerpetualsClient = (function () {
|
|
4834
4799
|
additionalSigners = [];
|
4835
4800
|
_b.label = 1;
|
4836
4801
|
case 1:
|
4837
|
-
_b.trys.push([1,
|
4838
|
-
|
4839
|
-
case 2:
|
4840
|
-
nftTokenAccount = _b.sent();
|
4802
|
+
_b.trys.push([1, 5, , 6]);
|
4803
|
+
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, publicKey, true);
|
4841
4804
|
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
4842
|
-
|
4843
|
-
case 3:
|
4844
|
-
receivingTokenAccount = _b.sent();
|
4805
|
+
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
4845
4806
|
_a = createUserATA;
|
4846
|
-
if (!_a) return [3,
|
4807
|
+
if (!_a) return [3, 3];
|
4847
4808
|
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
4848
|
-
case
|
4809
|
+
case 2:
|
4849
4810
|
_a = !(_b.sent());
|
4850
|
-
_b.label =
|
4851
|
-
case
|
4811
|
+
_b.label = 3;
|
4812
|
+
case 3:
|
4852
4813
|
if (_a) {
|
4853
4814
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
4854
4815
|
}
|
@@ -4873,14 +4834,14 @@ var PerpetualsClient = (function () {
|
|
4873
4834
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4874
4835
|
})
|
4875
4836
|
.instruction()];
|
4876
|
-
case
|
4837
|
+
case 4:
|
4877
4838
|
collectNftReward = _b.sent();
|
4878
4839
|
instructions.push(collectNftReward);
|
4879
|
-
return [3,
|
4880
|
-
case
|
4840
|
+
return [3, 6];
|
4841
|
+
case 5:
|
4881
4842
|
err_21 = _b.sent();
|
4882
4843
|
throw err_21;
|
4883
|
-
case
|
4844
|
+
case 6: return [2, {
|
4884
4845
|
instructions: __spreadArray([], instructions, true),
|
4885
4846
|
additionalSigners: additionalSigners
|
4886
4847
|
}];
|
@@ -5035,12 +4996,10 @@ var PerpetualsClient = (function () {
|
|
5035
4996
|
additionalSigners = [];
|
5036
4997
|
_b.label = 1;
|
5037
4998
|
case 1:
|
5038
|
-
_b.trys.push([1,
|
5039
|
-
if (!(collateralSymbol == 'SOL')) return [3,
|
4999
|
+
_b.trys.push([1, 7, , 8]);
|
5000
|
+
if (!(collateralSymbol == 'SOL')) return [3, 2];
|
5040
5001
|
console.log("collateralSymbol === SOL", collateralSymbol);
|
5041
|
-
|
5042
|
-
case 2:
|
5043
|
-
lamports = (_b.sent());
|
5002
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
5044
5003
|
if (!ephemeralSignerPubkey) {
|
5045
5004
|
wrappedSolAccount = new web3_js_1.Keypair();
|
5046
5005
|
additionalSigners.push(wrappedSolAccount);
|
@@ -5058,22 +5017,21 @@ var PerpetualsClient = (function () {
|
|
5058
5017
|
postInstructions = [
|
5059
5018
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), positionAccount.owner, positionAccount.owner),
|
5060
5019
|
];
|
5061
|
-
return [3,
|
5062
|
-
case
|
5063
|
-
|
5064
|
-
userReceivingTokenAccount = _b.sent();
|
5020
|
+
return [3, 5];
|
5021
|
+
case 2:
|
5022
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, positionAccount.owner, true);
|
5065
5023
|
_a = createUserATA;
|
5066
|
-
if (!_a) return [3,
|
5024
|
+
if (!_a) return [3, 4];
|
5067
5025
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
5068
|
-
case
|
5026
|
+
case 3:
|
5069
5027
|
_a = !(_b.sent());
|
5070
|
-
_b.label =
|
5071
|
-
case
|
5028
|
+
_b.label = 4;
|
5029
|
+
case 4:
|
5072
5030
|
if (_a) {
|
5073
5031
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, positionAccount.owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
5074
5032
|
}
|
5075
|
-
_b.label =
|
5076
|
-
case
|
5033
|
+
_b.label = 5;
|
5034
|
+
case 5: return [4, this.program.methods
|
5077
5035
|
.forceClosePosition({
|
5078
5036
|
privilege: types_1.Privilege.None,
|
5079
5037
|
isStopLoss: isStopLoss
|
@@ -5097,19 +5055,19 @@ var PerpetualsClient = (function () {
|
|
5097
5055
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5098
5056
|
})
|
5099
5057
|
.instruction()];
|
5100
|
-
case
|
5058
|
+
case 6:
|
5101
5059
|
forceClosePosition = _b.sent();
|
5102
5060
|
instructions.push(forceClosePosition);
|
5103
5061
|
if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
|
5104
5062
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, positionAccount.owner, positionAccount.owner);
|
5105
5063
|
postInstructions.push(closeWsolATAIns);
|
5106
5064
|
}
|
5107
|
-
return [3,
|
5108
|
-
case
|
5065
|
+
return [3, 8];
|
5066
|
+
case 7:
|
5109
5067
|
err_24 = _b.sent();
|
5110
5068
|
console.log("perpClient forceClosePosition error:: ", err_24);
|
5111
5069
|
throw err_24;
|
5112
|
-
case
|
5070
|
+
case 8: return [2, {
|
5113
5071
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5114
5072
|
additionalSigners: additionalSigners
|
5115
5073
|
}];
|
@@ -5269,7 +5227,6 @@ var PerpetualsClient = (function () {
|
|
5269
5227
|
instructions = [];
|
5270
5228
|
additionalSigners = [];
|
5271
5229
|
custodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(tokenMint); });
|
5272
|
-
console.log("custodyConfig: ", custodyConfig);
|
5273
5230
|
_g.label = 1;
|
5274
5231
|
case 1:
|
5275
5232
|
_g.trys.push([1, 4, , 5]);
|
@@ -5352,10 +5309,11 @@ var PerpetualsClient = (function () {
|
|
5352
5309
|
}
|
5353
5310
|
});
|
5354
5311
|
}); };
|
5355
|
-
this.addCompoundingLiquidity = function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, ephemeralSignerPubkey) {
|
5312
|
+
this.addCompoundingLiquidity = function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
5313
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
5356
5314
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5357
5315
|
return __awaiter(_this, void 0, void 0, function () {
|
5358
|
-
var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market,
|
5316
|
+
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_30;
|
5359
5317
|
return __generator(this, function (_e) {
|
5360
5318
|
switch (_e.label) {
|
5361
5319
|
case 0:
|
@@ -5368,15 +5326,9 @@ var PerpetualsClient = (function () {
|
|
5368
5326
|
inCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inTokenSymbol).mintKey); });
|
5369
5327
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
5370
5328
|
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
5371
|
-
|
5372
|
-
|
5373
|
-
|
5374
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(compoundingTokenMint, publicKey, true)];
|
5375
|
-
case 2:
|
5376
|
-
compoundingTokenAccount = _e.sent();
|
5377
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(inCustodyConfig.mintKey, publicKey, true)];
|
5378
|
-
case 3:
|
5379
|
-
fundingAccount = _e.sent();
|
5329
|
+
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
5330
|
+
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
5331
|
+
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inCustodyConfig.mintKey, publicKey, true);
|
5380
5332
|
custodyAccountMetas = [];
|
5381
5333
|
custodyOracleAccountMetas = [];
|
5382
5334
|
markets = [];
|
@@ -5402,29 +5354,28 @@ var PerpetualsClient = (function () {
|
|
5402
5354
|
});
|
5403
5355
|
}
|
5404
5356
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
5405
|
-
case
|
5357
|
+
case 1:
|
5406
5358
|
if (!(_e.sent())) {
|
5407
5359
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
5408
5360
|
}
|
5409
5361
|
return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
|
5410
|
-
case
|
5362
|
+
case 2:
|
5411
5363
|
if (!(_e.sent())) {
|
5412
5364
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
|
5413
5365
|
}
|
5414
|
-
if (!(inTokenSymbol == 'SOL')) return [3,
|
5366
|
+
if (!(inTokenSymbol == 'SOL')) return [3, 5];
|
5415
5367
|
console.log("inTokenSymbol === SOL", inTokenSymbol);
|
5416
|
-
|
5417
|
-
|
5418
|
-
accCreationLamports = (_e.sent());
|
5419
|
-
console.log("accCreationLamports:", accCreationLamports);
|
5420
|
-
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
5368
|
+
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
5369
|
+
if (!!skipBalanceChecks) return [3, 4];
|
5421
5370
|
_d = anchor_1.BN.bind;
|
5422
5371
|
return [4, this.provider.connection.getBalance(publicKey)];
|
5423
|
-
case
|
5372
|
+
case 3:
|
5424
5373
|
unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _e.sent()]))();
|
5425
5374
|
if (unWrappedSolBalance.lt(lamports)) {
|
5426
5375
|
throw "Insufficient SOL Funds";
|
5427
5376
|
}
|
5377
|
+
_e.label = 4;
|
5378
|
+
case 4:
|
5428
5379
|
if (!ephemeralSignerPubkey) {
|
5429
5380
|
wrappedSolAccount = new web3_js_1.Keypair();
|
5430
5381
|
additionalSigners.push(wrappedSolAccount);
|
@@ -5442,15 +5393,17 @@ var PerpetualsClient = (function () {
|
|
5442
5393
|
postInstructions = [
|
5443
5394
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
5444
5395
|
];
|
5445
|
-
return [3,
|
5446
|
-
case
|
5447
|
-
|
5396
|
+
return [3, 7];
|
5397
|
+
case 5:
|
5398
|
+
if (!!skipBalanceChecks) return [3, 7];
|
5399
|
+
return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
|
5400
|
+
case 6:
|
5448
5401
|
if (!(_e.sent())) {
|
5449
5402
|
throw "Insufficient Funds , token Account doesn't exist";
|
5450
5403
|
}
|
5451
|
-
_e.label =
|
5452
|
-
case
|
5453
|
-
_e.trys.push([
|
5404
|
+
_e.label = 7;
|
5405
|
+
case 7:
|
5406
|
+
_e.trys.push([7, 9, , 10]);
|
5454
5407
|
return [4, this.program.methods
|
5455
5408
|
.addCompoundingLiquidity({
|
5456
5409
|
amountIn: amountIn,
|
@@ -5478,15 +5431,15 @@ var PerpetualsClient = (function () {
|
|
5478
5431
|
})
|
5479
5432
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5480
5433
|
.instruction()];
|
5481
|
-
case
|
5434
|
+
case 8:
|
5482
5435
|
addCompoundingLiquidity = _e.sent();
|
5483
5436
|
instructions.push(addCompoundingLiquidity);
|
5484
|
-
return [3,
|
5485
|
-
case
|
5437
|
+
return [3, 10];
|
5438
|
+
case 9:
|
5486
5439
|
err_30 = _e.sent();
|
5487
5440
|
console.log("perpClient addCompoundingLiquidity error:: ", err_30);
|
5488
|
-
return [3,
|
5489
|
-
case
|
5441
|
+
return [3, 10];
|
5442
|
+
case 10: return [2, {
|
5490
5443
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5491
5444
|
additionalSigners: additionalSigners
|
5492
5445
|
}];
|
@@ -5498,7 +5451,7 @@ var PerpetualsClient = (function () {
|
|
5498
5451
|
if (createUserATA === void 0) { createUserATA = true; }
|
5499
5452
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5500
5453
|
return __awaiter(_this, void 0, void 0, function () {
|
5501
|
-
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, compoundingTokenAccount,
|
5454
|
+
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_31;
|
5502
5455
|
return __generator(this, function (_e) {
|
5503
5456
|
switch (_e.label) {
|
5504
5457
|
case 0:
|
@@ -5511,10 +5464,8 @@ var PerpetualsClient = (function () {
|
|
5511
5464
|
outCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(outTokenSymbol).mintKey); });
|
5512
5465
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
5513
5466
|
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
5514
|
-
if (!(outCustodyConfig.symbol == 'SOL')) return [3,
|
5515
|
-
|
5516
|
-
case 1:
|
5517
|
-
lamports = (_e.sent());
|
5467
|
+
if (!(outCustodyConfig.symbol == 'SOL')) return [3, 1];
|
5468
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
5518
5469
|
if (!ephemeralSignerPubkey) {
|
5519
5470
|
wrappedSolAccount = new web3_js_1.Keypair();
|
5520
5471
|
additionalSigners.push(wrappedSolAccount);
|
@@ -5532,22 +5483,21 @@ var PerpetualsClient = (function () {
|
|
5532
5483
|
postInstructions = [
|
5533
5484
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
5534
5485
|
];
|
5535
|
-
return [3,
|
5536
|
-
case
|
5537
|
-
|
5538
|
-
userReceivingTokenAccount = _e.sent();
|
5486
|
+
return [3, 4];
|
5487
|
+
case 1:
|
5488
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(outCustodyConfig.mintKey, publicKey, true);
|
5539
5489
|
_a = createUserATA;
|
5540
|
-
if (!_a) return [3,
|
5490
|
+
if (!_a) return [3, 3];
|
5541
5491
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
5542
|
-
case
|
5492
|
+
case 2:
|
5543
5493
|
_a = !(_e.sent());
|
5544
|
-
_e.label =
|
5545
|
-
case
|
5494
|
+
_e.label = 3;
|
5495
|
+
case 3:
|
5546
5496
|
if (_a) {
|
5547
5497
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
|
5548
5498
|
}
|
5549
|
-
_e.label =
|
5550
|
-
case
|
5499
|
+
_e.label = 4;
|
5500
|
+
case 4:
|
5551
5501
|
custodyAccountMetas = [];
|
5552
5502
|
custodyOracleAccountMetas = [];
|
5553
5503
|
markets = [];
|
@@ -5572,15 +5522,10 @@ var PerpetualsClient = (function () {
|
|
5572
5522
|
isWritable: false,
|
5573
5523
|
});
|
5574
5524
|
}
|
5575
|
-
|
5576
|
-
|
5577
|
-
|
5578
|
-
|
5579
|
-
case 8:
|
5580
|
-
receivingAccount = _e.sent();
|
5581
|
-
_e.label = 9;
|
5582
|
-
case 9:
|
5583
|
-
_e.trys.push([9, 11, , 12]);
|
5525
|
+
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
5526
|
+
_e.label = 5;
|
5527
|
+
case 5:
|
5528
|
+
_e.trys.push([5, 7, , 8]);
|
5584
5529
|
return [4, this.program.methods
|
5585
5530
|
.removeCompoundingLiquidity({
|
5586
5531
|
compoundingAmountIn: compoundingAmountIn,
|
@@ -5608,15 +5553,15 @@ var PerpetualsClient = (function () {
|
|
5608
5553
|
})
|
5609
5554
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5610
5555
|
.instruction()];
|
5611
|
-
case
|
5556
|
+
case 6:
|
5612
5557
|
removeCompoundingLiquidity = _e.sent();
|
5613
5558
|
instructions.push(removeCompoundingLiquidity);
|
5614
|
-
return [3,
|
5615
|
-
case
|
5559
|
+
return [3, 8];
|
5560
|
+
case 7:
|
5616
5561
|
err_31 = _e.sent();
|
5617
5562
|
console.log("perpClient removeCompoundingLiquidity error:: ", err_31);
|
5618
|
-
return [3,
|
5619
|
-
case
|
5563
|
+
return [3, 8];
|
5564
|
+
case 8: return [2, {
|
5620
5565
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5621
5566
|
additionalSigners: additionalSigners
|
5622
5567
|
}];
|
@@ -5639,16 +5584,14 @@ var PerpetualsClient = (function () {
|
|
5639
5584
|
rewardCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardTokenMint); });
|
5640
5585
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
5641
5586
|
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
5642
|
-
|
5643
|
-
case 1:
|
5644
|
-
compoudingTokenAccount = _e.sent();
|
5587
|
+
compoudingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
5645
5588
|
_a = createUserATA;
|
5646
|
-
if (!_a) return [3,
|
5589
|
+
if (!_a) return [3, 2];
|
5647
5590
|
return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
|
5648
|
-
case
|
5591
|
+
case 1:
|
5649
5592
|
_a = !(_e.sent());
|
5650
|
-
_e.label =
|
5651
|
-
case
|
5593
|
+
_e.label = 2;
|
5594
|
+
case 2:
|
5652
5595
|
if (_a) {
|
5653
5596
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
|
5654
5597
|
}
|
@@ -5678,9 +5621,9 @@ var PerpetualsClient = (function () {
|
|
5678
5621
|
isWritable: false,
|
5679
5622
|
});
|
5680
5623
|
}
|
5681
|
-
_e.label =
|
5682
|
-
case
|
5683
|
-
_e.trys.push([
|
5624
|
+
_e.label = 3;
|
5625
|
+
case 3:
|
5626
|
+
_e.trys.push([3, 5, , 6]);
|
5684
5627
|
return [4, this.program.methods
|
5685
5628
|
.migrateStake({
|
5686
5629
|
amount: amount
|
@@ -5705,15 +5648,15 @@ var PerpetualsClient = (function () {
|
|
5705
5648
|
})
|
5706
5649
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5707
5650
|
.instruction()];
|
5708
|
-
case
|
5651
|
+
case 4:
|
5709
5652
|
migrateStake = _e.sent();
|
5710
5653
|
instructions.push(migrateStake);
|
5711
|
-
return [3,
|
5712
|
-
case
|
5654
|
+
return [3, 6];
|
5655
|
+
case 5:
|
5713
5656
|
err_32 = _e.sent();
|
5714
5657
|
console.log("perpClient migrateStake error:: ", err_32);
|
5715
|
-
return [3,
|
5716
|
-
case
|
5658
|
+
return [3, 6];
|
5659
|
+
case 6: return [2, {
|
5717
5660
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5718
5661
|
additionalSigners: additionalSigners
|
5719
5662
|
}];
|
@@ -5734,9 +5677,7 @@ var PerpetualsClient = (function () {
|
|
5734
5677
|
rewardCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardTokenMint); });
|
5735
5678
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
5736
5679
|
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
5737
|
-
|
5738
|
-
case 1:
|
5739
|
-
compoudingTokenAccount = _d.sent();
|
5680
|
+
compoudingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
5740
5681
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
5741
5682
|
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
5742
5683
|
custodyAccountMetas = [];
|
@@ -5763,9 +5704,9 @@ var PerpetualsClient = (function () {
|
|
5763
5704
|
isWritable: false,
|
5764
5705
|
});
|
5765
5706
|
}
|
5766
|
-
_d.label =
|
5767
|
-
case
|
5768
|
-
_d.trys.push([
|
5707
|
+
_d.label = 1;
|
5708
|
+
case 1:
|
5709
|
+
_d.trys.push([1, 3, , 4]);
|
5769
5710
|
return [4, this.program.methods
|
5770
5711
|
.migrateFlp({
|
5771
5712
|
compoundingTokenAmount: amount
|
@@ -5791,15 +5732,15 @@ var PerpetualsClient = (function () {
|
|
5791
5732
|
})
|
5792
5733
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5793
5734
|
.instruction()];
|
5794
|
-
case
|
5735
|
+
case 2:
|
5795
5736
|
migrateFlp = _d.sent();
|
5796
5737
|
instructions.push(migrateFlp);
|
5797
|
-
return [3,
|
5798
|
-
case
|
5738
|
+
return [3, 4];
|
5739
|
+
case 3:
|
5799
5740
|
err_33 = _d.sent();
|
5800
5741
|
console.log("perpClient migrateFlp error:: ", err_33);
|
5801
|
-
return [3,
|
5802
|
-
case
|
5742
|
+
return [3, 4];
|
5743
|
+
case 4: return [2, {
|
5803
5744
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5804
5745
|
additionalSigners: additionalSigners
|
5805
5746
|
}];
|
@@ -6016,10 +5957,8 @@ var PerpetualsClient = (function () {
|
|
6016
5957
|
additionalSigners = [];
|
6017
5958
|
_a.label = 1;
|
6018
5959
|
case 1:
|
6019
|
-
_a.trys.push([1,
|
6020
|
-
|
6021
|
-
case 2:
|
6022
|
-
fundingAccount = _a.sent();
|
5960
|
+
_a.trys.push([1, 3, , 4]);
|
5961
|
+
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
6023
5962
|
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programRewardDistribution.programId)[0];
|
6024
5963
|
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programRewardDistribution.programId)[0];
|
6025
5964
|
rewardRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_record"), owner.toBuffer(), rewardVault.toBuffer(), counter.toArrayLike(Buffer, 'le', 8)], this.programRewardDistribution.programId)[0];
|
@@ -6042,15 +5981,15 @@ var PerpetualsClient = (function () {
|
|
6042
5981
|
program: this.programRewardDistribution.programId
|
6043
5982
|
})
|
6044
5983
|
.instruction()];
|
6045
|
-
case
|
5984
|
+
case 2:
|
6046
5985
|
distributeReward = _a.sent();
|
6047
5986
|
instructions.push(distributeReward);
|
6048
|
-
return [3,
|
6049
|
-
case
|
5987
|
+
return [3, 4];
|
5988
|
+
case 3:
|
6050
5989
|
err_38 = _a.sent();
|
6051
5990
|
console.log("rewardDistribution distributeReward error:: ", err_38);
|
6052
5991
|
throw err_38;
|
6053
|
-
case
|
5992
|
+
case 4: return [2, {
|
6054
5993
|
instructions: __spreadArray([], instructions, true),
|
6055
5994
|
additionalSigners: additionalSigners
|
6056
5995
|
}];
|
@@ -6070,17 +6009,15 @@ var PerpetualsClient = (function () {
|
|
6070
6009
|
additionalSigners = [];
|
6071
6010
|
_b.label = 1;
|
6072
6011
|
case 1:
|
6073
|
-
_b.trys.push([1,
|
6074
|
-
|
6075
|
-
case 2:
|
6076
|
-
receivingTokenAccount = _b.sent();
|
6012
|
+
_b.trys.push([1, 5, , 6]);
|
6013
|
+
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
6077
6014
|
_a = createUserATA;
|
6078
|
-
if (!_a) return [3,
|
6015
|
+
if (!_a) return [3, 3];
|
6079
6016
|
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
6080
|
-
case
|
6017
|
+
case 2:
|
6081
6018
|
_a = !(_b.sent());
|
6082
|
-
_b.label =
|
6083
|
-
case
|
6019
|
+
_b.label = 3;
|
6020
|
+
case 3:
|
6084
6021
|
if (_a) {
|
6085
6022
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
6086
6023
|
}
|
@@ -6103,14 +6040,14 @@ var PerpetualsClient = (function () {
|
|
6103
6040
|
program: this.programRewardDistribution.programId
|
6104
6041
|
})
|
6105
6042
|
.instruction()];
|
6106
|
-
case
|
6043
|
+
case 4:
|
6107
6044
|
collectNftReward = _b.sent();
|
6108
6045
|
instructions.push(collectNftReward);
|
6109
|
-
return [3,
|
6110
|
-
case
|
6046
|
+
return [3, 6];
|
6047
|
+
case 5:
|
6111
6048
|
err_39 = _b.sent();
|
6112
6049
|
throw err_39;
|
6113
|
-
case
|
6050
|
+
case 6: return [2, {
|
6114
6051
|
instructions: __spreadArray([], instructions, true),
|
6115
6052
|
additionalSigners: additionalSigners
|
6116
6053
|
}];
|
@@ -6132,6 +6069,7 @@ var PerpetualsClient = (function () {
|
|
6132
6069
|
this.perpetuals = this.findProgramAddress("perpetuals");
|
6133
6070
|
this.eventAuthority = this.findProgramAddress("__event_authority");
|
6134
6071
|
this.eventAuthorityRewardDistribution = this.findProgramAddressFromProgramId("__event_authority", null, this.programRewardDistribution.programId);
|
6072
|
+
this.minimumBalanceForRentExemptAccountLamports = 2039280;
|
6135
6073
|
this.prioritizationFee = (opts === null || opts === void 0 ? void 0 : opts.prioritizationFee) || 0;
|
6136
6074
|
this.useExtOracleAccount = useExtOracleAccount;
|
6137
6075
|
this.postSendTxCallback = opts === null || opts === void 0 ? void 0 : opts.postSendTxCallback;
|