flash-sdk 1.0.14 → 1.0.16
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/lib/PerpetualsClient.d.ts +9 -3
- package/lib/PerpetualsClient.js +196 -136
- package/lib/PoolConfig.json +7 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/PerpetualsClient.ts +161 -77
- package/src/PoolConfig.json +7 -0
- package/src/PoolConfig.ts +6 -6
- package/lib/client/src/target/types/limit_order_cpi.d.ts +0 -130
- package/lib/client/src/target/types/limit_order_cpi.js +0 -132
- package/lib/client/src/target/types/perpetuals.d.ts +0 -3539
- package/lib/client/src/target/types/perpetuals.d.ts.map +0 -1
- package/lib/client/src/target/types/perpetuals.js +0 -3541
- package/lib/client/src/target/types/perpetuals.js.map +0 -1
- package/lib/target/types/perpetuals.d.ts +0 -3538
- package/lib/target/types/perpetuals.d.ts.map +0 -1
- package/lib/target/types/perpetuals.js +0 -3540
- package/lib/target/types/perpetuals.js.map +0 -1
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Program, AnchorProvider, BN } from "@coral-xyz/anchor";
|
2
|
-
import { PublicKey, TransactionInstruction, Commitment } from "@solana/web3.js";
|
2
|
+
import { PublicKey, TransactionInstruction, Commitment, Signer } from "@solana/web3.js";
|
3
3
|
import { PoolAccount } from "./PoolAccount";
|
4
4
|
import { AumCalcMode, BorrowRateParams, Fees, OracleParams, Permissions, Position, PositionSide, PricingParams, Side, TokenRatios } from "./types";
|
5
5
|
import { OraclePrice } from "./OraclePrice";
|
@@ -1949,8 +1949,14 @@ export declare class PerpetualsClient {
|
|
1949
1949
|
getAumView: (poolName: string) => Promise<any>;
|
1950
1950
|
getAumTrx: (poolName: string) => Promise<string>;
|
1951
1951
|
getAumSdk: (poolAccount: PoolAccount, token_prices: OraclePrice[], token_ema_prices: OraclePrice[], custodies: CustodyAccount[], aum_calc_mode: AumCalcMode, currentTime: BN) => BN;
|
1952
|
-
openPosition: (payTokenSymbol: string, priceAfterSlippage: BN,
|
1953
|
-
|
1952
|
+
openPosition: (payTokenSymbol: string, priceAfterSlippage: BN, collateralWithfee: BN, fee: BN, size: BN, side: Side, poolConfig: PoolConfig, createUserWSOLATA?: boolean, skipBalanceChecks?: boolean) => Promise<{
|
1953
|
+
instructions: TransactionInstruction[];
|
1954
|
+
additionalSigners: Signer[];
|
1955
|
+
}>;
|
1956
|
+
closePosition: (receivingTokenSymbol: string, priceAfterSlippage: BN, side: Side, poolConfig: PoolConfig, createUserATA?: boolean, closeUsersWSOLATA?: boolean) => Promise<{
|
1957
|
+
instructions: TransactionInstruction[];
|
1958
|
+
additionalSigners: Signer[];
|
1959
|
+
}>;
|
1954
1960
|
swap: (poolReceivingTokenSymbol: string, poolDispensingTokenSymbol: string, amountIn: BN, minAmountOut: BN, poolConfig: PoolConfig, unWrapSol?: boolean) => Promise<TransactionInstruction[]>;
|
1955
1961
|
addLiquidity: (payTokenSymbol: string, tokenAmountIn: BN, minLpAmountOut: BN, poolConfig: PoolConfig) => Promise<TransactionInstruction[]>;
|
1956
1962
|
removeLiquidity: (recieveTokenSymbol: string, liquidityAmountIn: BN, minTokenAmountOut: BN, poolConfig: PoolConfig, closeLpATA?: boolean) => Promise<TransactionInstruction[]>;
|
package/lib/PerpetualsClient.js
CHANGED
@@ -1036,91 +1036,110 @@ var PerpetualsClient = /** @class */ (function () {
|
|
1036
1036
|
// TODO: handle SOL wrapping to WSOL and create a ATA - DONE
|
1037
1037
|
// TODO: Balance checks - DONE
|
1038
1038
|
// TODO: ATA check - else create - DONE
|
1039
|
-
//
|
1040
|
-
|
1041
|
-
) {
|
1039
|
+
// Create WSOL Token account and not ATA and close it in end
|
1040
|
+
// TODO: close other Accounts - NOT NEEDED
|
1041
|
+
this.openPosition = function (payTokenSymbol, priceAfterSlippage, collateralWithfee, fee, size, side, poolConfig, createUserWSOLATA, skipBalanceChecks) {
|
1042
1042
|
if (createUserWSOLATA === void 0) { createUserWSOLATA = true; }
|
1043
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
1043
1044
|
return __awaiter(_this, void 0, void 0, function () {
|
1044
|
-
var publicKey, payTokenCustody, userCustodyTokenAccount,
|
1045
|
-
return __generator(this, function (
|
1046
|
-
switch (
|
1045
|
+
var publicKey, payTokenCustody, userCustodyTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, tokenAccountBalance, _a, positionAccount, params, instruction, error_2;
|
1046
|
+
return __generator(this, function (_b) {
|
1047
|
+
switch (_b.label) {
|
1047
1048
|
case 0:
|
1048
1049
|
console.log("open position :::", payTokenSymbol, poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey.toBase58());
|
1049
1050
|
publicKey = this.provider.wallet.publicKey;
|
1050
1051
|
payTokenCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey); });
|
1051
1052
|
return [4 /*yield*/, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey, publicKey)];
|
1052
1053
|
case 1:
|
1053
|
-
userCustodyTokenAccount =
|
1054
|
+
userCustodyTokenAccount = _b.sent();
|
1055
|
+
preInstructions = [];
|
1054
1056
|
instructions = [];
|
1055
|
-
|
1057
|
+
postInstructions = [];
|
1058
|
+
additionalSigners = [];
|
1059
|
+
_b.label = 2;
|
1056
1060
|
case 2:
|
1057
|
-
|
1058
|
-
if (!(payTokenSymbol == 'SOL' && createUserWSOLATA)) return [3 /*break*/,
|
1061
|
+
_b.trys.push([2, 10, , 11]);
|
1062
|
+
if (!(payTokenSymbol == 'SOL' && createUserWSOLATA)) return [3 /*break*/, 4];
|
1059
1063
|
console.log("payTokenSymbol === sol", payTokenSymbol);
|
1060
|
-
wsolAssociatedTokenAccount = userCustodyTokenAccount;
|
1061
|
-
|
1064
|
+
// const wsolAssociatedTokenAccount = userCustodyTokenAccount;
|
1065
|
+
// const wsolATAExist = await checkIfAccountExists(wsolAssociatedTokenAccount, this.provider.connection)
|
1066
|
+
// if (!wsolATAExist) {
|
1067
|
+
// console.log("wsol ata does not exist");
|
1068
|
+
// instructions.push(
|
1069
|
+
// createAssociatedTokenAccountInstruction(
|
1070
|
+
// publicKey,
|
1071
|
+
// wsolAssociatedTokenAccount,
|
1072
|
+
// publicKey,
|
1073
|
+
// NATIVE_MINT
|
1074
|
+
// )
|
1075
|
+
// );
|
1076
|
+
// }
|
1077
|
+
// // get balance of WSOL associated token account
|
1078
|
+
// const wsolBalance = new BN(wsolATAExist ? (await this.provider.connection.getTokenAccountBalance(wsolAssociatedTokenAccount)).value.amount : 0);
|
1079
|
+
// if (wsolBalance.lt(collateralWithfee)) {
|
1080
|
+
// console.log("WSOL balance insufficient \n so Convert SOL to WSOL");
|
1081
|
+
// let unWrappedSolBalance = new BN(await this.provider.connection.getBalance(publicKey));
|
1082
|
+
// const totalSolBal = unWrappedSolBalance.add(wsolBalance);
|
1083
|
+
// // const rentExemptSolNeedforATA = new BN(0.02 * LAMPORTS_PER_SOL);
|
1084
|
+
// // console.log("rentExemptSolNeedforATA:",rentExemptSolNeedforATA.toString())
|
1085
|
+
// //TODOD :: add(rentExemptSolNeedforATA)
|
1086
|
+
// if (totalSolBal.lt(collateralWithfee)) {
|
1087
|
+
// throw "Insufficient SOL Funds"
|
1088
|
+
// } else {
|
1089
|
+
// console.log("SOL balance sufficient so transfer from SOL to WSOL ATA")
|
1090
|
+
// }
|
1091
|
+
// let conversionAmt = collateralWithfee.sub(wsolBalance);
|
1092
|
+
// console.log("conversionAmt:",conversionAmt.toString())
|
1093
|
+
// instructions.push(
|
1094
|
+
// SystemProgram.transfer({
|
1095
|
+
// fromPubkey: publicKey,
|
1096
|
+
// toPubkey: wsolAssociatedTokenAccount,
|
1097
|
+
// lamports: conversionAmt.toNumber(), // IS IT SAFE TO PUT AS NUMBER
|
1098
|
+
// }),
|
1099
|
+
// createSyncNativeInstruction(wsolAssociatedTokenAccount)
|
1100
|
+
// );
|
1101
|
+
// }
|
1102
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
1103
|
+
return [4 /*yield*/, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
1062
1104
|
case 3:
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1105
|
+
accCreationLamports = (_b.sent());
|
1106
|
+
console.log("accCreationLamports:", accCreationLamports);
|
1107
|
+
lamports = collateralWithfee.add(new anchor_1.BN(accCreationLamports));
|
1108
|
+
preInstructions = [
|
1109
|
+
web3_js_1.SystemProgram.createAccount({
|
1110
|
+
fromPubkey: publicKey,
|
1111
|
+
newAccountPubkey: wrappedSolAccount.publicKey,
|
1112
|
+
lamports: lamports.toNumber(),
|
1113
|
+
space: 165,
|
1114
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
1115
|
+
}),
|
1116
|
+
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
1117
|
+
];
|
1118
|
+
postInstructions = [
|
1119
|
+
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
1120
|
+
];
|
1121
|
+
additionalSigners.push(wrappedSolAccount);
|
1122
|
+
return [3 /*break*/, 8];
|
1072
1123
|
case 4:
|
1073
|
-
|
1074
|
-
return [3 /*break*/, 6];
|
1075
|
-
case 5:
|
1076
|
-
_b = 0;
|
1077
|
-
_e.label = 6;
|
1078
|
-
case 6:
|
1079
|
-
wsolBalance = new (_a.apply(anchor_1.BN, [void 0, _b]))();
|
1080
|
-
if (!wsolBalance.lt(collateralWithfee)) return [3 /*break*/, 8];
|
1081
|
-
console.log("WSOL balance insufficient \n so Convert SOL to WSOL");
|
1082
|
-
_c = anchor_1.BN.bind;
|
1083
|
-
return [4 /*yield*/, this.provider.connection.getBalance(publicKey)];
|
1084
|
-
case 7:
|
1085
|
-
unWrappedSolBalance = new (_c.apply(anchor_1.BN, [void 0, _e.sent()]))();
|
1086
|
-
totalSolBal = unWrappedSolBalance.add(wsolBalance);
|
1087
|
-
// const rentExemptSolNeedforATA = new BN(0.02 * LAMPORTS_PER_SOL);
|
1088
|
-
// console.log("rentExemptSolNeedforATA:",rentExemptSolNeedforATA.toString())
|
1089
|
-
//TODOD :: add(rentExemptSolNeedforATA)
|
1090
|
-
if (totalSolBal.lt(collateralWithfee)) {
|
1091
|
-
throw "Insufficient SOL Funds";
|
1092
|
-
}
|
1093
|
-
else {
|
1094
|
-
console.log("SOL balance sufficient so transfer from SOL to WSOL ATA");
|
1095
|
-
}
|
1096
|
-
conversionAmt = collateralWithfee.sub(wsolBalance);
|
1097
|
-
console.log("conversionAmt:", conversionAmt.toString());
|
1098
|
-
instructions.push(web3_js_1.SystemProgram.transfer({
|
1099
|
-
fromPubkey: publicKey,
|
1100
|
-
toPubkey: wsolAssociatedTokenAccount,
|
1101
|
-
lamports: conversionAmt.toNumber(), // IS IT SAFE TO PUT AS NUMBER
|
1102
|
-
}), (0, spl_token_1.createSyncNativeInstruction)(wsolAssociatedTokenAccount));
|
1103
|
-
_e.label = 8;
|
1104
|
-
case 8: return [3 /*break*/, 13];
|
1105
|
-
case 9:
|
1106
|
-
if (!(createUserWSOLATA == false)) return [3 /*break*/, 10];
|
1124
|
+
if (!(createUserWSOLATA == false)) return [3 /*break*/, 5];
|
1107
1125
|
console.log("skip WSOL checks and creation ,since createUserWSOLATA == false");
|
1108
|
-
return [3 /*break*/,
|
1109
|
-
case
|
1110
|
-
case
|
1126
|
+
return [3 /*break*/, 8];
|
1127
|
+
case 5: return [4 /*yield*/, (0, utils_1.checkIfAccountExists)(userCustodyTokenAccount, this.provider.connection)];
|
1128
|
+
case 6:
|
1111
1129
|
// for other tokens check if ATA and balance
|
1112
|
-
if (!(
|
1130
|
+
if (!(_b.sent())) {
|
1113
1131
|
throw "Insufficient Funds , token Account doesn't exist";
|
1114
1132
|
}
|
1115
|
-
|
1133
|
+
if (!!skipBalanceChecks) return [3 /*break*/, 8];
|
1134
|
+
_a = anchor_1.BN.bind;
|
1116
1135
|
return [4 /*yield*/, this.provider.connection.getTokenAccountBalance(userCustodyTokenAccount)];
|
1117
|
-
case
|
1118
|
-
tokenAccountBalance = new (
|
1119
|
-
if (tokenAccountBalance.lt(
|
1120
|
-
throw "Insufficient Funds";
|
1136
|
+
case 7:
|
1137
|
+
tokenAccountBalance = new (_a.apply(anchor_1.BN, [void 0, (_b.sent()).value.amount]))();
|
1138
|
+
if (tokenAccountBalance.lt(collateralWithfee)) {
|
1139
|
+
throw "Insufficient Funds need more ".concat(collateralWithfee.sub(tokenAccountBalance), " tokens");
|
1121
1140
|
}
|
1122
|
-
|
1123
|
-
case
|
1141
|
+
_b.label = 8;
|
1142
|
+
case 8:
|
1124
1143
|
positionAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
1125
1144
|
Buffer.from("position"),
|
1126
1145
|
publicKey.toBuffer(),
|
@@ -1130,7 +1149,7 @@ var PerpetualsClient = /** @class */ (function () {
|
|
1130
1149
|
], this.programId)[0];
|
1131
1150
|
params = {
|
1132
1151
|
price: priceAfterSlippage,
|
1133
|
-
collateral:
|
1152
|
+
collateral: collateralWithfee,
|
1134
1153
|
size: size,
|
1135
1154
|
side: side,
|
1136
1155
|
};
|
@@ -1138,7 +1157,7 @@ var PerpetualsClient = /** @class */ (function () {
|
|
1138
1157
|
.openPosition(params)
|
1139
1158
|
.accounts({
|
1140
1159
|
owner: publicKey,
|
1141
|
-
fundingAccount: userCustodyTokenAccount,
|
1160
|
+
fundingAccount: payTokenSymbol == 'SOL' ? wrappedSolAccount.publicKey : userCustodyTokenAccount,
|
1142
1161
|
transferAuthority: poolConfig.transferAuthority,
|
1143
1162
|
perpetuals: poolConfig.perpetuals,
|
1144
1163
|
pool: poolConfig.poolAddress,
|
@@ -1149,15 +1168,18 @@ var PerpetualsClient = /** @class */ (function () {
|
|
1149
1168
|
systemProgram: web3_js_1.SystemProgram.programId,
|
1150
1169
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
1151
1170
|
}).instruction()];
|
1152
|
-
case
|
1153
|
-
instruction =
|
1171
|
+
case 9:
|
1172
|
+
instruction = _b.sent();
|
1154
1173
|
instructions.push(instruction);
|
1155
|
-
return [3 /*break*/,
|
1156
|
-
case
|
1157
|
-
error_2 =
|
1174
|
+
return [3 /*break*/, 11];
|
1175
|
+
case 10:
|
1176
|
+
error_2 = _b.sent();
|
1158
1177
|
console.log("perpClient openPosition error:", error_2);
|
1159
|
-
return [3 /*break*/,
|
1160
|
-
case
|
1178
|
+
return [3 /*break*/, 11];
|
1179
|
+
case 11: return [2 /*return*/, {
|
1180
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
1181
|
+
additionalSigners: additionalSigners
|
1182
|
+
}];
|
1161
1183
|
}
|
1162
1184
|
});
|
1163
1185
|
});
|
@@ -1167,68 +1189,106 @@ var PerpetualsClient = /** @class */ (function () {
|
|
1167
1189
|
// TODO: ATA check - else create - DONE
|
1168
1190
|
// TODO: for close Accounts - DONE BY ANCHOR
|
1169
1191
|
// TODO : if out token WSOL -> unwrap to SOL - DONE
|
1170
|
-
this.closePosition = function (receivingTokenSymbol, priceAfterSlippage, side, poolConfig
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
.
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1192
|
+
this.closePosition = function (receivingTokenSymbol, priceAfterSlippage, side, poolConfig, createUserATA, closeUsersWSOLATA // to get back WSOL=>SOL
|
1193
|
+
) {
|
1194
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
1195
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
1196
|
+
return __awaiter(_this, void 0, void 0, function () {
|
1197
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, receivingTokenCustody, positionAccount, params, instruction, closeWsolATAIns, error_3;
|
1198
|
+
return __generator(this, function (_b) {
|
1199
|
+
switch (_b.label) {
|
1200
|
+
case 0:
|
1201
|
+
console.log("close position :::", receivingTokenSymbol, poolConfig.getTokenFromSymbol(receivingTokenSymbol).mintKey.toBase58());
|
1202
|
+
publicKey = this.provider.wallet.publicKey;
|
1203
|
+
preInstructions = [];
|
1204
|
+
instructions = [];
|
1205
|
+
postInstructions = [];
|
1206
|
+
additionalSigners = [];
|
1207
|
+
_b.label = 1;
|
1208
|
+
case 1:
|
1209
|
+
_b.trys.push([1, 9, , 10]);
|
1210
|
+
if (!(receivingTokenSymbol == 'SOL')) return [3 /*break*/, 3];
|
1211
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
1212
|
+
userReceivingTokenAccount = wrappedSolAccount.publicKey;
|
1213
|
+
return [4 /*yield*/, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
1214
|
+
case 2:
|
1215
|
+
lamports = (_b.sent());
|
1216
|
+
preInstructions = [
|
1217
|
+
web3_js_1.SystemProgram.createAccount({
|
1218
|
+
fromPubkey: publicKey,
|
1219
|
+
newAccountPubkey: wrappedSolAccount.publicKey,
|
1220
|
+
lamports: lamports,
|
1221
|
+
space: 165,
|
1222
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
1223
|
+
}),
|
1224
|
+
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
1225
|
+
];
|
1226
|
+
postInstructions = [
|
1227
|
+
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
1228
|
+
];
|
1229
|
+
additionalSigners.push(wrappedSolAccount);
|
1230
|
+
return [3 /*break*/, 7];
|
1231
|
+
case 3: return [4 /*yield*/, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(receivingTokenSymbol).mintKey, publicKey)];
|
1232
|
+
case 4:
|
1233
|
+
userReceivingTokenAccount = _b.sent();
|
1234
|
+
_a = createUserATA;
|
1235
|
+
if (!_a) return [3 /*break*/, 6];
|
1236
|
+
return [4 /*yield*/, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
1237
|
+
case 5:
|
1238
|
+
_a = !(_b.sent());
|
1239
|
+
_b.label = 6;
|
1240
|
+
case 6:
|
1241
|
+
if (_a) {
|
1242
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(receivingTokenSymbol).mintKey));
|
1243
|
+
}
|
1244
|
+
_b.label = 7;
|
1245
|
+
case 7:
|
1246
|
+
receivingTokenCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(receivingTokenSymbol).mintKey); });
|
1247
|
+
positionAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
1248
|
+
Buffer.from("position"),
|
1249
|
+
publicKey.toBuffer(),
|
1250
|
+
poolConfig.poolAddress.toBuffer(),
|
1251
|
+
receivingTokenCustody.custodyAccount.toBuffer(),
|
1252
|
+
(0, types_1.isVariant)(side, 'long') ? Buffer.from([1]) : Buffer.from([2]),
|
1253
|
+
], this.programId)[0];
|
1254
|
+
console.log("positionAccount:", positionAccount.toBase58());
|
1255
|
+
params = {
|
1256
|
+
price: priceAfterSlippage,
|
1257
|
+
};
|
1258
|
+
return [4 /*yield*/, this.program.methods
|
1259
|
+
.closePosition(params)
|
1260
|
+
.accounts({
|
1261
|
+
owner: publicKey,
|
1262
|
+
receivingAccount: userReceivingTokenAccount,
|
1263
|
+
transferAuthority: poolConfig.transferAuthority,
|
1264
|
+
perpetuals: poolConfig.perpetuals,
|
1265
|
+
pool: poolConfig.poolAddress,
|
1266
|
+
position: positionAccount,
|
1267
|
+
custody: receivingTokenCustody.custodyAccount,
|
1268
|
+
custodyOracleAccount: receivingTokenCustody.oracleAddress,
|
1269
|
+
custodyTokenAccount: receivingTokenCustody.tokenAccount,
|
1270
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
1271
|
+
}).instruction()];
|
1272
|
+
case 8:
|
1273
|
+
instruction = _b.sent();
|
1274
|
+
instructions.push(instruction);
|
1275
|
+
if (receivingTokenSymbol == 'WSOL' && closeUsersWSOLATA) {
|
1276
|
+
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
|
1277
|
+
postInstructions.push(closeWsolATAIns);
|
1278
|
+
}
|
1279
|
+
return [3 /*break*/, 10];
|
1280
|
+
case 9:
|
1281
|
+
error_3 = _b.sent();
|
1282
|
+
console.error("perpclient closePosition error:", error_3);
|
1283
|
+
return [3 /*break*/, 10];
|
1284
|
+
case 10: return [2 /*return*/, {
|
1285
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
1286
|
+
additionalSigners: additionalSigners
|
1287
|
+
}];
|
1288
|
+
}
|
1289
|
+
});
|
1230
1290
|
});
|
1231
|
-
}
|
1291
|
+
};
|
1232
1292
|
// TODO: ATA check - else create - DONE
|
1233
1293
|
// TODO: handle SOL wrapping to WSOL and create a ATA - DONE
|
1234
1294
|
// TODO : Balance checks - NOT NEEDED
|
package/lib/PoolConfig.json
CHANGED
@@ -31,6 +31,13 @@
|
|
31
31
|
"isStable": false,
|
32
32
|
"pythTicker": "Crypto.SOL/USD"
|
33
33
|
},
|
34
|
+
{
|
35
|
+
"symbol": "WSOL",
|
36
|
+
"mintKey": "So11111111111111111111111111111111111111112",
|
37
|
+
"decimals": 9,
|
38
|
+
"isStable": false,
|
39
|
+
"pythTicker": "Crypto.SOL/USD"
|
40
|
+
},
|
34
41
|
{
|
35
42
|
"symbol": "BTC",
|
36
43
|
"mintKey": "B8DYqbh57aEPRbUq7reyueY6jaYoN75js5YsiM84tFfP",
|