flash-sdk 2.14.2 → 2.15.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 +15 -15
- package/dist/PerpetualsClient.js +399 -347
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -2220,11 +2220,12 @@ var PerpetualsClient = (function () {
|
|
2220
2220
|
}
|
2221
2221
|
});
|
2222
2222
|
}); };
|
2223
|
-
this.openPosition = function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, skipBalanceChecks) {
|
2223
|
+
this.openPosition = function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2224
2224
|
if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
|
2225
2225
|
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
2226
2226
|
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
2227
2227
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2228
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2228
2229
|
return __awaiter(_this, void 0, void 0, function () {
|
2229
2230
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
2230
2231
|
return __generator(this, function (_c) {
|
@@ -2243,7 +2244,6 @@ var PerpetualsClient = (function () {
|
|
2243
2244
|
additionalSigners = [];
|
2244
2245
|
if (!(collateralSymbol == 'SOL')) return [3, 4];
|
2245
2246
|
console.log("collateralSymbol === SOL", collateralSymbol);
|
2246
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
2247
2247
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
2248
2248
|
case 2:
|
2249
2249
|
accCreationLamports = (_c.sent());
|
@@ -2256,20 +2256,23 @@ var PerpetualsClient = (function () {
|
|
2256
2256
|
if (unWrappedSolBalance.lt(lamports)) {
|
2257
2257
|
throw "Insufficient SOL Funds";
|
2258
2258
|
}
|
2259
|
+
if (!ephemeralSignerPubkey) {
|
2260
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
2261
|
+
additionalSigners.push(wrappedSolAccount);
|
2262
|
+
}
|
2259
2263
|
preInstructions = [
|
2260
2264
|
web3_js_1.SystemProgram.createAccount({
|
2261
2265
|
fromPubkey: publicKey,
|
2262
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
2266
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
2263
2267
|
lamports: lamports.toNumber(),
|
2264
2268
|
space: 165,
|
2265
2269
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
2266
2270
|
}),
|
2267
|
-
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
2271
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
2268
2272
|
];
|
2269
2273
|
postInstructions = [
|
2270
|
-
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
2274
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2271
2275
|
];
|
2272
|
-
additionalSigners.push(wrappedSolAccount);
|
2273
2276
|
return [3, 7];
|
2274
2277
|
case 4: return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
2275
2278
|
case 5:
|
@@ -2298,7 +2301,7 @@ var PerpetualsClient = (function () {
|
|
2298
2301
|
.accounts({
|
2299
2302
|
owner: publicKey,
|
2300
2303
|
feePayer: publicKey,
|
2301
|
-
fundingAccount: collateralSymbol == 'SOL' ? wrappedSolAccount.publicKey : userCollateralTokenAccount,
|
2304
|
+
fundingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userCollateralTokenAccount,
|
2302
2305
|
perpetuals: poolConfig.perpetuals,
|
2303
2306
|
pool: poolConfig.poolAddress,
|
2304
2307
|
position: positionAccount,
|
@@ -2328,11 +2331,12 @@ var PerpetualsClient = (function () {
|
|
2328
2331
|
});
|
2329
2332
|
});
|
2330
2333
|
};
|
2331
|
-
this.openPositionWithSwap = function (targetSymbol, collateralSymbol, inputSymbol, amountIn, minAmountOut, priceWithSlippage, size, side, swapPoolConfig, positionPoolConfig, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, skipBalanceChecks) {
|
2334
|
+
this.openPositionWithSwap = function (targetSymbol, collateralSymbol, inputSymbol, amountIn, minAmountOut, priceWithSlippage, size, side, swapPoolConfig, positionPoolConfig, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2332
2335
|
if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
|
2333
2336
|
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
2334
2337
|
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
2335
2338
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2339
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2336
2340
|
return __awaiter(_this, void 0, void 0, function () {
|
2337
2341
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, swapOutCustodyConfig, swapInCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userOutputTokenAccount, marketAccount, positionAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, instruction;
|
2338
2342
|
return __generator(this, function (_d) {
|
@@ -2352,7 +2356,6 @@ var PerpetualsClient = (function () {
|
|
2352
2356
|
additionalSigners = [];
|
2353
2357
|
if (!(inputSymbol == 'SOL')) return [3, 3];
|
2354
2358
|
console.log("inputSymbol === SOL", inputSymbol);
|
2355
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
2356
2359
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
2357
2360
|
case 1:
|
2358
2361
|
accCreationLamports = (_d.sent());
|
@@ -2365,20 +2368,23 @@ var PerpetualsClient = (function () {
|
|
2365
2368
|
if (unWrappedSolBalance.lt(lamports)) {
|
2366
2369
|
throw "Insufficient SOL Funds";
|
2367
2370
|
}
|
2371
|
+
if (!ephemeralSignerPubkey) {
|
2372
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
2373
|
+
additionalSigners.push(wrappedSolAccount);
|
2374
|
+
}
|
2368
2375
|
preInstructions = [
|
2369
2376
|
web3_js_1.SystemProgram.createAccount({
|
2370
2377
|
fromPubkey: publicKey,
|
2371
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
2378
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
2372
2379
|
lamports: lamports.toNumber(),
|
2373
2380
|
space: 165,
|
2374
2381
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
2375
2382
|
}),
|
2376
|
-
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
2383
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
2377
2384
|
];
|
2378
2385
|
postInstructions = [
|
2379
|
-
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
2386
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2380
2387
|
];
|
2381
|
-
additionalSigners.push(wrappedSolAccount);
|
2382
2388
|
return [3, 6];
|
2383
2389
|
case 3:
|
2384
2390
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(inputSymbol).mintKey, publicKey, true);
|
@@ -2432,7 +2438,7 @@ var PerpetualsClient = (function () {
|
|
2432
2438
|
.accounts({
|
2433
2439
|
perpProgram: this.programId,
|
2434
2440
|
owner: publicKey,
|
2435
|
-
fundingAccount: inputSymbol == 'SOL' ? wrappedSolAccount.publicKey : userInputTokenAccount,
|
2441
|
+
fundingAccount: inputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
|
2436
2442
|
receivingAccount: userOutputTokenAccount,
|
2437
2443
|
transferAuthority: swapPoolConfig.transferAuthority,
|
2438
2444
|
perpetuals: swapPoolConfig.perpetuals,
|
@@ -2469,12 +2475,13 @@ var PerpetualsClient = (function () {
|
|
2469
2475
|
});
|
2470
2476
|
});
|
2471
2477
|
};
|
2472
|
-
this.closePosition = function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, createUserATA, closeUsersWSOLATA) {
|
2478
|
+
this.closePosition = function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
2473
2479
|
if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
|
2474
2480
|
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
2475
2481
|
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
2476
2482
|
if (createUserATA === void 0) { createUserATA = true; }
|
2477
2483
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
2484
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2478
2485
|
return __awaiter(_this, void 0, void 0, function () {
|
2479
2486
|
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_2;
|
2480
2487
|
return __generator(this, function (_b) {
|
@@ -2490,24 +2497,26 @@ var PerpetualsClient = (function () {
|
|
2490
2497
|
case 1:
|
2491
2498
|
_b.trys.push([1, 9, , 10]);
|
2492
2499
|
if (!(collateralSymbol == 'SOL')) return [3, 3];
|
2493
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
2494
2500
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
2495
2501
|
case 2:
|
2496
2502
|
lamports = (_b.sent());
|
2503
|
+
if (!ephemeralSignerPubkey) {
|
2504
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
2505
|
+
additionalSigners.push(wrappedSolAccount);
|
2506
|
+
}
|
2497
2507
|
preInstructions = [
|
2498
2508
|
web3_js_1.SystemProgram.createAccount({
|
2499
2509
|
fromPubkey: publicKey,
|
2500
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
2510
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
2501
2511
|
lamports: lamports,
|
2502
2512
|
space: 165,
|
2503
2513
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
2504
2514
|
}),
|
2505
|
-
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
2515
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
2506
2516
|
];
|
2507
2517
|
postInstructions = [
|
2508
|
-
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
2518
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2509
2519
|
];
|
2510
|
-
additionalSigners.push(wrappedSolAccount);
|
2511
2520
|
return [3, 7];
|
2512
2521
|
case 3: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey)];
|
2513
2522
|
case 4:
|
@@ -2536,7 +2545,7 @@ var PerpetualsClient = (function () {
|
|
2536
2545
|
.accounts({
|
2537
2546
|
feePayer: publicKey,
|
2538
2547
|
owner: publicKey,
|
2539
|
-
receivingAccount: collateralSymbol == 'SOL' ? wrappedSolAccount.publicKey : userReceivingTokenAccount,
|
2548
|
+
receivingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
2540
2549
|
transferAuthority: poolConfig.transferAuthority,
|
2541
2550
|
perpetuals: poolConfig.perpetuals,
|
2542
2551
|
pool: poolConfig.poolAddress,
|
@@ -2574,10 +2583,11 @@ var PerpetualsClient = (function () {
|
|
2574
2583
|
});
|
2575
2584
|
});
|
2576
2585
|
};
|
2577
|
-
this.closePositionWithSwap = function (targetSymbol, outputSymbol, collateralSymbol, minAmountOut, priceAfterSlippage, side, swapPoolConfig, positionPoolConfig, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount) {
|
2586
|
+
this.closePositionWithSwap = function (targetSymbol, outputSymbol, collateralSymbol, minAmountOut, priceAfterSlippage, side, swapPoolConfig, positionPoolConfig, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, ephemeralSignerPubkey) {
|
2578
2587
|
if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
|
2579
2588
|
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
2580
2589
|
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
2590
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2581
2591
|
return __awaiter(_this, void 0, void 0, function () {
|
2582
2592
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, swapInCustodyConfig, swapOutCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody, instruction;
|
2583
2593
|
return __generator(this, function (_b) {
|
@@ -2597,22 +2607,25 @@ var PerpetualsClient = (function () {
|
|
2597
2607
|
additionalSigners = [];
|
2598
2608
|
if (!(outputSymbol == 'SOL')) return [3, 2];
|
2599
2609
|
console.log("outputSymbol === SOL", outputSymbol);
|
2600
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
2601
2610
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
2602
2611
|
case 1:
|
2603
2612
|
lamports = (_b.sent());
|
2613
|
+
if (!ephemeralSignerPubkey) {
|
2614
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
2615
|
+
additionalSigners.push(wrappedSolAccount);
|
2616
|
+
}
|
2604
2617
|
preInstructions = [
|
2605
2618
|
web3_js_1.SystemProgram.createAccount({
|
2606
2619
|
fromPubkey: publicKey,
|
2607
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
2620
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
2608
2621
|
lamports: lamports,
|
2609
2622
|
space: 165,
|
2610
2623
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
2611
2624
|
}),
|
2612
|
-
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
2625
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
2613
2626
|
];
|
2614
2627
|
postInstructions = [
|
2615
|
-
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
2628
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2616
2629
|
];
|
2617
2630
|
additionalSigners.push(wrappedSolAccount);
|
2618
2631
|
return [3, 5];
|
@@ -2659,7 +2672,7 @@ var PerpetualsClient = (function () {
|
|
2659
2672
|
perpProgram: this.programId,
|
2660
2673
|
owner: publicKey,
|
2661
2674
|
fundingAccount: userCollateralTokenAccount,
|
2662
|
-
receivingAccount: outputSymbol == 'SOL' ? wrappedSolAccount.publicKey : userReceivingTokenAccount,
|
2675
|
+
receivingAccount: outputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
2663
2676
|
transferAuthority: swapPoolConfig.transferAuthority,
|
2664
2677
|
perpetuals: swapPoolConfig.perpetuals,
|
2665
2678
|
swapPool: swapPoolConfig.poolAddress,
|
@@ -2694,11 +2707,12 @@ var PerpetualsClient = (function () {
|
|
2694
2707
|
});
|
2695
2708
|
});
|
2696
2709
|
};
|
2697
|
-
this.swap = function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks) {
|
2710
|
+
this.swap = function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey) {
|
2698
2711
|
if (useFeesPool === void 0) { useFeesPool = false; }
|
2699
2712
|
if (createUserATA === void 0) { createUserATA = true; }
|
2700
2713
|
if (unWrapSol === void 0) { unWrapSol = false; }
|
2701
2714
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2715
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2702
2716
|
return __awaiter(_this, void 0, void 0, function () {
|
2703
2717
|
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_2;
|
2704
2718
|
return __generator(this, function (_f) {
|
@@ -2759,7 +2773,6 @@ var PerpetualsClient = (function () {
|
|
2759
2773
|
_f.trys.push([6, 21, , 22]);
|
2760
2774
|
if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
|
2761
2775
|
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
2762
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
2763
2776
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
2764
2777
|
case 7:
|
2765
2778
|
accCreationLamports = (_f.sent());
|
@@ -2772,20 +2785,24 @@ var PerpetualsClient = (function () {
|
|
2772
2785
|
if (unWrappedSolBalance.lt(amountIn)) {
|
2773
2786
|
throw "Insufficient SOL Funds";
|
2774
2787
|
}
|
2788
|
+
if (!ephemeralSignerPubkey) {
|
2789
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
2790
|
+
additionalSigners.push(wrappedSolAccount);
|
2791
|
+
}
|
2792
|
+
;
|
2775
2793
|
preInstructions = [
|
2776
2794
|
web3_js_1.SystemProgram.createAccount({
|
2777
2795
|
fromPubkey: publicKey,
|
2778
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
2796
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
2779
2797
|
lamports: lamports.toNumber(),
|
2780
2798
|
space: 165,
|
2781
2799
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
2782
2800
|
}),
|
2783
|
-
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
2801
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
2784
2802
|
];
|
2785
2803
|
postInstructions = [
|
2786
|
-
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
2804
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2787
2805
|
];
|
2788
|
-
additionalSigners.push(wrappedSolAccount);
|
2789
2806
|
return [3, 13];
|
2790
2807
|
case 9: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey)];
|
2791
2808
|
case 10:
|
@@ -2806,24 +2823,27 @@ var PerpetualsClient = (function () {
|
|
2806
2823
|
_f.label = 13;
|
2807
2824
|
case 13:
|
2808
2825
|
if (!(userOutputTokenSymbol == 'SOL')) return [3, 15];
|
2809
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
2810
2826
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
2811
2827
|
case 14:
|
2812
2828
|
lamports = (_f.sent());
|
2829
|
+
if (!ephemeralSignerPubkey) {
|
2830
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
2831
|
+
additionalSigners.push(wrappedSolAccount);
|
2832
|
+
}
|
2833
|
+
;
|
2813
2834
|
preInstructions = [
|
2814
2835
|
web3_js_1.SystemProgram.createAccount({
|
2815
2836
|
fromPubkey: publicKey,
|
2816
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
2837
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
2817
2838
|
lamports: lamports,
|
2818
2839
|
space: 165,
|
2819
2840
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
2820
2841
|
}),
|
2821
|
-
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
2842
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
2822
2843
|
];
|
2823
2844
|
postInstructions = [
|
2824
|
-
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
2845
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2825
2846
|
];
|
2826
|
-
additionalSigners.push(wrappedSolAccount);
|
2827
2847
|
return [3, 19];
|
2828
2848
|
case 15: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey)];
|
2829
2849
|
case 16:
|
@@ -2864,8 +2884,8 @@ var PerpetualsClient = (function () {
|
|
2864
2884
|
.swap(params)
|
2865
2885
|
.accounts({
|
2866
2886
|
owner: publicKey,
|
2867
|
-
fundingAccount: userInputTokenSymbol == 'SOL' ? wrappedSolAccount.publicKey : userInputTokenAccount,
|
2868
|
-
receivingAccount: userOutputTokenSymbol == 'SOL' ? wrappedSolAccount.publicKey : userOutputTokenAccount,
|
2887
|
+
fundingAccount: userInputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
|
2888
|
+
receivingAccount: userOutputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userOutputTokenAccount,
|
2869
2889
|
transferAuthority: poolConfig.transferAuthority,
|
2870
2890
|
perpetuals: poolConfig.perpetuals,
|
2871
2891
|
pool: poolConfig.poolAddress,
|
@@ -2973,8 +2993,9 @@ var PerpetualsClient = (function () {
|
|
2973
2993
|
}
|
2974
2994
|
});
|
2975
2995
|
}); };
|
2976
|
-
this.addCollateral = function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks) {
|
2996
|
+
this.addCollateral = function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
2977
2997
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2998
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2978
2999
|
return __awaiter(_this, void 0, void 0, function () {
|
2979
3000
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, solBal, tokenAccountBalance, _b, instruction;
|
2980
3001
|
return __generator(this, function (_c) {
|
@@ -2994,7 +3015,6 @@ var PerpetualsClient = (function () {
|
|
2994
3015
|
additionalSigners = [];
|
2995
3016
|
if (!(collateralSymbol == 'SOL')) return [3, 4];
|
2996
3017
|
console.log("collateralSymbol === SOL", collateralSymbol);
|
2997
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
2998
3018
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
2999
3019
|
case 1:
|
3000
3020
|
accCreationLamports = (_c.sent());
|
@@ -3012,20 +3032,23 @@ var PerpetualsClient = (function () {
|
|
3012
3032
|
case 3:
|
3013
3033
|
solBal = _c.sent();
|
3014
3034
|
console.log("solBal>>:", solBal);
|
3035
|
+
if (!ephemeralSignerPubkey) {
|
3036
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
3037
|
+
additionalSigners.push(wrappedSolAccount);
|
3038
|
+
}
|
3015
3039
|
preInstructions = [
|
3016
3040
|
web3_js_1.SystemProgram.createAccount({
|
3017
3041
|
fromPubkey: publicKey,
|
3018
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
3042
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
3019
3043
|
lamports: lamports.toNumber(),
|
3020
3044
|
space: 165,
|
3021
3045
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3022
3046
|
}),
|
3023
|
-
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
3047
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
3024
3048
|
];
|
3025
3049
|
postInstructions = [
|
3026
|
-
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
3050
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3027
3051
|
];
|
3028
|
-
additionalSigners.push(wrappedSolAccount);
|
3029
3052
|
return [3, 7];
|
3030
3053
|
case 4: return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
3031
3054
|
case 5:
|
@@ -3047,7 +3070,7 @@ var PerpetualsClient = (function () {
|
|
3047
3070
|
owner: publicKey,
|
3048
3071
|
position: positionPubKey,
|
3049
3072
|
market: marketAccount,
|
3050
|
-
fundingAccount: collateralSymbol == 'SOL' ? wrappedSolAccount.publicKey : userPayingTokenAccount,
|
3073
|
+
fundingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userPayingTokenAccount,
|
3051
3074
|
perpetuals: poolConfig.perpetuals,
|
3052
3075
|
pool: poolConfig.poolAddress,
|
3053
3076
|
targetCustody: targetCustodyConfig.custodyAccount,
|
@@ -3072,8 +3095,9 @@ var PerpetualsClient = (function () {
|
|
3072
3095
|
});
|
3073
3096
|
});
|
3074
3097
|
};
|
3075
|
-
this.addCollateralWithSwap = function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minAmountOut, side, positionPubKey, poolConfigSwap, poolConfigPosition, skipBalanceChecks) {
|
3098
|
+
this.addCollateralWithSwap = function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minAmountOut, side, positionPubKey, poolConfigSwap, poolConfigPosition, skipBalanceChecks, ephemeralSignerPubkey) {
|
3076
3099
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3100
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3077
3101
|
return __awaiter(_this, void 0, void 0, function () {
|
3078
3102
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, outputCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, marketAccount, instruction;
|
3079
3103
|
return __generator(this, function (_d) {
|
@@ -3096,7 +3120,6 @@ var PerpetualsClient = (function () {
|
|
3096
3120
|
additionalSigners = [];
|
3097
3121
|
if (!(inputSymbol == 'SOL')) return [3, 3];
|
3098
3122
|
console.log("inputSymbol === SOL", inputSymbol);
|
3099
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
3100
3123
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
3101
3124
|
case 1:
|
3102
3125
|
accCreationLamports = (_d.sent());
|
@@ -3110,20 +3133,23 @@ var PerpetualsClient = (function () {
|
|
3110
3133
|
if (unWrappedSolBalance.lt(lamports)) {
|
3111
3134
|
throw "Insufficient SOL Funds";
|
3112
3135
|
}
|
3136
|
+
if (!ephemeralSignerPubkey) {
|
3137
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
3138
|
+
additionalSigners.push(wrappedSolAccount);
|
3139
|
+
}
|
3113
3140
|
preInstructions = [
|
3114
3141
|
web3_js_1.SystemProgram.createAccount({
|
3115
3142
|
fromPubkey: publicKey,
|
3116
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
3143
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
3117
3144
|
lamports: lamports.toNumber(),
|
3118
3145
|
space: 165,
|
3119
3146
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3120
3147
|
}),
|
3121
|
-
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
3148
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
3122
3149
|
];
|
3123
3150
|
postInstructions = [
|
3124
|
-
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
3151
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3125
3152
|
];
|
3126
|
-
additionalSigners.push(wrappedSolAccount);
|
3127
3153
|
return [3, 6];
|
3128
3154
|
case 3:
|
3129
3155
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
@@ -3170,7 +3196,7 @@ var PerpetualsClient = (function () {
|
|
3170
3196
|
}).accounts({
|
3171
3197
|
perpProgram: this.programId,
|
3172
3198
|
owner: publicKey,
|
3173
|
-
fundingAccount: inputSymbol == 'SOL' ? wrappedSolAccount.publicKey : userInputTokenAccount,
|
3199
|
+
fundingAccount: inputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
|
3174
3200
|
receivingAccount: userCollateralTokenAccount,
|
3175
3201
|
transferAuthority: poolConfigSwap.transferAuthority,
|
3176
3202
|
perpetuals: poolConfigSwap.perpetuals,
|
@@ -3206,9 +3232,10 @@ var PerpetualsClient = (function () {
|
|
3206
3232
|
});
|
3207
3233
|
});
|
3208
3234
|
};
|
3209
|
-
this.removeCollateral = function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA) {
|
3235
|
+
this.removeCollateral = function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
3210
3236
|
if (createUserATA === void 0) { createUserATA = true; }
|
3211
3237
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3238
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3212
3239
|
return __awaiter(_this, void 0, void 0, function () {
|
3213
3240
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns, error_3;
|
3214
3241
|
return __generator(this, function (_b) {
|
@@ -3234,25 +3261,27 @@ var PerpetualsClient = (function () {
|
|
3234
3261
|
console.log("removeCollateral -- collateralSymbol:", collateralSymbol);
|
3235
3262
|
if (!(collateralSymbol == 'SOL')) return [3, 3];
|
3236
3263
|
console.log("remove collateral in SOL ...create WSOL temp and close it ");
|
3237
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
3238
3264
|
userReceivingTokenAccount = wrappedSolAccount.publicKey;
|
3239
3265
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
3240
3266
|
case 2:
|
3241
3267
|
lamports = (_b.sent());
|
3268
|
+
if (!ephemeralSignerPubkey) {
|
3269
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
3270
|
+
additionalSigners.push(wrappedSolAccount);
|
3271
|
+
}
|
3242
3272
|
preInstructions = [
|
3243
3273
|
web3_js_1.SystemProgram.createAccount({
|
3244
3274
|
fromPubkey: publicKey,
|
3245
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
3275
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
3246
3276
|
lamports: lamports,
|
3247
3277
|
space: 165,
|
3248
3278
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3249
3279
|
}),
|
3250
|
-
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
3280
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
3251
3281
|
];
|
3252
3282
|
postInstructions = [
|
3253
|
-
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
3283
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3254
3284
|
];
|
3255
|
-
additionalSigners.push(wrappedSolAccount);
|
3256
3285
|
return [3, 7];
|
3257
3286
|
case 3: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey)];
|
3258
3287
|
case 4:
|
@@ -3276,7 +3305,7 @@ var PerpetualsClient = (function () {
|
|
3276
3305
|
})
|
3277
3306
|
.accounts({
|
3278
3307
|
owner: publicKey,
|
3279
|
-
receivingAccount: collateralSymbol == 'SOL' ? wrappedSolAccount.publicKey : userReceivingTokenAccount,
|
3308
|
+
receivingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
3280
3309
|
transferAuthority: poolConfig.transferAuthority,
|
3281
3310
|
perpetuals: poolConfig.perpetuals,
|
3282
3311
|
pool: poolConfig.poolAddress,
|
@@ -3313,120 +3342,125 @@ var PerpetualsClient = (function () {
|
|
3313
3342
|
});
|
3314
3343
|
});
|
3315
3344
|
};
|
3316
|
-
this.removeCollateralWithSwap = function (targetSymbol, collateralSymbol, outputSymbol, minAmountOut, collateralDelta, side, poolConfigSwap, poolConfigPosition
|
3317
|
-
|
3318
|
-
return
|
3319
|
-
|
3320
|
-
|
3321
|
-
|
3322
|
-
|
3323
|
-
|
3324
|
-
|
3325
|
-
|
3326
|
-
|
3327
|
-
|
3328
|
-
|
3329
|
-
|
3330
|
-
|
3331
|
-
|
3332
|
-
|
3333
|
-
|
3334
|
-
|
3335
|
-
|
3336
|
-
|
3337
|
-
|
3338
|
-
|
3339
|
-
|
3340
|
-
|
3341
|
-
|
3342
|
-
|
3343
|
-
|
3344
|
-
|
3345
|
-
|
3346
|
-
|
3347
|
-
|
3348
|
-
|
3349
|
-
|
3350
|
-
|
3351
|
-
|
3352
|
-
|
3353
|
-
|
3354
|
-
|
3355
|
-
|
3356
|
-
|
3357
|
-
|
3358
|
-
|
3359
|
-
|
3360
|
-
|
3361
|
-
|
3362
|
-
|
3363
|
-
|
3364
|
-
|
3365
|
-
|
3366
|
-
|
3367
|
-
|
3368
|
-
|
3369
|
-
|
3370
|
-
|
3371
|
-
|
3372
|
-
|
3373
|
-
|
3374
|
-
|
3375
|
-
|
3376
|
-
custodyAccountMetas
|
3377
|
-
|
3378
|
-
|
3379
|
-
|
3380
|
-
|
3381
|
-
|
3382
|
-
|
3383
|
-
|
3384
|
-
|
3385
|
-
|
3386
|
-
|
3387
|
-
|
3388
|
-
|
3389
|
-
|
3390
|
-
|
3391
|
-
|
3392
|
-
|
3393
|
-
|
3394
|
-
|
3395
|
-
|
3396
|
-
|
3397
|
-
|
3398
|
-
|
3399
|
-
|
3400
|
-
|
3401
|
-
|
3402
|
-
|
3403
|
-
|
3404
|
-
|
3405
|
-
|
3406
|
-
|
3407
|
-
|
3408
|
-
|
3409
|
-
|
3410
|
-
|
3411
|
-
|
3412
|
-
|
3413
|
-
|
3414
|
-
|
3415
|
-
|
3416
|
-
|
3417
|
-
|
3418
|
-
|
3419
|
-
|
3420
|
-
|
3421
|
-
|
3422
|
-
|
3423
|
-
|
3424
|
-
|
3425
|
-
|
3426
|
-
|
3427
|
-
|
3345
|
+
this.removeCollateralWithSwap = function (targetSymbol, collateralSymbol, outputSymbol, minAmountOut, collateralDelta, side, poolConfigSwap, poolConfigPosition, ephemeralSignerPubkey) {
|
3346
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3347
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3348
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, inputCusotdyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody, instruction;
|
3349
|
+
return __generator(this, function (_b) {
|
3350
|
+
switch (_b.label) {
|
3351
|
+
case 0:
|
3352
|
+
publicKey = this.provider.wallet.publicKey;
|
3353
|
+
targetCustodyConfig = poolConfigPosition.custodies.find(function (i) { return i.mintKey.equals(poolConfigPosition.getTokenFromSymbol(targetSymbol).mintKey); });
|
3354
|
+
collateralCustodyConfig = poolConfigPosition.custodies.find(function (i) { return i.mintKey.equals(poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey); });
|
3355
|
+
inputCusotdyConfig = poolConfigSwap.custodies.find(function (i) { return i.mintKey.equals(poolConfigSwap.getTokenFromSymbol(collateralSymbol).mintKey); });
|
3356
|
+
outputCustodyConfig = poolConfigSwap.custodies.find(function (i) { return i.mintKey.equals(poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey); });
|
3357
|
+
if (outputCustodyConfig.mintKey.equals(collateralCustodyConfig.mintKey)) {
|
3358
|
+
throw "Dont use swap, just call remove collateral";
|
3359
|
+
}
|
3360
|
+
preInstructions = [];
|
3361
|
+
instructions = [];
|
3362
|
+
postInstructions = [];
|
3363
|
+
additionalSigners = [];
|
3364
|
+
if (!(outputSymbol == 'SOL')) return [3, 2];
|
3365
|
+
console.log("outputSymbol === SOL", outputSymbol);
|
3366
|
+
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
3367
|
+
case 1:
|
3368
|
+
lamports = (_b.sent());
|
3369
|
+
if (!ephemeralSignerPubkey) {
|
3370
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
3371
|
+
additionalSigners.push(wrappedSolAccount);
|
3372
|
+
}
|
3373
|
+
preInstructions = [
|
3374
|
+
web3_js_1.SystemProgram.createAccount({
|
3375
|
+
fromPubkey: publicKey,
|
3376
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
3377
|
+
lamports: lamports,
|
3378
|
+
space: 165,
|
3379
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3380
|
+
}),
|
3381
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
3382
|
+
];
|
3383
|
+
postInstructions = [
|
3384
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3385
|
+
];
|
3386
|
+
return [3, 5];
|
3387
|
+
case 2: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey, publicKey)];
|
3388
|
+
case 3:
|
3389
|
+
userReceivingTokenAccount = _b.sent();
|
3390
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
3391
|
+
case 4:
|
3392
|
+
if (!(_b.sent())) {
|
3393
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey));
|
3394
|
+
}
|
3395
|
+
_b.label = 5;
|
3396
|
+
case 5:
|
3397
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
3398
|
+
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3399
|
+
case 6:
|
3400
|
+
if (!(_b.sent())) {
|
3401
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey));
|
3402
|
+
}
|
3403
|
+
marketAccount = poolConfigPosition.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3404
|
+
positionAccount = poolConfigPosition.getPositionFromMarketPk(publicKey, marketAccount);
|
3405
|
+
custodyAccountMetas = [];
|
3406
|
+
custodyOracleAccountMetas = [];
|
3407
|
+
for (_i = 0, _a = poolConfigSwap.custodies; _i < _a.length; _i++) {
|
3408
|
+
custody = _a[_i];
|
3409
|
+
custodyAccountMetas.push({
|
3410
|
+
pubkey: custody.custodyAccount,
|
3411
|
+
isSigner: false,
|
3412
|
+
isWritable: false,
|
3413
|
+
});
|
3414
|
+
custodyOracleAccountMetas.push({
|
3415
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
3416
|
+
isSigner: false,
|
3417
|
+
isWritable: false,
|
3418
|
+
});
|
3419
|
+
}
|
3420
|
+
return [4, this.programPerpComposability.methods
|
3421
|
+
.removeCollateralAndSwap({
|
3422
|
+
minAmountOut: minAmountOut,
|
3423
|
+
collateralDelta: collateralDelta,
|
3424
|
+
})
|
3425
|
+
.accounts({
|
3426
|
+
perpProgram: this.programId,
|
3427
|
+
owner: publicKey,
|
3428
|
+
fundingAccount: userCollateralTokenAccount,
|
3429
|
+
receivingAccount: outputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
3430
|
+
transferAuthority: poolConfigSwap.transferAuthority,
|
3431
|
+
perpetuals: poolConfigSwap.perpetuals,
|
3432
|
+
swapPool: poolConfigSwap.poolAddress,
|
3433
|
+
receivingCustody: inputCusotdyConfig.custodyAccount,
|
3434
|
+
receivingCustodyOracleAccount: this.useExtOracleAccount ? inputCusotdyConfig.extOracleAccount : inputCusotdyConfig.intOracleAccount,
|
3435
|
+
receivingCustodyTokenAccount: inputCusotdyConfig.tokenAccount,
|
3436
|
+
dispensingCustody: outputCustodyConfig.custodyAccount,
|
3437
|
+
dispensingCustodyOracleAccount: this.useExtOracleAccount ? outputCustodyConfig.extOracleAccount : outputCustodyConfig.intOracleAccount,
|
3438
|
+
dispensingCustodyTokenAccount: outputCustodyConfig.tokenAccount,
|
3439
|
+
positionPool: poolConfigPosition.poolAddress,
|
3440
|
+
position: positionAccount,
|
3441
|
+
market: marketAccount,
|
3442
|
+
targetCustody: targetCustodyConfig.custodyAccount,
|
3443
|
+
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
3444
|
+
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3445
|
+
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3446
|
+
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3447
|
+
eventAuthority: this.eventAuthority.publicKey,
|
3448
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3449
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3450
|
+
})
|
3451
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
3452
|
+
.instruction()];
|
3453
|
+
case 7:
|
3454
|
+
instruction = _b.sent();
|
3455
|
+
instructions.push(instruction);
|
3456
|
+
return [2, {
|
3457
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3458
|
+
additionalSigners: additionalSigners
|
3459
|
+
}];
|
3460
|
+
}
|
3461
|
+
});
|
3428
3462
|
});
|
3429
|
-
}
|
3463
|
+
};
|
3430
3464
|
this.increaseSize = function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount) {
|
3431
3465
|
if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
|
3432
3466
|
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
@@ -3547,8 +3581,9 @@ var PerpetualsClient = (function () {
|
|
3547
3581
|
});
|
3548
3582
|
});
|
3549
3583
|
};
|
3550
|
-
this.addLiquidity = function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks) {
|
3584
|
+
this.addLiquidity = function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3551
3585
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3586
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3552
3587
|
return __awaiter(_this, void 0, void 0, function () {
|
3553
3588
|
var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, accCreationLamports, lamports, unWrappedSolBalance, _d, tokenAccountBalance, _e, instruction, err_4;
|
3554
3589
|
return __generator(this, function (_f) {
|
@@ -3603,7 +3638,6 @@ var PerpetualsClient = (function () {
|
|
3603
3638
|
}
|
3604
3639
|
if (!(payTokenSymbol == 'SOL')) return [3, 7];
|
3605
3640
|
console.log("payTokenSymbol === SOL", payTokenSymbol);
|
3606
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
3607
3641
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
3608
3642
|
case 5:
|
3609
3643
|
accCreationLamports = (_f.sent());
|
@@ -3616,20 +3650,23 @@ var PerpetualsClient = (function () {
|
|
3616
3650
|
if (unWrappedSolBalance.lt(lamports)) {
|
3617
3651
|
throw "Insufficient SOL Funds";
|
3618
3652
|
}
|
3653
|
+
if (!ephemeralSignerPubkey) {
|
3654
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
3655
|
+
additionalSigners.push(wrappedSolAccount);
|
3656
|
+
}
|
3619
3657
|
preInstructions = [
|
3620
3658
|
web3_js_1.SystemProgram.createAccount({
|
3621
3659
|
fromPubkey: publicKey,
|
3622
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
3660
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
3623
3661
|
lamports: lamports.toNumber(),
|
3624
3662
|
space: 165,
|
3625
3663
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3626
3664
|
}),
|
3627
|
-
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
3665
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
3628
3666
|
];
|
3629
3667
|
postInstructions = [
|
3630
|
-
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
3668
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3631
3669
|
];
|
3632
|
-
additionalSigners.push(wrappedSolAccount);
|
3633
3670
|
return [3, 10];
|
3634
3671
|
case 7: return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
3635
3672
|
case 8:
|
@@ -3652,7 +3689,7 @@ var PerpetualsClient = (function () {
|
|
3652
3689
|
})
|
3653
3690
|
.accounts({
|
3654
3691
|
owner: publicKey,
|
3655
|
-
fundingAccount: payTokenSymbol == 'SOL' ? wrappedSolAccount.publicKey : userPayingTokenAccount,
|
3692
|
+
fundingAccount: payTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userPayingTokenAccount,
|
3656
3693
|
lpTokenAccount: lpTokenAccount,
|
3657
3694
|
transferAuthority: poolConfig.transferAuthority,
|
3658
3695
|
perpetuals: poolConfig.perpetuals,
|
@@ -3684,8 +3721,9 @@ var PerpetualsClient = (function () {
|
|
3684
3721
|
});
|
3685
3722
|
});
|
3686
3723
|
};
|
3687
|
-
this.addLiquidityAndStake = function (inputSymbol, amountIn, minLpAmountOut, poolConfig, skipBalanceChecks) {
|
3724
|
+
this.addLiquidityAndStake = function (inputSymbol, amountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3688
3725
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3726
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3689
3727
|
return __awaiter(_this, void 0, void 0, function () {
|
3690
3728
|
var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, flpStakeAccount, poolStakedLpVault, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _c, custody, _d, _e, market, instruction;
|
3691
3729
|
return __generator(this, function (_f) {
|
@@ -3705,7 +3743,6 @@ var PerpetualsClient = (function () {
|
|
3705
3743
|
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
3706
3744
|
if (!(inputSymbol == 'SOL')) return [3, 5];
|
3707
3745
|
console.log("inputSymbol === SOL", inputSymbol);
|
3708
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
3709
3746
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
3710
3747
|
case 2:
|
3711
3748
|
accCreationLamports = (_f.sent());
|
@@ -3724,20 +3761,23 @@ var PerpetualsClient = (function () {
|
|
3724
3761
|
if (!(_f.sent())) {
|
3725
3762
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
3726
3763
|
}
|
3764
|
+
if (!ephemeralSignerPubkey) {
|
3765
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
3766
|
+
additionalSigners.push(wrappedSolAccount);
|
3767
|
+
}
|
3727
3768
|
preInstructions = [
|
3728
3769
|
web3_js_1.SystemProgram.createAccount({
|
3729
3770
|
fromPubkey: publicKey,
|
3730
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
3771
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
3731
3772
|
lamports: lamports.toNumber(),
|
3732
3773
|
space: 165,
|
3733
3774
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3734
3775
|
}),
|
3735
|
-
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
3776
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
3736
3777
|
];
|
3737
3778
|
postInstructions = [
|
3738
|
-
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
3779
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3739
3780
|
];
|
3740
|
-
additionalSigners.push(wrappedSolAccount);
|
3741
3781
|
return [3, 8];
|
3742
3782
|
case 5:
|
3743
3783
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
@@ -3786,7 +3826,7 @@ var PerpetualsClient = (function () {
|
|
3786
3826
|
}).accounts({
|
3787
3827
|
owner: publicKey,
|
3788
3828
|
feePayer: publicKey,
|
3789
|
-
fundingAccount: inputSymbol == 'SOL' ? wrappedSolAccount.publicKey : userInputTokenAccount,
|
3829
|
+
fundingAccount: inputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
|
3790
3830
|
transferAuthority: poolConfig.transferAuthority,
|
3791
3831
|
perpetuals: poolConfig.perpetuals,
|
3792
3832
|
pool: poolConfig.poolAddress,
|
@@ -3815,10 +3855,11 @@ var PerpetualsClient = (function () {
|
|
3815
3855
|
});
|
3816
3856
|
});
|
3817
3857
|
};
|
3818
|
-
this.removeLiquidity = function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA) {
|
3858
|
+
this.removeLiquidity = function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
3819
3859
|
if (closeLpATA === void 0) { closeLpATA = false; }
|
3820
3860
|
if (createUserATA === void 0) { createUserATA = true; }
|
3821
3861
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3862
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3822
3863
|
return __awaiter(_this, void 0, void 0, function () {
|
3823
3864
|
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_5;
|
3824
3865
|
return __generator(this, function (_e) {
|
@@ -3864,25 +3905,26 @@ var PerpetualsClient = (function () {
|
|
3864
3905
|
});
|
3865
3906
|
}
|
3866
3907
|
if (!(recieveTokenSymbol == 'SOL')) return [3, 4];
|
3867
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
3868
|
-
userReceivingTokenAccount = wrappedSolAccount.publicKey;
|
3869
3908
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
3870
3909
|
case 3:
|
3871
3910
|
lamports = (_e.sent());
|
3911
|
+
if (!ephemeralSignerPubkey) {
|
3912
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
3913
|
+
additionalSigners.push(wrappedSolAccount);
|
3914
|
+
}
|
3872
3915
|
preInstructions = [
|
3873
3916
|
web3_js_1.SystemProgram.createAccount({
|
3874
3917
|
fromPubkey: publicKey,
|
3875
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
3918
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
3876
3919
|
lamports: lamports,
|
3877
3920
|
space: 165,
|
3878
3921
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3879
3922
|
}),
|
3880
|
-
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
3923
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
3881
3924
|
];
|
3882
3925
|
postInstructions = [
|
3883
|
-
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
3926
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3884
3927
|
];
|
3885
|
-
additionalSigners.push(wrappedSolAccount);
|
3886
3928
|
return [3, 8];
|
3887
3929
|
case 4: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey)];
|
3888
3930
|
case 5:
|
@@ -3907,7 +3949,7 @@ var PerpetualsClient = (function () {
|
|
3907
3949
|
})
|
3908
3950
|
.accounts({
|
3909
3951
|
owner: publicKey,
|
3910
|
-
receivingAccount: recieveTokenSymbol == 'SOL' ? wrappedSolAccount.publicKey : userReceivingTokenAccount,
|
3952
|
+
receivingAccount: recieveTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
3911
3953
|
lpTokenAccount: stakedLpTokenAccount,
|
3912
3954
|
transferAuthority: poolConfig.transferAuthority,
|
3913
3955
|
perpetuals: poolConfig.perpetuals,
|
@@ -4974,9 +5016,10 @@ var PerpetualsClient = (function () {
|
|
4974
5016
|
}
|
4975
5017
|
});
|
4976
5018
|
}); };
|
4977
|
-
this.forceClosePosition = function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA) {
|
5019
|
+
this.forceClosePosition = function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
4978
5020
|
if (createUserATA === void 0) { createUserATA = true; }
|
4979
5021
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
5022
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4980
5023
|
return __awaiter(_this, void 0, void 0, function () {
|
4981
5024
|
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, forceClosePosition, closeWsolATAIns, err_24;
|
4982
5025
|
return __generator(this, function (_b) {
|
@@ -4995,24 +5038,26 @@ var PerpetualsClient = (function () {
|
|
4995
5038
|
_b.trys.push([1, 9, , 10]);
|
4996
5039
|
if (!(collateralSymbol == 'SOL')) return [3, 3];
|
4997
5040
|
console.log("collateralSymbol === SOL", collateralSymbol);
|
4998
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
4999
5041
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
5000
5042
|
case 2:
|
5001
5043
|
lamports = (_b.sent());
|
5044
|
+
if (!ephemeralSignerPubkey) {
|
5045
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
5046
|
+
additionalSigners.push(wrappedSolAccount);
|
5047
|
+
}
|
5002
5048
|
preInstructions = [
|
5003
5049
|
web3_js_1.SystemProgram.createAccount({
|
5004
5050
|
fromPubkey: payerPubkey,
|
5005
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
5051
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
5006
5052
|
lamports: lamports,
|
5007
5053
|
space: 165,
|
5008
5054
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
5009
5055
|
}),
|
5010
|
-
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, positionAccount.owner),
|
5056
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, positionAccount.owner),
|
5011
5057
|
];
|
5012
5058
|
postInstructions = [
|
5013
|
-
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, positionAccount.owner, positionAccount.owner),
|
5059
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), positionAccount.owner, positionAccount.owner),
|
5014
5060
|
];
|
5015
|
-
additionalSigners.push(wrappedSolAccount);
|
5016
5061
|
return [3, 7];
|
5017
5062
|
case 3: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, positionAccount.owner)];
|
5018
5063
|
case 4:
|
@@ -5035,7 +5080,7 @@ var PerpetualsClient = (function () {
|
|
5035
5080
|
})
|
5036
5081
|
.accounts({
|
5037
5082
|
owner: positionAccount.owner,
|
5038
|
-
receivingAccount: collateralSymbol == 'SOL' ? wrappedSolAccount.publicKey : userReceivingTokenAccount,
|
5083
|
+
receivingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
5039
5084
|
transferAuthority: poolConfig.transferAuthority,
|
5040
5085
|
perpetuals: this.perpetuals.publicKey,
|
5041
5086
|
pool: poolConfig.poolAddress,
|
@@ -5307,145 +5352,151 @@ var PerpetualsClient = (function () {
|
|
5307
5352
|
}
|
5308
5353
|
});
|
5309
5354
|
}); };
|
5310
|
-
this.addCompoundingLiquidity = function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig
|
5311
|
-
|
5312
|
-
return
|
5313
|
-
|
5314
|
-
|
5315
|
-
|
5316
|
-
|
5317
|
-
|
5318
|
-
|
5319
|
-
|
5320
|
-
|
5321
|
-
|
5322
|
-
|
5323
|
-
|
5324
|
-
|
5325
|
-
|
5326
|
-
|
5327
|
-
|
5328
|
-
|
5329
|
-
|
5330
|
-
|
5331
|
-
|
5332
|
-
|
5333
|
-
|
5334
|
-
|
5335
|
-
|
5336
|
-
|
5337
|
-
|
5338
|
-
|
5339
|
-
|
5340
|
-
|
5341
|
-
|
5342
|
-
|
5343
|
-
|
5344
|
-
|
5345
|
-
|
5346
|
-
|
5347
|
-
|
5348
|
-
|
5349
|
-
|
5350
|
-
|
5351
|
-
markets.
|
5352
|
-
|
5353
|
-
|
5354
|
-
|
5355
|
-
|
5356
|
-
|
5357
|
-
|
5358
|
-
|
5359
|
-
|
5360
|
-
|
5361
|
-
|
5362
|
-
|
5363
|
-
|
5364
|
-
|
5365
|
-
|
5366
|
-
|
5367
|
-
|
5368
|
-
|
5369
|
-
|
5370
|
-
|
5371
|
-
|
5372
|
-
|
5373
|
-
|
5374
|
-
|
5375
|
-
|
5376
|
-
|
5377
|
-
|
5378
|
-
|
5379
|
-
|
5380
|
-
|
5381
|
-
|
5382
|
-
|
5383
|
-
|
5384
|
-
|
5385
|
-
|
5386
|
-
|
5387
|
-
|
5388
|
-
|
5389
|
-
|
5390
|
-
|
5391
|
-
|
5392
|
-
|
5393
|
-
|
5394
|
-
|
5395
|
-
|
5396
|
-
|
5397
|
-
|
5398
|
-
|
5399
|
-
|
5400
|
-
|
5401
|
-
|
5402
|
-
|
5403
|
-
|
5404
|
-
|
5405
|
-
|
5406
|
-
|
5407
|
-
|
5408
|
-
|
5409
|
-
|
5410
|
-
|
5411
|
-
|
5412
|
-
|
5413
|
-
|
5414
|
-
|
5415
|
-
|
5416
|
-
|
5417
|
-
|
5418
|
-
|
5419
|
-
|
5420
|
-
|
5421
|
-
|
5422
|
-
|
5423
|
-
|
5424
|
-
|
5425
|
-
|
5426
|
-
|
5427
|
-
|
5428
|
-
|
5429
|
-
|
5430
|
-
|
5431
|
-
|
5432
|
-
|
5433
|
-
|
5434
|
-
|
5435
|
-
|
5436
|
-
|
5437
|
-
|
5438
|
-
|
5439
|
-
|
5440
|
-
|
5441
|
-
|
5442
|
-
|
5443
|
-
|
5444
|
-
|
5355
|
+
this.addCompoundingLiquidity = function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, ephemeralSignerPubkey) {
|
5356
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5357
|
+
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, accCreationLamports, lamports, unWrappedSolBalance, _d, addCompoundingLiquidity, err_30;
|
5359
|
+
return __generator(this, function (_e) {
|
5360
|
+
switch (_e.label) {
|
5361
|
+
case 0:
|
5362
|
+
publicKey = this.provider.wallet.publicKey;
|
5363
|
+
preInstructions = [];
|
5364
|
+
instructions = [];
|
5365
|
+
additionalSigners = [];
|
5366
|
+
postInstructions = [];
|
5367
|
+
rewardCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardTokenMint); });
|
5368
|
+
inCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inTokenSymbol).mintKey); });
|
5369
|
+
lpTokenMint = poolConfig.stakedLpTokenMint;
|
5370
|
+
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
5371
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.stakedLpTokenMint, publicKey)];
|
5372
|
+
case 1:
|
5373
|
+
lpTokenAccount = _e.sent();
|
5374
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(compoundingTokenMint, publicKey)];
|
5375
|
+
case 2:
|
5376
|
+
compoundingTokenAccount = _e.sent();
|
5377
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(inCustodyConfig.mintKey, publicKey)];
|
5378
|
+
case 3:
|
5379
|
+
fundingAccount = _e.sent();
|
5380
|
+
custodyAccountMetas = [];
|
5381
|
+
custodyOracleAccountMetas = [];
|
5382
|
+
markets = [];
|
5383
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
5384
|
+
custody = _a[_i];
|
5385
|
+
custodyAccountMetas.push({
|
5386
|
+
pubkey: custody.custodyAccount,
|
5387
|
+
isSigner: false,
|
5388
|
+
isWritable: false,
|
5389
|
+
});
|
5390
|
+
custodyOracleAccountMetas.push({
|
5391
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
5392
|
+
isSigner: false,
|
5393
|
+
isWritable: false,
|
5394
|
+
});
|
5395
|
+
}
|
5396
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
5397
|
+
market = _c[_b];
|
5398
|
+
markets.push({
|
5399
|
+
pubkey: market.marketAccount,
|
5400
|
+
isSigner: false,
|
5401
|
+
isWritable: false,
|
5402
|
+
});
|
5403
|
+
}
|
5404
|
+
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
5405
|
+
case 4:
|
5406
|
+
if (!(_e.sent())) {
|
5407
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
5408
|
+
}
|
5409
|
+
return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
|
5410
|
+
case 5:
|
5411
|
+
if (!(_e.sent())) {
|
5412
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
|
5413
|
+
}
|
5414
|
+
if (!(inTokenSymbol == 'SOL')) return [3, 8];
|
5415
|
+
console.log("inTokenSymbol === SOL", inTokenSymbol);
|
5416
|
+
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
5417
|
+
case 6:
|
5418
|
+
accCreationLamports = (_e.sent());
|
5419
|
+
console.log("accCreationLamports:", accCreationLamports);
|
5420
|
+
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
5421
|
+
_d = anchor_1.BN.bind;
|
5422
|
+
return [4, this.provider.connection.getBalance(publicKey)];
|
5423
|
+
case 7:
|
5424
|
+
unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _e.sent()]))();
|
5425
|
+
if (unWrappedSolBalance.lt(lamports)) {
|
5426
|
+
throw "Insufficient SOL Funds";
|
5427
|
+
}
|
5428
|
+
if (!ephemeralSignerPubkey) {
|
5429
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
5430
|
+
additionalSigners.push(wrappedSolAccount);
|
5431
|
+
}
|
5432
|
+
preInstructions = [
|
5433
|
+
web3_js_1.SystemProgram.createAccount({
|
5434
|
+
fromPubkey: publicKey,
|
5435
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
5436
|
+
lamports: lamports.toNumber(),
|
5437
|
+
space: 165,
|
5438
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
5439
|
+
}),
|
5440
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
5441
|
+
];
|
5442
|
+
postInstructions = [
|
5443
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
5444
|
+
];
|
5445
|
+
return [3, 10];
|
5446
|
+
case 8: return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
|
5447
|
+
case 9:
|
5448
|
+
if (!(_e.sent())) {
|
5449
|
+
throw "Insufficient Funds , token Account doesn't exist";
|
5450
|
+
}
|
5451
|
+
_e.label = 10;
|
5452
|
+
case 10:
|
5453
|
+
_e.trys.push([10, 12, , 13]);
|
5454
|
+
return [4, this.program.methods
|
5455
|
+
.addCompoundingLiquidity({
|
5456
|
+
amountIn: amountIn,
|
5457
|
+
minCompoundingAmountOut: minCompoundingAmountOut
|
5458
|
+
})
|
5459
|
+
.accounts({
|
5460
|
+
owner: publicKey,
|
5461
|
+
fundingAccount: inTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : fundingAccount,
|
5462
|
+
compoundingTokenAccount: compoundingTokenAccount,
|
5463
|
+
poolCompoundingLpVault: poolConfig.compoundingLpVault,
|
5464
|
+
transferAuthority: poolConfig.transferAuthority,
|
5465
|
+
perpetuals: poolConfig.perpetuals,
|
5466
|
+
pool: poolConfig.poolAddress,
|
5467
|
+
inCustody: inCustodyConfig.custodyAccount,
|
5468
|
+
inCustodyOracleAccount: this.useExtOracleAccount ? inCustodyConfig.extOracleAccount : inCustodyConfig.intOracleAccount,
|
5469
|
+
inCustodyTokenAccount: inCustodyConfig.tokenAccount,
|
5470
|
+
rewardCustody: rewardCustody.custodyAccount,
|
5471
|
+
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
5472
|
+
lpTokenMint: lpTokenMint,
|
5473
|
+
compoundingTokenMint: compoundingTokenMint,
|
5474
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5475
|
+
eventAuthority: this.eventAuthority.publicKey,
|
5476
|
+
program: this.program.programId,
|
5477
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5478
|
+
})
|
5479
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5480
|
+
.instruction()];
|
5481
|
+
case 11:
|
5482
|
+
addCompoundingLiquidity = _e.sent();
|
5483
|
+
instructions.push(addCompoundingLiquidity);
|
5484
|
+
return [3, 13];
|
5485
|
+
case 12:
|
5486
|
+
err_30 = _e.sent();
|
5487
|
+
console.log("perpClient addCompoundingLiquidity error:: ", err_30);
|
5488
|
+
return [3, 13];
|
5489
|
+
case 13: return [2, {
|
5490
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5491
|
+
additionalSigners: additionalSigners
|
5492
|
+
}];
|
5493
|
+
}
|
5494
|
+
});
|
5445
5495
|
});
|
5446
|
-
}
|
5447
|
-
this.removeCompoundingLiquidity = function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA) {
|
5496
|
+
};
|
5497
|
+
this.removeCompoundingLiquidity = function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey) {
|
5448
5498
|
if (createUserATA === void 0) { createUserATA = true; }
|
5499
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5449
5500
|
return __awaiter(_this, void 0, void 0, function () {
|
5450
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, receivingAccount, removeCompoundingLiquidity, err_31;
|
5451
5502
|
return __generator(this, function (_e) {
|
@@ -5461,25 +5512,26 @@ var PerpetualsClient = (function () {
|
|
5461
5512
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
5462
5513
|
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
5463
5514
|
if (!(outCustodyConfig.symbol == 'SOL')) return [3, 2];
|
5464
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
5465
|
-
userReceivingTokenAccount = wrappedSolAccount.publicKey;
|
5466
5515
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
5467
5516
|
case 1:
|
5468
5517
|
lamports = (_e.sent());
|
5518
|
+
if (!ephemeralSignerPubkey) {
|
5519
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
5520
|
+
additionalSigners.push(wrappedSolAccount);
|
5521
|
+
}
|
5469
5522
|
preInstructions = [
|
5470
5523
|
web3_js_1.SystemProgram.createAccount({
|
5471
5524
|
fromPubkey: publicKey,
|
5472
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
5525
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
5473
5526
|
lamports: lamports,
|
5474
5527
|
space: 165,
|
5475
5528
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
5476
5529
|
}),
|
5477
|
-
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
5530
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
5478
5531
|
];
|
5479
5532
|
postInstructions = [
|
5480
|
-
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
5533
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
5481
5534
|
];
|
5482
|
-
additionalSigners.push(wrappedSolAccount);
|
5483
5535
|
return [3, 6];
|
5484
5536
|
case 2: return [4, (0, spl_token_1.getAssociatedTokenAddress)(outCustodyConfig.mintKey, publicKey)];
|
5485
5537
|
case 3:
|
@@ -5536,7 +5588,7 @@ var PerpetualsClient = (function () {
|
|
5536
5588
|
})
|
5537
5589
|
.accounts({
|
5538
5590
|
owner: publicKey,
|
5539
|
-
receivingAccount: outCustodyConfig.symbol == 'SOL' ? wrappedSolAccount.publicKey : userReceivingTokenAccount,
|
5591
|
+
receivingAccount: outCustodyConfig.symbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
5540
5592
|
compoundingTokenAccount: compoundingTokenAccount,
|
5541
5593
|
poolCompoundingLpVault: poolConfig.compoundingLpVault,
|
5542
5594
|
transferAuthority: poolConfig.transferAuthority,
|