flash-sdk 2.50.0 → 2.50.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -719,8 +719,7 @@ var PerpetualsClient = (function () {
719
719
  return { feeBps: fees.minFee, feeAmount: anchor_1.BN.max(amountAdd, amountRemove).mul(fees.minFee).div(new anchor_1.BN(constants_1.RATE_POWER)) };
720
720
  }
721
721
  var newRatio = _this.getNewRatioHelper(amountAdd, amountRemove, inputTokenCustodyAccount, maxOraclePrice, poolAumUsdMax);
722
- var inputCustodyConfig = poolConfig.custodies.find(function (i) { return i.custodyAccount.equals(inputTokenCustodyAccount.publicKey); });
723
- var index = inputCustodyConfig.custodyId;
722
+ var index = poolAccount.custodies.findIndex(function (c) { return c.equals(inputTokenCustodyAccount.publicKey); });
724
723
  var ratios = poolAccount.ratios[index];
725
724
  var fee = constants_1.BN_ZERO;
726
725
  if (action == types_1.FeesAction.AddLiquidity || action == types_1.FeesAction.SwapIn || action == types_1.FeesAction.StableSwapIn) {
@@ -2149,36 +2148,40 @@ var PerpetualsClient = (function () {
2149
2148
  }
2150
2149
  });
2151
2150
  }); };
2152
- this.getAddLiquidityAmountAndFeeView = function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
2153
- if (userPublicKey === void 0) { userPublicKey = undefined; }
2154
- return __awaiter(_this, void 0, void 0, function () {
2155
- var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_5, token, _a, custodies_6, custody, _b, _c, market, depositCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
2156
- var _d;
2157
- return __generator(this, function (_e) {
2158
- switch (_e.label) {
2151
+ this.getAddLiquidityAmountAndFeeView = function (amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1) {
2152
+ var args_1 = [];
2153
+ for (var _i = 4; _i < arguments.length; _i++) {
2154
+ args_1[_i - 4] = arguments[_i];
2155
+ }
2156
+ return __awaiter(_this, __spreadArray([amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
2157
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
2158
+ var _e;
2159
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
2160
+ return __generator(this, function (_f) {
2161
+ switch (_f.label) {
2159
2162
  case 0:
2160
2163
  backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
2161
2164
  custodies = POOL_CONFIG.custodies;
2162
2165
  custodyMetas = [];
2163
2166
  marketMetas = [];
2164
- for (_i = 0, custodies_5 = custodies; _i < custodies_5.length; _i++) {
2165
- token = custodies_5[_i];
2167
+ for (_a = 0, custodies_5 = custodies; _a < custodies_5.length; _a++) {
2168
+ token = custodies_5[_a];
2166
2169
  custodyMetas.push({
2167
2170
  isSigner: false,
2168
2171
  isWritable: false,
2169
2172
  pubkey: token.custodyAccount,
2170
2173
  });
2171
2174
  }
2172
- for (_a = 0, custodies_6 = custodies; _a < custodies_6.length; _a++) {
2173
- custody = custodies_6[_a];
2175
+ for (_b = 0, custodies_6 = custodies; _b < custodies_6.length; _b++) {
2176
+ custody = custodies_6[_b];
2174
2177
  custodyMetas.push({
2175
2178
  isSigner: false,
2176
2179
  isWritable: false,
2177
2180
  pubkey: custody.intOracleAccount,
2178
2181
  });
2179
2182
  }
2180
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2181
- market = _c[_b];
2183
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2184
+ market = _d[_c];
2182
2185
  marketMetas.push({
2183
2186
  pubkey: market.marketAccount,
2184
2187
  isSigner: false,
@@ -2201,14 +2204,14 @@ var PerpetualsClient = (function () {
2201
2204
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2202
2205
  .transaction()];
2203
2206
  case 1:
2204
- transaction = _e.sent();
2207
+ transaction = _f.sent();
2205
2208
  return [4, backUpOracleInstructionPromise];
2206
2209
  case 2:
2207
- backUpOracleInstruction = _e.sent();
2208
- (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
2210
+ backUpOracleInstruction = _f.sent();
2211
+ (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2209
2212
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2210
2213
  case 3:
2211
- result = _e.sent();
2214
+ result = _f.sent();
2212
2215
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddLiquidityAmountAndFee'; });
2213
2216
  res = this.viewHelper.decodeLogs(result, index, 'getAddLiquidityAmountAndFee');
2214
2217
  return [2, {
@@ -2219,36 +2222,40 @@ var PerpetualsClient = (function () {
2219
2222
  });
2220
2223
  });
2221
2224
  };
2222
- this.getRemoveLiquidityAmountAndFeeView = function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
2223
- if (userPublicKey === void 0) { userPublicKey = undefined; }
2224
- return __awaiter(_this, void 0, void 0, function () {
2225
- var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_7, token, _a, custodies_8, custody, _b, _c, market, removeCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
2226
- var _d;
2227
- return __generator(this, function (_e) {
2228
- switch (_e.label) {
2225
+ this.getRemoveLiquidityAmountAndFeeView = function (amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1) {
2226
+ var args_1 = [];
2227
+ for (var _i = 4; _i < arguments.length; _i++) {
2228
+ args_1[_i - 4] = arguments[_i];
2229
+ }
2230
+ return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
2231
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
2232
+ var _e;
2233
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
2234
+ return __generator(this, function (_f) {
2235
+ switch (_f.label) {
2229
2236
  case 0:
2230
2237
  backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
2231
2238
  custodies = POOL_CONFIG.custodies;
2232
2239
  custodyMetas = [];
2233
2240
  marketMetas = [];
2234
- for (_i = 0, custodies_7 = custodies; _i < custodies_7.length; _i++) {
2235
- token = custodies_7[_i];
2241
+ for (_a = 0, custodies_7 = custodies; _a < custodies_7.length; _a++) {
2242
+ token = custodies_7[_a];
2236
2243
  custodyMetas.push({
2237
2244
  isSigner: false,
2238
2245
  isWritable: false,
2239
2246
  pubkey: token.custodyAccount,
2240
2247
  });
2241
2248
  }
2242
- for (_a = 0, custodies_8 = custodies; _a < custodies_8.length; _a++) {
2243
- custody = custodies_8[_a];
2249
+ for (_b = 0, custodies_8 = custodies; _b < custodies_8.length; _b++) {
2250
+ custody = custodies_8[_b];
2244
2251
  custodyMetas.push({
2245
2252
  isSigner: false,
2246
2253
  isWritable: false,
2247
2254
  pubkey: custody.intOracleAccount,
2248
2255
  });
2249
2256
  }
2250
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2251
- market = _c[_b];
2257
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2258
+ market = _d[_c];
2252
2259
  marketMetas.push({
2253
2260
  pubkey: market.marketAccount,
2254
2261
  isSigner: false,
@@ -2271,14 +2278,14 @@ var PerpetualsClient = (function () {
2271
2278
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2272
2279
  .transaction()];
2273
2280
  case 1:
2274
- transaction = _e.sent();
2281
+ transaction = _f.sent();
2275
2282
  return [4, backUpOracleInstructionPromise];
2276
2283
  case 2:
2277
- backUpOracleInstruction = _e.sent();
2278
- (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
2284
+ backUpOracleInstruction = _f.sent();
2285
+ (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2279
2286
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2280
2287
  case 3:
2281
- result = _e.sent();
2288
+ result = _f.sent();
2282
2289
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveLiquidityAmountAndFee'; });
2283
2290
  if (result.value.err) {
2284
2291
  return [2, {
@@ -2354,36 +2361,40 @@ var PerpetualsClient = (function () {
2354
2361
  }
2355
2362
  });
2356
2363
  }); };
2357
- this.getAddCompoundingLiquidityAmountAndFeeView = function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
2358
- if (userPublicKey === void 0) { userPublicKey = undefined; }
2359
- return __awaiter(_this, void 0, void 0, function () {
2360
- var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_11, token, _a, custodies_12, custody, _b, _c, market, depositCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
2361
- var _d;
2362
- return __generator(this, function (_e) {
2363
- switch (_e.label) {
2364
+ this.getAddCompoundingLiquidityAmountAndFeeView = function (amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1) {
2365
+ var args_1 = [];
2366
+ for (var _i = 4; _i < arguments.length; _i++) {
2367
+ args_1[_i - 4] = arguments[_i];
2368
+ }
2369
+ return __awaiter(_this, __spreadArray([amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
2370
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
2371
+ var _e;
2372
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
2373
+ return __generator(this, function (_f) {
2374
+ switch (_f.label) {
2364
2375
  case 0:
2365
2376
  backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
2366
2377
  custodies = POOL_CONFIG.custodies;
2367
2378
  custodyMetas = [];
2368
2379
  marketMetas = [];
2369
- for (_i = 0, custodies_11 = custodies; _i < custodies_11.length; _i++) {
2370
- token = custodies_11[_i];
2380
+ for (_a = 0, custodies_11 = custodies; _a < custodies_11.length; _a++) {
2381
+ token = custodies_11[_a];
2371
2382
  custodyMetas.push({
2372
2383
  isSigner: false,
2373
2384
  isWritable: false,
2374
2385
  pubkey: token.custodyAccount,
2375
2386
  });
2376
2387
  }
2377
- for (_a = 0, custodies_12 = custodies; _a < custodies_12.length; _a++) {
2378
- custody = custodies_12[_a];
2388
+ for (_b = 0, custodies_12 = custodies; _b < custodies_12.length; _b++) {
2389
+ custody = custodies_12[_b];
2379
2390
  custodyMetas.push({
2380
2391
  isSigner: false,
2381
2392
  isWritable: false,
2382
2393
  pubkey: custody.intOracleAccount,
2383
2394
  });
2384
2395
  }
2385
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2386
- market = _c[_b];
2396
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2397
+ market = _d[_c];
2387
2398
  marketMetas.push({
2388
2399
  pubkey: market.marketAccount,
2389
2400
  isSigner: false,
@@ -2394,7 +2405,7 @@ var PerpetualsClient = (function () {
2394
2405
  rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
2395
2406
  return [4, backUpOracleInstructionPromise];
2396
2407
  case 1:
2397
- backUpOracleInstruction = _e.sent();
2408
+ backUpOracleInstruction = _f.sent();
2398
2409
  return [4, this.program.methods
2399
2410
  .getAddCompoundingLiquidityAmountAndFee({
2400
2411
  amountIn: amount,
@@ -2413,11 +2424,11 @@ var PerpetualsClient = (function () {
2413
2424
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2414
2425
  .transaction()];
2415
2426
  case 2:
2416
- transaction = _e.sent();
2417
- (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
2427
+ transaction = _f.sent();
2428
+ (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2418
2429
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2419
2430
  case 3:
2420
- result = _e.sent();
2431
+ result = _f.sent();
2421
2432
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddCompoundingLiquidityAmountAndFee'; });
2422
2433
  res = this.viewHelper.decodeLogs(result, index, 'getAddCompoundingLiquidityAmountAndFee');
2423
2434
  return [2, {
@@ -2428,36 +2439,40 @@ var PerpetualsClient = (function () {
2428
2439
  });
2429
2440
  });
2430
2441
  };
2431
- this.getRemoveCompoundingLiquidityAmountAndFeeView = function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
2432
- if (userPublicKey === void 0) { userPublicKey = undefined; }
2433
- return __awaiter(_this, void 0, void 0, function () {
2434
- var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_13, token, _a, custodies_14, custody, _b, _c, market, removeCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
2435
- var _d;
2436
- return __generator(this, function (_e) {
2437
- switch (_e.label) {
2442
+ this.getRemoveCompoundingLiquidityAmountAndFeeView = function (amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1) {
2443
+ var args_1 = [];
2444
+ for (var _i = 4; _i < arguments.length; _i++) {
2445
+ args_1[_i - 4] = arguments[_i];
2446
+ }
2447
+ return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
2448
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
2449
+ var _e;
2450
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
2451
+ return __generator(this, function (_f) {
2452
+ switch (_f.label) {
2438
2453
  case 0:
2439
2454
  backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
2440
2455
  custodies = POOL_CONFIG.custodies;
2441
2456
  custodyMetas = [];
2442
2457
  marketMetas = [];
2443
- for (_i = 0, custodies_13 = custodies; _i < custodies_13.length; _i++) {
2444
- token = custodies_13[_i];
2458
+ for (_a = 0, custodies_13 = custodies; _a < custodies_13.length; _a++) {
2459
+ token = custodies_13[_a];
2445
2460
  custodyMetas.push({
2446
2461
  isSigner: false,
2447
2462
  isWritable: false,
2448
2463
  pubkey: token.custodyAccount,
2449
2464
  });
2450
2465
  }
2451
- for (_a = 0, custodies_14 = custodies; _a < custodies_14.length; _a++) {
2452
- custody = custodies_14[_a];
2466
+ for (_b = 0, custodies_14 = custodies; _b < custodies_14.length; _b++) {
2467
+ custody = custodies_14[_b];
2453
2468
  custodyMetas.push({
2454
2469
  isSigner: false,
2455
2470
  isWritable: false,
2456
2471
  pubkey: custody.intOracleAccount,
2457
2472
  });
2458
2473
  }
2459
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2460
- market = _c[_b];
2474
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2475
+ market = _d[_c];
2461
2476
  marketMetas.push({
2462
2477
  pubkey: market.marketAccount,
2463
2478
  isSigner: false,
@@ -2468,7 +2483,7 @@ var PerpetualsClient = (function () {
2468
2483
  rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
2469
2484
  return [4, backUpOracleInstructionPromise];
2470
2485
  case 1:
2471
- backUpOracleInstruction = _e.sent();
2486
+ backUpOracleInstruction = _f.sent();
2472
2487
  return [4, this.program.methods
2473
2488
  .getRemoveCompoundingLiquidityAmountAndFee({
2474
2489
  compoundingAmountIn: amount,
@@ -2487,11 +2502,11 @@ var PerpetualsClient = (function () {
2487
2502
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2488
2503
  .transaction()];
2489
2504
  case 2:
2490
- transaction = _e.sent();
2491
- (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
2505
+ transaction = _f.sent();
2506
+ (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2492
2507
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2493
2508
  case 3:
2494
- result = _e.sent();
2509
+ result = _f.sent();
2495
2510
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveCompoundingLiquidityAmountAndFee'; });
2496
2511
  if (result.value.err) {
2497
2512
  return [2, {
@@ -2630,14 +2645,18 @@ var PerpetualsClient = (function () {
2630
2645
  }
2631
2646
  });
2632
2647
  }); };
2633
- this.openPosition = function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
2634
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2635
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2636
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2637
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2638
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2639
- return __awaiter(_this, void 0, void 0, function () {
2648
+ this.openPosition = function (targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1) {
2649
+ var args_1 = [];
2650
+ for (var _i = 8; _i < arguments.length; _i++) {
2651
+ args_1[_i - 8] = arguments[_i];
2652
+ }
2653
+ 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, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
2640
2654
  var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
2655
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2656
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2657
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2658
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2659
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2641
2660
  return __generator(this, function (_c) {
2642
2661
  switch (_c.label) {
2643
2662
  case 0:
@@ -2741,15 +2760,19 @@ var PerpetualsClient = (function () {
2741
2760
  });
2742
2761
  });
2743
2762
  };
2744
- this.closePosition = function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
2745
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2746
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2747
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2748
- if (createUserATA === void 0) { createUserATA = true; }
2749
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
2750
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2751
- return __awaiter(_this, void 0, void 0, function () {
2763
+ this.closePosition = function (marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
2764
+ var args_1 = [];
2765
+ for (var _i = 6; _i < arguments.length; _i++) {
2766
+ args_1[_i - 6] = arguments[_i];
2767
+ }
2768
+ 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, rebateTokenAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
2752
2769
  var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_2;
2770
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2771
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2772
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2773
+ if (createUserATA === void 0) { createUserATA = true; }
2774
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
2775
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2753
2776
  return __generator(this, function (_b) {
2754
2777
  switch (_b.label) {
2755
2778
  case 0:
@@ -2846,14 +2869,18 @@ var PerpetualsClient = (function () {
2846
2869
  });
2847
2870
  });
2848
2871
  };
2849
- this.swapAndOpen = function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, minCollateralAmountOut, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
2850
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2851
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2852
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2853
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2854
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2855
- return __awaiter(_this, void 0, void 0, function () {
2872
+ this.swapAndOpen = function (targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, minCollateralAmountOut_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1) {
2873
+ var args_1 = [];
2874
+ for (var _i = 10; _i < arguments.length; _i++) {
2875
+ args_1[_i - 10] = arguments[_i];
2876
+ }
2877
+ return __awaiter(_this, __spreadArray([targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, minCollateralAmountOut_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, minCollateralAmountOut, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
2856
2878
  var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_2;
2879
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2880
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2881
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2882
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2883
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2857
2884
  return __generator(this, function (_c) {
2858
2885
  switch (_c.label) {
2859
2886
  case 0:
@@ -2993,13 +3020,17 @@ var PerpetualsClient = (function () {
2993
3020
  });
2994
3021
  });
2995
3022
  };
2996
- this.closeAndSwap = function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, minSwapAmountOut, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, ephemeralSignerPubkey) {
2997
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2998
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2999
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3000
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3001
- return __awaiter(_this, void 0, void 0, function () {
3023
+ this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, minSwapAmountOut_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
3024
+ var args_1 = [];
3025
+ for (var _i = 8; _i < arguments.length; _i++) {
3026
+ args_1[_i - 8] = arguments[_i];
3027
+ }
3028
+ return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, minSwapAmountOut_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, minSwapAmountOut, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, ephemeralSignerPubkey) {
3002
3029
  var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, inx, err_3;
3030
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3031
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3032
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3033
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3003
3034
  return __generator(this, function (_a) {
3004
3035
  switch (_a.label) {
3005
3036
  case 0:
@@ -3113,16 +3144,20 @@ var PerpetualsClient = (function () {
3113
3144
  });
3114
3145
  });
3115
3146
  };
3116
- this.swap = function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey) {
3117
- if (useFeesPool === void 0) { useFeesPool = false; }
3118
- if (createUserATA === void 0) { createUserATA = true; }
3119
- if (unWrapSol === void 0) { unWrapSol = false; }
3120
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3121
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3122
- return __awaiter(_this, void 0, void 0, function () {
3123
- 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, _i, _e, custody, params, inx, closeWsolATAIns, err_4;
3124
- return __generator(this, function (_f) {
3125
- switch (_f.label) {
3147
+ this.swap = function (userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1) {
3148
+ var args_1 = [];
3149
+ for (var _i = 5; _i < arguments.length; _i++) {
3150
+ args_1[_i - 5] = arguments[_i];
3151
+ }
3152
+ 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) {
3153
+ 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, params, inx, closeWsolATAIns, err_4;
3154
+ if (useFeesPool === void 0) { useFeesPool = false; }
3155
+ if (createUserATA === void 0) { createUserATA = true; }
3156
+ if (unWrapSol === void 0) { unWrapSol = false; }
3157
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3158
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3159
+ return __generator(this, function (_g) {
3160
+ switch (_g.label) {
3126
3161
  case 0:
3127
3162
  userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
3128
3163
  if (!userInputCustodyConfig) {
@@ -3140,10 +3175,10 @@ var PerpetualsClient = (function () {
3140
3175
  if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
3141
3176
  return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
3142
3177
  case 1:
3143
- wsolAssociatedTokenAccount = _f.sent();
3178
+ wsolAssociatedTokenAccount = _g.sent();
3144
3179
  return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
3145
3180
  case 2:
3146
- wsolATAExist = _f.sent();
3181
+ wsolATAExist = _g.sent();
3147
3182
  if (!wsolATAExist) {
3148
3183
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
3149
3184
  }
@@ -3151,11 +3186,11 @@ var PerpetualsClient = (function () {
3151
3186
  _a = anchor_1.BN.bind;
3152
3187
  return [4, this.provider.connection.getBalance(publicKey)];
3153
3188
  case 3:
3154
- unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
3189
+ unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
3155
3190
  if (unWrappedSolBalance.lt(amountIn)) {
3156
3191
  throw "Insufficient SOL Funds";
3157
3192
  }
3158
- _f.label = 4;
3193
+ _g.label = 4;
3159
3194
  case 4:
3160
3195
  instructions.push(web3_js_1.SystemProgram.transfer({
3161
3196
  fromPubkey: publicKey,
@@ -3177,20 +3212,20 @@ var PerpetualsClient = (function () {
3177
3212
  additionalSigners: additionalSigners
3178
3213
  }];
3179
3214
  }
3180
- _f.label = 6;
3215
+ _g.label = 6;
3181
3216
  case 6:
3182
- _f.trys.push([6, 19, , 20]);
3217
+ _g.trys.push([6, 19, , 20]);
3183
3218
  if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
3184
3219
  console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
3185
3220
  return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
3186
3221
  case 7:
3187
- accCreationLamports = (_f.sent());
3222
+ accCreationLamports = (_g.sent());
3188
3223
  console.log("accCreationLamports:", accCreationLamports);
3189
3224
  lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
3190
3225
  _b = anchor_1.BN.bind;
3191
3226
  return [4, this.provider.connection.getBalance(publicKey)];
3192
3227
  case 8:
3193
- unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _f.sent()]))();
3228
+ unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _g.sent()]))();
3194
3229
  if (unWrappedSolBalance.lt(amountIn)) {
3195
3230
  throw "Insufficient SOL Funds";
3196
3231
  }
@@ -3217,18 +3252,18 @@ var PerpetualsClient = (function () {
3217
3252
  userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
3218
3253
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
3219
3254
  case 10:
3220
- if (!(_f.sent())) {
3255
+ if (!(_g.sent())) {
3221
3256
  throw "Insufficient Funds , Token Account doesn't exist";
3222
3257
  }
3223
3258
  if (!!skipBalanceChecks) return [3, 12];
3224
3259
  _c = anchor_1.BN.bind;
3225
3260
  return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
3226
3261
  case 11:
3227
- tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
3262
+ tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
3228
3263
  if (tokenAccountBalance.lt(amountIn)) {
3229
3264
  throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
3230
3265
  }
3231
- _f.label = 12;
3266
+ _g.label = 12;
3232
3267
  case 12:
3233
3268
  if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
3234
3269
  lamports = (this.minimumBalanceForRentExemptAccountLamports);
@@ -3253,23 +3288,23 @@ var PerpetualsClient = (function () {
3253
3288
  return [3, 17];
3254
3289
  case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
3255
3290
  case 14:
3256
- userOutputTokenAccount = _f.sent();
3291
+ userOutputTokenAccount = _g.sent();
3257
3292
  _d = createUserATA;
3258
3293
  if (!_d) return [3, 16];
3259
3294
  return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
3260
3295
  case 15:
3261
- _d = !(_f.sent());
3262
- _f.label = 16;
3296
+ _d = !(_g.sent());
3297
+ _g.label = 16;
3263
3298
  case 16:
3264
3299
  if (_d) {
3265
3300
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
3266
3301
  }
3267
- _f.label = 17;
3302
+ _g.label = 17;
3268
3303
  case 17:
3269
3304
  custodyAccountMetas = [];
3270
3305
  custodyOracleAccountMetas = [];
3271
- for (_i = 0, _e = poolConfig.custodies; _i < _e.length; _i++) {
3272
- custody = _e[_i];
3306
+ for (_e = 0, _f = poolConfig.custodies; _e < _f.length; _e++) {
3307
+ custody = _f[_e];
3273
3308
  custodyAccountMetas.push({
3274
3309
  pubkey: custody.custodyAccount,
3275
3310
  isSigner: false,
@@ -3309,7 +3344,7 @@ var PerpetualsClient = (function () {
3309
3344
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
3310
3345
  .instruction()];
3311
3346
  case 18:
3312
- inx = _f.sent();
3347
+ inx = _g.sent();
3313
3348
  instructions.push(inx);
3314
3349
  if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
3315
3350
  closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
@@ -3317,7 +3352,7 @@ var PerpetualsClient = (function () {
3317
3352
  }
3318
3353
  return [3, 20];
3319
3354
  case 19:
3320
- err_4 = _f.sent();
3355
+ err_4 = _g.sent();
3321
3356
  console.error("perpClient Swap error:: ", err_4);
3322
3357
  throw err_4;
3323
3358
  case 20: return [2, {
@@ -3399,11 +3434,15 @@ var PerpetualsClient = (function () {
3399
3434
  }
3400
3435
  });
3401
3436
  }); };
3402
- this.addCollateral = function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
3403
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3404
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3405
- return __awaiter(_this, void 0, void 0, function () {
3437
+ this.addCollateral = function (collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
3438
+ var args_1 = [];
3439
+ for (var _i = 6; _i < arguments.length; _i++) {
3440
+ args_1[_i - 6] = arguments[_i];
3441
+ }
3442
+ 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) {
3406
3443
  var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
3444
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3445
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3407
3446
  return __generator(this, function (_c) {
3408
3447
  switch (_c.label) {
3409
3448
  case 0:
@@ -3497,11 +3536,15 @@ var PerpetualsClient = (function () {
3497
3536
  });
3498
3537
  });
3499
3538
  };
3500
- this.swapAndAddCollateral = function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minCollateralAmountOut, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
3501
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3502
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3503
- return __awaiter(_this, void 0, void 0, function () {
3539
+ this.swapAndAddCollateral = function (targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1) {
3540
+ var args_1 = [];
3541
+ for (var _i = 8; _i < arguments.length; _i++) {
3542
+ args_1[_i - 8] = arguments[_i];
3543
+ }
3544
+ return __awaiter(_this, __spreadArray([targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minCollateralAmountOut, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
3504
3545
  var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
3546
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3547
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3505
3548
  return __generator(this, function (_c) {
3506
3549
  switch (_c.label) {
3507
3550
  case 0:
@@ -3612,12 +3655,16 @@ var PerpetualsClient = (function () {
3612
3655
  });
3613
3656
  });
3614
3657
  };
3615
- this.removeCollateral = function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
3616
- if (createUserATA === void 0) { createUserATA = true; }
3617
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
3618
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3619
- return __awaiter(_this, void 0, void 0, function () {
3658
+ this.removeCollateral = function (collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
3659
+ var args_1 = [];
3660
+ for (var _i = 6; _i < arguments.length; _i++) {
3661
+ args_1[_i - 6] = arguments[_i];
3662
+ }
3663
+ return __awaiter(_this, __spreadArray([collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
3620
3664
  var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns, error_3;
3665
+ if (createUserATA === void 0) { createUserATA = true; }
3666
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
3667
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3621
3668
  return __generator(this, function (_b) {
3622
3669
  switch (_b.label) {
3623
3670
  case 0:
@@ -3718,10 +3765,14 @@ var PerpetualsClient = (function () {
3718
3765
  });
3719
3766
  });
3720
3767
  };
3721
- this.removeCollateralAndSwap = function (targetSymbol, collateralSymbol, outputSymbol, minSwapAmountOut, collateralDelta, side, poolConfig, ephemeralSignerPubkey) {
3722
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3723
- return __awaiter(_this, void 0, void 0, function () {
3768
+ this.removeCollateralAndSwap = function (targetSymbol_1, collateralSymbol_1, outputSymbol_1, minSwapAmountOut_1, collateralDelta_1, side_1, poolConfig_1) {
3769
+ var args_1 = [];
3770
+ for (var _i = 7; _i < arguments.length; _i++) {
3771
+ args_1[_i - 7] = arguments[_i];
3772
+ }
3773
+ return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, outputSymbol_1, minSwapAmountOut_1, collateralDelta_1, side_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, outputSymbol, minSwapAmountOut, collateralDelta, side, poolConfig, ephemeralSignerPubkey) {
3724
3774
  var publicKey, targetCustodyConfig, collateralCustodyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, instruction;
3775
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3725
3776
  return __generator(this, function (_a) {
3726
3777
  switch (_a.label) {
3727
3778
  case 0:
@@ -3814,12 +3865,16 @@ var PerpetualsClient = (function () {
3814
3865
  });
3815
3866
  });
3816
3867
  };
3817
- this.increaseSize = function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
3818
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3819
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3820
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3821
- return __awaiter(_this, void 0, void 0, function () {
3868
+ this.increaseSize = function (targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
3869
+ var args_1 = [];
3870
+ for (var _i = 8; _i < arguments.length; _i++) {
3871
+ args_1[_i - 8] = arguments[_i];
3872
+ }
3873
+ 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, rebateTokenAccount) {
3822
3874
  var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
3875
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3876
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3877
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3823
3878
  return __generator(this, function (_a) {
3824
3879
  switch (_a.label) {
3825
3880
  case 0:
@@ -3874,12 +3929,16 @@ var PerpetualsClient = (function () {
3874
3929
  });
3875
3930
  });
3876
3931
  };
3877
- this.decreaseSize = function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
3878
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3879
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3880
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3881
- return __awaiter(_this, void 0, void 0, function () {
3932
+ this.decreaseSize = function (targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
3933
+ var args_1 = [];
3934
+ for (var _i = 8; _i < arguments.length; _i++) {
3935
+ args_1[_i - 8] = arguments[_i];
3936
+ }
3937
+ 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, rebateTokenAccount) {
3882
3938
  var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
3939
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3940
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3941
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3883
3942
  return __generator(this, function (_a) {
3884
3943
  switch (_a.label) {
3885
3944
  case 0:
@@ -3934,13 +3993,17 @@ var PerpetualsClient = (function () {
3934
3993
  });
3935
3994
  });
3936
3995
  };
3937
- this.addLiquidity = function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
3938
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3939
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3940
- return __awaiter(_this, void 0, void 0, function () {
3941
- var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, tokenAccountBalance, _e, instruction, err_6;
3942
- return __generator(this, function (_f) {
3943
- switch (_f.label) {
3996
+ this.addLiquidity = function (payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1) {
3997
+ var args_1 = [];
3998
+ for (var _i = 4; _i < arguments.length; _i++) {
3999
+ args_1[_i - 4] = arguments[_i];
4000
+ }
4001
+ return __awaiter(_this, __spreadArray([payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
4002
+ var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, tokenAccountBalance, _f, instruction, err_6;
4003
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4004
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4005
+ return __generator(this, function (_g) {
4006
+ switch (_g.label) {
3944
4007
  case 0:
3945
4008
  publicKey = this.provider.wallet.publicKey;
3946
4009
  payTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey); });
@@ -3951,16 +4014,16 @@ var PerpetualsClient = (function () {
3951
4014
  instructions = [];
3952
4015
  postInstructions = [];
3953
4016
  additionalSigners = [];
3954
- _f.label = 1;
4017
+ _g.label = 1;
3955
4018
  case 1:
3956
- _f.trys.push([1, 10, , 11]);
4019
+ _g.trys.push([1, 10, , 11]);
3957
4020
  userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true);
3958
4021
  lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
3959
4022
  custodyAccountMetas = [];
3960
4023
  custodyOracleAccountMetas = [];
3961
4024
  markets = [];
3962
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
3963
- custody = _a[_i];
4025
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
4026
+ custody = _b[_a];
3964
4027
  custodyAccountMetas.push({
3965
4028
  pubkey: custody.custodyAccount,
3966
4029
  isSigner: false,
@@ -3972,8 +4035,8 @@ var PerpetualsClient = (function () {
3972
4035
  isWritable: false,
3973
4036
  });
3974
4037
  }
3975
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
3976
- market = _c[_b];
4038
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
4039
+ market = _d[_c];
3977
4040
  markets.push({
3978
4041
  pubkey: market.marketAccount,
3979
4042
  isSigner: false,
@@ -3982,21 +4045,21 @@ var PerpetualsClient = (function () {
3982
4045
  }
3983
4046
  return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
3984
4047
  case 2:
3985
- if (!(_f.sent())) {
4048
+ if (!(_g.sent())) {
3986
4049
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
3987
4050
  }
3988
4051
  if (!(payTokenSymbol == 'SOL')) return [3, 5];
3989
4052
  console.log("payTokenSymbol === SOL", payTokenSymbol);
3990
4053
  lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
3991
4054
  if (!!skipBalanceChecks) return [3, 4];
3992
- _d = anchor_1.BN.bind;
4055
+ _e = anchor_1.BN.bind;
3993
4056
  return [4, this.provider.connection.getBalance(publicKey)];
3994
4057
  case 3:
3995
- unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _f.sent()]))();
4058
+ unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _g.sent()]))();
3996
4059
  if (unWrappedSolBalance.lt(lamports)) {
3997
4060
  throw "Insufficient SOL Funds";
3998
4061
  }
3999
- _f.label = 4;
4062
+ _g.label = 4;
4000
4063
  case 4:
4001
4064
  if (!ephemeralSignerPubkey) {
4002
4065
  wrappedSolAccount = new web3_js_1.Keypair();
@@ -4020,17 +4083,17 @@ var PerpetualsClient = (function () {
4020
4083
  if (!!skipBalanceChecks) return [3, 8];
4021
4084
  return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
4022
4085
  case 6:
4023
- if (!(_f.sent())) {
4086
+ if (!(_g.sent())) {
4024
4087
  throw "Insufficient Funds , token Account doesn't exist";
4025
4088
  }
4026
- _e = anchor_1.BN.bind;
4089
+ _f = anchor_1.BN.bind;
4027
4090
  return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
4028
4091
  case 7:
4029
- tokenAccountBalance = new (_e.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
4092
+ tokenAccountBalance = new (_f.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
4030
4093
  if (tokenAccountBalance.lt(tokenAmountIn)) {
4031
4094
  throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
4032
4095
  }
4033
- _f.label = 8;
4096
+ _g.label = 8;
4034
4097
  case 8: return [4, this.program.methods
4035
4098
  .addLiquidity({
4036
4099
  amountIn: tokenAmountIn,
@@ -4055,11 +4118,11 @@ var PerpetualsClient = (function () {
4055
4118
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4056
4119
  .instruction()];
4057
4120
  case 9:
4058
- instruction = _f.sent();
4121
+ instruction = _g.sent();
4059
4122
  instructions.push(instruction);
4060
4123
  return [3, 11];
4061
4124
  case 10:
4062
- err_6 = _f.sent();
4125
+ err_6 = _g.sent();
4063
4126
  console.error("perpClient addLiquidity error:: ", err_6);
4064
4127
  throw err_6;
4065
4128
  case 11: return [2, {
@@ -4070,14 +4133,18 @@ var PerpetualsClient = (function () {
4070
4133
  });
4071
4134
  });
4072
4135
  };
4073
- this.addLiquidityAndStake = function (inputSymbol, amountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
4074
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4075
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4076
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4077
- return __awaiter(_this, void 0, void 0, function () {
4078
- var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, flpStakeAccount, poolStakedLpVault, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _c, custody, _d, _e, market, instruction;
4079
- return __generator(this, function (_f) {
4080
- switch (_f.label) {
4136
+ this.addLiquidityAndStake = function (inputSymbol_1, amountIn_1, minLpAmountOut_1, poolConfig_1) {
4137
+ var args_1 = [];
4138
+ for (var _i = 4; _i < arguments.length; _i++) {
4139
+ args_1[_i - 4] = arguments[_i];
4140
+ }
4141
+ return __awaiter(_this, __spreadArray([inputSymbol_1, amountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (inputSymbol, amountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
4142
+ var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, flpStakeAccount, poolStakedLpVault, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, instruction;
4143
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4144
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4145
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4146
+ return __generator(this, function (_g) {
4147
+ switch (_g.label) {
4081
4148
  case 0:
4082
4149
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
4083
4150
  preInstructions = [];
@@ -4097,14 +4164,14 @@ var PerpetualsClient = (function () {
4097
4164
  _a = anchor_1.BN.bind;
4098
4165
  return [4, this.provider.connection.getBalance(publicKey)];
4099
4166
  case 1:
4100
- unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
4167
+ unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
4101
4168
  if (unWrappedSolBalance.lt(lamports)) {
4102
4169
  throw "Insufficient SOL Funds";
4103
4170
  }
4104
- _f.label = 2;
4171
+ _g.label = 2;
4105
4172
  case 2: return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
4106
4173
  case 3:
4107
- if (!(_f.sent())) {
4174
+ if (!(_g.sent())) {
4108
4175
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
4109
4176
  }
4110
4177
  if (!ephemeralSignerPubkey) {
@@ -4130,23 +4197,23 @@ var PerpetualsClient = (function () {
4130
4197
  if (!!skipBalanceChecks) return [3, 7];
4131
4198
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
4132
4199
  case 5:
4133
- if (!(_f.sent())) {
4200
+ if (!(_g.sent())) {
4134
4201
  throw "Insufficient Funds , token Account doesn't exist";
4135
4202
  }
4136
4203
  _b = anchor_1.BN.bind;
4137
4204
  return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
4138
4205
  case 6:
4139
- tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
4206
+ tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
4140
4207
  if (tokenAccountBalance.lt(amountIn)) {
4141
4208
  throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
4142
4209
  }
4143
- _f.label = 7;
4210
+ _g.label = 7;
4144
4211
  case 7:
4145
4212
  custodyAccountMetas = [];
4146
4213
  custodyOracleAccountMetas = [];
4147
4214
  markets = [];
4148
- for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
4149
- custody = _c[_i];
4215
+ for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
4216
+ custody = _d[_c];
4150
4217
  custodyAccountMetas.push({
4151
4218
  pubkey: custody.custodyAccount,
4152
4219
  isSigner: false,
@@ -4158,8 +4225,8 @@ var PerpetualsClient = (function () {
4158
4225
  isWritable: false,
4159
4226
  });
4160
4227
  }
4161
- for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
4162
- market = _e[_d];
4228
+ for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
4229
+ market = _f[_e];
4163
4230
  markets.push({
4164
4231
  pubkey: market.marketAccount,
4165
4232
  isSigner: false,
@@ -4191,7 +4258,7 @@ var PerpetualsClient = (function () {
4191
4258
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4192
4259
  .instruction()];
4193
4260
  case 8:
4194
- instruction = _f.sent();
4261
+ instruction = _g.sent();
4195
4262
  instructions.push(instruction);
4196
4263
  return [2, {
4197
4264
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -4201,16 +4268,20 @@ var PerpetualsClient = (function () {
4201
4268
  });
4202
4269
  });
4203
4270
  };
4204
- this.removeLiquidity = function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey, userPublicKey) {
4205
- if (closeLpATA === void 0) { closeLpATA = false; }
4206
- if (createUserATA === void 0) { createUserATA = true; }
4207
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
4208
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4209
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4210
- return __awaiter(_this, void 0, void 0, function () {
4211
- var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, _d, removeLiquidityTx, closeInx, closeWsolATAIns, err_7;
4212
- return __generator(this, function (_e) {
4213
- switch (_e.label) {
4271
+ this.removeLiquidity = function (recieveTokenSymbol_1, liquidityAmountIn_1, minTokenAmountOut_1, poolConfig_1) {
4272
+ var args_1 = [];
4273
+ for (var _i = 4; _i < arguments.length; _i++) {
4274
+ args_1[_i - 4] = arguments[_i];
4275
+ }
4276
+ return __awaiter(_this, __spreadArray([recieveTokenSymbol_1, liquidityAmountIn_1, minTokenAmountOut_1, poolConfig_1], args_1, true), void 0, function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey, userPublicKey) {
4277
+ var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, _e, removeLiquidityTx, closeInx, closeWsolATAIns, err_7;
4278
+ if (closeLpATA === void 0) { closeLpATA = false; }
4279
+ if (createUserATA === void 0) { createUserATA = true; }
4280
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
4281
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4282
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4283
+ return __generator(this, function (_f) {
4284
+ switch (_f.label) {
4214
4285
  case 0:
4215
4286
  recieveTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey); });
4216
4287
  if (!recieveTokenCustodyConfig) {
@@ -4221,15 +4292,15 @@ var PerpetualsClient = (function () {
4221
4292
  instructions = [];
4222
4293
  postInstructions = [];
4223
4294
  additionalSigners = [];
4224
- _e.label = 1;
4295
+ _f.label = 1;
4225
4296
  case 1:
4226
- _e.trys.push([1, 7, , 8]);
4297
+ _f.trys.push([1, 7, , 8]);
4227
4298
  stakedLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
4228
4299
  custodyAccountMetas = [];
4229
4300
  custodyOracleAccountMetas = [];
4230
4301
  markets = [];
4231
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
4232
- custody = _a[_i];
4302
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
4303
+ custody = _b[_a];
4233
4304
  custodyAccountMetas.push({
4234
4305
  pubkey: custody.custodyAccount,
4235
4306
  isSigner: false,
@@ -4241,8 +4312,8 @@ var PerpetualsClient = (function () {
4241
4312
  isWritable: false,
4242
4313
  });
4243
4314
  }
4244
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
4245
- market = _c[_b];
4315
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
4316
+ market = _d[_c];
4246
4317
  markets.push({
4247
4318
  pubkey: market.marketAccount,
4248
4319
  isSigner: false,
@@ -4271,17 +4342,17 @@ var PerpetualsClient = (function () {
4271
4342
  return [3, 5];
4272
4343
  case 2:
4273
4344
  userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true);
4274
- _d = createUserATA;
4275
- if (!_d) return [3, 4];
4345
+ _e = createUserATA;
4346
+ if (!_e) return [3, 4];
4276
4347
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
4277
4348
  case 3:
4278
- _d = !(_e.sent());
4279
- _e.label = 4;
4349
+ _e = !(_f.sent());
4350
+ _f.label = 4;
4280
4351
  case 4:
4281
- if (_d) {
4352
+ if (_e) {
4282
4353
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey));
4283
4354
  }
4284
- _e.label = 5;
4355
+ _f.label = 5;
4285
4356
  case 5: return [4, this.program.methods
4286
4357
  .removeLiquidity({
4287
4358
  lpAmountIn: liquidityAmountIn,
@@ -4306,7 +4377,7 @@ var PerpetualsClient = (function () {
4306
4377
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4307
4378
  .instruction()];
4308
4379
  case 6:
4309
- removeLiquidityTx = _e.sent();
4380
+ removeLiquidityTx = _f.sent();
4310
4381
  instructions.push(removeLiquidityTx);
4311
4382
  if (closeLpATA) {
4312
4383
  closeInx = (0, spl_token_1.createCloseAccountInstruction)(stakedLpTokenAccount, publicKey, publicKey);
@@ -4318,7 +4389,7 @@ var PerpetualsClient = (function () {
4318
4389
  }
4319
4390
  return [3, 8];
4320
4391
  case 7:
4321
- err_7 = _e.sent();
4392
+ err_7 = _f.sent();
4322
4393
  console.log("perpClient removeLiquidity error:: ", err_7);
4323
4394
  throw err_7;
4324
4395
  case 8: return [2, {
@@ -4736,22 +4807,26 @@ var PerpetualsClient = (function () {
4736
4807
  }
4737
4808
  });
4738
4809
  }); };
4739
- this.refreshStakeWithTokenStake = function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
4740
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4741
- return __awaiter(_this, void 0, void 0, function () {
4742
- var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_16;
4743
- return __generator(this, function (_b) {
4744
- switch (_b.label) {
4810
+ this.refreshStakeWithTokenStake = function (rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1) {
4811
+ var args_1 = [];
4812
+ for (var _i = 3; _i < arguments.length; _i++) {
4813
+ args_1[_i - 3] = arguments[_i];
4814
+ }
4815
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
4816
+ var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_16;
4817
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4818
+ return __generator(this, function (_c) {
4819
+ switch (_c.label) {
4745
4820
  case 0:
4746
- _b.trys.push([0, 2, , 3]);
4821
+ _c.trys.push([0, 2, , 3]);
4747
4822
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
4748
4823
  rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
4749
4824
  rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
4750
4825
  pool = poolConfig.poolAddress;
4751
4826
  feeDistributionTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("custody_token_account"), pool.toBuffer(), rewardCustodyMint.toBuffer()], this.programId)[0];
4752
4827
  custodyAccountMetas = [];
4753
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
4754
- custody = _a[_i];
4828
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
4829
+ custody = _b[_a];
4755
4830
  custodyAccountMetas.push({
4756
4831
  pubkey: custody.custodyAccount,
4757
4832
  isSigner: false,
@@ -4783,10 +4858,10 @@ var PerpetualsClient = (function () {
4783
4858
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
4784
4859
  .instruction()];
4785
4860
  case 1:
4786
- refreshStakeInstruction = _b.sent();
4861
+ refreshStakeInstruction = _c.sent();
4787
4862
  return [2, refreshStakeInstruction];
4788
4863
  case 2:
4789
- err_16 = _b.sent();
4864
+ err_16 = _c.sent();
4790
4865
  console.log("perpClient refreshStaking error:: ", err_16);
4791
4866
  throw err_16;
4792
4867
  case 3: return [2];
@@ -4794,10 +4869,14 @@ var PerpetualsClient = (function () {
4794
4869
  });
4795
4870
  });
4796
4871
  };
4797
- this.unstakeInstant = function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
4798
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4799
- return __awaiter(_this, void 0, void 0, function () {
4872
+ this.unstakeInstant = function (rewardSymbol_1, unstakeAmount_1, poolConfig_1) {
4873
+ var args_1 = [];
4874
+ for (var _i = 3; _i < arguments.length; _i++) {
4875
+ args_1[_i - 3] = arguments[_i];
4876
+ }
4877
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
4800
4878
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_17;
4879
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4801
4880
  return __generator(this, function (_b) {
4802
4881
  switch (_b.label) {
4803
4882
  case 0:
@@ -4956,13 +5035,17 @@ var PerpetualsClient = (function () {
4956
5035
  }
4957
5036
  });
4958
5037
  }); };
4959
- this.withdrawStake = function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
4960
- if (pendingActivation === void 0) { pendingActivation = true; }
4961
- if (deactivated === void 0) { deactivated = true; }
4962
- if (createUserLPTA === void 0) { createUserLPTA = true; }
4963
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4964
- return __awaiter(_this, void 0, void 0, function () {
5038
+ this.withdrawStake = function (poolConfig_1) {
5039
+ var args_1 = [];
5040
+ for (var _i = 1; _i < arguments.length; _i++) {
5041
+ args_1[_i - 1] = arguments[_i];
5042
+ }
5043
+ return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
4965
5044
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_20;
5045
+ if (pendingActivation === void 0) { pendingActivation = true; }
5046
+ if (deactivated === void 0) { deactivated = true; }
5047
+ if (createUserLPTA === void 0) { createUserLPTA = true; }
5048
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4966
5049
  return __generator(this, function (_b) {
4967
5050
  switch (_b.label) {
4968
5051
  case 0:
@@ -5024,10 +5107,14 @@ var PerpetualsClient = (function () {
5024
5107
  });
5025
5108
  });
5026
5109
  };
5027
- this.collectStakeFees = function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
5028
- if (createUserATA === void 0) { createUserATA = true; }
5029
- return __awaiter(_this, void 0, void 0, function () {
5110
+ this.collectStakeFees = function (rewardSymbol_1, poolConfig_1, tokenStakeAccount_1) {
5111
+ var args_1 = [];
5112
+ for (var _i = 3; _i < arguments.length; _i++) {
5113
+ args_1[_i - 3] = arguments[_i];
5114
+ }
5115
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
5030
5116
  var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_21;
5117
+ if (createUserATA === void 0) { createUserATA = true; }
5031
5118
  return __generator(this, function (_b) {
5032
5119
  switch (_b.label) {
5033
5120
  case 0:
@@ -5751,10 +5838,14 @@ var PerpetualsClient = (function () {
5751
5838
  }
5752
5839
  });
5753
5840
  }); };
5754
- this.collectTokenReward = function (owner, poolConfig, createUserATA) {
5755
- if (createUserATA === void 0) { createUserATA = true; }
5756
- return __awaiter(_this, void 0, void 0, function () {
5841
+ this.collectTokenReward = function (owner_1, poolConfig_1) {
5842
+ var args_1 = [];
5843
+ for (var _i = 2; _i < arguments.length; _i++) {
5844
+ args_1[_i - 2] = arguments[_i];
5845
+ }
5846
+ return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
5757
5847
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_35;
5848
+ if (createUserATA === void 0) { createUserATA = true; }
5758
5849
  return __generator(this, function (_b) {
5759
5850
  switch (_b.label) {
5760
5851
  case 0:
@@ -5809,10 +5900,14 @@ var PerpetualsClient = (function () {
5809
5900
  });
5810
5901
  });
5811
5902
  };
5812
- this.collectRevenue = function (owner, rewardSymbol, poolConfig, createUserATA) {
5813
- if (createUserATA === void 0) { createUserATA = true; }
5814
- return __awaiter(_this, void 0, void 0, function () {
5903
+ this.collectRevenue = function (owner_1, rewardSymbol_1, poolConfig_1) {
5904
+ var args_1 = [];
5905
+ for (var _i = 3; _i < arguments.length; _i++) {
5906
+ args_1[_i - 3] = arguments[_i];
5907
+ }
5908
+ return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
5815
5909
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_36;
5910
+ if (createUserATA === void 0) { createUserATA = true; }
5816
5911
  return __generator(this, function (_b) {
5817
5912
  switch (_b.label) {
5818
5913
  case 0:
@@ -5997,10 +6092,14 @@ var PerpetualsClient = (function () {
5997
6092
  }
5998
6093
  });
5999
6094
  }); };
6000
- this.collectNftReward = function (rewardSymbol, poolConfig, nftMint, createUserATA) {
6001
- if (createUserATA === void 0) { createUserATA = true; }
6002
- return __awaiter(_this, void 0, void 0, function () {
6095
+ this.collectNftReward = function (rewardSymbol_1, poolConfig_1, nftMint_1) {
6096
+ var args_1 = [];
6097
+ for (var _i = 3; _i < arguments.length; _i++) {
6098
+ args_1[_i - 3] = arguments[_i];
6099
+ }
6100
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
6003
6101
  var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_40;
6102
+ if (createUserATA === void 0) { createUserATA = true; }
6004
6103
  return __generator(this, function (_b) {
6005
6104
  switch (_b.label) {
6006
6105
  case 0:
@@ -6060,10 +6159,14 @@ var PerpetualsClient = (function () {
6060
6159
  });
6061
6160
  });
6062
6161
  };
6063
- this.collectAndDistributeFee = function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
6064
- if (createUserATA === void 0) { createUserATA = true; }
6065
- return __awaiter(_this, void 0, void 0, function () {
6162
+ this.collectAndDistributeFee = function (rewardSymbol_1, poolConfig_1) {
6163
+ var args_1 = [];
6164
+ for (var _i = 2; _i < arguments.length; _i++) {
6165
+ args_1[_i - 2] = arguments[_i];
6166
+ }
6167
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
6066
6168
  var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_41;
6169
+ if (createUserATA === void 0) { createUserATA = true; }
6067
6170
  return __generator(this, function (_b) {
6068
6171
  switch (_b.label) {
6069
6172
  case 0:
@@ -6188,12 +6291,16 @@ var PerpetualsClient = (function () {
6188
6291
  }
6189
6292
  });
6190
6293
  }); };
6191
- this.forceClosePosition = function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
6192
- if (createUserATA === void 0) { createUserATA = true; }
6193
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
6194
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6195
- return __awaiter(_this, void 0, void 0, function () {
6294
+ this.forceClosePosition = function (positionAccount_1, targetSymbol_1, collateralSymbol_1, side_1, isStopLoss_1, poolConfig_1) {
6295
+ var args_1 = [];
6296
+ for (var _i = 6; _i < arguments.length; _i++) {
6297
+ args_1[_i - 6] = arguments[_i];
6298
+ }
6299
+ return __awaiter(_this, __spreadArray([positionAccount_1, targetSymbol_1, collateralSymbol_1, side_1, isStopLoss_1, poolConfig_1], args_1, true), void 0, function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
6196
6300
  var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_43;
6301
+ if (createUserATA === void 0) { createUserATA = true; }
6302
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
6303
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6197
6304
  return __generator(this, function (_b) {
6198
6305
  switch (_b.label) {
6199
6306
  case 0:
@@ -6265,11 +6372,15 @@ var PerpetualsClient = (function () {
6265
6372
  });
6266
6373
  });
6267
6374
  };
6268
- this.placeLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
6269
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
6270
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6271
- return __awaiter(_this, void 0, void 0, function () {
6375
+ this.placeLimitOrder = function (targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, limitPrice_1, reserveAmount_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1) {
6376
+ var args_1 = [];
6377
+ for (var _i = 11; _i < arguments.length; _i++) {
6378
+ args_1[_i - 11] = arguments[_i];
6379
+ }
6380
+ 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) {
6272
6381
  var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_44;
6382
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
6383
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6273
6384
  return __generator(this, function (_c) {
6274
6385
  switch (_c.label) {
6275
6386
  case 0:
@@ -6385,11 +6496,15 @@ var PerpetualsClient = (function () {
6385
6496
  });
6386
6497
  });
6387
6498
  };
6388
- this.editLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
6389
- if (createUserATA === void 0) { createUserATA = true; }
6390
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6391
- return __awaiter(_this, void 0, void 0, function () {
6499
+ this.editLimitOrder = function (targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, orderId_1, limitPrice_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1) {
6500
+ var args_1 = [];
6501
+ for (var _i = 11; _i < arguments.length; _i++) {
6502
+ args_1[_i - 11] = arguments[_i];
6503
+ }
6504
+ 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) {
6392
6505
  var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_45;
6506
+ if (createUserATA === void 0) { createUserATA = true; }
6507
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6393
6508
  return __generator(this, function (_b) {
6394
6509
  switch (_b.label) {
6395
6510
  case 0:
@@ -6488,12 +6603,16 @@ var PerpetualsClient = (function () {
6488
6603
  });
6489
6604
  });
6490
6605
  };
6491
- this.executeLimitOrder = function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6492
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6493
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6494
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6495
- return __awaiter(_this, void 0, void 0, function () {
6606
+ this.executeLimitOrder = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
6607
+ var args_1 = [];
6608
+ for (var _i = 7; _i < arguments.length; _i++) {
6609
+ args_1[_i - 7] = arguments[_i];
6610
+ }
6611
+ return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6496
6612
  var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_46;
6613
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6614
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6615
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6497
6616
  return __generator(this, function (_a) {
6498
6617
  switch (_a.label) {
6499
6618
  case 0:
@@ -6553,12 +6672,16 @@ var PerpetualsClient = (function () {
6553
6672
  });
6554
6673
  });
6555
6674
  };
6556
- this.executeLimitWithSwap = function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6557
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6558
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6559
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6560
- return __awaiter(_this, void 0, void 0, function () {
6675
+ this.executeLimitWithSwap = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
6676
+ var args_1 = [];
6677
+ for (var _i = 8; _i < arguments.length; _i++) {
6678
+ args_1[_i - 8] = arguments[_i];
6679
+ }
6680
+ return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6561
6681
  var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_47;
6682
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6683
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6684
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6562
6685
  return __generator(this, function (_a) {
6563
6686
  switch (_a.label) {
6564
6687
  case 0:
@@ -6824,16 +6947,20 @@ var PerpetualsClient = (function () {
6824
6947
  }
6825
6948
  });
6826
6949
  }); };
6827
- this.executeTriggerWithSwap = function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6828
- if (createUserATA === void 0) { createUserATA = true; }
6829
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6830
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6831
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6832
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6833
- return __awaiter(_this, void 0, void 0, function () {
6834
- var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, executeTriggerWithSwap, err_52;
6835
- return __generator(this, function (_d) {
6836
- switch (_d.label) {
6950
+ this.executeTriggerWithSwap = function (owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
6951
+ var args_1 = [];
6952
+ for (var _i = 9; _i < arguments.length; _i++) {
6953
+ args_1[_i - 9] = arguments[_i];
6954
+ }
6955
+ 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, rebateTokenAccount) {
6956
+ var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap, err_52;
6957
+ if (createUserATA === void 0) { createUserATA = true; }
6958
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6959
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6960
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6961
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6962
+ return __generator(this, function (_e) {
6963
+ switch (_e.label) {
6837
6964
  case 0:
6838
6965
  payerPubkey = this.provider.wallet.publicKey;
6839
6966
  targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
@@ -6844,9 +6971,9 @@ var PerpetualsClient = (function () {
6844
6971
  instructions = [];
6845
6972
  postInstructions = [];
6846
6973
  additionalSigners = [];
6847
- _d.label = 1;
6974
+ _e.label = 1;
6848
6975
  case 1:
6849
- _d.trys.push([1, 9, , 10]);
6976
+ _e.trys.push([1, 9, , 10]);
6850
6977
  if (!false) return [3, 2];
6851
6978
  return [3, 7];
6852
6979
  case 2:
@@ -6855,8 +6982,8 @@ var PerpetualsClient = (function () {
6855
6982
  if (!_a) return [3, 4];
6856
6983
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
6857
6984
  case 3:
6858
- _a = !(_d.sent());
6859
- _d.label = 4;
6985
+ _a = !(_e.sent());
6986
+ _e.label = 4;
6860
6987
  case 4:
6861
6988
  if (_a) {
6862
6989
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
@@ -6866,20 +6993,20 @@ var PerpetualsClient = (function () {
6866
6993
  if (!_b) return [3, 6];
6867
6994
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
6868
6995
  case 5:
6869
- _b = !(_d.sent());
6870
- _d.label = 6;
6996
+ _b = !(_e.sent());
6997
+ _e.label = 6;
6871
6998
  case 6:
6872
6999
  if (_b) {
6873
7000
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
6874
7001
  }
6875
- _d.label = 7;
7002
+ _e.label = 7;
6876
7003
  case 7:
6877
7004
  positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
6878
7005
  orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
6879
7006
  custodyAccountMetas = [];
6880
7007
  custodyOracleAccountMetas = [];
6881
- for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
6882
- custody = _c[_i];
7008
+ for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
7009
+ custody = _d[_c];
6883
7010
  custodyAccountMetas.push({
6884
7011
  pubkey: custody.custodyAccount,
6885
7012
  isSigner: false,
@@ -6924,11 +7051,11 @@ var PerpetualsClient = (function () {
6924
7051
  .remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
6925
7052
  .instruction()];
6926
7053
  case 8:
6927
- executeTriggerWithSwap = _d.sent();
7054
+ executeTriggerWithSwap = _e.sent();
6928
7055
  instructions.push(executeTriggerWithSwap);
6929
7056
  return [3, 10];
6930
7057
  case 9:
6931
- err_52 = _d.sent();
7058
+ err_52 = _e.sent();
6932
7059
  console.log("perpClient executeTriggerWithSwap error:: ", err_52);
6933
7060
  throw err_52;
6934
7061
  case 10: return [2, {
@@ -6939,14 +7066,18 @@ var PerpetualsClient = (function () {
6939
7066
  });
6940
7067
  });
6941
7068
  };
6942
- this.executeTriggerOrder = function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6943
- if (createUserATA === void 0) { createUserATA = true; }
6944
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6945
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6946
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6947
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6948
- return __awaiter(_this, void 0, void 0, function () {
7069
+ this.executeTriggerOrder = function (owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
7070
+ var args_1 = [];
7071
+ for (var _i = 8; _i < arguments.length; _i++) {
7072
+ args_1[_i - 8] = arguments[_i];
7073
+ }
7074
+ 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, rebateTokenAccount) {
6949
7075
  var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_53;
7076
+ if (createUserATA === void 0) { createUserATA = true; }
7077
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7078
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
7079
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
7080
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6950
7081
  return __generator(this, function (_b) {
6951
7082
  switch (_b.label) {
6952
7083
  case 0:
@@ -7369,14 +7500,18 @@ var PerpetualsClient = (function () {
7369
7500
  }
7370
7501
  });
7371
7502
  }); };
7372
- this.addCompoundingLiquidity = function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
7373
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
7374
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7375
- if (userPublicKey === void 0) { userPublicKey = undefined; }
7376
- return __awaiter(_this, void 0, void 0, function () {
7377
- var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, addCompoundingLiquidity, err_62;
7378
- return __generator(this, function (_e) {
7379
- switch (_e.label) {
7503
+ this.addCompoundingLiquidity = function (amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
7504
+ var args_1 = [];
7505
+ for (var _i = 5; _i < arguments.length; _i++) {
7506
+ args_1[_i - 5] = arguments[_i];
7507
+ }
7508
+ return __awaiter(_this, __spreadArray([amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
7509
+ var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, addCompoundingLiquidity, err_62;
7510
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
7511
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7512
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
7513
+ return __generator(this, function (_f) {
7514
+ switch (_f.label) {
7380
7515
  case 0:
7381
7516
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
7382
7517
  preInstructions = [];
@@ -7393,8 +7528,8 @@ var PerpetualsClient = (function () {
7393
7528
  custodyAccountMetas = [];
7394
7529
  custodyOracleAccountMetas = [];
7395
7530
  markets = [];
7396
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
7397
- custody = _a[_i];
7531
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
7532
+ custody = _b[_a];
7398
7533
  custodyAccountMetas.push({
7399
7534
  pubkey: custody.custodyAccount,
7400
7535
  isSigner: false,
@@ -7406,8 +7541,8 @@ var PerpetualsClient = (function () {
7406
7541
  isWritable: false,
7407
7542
  });
7408
7543
  }
7409
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
7410
- market = _c[_b];
7544
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
7545
+ market = _d[_c];
7411
7546
  markets.push({
7412
7547
  pubkey: market.marketAccount,
7413
7548
  isSigner: false,
@@ -7416,26 +7551,26 @@ var PerpetualsClient = (function () {
7416
7551
  }
7417
7552
  return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
7418
7553
  case 1:
7419
- if (!(_e.sent())) {
7554
+ if (!(_f.sent())) {
7420
7555
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
7421
7556
  }
7422
7557
  return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
7423
7558
  case 2:
7424
- if (!(_e.sent())) {
7559
+ if (!(_f.sent())) {
7425
7560
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
7426
7561
  }
7427
7562
  if (!(inTokenSymbol == 'SOL')) return [3, 5];
7428
7563
  console.log("inTokenSymbol === SOL", inTokenSymbol);
7429
7564
  lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
7430
7565
  if (!!skipBalanceChecks) return [3, 4];
7431
- _d = anchor_1.BN.bind;
7566
+ _e = anchor_1.BN.bind;
7432
7567
  return [4, this.provider.connection.getBalance(publicKey)];
7433
7568
  case 3:
7434
- unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _e.sent()]))();
7569
+ unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _f.sent()]))();
7435
7570
  if (unWrappedSolBalance.lt(lamports)) {
7436
7571
  throw "Insufficient SOL Funds";
7437
7572
  }
7438
- _e.label = 4;
7573
+ _f.label = 4;
7439
7574
  case 4:
7440
7575
  if (!ephemeralSignerPubkey) {
7441
7576
  wrappedSolAccount = new web3_js_1.Keypair();
@@ -7459,12 +7594,12 @@ var PerpetualsClient = (function () {
7459
7594
  if (!!skipBalanceChecks) return [3, 7];
7460
7595
  return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
7461
7596
  case 6:
7462
- if (!(_e.sent())) {
7597
+ if (!(_f.sent())) {
7463
7598
  throw "Insufficient Funds , token Account doesn't exist";
7464
7599
  }
7465
- _e.label = 7;
7600
+ _f.label = 7;
7466
7601
  case 7:
7467
- _e.trys.push([7, 9, , 10]);
7602
+ _f.trys.push([7, 9, , 10]);
7468
7603
  return [4, this.program.methods
7469
7604
  .addCompoundingLiquidity({
7470
7605
  amountIn: amountIn,
@@ -7493,11 +7628,11 @@ var PerpetualsClient = (function () {
7493
7628
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
7494
7629
  .instruction()];
7495
7630
  case 8:
7496
- addCompoundingLiquidity = _e.sent();
7631
+ addCompoundingLiquidity = _f.sent();
7497
7632
  instructions.push(addCompoundingLiquidity);
7498
7633
  return [3, 10];
7499
7634
  case 9:
7500
- err_62 = _e.sent();
7635
+ err_62 = _f.sent();
7501
7636
  console.log("perpClient addCompoundingLiquidity error:: ", err_62);
7502
7637
  return [3, 10];
7503
7638
  case 10: return [2, {
@@ -7508,14 +7643,18 @@ var PerpetualsClient = (function () {
7508
7643
  });
7509
7644
  });
7510
7645
  };
7511
- this.removeCompoundingLiquidity = function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey, userPublicKey) {
7512
- if (createUserATA === void 0) { createUserATA = true; }
7513
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7514
- if (userPublicKey === void 0) { userPublicKey = undefined; }
7515
- return __awaiter(_this, void 0, void 0, function () {
7516
- var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, compoundingTokenAccount, removeCompoundingLiquidity, err_63;
7517
- return __generator(this, function (_e) {
7518
- switch (_e.label) {
7646
+ this.removeCompoundingLiquidity = function (compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
7647
+ var args_1 = [];
7648
+ for (var _i = 5; _i < arguments.length; _i++) {
7649
+ args_1[_i - 5] = arguments[_i];
7650
+ }
7651
+ 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) {
7652
+ var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, compoundingTokenAccount, removeCompoundingLiquidity, err_63;
7653
+ if (createUserATA === void 0) { createUserATA = true; }
7654
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7655
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
7656
+ return __generator(this, function (_f) {
7657
+ switch (_f.label) {
7519
7658
  case 0:
7520
7659
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
7521
7660
  preInstructions = [];
@@ -7552,19 +7691,19 @@ var PerpetualsClient = (function () {
7552
7691
  if (!_a) return [3, 3];
7553
7692
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
7554
7693
  case 2:
7555
- _a = !(_e.sent());
7556
- _e.label = 3;
7694
+ _a = !(_f.sent());
7695
+ _f.label = 3;
7557
7696
  case 3:
7558
7697
  if (_a) {
7559
7698
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
7560
7699
  }
7561
- _e.label = 4;
7700
+ _f.label = 4;
7562
7701
  case 4:
7563
7702
  custodyAccountMetas = [];
7564
7703
  custodyOracleAccountMetas = [];
7565
7704
  markets = [];
7566
- for (_i = 0, _b = poolConfig.custodies; _i < _b.length; _i++) {
7567
- custody = _b[_i];
7705
+ for (_b = 0, _c = poolConfig.custodies; _b < _c.length; _b++) {
7706
+ custody = _c[_b];
7568
7707
  custodyAccountMetas.push({
7569
7708
  pubkey: custody.custodyAccount,
7570
7709
  isSigner: false,
@@ -7576,8 +7715,8 @@ var PerpetualsClient = (function () {
7576
7715
  isWritable: false,
7577
7716
  });
7578
7717
  }
7579
- for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
7580
- market = _d[_c];
7718
+ for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
7719
+ market = _e[_d];
7581
7720
  markets.push({
7582
7721
  pubkey: market.marketAccount,
7583
7722
  isSigner: false,
@@ -7585,9 +7724,9 @@ var PerpetualsClient = (function () {
7585
7724
  });
7586
7725
  }
7587
7726
  compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
7588
- _e.label = 5;
7727
+ _f.label = 5;
7589
7728
  case 5:
7590
- _e.trys.push([5, 7, , 8]);
7729
+ _f.trys.push([5, 7, , 8]);
7591
7730
  return [4, this.program.methods
7592
7731
  .removeCompoundingLiquidity({
7593
7732
  compoundingAmountIn: compoundingAmountIn,
@@ -7616,11 +7755,11 @@ var PerpetualsClient = (function () {
7616
7755
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
7617
7756
  .instruction()];
7618
7757
  case 6:
7619
- removeCompoundingLiquidity = _e.sent();
7758
+ removeCompoundingLiquidity = _f.sent();
7620
7759
  instructions.push(removeCompoundingLiquidity);
7621
7760
  return [3, 8];
7622
7761
  case 7:
7623
- err_63 = _e.sent();
7762
+ err_63 = _f.sent();
7624
7763
  console.log("perpClient removeCompoundingLiquidity error:: ", err_63);
7625
7764
  return [3, 8];
7626
7765
  case 8: return [2, {
@@ -7631,12 +7770,16 @@ var PerpetualsClient = (function () {
7631
7770
  });
7632
7771
  });
7633
7772
  };
7634
- this.migrateStake = function (amount, rewardTokenMint, poolConfig, createUserATA) {
7635
- if (createUserATA === void 0) { createUserATA = true; }
7636
- return __awaiter(_this, void 0, void 0, function () {
7637
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _b, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _c, custody, _d, _e, market, migrateStake, err_64;
7638
- return __generator(this, function (_f) {
7639
- switch (_f.label) {
7773
+ this.migrateStake = function (amount_1, rewardTokenMint_1, poolConfig_1) {
7774
+ var args_1 = [];
7775
+ for (var _i = 3; _i < arguments.length; _i++) {
7776
+ args_1[_i - 3] = arguments[_i];
7777
+ }
7778
+ return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
7779
+ 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_64;
7780
+ if (createUserATA === void 0) { createUserATA = true; }
7781
+ return __generator(this, function (_g) {
7782
+ switch (_g.label) {
7640
7783
  case 0:
7641
7784
  publicKey = this.provider.wallet.publicKey;
7642
7785
  preInstructions = [];
@@ -7651,8 +7794,8 @@ var PerpetualsClient = (function () {
7651
7794
  if (!_a) return [3, 2];
7652
7795
  return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
7653
7796
  case 1:
7654
- _a = !(_f.sent());
7655
- _f.label = 2;
7797
+ _a = !(_g.sent());
7798
+ _g.label = 2;
7656
7799
  case 2:
7657
7800
  if (_a) {
7658
7801
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
@@ -7664,8 +7807,8 @@ var PerpetualsClient = (function () {
7664
7807
  if (!_b) return [3, 4];
7665
7808
  return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
7666
7809
  case 3:
7667
- _b = (_f.sent());
7668
- _f.label = 4;
7810
+ _b = (_g.sent());
7811
+ _g.label = 4;
7669
7812
  case 4:
7670
7813
  if (_b) {
7671
7814
  tokenStakeAccounts.push({
@@ -7678,8 +7821,8 @@ var PerpetualsClient = (function () {
7678
7821
  custodyAccountMetas = [];
7679
7822
  custodyOracleAccountMetas = [];
7680
7823
  markets = [];
7681
- for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
7682
- custody = _c[_i];
7824
+ for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
7825
+ custody = _d[_c];
7683
7826
  custodyAccountMetas.push({
7684
7827
  pubkey: custody.custodyAccount,
7685
7828
  isSigner: false,
@@ -7691,17 +7834,17 @@ var PerpetualsClient = (function () {
7691
7834
  isWritable: false,
7692
7835
  });
7693
7836
  }
7694
- for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
7695
- market = _e[_d];
7837
+ for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
7838
+ market = _f[_e];
7696
7839
  markets.push({
7697
7840
  pubkey: market.marketAccount,
7698
7841
  isSigner: false,
7699
7842
  isWritable: false,
7700
7843
  });
7701
7844
  }
7702
- _f.label = 5;
7845
+ _g.label = 5;
7703
7846
  case 5:
7704
- _f.trys.push([5, 7, , 8]);
7847
+ _g.trys.push([5, 7, , 8]);
7705
7848
  return [4, this.program.methods
7706
7849
  .migrateStake({
7707
7850
  amount: amount
@@ -7727,11 +7870,11 @@ var PerpetualsClient = (function () {
7727
7870
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
7728
7871
  .instruction()];
7729
7872
  case 6:
7730
- migrateStake = _f.sent();
7873
+ migrateStake = _g.sent();
7731
7874
  instructions.push(migrateStake);
7732
7875
  return [3, 8];
7733
7876
  case 7:
7734
- err_64 = _f.sent();
7877
+ err_64 = _g.sent();
7735
7878
  console.log("perpClient migrateStake error:: ", err_64);
7736
7879
  return [3, 8];
7737
7880
  case 8: return [2, {
@@ -7825,12 +7968,16 @@ var PerpetualsClient = (function () {
7825
7968
  }
7826
7969
  });
7827
7970
  }); };
7828
- this.compoundingFee = function (poolConfig, rewardTokenSymbol) {
7829
- if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
7830
- return __awaiter(_this, void 0, void 0, function () {
7831
- var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, compoundingFee, err_66;
7832
- return __generator(this, function (_d) {
7833
- switch (_d.label) {
7971
+ this.compoundingFee = function (poolConfig_1) {
7972
+ var args_1 = [];
7973
+ for (var _i = 1; _i < arguments.length; _i++) {
7974
+ args_1[_i - 1] = arguments[_i];
7975
+ }
7976
+ return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
7977
+ var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_66;
7978
+ if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
7979
+ return __generator(this, function (_e) {
7980
+ switch (_e.label) {
7834
7981
  case 0:
7835
7982
  instructions = [];
7836
7983
  additionalSigners = [];
@@ -7839,8 +7986,8 @@ var PerpetualsClient = (function () {
7839
7986
  custodyAccountMetas = [];
7840
7987
  custodyOracleAccountMetas = [];
7841
7988
  markets = [];
7842
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
7843
- custody = _a[_i];
7989
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
7990
+ custody = _b[_a];
7844
7991
  custodyAccountMetas.push({
7845
7992
  pubkey: custody.custodyAccount,
7846
7993
  isSigner: false,
@@ -7852,17 +7999,17 @@ var PerpetualsClient = (function () {
7852
7999
  isWritable: false,
7853
8000
  });
7854
8001
  }
7855
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
7856
- market = _c[_b];
8002
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
8003
+ market = _d[_c];
7857
8004
  markets.push({
7858
8005
  pubkey: market.marketAccount,
7859
8006
  isSigner: false,
7860
8007
  isWritable: false,
7861
8008
  });
7862
8009
  }
7863
- _d.label = 1;
8010
+ _e.label = 1;
7864
8011
  case 1:
7865
- _d.trys.push([1, 3, , 4]);
8012
+ _e.trys.push([1, 3, , 4]);
7866
8013
  return [4, this.program.methods
7867
8014
  .compoundFees({})
7868
8015
  .accounts({
@@ -7881,11 +8028,11 @@ var PerpetualsClient = (function () {
7881
8028
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
7882
8029
  .instruction()];
7883
8030
  case 2:
7884
- compoundingFee = _d.sent();
8031
+ compoundingFee = _e.sent();
7885
8032
  instructions.push(compoundingFee);
7886
8033
  return [3, 4];
7887
8034
  case 3:
7888
- err_66 = _d.sent();
8035
+ err_66 = _e.sent();
7889
8036
  console.log("perpClient compoundingFee error:: ", err_66);
7890
8037
  return [3, 4];
7891
8038
  case 4: return [2, {
@@ -8046,9 +8193,9 @@ var PerpetualsClient = (function () {
8046
8193
  }
8047
8194
  }
8048
8195
  };
8049
- PerpetualsClient.prototype.sendTransaction = function (ixs, opts) {
8050
- if (opts === void 0) { opts = {}; }
8051
- return __awaiter(this, void 0, void 0, function () {
8196
+ PerpetualsClient.prototype.sendTransaction = function (ixs_1) {
8197
+ return __awaiter(this, arguments, void 0, function (ixs, opts) {
8198
+ if (opts === void 0) { opts = {}; }
8052
8199
  return __generator(this, function (_a) {
8053
8200
  switch (_a.label) {
8054
8201
  case 0: return [4, (0, rpc_1.sendTransaction)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
@@ -8057,9 +8204,9 @@ var PerpetualsClient = (function () {
8057
8204
  });
8058
8205
  });
8059
8206
  };
8060
- PerpetualsClient.prototype.sendTransactionV3 = function (ixs, opts) {
8061
- if (opts === void 0) { opts = {}; }
8062
- return __awaiter(this, void 0, void 0, function () {
8207
+ PerpetualsClient.prototype.sendTransactionV3 = function (ixs_1) {
8208
+ return __awaiter(this, arguments, void 0, function (ixs, opts) {
8209
+ if (opts === void 0) { opts = {}; }
8063
8210
  return __generator(this, function (_a) {
8064
8211
  switch (_a.label) {
8065
8212
  case 0: return [4, (0, rpc_1.sendTransactionV3)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];