flash-sdk 2.30.2 → 2.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PerpetualsClient.d.ts +8 -0
- package/dist/PerpetualsClient.js +222 -26
- package/dist/PoolConfig.json +0 -157
- package/dist/idl/perpetuals.d.ts +504 -1
- package/dist/idl/perpetuals.js +504 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/utils/alt.d.ts +1 -0
- package/package.json +1 -1
@@ -4018,6 +4018,10 @@ export declare class PerpetualsClient {
|
|
4018
4018
|
instructions: TransactionInstruction[];
|
4019
4019
|
additionalSigners: Signer[];
|
4020
4020
|
}>;
|
4021
|
+
swapAndAddCollateral: (targetSymbol: string, inputSymbol: string, collateralSymbol: string, amountIn: BN, minCollateralAmountOut: BN, side: Side, positionPubKey: PublicKey, poolConfig: PoolConfig, skipBalanceChecks?: boolean, ephemeralSignerPubkey?: any) => Promise<{
|
4022
|
+
instructions: TransactionInstruction[];
|
4023
|
+
additionalSigners: Signer[];
|
4024
|
+
}>;
|
4021
4025
|
removeCollateral: (collateralWithFee: BN, marketSymbol: string, collateralSymbol: string, side: Side, positionPubKey: PublicKey, poolConfig: PoolConfig, createUserATA?: boolean, closeUsersWSOLATA?: boolean, ephemeralSignerPubkey?: any) => Promise<{
|
4022
4026
|
instructions: TransactionInstruction[];
|
4023
4027
|
additionalSigners: Signer[];
|
@@ -4026,6 +4030,10 @@ export declare class PerpetualsClient {
|
|
4026
4030
|
instructions: TransactionInstruction[];
|
4027
4031
|
additionalSigners: Signer[];
|
4028
4032
|
}>;
|
4033
|
+
removeCollateralAndSwap: (targetSymbol: string, collateralSymbol: string, outputSymbol: string, minSwapAmountOut: BN, collateralDelta: BN, side: Side, poolConfig: PoolConfig, ephemeralSignerPubkey?: any) => Promise<{
|
4034
|
+
instructions: TransactionInstruction[];
|
4035
|
+
additionalSigners: Signer[];
|
4036
|
+
}>;
|
4029
4037
|
increaseSize: (targetSymbol: string, collateralSymbol: string, positionPubKey: PublicKey, side: Side, poolConfig: PoolConfig, priceWithSlippage: ContractOraclePrice, sizeDelta: BN, privilege: Privilege, nftTradingAccount?: PublicKey, nftReferralAccount?: PublicKey, nftRebateTokenAccount?: PublicKey) => Promise<{
|
4030
4038
|
instructions: TransactionInstruction[];
|
4031
4039
|
additionalSigners: Signer[];
|
package/dist/PerpetualsClient.js
CHANGED
@@ -798,7 +798,7 @@ var PerpetualsClient = (function () {
|
|
798
798
|
divergenceBps = price.getDivergenceFactor(emaPrice);
|
799
799
|
}
|
800
800
|
if (divergenceBps.gte(custodyAccount.oracle.maxDivergenceBps)) {
|
801
|
-
var factorBps = (divergenceBps.mul(new anchor_1.BN(constants_1.BPS_POWER))).div(custodyAccount.oracle.maxDivergenceBps);
|
801
|
+
var factorBps = custodyAccount.oracle.maxDivergenceBps.isZero ? constants_1.BN_ZERO : (divergenceBps.mul(new anchor_1.BN(constants_1.BPS_POWER))).div(custodyAccount.oracle.maxDivergenceBps);
|
802
802
|
var confBps = (price.confidence.muln(constants_1.BPS_POWER)).div(price.price);
|
803
803
|
if (confBps.lt(custodyAccount.oracle.maxConfBps)) {
|
804
804
|
var confFactor = anchor_1.BN.min(factorBps, new anchor_1.BN(50000));
|
@@ -1285,8 +1285,7 @@ var PerpetualsClient = (function () {
|
|
1285
1285
|
newPosition.sizeUsd = positionAccount.sizeUsd.sub(positionDelta.sizeUsd);
|
1286
1286
|
newPosition.lockedUsd = positionAccount.lockedUsd.sub(positionDelta.lockedUsd);
|
1287
1287
|
newPosition.lockedAmount = positionAccount.lockedAmount.sub(positionDelta.lockedAmount);
|
1288
|
-
newPosition.
|
1289
|
-
newPosition.collateralAmount = positionAccount.collateralAmount.sub(positionDelta.collateralAmount).add(closeAmount);
|
1288
|
+
newPosition.collateralAmount = positionAccount.collateralAmount.sub(closeAmount);
|
1290
1289
|
newPosition.collateralUsd = collateralMinMaxPrice.min.getAssetAmountUsd(newPosition.collateralAmount, collateralCustodyAccount.decimals);
|
1291
1290
|
var feeUsdWithDiscount = constants_1.BN_ZERO;
|
1292
1291
|
var feeUsd = sizeDeltaUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
@@ -1303,44 +1302,34 @@ var PerpetualsClient = (function () {
|
|
1303
1302
|
var exitFee = _this.getExitFeeSync(positionAccount, targetCustodyAccount, collateralCustodyAccount, collateralPrice, collateralEmaPrice);
|
1304
1303
|
var lockAndUnsettledFeeUsd_1 = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
1305
1304
|
var pnlUsdWithFee = pnlUsd.sub(lockAndUnsettledFeeUsd_1).sub(exitFee.exitFeeUsd);
|
1306
|
-
var
|
1307
|
-
var collateralAmountRecievedUsd =
|
1308
|
-
var collateralAmountReceived = collateralMinMaxPrice.max.getTokenAmount(collateralAmountRecievedUsd, collateralCustodyAccount.decimals);
|
1309
|
-
var maxWithdrawableAmount = _this.getMaxWithdrawableAmountSync(newPosition, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig);
|
1305
|
+
var collateralAmountReceived = closeAmount;
|
1306
|
+
var collateralAmountRecievedUsd = collateralMinMaxPrice.min.getAssetAmountUsd(collateralAmountReceived, collateralCustodyAccount.decimals);
|
1310
1307
|
if (collateralAmountReceived.lt(constants_1.BN_ZERO)) {
|
1311
1308
|
collateralAmountReceived = constants_1.BN_ZERO;
|
1312
1309
|
collateralAmountRecievedUsd = constants_1.BN_ZERO;
|
1313
1310
|
}
|
1314
|
-
else if (collateralAmountReceived.gt(maxWithdrawableAmount)) {
|
1315
|
-
collateralAmountReceived = maxWithdrawableAmount;
|
1316
|
-
collateralAmountRecievedUsd = collateralMinMaxPrice.min.getAssetAmountUsd(maxWithdrawableAmount, collateralCustodyAccount.decimals);
|
1317
|
-
}
|
1318
|
-
if (discountBps.gt(constants_1.BN_ZERO)) {
|
1319
|
-
var discount = collateralAmountRecievedUsd.mul(discountBps).div(new anchor_1.BN(constants_1.BPS_POWER));
|
1320
|
-
collateralAmountRecievedUsd = exitFeeUsd.sub(discount);
|
1321
|
-
}
|
1322
|
-
newPosition.collateralAmount = newPosition.collateralAmount.sub(collateralAmountReceived);
|
1323
|
-
newPosition.collateralUsd = collateralMinMaxPrice.min.getAssetAmountUsd(newPosition.collateralAmount, collateralCustodyAccount.decimals);
|
1324
1311
|
var entryPrice = OraclePrice_1.OraclePrice.from({ price: newPosition.entryPrice.price, exponent: new anchor_1.BN(newPosition.entryPrice.exponent), confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
|
1325
1312
|
var finalInterestUsd = _this.getLockFeeAndUnsettledUsdForPosition(newPosition, collateralCustodyAccount, currentTimestamp);
|
1326
1313
|
var finalLiquidationPrice = _this.getLiquidationPriceSync(newPosition.collateralAmount, newPosition.sizeAmount, entryPrice, finalInterestUsd, marketCorrelation, side, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, newPosition);
|
1327
1314
|
var finalPnl = _this.getPnlSync(newPosition, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1328
1315
|
var finalPnlUsd = finalPnl.profitUsd.sub(finalPnl.lossUsd);
|
1329
|
-
var
|
1330
|
-
var finalPnlUsdWithFee = finalPnlUsd.sub(finalInterestUsd).sub(newExitFee.exitFeeUsd);
|
1331
|
-
var newLev = _this.getLeverageSync(newPosition.sizeUsd, newPosition.collateralAmount, collateralMinMaxPrice.min, collateralCustodyAccount.decimals, finalPnlUsdWithFee);
|
1316
|
+
var newLev = _this.getLeverageSync(newPosition.sizeUsd, newPosition.collateralAmount, collateralMinMaxPrice.min, collateralCustodyAccount.decimals, constants_1.BN_ZERO);
|
1332
1317
|
return {
|
1333
1318
|
newSizeUsd: newPosition.sizeUsd,
|
1334
|
-
feeUsd: feeUsd
|
1319
|
+
feeUsd: feeUsd,
|
1335
1320
|
feeUsdWithDiscount: feeUsdWithDiscount.add(collateralAmountRecievedUsd),
|
1336
1321
|
newLev: newLev,
|
1337
1322
|
liquidationPrice: finalLiquidationPrice,
|
1338
1323
|
collateralAmountRecieved: collateralAmountReceived,
|
1339
1324
|
newCollateralAmount: newPosition.collateralAmount,
|
1340
|
-
newPnl:
|
1325
|
+
newPnl: finalPnlUsd
|
1341
1326
|
};
|
1342
1327
|
}
|
1343
1328
|
else {
|
1329
|
+
var collateralAmountReceived = closeAmount.sub(positionDelta.collateralAmount);
|
1330
|
+
if (collateralAmountReceived.lte(constants_1.BN_ZERO)) {
|
1331
|
+
collateralAmountReceived = constants_1.BN_ZERO;
|
1332
|
+
}
|
1344
1333
|
var entryPrice = OraclePrice_1.OraclePrice.from({ price: newPosition.entryPrice.price, exponent: new anchor_1.BN(newPosition.entryPrice.exponent), confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
|
1345
1334
|
var finalInterestUsd = _this.getLockFeeAndUnsettledUsdForPosition(newPosition, collateralCustodyAccount, currentTimestamp);
|
1346
1335
|
var finalLiquidationPrice = _this.getLiquidationPriceSync(newPosition.collateralAmount, newPosition.sizeAmount, entryPrice, finalInterestUsd, marketCorrelation, side, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, newPosition);
|
@@ -1350,10 +1339,6 @@ var PerpetualsClient = (function () {
|
|
1350
1339
|
var lockFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(newPosition, collateralCustodyAccount, currentTimestamp);
|
1351
1340
|
var finalPnlUsdWithFee = finalPnlUsd.sub(lockFeeUsd).sub(exitFee.exitFeeUsd);
|
1352
1341
|
var newLev = _this.getLeverageSync(newPosition.sizeUsd, newPosition.collateralAmount, collateralMinMaxPrice.min, collateralCustodyAccount.decimals, finalPnlUsdWithFee);
|
1353
|
-
var collateralAmountReceived = newPosition.collateralAmount.sub(positionAccount.collateralAmount);
|
1354
|
-
if (collateralAmountReceived.lte(constants_1.BN_ZERO)) {
|
1355
|
-
collateralAmountReceived = constants_1.BN_ZERO;
|
1356
|
-
}
|
1357
1342
|
return {
|
1358
1343
|
newSizeUsd: newPosition.sizeUsd,
|
1359
1344
|
feeUsd: feeUsd,
|
@@ -3826,6 +3811,121 @@ var PerpetualsClient = (function () {
|
|
3826
3811
|
});
|
3827
3812
|
});
|
3828
3813
|
};
|
3814
|
+
this.swapAndAddCollateral = function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minCollateralAmountOut, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3815
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3816
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3817
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3818
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
|
3819
|
+
return __generator(this, function (_c) {
|
3820
|
+
switch (_c.label) {
|
3821
|
+
case 0:
|
3822
|
+
publicKey = this.provider.wallet.publicKey;
|
3823
|
+
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
3824
|
+
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
3825
|
+
inputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inputSymbol).mintKey); });
|
3826
|
+
if (!collateralCustodyConfig || !targetCustodyConfig || !inputCustodyConfig) {
|
3827
|
+
throw "payTokenCustody not found";
|
3828
|
+
}
|
3829
|
+
if (inputCustodyConfig.mintKey.equals(collateralCustodyConfig.mintKey)) {
|
3830
|
+
throw "Use Simple Swap";
|
3831
|
+
}
|
3832
|
+
preInstructions = [];
|
3833
|
+
instructions = [];
|
3834
|
+
postInstructions = [];
|
3835
|
+
additionalSigners = [];
|
3836
|
+
if (!(inputSymbol == 'SOL')) return [3, 3];
|
3837
|
+
console.log("inputSymbol === SOL", inputSymbol);
|
3838
|
+
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3839
|
+
console.log("lamports:", lamports.toNumber());
|
3840
|
+
if (!!skipBalanceChecks) return [3, 2];
|
3841
|
+
_a = anchor_1.BN.bind;
|
3842
|
+
return [4, this.provider.connection.getBalance(publicKey)];
|
3843
|
+
case 1:
|
3844
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
|
3845
|
+
if (unWrappedSolBalance.lt(lamports)) {
|
3846
|
+
throw "Insufficient SOL Funds";
|
3847
|
+
}
|
3848
|
+
_c.label = 2;
|
3849
|
+
case 2:
|
3850
|
+
if (!ephemeralSignerPubkey) {
|
3851
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
3852
|
+
additionalSigners.push(wrappedSolAccount);
|
3853
|
+
}
|
3854
|
+
preInstructions = [
|
3855
|
+
web3_js_1.SystemProgram.createAccount({
|
3856
|
+
fromPubkey: publicKey,
|
3857
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
3858
|
+
lamports: lamports.toNumber(),
|
3859
|
+
space: 165,
|
3860
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3861
|
+
}),
|
3862
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
3863
|
+
];
|
3864
|
+
postInstructions = [
|
3865
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3866
|
+
];
|
3867
|
+
return [3, 6];
|
3868
|
+
case 3:
|
3869
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
3870
|
+
if (!!skipBalanceChecks) return [3, 6];
|
3871
|
+
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3872
|
+
case 4:
|
3873
|
+
if (!(_c.sent())) {
|
3874
|
+
throw "Insufficient Funds , token Account doesn't exist";
|
3875
|
+
}
|
3876
|
+
_b = anchor_1.BN.bind;
|
3877
|
+
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3878
|
+
case 5:
|
3879
|
+
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
3880
|
+
if (tokenAccountBalance.lt(amountIn)) {
|
3881
|
+
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3882
|
+
}
|
3883
|
+
_c.label = 6;
|
3884
|
+
case 6:
|
3885
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
|
3886
|
+
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3887
|
+
case 7:
|
3888
|
+
if (!(_c.sent())) {
|
3889
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey));
|
3890
|
+
}
|
3891
|
+
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3892
|
+
return [4, this.program.methods.swapAndAddCollateral({
|
3893
|
+
amountIn: amountIn,
|
3894
|
+
minCollateralAmountOut: minCollateralAmountOut,
|
3895
|
+
}).accounts({
|
3896
|
+
owner: publicKey,
|
3897
|
+
feePayer: publicKey,
|
3898
|
+
fundingAccount: inputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
|
3899
|
+
transferAuthority: poolConfig.transferAuthority,
|
3900
|
+
perpetuals: poolConfig.perpetuals,
|
3901
|
+
pool: poolConfig.poolAddress,
|
3902
|
+
receivingCustody: inputCustodyConfig.custodyAccount,
|
3903
|
+
receivingCustodyOracleAccount: this.useExtOracleAccount ? inputCustodyConfig.extOracleAccount : inputCustodyConfig.intOracleAccount,
|
3904
|
+
receivingCustodyTokenAccount: inputCustodyConfig.tokenAccount,
|
3905
|
+
position: positionPubKey,
|
3906
|
+
market: marketAccount,
|
3907
|
+
targetCustody: targetCustodyConfig.custodyAccount,
|
3908
|
+
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
3909
|
+
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3910
|
+
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3911
|
+
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3912
|
+
eventAuthority: this.eventAuthority.publicKey,
|
3913
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3914
|
+
program: this.programId,
|
3915
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3916
|
+
})
|
3917
|
+
.instruction()];
|
3918
|
+
case 8:
|
3919
|
+
instruction = _c.sent();
|
3920
|
+
instructions.push(instruction);
|
3921
|
+
return [2, {
|
3922
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3923
|
+
additionalSigners: additionalSigners
|
3924
|
+
}];
|
3925
|
+
}
|
3926
|
+
});
|
3927
|
+
});
|
3928
|
+
};
|
3829
3929
|
this.removeCollateral = function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
3830
3930
|
if (createUserATA === void 0) { createUserATA = true; }
|
3831
3931
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
@@ -4048,6 +4148,102 @@ var PerpetualsClient = (function () {
|
|
4048
4148
|
});
|
4049
4149
|
});
|
4050
4150
|
};
|
4151
|
+
this.removeCollateralAndSwap = function (targetSymbol, collateralSymbol, outputSymbol, minSwapAmountOut, collateralDelta, side, poolConfig, ephemeralSignerPubkey) {
|
4152
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4153
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4154
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, instruction;
|
4155
|
+
return __generator(this, function (_a) {
|
4156
|
+
switch (_a.label) {
|
4157
|
+
case 0:
|
4158
|
+
publicKey = this.provider.wallet.publicKey;
|
4159
|
+
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
4160
|
+
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
4161
|
+
outputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(outputSymbol).mintKey); });
|
4162
|
+
if (outputCustodyConfig.mintKey.equals(collateralCustodyConfig.mintKey)) {
|
4163
|
+
throw "Dont use swap, just call remove collateral";
|
4164
|
+
}
|
4165
|
+
preInstructions = [];
|
4166
|
+
instructions = [];
|
4167
|
+
postInstructions = [];
|
4168
|
+
additionalSigners = [];
|
4169
|
+
if (!(outputSymbol == 'SOL')) return [3, 1];
|
4170
|
+
console.log("outputSymbol === SOL", outputSymbol);
|
4171
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
4172
|
+
if (!ephemeralSignerPubkey) {
|
4173
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
4174
|
+
additionalSigners.push(wrappedSolAccount);
|
4175
|
+
}
|
4176
|
+
preInstructions = [
|
4177
|
+
web3_js_1.SystemProgram.createAccount({
|
4178
|
+
fromPubkey: publicKey,
|
4179
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
4180
|
+
lamports: lamports,
|
4181
|
+
space: 165,
|
4182
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
4183
|
+
}),
|
4184
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
4185
|
+
];
|
4186
|
+
postInstructions = [
|
4187
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
4188
|
+
];
|
4189
|
+
return [3, 3];
|
4190
|
+
case 1:
|
4191
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true);
|
4192
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
4193
|
+
case 2:
|
4194
|
+
if (!(_a.sent())) {
|
4195
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(outputSymbol).mintKey));
|
4196
|
+
}
|
4197
|
+
_a.label = 3;
|
4198
|
+
case 3:
|
4199
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
4200
|
+
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
4201
|
+
case 4:
|
4202
|
+
if (!(_a.sent())) {
|
4203
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
4204
|
+
}
|
4205
|
+
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
4206
|
+
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
4207
|
+
return [4, this.program.methods
|
4208
|
+
.removeCollateralAndSwap({
|
4209
|
+
collateralDelta: collateralDelta,
|
4210
|
+
minSwapAmountOut: minSwapAmountOut,
|
4211
|
+
})
|
4212
|
+
.accounts({
|
4213
|
+
owner: publicKey,
|
4214
|
+
feePayer: publicKey,
|
4215
|
+
receivingAccount: outputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
4216
|
+
collateralAccount: userCollateralTokenAccount,
|
4217
|
+
transferAuthority: poolConfig.transferAuthority,
|
4218
|
+
perpetuals: poolConfig.perpetuals,
|
4219
|
+
pool: poolConfig.poolAddress,
|
4220
|
+
position: positionAccount,
|
4221
|
+
market: marketAccount,
|
4222
|
+
targetCustody: targetCustodyConfig.custodyAccount,
|
4223
|
+
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
4224
|
+
collateralCustody: collateralCustodyConfig.custodyAccount,
|
4225
|
+
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
4226
|
+
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
4227
|
+
dispensingCustody: outputCustodyConfig.custodyAccount,
|
4228
|
+
dispensingOracleAccount: this.useExtOracleAccount ? outputCustodyConfig.extOracleAccount : outputCustodyConfig.intOracleAccount,
|
4229
|
+
dispensingCustodyTokenAccount: outputCustodyConfig.tokenAccount,
|
4230
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4231
|
+
eventAuthority: this.eventAuthority.publicKey,
|
4232
|
+
program: this.programId,
|
4233
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4234
|
+
})
|
4235
|
+
.instruction()];
|
4236
|
+
case 5:
|
4237
|
+
instruction = _a.sent();
|
4238
|
+
instructions.push(instruction);
|
4239
|
+
return [2, {
|
4240
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4241
|
+
additionalSigners: additionalSigners
|
4242
|
+
}];
|
4243
|
+
}
|
4244
|
+
});
|
4245
|
+
});
|
4246
|
+
};
|
4051
4247
|
this.increaseSize = function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount) {
|
4052
4248
|
if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
|
4053
4249
|
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
package/dist/PoolConfig.json
CHANGED
@@ -1472,123 +1472,6 @@
|
|
1472
1472
|
}
|
1473
1473
|
]
|
1474
1474
|
},
|
1475
|
-
{
|
1476
|
-
"programId": "FLASH6Lo6h3iasJKWDs2F8TkW2UKf3s15C8PMGuVfgBn",
|
1477
|
-
"perpComposibilityProgramId": "FSWAPViR8ny5K96hezav8jynVubP2dJ2L7SbKzds2hwm",
|
1478
|
-
"fbNftRewardProgramId": "FBRWDXSLysNbFQk64MQJcpkXP8e4fjezsGabV8jV7d7o",
|
1479
|
-
"cluster": "mainnet-beta",
|
1480
|
-
"poolName": "Test.1",
|
1481
|
-
"poolAddress": "8isRqdPXU5DLhitggkw6xfyPu78W83JJ5TZYfpE36Beg",
|
1482
|
-
"stakedLpTokenMint": "G79ZLZPd1wjK8dJAmGPti9D34XXo8RemnhgETFityz5",
|
1483
|
-
"compoundingTokenMint": "8arwA4hCG4Jgs7WSqoV9mv7EGuSDoxQeVZ7zLt1kPCW2",
|
1484
|
-
"stakedLpVault": "HaMspzihCtjULo7Jj2RksFDbnjU3YfoLg5biF1WCfiLM",
|
1485
|
-
"compoundingLpVault": "EcMpHGK3xQJgDDUxnicHJDAUq812bLxWtD3KH2NCrieQ",
|
1486
|
-
"metadataAccount": "F5c5aokEimuxvFUU7RwzjB2g9g95wgUqMtFdRdyti1oi",
|
1487
|
-
"lpDecimals": 6,
|
1488
|
-
"compoundingLpTokenSymbol": "FLP.7",
|
1489
|
-
"stakedLpTokenSymbol": "sFLP.7",
|
1490
|
-
"perpetuals": "7DWCtB5Z8rPiyBMKUwqyC95R9tJpbhoQhLM9LbK3Z5QZ",
|
1491
|
-
"transferAuthority": "81xGAvJ27ZeRThU2JEfKAUeT4Fx6qCCd8WHZpujZbiiG",
|
1492
|
-
"multisig": "3FqKnAQrvr6G6AqCAWKdqg9fVe6ceAk3A5Y1ibeQqV2V",
|
1493
|
-
"addressLookupTableAddresses": [
|
1494
|
-
"AUebVLw8UwN35Us2XcPQaTQejJoQ5T7ckWzxHTwN1mkM"
|
1495
|
-
],
|
1496
|
-
"backupOracle": "AjAubETeBLhebBxLcErmzbavZfqF9bCxkpRAdyJtoi9G",
|
1497
|
-
"nftCollectionAddress": "H4EQ8pcE7PQSQGG1WYW4hAA1nizU6ULYipHZcYk9b64u",
|
1498
|
-
"rewardDistributionProgram": {
|
1499
|
-
"programId": "FARNT7LL119pmy9vSkN9q1ApZESPaKHuuX5Acz1oBoME",
|
1500
|
-
"transferAuthority": "E2GZM2FQmX2uGBcBpLQB3s5UhPJvM2F8BgHEkBG45xBN",
|
1501
|
-
"rewardVault": "6sXyDryKp6hqV6E1jc7gbzTeWxTFUW1A6s39vzp55hLL",
|
1502
|
-
"rewardMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
1503
|
-
"rewardTokenAccount": "EhH4KEra2UfKdwRErjEFf2286BQ3BstKxfLiyYnF513h"
|
1504
|
-
},
|
1505
|
-
"tokens": [
|
1506
|
-
{
|
1507
|
-
"symbol": "USDC",
|
1508
|
-
"mintKey": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
1509
|
-
"decimals": 6,
|
1510
|
-
"usdPrecision": 2,
|
1511
|
-
"tokenPrecision": 4,
|
1512
|
-
"isStable": true,
|
1513
|
-
"isVirtual": false,
|
1514
|
-
"pythTicker": "Crypto.USDC/USD",
|
1515
|
-
"pythPriceId": "0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a"
|
1516
|
-
},
|
1517
|
-
{
|
1518
|
-
"symbol": "TNSR",
|
1519
|
-
"mintKey": "TNSRxcUxoT9xBG3de7PiJyTDYu7kskLqcpddxnEJAS6",
|
1520
|
-
"decimals": 9,
|
1521
|
-
"usdPrecision": 4,
|
1522
|
-
"tokenPrecision": 4,
|
1523
|
-
"isStable": false,
|
1524
|
-
"isVirtual": false,
|
1525
|
-
"pythTicker": "Crypto.TNSR/USD",
|
1526
|
-
"pythPriceId": "05ecd4597cd48fe13d6cc3596c62af4f9675aee06e2e0b94c06d8bee2b659e05"
|
1527
|
-
}
|
1528
|
-
],
|
1529
|
-
"custodies": [
|
1530
|
-
{
|
1531
|
-
"custodyId": 0,
|
1532
|
-
"custodyAccount": "8K7KATrT8wv23BDToiJo6Vw2BAnuWCRpsdPszTQcQVWG",
|
1533
|
-
"tokenAccount": "GoBRUmxBeeJhi62qc3GJSJp6eHZJS2N2muqdC427z3Lg",
|
1534
|
-
"symbol": "USDC",
|
1535
|
-
"mintKey": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
1536
|
-
"decimals": 6,
|
1537
|
-
"usdPrecision": 2,
|
1538
|
-
"tokenPrecision": 2,
|
1539
|
-
"isStable": true,
|
1540
|
-
"isVirtual": false,
|
1541
|
-
"intOracleAddress": "GCtJxWQ57B3BJUYdWrhb3TUxzeiDUx275ZCxKkTV6G3N",
|
1542
|
-
"extOracleAddress": "Dpw1EAVrSB1ibxiDQyTAW6Zip3J4Btk2x4SgApQCeFbX",
|
1543
|
-
"pythTicker": "Crypto.USDC/USD",
|
1544
|
-
"pythPriceId": "0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a"
|
1545
|
-
},
|
1546
|
-
{
|
1547
|
-
"custodyId": 1,
|
1548
|
-
"custodyAccount": "FH2PJoGUWX8FrdPZRFL6X1uu39HNCNiototRYzKoSGvT",
|
1549
|
-
"tokenAccount": "3bzDGCaqaNgH9JDECPd5DbdBkgrBT8pPpitqV1GurGsd",
|
1550
|
-
"symbol": "TNSR",
|
1551
|
-
"mintKey": "TNSRxcUxoT9xBG3de7PiJyTDYu7kskLqcpddxnEJAS6",
|
1552
|
-
"decimals": 9,
|
1553
|
-
"usdPrecision": 4,
|
1554
|
-
"tokenPrecision": 4,
|
1555
|
-
"isStable": false,
|
1556
|
-
"isVirtual": false,
|
1557
|
-
"intOracleAddress": "AH1f6CwHweibN4qybx7eu7AS1jUD2WtAG4ZXkndZKMyg",
|
1558
|
-
"extOracleAddress": "9TSGDwcPQX4JpAvZbu2Wp5b68wSYkQvHCvfeBjYcCyC",
|
1559
|
-
"pythTicker": "Crypto.TNSR/USD",
|
1560
|
-
"pythPriceId": "05ecd4597cd48fe13d6cc3596c62af4f9675aee06e2e0b94c06d8bee2b659e05"
|
1561
|
-
}
|
1562
|
-
],
|
1563
|
-
"markets": [
|
1564
|
-
{
|
1565
|
-
"marketId": 0,
|
1566
|
-
"marketAccount": "FBcbz7KLBf316xtgBsFCQ4nfa7J3Es6QXAzYdeBJJYgz",
|
1567
|
-
"pool": "8isRqdPXU5DLhitggkw6xfyPu78W83JJ5TZYfpE36Beg",
|
1568
|
-
"targetCustody": "FH2PJoGUWX8FrdPZRFL6X1uu39HNCNiototRYzKoSGvT",
|
1569
|
-
"collateralCustody": "FH2PJoGUWX8FrdPZRFL6X1uu39HNCNiototRYzKoSGvT",
|
1570
|
-
"side": "long",
|
1571
|
-
"maxLev": 10,
|
1572
|
-
"targetCustodyId": 1,
|
1573
|
-
"collateralCustodyId": 1,
|
1574
|
-
"targetMint": "TNSRxcUxoT9xBG3de7PiJyTDYu7kskLqcpddxnEJAS6",
|
1575
|
-
"collateralMint": "TNSRxcUxoT9xBG3de7PiJyTDYu7kskLqcpddxnEJAS6"
|
1576
|
-
},
|
1577
|
-
{
|
1578
|
-
"marketId": 1,
|
1579
|
-
"marketAccount": "AsohBEPcsY6tyUnZWiyFDAMPZgRkboD61ZjTKnCuxXBc",
|
1580
|
-
"pool": "8isRqdPXU5DLhitggkw6xfyPu78W83JJ5TZYfpE36Beg",
|
1581
|
-
"targetCustody": "FH2PJoGUWX8FrdPZRFL6X1uu39HNCNiototRYzKoSGvT",
|
1582
|
-
"collateralCustody": "8K7KATrT8wv23BDToiJo6Vw2BAnuWCRpsdPszTQcQVWG",
|
1583
|
-
"side": "short",
|
1584
|
-
"maxLev": 10,
|
1585
|
-
"targetCustodyId": 1,
|
1586
|
-
"collateralCustodyId": 0,
|
1587
|
-
"targetMint": "TNSRxcUxoT9xBG3de7PiJyTDYu7kskLqcpddxnEJAS6",
|
1588
|
-
"collateralMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
|
1589
|
-
}
|
1590
|
-
]
|
1591
|
-
},
|
1592
1475
|
{
|
1593
1476
|
"programId": "FLASH6Lo6h3iasJKWDs2F8TkW2UKf3s15C8PMGuVfgBn",
|
1594
1477
|
"perpComposibilityProgramId": "FSWAPViR8ny5K96hezav8jynVubP2dJ2L7SbKzds2hwm",
|
@@ -1791,17 +1674,6 @@
|
|
1791
1674
|
"isVirtual": false,
|
1792
1675
|
"pythTicker": "Crypto.ETH/USD",
|
1793
1676
|
"pythPriceId": "0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace"
|
1794
|
-
},
|
1795
|
-
{
|
1796
|
-
"symbol": "JitoSOL",
|
1797
|
-
"mintKey": "jtoSPya9XS5ESevDF1wTVsaJTGXG2Zi7PoNhZuNsaEg",
|
1798
|
-
"decimals": 9,
|
1799
|
-
"usdPrecision": 2,
|
1800
|
-
"tokenPrecision": 4,
|
1801
|
-
"isStable": false,
|
1802
|
-
"isVirtual": false,
|
1803
|
-
"pythTicker": "Crypto.JITOSOL/USD",
|
1804
|
-
"pythPriceId": "67be9f519b95cf24338801051f9a808eff0a578ccb388db73b7f6fe1de019ffb"
|
1805
1677
|
}
|
1806
1678
|
],
|
1807
1679
|
"custodies": [
|
@@ -1868,22 +1740,6 @@
|
|
1868
1740
|
"extOracleAddress": "42amVS4KgzR9rA28tkVYqVXjq9Qa8dcZQMbH5EYFX6XC",
|
1869
1741
|
"pythTicker": "Crypto.ETH/USD",
|
1870
1742
|
"pythPriceId": "0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace"
|
1871
|
-
},
|
1872
|
-
{
|
1873
|
-
"custodyId": 4,
|
1874
|
-
"custodyAccount": "ATbBmmYoe8boViFtxYV2QLkX6b194sHMG54gFu9pNCWa",
|
1875
|
-
"tokenAccount": "FuDjFggDYszQgBb2CT4iwy5XKcqPRfcAs6qmNNjC8Uxd",
|
1876
|
-
"symbol": "JitoSOL",
|
1877
|
-
"mintKey": "jtoSPya9XS5ESevDF1wTVsaJTGXG2Zi7PoNhZuNsaEg",
|
1878
|
-
"decimals": 9,
|
1879
|
-
"usdPrecision": 2,
|
1880
|
-
"tokenPrecision": 4,
|
1881
|
-
"isStable": false,
|
1882
|
-
"isVirtual": false,
|
1883
|
-
"intOracleAddress": "CvoTpWoqprBrzApWq5PQyxaj3neyYEMchSm1AVi43FrD",
|
1884
|
-
"extOracleAddress": "AxaxyeDT8JnWERSaTKvFXvPKkEdxnamKSqpWbsSjYg1g",
|
1885
|
-
"pythTicker": "Crypto.JITOSOL/USD",
|
1886
|
-
"pythPriceId": "67be9f519b95cf24338801051f9a808eff0a578ccb388db73b7f6fe1de019ffb"
|
1887
1743
|
}
|
1888
1744
|
],
|
1889
1745
|
"markets": [
|
@@ -1964,19 +1820,6 @@
|
|
1964
1820
|
"collateralCustodyId": 0,
|
1965
1821
|
"targetMint": "BA17bkYW78GvnirtgRHcceQxZdwkhpzbvrwDU6voUXRz",
|
1966
1822
|
"collateralMint": "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr"
|
1967
|
-
},
|
1968
|
-
{
|
1969
|
-
"marketId": 6,
|
1970
|
-
"marketAccount": "BWhe2aFnpcmtLKVPWCgxeUuyKCUFKVMicnXVYK8iYyEz",
|
1971
|
-
"pool": "7jA4ZSGwaBxXk5EmPKDCSc5RtZNHxyoxy22iQt3D2mH9",
|
1972
|
-
"targetCustody": "8BHHyTJKvZXQkjCeigdkH7hAFcnfX5ecXwysjLnG18FT",
|
1973
|
-
"collateralCustody": "ATbBmmYoe8boViFtxYV2QLkX6b194sHMG54gFu9pNCWa",
|
1974
|
-
"side": "long",
|
1975
|
-
"maxLev": 100,
|
1976
|
-
"targetCustodyId": 1,
|
1977
|
-
"collateralCustodyId": 4,
|
1978
|
-
"targetMint": "So11111111111111111111111111111111111111112",
|
1979
|
-
"collateralMint": "jtoSPya9XS5ESevDF1wTVsaJTGXG2Zi7PoNhZuNsaEg"
|
1980
1823
|
}
|
1981
1824
|
]
|
1982
1825
|
},
|