flash-sdk 2.11.1 → 2.11.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/PerpetualsClient.d.ts +6 -2
- package/dist/PerpetualsClient.js +447 -132
- package/dist/PoolConfig.json +5 -5
- package/dist/idl/perp_composability.d.ts +119 -0
- package/dist/idl/perp_composability.js +119 -0
- package/dist/idl/perpetuals.d.ts +212 -0
- package/dist/idl/perpetuals.js +212 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -3140,6 +3140,133 @@ var PerpetualsClient = (function () {
|
|
3140
3140
|
});
|
3141
3141
|
});
|
3142
3142
|
};
|
3143
|
+
this.addLiquidityAndStake = function (inputSymbol, amountIn, minLpAmountOut, poolConfig, skipBalanceChecks) {
|
3144
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3145
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3146
|
+
var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, flpStakeAccount, poolStakedFlpVault, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _c, custody, _d, _e, market, instruction;
|
3147
|
+
return __generator(this, function (_f) {
|
3148
|
+
switch (_f.label) {
|
3149
|
+
case 0:
|
3150
|
+
publicKey = this.provider.wallet.publicKey;
|
3151
|
+
preInstructions = [];
|
3152
|
+
instructions = [];
|
3153
|
+
postInstructions = [];
|
3154
|
+
additionalSigners = [];
|
3155
|
+
lpTokenMint = poolConfig.lpTokenMint;
|
3156
|
+
inputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inputSymbol).mintKey); });
|
3157
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(lpTokenMint, publicKey)];
|
3158
|
+
case 1:
|
3159
|
+
lpTokenAccount = _f.sent();
|
3160
|
+
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
3161
|
+
poolStakedFlpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
3162
|
+
if (!(inputSymbol == 'SOL')) return [3, 4];
|
3163
|
+
console.log("inputSymbol === SOL", inputSymbol);
|
3164
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
3165
|
+
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
3166
|
+
case 2:
|
3167
|
+
accCreationLamports = (_f.sent());
|
3168
|
+
console.log("accCreationLamports:", accCreationLamports);
|
3169
|
+
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
3170
|
+
console.log("lamports:", lamports.toNumber());
|
3171
|
+
_a = anchor_1.BN.bind;
|
3172
|
+
return [4, this.provider.connection.getBalance(publicKey)];
|
3173
|
+
case 3:
|
3174
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
3175
|
+
if (unWrappedSolBalance.lt(lamports)) {
|
3176
|
+
throw "Insufficient SOL Funds";
|
3177
|
+
}
|
3178
|
+
preInstructions = [
|
3179
|
+
web3_js_1.SystemProgram.createAccount({
|
3180
|
+
fromPubkey: publicKey,
|
3181
|
+
newAccountPubkey: wrappedSolAccount.publicKey,
|
3182
|
+
lamports: lamports.toNumber(),
|
3183
|
+
space: 165,
|
3184
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3185
|
+
}),
|
3186
|
+
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
3187
|
+
];
|
3188
|
+
postInstructions = [
|
3189
|
+
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
3190
|
+
];
|
3191
|
+
additionalSigners.push(wrappedSolAccount);
|
3192
|
+
return [3, 7];
|
3193
|
+
case 4:
|
3194
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
3195
|
+
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3196
|
+
case 5:
|
3197
|
+
if (!(_f.sent())) {
|
3198
|
+
throw "Insufficient Funds , token Account doesn't exist";
|
3199
|
+
}
|
3200
|
+
if (!!skipBalanceChecks) return [3, 7];
|
3201
|
+
_b = anchor_1.BN.bind;
|
3202
|
+
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3203
|
+
case 6:
|
3204
|
+
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
3205
|
+
if (tokenAccountBalance.lt(amountIn)) {
|
3206
|
+
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3207
|
+
}
|
3208
|
+
_f.label = 7;
|
3209
|
+
case 7:
|
3210
|
+
custodyAccountMetas = [];
|
3211
|
+
custodyOracleAccountMetas = [];
|
3212
|
+
markets = [];
|
3213
|
+
for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
|
3214
|
+
custody = _c[_i];
|
3215
|
+
custodyAccountMetas.push({
|
3216
|
+
pubkey: custody.custodyAccount,
|
3217
|
+
isSigner: false,
|
3218
|
+
isWritable: false,
|
3219
|
+
});
|
3220
|
+
custodyOracleAccountMetas.push({
|
3221
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
3222
|
+
isSigner: false,
|
3223
|
+
isWritable: false,
|
3224
|
+
});
|
3225
|
+
}
|
3226
|
+
for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
|
3227
|
+
market = _e[_d];
|
3228
|
+
markets.push({
|
3229
|
+
pubkey: market.marketAccount,
|
3230
|
+
isSigner: false,
|
3231
|
+
isWritable: false,
|
3232
|
+
});
|
3233
|
+
}
|
3234
|
+
return [4, this.programPerpComposability.methods.addLiquidityAndStake({
|
3235
|
+
amountIn: amountIn,
|
3236
|
+
minLpAmountOut: minLpAmountOut,
|
3237
|
+
}).accounts({
|
3238
|
+
perpProgram: this.programId,
|
3239
|
+
owner: publicKey,
|
3240
|
+
feePayer: publicKey,
|
3241
|
+
fundingAccount: inputSymbol == 'SOL' ? wrappedSolAccount.publicKey : userInputTokenAccount,
|
3242
|
+
lpTokenAccount: lpTokenAccount,
|
3243
|
+
transferAuthority: poolConfig.transferAuthority,
|
3244
|
+
perpetuals: poolConfig.perpetuals,
|
3245
|
+
pool: poolConfig.poolAddress,
|
3246
|
+
custody: inputCustodyConfig.custodyAccount,
|
3247
|
+
custodyOracleAccount: this.useExtOracleAccount ? inputCustodyConfig.extOracleAccount : inputCustodyConfig.intOracleAccount,
|
3248
|
+
custodyTokenAccount: inputCustodyConfig.tokenAccount,
|
3249
|
+
lpTokenMint: lpTokenMint,
|
3250
|
+
flpStakeAccount: flpStakeAccount,
|
3251
|
+
poolStakedFlpVault: poolStakedFlpVault,
|
3252
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
3253
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3254
|
+
eventAuthority: this.eventAuthority.publicKey,
|
3255
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3256
|
+
})
|
3257
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
3258
|
+
.instruction()];
|
3259
|
+
case 8:
|
3260
|
+
instruction = _f.sent();
|
3261
|
+
instructions.push(instruction);
|
3262
|
+
return [2, {
|
3263
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3264
|
+
additionalSigners: additionalSigners
|
3265
|
+
}];
|
3266
|
+
}
|
3267
|
+
});
|
3268
|
+
});
|
3269
|
+
};
|
3143
3270
|
this.removeLiquidity = function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA) {
|
3144
3271
|
if (closeLpATA === void 0) { closeLpATA = false; }
|
3145
3272
|
if (createUserATA === void 0) { createUserATA = true; }
|
@@ -3536,7 +3663,7 @@ var PerpetualsClient = (function () {
|
|
3536
3663
|
_a.trys.push([1, 3, , 4]);
|
3537
3664
|
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
3538
3665
|
compoundingTokenMint = this.getPoolCompoundingTokenKey(poolConfig.poolName);
|
3539
|
-
compoundingVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("compounding_lp_token_account"), poolConfig.poolAddress.toBuffer(),
|
3666
|
+
compoundingVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("compounding_lp_token_account"), poolConfig.poolAddress.toBuffer(), poolConfig.lpTokenMint.toBuffer()], this.programId)[0];
|
3540
3667
|
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), compoundingTokenMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
3541
3668
|
return [4, this.program.methods
|
3542
3669
|
.initCompounding({
|
@@ -4627,27 +4754,103 @@ var PerpetualsClient = (function () {
|
|
4627
4754
|
});
|
4628
4755
|
}); };
|
4629
4756
|
this.addCompoundingLiquidity = function (amountIn, minSflpAmountOut, inTokenSymbol, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4630
|
-
var publicKey, instructions, additionalSigners, rewardCustody, inCustodyConfig, lpTokenMint, sFlpTokenMint, sflpTokenAccount, fundingAccount, compoundingVault, addCompoundingLiquidity, err_30;
|
4631
|
-
return __generator(this, function (
|
4632
|
-
switch (
|
4757
|
+
var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, sFlpTokenMint, wrappedSolAccount, lpTokenAccount, sflpTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, accCreationLamports, lamports, unWrappedSolBalance, _d, compoundingVault, addCompoundingLiquidity, err_30;
|
4758
|
+
return __generator(this, function (_e) {
|
4759
|
+
switch (_e.label) {
|
4633
4760
|
case 0:
|
4634
4761
|
publicKey = this.provider.wallet.publicKey;
|
4762
|
+
preInstructions = [];
|
4635
4763
|
instructions = [];
|
4636
4764
|
additionalSigners = [];
|
4765
|
+
postInstructions = [];
|
4637
4766
|
rewardCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardTokenMint); });
|
4638
4767
|
inCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inTokenSymbol).mintKey); });
|
4639
4768
|
lpTokenMint = poolConfig.lpTokenMint;
|
4640
4769
|
sFlpTokenMint = poolConfig.sFlpTokenMint;
|
4641
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(
|
4770
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.lpTokenMint, publicKey)];
|
4642
4771
|
case 1:
|
4643
|
-
|
4644
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(
|
4772
|
+
lpTokenAccount = _e.sent();
|
4773
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(sFlpTokenMint, publicKey)];
|
4645
4774
|
case 2:
|
4646
|
-
|
4647
|
-
|
4648
|
-
_a.label = 3;
|
4775
|
+
sflpTokenAccount = _e.sent();
|
4776
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(inCustodyConfig.mintKey, publicKey)];
|
4649
4777
|
case 3:
|
4650
|
-
|
4778
|
+
fundingAccount = _e.sent();
|
4779
|
+
custodyAccountMetas = [];
|
4780
|
+
custodyOracleAccountMetas = [];
|
4781
|
+
markets = [];
|
4782
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
4783
|
+
custody = _a[_i];
|
4784
|
+
custodyAccountMetas.push({
|
4785
|
+
pubkey: custody.custodyAccount,
|
4786
|
+
isSigner: false,
|
4787
|
+
isWritable: false,
|
4788
|
+
});
|
4789
|
+
custodyOracleAccountMetas.push({
|
4790
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
4791
|
+
isSigner: false,
|
4792
|
+
isWritable: false,
|
4793
|
+
});
|
4794
|
+
}
|
4795
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
4796
|
+
market = _c[_b];
|
4797
|
+
markets.push({
|
4798
|
+
pubkey: market.marketAccount,
|
4799
|
+
isSigner: false,
|
4800
|
+
isWritable: false,
|
4801
|
+
});
|
4802
|
+
}
|
4803
|
+
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
4804
|
+
case 4:
|
4805
|
+
if (!(_e.sent())) {
|
4806
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.lpTokenMint));
|
4807
|
+
}
|
4808
|
+
return [4, (0, utils_1.checkIfAccountExists)(sflpTokenAccount, this.provider.connection)];
|
4809
|
+
case 5:
|
4810
|
+
if (!(_e.sent())) {
|
4811
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, sflpTokenAccount, publicKey, poolConfig.sFlpTokenMint));
|
4812
|
+
}
|
4813
|
+
if (!(inTokenSymbol == 'SOL')) return [3, 8];
|
4814
|
+
console.log("inTokenSymbol === SOL", inTokenSymbol);
|
4815
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
4816
|
+
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
4817
|
+
case 6:
|
4818
|
+
accCreationLamports = (_e.sent());
|
4819
|
+
console.log("accCreationLamports:", accCreationLamports);
|
4820
|
+
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
4821
|
+
_d = anchor_1.BN.bind;
|
4822
|
+
return [4, this.provider.connection.getBalance(publicKey)];
|
4823
|
+
case 7:
|
4824
|
+
unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _e.sent()]))();
|
4825
|
+
if (unWrappedSolBalance.lt(lamports)) {
|
4826
|
+
throw "Insufficient SOL Funds";
|
4827
|
+
}
|
4828
|
+
preInstructions = [
|
4829
|
+
web3_js_1.SystemProgram.createAccount({
|
4830
|
+
fromPubkey: publicKey,
|
4831
|
+
newAccountPubkey: wrappedSolAccount.publicKey,
|
4832
|
+
lamports: lamports.toNumber(),
|
4833
|
+
space: 165,
|
4834
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
4835
|
+
}),
|
4836
|
+
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
4837
|
+
];
|
4838
|
+
postInstructions = [
|
4839
|
+
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
4840
|
+
];
|
4841
|
+
additionalSigners.push(wrappedSolAccount);
|
4842
|
+
return [3, 10];
|
4843
|
+
case 8: return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
|
4844
|
+
case 9:
|
4845
|
+
if (!(_e.sent())) {
|
4846
|
+
throw "Insufficient Funds , token Account doesn't exist";
|
4847
|
+
}
|
4848
|
+
_e.label = 10;
|
4849
|
+
case 10:
|
4850
|
+
compoundingVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("compounding_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
4851
|
+
_e.label = 11;
|
4852
|
+
case 11:
|
4853
|
+
_e.trys.push([11, 13, , 14]);
|
4651
4854
|
return [4, this.program.methods
|
4652
4855
|
.addCompoundingLiquidity({
|
4653
4856
|
amountIn: amountIn,
|
@@ -4673,138 +4876,250 @@ var PerpetualsClient = (function () {
|
|
4673
4876
|
program: this.program.programId,
|
4674
4877
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4675
4878
|
})
|
4879
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4676
4880
|
.instruction()];
|
4677
|
-
case
|
4678
|
-
addCompoundingLiquidity =
|
4881
|
+
case 12:
|
4882
|
+
addCompoundingLiquidity = _e.sent();
|
4679
4883
|
instructions.push(addCompoundingLiquidity);
|
4680
|
-
return [3,
|
4681
|
-
case
|
4682
|
-
err_30 =
|
4884
|
+
return [3, 14];
|
4885
|
+
case 13:
|
4886
|
+
err_30 = _e.sent();
|
4683
4887
|
console.log("perpClient addCompoundingLiquidity error:: ", err_30);
|
4684
|
-
return [3,
|
4685
|
-
case
|
4888
|
+
return [3, 14];
|
4889
|
+
case 14: return [2, {
|
4686
4890
|
instructions: __spreadArray([], instructions, true),
|
4687
4891
|
additionalSigners: additionalSigners
|
4688
4892
|
}];
|
4689
4893
|
}
|
4690
4894
|
});
|
4691
4895
|
}); };
|
4692
|
-
this.removeCompoundingLiquidity = function (sflpAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig
|
4693
|
-
|
4694
|
-
return
|
4695
|
-
|
4696
|
-
|
4697
|
-
|
4698
|
-
|
4699
|
-
|
4700
|
-
|
4701
|
-
|
4702
|
-
|
4703
|
-
|
4704
|
-
|
4705
|
-
|
4706
|
-
|
4707
|
-
|
4708
|
-
|
4709
|
-
|
4710
|
-
|
4711
|
-
|
4712
|
-
|
4713
|
-
|
4714
|
-
|
4715
|
-
.
|
4716
|
-
|
4717
|
-
|
4718
|
-
|
4719
|
-
|
4720
|
-
|
4721
|
-
|
4722
|
-
|
4723
|
-
|
4724
|
-
|
4725
|
-
|
4726
|
-
|
4727
|
-
|
4728
|
-
|
4729
|
-
|
4730
|
-
|
4731
|
-
|
4732
|
-
|
4733
|
-
|
4734
|
-
|
4735
|
-
|
4736
|
-
|
4737
|
-
|
4738
|
-
|
4739
|
-
|
4740
|
-
|
4741
|
-
|
4742
|
-
|
4743
|
-
|
4744
|
-
|
4745
|
-
|
4746
|
-
|
4747
|
-
|
4748
|
-
|
4749
|
-
|
4750
|
-
|
4751
|
-
|
4752
|
-
|
4896
|
+
this.removeCompoundingLiquidity = function (sflpAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA) {
|
4897
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
4898
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4899
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, sFlpTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, sflpTokenAccount, receivingAccount, compoundingVault, removeCompoundingLiquidity, err_31;
|
4900
|
+
return __generator(this, function (_e) {
|
4901
|
+
switch (_e.label) {
|
4902
|
+
case 0:
|
4903
|
+
publicKey = this.provider.wallet.publicKey;
|
4904
|
+
preInstructions = [];
|
4905
|
+
instructions = [];
|
4906
|
+
postInstructions = [];
|
4907
|
+
additionalSigners = [];
|
4908
|
+
rewardCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardTokenMint); });
|
4909
|
+
outCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(outTokenSymbol).mintKey); });
|
4910
|
+
lpTokenMint = poolConfig.lpTokenMint;
|
4911
|
+
sFlpTokenMint = poolConfig.sFlpTokenMint;
|
4912
|
+
if (!(outCustodyConfig.symbol == 'SOL')) return [3, 2];
|
4913
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
4914
|
+
userReceivingTokenAccount = wrappedSolAccount.publicKey;
|
4915
|
+
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
4916
|
+
case 1:
|
4917
|
+
lamports = (_e.sent());
|
4918
|
+
preInstructions = [
|
4919
|
+
web3_js_1.SystemProgram.createAccount({
|
4920
|
+
fromPubkey: publicKey,
|
4921
|
+
newAccountPubkey: wrappedSolAccount.publicKey,
|
4922
|
+
lamports: lamports,
|
4923
|
+
space: 165,
|
4924
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
4925
|
+
}),
|
4926
|
+
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
4927
|
+
];
|
4928
|
+
postInstructions = [
|
4929
|
+
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
4930
|
+
];
|
4931
|
+
additionalSigners.push(wrappedSolAccount);
|
4932
|
+
return [3, 6];
|
4933
|
+
case 2: return [4, (0, spl_token_1.getAssociatedTokenAddress)(outCustodyConfig.mintKey, publicKey)];
|
4934
|
+
case 3:
|
4935
|
+
userReceivingTokenAccount = _e.sent();
|
4936
|
+
_a = createUserATA;
|
4937
|
+
if (!_a) return [3, 5];
|
4938
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
4939
|
+
case 4:
|
4940
|
+
_a = !(_e.sent());
|
4941
|
+
_e.label = 5;
|
4942
|
+
case 5:
|
4943
|
+
if (_a) {
|
4944
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
|
4945
|
+
}
|
4946
|
+
_e.label = 6;
|
4947
|
+
case 6:
|
4948
|
+
custodyAccountMetas = [];
|
4949
|
+
custodyOracleAccountMetas = [];
|
4950
|
+
markets = [];
|
4951
|
+
for (_i = 0, _b = poolConfig.custodies; _i < _b.length; _i++) {
|
4952
|
+
custody = _b[_i];
|
4953
|
+
custodyAccountMetas.push({
|
4954
|
+
pubkey: custody.custodyAccount,
|
4955
|
+
isSigner: false,
|
4956
|
+
isWritable: false,
|
4957
|
+
});
|
4958
|
+
custodyOracleAccountMetas.push({
|
4959
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
4960
|
+
isSigner: false,
|
4961
|
+
isWritable: false,
|
4962
|
+
});
|
4963
|
+
}
|
4964
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
4965
|
+
market = _d[_c];
|
4966
|
+
markets.push({
|
4967
|
+
pubkey: market.marketAccount,
|
4968
|
+
isSigner: false,
|
4969
|
+
isWritable: false,
|
4970
|
+
});
|
4971
|
+
}
|
4972
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(sFlpTokenMint, publicKey)];
|
4973
|
+
case 7:
|
4974
|
+
sflpTokenAccount = _e.sent();
|
4975
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(outCustodyConfig.mintKey, publicKey)];
|
4976
|
+
case 8:
|
4977
|
+
receivingAccount = _e.sent();
|
4978
|
+
compoundingVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("compounding_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
4979
|
+
_e.label = 9;
|
4980
|
+
case 9:
|
4981
|
+
_e.trys.push([9, 11, , 12]);
|
4982
|
+
return [4, this.program.methods
|
4983
|
+
.removeCompoundingLiquidity({
|
4984
|
+
sflpAmountIn: sflpAmountIn,
|
4985
|
+
minAmountOut: minAmountOut
|
4986
|
+
})
|
4987
|
+
.accounts({
|
4988
|
+
owner: publicKey,
|
4989
|
+
receivingAccount: outCustodyConfig.symbol == 'SOL' ? wrappedSolAccount.publicKey : userReceivingTokenAccount,
|
4990
|
+
sflpTokenAccount: sflpTokenAccount,
|
4991
|
+
poolCompoundingFlpVault: compoundingVault,
|
4992
|
+
transferAuthority: poolConfig.transferAuthority,
|
4993
|
+
perpetuals: poolConfig.perpetuals,
|
4994
|
+
pool: poolConfig.poolAddress,
|
4995
|
+
outCustody: outCustodyConfig.custodyAccount,
|
4996
|
+
outCustodyOracleAccount: this.useExtOracleAccount ? outCustodyConfig.extOracleAccount : outCustodyConfig.intOracleAccount,
|
4997
|
+
outCustodyTokenAccount: outCustodyConfig.tokenAccount,
|
4998
|
+
rewardCustody: rewardCustody.custodyAccount,
|
4999
|
+
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
5000
|
+
lpTokenMint: lpTokenMint,
|
5001
|
+
sflpTokenMint: sFlpTokenMint,
|
5002
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5003
|
+
eventAuthority: this.eventAuthority.publicKey,
|
5004
|
+
program: this.program.programId,
|
5005
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5006
|
+
})
|
5007
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5008
|
+
.instruction()];
|
5009
|
+
case 10:
|
5010
|
+
removeCompoundingLiquidity = _e.sent();
|
5011
|
+
instructions.push(removeCompoundingLiquidity);
|
5012
|
+
return [3, 12];
|
5013
|
+
case 11:
|
5014
|
+
err_31 = _e.sent();
|
5015
|
+
console.log("perpClient removeCompoundingLiquidity error:: ", err_31);
|
5016
|
+
return [3, 12];
|
5017
|
+
case 12: return [2, {
|
5018
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5019
|
+
additionalSigners: additionalSigners
|
5020
|
+
}];
|
5021
|
+
}
|
5022
|
+
});
|
4753
5023
|
});
|
4754
|
-
}
|
4755
|
-
this.migrateStake = function (amount, rewardTokenMint, poolConfig
|
4756
|
-
|
4757
|
-
return
|
4758
|
-
|
4759
|
-
|
4760
|
-
|
4761
|
-
|
4762
|
-
|
4763
|
-
|
4764
|
-
|
4765
|
-
|
4766
|
-
|
4767
|
-
|
4768
|
-
|
4769
|
-
|
4770
|
-
|
4771
|
-
|
4772
|
-
|
4773
|
-
|
4774
|
-
|
4775
|
-
|
4776
|
-
|
4777
|
-
|
4778
|
-
|
4779
|
-
|
4780
|
-
|
4781
|
-
|
4782
|
-
|
4783
|
-
|
4784
|
-
|
4785
|
-
|
4786
|
-
|
4787
|
-
|
4788
|
-
|
4789
|
-
|
4790
|
-
|
4791
|
-
|
4792
|
-
|
4793
|
-
|
4794
|
-
|
4795
|
-
|
4796
|
-
|
4797
|
-
|
4798
|
-
|
4799
|
-
|
4800
|
-
|
4801
|
-
|
4802
|
-
|
4803
|
-
|
4804
|
-
|
4805
|
-
|
5024
|
+
};
|
5025
|
+
this.migrateStake = function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
5026
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5027
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5028
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, sFlpTokenMint, sflpTokenAccount, _a, flpStakeAccount, compoundingVault, poolStakedFlpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, migrateStake, err_32;
|
5029
|
+
return __generator(this, function (_e) {
|
5030
|
+
switch (_e.label) {
|
5031
|
+
case 0:
|
5032
|
+
publicKey = this.provider.wallet.publicKey;
|
5033
|
+
preInstructions = [];
|
5034
|
+
instructions = [];
|
5035
|
+
postInstructions = [];
|
5036
|
+
additionalSigners = [];
|
5037
|
+
rewardCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardTokenMint); });
|
5038
|
+
lpTokenMint = poolConfig.lpTokenMint;
|
5039
|
+
sFlpTokenMint = poolConfig.sFlpTokenMint;
|
5040
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(sFlpTokenMint, publicKey)];
|
5041
|
+
case 1:
|
5042
|
+
sflpTokenAccount = _e.sent();
|
5043
|
+
_a = createUserATA;
|
5044
|
+
if (!_a) return [3, 3];
|
5045
|
+
return [4, (0, utils_1.checkIfAccountExists)(sflpTokenAccount, this.provider.connection)];
|
5046
|
+
case 2:
|
5047
|
+
_a = !(_e.sent());
|
5048
|
+
_e.label = 3;
|
5049
|
+
case 3:
|
5050
|
+
if (_a) {
|
5051
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, sflpTokenAccount, publicKey, sFlpTokenMint));
|
5052
|
+
}
|
5053
|
+
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
5054
|
+
compoundingVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("compounding_lp_token_account"), poolConfig.poolAddress.toBuffer(), poolConfig.lpTokenMint.toBuffer()], this.programId)[0];
|
5055
|
+
poolStakedFlpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
5056
|
+
custodyAccountMetas = [];
|
5057
|
+
custodyOracleAccountMetas = [];
|
5058
|
+
markets = [];
|
5059
|
+
for (_i = 0, _b = poolConfig.custodies; _i < _b.length; _i++) {
|
5060
|
+
custody = _b[_i];
|
5061
|
+
custodyAccountMetas.push({
|
5062
|
+
pubkey: custody.custodyAccount,
|
5063
|
+
isSigner: false,
|
5064
|
+
isWritable: false,
|
5065
|
+
});
|
5066
|
+
custodyOracleAccountMetas.push({
|
5067
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
5068
|
+
isSigner: false,
|
5069
|
+
isWritable: false,
|
5070
|
+
});
|
5071
|
+
}
|
5072
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
5073
|
+
market = _d[_c];
|
5074
|
+
markets.push({
|
5075
|
+
pubkey: market.marketAccount,
|
5076
|
+
isSigner: false,
|
5077
|
+
isWritable: false,
|
5078
|
+
});
|
5079
|
+
}
|
5080
|
+
_e.label = 4;
|
5081
|
+
case 4:
|
5082
|
+
_e.trys.push([4, 6, , 7]);
|
5083
|
+
return [4, this.program.methods
|
5084
|
+
.migrateStake({
|
5085
|
+
amount: amount
|
5086
|
+
})
|
5087
|
+
.accounts({
|
5088
|
+
owner: publicKey,
|
5089
|
+
sflpTokenAccount: sflpTokenAccount,
|
5090
|
+
transferAuthority: poolConfig.transferAuthority,
|
5091
|
+
perpetuals: poolConfig.perpetuals,
|
5092
|
+
pool: poolConfig.poolAddress,
|
5093
|
+
flpStakeAccount: flpStakeAccount,
|
5094
|
+
rewardCustody: rewardCustody.custodyAccount,
|
5095
|
+
rewardCustodyOracleAccount: rewardCustody.intOracleAccount,
|
5096
|
+
poolStakedFlpVault: poolStakedFlpVault,
|
5097
|
+
poolCompoundingFlpVault: compoundingVault,
|
5098
|
+
lpTokenMint: lpTokenMint,
|
5099
|
+
sflpTokenMint: sFlpTokenMint,
|
5100
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5101
|
+
eventAuthority: this.eventAuthority.publicKey,
|
5102
|
+
program: this.program.programId,
|
5103
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5104
|
+
})
|
5105
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5106
|
+
.instruction()];
|
5107
|
+
case 5:
|
5108
|
+
migrateStake = _e.sent();
|
5109
|
+
instructions.push(migrateStake);
|
5110
|
+
return [3, 7];
|
5111
|
+
case 6:
|
5112
|
+
err_32 = _e.sent();
|
5113
|
+
console.log("perpClient migrateStake error:: ", err_32);
|
5114
|
+
return [3, 7];
|
5115
|
+
case 7: return [2, {
|
5116
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5117
|
+
additionalSigners: additionalSigners
|
5118
|
+
}];
|
5119
|
+
}
|
5120
|
+
});
|
4806
5121
|
});
|
4807
|
-
}
|
5122
|
+
};
|
4808
5123
|
this.compoundingFee = function (rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4809
5124
|
var publicKey, instructions, additionalSigners, rewardCustody, lpTokenMint, sFlpTokenMint, compoundingVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, compoundingFee, err_33;
|
4810
5125
|
return __generator(this, function (_d) {
|