flash-sdk 2.25.2 → 2.25.4
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 +318 -268
- package/dist/PoolConfig.d.ts +1 -0
- package/dist/PoolConfig.json +119 -67
- package/dist/idl/perpetuals.d.ts +192 -14
- package/dist/idl/perpetuals.js +192 -14
- 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, oracle, pricing, permissions, fees, borrowRate, ratios, depegAdjustment) { return __awaiter(_this, void 0, void 0, function () {
|
504
|
+
this.addCustody = function (poolName, tokenMint, isStable, isVirtual, token22, 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,6 +511,7 @@ var PerpetualsClient = (function () {
|
|
511
511
|
.addCustody({
|
512
512
|
isStable: isStable,
|
513
513
|
isVirtual: isVirtual,
|
514
|
+
token22: token22,
|
514
515
|
oracle: oracle,
|
515
516
|
pricing: pricing,
|
516
517
|
permissions: permissions,
|
@@ -2481,34 +2482,33 @@ var PerpetualsClient = (function () {
|
|
2481
2482
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2482
2483
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2483
2484
|
return __awaiter(_this, void 0, void 0, function () {
|
2484
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
2485
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, collateralToken, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, rebateMintAccount, params, instruction;
|
2485
2486
|
return __generator(this, function (_c) {
|
2486
2487
|
switch (_c.label) {
|
2487
2488
|
case 0:
|
2488
2489
|
publicKey = this.provider.wallet.publicKey;
|
2489
2490
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
2490
2491
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
2492
|
+
collateralToken = poolConfig.getTokenFromSymbol(collateralSymbol);
|
2491
2493
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
2492
|
-
|
2493
|
-
case 1:
|
2494
|
-
userCollateralTokenAccount = _c.sent();
|
2494
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
2495
2495
|
preInstructions = [];
|
2496
2496
|
instructions = [];
|
2497
2497
|
postInstructions = [];
|
2498
2498
|
additionalSigners = [];
|
2499
|
-
if (!(collateralSymbol == 'SOL')) return [3,
|
2499
|
+
if (!(collateralSymbol == 'SOL')) return [3, 3];
|
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, 2];
|
2503
2503
|
_a = anchor_1.BN.bind;
|
2504
2504
|
return [4, this.provider.connection.getBalance(publicKey)];
|
2505
|
-
case
|
2505
|
+
case 1:
|
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 = 2;
|
2511
|
+
case 2:
|
2512
2512
|
if (!ephemeralSignerPubkey) {
|
2513
2513
|
wrappedSolAccount = new web3_js_1.Keypair();
|
2514
2514
|
additionalSigners.push(wrappedSolAccount);
|
@@ -2526,24 +2526,29 @@ 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
|
2531
|
-
if (!!skipBalanceChecks) return [3,
|
2529
|
+
return [3, 6];
|
2530
|
+
case 3:
|
2531
|
+
if (!!skipBalanceChecks) return [3, 6];
|
2532
2532
|
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
2533
|
-
case
|
2533
|
+
case 4:
|
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 5:
|
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 = 6;
|
2545
|
+
case 6:
|
2546
2546
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
2547
|
+
rebateMintAccount = {
|
2548
|
+
pubkey: collateralCustodyConfig.mintKey,
|
2549
|
+
isSigner: false,
|
2550
|
+
isWritable: false
|
2551
|
+
};
|
2547
2552
|
params = {
|
2548
2553
|
priceWithSlippage: priceWithSlippage,
|
2549
2554
|
collateralAmount: collateralWithfee,
|
@@ -2570,11 +2575,12 @@ var PerpetualsClient = (function () {
|
|
2570
2575
|
eventAuthority: this.eventAuthority.publicKey,
|
2571
2576
|
program: this.programId,
|
2572
2577
|
transferAuthority: this.authority.publicKey,
|
2573
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2578
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2579
|
+
fundingMint: collateralCustodyConfig.mintKey
|
2574
2580
|
})
|
2575
|
-
.remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
|
2581
|
+
.remainingAccounts(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), [rebateMintAccount], false))
|
2576
2582
|
.instruction()];
|
2577
|
-
case
|
2583
|
+
case 7:
|
2578
2584
|
instruction = _c.sent();
|
2579
2585
|
instructions.push(instruction);
|
2580
2586
|
return [2, {
|
@@ -2640,7 +2646,7 @@ var PerpetualsClient = (function () {
|
|
2640
2646
|
];
|
2641
2647
|
return [3, 6];
|
2642
2648
|
case 3:
|
2643
|
-
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(inputSymbol).mintKey, publicKey, true);
|
2649
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(inputSymbol).mintKey, publicKey, true, swapPoolConfig.getTokenFromSymbol(inputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
2644
2650
|
if (!!skipBalanceChecks) return [3, 6];
|
2645
2651
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
2646
2652
|
case 4:
|
@@ -2656,11 +2662,11 @@ var PerpetualsClient = (function () {
|
|
2656
2662
|
}
|
2657
2663
|
_d.label = 6;
|
2658
2664
|
case 6:
|
2659
|
-
userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).mintKey, publicKey, true);
|
2665
|
+
userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).mintKey, publicKey, true, swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
2660
2666
|
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
2661
2667
|
case 7:
|
2662
2668
|
if (!(_d.sent())) {
|
2663
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).mintKey));
|
2669
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).mintKey, swapPoolConfig.getTokenFromSymbol(swapOutCustodyConfig.symbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
2664
2670
|
}
|
2665
2671
|
marketAccount = positionPoolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
2666
2672
|
positionAccount = positionPoolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
@@ -2735,7 +2741,7 @@ var PerpetualsClient = (function () {
|
|
2735
2741
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
2736
2742
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2737
2743
|
return __awaiter(_this, void 0, void 0, function () {
|
2738
|
-
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_2;
|
2744
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, rebateMintAccount, instruction, closeWsolATAIns, error_2;
|
2739
2745
|
return __generator(this, function (_b) {
|
2740
2746
|
switch (_b.label) {
|
2741
2747
|
case 0:
|
@@ -2769,7 +2775,7 @@ var PerpetualsClient = (function () {
|
|
2769
2775
|
];
|
2770
2776
|
return [3, 5];
|
2771
2777
|
case 2:
|
2772
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
2778
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
2773
2779
|
_a = createUserATA;
|
2774
2780
|
if (!_a) return [3, 4];
|
2775
2781
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -2778,7 +2784,7 @@ var PerpetualsClient = (function () {
|
|
2778
2784
|
_b.label = 4;
|
2779
2785
|
case 4:
|
2780
2786
|
if (_a) {
|
2781
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
2787
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
2782
2788
|
}
|
2783
2789
|
_b.label = 5;
|
2784
2790
|
case 5:
|
@@ -2786,6 +2792,11 @@ var PerpetualsClient = (function () {
|
|
2786
2792
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(marketSymbol).mintKey); });
|
2787
2793
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
2788
2794
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
2795
|
+
rebateMintAccount = {
|
2796
|
+
pubkey: collateralCustodyConfig.mintKey,
|
2797
|
+
isSigner: false,
|
2798
|
+
isWritable: false
|
2799
|
+
};
|
2789
2800
|
return [4, this.program.methods
|
2790
2801
|
.closePosition({
|
2791
2802
|
priceWithSlippage: priceWithSlippage,
|
@@ -2808,9 +2819,10 @@ var PerpetualsClient = (function () {
|
|
2808
2819
|
eventAuthority: this.eventAuthority.publicKey,
|
2809
2820
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
2810
2821
|
program: this.programId,
|
2811
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2822
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2823
|
+
receivingMint: collateralCustodyConfig.mintKey
|
2812
2824
|
})
|
2813
|
-
.remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
|
2825
|
+
.remainingAccounts(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), [rebateMintAccount], false))
|
2814
2826
|
.instruction()];
|
2815
2827
|
case 6:
|
2816
2828
|
instruction = _b.sent();
|
@@ -2875,22 +2887,21 @@ var PerpetualsClient = (function () {
|
|
2875
2887
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2876
2888
|
];
|
2877
2889
|
additionalSigners.push(wrappedSolAccount);
|
2878
|
-
return [3,
|
2879
|
-
case 1:
|
2880
|
-
|
2881
|
-
userReceivingTokenAccount = _b.sent();
|
2890
|
+
return [3, 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);
|
2882
2893
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
2883
|
-
case
|
2894
|
+
case 2:
|
2884
2895
|
if (!(_b.sent())) {
|
2885
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey));
|
2896
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey, swapPoolConfig.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
2886
2897
|
}
|
2887
|
-
_b.label =
|
2888
|
-
case
|
2889
|
-
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
2898
|
+
_b.label = 3;
|
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);
|
2890
2901
|
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
2891
|
-
case
|
2902
|
+
case 4:
|
2892
2903
|
if (!(_b.sent())) {
|
2893
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
2904
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey, positionPoolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
2894
2905
|
}
|
2895
2906
|
marketAccount = positionPoolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
2896
2907
|
positionAccount = positionPoolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
@@ -2939,11 +2950,11 @@ var PerpetualsClient = (function () {
|
|
2939
2950
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
2940
2951
|
eventAuthority: this.eventAuthority.publicKey,
|
2941
2952
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
2942
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2953
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2943
2954
|
})
|
2944
2955
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
2945
2956
|
.instruction()];
|
2946
|
-
case
|
2957
|
+
case 5:
|
2947
2958
|
instruction = _b.sent();
|
2948
2959
|
instructions.push(instruction);
|
2949
2960
|
return [2, {
|
@@ -2961,7 +2972,7 @@ var PerpetualsClient = (function () {
|
|
2961
2972
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2962
2973
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2963
2974
|
return __awaiter(_this, void 0, void 0, function () {
|
2964
|
-
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_2;
|
2975
|
+
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userOutputTokenAccount, rebateMintAccount, inx, err_2;
|
2965
2976
|
return __generator(this, function (_c) {
|
2966
2977
|
switch (_c.label) {
|
2967
2978
|
case 0:
|
@@ -3019,7 +3030,7 @@ var PerpetualsClient = (function () {
|
|
3019
3030
|
];
|
3020
3031
|
return [3, 6];
|
3021
3032
|
case 3:
|
3022
|
-
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
|
3033
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(userInputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3023
3034
|
if (!!skipBalanceChecks) return [3, 6];
|
3024
3035
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3025
3036
|
case 4:
|
@@ -3035,12 +3046,17 @@ var PerpetualsClient = (function () {
|
|
3035
3046
|
}
|
3036
3047
|
_c.label = 6;
|
3037
3048
|
case 6:
|
3038
|
-
userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey, publicKey, true);
|
3049
|
+
userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3039
3050
|
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
3040
3051
|
case 7:
|
3041
3052
|
if (!(_c.sent())) {
|
3042
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey));
|
3053
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3043
3054
|
}
|
3055
|
+
rebateMintAccount = {
|
3056
|
+
pubkey: collateralCustodyConfig.mintKey,
|
3057
|
+
isSigner: false,
|
3058
|
+
isWritable: false
|
3059
|
+
};
|
3044
3060
|
_c.label = 8;
|
3045
3061
|
case 8:
|
3046
3062
|
_c.trys.push([8, 10, , 11]);
|
@@ -3073,9 +3089,11 @@ var PerpetualsClient = (function () {
|
|
3073
3089
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3074
3090
|
eventAuthority: this.eventAuthority.publicKey,
|
3075
3091
|
program: this.programId,
|
3076
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3092
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3093
|
+
fundingMint: userInputCustodyConfig.mintKey,
|
3094
|
+
fundingTokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
3077
3095
|
})
|
3078
|
-
.remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
|
3096
|
+
.remainingAccounts(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), [rebateMintAccount], false))
|
3079
3097
|
.instruction()];
|
3080
3098
|
case 9:
|
3081
3099
|
inx = _c.sent();
|
@@ -3099,7 +3117,7 @@ var PerpetualsClient = (function () {
|
|
3099
3117
|
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
3100
3118
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3101
3119
|
return __awaiter(_this, void 0, void 0, function () {
|
3102
|
-
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, inx, err_3;
|
3120
|
+
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, rebateMintAccount, inx, err_3;
|
3103
3121
|
return __generator(this, function (_a) {
|
3104
3122
|
switch (_a.label) {
|
3105
3123
|
case 0:
|
@@ -3146,26 +3164,30 @@ var PerpetualsClient = (function () {
|
|
3146
3164
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3147
3165
|
];
|
3148
3166
|
additionalSigners.push(wrappedSolAccount);
|
3149
|
-
return [3,
|
3150
|
-
case 1:
|
3151
|
-
|
3152
|
-
userReceivingTokenAccount = _a.sent();
|
3167
|
+
return [3, 3];
|
3168
|
+
case 1:
|
3169
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3153
3170
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
3154
|
-
case
|
3171
|
+
case 2:
|
3155
3172
|
if (!(_a.sent())) {
|
3156
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
|
3173
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3157
3174
|
}
|
3158
|
-
_a.label =
|
3159
|
-
case
|
3160
|
-
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralTokenSymbol).mintKey, publicKey, true);
|
3175
|
+
_a.label = 3;
|
3176
|
+
case 3:
|
3177
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralTokenSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3161
3178
|
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3162
|
-
case
|
3179
|
+
case 4:
|
3163
3180
|
if (!(_a.sent())) {
|
3164
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralTokenSymbol).mintKey));
|
3181
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralTokenSymbol).mintKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3165
3182
|
}
|
3166
|
-
|
3167
|
-
|
3168
|
-
|
3183
|
+
rebateMintAccount = {
|
3184
|
+
pubkey: collateralCustodyConfig.mintKey,
|
3185
|
+
isSigner: false,
|
3186
|
+
isWritable: false
|
3187
|
+
};
|
3188
|
+
_a.label = 5;
|
3189
|
+
case 5:
|
3190
|
+
_a.trys.push([5, 7, , 8]);
|
3169
3191
|
return [4, this.program.methods
|
3170
3192
|
.closeAndSwap({
|
3171
3193
|
priceWithSlippage: priceWithSlippage,
|
@@ -3190,22 +3212,25 @@ var PerpetualsClient = (function () {
|
|
3190
3212
|
dispensingCustody: userOutputCustodyConfig.custodyAccount,
|
3191
3213
|
dispensingOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
|
3192
3214
|
dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
|
3193
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3194
3215
|
eventAuthority: this.eventAuthority.publicKey,
|
3195
3216
|
program: this.programId,
|
3196
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3217
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3218
|
+
receivingMint: userOutputCustodyConfig.mintKey,
|
3219
|
+
receivingTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3220
|
+
collateralMint: collateralCustodyConfig.mintKey,
|
3221
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
3197
3222
|
})
|
3198
|
-
.remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
|
3223
|
+
.remainingAccounts(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), [rebateMintAccount], false))
|
3199
3224
|
.instruction()];
|
3200
|
-
case
|
3225
|
+
case 6:
|
3201
3226
|
inx = _a.sent();
|
3202
3227
|
instructions.push(inx);
|
3203
|
-
return [3,
|
3204
|
-
case
|
3228
|
+
return [3, 8];
|
3229
|
+
case 7:
|
3205
3230
|
err_3 = _a.sent();
|
3206
3231
|
console.error("perpClient CloseAndSwap error:: ", err_3);
|
3207
3232
|
throw err_3;
|
3208
|
-
case
|
3233
|
+
case 8: return [2, {
|
3209
3234
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3210
3235
|
additionalSigners: additionalSigners
|
3211
3236
|
}];
|
@@ -3237,26 +3262,24 @@ var PerpetualsClient = (function () {
|
|
3237
3262
|
instructions = [];
|
3238
3263
|
postInstructions = [];
|
3239
3264
|
additionalSigners = [];
|
3240
|
-
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3,
|
3241
|
-
|
3242
|
-
case 1:
|
3243
|
-
wsolAssociatedTokenAccount = _f.sent();
|
3265
|
+
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 4];
|
3266
|
+
wsolAssociatedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, publicKey, true);
|
3244
3267
|
return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
|
3245
|
-
case
|
3268
|
+
case 1:
|
3246
3269
|
wsolATAExist = _f.sent();
|
3247
3270
|
if (!wsolATAExist) {
|
3248
3271
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
3249
3272
|
}
|
3250
|
-
if (!!skipBalanceChecks) return [3,
|
3273
|
+
if (!!skipBalanceChecks) return [3, 3];
|
3251
3274
|
_a = anchor_1.BN.bind;
|
3252
3275
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3253
|
-
case
|
3276
|
+
case 2:
|
3254
3277
|
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
3255
3278
|
if (unWrappedSolBalance.lt(amountIn)) {
|
3256
3279
|
throw "Insufficient SOL Funds";
|
3257
3280
|
}
|
3258
|
-
_f.label =
|
3259
|
-
case
|
3281
|
+
_f.label = 3;
|
3282
|
+
case 3:
|
3260
3283
|
instructions.push(web3_js_1.SystemProgram.transfer({
|
3261
3284
|
fromPubkey: publicKey,
|
3262
3285
|
toPubkey: wsolAssociatedTokenAccount,
|
@@ -3266,7 +3289,7 @@ var PerpetualsClient = (function () {
|
|
3266
3289
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3267
3290
|
additionalSigners: additionalSigners
|
3268
3291
|
}];
|
3269
|
-
case
|
3292
|
+
case 4:
|
3270
3293
|
if (userInputTokenSymbol == 'WSOL' && userOutputTokenSymbol == 'SOL') {
|
3271
3294
|
console.log("WSOL=> SOL : NOTE : ONLY WAY IS TO CLOSE THE WSOL ATA and GET ALL SOL ");
|
3272
3295
|
wsolAssociatedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, publicKey, true);
|
@@ -3277,19 +3300,19 @@ var PerpetualsClient = (function () {
|
|
3277
3300
|
additionalSigners: additionalSigners
|
3278
3301
|
}];
|
3279
3302
|
}
|
3280
|
-
_f.label =
|
3281
|
-
case
|
3282
|
-
_f.trys.push([
|
3283
|
-
if (!(userInputTokenSymbol == 'SOL')) return [3,
|
3303
|
+
_f.label = 5;
|
3304
|
+
case 5:
|
3305
|
+
_f.trys.push([5, 17, , 18]);
|
3306
|
+
if (!(userInputTokenSymbol == 'SOL')) return [3, 8];
|
3284
3307
|
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
3285
3308
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
3286
|
-
case
|
3309
|
+
case 6:
|
3287
3310
|
accCreationLamports = (_f.sent());
|
3288
3311
|
console.log("accCreationLamports:", accCreationLamports);
|
3289
3312
|
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
3290
3313
|
_b = anchor_1.BN.bind;
|
3291
3314
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3292
|
-
case
|
3315
|
+
case 7:
|
3293
3316
|
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
3294
3317
|
if (unWrappedSolBalance.lt(amountIn)) {
|
3295
3318
|
throw "Insufficient SOL Funds";
|
@@ -3312,25 +3335,25 @@ var PerpetualsClient = (function () {
|
|
3312
3335
|
postInstructions = [
|
3313
3336
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3314
3337
|
];
|
3315
|
-
return [3,
|
3316
|
-
case
|
3317
|
-
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
|
3338
|
+
return [3, 11];
|
3339
|
+
case 8:
|
3340
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3318
3341
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3319
|
-
case
|
3342
|
+
case 9:
|
3320
3343
|
if (!(_f.sent())) {
|
3321
3344
|
throw "Insufficient Funds , Token Account doesn't exist";
|
3322
3345
|
}
|
3323
|
-
if (!!skipBalanceChecks) return [3,
|
3346
|
+
if (!!skipBalanceChecks) return [3, 11];
|
3324
3347
|
_c = anchor_1.BN.bind;
|
3325
3348
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3326
|
-
case
|
3349
|
+
case 10:
|
3327
3350
|
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
3328
3351
|
if (tokenAccountBalance.lt(amountIn)) {
|
3329
3352
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3330
3353
|
}
|
3331
|
-
_f.label =
|
3332
|
-
case
|
3333
|
-
if (!(userOutputTokenSymbol == 'SOL')) return [3,
|
3354
|
+
_f.label = 11;
|
3355
|
+
case 11:
|
3356
|
+
if (!(userOutputTokenSymbol == 'SOL')) return [3, 12];
|
3334
3357
|
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
3335
3358
|
if (!ephemeralSignerPubkey) {
|
3336
3359
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -3350,22 +3373,21 @@ var PerpetualsClient = (function () {
|
|
3350
3373
|
postInstructions = [
|
3351
3374
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3352
3375
|
];
|
3353
|
-
return [3,
|
3354
|
-
case
|
3355
|
-
|
3356
|
-
userOutputTokenAccount = _f.sent();
|
3376
|
+
return [3, 15];
|
3377
|
+
case 12:
|
3378
|
+
userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3357
3379
|
_d = createUserATA;
|
3358
|
-
if (!_d) return [3,
|
3380
|
+
if (!_d) return [3, 14];
|
3359
3381
|
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
3360
|
-
case
|
3382
|
+
case 13:
|
3361
3383
|
_d = !(_f.sent());
|
3362
|
-
_f.label =
|
3363
|
-
case
|
3384
|
+
_f.label = 14;
|
3385
|
+
case 14:
|
3364
3386
|
if (_d) {
|
3365
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
|
3387
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3366
3388
|
}
|
3367
|
-
_f.label =
|
3368
|
-
case
|
3389
|
+
_f.label = 15;
|
3390
|
+
case 15:
|
3369
3391
|
custodyAccountMetas = [];
|
3370
3392
|
custodyOracleAccountMetas = [];
|
3371
3393
|
for (_i = 0, _e = poolConfig.custodies; _i < _e.length; _i++) {
|
@@ -3402,25 +3424,28 @@ var PerpetualsClient = (function () {
|
|
3402
3424
|
dispensingCustodyOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
|
3403
3425
|
dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
|
3404
3426
|
eventAuthority: this.eventAuthority.publicKey,
|
3405
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3406
3427
|
program: this.programId,
|
3407
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3428
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3429
|
+
fundingMint: userInputCustodyConfig.mintKey,
|
3430
|
+
fundingTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3431
|
+
receivingMint: userOutputCustodyConfig.mintKey,
|
3432
|
+
receivingTokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
3408
3433
|
})
|
3409
3434
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
3410
3435
|
.instruction()];
|
3411
|
-
case
|
3436
|
+
case 16:
|
3412
3437
|
inx = _f.sent();
|
3413
3438
|
instructions.push(inx);
|
3414
3439
|
if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
|
3415
3440
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
|
3416
3441
|
instructions.push(closeWsolATAIns);
|
3417
3442
|
}
|
3418
|
-
return [3,
|
3419
|
-
case
|
3443
|
+
return [3, 18];
|
3444
|
+
case 17:
|
3420
3445
|
err_4 = _f.sent();
|
3421
3446
|
console.error("perpClient Swap error:: ", err_4);
|
3422
3447
|
throw err_4;
|
3423
|
-
case
|
3448
|
+
case 18: return [2, {
|
3424
3449
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3425
3450
|
additionalSigners: additionalSigners
|
3426
3451
|
}];
|
@@ -3514,7 +3539,7 @@ var PerpetualsClient = (function () {
|
|
3514
3539
|
if (!collateralCustodyConfig || !targetCustodyConfig) {
|
3515
3540
|
throw "payTokenCustody not found";
|
3516
3541
|
}
|
3517
|
-
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
|
3542
|
+
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3518
3543
|
preInstructions = [];
|
3519
3544
|
instructions = [];
|
3520
3545
|
postInstructions = [];
|
@@ -3584,6 +3609,7 @@ var PerpetualsClient = (function () {
|
|
3584
3609
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3585
3610
|
program: this.programId,
|
3586
3611
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3612
|
+
fundingMint: collateralCustodyConfig.mintKey
|
3587
3613
|
})
|
3588
3614
|
.instruction()];
|
3589
3615
|
case 7:
|
@@ -3653,7 +3679,7 @@ var PerpetualsClient = (function () {
|
|
3653
3679
|
];
|
3654
3680
|
return [3, 6];
|
3655
3681
|
case 3:
|
3656
|
-
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
3682
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true, poolConfigSwap.getTokenFromSymbol(inputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3657
3683
|
if (!!skipBalanceChecks) return [3, 6];
|
3658
3684
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3659
3685
|
case 4:
|
@@ -3669,11 +3695,11 @@ var PerpetualsClient = (function () {
|
|
3669
3695
|
}
|
3670
3696
|
_d.label = 6;
|
3671
3697
|
case 6:
|
3672
|
-
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
|
3698
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true, poolConfigPosition.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3673
3699
|
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3674
3700
|
case 7:
|
3675
3701
|
if (!(_d.sent())) {
|
3676
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey));
|
3702
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey, poolConfigPosition.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3677
3703
|
}
|
3678
3704
|
custodyAccountMetas = [];
|
3679
3705
|
custodyOracleAccountMetas = [];
|
@@ -3782,7 +3808,7 @@ var PerpetualsClient = (function () {
|
|
3782
3808
|
];
|
3783
3809
|
return [3, 5];
|
3784
3810
|
case 2:
|
3785
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
3811
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3786
3812
|
_a = createUserATA;
|
3787
3813
|
if (!_a) return [3, 4];
|
3788
3814
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -3791,7 +3817,7 @@ var PerpetualsClient = (function () {
|
|
3791
3817
|
_b.label = 4;
|
3792
3818
|
case 4:
|
3793
3819
|
if (_a) {
|
3794
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
3820
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3795
3821
|
}
|
3796
3822
|
_b.label = 5;
|
3797
3823
|
case 5:
|
@@ -3816,7 +3842,8 @@ var PerpetualsClient = (function () {
|
|
3816
3842
|
eventAuthority: this.eventAuthority.publicKey,
|
3817
3843
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3818
3844
|
program: this.programId,
|
3819
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3845
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3846
|
+
receivingMint: collateralCustodyConfig.mintKey
|
3820
3847
|
})
|
3821
3848
|
.instruction()];
|
3822
3849
|
case 6:
|
@@ -3880,19 +3907,19 @@ var PerpetualsClient = (function () {
|
|
3880
3907
|
];
|
3881
3908
|
return [3, 3];
|
3882
3909
|
case 1:
|
3883
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true);
|
3910
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true, poolConfigSwap.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3884
3911
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
3885
3912
|
case 2:
|
3886
3913
|
if (!(_b.sent())) {
|
3887
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey));
|
3914
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfigSwap.getTokenFromSymbol(outputSymbol).mintKey, poolConfigSwap.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3888
3915
|
}
|
3889
3916
|
_b.label = 3;
|
3890
3917
|
case 3:
|
3891
|
-
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
3918
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, poolConfigPosition.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3892
3919
|
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3893
3920
|
case 4:
|
3894
3921
|
if (!(_b.sent())) {
|
3895
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey));
|
3922
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfigPosition.getTokenFromSymbol(collateralSymbol).mintKey, poolConfigPosition.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3896
3923
|
}
|
3897
3924
|
marketAccount = poolConfigPosition.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3898
3925
|
positionAccount = poolConfigPosition.getPositionFromMarketPk(publicKey, marketAccount);
|
@@ -3960,7 +3987,7 @@ var PerpetualsClient = (function () {
|
|
3960
3987
|
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
3961
3988
|
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
3962
3989
|
return __awaiter(_this, void 0, void 0, function () {
|
3963
|
-
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3990
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, rebateMintAccount, instruction;
|
3964
3991
|
return __generator(this, function (_a) {
|
3965
3992
|
switch (_a.label) {
|
3966
3993
|
case 0:
|
@@ -3979,6 +4006,11 @@ var PerpetualsClient = (function () {
|
|
3979
4006
|
instructions = [];
|
3980
4007
|
postInstructions = [];
|
3981
4008
|
additionalSigners = [];
|
4009
|
+
rebateMintAccount = {
|
4010
|
+
pubkey: collateralCustodyConfig.mintKey,
|
4011
|
+
isSigner: false,
|
4012
|
+
isWritable: false
|
4013
|
+
};
|
3982
4014
|
return [4, this.program.methods
|
3983
4015
|
.increaseSize({
|
3984
4016
|
priceWithSlippage: priceWithSlippage,
|
@@ -4002,7 +4034,7 @@ var PerpetualsClient = (function () {
|
|
4002
4034
|
program: this.programId,
|
4003
4035
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4004
4036
|
})
|
4005
|
-
.remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
|
4037
|
+
.remainingAccounts(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), [rebateMintAccount], false))
|
4006
4038
|
.instruction()];
|
4007
4039
|
case 1:
|
4008
4040
|
instruction = _a.sent();
|
@@ -4020,7 +4052,7 @@ var PerpetualsClient = (function () {
|
|
4020
4052
|
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
4021
4053
|
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
4022
4054
|
return __awaiter(_this, void 0, void 0, function () {
|
4023
|
-
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
4055
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, rebateMintAccount, instruction;
|
4024
4056
|
return __generator(this, function (_a) {
|
4025
4057
|
switch (_a.label) {
|
4026
4058
|
case 0:
|
@@ -4039,6 +4071,11 @@ var PerpetualsClient = (function () {
|
|
4039
4071
|
instructions = [];
|
4040
4072
|
postInstructions = [];
|
4041
4073
|
additionalSigners = [];
|
4074
|
+
rebateMintAccount = {
|
4075
|
+
pubkey: collateralCustodyConfig.mintKey,
|
4076
|
+
isSigner: false,
|
4077
|
+
isWritable: false
|
4078
|
+
};
|
4042
4079
|
return [4, this.program.methods
|
4043
4080
|
.decreaseSize({
|
4044
4081
|
priceWithSlippage: priceWithSlippage,
|
@@ -4062,7 +4099,7 @@ var PerpetualsClient = (function () {
|
|
4062
4099
|
program: this.programId,
|
4063
4100
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4064
4101
|
})
|
4065
|
-
.remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
|
4102
|
+
.remainingAccounts(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), [rebateMintAccount], false))
|
4066
4103
|
.instruction()];
|
4067
4104
|
case 1:
|
4068
4105
|
instruction = _a.sent();
|
@@ -4095,7 +4132,7 @@ var PerpetualsClient = (function () {
|
|
4095
4132
|
_f.label = 1;
|
4096
4133
|
case 1:
|
4097
4134
|
_f.trys.push([1, 10, , 11]);
|
4098
|
-
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true);
|
4135
|
+
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true, poolConfig.getTokenFromSymbol(payTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
4099
4136
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
4100
4137
|
custodyAccountMetas = [];
|
4101
4138
|
custodyOracleAccountMetas = [];
|
@@ -4191,7 +4228,9 @@ var PerpetualsClient = (function () {
|
|
4191
4228
|
eventAuthority: this.eventAuthority.publicKey,
|
4192
4229
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4193
4230
|
program: this.programId,
|
4194
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4231
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
4232
|
+
fundingMint: payTokenCustodyConfig.mintKey,
|
4233
|
+
fundingTokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
4195
4234
|
})
|
4196
4235
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4197
4236
|
.instruction()];
|
@@ -4266,7 +4305,7 @@ var PerpetualsClient = (function () {
|
|
4266
4305
|
];
|
4267
4306
|
return [3, 7];
|
4268
4307
|
case 4:
|
4269
|
-
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
4308
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true, poolConfig.getTokenFromSymbol(inputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
4270
4309
|
if (!!skipBalanceChecks) return [3, 7];
|
4271
4310
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
4272
4311
|
case 5:
|
@@ -4326,7 +4365,9 @@ var PerpetualsClient = (function () {
|
|
4326
4365
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4327
4366
|
eventAuthority: this.eventAuthority.publicKey,
|
4328
4367
|
program: this.programId,
|
4329
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4368
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
4369
|
+
fundingMint: inputCustodyConfig.mintKey,
|
4370
|
+
fundingTokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
4330
4371
|
})
|
4331
4372
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4332
4373
|
.instruction()];
|
@@ -4409,7 +4450,7 @@ var PerpetualsClient = (function () {
|
|
4409
4450
|
];
|
4410
4451
|
return [3, 5];
|
4411
4452
|
case 2:
|
4412
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true);
|
4453
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(recieveTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
4413
4454
|
_d = createUserATA;
|
4414
4455
|
if (!_d) return [3, 4];
|
4415
4456
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -4418,7 +4459,7 @@ var PerpetualsClient = (function () {
|
|
4418
4459
|
_e.label = 4;
|
4419
4460
|
case 4:
|
4420
4461
|
if (_d) {
|
4421
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey));
|
4462
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
4422
4463
|
}
|
4423
4464
|
_e.label = 5;
|
4424
4465
|
case 5: return [4, this.program.methods
|
@@ -4440,7 +4481,9 @@ var PerpetualsClient = (function () {
|
|
4440
4481
|
eventAuthority: this.eventAuthority.publicKey,
|
4441
4482
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4442
4483
|
program: this.programId,
|
4443
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4484
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
4485
|
+
receivingMint: recieveTokenCustodyConfig.mintKey,
|
4486
|
+
receivingTokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
4444
4487
|
})
|
4445
4488
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4446
4489
|
.instruction()];
|
@@ -4567,7 +4610,7 @@ var PerpetualsClient = (function () {
|
|
4567
4610
|
additionalSigners = [];
|
4568
4611
|
_a.label = 1;
|
4569
4612
|
case 1:
|
4570
|
-
_a.trys.push([1,
|
4613
|
+
_a.trys.push([1, 3, , 4]);
|
4571
4614
|
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4572
4615
|
Buffer.from("trading"),
|
4573
4616
|
nftMint.toBuffer(),
|
@@ -4576,9 +4619,7 @@ var PerpetualsClient = (function () {
|
|
4576
4619
|
Buffer.from("referral"),
|
4577
4620
|
publicKey.toBuffer(),
|
4578
4621
|
], this.programId)[0];
|
4579
|
-
|
4580
|
-
case 2:
|
4581
|
-
nftTokenAccount = _a.sent();
|
4622
|
+
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, publicKey, true);
|
4582
4623
|
flpStakeAccountMetas = [];
|
4583
4624
|
for (_i = 0, flpStakeAccounts_1 = flpStakeAccounts; _i < flpStakeAccounts_1.length; _i++) {
|
4584
4625
|
flpStakeAccountPk = flpStakeAccounts_1[_i];
|
@@ -4601,15 +4642,15 @@ var PerpetualsClient = (function () {
|
|
4601
4642
|
tradingAccount: nftTradingAccount
|
4602
4643
|
})
|
4603
4644
|
.instruction()];
|
4604
|
-
case
|
4645
|
+
case 2:
|
4605
4646
|
updateNftTradingAccountInstruction = _a.sent();
|
4606
4647
|
instructions.push(updateNftTradingAccountInstruction);
|
4607
|
-
return [3,
|
4608
|
-
case
|
4648
|
+
return [3, 4];
|
4649
|
+
case 3:
|
4609
4650
|
err_10 = _a.sent();
|
4610
4651
|
console.log("perpClient updateNftAccount error:: ", err_10);
|
4611
4652
|
throw err_10;
|
4612
|
-
case
|
4653
|
+
case 4: return [2, {
|
4613
4654
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4614
4655
|
additionalSigners: additionalSigners
|
4615
4656
|
}];
|
@@ -4782,13 +4823,11 @@ var PerpetualsClient = (function () {
|
|
4782
4823
|
additionalSigners = [];
|
4783
4824
|
_a.label = 1;
|
4784
4825
|
case 1:
|
4785
|
-
_a.trys.push([1,
|
4826
|
+
_a.trys.push([1, 3, , 4]);
|
4786
4827
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
4787
4828
|
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
4788
4829
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), owner.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
4789
|
-
|
4790
|
-
case 2:
|
4791
|
-
userLpTokenAccount = _a.sent();
|
4830
|
+
userLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, owner, true);
|
4792
4831
|
return [4, this.program.methods
|
4793
4832
|
.depositStake({
|
4794
4833
|
depositAmount: depositAmount
|
@@ -4805,18 +4844,19 @@ var PerpetualsClient = (function () {
|
|
4805
4844
|
systemProgram: web3_js_1.SystemProgram.programId,
|
4806
4845
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4807
4846
|
eventAuthority: this.eventAuthority.publicKey,
|
4808
|
-
program: this.programId
|
4847
|
+
program: this.programId,
|
4848
|
+
lpTokenMint: poolConfig.stakedLpTokenMint
|
4809
4849
|
})
|
4810
4850
|
.instruction()];
|
4811
|
-
case
|
4851
|
+
case 2:
|
4812
4852
|
depositStakeInstruction = _a.sent();
|
4813
4853
|
instructions.push(depositStakeInstruction);
|
4814
|
-
return [3,
|
4815
|
-
case
|
4854
|
+
return [3, 4];
|
4855
|
+
case 3:
|
4816
4856
|
err_14 = _a.sent();
|
4817
4857
|
console.log("perpClient depositStaking error:: ", err_14);
|
4818
4858
|
throw err_14;
|
4819
|
-
case
|
4859
|
+
case 4: return [2, {
|
4820
4860
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4821
4861
|
additionalSigners: additionalSigners
|
4822
4862
|
}];
|
@@ -5103,6 +5143,7 @@ var PerpetualsClient = (function () {
|
|
5103
5143
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5104
5144
|
eventAuthority: this.eventAuthority.publicKey,
|
5105
5145
|
program: this.program.programId,
|
5146
|
+
lpMint: poolConfig.stakedLpTokenMint
|
5106
5147
|
})
|
5107
5148
|
.instruction()];
|
5108
5149
|
case 4:
|
@@ -5140,7 +5181,7 @@ var PerpetualsClient = (function () {
|
|
5140
5181
|
_b.trys.push([1, 5, , 6]);
|
5141
5182
|
pool = poolConfig.poolAddress;
|
5142
5183
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
|
5143
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5184
|
+
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, poolConfig.getTokenFromSymbol(rewardSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5144
5185
|
_a = createUserATA;
|
5145
5186
|
if (!_a) return [3, 3];
|
5146
5187
|
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
@@ -5149,7 +5190,7 @@ var PerpetualsClient = (function () {
|
|
5149
5190
|
_b.label = 3;
|
5150
5191
|
case 3:
|
5151
5192
|
if (_a) {
|
5152
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
5193
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint, poolConfig.getTokenFromSymbol(rewardSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
5153
5194
|
}
|
5154
5195
|
tradingAccount = [];
|
5155
5196
|
if (nftTradingAccount) {
|
@@ -5182,7 +5223,8 @@ var PerpetualsClient = (function () {
|
|
5182
5223
|
systemProgram: web3_js_1.SystemProgram.programId,
|
5183
5224
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5184
5225
|
eventAuthority: this.eventAuthority.publicKey,
|
5185
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5226
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5227
|
+
receivingMint: rewardCustodyMint
|
5186
5228
|
})
|
5187
5229
|
.remainingAccounts(__spreadArray(__spreadArray([], tradingAccount, true), boostingAccount, true))
|
5188
5230
|
.instruction()];
|
@@ -5251,18 +5293,19 @@ var PerpetualsClient = (function () {
|
|
5251
5293
|
});
|
5252
5294
|
}); };
|
5253
5295
|
this.distributeReward = function (rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5254
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_22;
|
5296
|
+
var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_22;
|
5255
5297
|
return __generator(this, function (_a) {
|
5256
5298
|
switch (_a.label) {
|
5257
5299
|
case 0:
|
5258
5300
|
publicKey = this.provider.wallet.publicKey;
|
5259
|
-
|
5301
|
+
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
5302
|
+
rewardCustodyMint = rewardToken.mintKey;
|
5260
5303
|
instructions = [];
|
5261
5304
|
additionalSigners = [];
|
5262
5305
|
_a.label = 1;
|
5263
5306
|
case 1:
|
5264
5307
|
_a.trys.push([1, 3, , 4]);
|
5265
|
-
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5308
|
+
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5266
5309
|
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
5267
5310
|
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programFbnftReward.programId)[0];
|
5268
5311
|
return [4, this.programFbnftReward.methods
|
@@ -5295,12 +5338,13 @@ var PerpetualsClient = (function () {
|
|
5295
5338
|
this.collectNftReward = function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
5296
5339
|
if (createUserATA === void 0) { createUserATA = true; }
|
5297
5340
|
return __awaiter(_this, void 0, void 0, function () {
|
5298
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_23;
|
5341
|
+
var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_23;
|
5299
5342
|
return __generator(this, function (_b) {
|
5300
5343
|
switch (_b.label) {
|
5301
5344
|
case 0:
|
5302
5345
|
publicKey = this.provider.wallet.publicKey;
|
5303
|
-
|
5346
|
+
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
5347
|
+
rewardCustodyMint = rewardToken.mintKey;
|
5304
5348
|
instructions = [];
|
5305
5349
|
additionalSigners = [];
|
5306
5350
|
_b.label = 1;
|
@@ -5308,7 +5352,7 @@ var PerpetualsClient = (function () {
|
|
5308
5352
|
_b.trys.push([1, 5, , 6]);
|
5309
5353
|
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, publicKey, true);
|
5310
5354
|
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5311
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5355
|
+
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5312
5356
|
_a = createUserATA;
|
5313
5357
|
if (!_a) return [3, 3];
|
5314
5358
|
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
@@ -5317,7 +5361,7 @@ var PerpetualsClient = (function () {
|
|
5317
5361
|
_b.label = 3;
|
5318
5362
|
case 3:
|
5319
5363
|
if (_a) {
|
5320
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
5364
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
5321
5365
|
}
|
5322
5366
|
rewardRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_record"), nftMint.toBuffer()], this.programFbnftReward.programId)[0];
|
5323
5367
|
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
@@ -5358,13 +5402,14 @@ var PerpetualsClient = (function () {
|
|
5358
5402
|
this.collectAndDistributeFee = function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
5359
5403
|
if (createUserATA === void 0) { createUserATA = true; }
|
5360
5404
|
return __awaiter(_this, void 0, void 0, function () {
|
5361
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_24;
|
5405
|
+
var publicKey, rewardToken, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_24;
|
5362
5406
|
return __generator(this, function (_b) {
|
5363
5407
|
switch (_b.label) {
|
5364
5408
|
case 0:
|
5365
5409
|
publicKey = this.provider.wallet.publicKey;
|
5366
|
-
|
5367
|
-
|
5410
|
+
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
5411
|
+
rewardCustodyMint = rewardToken.mintKey;
|
5412
|
+
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardToken.mintKey); });
|
5368
5413
|
preInstructions = [];
|
5369
5414
|
instructions = [];
|
5370
5415
|
postInstructions = [];
|
@@ -5374,7 +5419,7 @@ var PerpetualsClient = (function () {
|
|
5374
5419
|
_b.trys.push([1, 5, , 6]);
|
5375
5420
|
pool = poolConfig.poolAddress;
|
5376
5421
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
|
5377
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5422
|
+
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5378
5423
|
_a = createUserATA;
|
5379
5424
|
if (!_a) return [3, 3];
|
5380
5425
|
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
@@ -5383,7 +5428,7 @@ var PerpetualsClient = (function () {
|
|
5383
5428
|
_b.label = 3;
|
5384
5429
|
case 3:
|
5385
5430
|
if (_a) {
|
5386
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
5431
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
5387
5432
|
}
|
5388
5433
|
tradingAccount = [];
|
5389
5434
|
if (nftTradingAccount) {
|
@@ -5502,19 +5547,17 @@ var PerpetualsClient = (function () {
|
|
5502
5547
|
additionalSigners = [];
|
5503
5548
|
_b.label = 1;
|
5504
5549
|
case 1:
|
5505
|
-
_b.trys.push([1,
|
5506
|
-
|
5507
|
-
case 2:
|
5508
|
-
userReceivingTokenAccount = _b.sent();
|
5550
|
+
_b.trys.push([1, 5, , 6]);
|
5551
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, positionAccount.owner, false, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5509
5552
|
_a = createUserATA;
|
5510
|
-
if (!_a) return [3,
|
5553
|
+
if (!_a) return [3, 3];
|
5511
5554
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
5512
|
-
case
|
5555
|
+
case 2:
|
5513
5556
|
_a = !(_b.sent());
|
5514
|
-
_b.label =
|
5515
|
-
case
|
5557
|
+
_b.label = 3;
|
5558
|
+
case 3:
|
5516
5559
|
if (_a) {
|
5517
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, positionAccount.owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
5560
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, positionAccount.owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
5518
5561
|
}
|
5519
5562
|
return [4, this.program.methods
|
5520
5563
|
.forceClosePosition({
|
@@ -5537,22 +5580,23 @@ var PerpetualsClient = (function () {
|
|
5537
5580
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5538
5581
|
eventAuthority: this.eventAuthority.publicKey,
|
5539
5582
|
program: this.programId,
|
5540
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5583
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5584
|
+
receivingMint: collateralCustodyConfig.mintKey
|
5541
5585
|
})
|
5542
5586
|
.instruction()];
|
5543
|
-
case
|
5587
|
+
case 4:
|
5544
5588
|
forceClosePosition = _b.sent();
|
5545
5589
|
instructions.push(forceClosePosition);
|
5546
5590
|
if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
|
5547
5591
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, positionAccount.owner, positionAccount.owner);
|
5548
5592
|
postInstructions.push(closeWsolATAIns);
|
5549
5593
|
}
|
5550
|
-
return [3,
|
5551
|
-
case
|
5594
|
+
return [3, 6];
|
5595
|
+
case 5:
|
5552
5596
|
err_26 = _b.sent();
|
5553
5597
|
console.log("perpClient forceClosePosition error:: ", err_26);
|
5554
5598
|
throw err_26;
|
5555
|
-
case
|
5599
|
+
case 6: return [2, {
|
5556
5600
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5557
5601
|
additionalSigners: additionalSigners
|
5558
5602
|
}];
|
@@ -5573,30 +5617,28 @@ var PerpetualsClient = (function () {
|
|
5573
5617
|
reserveCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey); });
|
5574
5618
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
5575
5619
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
5576
|
-
|
5577
|
-
case 1:
|
5578
|
-
userReserveTokenAccount = _c.sent();
|
5620
|
+
userReserveTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey, false, poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5579
5621
|
preInstructions = [];
|
5580
5622
|
instructions = [];
|
5581
5623
|
postInstructions = [];
|
5582
5624
|
additionalSigners = [];
|
5583
|
-
_c.label =
|
5584
|
-
case
|
5585
|
-
_c.trys.push([
|
5586
|
-
if (!(reserveSymbol == 'SOL')) return [3,
|
5625
|
+
_c.label = 1;
|
5626
|
+
case 1:
|
5627
|
+
_c.trys.push([1, 9, , 10]);
|
5628
|
+
if (!(reserveSymbol == 'SOL')) return [3, 4];
|
5587
5629
|
console.log("reserveSymbol === SOL", reserveSymbol);
|
5588
5630
|
accCreationLamports = this.minimumBalanceForRentExemptAccountLamports;
|
5589
5631
|
lamports = reserveAmount.add(new anchor_1.BN(accCreationLamports));
|
5590
|
-
if (!!skipBalanceChecks) return [3,
|
5632
|
+
if (!!skipBalanceChecks) return [3, 3];
|
5591
5633
|
_a = anchor_1.BN.bind;
|
5592
5634
|
return [4, this.provider.connection.getBalance(publicKey)];
|
5593
|
-
case
|
5635
|
+
case 2:
|
5594
5636
|
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
|
5595
5637
|
if (unWrappedSolBalance.lt(lamports)) {
|
5596
5638
|
throw "Insufficient SOL Funds";
|
5597
5639
|
}
|
5598
|
-
_c.label =
|
5599
|
-
case
|
5640
|
+
_c.label = 3;
|
5641
|
+
case 3:
|
5600
5642
|
if (!ephemeralSignerPubkey) {
|
5601
5643
|
wrappedSolAccount = new web3_js_1.Keypair();
|
5602
5644
|
additionalSigners.push(wrappedSolAccount);
|
@@ -5615,22 +5657,22 @@ var PerpetualsClient = (function () {
|
|
5615
5657
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
5616
5658
|
];
|
5617
5659
|
additionalSigners.push(wrappedSolAccount);
|
5618
|
-
return [3,
|
5619
|
-
case
|
5620
|
-
case
|
5660
|
+
return [3, 7];
|
5661
|
+
case 4: return [4, (0, utils_1.checkIfAccountExists)(userReserveTokenAccount, this.provider.connection)];
|
5662
|
+
case 5:
|
5621
5663
|
if (!(_c.sent())) {
|
5622
5664
|
throw "Insufficient Funds , token Account doesn't exist";
|
5623
5665
|
}
|
5624
|
-
if (!!skipBalanceChecks) return [3,
|
5666
|
+
if (!!skipBalanceChecks) return [3, 7];
|
5625
5667
|
_b = anchor_1.BN.bind;
|
5626
5668
|
return [4, this.provider.connection.getTokenAccountBalance(userReserveTokenAccount)];
|
5627
|
-
case
|
5669
|
+
case 6:
|
5628
5670
|
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
5629
5671
|
if (tokenAccountBalance.lt(reserveAmount)) {
|
5630
5672
|
throw "Insufficient Funds need more ".concat(reserveAmount.sub(tokenAccountBalance), " tokens");
|
5631
5673
|
}
|
5632
|
-
_c.label =
|
5633
|
-
case
|
5674
|
+
_c.label = 7;
|
5675
|
+
case 7:
|
5634
5676
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
5635
5677
|
orderAccount = poolConfig.getOrderFromMarketPk(publicKey, marketAccount);
|
5636
5678
|
return [4, this.program.methods
|
@@ -5660,18 +5702,19 @@ var PerpetualsClient = (function () {
|
|
5660
5702
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5661
5703
|
eventAuthority: this.eventAuthority.publicKey,
|
5662
5704
|
program: this.programId,
|
5663
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5705
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5706
|
+
fundingMint: reserveCustodyConfig.mintKey
|
5664
5707
|
})
|
5665
5708
|
.instruction()];
|
5666
|
-
case
|
5709
|
+
case 8:
|
5667
5710
|
placeLimitOrder = _c.sent();
|
5668
5711
|
instructions.push(placeLimitOrder);
|
5669
|
-
return [3,
|
5670
|
-
case
|
5712
|
+
return [3, 10];
|
5713
|
+
case 9:
|
5671
5714
|
err_27 = _c.sent();
|
5672
5715
|
console.log("perpClient placeLimitOrder error:: ", err_27);
|
5673
5716
|
throw err_27;
|
5674
|
-
case
|
5717
|
+
case 10: return [2, {
|
5675
5718
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5676
5719
|
additionalSigners: additionalSigners
|
5677
5720
|
}];
|
@@ -5720,7 +5763,7 @@ var PerpetualsClient = (function () {
|
|
5720
5763
|
];
|
5721
5764
|
return [3, 5];
|
5722
5765
|
case 2:
|
5723
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey, true);
|
5766
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5724
5767
|
_a = createUserATA;
|
5725
5768
|
if (!_a) return [3, 4];
|
5726
5769
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -5729,7 +5772,7 @@ var PerpetualsClient = (function () {
|
|
5729
5772
|
_b.label = 4;
|
5730
5773
|
case 4:
|
5731
5774
|
if (_a) {
|
5732
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(reserveSymbol).mintKey));
|
5775
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
5733
5776
|
}
|
5734
5777
|
_b.label = 5;
|
5735
5778
|
case 5:
|
@@ -5763,6 +5806,7 @@ var PerpetualsClient = (function () {
|
|
5763
5806
|
eventAuthority: this.eventAuthority.publicKey,
|
5764
5807
|
program: this.programId,
|
5765
5808
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5809
|
+
receivingMint: reserveCustodyConfig.mintKey
|
5766
5810
|
})
|
5767
5811
|
.instruction()];
|
5768
5812
|
case 6:
|
@@ -6104,7 +6148,7 @@ var PerpetualsClient = (function () {
|
|
6104
6148
|
if (!false) return [3, 2];
|
6105
6149
|
return [3, 7];
|
6106
6150
|
case 2:
|
6107
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(receivingSymbol).mintKey, owner, true);
|
6151
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(receivingSymbol).mintKey, owner, true, poolConfig.getTokenFromSymbol(receivingSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
6108
6152
|
_a = createUserATA;
|
6109
6153
|
if (!_a) return [3, 4];
|
6110
6154
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -6113,9 +6157,9 @@ var PerpetualsClient = (function () {
|
|
6113
6157
|
_d.label = 4;
|
6114
6158
|
case 4:
|
6115
6159
|
if (_a) {
|
6116
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
|
6160
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey, poolConfig.getTokenFromSymbol(receivingSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
6117
6161
|
}
|
6118
|
-
userReceivingTokenAccountCollateral = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, owner, true);
|
6162
|
+
userReceivingTokenAccountCollateral = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, owner, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
6119
6163
|
_b = createUserATA;
|
6120
6164
|
if (!_b) return [3, 6];
|
6121
6165
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
|
@@ -6124,7 +6168,7 @@ var PerpetualsClient = (function () {
|
|
6124
6168
|
_d.label = 6;
|
6125
6169
|
case 6:
|
6126
6170
|
if (_b) {
|
6127
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
6171
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
6128
6172
|
}
|
6129
6173
|
_d.label = 7;
|
6130
6174
|
case 7:
|
@@ -6168,10 +6212,13 @@ var PerpetualsClient = (function () {
|
|
6168
6212
|
dispensingCustody: receivingCustodyConfig.custodyAccount,
|
6169
6213
|
dispensingOracleAccount: this.useExtOracleAccount ? receivingCustodyConfig.extOracleAccount : receivingCustodyConfig.intOracleAccount,
|
6170
6214
|
dispensingCustodyTokenAccount: receivingCustodyConfig.tokenAccount,
|
6171
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6172
6215
|
eventAuthority: this.eventAuthority.publicKey,
|
6173
6216
|
program: this.programId,
|
6174
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6217
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6218
|
+
receivingMint: receivingCustodyConfig.mintKey,
|
6219
|
+
receivingTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6220
|
+
collateralMint: collateralCustodyConfig.mintKey,
|
6221
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
6175
6222
|
})
|
6176
6223
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
6177
6224
|
.instruction()];
|
@@ -6213,7 +6260,7 @@ var PerpetualsClient = (function () {
|
|
6213
6260
|
if (!false) return [3, 2];
|
6214
6261
|
return [3, 5];
|
6215
6262
|
case 2:
|
6216
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, owner, true);
|
6263
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, owner, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
6217
6264
|
_a = createUserATA;
|
6218
6265
|
if (!_a) return [3, 4];
|
6219
6266
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -6222,7 +6269,7 @@ var PerpetualsClient = (function () {
|
|
6222
6269
|
_b.label = 4;
|
6223
6270
|
case 4:
|
6224
6271
|
if (_a) {
|
6225
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
6272
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
6226
6273
|
}
|
6227
6274
|
_b.label = 5;
|
6228
6275
|
case 5:
|
@@ -6250,7 +6297,8 @@ var PerpetualsClient = (function () {
|
|
6250
6297
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6251
6298
|
eventAuthority: this.eventAuthority.publicKey,
|
6252
6299
|
program: this.programId,
|
6253
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6300
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6301
|
+
receivingMint: collateralCustodyConfig.mintKey
|
6254
6302
|
})
|
6255
6303
|
.instruction()];
|
6256
6304
|
case 6:
|
@@ -6354,14 +6402,12 @@ var PerpetualsClient = (function () {
|
|
6354
6402
|
case 0:
|
6355
6403
|
publicKey = this.provider.wallet.publicKey;
|
6356
6404
|
custodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
6357
|
-
|
6358
|
-
case 1:
|
6359
|
-
receivingTokenAccount = _a.sent();
|
6405
|
+
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(rewardSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
6360
6406
|
instructions = [];
|
6361
6407
|
additionalSigners = [];
|
6362
|
-
_a.label =
|
6363
|
-
case
|
6364
|
-
_a.trys.push([
|
6408
|
+
_a.label = 1;
|
6409
|
+
case 1:
|
6410
|
+
_a.trys.push([1, 3, , 4]);
|
6365
6411
|
return [4, this.program.methods
|
6366
6412
|
.withdrawFees({})
|
6367
6413
|
.accounts({
|
@@ -6373,18 +6419,19 @@ var PerpetualsClient = (function () {
|
|
6373
6419
|
custody: custodyConfig.custodyAccount,
|
6374
6420
|
custodyTokenAccount: custodyConfig.tokenAccount,
|
6375
6421
|
receivingTokenAccount: receivingTokenAccount,
|
6376
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
6422
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6423
|
+
receivingMint: custodyConfig.mintKey
|
6377
6424
|
})
|
6378
6425
|
.instruction()];
|
6379
|
-
case
|
6426
|
+
case 2:
|
6380
6427
|
withdrawFeesIx = _a.sent();
|
6381
6428
|
instructions.push(withdrawFeesIx);
|
6382
|
-
return [3,
|
6383
|
-
case
|
6429
|
+
return [3, 4];
|
6430
|
+
case 3:
|
6384
6431
|
err_38 = _a.sent();
|
6385
6432
|
console.log("perpClient setPool error:: ", err_38);
|
6386
6433
|
throw err_38;
|
6387
|
-
case
|
6434
|
+
case 4: return [2, {
|
6388
6435
|
instructions: __spreadArray([], instructions, true),
|
6389
6436
|
additionalSigners: additionalSigners
|
6390
6437
|
}];
|
@@ -6430,10 +6477,9 @@ var PerpetualsClient = (function () {
|
|
6430
6477
|
});
|
6431
6478
|
}); };
|
6432
6479
|
this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6433
|
-
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse,
|
6434
|
-
|
6435
|
-
|
6436
|
-
switch (_g.label) {
|
6480
|
+
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, err_40;
|
6481
|
+
return __generator(this, function (_d) {
|
6482
|
+
switch (_d.label) {
|
6437
6483
|
case 0:
|
6438
6484
|
custodyAccountMetas = [];
|
6439
6485
|
custodyOracleAccountMetas = [];
|
@@ -6462,38 +6508,36 @@ var PerpetualsClient = (function () {
|
|
6462
6508
|
instructions = [];
|
6463
6509
|
additionalSigners = [];
|
6464
6510
|
custodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(tokenMint); });
|
6465
|
-
|
6511
|
+
_d.label = 1;
|
6466
6512
|
case 1:
|
6467
|
-
|
6468
|
-
|
6469
|
-
|
6470
|
-
|
6471
|
-
|
6472
|
-
|
6473
|
-
|
6474
|
-
|
6475
|
-
|
6476
|
-
|
6477
|
-
|
6478
|
-
|
6479
|
-
|
6480
|
-
|
6481
|
-
|
6482
|
-
|
6483
|
-
|
6484
|
-
|
6485
|
-
|
6486
|
-
|
6487
|
-
|
6488
|
-
case 3:
|
6489
|
-
reimburse = _g.sent();
|
6513
|
+
_d.trys.push([1, 3, , 4]);
|
6514
|
+
return [4, this.program.methods
|
6515
|
+
.reimburse({ amountIn: amountIn })
|
6516
|
+
.accounts({
|
6517
|
+
admin: this.provider.wallet.publicKey,
|
6518
|
+
multisig: poolConfig.multisig,
|
6519
|
+
fundingAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(tokenMint, this.provider.wallet.publicKey, true),
|
6520
|
+
perpetuals: poolConfig.perpetuals,
|
6521
|
+
pool: poolConfig.poolAddress,
|
6522
|
+
custody: custodyConfig.custodyAccount,
|
6523
|
+
custodyOracleAccount: this.useExtOracleAccount ? custodyConfig.extOracleAccount : custodyConfig.intOracleAccount,
|
6524
|
+
custodyTokenAccount: custodyConfig.tokenAccount,
|
6525
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6526
|
+
program: poolConfig.programId,
|
6527
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6528
|
+
fundingMint: custodyConfig.mintKey
|
6529
|
+
})
|
6530
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
6531
|
+
.instruction()];
|
6532
|
+
case 2:
|
6533
|
+
reimburse = _d.sent();
|
6490
6534
|
instructions.push(reimburse);
|
6491
|
-
return [3,
|
6492
|
-
case
|
6493
|
-
err_40 =
|
6535
|
+
return [3, 4];
|
6536
|
+
case 3:
|
6537
|
+
err_40 = _d.sent();
|
6494
6538
|
console.log("perpClient setPool error:: ", err_40);
|
6495
6539
|
throw err_40;
|
6496
|
-
case
|
6540
|
+
case 4: return [2, {
|
6497
6541
|
instructions: __spreadArray([], instructions, true),
|
6498
6542
|
additionalSigners: additionalSigners
|
6499
6543
|
}];
|
@@ -6563,7 +6607,7 @@ var PerpetualsClient = (function () {
|
|
6563
6607
|
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
6564
6608
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
6565
6609
|
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
6566
|
-
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inCustodyConfig.mintKey, publicKey, true);
|
6610
|
+
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inCustodyConfig.mintKey, publicKey, true, poolConfig.getTokenFromSymbol(inTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
6567
6611
|
custodyAccountMetas = [];
|
6568
6612
|
custodyOracleAccountMetas = [];
|
6569
6613
|
markets = [];
|
@@ -6662,7 +6706,9 @@ var PerpetualsClient = (function () {
|
|
6662
6706
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6663
6707
|
eventAuthority: this.eventAuthority.publicKey,
|
6664
6708
|
program: this.program.programId,
|
6665
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6709
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6710
|
+
fundingMint: inCustodyConfig.mintKey,
|
6711
|
+
fundingTokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
6666
6712
|
})
|
6667
6713
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
6668
6714
|
.instruction()];
|
@@ -6720,7 +6766,7 @@ var PerpetualsClient = (function () {
|
|
6720
6766
|
];
|
6721
6767
|
return [3, 4];
|
6722
6768
|
case 1:
|
6723
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(outCustodyConfig.mintKey, publicKey, true);
|
6769
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(outCustodyConfig.mintKey, publicKey, true, poolConfig.getTokenFromSymbol(outTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
6724
6770
|
_a = createUserATA;
|
6725
6771
|
if (!_a) return [3, 3];
|
6726
6772
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -6729,7 +6775,7 @@ var PerpetualsClient = (function () {
|
|
6729
6775
|
_e.label = 3;
|
6730
6776
|
case 3:
|
6731
6777
|
if (_a) {
|
6732
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
|
6778
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey, poolConfig.getTokenFromSymbol(outTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
6733
6779
|
}
|
6734
6780
|
_e.label = 4;
|
6735
6781
|
case 4:
|
@@ -6784,7 +6830,9 @@ var PerpetualsClient = (function () {
|
|
6784
6830
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6785
6831
|
eventAuthority: this.eventAuthority.publicKey,
|
6786
6832
|
program: this.program.programId,
|
6787
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6833
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6834
|
+
receivingMint: outCustodyConfig.mintKey,
|
6835
|
+
receivingTokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
6788
6836
|
})
|
6789
6837
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
6790
6838
|
.instruction()];
|
@@ -7182,18 +7230,19 @@ var PerpetualsClient = (function () {
|
|
7182
7230
|
});
|
7183
7231
|
}); };
|
7184
7232
|
this.rewardDistribution = function (counter, owner, rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7185
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, rewardRecord, distributeReward, err_50;
|
7233
|
+
var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, rewardRecord, distributeReward, err_50;
|
7186
7234
|
return __generator(this, function (_a) {
|
7187
7235
|
switch (_a.label) {
|
7188
7236
|
case 0:
|
7189
7237
|
publicKey = this.provider.wallet.publicKey;
|
7190
|
-
|
7238
|
+
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
7239
|
+
rewardCustodyMint = rewardToken.mintKey;
|
7191
7240
|
instructions = [];
|
7192
7241
|
additionalSigners = [];
|
7193
7242
|
_a.label = 1;
|
7194
7243
|
case 1:
|
7195
7244
|
_a.trys.push([1, 3, , 4]);
|
7196
|
-
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
7245
|
+
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
7197
7246
|
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programRewardDistribution.programId)[0];
|
7198
7247
|
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programRewardDistribution.programId)[0];
|
7199
7248
|
rewardRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_record"), owner.toBuffer(), rewardVault.toBuffer(), counter.toArrayLike(Buffer, 'le', 8)], this.programRewardDistribution.programId)[0];
|
@@ -7234,18 +7283,19 @@ var PerpetualsClient = (function () {
|
|
7234
7283
|
this.collectReward = function (counter, owner, rewardSymbol, poolConfig, createUserATA) {
|
7235
7284
|
if (createUserATA === void 0) { createUserATA = true; }
|
7236
7285
|
return __awaiter(_this, void 0, void 0, function () {
|
7237
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, receivingTokenAccount, _a, rewardVault, rewardTokenAccount, rewardRecord, transferAuthority, collectRaffleReward, err_51;
|
7286
|
+
var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, receivingTokenAccount, _a, rewardVault, rewardTokenAccount, rewardRecord, transferAuthority, collectRaffleReward, err_51;
|
7238
7287
|
return __generator(this, function (_b) {
|
7239
7288
|
switch (_b.label) {
|
7240
7289
|
case 0:
|
7241
7290
|
publicKey = this.provider.wallet.publicKey;
|
7242
|
-
|
7291
|
+
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
7292
|
+
rewardCustodyMint = rewardToken.mintKey;
|
7243
7293
|
instructions = [];
|
7244
7294
|
additionalSigners = [];
|
7245
7295
|
_b.label = 1;
|
7246
7296
|
case 1:
|
7247
7297
|
_b.trys.push([1, 5, , 6]);
|
7248
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
7298
|
+
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
7249
7299
|
_a = createUserATA;
|
7250
7300
|
if (!_a) return [3, 3];
|
7251
7301
|
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
@@ -7254,7 +7304,7 @@ var PerpetualsClient = (function () {
|
|
7254
7304
|
_b.label = 3;
|
7255
7305
|
case 3:
|
7256
7306
|
if (_a) {
|
7257
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
7307
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
7258
7308
|
}
|
7259
7309
|
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programRewardDistribution.programId)[0];
|
7260
7310
|
rewardTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_token_account")], this.programRewardDistribution.programId)[0];
|