flash-sdk 2.48.2 → 2.48.3

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.
@@ -2149,36 +2149,40 @@ var PerpetualsClient = (function () {
2149
2149
  }
2150
2150
  });
2151
2151
  }); };
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) {
2152
+ this.getAddLiquidityAmountAndFeeView = function (amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1) {
2153
+ var args_1 = [];
2154
+ for (var _i = 4; _i < arguments.length; _i++) {
2155
+ args_1[_i - 4] = arguments[_i];
2156
+ }
2157
+ 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) {
2158
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
2159
+ var _e;
2160
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
2161
+ return __generator(this, function (_f) {
2162
+ switch (_f.label) {
2159
2163
  case 0:
2160
2164
  backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
2161
2165
  custodies = POOL_CONFIG.custodies;
2162
2166
  custodyMetas = [];
2163
2167
  marketMetas = [];
2164
- for (_i = 0, custodies_5 = custodies; _i < custodies_5.length; _i++) {
2165
- token = custodies_5[_i];
2168
+ for (_a = 0, custodies_5 = custodies; _a < custodies_5.length; _a++) {
2169
+ token = custodies_5[_a];
2166
2170
  custodyMetas.push({
2167
2171
  isSigner: false,
2168
2172
  isWritable: false,
2169
2173
  pubkey: token.custodyAccount,
2170
2174
  });
2171
2175
  }
2172
- for (_a = 0, custodies_6 = custodies; _a < custodies_6.length; _a++) {
2173
- custody = custodies_6[_a];
2176
+ for (_b = 0, custodies_6 = custodies; _b < custodies_6.length; _b++) {
2177
+ custody = custodies_6[_b];
2174
2178
  custodyMetas.push({
2175
2179
  isSigner: false,
2176
2180
  isWritable: false,
2177
2181
  pubkey: custody.intOracleAccount,
2178
2182
  });
2179
2183
  }
2180
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2181
- market = _c[_b];
2184
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2185
+ market = _d[_c];
2182
2186
  marketMetas.push({
2183
2187
  pubkey: market.marketAccount,
2184
2188
  isSigner: false,
@@ -2201,14 +2205,14 @@ var PerpetualsClient = (function () {
2201
2205
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2202
2206
  .transaction()];
2203
2207
  case 1:
2204
- transaction = _e.sent();
2208
+ transaction = _f.sent();
2205
2209
  return [4, backUpOracleInstructionPromise];
2206
2210
  case 2:
2207
- backUpOracleInstruction = _e.sent();
2208
- (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
2211
+ backUpOracleInstruction = _f.sent();
2212
+ (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2209
2213
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2210
2214
  case 3:
2211
- result = _e.sent();
2215
+ result = _f.sent();
2212
2216
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddLiquidityAmountAndFee'; });
2213
2217
  res = this.viewHelper.decodeLogs(result, index, 'getAddLiquidityAmountAndFee');
2214
2218
  return [2, {
@@ -2219,36 +2223,40 @@ var PerpetualsClient = (function () {
2219
2223
  });
2220
2224
  });
2221
2225
  };
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) {
2226
+ this.getRemoveLiquidityAmountAndFeeView = function (amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1) {
2227
+ var args_1 = [];
2228
+ for (var _i = 4; _i < arguments.length; _i++) {
2229
+ args_1[_i - 4] = arguments[_i];
2230
+ }
2231
+ 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) {
2232
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
2233
+ var _e;
2234
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
2235
+ return __generator(this, function (_f) {
2236
+ switch (_f.label) {
2229
2237
  case 0:
2230
2238
  backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
2231
2239
  custodies = POOL_CONFIG.custodies;
2232
2240
  custodyMetas = [];
2233
2241
  marketMetas = [];
2234
- for (_i = 0, custodies_7 = custodies; _i < custodies_7.length; _i++) {
2235
- token = custodies_7[_i];
2242
+ for (_a = 0, custodies_7 = custodies; _a < custodies_7.length; _a++) {
2243
+ token = custodies_7[_a];
2236
2244
  custodyMetas.push({
2237
2245
  isSigner: false,
2238
2246
  isWritable: false,
2239
2247
  pubkey: token.custodyAccount,
2240
2248
  });
2241
2249
  }
2242
- for (_a = 0, custodies_8 = custodies; _a < custodies_8.length; _a++) {
2243
- custody = custodies_8[_a];
2250
+ for (_b = 0, custodies_8 = custodies; _b < custodies_8.length; _b++) {
2251
+ custody = custodies_8[_b];
2244
2252
  custodyMetas.push({
2245
2253
  isSigner: false,
2246
2254
  isWritable: false,
2247
2255
  pubkey: custody.intOracleAccount,
2248
2256
  });
2249
2257
  }
2250
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2251
- market = _c[_b];
2258
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2259
+ market = _d[_c];
2252
2260
  marketMetas.push({
2253
2261
  pubkey: market.marketAccount,
2254
2262
  isSigner: false,
@@ -2271,14 +2279,14 @@ var PerpetualsClient = (function () {
2271
2279
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2272
2280
  .transaction()];
2273
2281
  case 1:
2274
- transaction = _e.sent();
2282
+ transaction = _f.sent();
2275
2283
  return [4, backUpOracleInstructionPromise];
2276
2284
  case 2:
2277
- backUpOracleInstruction = _e.sent();
2278
- (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
2285
+ backUpOracleInstruction = _f.sent();
2286
+ (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2279
2287
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2280
2288
  case 3:
2281
- result = _e.sent();
2289
+ result = _f.sent();
2282
2290
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveLiquidityAmountAndFee'; });
2283
2291
  if (result.value.err) {
2284
2292
  return [2, {
@@ -2354,36 +2362,40 @@ var PerpetualsClient = (function () {
2354
2362
  }
2355
2363
  });
2356
2364
  }); };
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) {
2365
+ this.getAddCompoundingLiquidityAmountAndFeeView = function (amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1) {
2366
+ var args_1 = [];
2367
+ for (var _i = 4; _i < arguments.length; _i++) {
2368
+ args_1[_i - 4] = arguments[_i];
2369
+ }
2370
+ 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) {
2371
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
2372
+ var _e;
2373
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
2374
+ return __generator(this, function (_f) {
2375
+ switch (_f.label) {
2364
2376
  case 0:
2365
2377
  backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
2366
2378
  custodies = POOL_CONFIG.custodies;
2367
2379
  custodyMetas = [];
2368
2380
  marketMetas = [];
2369
- for (_i = 0, custodies_11 = custodies; _i < custodies_11.length; _i++) {
2370
- token = custodies_11[_i];
2381
+ for (_a = 0, custodies_11 = custodies; _a < custodies_11.length; _a++) {
2382
+ token = custodies_11[_a];
2371
2383
  custodyMetas.push({
2372
2384
  isSigner: false,
2373
2385
  isWritable: false,
2374
2386
  pubkey: token.custodyAccount,
2375
2387
  });
2376
2388
  }
2377
- for (_a = 0, custodies_12 = custodies; _a < custodies_12.length; _a++) {
2378
- custody = custodies_12[_a];
2389
+ for (_b = 0, custodies_12 = custodies; _b < custodies_12.length; _b++) {
2390
+ custody = custodies_12[_b];
2379
2391
  custodyMetas.push({
2380
2392
  isSigner: false,
2381
2393
  isWritable: false,
2382
2394
  pubkey: custody.intOracleAccount,
2383
2395
  });
2384
2396
  }
2385
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2386
- market = _c[_b];
2397
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2398
+ market = _d[_c];
2387
2399
  marketMetas.push({
2388
2400
  pubkey: market.marketAccount,
2389
2401
  isSigner: false,
@@ -2394,7 +2406,7 @@ var PerpetualsClient = (function () {
2394
2406
  rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
2395
2407
  return [4, backUpOracleInstructionPromise];
2396
2408
  case 1:
2397
- backUpOracleInstruction = _e.sent();
2409
+ backUpOracleInstruction = _f.sent();
2398
2410
  return [4, this.program.methods
2399
2411
  .getAddCompoundingLiquidityAmountAndFee({
2400
2412
  amountIn: amount,
@@ -2413,11 +2425,11 @@ var PerpetualsClient = (function () {
2413
2425
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2414
2426
  .transaction()];
2415
2427
  case 2:
2416
- transaction = _e.sent();
2417
- (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
2428
+ transaction = _f.sent();
2429
+ (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2418
2430
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2419
2431
  case 3:
2420
- result = _e.sent();
2432
+ result = _f.sent();
2421
2433
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddCompoundingLiquidityAmountAndFee'; });
2422
2434
  res = this.viewHelper.decodeLogs(result, index, 'getAddCompoundingLiquidityAmountAndFee');
2423
2435
  return [2, {
@@ -2428,36 +2440,40 @@ var PerpetualsClient = (function () {
2428
2440
  });
2429
2441
  });
2430
2442
  };
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) {
2443
+ this.getRemoveCompoundingLiquidityAmountAndFeeView = function (amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1) {
2444
+ var args_1 = [];
2445
+ for (var _i = 4; _i < arguments.length; _i++) {
2446
+ args_1[_i - 4] = arguments[_i];
2447
+ }
2448
+ 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) {
2449
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
2450
+ var _e;
2451
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
2452
+ return __generator(this, function (_f) {
2453
+ switch (_f.label) {
2438
2454
  case 0:
2439
2455
  backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
2440
2456
  custodies = POOL_CONFIG.custodies;
2441
2457
  custodyMetas = [];
2442
2458
  marketMetas = [];
2443
- for (_i = 0, custodies_13 = custodies; _i < custodies_13.length; _i++) {
2444
- token = custodies_13[_i];
2459
+ for (_a = 0, custodies_13 = custodies; _a < custodies_13.length; _a++) {
2460
+ token = custodies_13[_a];
2445
2461
  custodyMetas.push({
2446
2462
  isSigner: false,
2447
2463
  isWritable: false,
2448
2464
  pubkey: token.custodyAccount,
2449
2465
  });
2450
2466
  }
2451
- for (_a = 0, custodies_14 = custodies; _a < custodies_14.length; _a++) {
2452
- custody = custodies_14[_a];
2467
+ for (_b = 0, custodies_14 = custodies; _b < custodies_14.length; _b++) {
2468
+ custody = custodies_14[_b];
2453
2469
  custodyMetas.push({
2454
2470
  isSigner: false,
2455
2471
  isWritable: false,
2456
2472
  pubkey: custody.intOracleAccount,
2457
2473
  });
2458
2474
  }
2459
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2460
- market = _c[_b];
2475
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2476
+ market = _d[_c];
2461
2477
  marketMetas.push({
2462
2478
  pubkey: market.marketAccount,
2463
2479
  isSigner: false,
@@ -2468,7 +2484,7 @@ var PerpetualsClient = (function () {
2468
2484
  rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
2469
2485
  return [4, backUpOracleInstructionPromise];
2470
2486
  case 1:
2471
- backUpOracleInstruction = _e.sent();
2487
+ backUpOracleInstruction = _f.sent();
2472
2488
  return [4, this.program.methods
2473
2489
  .getRemoveCompoundingLiquidityAmountAndFee({
2474
2490
  compoundingAmountIn: amount,
@@ -2487,11 +2503,11 @@ var PerpetualsClient = (function () {
2487
2503
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2488
2504
  .transaction()];
2489
2505
  case 2:
2490
- transaction = _e.sent();
2491
- (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
2506
+ transaction = _f.sent();
2507
+ (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2492
2508
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2493
2509
  case 3:
2494
- result = _e.sent();
2510
+ result = _f.sent();
2495
2511
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveCompoundingLiquidityAmountAndFee'; });
2496
2512
  if (result.value.err) {
2497
2513
  return [2, {
@@ -2630,14 +2646,18 @@ var PerpetualsClient = (function () {
2630
2646
  }
2631
2647
  });
2632
2648
  }); };
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 () {
2649
+ this.openPosition = function (targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1) {
2650
+ var args_1 = [];
2651
+ for (var _i = 8; _i < arguments.length; _i++) {
2652
+ args_1[_i - 8] = arguments[_i];
2653
+ }
2654
+ 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
2655
  var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
2656
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2657
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2658
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2659
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2660
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2641
2661
  return __generator(this, function (_c) {
2642
2662
  switch (_c.label) {
2643
2663
  case 0:
@@ -2741,15 +2761,19 @@ var PerpetualsClient = (function () {
2741
2761
  });
2742
2762
  });
2743
2763
  };
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 () {
2764
+ this.closePosition = function (marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
2765
+ var args_1 = [];
2766
+ for (var _i = 6; _i < arguments.length; _i++) {
2767
+ args_1[_i - 6] = arguments[_i];
2768
+ }
2769
+ 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
2770
  var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_2;
2771
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2772
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2773
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2774
+ if (createUserATA === void 0) { createUserATA = true; }
2775
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
2776
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2753
2777
  return __generator(this, function (_b) {
2754
2778
  switch (_b.label) {
2755
2779
  case 0:
@@ -2846,14 +2870,18 @@ var PerpetualsClient = (function () {
2846
2870
  });
2847
2871
  });
2848
2872
  };
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 () {
2873
+ this.swapAndOpen = function (targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, minCollateralAmountOut_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1) {
2874
+ var args_1 = [];
2875
+ for (var _i = 10; _i < arguments.length; _i++) {
2876
+ args_1[_i - 10] = arguments[_i];
2877
+ }
2878
+ 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
2879
  var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_2;
2880
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2881
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2882
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2883
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2884
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2857
2885
  return __generator(this, function (_c) {
2858
2886
  switch (_c.label) {
2859
2887
  case 0:
@@ -2993,13 +3021,17 @@ var PerpetualsClient = (function () {
2993
3021
  });
2994
3022
  });
2995
3023
  };
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 () {
3024
+ this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, minSwapAmountOut_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
3025
+ var args_1 = [];
3026
+ for (var _i = 8; _i < arguments.length; _i++) {
3027
+ args_1[_i - 8] = arguments[_i];
3028
+ }
3029
+ 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
3030
  var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, inx, err_3;
3031
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3032
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3033
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3034
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3003
3035
  return __generator(this, function (_a) {
3004
3036
  switch (_a.label) {
3005
3037
  case 0:
@@ -3113,16 +3145,20 @@ var PerpetualsClient = (function () {
3113
3145
  });
3114
3146
  });
3115
3147
  };
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) {
3148
+ this.swap = function (userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1) {
3149
+ var args_1 = [];
3150
+ for (var _i = 5; _i < arguments.length; _i++) {
3151
+ args_1[_i - 5] = arguments[_i];
3152
+ }
3153
+ 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) {
3154
+ 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;
3155
+ if (useFeesPool === void 0) { useFeesPool = false; }
3156
+ if (createUserATA === void 0) { createUserATA = true; }
3157
+ if (unWrapSol === void 0) { unWrapSol = false; }
3158
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3159
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3160
+ return __generator(this, function (_g) {
3161
+ switch (_g.label) {
3126
3162
  case 0:
3127
3163
  userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
3128
3164
  if (!userInputCustodyConfig) {
@@ -3140,10 +3176,10 @@ var PerpetualsClient = (function () {
3140
3176
  if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
3141
3177
  return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
3142
3178
  case 1:
3143
- wsolAssociatedTokenAccount = _f.sent();
3179
+ wsolAssociatedTokenAccount = _g.sent();
3144
3180
  return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
3145
3181
  case 2:
3146
- wsolATAExist = _f.sent();
3182
+ wsolATAExist = _g.sent();
3147
3183
  if (!wsolATAExist) {
3148
3184
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
3149
3185
  }
@@ -3151,11 +3187,11 @@ var PerpetualsClient = (function () {
3151
3187
  _a = anchor_1.BN.bind;
3152
3188
  return [4, this.provider.connection.getBalance(publicKey)];
3153
3189
  case 3:
3154
- unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
3190
+ unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
3155
3191
  if (unWrappedSolBalance.lt(amountIn)) {
3156
3192
  throw "Insufficient SOL Funds";
3157
3193
  }
3158
- _f.label = 4;
3194
+ _g.label = 4;
3159
3195
  case 4:
3160
3196
  instructions.push(web3_js_1.SystemProgram.transfer({
3161
3197
  fromPubkey: publicKey,
@@ -3177,20 +3213,20 @@ var PerpetualsClient = (function () {
3177
3213
  additionalSigners: additionalSigners
3178
3214
  }];
3179
3215
  }
3180
- _f.label = 6;
3216
+ _g.label = 6;
3181
3217
  case 6:
3182
- _f.trys.push([6, 19, , 20]);
3218
+ _g.trys.push([6, 19, , 20]);
3183
3219
  if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
3184
3220
  console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
3185
3221
  return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
3186
3222
  case 7:
3187
- accCreationLamports = (_f.sent());
3223
+ accCreationLamports = (_g.sent());
3188
3224
  console.log("accCreationLamports:", accCreationLamports);
3189
3225
  lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
3190
3226
  _b = anchor_1.BN.bind;
3191
3227
  return [4, this.provider.connection.getBalance(publicKey)];
3192
3228
  case 8:
3193
- unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _f.sent()]))();
3229
+ unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _g.sent()]))();
3194
3230
  if (unWrappedSolBalance.lt(amountIn)) {
3195
3231
  throw "Insufficient SOL Funds";
3196
3232
  }
@@ -3217,18 +3253,18 @@ var PerpetualsClient = (function () {
3217
3253
  userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
3218
3254
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
3219
3255
  case 10:
3220
- if (!(_f.sent())) {
3256
+ if (!(_g.sent())) {
3221
3257
  throw "Insufficient Funds , Token Account doesn't exist";
3222
3258
  }
3223
3259
  if (!!skipBalanceChecks) return [3, 12];
3224
3260
  _c = anchor_1.BN.bind;
3225
3261
  return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
3226
3262
  case 11:
3227
- tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
3263
+ tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
3228
3264
  if (tokenAccountBalance.lt(amountIn)) {
3229
3265
  throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
3230
3266
  }
3231
- _f.label = 12;
3267
+ _g.label = 12;
3232
3268
  case 12:
3233
3269
  if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
3234
3270
  lamports = (this.minimumBalanceForRentExemptAccountLamports);
@@ -3253,23 +3289,23 @@ var PerpetualsClient = (function () {
3253
3289
  return [3, 17];
3254
3290
  case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
3255
3291
  case 14:
3256
- userOutputTokenAccount = _f.sent();
3292
+ userOutputTokenAccount = _g.sent();
3257
3293
  _d = createUserATA;
3258
3294
  if (!_d) return [3, 16];
3259
3295
  return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
3260
3296
  case 15:
3261
- _d = !(_f.sent());
3262
- _f.label = 16;
3297
+ _d = !(_g.sent());
3298
+ _g.label = 16;
3263
3299
  case 16:
3264
3300
  if (_d) {
3265
3301
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
3266
3302
  }
3267
- _f.label = 17;
3303
+ _g.label = 17;
3268
3304
  case 17:
3269
3305
  custodyAccountMetas = [];
3270
3306
  custodyOracleAccountMetas = [];
3271
- for (_i = 0, _e = poolConfig.custodies; _i < _e.length; _i++) {
3272
- custody = _e[_i];
3307
+ for (_e = 0, _f = poolConfig.custodies; _e < _f.length; _e++) {
3308
+ custody = _f[_e];
3273
3309
  custodyAccountMetas.push({
3274
3310
  pubkey: custody.custodyAccount,
3275
3311
  isSigner: false,
@@ -3309,7 +3345,7 @@ var PerpetualsClient = (function () {
3309
3345
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
3310
3346
  .instruction()];
3311
3347
  case 18:
3312
- inx = _f.sent();
3348
+ inx = _g.sent();
3313
3349
  instructions.push(inx);
3314
3350
  if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
3315
3351
  closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
@@ -3317,7 +3353,7 @@ var PerpetualsClient = (function () {
3317
3353
  }
3318
3354
  return [3, 20];
3319
3355
  case 19:
3320
- err_4 = _f.sent();
3356
+ err_4 = _g.sent();
3321
3357
  console.error("perpClient Swap error:: ", err_4);
3322
3358
  throw err_4;
3323
3359
  case 20: return [2, {
@@ -3399,11 +3435,15 @@ var PerpetualsClient = (function () {
3399
3435
  }
3400
3436
  });
3401
3437
  }); };
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 () {
3438
+ this.addCollateral = function (collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
3439
+ var args_1 = [];
3440
+ for (var _i = 6; _i < arguments.length; _i++) {
3441
+ args_1[_i - 6] = arguments[_i];
3442
+ }
3443
+ 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
3444
  var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
3445
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3446
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3407
3447
  return __generator(this, function (_c) {
3408
3448
  switch (_c.label) {
3409
3449
  case 0:
@@ -3497,11 +3537,15 @@ var PerpetualsClient = (function () {
3497
3537
  });
3498
3538
  });
3499
3539
  };
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 () {
3540
+ this.swapAndAddCollateral = function (targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1) {
3541
+ var args_1 = [];
3542
+ for (var _i = 8; _i < arguments.length; _i++) {
3543
+ args_1[_i - 8] = arguments[_i];
3544
+ }
3545
+ 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
3546
  var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
3547
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3548
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3505
3549
  return __generator(this, function (_c) {
3506
3550
  switch (_c.label) {
3507
3551
  case 0:
@@ -3612,12 +3656,16 @@ var PerpetualsClient = (function () {
3612
3656
  });
3613
3657
  });
3614
3658
  };
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 () {
3659
+ this.removeCollateral = function (collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
3660
+ var args_1 = [];
3661
+ for (var _i = 6; _i < arguments.length; _i++) {
3662
+ args_1[_i - 6] = arguments[_i];
3663
+ }
3664
+ 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
3665
  var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns, error_3;
3666
+ if (createUserATA === void 0) { createUserATA = true; }
3667
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
3668
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3621
3669
  return __generator(this, function (_b) {
3622
3670
  switch (_b.label) {
3623
3671
  case 0:
@@ -3718,10 +3766,14 @@ var PerpetualsClient = (function () {
3718
3766
  });
3719
3767
  });
3720
3768
  };
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 () {
3769
+ this.removeCollateralAndSwap = function (targetSymbol_1, collateralSymbol_1, outputSymbol_1, minSwapAmountOut_1, collateralDelta_1, side_1, poolConfig_1) {
3770
+ var args_1 = [];
3771
+ for (var _i = 7; _i < arguments.length; _i++) {
3772
+ args_1[_i - 7] = arguments[_i];
3773
+ }
3774
+ 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
3775
  var publicKey, targetCustodyConfig, collateralCustodyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, instruction;
3776
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3725
3777
  return __generator(this, function (_a) {
3726
3778
  switch (_a.label) {
3727
3779
  case 0:
@@ -3814,12 +3866,16 @@ var PerpetualsClient = (function () {
3814
3866
  });
3815
3867
  });
3816
3868
  };
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 () {
3869
+ this.increaseSize = function (targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
3870
+ var args_1 = [];
3871
+ for (var _i = 8; _i < arguments.length; _i++) {
3872
+ args_1[_i - 8] = arguments[_i];
3873
+ }
3874
+ 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
3875
  var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
3876
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3877
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3878
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3823
3879
  return __generator(this, function (_a) {
3824
3880
  switch (_a.label) {
3825
3881
  case 0:
@@ -3874,12 +3930,16 @@ var PerpetualsClient = (function () {
3874
3930
  });
3875
3931
  });
3876
3932
  };
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 () {
3933
+ this.decreaseSize = function (targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
3934
+ var args_1 = [];
3935
+ for (var _i = 8; _i < arguments.length; _i++) {
3936
+ args_1[_i - 8] = arguments[_i];
3937
+ }
3938
+ 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
3939
  var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
3940
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3941
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3942
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3883
3943
  return __generator(this, function (_a) {
3884
3944
  switch (_a.label) {
3885
3945
  case 0:
@@ -3934,13 +3994,17 @@ var PerpetualsClient = (function () {
3934
3994
  });
3935
3995
  });
3936
3996
  };
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) {
3997
+ this.addLiquidity = function (payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1) {
3998
+ var args_1 = [];
3999
+ for (var _i = 4; _i < arguments.length; _i++) {
4000
+ args_1[_i - 4] = arguments[_i];
4001
+ }
4002
+ return __awaiter(_this, __spreadArray([payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
4003
+ 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;
4004
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4005
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4006
+ return __generator(this, function (_g) {
4007
+ switch (_g.label) {
3944
4008
  case 0:
3945
4009
  publicKey = this.provider.wallet.publicKey;
3946
4010
  payTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey); });
@@ -3951,16 +4015,16 @@ var PerpetualsClient = (function () {
3951
4015
  instructions = [];
3952
4016
  postInstructions = [];
3953
4017
  additionalSigners = [];
3954
- _f.label = 1;
4018
+ _g.label = 1;
3955
4019
  case 1:
3956
- _f.trys.push([1, 10, , 11]);
4020
+ _g.trys.push([1, 10, , 11]);
3957
4021
  userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true);
3958
4022
  lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
3959
4023
  custodyAccountMetas = [];
3960
4024
  custodyOracleAccountMetas = [];
3961
4025
  markets = [];
3962
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
3963
- custody = _a[_i];
4026
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
4027
+ custody = _b[_a];
3964
4028
  custodyAccountMetas.push({
3965
4029
  pubkey: custody.custodyAccount,
3966
4030
  isSigner: false,
@@ -3972,8 +4036,8 @@ var PerpetualsClient = (function () {
3972
4036
  isWritable: false,
3973
4037
  });
3974
4038
  }
3975
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
3976
- market = _c[_b];
4039
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
4040
+ market = _d[_c];
3977
4041
  markets.push({
3978
4042
  pubkey: market.marketAccount,
3979
4043
  isSigner: false,
@@ -3982,21 +4046,21 @@ var PerpetualsClient = (function () {
3982
4046
  }
3983
4047
  return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
3984
4048
  case 2:
3985
- if (!(_f.sent())) {
4049
+ if (!(_g.sent())) {
3986
4050
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
3987
4051
  }
3988
4052
  if (!(payTokenSymbol == 'SOL')) return [3, 5];
3989
4053
  console.log("payTokenSymbol === SOL", payTokenSymbol);
3990
4054
  lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
3991
4055
  if (!!skipBalanceChecks) return [3, 4];
3992
- _d = anchor_1.BN.bind;
4056
+ _e = anchor_1.BN.bind;
3993
4057
  return [4, this.provider.connection.getBalance(publicKey)];
3994
4058
  case 3:
3995
- unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _f.sent()]))();
4059
+ unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _g.sent()]))();
3996
4060
  if (unWrappedSolBalance.lt(lamports)) {
3997
4061
  throw "Insufficient SOL Funds";
3998
4062
  }
3999
- _f.label = 4;
4063
+ _g.label = 4;
4000
4064
  case 4:
4001
4065
  if (!ephemeralSignerPubkey) {
4002
4066
  wrappedSolAccount = new web3_js_1.Keypair();
@@ -4020,17 +4084,17 @@ var PerpetualsClient = (function () {
4020
4084
  if (!!skipBalanceChecks) return [3, 8];
4021
4085
  return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
4022
4086
  case 6:
4023
- if (!(_f.sent())) {
4087
+ if (!(_g.sent())) {
4024
4088
  throw "Insufficient Funds , token Account doesn't exist";
4025
4089
  }
4026
- _e = anchor_1.BN.bind;
4090
+ _f = anchor_1.BN.bind;
4027
4091
  return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
4028
4092
  case 7:
4029
- tokenAccountBalance = new (_e.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
4093
+ tokenAccountBalance = new (_f.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
4030
4094
  if (tokenAccountBalance.lt(tokenAmountIn)) {
4031
4095
  throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
4032
4096
  }
4033
- _f.label = 8;
4097
+ _g.label = 8;
4034
4098
  case 8: return [4, this.program.methods
4035
4099
  .addLiquidity({
4036
4100
  amountIn: tokenAmountIn,
@@ -4055,11 +4119,11 @@ var PerpetualsClient = (function () {
4055
4119
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4056
4120
  .instruction()];
4057
4121
  case 9:
4058
- instruction = _f.sent();
4122
+ instruction = _g.sent();
4059
4123
  instructions.push(instruction);
4060
4124
  return [3, 11];
4061
4125
  case 10:
4062
- err_6 = _f.sent();
4126
+ err_6 = _g.sent();
4063
4127
  console.error("perpClient addLiquidity error:: ", err_6);
4064
4128
  throw err_6;
4065
4129
  case 11: return [2, {
@@ -4070,14 +4134,18 @@ var PerpetualsClient = (function () {
4070
4134
  });
4071
4135
  });
4072
4136
  };
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) {
4137
+ this.addLiquidityAndStake = function (inputSymbol_1, amountIn_1, minLpAmountOut_1, poolConfig_1) {
4138
+ var args_1 = [];
4139
+ for (var _i = 4; _i < arguments.length; _i++) {
4140
+ args_1[_i - 4] = arguments[_i];
4141
+ }
4142
+ 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) {
4143
+ 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;
4144
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4145
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4146
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4147
+ return __generator(this, function (_g) {
4148
+ switch (_g.label) {
4081
4149
  case 0:
4082
4150
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
4083
4151
  preInstructions = [];
@@ -4097,14 +4165,14 @@ var PerpetualsClient = (function () {
4097
4165
  _a = anchor_1.BN.bind;
4098
4166
  return [4, this.provider.connection.getBalance(publicKey)];
4099
4167
  case 1:
4100
- unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
4168
+ unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
4101
4169
  if (unWrappedSolBalance.lt(lamports)) {
4102
4170
  throw "Insufficient SOL Funds";
4103
4171
  }
4104
- _f.label = 2;
4172
+ _g.label = 2;
4105
4173
  case 2: return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
4106
4174
  case 3:
4107
- if (!(_f.sent())) {
4175
+ if (!(_g.sent())) {
4108
4176
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
4109
4177
  }
4110
4178
  if (!ephemeralSignerPubkey) {
@@ -4130,23 +4198,23 @@ var PerpetualsClient = (function () {
4130
4198
  if (!!skipBalanceChecks) return [3, 7];
4131
4199
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
4132
4200
  case 5:
4133
- if (!(_f.sent())) {
4201
+ if (!(_g.sent())) {
4134
4202
  throw "Insufficient Funds , token Account doesn't exist";
4135
4203
  }
4136
4204
  _b = anchor_1.BN.bind;
4137
4205
  return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
4138
4206
  case 6:
4139
- tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
4207
+ tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
4140
4208
  if (tokenAccountBalance.lt(amountIn)) {
4141
4209
  throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
4142
4210
  }
4143
- _f.label = 7;
4211
+ _g.label = 7;
4144
4212
  case 7:
4145
4213
  custodyAccountMetas = [];
4146
4214
  custodyOracleAccountMetas = [];
4147
4215
  markets = [];
4148
- for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
4149
- custody = _c[_i];
4216
+ for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
4217
+ custody = _d[_c];
4150
4218
  custodyAccountMetas.push({
4151
4219
  pubkey: custody.custodyAccount,
4152
4220
  isSigner: false,
@@ -4158,8 +4226,8 @@ var PerpetualsClient = (function () {
4158
4226
  isWritable: false,
4159
4227
  });
4160
4228
  }
4161
- for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
4162
- market = _e[_d];
4229
+ for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
4230
+ market = _f[_e];
4163
4231
  markets.push({
4164
4232
  pubkey: market.marketAccount,
4165
4233
  isSigner: false,
@@ -4191,7 +4259,7 @@ var PerpetualsClient = (function () {
4191
4259
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4192
4260
  .instruction()];
4193
4261
  case 8:
4194
- instruction = _f.sent();
4262
+ instruction = _g.sent();
4195
4263
  instructions.push(instruction);
4196
4264
  return [2, {
4197
4265
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -4201,16 +4269,20 @@ var PerpetualsClient = (function () {
4201
4269
  });
4202
4270
  });
4203
4271
  };
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) {
4272
+ this.removeLiquidity = function (recieveTokenSymbol_1, liquidityAmountIn_1, minTokenAmountOut_1, poolConfig_1) {
4273
+ var args_1 = [];
4274
+ for (var _i = 4; _i < arguments.length; _i++) {
4275
+ args_1[_i - 4] = arguments[_i];
4276
+ }
4277
+ 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) {
4278
+ 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;
4279
+ if (closeLpATA === void 0) { closeLpATA = false; }
4280
+ if (createUserATA === void 0) { createUserATA = true; }
4281
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
4282
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4283
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4284
+ return __generator(this, function (_f) {
4285
+ switch (_f.label) {
4214
4286
  case 0:
4215
4287
  recieveTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey); });
4216
4288
  if (!recieveTokenCustodyConfig) {
@@ -4221,15 +4293,15 @@ var PerpetualsClient = (function () {
4221
4293
  instructions = [];
4222
4294
  postInstructions = [];
4223
4295
  additionalSigners = [];
4224
- _e.label = 1;
4296
+ _f.label = 1;
4225
4297
  case 1:
4226
- _e.trys.push([1, 7, , 8]);
4298
+ _f.trys.push([1, 7, , 8]);
4227
4299
  stakedLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
4228
4300
  custodyAccountMetas = [];
4229
4301
  custodyOracleAccountMetas = [];
4230
4302
  markets = [];
4231
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
4232
- custody = _a[_i];
4303
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
4304
+ custody = _b[_a];
4233
4305
  custodyAccountMetas.push({
4234
4306
  pubkey: custody.custodyAccount,
4235
4307
  isSigner: false,
@@ -4241,8 +4313,8 @@ var PerpetualsClient = (function () {
4241
4313
  isWritable: false,
4242
4314
  });
4243
4315
  }
4244
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
4245
- market = _c[_b];
4316
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
4317
+ market = _d[_c];
4246
4318
  markets.push({
4247
4319
  pubkey: market.marketAccount,
4248
4320
  isSigner: false,
@@ -4271,17 +4343,17 @@ var PerpetualsClient = (function () {
4271
4343
  return [3, 5];
4272
4344
  case 2:
4273
4345
  userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true);
4274
- _d = createUserATA;
4275
- if (!_d) return [3, 4];
4346
+ _e = createUserATA;
4347
+ if (!_e) return [3, 4];
4276
4348
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
4277
4349
  case 3:
4278
- _d = !(_e.sent());
4279
- _e.label = 4;
4350
+ _e = !(_f.sent());
4351
+ _f.label = 4;
4280
4352
  case 4:
4281
- if (_d) {
4353
+ if (_e) {
4282
4354
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey));
4283
4355
  }
4284
- _e.label = 5;
4356
+ _f.label = 5;
4285
4357
  case 5: return [4, this.program.methods
4286
4358
  .removeLiquidity({
4287
4359
  lpAmountIn: liquidityAmountIn,
@@ -4306,7 +4378,7 @@ var PerpetualsClient = (function () {
4306
4378
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4307
4379
  .instruction()];
4308
4380
  case 6:
4309
- removeLiquidityTx = _e.sent();
4381
+ removeLiquidityTx = _f.sent();
4310
4382
  instructions.push(removeLiquidityTx);
4311
4383
  if (closeLpATA) {
4312
4384
  closeInx = (0, spl_token_1.createCloseAccountInstruction)(stakedLpTokenAccount, publicKey, publicKey);
@@ -4318,7 +4390,7 @@ var PerpetualsClient = (function () {
4318
4390
  }
4319
4391
  return [3, 8];
4320
4392
  case 7:
4321
- err_7 = _e.sent();
4393
+ err_7 = _f.sent();
4322
4394
  console.log("perpClient removeLiquidity error:: ", err_7);
4323
4395
  throw err_7;
4324
4396
  case 8: return [2, {
@@ -4736,22 +4808,26 @@ var PerpetualsClient = (function () {
4736
4808
  }
4737
4809
  });
4738
4810
  }); };
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) {
4811
+ this.refreshStakeWithTokenStake = function (rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1) {
4812
+ var args_1 = [];
4813
+ for (var _i = 3; _i < arguments.length; _i++) {
4814
+ args_1[_i - 3] = arguments[_i];
4815
+ }
4816
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
4817
+ var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_16;
4818
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4819
+ return __generator(this, function (_c) {
4820
+ switch (_c.label) {
4745
4821
  case 0:
4746
- _b.trys.push([0, 2, , 3]);
4822
+ _c.trys.push([0, 2, , 3]);
4747
4823
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
4748
4824
  rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
4749
4825
  rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
4750
4826
  pool = poolConfig.poolAddress;
4751
4827
  feeDistributionTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("custody_token_account"), pool.toBuffer(), rewardCustodyMint.toBuffer()], this.programId)[0];
4752
4828
  custodyAccountMetas = [];
4753
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
4754
- custody = _a[_i];
4829
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
4830
+ custody = _b[_a];
4755
4831
  custodyAccountMetas.push({
4756
4832
  pubkey: custody.custodyAccount,
4757
4833
  isSigner: false,
@@ -4783,10 +4859,10 @@ var PerpetualsClient = (function () {
4783
4859
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
4784
4860
  .instruction()];
4785
4861
  case 1:
4786
- refreshStakeInstruction = _b.sent();
4862
+ refreshStakeInstruction = _c.sent();
4787
4863
  return [2, refreshStakeInstruction];
4788
4864
  case 2:
4789
- err_16 = _b.sent();
4865
+ err_16 = _c.sent();
4790
4866
  console.log("perpClient refreshStaking error:: ", err_16);
4791
4867
  throw err_16;
4792
4868
  case 3: return [2];
@@ -4953,12 +5029,16 @@ var PerpetualsClient = (function () {
4953
5029
  }
4954
5030
  });
4955
5031
  }); };
4956
- this.withdrawStake = function (poolConfig, pendingActivation, deactivated, createUserLPTA) {
4957
- if (pendingActivation === void 0) { pendingActivation = true; }
4958
- if (deactivated === void 0) { deactivated = true; }
4959
- if (createUserLPTA === void 0) { createUserLPTA = true; }
4960
- return __awaiter(_this, void 0, void 0, function () {
5032
+ this.withdrawStake = function (poolConfig_1) {
5033
+ var args_1 = [];
5034
+ for (var _i = 1; _i < arguments.length; _i++) {
5035
+ args_1[_i - 1] = arguments[_i];
5036
+ }
5037
+ return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA) {
4961
5038
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_20;
5039
+ if (pendingActivation === void 0) { pendingActivation = true; }
5040
+ if (deactivated === void 0) { deactivated = true; }
5041
+ if (createUserLPTA === void 0) { createUserLPTA = true; }
4962
5042
  return __generator(this, function (_b) {
4963
5043
  switch (_b.label) {
4964
5044
  case 0:
@@ -5020,10 +5100,14 @@ var PerpetualsClient = (function () {
5020
5100
  });
5021
5101
  });
5022
5102
  };
5023
- this.collectStakeFees = function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
5024
- if (createUserATA === void 0) { createUserATA = true; }
5025
- return __awaiter(_this, void 0, void 0, function () {
5103
+ this.collectStakeFees = function (rewardSymbol_1, poolConfig_1, tokenStakeAccount_1) {
5104
+ var args_1 = [];
5105
+ for (var _i = 3; _i < arguments.length; _i++) {
5106
+ args_1[_i - 3] = arguments[_i];
5107
+ }
5108
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
5026
5109
  var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_21;
5110
+ if (createUserATA === void 0) { createUserATA = true; }
5027
5111
  return __generator(this, function (_b) {
5028
5112
  switch (_b.label) {
5029
5113
  case 0:
@@ -5747,10 +5831,14 @@ var PerpetualsClient = (function () {
5747
5831
  }
5748
5832
  });
5749
5833
  }); };
5750
- this.collectTokenReward = function (owner, poolConfig, createUserATA) {
5751
- if (createUserATA === void 0) { createUserATA = true; }
5752
- return __awaiter(_this, void 0, void 0, function () {
5834
+ this.collectTokenReward = function (owner_1, poolConfig_1) {
5835
+ var args_1 = [];
5836
+ for (var _i = 2; _i < arguments.length; _i++) {
5837
+ args_1[_i - 2] = arguments[_i];
5838
+ }
5839
+ return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
5753
5840
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_35;
5841
+ if (createUserATA === void 0) { createUserATA = true; }
5754
5842
  return __generator(this, function (_b) {
5755
5843
  switch (_b.label) {
5756
5844
  case 0:
@@ -5805,10 +5893,14 @@ var PerpetualsClient = (function () {
5805
5893
  });
5806
5894
  });
5807
5895
  };
5808
- this.collectRevenue = function (owner, rewardSymbol, poolConfig, createUserATA) {
5809
- if (createUserATA === void 0) { createUserATA = true; }
5810
- return __awaiter(_this, void 0, void 0, function () {
5896
+ this.collectRevenue = function (owner_1, rewardSymbol_1, poolConfig_1) {
5897
+ var args_1 = [];
5898
+ for (var _i = 3; _i < arguments.length; _i++) {
5899
+ args_1[_i - 3] = arguments[_i];
5900
+ }
5901
+ return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
5811
5902
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_36;
5903
+ if (createUserATA === void 0) { createUserATA = true; }
5812
5904
  return __generator(this, function (_b) {
5813
5905
  switch (_b.label) {
5814
5906
  case 0:
@@ -5993,10 +6085,14 @@ var PerpetualsClient = (function () {
5993
6085
  }
5994
6086
  });
5995
6087
  }); };
5996
- this.collectNftReward = function (rewardSymbol, poolConfig, nftMint, createUserATA) {
5997
- if (createUserATA === void 0) { createUserATA = true; }
5998
- return __awaiter(_this, void 0, void 0, function () {
6088
+ this.collectNftReward = function (rewardSymbol_1, poolConfig_1, nftMint_1) {
6089
+ var args_1 = [];
6090
+ for (var _i = 3; _i < arguments.length; _i++) {
6091
+ args_1[_i - 3] = arguments[_i];
6092
+ }
6093
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
5999
6094
  var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_40;
6095
+ if (createUserATA === void 0) { createUserATA = true; }
6000
6096
  return __generator(this, function (_b) {
6001
6097
  switch (_b.label) {
6002
6098
  case 0:
@@ -6056,10 +6152,14 @@ var PerpetualsClient = (function () {
6056
6152
  });
6057
6153
  });
6058
6154
  };
6059
- this.collectAndDistributeFee = function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
6060
- if (createUserATA === void 0) { createUserATA = true; }
6061
- return __awaiter(_this, void 0, void 0, function () {
6155
+ this.collectAndDistributeFee = function (rewardSymbol_1, poolConfig_1) {
6156
+ var args_1 = [];
6157
+ for (var _i = 2; _i < arguments.length; _i++) {
6158
+ args_1[_i - 2] = arguments[_i];
6159
+ }
6160
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
6062
6161
  var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_41;
6162
+ if (createUserATA === void 0) { createUserATA = true; }
6063
6163
  return __generator(this, function (_b) {
6064
6164
  switch (_b.label) {
6065
6165
  case 0:
@@ -6184,12 +6284,16 @@ var PerpetualsClient = (function () {
6184
6284
  }
6185
6285
  });
6186
6286
  }); };
6187
- this.forceClosePosition = function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
6188
- if (createUserATA === void 0) { createUserATA = true; }
6189
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
6190
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6191
- return __awaiter(_this, void 0, void 0, function () {
6287
+ this.forceClosePosition = function (positionAccount_1, targetSymbol_1, collateralSymbol_1, side_1, isStopLoss_1, poolConfig_1) {
6288
+ var args_1 = [];
6289
+ for (var _i = 6; _i < arguments.length; _i++) {
6290
+ args_1[_i - 6] = arguments[_i];
6291
+ }
6292
+ 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) {
6192
6293
  var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_43;
6294
+ if (createUserATA === void 0) { createUserATA = true; }
6295
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
6296
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6193
6297
  return __generator(this, function (_b) {
6194
6298
  switch (_b.label) {
6195
6299
  case 0:
@@ -6261,11 +6365,15 @@ var PerpetualsClient = (function () {
6261
6365
  });
6262
6366
  });
6263
6367
  };
6264
- this.placeLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
6265
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
6266
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6267
- return __awaiter(_this, void 0, void 0, function () {
6368
+ 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) {
6369
+ var args_1 = [];
6370
+ for (var _i = 11; _i < arguments.length; _i++) {
6371
+ args_1[_i - 11] = arguments[_i];
6372
+ }
6373
+ 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) {
6268
6374
  var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_44;
6375
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
6376
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6269
6377
  return __generator(this, function (_c) {
6270
6378
  switch (_c.label) {
6271
6379
  case 0:
@@ -6381,11 +6489,15 @@ var PerpetualsClient = (function () {
6381
6489
  });
6382
6490
  });
6383
6491
  };
6384
- this.editLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
6385
- if (createUserATA === void 0) { createUserATA = true; }
6386
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6387
- return __awaiter(_this, void 0, void 0, function () {
6492
+ 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) {
6493
+ var args_1 = [];
6494
+ for (var _i = 11; _i < arguments.length; _i++) {
6495
+ args_1[_i - 11] = arguments[_i];
6496
+ }
6497
+ 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) {
6388
6498
  var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_45;
6499
+ if (createUserATA === void 0) { createUserATA = true; }
6500
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6389
6501
  return __generator(this, function (_b) {
6390
6502
  switch (_b.label) {
6391
6503
  case 0:
@@ -6484,12 +6596,16 @@ var PerpetualsClient = (function () {
6484
6596
  });
6485
6597
  });
6486
6598
  };
6487
- this.executeLimitOrder = function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6488
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6489
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6490
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6491
- return __awaiter(_this, void 0, void 0, function () {
6599
+ this.executeLimitOrder = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
6600
+ var args_1 = [];
6601
+ for (var _i = 7; _i < arguments.length; _i++) {
6602
+ args_1[_i - 7] = arguments[_i];
6603
+ }
6604
+ 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) {
6492
6605
  var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_46;
6606
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6607
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6608
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6493
6609
  return __generator(this, function (_a) {
6494
6610
  switch (_a.label) {
6495
6611
  case 0:
@@ -6549,12 +6665,16 @@ var PerpetualsClient = (function () {
6549
6665
  });
6550
6666
  });
6551
6667
  };
6552
- this.executeLimitWithSwap = function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6553
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6554
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6555
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6556
- return __awaiter(_this, void 0, void 0, function () {
6668
+ this.executeLimitWithSwap = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
6669
+ var args_1 = [];
6670
+ for (var _i = 8; _i < arguments.length; _i++) {
6671
+ args_1[_i - 8] = arguments[_i];
6672
+ }
6673
+ 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) {
6557
6674
  var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_47;
6675
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6676
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6677
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6558
6678
  return __generator(this, function (_a) {
6559
6679
  switch (_a.label) {
6560
6680
  case 0:
@@ -6820,16 +6940,20 @@ var PerpetualsClient = (function () {
6820
6940
  }
6821
6941
  });
6822
6942
  }); };
6823
- this.executeTriggerWithSwap = function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6824
- if (createUserATA === void 0) { createUserATA = true; }
6825
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6826
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6827
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6828
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6829
- return __awaiter(_this, void 0, void 0, function () {
6830
- 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;
6831
- return __generator(this, function (_d) {
6832
- switch (_d.label) {
6943
+ this.executeTriggerWithSwap = function (owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
6944
+ var args_1 = [];
6945
+ for (var _i = 9; _i < arguments.length; _i++) {
6946
+ args_1[_i - 9] = arguments[_i];
6947
+ }
6948
+ 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) {
6949
+ 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;
6950
+ if (createUserATA === void 0) { createUserATA = true; }
6951
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6952
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6953
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6954
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6955
+ return __generator(this, function (_e) {
6956
+ switch (_e.label) {
6833
6957
  case 0:
6834
6958
  payerPubkey = this.provider.wallet.publicKey;
6835
6959
  targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
@@ -6840,9 +6964,9 @@ var PerpetualsClient = (function () {
6840
6964
  instructions = [];
6841
6965
  postInstructions = [];
6842
6966
  additionalSigners = [];
6843
- _d.label = 1;
6967
+ _e.label = 1;
6844
6968
  case 1:
6845
- _d.trys.push([1, 9, , 10]);
6969
+ _e.trys.push([1, 9, , 10]);
6846
6970
  if (!false) return [3, 2];
6847
6971
  return [3, 7];
6848
6972
  case 2:
@@ -6851,8 +6975,8 @@ var PerpetualsClient = (function () {
6851
6975
  if (!_a) return [3, 4];
6852
6976
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
6853
6977
  case 3:
6854
- _a = !(_d.sent());
6855
- _d.label = 4;
6978
+ _a = !(_e.sent());
6979
+ _e.label = 4;
6856
6980
  case 4:
6857
6981
  if (_a) {
6858
6982
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
@@ -6862,20 +6986,20 @@ var PerpetualsClient = (function () {
6862
6986
  if (!_b) return [3, 6];
6863
6987
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
6864
6988
  case 5:
6865
- _b = !(_d.sent());
6866
- _d.label = 6;
6989
+ _b = !(_e.sent());
6990
+ _e.label = 6;
6867
6991
  case 6:
6868
6992
  if (_b) {
6869
6993
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
6870
6994
  }
6871
- _d.label = 7;
6995
+ _e.label = 7;
6872
6996
  case 7:
6873
6997
  positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
6874
6998
  orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
6875
6999
  custodyAccountMetas = [];
6876
7000
  custodyOracleAccountMetas = [];
6877
- for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
6878
- custody = _c[_i];
7001
+ for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
7002
+ custody = _d[_c];
6879
7003
  custodyAccountMetas.push({
6880
7004
  pubkey: custody.custodyAccount,
6881
7005
  isSigner: false,
@@ -6920,11 +7044,11 @@ var PerpetualsClient = (function () {
6920
7044
  .remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
6921
7045
  .instruction()];
6922
7046
  case 8:
6923
- executeTriggerWithSwap = _d.sent();
7047
+ executeTriggerWithSwap = _e.sent();
6924
7048
  instructions.push(executeTriggerWithSwap);
6925
7049
  return [3, 10];
6926
7050
  case 9:
6927
- err_52 = _d.sent();
7051
+ err_52 = _e.sent();
6928
7052
  console.log("perpClient executeTriggerWithSwap error:: ", err_52);
6929
7053
  throw err_52;
6930
7054
  case 10: return [2, {
@@ -6935,14 +7059,18 @@ var PerpetualsClient = (function () {
6935
7059
  });
6936
7060
  });
6937
7061
  };
6938
- this.executeTriggerOrder = function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6939
- if (createUserATA === void 0) { createUserATA = true; }
6940
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6941
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6942
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6943
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6944
- return __awaiter(_this, void 0, void 0, function () {
7062
+ this.executeTriggerOrder = function (owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
7063
+ var args_1 = [];
7064
+ for (var _i = 8; _i < arguments.length; _i++) {
7065
+ args_1[_i - 8] = arguments[_i];
7066
+ }
7067
+ 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) {
6945
7068
  var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_53;
7069
+ if (createUserATA === void 0) { createUserATA = true; }
7070
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7071
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
7072
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
7073
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6946
7074
  return __generator(this, function (_b) {
6947
7075
  switch (_b.label) {
6948
7076
  case 0:
@@ -7365,14 +7493,18 @@ var PerpetualsClient = (function () {
7365
7493
  }
7366
7494
  });
7367
7495
  }); };
7368
- this.addCompoundingLiquidity = function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
7369
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
7370
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7371
- if (userPublicKey === void 0) { userPublicKey = undefined; }
7372
- return __awaiter(_this, void 0, void 0, function () {
7373
- 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;
7374
- return __generator(this, function (_e) {
7375
- switch (_e.label) {
7496
+ this.addCompoundingLiquidity = function (amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
7497
+ var args_1 = [];
7498
+ for (var _i = 5; _i < arguments.length; _i++) {
7499
+ args_1[_i - 5] = arguments[_i];
7500
+ }
7501
+ 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) {
7502
+ 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;
7503
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
7504
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7505
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
7506
+ return __generator(this, function (_f) {
7507
+ switch (_f.label) {
7376
7508
  case 0:
7377
7509
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
7378
7510
  preInstructions = [];
@@ -7389,8 +7521,8 @@ var PerpetualsClient = (function () {
7389
7521
  custodyAccountMetas = [];
7390
7522
  custodyOracleAccountMetas = [];
7391
7523
  markets = [];
7392
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
7393
- custody = _a[_i];
7524
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
7525
+ custody = _b[_a];
7394
7526
  custodyAccountMetas.push({
7395
7527
  pubkey: custody.custodyAccount,
7396
7528
  isSigner: false,
@@ -7402,8 +7534,8 @@ var PerpetualsClient = (function () {
7402
7534
  isWritable: false,
7403
7535
  });
7404
7536
  }
7405
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
7406
- market = _c[_b];
7537
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
7538
+ market = _d[_c];
7407
7539
  markets.push({
7408
7540
  pubkey: market.marketAccount,
7409
7541
  isSigner: false,
@@ -7412,26 +7544,26 @@ var PerpetualsClient = (function () {
7412
7544
  }
7413
7545
  return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
7414
7546
  case 1:
7415
- if (!(_e.sent())) {
7547
+ if (!(_f.sent())) {
7416
7548
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
7417
7549
  }
7418
7550
  return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
7419
7551
  case 2:
7420
- if (!(_e.sent())) {
7552
+ if (!(_f.sent())) {
7421
7553
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
7422
7554
  }
7423
7555
  if (!(inTokenSymbol == 'SOL')) return [3, 5];
7424
7556
  console.log("inTokenSymbol === SOL", inTokenSymbol);
7425
7557
  lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
7426
7558
  if (!!skipBalanceChecks) return [3, 4];
7427
- _d = anchor_1.BN.bind;
7559
+ _e = anchor_1.BN.bind;
7428
7560
  return [4, this.provider.connection.getBalance(publicKey)];
7429
7561
  case 3:
7430
- unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _e.sent()]))();
7562
+ unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _f.sent()]))();
7431
7563
  if (unWrappedSolBalance.lt(lamports)) {
7432
7564
  throw "Insufficient SOL Funds";
7433
7565
  }
7434
- _e.label = 4;
7566
+ _f.label = 4;
7435
7567
  case 4:
7436
7568
  if (!ephemeralSignerPubkey) {
7437
7569
  wrappedSolAccount = new web3_js_1.Keypair();
@@ -7455,12 +7587,12 @@ var PerpetualsClient = (function () {
7455
7587
  if (!!skipBalanceChecks) return [3, 7];
7456
7588
  return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
7457
7589
  case 6:
7458
- if (!(_e.sent())) {
7590
+ if (!(_f.sent())) {
7459
7591
  throw "Insufficient Funds , token Account doesn't exist";
7460
7592
  }
7461
- _e.label = 7;
7593
+ _f.label = 7;
7462
7594
  case 7:
7463
- _e.trys.push([7, 9, , 10]);
7595
+ _f.trys.push([7, 9, , 10]);
7464
7596
  return [4, this.program.methods
7465
7597
  .addCompoundingLiquidity({
7466
7598
  amountIn: amountIn,
@@ -7489,11 +7621,11 @@ var PerpetualsClient = (function () {
7489
7621
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
7490
7622
  .instruction()];
7491
7623
  case 8:
7492
- addCompoundingLiquidity = _e.sent();
7624
+ addCompoundingLiquidity = _f.sent();
7493
7625
  instructions.push(addCompoundingLiquidity);
7494
7626
  return [3, 10];
7495
7627
  case 9:
7496
- err_62 = _e.sent();
7628
+ err_62 = _f.sent();
7497
7629
  console.log("perpClient addCompoundingLiquidity error:: ", err_62);
7498
7630
  return [3, 10];
7499
7631
  case 10: return [2, {
@@ -7504,14 +7636,18 @@ var PerpetualsClient = (function () {
7504
7636
  });
7505
7637
  });
7506
7638
  };
7507
- this.removeCompoundingLiquidity = function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey, userPublicKey) {
7508
- if (createUserATA === void 0) { createUserATA = true; }
7509
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7510
- if (userPublicKey === void 0) { userPublicKey = undefined; }
7511
- return __awaiter(_this, void 0, void 0, function () {
7512
- 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;
7513
- return __generator(this, function (_e) {
7514
- switch (_e.label) {
7639
+ this.removeCompoundingLiquidity = function (compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
7640
+ var args_1 = [];
7641
+ for (var _i = 5; _i < arguments.length; _i++) {
7642
+ args_1[_i - 5] = arguments[_i];
7643
+ }
7644
+ 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) {
7645
+ 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;
7646
+ if (createUserATA === void 0) { createUserATA = true; }
7647
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7648
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
7649
+ return __generator(this, function (_f) {
7650
+ switch (_f.label) {
7515
7651
  case 0:
7516
7652
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
7517
7653
  preInstructions = [];
@@ -7548,19 +7684,19 @@ var PerpetualsClient = (function () {
7548
7684
  if (!_a) return [3, 3];
7549
7685
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
7550
7686
  case 2:
7551
- _a = !(_e.sent());
7552
- _e.label = 3;
7687
+ _a = !(_f.sent());
7688
+ _f.label = 3;
7553
7689
  case 3:
7554
7690
  if (_a) {
7555
7691
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
7556
7692
  }
7557
- _e.label = 4;
7693
+ _f.label = 4;
7558
7694
  case 4:
7559
7695
  custodyAccountMetas = [];
7560
7696
  custodyOracleAccountMetas = [];
7561
7697
  markets = [];
7562
- for (_i = 0, _b = poolConfig.custodies; _i < _b.length; _i++) {
7563
- custody = _b[_i];
7698
+ for (_b = 0, _c = poolConfig.custodies; _b < _c.length; _b++) {
7699
+ custody = _c[_b];
7564
7700
  custodyAccountMetas.push({
7565
7701
  pubkey: custody.custodyAccount,
7566
7702
  isSigner: false,
@@ -7572,8 +7708,8 @@ var PerpetualsClient = (function () {
7572
7708
  isWritable: false,
7573
7709
  });
7574
7710
  }
7575
- for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
7576
- market = _d[_c];
7711
+ for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
7712
+ market = _e[_d];
7577
7713
  markets.push({
7578
7714
  pubkey: market.marketAccount,
7579
7715
  isSigner: false,
@@ -7581,9 +7717,9 @@ var PerpetualsClient = (function () {
7581
7717
  });
7582
7718
  }
7583
7719
  compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
7584
- _e.label = 5;
7720
+ _f.label = 5;
7585
7721
  case 5:
7586
- _e.trys.push([5, 7, , 8]);
7722
+ _f.trys.push([5, 7, , 8]);
7587
7723
  return [4, this.program.methods
7588
7724
  .removeCompoundingLiquidity({
7589
7725
  compoundingAmountIn: compoundingAmountIn,
@@ -7612,11 +7748,11 @@ var PerpetualsClient = (function () {
7612
7748
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
7613
7749
  .instruction()];
7614
7750
  case 6:
7615
- removeCompoundingLiquidity = _e.sent();
7751
+ removeCompoundingLiquidity = _f.sent();
7616
7752
  instructions.push(removeCompoundingLiquidity);
7617
7753
  return [3, 8];
7618
7754
  case 7:
7619
- err_63 = _e.sent();
7755
+ err_63 = _f.sent();
7620
7756
  console.log("perpClient removeCompoundingLiquidity error:: ", err_63);
7621
7757
  return [3, 8];
7622
7758
  case 8: return [2, {
@@ -7627,12 +7763,16 @@ var PerpetualsClient = (function () {
7627
7763
  });
7628
7764
  });
7629
7765
  };
7630
- this.migrateStake = function (amount, rewardTokenMint, poolConfig, createUserATA) {
7631
- if (createUserATA === void 0) { createUserATA = true; }
7632
- return __awaiter(_this, void 0, void 0, function () {
7633
- 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;
7634
- return __generator(this, function (_f) {
7635
- switch (_f.label) {
7766
+ this.migrateStake = function (amount_1, rewardTokenMint_1, poolConfig_1) {
7767
+ var args_1 = [];
7768
+ for (var _i = 3; _i < arguments.length; _i++) {
7769
+ args_1[_i - 3] = arguments[_i];
7770
+ }
7771
+ return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
7772
+ 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;
7773
+ if (createUserATA === void 0) { createUserATA = true; }
7774
+ return __generator(this, function (_g) {
7775
+ switch (_g.label) {
7636
7776
  case 0:
7637
7777
  publicKey = this.provider.wallet.publicKey;
7638
7778
  preInstructions = [];
@@ -7647,8 +7787,8 @@ var PerpetualsClient = (function () {
7647
7787
  if (!_a) return [3, 2];
7648
7788
  return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
7649
7789
  case 1:
7650
- _a = !(_f.sent());
7651
- _f.label = 2;
7790
+ _a = !(_g.sent());
7791
+ _g.label = 2;
7652
7792
  case 2:
7653
7793
  if (_a) {
7654
7794
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
@@ -7660,8 +7800,8 @@ var PerpetualsClient = (function () {
7660
7800
  if (!_b) return [3, 4];
7661
7801
  return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
7662
7802
  case 3:
7663
- _b = (_f.sent());
7664
- _f.label = 4;
7803
+ _b = (_g.sent());
7804
+ _g.label = 4;
7665
7805
  case 4:
7666
7806
  if (_b) {
7667
7807
  tokenStakeAccounts.push({
@@ -7674,8 +7814,8 @@ var PerpetualsClient = (function () {
7674
7814
  custodyAccountMetas = [];
7675
7815
  custodyOracleAccountMetas = [];
7676
7816
  markets = [];
7677
- for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
7678
- custody = _c[_i];
7817
+ for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
7818
+ custody = _d[_c];
7679
7819
  custodyAccountMetas.push({
7680
7820
  pubkey: custody.custodyAccount,
7681
7821
  isSigner: false,
@@ -7687,17 +7827,17 @@ var PerpetualsClient = (function () {
7687
7827
  isWritable: false,
7688
7828
  });
7689
7829
  }
7690
- for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
7691
- market = _e[_d];
7830
+ for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
7831
+ market = _f[_e];
7692
7832
  markets.push({
7693
7833
  pubkey: market.marketAccount,
7694
7834
  isSigner: false,
7695
7835
  isWritable: false,
7696
7836
  });
7697
7837
  }
7698
- _f.label = 5;
7838
+ _g.label = 5;
7699
7839
  case 5:
7700
- _f.trys.push([5, 7, , 8]);
7840
+ _g.trys.push([5, 7, , 8]);
7701
7841
  return [4, this.program.methods
7702
7842
  .migrateStake({
7703
7843
  amount: amount
@@ -7723,11 +7863,11 @@ var PerpetualsClient = (function () {
7723
7863
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
7724
7864
  .instruction()];
7725
7865
  case 6:
7726
- migrateStake = _f.sent();
7866
+ migrateStake = _g.sent();
7727
7867
  instructions.push(migrateStake);
7728
7868
  return [3, 8];
7729
7869
  case 7:
7730
- err_64 = _f.sent();
7870
+ err_64 = _g.sent();
7731
7871
  console.log("perpClient migrateStake error:: ", err_64);
7732
7872
  return [3, 8];
7733
7873
  case 8: return [2, {
@@ -7821,12 +7961,16 @@ var PerpetualsClient = (function () {
7821
7961
  }
7822
7962
  });
7823
7963
  }); };
7824
- this.compoundingFee = function (poolConfig, rewardTokenSymbol) {
7825
- if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
7826
- return __awaiter(_this, void 0, void 0, function () {
7827
- var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, compoundingFee, err_66;
7828
- return __generator(this, function (_d) {
7829
- switch (_d.label) {
7964
+ this.compoundingFee = function (poolConfig_1) {
7965
+ var args_1 = [];
7966
+ for (var _i = 1; _i < arguments.length; _i++) {
7967
+ args_1[_i - 1] = arguments[_i];
7968
+ }
7969
+ return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
7970
+ var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_66;
7971
+ if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
7972
+ return __generator(this, function (_e) {
7973
+ switch (_e.label) {
7830
7974
  case 0:
7831
7975
  instructions = [];
7832
7976
  additionalSigners = [];
@@ -7835,8 +7979,8 @@ var PerpetualsClient = (function () {
7835
7979
  custodyAccountMetas = [];
7836
7980
  custodyOracleAccountMetas = [];
7837
7981
  markets = [];
7838
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
7839
- custody = _a[_i];
7982
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
7983
+ custody = _b[_a];
7840
7984
  custodyAccountMetas.push({
7841
7985
  pubkey: custody.custodyAccount,
7842
7986
  isSigner: false,
@@ -7848,17 +7992,17 @@ var PerpetualsClient = (function () {
7848
7992
  isWritable: false,
7849
7993
  });
7850
7994
  }
7851
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
7852
- market = _c[_b];
7995
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
7996
+ market = _d[_c];
7853
7997
  markets.push({
7854
7998
  pubkey: market.marketAccount,
7855
7999
  isSigner: false,
7856
8000
  isWritable: false,
7857
8001
  });
7858
8002
  }
7859
- _d.label = 1;
8003
+ _e.label = 1;
7860
8004
  case 1:
7861
- _d.trys.push([1, 3, , 4]);
8005
+ _e.trys.push([1, 3, , 4]);
7862
8006
  return [4, this.program.methods
7863
8007
  .compoundFees({})
7864
8008
  .accounts({
@@ -7877,11 +8021,11 @@ var PerpetualsClient = (function () {
7877
8021
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
7878
8022
  .instruction()];
7879
8023
  case 2:
7880
- compoundingFee = _d.sent();
8024
+ compoundingFee = _e.sent();
7881
8025
  instructions.push(compoundingFee);
7882
8026
  return [3, 4];
7883
8027
  case 3:
7884
- err_66 = _d.sent();
8028
+ err_66 = _e.sent();
7885
8029
  console.log("perpClient compoundingFee error:: ", err_66);
7886
8030
  return [3, 4];
7887
8031
  case 4: return [2, {
@@ -8042,9 +8186,9 @@ var PerpetualsClient = (function () {
8042
8186
  }
8043
8187
  }
8044
8188
  };
8045
- PerpetualsClient.prototype.sendTransaction = function (ixs, opts) {
8046
- if (opts === void 0) { opts = {}; }
8047
- return __awaiter(this, void 0, void 0, function () {
8189
+ PerpetualsClient.prototype.sendTransaction = function (ixs_1) {
8190
+ return __awaiter(this, arguments, void 0, function (ixs, opts) {
8191
+ if (opts === void 0) { opts = {}; }
8048
8192
  return __generator(this, function (_a) {
8049
8193
  switch (_a.label) {
8050
8194
  case 0: return [4, (0, rpc_1.sendTransaction)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
@@ -8053,9 +8197,9 @@ var PerpetualsClient = (function () {
8053
8197
  });
8054
8198
  });
8055
8199
  };
8056
- PerpetualsClient.prototype.sendTransactionV3 = function (ixs, opts) {
8057
- if (opts === void 0) { opts = {}; }
8058
- return __awaiter(this, void 0, void 0, function () {
8200
+ PerpetualsClient.prototype.sendTransactionV3 = function (ixs_1) {
8201
+ return __awaiter(this, arguments, void 0, function (ixs, opts) {
8202
+ if (opts === void 0) { opts = {}; }
8059
8203
  return __generator(this, function (_a) {
8060
8204
  switch (_a.label) {
8061
8205
  case 0: return [4, (0, rpc_1.sendTransactionV3)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];