flash-sdk 2.51.3 → 2.51.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, {
@@ -2671,14 +2687,18 @@ var PerpetualsClient = (function () {
2671
2687
  }
2672
2688
  });
2673
2689
  }); };
2674
- this.openPosition = function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
2675
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2676
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2677
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2678
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2679
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2680
- 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) {
2681
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; }
2682
2702
  return __generator(this, function (_c) {
2683
2703
  switch (_c.label) {
2684
2704
  case 0:
@@ -2782,15 +2802,19 @@ var PerpetualsClient = (function () {
2782
2802
  });
2783
2803
  });
2784
2804
  };
2785
- this.closePosition = function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
2786
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2787
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2788
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2789
- if (createUserATA === void 0) { createUserATA = true; }
2790
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
2791
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2792
- 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) {
2793
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; }
2794
2818
  return __generator(this, function (_b) {
2795
2819
  switch (_b.label) {
2796
2820
  case 0:
@@ -2887,14 +2911,18 @@ var PerpetualsClient = (function () {
2887
2911
  });
2888
2912
  });
2889
2913
  };
2890
- this.swapAndOpen = function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, minCollateralAmountOut, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
2891
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2892
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2893
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2894
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2895
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2896
- 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) {
2897
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; }
2898
2926
  return __generator(this, function (_c) {
2899
2927
  switch (_c.label) {
2900
2928
  case 0:
@@ -3034,13 +3062,17 @@ var PerpetualsClient = (function () {
3034
3062
  });
3035
3063
  });
3036
3064
  };
3037
- this.closeAndSwap = function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, minSwapAmountOut, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, ephemeralSignerPubkey) {
3038
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3039
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3040
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3041
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3042
- 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) {
3043
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; }
3044
3076
  return __generator(this, function (_a) {
3045
3077
  switch (_a.label) {
3046
3078
  case 0:
@@ -3154,16 +3186,20 @@ var PerpetualsClient = (function () {
3154
3186
  });
3155
3187
  });
3156
3188
  };
3157
- this.swap = function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey) {
3158
- if (useFeesPool === void 0) { useFeesPool = false; }
3159
- if (createUserATA === void 0) { createUserATA = true; }
3160
- if (unWrapSol === void 0) { unWrapSol = false; }
3161
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3162
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3163
- return __awaiter(_this, void 0, void 0, function () {
3164
- 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;
3165
- return __generator(this, function (_f) {
3166
- 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) {
3167
3203
  case 0:
3168
3204
  userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
3169
3205
  if (!userInputCustodyConfig) {
@@ -3181,10 +3217,10 @@ var PerpetualsClient = (function () {
3181
3217
  if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
3182
3218
  return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
3183
3219
  case 1:
3184
- wsolAssociatedTokenAccount = _f.sent();
3220
+ wsolAssociatedTokenAccount = _g.sent();
3185
3221
  return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
3186
3222
  case 2:
3187
- wsolATAExist = _f.sent();
3223
+ wsolATAExist = _g.sent();
3188
3224
  if (!wsolATAExist) {
3189
3225
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
3190
3226
  }
@@ -3192,11 +3228,11 @@ var PerpetualsClient = (function () {
3192
3228
  _a = anchor_1.BN.bind;
3193
3229
  return [4, this.provider.connection.getBalance(publicKey)];
3194
3230
  case 3:
3195
- unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
3231
+ unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
3196
3232
  if (unWrappedSolBalance.lt(amountIn)) {
3197
3233
  throw "Insufficient SOL Funds";
3198
3234
  }
3199
- _f.label = 4;
3235
+ _g.label = 4;
3200
3236
  case 4:
3201
3237
  instructions.push(web3_js_1.SystemProgram.transfer({
3202
3238
  fromPubkey: publicKey,
@@ -3218,20 +3254,20 @@ var PerpetualsClient = (function () {
3218
3254
  additionalSigners: additionalSigners
3219
3255
  }];
3220
3256
  }
3221
- _f.label = 6;
3257
+ _g.label = 6;
3222
3258
  case 6:
3223
- _f.trys.push([6, 19, , 20]);
3259
+ _g.trys.push([6, 19, , 20]);
3224
3260
  if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
3225
3261
  console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
3226
3262
  return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
3227
3263
  case 7:
3228
- accCreationLamports = (_f.sent());
3264
+ accCreationLamports = (_g.sent());
3229
3265
  console.log("accCreationLamports:", accCreationLamports);
3230
3266
  lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
3231
3267
  _b = anchor_1.BN.bind;
3232
3268
  return [4, this.provider.connection.getBalance(publicKey)];
3233
3269
  case 8:
3234
- unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _f.sent()]))();
3270
+ unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _g.sent()]))();
3235
3271
  if (unWrappedSolBalance.lt(amountIn)) {
3236
3272
  throw "Insufficient SOL Funds";
3237
3273
  }
@@ -3258,18 +3294,18 @@ var PerpetualsClient = (function () {
3258
3294
  userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
3259
3295
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
3260
3296
  case 10:
3261
- if (!(_f.sent())) {
3297
+ if (!(_g.sent())) {
3262
3298
  throw "Insufficient Funds , Token Account doesn't exist";
3263
3299
  }
3264
3300
  if (!!skipBalanceChecks) return [3, 12];
3265
3301
  _c = anchor_1.BN.bind;
3266
3302
  return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
3267
3303
  case 11:
3268
- 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]))();
3269
3305
  if (tokenAccountBalance.lt(amountIn)) {
3270
3306
  throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
3271
3307
  }
3272
- _f.label = 12;
3308
+ _g.label = 12;
3273
3309
  case 12:
3274
3310
  if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
3275
3311
  lamports = (this.minimumBalanceForRentExemptAccountLamports);
@@ -3294,23 +3330,23 @@ var PerpetualsClient = (function () {
3294
3330
  return [3, 17];
3295
3331
  case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
3296
3332
  case 14:
3297
- userOutputTokenAccount = _f.sent();
3333
+ userOutputTokenAccount = _g.sent();
3298
3334
  _d = createUserATA;
3299
3335
  if (!_d) return [3, 16];
3300
3336
  return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
3301
3337
  case 15:
3302
- _d = !(_f.sent());
3303
- _f.label = 16;
3338
+ _d = !(_g.sent());
3339
+ _g.label = 16;
3304
3340
  case 16:
3305
3341
  if (_d) {
3306
3342
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
3307
3343
  }
3308
- _f.label = 17;
3344
+ _g.label = 17;
3309
3345
  case 17:
3310
3346
  custodyAccountMetas = [];
3311
3347
  custodyOracleAccountMetas = [];
3312
- for (_i = 0, _e = poolConfig.custodies; _i < _e.length; _i++) {
3313
- custody = _e[_i];
3348
+ for (_e = 0, _f = poolConfig.custodies; _e < _f.length; _e++) {
3349
+ custody = _f[_e];
3314
3350
  custodyAccountMetas.push({
3315
3351
  pubkey: custody.custodyAccount,
3316
3352
  isSigner: false,
@@ -3350,7 +3386,7 @@ var PerpetualsClient = (function () {
3350
3386
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
3351
3387
  .instruction()];
3352
3388
  case 18:
3353
- inx = _f.sent();
3389
+ inx = _g.sent();
3354
3390
  instructions.push(inx);
3355
3391
  if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
3356
3392
  closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
@@ -3358,7 +3394,7 @@ var PerpetualsClient = (function () {
3358
3394
  }
3359
3395
  return [3, 20];
3360
3396
  case 19:
3361
- err_5 = _f.sent();
3397
+ err_5 = _g.sent();
3362
3398
  console.error("perpClient Swap error:: ", err_5);
3363
3399
  throw err_5;
3364
3400
  case 20: return [2, {
@@ -3440,11 +3476,15 @@ var PerpetualsClient = (function () {
3440
3476
  }
3441
3477
  });
3442
3478
  }); };
3443
- this.addCollateral = function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
3444
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3445
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3446
- 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) {
3447
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; }
3448
3488
  return __generator(this, function (_c) {
3449
3489
  switch (_c.label) {
3450
3490
  case 0:
@@ -3538,11 +3578,15 @@ var PerpetualsClient = (function () {
3538
3578
  });
3539
3579
  });
3540
3580
  };
3541
- this.swapAndAddCollateral = function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minCollateralAmountOut, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
3542
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3543
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3544
- 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) {
3545
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; }
3546
3590
  return __generator(this, function (_c) {
3547
3591
  switch (_c.label) {
3548
3592
  case 0:
@@ -3653,12 +3697,16 @@ var PerpetualsClient = (function () {
3653
3697
  });
3654
3698
  });
3655
3699
  };
3656
- this.removeCollateral = function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
3657
- if (createUserATA === void 0) { createUserATA = true; }
3658
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
3659
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3660
- 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) {
3661
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; }
3662
3710
  return __generator(this, function (_b) {
3663
3711
  switch (_b.label) {
3664
3712
  case 0:
@@ -3759,10 +3807,14 @@ var PerpetualsClient = (function () {
3759
3807
  });
3760
3808
  });
3761
3809
  };
3762
- this.removeCollateralAndSwap = function (targetSymbol, collateralSymbol, outputSymbol, minSwapAmountOut, collateralDelta, side, poolConfig, ephemeralSignerPubkey) {
3763
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3764
- 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) {
3765
3816
  var publicKey, targetCustodyConfig, collateralCustodyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, instruction;
3817
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3766
3818
  return __generator(this, function (_a) {
3767
3819
  switch (_a.label) {
3768
3820
  case 0:
@@ -3855,12 +3907,16 @@ var PerpetualsClient = (function () {
3855
3907
  });
3856
3908
  });
3857
3909
  };
3858
- this.increaseSize = function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
3859
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3860
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3861
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3862
- 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) {
3863
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; }
3864
3920
  return __generator(this, function (_a) {
3865
3921
  switch (_a.label) {
3866
3922
  case 0:
@@ -3915,12 +3971,16 @@ var PerpetualsClient = (function () {
3915
3971
  });
3916
3972
  });
3917
3973
  };
3918
- this.decreaseSize = function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
3919
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3920
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3921
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3922
- 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) {
3923
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; }
3924
3984
  return __generator(this, function (_a) {
3925
3985
  switch (_a.label) {
3926
3986
  case 0:
@@ -3975,13 +4035,17 @@ var PerpetualsClient = (function () {
3975
4035
  });
3976
4036
  });
3977
4037
  };
3978
- this.addLiquidity = function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
3979
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3980
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3981
- return __awaiter(_this, void 0, void 0, function () {
3982
- 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;
3983
- return __generator(this, function (_f) {
3984
- 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) {
3985
4049
  case 0:
3986
4050
  publicKey = this.provider.wallet.publicKey;
3987
4051
  payTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey); });
@@ -3992,16 +4056,16 @@ var PerpetualsClient = (function () {
3992
4056
  instructions = [];
3993
4057
  postInstructions = [];
3994
4058
  additionalSigners = [];
3995
- _f.label = 1;
4059
+ _g.label = 1;
3996
4060
  case 1:
3997
- _f.trys.push([1, 10, , 11]);
4061
+ _g.trys.push([1, 10, , 11]);
3998
4062
  userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true);
3999
4063
  lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
4000
4064
  custodyAccountMetas = [];
4001
4065
  custodyOracleAccountMetas = [];
4002
4066
  markets = [];
4003
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
4004
- custody = _a[_i];
4067
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
4068
+ custody = _b[_a];
4005
4069
  custodyAccountMetas.push({
4006
4070
  pubkey: custody.custodyAccount,
4007
4071
  isSigner: false,
@@ -4013,8 +4077,8 @@ var PerpetualsClient = (function () {
4013
4077
  isWritable: false,
4014
4078
  });
4015
4079
  }
4016
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
4017
- market = _c[_b];
4080
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
4081
+ market = _d[_c];
4018
4082
  markets.push({
4019
4083
  pubkey: market.marketAccount,
4020
4084
  isSigner: false,
@@ -4023,21 +4087,21 @@ var PerpetualsClient = (function () {
4023
4087
  }
4024
4088
  return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
4025
4089
  case 2:
4026
- if (!(_f.sent())) {
4090
+ if (!(_g.sent())) {
4027
4091
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
4028
4092
  }
4029
4093
  if (!(payTokenSymbol == 'SOL')) return [3, 5];
4030
4094
  console.log("payTokenSymbol === SOL", payTokenSymbol);
4031
4095
  lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
4032
4096
  if (!!skipBalanceChecks) return [3, 4];
4033
- _d = anchor_1.BN.bind;
4097
+ _e = anchor_1.BN.bind;
4034
4098
  return [4, this.provider.connection.getBalance(publicKey)];
4035
4099
  case 3:
4036
- unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _f.sent()]))();
4100
+ unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _g.sent()]))();
4037
4101
  if (unWrappedSolBalance.lt(lamports)) {
4038
4102
  throw "Insufficient SOL Funds";
4039
4103
  }
4040
- _f.label = 4;
4104
+ _g.label = 4;
4041
4105
  case 4:
4042
4106
  if (!ephemeralSignerPubkey) {
4043
4107
  wrappedSolAccount = new web3_js_1.Keypair();
@@ -4061,17 +4125,17 @@ var PerpetualsClient = (function () {
4061
4125
  if (!!skipBalanceChecks) return [3, 8];
4062
4126
  return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
4063
4127
  case 6:
4064
- if (!(_f.sent())) {
4128
+ if (!(_g.sent())) {
4065
4129
  throw "Insufficient Funds , token Account doesn't exist";
4066
4130
  }
4067
- _e = anchor_1.BN.bind;
4131
+ _f = anchor_1.BN.bind;
4068
4132
  return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
4069
4133
  case 7:
4070
- 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]))();
4071
4135
  if (tokenAccountBalance.lt(tokenAmountIn)) {
4072
4136
  throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
4073
4137
  }
4074
- _f.label = 8;
4138
+ _g.label = 8;
4075
4139
  case 8: return [4, this.program.methods
4076
4140
  .addLiquidity({
4077
4141
  amountIn: tokenAmountIn,
@@ -4096,11 +4160,11 @@ var PerpetualsClient = (function () {
4096
4160
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4097
4161
  .instruction()];
4098
4162
  case 9:
4099
- instruction = _f.sent();
4163
+ instruction = _g.sent();
4100
4164
  instructions.push(instruction);
4101
4165
  return [3, 11];
4102
4166
  case 10:
4103
- err_7 = _f.sent();
4167
+ err_7 = _g.sent();
4104
4168
  console.error("perpClient addLiquidity error:: ", err_7);
4105
4169
  throw err_7;
4106
4170
  case 11: return [2, {
@@ -4111,14 +4175,18 @@ var PerpetualsClient = (function () {
4111
4175
  });
4112
4176
  });
4113
4177
  };
4114
- this.addLiquidityAndStake = function (inputSymbol, amountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
4115
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4116
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4117
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4118
- return __awaiter(_this, void 0, void 0, function () {
4119
- 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;
4120
- return __generator(this, function (_f) {
4121
- 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) {
4122
4190
  case 0:
4123
4191
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
4124
4192
  preInstructions = [];
@@ -4138,14 +4206,14 @@ var PerpetualsClient = (function () {
4138
4206
  _a = anchor_1.BN.bind;
4139
4207
  return [4, this.provider.connection.getBalance(publicKey)];
4140
4208
  case 1:
4141
- unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
4209
+ unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
4142
4210
  if (unWrappedSolBalance.lt(lamports)) {
4143
4211
  throw "Insufficient SOL Funds";
4144
4212
  }
4145
- _f.label = 2;
4213
+ _g.label = 2;
4146
4214
  case 2: return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
4147
4215
  case 3:
4148
- if (!(_f.sent())) {
4216
+ if (!(_g.sent())) {
4149
4217
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
4150
4218
  }
4151
4219
  if (!ephemeralSignerPubkey) {
@@ -4171,23 +4239,23 @@ var PerpetualsClient = (function () {
4171
4239
  if (!!skipBalanceChecks) return [3, 7];
4172
4240
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
4173
4241
  case 5:
4174
- if (!(_f.sent())) {
4242
+ if (!(_g.sent())) {
4175
4243
  throw "Insufficient Funds , token Account doesn't exist";
4176
4244
  }
4177
4245
  _b = anchor_1.BN.bind;
4178
4246
  return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
4179
4247
  case 6:
4180
- 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]))();
4181
4249
  if (tokenAccountBalance.lt(amountIn)) {
4182
4250
  throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
4183
4251
  }
4184
- _f.label = 7;
4252
+ _g.label = 7;
4185
4253
  case 7:
4186
4254
  custodyAccountMetas = [];
4187
4255
  custodyOracleAccountMetas = [];
4188
4256
  markets = [];
4189
- for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
4190
- custody = _c[_i];
4257
+ for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
4258
+ custody = _d[_c];
4191
4259
  custodyAccountMetas.push({
4192
4260
  pubkey: custody.custodyAccount,
4193
4261
  isSigner: false,
@@ -4199,8 +4267,8 @@ var PerpetualsClient = (function () {
4199
4267
  isWritable: false,
4200
4268
  });
4201
4269
  }
4202
- for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
4203
- market = _e[_d];
4270
+ for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
4271
+ market = _f[_e];
4204
4272
  markets.push({
4205
4273
  pubkey: market.marketAccount,
4206
4274
  isSigner: false,
@@ -4232,7 +4300,7 @@ var PerpetualsClient = (function () {
4232
4300
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4233
4301
  .instruction()];
4234
4302
  case 8:
4235
- instruction = _f.sent();
4303
+ instruction = _g.sent();
4236
4304
  instructions.push(instruction);
4237
4305
  return [2, {
4238
4306
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -4242,16 +4310,20 @@ var PerpetualsClient = (function () {
4242
4310
  });
4243
4311
  });
4244
4312
  };
4245
- this.removeLiquidity = function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey, userPublicKey) {
4246
- if (closeLpATA === void 0) { closeLpATA = false; }
4247
- if (createUserATA === void 0) { createUserATA = true; }
4248
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
4249
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4250
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4251
- return __awaiter(_this, void 0, void 0, function () {
4252
- 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;
4253
- return __generator(this, function (_e) {
4254
- 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) {
4255
4327
  case 0:
4256
4328
  recieveTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey); });
4257
4329
  if (!recieveTokenCustodyConfig) {
@@ -4262,15 +4334,15 @@ var PerpetualsClient = (function () {
4262
4334
  instructions = [];
4263
4335
  postInstructions = [];
4264
4336
  additionalSigners = [];
4265
- _e.label = 1;
4337
+ _f.label = 1;
4266
4338
  case 1:
4267
- _e.trys.push([1, 7, , 8]);
4339
+ _f.trys.push([1, 7, , 8]);
4268
4340
  stakedLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
4269
4341
  custodyAccountMetas = [];
4270
4342
  custodyOracleAccountMetas = [];
4271
4343
  markets = [];
4272
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
4273
- custody = _a[_i];
4344
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
4345
+ custody = _b[_a];
4274
4346
  custodyAccountMetas.push({
4275
4347
  pubkey: custody.custodyAccount,
4276
4348
  isSigner: false,
@@ -4282,8 +4354,8 @@ var PerpetualsClient = (function () {
4282
4354
  isWritable: false,
4283
4355
  });
4284
4356
  }
4285
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
4286
- market = _c[_b];
4357
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
4358
+ market = _d[_c];
4287
4359
  markets.push({
4288
4360
  pubkey: market.marketAccount,
4289
4361
  isSigner: false,
@@ -4312,17 +4384,17 @@ var PerpetualsClient = (function () {
4312
4384
  return [3, 5];
4313
4385
  case 2:
4314
4386
  userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true);
4315
- _d = createUserATA;
4316
- if (!_d) return [3, 4];
4387
+ _e = createUserATA;
4388
+ if (!_e) return [3, 4];
4317
4389
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
4318
4390
  case 3:
4319
- _d = !(_e.sent());
4320
- _e.label = 4;
4391
+ _e = !(_f.sent());
4392
+ _f.label = 4;
4321
4393
  case 4:
4322
- if (_d) {
4394
+ if (_e) {
4323
4395
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey));
4324
4396
  }
4325
- _e.label = 5;
4397
+ _f.label = 5;
4326
4398
  case 5: return [4, this.program.methods
4327
4399
  .removeLiquidity({
4328
4400
  lpAmountIn: liquidityAmountIn,
@@ -4347,7 +4419,7 @@ var PerpetualsClient = (function () {
4347
4419
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4348
4420
  .instruction()];
4349
4421
  case 6:
4350
- removeLiquidityTx = _e.sent();
4422
+ removeLiquidityTx = _f.sent();
4351
4423
  instructions.push(removeLiquidityTx);
4352
4424
  if (closeLpATA) {
4353
4425
  closeInx = (0, spl_token_1.createCloseAccountInstruction)(stakedLpTokenAccount, publicKey, publicKey);
@@ -4359,7 +4431,7 @@ var PerpetualsClient = (function () {
4359
4431
  }
4360
4432
  return [3, 8];
4361
4433
  case 7:
4362
- err_8 = _e.sent();
4434
+ err_8 = _f.sent();
4363
4435
  console.log("perpClient removeLiquidity error:: ", err_8);
4364
4436
  throw err_8;
4365
4437
  case 8: return [2, {
@@ -4777,22 +4849,26 @@ var PerpetualsClient = (function () {
4777
4849
  }
4778
4850
  });
4779
4851
  }); };
4780
- this.refreshStakeWithTokenStake = function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
4781
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4782
- return __awaiter(_this, void 0, void 0, function () {
4783
- var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_17;
4784
- return __generator(this, function (_b) {
4785
- 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) {
4786
4862
  case 0:
4787
- _b.trys.push([0, 2, , 3]);
4863
+ _c.trys.push([0, 2, , 3]);
4788
4864
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
4789
4865
  rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
4790
4866
  rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
4791
4867
  pool = poolConfig.poolAddress;
4792
4868
  feeDistributionTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("custody_token_account"), pool.toBuffer(), rewardCustodyMint.toBuffer()], this.programId)[0];
4793
4869
  custodyAccountMetas = [];
4794
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
4795
- custody = _a[_i];
4870
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
4871
+ custody = _b[_a];
4796
4872
  custodyAccountMetas.push({
4797
4873
  pubkey: custody.custodyAccount,
4798
4874
  isSigner: false,
@@ -4824,10 +4900,10 @@ var PerpetualsClient = (function () {
4824
4900
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
4825
4901
  .instruction()];
4826
4902
  case 1:
4827
- refreshStakeInstruction = _b.sent();
4903
+ refreshStakeInstruction = _c.sent();
4828
4904
  return [2, refreshStakeInstruction];
4829
4905
  case 2:
4830
- err_17 = _b.sent();
4906
+ err_17 = _c.sent();
4831
4907
  console.log("perpClient refreshStaking error:: ", err_17);
4832
4908
  throw err_17;
4833
4909
  case 3: return [2];
@@ -4835,10 +4911,14 @@ var PerpetualsClient = (function () {
4835
4911
  });
4836
4912
  });
4837
4913
  };
4838
- this.unstakeInstant = function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
4839
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4840
- 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) {
4841
4920
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_18;
4921
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4842
4922
  return __generator(this, function (_b) {
4843
4923
  switch (_b.label) {
4844
4924
  case 0:
@@ -4997,13 +5077,17 @@ var PerpetualsClient = (function () {
4997
5077
  }
4998
5078
  });
4999
5079
  }); };
5000
- this.withdrawStake = function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
5001
- if (pendingActivation === void 0) { pendingActivation = true; }
5002
- if (deactivated === void 0) { deactivated = true; }
5003
- if (createUserLPTA === void 0) { createUserLPTA = true; }
5004
- if (userPublicKey === void 0) { userPublicKey = undefined; }
5005
- 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) {
5006
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; }
5007
5091
  return __generator(this, function (_b) {
5008
5092
  switch (_b.label) {
5009
5093
  case 0:
@@ -5065,10 +5149,14 @@ var PerpetualsClient = (function () {
5065
5149
  });
5066
5150
  });
5067
5151
  };
5068
- this.collectStakeFees = function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
5069
- if (createUserATA === void 0) { createUserATA = true; }
5070
- 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) {
5071
5158
  var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_22;
5159
+ if (createUserATA === void 0) { createUserATA = true; }
5072
5160
  return __generator(this, function (_b) {
5073
5161
  switch (_b.label) {
5074
5162
  case 0:
@@ -5792,10 +5880,14 @@ var PerpetualsClient = (function () {
5792
5880
  }
5793
5881
  });
5794
5882
  }); };
5795
- this.collectTokenReward = function (owner, poolConfig, createUserATA) {
5796
- if (createUserATA === void 0) { createUserATA = true; }
5797
- 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) {
5798
5889
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_36;
5890
+ if (createUserATA === void 0) { createUserATA = true; }
5799
5891
  return __generator(this, function (_b) {
5800
5892
  switch (_b.label) {
5801
5893
  case 0:
@@ -5850,10 +5942,14 @@ var PerpetualsClient = (function () {
5850
5942
  });
5851
5943
  });
5852
5944
  };
5853
- this.collectRevenue = function (owner, rewardSymbol, poolConfig, createUserATA) {
5854
- if (createUserATA === void 0) { createUserATA = true; }
5855
- 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) {
5856
5951
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_37;
5952
+ if (createUserATA === void 0) { createUserATA = true; }
5857
5953
  return __generator(this, function (_b) {
5858
5954
  switch (_b.label) {
5859
5955
  case 0:
@@ -6038,10 +6134,14 @@ var PerpetualsClient = (function () {
6038
6134
  }
6039
6135
  });
6040
6136
  }); };
6041
- this.collectNftReward = function (rewardSymbol, poolConfig, nftMint, createUserATA) {
6042
- if (createUserATA === void 0) { createUserATA = true; }
6043
- 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) {
6044
6143
  var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_41;
6144
+ if (createUserATA === void 0) { createUserATA = true; }
6045
6145
  return __generator(this, function (_b) {
6046
6146
  switch (_b.label) {
6047
6147
  case 0:
@@ -6101,10 +6201,14 @@ var PerpetualsClient = (function () {
6101
6201
  });
6102
6202
  });
6103
6203
  };
6104
- this.collectAndDistributeFee = function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
6105
- if (createUserATA === void 0) { createUserATA = true; }
6106
- 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) {
6107
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; }
6108
6212
  return __generator(this, function (_b) {
6109
6213
  switch (_b.label) {
6110
6214
  case 0:
@@ -6229,12 +6333,16 @@ var PerpetualsClient = (function () {
6229
6333
  }
6230
6334
  });
6231
6335
  }); };
6232
- this.forceClosePosition = function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
6233
- if (createUserATA === void 0) { createUserATA = true; }
6234
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
6235
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6236
- 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) {
6237
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; }
6238
6346
  return __generator(this, function (_b) {
6239
6347
  switch (_b.label) {
6240
6348
  case 0:
@@ -6306,11 +6414,15 @@ var PerpetualsClient = (function () {
6306
6414
  });
6307
6415
  });
6308
6416
  };
6309
- this.placeLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
6310
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
6311
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6312
- 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) {
6313
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; }
6314
6426
  return __generator(this, function (_c) {
6315
6427
  switch (_c.label) {
6316
6428
  case 0:
@@ -6426,11 +6538,15 @@ var PerpetualsClient = (function () {
6426
6538
  });
6427
6539
  });
6428
6540
  };
6429
- this.editLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
6430
- if (createUserATA === void 0) { createUserATA = true; }
6431
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6432
- 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) {
6433
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; }
6434
6550
  return __generator(this, function (_b) {
6435
6551
  switch (_b.label) {
6436
6552
  case 0:
@@ -6529,12 +6645,16 @@ var PerpetualsClient = (function () {
6529
6645
  });
6530
6646
  });
6531
6647
  };
6532
- this.executeLimitOrder = function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6533
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6534
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6535
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6536
- 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) {
6537
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; }
6538
6658
  return __generator(this, function (_a) {
6539
6659
  switch (_a.label) {
6540
6660
  case 0:
@@ -6594,12 +6714,16 @@ var PerpetualsClient = (function () {
6594
6714
  });
6595
6715
  });
6596
6716
  };
6597
- this.executeLimitWithSwap = function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6598
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6599
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6600
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6601
- 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) {
6602
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; }
6603
6727
  return __generator(this, function (_a) {
6604
6728
  switch (_a.label) {
6605
6729
  case 0:
@@ -6865,16 +6989,20 @@ var PerpetualsClient = (function () {
6865
6989
  }
6866
6990
  });
6867
6991
  }); };
6868
- this.executeTriggerWithSwap = function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6869
- if (createUserATA === void 0) { createUserATA = true; }
6870
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6871
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6872
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6873
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6874
- return __awaiter(_this, void 0, void 0, function () {
6875
- 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;
6876
- return __generator(this, function (_d) {
6877
- 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) {
6878
7006
  case 0:
6879
7007
  payerPubkey = this.provider.wallet.publicKey;
6880
7008
  targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
@@ -6885,9 +7013,9 @@ var PerpetualsClient = (function () {
6885
7013
  instructions = [];
6886
7014
  postInstructions = [];
6887
7015
  additionalSigners = [];
6888
- _d.label = 1;
7016
+ _e.label = 1;
6889
7017
  case 1:
6890
- _d.trys.push([1, 9, , 10]);
7018
+ _e.trys.push([1, 9, , 10]);
6891
7019
  if (!false) return [3, 2];
6892
7020
  return [3, 7];
6893
7021
  case 2:
@@ -6896,8 +7024,8 @@ var PerpetualsClient = (function () {
6896
7024
  if (!_a) return [3, 4];
6897
7025
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
6898
7026
  case 3:
6899
- _a = !(_d.sent());
6900
- _d.label = 4;
7027
+ _a = !(_e.sent());
7028
+ _e.label = 4;
6901
7029
  case 4:
6902
7030
  if (_a) {
6903
7031
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
@@ -6907,20 +7035,20 @@ var PerpetualsClient = (function () {
6907
7035
  if (!_b) return [3, 6];
6908
7036
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
6909
7037
  case 5:
6910
- _b = !(_d.sent());
6911
- _d.label = 6;
7038
+ _b = !(_e.sent());
7039
+ _e.label = 6;
6912
7040
  case 6:
6913
7041
  if (_b) {
6914
7042
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
6915
7043
  }
6916
- _d.label = 7;
7044
+ _e.label = 7;
6917
7045
  case 7:
6918
7046
  positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
6919
7047
  orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
6920
7048
  custodyAccountMetas = [];
6921
7049
  custodyOracleAccountMetas = [];
6922
- for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
6923
- custody = _c[_i];
7050
+ for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
7051
+ custody = _d[_c];
6924
7052
  custodyAccountMetas.push({
6925
7053
  pubkey: custody.custodyAccount,
6926
7054
  isSigner: false,
@@ -6965,11 +7093,11 @@ var PerpetualsClient = (function () {
6965
7093
  .remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
6966
7094
  .instruction()];
6967
7095
  case 8:
6968
- executeTriggerWithSwap = _d.sent();
7096
+ executeTriggerWithSwap = _e.sent();
6969
7097
  instructions.push(executeTriggerWithSwap);
6970
7098
  return [3, 10];
6971
7099
  case 9:
6972
- err_53 = _d.sent();
7100
+ err_53 = _e.sent();
6973
7101
  console.log("perpClient executeTriggerWithSwap error:: ", err_53);
6974
7102
  throw err_53;
6975
7103
  case 10: return [2, {
@@ -6980,14 +7108,18 @@ var PerpetualsClient = (function () {
6980
7108
  });
6981
7109
  });
6982
7110
  };
6983
- this.executeTriggerOrder = function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6984
- if (createUserATA === void 0) { createUserATA = true; }
6985
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6986
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6987
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6988
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6989
- 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) {
6990
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; }
6991
7123
  return __generator(this, function (_b) {
6992
7124
  switch (_b.label) {
6993
7125
  case 0:
@@ -7532,14 +7664,18 @@ var PerpetualsClient = (function () {
7532
7664
  }
7533
7665
  });
7534
7666
  }); };
7535
- this.addCompoundingLiquidity = function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
7536
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
7537
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7538
- if (userPublicKey === void 0) { userPublicKey = undefined; }
7539
- return __awaiter(_this, void 0, void 0, function () {
7540
- 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_65;
7541
- return __generator(this, function (_e) {
7542
- switch (_e.label) {
7667
+ this.addCompoundingLiquidity = function (amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
7668
+ var args_1 = [];
7669
+ for (var _i = 5; _i < arguments.length; _i++) {
7670
+ args_1[_i - 5] = arguments[_i];
7671
+ }
7672
+ 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) {
7673
+ 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_65;
7674
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
7675
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7676
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
7677
+ return __generator(this, function (_f) {
7678
+ switch (_f.label) {
7543
7679
  case 0:
7544
7680
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
7545
7681
  preInstructions = [];
@@ -7556,8 +7692,8 @@ var PerpetualsClient = (function () {
7556
7692
  custodyAccountMetas = [];
7557
7693
  custodyOracleAccountMetas = [];
7558
7694
  markets = [];
7559
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
7560
- custody = _a[_i];
7695
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
7696
+ custody = _b[_a];
7561
7697
  custodyAccountMetas.push({
7562
7698
  pubkey: custody.custodyAccount,
7563
7699
  isSigner: false,
@@ -7569,8 +7705,8 @@ var PerpetualsClient = (function () {
7569
7705
  isWritable: false,
7570
7706
  });
7571
7707
  }
7572
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
7573
- market = _c[_b];
7708
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
7709
+ market = _d[_c];
7574
7710
  markets.push({
7575
7711
  pubkey: market.marketAccount,
7576
7712
  isSigner: false,
@@ -7579,26 +7715,26 @@ var PerpetualsClient = (function () {
7579
7715
  }
7580
7716
  return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
7581
7717
  case 1:
7582
- if (!(_e.sent())) {
7718
+ if (!(_f.sent())) {
7583
7719
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
7584
7720
  }
7585
7721
  return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
7586
7722
  case 2:
7587
- if (!(_e.sent())) {
7723
+ if (!(_f.sent())) {
7588
7724
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
7589
7725
  }
7590
7726
  if (!(inTokenSymbol == 'SOL')) return [3, 5];
7591
7727
  console.log("inTokenSymbol === SOL", inTokenSymbol);
7592
7728
  lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
7593
7729
  if (!!skipBalanceChecks) return [3, 4];
7594
- _d = anchor_1.BN.bind;
7730
+ _e = anchor_1.BN.bind;
7595
7731
  return [4, this.provider.connection.getBalance(publicKey)];
7596
7732
  case 3:
7597
- unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _e.sent()]))();
7733
+ unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _f.sent()]))();
7598
7734
  if (unWrappedSolBalance.lt(lamports)) {
7599
7735
  throw "Insufficient SOL Funds";
7600
7736
  }
7601
- _e.label = 4;
7737
+ _f.label = 4;
7602
7738
  case 4:
7603
7739
  if (!ephemeralSignerPubkey) {
7604
7740
  wrappedSolAccount = new web3_js_1.Keypair();
@@ -7622,12 +7758,12 @@ var PerpetualsClient = (function () {
7622
7758
  if (!!skipBalanceChecks) return [3, 7];
7623
7759
  return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
7624
7760
  case 6:
7625
- if (!(_e.sent())) {
7761
+ if (!(_f.sent())) {
7626
7762
  throw "Insufficient Funds , token Account doesn't exist";
7627
7763
  }
7628
- _e.label = 7;
7764
+ _f.label = 7;
7629
7765
  case 7:
7630
- _e.trys.push([7, 9, , 10]);
7766
+ _f.trys.push([7, 9, , 10]);
7631
7767
  return [4, this.program.methods
7632
7768
  .addCompoundingLiquidity({
7633
7769
  amountIn: amountIn,
@@ -7656,11 +7792,11 @@ var PerpetualsClient = (function () {
7656
7792
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
7657
7793
  .instruction()];
7658
7794
  case 8:
7659
- addCompoundingLiquidity = _e.sent();
7795
+ addCompoundingLiquidity = _f.sent();
7660
7796
  instructions.push(addCompoundingLiquidity);
7661
7797
  return [3, 10];
7662
7798
  case 9:
7663
- err_65 = _e.sent();
7799
+ err_65 = _f.sent();
7664
7800
  console.log("perpClient addCompoundingLiquidity error:: ", err_65);
7665
7801
  return [3, 10];
7666
7802
  case 10: return [2, {
@@ -7671,14 +7807,18 @@ var PerpetualsClient = (function () {
7671
7807
  });
7672
7808
  });
7673
7809
  };
7674
- this.removeCompoundingLiquidity = function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey, userPublicKey) {
7675
- if (createUserATA === void 0) { createUserATA = true; }
7676
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7677
- if (userPublicKey === void 0) { userPublicKey = undefined; }
7678
- return __awaiter(_this, void 0, void 0, function () {
7679
- 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_66;
7680
- return __generator(this, function (_e) {
7681
- switch (_e.label) {
7810
+ this.removeCompoundingLiquidity = function (compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
7811
+ var args_1 = [];
7812
+ for (var _i = 5; _i < arguments.length; _i++) {
7813
+ args_1[_i - 5] = arguments[_i];
7814
+ }
7815
+ 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) {
7816
+ 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_66;
7817
+ if (createUserATA === void 0) { createUserATA = true; }
7818
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
7819
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
7820
+ return __generator(this, function (_f) {
7821
+ switch (_f.label) {
7682
7822
  case 0:
7683
7823
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
7684
7824
  preInstructions = [];
@@ -7715,19 +7855,19 @@ var PerpetualsClient = (function () {
7715
7855
  if (!_a) return [3, 3];
7716
7856
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
7717
7857
  case 2:
7718
- _a = !(_e.sent());
7719
- _e.label = 3;
7858
+ _a = !(_f.sent());
7859
+ _f.label = 3;
7720
7860
  case 3:
7721
7861
  if (_a) {
7722
7862
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
7723
7863
  }
7724
- _e.label = 4;
7864
+ _f.label = 4;
7725
7865
  case 4:
7726
7866
  custodyAccountMetas = [];
7727
7867
  custodyOracleAccountMetas = [];
7728
7868
  markets = [];
7729
- for (_i = 0, _b = poolConfig.custodies; _i < _b.length; _i++) {
7730
- custody = _b[_i];
7869
+ for (_b = 0, _c = poolConfig.custodies; _b < _c.length; _b++) {
7870
+ custody = _c[_b];
7731
7871
  custodyAccountMetas.push({
7732
7872
  pubkey: custody.custodyAccount,
7733
7873
  isSigner: false,
@@ -7739,8 +7879,8 @@ var PerpetualsClient = (function () {
7739
7879
  isWritable: false,
7740
7880
  });
7741
7881
  }
7742
- for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
7743
- market = _d[_c];
7882
+ for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
7883
+ market = _e[_d];
7744
7884
  markets.push({
7745
7885
  pubkey: market.marketAccount,
7746
7886
  isSigner: false,
@@ -7748,9 +7888,9 @@ var PerpetualsClient = (function () {
7748
7888
  });
7749
7889
  }
7750
7890
  compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
7751
- _e.label = 5;
7891
+ _f.label = 5;
7752
7892
  case 5:
7753
- _e.trys.push([5, 7, , 8]);
7893
+ _f.trys.push([5, 7, , 8]);
7754
7894
  return [4, this.program.methods
7755
7895
  .removeCompoundingLiquidity({
7756
7896
  compoundingAmountIn: compoundingAmountIn,
@@ -7779,11 +7919,11 @@ var PerpetualsClient = (function () {
7779
7919
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
7780
7920
  .instruction()];
7781
7921
  case 6:
7782
- removeCompoundingLiquidity = _e.sent();
7922
+ removeCompoundingLiquidity = _f.sent();
7783
7923
  instructions.push(removeCompoundingLiquidity);
7784
7924
  return [3, 8];
7785
7925
  case 7:
7786
- err_66 = _e.sent();
7926
+ err_66 = _f.sent();
7787
7927
  console.log("perpClient removeCompoundingLiquidity error:: ", err_66);
7788
7928
  return [3, 8];
7789
7929
  case 8: return [2, {
@@ -7794,12 +7934,16 @@ var PerpetualsClient = (function () {
7794
7934
  });
7795
7935
  });
7796
7936
  };
7797
- this.migrateStake = function (amount, rewardTokenMint, poolConfig, createUserATA) {
7798
- if (createUserATA === void 0) { createUserATA = true; }
7799
- return __awaiter(_this, void 0, void 0, function () {
7800
- 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_67;
7801
- return __generator(this, function (_f) {
7802
- switch (_f.label) {
7937
+ this.migrateStake = function (amount_1, rewardTokenMint_1, poolConfig_1) {
7938
+ var args_1 = [];
7939
+ for (var _i = 3; _i < arguments.length; _i++) {
7940
+ args_1[_i - 3] = arguments[_i];
7941
+ }
7942
+ return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
7943
+ 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_67;
7944
+ if (createUserATA === void 0) { createUserATA = true; }
7945
+ return __generator(this, function (_g) {
7946
+ switch (_g.label) {
7803
7947
  case 0:
7804
7948
  publicKey = this.provider.wallet.publicKey;
7805
7949
  preInstructions = [];
@@ -7814,8 +7958,8 @@ var PerpetualsClient = (function () {
7814
7958
  if (!_a) return [3, 2];
7815
7959
  return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
7816
7960
  case 1:
7817
- _a = !(_f.sent());
7818
- _f.label = 2;
7961
+ _a = !(_g.sent());
7962
+ _g.label = 2;
7819
7963
  case 2:
7820
7964
  if (_a) {
7821
7965
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
@@ -7827,8 +7971,8 @@ var PerpetualsClient = (function () {
7827
7971
  if (!_b) return [3, 4];
7828
7972
  return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
7829
7973
  case 3:
7830
- _b = (_f.sent());
7831
- _f.label = 4;
7974
+ _b = (_g.sent());
7975
+ _g.label = 4;
7832
7976
  case 4:
7833
7977
  if (_b) {
7834
7978
  tokenStakeAccounts.push({
@@ -7841,8 +7985,8 @@ var PerpetualsClient = (function () {
7841
7985
  custodyAccountMetas = [];
7842
7986
  custodyOracleAccountMetas = [];
7843
7987
  markets = [];
7844
- for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
7845
- custody = _c[_i];
7988
+ for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
7989
+ custody = _d[_c];
7846
7990
  custodyAccountMetas.push({
7847
7991
  pubkey: custody.custodyAccount,
7848
7992
  isSigner: false,
@@ -7854,17 +7998,17 @@ var PerpetualsClient = (function () {
7854
7998
  isWritable: false,
7855
7999
  });
7856
8000
  }
7857
- for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
7858
- market = _e[_d];
8001
+ for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
8002
+ market = _f[_e];
7859
8003
  markets.push({
7860
8004
  pubkey: market.marketAccount,
7861
8005
  isSigner: false,
7862
8006
  isWritable: false,
7863
8007
  });
7864
8008
  }
7865
- _f.label = 5;
8009
+ _g.label = 5;
7866
8010
  case 5:
7867
- _f.trys.push([5, 7, , 8]);
8011
+ _g.trys.push([5, 7, , 8]);
7868
8012
  return [4, this.program.methods
7869
8013
  .migrateStake({
7870
8014
  amount: amount
@@ -7890,11 +8034,11 @@ var PerpetualsClient = (function () {
7890
8034
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
7891
8035
  .instruction()];
7892
8036
  case 6:
7893
- migrateStake = _f.sent();
8037
+ migrateStake = _g.sent();
7894
8038
  instructions.push(migrateStake);
7895
8039
  return [3, 8];
7896
8040
  case 7:
7897
- err_67 = _f.sent();
8041
+ err_67 = _g.sent();
7898
8042
  console.log("perpClient migrateStake error:: ", err_67);
7899
8043
  return [3, 8];
7900
8044
  case 8: return [2, {
@@ -7988,12 +8132,16 @@ var PerpetualsClient = (function () {
7988
8132
  }
7989
8133
  });
7990
8134
  }); };
7991
- this.compoundingFee = function (poolConfig, rewardTokenSymbol) {
7992
- if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
7993
- return __awaiter(_this, void 0, void 0, function () {
7994
- var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, compoundingFee, err_69;
7995
- return __generator(this, function (_d) {
7996
- switch (_d.label) {
8135
+ this.compoundingFee = function (poolConfig_1) {
8136
+ var args_1 = [];
8137
+ for (var _i = 1; _i < arguments.length; _i++) {
8138
+ args_1[_i - 1] = arguments[_i];
8139
+ }
8140
+ return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
8141
+ var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_69;
8142
+ if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
8143
+ return __generator(this, function (_e) {
8144
+ switch (_e.label) {
7997
8145
  case 0:
7998
8146
  instructions = [];
7999
8147
  additionalSigners = [];
@@ -8002,8 +8150,8 @@ var PerpetualsClient = (function () {
8002
8150
  custodyAccountMetas = [];
8003
8151
  custodyOracleAccountMetas = [];
8004
8152
  markets = [];
8005
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
8006
- custody = _a[_i];
8153
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
8154
+ custody = _b[_a];
8007
8155
  custodyAccountMetas.push({
8008
8156
  pubkey: custody.custodyAccount,
8009
8157
  isSigner: false,
@@ -8015,17 +8163,17 @@ var PerpetualsClient = (function () {
8015
8163
  isWritable: false,
8016
8164
  });
8017
8165
  }
8018
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
8019
- market = _c[_b];
8166
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
8167
+ market = _d[_c];
8020
8168
  markets.push({
8021
8169
  pubkey: market.marketAccount,
8022
8170
  isSigner: false,
8023
8171
  isWritable: false,
8024
8172
  });
8025
8173
  }
8026
- _d.label = 1;
8174
+ _e.label = 1;
8027
8175
  case 1:
8028
- _d.trys.push([1, 3, , 4]);
8176
+ _e.trys.push([1, 3, , 4]);
8029
8177
  return [4, this.program.methods
8030
8178
  .compoundFees({})
8031
8179
  .accounts({
@@ -8044,11 +8192,11 @@ var PerpetualsClient = (function () {
8044
8192
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
8045
8193
  .instruction()];
8046
8194
  case 2:
8047
- compoundingFee = _d.sent();
8195
+ compoundingFee = _e.sent();
8048
8196
  instructions.push(compoundingFee);
8049
8197
  return [3, 4];
8050
8198
  case 3:
8051
- err_69 = _d.sent();
8199
+ err_69 = _e.sent();
8052
8200
  console.log("perpClient compoundingFee error:: ", err_69);
8053
8201
  return [3, 4];
8054
8202
  case 4: return [2, {
@@ -8209,9 +8357,9 @@ var PerpetualsClient = (function () {
8209
8357
  }
8210
8358
  }
8211
8359
  };
8212
- PerpetualsClient.prototype.sendTransaction = function (ixs, opts) {
8213
- if (opts === void 0) { opts = {}; }
8214
- return __awaiter(this, void 0, void 0, function () {
8360
+ PerpetualsClient.prototype.sendTransaction = function (ixs_1) {
8361
+ return __awaiter(this, arguments, void 0, function (ixs, opts) {
8362
+ if (opts === void 0) { opts = {}; }
8215
8363
  return __generator(this, function (_a) {
8216
8364
  switch (_a.label) {
8217
8365
  case 0: return [4, (0, rpc_1.sendTransaction)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
@@ -8220,9 +8368,9 @@ var PerpetualsClient = (function () {
8220
8368
  });
8221
8369
  });
8222
8370
  };
8223
- PerpetualsClient.prototype.sendTransactionV3 = function (ixs, opts) {
8224
- if (opts === void 0) { opts = {}; }
8225
- return __awaiter(this, void 0, void 0, function () {
8371
+ PerpetualsClient.prototype.sendTransactionV3 = function (ixs_1) {
8372
+ return __awaiter(this, arguments, void 0, function (ixs, opts) {
8373
+ if (opts === void 0) { opts = {}; }
8226
8374
  return __generator(this, function (_a) {
8227
8375
  switch (_a.label) {
8228
8376
  case 0: return [4, (0, rpc_1.sendTransactionV3)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];