flash-sdk 2.25.8 → 2.26.1
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/CustodyAccount.d.ts +1 -1
- package/dist/PerpetualsClient.d.ts +14 -14
- package/dist/PerpetualsClient.js +289 -352
- package/dist/PoolConfig.d.ts +0 -1
- package/dist/PoolConfig.json +167 -219
- package/dist/idl/perpetuals.d.ts +14 -192
- package/dist/idl/perpetuals.js +14 -192
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -501,7 +501,7 @@ var PerpetualsClient = (function () {
|
|
501
501
|
}
|
502
502
|
});
|
503
503
|
}); };
|
504
|
-
this.addCustody = function (poolName, tokenMint, isStable, isVirtual,
|
504
|
+
this.addCustody = function (poolName, tokenMint, isStable, isVirtual, oracle, pricing, permissions, fees, borrowRate, ratios, depegAdjustment) { return __awaiter(_this, void 0, void 0, function () {
|
505
505
|
var trx_id, error_1;
|
506
506
|
return __generator(this, function (_a) {
|
507
507
|
switch (_a.label) {
|
@@ -511,7 +511,6 @@ var PerpetualsClient = (function () {
|
|
511
511
|
.addCustody({
|
512
512
|
isStable: isStable,
|
513
513
|
isVirtual: isVirtual,
|
514
|
-
token22: token22,
|
515
514
|
oracle: oracle,
|
516
515
|
pricing: pricing,
|
517
516
|
permissions: permissions,
|
@@ -2482,33 +2481,34 @@ var PerpetualsClient = (function () {
|
|
2482
2481
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2483
2482
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2484
2483
|
return __awaiter(_this, void 0, void 0, function () {
|
2485
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig,
|
2484
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
2486
2485
|
return __generator(this, function (_c) {
|
2487
2486
|
switch (_c.label) {
|
2488
2487
|
case 0:
|
2489
2488
|
publicKey = this.provider.wallet.publicKey;
|
2490
2489
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
2491
2490
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
2492
|
-
collateralToken = poolConfig.getTokenFromSymbol(collateralSymbol);
|
2493
2491
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
2494
|
-
|
2492
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true)];
|
2493
|
+
case 1:
|
2494
|
+
userCollateralTokenAccount = _c.sent();
|
2495
2495
|
preInstructions = [];
|
2496
2496
|
instructions = [];
|
2497
2497
|
postInstructions = [];
|
2498
2498
|
additionalSigners = [];
|
2499
|
-
if (!(collateralSymbol == 'SOL')) return [3,
|
2499
|
+
if (!(collateralSymbol == 'SOL')) return [3, 4];
|
2500
2500
|
console.log("collateralSymbol === SOL", collateralSymbol);
|
2501
2501
|
lamports = collateralWithfee.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
2502
|
-
if (!!skipBalanceChecks) return [3,
|
2502
|
+
if (!!skipBalanceChecks) return [3, 3];
|
2503
2503
|
_a = anchor_1.BN.bind;
|
2504
2504
|
return [4, this.provider.connection.getBalance(publicKey)];
|
2505
|
-
case
|
2505
|
+
case 2:
|
2506
2506
|
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
|
2507
2507
|
if (unWrappedSolBalance.lt(lamports)) {
|
2508
2508
|
throw "Insufficient SOL Funds";
|
2509
2509
|
}
|
2510
|
-
_c.label =
|
2511
|
-
case
|
2510
|
+
_c.label = 3;
|
2511
|
+
case 3:
|
2512
2512
|
if (!ephemeralSignerPubkey) {
|
2513
2513
|
wrappedSolAccount = new web3_js_1.Keypair();
|
2514
2514
|
additionalSigners.push(wrappedSolAccount);
|
@@ -2526,29 +2526,24 @@ var PerpetualsClient = (function () {
|
|
2526
2526
|
postInstructions = [
|
2527
2527
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2528
2528
|
];
|
2529
|
-
return [3,
|
2530
|
-
case 3:
|
2531
|
-
if (!!skipBalanceChecks) return [3, 6];
|
2532
|
-
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
2529
|
+
return [3, 7];
|
2533
2530
|
case 4:
|
2531
|
+
if (!!skipBalanceChecks) return [3, 7];
|
2532
|
+
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
2533
|
+
case 5:
|
2534
2534
|
if (!(_c.sent())) {
|
2535
2535
|
throw "Insufficient Funds , token Account doesn't exist";
|
2536
2536
|
}
|
2537
2537
|
_b = anchor_1.BN.bind;
|
2538
2538
|
return [4, this.provider.connection.getTokenAccountBalance(userCollateralTokenAccount)];
|
2539
|
-
case
|
2539
|
+
case 6:
|
2540
2540
|
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
2541
2541
|
if (tokenAccountBalance.lt(collateralWithfee)) {
|
2542
2542
|
throw "Insufficient Funds need more ".concat(collateralWithfee.sub(tokenAccountBalance), " tokens");
|
2543
2543
|
}
|
2544
|
-
_c.label =
|
2545
|
-
case
|
2544
|
+
_c.label = 7;
|
2545
|
+
case 7:
|
2546
2546
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
2547
|
-
rebateMintAccount = {
|
2548
|
-
pubkey: collateralCustodyConfig.mintKey,
|
2549
|
-
isSigner: false,
|
2550
|
-
isWritable: false
|
2551
|
-
};
|
2552
2547
|
params = {
|
2553
2548
|
priceWithSlippage: priceWithSlippage,
|
2554
2549
|
collateralAmount: collateralWithfee,
|
@@ -2571,16 +2566,15 @@ var PerpetualsClient = (function () {
|
|
2571
2566
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
2572
2567
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
2573
2568
|
systemProgram: web3_js_1.SystemProgram.programId,
|
2574
|
-
tokenProgram:
|
2569
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
2575
2570
|
eventAuthority: this.eventAuthority.publicKey,
|
2576
2571
|
program: this.programId,
|
2577
2572
|
transferAuthority: this.authority.publicKey,
|
2578
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2579
|
-
fundingMint: collateralCustodyConfig.mintKey
|
2573
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2580
2574
|
})
|
2581
|
-
.remainingAccounts(__spreadArray(
|
2575
|
+
.remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
|
2582
2576
|
.instruction()];
|
2583
|
-
case
|
2577
|
+
case 8:
|
2584
2578
|
instruction = _c.sent();
|
2585
2579
|
instructions.push(instruction);
|
2586
2580
|
return [2, {
|
@@ -2646,7 +2640,7 @@ var PerpetualsClient = (function () {
|
|
2646
2640
|
];
|
2647
2641
|
return [3, 6];
|
2648
2642
|
case 3:
|
2649
|
-
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(inputSymbol).mintKey, publicKey, true
|
2643
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(inputSymbol).mintKey, publicKey, true);
|
2650
2644
|
if (!!skipBalanceChecks) return [3, 6];
|
2651
2645
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
2652
2646
|
case 4:
|
@@ -2662,11 +2656,11 @@ var PerpetualsClient = (function () {
|
|
2662
2656
|
}
|
2663
2657
|
_d.label = 6;
|
2664
2658
|
case 6:
|
2665
|
-
userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).mintKey, publicKey, true
|
2659
|
+
userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).mintKey, publicKey, true);
|
2666
2660
|
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
2667
2661
|
case 7:
|
2668
2662
|
if (!(_d.sent())) {
|
2669
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).mintKey
|
2663
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).mintKey));
|
2670
2664
|
}
|
2671
2665
|
marketAccount = positionPoolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
2672
2666
|
positionAccount = positionPoolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
@@ -2741,7 +2735,7 @@ var PerpetualsClient = (function () {
|
|
2741
2735
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
2742
2736
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2743
2737
|
return __awaiter(_this, void 0, void 0, function () {
|
2744
|
-
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount,
|
2738
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_2;
|
2745
2739
|
return __generator(this, function (_b) {
|
2746
2740
|
switch (_b.label) {
|
2747
2741
|
case 0:
|
@@ -2775,7 +2769,7 @@ var PerpetualsClient = (function () {
|
|
2775
2769
|
];
|
2776
2770
|
return [3, 5];
|
2777
2771
|
case 2:
|
2778
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true
|
2772
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
2779
2773
|
_a = createUserATA;
|
2780
2774
|
if (!_a) return [3, 4];
|
2781
2775
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -2784,7 +2778,7 @@ var PerpetualsClient = (function () {
|
|
2784
2778
|
_b.label = 4;
|
2785
2779
|
case 4:
|
2786
2780
|
if (_a) {
|
2787
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey
|
2781
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
2788
2782
|
}
|
2789
2783
|
_b.label = 5;
|
2790
2784
|
case 5:
|
@@ -2792,11 +2786,6 @@ var PerpetualsClient = (function () {
|
|
2792
2786
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(marketSymbol).mintKey); });
|
2793
2787
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
2794
2788
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
2795
|
-
rebateMintAccount = {
|
2796
|
-
pubkey: collateralCustodyConfig.mintKey,
|
2797
|
-
isSigner: false,
|
2798
|
-
isWritable: false
|
2799
|
-
};
|
2800
2789
|
return [4, this.program.methods
|
2801
2790
|
.closePosition({
|
2802
2791
|
priceWithSlippage: priceWithSlippage,
|
@@ -2817,12 +2806,11 @@ var PerpetualsClient = (function () {
|
|
2817
2806
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
2818
2807
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
2819
2808
|
eventAuthority: this.eventAuthority.publicKey,
|
2820
|
-
tokenProgram:
|
2809
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
2821
2810
|
program: this.programId,
|
2822
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2823
|
-
receivingMint: collateralCustodyConfig.mintKey
|
2811
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2824
2812
|
})
|
2825
|
-
.remainingAccounts(__spreadArray(
|
2813
|
+
.remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
|
2826
2814
|
.instruction()];
|
2827
2815
|
case 6:
|
2828
2816
|
instruction = _b.sent();
|
@@ -2887,21 +2875,22 @@ var PerpetualsClient = (function () {
|
|
2887
2875
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2888
2876
|
];
|
2889
2877
|
additionalSigners.push(wrappedSolAccount);
|
2890
|
-
return [3,
|
2891
|
-
case 1:
|
2892
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true, swapPoolConfig.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
2893
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
2878
|
+
return [3, 4];
|
2879
|
+
case 1: return [4, (0, spl_token_1.getAssociatedTokenAddress)(swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true)];
|
2894
2880
|
case 2:
|
2881
|
+
userReceivingTokenAccount = _b.sent();
|
2882
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
2883
|
+
case 3:
|
2895
2884
|
if (!(_b.sent())) {
|
2896
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey
|
2885
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey));
|
2897
2886
|
}
|
2898
|
-
_b.label =
|
2899
|
-
case 3:
|
2900
|
-
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, positionPoolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
2901
|
-
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
2887
|
+
_b.label = 4;
|
2902
2888
|
case 4:
|
2889
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
2890
|
+
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
2891
|
+
case 5:
|
2903
2892
|
if (!(_b.sent())) {
|
2904
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey
|
2893
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
2905
2894
|
}
|
2906
2895
|
marketAccount = positionPoolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
2907
2896
|
positionAccount = positionPoolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
@@ -2950,11 +2939,11 @@ var PerpetualsClient = (function () {
|
|
2950
2939
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
2951
2940
|
eventAuthority: this.eventAuthority.publicKey,
|
2952
2941
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
2953
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2942
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2954
2943
|
})
|
2955
2944
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
2956
2945
|
.instruction()];
|
2957
|
-
case
|
2946
|
+
case 6:
|
2958
2947
|
instruction = _b.sent();
|
2959
2948
|
instructions.push(instruction);
|
2960
2949
|
return [2, {
|
@@ -2972,7 +2961,7 @@ var PerpetualsClient = (function () {
|
|
2972
2961
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2973
2962
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2974
2963
|
return __awaiter(_this, void 0, void 0, function () {
|
2975
|
-
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners,
|
2964
|
+
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_2;
|
2976
2965
|
return __generator(this, function (_c) {
|
2977
2966
|
switch (_c.label) {
|
2978
2967
|
case 0:
|
@@ -2998,8 +2987,6 @@ var PerpetualsClient = (function () {
|
|
2998
2987
|
instructions = [];
|
2999
2988
|
postInstructions = [];
|
3000
2989
|
additionalSigners = [];
|
3001
|
-
targetToken = poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol);
|
3002
|
-
userInputToken = poolConfig.getTokenFromSymbol(userInputTokenSymbol);
|
3003
2990
|
if (!(userInputTokenSymbol == 'SOL')) return [3, 3];
|
3004
2991
|
console.log("inputSymbol === SOL", userInputTokenSymbol);
|
3005
2992
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
@@ -3032,7 +3019,7 @@ var PerpetualsClient = (function () {
|
|
3032
3019
|
];
|
3033
3020
|
return [3, 6];
|
3034
3021
|
case 3:
|
3035
|
-
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(
|
3022
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
|
3036
3023
|
if (!!skipBalanceChecks) return [3, 6];
|
3037
3024
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3038
3025
|
case 4:
|
@@ -3048,17 +3035,12 @@ var PerpetualsClient = (function () {
|
|
3048
3035
|
}
|
3049
3036
|
_c.label = 6;
|
3050
3037
|
case 6:
|
3051
|
-
userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(
|
3038
|
+
userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey, publicKey, true);
|
3052
3039
|
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
3053
3040
|
case 7:
|
3054
3041
|
if (!(_c.sent())) {
|
3055
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey,
|
3042
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey));
|
3056
3043
|
}
|
3057
|
-
rebateMintAccount = {
|
3058
|
-
pubkey: collateralCustodyConfig.mintKey,
|
3059
|
-
isSigner: false,
|
3060
|
-
isWritable: false
|
3061
|
-
};
|
3062
3044
|
_c.label = 8;
|
3063
3045
|
case 8:
|
3064
3046
|
_c.trys.push([8, 10, , 11]);
|
@@ -3088,14 +3070,12 @@ var PerpetualsClient = (function () {
|
|
3088
3070
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3089
3071
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3090
3072
|
systemProgram: web3_js_1.SystemProgram.programId,
|
3091
|
-
tokenProgram:
|
3073
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3092
3074
|
eventAuthority: this.eventAuthority.publicKey,
|
3093
3075
|
program: this.programId,
|
3094
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3095
|
-
fundingMint: userInputCustodyConfig.mintKey,
|
3096
|
-
fundingTokenProgram: userInputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
3076
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3097
3077
|
})
|
3098
|
-
.remainingAccounts(__spreadArray(
|
3078
|
+
.remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
|
3099
3079
|
.instruction()];
|
3100
3080
|
case 9:
|
3101
3081
|
inx = _c.sent();
|
@@ -3119,7 +3099,7 @@ var PerpetualsClient = (function () {
|
|
3119
3099
|
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
3120
3100
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3121
3101
|
return __awaiter(_this, void 0, void 0, function () {
|
3122
|
-
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount,
|
3102
|
+
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, inx, err_3;
|
3123
3103
|
return __generator(this, function (_a) {
|
3124
3104
|
switch (_a.label) {
|
3125
3105
|
case 0:
|
@@ -3145,8 +3125,6 @@ var PerpetualsClient = (function () {
|
|
3145
3125
|
instructions = [];
|
3146
3126
|
postInstructions = [];
|
3147
3127
|
additionalSigners = [];
|
3148
|
-
collateralToken = poolConfig.getTokenFromSymbol(collateralTokenSymbol);
|
3149
|
-
userOutputToken = poolConfig.getTokenFromSymbol(userOutputTokenSymbol);
|
3150
3128
|
if (!(userOutputTokenSymbol == 'SOL')) return [3, 1];
|
3151
3129
|
console.log("outputSymbol === SOL", userOutputTokenSymbol);
|
3152
3130
|
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
@@ -3168,30 +3146,26 @@ var PerpetualsClient = (function () {
|
|
3168
3146
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3169
3147
|
];
|
3170
3148
|
additionalSigners.push(wrappedSolAccount);
|
3171
|
-
return [3,
|
3172
|
-
case 1:
|
3173
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(userOutputToken.mintKey, publicKey, true, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3174
|
-
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
3149
|
+
return [3, 4];
|
3150
|
+
case 1: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
|
3175
3151
|
case 2:
|
3152
|
+
userReceivingTokenAccount = _a.sent();
|
3153
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
3154
|
+
case 3:
|
3176
3155
|
if (!(_a.sent())) {
|
3177
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey,
|
3156
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
|
3178
3157
|
}
|
3179
|
-
_a.label =
|
3180
|
-
case 3:
|
3181
|
-
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralToken.mintKey, publicKey, true, collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3182
|
-
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3158
|
+
_a.label = 4;
|
3183
3159
|
case 4:
|
3160
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralTokenSymbol).mintKey, publicKey, true);
|
3161
|
+
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3162
|
+
case 5:
|
3184
3163
|
if (!(_a.sent())) {
|
3185
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey,
|
3164
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralTokenSymbol).mintKey));
|
3186
3165
|
}
|
3187
|
-
|
3188
|
-
|
3189
|
-
|
3190
|
-
isWritable: false
|
3191
|
-
};
|
3192
|
-
_a.label = 5;
|
3193
|
-
case 5:
|
3194
|
-
_a.trys.push([5, 7, , 8]);
|
3166
|
+
_a.label = 6;
|
3167
|
+
case 6:
|
3168
|
+
_a.trys.push([6, 8, , 9]);
|
3195
3169
|
return [4, this.program.methods
|
3196
3170
|
.closeAndSwap({
|
3197
3171
|
priceWithSlippage: priceWithSlippage,
|
@@ -3216,25 +3190,22 @@ var PerpetualsClient = (function () {
|
|
3216
3190
|
dispensingCustody: userOutputCustodyConfig.custodyAccount,
|
3217
3191
|
dispensingOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
|
3218
3192
|
dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
|
3193
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3219
3194
|
eventAuthority: this.eventAuthority.publicKey,
|
3220
3195
|
program: this.programId,
|
3221
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3222
|
-
receivingMint: userOutputCustodyConfig.mintKey,
|
3223
|
-
receivingTokenProgram: userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
3224
|
-
collateralMint: collateralCustodyConfig.mintKey,
|
3225
|
-
collateralTokenProgram: collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
3196
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3226
3197
|
})
|
3227
|
-
.remainingAccounts(__spreadArray(
|
3198
|
+
.remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
|
3228
3199
|
.instruction()];
|
3229
|
-
case
|
3200
|
+
case 7:
|
3230
3201
|
inx = _a.sent();
|
3231
3202
|
instructions.push(inx);
|
3232
|
-
return [3,
|
3233
|
-
case
|
3203
|
+
return [3, 9];
|
3204
|
+
case 8:
|
3234
3205
|
err_3 = _a.sent();
|
3235
3206
|
console.error("perpClient CloseAndSwap error:: ", err_3);
|
3236
3207
|
throw err_3;
|
3237
|
-
case
|
3208
|
+
case 9: return [2, {
|
3238
3209
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3239
3210
|
additionalSigners: additionalSigners
|
3240
3211
|
}];
|
@@ -3249,7 +3220,7 @@ var PerpetualsClient = (function () {
|
|
3249
3220
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3250
3221
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3251
3222
|
return __awaiter(_this, void 0, void 0, function () {
|
3252
|
-
var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount,
|
3223
|
+
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_4;
|
3253
3224
|
return __generator(this, function (_f) {
|
3254
3225
|
switch (_f.label) {
|
3255
3226
|
case 0:
|
@@ -3266,26 +3237,26 @@ var PerpetualsClient = (function () {
|
|
3266
3237
|
instructions = [];
|
3267
3238
|
postInstructions = [];
|
3268
3239
|
additionalSigners = [];
|
3269
|
-
|
3270
|
-
|
3271
|
-
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 4];
|
3272
|
-
wsolAssociatedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, publicKey, true);
|
3273
|
-
return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
|
3240
|
+
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
|
3241
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
|
3274
3242
|
case 1:
|
3243
|
+
wsolAssociatedTokenAccount = _f.sent();
|
3244
|
+
return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
|
3245
|
+
case 2:
|
3275
3246
|
wsolATAExist = _f.sent();
|
3276
3247
|
if (!wsolATAExist) {
|
3277
3248
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
3278
3249
|
}
|
3279
|
-
if (!!skipBalanceChecks) return [3,
|
3250
|
+
if (!!skipBalanceChecks) return [3, 4];
|
3280
3251
|
_a = anchor_1.BN.bind;
|
3281
3252
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3282
|
-
case
|
3253
|
+
case 3:
|
3283
3254
|
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
3284
3255
|
if (unWrappedSolBalance.lt(amountIn)) {
|
3285
3256
|
throw "Insufficient SOL Funds";
|
3286
3257
|
}
|
3287
|
-
_f.label =
|
3288
|
-
case
|
3258
|
+
_f.label = 4;
|
3259
|
+
case 4:
|
3289
3260
|
instructions.push(web3_js_1.SystemProgram.transfer({
|
3290
3261
|
fromPubkey: publicKey,
|
3291
3262
|
toPubkey: wsolAssociatedTokenAccount,
|
@@ -3295,7 +3266,7 @@ var PerpetualsClient = (function () {
|
|
3295
3266
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3296
3267
|
additionalSigners: additionalSigners
|
3297
3268
|
}];
|
3298
|
-
case
|
3269
|
+
case 5:
|
3299
3270
|
if (userInputTokenSymbol == 'WSOL' && userOutputTokenSymbol == 'SOL') {
|
3300
3271
|
console.log("WSOL=> SOL : NOTE : ONLY WAY IS TO CLOSE THE WSOL ATA and GET ALL SOL ");
|
3301
3272
|
wsolAssociatedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, publicKey, true);
|
@@ -3306,19 +3277,19 @@ var PerpetualsClient = (function () {
|
|
3306
3277
|
additionalSigners: additionalSigners
|
3307
3278
|
}];
|
3308
3279
|
}
|
3309
|
-
_f.label =
|
3310
|
-
case
|
3311
|
-
_f.trys.push([
|
3312
|
-
if (!(userInputTokenSymbol == 'SOL')) return [3,
|
3280
|
+
_f.label = 6;
|
3281
|
+
case 6:
|
3282
|
+
_f.trys.push([6, 19, , 20]);
|
3283
|
+
if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
|
3313
3284
|
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
3314
3285
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
3315
|
-
case
|
3286
|
+
case 7:
|
3316
3287
|
accCreationLamports = (_f.sent());
|
3317
3288
|
console.log("accCreationLamports:", accCreationLamports);
|
3318
3289
|
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
3319
3290
|
_b = anchor_1.BN.bind;
|
3320
3291
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3321
|
-
case
|
3292
|
+
case 8:
|
3322
3293
|
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
3323
3294
|
if (unWrappedSolBalance.lt(amountIn)) {
|
3324
3295
|
throw "Insufficient SOL Funds";
|
@@ -3341,25 +3312,25 @@ var PerpetualsClient = (function () {
|
|
3341
3312
|
postInstructions = [
|
3342
3313
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3343
3314
|
];
|
3344
|
-
return [3,
|
3345
|
-
case 8:
|
3346
|
-
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(userInputToken.mintKey, publicKey, true, userInputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3347
|
-
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3315
|
+
return [3, 12];
|
3348
3316
|
case 9:
|
3317
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
|
3318
|
+
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3319
|
+
case 10:
|
3349
3320
|
if (!(_f.sent())) {
|
3350
3321
|
throw "Insufficient Funds , Token Account doesn't exist";
|
3351
3322
|
}
|
3352
|
-
if (!!skipBalanceChecks) return [3,
|
3323
|
+
if (!!skipBalanceChecks) return [3, 12];
|
3353
3324
|
_c = anchor_1.BN.bind;
|
3354
3325
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3355
|
-
case
|
3326
|
+
case 11:
|
3356
3327
|
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
3357
3328
|
if (tokenAccountBalance.lt(amountIn)) {
|
3358
3329
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3359
3330
|
}
|
3360
|
-
_f.label =
|
3361
|
-
case
|
3362
|
-
if (!(userOutputTokenSymbol == 'SOL')) return [3,
|
3331
|
+
_f.label = 12;
|
3332
|
+
case 12:
|
3333
|
+
if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
|
3363
3334
|
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
3364
3335
|
if (!ephemeralSignerPubkey) {
|
3365
3336
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -3379,21 +3350,22 @@ var PerpetualsClient = (function () {
|
|
3379
3350
|
postInstructions = [
|
3380
3351
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3381
3352
|
];
|
3382
|
-
return [3,
|
3383
|
-
case
|
3384
|
-
|
3353
|
+
return [3, 17];
|
3354
|
+
case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
|
3355
|
+
case 14:
|
3356
|
+
userOutputTokenAccount = _f.sent();
|
3385
3357
|
_d = createUserATA;
|
3386
|
-
if (!_d) return [3,
|
3358
|
+
if (!_d) return [3, 16];
|
3387
3359
|
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
3388
|
-
case
|
3360
|
+
case 15:
|
3389
3361
|
_d = !(_f.sent());
|
3390
|
-
_f.label =
|
3391
|
-
case
|
3362
|
+
_f.label = 16;
|
3363
|
+
case 16:
|
3392
3364
|
if (_d) {
|
3393
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey,
|
3365
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
|
3394
3366
|
}
|
3395
|
-
_f.label =
|
3396
|
-
case
|
3367
|
+
_f.label = 17;
|
3368
|
+
case 17:
|
3397
3369
|
custodyAccountMetas = [];
|
3398
3370
|
custodyOracleAccountMetas = [];
|
3399
3371
|
for (_i = 0, _e = poolConfig.custodies; _i < _e.length; _i++) {
|
@@ -3430,28 +3402,25 @@ var PerpetualsClient = (function () {
|
|
3430
3402
|
dispensingCustodyOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
|
3431
3403
|
dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
|
3432
3404
|
eventAuthority: this.eventAuthority.publicKey,
|
3405
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3433
3406
|
program: this.programId,
|
3434
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3435
|
-
fundingMint: userInputCustodyConfig.mintKey,
|
3436
|
-
fundingTokenProgram: userInputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
3437
|
-
receivingMint: userOutputCustodyConfig.mintKey,
|
3438
|
-
receivingTokenProgram: userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
3407
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3439
3408
|
})
|
3440
3409
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
3441
3410
|
.instruction()];
|
3442
|
-
case
|
3411
|
+
case 18:
|
3443
3412
|
inx = _f.sent();
|
3444
3413
|
instructions.push(inx);
|
3445
3414
|
if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
|
3446
3415
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
|
3447
3416
|
instructions.push(closeWsolATAIns);
|
3448
3417
|
}
|
3449
|
-
return [3,
|
3450
|
-
case
|
3418
|
+
return [3, 20];
|
3419
|
+
case 19:
|
3451
3420
|
err_4 = _f.sent();
|
3452
3421
|
console.error("perpClient Swap error:: ", err_4);
|
3453
3422
|
throw err_4;
|
3454
|
-
case
|
3423
|
+
case 20: return [2, {
|
3455
3424
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3456
3425
|
additionalSigners: additionalSigners
|
3457
3426
|
}];
|
@@ -3545,7 +3514,7 @@ var PerpetualsClient = (function () {
|
|
3545
3514
|
if (!collateralCustodyConfig || !targetCustodyConfig) {
|
3546
3515
|
throw "payTokenCustody not found";
|
3547
3516
|
}
|
3548
|
-
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true
|
3517
|
+
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
|
3549
3518
|
preInstructions = [];
|
3550
3519
|
instructions = [];
|
3551
3520
|
postInstructions = [];
|
@@ -3612,10 +3581,9 @@ var PerpetualsClient = (function () {
|
|
3612
3581
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3613
3582
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3614
3583
|
eventAuthority: this.eventAuthority.publicKey,
|
3615
|
-
tokenProgram:
|
3584
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3616
3585
|
program: this.programId,
|
3617
3586
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3618
|
-
fundingMint: collateralCustodyConfig.mintKey
|
3619
3587
|
})
|
3620
3588
|
.instruction()];
|
3621
3589
|
case 7:
|
@@ -3685,7 +3653,7 @@ var PerpetualsClient = (function () {
|
|
3685
3653
|
];
|
3686
3654
|
return [3, 6];
|
3687
3655
|
case 3:
|
3688
|
-
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true
|
3656
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
3689
3657
|
if (!!skipBalanceChecks) return [3, 6];
|
3690
3658
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3691
3659
|
case 4:
|
@@ -3701,11 +3669,11 @@ var PerpetualsClient = (function () {
|
|
3701
3669
|
}
|
3702
3670
|
_d.label = 6;
|
3703
3671
|
case 6:
|
3704
|
-
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true
|
3672
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
|
3705
3673
|
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3706
3674
|
case 7:
|
3707
3675
|
if (!(_d.sent())) {
|
3708
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey
|
3676
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey));
|
3709
3677
|
}
|
3710
3678
|
custodyAccountMetas = [];
|
3711
3679
|
custodyOracleAccountMetas = [];
|
@@ -3814,7 +3782,7 @@ var PerpetualsClient = (function () {
|
|
3814
3782
|
];
|
3815
3783
|
return [3, 5];
|
3816
3784
|
case 2:
|
3817
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true
|
3785
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
3818
3786
|
_a = createUserATA;
|
3819
3787
|
if (!_a) return [3, 4];
|
3820
3788
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -3823,7 +3791,7 @@ var PerpetualsClient = (function () {
|
|
3823
3791
|
_b.label = 4;
|
3824
3792
|
case 4:
|
3825
3793
|
if (_a) {
|
3826
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey
|
3794
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
3827
3795
|
}
|
3828
3796
|
_b.label = 5;
|
3829
3797
|
case 5:
|
@@ -3846,10 +3814,9 @@ var PerpetualsClient = (function () {
|
|
3846
3814
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3847
3815
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3848
3816
|
eventAuthority: this.eventAuthority.publicKey,
|
3849
|
-
tokenProgram:
|
3817
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3850
3818
|
program: this.programId,
|
3851
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3852
|
-
receivingMint: collateralCustodyConfig.mintKey
|
3819
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3853
3820
|
})
|
3854
3821
|
.instruction()];
|
3855
3822
|
case 6:
|
@@ -3913,19 +3880,19 @@ var PerpetualsClient = (function () {
|
|
3913
3880
|
];
|
3914
3881
|
return [3, 3];
|
3915
3882
|
case 1:
|
3916
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true
|
3883
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true);
|
3917
3884
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
3918
3885
|
case 2:
|
3919
3886
|
if (!(_b.sent())) {
|
3920
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey
|
3887
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey));
|
3921
3888
|
}
|
3922
3889
|
_b.label = 3;
|
3923
3890
|
case 3:
|
3924
|
-
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true
|
3891
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
3925
3892
|
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3926
3893
|
case 4:
|
3927
3894
|
if (!(_b.sent())) {
|
3928
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey
|
3895
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey));
|
3929
3896
|
}
|
3930
3897
|
marketAccount = poolConfigPosition.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3931
3898
|
positionAccount = poolConfigPosition.getPositionFromMarketPk(publicKey, marketAccount);
|
@@ -3993,7 +3960,7 @@ var PerpetualsClient = (function () {
|
|
3993
3960
|
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
3994
3961
|
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
3995
3962
|
return __awaiter(_this, void 0, void 0, function () {
|
3996
|
-
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners,
|
3963
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3997
3964
|
return __generator(this, function (_a) {
|
3998
3965
|
switch (_a.label) {
|
3999
3966
|
case 0:
|
@@ -4012,11 +3979,6 @@ var PerpetualsClient = (function () {
|
|
4012
3979
|
instructions = [];
|
4013
3980
|
postInstructions = [];
|
4014
3981
|
additionalSigners = [];
|
4015
|
-
rebateMintAccount = {
|
4016
|
-
pubkey: collateralCustodyConfig.mintKey,
|
4017
|
-
isSigner: false,
|
4018
|
-
isWritable: false
|
4019
|
-
};
|
4020
3982
|
return [4, this.program.methods
|
4021
3983
|
.increaseSize({
|
4022
3984
|
priceWithSlippage: priceWithSlippage,
|
@@ -4035,12 +3997,12 @@ var PerpetualsClient = (function () {
|
|
4035
3997
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
4036
3998
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
4037
3999
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
4038
|
-
tokenProgram:
|
4000
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4039
4001
|
eventAuthority: this.eventAuthority.publicKey,
|
4040
4002
|
program: this.programId,
|
4041
4003
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4042
4004
|
})
|
4043
|
-
.remainingAccounts(__spreadArray(
|
4005
|
+
.remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
|
4044
4006
|
.instruction()];
|
4045
4007
|
case 1:
|
4046
4008
|
instruction = _a.sent();
|
@@ -4058,7 +4020,7 @@ var PerpetualsClient = (function () {
|
|
4058
4020
|
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
4059
4021
|
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
4060
4022
|
return __awaiter(_this, void 0, void 0, function () {
|
4061
|
-
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners,
|
4023
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
4062
4024
|
return __generator(this, function (_a) {
|
4063
4025
|
switch (_a.label) {
|
4064
4026
|
case 0:
|
@@ -4077,11 +4039,6 @@ var PerpetualsClient = (function () {
|
|
4077
4039
|
instructions = [];
|
4078
4040
|
postInstructions = [];
|
4079
4041
|
additionalSigners = [];
|
4080
|
-
rebateMintAccount = {
|
4081
|
-
pubkey: collateralCustodyConfig.mintKey,
|
4082
|
-
isSigner: false,
|
4083
|
-
isWritable: false
|
4084
|
-
};
|
4085
4042
|
return [4, this.program.methods
|
4086
4043
|
.decreaseSize({
|
4087
4044
|
priceWithSlippage: priceWithSlippage,
|
@@ -4100,12 +4057,12 @@ var PerpetualsClient = (function () {
|
|
4100
4057
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
4101
4058
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
4102
4059
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
4103
|
-
tokenProgram:
|
4060
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4104
4061
|
eventAuthority: this.eventAuthority.publicKey,
|
4105
4062
|
program: this.programId,
|
4106
4063
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4107
4064
|
})
|
4108
|
-
.remainingAccounts(__spreadArray(
|
4065
|
+
.remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
|
4109
4066
|
.instruction()];
|
4110
4067
|
case 1:
|
4111
4068
|
instruction = _a.sent();
|
@@ -4122,7 +4079,7 @@ var PerpetualsClient = (function () {
|
|
4122
4079
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4123
4080
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4124
4081
|
return __awaiter(_this, void 0, void 0, function () {
|
4125
|
-
var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners,
|
4082
|
+
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_6;
|
4126
4083
|
return __generator(this, function (_f) {
|
4127
4084
|
switch (_f.label) {
|
4128
4085
|
case 0:
|
@@ -4135,11 +4092,10 @@ var PerpetualsClient = (function () {
|
|
4135
4092
|
instructions = [];
|
4136
4093
|
postInstructions = [];
|
4137
4094
|
additionalSigners = [];
|
4138
|
-
payToken = poolConfig.getTokenFromSymbol(payTokenSymbol);
|
4139
4095
|
_f.label = 1;
|
4140
4096
|
case 1:
|
4141
4097
|
_f.trys.push([1, 10, , 11]);
|
4142
|
-
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true
|
4098
|
+
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true);
|
4143
4099
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
4144
4100
|
custodyAccountMetas = [];
|
4145
4101
|
custodyOracleAccountMetas = [];
|
@@ -4235,9 +4191,7 @@ var PerpetualsClient = (function () {
|
|
4235
4191
|
eventAuthority: this.eventAuthority.publicKey,
|
4236
4192
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4237
4193
|
program: this.programId,
|
4238
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4239
|
-
fundingMint: payTokenCustodyConfig.mintKey,
|
4240
|
-
fundingTokenProgram: payToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
4194
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4241
4195
|
})
|
4242
4196
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4243
4197
|
.instruction()];
|
@@ -4261,7 +4215,7 @@ var PerpetualsClient = (function () {
|
|
4261
4215
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4262
4216
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4263
4217
|
return __awaiter(_this, void 0, void 0, function () {
|
4264
|
-
var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig,
|
4218
|
+
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;
|
4265
4219
|
return __generator(this, function (_f) {
|
4266
4220
|
switch (_f.label) {
|
4267
4221
|
case 0:
|
@@ -4272,7 +4226,6 @@ var PerpetualsClient = (function () {
|
|
4272
4226
|
additionalSigners = [];
|
4273
4227
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
4274
4228
|
inputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inputSymbol).mintKey); });
|
4275
|
-
inputToken = poolConfig.getTokenFromSymbol(inputSymbol);
|
4276
4229
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(lpTokenMint, publicKey, true);
|
4277
4230
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
4278
4231
|
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
@@ -4313,7 +4266,7 @@ var PerpetualsClient = (function () {
|
|
4313
4266
|
];
|
4314
4267
|
return [3, 7];
|
4315
4268
|
case 4:
|
4316
|
-
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true
|
4269
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
4317
4270
|
if (!!skipBalanceChecks) return [3, 7];
|
4318
4271
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
4319
4272
|
case 5:
|
@@ -4373,9 +4326,7 @@ var PerpetualsClient = (function () {
|
|
4373
4326
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4374
4327
|
eventAuthority: this.eventAuthority.publicKey,
|
4375
4328
|
program: this.programId,
|
4376
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4377
|
-
fundingMint: inputCustodyConfig.mintKey,
|
4378
|
-
fundingTokenProgram: inputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
4329
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4379
4330
|
})
|
4380
4331
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4381
4332
|
.instruction()];
|
@@ -4396,7 +4347,7 @@ var PerpetualsClient = (function () {
|
|
4396
4347
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
4397
4348
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4398
4349
|
return __awaiter(_this, void 0, void 0, function () {
|
4399
|
-
var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners,
|
4350
|
+
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_7;
|
4400
4351
|
return __generator(this, function (_e) {
|
4401
4352
|
switch (_e.label) {
|
4402
4353
|
case 0:
|
@@ -4409,7 +4360,6 @@ var PerpetualsClient = (function () {
|
|
4409
4360
|
instructions = [];
|
4410
4361
|
postInstructions = [];
|
4411
4362
|
additionalSigners = [];
|
4412
|
-
recieveToken = poolConfig.getTokenFromSymbol(recieveTokenSymbol);
|
4413
4363
|
_e.label = 1;
|
4414
4364
|
case 1:
|
4415
4365
|
_e.trys.push([1, 7, , 8]);
|
@@ -4459,7 +4409,7 @@ var PerpetualsClient = (function () {
|
|
4459
4409
|
];
|
4460
4410
|
return [3, 5];
|
4461
4411
|
case 2:
|
4462
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(
|
4412
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true);
|
4463
4413
|
_d = createUserATA;
|
4464
4414
|
if (!_d) return [3, 4];
|
4465
4415
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -4468,7 +4418,7 @@ var PerpetualsClient = (function () {
|
|
4468
4418
|
_e.label = 4;
|
4469
4419
|
case 4:
|
4470
4420
|
if (_d) {
|
4471
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey,
|
4421
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey));
|
4472
4422
|
}
|
4473
4423
|
_e.label = 5;
|
4474
4424
|
case 5: return [4, this.program.methods
|
@@ -4490,9 +4440,7 @@ var PerpetualsClient = (function () {
|
|
4490
4440
|
eventAuthority: this.eventAuthority.publicKey,
|
4491
4441
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4492
4442
|
program: this.programId,
|
4493
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4494
|
-
receivingMint: recieveTokenCustodyConfig.mintKey,
|
4495
|
-
receivingTokenProgram: recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
4443
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4496
4444
|
})
|
4497
4445
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4498
4446
|
.instruction()];
|
@@ -4619,7 +4567,7 @@ var PerpetualsClient = (function () {
|
|
4619
4567
|
additionalSigners = [];
|
4620
4568
|
_a.label = 1;
|
4621
4569
|
case 1:
|
4622
|
-
_a.trys.push([1,
|
4570
|
+
_a.trys.push([1, 4, , 5]);
|
4623
4571
|
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4624
4572
|
Buffer.from("trading"),
|
4625
4573
|
nftMint.toBuffer(),
|
@@ -4628,7 +4576,9 @@ var PerpetualsClient = (function () {
|
|
4628
4576
|
Buffer.from("referral"),
|
4629
4577
|
publicKey.toBuffer(),
|
4630
4578
|
], this.programId)[0];
|
4631
|
-
|
4579
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(nftMint, publicKey, true)];
|
4580
|
+
case 2:
|
4581
|
+
nftTokenAccount = _a.sent();
|
4632
4582
|
flpStakeAccountMetas = [];
|
4633
4583
|
for (_i = 0, flpStakeAccounts_1 = flpStakeAccounts; _i < flpStakeAccounts_1.length; _i++) {
|
4634
4584
|
flpStakeAccountPk = flpStakeAccounts_1[_i];
|
@@ -4651,15 +4601,15 @@ var PerpetualsClient = (function () {
|
|
4651
4601
|
tradingAccount: nftTradingAccount
|
4652
4602
|
})
|
4653
4603
|
.instruction()];
|
4654
|
-
case
|
4604
|
+
case 3:
|
4655
4605
|
updateNftTradingAccountInstruction = _a.sent();
|
4656
4606
|
instructions.push(updateNftTradingAccountInstruction);
|
4657
|
-
return [3,
|
4658
|
-
case
|
4607
|
+
return [3, 5];
|
4608
|
+
case 4:
|
4659
4609
|
err_10 = _a.sent();
|
4660
4610
|
console.log("perpClient updateNftAccount error:: ", err_10);
|
4661
4611
|
throw err_10;
|
4662
|
-
case
|
4612
|
+
case 5: return [2, {
|
4663
4613
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4664
4614
|
additionalSigners: additionalSigners
|
4665
4615
|
}];
|
@@ -4832,11 +4782,13 @@ var PerpetualsClient = (function () {
|
|
4832
4782
|
additionalSigners = [];
|
4833
4783
|
_a.label = 1;
|
4834
4784
|
case 1:
|
4835
|
-
_a.trys.push([1,
|
4785
|
+
_a.trys.push([1, 4, , 5]);
|
4836
4786
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
4837
4787
|
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
4838
4788
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), owner.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
4839
|
-
|
4789
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.stakedLpTokenMint, owner, true)];
|
4790
|
+
case 2:
|
4791
|
+
userLpTokenAccount = _a.sent();
|
4840
4792
|
return [4, this.program.methods
|
4841
4793
|
.depositStake({
|
4842
4794
|
depositAmount: depositAmount
|
@@ -4853,19 +4805,18 @@ var PerpetualsClient = (function () {
|
|
4853
4805
|
systemProgram: web3_js_1.SystemProgram.programId,
|
4854
4806
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4855
4807
|
eventAuthority: this.eventAuthority.publicKey,
|
4856
|
-
program: this.programId
|
4857
|
-
lpTokenMint: poolConfig.stakedLpTokenMint
|
4808
|
+
program: this.programId
|
4858
4809
|
})
|
4859
4810
|
.instruction()];
|
4860
|
-
case
|
4811
|
+
case 3:
|
4861
4812
|
depositStakeInstruction = _a.sent();
|
4862
4813
|
instructions.push(depositStakeInstruction);
|
4863
|
-
return [3,
|
4864
|
-
case
|
4814
|
+
return [3, 5];
|
4815
|
+
case 4:
|
4865
4816
|
err_14 = _a.sent();
|
4866
4817
|
console.log("perpClient depositStaking error:: ", err_14);
|
4867
4818
|
throw err_14;
|
4868
|
-
case
|
4819
|
+
case 5: return [2, {
|
4869
4820
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4870
4821
|
additionalSigners: additionalSigners
|
4871
4822
|
}];
|
@@ -5152,7 +5103,6 @@ var PerpetualsClient = (function () {
|
|
5152
5103
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5153
5104
|
eventAuthority: this.eventAuthority.publicKey,
|
5154
5105
|
program: this.program.programId,
|
5155
|
-
lpMint: poolConfig.stakedLpTokenMint
|
5156
5106
|
})
|
5157
5107
|
.instruction()];
|
5158
5108
|
case 4:
|
@@ -5190,7 +5140,7 @@ var PerpetualsClient = (function () {
|
|
5190
5140
|
_b.trys.push([1, 5, , 6]);
|
5191
5141
|
pool = poolConfig.poolAddress;
|
5192
5142
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
|
5193
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true
|
5143
|
+
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5194
5144
|
_a = createUserATA;
|
5195
5145
|
if (!_a) return [3, 3];
|
5196
5146
|
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
@@ -5199,7 +5149,7 @@ var PerpetualsClient = (function () {
|
|
5199
5149
|
_b.label = 3;
|
5200
5150
|
case 3:
|
5201
5151
|
if (_a) {
|
5202
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint
|
5152
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
5203
5153
|
}
|
5204
5154
|
tradingAccount = [];
|
5205
5155
|
if (nftTradingAccount) {
|
@@ -5232,8 +5182,7 @@ var PerpetualsClient = (function () {
|
|
5232
5182
|
systemProgram: web3_js_1.SystemProgram.programId,
|
5233
5183
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5234
5184
|
eventAuthority: this.eventAuthority.publicKey,
|
5235
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5236
|
-
receivingMint: rewardCustodyMint
|
5185
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5237
5186
|
})
|
5238
5187
|
.remainingAccounts(__spreadArray(__spreadArray([], tradingAccount, true), boostingAccount, true))
|
5239
5188
|
.instruction()];
|
@@ -5302,19 +5251,18 @@ var PerpetualsClient = (function () {
|
|
5302
5251
|
});
|
5303
5252
|
}); };
|
5304
5253
|
this.distributeReward = function (rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5305
|
-
var publicKey,
|
5254
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_22;
|
5306
5255
|
return __generator(this, function (_a) {
|
5307
5256
|
switch (_a.label) {
|
5308
5257
|
case 0:
|
5309
5258
|
publicKey = this.provider.wallet.publicKey;
|
5310
|
-
|
5311
|
-
rewardCustodyMint = rewardToken.mintKey;
|
5259
|
+
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
5312
5260
|
instructions = [];
|
5313
5261
|
additionalSigners = [];
|
5314
5262
|
_a.label = 1;
|
5315
5263
|
case 1:
|
5316
5264
|
_a.trys.push([1, 3, , 4]);
|
5317
|
-
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true
|
5265
|
+
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5318
5266
|
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5319
5267
|
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5320
5268
|
return [4, this.programFbnftReward.methods
|
@@ -5347,13 +5295,12 @@ var PerpetualsClient = (function () {
|
|
5347
5295
|
this.collectNftReward = function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
5348
5296
|
if (createUserATA === void 0) { createUserATA = true; }
|
5349
5297
|
return __awaiter(_this, void 0, void 0, function () {
|
5350
|
-
var publicKey,
|
5298
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_23;
|
5351
5299
|
return __generator(this, function (_b) {
|
5352
5300
|
switch (_b.label) {
|
5353
5301
|
case 0:
|
5354
5302
|
publicKey = this.provider.wallet.publicKey;
|
5355
|
-
|
5356
|
-
rewardCustodyMint = rewardToken.mintKey;
|
5303
|
+
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
5357
5304
|
instructions = [];
|
5358
5305
|
additionalSigners = [];
|
5359
5306
|
_b.label = 1;
|
@@ -5361,7 +5308,7 @@ var PerpetualsClient = (function () {
|
|
5361
5308
|
_b.trys.push([1, 5, , 6]);
|
5362
5309
|
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, publicKey, true);
|
5363
5310
|
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5364
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true
|
5311
|
+
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5365
5312
|
_a = createUserATA;
|
5366
5313
|
if (!_a) return [3, 3];
|
5367
5314
|
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
@@ -5370,7 +5317,7 @@ var PerpetualsClient = (function () {
|
|
5370
5317
|
_b.label = 3;
|
5371
5318
|
case 3:
|
5372
5319
|
if (_a) {
|
5373
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint
|
5320
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
5374
5321
|
}
|
5375
5322
|
rewardRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_record"), nftMint.toBuffer()], this.programFbnftReward.programId)[0];
|
5376
5323
|
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
@@ -5390,7 +5337,7 @@ var PerpetualsClient = (function () {
|
|
5390
5337
|
rewardTokenAccount: rewardTokenAccount,
|
5391
5338
|
transferAuthority: nftTransferAuthority,
|
5392
5339
|
systemProgram: web3_js_1.SystemProgram.programId,
|
5393
|
-
tokenProgram:
|
5340
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5394
5341
|
})
|
5395
5342
|
.instruction()];
|
5396
5343
|
case 4:
|
@@ -5411,14 +5358,13 @@ var PerpetualsClient = (function () {
|
|
5411
5358
|
this.collectAndDistributeFee = function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
5412
5359
|
if (createUserATA === void 0) { createUserATA = true; }
|
5413
5360
|
return __awaiter(_this, void 0, void 0, function () {
|
5414
|
-
var publicKey,
|
5361
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_24;
|
5415
5362
|
return __generator(this, function (_b) {
|
5416
5363
|
switch (_b.label) {
|
5417
5364
|
case 0:
|
5418
5365
|
publicKey = this.provider.wallet.publicKey;
|
5419
|
-
|
5420
|
-
|
5421
|
-
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardToken.mintKey); });
|
5366
|
+
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
5367
|
+
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
5422
5368
|
preInstructions = [];
|
5423
5369
|
instructions = [];
|
5424
5370
|
postInstructions = [];
|
@@ -5428,7 +5374,7 @@ var PerpetualsClient = (function () {
|
|
5428
5374
|
_b.trys.push([1, 5, , 6]);
|
5429
5375
|
pool = poolConfig.poolAddress;
|
5430
5376
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
|
5431
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true
|
5377
|
+
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5432
5378
|
_a = createUserATA;
|
5433
5379
|
if (!_a) return [3, 3];
|
5434
5380
|
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
@@ -5437,7 +5383,7 @@ var PerpetualsClient = (function () {
|
|
5437
5383
|
_b.label = 3;
|
5438
5384
|
case 3:
|
5439
5385
|
if (_a) {
|
5440
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint
|
5386
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
5441
5387
|
}
|
5442
5388
|
tradingAccount = [];
|
5443
5389
|
if (nftTradingAccount) {
|
@@ -5556,17 +5502,19 @@ var PerpetualsClient = (function () {
|
|
5556
5502
|
additionalSigners = [];
|
5557
5503
|
_b.label = 1;
|
5558
5504
|
case 1:
|
5559
|
-
_b.trys.push([1,
|
5560
|
-
|
5505
|
+
_b.trys.push([1, 6, , 7]);
|
5506
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, positionAccount.owner)];
|
5507
|
+
case 2:
|
5508
|
+
userReceivingTokenAccount = _b.sent();
|
5561
5509
|
_a = createUserATA;
|
5562
|
-
if (!_a) return [3,
|
5510
|
+
if (!_a) return [3, 4];
|
5563
5511
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
5564
|
-
case 2:
|
5565
|
-
_a = !(_b.sent());
|
5566
|
-
_b.label = 3;
|
5567
5512
|
case 3:
|
5513
|
+
_a = !(_b.sent());
|
5514
|
+
_b.label = 4;
|
5515
|
+
case 4:
|
5568
5516
|
if (_a) {
|
5569
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, positionAccount.owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey
|
5517
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, positionAccount.owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
5570
5518
|
}
|
5571
5519
|
return [4, this.program.methods
|
5572
5520
|
.forceClosePosition({
|
@@ -5586,26 +5534,25 @@ var PerpetualsClient = (function () {
|
|
5586
5534
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
5587
5535
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
5588
5536
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
5589
|
-
tokenProgram:
|
5537
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5590
5538
|
eventAuthority: this.eventAuthority.publicKey,
|
5591
5539
|
program: this.programId,
|
5592
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5593
|
-
receivingMint: collateralCustodyConfig.mintKey
|
5540
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5594
5541
|
})
|
5595
5542
|
.instruction()];
|
5596
|
-
case
|
5543
|
+
case 5:
|
5597
5544
|
forceClosePosition = _b.sent();
|
5598
5545
|
instructions.push(forceClosePosition);
|
5599
5546
|
if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
|
5600
5547
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, positionAccount.owner, positionAccount.owner);
|
5601
5548
|
postInstructions.push(closeWsolATAIns);
|
5602
5549
|
}
|
5603
|
-
return [3,
|
5604
|
-
case
|
5550
|
+
return [3, 7];
|
5551
|
+
case 6:
|
5605
5552
|
err_26 = _b.sent();
|
5606
5553
|
console.log("perpClient forceClosePosition error:: ", err_26);
|
5607
5554
|
throw err_26;
|
5608
|
-
case
|
5555
|
+
case 7: return [2, {
|
5609
5556
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5610
5557
|
additionalSigners: additionalSigners
|
5611
5558
|
}];
|
@@ -5626,28 +5573,30 @@ var PerpetualsClient = (function () {
|
|
5626
5573
|
reserveCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey); });
|
5627
5574
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
5628
5575
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
5629
|
-
|
5576
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey)];
|
5577
|
+
case 1:
|
5578
|
+
userReserveTokenAccount = _c.sent();
|
5630
5579
|
preInstructions = [];
|
5631
5580
|
instructions = [];
|
5632
5581
|
postInstructions = [];
|
5633
5582
|
additionalSigners = [];
|
5634
|
-
_c.label =
|
5635
|
-
case
|
5636
|
-
_c.trys.push([
|
5637
|
-
if (!(reserveSymbol == 'SOL')) return [3,
|
5583
|
+
_c.label = 2;
|
5584
|
+
case 2:
|
5585
|
+
_c.trys.push([2, 10, , 11]);
|
5586
|
+
if (!(reserveSymbol == 'SOL')) return [3, 5];
|
5638
5587
|
console.log("reserveSymbol === SOL", reserveSymbol);
|
5639
5588
|
accCreationLamports = this.minimumBalanceForRentExemptAccountLamports;
|
5640
5589
|
lamports = reserveAmount.add(new anchor_1.BN(accCreationLamports));
|
5641
|
-
if (!!skipBalanceChecks) return [3,
|
5590
|
+
if (!!skipBalanceChecks) return [3, 4];
|
5642
5591
|
_a = anchor_1.BN.bind;
|
5643
5592
|
return [4, this.provider.connection.getBalance(publicKey)];
|
5644
|
-
case
|
5593
|
+
case 3:
|
5645
5594
|
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
|
5646
5595
|
if (unWrappedSolBalance.lt(lamports)) {
|
5647
5596
|
throw "Insufficient SOL Funds";
|
5648
5597
|
}
|
5649
|
-
_c.label =
|
5650
|
-
case
|
5598
|
+
_c.label = 4;
|
5599
|
+
case 4:
|
5651
5600
|
if (!ephemeralSignerPubkey) {
|
5652
5601
|
wrappedSolAccount = new web3_js_1.Keypair();
|
5653
5602
|
additionalSigners.push(wrappedSolAccount);
|
@@ -5666,22 +5615,22 @@ var PerpetualsClient = (function () {
|
|
5666
5615
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
5667
5616
|
];
|
5668
5617
|
additionalSigners.push(wrappedSolAccount);
|
5669
|
-
return [3,
|
5670
|
-
case
|
5671
|
-
case
|
5618
|
+
return [3, 8];
|
5619
|
+
case 5: return [4, (0, utils_1.checkIfAccountExists)(userReserveTokenAccount, this.provider.connection)];
|
5620
|
+
case 6:
|
5672
5621
|
if (!(_c.sent())) {
|
5673
5622
|
throw "Insufficient Funds , token Account doesn't exist";
|
5674
5623
|
}
|
5675
|
-
if (!!skipBalanceChecks) return [3,
|
5624
|
+
if (!!skipBalanceChecks) return [3, 8];
|
5676
5625
|
_b = anchor_1.BN.bind;
|
5677
5626
|
return [4, this.provider.connection.getTokenAccountBalance(userReserveTokenAccount)];
|
5678
|
-
case
|
5627
|
+
case 7:
|
5679
5628
|
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
5680
5629
|
if (tokenAccountBalance.lt(reserveAmount)) {
|
5681
5630
|
throw "Insufficient Funds need more ".concat(reserveAmount.sub(tokenAccountBalance), " tokens");
|
5682
5631
|
}
|
5683
|
-
_c.label =
|
5684
|
-
case
|
5632
|
+
_c.label = 8;
|
5633
|
+
case 8:
|
5685
5634
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
5686
5635
|
orderAccount = poolConfig.getOrderFromMarketPk(publicKey, marketAccount);
|
5687
5636
|
return [4, this.program.methods
|
@@ -5708,22 +5657,21 @@ var PerpetualsClient = (function () {
|
|
5708
5657
|
reserveOracleAccount: this.useExtOracleAccount ? reserveCustodyConfig.extOracleAccount : reserveCustodyConfig.intOracleAccount,
|
5709
5658
|
reserveCustodyTokenAccount: reserveCustodyConfig.tokenAccount,
|
5710
5659
|
systemProgram: web3_js_1.SystemProgram.programId,
|
5711
|
-
tokenProgram:
|
5660
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5712
5661
|
eventAuthority: this.eventAuthority.publicKey,
|
5713
5662
|
program: this.programId,
|
5714
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5715
|
-
fundingMint: reserveCustodyConfig.mintKey
|
5663
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5716
5664
|
})
|
5717
5665
|
.instruction()];
|
5718
|
-
case
|
5666
|
+
case 9:
|
5719
5667
|
placeLimitOrder = _c.sent();
|
5720
5668
|
instructions.push(placeLimitOrder);
|
5721
|
-
return [3,
|
5722
|
-
case
|
5669
|
+
return [3, 11];
|
5670
|
+
case 10:
|
5723
5671
|
err_27 = _c.sent();
|
5724
5672
|
console.log("perpClient placeLimitOrder error:: ", err_27);
|
5725
5673
|
throw err_27;
|
5726
|
-
case
|
5674
|
+
case 11: return [2, {
|
5727
5675
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5728
5676
|
additionalSigners: additionalSigners
|
5729
5677
|
}];
|
@@ -5772,7 +5720,7 @@ var PerpetualsClient = (function () {
|
|
5772
5720
|
];
|
5773
5721
|
return [3, 5];
|
5774
5722
|
case 2:
|
5775
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey, true
|
5723
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey, true);
|
5776
5724
|
_a = createUserATA;
|
5777
5725
|
if (!_a) return [3, 4];
|
5778
5726
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -5781,7 +5729,7 @@ var PerpetualsClient = (function () {
|
|
5781
5729
|
_b.label = 4;
|
5782
5730
|
case 4:
|
5783
5731
|
if (_a) {
|
5784
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(reserveSymbol).mintKey
|
5732
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(reserveSymbol).mintKey));
|
5785
5733
|
}
|
5786
5734
|
_b.label = 5;
|
5787
5735
|
case 5:
|
@@ -5811,11 +5759,10 @@ var PerpetualsClient = (function () {
|
|
5811
5759
|
reserveOracleAccount: this.useExtOracleAccount ? reserveCustodyConfig.extOracleAccount : reserveCustodyConfig.intOracleAccount,
|
5812
5760
|
reserveCustodyTokenAccount: reserveCustodyConfig.tokenAccount,
|
5813
5761
|
receivingAccount: reserveSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
5814
|
-
tokenProgram:
|
5762
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5815
5763
|
eventAuthority: this.eventAuthority.publicKey,
|
5816
5764
|
program: this.programId,
|
5817
5765
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5818
|
-
receivingMint: reserveCustodyConfig.mintKey
|
5819
5766
|
})
|
5820
5767
|
.instruction()];
|
5821
5768
|
case 6:
|
@@ -6138,7 +6085,7 @@ var PerpetualsClient = (function () {
|
|
6138
6085
|
if (createUserATA === void 0) { createUserATA = true; }
|
6139
6086
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6140
6087
|
return __awaiter(_this, void 0, void 0, function () {
|
6141
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners,
|
6088
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, executeTriggerWithSwap, err_34;
|
6142
6089
|
return __generator(this, function (_d) {
|
6143
6090
|
switch (_d.label) {
|
6144
6091
|
case 0:
|
@@ -6151,15 +6098,13 @@ var PerpetualsClient = (function () {
|
|
6151
6098
|
instructions = [];
|
6152
6099
|
postInstructions = [];
|
6153
6100
|
additionalSigners = [];
|
6154
|
-
collateralToken = poolConfig.getTokenFromSymbol(collateralSymbol);
|
6155
|
-
receivingToken = poolConfig.getTokenFromSymbol(receivingSymbol);
|
6156
6101
|
_d.label = 1;
|
6157
6102
|
case 1:
|
6158
6103
|
_d.trys.push([1, 9, , 10]);
|
6159
6104
|
if (!false) return [3, 2];
|
6160
6105
|
return [3, 7];
|
6161
6106
|
case 2:
|
6162
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(
|
6107
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(receivingSymbol).mintKey, owner, true);
|
6163
6108
|
_a = createUserATA;
|
6164
6109
|
if (!_a) return [3, 4];
|
6165
6110
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -6168,9 +6113,9 @@ var PerpetualsClient = (function () {
|
|
6168
6113
|
_d.label = 4;
|
6169
6114
|
case 4:
|
6170
6115
|
if (_a) {
|
6171
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner,
|
6116
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
|
6172
6117
|
}
|
6173
|
-
userReceivingTokenAccountCollateral = (0, spl_token_1.getAssociatedTokenAddressSync)(
|
6118
|
+
userReceivingTokenAccountCollateral = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, owner, true);
|
6174
6119
|
_b = createUserATA;
|
6175
6120
|
if (!_b) return [3, 6];
|
6176
6121
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
|
@@ -6179,7 +6124,7 @@ var PerpetualsClient = (function () {
|
|
6179
6124
|
_d.label = 6;
|
6180
6125
|
case 6:
|
6181
6126
|
if (_b) {
|
6182
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner,
|
6127
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
6183
6128
|
}
|
6184
6129
|
_d.label = 7;
|
6185
6130
|
case 7:
|
@@ -6223,13 +6168,10 @@ var PerpetualsClient = (function () {
|
|
6223
6168
|
dispensingCustody: receivingCustodyConfig.custodyAccount,
|
6224
6169
|
dispensingOracleAccount: this.useExtOracleAccount ? receivingCustodyConfig.extOracleAccount : receivingCustodyConfig.intOracleAccount,
|
6225
6170
|
dispensingCustodyTokenAccount: receivingCustodyConfig.tokenAccount,
|
6171
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6226
6172
|
eventAuthority: this.eventAuthority.publicKey,
|
6227
6173
|
program: this.programId,
|
6228
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6229
|
-
receivingMint: receivingCustodyConfig.mintKey,
|
6230
|
-
receivingTokenProgram: receivingToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
6231
|
-
collateralMint: collateralCustodyConfig.mintKey,
|
6232
|
-
collateralTokenProgram: collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
6174
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6233
6175
|
})
|
6234
6176
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
6235
6177
|
.instruction()];
|
@@ -6271,7 +6213,7 @@ var PerpetualsClient = (function () {
|
|
6271
6213
|
if (!false) return [3, 2];
|
6272
6214
|
return [3, 5];
|
6273
6215
|
case 2:
|
6274
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, owner, true
|
6216
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, owner, true);
|
6275
6217
|
_a = createUserATA;
|
6276
6218
|
if (!_a) return [3, 4];
|
6277
6219
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -6280,7 +6222,7 @@ var PerpetualsClient = (function () {
|
|
6280
6222
|
_b.label = 4;
|
6281
6223
|
case 4:
|
6282
6224
|
if (_a) {
|
6283
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey
|
6225
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
6284
6226
|
}
|
6285
6227
|
_b.label = 5;
|
6286
6228
|
case 5:
|
@@ -6305,11 +6247,10 @@ var PerpetualsClient = (function () {
|
|
6305
6247
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
6306
6248
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
6307
6249
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
6308
|
-
tokenProgram:
|
6250
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6309
6251
|
eventAuthority: this.eventAuthority.publicKey,
|
6310
6252
|
program: this.programId,
|
6311
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6312
|
-
receivingMint: collateralCustodyConfig.mintKey
|
6253
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6313
6254
|
})
|
6314
6255
|
.instruction()];
|
6315
6256
|
case 6:
|
@@ -6413,12 +6354,14 @@ var PerpetualsClient = (function () {
|
|
6413
6354
|
case 0:
|
6414
6355
|
publicKey = this.provider.wallet.publicKey;
|
6415
6356
|
custodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
6416
|
-
|
6357
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey, publicKey, true)];
|
6358
|
+
case 1:
|
6359
|
+
receivingTokenAccount = _a.sent();
|
6417
6360
|
instructions = [];
|
6418
6361
|
additionalSigners = [];
|
6419
|
-
_a.label =
|
6420
|
-
case
|
6421
|
-
_a.trys.push([
|
6362
|
+
_a.label = 2;
|
6363
|
+
case 2:
|
6364
|
+
_a.trys.push([2, 4, , 5]);
|
6422
6365
|
return [4, this.program.methods
|
6423
6366
|
.withdrawFees({})
|
6424
6367
|
.accounts({
|
@@ -6430,19 +6373,18 @@ var PerpetualsClient = (function () {
|
|
6430
6373
|
custody: custodyConfig.custodyAccount,
|
6431
6374
|
custodyTokenAccount: custodyConfig.tokenAccount,
|
6432
6375
|
receivingTokenAccount: receivingTokenAccount,
|
6433
|
-
tokenProgram:
|
6434
|
-
receivingMint: custodyConfig.mintKey
|
6376
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
6435
6377
|
})
|
6436
6378
|
.instruction()];
|
6437
|
-
case
|
6379
|
+
case 3:
|
6438
6380
|
withdrawFeesIx = _a.sent();
|
6439
6381
|
instructions.push(withdrawFeesIx);
|
6440
|
-
return [3,
|
6441
|
-
case
|
6382
|
+
return [3, 5];
|
6383
|
+
case 4:
|
6442
6384
|
err_38 = _a.sent();
|
6443
6385
|
console.log("perpClient setPool error:: ", err_38);
|
6444
6386
|
throw err_38;
|
6445
|
-
case
|
6387
|
+
case 5: return [2, {
|
6446
6388
|
instructions: __spreadArray([], instructions, true),
|
6447
6389
|
additionalSigners: additionalSigners
|
6448
6390
|
}];
|
@@ -6488,9 +6430,10 @@ var PerpetualsClient = (function () {
|
|
6488
6430
|
});
|
6489
6431
|
}); };
|
6490
6432
|
this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6491
|
-
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, err_40;
|
6492
|
-
|
6493
|
-
|
6433
|
+
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_40;
|
6434
|
+
var _f;
|
6435
|
+
return __generator(this, function (_g) {
|
6436
|
+
switch (_g.label) {
|
6494
6437
|
case 0:
|
6495
6438
|
custodyAccountMetas = [];
|
6496
6439
|
custodyOracleAccountMetas = [];
|
@@ -6519,36 +6462,38 @@ var PerpetualsClient = (function () {
|
|
6519
6462
|
instructions = [];
|
6520
6463
|
additionalSigners = [];
|
6521
6464
|
custodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(tokenMint); });
|
6522
|
-
|
6465
|
+
_g.label = 1;
|
6523
6466
|
case 1:
|
6524
|
-
|
6525
|
-
|
6526
|
-
|
6527
|
-
|
6528
|
-
|
6529
|
-
|
6530
|
-
|
6531
|
-
|
6532
|
-
|
6533
|
-
|
6534
|
-
|
6535
|
-
|
6536
|
-
|
6537
|
-
|
6538
|
-
|
6539
|
-
|
6540
|
-
|
6541
|
-
.
|
6542
|
-
|
6543
|
-
|
6544
|
-
|
6545
|
-
instructions.push(reimburse);
|
6546
|
-
return [3, 4];
|
6467
|
+
_g.trys.push([1, 4, , 5]);
|
6468
|
+
_e = (_d = this.program.methods
|
6469
|
+
.reimburse({ amountIn: amountIn }))
|
6470
|
+
.accounts;
|
6471
|
+
_f = {
|
6472
|
+
admin: this.provider.wallet.publicKey,
|
6473
|
+
multisig: poolConfig.multisig
|
6474
|
+
};
|
6475
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(tokenMint, this.provider.wallet.publicKey, true)];
|
6476
|
+
case 2: return [4, _e.apply(_d, [(_f.fundingAccount = _g.sent(),
|
6477
|
+
_f.perpetuals = poolConfig.perpetuals,
|
6478
|
+
_f.pool = poolConfig.poolAddress,
|
6479
|
+
_f.custody = custodyConfig.custodyAccount,
|
6480
|
+
_f.custodyOracleAccount = this.useExtOracleAccount ? custodyConfig.extOracleAccount : custodyConfig.intOracleAccount,
|
6481
|
+
_f.custodyTokenAccount = custodyConfig.tokenAccount,
|
6482
|
+
_f.tokenProgram = spl_token_1.TOKEN_PROGRAM_ID,
|
6483
|
+
_f.program = poolConfig.programId,
|
6484
|
+
_f.ixSysvar = web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6485
|
+
_f)])
|
6486
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
6487
|
+
.instruction()];
|
6547
6488
|
case 3:
|
6548
|
-
|
6489
|
+
reimburse = _g.sent();
|
6490
|
+
instructions.push(reimburse);
|
6491
|
+
return [3, 5];
|
6492
|
+
case 4:
|
6493
|
+
err_40 = _g.sent();
|
6549
6494
|
console.log("perpClient setPool error:: ", err_40);
|
6550
6495
|
throw err_40;
|
6551
|
-
case
|
6496
|
+
case 5: return [2, {
|
6552
6497
|
instructions: __spreadArray([], instructions, true),
|
6553
6498
|
additionalSigners: additionalSigners
|
6554
6499
|
}];
|
@@ -6603,23 +6548,22 @@ var PerpetualsClient = (function () {
|
|
6603
6548
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6604
6549
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6605
6550
|
return __awaiter(_this, void 0, void 0, function () {
|
6606
|
-
var publicKey,
|
6551
|
+
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_42;
|
6607
6552
|
return __generator(this, function (_e) {
|
6608
6553
|
switch (_e.label) {
|
6609
6554
|
case 0:
|
6610
6555
|
publicKey = this.provider.wallet.publicKey;
|
6611
|
-
inToken = poolConfig.getTokenFromSymbol(inTokenSymbol);
|
6612
6556
|
preInstructions = [];
|
6613
6557
|
instructions = [];
|
6614
6558
|
additionalSigners = [];
|
6615
6559
|
postInstructions = [];
|
6616
6560
|
rewardCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardTokenMint); });
|
6617
|
-
inCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(
|
6561
|
+
inCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inTokenSymbol).mintKey); });
|
6618
6562
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
6619
6563
|
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
6620
6564
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
6621
6565
|
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
6622
|
-
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inCustodyConfig.mintKey, publicKey, true
|
6566
|
+
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inCustodyConfig.mintKey, publicKey, true);
|
6623
6567
|
custodyAccountMetas = [];
|
6624
6568
|
custodyOracleAccountMetas = [];
|
6625
6569
|
markets = [];
|
@@ -6718,9 +6662,7 @@ var PerpetualsClient = (function () {
|
|
6718
6662
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6719
6663
|
eventAuthority: this.eventAuthority.publicKey,
|
6720
6664
|
program: this.program.programId,
|
6721
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6722
|
-
fundingMint: inCustodyConfig.mintKey,
|
6723
|
-
fundingTokenProgram: inToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
6665
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6724
6666
|
})
|
6725
6667
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
6726
6668
|
.instruction()];
|
@@ -6744,7 +6686,7 @@ var PerpetualsClient = (function () {
|
|
6744
6686
|
if (createUserATA === void 0) { createUserATA = true; }
|
6745
6687
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6746
6688
|
return __awaiter(_this, void 0, void 0, function () {
|
6747
|
-
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint,
|
6689
|
+
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_43;
|
6748
6690
|
return __generator(this, function (_e) {
|
6749
6691
|
switch (_e.label) {
|
6750
6692
|
case 0:
|
@@ -6757,7 +6699,6 @@ var PerpetualsClient = (function () {
|
|
6757
6699
|
outCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(outTokenSymbol).mintKey); });
|
6758
6700
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
6759
6701
|
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
6760
|
-
outToken = poolConfig.getTokenFromSymbol(outTokenSymbol);
|
6761
6702
|
if (!(outCustodyConfig.symbol == 'SOL')) return [3, 1];
|
6762
6703
|
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
6763
6704
|
if (!ephemeralSignerPubkey) {
|
@@ -6779,7 +6720,7 @@ var PerpetualsClient = (function () {
|
|
6779
6720
|
];
|
6780
6721
|
return [3, 4];
|
6781
6722
|
case 1:
|
6782
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(outCustodyConfig.mintKey, publicKey, true
|
6723
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(outCustodyConfig.mintKey, publicKey, true);
|
6783
6724
|
_a = createUserATA;
|
6784
6725
|
if (!_a) return [3, 3];
|
6785
6726
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -6788,7 +6729,7 @@ var PerpetualsClient = (function () {
|
|
6788
6729
|
_e.label = 3;
|
6789
6730
|
case 3:
|
6790
6731
|
if (_a) {
|
6791
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey
|
6732
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
|
6792
6733
|
}
|
6793
6734
|
_e.label = 4;
|
6794
6735
|
case 4:
|
@@ -6843,9 +6784,7 @@ var PerpetualsClient = (function () {
|
|
6843
6784
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6844
6785
|
eventAuthority: this.eventAuthority.publicKey,
|
6845
6786
|
program: this.program.programId,
|
6846
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6847
|
-
receivingMint: outCustodyConfig.mintKey,
|
6848
|
-
receivingTokenProgram: outToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
6787
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6849
6788
|
})
|
6850
6789
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
6851
6790
|
.instruction()];
|
@@ -7243,19 +7182,18 @@ var PerpetualsClient = (function () {
|
|
7243
7182
|
});
|
7244
7183
|
}); };
|
7245
7184
|
this.rewardDistribution = function (counter, owner, rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7246
|
-
var publicKey,
|
7185
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, rewardRecord, distributeReward, err_50;
|
7247
7186
|
return __generator(this, function (_a) {
|
7248
7187
|
switch (_a.label) {
|
7249
7188
|
case 0:
|
7250
7189
|
publicKey = this.provider.wallet.publicKey;
|
7251
|
-
|
7252
|
-
rewardCustodyMint = rewardToken.mintKey;
|
7190
|
+
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
7253
7191
|
instructions = [];
|
7254
7192
|
additionalSigners = [];
|
7255
7193
|
_a.label = 1;
|
7256
7194
|
case 1:
|
7257
7195
|
_a.trys.push([1, 3, , 4]);
|
7258
|
-
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true
|
7196
|
+
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
7259
7197
|
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programRewardDistribution.programId)[0];
|
7260
7198
|
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programRewardDistribution.programId)[0];
|
7261
7199
|
rewardRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_record"), owner.toBuffer(), rewardVault.toBuffer(), counter.toArrayLike(Buffer, 'le', 8)], this.programRewardDistribution.programId)[0];
|
@@ -7272,7 +7210,7 @@ var PerpetualsClient = (function () {
|
|
7272
7210
|
rewardTokenAccount: rewardTokenAccount,
|
7273
7211
|
rewardRecord: rewardRecord,
|
7274
7212
|
systemProgram: web3_js_1.SystemProgram.programId,
|
7275
|
-
tokenProgram:
|
7213
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7276
7214
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
7277
7215
|
eventAuthority: this.eventAuthorityRewardDistribution.publicKey,
|
7278
7216
|
program: this.programRewardDistribution.programId
|
@@ -7296,19 +7234,18 @@ var PerpetualsClient = (function () {
|
|
7296
7234
|
this.collectReward = function (counter, owner, rewardSymbol, poolConfig, createUserATA) {
|
7297
7235
|
if (createUserATA === void 0) { createUserATA = true; }
|
7298
7236
|
return __awaiter(_this, void 0, void 0, function () {
|
7299
|
-
var publicKey,
|
7237
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, receivingTokenAccount, _a, rewardVault, rewardTokenAccount, rewardRecord, transferAuthority, collectRaffleReward, err_51;
|
7300
7238
|
return __generator(this, function (_b) {
|
7301
7239
|
switch (_b.label) {
|
7302
7240
|
case 0:
|
7303
7241
|
publicKey = this.provider.wallet.publicKey;
|
7304
|
-
|
7305
|
-
rewardCustodyMint = rewardToken.mintKey;
|
7242
|
+
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
7306
7243
|
instructions = [];
|
7307
7244
|
additionalSigners = [];
|
7308
7245
|
_b.label = 1;
|
7309
7246
|
case 1:
|
7310
7247
|
_b.trys.push([1, 5, , 6]);
|
7311
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true
|
7248
|
+
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
7312
7249
|
_a = createUserATA;
|
7313
7250
|
if (!_a) return [3, 3];
|
7314
7251
|
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
@@ -7317,7 +7254,7 @@ var PerpetualsClient = (function () {
|
|
7317
7254
|
_b.label = 3;
|
7318
7255
|
case 3:
|
7319
7256
|
if (_a) {
|
7320
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint
|
7257
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
7321
7258
|
}
|
7322
7259
|
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programRewardDistribution.programId)[0];
|
7323
7260
|
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programRewardDistribution.programId)[0];
|