flash-sdk 2.50.2 → 2.50.4

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.
@@ -2148,36 +2148,40 @@ var PerpetualsClient = (function () {
2148
2148
  }
2149
2149
  });
2150
2150
  }); };
2151
- this.getAddLiquidityAmountAndFeeView = function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
2152
- if (userPublicKey === void 0) { userPublicKey = undefined; }
2153
- return __awaiter(_this, void 0, void 0, function () {
2154
- var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_5, token, _a, custodies_6, custody, _b, _c, market, depositCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
2155
- var _d;
2156
- return __generator(this, function (_e) {
2157
- switch (_e.label) {
2151
+ this.getAddLiquidityAmountAndFeeView = function (amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1) {
2152
+ var args_1 = [];
2153
+ for (var _i = 4; _i < arguments.length; _i++) {
2154
+ args_1[_i - 4] = arguments[_i];
2155
+ }
2156
+ return __awaiter(_this, __spreadArray([amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
2157
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
2158
+ var _e;
2159
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
2160
+ return __generator(this, function (_f) {
2161
+ switch (_f.label) {
2158
2162
  case 0:
2159
2163
  backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
2160
2164
  custodies = POOL_CONFIG.custodies;
2161
2165
  custodyMetas = [];
2162
2166
  marketMetas = [];
2163
- for (_i = 0, custodies_5 = custodies; _i < custodies_5.length; _i++) {
2164
- token = custodies_5[_i];
2167
+ for (_a = 0, custodies_5 = custodies; _a < custodies_5.length; _a++) {
2168
+ token = custodies_5[_a];
2165
2169
  custodyMetas.push({
2166
2170
  isSigner: false,
2167
2171
  isWritable: false,
2168
2172
  pubkey: token.custodyAccount,
2169
2173
  });
2170
2174
  }
2171
- for (_a = 0, custodies_6 = custodies; _a < custodies_6.length; _a++) {
2172
- custody = custodies_6[_a];
2175
+ for (_b = 0, custodies_6 = custodies; _b < custodies_6.length; _b++) {
2176
+ custody = custodies_6[_b];
2173
2177
  custodyMetas.push({
2174
2178
  isSigner: false,
2175
2179
  isWritable: false,
2176
2180
  pubkey: custody.intOracleAccount,
2177
2181
  });
2178
2182
  }
2179
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2180
- market = _c[_b];
2183
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2184
+ market = _d[_c];
2181
2185
  marketMetas.push({
2182
2186
  pubkey: market.marketAccount,
2183
2187
  isSigner: false,
@@ -2200,14 +2204,14 @@ var PerpetualsClient = (function () {
2200
2204
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2201
2205
  .transaction()];
2202
2206
  case 1:
2203
- transaction = _e.sent();
2207
+ transaction = _f.sent();
2204
2208
  return [4, backUpOracleInstructionPromise];
2205
2209
  case 2:
2206
- backUpOracleInstruction = _e.sent();
2207
- (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
2210
+ backUpOracleInstruction = _f.sent();
2211
+ (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2208
2212
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2209
2213
  case 3:
2210
- result = _e.sent();
2214
+ result = _f.sent();
2211
2215
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddLiquidityAmountAndFee'; });
2212
2216
  res = this.viewHelper.decodeLogs(result, index, 'getAddLiquidityAmountAndFee');
2213
2217
  return [2, {
@@ -2218,36 +2222,40 @@ var PerpetualsClient = (function () {
2218
2222
  });
2219
2223
  });
2220
2224
  };
2221
- this.getRemoveLiquidityAmountAndFeeView = function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
2222
- if (userPublicKey === void 0) { userPublicKey = undefined; }
2223
- return __awaiter(_this, void 0, void 0, function () {
2224
- var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_7, token, _a, custodies_8, custody, _b, _c, market, removeCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
2225
- var _d;
2226
- return __generator(this, function (_e) {
2227
- switch (_e.label) {
2225
+ this.getRemoveLiquidityAmountAndFeeView = function (amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1) {
2226
+ var args_1 = [];
2227
+ for (var _i = 4; _i < arguments.length; _i++) {
2228
+ args_1[_i - 4] = arguments[_i];
2229
+ }
2230
+ return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
2231
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
2232
+ var _e;
2233
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
2234
+ return __generator(this, function (_f) {
2235
+ switch (_f.label) {
2228
2236
  case 0:
2229
2237
  backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
2230
2238
  custodies = POOL_CONFIG.custodies;
2231
2239
  custodyMetas = [];
2232
2240
  marketMetas = [];
2233
- for (_i = 0, custodies_7 = custodies; _i < custodies_7.length; _i++) {
2234
- token = custodies_7[_i];
2241
+ for (_a = 0, custodies_7 = custodies; _a < custodies_7.length; _a++) {
2242
+ token = custodies_7[_a];
2235
2243
  custodyMetas.push({
2236
2244
  isSigner: false,
2237
2245
  isWritable: false,
2238
2246
  pubkey: token.custodyAccount,
2239
2247
  });
2240
2248
  }
2241
- for (_a = 0, custodies_8 = custodies; _a < custodies_8.length; _a++) {
2242
- custody = custodies_8[_a];
2249
+ for (_b = 0, custodies_8 = custodies; _b < custodies_8.length; _b++) {
2250
+ custody = custodies_8[_b];
2243
2251
  custodyMetas.push({
2244
2252
  isSigner: false,
2245
2253
  isWritable: false,
2246
2254
  pubkey: custody.intOracleAccount,
2247
2255
  });
2248
2256
  }
2249
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2250
- market = _c[_b];
2257
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2258
+ market = _d[_c];
2251
2259
  marketMetas.push({
2252
2260
  pubkey: market.marketAccount,
2253
2261
  isSigner: false,
@@ -2270,14 +2278,14 @@ var PerpetualsClient = (function () {
2270
2278
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2271
2279
  .transaction()];
2272
2280
  case 1:
2273
- transaction = _e.sent();
2281
+ transaction = _f.sent();
2274
2282
  return [4, backUpOracleInstructionPromise];
2275
2283
  case 2:
2276
- backUpOracleInstruction = _e.sent();
2277
- (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
2284
+ backUpOracleInstruction = _f.sent();
2285
+ (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2278
2286
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2279
2287
  case 3:
2280
- result = _e.sent();
2288
+ result = _f.sent();
2281
2289
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveLiquidityAmountAndFee'; });
2282
2290
  if (result.value.err) {
2283
2291
  return [2, {
@@ -2353,36 +2361,40 @@ var PerpetualsClient = (function () {
2353
2361
  }
2354
2362
  });
2355
2363
  }); };
2356
- this.getAddCompoundingLiquidityAmountAndFeeView = function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
2357
- if (userPublicKey === void 0) { userPublicKey = undefined; }
2358
- return __awaiter(_this, void 0, void 0, function () {
2359
- var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_11, token, _a, custodies_12, custody, _b, _c, market, depositCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
2360
- var _d;
2361
- return __generator(this, function (_e) {
2362
- switch (_e.label) {
2364
+ this.getAddCompoundingLiquidityAmountAndFeeView = function (amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1) {
2365
+ var args_1 = [];
2366
+ for (var _i = 4; _i < arguments.length; _i++) {
2367
+ args_1[_i - 4] = arguments[_i];
2368
+ }
2369
+ return __awaiter(_this, __spreadArray([amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
2370
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
2371
+ var _e;
2372
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
2373
+ return __generator(this, function (_f) {
2374
+ switch (_f.label) {
2363
2375
  case 0:
2364
2376
  backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
2365
2377
  custodies = POOL_CONFIG.custodies;
2366
2378
  custodyMetas = [];
2367
2379
  marketMetas = [];
2368
- for (_i = 0, custodies_11 = custodies; _i < custodies_11.length; _i++) {
2369
- token = custodies_11[_i];
2380
+ for (_a = 0, custodies_11 = custodies; _a < custodies_11.length; _a++) {
2381
+ token = custodies_11[_a];
2370
2382
  custodyMetas.push({
2371
2383
  isSigner: false,
2372
2384
  isWritable: false,
2373
2385
  pubkey: token.custodyAccount,
2374
2386
  });
2375
2387
  }
2376
- for (_a = 0, custodies_12 = custodies; _a < custodies_12.length; _a++) {
2377
- custody = custodies_12[_a];
2388
+ for (_b = 0, custodies_12 = custodies; _b < custodies_12.length; _b++) {
2389
+ custody = custodies_12[_b];
2378
2390
  custodyMetas.push({
2379
2391
  isSigner: false,
2380
2392
  isWritable: false,
2381
2393
  pubkey: custody.intOracleAccount,
2382
2394
  });
2383
2395
  }
2384
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2385
- market = _c[_b];
2396
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2397
+ market = _d[_c];
2386
2398
  marketMetas.push({
2387
2399
  pubkey: market.marketAccount,
2388
2400
  isSigner: false,
@@ -2393,7 +2405,7 @@ var PerpetualsClient = (function () {
2393
2405
  rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
2394
2406
  return [4, backUpOracleInstructionPromise];
2395
2407
  case 1:
2396
- backUpOracleInstruction = _e.sent();
2408
+ backUpOracleInstruction = _f.sent();
2397
2409
  return [4, this.program.methods
2398
2410
  .getAddCompoundingLiquidityAmountAndFee({
2399
2411
  amountIn: amount,
@@ -2412,11 +2424,11 @@ var PerpetualsClient = (function () {
2412
2424
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2413
2425
  .transaction()];
2414
2426
  case 2:
2415
- transaction = _e.sent();
2416
- (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
2427
+ transaction = _f.sent();
2428
+ (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2417
2429
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2418
2430
  case 3:
2419
- result = _e.sent();
2431
+ result = _f.sent();
2420
2432
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddCompoundingLiquidityAmountAndFee'; });
2421
2433
  res = this.viewHelper.decodeLogs(result, index, 'getAddCompoundingLiquidityAmountAndFee');
2422
2434
  return [2, {
@@ -2427,36 +2439,40 @@ var PerpetualsClient = (function () {
2427
2439
  });
2428
2440
  });
2429
2441
  };
2430
- this.getRemoveCompoundingLiquidityAmountAndFeeView = function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
2431
- if (userPublicKey === void 0) { userPublicKey = undefined; }
2432
- return __awaiter(_this, void 0, void 0, function () {
2433
- var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_13, token, _a, custodies_14, custody, _b, _c, market, removeCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
2434
- var _d;
2435
- return __generator(this, function (_e) {
2436
- switch (_e.label) {
2442
+ this.getRemoveCompoundingLiquidityAmountAndFeeView = function (amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1) {
2443
+ var args_1 = [];
2444
+ for (var _i = 4; _i < arguments.length; _i++) {
2445
+ args_1[_i - 4] = arguments[_i];
2446
+ }
2447
+ return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
2448
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
2449
+ var _e;
2450
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
2451
+ return __generator(this, function (_f) {
2452
+ switch (_f.label) {
2437
2453
  case 0:
2438
2454
  backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
2439
2455
  custodies = POOL_CONFIG.custodies;
2440
2456
  custodyMetas = [];
2441
2457
  marketMetas = [];
2442
- for (_i = 0, custodies_13 = custodies; _i < custodies_13.length; _i++) {
2443
- token = custodies_13[_i];
2458
+ for (_a = 0, custodies_13 = custodies; _a < custodies_13.length; _a++) {
2459
+ token = custodies_13[_a];
2444
2460
  custodyMetas.push({
2445
2461
  isSigner: false,
2446
2462
  isWritable: false,
2447
2463
  pubkey: token.custodyAccount,
2448
2464
  });
2449
2465
  }
2450
- for (_a = 0, custodies_14 = custodies; _a < custodies_14.length; _a++) {
2451
- custody = custodies_14[_a];
2466
+ for (_b = 0, custodies_14 = custodies; _b < custodies_14.length; _b++) {
2467
+ custody = custodies_14[_b];
2452
2468
  custodyMetas.push({
2453
2469
  isSigner: false,
2454
2470
  isWritable: false,
2455
2471
  pubkey: custody.intOracleAccount,
2456
2472
  });
2457
2473
  }
2458
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2459
- market = _c[_b];
2474
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2475
+ market = _d[_c];
2460
2476
  marketMetas.push({
2461
2477
  pubkey: market.marketAccount,
2462
2478
  isSigner: false,
@@ -2467,7 +2483,7 @@ var PerpetualsClient = (function () {
2467
2483
  rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
2468
2484
  return [4, backUpOracleInstructionPromise];
2469
2485
  case 1:
2470
- backUpOracleInstruction = _e.sent();
2486
+ backUpOracleInstruction = _f.sent();
2471
2487
  return [4, this.program.methods
2472
2488
  .getRemoveCompoundingLiquidityAmountAndFee({
2473
2489
  compoundingAmountIn: amount,
@@ -2486,11 +2502,11 @@ var PerpetualsClient = (function () {
2486
2502
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2487
2503
  .transaction()];
2488
2504
  case 2:
2489
- transaction = _e.sent();
2490
- (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
2505
+ transaction = _f.sent();
2506
+ (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2491
2507
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2492
2508
  case 3:
2493
- result = _e.sent();
2509
+ result = _f.sent();
2494
2510
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveCompoundingLiquidityAmountAndFee'; });
2495
2511
  if (result.value.err) {
2496
2512
  return [2, {
@@ -2532,6 +2548,7 @@ var PerpetualsClient = (function () {
2532
2548
  targetOracleAccount: targetCustodyConfig.intOracleAccount,
2533
2549
  collateralCustody: collateralCustodyConfig.custodyAccount,
2534
2550
  collateralOracleAccount: collateralCustodyConfig.intOracleAccount,
2551
+ market: marketConfig_1.marketAccount,
2535
2552
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
2536
2553
  })
2537
2554
  .view()
@@ -2670,14 +2687,18 @@ var PerpetualsClient = (function () {
2670
2687
  }
2671
2688
  });
2672
2689
  }); };
2673
- this.openPosition = function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
2674
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2675
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2676
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2677
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2678
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2679
- return __awaiter(_this, void 0, void 0, function () {
2690
+ this.openPosition = function (targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1) {
2691
+ var args_1 = [];
2692
+ for (var _i = 8; _i < arguments.length; _i++) {
2693
+ args_1[_i - 8] = arguments[_i];
2694
+ }
2695
+ 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) {
2680
2696
  var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
2697
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2698
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2699
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2700
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2701
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2681
2702
  return __generator(this, function (_c) {
2682
2703
  switch (_c.label) {
2683
2704
  case 0:
@@ -2781,15 +2802,19 @@ var PerpetualsClient = (function () {
2781
2802
  });
2782
2803
  });
2783
2804
  };
2784
- this.closePosition = function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
2785
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2786
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2787
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2788
- if (createUserATA === void 0) { createUserATA = true; }
2789
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
2790
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2791
- return __awaiter(_this, void 0, void 0, function () {
2805
+ this.closePosition = function (marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
2806
+ var args_1 = [];
2807
+ for (var _i = 6; _i < arguments.length; _i++) {
2808
+ args_1[_i - 6] = arguments[_i];
2809
+ }
2810
+ 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) {
2792
2811
  var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_2;
2812
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2813
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2814
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2815
+ if (createUserATA === void 0) { createUserATA = true; }
2816
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
2817
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2793
2818
  return __generator(this, function (_b) {
2794
2819
  switch (_b.label) {
2795
2820
  case 0:
@@ -2886,14 +2911,18 @@ var PerpetualsClient = (function () {
2886
2911
  });
2887
2912
  });
2888
2913
  };
2889
- this.swapAndOpen = function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, minCollateralAmountOut, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
2890
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2891
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2892
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2893
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2894
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2895
- return __awaiter(_this, void 0, void 0, function () {
2914
+ this.swapAndOpen = function (targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, minCollateralAmountOut_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1) {
2915
+ var args_1 = [];
2916
+ for (var _i = 10; _i < arguments.length; _i++) {
2917
+ args_1[_i - 10] = arguments[_i];
2918
+ }
2919
+ 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) {
2896
2920
  var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_3;
2921
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2922
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2923
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2924
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2925
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2897
2926
  return __generator(this, function (_c) {
2898
2927
  switch (_c.label) {
2899
2928
  case 0:
@@ -3033,13 +3062,17 @@ var PerpetualsClient = (function () {
3033
3062
  });
3034
3063
  });
3035
3064
  };
3036
- this.closeAndSwap = function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, minSwapAmountOut, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, ephemeralSignerPubkey) {
3037
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3038
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3039
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3040
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3041
- return __awaiter(_this, void 0, void 0, function () {
3065
+ this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, minSwapAmountOut_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
3066
+ var args_1 = [];
3067
+ for (var _i = 8; _i < arguments.length; _i++) {
3068
+ args_1[_i - 8] = arguments[_i];
3069
+ }
3070
+ 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) {
3042
3071
  var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, inx, err_4;
3072
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3073
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3074
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3075
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3043
3076
  return __generator(this, function (_a) {
3044
3077
  switch (_a.label) {
3045
3078
  case 0:
@@ -3153,16 +3186,20 @@ var PerpetualsClient = (function () {
3153
3186
  });
3154
3187
  });
3155
3188
  };
3156
- this.swap = function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey) {
3157
- if (useFeesPool === void 0) { useFeesPool = false; }
3158
- if (createUserATA === void 0) { createUserATA = true; }
3159
- if (unWrapSol === void 0) { unWrapSol = false; }
3160
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3161
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3162
- return __awaiter(_this, void 0, void 0, function () {
3163
- 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_5;
3164
- return __generator(this, function (_f) {
3165
- switch (_f.label) {
3189
+ this.swap = function (userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1) {
3190
+ var args_1 = [];
3191
+ for (var _i = 5; _i < arguments.length; _i++) {
3192
+ args_1[_i - 5] = arguments[_i];
3193
+ }
3194
+ 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) {
3195
+ 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_5;
3196
+ if (useFeesPool === void 0) { useFeesPool = false; }
3197
+ if (createUserATA === void 0) { createUserATA = true; }
3198
+ if (unWrapSol === void 0) { unWrapSol = false; }
3199
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3200
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3201
+ return __generator(this, function (_g) {
3202
+ switch (_g.label) {
3166
3203
  case 0:
3167
3204
  userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
3168
3205
  if (!userInputCustodyConfig) {
@@ -3180,10 +3217,10 @@ var PerpetualsClient = (function () {
3180
3217
  if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
3181
3218
  return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
3182
3219
  case 1:
3183
- wsolAssociatedTokenAccount = _f.sent();
3220
+ wsolAssociatedTokenAccount = _g.sent();
3184
3221
  return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
3185
3222
  case 2:
3186
- wsolATAExist = _f.sent();
3223
+ wsolATAExist = _g.sent();
3187
3224
  if (!wsolATAExist) {
3188
3225
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
3189
3226
  }
@@ -3191,11 +3228,11 @@ var PerpetualsClient = (function () {
3191
3228
  _a = anchor_1.BN.bind;
3192
3229
  return [4, this.provider.connection.getBalance(publicKey)];
3193
3230
  case 3:
3194
- unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
3231
+ unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
3195
3232
  if (unWrappedSolBalance.lt(amountIn)) {
3196
3233
  throw "Insufficient SOL Funds";
3197
3234
  }
3198
- _f.label = 4;
3235
+ _g.label = 4;
3199
3236
  case 4:
3200
3237
  instructions.push(web3_js_1.SystemProgram.transfer({
3201
3238
  fromPubkey: publicKey,
@@ -3217,20 +3254,20 @@ var PerpetualsClient = (function () {
3217
3254
  additionalSigners: additionalSigners
3218
3255
  }];
3219
3256
  }
3220
- _f.label = 6;
3257
+ _g.label = 6;
3221
3258
  case 6:
3222
- _f.trys.push([6, 19, , 20]);
3259
+ _g.trys.push([6, 19, , 20]);
3223
3260
  if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
3224
3261
  console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
3225
3262
  return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
3226
3263
  case 7:
3227
- accCreationLamports = (_f.sent());
3264
+ accCreationLamports = (_g.sent());
3228
3265
  console.log("accCreationLamports:", accCreationLamports);
3229
3266
  lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
3230
3267
  _b = anchor_1.BN.bind;
3231
3268
  return [4, this.provider.connection.getBalance(publicKey)];
3232
3269
  case 8:
3233
- unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _f.sent()]))();
3270
+ unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _g.sent()]))();
3234
3271
  if (unWrappedSolBalance.lt(amountIn)) {
3235
3272
  throw "Insufficient SOL Funds";
3236
3273
  }
@@ -3257,18 +3294,18 @@ var PerpetualsClient = (function () {
3257
3294
  userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
3258
3295
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
3259
3296
  case 10:
3260
- if (!(_f.sent())) {
3297
+ if (!(_g.sent())) {
3261
3298
  throw "Insufficient Funds , Token Account doesn't exist";
3262
3299
  }
3263
3300
  if (!!skipBalanceChecks) return [3, 12];
3264
3301
  _c = anchor_1.BN.bind;
3265
3302
  return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
3266
3303
  case 11:
3267
- tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
3304
+ tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
3268
3305
  if (tokenAccountBalance.lt(amountIn)) {
3269
3306
  throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
3270
3307
  }
3271
- _f.label = 12;
3308
+ _g.label = 12;
3272
3309
  case 12:
3273
3310
  if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
3274
3311
  lamports = (this.minimumBalanceForRentExemptAccountLamports);
@@ -3293,23 +3330,23 @@ var PerpetualsClient = (function () {
3293
3330
  return [3, 17];
3294
3331
  case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
3295
3332
  case 14:
3296
- userOutputTokenAccount = _f.sent();
3333
+ userOutputTokenAccount = _g.sent();
3297
3334
  _d = createUserATA;
3298
3335
  if (!_d) return [3, 16];
3299
3336
  return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
3300
3337
  case 15:
3301
- _d = !(_f.sent());
3302
- _f.label = 16;
3338
+ _d = !(_g.sent());
3339
+ _g.label = 16;
3303
3340
  case 16:
3304
3341
  if (_d) {
3305
3342
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
3306
3343
  }
3307
- _f.label = 17;
3344
+ _g.label = 17;
3308
3345
  case 17:
3309
3346
  custodyAccountMetas = [];
3310
3347
  custodyOracleAccountMetas = [];
3311
- for (_i = 0, _e = poolConfig.custodies; _i < _e.length; _i++) {
3312
- custody = _e[_i];
3348
+ for (_e = 0, _f = poolConfig.custodies; _e < _f.length; _e++) {
3349
+ custody = _f[_e];
3313
3350
  custodyAccountMetas.push({
3314
3351
  pubkey: custody.custodyAccount,
3315
3352
  isSigner: false,
@@ -3349,7 +3386,7 @@ var PerpetualsClient = (function () {
3349
3386
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
3350
3387
  .instruction()];
3351
3388
  case 18:
3352
- inx = _f.sent();
3389
+ inx = _g.sent();
3353
3390
  instructions.push(inx);
3354
3391
  if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
3355
3392
  closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
@@ -3357,7 +3394,7 @@ var PerpetualsClient = (function () {
3357
3394
  }
3358
3395
  return [3, 20];
3359
3396
  case 19:
3360
- err_5 = _f.sent();
3397
+ err_5 = _g.sent();
3361
3398
  console.error("perpClient Swap error:: ", err_5);
3362
3399
  throw err_5;
3363
3400
  case 20: return [2, {
@@ -3439,11 +3476,15 @@ var PerpetualsClient = (function () {
3439
3476
  }
3440
3477
  });
3441
3478
  }); };
3442
- this.addCollateral = function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
3443
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3444
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3445
- return __awaiter(_this, void 0, void 0, function () {
3479
+ this.addCollateral = function (collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
3480
+ var args_1 = [];
3481
+ for (var _i = 6; _i < arguments.length; _i++) {
3482
+ args_1[_i - 6] = arguments[_i];
3483
+ }
3484
+ 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) {
3446
3485
  var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
3486
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3487
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3447
3488
  return __generator(this, function (_c) {
3448
3489
  switch (_c.label) {
3449
3490
  case 0:
@@ -3537,11 +3578,15 @@ var PerpetualsClient = (function () {
3537
3578
  });
3538
3579
  });
3539
3580
  };
3540
- this.swapAndAddCollateral = function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minCollateralAmountOut, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
3541
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3542
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3543
- return __awaiter(_this, void 0, void 0, function () {
3581
+ this.swapAndAddCollateral = function (targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1) {
3582
+ var args_1 = [];
3583
+ for (var _i = 8; _i < arguments.length; _i++) {
3584
+ args_1[_i - 8] = arguments[_i];
3585
+ }
3586
+ 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) {
3544
3587
  var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
3588
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3589
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3545
3590
  return __generator(this, function (_c) {
3546
3591
  switch (_c.label) {
3547
3592
  case 0:
@@ -3652,12 +3697,16 @@ var PerpetualsClient = (function () {
3652
3697
  });
3653
3698
  });
3654
3699
  };
3655
- this.removeCollateral = function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
3656
- if (createUserATA === void 0) { createUserATA = true; }
3657
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
3658
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3659
- return __awaiter(_this, void 0, void 0, function () {
3700
+ this.removeCollateral = function (collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
3701
+ var args_1 = [];
3702
+ for (var _i = 6; _i < arguments.length; _i++) {
3703
+ args_1[_i - 6] = arguments[_i];
3704
+ }
3705
+ 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) {
3660
3706
  var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns, error_3;
3707
+ if (createUserATA === void 0) { createUserATA = true; }
3708
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
3709
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3661
3710
  return __generator(this, function (_b) {
3662
3711
  switch (_b.label) {
3663
3712
  case 0:
@@ -3758,10 +3807,14 @@ var PerpetualsClient = (function () {
3758
3807
  });
3759
3808
  });
3760
3809
  };
3761
- this.removeCollateralAndSwap = function (targetSymbol, collateralSymbol, outputSymbol, minSwapAmountOut, collateralDelta, side, poolConfig, ephemeralSignerPubkey) {
3762
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3763
- return __awaiter(_this, void 0, void 0, function () {
3810
+ this.removeCollateralAndSwap = function (targetSymbol_1, collateralSymbol_1, outputSymbol_1, minSwapAmountOut_1, collateralDelta_1, side_1, poolConfig_1) {
3811
+ var args_1 = [];
3812
+ for (var _i = 7; _i < arguments.length; _i++) {
3813
+ args_1[_i - 7] = arguments[_i];
3814
+ }
3815
+ 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) {
3764
3816
  var publicKey, targetCustodyConfig, collateralCustodyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, instruction;
3817
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3765
3818
  return __generator(this, function (_a) {
3766
3819
  switch (_a.label) {
3767
3820
  case 0:
@@ -3854,12 +3907,16 @@ var PerpetualsClient = (function () {
3854
3907
  });
3855
3908
  });
3856
3909
  };
3857
- this.increaseSize = function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
3858
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3859
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3860
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3861
- return __awaiter(_this, void 0, void 0, function () {
3910
+ this.increaseSize = function (targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
3911
+ var args_1 = [];
3912
+ for (var _i = 8; _i < arguments.length; _i++) {
3913
+ args_1[_i - 8] = arguments[_i];
3914
+ }
3915
+ 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) {
3862
3916
  var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
3917
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3918
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3919
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3863
3920
  return __generator(this, function (_a) {
3864
3921
  switch (_a.label) {
3865
3922
  case 0:
@@ -3914,12 +3971,16 @@ var PerpetualsClient = (function () {
3914
3971
  });
3915
3972
  });
3916
3973
  };
3917
- this.decreaseSize = function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
3918
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3919
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3920
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3921
- return __awaiter(_this, void 0, void 0, function () {
3974
+ this.decreaseSize = function (targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
3975
+ var args_1 = [];
3976
+ for (var _i = 8; _i < arguments.length; _i++) {
3977
+ args_1[_i - 8] = arguments[_i];
3978
+ }
3979
+ 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) {
3922
3980
  var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
3981
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3982
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3983
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3923
3984
  return __generator(this, function (_a) {
3924
3985
  switch (_a.label) {
3925
3986
  case 0:
@@ -3974,13 +4035,17 @@ var PerpetualsClient = (function () {
3974
4035
  });
3975
4036
  });
3976
4037
  };
3977
- this.addLiquidity = function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
3978
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3979
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3980
- return __awaiter(_this, void 0, void 0, function () {
3981
- 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_7;
3982
- return __generator(this, function (_f) {
3983
- switch (_f.label) {
4038
+ this.addLiquidity = function (payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1) {
4039
+ var args_1 = [];
4040
+ for (var _i = 4; _i < arguments.length; _i++) {
4041
+ args_1[_i - 4] = arguments[_i];
4042
+ }
4043
+ return __awaiter(_this, __spreadArray([payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
4044
+ 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_7;
4045
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4046
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4047
+ return __generator(this, function (_g) {
4048
+ switch (_g.label) {
3984
4049
  case 0:
3985
4050
  publicKey = this.provider.wallet.publicKey;
3986
4051
  payTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey); });
@@ -3991,16 +4056,16 @@ var PerpetualsClient = (function () {
3991
4056
  instructions = [];
3992
4057
  postInstructions = [];
3993
4058
  additionalSigners = [];
3994
- _f.label = 1;
4059
+ _g.label = 1;
3995
4060
  case 1:
3996
- _f.trys.push([1, 10, , 11]);
4061
+ _g.trys.push([1, 10, , 11]);
3997
4062
  userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true);
3998
4063
  lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
3999
4064
  custodyAccountMetas = [];
4000
4065
  custodyOracleAccountMetas = [];
4001
4066
  markets = [];
4002
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
4003
- custody = _a[_i];
4067
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
4068
+ custody = _b[_a];
4004
4069
  custodyAccountMetas.push({
4005
4070
  pubkey: custody.custodyAccount,
4006
4071
  isSigner: false,
@@ -4012,8 +4077,8 @@ var PerpetualsClient = (function () {
4012
4077
  isWritable: false,
4013
4078
  });
4014
4079
  }
4015
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
4016
- market = _c[_b];
4080
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
4081
+ market = _d[_c];
4017
4082
  markets.push({
4018
4083
  pubkey: market.marketAccount,
4019
4084
  isSigner: false,
@@ -4022,21 +4087,21 @@ var PerpetualsClient = (function () {
4022
4087
  }
4023
4088
  return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
4024
4089
  case 2:
4025
- if (!(_f.sent())) {
4090
+ if (!(_g.sent())) {
4026
4091
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
4027
4092
  }
4028
4093
  if (!(payTokenSymbol == 'SOL')) return [3, 5];
4029
4094
  console.log("payTokenSymbol === SOL", payTokenSymbol);
4030
4095
  lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
4031
4096
  if (!!skipBalanceChecks) return [3, 4];
4032
- _d = anchor_1.BN.bind;
4097
+ _e = anchor_1.BN.bind;
4033
4098
  return [4, this.provider.connection.getBalance(publicKey)];
4034
4099
  case 3:
4035
- unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _f.sent()]))();
4100
+ unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _g.sent()]))();
4036
4101
  if (unWrappedSolBalance.lt(lamports)) {
4037
4102
  throw "Insufficient SOL Funds";
4038
4103
  }
4039
- _f.label = 4;
4104
+ _g.label = 4;
4040
4105
  case 4:
4041
4106
  if (!ephemeralSignerPubkey) {
4042
4107
  wrappedSolAccount = new web3_js_1.Keypair();
@@ -4060,17 +4125,17 @@ var PerpetualsClient = (function () {
4060
4125
  if (!!skipBalanceChecks) return [3, 8];
4061
4126
  return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
4062
4127
  case 6:
4063
- if (!(_f.sent())) {
4128
+ if (!(_g.sent())) {
4064
4129
  throw "Insufficient Funds , token Account doesn't exist";
4065
4130
  }
4066
- _e = anchor_1.BN.bind;
4131
+ _f = anchor_1.BN.bind;
4067
4132
  return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
4068
4133
  case 7:
4069
- tokenAccountBalance = new (_e.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
4134
+ tokenAccountBalance = new (_f.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
4070
4135
  if (tokenAccountBalance.lt(tokenAmountIn)) {
4071
4136
  throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
4072
4137
  }
4073
- _f.label = 8;
4138
+ _g.label = 8;
4074
4139
  case 8: return [4, this.program.methods
4075
4140
  .addLiquidity({
4076
4141
  amountIn: tokenAmountIn,
@@ -4095,11 +4160,11 @@ var PerpetualsClient = (function () {
4095
4160
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4096
4161
  .instruction()];
4097
4162
  case 9:
4098
- instruction = _f.sent();
4163
+ instruction = _g.sent();
4099
4164
  instructions.push(instruction);
4100
4165
  return [3, 11];
4101
4166
  case 10:
4102
- err_7 = _f.sent();
4167
+ err_7 = _g.sent();
4103
4168
  console.error("perpClient addLiquidity error:: ", err_7);
4104
4169
  throw err_7;
4105
4170
  case 11: return [2, {
@@ -4110,14 +4175,18 @@ var PerpetualsClient = (function () {
4110
4175
  });
4111
4176
  });
4112
4177
  };
4113
- this.addLiquidityAndStake = function (inputSymbol, amountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
4114
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4115
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4116
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4117
- return __awaiter(_this, void 0, void 0, function () {
4118
- 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;
4119
- return __generator(this, function (_f) {
4120
- switch (_f.label) {
4178
+ this.addLiquidityAndStake = function (inputSymbol_1, amountIn_1, minLpAmountOut_1, poolConfig_1) {
4179
+ var args_1 = [];
4180
+ for (var _i = 4; _i < arguments.length; _i++) {
4181
+ args_1[_i - 4] = arguments[_i];
4182
+ }
4183
+ 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) {
4184
+ 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;
4185
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4186
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4187
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4188
+ return __generator(this, function (_g) {
4189
+ switch (_g.label) {
4121
4190
  case 0:
4122
4191
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
4123
4192
  preInstructions = [];
@@ -4137,14 +4206,14 @@ var PerpetualsClient = (function () {
4137
4206
  _a = anchor_1.BN.bind;
4138
4207
  return [4, this.provider.connection.getBalance(publicKey)];
4139
4208
  case 1:
4140
- unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
4209
+ unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
4141
4210
  if (unWrappedSolBalance.lt(lamports)) {
4142
4211
  throw "Insufficient SOL Funds";
4143
4212
  }
4144
- _f.label = 2;
4213
+ _g.label = 2;
4145
4214
  case 2: return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
4146
4215
  case 3:
4147
- if (!(_f.sent())) {
4216
+ if (!(_g.sent())) {
4148
4217
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
4149
4218
  }
4150
4219
  if (!ephemeralSignerPubkey) {
@@ -4170,23 +4239,23 @@ var PerpetualsClient = (function () {
4170
4239
  if (!!skipBalanceChecks) return [3, 7];
4171
4240
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
4172
4241
  case 5:
4173
- if (!(_f.sent())) {
4242
+ if (!(_g.sent())) {
4174
4243
  throw "Insufficient Funds , token Account doesn't exist";
4175
4244
  }
4176
4245
  _b = anchor_1.BN.bind;
4177
4246
  return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
4178
4247
  case 6:
4179
- tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
4248
+ tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
4180
4249
  if (tokenAccountBalance.lt(amountIn)) {
4181
4250
  throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
4182
4251
  }
4183
- _f.label = 7;
4252
+ _g.label = 7;
4184
4253
  case 7:
4185
4254
  custodyAccountMetas = [];
4186
4255
  custodyOracleAccountMetas = [];
4187
4256
  markets = [];
4188
- for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
4189
- custody = _c[_i];
4257
+ for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
4258
+ custody = _d[_c];
4190
4259
  custodyAccountMetas.push({
4191
4260
  pubkey: custody.custodyAccount,
4192
4261
  isSigner: false,
@@ -4198,8 +4267,8 @@ var PerpetualsClient = (function () {
4198
4267
  isWritable: false,
4199
4268
  });
4200
4269
  }
4201
- for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
4202
- market = _e[_d];
4270
+ for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
4271
+ market = _f[_e];
4203
4272
  markets.push({
4204
4273
  pubkey: market.marketAccount,
4205
4274
  isSigner: false,
@@ -4231,7 +4300,7 @@ var PerpetualsClient = (function () {
4231
4300
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4232
4301
  .instruction()];
4233
4302
  case 8:
4234
- instruction = _f.sent();
4303
+ instruction = _g.sent();
4235
4304
  instructions.push(instruction);
4236
4305
  return [2, {
4237
4306
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -4241,16 +4310,20 @@ var PerpetualsClient = (function () {
4241
4310
  });
4242
4311
  });
4243
4312
  };
4244
- this.removeLiquidity = function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey, userPublicKey) {
4245
- if (closeLpATA === void 0) { closeLpATA = false; }
4246
- if (createUserATA === void 0) { createUserATA = true; }
4247
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
4248
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4249
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4250
- return __awaiter(_this, void 0, void 0, function () {
4251
- 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_8;
4252
- return __generator(this, function (_e) {
4253
- switch (_e.label) {
4313
+ this.removeLiquidity = function (recieveTokenSymbol_1, liquidityAmountIn_1, minTokenAmountOut_1, poolConfig_1) {
4314
+ var args_1 = [];
4315
+ for (var _i = 4; _i < arguments.length; _i++) {
4316
+ args_1[_i - 4] = arguments[_i];
4317
+ }
4318
+ 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) {
4319
+ 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_8;
4320
+ if (closeLpATA === void 0) { closeLpATA = false; }
4321
+ if (createUserATA === void 0) { createUserATA = true; }
4322
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
4323
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4324
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4325
+ return __generator(this, function (_f) {
4326
+ switch (_f.label) {
4254
4327
  case 0:
4255
4328
  recieveTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey); });
4256
4329
  if (!recieveTokenCustodyConfig) {
@@ -4261,15 +4334,15 @@ var PerpetualsClient = (function () {
4261
4334
  instructions = [];
4262
4335
  postInstructions = [];
4263
4336
  additionalSigners = [];
4264
- _e.label = 1;
4337
+ _f.label = 1;
4265
4338
  case 1:
4266
- _e.trys.push([1, 7, , 8]);
4339
+ _f.trys.push([1, 7, , 8]);
4267
4340
  stakedLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
4268
4341
  custodyAccountMetas = [];
4269
4342
  custodyOracleAccountMetas = [];
4270
4343
  markets = [];
4271
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
4272
- custody = _a[_i];
4344
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
4345
+ custody = _b[_a];
4273
4346
  custodyAccountMetas.push({
4274
4347
  pubkey: custody.custodyAccount,
4275
4348
  isSigner: false,
@@ -4281,8 +4354,8 @@ var PerpetualsClient = (function () {
4281
4354
  isWritable: false,
4282
4355
  });
4283
4356
  }
4284
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
4285
- market = _c[_b];
4357
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
4358
+ market = _d[_c];
4286
4359
  markets.push({
4287
4360
  pubkey: market.marketAccount,
4288
4361
  isSigner: false,
@@ -4311,17 +4384,17 @@ var PerpetualsClient = (function () {
4311
4384
  return [3, 5];
4312
4385
  case 2:
4313
4386
  userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true);
4314
- _d = createUserATA;
4315
- if (!_d) return [3, 4];
4387
+ _e = createUserATA;
4388
+ if (!_e) return [3, 4];
4316
4389
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
4317
4390
  case 3:
4318
- _d = !(_e.sent());
4319
- _e.label = 4;
4391
+ _e = !(_f.sent());
4392
+ _f.label = 4;
4320
4393
  case 4:
4321
- if (_d) {
4394
+ if (_e) {
4322
4395
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey));
4323
4396
  }
4324
- _e.label = 5;
4397
+ _f.label = 5;
4325
4398
  case 5: return [4, this.program.methods
4326
4399
  .removeLiquidity({
4327
4400
  lpAmountIn: liquidityAmountIn,
@@ -4346,7 +4419,7 @@ var PerpetualsClient = (function () {
4346
4419
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4347
4420
  .instruction()];
4348
4421
  case 6:
4349
- removeLiquidityTx = _e.sent();
4422
+ removeLiquidityTx = _f.sent();
4350
4423
  instructions.push(removeLiquidityTx);
4351
4424
  if (closeLpATA) {
4352
4425
  closeInx = (0, spl_token_1.createCloseAccountInstruction)(stakedLpTokenAccount, publicKey, publicKey);
@@ -4358,7 +4431,7 @@ var PerpetualsClient = (function () {
4358
4431
  }
4359
4432
  return [3, 8];
4360
4433
  case 7:
4361
- err_8 = _e.sent();
4434
+ err_8 = _f.sent();
4362
4435
  console.log("perpClient removeLiquidity error:: ", err_8);
4363
4436
  throw err_8;
4364
4437
  case 8: return [2, {
@@ -4776,22 +4849,26 @@ var PerpetualsClient = (function () {
4776
4849
  }
4777
4850
  });
4778
4851
  }); };
4779
- this.refreshStakeWithTokenStake = function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
4780
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4781
- return __awaiter(_this, void 0, void 0, function () {
4782
- var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_17;
4783
- return __generator(this, function (_b) {
4784
- switch (_b.label) {
4852
+ this.refreshStakeWithTokenStake = function (rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1) {
4853
+ var args_1 = [];
4854
+ for (var _i = 3; _i < arguments.length; _i++) {
4855
+ args_1[_i - 3] = arguments[_i];
4856
+ }
4857
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
4858
+ var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_17;
4859
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4860
+ return __generator(this, function (_c) {
4861
+ switch (_c.label) {
4785
4862
  case 0:
4786
- _b.trys.push([0, 2, , 3]);
4863
+ _c.trys.push([0, 2, , 3]);
4787
4864
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
4788
4865
  rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
4789
4866
  rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
4790
4867
  pool = poolConfig.poolAddress;
4791
4868
  feeDistributionTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("custody_token_account"), pool.toBuffer(), rewardCustodyMint.toBuffer()], this.programId)[0];
4792
4869
  custodyAccountMetas = [];
4793
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
4794
- custody = _a[_i];
4870
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
4871
+ custody = _b[_a];
4795
4872
  custodyAccountMetas.push({
4796
4873
  pubkey: custody.custodyAccount,
4797
4874
  isSigner: false,
@@ -4823,10 +4900,10 @@ var PerpetualsClient = (function () {
4823
4900
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
4824
4901
  .instruction()];
4825
4902
  case 1:
4826
- refreshStakeInstruction = _b.sent();
4903
+ refreshStakeInstruction = _c.sent();
4827
4904
  return [2, refreshStakeInstruction];
4828
4905
  case 2:
4829
- err_17 = _b.sent();
4906
+ err_17 = _c.sent();
4830
4907
  console.log("perpClient refreshStaking error:: ", err_17);
4831
4908
  throw err_17;
4832
4909
  case 3: return [2];
@@ -4834,10 +4911,14 @@ var PerpetualsClient = (function () {
4834
4911
  });
4835
4912
  });
4836
4913
  };
4837
- this.unstakeInstant = function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
4838
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4839
- return __awaiter(_this, void 0, void 0, function () {
4914
+ this.unstakeInstant = function (rewardSymbol_1, unstakeAmount_1, poolConfig_1) {
4915
+ var args_1 = [];
4916
+ for (var _i = 3; _i < arguments.length; _i++) {
4917
+ args_1[_i - 3] = arguments[_i];
4918
+ }
4919
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
4840
4920
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_18;
4921
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4841
4922
  return __generator(this, function (_b) {
4842
4923
  switch (_b.label) {
4843
4924
  case 0:
@@ -4996,13 +5077,17 @@ var PerpetualsClient = (function () {
4996
5077
  }
4997
5078
  });
4998
5079
  }); };
4999
- this.withdrawStake = function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
5000
- if (pendingActivation === void 0) { pendingActivation = true; }
5001
- if (deactivated === void 0) { deactivated = true; }
5002
- if (createUserLPTA === void 0) { createUserLPTA = true; }
5003
- if (userPublicKey === void 0) { userPublicKey = undefined; }
5004
- return __awaiter(_this, void 0, void 0, function () {
5080
+ this.withdrawStake = function (poolConfig_1) {
5081
+ var args_1 = [];
5082
+ for (var _i = 1; _i < arguments.length; _i++) {
5083
+ args_1[_i - 1] = arguments[_i];
5084
+ }
5085
+ return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
5005
5086
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_21;
5087
+ if (pendingActivation === void 0) { pendingActivation = true; }
5088
+ if (deactivated === void 0) { deactivated = true; }
5089
+ if (createUserLPTA === void 0) { createUserLPTA = true; }
5090
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
5006
5091
  return __generator(this, function (_b) {
5007
5092
  switch (_b.label) {
5008
5093
  case 0:
@@ -5064,10 +5149,14 @@ var PerpetualsClient = (function () {
5064
5149
  });
5065
5150
  });
5066
5151
  };
5067
- this.collectStakeFees = function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
5068
- if (createUserATA === void 0) { createUserATA = true; }
5069
- return __awaiter(_this, void 0, void 0, function () {
5152
+ this.collectStakeFees = function (rewardSymbol_1, poolConfig_1, tokenStakeAccount_1) {
5153
+ var args_1 = [];
5154
+ for (var _i = 3; _i < arguments.length; _i++) {
5155
+ args_1[_i - 3] = arguments[_i];
5156
+ }
5157
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
5070
5158
  var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_22;
5159
+ if (createUserATA === void 0) { createUserATA = true; }
5071
5160
  return __generator(this, function (_b) {
5072
5161
  switch (_b.label) {
5073
5162
  case 0:
@@ -5791,10 +5880,14 @@ var PerpetualsClient = (function () {
5791
5880
  }
5792
5881
  });
5793
5882
  }); };
5794
- this.collectTokenReward = function (owner, poolConfig, createUserATA) {
5795
- if (createUserATA === void 0) { createUserATA = true; }
5796
- return __awaiter(_this, void 0, void 0, function () {
5883
+ this.collectTokenReward = function (owner_1, poolConfig_1) {
5884
+ var args_1 = [];
5885
+ for (var _i = 2; _i < arguments.length; _i++) {
5886
+ args_1[_i - 2] = arguments[_i];
5887
+ }
5888
+ return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
5797
5889
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_36;
5890
+ if (createUserATA === void 0) { createUserATA = true; }
5798
5891
  return __generator(this, function (_b) {
5799
5892
  switch (_b.label) {
5800
5893
  case 0:
@@ -5849,10 +5942,14 @@ var PerpetualsClient = (function () {
5849
5942
  });
5850
5943
  });
5851
5944
  };
5852
- this.collectRevenue = function (owner, rewardSymbol, poolConfig, createUserATA) {
5853
- if (createUserATA === void 0) { createUserATA = true; }
5854
- return __awaiter(_this, void 0, void 0, function () {
5945
+ this.collectRevenue = function (owner_1, rewardSymbol_1, poolConfig_1) {
5946
+ var args_1 = [];
5947
+ for (var _i = 3; _i < arguments.length; _i++) {
5948
+ args_1[_i - 3] = arguments[_i];
5949
+ }
5950
+ return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
5855
5951
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_37;
5952
+ if (createUserATA === void 0) { createUserATA = true; }
5856
5953
  return __generator(this, function (_b) {
5857
5954
  switch (_b.label) {
5858
5955
  case 0:
@@ -6037,10 +6134,14 @@ var PerpetualsClient = (function () {
6037
6134
  }
6038
6135
  });
6039
6136
  }); };
6040
- this.collectNftReward = function (rewardSymbol, poolConfig, nftMint, createUserATA) {
6041
- if (createUserATA === void 0) { createUserATA = true; }
6042
- return __awaiter(_this, void 0, void 0, function () {
6137
+ this.collectNftReward = function (rewardSymbol_1, poolConfig_1, nftMint_1) {
6138
+ var args_1 = [];
6139
+ for (var _i = 3; _i < arguments.length; _i++) {
6140
+ args_1[_i - 3] = arguments[_i];
6141
+ }
6142
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
6043
6143
  var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_41;
6144
+ if (createUserATA === void 0) { createUserATA = true; }
6044
6145
  return __generator(this, function (_b) {
6045
6146
  switch (_b.label) {
6046
6147
  case 0:
@@ -6100,10 +6201,14 @@ var PerpetualsClient = (function () {
6100
6201
  });
6101
6202
  });
6102
6203
  };
6103
- this.collectAndDistributeFee = function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
6104
- if (createUserATA === void 0) { createUserATA = true; }
6105
- return __awaiter(_this, void 0, void 0, function () {
6204
+ this.collectAndDistributeFee = function (rewardSymbol_1, poolConfig_1) {
6205
+ var args_1 = [];
6206
+ for (var _i = 2; _i < arguments.length; _i++) {
6207
+ args_1[_i - 2] = arguments[_i];
6208
+ }
6209
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
6106
6210
  var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_42;
6211
+ if (createUserATA === void 0) { createUserATA = true; }
6107
6212
  return __generator(this, function (_b) {
6108
6213
  switch (_b.label) {
6109
6214
  case 0:
@@ -6228,12 +6333,16 @@ var PerpetualsClient = (function () {
6228
6333
  }
6229
6334
  });
6230
6335
  }); };
6231
- this.forceClosePosition = function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
6232
- if (createUserATA === void 0) { createUserATA = true; }
6233
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
6234
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6235
- return __awaiter(_this, void 0, void 0, function () {
6336
+ this.forceClosePosition = function (positionAccount_2, targetSymbol_1, collateralSymbol_1, side_1, isStopLoss_1, poolConfig_1) {
6337
+ var args_1 = [];
6338
+ for (var _i = 6; _i < arguments.length; _i++) {
6339
+ args_1[_i - 6] = arguments[_i];
6340
+ }
6341
+ return __awaiter(_this, __spreadArray([positionAccount_2, 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) {
6236
6342
  var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_44;
6343
+ if (createUserATA === void 0) { createUserATA = true; }
6344
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
6345
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6237
6346
  return __generator(this, function (_b) {
6238
6347
  switch (_b.label) {
6239
6348
  case 0:
@@ -6305,11 +6414,15 @@ var PerpetualsClient = (function () {
6305
6414
  });
6306
6415
  });
6307
6416
  };
6308
- this.placeLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
6309
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
6310
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6311
- return __awaiter(_this, void 0, void 0, function () {
6417
+ 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) {
6418
+ var args_1 = [];
6419
+ for (var _i = 11; _i < arguments.length; _i++) {
6420
+ args_1[_i - 11] = arguments[_i];
6421
+ }
6422
+ 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) {
6312
6423
  var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_45;
6424
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
6425
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6313
6426
  return __generator(this, function (_c) {
6314
6427
  switch (_c.label) {
6315
6428
  case 0:
@@ -6425,11 +6538,15 @@ var PerpetualsClient = (function () {
6425
6538
  });
6426
6539
  });
6427
6540
  };
6428
- this.editLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
6429
- if (createUserATA === void 0) { createUserATA = true; }
6430
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6431
- return __awaiter(_this, void 0, void 0, function () {
6541
+ 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) {
6542
+ var args_1 = [];
6543
+ for (var _i = 11; _i < arguments.length; _i++) {
6544
+ args_1[_i - 11] = arguments[_i];
6545
+ }
6546
+ 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) {
6432
6547
  var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_46;
6548
+ if (createUserATA === void 0) { createUserATA = true; }
6549
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6433
6550
  return __generator(this, function (_b) {
6434
6551
  switch (_b.label) {
6435
6552
  case 0:
@@ -6528,12 +6645,16 @@ var PerpetualsClient = (function () {
6528
6645
  });
6529
6646
  });
6530
6647
  };
6531
- this.executeLimitOrder = function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6532
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6533
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6534
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6535
- return __awaiter(_this, void 0, void 0, function () {
6648
+ this.executeLimitOrder = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
6649
+ var args_1 = [];
6650
+ for (var _i = 7; _i < arguments.length; _i++) {
6651
+ args_1[_i - 7] = arguments[_i];
6652
+ }
6653
+ 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) {
6536
6654
  var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_47;
6655
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6656
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6657
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6537
6658
  return __generator(this, function (_a) {
6538
6659
  switch (_a.label) {
6539
6660
  case 0:
@@ -6593,12 +6714,16 @@ var PerpetualsClient = (function () {
6593
6714
  });
6594
6715
  });
6595
6716
  };
6596
- this.executeLimitWithSwap = function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6597
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6598
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6599
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6600
- return __awaiter(_this, void 0, void 0, function () {
6717
+ this.executeLimitWithSwap = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
6718
+ var args_1 = [];
6719
+ for (var _i = 8; _i < arguments.length; _i++) {
6720
+ args_1[_i - 8] = arguments[_i];
6721
+ }
6722
+ 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) {
6601
6723
  var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_48;
6724
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6725
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6726
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6602
6727
  return __generator(this, function (_a) {
6603
6728
  switch (_a.label) {
6604
6729
  case 0:
@@ -6864,16 +6989,20 @@ var PerpetualsClient = (function () {
6864
6989
  }
6865
6990
  });
6866
6991
  }); };
6867
- this.executeTriggerWithSwap = function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6868
- if (createUserATA === void 0) { createUserATA = true; }
6869
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6870
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6871
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6872
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6873
- return __awaiter(_this, void 0, void 0, function () {
6874
- var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, executeTriggerWithSwap, err_53;
6875
- return __generator(this, function (_d) {
6876
- switch (_d.label) {
6992
+ this.executeTriggerWithSwap = function (owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
6993
+ var args_1 = [];
6994
+ for (var _i = 9; _i < arguments.length; _i++) {
6995
+ args_1[_i - 9] = arguments[_i];
6996
+ }
6997
+ 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) {
6998
+ var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap, err_53;
6999
+ if (createUserATA === void 0) { createUserATA = true; }
7000
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7001
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
7002
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
7003
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
7004
+ return __generator(this, function (_e) {
7005
+ switch (_e.label) {
6877
7006
  case 0:
6878
7007
  payerPubkey = this.provider.wallet.publicKey;
6879
7008
  targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
@@ -6884,9 +7013,9 @@ var PerpetualsClient = (function () {
6884
7013
  instructions = [];
6885
7014
  postInstructions = [];
6886
7015
  additionalSigners = [];
6887
- _d.label = 1;
7016
+ _e.label = 1;
6888
7017
  case 1:
6889
- _d.trys.push([1, 9, , 10]);
7018
+ _e.trys.push([1, 9, , 10]);
6890
7019
  if (!false) return [3, 2];
6891
7020
  return [3, 7];
6892
7021
  case 2:
@@ -6895,8 +7024,8 @@ var PerpetualsClient = (function () {
6895
7024
  if (!_a) return [3, 4];
6896
7025
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
6897
7026
  case 3:
6898
- _a = !(_d.sent());
6899
- _d.label = 4;
7027
+ _a = !(_e.sent());
7028
+ _e.label = 4;
6900
7029
  case 4:
6901
7030
  if (_a) {
6902
7031
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
@@ -6906,20 +7035,20 @@ var PerpetualsClient = (function () {
6906
7035
  if (!_b) return [3, 6];
6907
7036
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
6908
7037
  case 5:
6909
- _b = !(_d.sent());
6910
- _d.label = 6;
7038
+ _b = !(_e.sent());
7039
+ _e.label = 6;
6911
7040
  case 6:
6912
7041
  if (_b) {
6913
7042
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
6914
7043
  }
6915
- _d.label = 7;
7044
+ _e.label = 7;
6916
7045
  case 7:
6917
7046
  positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
6918
7047
  orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
6919
7048
  custodyAccountMetas = [];
6920
7049
  custodyOracleAccountMetas = [];
6921
- for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
6922
- custody = _c[_i];
7050
+ for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
7051
+ custody = _d[_c];
6923
7052
  custodyAccountMetas.push({
6924
7053
  pubkey: custody.custodyAccount,
6925
7054
  isSigner: false,
@@ -6964,11 +7093,11 @@ var PerpetualsClient = (function () {
6964
7093
  .remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
6965
7094
  .instruction()];
6966
7095
  case 8:
6967
- executeTriggerWithSwap = _d.sent();
7096
+ executeTriggerWithSwap = _e.sent();
6968
7097
  instructions.push(executeTriggerWithSwap);
6969
7098
  return [3, 10];
6970
7099
  case 9:
6971
- err_53 = _d.sent();
7100
+ err_53 = _e.sent();
6972
7101
  console.log("perpClient executeTriggerWithSwap error:: ", err_53);
6973
7102
  throw err_53;
6974
7103
  case 10: return [2, {
@@ -6979,14 +7108,18 @@ var PerpetualsClient = (function () {
6979
7108
  });
6980
7109
  });
6981
7110
  };
6982
- this.executeTriggerOrder = function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6983
- if (createUserATA === void 0) { createUserATA = true; }
6984
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6985
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6986
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6987
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6988
- return __awaiter(_this, void 0, void 0, function () {
7111
+ this.executeTriggerOrder = function (owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
7112
+ var args_1 = [];
7113
+ for (var _i = 8; _i < arguments.length; _i++) {
7114
+ args_1[_i - 8] = arguments[_i];
7115
+ }
7116
+ 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) {
6989
7117
  var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_54;
7118
+ if (createUserATA === void 0) { createUserATA = true; }
7119
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7120
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
7121
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
7122
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6990
7123
  return __generator(this, function (_b) {
6991
7124
  switch (_b.label) {
6992
7125
  case 0:
@@ -7409,14 +7542,18 @@ var PerpetualsClient = (function () {
7409
7542
  }
7410
7543
  });
7411
7544
  }); };
7412
- this.addCompoundingLiquidity = function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
7413
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
7414
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7415
- if (userPublicKey === void 0) { userPublicKey = undefined; }
7416
- return __awaiter(_this, void 0, void 0, function () {
7417
- 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_63;
7418
- return __generator(this, function (_e) {
7419
- switch (_e.label) {
7545
+ this.addCompoundingLiquidity = function (amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
7546
+ var args_1 = [];
7547
+ for (var _i = 5; _i < arguments.length; _i++) {
7548
+ args_1[_i - 5] = arguments[_i];
7549
+ }
7550
+ 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) {
7551
+ 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_63;
7552
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
7553
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7554
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
7555
+ return __generator(this, function (_f) {
7556
+ switch (_f.label) {
7420
7557
  case 0:
7421
7558
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
7422
7559
  preInstructions = [];
@@ -7433,8 +7570,8 @@ var PerpetualsClient = (function () {
7433
7570
  custodyAccountMetas = [];
7434
7571
  custodyOracleAccountMetas = [];
7435
7572
  markets = [];
7436
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
7437
- custody = _a[_i];
7573
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
7574
+ custody = _b[_a];
7438
7575
  custodyAccountMetas.push({
7439
7576
  pubkey: custody.custodyAccount,
7440
7577
  isSigner: false,
@@ -7446,8 +7583,8 @@ var PerpetualsClient = (function () {
7446
7583
  isWritable: false,
7447
7584
  });
7448
7585
  }
7449
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
7450
- market = _c[_b];
7586
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
7587
+ market = _d[_c];
7451
7588
  markets.push({
7452
7589
  pubkey: market.marketAccount,
7453
7590
  isSigner: false,
@@ -7456,26 +7593,26 @@ var PerpetualsClient = (function () {
7456
7593
  }
7457
7594
  return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
7458
7595
  case 1:
7459
- if (!(_e.sent())) {
7596
+ if (!(_f.sent())) {
7460
7597
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
7461
7598
  }
7462
7599
  return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
7463
7600
  case 2:
7464
- if (!(_e.sent())) {
7601
+ if (!(_f.sent())) {
7465
7602
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
7466
7603
  }
7467
7604
  if (!(inTokenSymbol == 'SOL')) return [3, 5];
7468
7605
  console.log("inTokenSymbol === SOL", inTokenSymbol);
7469
7606
  lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
7470
7607
  if (!!skipBalanceChecks) return [3, 4];
7471
- _d = anchor_1.BN.bind;
7608
+ _e = anchor_1.BN.bind;
7472
7609
  return [4, this.provider.connection.getBalance(publicKey)];
7473
7610
  case 3:
7474
- unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _e.sent()]))();
7611
+ unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _f.sent()]))();
7475
7612
  if (unWrappedSolBalance.lt(lamports)) {
7476
7613
  throw "Insufficient SOL Funds";
7477
7614
  }
7478
- _e.label = 4;
7615
+ _f.label = 4;
7479
7616
  case 4:
7480
7617
  if (!ephemeralSignerPubkey) {
7481
7618
  wrappedSolAccount = new web3_js_1.Keypair();
@@ -7499,12 +7636,12 @@ var PerpetualsClient = (function () {
7499
7636
  if (!!skipBalanceChecks) return [3, 7];
7500
7637
  return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
7501
7638
  case 6:
7502
- if (!(_e.sent())) {
7639
+ if (!(_f.sent())) {
7503
7640
  throw "Insufficient Funds , token Account doesn't exist";
7504
7641
  }
7505
- _e.label = 7;
7642
+ _f.label = 7;
7506
7643
  case 7:
7507
- _e.trys.push([7, 9, , 10]);
7644
+ _f.trys.push([7, 9, , 10]);
7508
7645
  return [4, this.program.methods
7509
7646
  .addCompoundingLiquidity({
7510
7647
  amountIn: amountIn,
@@ -7533,11 +7670,11 @@ var PerpetualsClient = (function () {
7533
7670
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
7534
7671
  .instruction()];
7535
7672
  case 8:
7536
- addCompoundingLiquidity = _e.sent();
7673
+ addCompoundingLiquidity = _f.sent();
7537
7674
  instructions.push(addCompoundingLiquidity);
7538
7675
  return [3, 10];
7539
7676
  case 9:
7540
- err_63 = _e.sent();
7677
+ err_63 = _f.sent();
7541
7678
  console.log("perpClient addCompoundingLiquidity error:: ", err_63);
7542
7679
  return [3, 10];
7543
7680
  case 10: return [2, {
@@ -7548,14 +7685,18 @@ var PerpetualsClient = (function () {
7548
7685
  });
7549
7686
  });
7550
7687
  };
7551
- this.removeCompoundingLiquidity = function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey, userPublicKey) {
7552
- if (createUserATA === void 0) { createUserATA = true; }
7553
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7554
- if (userPublicKey === void 0) { userPublicKey = undefined; }
7555
- return __awaiter(_this, void 0, void 0, function () {
7556
- 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_64;
7557
- return __generator(this, function (_e) {
7558
- switch (_e.label) {
7688
+ this.removeCompoundingLiquidity = function (compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
7689
+ var args_1 = [];
7690
+ for (var _i = 5; _i < arguments.length; _i++) {
7691
+ args_1[_i - 5] = arguments[_i];
7692
+ }
7693
+ 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) {
7694
+ 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_64;
7695
+ if (createUserATA === void 0) { createUserATA = true; }
7696
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7697
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
7698
+ return __generator(this, function (_f) {
7699
+ switch (_f.label) {
7559
7700
  case 0:
7560
7701
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
7561
7702
  preInstructions = [];
@@ -7592,19 +7733,19 @@ var PerpetualsClient = (function () {
7592
7733
  if (!_a) return [3, 3];
7593
7734
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
7594
7735
  case 2:
7595
- _a = !(_e.sent());
7596
- _e.label = 3;
7736
+ _a = !(_f.sent());
7737
+ _f.label = 3;
7597
7738
  case 3:
7598
7739
  if (_a) {
7599
7740
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
7600
7741
  }
7601
- _e.label = 4;
7742
+ _f.label = 4;
7602
7743
  case 4:
7603
7744
  custodyAccountMetas = [];
7604
7745
  custodyOracleAccountMetas = [];
7605
7746
  markets = [];
7606
- for (_i = 0, _b = poolConfig.custodies; _i < _b.length; _i++) {
7607
- custody = _b[_i];
7747
+ for (_b = 0, _c = poolConfig.custodies; _b < _c.length; _b++) {
7748
+ custody = _c[_b];
7608
7749
  custodyAccountMetas.push({
7609
7750
  pubkey: custody.custodyAccount,
7610
7751
  isSigner: false,
@@ -7616,8 +7757,8 @@ var PerpetualsClient = (function () {
7616
7757
  isWritable: false,
7617
7758
  });
7618
7759
  }
7619
- for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
7620
- market = _d[_c];
7760
+ for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
7761
+ market = _e[_d];
7621
7762
  markets.push({
7622
7763
  pubkey: market.marketAccount,
7623
7764
  isSigner: false,
@@ -7625,9 +7766,9 @@ var PerpetualsClient = (function () {
7625
7766
  });
7626
7767
  }
7627
7768
  compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
7628
- _e.label = 5;
7769
+ _f.label = 5;
7629
7770
  case 5:
7630
- _e.trys.push([5, 7, , 8]);
7771
+ _f.trys.push([5, 7, , 8]);
7631
7772
  return [4, this.program.methods
7632
7773
  .removeCompoundingLiquidity({
7633
7774
  compoundingAmountIn: compoundingAmountIn,
@@ -7656,11 +7797,11 @@ var PerpetualsClient = (function () {
7656
7797
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
7657
7798
  .instruction()];
7658
7799
  case 6:
7659
- removeCompoundingLiquidity = _e.sent();
7800
+ removeCompoundingLiquidity = _f.sent();
7660
7801
  instructions.push(removeCompoundingLiquidity);
7661
7802
  return [3, 8];
7662
7803
  case 7:
7663
- err_64 = _e.sent();
7804
+ err_64 = _f.sent();
7664
7805
  console.log("perpClient removeCompoundingLiquidity error:: ", err_64);
7665
7806
  return [3, 8];
7666
7807
  case 8: return [2, {
@@ -7671,12 +7812,16 @@ var PerpetualsClient = (function () {
7671
7812
  });
7672
7813
  });
7673
7814
  };
7674
- this.migrateStake = function (amount, rewardTokenMint, poolConfig, createUserATA) {
7675
- if (createUserATA === void 0) { createUserATA = true; }
7676
- return __awaiter(_this, void 0, void 0, function () {
7677
- 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_65;
7678
- return __generator(this, function (_f) {
7679
- switch (_f.label) {
7815
+ this.migrateStake = function (amount_1, rewardTokenMint_1, poolConfig_1) {
7816
+ var args_1 = [];
7817
+ for (var _i = 3; _i < arguments.length; _i++) {
7818
+ args_1[_i - 3] = arguments[_i];
7819
+ }
7820
+ return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
7821
+ 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_65;
7822
+ if (createUserATA === void 0) { createUserATA = true; }
7823
+ return __generator(this, function (_g) {
7824
+ switch (_g.label) {
7680
7825
  case 0:
7681
7826
  publicKey = this.provider.wallet.publicKey;
7682
7827
  preInstructions = [];
@@ -7691,8 +7836,8 @@ var PerpetualsClient = (function () {
7691
7836
  if (!_a) return [3, 2];
7692
7837
  return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
7693
7838
  case 1:
7694
- _a = !(_f.sent());
7695
- _f.label = 2;
7839
+ _a = !(_g.sent());
7840
+ _g.label = 2;
7696
7841
  case 2:
7697
7842
  if (_a) {
7698
7843
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
@@ -7704,8 +7849,8 @@ var PerpetualsClient = (function () {
7704
7849
  if (!_b) return [3, 4];
7705
7850
  return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
7706
7851
  case 3:
7707
- _b = (_f.sent());
7708
- _f.label = 4;
7852
+ _b = (_g.sent());
7853
+ _g.label = 4;
7709
7854
  case 4:
7710
7855
  if (_b) {
7711
7856
  tokenStakeAccounts.push({
@@ -7718,8 +7863,8 @@ var PerpetualsClient = (function () {
7718
7863
  custodyAccountMetas = [];
7719
7864
  custodyOracleAccountMetas = [];
7720
7865
  markets = [];
7721
- for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
7722
- custody = _c[_i];
7866
+ for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
7867
+ custody = _d[_c];
7723
7868
  custodyAccountMetas.push({
7724
7869
  pubkey: custody.custodyAccount,
7725
7870
  isSigner: false,
@@ -7731,17 +7876,17 @@ var PerpetualsClient = (function () {
7731
7876
  isWritable: false,
7732
7877
  });
7733
7878
  }
7734
- for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
7735
- market = _e[_d];
7879
+ for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
7880
+ market = _f[_e];
7736
7881
  markets.push({
7737
7882
  pubkey: market.marketAccount,
7738
7883
  isSigner: false,
7739
7884
  isWritable: false,
7740
7885
  });
7741
7886
  }
7742
- _f.label = 5;
7887
+ _g.label = 5;
7743
7888
  case 5:
7744
- _f.trys.push([5, 7, , 8]);
7889
+ _g.trys.push([5, 7, , 8]);
7745
7890
  return [4, this.program.methods
7746
7891
  .migrateStake({
7747
7892
  amount: amount
@@ -7767,11 +7912,11 @@ var PerpetualsClient = (function () {
7767
7912
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
7768
7913
  .instruction()];
7769
7914
  case 6:
7770
- migrateStake = _f.sent();
7915
+ migrateStake = _g.sent();
7771
7916
  instructions.push(migrateStake);
7772
7917
  return [3, 8];
7773
7918
  case 7:
7774
- err_65 = _f.sent();
7919
+ err_65 = _g.sent();
7775
7920
  console.log("perpClient migrateStake error:: ", err_65);
7776
7921
  return [3, 8];
7777
7922
  case 8: return [2, {
@@ -7865,12 +8010,16 @@ var PerpetualsClient = (function () {
7865
8010
  }
7866
8011
  });
7867
8012
  }); };
7868
- this.compoundingFee = function (poolConfig, rewardTokenSymbol) {
7869
- if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
7870
- return __awaiter(_this, void 0, void 0, function () {
7871
- var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, compoundingFee, err_67;
7872
- return __generator(this, function (_d) {
7873
- switch (_d.label) {
8013
+ this.compoundingFee = function (poolConfig_1) {
8014
+ var args_1 = [];
8015
+ for (var _i = 1; _i < arguments.length; _i++) {
8016
+ args_1[_i - 1] = arguments[_i];
8017
+ }
8018
+ return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
8019
+ var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_67;
8020
+ if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
8021
+ return __generator(this, function (_e) {
8022
+ switch (_e.label) {
7874
8023
  case 0:
7875
8024
  instructions = [];
7876
8025
  additionalSigners = [];
@@ -7879,8 +8028,8 @@ var PerpetualsClient = (function () {
7879
8028
  custodyAccountMetas = [];
7880
8029
  custodyOracleAccountMetas = [];
7881
8030
  markets = [];
7882
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
7883
- custody = _a[_i];
8031
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
8032
+ custody = _b[_a];
7884
8033
  custodyAccountMetas.push({
7885
8034
  pubkey: custody.custodyAccount,
7886
8035
  isSigner: false,
@@ -7892,17 +8041,17 @@ var PerpetualsClient = (function () {
7892
8041
  isWritable: false,
7893
8042
  });
7894
8043
  }
7895
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
7896
- market = _c[_b];
8044
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
8045
+ market = _d[_c];
7897
8046
  markets.push({
7898
8047
  pubkey: market.marketAccount,
7899
8048
  isSigner: false,
7900
8049
  isWritable: false,
7901
8050
  });
7902
8051
  }
7903
- _d.label = 1;
8052
+ _e.label = 1;
7904
8053
  case 1:
7905
- _d.trys.push([1, 3, , 4]);
8054
+ _e.trys.push([1, 3, , 4]);
7906
8055
  return [4, this.program.methods
7907
8056
  .compoundFees({})
7908
8057
  .accounts({
@@ -7921,11 +8070,11 @@ var PerpetualsClient = (function () {
7921
8070
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
7922
8071
  .instruction()];
7923
8072
  case 2:
7924
- compoundingFee = _d.sent();
8073
+ compoundingFee = _e.sent();
7925
8074
  instructions.push(compoundingFee);
7926
8075
  return [3, 4];
7927
8076
  case 3:
7928
- err_67 = _d.sent();
8077
+ err_67 = _e.sent();
7929
8078
  console.log("perpClient compoundingFee error:: ", err_67);
7930
8079
  return [3, 4];
7931
8080
  case 4: return [2, {
@@ -8086,9 +8235,9 @@ var PerpetualsClient = (function () {
8086
8235
  }
8087
8236
  }
8088
8237
  };
8089
- PerpetualsClient.prototype.sendTransaction = function (ixs, opts) {
8090
- if (opts === void 0) { opts = {}; }
8091
- return __awaiter(this, void 0, void 0, function () {
8238
+ PerpetualsClient.prototype.sendTransaction = function (ixs_1) {
8239
+ return __awaiter(this, arguments, void 0, function (ixs, opts) {
8240
+ if (opts === void 0) { opts = {}; }
8092
8241
  return __generator(this, function (_a) {
8093
8242
  switch (_a.label) {
8094
8243
  case 0: return [4, (0, rpc_1.sendTransaction)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
@@ -8097,9 +8246,9 @@ var PerpetualsClient = (function () {
8097
8246
  });
8098
8247
  });
8099
8248
  };
8100
- PerpetualsClient.prototype.sendTransactionV3 = function (ixs, opts) {
8101
- if (opts === void 0) { opts = {}; }
8102
- return __awaiter(this, void 0, void 0, function () {
8249
+ PerpetualsClient.prototype.sendTransactionV3 = function (ixs_1) {
8250
+ return __awaiter(this, arguments, void 0, function (ixs, opts) {
8251
+ if (opts === void 0) { opts = {}; }
8103
8252
  return __generator(this, function (_a) {
8104
8253
  switch (_a.label) {
8105
8254
  case 0: return [4, (0, rpc_1.sendTransactionV3)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];