flash-sdk 11.11.4-alpha.0 → 11.11.5-alpha.0
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/MarketAccount.d.ts +2 -2
- package/dist/OraclePrice.d.ts +0 -1
- package/dist/OrderAccount.d.ts +0 -1
- package/dist/PerpetualsClient.d.ts +267 -4418
- package/dist/PerpetualsClient.js +791 -677
- package/dist/PoolAccount.d.ts +0 -1
- package/dist/PoolDataClient.d.ts +0 -1
- package/dist/PositionAccount.d.ts +0 -1
- package/dist/TokenStakeAccount.d.ts +0 -1
- package/dist/TokenVaultAccount.d.ts +0 -1
- package/dist/ViewHelper.js +8 -5
- package/dist/backupOracle.js +4 -4
- package/dist/constants/index.d.ts +0 -1
- package/dist/idl/perpetuals.d.ts +26232 -13443
- package/dist/idl/perpetuals.js +0 -18151
- package/dist/idl/perpetuals.json +30940 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -2
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/generated.d.ts +2272 -0
- package/dist/types/generated.js +2 -0
- package/dist/types/index.d.ts +46 -157
- package/dist/types/index.js +35 -20
- package/dist/utils/IdlCoder.d.ts +3 -2
- package/dist/utils/IdlCoder.js +21 -9
- package/dist/utils/alt.js +5 -6
- package/dist/utils/anchorCpiEvents.d.ts +1 -2
- package/dist/utils/anchorCpiEvents.js +14 -10
- package/dist/utils/index.js +6 -6
- package/dist/utils/rpc.js +9 -9
- package/package.json +5 -5
package/dist/PerpetualsClient.js
CHANGED
|
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g =
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -68,7 +68,7 @@ var bs58_1 = require("bs58");
|
|
|
68
68
|
var PositionAccount_1 = require("./PositionAccount");
|
|
69
69
|
var types_1 = require("./types");
|
|
70
70
|
var OraclePrice_1 = require("./OraclePrice");
|
|
71
|
-
var
|
|
71
|
+
var perpetuals_json_1 = __importDefault(require("./idl/perpetuals.json"));
|
|
72
72
|
var rpc_1 = require("./utils/rpc");
|
|
73
73
|
var utils_1 = require("./utils");
|
|
74
74
|
var constants_1 = require("./constants");
|
|
@@ -262,11 +262,6 @@ var PerpetualsClient = (function () {
|
|
|
262
262
|
tokenMint,
|
|
263
263
|
]).publicKey;
|
|
264
264
|
};
|
|
265
|
-
this.getTradingAccount = function (tradingAccount) { return __awaiter(_this, void 0, void 0, function () {
|
|
266
|
-
return __generator(this, function (_a) {
|
|
267
|
-
return [2, this.program.account.trading.fetch(tradingAccount)];
|
|
268
|
-
});
|
|
269
|
-
}); };
|
|
270
265
|
this.getPosition = function (postionKey) { return __awaiter(_this, void 0, void 0, function () {
|
|
271
266
|
return __generator(this, function (_a) {
|
|
272
267
|
return [2, this.program.account.position.fetch(postionKey)];
|
|
@@ -285,7 +280,7 @@ var PerpetualsClient = (function () {
|
|
|
285
280
|
_a.trys.push([1, 3, , 4]);
|
|
286
281
|
return [4, this.program.methods
|
|
287
282
|
.getPositionData({})
|
|
288
|
-
.
|
|
283
|
+
.accountsPartial({
|
|
289
284
|
perpetuals: this.perpetuals.publicKey,
|
|
290
285
|
pool: poolConfig.poolAddress,
|
|
291
286
|
position: position.publicKey,
|
|
@@ -390,7 +385,7 @@ var PerpetualsClient = (function () {
|
|
|
390
385
|
return __generator(this, function (_a) {
|
|
391
386
|
switch (_a.label) {
|
|
392
387
|
case 0:
|
|
393
|
-
data = (0, bs58_1.encode)(
|
|
388
|
+
data = (0, bs58_1.encode)(new Uint8Array(marketKey.toBuffer()));
|
|
394
389
|
return [4, this.program.account.position.all([
|
|
395
390
|
{
|
|
396
391
|
memcmp: { bytes: data, offset: 40 }
|
|
@@ -407,7 +402,7 @@ var PerpetualsClient = (function () {
|
|
|
407
402
|
return __generator(this, function (_a) {
|
|
408
403
|
switch (_a.label) {
|
|
409
404
|
case 0:
|
|
410
|
-
data = (0, bs58_1.encode)(
|
|
405
|
+
data = (0, bs58_1.encode)(new Uint8Array(marketKey.toBuffer()));
|
|
411
406
|
return [4, this.program.account.position.all([
|
|
412
407
|
{
|
|
413
408
|
memcmp: { bytes: data, offset: 40 }
|
|
@@ -450,7 +445,7 @@ var PerpetualsClient = (function () {
|
|
|
450
445
|
collateralCustodyConfig = poolConfig.custodies.find(function (f) { return f.mintKey.equals(collateralMint); });
|
|
451
446
|
return [4, this.program.methods
|
|
452
447
|
.liquidate({})
|
|
453
|
-
.
|
|
448
|
+
.accountsPartial({
|
|
454
449
|
signer: this.provider.wallet.publicKey,
|
|
455
450
|
perpetuals: this.perpetuals.publicKey,
|
|
456
451
|
pool: poolConfig.poolAddress,
|
|
@@ -460,7 +455,6 @@ var PerpetualsClient = (function () {
|
|
|
460
455
|
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
|
461
456
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
|
462
457
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
|
463
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
464
458
|
program: this.program.programId,
|
|
465
459
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
|
466
460
|
})
|
|
@@ -2011,7 +2005,7 @@ var PerpetualsClient = (function () {
|
|
|
2011
2005
|
}
|
|
2012
2006
|
return [4, this.program.methods
|
|
2013
2007
|
.getLpTokenPrice({})
|
|
2014
|
-
.
|
|
2008
|
+
.accountsPartial({
|
|
2015
2009
|
perpetuals: POOL_CONFIG.perpetuals,
|
|
2016
2010
|
pool: poolKey,
|
|
2017
2011
|
lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
|
|
@@ -2033,7 +2027,7 @@ var PerpetualsClient = (function () {
|
|
|
2033
2027
|
return [4, this.viewHelper.simulateTransaction(transaction, addressLookupTables)];
|
|
2034
2028
|
case 4:
|
|
2035
2029
|
result = _e.sent();
|
|
2036
|
-
index =
|
|
2030
|
+
index = perpetuals_json_1.default.instructions.findIndex(function (f) { return f.name === 'getLpTokenPrice'; });
|
|
2037
2031
|
res = this.viewHelper.decodeLogs(result, index, 'getLpTokenPrice');
|
|
2038
2032
|
return [2, res.toString()];
|
|
2039
2033
|
}
|
|
@@ -2074,7 +2068,7 @@ var PerpetualsClient = (function () {
|
|
|
2074
2068
|
}
|
|
2075
2069
|
return [4, this.program.methods
|
|
2076
2070
|
.getAssetsUnderManagement({})
|
|
2077
|
-
.
|
|
2071
|
+
.accountsPartial({
|
|
2078
2072
|
perpetuals: POOL_CONFIG.perpetuals,
|
|
2079
2073
|
pool: poolKey,
|
|
2080
2074
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -2140,7 +2134,7 @@ var PerpetualsClient = (function () {
|
|
|
2140
2134
|
.getAddLiquidityAmountAndFee({
|
|
2141
2135
|
amountIn: amount,
|
|
2142
2136
|
})
|
|
2143
|
-
.
|
|
2137
|
+
.accountsPartial({
|
|
2144
2138
|
perpetuals: POOL_CONFIG.perpetuals,
|
|
2145
2139
|
pool: poolKey,
|
|
2146
2140
|
custody: depositCustodyKey,
|
|
@@ -2174,7 +2168,7 @@ var PerpetualsClient = (function () {
|
|
|
2174
2168
|
error: 'Simulation failed: ' + JSON.stringify(result.value.err),
|
|
2175
2169
|
}];
|
|
2176
2170
|
}
|
|
2177
|
-
index =
|
|
2171
|
+
index = perpetuals_json_1.default.instructions.findIndex(function (f) { return f.name === 'getAddLiquidityAmountAndFee'; });
|
|
2178
2172
|
res = this.viewHelper.decodeLogs(result, index, 'getAddLiquidityAmountAndFee');
|
|
2179
2173
|
return [2, {
|
|
2180
2174
|
amount: res.amount,
|
|
@@ -2235,7 +2229,7 @@ var PerpetualsClient = (function () {
|
|
|
2235
2229
|
.getRemoveLiquidityAmountAndFee({
|
|
2236
2230
|
lpAmountIn: amount,
|
|
2237
2231
|
})
|
|
2238
|
-
.
|
|
2232
|
+
.accountsPartial({
|
|
2239
2233
|
perpetuals: POOL_CONFIG.perpetuals,
|
|
2240
2234
|
pool: poolKey,
|
|
2241
2235
|
custody: removeTokenCustodyKey,
|
|
@@ -2261,7 +2255,7 @@ var PerpetualsClient = (function () {
|
|
|
2261
2255
|
return [4, this.viewHelper.simulateTransaction(transaction, addressLookupTables, userPublicKey)];
|
|
2262
2256
|
case 5:
|
|
2263
2257
|
result = _f.sent();
|
|
2264
|
-
index =
|
|
2258
|
+
index = perpetuals_json_1.default.instructions.findIndex(function (f) { return f.name === 'getRemoveLiquidityAmountAndFee'; });
|
|
2265
2259
|
if (result.value.err) {
|
|
2266
2260
|
console.error('error Simulation failed:', result);
|
|
2267
2261
|
return [2, {
|
|
@@ -2318,7 +2312,7 @@ var PerpetualsClient = (function () {
|
|
|
2318
2312
|
backUpOracleInstruction = _e.sent();
|
|
2319
2313
|
return [4, this.program.methods
|
|
2320
2314
|
.getCompoundingTokenPrice({})
|
|
2321
|
-
.
|
|
2315
|
+
.accountsPartial({
|
|
2322
2316
|
perpetuals: POOL_CONFIG.perpetuals,
|
|
2323
2317
|
pool: poolKey,
|
|
2324
2318
|
lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
|
|
@@ -2337,7 +2331,7 @@ var PerpetualsClient = (function () {
|
|
|
2337
2331
|
return [4, this.viewHelper.simulateTransaction(transaction, addressLookupTables)];
|
|
2338
2332
|
case 4:
|
|
2339
2333
|
result = _e.sent();
|
|
2340
|
-
index =
|
|
2334
|
+
index = perpetuals_json_1.default.instructions.findIndex(function (f) { return f.name === 'getCompoundingTokenPrice'; });
|
|
2341
2335
|
res = this.viewHelper.decodeLogs(result, index, 'getCompoundingTokenPrice');
|
|
2342
2336
|
return [2, res.toString()];
|
|
2343
2337
|
}
|
|
@@ -2395,7 +2389,7 @@ var PerpetualsClient = (function () {
|
|
|
2395
2389
|
.getAddCompoundingLiquidityAmountAndFee({
|
|
2396
2390
|
amountIn: amount,
|
|
2397
2391
|
})
|
|
2398
|
-
.
|
|
2392
|
+
.accountsPartial({
|
|
2399
2393
|
perpetuals: POOL_CONFIG.perpetuals,
|
|
2400
2394
|
pool: poolKey,
|
|
2401
2395
|
inCustody: depositCustodyKey,
|
|
@@ -2424,7 +2418,7 @@ var PerpetualsClient = (function () {
|
|
|
2424
2418
|
case 4: return [4, this.viewHelper.simulateTransaction(transaction, addressLookupTables, userPublicKey)];
|
|
2425
2419
|
case 5:
|
|
2426
2420
|
result = _f.sent();
|
|
2427
|
-
index =
|
|
2421
|
+
index = perpetuals_json_1.default.instructions.findIndex(function (f) { return f.name === 'getAddCompoundingLiquidityAmountAndFee'; });
|
|
2428
2422
|
res = this.viewHelper.decodeLogs(result, index, 'getAddCompoundingLiquidityAmountAndFee');
|
|
2429
2423
|
return [2, {
|
|
2430
2424
|
amount: res.amount,
|
|
@@ -2486,7 +2480,7 @@ var PerpetualsClient = (function () {
|
|
|
2486
2480
|
.getRemoveCompoundingLiquidityAmountAndFee({
|
|
2487
2481
|
compoundingAmountIn: amount,
|
|
2488
2482
|
})
|
|
2489
|
-
.
|
|
2483
|
+
.accountsPartial({
|
|
2490
2484
|
perpetuals: POOL_CONFIG.perpetuals,
|
|
2491
2485
|
pool: poolKey,
|
|
2492
2486
|
outCustody: removeTokenCustodyKey,
|
|
@@ -2515,7 +2509,7 @@ var PerpetualsClient = (function () {
|
|
|
2515
2509
|
return [4, this.viewHelper.simulateTransaction(transaction, addressLookupTables, userPublicKey)];
|
|
2516
2510
|
case 5:
|
|
2517
2511
|
result = _f.sent();
|
|
2518
|
-
index =
|
|
2512
|
+
index = perpetuals_json_1.default.instructions.findIndex(function (f) { return f.name === 'getRemoveCompoundingLiquidityAmountAndFee'; });
|
|
2519
2513
|
if (result.value.err) {
|
|
2520
2514
|
return [2, {
|
|
2521
2515
|
amount: new anchor_1.BN(0),
|
|
@@ -2548,7 +2542,7 @@ var PerpetualsClient = (function () {
|
|
|
2548
2542
|
collateralCustodyConfig = poolConfig.custodies.find(function (f) { return f.custodyAccount.equals(marketConfig_1.collateralCustody); });
|
|
2549
2543
|
return [4, this.program.methods
|
|
2550
2544
|
.getLiquidationPrice({})
|
|
2551
|
-
.
|
|
2545
|
+
.accountsPartial({
|
|
2552
2546
|
perpetuals: this.perpetuals.publicKey,
|
|
2553
2547
|
pool: poolConfig.poolAddress,
|
|
2554
2548
|
position: positionAccountKey,
|
|
@@ -2582,7 +2576,7 @@ var PerpetualsClient = (function () {
|
|
|
2582
2576
|
collateralCustodyConfig = poolConfig.custodies.find(function (f) { return f.mintKey.equals(collateralMint); });
|
|
2583
2577
|
return [4, this.program.methods
|
|
2584
2578
|
.getLiquidationState({})
|
|
2585
|
-
.
|
|
2579
|
+
.accountsPartial({
|
|
2586
2580
|
perpetuals: this.perpetuals.publicKey,
|
|
2587
2581
|
pool: poolConfig.poolAddress,
|
|
2588
2582
|
position: positionAccount,
|
|
@@ -2632,7 +2626,7 @@ var PerpetualsClient = (function () {
|
|
|
2632
2626
|
}
|
|
2633
2627
|
return [4, this.program.methods
|
|
2634
2628
|
.getCompoundingTokenData({})
|
|
2635
|
-
.
|
|
2629
|
+
.accountsPartial({
|
|
2636
2630
|
perpetuals: this.perpetuals.publicKey,
|
|
2637
2631
|
pool: poolConfig.poolAddress,
|
|
2638
2632
|
lpTokenMint: poolConfig.stakedLpTokenMint,
|
|
@@ -2679,7 +2673,7 @@ var PerpetualsClient = (function () {
|
|
|
2679
2673
|
}
|
|
2680
2674
|
return [4, this.program.methods
|
|
2681
2675
|
.getLpTokenPrice({})
|
|
2682
|
-
.
|
|
2676
|
+
.accountsPartial({
|
|
2683
2677
|
perpetuals: this.perpetuals.publicKey,
|
|
2684
2678
|
pool: poolConfig.poolAddress,
|
|
2685
2679
|
lpTokenMint: poolConfig.stakedLpTokenMint,
|
|
@@ -2700,7 +2694,7 @@ var PerpetualsClient = (function () {
|
|
|
2700
2694
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
2701
2695
|
args_1[_i - 8] = arguments[_i];
|
|
2702
2696
|
}
|
|
2703
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, skipBalanceChecks, ephemeralSignerPubkey
|
|
2697
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
|
2704
2698
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, collateralToken, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
|
2705
2699
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
2706
2700
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
@@ -2709,7 +2703,7 @@ var PerpetualsClient = (function () {
|
|
|
2709
2703
|
return __generator(this, function (_c) {
|
|
2710
2704
|
switch (_c.label) {
|
|
2711
2705
|
case 0:
|
|
2712
|
-
publicKey =
|
|
2706
|
+
publicKey = this.provider.wallet.publicKey;
|
|
2713
2707
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
2714
2708
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
2715
2709
|
collateralToken = poolConfig.getTokenFromSymbol(collateralSymbol);
|
|
@@ -2775,7 +2769,7 @@ var PerpetualsClient = (function () {
|
|
|
2775
2769
|
};
|
|
2776
2770
|
return [4, this.program.methods
|
|
2777
2771
|
.openPosition(params)
|
|
2778
|
-
.
|
|
2772
|
+
.accountsPartial({
|
|
2779
2773
|
owner: publicKey,
|
|
2780
2774
|
feePayer: publicKey,
|
|
2781
2775
|
fundingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userCollateralTokenAccount,
|
|
@@ -2790,8 +2784,6 @@ var PerpetualsClient = (function () {
|
|
|
2790
2784
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
|
2791
2785
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
2792
2786
|
fundingTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
2793
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
2794
|
-
program: this.programId,
|
|
2795
2787
|
transferAuthority: this.authority.publicKey,
|
|
2796
2788
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2797
2789
|
fundingMint: collateralCustodyConfig.mintKey
|
|
@@ -2814,48 +2806,59 @@ var PerpetualsClient = (function () {
|
|
|
2814
2806
|
for (var _i = 6; _i < arguments.length; _i++) {
|
|
2815
2807
|
args_1[_i - 6] = arguments[_i];
|
|
2816
2808
|
}
|
|
2817
|
-
return __awaiter(_this, __spreadArray([marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey
|
|
2818
|
-
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_1;
|
|
2809
|
+
return __awaiter(_this, __spreadArray([marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
|
2810
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_1;
|
|
2819
2811
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
2820
2812
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
2821
2813
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
2822
2814
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
|
2823
2815
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
2824
|
-
return __generator(this, function (
|
|
2825
|
-
switch (
|
|
2816
|
+
return __generator(this, function (_b) {
|
|
2817
|
+
switch (_b.label) {
|
|
2826
2818
|
case 0:
|
|
2827
|
-
|
|
2819
|
+
console.log("close position :::", marketSymbol, poolConfig.getTokenFromSymbol(marketSymbol).mintKey.toBase58());
|
|
2820
|
+
publicKey = this.provider.wallet.publicKey;
|
|
2828
2821
|
preInstructions = [];
|
|
2829
2822
|
instructions = [];
|
|
2830
2823
|
postInstructions = [];
|
|
2831
2824
|
additionalSigners = [];
|
|
2832
|
-
|
|
2825
|
+
_b.label = 1;
|
|
2833
2826
|
case 1:
|
|
2834
|
-
|
|
2835
|
-
if (collateralSymbol == 'SOL')
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
}
|
|
2841
|
-
preInstructions = [
|
|
2842
|
-
web3_js_1.SystemProgram.createAccount({
|
|
2843
|
-
fromPubkey: publicKey,
|
|
2844
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
2845
|
-
lamports: lamports,
|
|
2846
|
-
space: 165,
|
|
2847
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2848
|
-
}),
|
|
2849
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
2850
|
-
];
|
|
2851
|
-
postInstructions = [
|
|
2852
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
2853
|
-
];
|
|
2827
|
+
_b.trys.push([1, 7, , 8]);
|
|
2828
|
+
if (!(collateralSymbol == 'SOL')) return [3, 2];
|
|
2829
|
+
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
|
2830
|
+
if (!ephemeralSignerPubkey) {
|
|
2831
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
2832
|
+
additionalSigners.push(wrappedSolAccount);
|
|
2854
2833
|
}
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2834
|
+
preInstructions = [
|
|
2835
|
+
web3_js_1.SystemProgram.createAccount({
|
|
2836
|
+
fromPubkey: publicKey,
|
|
2837
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
2838
|
+
lamports: lamports,
|
|
2839
|
+
space: 165,
|
|
2840
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2841
|
+
}),
|
|
2842
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
2843
|
+
];
|
|
2844
|
+
postInstructions = [
|
|
2845
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
2846
|
+
];
|
|
2847
|
+
return [3, 5];
|
|
2848
|
+
case 2:
|
|
2849
|
+
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);
|
|
2850
|
+
_a = createUserATA;
|
|
2851
|
+
if (!_a) return [3, 4];
|
|
2852
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
2853
|
+
case 3:
|
|
2854
|
+
_a = !(_b.sent());
|
|
2855
|
+
_b.label = 4;
|
|
2856
|
+
case 4:
|
|
2857
|
+
if (_a) {
|
|
2858
|
+
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));
|
|
2858
2859
|
}
|
|
2860
|
+
_b.label = 5;
|
|
2861
|
+
case 5:
|
|
2859
2862
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
2860
2863
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(marketSymbol).mintKey); });
|
|
2861
2864
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
@@ -2865,7 +2868,7 @@ var PerpetualsClient = (function () {
|
|
|
2865
2868
|
priceWithSlippage: priceWithSlippage,
|
|
2866
2869
|
privilege: privilege
|
|
2867
2870
|
})
|
|
2868
|
-
.
|
|
2871
|
+
.accountsPartial({
|
|
2869
2872
|
feePayer: publicKey,
|
|
2870
2873
|
owner: publicKey,
|
|
2871
2874
|
receivingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
|
@@ -2880,26 +2883,25 @@ var PerpetualsClient = (function () {
|
|
|
2880
2883
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
|
2881
2884
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
|
2882
2885
|
eventAuthority: this.eventAuthority.publicKey,
|
|
2883
|
-
program: this.programId,
|
|
2884
2886
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2885
2887
|
collateralMint: collateralCustodyConfig.mintKey,
|
|
2886
2888
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
|
2887
2889
|
})
|
|
2888
2890
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
2889
2891
|
.instruction()];
|
|
2890
|
-
case
|
|
2891
|
-
instruction =
|
|
2892
|
+
case 6:
|
|
2893
|
+
instruction = _b.sent();
|
|
2892
2894
|
instructions.push(instruction);
|
|
2893
2895
|
if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
|
|
2894
2896
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
|
|
2895
2897
|
postInstructions.push(closeWsolATAIns);
|
|
2896
2898
|
}
|
|
2897
|
-
return [3,
|
|
2898
|
-
case
|
|
2899
|
-
error_1 =
|
|
2899
|
+
return [3, 8];
|
|
2900
|
+
case 7:
|
|
2901
|
+
error_1 = _b.sent();
|
|
2900
2902
|
console.error("perpclient closePosition error:", error_1);
|
|
2901
2903
|
throw error_1;
|
|
2902
|
-
case
|
|
2904
|
+
case 8: return [2, {
|
|
2903
2905
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
2904
2906
|
additionalSigners: additionalSigners
|
|
2905
2907
|
}];
|
|
@@ -2912,7 +2914,7 @@ var PerpetualsClient = (function () {
|
|
|
2912
2914
|
for (var _i = 9; _i < arguments.length; _i++) {
|
|
2913
2915
|
args_1[_i - 9] = arguments[_i];
|
|
2914
2916
|
}
|
|
2915
|
-
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, skipBalanceChecks, ephemeralSignerPubkey
|
|
2917
|
+
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
|
2916
2918
|
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, targetToken, userInputTokenAccount, userInputToken, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_3;
|
|
2917
2919
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
2918
2920
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
@@ -2921,7 +2923,7 @@ var PerpetualsClient = (function () {
|
|
|
2921
2923
|
return __generator(this, function (_c) {
|
|
2922
2924
|
switch (_c.label) {
|
|
2923
2925
|
case 0:
|
|
2924
|
-
publicKey =
|
|
2926
|
+
publicKey = this.provider.wallet.publicKey;
|
|
2925
2927
|
userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
|
|
2926
2928
|
if (!userInputCustodyConfig) {
|
|
2927
2929
|
throw "userInputCustodyConfig not found";
|
|
@@ -2945,7 +2947,7 @@ var PerpetualsClient = (function () {
|
|
|
2945
2947
|
additionalSigners = [];
|
|
2946
2948
|
targetToken = poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol);
|
|
2947
2949
|
userInputToken = poolConfig.getTokenFromSymbol(userInputTokenSymbol);
|
|
2948
|
-
if (!(userInputTokenSymbol == 'SOL')) return [3,
|
|
2950
|
+
if (!(userInputTokenSymbol == 'SOL')) return [3, 5];
|
|
2949
2951
|
console.log("inputSymbol === SOL", userInputTokenSymbol);
|
|
2950
2952
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
|
2951
2953
|
if (!!skipBalanceChecks) return [3, 2];
|
|
@@ -2975,33 +2977,41 @@ var PerpetualsClient = (function () {
|
|
|
2975
2977
|
postInstructions = [
|
|
2976
2978
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
2977
2979
|
];
|
|
2978
|
-
if (
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
}
|
|
2982
|
-
return [3, 7];
|
|
2980
|
+
if (!!poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey.equals(spl_token_1.NATIVE_MINT)) return [3, 4];
|
|
2981
|
+
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);
|
|
2982
|
+
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
|
2983
2983
|
case 3:
|
|
2984
|
+
if (!(_c.sent())) {
|
|
2985
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey));
|
|
2986
|
+
}
|
|
2987
|
+
_c.label = 4;
|
|
2988
|
+
case 4: return [3, 10];
|
|
2989
|
+
case 5:
|
|
2984
2990
|
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);
|
|
2985
|
-
if (!!skipBalanceChecks) return [3,
|
|
2991
|
+
if (!!skipBalanceChecks) return [3, 8];
|
|
2986
2992
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
|
2987
|
-
case
|
|
2993
|
+
case 6:
|
|
2988
2994
|
if (!(_c.sent())) {
|
|
2989
2995
|
throw "Insufficient Funds , Token Account doesn't exist";
|
|
2990
2996
|
}
|
|
2991
2997
|
_b = anchor_1.BN.bind;
|
|
2992
2998
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
|
2993
|
-
case
|
|
2999
|
+
case 7:
|
|
2994
3000
|
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
|
2995
3001
|
if (tokenAccountBalance.lt(amountIn)) {
|
|
2996
3002
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
|
2997
3003
|
}
|
|
2998
|
-
_c.label =
|
|
2999
|
-
case
|
|
3004
|
+
_c.label = 8;
|
|
3005
|
+
case 8:
|
|
3000
3006
|
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);
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3007
|
+
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
|
3008
|
+
case 9:
|
|
3009
|
+
if (!(_c.sent())) {
|
|
3010
|
+
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));
|
|
3011
|
+
}
|
|
3012
|
+
_c.label = 10;
|
|
3013
|
+
case 10:
|
|
3014
|
+
_c.trys.push([10, 12, , 13]);
|
|
3005
3015
|
return [4, this.program.methods
|
|
3006
3016
|
.swapAndOpen({
|
|
3007
3017
|
amountIn: amountIn,
|
|
@@ -3009,7 +3019,7 @@ var PerpetualsClient = (function () {
|
|
|
3009
3019
|
sizeAmount: sizeAmount,
|
|
3010
3020
|
privilege: privilege
|
|
3011
3021
|
})
|
|
3012
|
-
.
|
|
3022
|
+
.accountsPartial({
|
|
3013
3023
|
owner: publicKey,
|
|
3014
3024
|
feePayer: publicKey,
|
|
3015
3025
|
fundingAccount: userInputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
|
|
@@ -3028,7 +3038,6 @@ var PerpetualsClient = (function () {
|
|
|
3028
3038
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
|
3029
3039
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
3030
3040
|
eventAuthority: this.eventAuthority.publicKey,
|
|
3031
|
-
program: this.programId,
|
|
3032
3041
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3033
3042
|
fundingMint: userInputCustodyConfig.mintKey,
|
|
3034
3043
|
fundingTokenProgram: poolConfig.getTokenFromSymbol(userInputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
@@ -3037,15 +3046,15 @@ var PerpetualsClient = (function () {
|
|
|
3037
3046
|
})
|
|
3038
3047
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
3039
3048
|
.instruction()];
|
|
3040
|
-
case
|
|
3049
|
+
case 11:
|
|
3041
3050
|
inx = _c.sent();
|
|
3042
3051
|
instructions.push(inx);
|
|
3043
|
-
return [3,
|
|
3044
|
-
case
|
|
3052
|
+
return [3, 13];
|
|
3053
|
+
case 12:
|
|
3045
3054
|
err_3 = _c.sent();
|
|
3046
3055
|
console.error("perpClient SwapAndOpen error:: ", err_3);
|
|
3047
3056
|
throw err_3;
|
|
3048
|
-
case
|
|
3057
|
+
case 13: return [2, {
|
|
3049
3058
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
3050
3059
|
additionalSigners: additionalSigners
|
|
3051
3060
|
}];
|
|
@@ -3058,7 +3067,7 @@ var PerpetualsClient = (function () {
|
|
|
3058
3067
|
for (var _i = 7; _i < arguments.length; _i++) {
|
|
3059
3068
|
args_1[_i - 7] = arguments[_i];
|
|
3060
3069
|
}
|
|
3061
|
-
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, ephemeralSignerPubkey
|
|
3070
|
+
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, ephemeralSignerPubkey) {
|
|
3062
3071
|
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, collateralToken, userOutputToken, lamports, userCollateralTokenAccount, inx, err_4;
|
|
3063
3072
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
3064
3073
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
@@ -3066,7 +3075,7 @@ var PerpetualsClient = (function () {
|
|
|
3066
3075
|
return __generator(this, function (_a) {
|
|
3067
3076
|
switch (_a.label) {
|
|
3068
3077
|
case 0:
|
|
3069
|
-
publicKey =
|
|
3078
|
+
publicKey = this.provider.wallet.publicKey;
|
|
3070
3079
|
userOutputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey); });
|
|
3071
3080
|
if (!userOutputCustodyConfig) {
|
|
3072
3081
|
throw "userOutputCustodyConfig not found";
|
|
@@ -3090,43 +3099,52 @@ var PerpetualsClient = (function () {
|
|
|
3090
3099
|
additionalSigners = [];
|
|
3091
3100
|
collateralToken = poolConfig.getTokenFromSymbol(collateralTokenSymbol);
|
|
3092
3101
|
userOutputToken = poolConfig.getTokenFromSymbol(userOutputTokenSymbol);
|
|
3093
|
-
if (userOutputTokenSymbol == 'SOL')
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
additionalSigners.push(wrappedSolAccount);
|
|
3099
|
-
}
|
|
3100
|
-
preInstructions = [
|
|
3101
|
-
web3_js_1.SystemProgram.createAccount({
|
|
3102
|
-
fromPubkey: publicKey,
|
|
3103
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3104
|
-
lamports: lamports,
|
|
3105
|
-
space: 165,
|
|
3106
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3107
|
-
}),
|
|
3108
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3109
|
-
];
|
|
3110
|
-
postInstructions = [
|
|
3111
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3112
|
-
];
|
|
3102
|
+
if (!(userOutputTokenSymbol == 'SOL')) return [3, 1];
|
|
3103
|
+
console.log("outputSymbol === SOL", userOutputTokenSymbol);
|
|
3104
|
+
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
|
3105
|
+
if (!ephemeralSignerPubkey) {
|
|
3106
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
3113
3107
|
additionalSigners.push(wrappedSolAccount);
|
|
3114
3108
|
}
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3109
|
+
preInstructions = [
|
|
3110
|
+
web3_js_1.SystemProgram.createAccount({
|
|
3111
|
+
fromPubkey: publicKey,
|
|
3112
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3113
|
+
lamports: lamports,
|
|
3114
|
+
space: 165,
|
|
3115
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3116
|
+
}),
|
|
3117
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3118
|
+
];
|
|
3119
|
+
postInstructions = [
|
|
3120
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3121
|
+
];
|
|
3122
|
+
additionalSigners.push(wrappedSolAccount);
|
|
3123
|
+
return [3, 3];
|
|
3124
|
+
case 1:
|
|
3125
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(userOutputToken.mintKey, publicKey, true, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3126
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
3127
|
+
case 2:
|
|
3128
|
+
if (!(_a.sent())) {
|
|
3129
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, userOutputToken.mintKey, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3118
3130
|
}
|
|
3131
|
+
_a.label = 3;
|
|
3132
|
+
case 3:
|
|
3119
3133
|
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralToken.mintKey, publicKey, true, collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3134
|
+
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
|
3135
|
+
case 4:
|
|
3136
|
+
if (!(_a.sent())) {
|
|
3137
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralToken.mintKey, collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3138
|
+
}
|
|
3139
|
+
_a.label = 5;
|
|
3140
|
+
case 5:
|
|
3141
|
+
_a.trys.push([5, 7, , 8]);
|
|
3124
3142
|
return [4, this.program.methods
|
|
3125
3143
|
.closeAndSwap({
|
|
3126
3144
|
priceWithSlippage: priceWithSlippage,
|
|
3127
3145
|
privilege: privilege
|
|
3128
3146
|
})
|
|
3129
|
-
.
|
|
3147
|
+
.accountsPartial({
|
|
3130
3148
|
owner: publicKey,
|
|
3131
3149
|
feePayer: publicKey,
|
|
3132
3150
|
receivingAccount: userOutputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
|
@@ -3144,8 +3162,6 @@ var PerpetualsClient = (function () {
|
|
|
3144
3162
|
dispensingCustody: userOutputCustodyConfig.custodyAccount,
|
|
3145
3163
|
dispensingOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
|
|
3146
3164
|
dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
|
|
3147
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
3148
|
-
program: this.programId,
|
|
3149
3165
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3150
3166
|
receivingMint: userOutputCustodyConfig.mintKey,
|
|
3151
3167
|
receivingTokenProgram: userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
@@ -3154,15 +3170,15 @@ var PerpetualsClient = (function () {
|
|
|
3154
3170
|
})
|
|
3155
3171
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
3156
3172
|
.instruction()];
|
|
3157
|
-
case
|
|
3173
|
+
case 6:
|
|
3158
3174
|
inx = _a.sent();
|
|
3159
3175
|
instructions.push(inx);
|
|
3160
|
-
return [3,
|
|
3161
|
-
case
|
|
3176
|
+
return [3, 8];
|
|
3177
|
+
case 7:
|
|
3162
3178
|
err_4 = _a.sent();
|
|
3163
3179
|
console.error("perpClient CloseAndSwap error:: ", err_4);
|
|
3164
3180
|
throw err_4;
|
|
3165
|
-
case
|
|
3181
|
+
case 8: return [2, {
|
|
3166
3182
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
3167
3183
|
additionalSigners: additionalSigners
|
|
3168
3184
|
}];
|
|
@@ -3175,14 +3191,14 @@ var PerpetualsClient = (function () {
|
|
|
3175
3191
|
for (var _i = 6; _i < arguments.length; _i++) {
|
|
3176
3192
|
args_1[_i - 6] = arguments[_i];
|
|
3177
3193
|
}
|
|
3178
|
-
return __awaiter(_this, __spreadArray([collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey
|
|
3194
|
+
return __awaiter(_this, __spreadArray([collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
|
3179
3195
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
|
|
3180
3196
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
3181
3197
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
3182
3198
|
return __generator(this, function (_c) {
|
|
3183
3199
|
switch (_c.label) {
|
|
3184
3200
|
case 0:
|
|
3185
|
-
publicKey =
|
|
3201
|
+
publicKey = this.provider.wallet.publicKey;
|
|
3186
3202
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
3187
3203
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
3188
3204
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
@@ -3243,7 +3259,7 @@ var PerpetualsClient = (function () {
|
|
|
3243
3259
|
_c.label = 6;
|
|
3244
3260
|
case 6: return [4, this.program.methods.addCollateral({
|
|
3245
3261
|
collateralDelta: collateralWithFee
|
|
3246
|
-
}).
|
|
3262
|
+
}).accountsPartial({
|
|
3247
3263
|
owner: publicKey,
|
|
3248
3264
|
position: positionPubKey,
|
|
3249
3265
|
market: marketAccount,
|
|
@@ -3255,9 +3271,7 @@ var PerpetualsClient = (function () {
|
|
|
3255
3271
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
|
3256
3272
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
|
3257
3273
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
|
3258
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
3259
3274
|
fundingTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
3260
|
-
program: this.programId,
|
|
3261
3275
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3262
3276
|
fundingMint: collateralCustodyConfig.mintKey
|
|
3263
3277
|
})
|
|
@@ -3278,14 +3292,14 @@ var PerpetualsClient = (function () {
|
|
|
3278
3292
|
for (var _i = 7; _i < arguments.length; _i++) {
|
|
3279
3293
|
args_1[_i - 7] = arguments[_i];
|
|
3280
3294
|
}
|
|
3281
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, inputSymbol, collateralSymbol, amountIn, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey
|
|
3295
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, inputSymbol, collateralSymbol, amountIn, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
|
3282
3296
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
|
|
3283
3297
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
3284
3298
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
3285
3299
|
return __generator(this, function (_c) {
|
|
3286
3300
|
switch (_c.label) {
|
|
3287
3301
|
case 0:
|
|
3288
|
-
publicKey =
|
|
3302
|
+
publicKey = this.provider.wallet.publicKey;
|
|
3289
3303
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
3290
3304
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
3291
3305
|
inputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inputSymbol).mintKey); });
|
|
@@ -3349,11 +3363,15 @@ var PerpetualsClient = (function () {
|
|
|
3349
3363
|
_c.label = 6;
|
|
3350
3364
|
case 6:
|
|
3351
3365
|
userCollateralTokenAccount = (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);
|
|
3352
|
-
|
|
3366
|
+
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
|
3367
|
+
case 7:
|
|
3368
|
+
if (!(_c.sent())) {
|
|
3369
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3370
|
+
}
|
|
3353
3371
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
3354
3372
|
return [4, this.program.methods.swapAndAddCollateral({
|
|
3355
3373
|
amountIn: amountIn,
|
|
3356
|
-
}).
|
|
3374
|
+
}).accountsPartial({
|
|
3357
3375
|
owner: publicKey,
|
|
3358
3376
|
feePayer: publicKey,
|
|
3359
3377
|
fundingAccount: inputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
|
|
@@ -3370,14 +3388,12 @@ var PerpetualsClient = (function () {
|
|
|
3370
3388
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
|
3371
3389
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
|
3372
3390
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
|
3373
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
3374
3391
|
fundingTokenProgram: poolConfig.getTokenFromSymbol(inputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
3375
|
-
program: this.programId,
|
|
3376
3392
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3377
3393
|
fundingMint: poolConfig.getTokenFromSymbol(inputSymbol).mintKey,
|
|
3378
3394
|
})
|
|
3379
3395
|
.instruction()];
|
|
3380
|
-
case
|
|
3396
|
+
case 8:
|
|
3381
3397
|
instruction = _c.sent();
|
|
3382
3398
|
instructions.push(instruction);
|
|
3383
3399
|
return [2, {
|
|
@@ -3393,15 +3409,15 @@ var PerpetualsClient = (function () {
|
|
|
3393
3409
|
for (var _i = 6; _i < arguments.length; _i++) {
|
|
3394
3410
|
args_1[_i - 6] = arguments[_i];
|
|
3395
3411
|
}
|
|
3396
|
-
return __awaiter(_this, __spreadArray([collateralDeltaUsd_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralDeltaUsd, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey
|
|
3397
|
-
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, marketAccount, instruction, closeWsolATAIns, error_2;
|
|
3412
|
+
return __awaiter(_this, __spreadArray([collateralDeltaUsd_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralDeltaUsd, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
|
3413
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns, error_2;
|
|
3398
3414
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
3399
3415
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
|
3400
3416
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
3401
|
-
return __generator(this, function (
|
|
3402
|
-
switch (
|
|
3417
|
+
return __generator(this, function (_b) {
|
|
3418
|
+
switch (_b.label) {
|
|
3403
3419
|
case 0:
|
|
3404
|
-
publicKey =
|
|
3420
|
+
publicKey = this.provider.wallet.publicKey;
|
|
3405
3421
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) {
|
|
3406
3422
|
return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey);
|
|
3407
3423
|
});
|
|
@@ -3415,41 +3431,51 @@ var PerpetualsClient = (function () {
|
|
|
3415
3431
|
instructions = [];
|
|
3416
3432
|
postInstructions = [];
|
|
3417
3433
|
additionalSigners = [];
|
|
3418
|
-
|
|
3434
|
+
_b.label = 1;
|
|
3419
3435
|
case 1:
|
|
3420
|
-
|
|
3436
|
+
_b.trys.push([1, 7, , 8]);
|
|
3421
3437
|
console.log("removeCollateral -- collateralSymbol:", collateralSymbol);
|
|
3422
|
-
if (collateralSymbol == 'SOL')
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
}
|
|
3429
|
-
preInstructions = [
|
|
3430
|
-
web3_js_1.SystemProgram.createAccount({
|
|
3431
|
-
fromPubkey: publicKey,
|
|
3432
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3433
|
-
lamports: lamports,
|
|
3434
|
-
space: 165,
|
|
3435
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3436
|
-
}),
|
|
3437
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3438
|
-
];
|
|
3439
|
-
postInstructions = [
|
|
3440
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3441
|
-
];
|
|
3438
|
+
if (!(collateralSymbol == 'SOL')) return [3, 2];
|
|
3439
|
+
console.log("remove collateral in SOL ...create WSOL temp and close it ");
|
|
3440
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
|
3441
|
+
if (!ephemeralSignerPubkey) {
|
|
3442
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
3443
|
+
additionalSigners.push(wrappedSolAccount);
|
|
3442
3444
|
}
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3445
|
+
preInstructions = [
|
|
3446
|
+
web3_js_1.SystemProgram.createAccount({
|
|
3447
|
+
fromPubkey: publicKey,
|
|
3448
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3449
|
+
lamports: lamports,
|
|
3450
|
+
space: 165,
|
|
3451
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3452
|
+
}),
|
|
3453
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3454
|
+
];
|
|
3455
|
+
postInstructions = [
|
|
3456
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3457
|
+
];
|
|
3458
|
+
return [3, 5];
|
|
3459
|
+
case 2:
|
|
3460
|
+
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);
|
|
3461
|
+
_a = createUserATA;
|
|
3462
|
+
if (!_a) return [3, 4];
|
|
3463
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
3464
|
+
case 3:
|
|
3465
|
+
_a = !(_b.sent());
|
|
3466
|
+
_b.label = 4;
|
|
3467
|
+
case 4:
|
|
3468
|
+
if (_a) {
|
|
3469
|
+
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));
|
|
3446
3470
|
}
|
|
3471
|
+
_b.label = 5;
|
|
3472
|
+
case 5:
|
|
3447
3473
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
3448
3474
|
return [4, this.program.methods
|
|
3449
3475
|
.removeCollateral({
|
|
3450
3476
|
collateralDeltaUsd: collateralDeltaUsd,
|
|
3451
3477
|
})
|
|
3452
|
-
.
|
|
3478
|
+
.accountsPartial({
|
|
3453
3479
|
owner: publicKey,
|
|
3454
3480
|
receivingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
|
3455
3481
|
transferAuthority: poolConfig.transferAuthority,
|
|
@@ -3464,24 +3490,23 @@ var PerpetualsClient = (function () {
|
|
|
3464
3490
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
|
3465
3491
|
eventAuthority: this.eventAuthority.publicKey,
|
|
3466
3492
|
receivingTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
3467
|
-
program: this.programId,
|
|
3468
3493
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3469
3494
|
receivingMint: collateralCustodyConfig.mintKey
|
|
3470
3495
|
})
|
|
3471
3496
|
.instruction()];
|
|
3472
|
-
case
|
|
3473
|
-
instruction =
|
|
3497
|
+
case 6:
|
|
3498
|
+
instruction = _b.sent();
|
|
3474
3499
|
instructions.push(instruction);
|
|
3475
3500
|
if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
|
|
3476
3501
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, publicKey, publicKey);
|
|
3477
3502
|
postInstructions.push(closeWsolATAIns);
|
|
3478
3503
|
}
|
|
3479
|
-
return [3,
|
|
3480
|
-
case
|
|
3481
|
-
error_2 =
|
|
3504
|
+
return [3, 8];
|
|
3505
|
+
case 7:
|
|
3506
|
+
error_2 = _b.sent();
|
|
3482
3507
|
console.error("perpclient removeCollateral error:", error_2);
|
|
3483
3508
|
throw error_2;
|
|
3484
|
-
case
|
|
3509
|
+
case 8: return [2, {
|
|
3485
3510
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
3486
3511
|
additionalSigners: additionalSigners
|
|
3487
3512
|
}];
|
|
@@ -3494,13 +3519,13 @@ var PerpetualsClient = (function () {
|
|
|
3494
3519
|
for (var _i = 6; _i < arguments.length; _i++) {
|
|
3495
3520
|
args_1[_i - 6] = arguments[_i];
|
|
3496
3521
|
}
|
|
3497
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, outputSymbol_1, collateralDeltaUsd_1, side_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, outputSymbol, collateralDeltaUsd, side, poolConfig, ephemeralSignerPubkey
|
|
3522
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, outputSymbol_1, collateralDeltaUsd_1, side_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, outputSymbol, collateralDeltaUsd, side, poolConfig, ephemeralSignerPubkey) {
|
|
3498
3523
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, instruction;
|
|
3499
3524
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
3500
3525
|
return __generator(this, function (_a) {
|
|
3501
3526
|
switch (_a.label) {
|
|
3502
3527
|
case 0:
|
|
3503
|
-
publicKey =
|
|
3528
|
+
publicKey = this.provider.wallet.publicKey;
|
|
3504
3529
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
3505
3530
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
3506
3531
|
outputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(outputSymbol).mintKey); });
|
|
@@ -3511,40 +3536,49 @@ var PerpetualsClient = (function () {
|
|
|
3511
3536
|
instructions = [];
|
|
3512
3537
|
postInstructions = [];
|
|
3513
3538
|
additionalSigners = [];
|
|
3514
|
-
if (outputSymbol == 'SOL')
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
}
|
|
3521
|
-
preInstructions = [
|
|
3522
|
-
web3_js_1.SystemProgram.createAccount({
|
|
3523
|
-
fromPubkey: publicKey,
|
|
3524
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3525
|
-
lamports: lamports,
|
|
3526
|
-
space: 165,
|
|
3527
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3528
|
-
}),
|
|
3529
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3530
|
-
];
|
|
3531
|
-
postInstructions = [
|
|
3532
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3533
|
-
];
|
|
3539
|
+
if (!(outputSymbol == 'SOL')) return [3, 1];
|
|
3540
|
+
console.log("outputSymbol === SOL", outputSymbol);
|
|
3541
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
|
3542
|
+
if (!ephemeralSignerPubkey) {
|
|
3543
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
3544
|
+
additionalSigners.push(wrappedSolAccount);
|
|
3534
3545
|
}
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3546
|
+
preInstructions = [
|
|
3547
|
+
web3_js_1.SystemProgram.createAccount({
|
|
3548
|
+
fromPubkey: publicKey,
|
|
3549
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
3550
|
+
lamports: lamports,
|
|
3551
|
+
space: 165,
|
|
3552
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3553
|
+
}),
|
|
3554
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
3555
|
+
];
|
|
3556
|
+
postInstructions = [
|
|
3557
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3558
|
+
];
|
|
3559
|
+
return [3, 3];
|
|
3560
|
+
case 1:
|
|
3561
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3562
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
3563
|
+
case 2:
|
|
3564
|
+
if (!(_a.sent())) {
|
|
3565
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(outputSymbol).mintKey, poolConfig.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3538
3566
|
}
|
|
3567
|
+
_a.label = 3;
|
|
3568
|
+
case 3:
|
|
3539
3569
|
userCollateralTokenAccount = (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);
|
|
3540
|
-
|
|
3570
|
+
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
|
3571
|
+
case 4:
|
|
3572
|
+
if (!(_a.sent())) {
|
|
3573
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
3574
|
+
}
|
|
3541
3575
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
3542
3576
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
|
3543
3577
|
return [4, this.program.methods
|
|
3544
3578
|
.removeCollateralAndSwap({
|
|
3545
3579
|
collateralDeltaUsd: collateralDeltaUsd,
|
|
3546
3580
|
})
|
|
3547
|
-
.
|
|
3581
|
+
.accountsPartial({
|
|
3548
3582
|
owner: publicKey,
|
|
3549
3583
|
feePayer: publicKey,
|
|
3550
3584
|
receivingAccount: outputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
|
@@ -3562,8 +3596,6 @@ var PerpetualsClient = (function () {
|
|
|
3562
3596
|
dispensingCustody: outputCustodyConfig.custodyAccount,
|
|
3563
3597
|
dispensingOracleAccount: this.useExtOracleAccount ? outputCustodyConfig.extOracleAccount : outputCustodyConfig.intOracleAccount,
|
|
3564
3598
|
dispensingCustodyTokenAccount: outputCustodyConfig.tokenAccount,
|
|
3565
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
3566
|
-
program: this.programId,
|
|
3567
3599
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3568
3600
|
receivingMint: outputCustodyConfig.mintKey,
|
|
3569
3601
|
receivingTokenProgram: poolConfig.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
@@ -3571,7 +3603,7 @@ var PerpetualsClient = (function () {
|
|
|
3571
3603
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
|
3572
3604
|
})
|
|
3573
3605
|
.instruction()];
|
|
3574
|
-
case
|
|
3606
|
+
case 5:
|
|
3575
3607
|
instruction = _a.sent();
|
|
3576
3608
|
instructions.push(instruction);
|
|
3577
3609
|
return [2, {
|
|
@@ -3587,14 +3619,14 @@ var PerpetualsClient = (function () {
|
|
|
3587
3619
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
3588
3620
|
args_1[_i - 8] = arguments[_i];
|
|
3589
3621
|
}
|
|
3590
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount
|
|
3622
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount) {
|
|
3591
3623
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
|
3592
3624
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
3593
3625
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
3594
3626
|
return __generator(this, function (_a) {
|
|
3595
3627
|
switch (_a.label) {
|
|
3596
3628
|
case 0:
|
|
3597
|
-
publicKey =
|
|
3629
|
+
publicKey = this.provider.wallet.publicKey;
|
|
3598
3630
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) {
|
|
3599
3631
|
return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey);
|
|
3600
3632
|
});
|
|
@@ -3615,7 +3647,7 @@ var PerpetualsClient = (function () {
|
|
|
3615
3647
|
sizeDelta: sizeDelta,
|
|
3616
3648
|
privilege: privilege
|
|
3617
3649
|
})
|
|
3618
|
-
.
|
|
3650
|
+
.accountsPartial({
|
|
3619
3651
|
owner: publicKey,
|
|
3620
3652
|
transferAuthority: poolConfig.transferAuthority,
|
|
3621
3653
|
perpetuals: poolConfig.perpetuals,
|
|
@@ -3629,7 +3661,6 @@ var PerpetualsClient = (function () {
|
|
|
3629
3661
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
|
3630
3662
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
3631
3663
|
eventAuthority: this.eventAuthority.publicKey,
|
|
3632
|
-
program: this.programId,
|
|
3633
3664
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3634
3665
|
collateralMint: collateralCustodyConfig.mintKey
|
|
3635
3666
|
})
|
|
@@ -3651,14 +3682,14 @@ var PerpetualsClient = (function () {
|
|
|
3651
3682
|
for (var _i = 8; _i < arguments.length; _i++) {
|
|
3652
3683
|
args_1[_i - 8] = arguments[_i];
|
|
3653
3684
|
}
|
|
3654
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount
|
|
3685
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount) {
|
|
3655
3686
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
|
3656
3687
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
3657
3688
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
3658
3689
|
return __generator(this, function (_a) {
|
|
3659
3690
|
switch (_a.label) {
|
|
3660
3691
|
case 0:
|
|
3661
|
-
publicKey =
|
|
3692
|
+
publicKey = this.provider.wallet.publicKey;
|
|
3662
3693
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) {
|
|
3663
3694
|
return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey);
|
|
3664
3695
|
});
|
|
@@ -3679,7 +3710,7 @@ var PerpetualsClient = (function () {
|
|
|
3679
3710
|
sizeDelta: sizeDelta,
|
|
3680
3711
|
privilege: privilege
|
|
3681
3712
|
})
|
|
3682
|
-
.
|
|
3713
|
+
.accountsPartial({
|
|
3683
3714
|
owner: publicKey,
|
|
3684
3715
|
transferAuthority: poolConfig.transferAuthority,
|
|
3685
3716
|
perpetuals: poolConfig.perpetuals,
|
|
@@ -3693,7 +3724,6 @@ var PerpetualsClient = (function () {
|
|
|
3693
3724
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
|
3694
3725
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
3695
3726
|
eventAuthority: this.eventAuthority.publicKey,
|
|
3696
|
-
program: this.programId,
|
|
3697
3727
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3698
3728
|
collateralMint: collateralCustodyConfig.mintKey
|
|
3699
3729
|
})
|
|
@@ -3715,7 +3745,7 @@ var PerpetualsClient = (function () {
|
|
|
3715
3745
|
for (var _i = 4; _i < arguments.length; _i++) {
|
|
3716
3746
|
args_1[_i - 4] = arguments[_i];
|
|
3717
3747
|
}
|
|
3718
|
-
return __awaiter(_this, __spreadArray([payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, isWhitelistedUser
|
|
3748
|
+
return __awaiter(_this, __spreadArray([payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, isWhitelistedUser) {
|
|
3719
3749
|
var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, payToken, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, tokenAccountBalance, _f, whitelistPda, whitelistMeta, instruction, err_5;
|
|
3720
3750
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
3721
3751
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
@@ -3723,7 +3753,7 @@ var PerpetualsClient = (function () {
|
|
|
3723
3753
|
return __generator(this, function (_g) {
|
|
3724
3754
|
switch (_g.label) {
|
|
3725
3755
|
case 0:
|
|
3726
|
-
publicKey =
|
|
3756
|
+
publicKey = this.provider.wallet.publicKey;
|
|
3727
3757
|
payTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey); });
|
|
3728
3758
|
if (!payTokenCustodyConfig) {
|
|
3729
3759
|
throw "payTokenCustodyConfig not found";
|
|
@@ -3735,7 +3765,7 @@ var PerpetualsClient = (function () {
|
|
|
3735
3765
|
payToken = poolConfig.getTokenFromSymbol(payTokenSymbol);
|
|
3736
3766
|
_g.label = 1;
|
|
3737
3767
|
case 1:
|
|
3738
|
-
_g.trys.push([1,
|
|
3768
|
+
_g.trys.push([1, 10, , 11]);
|
|
3739
3769
|
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true, payToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3740
3770
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
|
3741
3771
|
custodyAccountMetas = [];
|
|
@@ -3762,20 +3792,24 @@ var PerpetualsClient = (function () {
|
|
|
3762
3792
|
isWritable: false,
|
|
3763
3793
|
});
|
|
3764
3794
|
}
|
|
3765
|
-
|
|
3766
|
-
|
|
3795
|
+
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
|
3796
|
+
case 2:
|
|
3797
|
+
if (!(_g.sent())) {
|
|
3798
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
|
3799
|
+
}
|
|
3800
|
+
if (!(payTokenSymbol == 'SOL')) return [3, 5];
|
|
3767
3801
|
console.log("payTokenSymbol === SOL", payTokenSymbol);
|
|
3768
3802
|
lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
|
3769
|
-
if (!!skipBalanceChecks) return [3,
|
|
3803
|
+
if (!!skipBalanceChecks) return [3, 4];
|
|
3770
3804
|
_e = anchor_1.BN.bind;
|
|
3771
3805
|
return [4, this.provider.connection.getBalance(publicKey)];
|
|
3772
|
-
case
|
|
3806
|
+
case 3:
|
|
3773
3807
|
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
|
3774
3808
|
if (unWrappedSolBalance.lt(lamports)) {
|
|
3775
3809
|
throw "Insufficient SOL Funds";
|
|
3776
3810
|
}
|
|
3777
|
-
_g.label =
|
|
3778
|
-
case
|
|
3811
|
+
_g.label = 4;
|
|
3812
|
+
case 4:
|
|
3779
3813
|
if (!ephemeralSignerPubkey) {
|
|
3780
3814
|
wrappedSolAccount = new web3_js_1.Keypair();
|
|
3781
3815
|
additionalSigners.push(wrappedSolAccount);
|
|
@@ -3793,23 +3827,23 @@ var PerpetualsClient = (function () {
|
|
|
3793
3827
|
postInstructions = [
|
|
3794
3828
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3795
3829
|
];
|
|
3796
|
-
return [3,
|
|
3797
|
-
case 4:
|
|
3798
|
-
if (!!skipBalanceChecks) return [3, 7];
|
|
3799
|
-
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
|
3830
|
+
return [3, 8];
|
|
3800
3831
|
case 5:
|
|
3832
|
+
if (!!skipBalanceChecks) return [3, 8];
|
|
3833
|
+
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
|
3834
|
+
case 6:
|
|
3801
3835
|
if (!(_g.sent())) {
|
|
3802
3836
|
throw "Insufficient Funds , token Account doesn't exist";
|
|
3803
3837
|
}
|
|
3804
3838
|
_f = anchor_1.BN.bind;
|
|
3805
3839
|
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
|
3806
|
-
case
|
|
3840
|
+
case 7:
|
|
3807
3841
|
tokenAccountBalance = new (_f.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
|
3808
3842
|
if (tokenAccountBalance.lt(tokenAmountIn)) {
|
|
3809
3843
|
throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
|
|
3810
3844
|
}
|
|
3811
|
-
_g.label =
|
|
3812
|
-
case
|
|
3845
|
+
_g.label = 8;
|
|
3846
|
+
case 8:
|
|
3813
3847
|
whitelistPda = this.findProgramAddress("whitelist", [publicKey]).publicKey;
|
|
3814
3848
|
whitelistMeta = {
|
|
3815
3849
|
pubkey: whitelistPda,
|
|
@@ -3821,7 +3855,7 @@ var PerpetualsClient = (function () {
|
|
|
3821
3855
|
amountIn: tokenAmountIn,
|
|
3822
3856
|
minLpAmountOut: minLpAmountOut
|
|
3823
3857
|
})
|
|
3824
|
-
.
|
|
3858
|
+
.accountsPartial({
|
|
3825
3859
|
owner: publicKey,
|
|
3826
3860
|
fundingAccount: payTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userPayingTokenAccount,
|
|
3827
3861
|
lpTokenAccount: lpTokenAccount,
|
|
@@ -3834,22 +3868,21 @@ var PerpetualsClient = (function () {
|
|
|
3834
3868
|
lpTokenMint: poolConfig.stakedLpTokenMint,
|
|
3835
3869
|
eventAuthority: this.eventAuthority.publicKey,
|
|
3836
3870
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3837
|
-
program: this.programId,
|
|
3838
3871
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3839
3872
|
fundingMint: payTokenCustodyConfig.mintKey,
|
|
3840
3873
|
fundingTokenProgram: payToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
3841
3874
|
})
|
|
3842
3875
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
3843
3876
|
.instruction()];
|
|
3844
|
-
case
|
|
3877
|
+
case 9:
|
|
3845
3878
|
instruction = _g.sent();
|
|
3846
3879
|
instructions.push(instruction);
|
|
3847
|
-
return [3,
|
|
3848
|
-
case
|
|
3880
|
+
return [3, 11];
|
|
3881
|
+
case 10:
|
|
3849
3882
|
err_5 = _g.sent();
|
|
3850
3883
|
console.error("perpClient addLiquidity error:: ", err_5);
|
|
3851
3884
|
throw err_5;
|
|
3852
|
-
case
|
|
3885
|
+
case 11: return [2, {
|
|
3853
3886
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
3854
3887
|
additionalSigners: additionalSigners
|
|
3855
3888
|
}];
|
|
@@ -3882,7 +3915,7 @@ var PerpetualsClient = (function () {
|
|
|
3882
3915
|
inputToken = poolConfig.getTokenFromSymbol(inputSymbol);
|
|
3883
3916
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
|
3884
3917
|
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
|
3885
|
-
if (!(inputSymbol == 'SOL')) return [3,
|
|
3918
|
+
if (!(inputSymbol == 'SOL')) return [3, 4];
|
|
3886
3919
|
console.log("inputSymbol === SOL", inputSymbol);
|
|
3887
3920
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
|
3888
3921
|
console.log("lamports:", lamports.toNumber());
|
|
@@ -3895,8 +3928,11 @@ var PerpetualsClient = (function () {
|
|
|
3895
3928
|
throw "Insufficient SOL Funds";
|
|
3896
3929
|
}
|
|
3897
3930
|
_g.label = 2;
|
|
3898
|
-
case 2:
|
|
3899
|
-
|
|
3931
|
+
case 2: return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
|
3932
|
+
case 3:
|
|
3933
|
+
if (!(_g.sent())) {
|
|
3934
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
|
3935
|
+
}
|
|
3900
3936
|
if (!ephemeralSignerPubkey) {
|
|
3901
3937
|
wrappedSolAccount = new web3_js_1.Keypair();
|
|
3902
3938
|
additionalSigners.push(wrappedSolAccount);
|
|
@@ -3914,24 +3950,24 @@ var PerpetualsClient = (function () {
|
|
|
3914
3950
|
postInstructions = [
|
|
3915
3951
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
3916
3952
|
];
|
|
3917
|
-
return [3,
|
|
3918
|
-
case
|
|
3953
|
+
return [3, 7];
|
|
3954
|
+
case 4:
|
|
3919
3955
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true, inputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
3920
|
-
if (!!skipBalanceChecks) return [3,
|
|
3956
|
+
if (!!skipBalanceChecks) return [3, 7];
|
|
3921
3957
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
|
3922
|
-
case
|
|
3958
|
+
case 5:
|
|
3923
3959
|
if (!(_g.sent())) {
|
|
3924
3960
|
throw "Insufficient Funds , token Account doesn't exist";
|
|
3925
3961
|
}
|
|
3926
3962
|
_b = anchor_1.BN.bind;
|
|
3927
3963
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
|
3928
|
-
case
|
|
3964
|
+
case 6:
|
|
3929
3965
|
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
|
3930
3966
|
if (tokenAccountBalance.lt(amountIn)) {
|
|
3931
3967
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
|
3932
3968
|
}
|
|
3933
|
-
_g.label =
|
|
3934
|
-
case
|
|
3969
|
+
_g.label = 7;
|
|
3970
|
+
case 7:
|
|
3935
3971
|
custodyAccountMetas = [];
|
|
3936
3972
|
custodyOracleAccountMetas = [];
|
|
3937
3973
|
markets = [];
|
|
@@ -3965,7 +4001,7 @@ var PerpetualsClient = (function () {
|
|
|
3965
4001
|
return [4, this.program.methods.addLiquidityAndStake({
|
|
3966
4002
|
amountIn: amountIn,
|
|
3967
4003
|
minLpAmountOut: minLpAmountOut,
|
|
3968
|
-
}).
|
|
4004
|
+
}).accountsPartial({
|
|
3969
4005
|
owner: publicKey,
|
|
3970
4006
|
feePayer: publicKey,
|
|
3971
4007
|
fundingAccount: inputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
|
|
@@ -3980,15 +4016,13 @@ var PerpetualsClient = (function () {
|
|
|
3980
4016
|
poolStakedLpVault: poolStakedLpVault,
|
|
3981
4017
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
3982
4018
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3983
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
3984
|
-
program: this.programId,
|
|
3985
4019
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3986
4020
|
fundingMint: inputCustodyConfig.mintKey,
|
|
3987
4021
|
fundingTokenProgram: inputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
3988
4022
|
})
|
|
3989
4023
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
3990
4024
|
.instruction()];
|
|
3991
|
-
case
|
|
4025
|
+
case 8:
|
|
3992
4026
|
instruction = _g.sent();
|
|
3993
4027
|
instructions.push(instruction);
|
|
3994
4028
|
return [2, {
|
|
@@ -4098,7 +4132,7 @@ var PerpetualsClient = (function () {
|
|
|
4098
4132
|
lpAmountIn: liquidityAmountIn,
|
|
4099
4133
|
minAmountOut: minTokenAmountOut
|
|
4100
4134
|
})
|
|
4101
|
-
.
|
|
4135
|
+
.accountsPartial({
|
|
4102
4136
|
owner: publicKey,
|
|
4103
4137
|
receivingAccount: recieveTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
|
4104
4138
|
lpTokenAccount: stakedLpTokenAccount,
|
|
@@ -4111,7 +4145,6 @@ var PerpetualsClient = (function () {
|
|
|
4111
4145
|
lpTokenMint: poolConfig.stakedLpTokenMint,
|
|
4112
4146
|
eventAuthority: this.eventAuthority.publicKey,
|
|
4113
4147
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4114
|
-
program: this.programId,
|
|
4115
4148
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
4116
4149
|
receivingMint: recieveTokenCustodyConfig.mintKey,
|
|
4117
4150
|
receivingTokenProgram: recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
@@ -4157,7 +4190,7 @@ var PerpetualsClient = (function () {
|
|
|
4157
4190
|
_a.trys.push([1, 3, , 4]);
|
|
4158
4191
|
return [4, this.program.methods
|
|
4159
4192
|
.createReferral({})
|
|
4160
|
-
.
|
|
4193
|
+
.accountsPartial({
|
|
4161
4194
|
owner: publicKey,
|
|
4162
4195
|
feePayer: publicKey,
|
|
4163
4196
|
referralAccount: nftReferralAccount,
|
|
@@ -4202,7 +4235,7 @@ var PerpetualsClient = (function () {
|
|
|
4202
4235
|
.depositStake({
|
|
4203
4236
|
depositAmount: depositAmount
|
|
4204
4237
|
})
|
|
4205
|
-
.
|
|
4238
|
+
.accountsPartial({
|
|
4206
4239
|
owner: owner,
|
|
4207
4240
|
feePayer: feePayer,
|
|
4208
4241
|
fundingLpTokenAccount: userLpTokenAccount,
|
|
@@ -4213,8 +4246,6 @@ var PerpetualsClient = (function () {
|
|
|
4213
4246
|
poolStakedLpVault: poolStakedLpVault,
|
|
4214
4247
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
4215
4248
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4216
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
4217
|
-
program: this.programId,
|
|
4218
4249
|
lpTokenMint: poolConfig.stakedLpTokenMint,
|
|
4219
4250
|
})
|
|
4220
4251
|
.instruction()];
|
|
@@ -4267,12 +4298,11 @@ var PerpetualsClient = (function () {
|
|
|
4267
4298
|
}
|
|
4268
4299
|
return [4, this.program.methods
|
|
4269
4300
|
.refreshStake({})
|
|
4270
|
-
.
|
|
4301
|
+
.accountsPartial({
|
|
4271
4302
|
perpetuals: this.perpetuals.publicKey,
|
|
4272
4303
|
pool: pool,
|
|
4273
4304
|
rewardCustody: rewardCustodyConfig.custodyAccount,
|
|
4274
4305
|
feeDistributionTokenAccount: feeDistributionTokenAccount,
|
|
4275
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
4276
4306
|
program: this.program.programId,
|
|
4277
4307
|
})
|
|
4278
4308
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), flpStakeAccountMetas, true))
|
|
@@ -4328,12 +4358,11 @@ var PerpetualsClient = (function () {
|
|
|
4328
4358
|
});
|
|
4329
4359
|
return [4, this.program.methods
|
|
4330
4360
|
.refreshStake({})
|
|
4331
|
-
.
|
|
4361
|
+
.accountsPartial({
|
|
4332
4362
|
perpetuals: this.perpetuals.publicKey,
|
|
4333
4363
|
pool: pool,
|
|
4334
4364
|
rewardCustody: rewardCustodyConfig.custodyAccount,
|
|
4335
4365
|
feeDistributionTokenAccount: feeDistributionTokenAccount,
|
|
4336
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
4337
4366
|
program: this.program.programId,
|
|
4338
4367
|
})
|
|
4339
4368
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
|
|
@@ -4392,13 +4421,12 @@ var PerpetualsClient = (function () {
|
|
|
4392
4421
|
.unstakeInstant({
|
|
4393
4422
|
unstakeAmount: unstakeAmount
|
|
4394
4423
|
})
|
|
4395
|
-
.
|
|
4424
|
+
.accountsPartial({
|
|
4396
4425
|
owner: publicKey,
|
|
4397
4426
|
perpetuals: this.perpetuals.publicKey,
|
|
4398
4427
|
pool: pool,
|
|
4399
4428
|
flpStakeAccount: flpStakeAccount,
|
|
4400
4429
|
rewardCustody: rewardCustodyConfig.custodyAccount,
|
|
4401
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
4402
4430
|
program: this.program.programId,
|
|
4403
4431
|
})
|
|
4404
4432
|
.remainingAccounts(__spreadArray([], tokenStakeAccounts, true))
|
|
@@ -4453,7 +4481,7 @@ var PerpetualsClient = (function () {
|
|
|
4453
4481
|
.setFeeShare({
|
|
4454
4482
|
feeShareBps: new anchor_1.BN(7000)
|
|
4455
4483
|
})
|
|
4456
|
-
.
|
|
4484
|
+
.accountsPartial({
|
|
4457
4485
|
admin: publicKey,
|
|
4458
4486
|
multisig: this.multisig.publicKey,
|
|
4459
4487
|
pool: pool,
|
|
@@ -4471,12 +4499,12 @@ var PerpetualsClient = (function () {
|
|
|
4471
4499
|
}
|
|
4472
4500
|
});
|
|
4473
4501
|
}); };
|
|
4474
|
-
this.unstakeRequest = function (unstakeAmount, poolConfig
|
|
4502
|
+
this.unstakeRequest = function (unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
4475
4503
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_13;
|
|
4476
4504
|
return __generator(this, function (_a) {
|
|
4477
4505
|
switch (_a.label) {
|
|
4478
4506
|
case 0:
|
|
4479
|
-
publicKey =
|
|
4507
|
+
publicKey = this.provider.wallet.publicKey;
|
|
4480
4508
|
preInstructions = [];
|
|
4481
4509
|
instructions = [];
|
|
4482
4510
|
postInstructions = [];
|
|
@@ -4490,14 +4518,13 @@ var PerpetualsClient = (function () {
|
|
|
4490
4518
|
.unstakeRequest({
|
|
4491
4519
|
unstakeAmount: unstakeAmount
|
|
4492
4520
|
})
|
|
4493
|
-
.
|
|
4521
|
+
.accountsPartial({
|
|
4494
4522
|
owner: publicKey,
|
|
4495
4523
|
perpetuals: this.perpetuals.publicKey,
|
|
4496
4524
|
pool: pool,
|
|
4497
4525
|
flpStakeAccount: flpStakeAccount,
|
|
4498
4526
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
4499
4527
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4500
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
4501
4528
|
program: this.programId
|
|
4502
4529
|
})
|
|
4503
4530
|
.instruction()];
|
|
@@ -4558,7 +4585,7 @@ var PerpetualsClient = (function () {
|
|
|
4558
4585
|
pendingActivation: pendingActivation,
|
|
4559
4586
|
deactivated: deactivated
|
|
4560
4587
|
})
|
|
4561
|
-
.
|
|
4588
|
+
.accountsPartial({
|
|
4562
4589
|
owner: publicKey,
|
|
4563
4590
|
receivingLpTokenAccount: userLpTokenAccount,
|
|
4564
4591
|
transferAuthority: poolConfig.transferAuthority,
|
|
@@ -4568,7 +4595,6 @@ var PerpetualsClient = (function () {
|
|
|
4568
4595
|
poolStakedLpVault: poolStakedLpVault,
|
|
4569
4596
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
4570
4597
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4571
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
4572
4598
|
program: this.program.programId,
|
|
4573
4599
|
lpMint: poolConfig.stakedLpTokenMint,
|
|
4574
4600
|
})
|
|
@@ -4595,10 +4621,10 @@ var PerpetualsClient = (function () {
|
|
|
4595
4621
|
args_1[_i - 3] = arguments[_i];
|
|
4596
4622
|
}
|
|
4597
4623
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
|
4598
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, tokenStakeAccounts, withdrawStakeInstruction, err_15;
|
|
4624
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_15;
|
|
4599
4625
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
4600
|
-
return __generator(this, function (
|
|
4601
|
-
switch (
|
|
4626
|
+
return __generator(this, function (_b) {
|
|
4627
|
+
switch (_b.label) {
|
|
4602
4628
|
case 0:
|
|
4603
4629
|
publicKey = this.provider.wallet.publicKey;
|
|
4604
4630
|
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
|
@@ -4607,13 +4633,22 @@ var PerpetualsClient = (function () {
|
|
|
4607
4633
|
instructions = [];
|
|
4608
4634
|
postInstructions = [];
|
|
4609
4635
|
additionalSigners = [];
|
|
4610
|
-
|
|
4636
|
+
_b.label = 1;
|
|
4611
4637
|
case 1:
|
|
4612
|
-
|
|
4638
|
+
_b.trys.push([1, 5, , 6]);
|
|
4613
4639
|
pool = poolConfig.poolAddress;
|
|
4614
4640
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
|
|
4615
4641
|
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
|
4616
|
-
|
|
4642
|
+
_a = createUserATA;
|
|
4643
|
+
if (!_a) return [3, 3];
|
|
4644
|
+
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
|
4645
|
+
case 2:
|
|
4646
|
+
_a = !(_b.sent());
|
|
4647
|
+
_b.label = 3;
|
|
4648
|
+
case 3:
|
|
4649
|
+
if (_a) {
|
|
4650
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
|
4651
|
+
}
|
|
4617
4652
|
tokenStakeAccounts = [];
|
|
4618
4653
|
if (tokenStakeAccount) {
|
|
4619
4654
|
tokenStakeAccounts.push({
|
|
@@ -4624,7 +4659,7 @@ var PerpetualsClient = (function () {
|
|
|
4624
4659
|
}
|
|
4625
4660
|
return [4, this.program.methods
|
|
4626
4661
|
.collectStakeFees({})
|
|
4627
|
-
.
|
|
4662
|
+
.accountsPartial({
|
|
4628
4663
|
owner: publicKey,
|
|
4629
4664
|
receivingTokenAccount: receivingTokenAccount,
|
|
4630
4665
|
transferAuthority: poolConfig.transferAuthority,
|
|
@@ -4636,21 +4671,20 @@ var PerpetualsClient = (function () {
|
|
|
4636
4671
|
program: this.program.programId,
|
|
4637
4672
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
4638
4673
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4639
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
4640
4674
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
4641
4675
|
receivingMint: rewardCustodyMint,
|
|
4642
4676
|
})
|
|
4643
4677
|
.remainingAccounts(__spreadArray([], tokenStakeAccounts, true))
|
|
4644
4678
|
.instruction()];
|
|
4645
|
-
case
|
|
4646
|
-
withdrawStakeInstruction =
|
|
4679
|
+
case 4:
|
|
4680
|
+
withdrawStakeInstruction = _b.sent();
|
|
4647
4681
|
instructions.push(withdrawStakeInstruction);
|
|
4648
|
-
return [3,
|
|
4649
|
-
case
|
|
4650
|
-
err_15 =
|
|
4682
|
+
return [3, 6];
|
|
4683
|
+
case 5:
|
|
4684
|
+
err_15 = _b.sent();
|
|
4651
4685
|
console.log("perpClient withdrawStake error:: ", err_15);
|
|
4652
4686
|
throw err_15;
|
|
4653
|
-
case
|
|
4687
|
+
case 6: return [2, {
|
|
4654
4688
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4655
4689
|
additionalSigners: additionalSigners
|
|
4656
4690
|
}];
|
|
@@ -4709,21 +4743,29 @@ var PerpetualsClient = (function () {
|
|
|
4709
4743
|
isWritable: false,
|
|
4710
4744
|
});
|
|
4711
4745
|
}
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
if (!(
|
|
4746
|
+
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
|
4747
|
+
case 1:
|
|
4748
|
+
if (!(_f.sent())) {
|
|
4749
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
|
4750
|
+
}
|
|
4751
|
+
return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
|
|
4752
|
+
case 2:
|
|
4753
|
+
if (!(_f.sent())) {
|
|
4754
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
|
|
4755
|
+
}
|
|
4756
|
+
if (!(inTokenSymbol == 'SOL')) return [3, 5];
|
|
4715
4757
|
console.log("inTokenSymbol === SOL", inTokenSymbol);
|
|
4716
4758
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
|
4717
|
-
if (!!skipBalanceChecks) return [3,
|
|
4759
|
+
if (!!skipBalanceChecks) return [3, 4];
|
|
4718
4760
|
_e = anchor_1.BN.bind;
|
|
4719
4761
|
return [4, this.provider.connection.getBalance(publicKey)];
|
|
4720
|
-
case
|
|
4762
|
+
case 3:
|
|
4721
4763
|
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
|
4722
4764
|
if (unWrappedSolBalance.lt(lamports)) {
|
|
4723
4765
|
throw "Insufficient SOL Funds";
|
|
4724
4766
|
}
|
|
4725
|
-
_f.label =
|
|
4726
|
-
case
|
|
4767
|
+
_f.label = 4;
|
|
4768
|
+
case 4:
|
|
4727
4769
|
if (!ephemeralSignerPubkey) {
|
|
4728
4770
|
wrappedSolAccount = new web3_js_1.Keypair();
|
|
4729
4771
|
additionalSigners.push(wrappedSolAccount);
|
|
@@ -4741,17 +4783,17 @@ var PerpetualsClient = (function () {
|
|
|
4741
4783
|
postInstructions = [
|
|
4742
4784
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
4743
4785
|
];
|
|
4744
|
-
return [3,
|
|
4745
|
-
case
|
|
4746
|
-
if (!!skipBalanceChecks) return [3,
|
|
4786
|
+
return [3, 7];
|
|
4787
|
+
case 5:
|
|
4788
|
+
if (!!skipBalanceChecks) return [3, 7];
|
|
4747
4789
|
return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
|
|
4748
|
-
case
|
|
4790
|
+
case 6:
|
|
4749
4791
|
if (!(_f.sent())) {
|
|
4750
4792
|
throw "Insufficient Funds , token Account doesn't exist";
|
|
4751
4793
|
}
|
|
4752
|
-
_f.label =
|
|
4753
|
-
case
|
|
4754
|
-
_f.trys.push([
|
|
4794
|
+
_f.label = 7;
|
|
4795
|
+
case 7:
|
|
4796
|
+
_f.trys.push([7, 9, , 10]);
|
|
4755
4797
|
if (enableHeapSizeIx) {
|
|
4756
4798
|
heapSizeIx = web3_js_1.ComputeBudgetProgram.requestHeapFrame({
|
|
4757
4799
|
bytes: 64 * 1024,
|
|
@@ -4769,7 +4811,7 @@ var PerpetualsClient = (function () {
|
|
|
4769
4811
|
amountIn: amountIn,
|
|
4770
4812
|
minCompoundingAmountOut: minCompoundingAmountOut
|
|
4771
4813
|
})
|
|
4772
|
-
.
|
|
4814
|
+
.accountsPartial({
|
|
4773
4815
|
owner: publicKey,
|
|
4774
4816
|
fundingAccount: inTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : fundingAccount,
|
|
4775
4817
|
compoundingTokenAccount: compoundingTokenAccount,
|
|
@@ -4785,7 +4827,6 @@ var PerpetualsClient = (function () {
|
|
|
4785
4827
|
lpTokenMint: lpTokenMint,
|
|
4786
4828
|
compoundingTokenMint: compoundingTokenMint,
|
|
4787
4829
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4788
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
4789
4830
|
program: this.program.programId,
|
|
4790
4831
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
4791
4832
|
fundingMint: inCustodyConfig.mintKey,
|
|
@@ -4793,15 +4834,15 @@ var PerpetualsClient = (function () {
|
|
|
4793
4834
|
})
|
|
4794
4835
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
4795
4836
|
.instruction()];
|
|
4796
|
-
case
|
|
4837
|
+
case 8:
|
|
4797
4838
|
addCompoundingLiquidity = _f.sent();
|
|
4798
4839
|
instructions.push(addCompoundingLiquidity);
|
|
4799
|
-
return [3,
|
|
4800
|
-
case
|
|
4840
|
+
return [3, 10];
|
|
4841
|
+
case 9:
|
|
4801
4842
|
err_16 = _f.sent();
|
|
4802
4843
|
console.log("perpClient addCompoundingLiquidity error:: ", err_16);
|
|
4803
|
-
return [3,
|
|
4804
|
-
case
|
|
4844
|
+
return [3, 10];
|
|
4845
|
+
case 10: return [2, {
|
|
4805
4846
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4806
4847
|
additionalSigners: additionalSigners
|
|
4807
4848
|
}];
|
|
@@ -4815,14 +4856,14 @@ var PerpetualsClient = (function () {
|
|
|
4815
4856
|
args_1[_i - 5] = arguments[_i];
|
|
4816
4857
|
}
|
|
4817
4858
|
return __awaiter(_this, __spreadArray([compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey, userPublicKey, enableHeapSizeIx, isWhitelistedUser) {
|
|
4818
|
-
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, custodyAccountMetas, custodyOracleAccountMetas, markets,
|
|
4859
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, compoundingTokenAccount, heapSizeIx, whitelistPda, whitelistMeta, removeCompoundingLiquidity, err_17;
|
|
4819
4860
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
4820
4861
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
4821
4862
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
4822
4863
|
if (enableHeapSizeIx === void 0) { enableHeapSizeIx = true; }
|
|
4823
4864
|
if (isWhitelistedUser === void 0) { isWhitelistedUser = false; }
|
|
4824
|
-
return __generator(this, function (
|
|
4825
|
-
switch (
|
|
4865
|
+
return __generator(this, function (_f) {
|
|
4866
|
+
switch (_f.label) {
|
|
4826
4867
|
case 0:
|
|
4827
4868
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
|
4828
4869
|
preInstructions = [];
|
|
@@ -4833,35 +4874,45 @@ var PerpetualsClient = (function () {
|
|
|
4833
4874
|
outCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(outTokenSymbol).mintKey); });
|
|
4834
4875
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
|
4835
4876
|
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
|
4836
|
-
if (outCustodyConfig.symbol == 'SOL')
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
}
|
|
4842
|
-
preInstructions = [
|
|
4843
|
-
web3_js_1.SystemProgram.createAccount({
|
|
4844
|
-
fromPubkey: publicKey,
|
|
4845
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
4846
|
-
lamports: lamports,
|
|
4847
|
-
space: 165,
|
|
4848
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4849
|
-
}),
|
|
4850
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
4851
|
-
];
|
|
4852
|
-
postInstructions = [
|
|
4853
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
4854
|
-
];
|
|
4877
|
+
if (!(outCustodyConfig.symbol == 'SOL')) return [3, 1];
|
|
4878
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
|
4879
|
+
if (!ephemeralSignerPubkey) {
|
|
4880
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
4881
|
+
additionalSigners.push(wrappedSolAccount);
|
|
4855
4882
|
}
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4883
|
+
preInstructions = [
|
|
4884
|
+
web3_js_1.SystemProgram.createAccount({
|
|
4885
|
+
fromPubkey: publicKey,
|
|
4886
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
4887
|
+
lamports: lamports,
|
|
4888
|
+
space: 165,
|
|
4889
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4890
|
+
}),
|
|
4891
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
4892
|
+
];
|
|
4893
|
+
postInstructions = [
|
|
4894
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
4895
|
+
];
|
|
4896
|
+
return [3, 4];
|
|
4897
|
+
case 1:
|
|
4898
|
+
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);
|
|
4899
|
+
_a = createUserATA;
|
|
4900
|
+
if (!_a) return [3, 3];
|
|
4901
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
4902
|
+
case 2:
|
|
4903
|
+
_a = !(_f.sent());
|
|
4904
|
+
_f.label = 3;
|
|
4905
|
+
case 3:
|
|
4906
|
+
if (_a) {
|
|
4907
|
+
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));
|
|
4859
4908
|
}
|
|
4909
|
+
_f.label = 4;
|
|
4910
|
+
case 4:
|
|
4860
4911
|
custodyAccountMetas = [];
|
|
4861
4912
|
custodyOracleAccountMetas = [];
|
|
4862
4913
|
markets = [];
|
|
4863
|
-
for (
|
|
4864
|
-
custody = _b
|
|
4914
|
+
for (_b = 0, _c = poolConfig.custodies; _b < _c.length; _b++) {
|
|
4915
|
+
custody = _c[_b];
|
|
4865
4916
|
custodyAccountMetas.push({
|
|
4866
4917
|
pubkey: custody.custodyAccount,
|
|
4867
4918
|
isSigner: false,
|
|
@@ -4873,8 +4924,8 @@ var PerpetualsClient = (function () {
|
|
|
4873
4924
|
isWritable: false,
|
|
4874
4925
|
});
|
|
4875
4926
|
}
|
|
4876
|
-
for (
|
|
4877
|
-
market = _d
|
|
4927
|
+
for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
|
|
4928
|
+
market = _e[_d];
|
|
4878
4929
|
markets.push({
|
|
4879
4930
|
pubkey: market.marketAccount,
|
|
4880
4931
|
isSigner: false,
|
|
@@ -4882,9 +4933,9 @@ var PerpetualsClient = (function () {
|
|
|
4882
4933
|
});
|
|
4883
4934
|
}
|
|
4884
4935
|
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
|
4885
|
-
|
|
4886
|
-
case
|
|
4887
|
-
|
|
4936
|
+
_f.label = 5;
|
|
4937
|
+
case 5:
|
|
4938
|
+
_f.trys.push([5, 7, , 8]);
|
|
4888
4939
|
if (enableHeapSizeIx) {
|
|
4889
4940
|
heapSizeIx = web3_js_1.ComputeBudgetProgram.requestHeapFrame({
|
|
4890
4941
|
bytes: 64 * 1024,
|
|
@@ -4902,7 +4953,7 @@ var PerpetualsClient = (function () {
|
|
|
4902
4953
|
compoundingAmountIn: compoundingAmountIn,
|
|
4903
4954
|
minAmountOut: minAmountOut
|
|
4904
4955
|
})
|
|
4905
|
-
.
|
|
4956
|
+
.accountsPartial({
|
|
4906
4957
|
owner: publicKey,
|
|
4907
4958
|
receivingAccount: outCustodyConfig.symbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
|
4908
4959
|
compoundingTokenAccount: compoundingTokenAccount,
|
|
@@ -4918,7 +4969,6 @@ var PerpetualsClient = (function () {
|
|
|
4918
4969
|
lpTokenMint: lpTokenMint,
|
|
4919
4970
|
compoundingTokenMint: compoundingTokenMint,
|
|
4920
4971
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
4921
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
4922
4972
|
program: this.program.programId,
|
|
4923
4973
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
4924
4974
|
receivingMint: outCustodyConfig.mintKey,
|
|
@@ -4926,15 +4976,15 @@ var PerpetualsClient = (function () {
|
|
|
4926
4976
|
})
|
|
4927
4977
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
4928
4978
|
.instruction()];
|
|
4929
|
-
case
|
|
4930
|
-
removeCompoundingLiquidity =
|
|
4979
|
+
case 6:
|
|
4980
|
+
removeCompoundingLiquidity = _f.sent();
|
|
4931
4981
|
instructions.push(removeCompoundingLiquidity);
|
|
4932
|
-
return [3,
|
|
4933
|
-
case
|
|
4934
|
-
err_17 =
|
|
4982
|
+
return [3, 8];
|
|
4983
|
+
case 7:
|
|
4984
|
+
err_17 = _f.sent();
|
|
4935
4985
|
console.log("perpClient removeCompoundingLiquidity error:: ", err_17);
|
|
4936
|
-
return [3,
|
|
4937
|
-
case
|
|
4986
|
+
return [3, 8];
|
|
4987
|
+
case 8: return [2, {
|
|
4938
4988
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
4939
4989
|
additionalSigners: additionalSigners
|
|
4940
4990
|
}];
|
|
@@ -4947,13 +4997,13 @@ var PerpetualsClient = (function () {
|
|
|
4947
4997
|
for (var _i = 3; _i < arguments.length; _i++) {
|
|
4948
4998
|
args_1[_i - 3] = arguments[_i];
|
|
4949
4999
|
}
|
|
4950
|
-
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA
|
|
4951
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts,
|
|
5000
|
+
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
|
5001
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _b, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, migrateStake, err_18;
|
|
4952
5002
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
4953
|
-
return __generator(this, function (
|
|
4954
|
-
switch (
|
|
5003
|
+
return __generator(this, function (_g) {
|
|
5004
|
+
switch (_g.label) {
|
|
4955
5005
|
case 0:
|
|
4956
|
-
publicKey =
|
|
5006
|
+
publicKey = this.provider.wallet.publicKey;
|
|
4957
5007
|
preInstructions = [];
|
|
4958
5008
|
instructions = [];
|
|
4959
5009
|
postInstructions = [];
|
|
@@ -4962,18 +5012,27 @@ var PerpetualsClient = (function () {
|
|
|
4962
5012
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
|
4963
5013
|
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
|
4964
5014
|
compoudingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
|
4965
|
-
|
|
4966
|
-
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
|
4967
|
-
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), publicKey.toBuffer()], this.programId)[0];
|
|
4968
|
-
tokenStakeAccounts = [];
|
|
4969
|
-
_a = tokenStakeAccount;
|
|
5015
|
+
_a = createUserATA;
|
|
4970
5016
|
if (!_a) return [3, 2];
|
|
4971
|
-
return [4, (0, utils_1.checkIfAccountExists)(
|
|
5017
|
+
return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
|
|
4972
5018
|
case 1:
|
|
4973
|
-
_a = (
|
|
4974
|
-
|
|
5019
|
+
_a = !(_g.sent());
|
|
5020
|
+
_g.label = 2;
|
|
4975
5021
|
case 2:
|
|
4976
5022
|
if (_a) {
|
|
5023
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
|
|
5024
|
+
}
|
|
5025
|
+
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
|
5026
|
+
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), publicKey.toBuffer()], this.programId)[0];
|
|
5027
|
+
tokenStakeAccounts = [];
|
|
5028
|
+
_b = tokenStakeAccount;
|
|
5029
|
+
if (!_b) return [3, 4];
|
|
5030
|
+
return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
|
|
5031
|
+
case 3:
|
|
5032
|
+
_b = (_g.sent());
|
|
5033
|
+
_g.label = 4;
|
|
5034
|
+
case 4:
|
|
5035
|
+
if (_b) {
|
|
4977
5036
|
tokenStakeAccounts.push({
|
|
4978
5037
|
pubkey: tokenStakeAccount,
|
|
4979
5038
|
isSigner: false,
|
|
@@ -4984,8 +5043,8 @@ var PerpetualsClient = (function () {
|
|
|
4984
5043
|
custodyAccountMetas = [];
|
|
4985
5044
|
custodyOracleAccountMetas = [];
|
|
4986
5045
|
markets = [];
|
|
4987
|
-
for (
|
|
4988
|
-
custody = _c
|
|
5046
|
+
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
|
5047
|
+
custody = _d[_c];
|
|
4989
5048
|
custodyAccountMetas.push({
|
|
4990
5049
|
pubkey: custody.custodyAccount,
|
|
4991
5050
|
isSigner: false,
|
|
@@ -4997,22 +5056,22 @@ var PerpetualsClient = (function () {
|
|
|
4997
5056
|
isWritable: false,
|
|
4998
5057
|
});
|
|
4999
5058
|
}
|
|
5000
|
-
for (
|
|
5001
|
-
market = _e
|
|
5059
|
+
for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
|
|
5060
|
+
market = _f[_e];
|
|
5002
5061
|
markets.push({
|
|
5003
5062
|
pubkey: market.marketAccount,
|
|
5004
5063
|
isSigner: false,
|
|
5005
5064
|
isWritable: false,
|
|
5006
5065
|
});
|
|
5007
5066
|
}
|
|
5008
|
-
|
|
5009
|
-
case
|
|
5010
|
-
|
|
5067
|
+
_g.label = 5;
|
|
5068
|
+
case 5:
|
|
5069
|
+
_g.trys.push([5, 7, , 8]);
|
|
5011
5070
|
return [4, this.program.methods
|
|
5012
5071
|
.migrateStake({
|
|
5013
5072
|
amount: amount
|
|
5014
5073
|
})
|
|
5015
|
-
.
|
|
5074
|
+
.accountsPartial({
|
|
5016
5075
|
owner: publicKey,
|
|
5017
5076
|
compoundingTokenAccount: compoudingTokenAccount,
|
|
5018
5077
|
transferAuthority: poolConfig.transferAuthority,
|
|
@@ -5026,21 +5085,20 @@ var PerpetualsClient = (function () {
|
|
|
5026
5085
|
lpTokenMint: lpTokenMint,
|
|
5027
5086
|
compoundingTokenMint: compoundingTokenMint,
|
|
5028
5087
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5029
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5030
5088
|
program: this.program.programId,
|
|
5031
5089
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
|
5032
5090
|
})
|
|
5033
5091
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
|
|
5034
5092
|
.instruction()];
|
|
5035
|
-
case
|
|
5036
|
-
migrateStake =
|
|
5093
|
+
case 6:
|
|
5094
|
+
migrateStake = _g.sent();
|
|
5037
5095
|
instructions.push(migrateStake);
|
|
5038
|
-
return [3,
|
|
5039
|
-
case
|
|
5040
|
-
err_18 =
|
|
5096
|
+
return [3, 8];
|
|
5097
|
+
case 7:
|
|
5098
|
+
err_18 = _g.sent();
|
|
5041
5099
|
console.log("perpClient migrateStake error:: ", err_18);
|
|
5042
|
-
return [3,
|
|
5043
|
-
case
|
|
5100
|
+
return [3, 8];
|
|
5101
|
+
case 8: return [2, {
|
|
5044
5102
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5045
5103
|
additionalSigners: additionalSigners
|
|
5046
5104
|
}];
|
|
@@ -5048,12 +5106,12 @@ var PerpetualsClient = (function () {
|
|
|
5048
5106
|
});
|
|
5049
5107
|
});
|
|
5050
5108
|
};
|
|
5051
|
-
this.migrateFlp = function (amount, rewardTokenMint, poolConfig
|
|
5109
|
+
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
5052
5110
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_19;
|
|
5053
5111
|
return __generator(this, function (_d) {
|
|
5054
5112
|
switch (_d.label) {
|
|
5055
5113
|
case 0:
|
|
5056
|
-
publicKey =
|
|
5114
|
+
publicKey = this.provider.wallet.publicKey;
|
|
5057
5115
|
preInstructions = [];
|
|
5058
5116
|
instructions = [];
|
|
5059
5117
|
postInstructions = [];
|
|
@@ -5095,7 +5153,7 @@ var PerpetualsClient = (function () {
|
|
|
5095
5153
|
.migrateFlp({
|
|
5096
5154
|
compoundingTokenAmount: amount
|
|
5097
5155
|
})
|
|
5098
|
-
.
|
|
5156
|
+
.accountsPartial({
|
|
5099
5157
|
owner: publicKey,
|
|
5100
5158
|
compoundingTokenAccount: compoudingTokenAccount,
|
|
5101
5159
|
transferAuthority: poolConfig.transferAuthority,
|
|
@@ -5110,7 +5168,6 @@ var PerpetualsClient = (function () {
|
|
|
5110
5168
|
compoundingTokenMint: compoundingTokenMint,
|
|
5111
5169
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
5112
5170
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5113
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5114
5171
|
program: this.program.programId,
|
|
5115
5172
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
|
5116
5173
|
})
|
|
@@ -5175,7 +5232,7 @@ var PerpetualsClient = (function () {
|
|
|
5175
5232
|
_e.trys.push([1, 3, , 4]);
|
|
5176
5233
|
return [4, this.program.methods
|
|
5177
5234
|
.compoundFees({})
|
|
5178
|
-
.
|
|
5235
|
+
.accountsPartial({
|
|
5179
5236
|
poolCompoundingLpVault: poolConfig.compoundingLpVault,
|
|
5180
5237
|
transferAuthority: poolConfig.transferAuthority,
|
|
5181
5238
|
perpetuals: poolConfig.perpetuals,
|
|
@@ -5184,7 +5241,6 @@ var PerpetualsClient = (function () {
|
|
|
5184
5241
|
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
|
5185
5242
|
lpTokenMint: lpTokenMint,
|
|
5186
5243
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5187
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5188
5244
|
program: this.program.programId,
|
|
5189
5245
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
|
5190
5246
|
})
|
|
@@ -5217,15 +5273,19 @@ var PerpetualsClient = (function () {
|
|
|
5217
5273
|
additionalSigners = [];
|
|
5218
5274
|
_a.label = 1;
|
|
5219
5275
|
case 1:
|
|
5220
|
-
_a.trys.push([1,
|
|
5276
|
+
_a.trys.push([1, 4, , 5]);
|
|
5221
5277
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5222
5278
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5223
|
-
|
|
5279
|
+
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5280
|
+
case 2:
|
|
5281
|
+
if (!(_a.sent())) {
|
|
5282
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(feePayer, userTokenAccount, owner, poolConfig.tokenMint));
|
|
5283
|
+
}
|
|
5224
5284
|
return [4, this.program.methods
|
|
5225
5285
|
.depositTokenStake({
|
|
5226
5286
|
depositAmount: depositAmount
|
|
5227
5287
|
})
|
|
5228
|
-
.
|
|
5288
|
+
.accountsPartial({
|
|
5229
5289
|
owner: owner,
|
|
5230
5290
|
feePayer: feePayer,
|
|
5231
5291
|
fundingTokenAccount: userTokenAccount,
|
|
@@ -5235,20 +5295,18 @@ var PerpetualsClient = (function () {
|
|
|
5235
5295
|
tokenStakeAccount: tokenStakeAccount,
|
|
5236
5296
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
5237
5297
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5238
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5239
|
-
program: this.programId,
|
|
5240
5298
|
tokenMint: poolConfig.tokenMint,
|
|
5241
5299
|
})
|
|
5242
5300
|
.instruction()];
|
|
5243
|
-
case
|
|
5301
|
+
case 3:
|
|
5244
5302
|
depositTokenStakeInstruction = _a.sent();
|
|
5245
5303
|
instructions.push(depositTokenStakeInstruction);
|
|
5246
|
-
return [3,
|
|
5247
|
-
case
|
|
5304
|
+
return [3, 5];
|
|
5305
|
+
case 4:
|
|
5248
5306
|
err_21 = _a.sent();
|
|
5249
5307
|
console.log("perpClient depositStakingInstruction error:: ", err_21);
|
|
5250
5308
|
throw err_21;
|
|
5251
|
-
case
|
|
5309
|
+
case 5: return [2, {
|
|
5252
5310
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5253
5311
|
additionalSigners: additionalSigners
|
|
5254
5312
|
}];
|
|
@@ -5272,11 +5330,10 @@ var PerpetualsClient = (function () {
|
|
|
5272
5330
|
.unstakeTokenRequest({
|
|
5273
5331
|
unstakeAmount: unstakeAmount
|
|
5274
5332
|
})
|
|
5275
|
-
.
|
|
5333
|
+
.accountsPartial({
|
|
5276
5334
|
owner: owner,
|
|
5277
5335
|
tokenVault: poolConfig.tokenVault,
|
|
5278
5336
|
tokenStakeAccount: tokenStakeAccount,
|
|
5279
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5280
5337
|
program: this.programId
|
|
5281
5338
|
})
|
|
5282
5339
|
.instruction()];
|
|
@@ -5306,15 +5363,19 @@ var PerpetualsClient = (function () {
|
|
|
5306
5363
|
additionalSigners = [];
|
|
5307
5364
|
_a.label = 1;
|
|
5308
5365
|
case 1:
|
|
5309
|
-
_a.trys.push([1,
|
|
5366
|
+
_a.trys.push([1, 4, , 5]);
|
|
5310
5367
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5311
5368
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5312
|
-
|
|
5369
|
+
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5370
|
+
case 2:
|
|
5371
|
+
if (!(_a.sent())) {
|
|
5372
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(this.provider.wallet.publicKey, userTokenAccount, owner, poolConfig.tokenMint));
|
|
5373
|
+
}
|
|
5313
5374
|
return [4, this.program.methods
|
|
5314
5375
|
.unstakeTokenInstant({
|
|
5315
5376
|
unstakeAmount: unstakeAmount
|
|
5316
5377
|
})
|
|
5317
|
-
.
|
|
5378
|
+
.accountsPartial({
|
|
5318
5379
|
owner: owner,
|
|
5319
5380
|
receivingTokenAccount: userTokenAccount,
|
|
5320
5381
|
perpetuals: poolConfig.perpetuals,
|
|
@@ -5323,20 +5384,18 @@ var PerpetualsClient = (function () {
|
|
|
5323
5384
|
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
|
5324
5385
|
tokenStakeAccount: tokenStakeAccount,
|
|
5325
5386
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5326
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5327
|
-
program: this.programId,
|
|
5328
5387
|
tokenMint: poolConfig.tokenMint,
|
|
5329
5388
|
})
|
|
5330
5389
|
.instruction()];
|
|
5331
|
-
case
|
|
5390
|
+
case 3:
|
|
5332
5391
|
unstakeTokenInstantInstruction = _a.sent();
|
|
5333
5392
|
instructions.push(unstakeTokenInstantInstruction);
|
|
5334
|
-
return [3,
|
|
5335
|
-
case
|
|
5393
|
+
return [3, 5];
|
|
5394
|
+
case 4:
|
|
5336
5395
|
err_23 = _a.sent();
|
|
5337
5396
|
console.log("perpClient unstakeTokenInstantInstruction error:: ", err_23);
|
|
5338
5397
|
throw err_23;
|
|
5339
|
-
case
|
|
5398
|
+
case 5: return [2, {
|
|
5340
5399
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5341
5400
|
additionalSigners: additionalSigners
|
|
5342
5401
|
}];
|
|
@@ -5354,15 +5413,19 @@ var PerpetualsClient = (function () {
|
|
|
5354
5413
|
additionalSigners = [];
|
|
5355
5414
|
_a.label = 1;
|
|
5356
5415
|
case 1:
|
|
5357
|
-
_a.trys.push([1,
|
|
5416
|
+
_a.trys.push([1, 4, , 5]);
|
|
5358
5417
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5359
5418
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5360
|
-
|
|
5419
|
+
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5420
|
+
case 2:
|
|
5421
|
+
if (!(_a.sent())) {
|
|
5422
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(this.provider.wallet.publicKey, userTokenAccount, owner, poolConfig.tokenMint));
|
|
5423
|
+
}
|
|
5361
5424
|
return [4, this.program.methods
|
|
5362
5425
|
.withdrawToken({
|
|
5363
5426
|
withdrawRequestId: withdrawRequestId
|
|
5364
5427
|
})
|
|
5365
|
-
.
|
|
5428
|
+
.accountsPartial({
|
|
5366
5429
|
owner: owner,
|
|
5367
5430
|
receivingTokenAccount: userTokenAccount,
|
|
5368
5431
|
perpetuals: this.perpetuals.publicKey,
|
|
@@ -5371,20 +5434,18 @@ var PerpetualsClient = (function () {
|
|
|
5371
5434
|
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
|
5372
5435
|
tokenStakeAccount: tokenStakeAccount,
|
|
5373
5436
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5374
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5375
|
-
program: this.programId,
|
|
5376
5437
|
tokenMint: poolConfig.tokenMint,
|
|
5377
5438
|
})
|
|
5378
5439
|
.instruction()];
|
|
5379
|
-
case
|
|
5440
|
+
case 3:
|
|
5380
5441
|
withdrawTokenInstruction = _a.sent();
|
|
5381
5442
|
instructions.push(withdrawTokenInstruction);
|
|
5382
|
-
return [3,
|
|
5383
|
-
case
|
|
5443
|
+
return [3, 5];
|
|
5444
|
+
case 4:
|
|
5384
5445
|
err_24 = _a.sent();
|
|
5385
5446
|
console.log("perpClient withdrawTokenInstruction error:: ", err_24);
|
|
5386
5447
|
throw err_24;
|
|
5387
|
-
case
|
|
5448
|
+
case 5: return [2, {
|
|
5388
5449
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5389
5450
|
additionalSigners: additionalSigners
|
|
5390
5451
|
}];
|
|
@@ -5408,11 +5469,10 @@ var PerpetualsClient = (function () {
|
|
|
5408
5469
|
.cancelUnstakeTokenRequest({
|
|
5409
5470
|
withdrawRequestId: withdrawRequestId
|
|
5410
5471
|
})
|
|
5411
|
-
.
|
|
5472
|
+
.accountsPartial({
|
|
5412
5473
|
owner: owner,
|
|
5413
5474
|
tokenVault: poolConfig.tokenVault,
|
|
5414
5475
|
tokenStakeAccount: tokenStakeAccount,
|
|
5415
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5416
5476
|
program: this.programId
|
|
5417
5477
|
})
|
|
5418
5478
|
.instruction()];
|
|
@@ -5436,26 +5496,35 @@ var PerpetualsClient = (function () {
|
|
|
5436
5496
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
5437
5497
|
args_1[_i - 2] = arguments[_i];
|
|
5438
5498
|
}
|
|
5439
|
-
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA
|
|
5440
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, collectTokenRewardInstruction, err_26;
|
|
5499
|
+
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
|
5500
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_26;
|
|
5441
5501
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5442
|
-
return __generator(this, function (
|
|
5443
|
-
switch (
|
|
5502
|
+
return __generator(this, function (_b) {
|
|
5503
|
+
switch (_b.label) {
|
|
5444
5504
|
case 0:
|
|
5445
|
-
publicKey =
|
|
5505
|
+
publicKey = this.provider.wallet.publicKey;
|
|
5446
5506
|
preInstructions = [];
|
|
5447
5507
|
instructions = [];
|
|
5448
5508
|
postInstructions = [];
|
|
5449
5509
|
additionalSigners = [];
|
|
5450
|
-
|
|
5510
|
+
_b.label = 1;
|
|
5451
5511
|
case 1:
|
|
5452
|
-
|
|
5512
|
+
_b.trys.push([1, 5, , 6]);
|
|
5453
5513
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5454
5514
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, owner, true);
|
|
5455
|
-
|
|
5515
|
+
_a = createUserATA;
|
|
5516
|
+
if (!_a) return [3, 3];
|
|
5517
|
+
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5518
|
+
case 2:
|
|
5519
|
+
_a = !(_b.sent());
|
|
5520
|
+
_b.label = 3;
|
|
5521
|
+
case 3:
|
|
5522
|
+
if (_a) {
|
|
5523
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, poolConfig.tokenMint));
|
|
5524
|
+
}
|
|
5456
5525
|
return [4, this.program.methods
|
|
5457
5526
|
.collectTokenReward({})
|
|
5458
|
-
.
|
|
5527
|
+
.accountsPartial({
|
|
5459
5528
|
owner: owner,
|
|
5460
5529
|
receivingTokenAccount: userTokenAccount,
|
|
5461
5530
|
perpetuals: this.perpetuals.publicKey,
|
|
@@ -5464,20 +5533,18 @@ var PerpetualsClient = (function () {
|
|
|
5464
5533
|
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
|
5465
5534
|
tokenStakeAccount: tokenStakeAccount,
|
|
5466
5535
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5467
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5468
|
-
program: this.programId,
|
|
5469
5536
|
tokenMint: poolConfig.tokenMint,
|
|
5470
5537
|
})
|
|
5471
5538
|
.instruction()];
|
|
5472
|
-
case
|
|
5473
|
-
collectTokenRewardInstruction =
|
|
5539
|
+
case 4:
|
|
5540
|
+
collectTokenRewardInstruction = _b.sent();
|
|
5474
5541
|
instructions.push(collectTokenRewardInstruction);
|
|
5475
|
-
return [3,
|
|
5476
|
-
case
|
|
5477
|
-
err_26 =
|
|
5542
|
+
return [3, 6];
|
|
5543
|
+
case 5:
|
|
5544
|
+
err_26 = _b.sent();
|
|
5478
5545
|
console.log("perpClient collectTokenRewardInstruction error:: ", err_26);
|
|
5479
5546
|
throw err_26;
|
|
5480
|
-
case
|
|
5547
|
+
case 6: return [2, {
|
|
5481
5548
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5482
5549
|
additionalSigners: additionalSigners
|
|
5483
5550
|
}];
|
|
@@ -5491,26 +5558,35 @@ var PerpetualsClient = (function () {
|
|
|
5491
5558
|
args_1[_i - 3] = arguments[_i];
|
|
5492
5559
|
}
|
|
5493
5560
|
return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
|
|
5494
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, collectRevenueInstruction, err_27;
|
|
5561
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_27;
|
|
5495
5562
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5496
|
-
return __generator(this, function (
|
|
5497
|
-
switch (
|
|
5563
|
+
return __generator(this, function (_b) {
|
|
5564
|
+
switch (_b.label) {
|
|
5498
5565
|
case 0:
|
|
5499
5566
|
publicKey = this.provider.wallet.publicKey;
|
|
5500
5567
|
preInstructions = [];
|
|
5501
5568
|
instructions = [];
|
|
5502
5569
|
postInstructions = [];
|
|
5503
5570
|
additionalSigners = [];
|
|
5504
|
-
|
|
5571
|
+
_b.label = 1;
|
|
5505
5572
|
case 1:
|
|
5506
|
-
|
|
5573
|
+
_b.trys.push([1, 5, , 6]);
|
|
5507
5574
|
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
|
5508
5575
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5509
5576
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, owner, true);
|
|
5510
|
-
|
|
5577
|
+
_a = createUserATA;
|
|
5578
|
+
if (!_a) return [3, 3];
|
|
5579
|
+
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5580
|
+
case 2:
|
|
5581
|
+
_a = !(_b.sent());
|
|
5582
|
+
_b.label = 3;
|
|
5583
|
+
case 3:
|
|
5584
|
+
if (_a) {
|
|
5585
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, rewardCustodyMint));
|
|
5586
|
+
}
|
|
5511
5587
|
return [4, this.program.methods
|
|
5512
5588
|
.collectRevenue({})
|
|
5513
|
-
.
|
|
5589
|
+
.accountsPartial({
|
|
5514
5590
|
owner: owner,
|
|
5515
5591
|
receivingRevenueAccount: userTokenAccount,
|
|
5516
5592
|
perpetuals: this.perpetuals.publicKey,
|
|
@@ -5519,20 +5595,18 @@ var PerpetualsClient = (function () {
|
|
|
5519
5595
|
revenueTokenAccount: poolConfig.revenueTokenAccount,
|
|
5520
5596
|
tokenStakeAccount: tokenStakeAccount,
|
|
5521
5597
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5522
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5523
|
-
program: this.programId,
|
|
5524
5598
|
receivingTokenMint: rewardCustodyMint,
|
|
5525
5599
|
})
|
|
5526
5600
|
.instruction()];
|
|
5527
|
-
case
|
|
5528
|
-
collectRevenueInstruction =
|
|
5601
|
+
case 4:
|
|
5602
|
+
collectRevenueInstruction = _b.sent();
|
|
5529
5603
|
instructions.push(collectRevenueInstruction);
|
|
5530
|
-
return [3,
|
|
5531
|
-
case
|
|
5532
|
-
err_27 =
|
|
5604
|
+
return [3, 6];
|
|
5605
|
+
case 5:
|
|
5606
|
+
err_27 = _b.sent();
|
|
5533
5607
|
console.log("perpClient collectRevenueInstruction error:: ", err_27);
|
|
5534
5608
|
throw err_27;
|
|
5535
|
-
case
|
|
5609
|
+
case 6: return [2, {
|
|
5536
5610
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5537
5611
|
additionalSigners: additionalSigners
|
|
5538
5612
|
}];
|
|
@@ -5546,26 +5620,35 @@ var PerpetualsClient = (function () {
|
|
|
5546
5620
|
args_1[_i - 3] = arguments[_i];
|
|
5547
5621
|
}
|
|
5548
5622
|
return __awaiter(_this, __spreadArray([owner_1, rebateSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rebateSymbol, poolConfig, createUserATA) {
|
|
5549
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rebateMint, tokenStakeAccount, userTokenAccount, collectRebateInstruction, err_28;
|
|
5623
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rebateMint, tokenStakeAccount, userTokenAccount, _a, collectRebateInstruction, err_28;
|
|
5550
5624
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5551
|
-
return __generator(this, function (
|
|
5552
|
-
switch (
|
|
5625
|
+
return __generator(this, function (_b) {
|
|
5626
|
+
switch (_b.label) {
|
|
5553
5627
|
case 0:
|
|
5554
5628
|
publicKey = this.provider.wallet.publicKey;
|
|
5555
5629
|
preInstructions = [];
|
|
5556
5630
|
instructions = [];
|
|
5557
5631
|
postInstructions = [];
|
|
5558
5632
|
additionalSigners = [];
|
|
5559
|
-
|
|
5633
|
+
_b.label = 1;
|
|
5560
5634
|
case 1:
|
|
5561
|
-
|
|
5635
|
+
_b.trys.push([1, 5, , 6]);
|
|
5562
5636
|
rebateMint = poolConfig.getTokenFromSymbol(rebateSymbol).mintKey;
|
|
5563
5637
|
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
|
5564
5638
|
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rebateMint, owner, true);
|
|
5565
|
-
|
|
5639
|
+
_a = createUserATA;
|
|
5640
|
+
if (!_a) return [3, 3];
|
|
5641
|
+
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
|
5642
|
+
case 2:
|
|
5643
|
+
_a = !(_b.sent());
|
|
5644
|
+
_b.label = 3;
|
|
5645
|
+
case 3:
|
|
5646
|
+
if (_a) {
|
|
5647
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, rebateMint));
|
|
5648
|
+
}
|
|
5566
5649
|
return [4, this.program.methods
|
|
5567
5650
|
.collectRebate()
|
|
5568
|
-
.
|
|
5651
|
+
.accountsPartial({
|
|
5569
5652
|
owner: owner,
|
|
5570
5653
|
receivingTokenAccount: userTokenAccount,
|
|
5571
5654
|
perpetuals: this.perpetuals.publicKey,
|
|
@@ -5574,20 +5657,18 @@ var PerpetualsClient = (function () {
|
|
|
5574
5657
|
rebateTokenAccount: poolConfig.rebateTokenAccount,
|
|
5575
5658
|
tokenStakeAccount: tokenStakeAccount,
|
|
5576
5659
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5577
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5578
|
-
program: this.programId,
|
|
5579
5660
|
receivingTokenMint: rebateMint,
|
|
5580
5661
|
})
|
|
5581
5662
|
.instruction()];
|
|
5582
|
-
case
|
|
5583
|
-
collectRebateInstruction =
|
|
5663
|
+
case 4:
|
|
5664
|
+
collectRebateInstruction = _b.sent();
|
|
5584
5665
|
instructions.push(collectRebateInstruction);
|
|
5585
|
-
return [3,
|
|
5586
|
-
case
|
|
5587
|
-
err_28 =
|
|
5666
|
+
return [3, 6];
|
|
5667
|
+
case 5:
|
|
5668
|
+
err_28 = _b.sent();
|
|
5588
5669
|
console.log("perpClient collectRebateInstruction error:: ", err_28);
|
|
5589
5670
|
throw err_28;
|
|
5590
|
-
case
|
|
5671
|
+
case 6: return [2, {
|
|
5591
5672
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5592
5673
|
additionalSigners: additionalSigners
|
|
5593
5674
|
}];
|
|
@@ -5611,7 +5692,7 @@ var PerpetualsClient = (function () {
|
|
|
5611
5692
|
rebateMint = poolConfig.getTokenFromSymbol(rebateSymbol).mintKey;
|
|
5612
5693
|
return [4, this.program.methods
|
|
5613
5694
|
.settleRebates()
|
|
5614
|
-
.
|
|
5695
|
+
.accountsPartial({
|
|
5615
5696
|
transferAuthority: poolConfig.transferAuthority,
|
|
5616
5697
|
perpetuals: this.perpetuals.publicKey,
|
|
5617
5698
|
pool: poolConfig.poolAddress,
|
|
@@ -5622,8 +5703,6 @@ var PerpetualsClient = (function () {
|
|
|
5622
5703
|
rebateTokenAccount: poolConfig.rebateTokenAccount,
|
|
5623
5704
|
tokenMint: rebateMint,
|
|
5624
5705
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5625
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5626
|
-
program: this.programId,
|
|
5627
5706
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
|
5628
5707
|
})
|
|
5629
5708
|
.instruction()];
|
|
@@ -5647,14 +5726,14 @@ var PerpetualsClient = (function () {
|
|
|
5647
5726
|
for (var _i = 11; _i < arguments.length; _i++) {
|
|
5648
5727
|
args_1[_i - 11] = arguments[_i];
|
|
5649
5728
|
}
|
|
5650
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, limitPrice_1, reserveAmount_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey
|
|
5729
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, limitPrice_1, reserveAmount_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
|
5651
5730
|
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_30;
|
|
5652
5731
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
5653
5732
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
5654
5733
|
return __generator(this, function (_c) {
|
|
5655
5734
|
switch (_c.label) {
|
|
5656
5735
|
case 0:
|
|
5657
|
-
publicKey =
|
|
5736
|
+
publicKey = this.provider.wallet.publicKey;
|
|
5658
5737
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
5659
5738
|
reserveCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey); });
|
|
5660
5739
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
@@ -5726,7 +5805,7 @@ var PerpetualsClient = (function () {
|
|
|
5726
5805
|
stopLossPrice: stopLossPrice,
|
|
5727
5806
|
takeProfitPrice: takeProfitPrice
|
|
5728
5807
|
})
|
|
5729
|
-
.
|
|
5808
|
+
.accountsPartial({
|
|
5730
5809
|
owner: publicKey,
|
|
5731
5810
|
feePayer: publicKey,
|
|
5732
5811
|
fundingAccount: reserveSymbol == 'SOL' ? wrappedSolAccount.publicKey : userReserveTokenAccount,
|
|
@@ -5743,8 +5822,6 @@ var PerpetualsClient = (function () {
|
|
|
5743
5822
|
receiveCustody: receiveCustodyConfig.custodyAccount,
|
|
5744
5823
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
5745
5824
|
fundingTokenProgram: poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
5746
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5747
|
-
program: this.programId,
|
|
5748
5825
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
5749
5826
|
fundingMint: reserveCustodyConfig.mintKey,
|
|
5750
5827
|
})
|
|
@@ -5770,14 +5847,14 @@ var PerpetualsClient = (function () {
|
|
|
5770
5847
|
for (var _i = 11; _i < arguments.length; _i++) {
|
|
5771
5848
|
args_1[_i - 11] = arguments[_i];
|
|
5772
5849
|
}
|
|
5773
|
-
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, orderId_1, limitPrice_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey
|
|
5774
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, positionAccount, orderAccount, editLimitOrder, err_31;
|
|
5850
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, orderId_1, limitPrice_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
|
|
5851
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_31;
|
|
5775
5852
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
5776
5853
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
5777
|
-
return __generator(this, function (
|
|
5778
|
-
switch (
|
|
5854
|
+
return __generator(this, function (_b) {
|
|
5855
|
+
switch (_b.label) {
|
|
5779
5856
|
case 0:
|
|
5780
|
-
publicKey =
|
|
5857
|
+
publicKey = this.provider.wallet.publicKey;
|
|
5781
5858
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
5782
5859
|
reserveCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey); });
|
|
5783
5860
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
@@ -5787,33 +5864,43 @@ var PerpetualsClient = (function () {
|
|
|
5787
5864
|
instructions = [];
|
|
5788
5865
|
postInstructions = [];
|
|
5789
5866
|
additionalSigners = [];
|
|
5790
|
-
|
|
5867
|
+
_b.label = 1;
|
|
5791
5868
|
case 1:
|
|
5792
|
-
|
|
5793
|
-
if (reserveSymbol == 'SOL')
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
}
|
|
5799
|
-
preInstructions = [
|
|
5800
|
-
web3_js_1.SystemProgram.createAccount({
|
|
5801
|
-
fromPubkey: publicKey,
|
|
5802
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
5803
|
-
lamports: lamports,
|
|
5804
|
-
space: 165,
|
|
5805
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5806
|
-
}),
|
|
5807
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
5808
|
-
];
|
|
5809
|
-
postInstructions = [
|
|
5810
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
5811
|
-
];
|
|
5869
|
+
_b.trys.push([1, 7, , 8]);
|
|
5870
|
+
if (!(reserveSymbol == 'SOL')) return [3, 2];
|
|
5871
|
+
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
|
5872
|
+
if (!ephemeralSignerPubkey) {
|
|
5873
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
|
5874
|
+
additionalSigners.push(wrappedSolAccount);
|
|
5812
5875
|
}
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
|
|
5876
|
+
preInstructions = [
|
|
5877
|
+
web3_js_1.SystemProgram.createAccount({
|
|
5878
|
+
fromPubkey: publicKey,
|
|
5879
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
|
5880
|
+
lamports: lamports,
|
|
5881
|
+
space: 165,
|
|
5882
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
5883
|
+
}),
|
|
5884
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
|
5885
|
+
];
|
|
5886
|
+
postInstructions = [
|
|
5887
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
5888
|
+
];
|
|
5889
|
+
return [3, 5];
|
|
5890
|
+
case 2:
|
|
5891
|
+
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);
|
|
5892
|
+
_a = createUserATA;
|
|
5893
|
+
if (!_a) return [3, 4];
|
|
5894
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
5895
|
+
case 3:
|
|
5896
|
+
_a = !(_b.sent());
|
|
5897
|
+
_b.label = 4;
|
|
5898
|
+
case 4:
|
|
5899
|
+
if (_a) {
|
|
5900
|
+
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));
|
|
5816
5901
|
}
|
|
5902
|
+
_b.label = 5;
|
|
5903
|
+
case 5:
|
|
5817
5904
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
|
5818
5905
|
orderAccount = poolConfig.getOrderFromMarketPk(publicKey, marketAccount);
|
|
5819
5906
|
return [4, this.program.methods
|
|
@@ -5824,7 +5911,7 @@ var PerpetualsClient = (function () {
|
|
|
5824
5911
|
stopLossPrice: stopLossPrice,
|
|
5825
5912
|
takeProfitPrice: takeProfitPrice
|
|
5826
5913
|
})
|
|
5827
|
-
.
|
|
5914
|
+
.accountsPartial({
|
|
5828
5915
|
owner: publicKey,
|
|
5829
5916
|
feePayer: publicKey,
|
|
5830
5917
|
receivingAccount: reserveSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
|
@@ -5841,21 +5928,19 @@ var PerpetualsClient = (function () {
|
|
|
5841
5928
|
reserveCustodyTokenAccount: reserveCustodyConfig.tokenAccount,
|
|
5842
5929
|
receiveCustody: receiveCustodyConfig.custodyAccount,
|
|
5843
5930
|
receivingTokenProgram: poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
5844
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5845
|
-
program: this.programId,
|
|
5846
5931
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
5847
5932
|
receivingMint: poolConfig.getTokenFromSymbol(reserveSymbol).mintKey
|
|
5848
5933
|
})
|
|
5849
5934
|
.instruction()];
|
|
5850
|
-
case
|
|
5851
|
-
editLimitOrder =
|
|
5935
|
+
case 6:
|
|
5936
|
+
editLimitOrder = _b.sent();
|
|
5852
5937
|
instructions.push(editLimitOrder);
|
|
5853
|
-
return [3,
|
|
5854
|
-
case
|
|
5855
|
-
err_31 =
|
|
5938
|
+
return [3, 8];
|
|
5939
|
+
case 7:
|
|
5940
|
+
err_31 = _b.sent();
|
|
5856
5941
|
console.log("perpClient editLimitOrder error:: ", err_31);
|
|
5857
5942
|
throw err_31;
|
|
5858
|
-
case
|
|
5943
|
+
case 8: return [2, {
|
|
5859
5944
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
5860
5945
|
additionalSigners: additionalSigners
|
|
5861
5946
|
}];
|
|
@@ -5893,7 +5978,7 @@ var PerpetualsClient = (function () {
|
|
|
5893
5978
|
orderId: orderId,
|
|
5894
5979
|
privilege: privilege
|
|
5895
5980
|
})
|
|
5896
|
-
.
|
|
5981
|
+
.accountsPartial({
|
|
5897
5982
|
positionOwner: userPubkey,
|
|
5898
5983
|
feePayer: publicKey,
|
|
5899
5984
|
transferAuthority: poolConfig.transferAuthority,
|
|
@@ -5909,8 +5994,6 @@ var PerpetualsClient = (function () {
|
|
|
5909
5994
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
|
5910
5995
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
5911
5996
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
5912
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5913
|
-
program: this.programId,
|
|
5914
5997
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
5915
5998
|
collateralMint: collateralCustodyConfig.mintKey,
|
|
5916
5999
|
})
|
|
@@ -5963,7 +6046,7 @@ var PerpetualsClient = (function () {
|
|
|
5963
6046
|
orderId: orderId,
|
|
5964
6047
|
privilege: privilege
|
|
5965
6048
|
})
|
|
5966
|
-
.
|
|
6049
|
+
.accountsPartial({
|
|
5967
6050
|
positionOwner: userPubkey,
|
|
5968
6051
|
feePayer: publicKey,
|
|
5969
6052
|
transferAuthority: poolConfig.transferAuthority,
|
|
@@ -5981,8 +6064,6 @@ var PerpetualsClient = (function () {
|
|
|
5981
6064
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
|
5982
6065
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
5983
6066
|
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
5984
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
5985
|
-
program: this.programId,
|
|
5986
6067
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
5987
6068
|
collateralMint: collateralCustodyConfig.mintKey,
|
|
5988
6069
|
})
|
|
@@ -6004,12 +6085,12 @@ var PerpetualsClient = (function () {
|
|
|
6004
6085
|
});
|
|
6005
6086
|
});
|
|
6006
6087
|
};
|
|
6007
|
-
this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig
|
|
6088
|
+
this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6008
6089
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_34;
|
|
6009
6090
|
return __generator(this, function (_a) {
|
|
6010
6091
|
switch (_a.label) {
|
|
6011
6092
|
case 0:
|
|
6012
|
-
publicKey =
|
|
6093
|
+
publicKey = this.provider.wallet.publicKey;
|
|
6013
6094
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
6014
6095
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
6015
6096
|
receivingCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(receiveSymbol).mintKey); });
|
|
@@ -6029,7 +6110,7 @@ var PerpetualsClient = (function () {
|
|
|
6029
6110
|
deltaSizeAmount: deltaSizeAmount,
|
|
6030
6111
|
isStopLoss: isStopLoss
|
|
6031
6112
|
})
|
|
6032
|
-
.
|
|
6113
|
+
.accountsPartial({
|
|
6033
6114
|
owner: publicKey,
|
|
6034
6115
|
feePayer: publicKey,
|
|
6035
6116
|
perpetuals: poolConfig.perpetuals,
|
|
@@ -6043,8 +6124,6 @@ var PerpetualsClient = (function () {
|
|
|
6043
6124
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
|
6044
6125
|
receiveCustody: receivingCustodyConfig.custodyAccount,
|
|
6045
6126
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
6046
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
6047
|
-
program: this.programId,
|
|
6048
6127
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
|
6049
6128
|
})
|
|
6050
6129
|
.instruction()];
|
|
@@ -6063,12 +6142,12 @@ var PerpetualsClient = (function () {
|
|
|
6063
6142
|
}
|
|
6064
6143
|
});
|
|
6065
6144
|
}); };
|
|
6066
|
-
this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig
|
|
6145
|
+
this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6067
6146
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_35;
|
|
6068
6147
|
return __generator(this, function (_a) {
|
|
6069
6148
|
switch (_a.label) {
|
|
6070
6149
|
case 0:
|
|
6071
|
-
publicKey =
|
|
6150
|
+
publicKey = this.provider.wallet.publicKey;
|
|
6072
6151
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
6073
6152
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
6074
6153
|
receivingCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(receiveSymbol).mintKey); });
|
|
@@ -6089,7 +6168,7 @@ var PerpetualsClient = (function () {
|
|
|
6089
6168
|
deltaSizeAmount: deltaSizeAmount,
|
|
6090
6169
|
isStopLoss: isStopLoss
|
|
6091
6170
|
})
|
|
6092
|
-
.
|
|
6171
|
+
.accountsPartial({
|
|
6093
6172
|
owner: publicKey,
|
|
6094
6173
|
perpetuals: poolConfig.perpetuals,
|
|
6095
6174
|
pool: poolConfig.poolAddress,
|
|
@@ -6101,8 +6180,6 @@ var PerpetualsClient = (function () {
|
|
|
6101
6180
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
|
6102
6181
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
|
6103
6182
|
receiveCustody: receivingCustodyConfig.custodyAccount,
|
|
6104
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
6105
|
-
program: this.programId,
|
|
6106
6183
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
|
6107
6184
|
})
|
|
6108
6185
|
.instruction()];
|
|
@@ -6121,12 +6198,12 @@ var PerpetualsClient = (function () {
|
|
|
6121
6198
|
}
|
|
6122
6199
|
});
|
|
6123
6200
|
}); };
|
|
6124
|
-
this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig
|
|
6201
|
+
this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6125
6202
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_36;
|
|
6126
6203
|
return __generator(this, function (_a) {
|
|
6127
6204
|
switch (_a.label) {
|
|
6128
6205
|
case 0:
|
|
6129
|
-
publicKey =
|
|
6206
|
+
publicKey = this.provider.wallet.publicKey;
|
|
6130
6207
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
6131
6208
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
6132
6209
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
@@ -6143,11 +6220,9 @@ var PerpetualsClient = (function () {
|
|
|
6143
6220
|
orderId: orderId,
|
|
6144
6221
|
isStopLoss: isStopLoss
|
|
6145
6222
|
})
|
|
6146
|
-
.
|
|
6223
|
+
.accountsPartial({
|
|
6147
6224
|
owner: publicKey,
|
|
6148
6225
|
order: orderAccount,
|
|
6149
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
6150
|
-
program: this.programId,
|
|
6151
6226
|
})
|
|
6152
6227
|
.instruction()];
|
|
6153
6228
|
case 2:
|
|
@@ -6165,12 +6240,12 @@ var PerpetualsClient = (function () {
|
|
|
6165
6240
|
}
|
|
6166
6241
|
});
|
|
6167
6242
|
}); };
|
|
6168
|
-
this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig
|
|
6243
|
+
this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
|
6169
6244
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_37;
|
|
6170
6245
|
return __generator(this, function (_a) {
|
|
6171
6246
|
switch (_a.label) {
|
|
6172
6247
|
case 0:
|
|
6173
|
-
publicKey =
|
|
6248
|
+
publicKey = this.provider.wallet.publicKey;
|
|
6174
6249
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
6175
6250
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
|
6176
6251
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
|
@@ -6185,11 +6260,9 @@ var PerpetualsClient = (function () {
|
|
|
6185
6260
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
|
6186
6261
|
return [4, this.program.methods
|
|
6187
6262
|
.cancelAllTriggerOrders()
|
|
6188
|
-
.
|
|
6263
|
+
.accountsPartial({
|
|
6189
6264
|
position: positionAccount,
|
|
6190
6265
|
order: orderAccount,
|
|
6191
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
6192
|
-
program: this.programId,
|
|
6193
6266
|
})
|
|
6194
6267
|
.instruction()];
|
|
6195
6268
|
case 2:
|
|
@@ -6213,13 +6286,13 @@ var PerpetualsClient = (function () {
|
|
|
6213
6286
|
args_1[_i - 9] = arguments[_i];
|
|
6214
6287
|
}
|
|
6215
6288
|
return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount) {
|
|
6216
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, collateralToken, receivingToken, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas,
|
|
6289
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, collateralToken, receivingToken, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap, err_38;
|
|
6217
6290
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6218
6291
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
6219
6292
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
6220
6293
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
6221
|
-
return __generator(this, function (
|
|
6222
|
-
switch (
|
|
6294
|
+
return __generator(this, function (_e) {
|
|
6295
|
+
switch (_e.label) {
|
|
6223
6296
|
case 0:
|
|
6224
6297
|
payerPubkey = this.provider.wallet.publicKey;
|
|
6225
6298
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
@@ -6232,23 +6305,42 @@ var PerpetualsClient = (function () {
|
|
|
6232
6305
|
additionalSigners = [];
|
|
6233
6306
|
collateralToken = poolConfig.getTokenFromSymbol(collateralSymbol);
|
|
6234
6307
|
receivingToken = poolConfig.getTokenFromSymbol(receivingSymbol);
|
|
6235
|
-
|
|
6308
|
+
_e.label = 1;
|
|
6236
6309
|
case 1:
|
|
6237
|
-
|
|
6238
|
-
if (false)
|
|
6310
|
+
_e.trys.push([1, 9, , 10]);
|
|
6311
|
+
if (!false) return [3, 2];
|
|
6312
|
+
return [3, 7];
|
|
6313
|
+
case 2:
|
|
6314
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(receivingSymbol).mintKey, owner, true, receivingToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
|
6315
|
+
_a = createUserATA;
|
|
6316
|
+
if (!_a) return [3, 4];
|
|
6317
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
6318
|
+
case 3:
|
|
6319
|
+
_a = !(_e.sent());
|
|
6320
|
+
_e.label = 4;
|
|
6321
|
+
case 4:
|
|
6322
|
+
if (_a) {
|
|
6323
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
|
|
6239
6324
|
}
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6325
|
+
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);
|
|
6326
|
+
_b = createUserATA;
|
|
6327
|
+
if (!_b) return [3, 6];
|
|
6328
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
|
|
6329
|
+
case 5:
|
|
6330
|
+
_b = !(_e.sent());
|
|
6331
|
+
_e.label = 6;
|
|
6332
|
+
case 6:
|
|
6333
|
+
if (_b) {
|
|
6334
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
|
6245
6335
|
}
|
|
6336
|
+
_e.label = 7;
|
|
6337
|
+
case 7:
|
|
6246
6338
|
positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
|
|
6247
6339
|
orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
|
|
6248
6340
|
custodyAccountMetas = [];
|
|
6249
6341
|
custodyOracleAccountMetas = [];
|
|
6250
|
-
for (
|
|
6251
|
-
custody =
|
|
6342
|
+
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
|
6343
|
+
custody = _d[_c];
|
|
6252
6344
|
custodyAccountMetas.push({
|
|
6253
6345
|
pubkey: custody.custodyAccount,
|
|
6254
6346
|
isSigner: false,
|
|
@@ -6266,7 +6358,7 @@ var PerpetualsClient = (function () {
|
|
|
6266
6358
|
orderId: orderId,
|
|
6267
6359
|
privilege: privilege
|
|
6268
6360
|
})
|
|
6269
|
-
.
|
|
6361
|
+
.accountsPartial({
|
|
6270
6362
|
positionOwner: owner,
|
|
6271
6363
|
feePayer: payerPubkey,
|
|
6272
6364
|
receivingAccount: userReceivingTokenAccount,
|
|
@@ -6285,8 +6377,6 @@ var PerpetualsClient = (function () {
|
|
|
6285
6377
|
dispensingCustody: receivingCustodyConfig.custodyAccount,
|
|
6286
6378
|
dispensingOracleAccount: this.useExtOracleAccount ? receivingCustodyConfig.extOracleAccount : receivingCustodyConfig.intOracleAccount,
|
|
6287
6379
|
dispensingCustodyTokenAccount: receivingCustodyConfig.tokenAccount,
|
|
6288
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
6289
|
-
program: this.programId,
|
|
6290
6380
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
6291
6381
|
receivingMint: receivingCustodyConfig.mintKey,
|
|
6292
6382
|
receivingTokenProgram: receivingToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
@@ -6295,15 +6385,15 @@ var PerpetualsClient = (function () {
|
|
|
6295
6385
|
})
|
|
6296
6386
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
6297
6387
|
.instruction()];
|
|
6298
|
-
case
|
|
6299
|
-
executeTriggerWithSwap =
|
|
6388
|
+
case 8:
|
|
6389
|
+
executeTriggerWithSwap = _e.sent();
|
|
6300
6390
|
instructions.push(executeTriggerWithSwap);
|
|
6301
|
-
return [3,
|
|
6302
|
-
case
|
|
6303
|
-
err_38 =
|
|
6391
|
+
return [3, 10];
|
|
6392
|
+
case 9:
|
|
6393
|
+
err_38 = _e.sent();
|
|
6304
6394
|
console.log("perpClient executeTriggerWithSwap error:: ", err_38);
|
|
6305
6395
|
throw err_38;
|
|
6306
|
-
case
|
|
6396
|
+
case 10: return [2, {
|
|
6307
6397
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6308
6398
|
additionalSigners: additionalSigners
|
|
6309
6399
|
}];
|
|
@@ -6317,13 +6407,13 @@ var PerpetualsClient = (function () {
|
|
|
6317
6407
|
args_1[_i - 8] = arguments[_i];
|
|
6318
6408
|
}
|
|
6319
6409
|
return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount) {
|
|
6320
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeTriggerOrder, err_39;
|
|
6410
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_39;
|
|
6321
6411
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6322
6412
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
6323
6413
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
|
6324
6414
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
|
6325
|
-
return __generator(this, function (
|
|
6326
|
-
switch (
|
|
6415
|
+
return __generator(this, function (_b) {
|
|
6416
|
+
switch (_b.label) {
|
|
6327
6417
|
case 0:
|
|
6328
6418
|
payerPubkey = this.provider.wallet.publicKey;
|
|
6329
6419
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
|
@@ -6333,15 +6423,25 @@ var PerpetualsClient = (function () {
|
|
|
6333
6423
|
instructions = [];
|
|
6334
6424
|
postInstructions = [];
|
|
6335
6425
|
additionalSigners = [];
|
|
6336
|
-
|
|
6426
|
+
_b.label = 1;
|
|
6337
6427
|
case 1:
|
|
6338
|
-
|
|
6339
|
-
if (false)
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6428
|
+
_b.trys.push([1, 7, , 8]);
|
|
6429
|
+
if (!false) return [3, 2];
|
|
6430
|
+
return [3, 5];
|
|
6431
|
+
case 2:
|
|
6432
|
+
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);
|
|
6433
|
+
_a = createUserATA;
|
|
6434
|
+
if (!_a) return [3, 4];
|
|
6435
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
|
6436
|
+
case 3:
|
|
6437
|
+
_a = !(_b.sent());
|
|
6438
|
+
_b.label = 4;
|
|
6439
|
+
case 4:
|
|
6440
|
+
if (_a) {
|
|
6441
|
+
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));
|
|
6344
6442
|
}
|
|
6443
|
+
_b.label = 5;
|
|
6444
|
+
case 5:
|
|
6345
6445
|
positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
|
|
6346
6446
|
orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
|
|
6347
6447
|
return [4, this.program.methods
|
|
@@ -6350,7 +6450,7 @@ var PerpetualsClient = (function () {
|
|
|
6350
6450
|
orderId: orderId,
|
|
6351
6451
|
privilege: privilege
|
|
6352
6452
|
})
|
|
6353
|
-
.
|
|
6453
|
+
.accountsPartial({
|
|
6354
6454
|
feePayer: payerPubkey,
|
|
6355
6455
|
positionOwner: owner,
|
|
6356
6456
|
receivingAccount: userReceivingTokenAccount,
|
|
@@ -6366,22 +6466,20 @@ var PerpetualsClient = (function () {
|
|
|
6366
6466
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
|
6367
6467
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
|
6368
6468
|
receivingTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
6369
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
6370
|
-
program: this.programId,
|
|
6371
6469
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
6372
6470
|
receivingMint: collateralCustodyConfig.mintKey
|
|
6373
6471
|
})
|
|
6374
6472
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, privilege), true))
|
|
6375
6473
|
.instruction()];
|
|
6376
|
-
case
|
|
6377
|
-
executeTriggerOrder =
|
|
6474
|
+
case 6:
|
|
6475
|
+
executeTriggerOrder = _b.sent();
|
|
6378
6476
|
instructions.push(executeTriggerOrder);
|
|
6379
|
-
return [3,
|
|
6380
|
-
case
|
|
6381
|
-
err_39 =
|
|
6477
|
+
return [3, 8];
|
|
6478
|
+
case 7:
|
|
6479
|
+
err_39 = _b.sent();
|
|
6382
6480
|
console.log("perpClient executeTriggerOrder error:: ", err_39);
|
|
6383
6481
|
throw err_39;
|
|
6384
|
-
case
|
|
6482
|
+
case 8: return [2, {
|
|
6385
6483
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6386
6484
|
additionalSigners: additionalSigners
|
|
6387
6485
|
}];
|
|
@@ -6394,16 +6492,16 @@ var PerpetualsClient = (function () {
|
|
|
6394
6492
|
for (var _i = 5; _i < arguments.length; _i++) {
|
|
6395
6493
|
args_1[_i - 5] = arguments[_i];
|
|
6396
6494
|
}
|
|
6397
|
-
return __awaiter(_this, __spreadArray([userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1], args_1, true), void 0, function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey, isWhitelistedUser
|
|
6398
|
-
var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount, unWrappedSolBalance, _a, wsolAssociatedTokenAccount, closeWsolATAIns, accCreationLamports, lamports, unWrappedSolBalance, _b, tokenAccountBalance, _c, lamports, custodyAccountMetas, custodyOracleAccountMetas,
|
|
6495
|
+
return __awaiter(_this, __spreadArray([userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1], args_1, true), void 0, function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey, isWhitelistedUser) {
|
|
6496
|
+
var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount, wsolATAExist, unWrappedSolBalance, _a, wsolAssociatedTokenAccount, closeWsolATAIns, accCreationLamports, lamports, unWrappedSolBalance, _b, tokenAccountBalance, _c, lamports, _d, custodyAccountMetas, custodyOracleAccountMetas, _e, _f, custody, whitelistPda, whitelistMeta, params, inx, closeWsolATAIns, err_40;
|
|
6399
6497
|
if (useFeesPool === void 0) { useFeesPool = false; }
|
|
6400
6498
|
if (createUserATA === void 0) { createUserATA = true; }
|
|
6401
6499
|
if (unWrapSol === void 0) { unWrapSol = false; }
|
|
6402
6500
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
|
6403
6501
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
|
6404
6502
|
if (isWhitelistedUser === void 0) { isWhitelistedUser = false; }
|
|
6405
|
-
return __generator(this, function (
|
|
6406
|
-
switch (
|
|
6503
|
+
return __generator(this, function (_g) {
|
|
6504
|
+
switch (_g.label) {
|
|
6407
6505
|
case 0:
|
|
6408
6506
|
userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
|
|
6409
6507
|
if (!userInputCustodyConfig) {
|
|
@@ -6413,26 +6511,31 @@ var PerpetualsClient = (function () {
|
|
|
6413
6511
|
if (!userOutputCustodyConfig) {
|
|
6414
6512
|
throw "userOutputCustodyConfig not found";
|
|
6415
6513
|
}
|
|
6416
|
-
publicKey =
|
|
6514
|
+
publicKey = this.provider.wallet.publicKey;
|
|
6417
6515
|
preInstructions = [];
|
|
6418
6516
|
instructions = [];
|
|
6419
6517
|
postInstructions = [];
|
|
6420
6518
|
additionalSigners = [];
|
|
6421
|
-
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3,
|
|
6519
|
+
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
|
|
6422
6520
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
|
|
6423
6521
|
case 1:
|
|
6424
|
-
wsolAssociatedTokenAccount =
|
|
6425
|
-
|
|
6426
|
-
|
|
6522
|
+
wsolAssociatedTokenAccount = _g.sent();
|
|
6523
|
+
return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
|
|
6524
|
+
case 2:
|
|
6525
|
+
wsolATAExist = _g.sent();
|
|
6526
|
+
if (!wsolATAExist) {
|
|
6527
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
|
6528
|
+
}
|
|
6529
|
+
if (!!skipBalanceChecks) return [3, 4];
|
|
6427
6530
|
_a = anchor_1.BN.bind;
|
|
6428
6531
|
return [4, this.provider.connection.getBalance(publicKey)];
|
|
6429
|
-
case
|
|
6430
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
|
6532
|
+
case 3:
|
|
6533
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
|
6431
6534
|
if (unWrappedSolBalance.lt(amountIn)) {
|
|
6432
6535
|
throw "Insufficient SOL Funds";
|
|
6433
6536
|
}
|
|
6434
|
-
|
|
6435
|
-
case
|
|
6537
|
+
_g.label = 4;
|
|
6538
|
+
case 4:
|
|
6436
6539
|
instructions.push(web3_js_1.SystemProgram.transfer({
|
|
6437
6540
|
fromPubkey: publicKey,
|
|
6438
6541
|
toPubkey: wsolAssociatedTokenAccount,
|
|
@@ -6442,7 +6545,7 @@ var PerpetualsClient = (function () {
|
|
|
6442
6545
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6443
6546
|
additionalSigners: additionalSigners
|
|
6444
6547
|
}];
|
|
6445
|
-
case
|
|
6548
|
+
case 5:
|
|
6446
6549
|
if (userInputTokenSymbol == 'WSOL' && userOutputTokenSymbol == 'SOL') {
|
|
6447
6550
|
console.log("WSOL=> SOL : NOTE : ONLY WAY IS TO CLOSE THE WSOL ATA and GET ALL SOL ");
|
|
6448
6551
|
wsolAssociatedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, publicKey, true);
|
|
@@ -6453,20 +6556,20 @@ var PerpetualsClient = (function () {
|
|
|
6453
6556
|
additionalSigners: additionalSigners
|
|
6454
6557
|
}];
|
|
6455
6558
|
}
|
|
6456
|
-
|
|
6457
|
-
case
|
|
6458
|
-
|
|
6459
|
-
if (!(userInputTokenSymbol == 'SOL')) return [3,
|
|
6559
|
+
_g.label = 6;
|
|
6560
|
+
case 6:
|
|
6561
|
+
_g.trys.push([6, 19, , 20]);
|
|
6562
|
+
if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
|
|
6460
6563
|
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
|
6461
6564
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
|
6462
|
-
case
|
|
6463
|
-
accCreationLamports = (
|
|
6565
|
+
case 7:
|
|
6566
|
+
accCreationLamports = (_g.sent());
|
|
6464
6567
|
console.log("accCreationLamports:", accCreationLamports);
|
|
6465
6568
|
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
|
6466
6569
|
_b = anchor_1.BN.bind;
|
|
6467
6570
|
return [4, this.provider.connection.getBalance(publicKey)];
|
|
6468
|
-
case
|
|
6469
|
-
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0,
|
|
6571
|
+
case 8:
|
|
6572
|
+
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
|
6470
6573
|
if (unWrappedSolBalance.lt(amountIn)) {
|
|
6471
6574
|
throw "Insufficient SOL Funds";
|
|
6472
6575
|
}
|
|
@@ -6488,25 +6591,25 @@ var PerpetualsClient = (function () {
|
|
|
6488
6591
|
postInstructions = [
|
|
6489
6592
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
6490
6593
|
];
|
|
6491
|
-
return [3,
|
|
6492
|
-
case
|
|
6594
|
+
return [3, 12];
|
|
6595
|
+
case 9:
|
|
6493
6596
|
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);
|
|
6494
6597
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
|
6495
|
-
case
|
|
6496
|
-
if (!(
|
|
6598
|
+
case 10:
|
|
6599
|
+
if (!(_g.sent())) {
|
|
6497
6600
|
throw "Insufficient Funds , Token Account doesn't exist";
|
|
6498
6601
|
}
|
|
6499
|
-
if (!!skipBalanceChecks) return [3,
|
|
6602
|
+
if (!!skipBalanceChecks) return [3, 12];
|
|
6500
6603
|
_c = anchor_1.BN.bind;
|
|
6501
6604
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
|
6502
|
-
case
|
|
6503
|
-
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (
|
|
6605
|
+
case 11:
|
|
6606
|
+
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
|
6504
6607
|
if (tokenAccountBalance.lt(amountIn)) {
|
|
6505
6608
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
|
6506
6609
|
}
|
|
6507
|
-
|
|
6508
|
-
case
|
|
6509
|
-
if (!(userOutputTokenSymbol == 'SOL')) return [3,
|
|
6610
|
+
_g.label = 12;
|
|
6611
|
+
case 12:
|
|
6612
|
+
if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
|
|
6510
6613
|
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
|
6511
6614
|
if (!ephemeralSignerPubkey) {
|
|
6512
6615
|
wrappedSolAccount = new web3_js_1.Keypair();
|
|
@@ -6526,17 +6629,26 @@ var PerpetualsClient = (function () {
|
|
|
6526
6629
|
postInstructions = [
|
|
6527
6630
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
|
6528
6631
|
];
|
|
6529
|
-
return [3,
|
|
6530
|
-
case
|
|
6531
|
-
case 13:
|
|
6532
|
-
userOutputTokenAccount = _f.sent();
|
|
6533
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
|
6534
|
-
_f.label = 14;
|
|
6632
|
+
return [3, 17];
|
|
6633
|
+
case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID)];
|
|
6535
6634
|
case 14:
|
|
6635
|
+
userOutputTokenAccount = _g.sent();
|
|
6636
|
+
_d = createUserATA;
|
|
6637
|
+
if (!_d) return [3, 16];
|
|
6638
|
+
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
|
6639
|
+
case 15:
|
|
6640
|
+
_d = !(_g.sent());
|
|
6641
|
+
_g.label = 16;
|
|
6642
|
+
case 16:
|
|
6643
|
+
if (_d) {
|
|
6644
|
+
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));
|
|
6645
|
+
}
|
|
6646
|
+
_g.label = 17;
|
|
6647
|
+
case 17:
|
|
6536
6648
|
custodyAccountMetas = [];
|
|
6537
6649
|
custodyOracleAccountMetas = [];
|
|
6538
|
-
for (
|
|
6539
|
-
custody = _e
|
|
6650
|
+
for (_e = 0, _f = poolConfig.custodies; _e < _f.length; _e++) {
|
|
6651
|
+
custody = _f[_e];
|
|
6540
6652
|
custodyAccountMetas.push({
|
|
6541
6653
|
pubkey: custody.custodyAccount,
|
|
6542
6654
|
isSigner: false,
|
|
@@ -6561,7 +6673,7 @@ var PerpetualsClient = (function () {
|
|
|
6561
6673
|
};
|
|
6562
6674
|
return [4, this.program.methods
|
|
6563
6675
|
.swap(params)
|
|
6564
|
-
.
|
|
6676
|
+
.accountsPartial({
|
|
6565
6677
|
owner: publicKey,
|
|
6566
6678
|
fundingAccount: userInputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
|
|
6567
6679
|
receivingAccount: userOutputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userOutputTokenAccount,
|
|
@@ -6575,7 +6687,6 @@ var PerpetualsClient = (function () {
|
|
|
6575
6687
|
dispensingCustodyOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
|
|
6576
6688
|
dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
|
|
6577
6689
|
eventAuthority: this.eventAuthority.publicKey,
|
|
6578
|
-
program: this.programId,
|
|
6579
6690
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
6580
6691
|
fundingMint: userInputCustodyConfig.mintKey,
|
|
6581
6692
|
fundingTokenProgram: poolConfig.getTokenFromSymbol(userInputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
@@ -6584,19 +6695,19 @@ var PerpetualsClient = (function () {
|
|
|
6584
6695
|
})
|
|
6585
6696
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
|
|
6586
6697
|
.instruction()];
|
|
6587
|
-
case
|
|
6588
|
-
inx =
|
|
6698
|
+
case 18:
|
|
6699
|
+
inx = _g.sent();
|
|
6589
6700
|
instructions.push(inx);
|
|
6590
6701
|
if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
|
|
6591
6702
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
|
|
6592
6703
|
instructions.push(closeWsolATAIns);
|
|
6593
6704
|
}
|
|
6594
|
-
return [3,
|
|
6595
|
-
case
|
|
6596
|
-
err_40 =
|
|
6705
|
+
return [3, 20];
|
|
6706
|
+
case 19:
|
|
6707
|
+
err_40 = _g.sent();
|
|
6597
6708
|
console.error("perpClient Swap error:: ", err_40);
|
|
6598
6709
|
throw err_40;
|
|
6599
|
-
case
|
|
6710
|
+
case 20: return [2, {
|
|
6600
6711
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
6601
6712
|
additionalSigners: additionalSigners
|
|
6602
6713
|
}];
|
|
@@ -6643,15 +6754,13 @@ var PerpetualsClient = (function () {
|
|
|
6643
6754
|
params = {};
|
|
6644
6755
|
return [4, this.program.methods
|
|
6645
6756
|
.swapFeeInternal(params)
|
|
6646
|
-
.
|
|
6757
|
+
.accountsPartial({
|
|
6647
6758
|
owner: publicKey,
|
|
6648
6759
|
perpetuals: poolConfig.perpetuals,
|
|
6649
6760
|
pool: poolConfig.poolAddress,
|
|
6650
6761
|
rewardCustody: rewardCustody.custodyAccount,
|
|
6651
6762
|
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
|
6652
6763
|
rewardCustodyTokenAccount: rewardCustody.tokenAccount,
|
|
6653
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
6654
|
-
program: this.programId,
|
|
6655
6764
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
|
6656
6765
|
})
|
|
6657
6766
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
|
@@ -6707,7 +6816,7 @@ var PerpetualsClient = (function () {
|
|
|
6707
6816
|
}
|
|
6708
6817
|
return [4, this.program.methods
|
|
6709
6818
|
.setLpTokenPrice({})
|
|
6710
|
-
.
|
|
6819
|
+
.accountsPartial({
|
|
6711
6820
|
perpetuals: poolConfig.perpetuals,
|
|
6712
6821
|
pool: poolConfig.poolAddress,
|
|
6713
6822
|
lpTokenMint: poolConfig.stakedLpTokenMint,
|
|
@@ -6747,7 +6856,7 @@ var PerpetualsClient = (function () {
|
|
|
6747
6856
|
}
|
|
6748
6857
|
return [4, this.program.methods
|
|
6749
6858
|
.init(config)
|
|
6750
|
-
.
|
|
6859
|
+
.accountsPartial({
|
|
6751
6860
|
upgradeAuthority: this.provider.wallet.publicKey,
|
|
6752
6861
|
multisig: this.multisig.publicKey,
|
|
6753
6862
|
transferAuthority: this.authority.publicKey,
|
|
@@ -6790,7 +6899,7 @@ var PerpetualsClient = (function () {
|
|
|
6790
6899
|
.setAdminSigners({
|
|
6791
6900
|
minSignatures: minSignatures,
|
|
6792
6901
|
})
|
|
6793
|
-
.
|
|
6902
|
+
.accountsPartial({
|
|
6794
6903
|
admin: this.admin,
|
|
6795
6904
|
multisig: this.multisig.publicKey,
|
|
6796
6905
|
})
|
|
@@ -6827,7 +6936,7 @@ var PerpetualsClient = (function () {
|
|
|
6827
6936
|
maxLpPriceUsd: maxLpPriceUsd,
|
|
6828
6937
|
thresholdUsd: thresholdUsd
|
|
6829
6938
|
})
|
|
6830
|
-
.
|
|
6939
|
+
.accountsPartial({
|
|
6831
6940
|
admin: this.provider.wallet.publicKey,
|
|
6832
6941
|
multisig: this.multisig.publicKey,
|
|
6833
6942
|
transferAuthority: this.authority.publicKey,
|
|
@@ -6854,7 +6963,7 @@ var PerpetualsClient = (function () {
|
|
|
6854
6963
|
switch (_a.label) {
|
|
6855
6964
|
case 0: return [4, this.program.methods
|
|
6856
6965
|
.removePool({})
|
|
6857
|
-
.
|
|
6966
|
+
.accountsPartial({
|
|
6858
6967
|
admin: this.admin,
|
|
6859
6968
|
multisig: this.multisig.publicKey,
|
|
6860
6969
|
transferAuthority: this.authority.publicKey,
|
|
@@ -6895,7 +7004,7 @@ var PerpetualsClient = (function () {
|
|
|
6895
7004
|
minReserveUsd: minReserveUsd,
|
|
6896
7005
|
limitPriceBufferBps: limitPriceBufferBps
|
|
6897
7006
|
})
|
|
6898
|
-
.
|
|
7007
|
+
.accountsPartial({
|
|
6899
7008
|
admin: this.admin,
|
|
6900
7009
|
multisig: this.multisig.publicKey,
|
|
6901
7010
|
transferAuthority: this.authority.publicKey,
|
|
@@ -6939,7 +7048,7 @@ var PerpetualsClient = (function () {
|
|
|
6939
7048
|
borrowRate: borrowRate,
|
|
6940
7049
|
ratios: ratios,
|
|
6941
7050
|
})
|
|
6942
|
-
.
|
|
7051
|
+
.accountsPartial({
|
|
6943
7052
|
admin: this.admin,
|
|
6944
7053
|
multisig: this.multisig.publicKey,
|
|
6945
7054
|
transferAuthority: this.authority.publicKey,
|
|
@@ -6973,7 +7082,7 @@ var PerpetualsClient = (function () {
|
|
|
6973
7082
|
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(tokenMint, this.admin, true);
|
|
6974
7083
|
return [4, this.program.methods
|
|
6975
7084
|
.removeCustody({ ratios: ratios })
|
|
6976
|
-
.
|
|
7085
|
+
.accountsPartial({
|
|
6977
7086
|
admin: this.admin,
|
|
6978
7087
|
receivingAccount: userReceivingTokenAccount,
|
|
6979
7088
|
multisig: this.multisig.publicKey,
|
|
@@ -7016,7 +7125,7 @@ var PerpetualsClient = (function () {
|
|
|
7016
7125
|
_a.trys.push([2, 4, , 5]);
|
|
7017
7126
|
return [4, this.program.methods
|
|
7018
7127
|
.withdrawFees({})
|
|
7019
|
-
.
|
|
7128
|
+
.accountsPartial({
|
|
7020
7129
|
admin: publicKey,
|
|
7021
7130
|
multisig: this.multisig.publicKey,
|
|
7022
7131
|
transferAuthority: this.authority.publicKey,
|
|
@@ -7057,7 +7166,7 @@ var PerpetualsClient = (function () {
|
|
|
7057
7166
|
_a.trys.push([1, 3, , 4]);
|
|
7058
7167
|
return [4, this.program.methods
|
|
7059
7168
|
.moveProtocolFees()
|
|
7060
|
-
.
|
|
7169
|
+
.accountsPartial({
|
|
7061
7170
|
transferAuthority: this.authority.publicKey,
|
|
7062
7171
|
perpetuals: this.perpetuals.publicKey,
|
|
7063
7172
|
tokenVault: poolConfig.tokenVault,
|
|
@@ -7068,7 +7177,6 @@ var PerpetualsClient = (function () {
|
|
|
7068
7177
|
protocolVault: poolConfig.protocolVault,
|
|
7069
7178
|
protocolTokenAccount: poolConfig.protocolTokenAccount,
|
|
7070
7179
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
7071
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
7072
7180
|
program: this.program.programId,
|
|
7073
7181
|
tokenMint: rewardCustodyConfig.mintKey,
|
|
7074
7182
|
})
|
|
@@ -7099,7 +7207,7 @@ var PerpetualsClient = (function () {
|
|
|
7099
7207
|
.setProtocolFeeShare({
|
|
7100
7208
|
feeShareBps: feeShareBps
|
|
7101
7209
|
})
|
|
7102
|
-
.
|
|
7210
|
+
.accountsPartial({
|
|
7103
7211
|
admin: publicKey,
|
|
7104
7212
|
multisig: this.multisig.publicKey,
|
|
7105
7213
|
protocolVault: poolConfig.protocolVault,
|
|
@@ -7133,7 +7241,7 @@ var PerpetualsClient = (function () {
|
|
|
7133
7241
|
.setPermissions({
|
|
7134
7242
|
permissions: permissions,
|
|
7135
7243
|
})
|
|
7136
|
-
.
|
|
7244
|
+
.accountsPartial({
|
|
7137
7245
|
admin: publicKey,
|
|
7138
7246
|
multisig: this.multisig.publicKey,
|
|
7139
7247
|
perpetuals: this.perpetuals.publicKey
|
|
@@ -7192,7 +7300,7 @@ var PerpetualsClient = (function () {
|
|
|
7192
7300
|
_g.trys.push([1, 4, , 5]);
|
|
7193
7301
|
_e = (_d = this.program.methods
|
|
7194
7302
|
.reimburse({ amountIn: amountIn }))
|
|
7195
|
-
.
|
|
7303
|
+
.accountsPartial;
|
|
7196
7304
|
_f = {
|
|
7197
7305
|
admin: this.provider.wallet.publicKey,
|
|
7198
7306
|
multisig: poolConfig.multisig
|
|
@@ -7246,7 +7354,7 @@ var PerpetualsClient = (function () {
|
|
|
7246
7354
|
ema: ema,
|
|
7247
7355
|
publishTime: publishTime,
|
|
7248
7356
|
})
|
|
7249
|
-
.
|
|
7357
|
+
.accountsPartial({
|
|
7250
7358
|
authority: poolConfig.backupOracle,
|
|
7251
7359
|
perpetuals: poolConfig.perpetuals,
|
|
7252
7360
|
pool: poolConfig.poolAddress,
|
|
@@ -7308,7 +7416,7 @@ var PerpetualsClient = (function () {
|
|
|
7308
7416
|
useCurrentTime: useCurrentTime,
|
|
7309
7417
|
prices: tokenInternalPrices
|
|
7310
7418
|
})
|
|
7311
|
-
.
|
|
7419
|
+
.accountsPartial({
|
|
7312
7420
|
authority: POOL_CONFIGS[0].backupOracle,
|
|
7313
7421
|
})
|
|
7314
7422
|
.remainingAccounts(__spreadArray([], accountMetas, true))
|
|
@@ -7359,7 +7467,7 @@ var PerpetualsClient = (function () {
|
|
|
7359
7467
|
.setInternalEmaPrice({
|
|
7360
7468
|
prices: tokenInternalEmaPrices
|
|
7361
7469
|
})
|
|
7362
|
-
.
|
|
7470
|
+
.accountsPartial({
|
|
7363
7471
|
authority: POOL_CONFIGS[0].backupOracle,
|
|
7364
7472
|
})
|
|
7365
7473
|
.remainingAccounts(__spreadArray([], accountMetas, true))
|
|
@@ -7393,10 +7501,9 @@ var PerpetualsClient = (function () {
|
|
|
7393
7501
|
.setPositionPriceImpact({
|
|
7394
7502
|
priceImpactUsd: priceImpactUsd,
|
|
7395
7503
|
})
|
|
7396
|
-
.
|
|
7504
|
+
.accountsPartial({
|
|
7397
7505
|
authority: penaltyAuthority,
|
|
7398
7506
|
position: positionPubkey,
|
|
7399
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
7400
7507
|
program: this.program.programId,
|
|
7401
7508
|
})
|
|
7402
7509
|
.instruction()];
|
|
@@ -7435,7 +7542,7 @@ var PerpetualsClient = (function () {
|
|
|
7435
7542
|
lpTokenSymbol: lpTokenSymbol,
|
|
7436
7543
|
lpTokenUri: lpTokenUri,
|
|
7437
7544
|
})
|
|
7438
|
-
.
|
|
7545
|
+
.accountsPartial({
|
|
7439
7546
|
admin: publicKey,
|
|
7440
7547
|
multisig: this.multisig.publicKey,
|
|
7441
7548
|
transferAuthority: poolConfig.transferAuthority,
|
|
@@ -7484,7 +7591,7 @@ var PerpetualsClient = (function () {
|
|
|
7484
7591
|
.initStaking({
|
|
7485
7592
|
stakingFeeShareBps: stakingFeeShareBps
|
|
7486
7593
|
})
|
|
7487
|
-
.
|
|
7594
|
+
.accountsPartial({
|
|
7488
7595
|
admin: publicKey,
|
|
7489
7596
|
multisig: this.multisig.publicKey,
|
|
7490
7597
|
transferAuthority: poolConfig.transferAuthority,
|
|
@@ -7537,7 +7644,7 @@ var PerpetualsClient = (function () {
|
|
|
7537
7644
|
metadataSymbol: metadataSymbol,
|
|
7538
7645
|
metadataUri: metadataUri
|
|
7539
7646
|
})
|
|
7540
|
-
.
|
|
7647
|
+
.accountsPartial({
|
|
7541
7648
|
admin: publicKey,
|
|
7542
7649
|
multisig: this.multisig.publicKey,
|
|
7543
7650
|
transferAuthority: poolConfig.transferAuthority,
|
|
@@ -7591,7 +7698,7 @@ var PerpetualsClient = (function () {
|
|
|
7591
7698
|
withdrawInstantFee: withdrawInstantFee,
|
|
7592
7699
|
stakeLevel: stakeLevel,
|
|
7593
7700
|
})
|
|
7594
|
-
.
|
|
7701
|
+
.accountsPartial({
|
|
7595
7702
|
admin: publicKey,
|
|
7596
7703
|
multisig: this.multisig.publicKey,
|
|
7597
7704
|
perpetuals: this.perpetuals.publicKey,
|
|
@@ -7640,7 +7747,7 @@ var PerpetualsClient = (function () {
|
|
|
7640
7747
|
withdrawInstantFee: withdrawInstantFee,
|
|
7641
7748
|
stakeLevel: stakeLevel,
|
|
7642
7749
|
})
|
|
7643
|
-
.
|
|
7750
|
+
.accountsPartial({
|
|
7644
7751
|
admin: publicKey,
|
|
7645
7752
|
multisig: this.multisig.publicKey,
|
|
7646
7753
|
tokenVault: poolConfig.tokenVault,
|
|
@@ -7674,14 +7781,18 @@ var PerpetualsClient = (function () {
|
|
|
7674
7781
|
additionalSigners = [];
|
|
7675
7782
|
_a.label = 1;
|
|
7676
7783
|
case 1:
|
|
7677
|
-
_a.trys.push([1,
|
|
7784
|
+
_a.trys.push([1, 5, , 6]);
|
|
7678
7785
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.tokenMint, publicKey, true)];
|
|
7679
7786
|
case 2:
|
|
7680
7787
|
receivingTokenAccount = _a.sent();
|
|
7681
|
-
|
|
7788
|
+
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
|
7789
|
+
case 3:
|
|
7790
|
+
if (!(_a.sent())) {
|
|
7791
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint));
|
|
7792
|
+
}
|
|
7682
7793
|
return [4, this.program.methods
|
|
7683
7794
|
.withdrawInstantFees({})
|
|
7684
|
-
.
|
|
7795
|
+
.accountsPartial({
|
|
7685
7796
|
admin: publicKey,
|
|
7686
7797
|
multisig: this.multisig.publicKey,
|
|
7687
7798
|
perpetuals: this.perpetuals.publicKey,
|
|
@@ -7693,15 +7804,15 @@ var PerpetualsClient = (function () {
|
|
|
7693
7804
|
receivingTokenMint: poolConfig.tokenMint,
|
|
7694
7805
|
})
|
|
7695
7806
|
.instruction()];
|
|
7696
|
-
case
|
|
7807
|
+
case 4:
|
|
7697
7808
|
withdrawInstantFeeInstruction = _a.sent();
|
|
7698
7809
|
instructions.push(withdrawInstantFeeInstruction);
|
|
7699
|
-
return [3,
|
|
7700
|
-
case
|
|
7810
|
+
return [3, 6];
|
|
7811
|
+
case 5:
|
|
7701
7812
|
err_58 = _a.sent();
|
|
7702
7813
|
console.log("perpClient withdrawInstantFeeInstruction error:: ", err_58);
|
|
7703
7814
|
throw err_58;
|
|
7704
|
-
case
|
|
7815
|
+
case 6: return [2, {
|
|
7705
7816
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7706
7817
|
additionalSigners: additionalSigners
|
|
7707
7818
|
}];
|
|
@@ -7720,14 +7831,18 @@ var PerpetualsClient = (function () {
|
|
|
7720
7831
|
additionalSigners = [];
|
|
7721
7832
|
_a.label = 1;
|
|
7722
7833
|
case 1:
|
|
7723
|
-
_a.trys.push([1,
|
|
7834
|
+
_a.trys.push([1, 5, , 6]);
|
|
7724
7835
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.tokenMint, publicKey, true)];
|
|
7725
7836
|
case 2:
|
|
7726
7837
|
receivingTokenAccount = _a.sent();
|
|
7727
|
-
|
|
7838
|
+
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
|
7839
|
+
case 3:
|
|
7840
|
+
if (!(_a.sent())) {
|
|
7841
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint));
|
|
7842
|
+
}
|
|
7728
7843
|
return [4, this.program.methods
|
|
7729
7844
|
.withdrawUnclaimedTokens({})
|
|
7730
|
-
.
|
|
7845
|
+
.accountsPartial({
|
|
7731
7846
|
admin: publicKey,
|
|
7732
7847
|
multisig: this.multisig.publicKey,
|
|
7733
7848
|
perpetuals: this.perpetuals.publicKey,
|
|
@@ -7739,15 +7854,15 @@ var PerpetualsClient = (function () {
|
|
|
7739
7854
|
receivingTokenMint: poolConfig.tokenMint,
|
|
7740
7855
|
})
|
|
7741
7856
|
.instruction()];
|
|
7742
|
-
case
|
|
7857
|
+
case 4:
|
|
7743
7858
|
withdrawUnclaimedTokensInstruction = _a.sent();
|
|
7744
7859
|
instructions.push(withdrawUnclaimedTokensInstruction);
|
|
7745
|
-
return [3,
|
|
7746
|
-
case
|
|
7860
|
+
return [3, 6];
|
|
7861
|
+
case 5:
|
|
7747
7862
|
err_59 = _a.sent();
|
|
7748
7863
|
console.log("perpClient withdrawUnclaimedTokensInstruction error:: ", err_59);
|
|
7749
7864
|
throw err_59;
|
|
7750
|
-
case
|
|
7865
|
+
case 6: return [2, {
|
|
7751
7866
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
7752
7867
|
additionalSigners: additionalSigners
|
|
7753
7868
|
}];
|
|
@@ -7772,7 +7887,7 @@ var PerpetualsClient = (function () {
|
|
|
7772
7887
|
.initRevenueTokenAccount({
|
|
7773
7888
|
feeShareBps: feeShareBps
|
|
7774
7889
|
})
|
|
7775
|
-
.
|
|
7890
|
+
.accountsPartial({
|
|
7776
7891
|
admin: publicKey,
|
|
7777
7892
|
multisig: this.multisig.publicKey,
|
|
7778
7893
|
perpetuals: this.perpetuals.publicKey,
|
|
@@ -7820,7 +7935,7 @@ var PerpetualsClient = (function () {
|
|
|
7820
7935
|
.initRebateVault({
|
|
7821
7936
|
allowRebatePayout: allowRebatePayout
|
|
7822
7937
|
})
|
|
7823
|
-
.
|
|
7938
|
+
.accountsPartial({
|
|
7824
7939
|
admin: publicKey,
|
|
7825
7940
|
multisig: this.multisig.publicKey,
|
|
7826
7941
|
transferAuthority: poolConfig.transferAuthority,
|
|
@@ -7869,7 +7984,7 @@ var PerpetualsClient = (function () {
|
|
|
7869
7984
|
amount: amount,
|
|
7870
7985
|
epochCount: epochCount,
|
|
7871
7986
|
})
|
|
7872
|
-
.
|
|
7987
|
+
.accountsPartial({
|
|
7873
7988
|
admin: publicKey,
|
|
7874
7989
|
multisig: this.multisig.publicKey,
|
|
7875
7990
|
perpetuals: this.perpetuals.publicKey,
|
|
@@ -7878,8 +7993,6 @@ var PerpetualsClient = (function () {
|
|
|
7878
7993
|
tokenVault: poolConfig.tokenVault,
|
|
7879
7994
|
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
|
7880
7995
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
7881
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
7882
|
-
program: this.programId,
|
|
7883
7996
|
tokenMint: poolConfig.tokenMint,
|
|
7884
7997
|
})
|
|
7885
7998
|
.instruction()];
|
|
@@ -7916,7 +8029,7 @@ var PerpetualsClient = (function () {
|
|
|
7916
8029
|
.setTokenStakeLevel({
|
|
7917
8030
|
level: stakeLevel,
|
|
7918
8031
|
})
|
|
7919
|
-
.
|
|
8032
|
+
.accountsPartial({
|
|
7920
8033
|
admin: publicKey,
|
|
7921
8034
|
multisig: this.multisig.publicKey,
|
|
7922
8035
|
tokenStakeAccount: tokenStakeAccount,
|
|
@@ -7956,12 +8069,11 @@ var PerpetualsClient = (function () {
|
|
|
7956
8069
|
amount: amount,
|
|
7957
8070
|
epochCount: epochCount,
|
|
7958
8071
|
})
|
|
7959
|
-
.
|
|
8072
|
+
.accountsPartial({
|
|
7960
8073
|
admin: publicKey,
|
|
7961
8074
|
multisig: this.multisig.publicKey,
|
|
7962
8075
|
tokenVault: poolConfig.tokenVault,
|
|
7963
8076
|
tokenStakeAccount: tokenStakeAccount,
|
|
7964
|
-
eventAuthority: this.eventAuthority.publicKey,
|
|
7965
8077
|
program: this.programId
|
|
7966
8078
|
})
|
|
7967
8079
|
.instruction()];
|
|
@@ -7997,7 +8109,7 @@ var PerpetualsClient = (function () {
|
|
|
7997
8109
|
.resizeInternalOracle({
|
|
7998
8110
|
extOracle: extOracle
|
|
7999
8111
|
})
|
|
8000
|
-
.
|
|
8112
|
+
.accountsPartial({
|
|
8001
8113
|
admin: publicKey,
|
|
8002
8114
|
multisig: this.multisig.publicKey,
|
|
8003
8115
|
custodyTokenMint: tokenMint,
|
|
@@ -8041,7 +8153,7 @@ var PerpetualsClient = (function () {
|
|
|
8041
8153
|
isWithdrawalFeeExempt: isWithdrawalFeeExempt,
|
|
8042
8154
|
poolAddress: poolAddress,
|
|
8043
8155
|
})
|
|
8044
|
-
.
|
|
8156
|
+
.accountsPartial({
|
|
8045
8157
|
admin: publicKey,
|
|
8046
8158
|
multisig: this.multisig.publicKey,
|
|
8047
8159
|
owner: owner,
|
|
@@ -8085,7 +8197,7 @@ var PerpetualsClient = (function () {
|
|
|
8085
8197
|
isWithdrawalFeeExempt: isWithdrawalFeeExempt,
|
|
8086
8198
|
poolAddress: poolAddress
|
|
8087
8199
|
})
|
|
8088
|
-
.
|
|
8200
|
+
.accountsPartial({
|
|
8089
8201
|
admin: publicKey,
|
|
8090
8202
|
multisig: this.multisig.publicKey,
|
|
8091
8203
|
owner: owner,
|
|
@@ -8110,7 +8222,9 @@ var PerpetualsClient = (function () {
|
|
|
8110
8222
|
}); };
|
|
8111
8223
|
this.provider = provider;
|
|
8112
8224
|
(0, anchor_1.setProvider)(provider);
|
|
8113
|
-
this.program = new anchor_1.Program(
|
|
8225
|
+
this.program = new anchor_1.Program(perpetuals_json_1.default, {
|
|
8226
|
+
connection: provider.connection,
|
|
8227
|
+
});
|
|
8114
8228
|
this.programId = programId;
|
|
8115
8229
|
this.admin = this.provider.wallet.publicKey;
|
|
8116
8230
|
this.multisig = this.findProgramAddress("multisig");
|