flash-sdk 2.54.0 → 2.54.2

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.
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
20
20
  });
21
21
  };
22
22
  var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
25
  function verb(n) { return function (v) { return step([n, v]); }; }
26
26
  function step(op) {
27
27
  if (f) throw new TypeError("Generator is already executing.");
@@ -1816,11 +1816,15 @@ var PerpetualsClient = (function () {
1816
1816
  }
1817
1817
  return finalIndexPriceAtT1.toString();
1818
1818
  };
1819
- this.getUserClaimableRevenueAmount = function (POOL_CONFIG, userPublicKey, enableDebuglogs) {
1820
- if (enableDebuglogs === void 0) { enableDebuglogs = false; }
1821
- return __awaiter(_this, void 0, void 0, function () {
1819
+ this.getUserClaimableRevenueAmount = function (POOL_CONFIG_1, userPublicKey_1) {
1820
+ var args_1 = [];
1821
+ for (var _i = 2; _i < arguments.length; _i++) {
1822
+ args_1[_i - 2] = arguments[_i];
1823
+ }
1824
+ return __awaiter(_this, __spreadArray([POOL_CONFIG_1, userPublicKey_1], args_1, true), void 0, function (POOL_CONFIG, userPublicKey, enableDebuglogs) {
1822
1825
  var fafTokenVaultPk, fafTokenVaultAccountInfo, fafTokenVaultAccount, fafTokenVault, tokenStakeAccount, accountInfo, fafStakeData, tokenStakeFafAccount, activeStakeAmount, revenuePerFafStaked, revenueWatermark, revenueSnapshot, unclaimedRevenue, revenueAmount;
1823
1826
  var _a, _b, _c, _d;
1827
+ if (enableDebuglogs === void 0) { enableDebuglogs = false; }
1824
1828
  return __generator(this, function (_e) {
1825
1829
  switch (_e.label) {
1826
1830
  case 0:
@@ -1977,34 +1981,38 @@ var PerpetualsClient = (function () {
1977
1981
  }
1978
1982
  });
1979
1983
  }); };
1980
- this.getAddLiquidityAmountAndFeeView = function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
1981
- if (userPublicKey === void 0) { userPublicKey = undefined; }
1982
- return __awaiter(_this, void 0, void 0, function () {
1983
- var custodies, custodyMetas, marketMetas, _i, custodies_5, token, _a, custodies_6, custody, _b, _c, market, depositCustodyConfig, transaction, result, index, res;
1984
- return __generator(this, function (_d) {
1985
- switch (_d.label) {
1984
+ this.getAddLiquidityAmountAndFeeView = function (amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1) {
1985
+ var args_1 = [];
1986
+ for (var _i = 4; _i < arguments.length; _i++) {
1987
+ args_1[_i - 4] = arguments[_i];
1988
+ }
1989
+ 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) {
1990
+ var custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, result, index, res;
1991
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
1992
+ return __generator(this, function (_e) {
1993
+ switch (_e.label) {
1986
1994
  case 0:
1987
1995
  custodies = POOL_CONFIG.custodies;
1988
1996
  custodyMetas = [];
1989
1997
  marketMetas = [];
1990
- for (_i = 0, custodies_5 = custodies; _i < custodies_5.length; _i++) {
1991
- token = custodies_5[_i];
1998
+ for (_a = 0, custodies_5 = custodies; _a < custodies_5.length; _a++) {
1999
+ token = custodies_5[_a];
1992
2000
  custodyMetas.push({
1993
2001
  isSigner: false,
1994
2002
  isWritable: false,
1995
2003
  pubkey: token.custodyAccount,
1996
2004
  });
1997
2005
  }
1998
- for (_a = 0, custodies_6 = custodies; _a < custodies_6.length; _a++) {
1999
- custody = custodies_6[_a];
2006
+ for (_b = 0, custodies_6 = custodies; _b < custodies_6.length; _b++) {
2007
+ custody = custodies_6[_b];
2000
2008
  custodyMetas.push({
2001
2009
  isSigner: false,
2002
2010
  isWritable: false,
2003
2011
  pubkey: custody.intOracleAccount,
2004
2012
  });
2005
2013
  }
2006
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2007
- market = _c[_b];
2014
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2015
+ market = _d[_c];
2008
2016
  marketMetas.push({
2009
2017
  pubkey: market.marketAccount,
2010
2018
  isSigner: false,
@@ -2027,10 +2035,10 @@ var PerpetualsClient = (function () {
2027
2035
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2028
2036
  .transaction()];
2029
2037
  case 1:
2030
- transaction = _d.sent();
2038
+ transaction = _e.sent();
2031
2039
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2032
2040
  case 2:
2033
- result = _d.sent();
2041
+ result = _e.sent();
2034
2042
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddLiquidityAmountAndFee'; });
2035
2043
  res = this.viewHelper.decodeLogs(result, index, 'getAddLiquidityAmountAndFee');
2036
2044
  return [2, {
@@ -2041,34 +2049,38 @@ var PerpetualsClient = (function () {
2041
2049
  });
2042
2050
  });
2043
2051
  };
2044
- this.getRemoveLiquidityAmountAndFeeView = function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
2045
- if (userPublicKey === void 0) { userPublicKey = undefined; }
2046
- return __awaiter(_this, void 0, void 0, function () {
2047
- var custodies, custodyMetas, marketMetas, _i, custodies_7, token, _a, custodies_8, custody, _b, _c, market, removeCustodyConfig, transaction, result, index, res;
2048
- return __generator(this, function (_d) {
2049
- switch (_d.label) {
2052
+ this.getRemoveLiquidityAmountAndFeeView = function (amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1) {
2053
+ var args_1 = [];
2054
+ for (var _i = 4; _i < arguments.length; _i++) {
2055
+ args_1[_i - 4] = arguments[_i];
2056
+ }
2057
+ 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) {
2058
+ var custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, result, index, res;
2059
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
2060
+ return __generator(this, function (_e) {
2061
+ switch (_e.label) {
2050
2062
  case 0:
2051
2063
  custodies = POOL_CONFIG.custodies;
2052
2064
  custodyMetas = [];
2053
2065
  marketMetas = [];
2054
- for (_i = 0, custodies_7 = custodies; _i < custodies_7.length; _i++) {
2055
- token = custodies_7[_i];
2066
+ for (_a = 0, custodies_7 = custodies; _a < custodies_7.length; _a++) {
2067
+ token = custodies_7[_a];
2056
2068
  custodyMetas.push({
2057
2069
  isSigner: false,
2058
2070
  isWritable: false,
2059
2071
  pubkey: token.custodyAccount,
2060
2072
  });
2061
2073
  }
2062
- for (_a = 0, custodies_8 = custodies; _a < custodies_8.length; _a++) {
2063
- custody = custodies_8[_a];
2074
+ for (_b = 0, custodies_8 = custodies; _b < custodies_8.length; _b++) {
2075
+ custody = custodies_8[_b];
2064
2076
  custodyMetas.push({
2065
2077
  isSigner: false,
2066
2078
  isWritable: false,
2067
2079
  pubkey: custody.intOracleAccount,
2068
2080
  });
2069
2081
  }
2070
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2071
- market = _c[_b];
2082
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2083
+ market = _d[_c];
2072
2084
  marketMetas.push({
2073
2085
  pubkey: market.marketAccount,
2074
2086
  isSigner: false,
@@ -2091,10 +2103,10 @@ var PerpetualsClient = (function () {
2091
2103
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2092
2104
  .transaction()];
2093
2105
  case 1:
2094
- transaction = _d.sent();
2106
+ transaction = _e.sent();
2095
2107
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2096
2108
  case 2:
2097
- result = _d.sent();
2109
+ result = _e.sent();
2098
2110
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveLiquidityAmountAndFee'; });
2099
2111
  if (result.value.err) {
2100
2112
  return [2, {
@@ -2170,34 +2182,38 @@ var PerpetualsClient = (function () {
2170
2182
  }
2171
2183
  });
2172
2184
  }); };
2173
- this.getAddCompoundingLiquidityAmountAndFeeView = function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
2174
- if (userPublicKey === void 0) { userPublicKey = undefined; }
2175
- return __awaiter(_this, void 0, void 0, function () {
2176
- var custodies, custodyMetas, marketMetas, _i, custodies_11, token, _a, custodies_12, custody, _b, _c, market, depositCustodyConfig, rewardCustody, transaction, result, index, res;
2177
- return __generator(this, function (_d) {
2178
- switch (_d.label) {
2185
+ this.getAddCompoundingLiquidityAmountAndFeeView = function (amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1) {
2186
+ var args_1 = [];
2187
+ for (var _i = 4; _i < arguments.length; _i++) {
2188
+ args_1[_i - 4] = arguments[_i];
2189
+ }
2190
+ 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) {
2191
+ var custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, transaction, result, index, res;
2192
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
2193
+ return __generator(this, function (_e) {
2194
+ switch (_e.label) {
2179
2195
  case 0:
2180
2196
  custodies = POOL_CONFIG.custodies;
2181
2197
  custodyMetas = [];
2182
2198
  marketMetas = [];
2183
- for (_i = 0, custodies_11 = custodies; _i < custodies_11.length; _i++) {
2184
- token = custodies_11[_i];
2199
+ for (_a = 0, custodies_11 = custodies; _a < custodies_11.length; _a++) {
2200
+ token = custodies_11[_a];
2185
2201
  custodyMetas.push({
2186
2202
  isSigner: false,
2187
2203
  isWritable: false,
2188
2204
  pubkey: token.custodyAccount,
2189
2205
  });
2190
2206
  }
2191
- for (_a = 0, custodies_12 = custodies; _a < custodies_12.length; _a++) {
2192
- custody = custodies_12[_a];
2207
+ for (_b = 0, custodies_12 = custodies; _b < custodies_12.length; _b++) {
2208
+ custody = custodies_12[_b];
2193
2209
  custodyMetas.push({
2194
2210
  isSigner: false,
2195
2211
  isWritable: false,
2196
2212
  pubkey: custody.intOracleAccount,
2197
2213
  });
2198
2214
  }
2199
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2200
- market = _c[_b];
2215
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2216
+ market = _d[_c];
2201
2217
  marketMetas.push({
2202
2218
  pubkey: market.marketAccount,
2203
2219
  isSigner: false,
@@ -2224,10 +2240,10 @@ var PerpetualsClient = (function () {
2224
2240
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2225
2241
  .transaction()];
2226
2242
  case 1:
2227
- transaction = _d.sent();
2243
+ transaction = _e.sent();
2228
2244
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2229
2245
  case 2:
2230
- result = _d.sent();
2246
+ result = _e.sent();
2231
2247
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddCompoundingLiquidityAmountAndFee'; });
2232
2248
  res = this.viewHelper.decodeLogs(result, index, 'getAddCompoundingLiquidityAmountAndFee');
2233
2249
  return [2, {
@@ -2238,34 +2254,38 @@ var PerpetualsClient = (function () {
2238
2254
  });
2239
2255
  });
2240
2256
  };
2241
- this.getRemoveCompoundingLiquidityAmountAndFeeView = function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
2242
- if (userPublicKey === void 0) { userPublicKey = undefined; }
2243
- return __awaiter(_this, void 0, void 0, function () {
2244
- var custodies, custodyMetas, marketMetas, _i, custodies_13, token, _a, custodies_14, custody, _b, _c, market, removeCustodyConfig, rewardCustody, transaction, result, index, res;
2245
- return __generator(this, function (_d) {
2246
- switch (_d.label) {
2257
+ this.getRemoveCompoundingLiquidityAmountAndFeeView = function (amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1) {
2258
+ var args_1 = [];
2259
+ for (var _i = 4; _i < arguments.length; _i++) {
2260
+ args_1[_i - 4] = arguments[_i];
2261
+ }
2262
+ 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) {
2263
+ var custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, transaction, result, index, res;
2264
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
2265
+ return __generator(this, function (_e) {
2266
+ switch (_e.label) {
2247
2267
  case 0:
2248
2268
  custodies = POOL_CONFIG.custodies;
2249
2269
  custodyMetas = [];
2250
2270
  marketMetas = [];
2251
- for (_i = 0, custodies_13 = custodies; _i < custodies_13.length; _i++) {
2252
- token = custodies_13[_i];
2271
+ for (_a = 0, custodies_13 = custodies; _a < custodies_13.length; _a++) {
2272
+ token = custodies_13[_a];
2253
2273
  custodyMetas.push({
2254
2274
  isSigner: false,
2255
2275
  isWritable: false,
2256
2276
  pubkey: token.custodyAccount,
2257
2277
  });
2258
2278
  }
2259
- for (_a = 0, custodies_14 = custodies; _a < custodies_14.length; _a++) {
2260
- custody = custodies_14[_a];
2279
+ for (_b = 0, custodies_14 = custodies; _b < custodies_14.length; _b++) {
2280
+ custody = custodies_14[_b];
2261
2281
  custodyMetas.push({
2262
2282
  isSigner: false,
2263
2283
  isWritable: false,
2264
2284
  pubkey: custody.intOracleAccount,
2265
2285
  });
2266
2286
  }
2267
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2268
- market = _c[_b];
2287
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2288
+ market = _d[_c];
2269
2289
  marketMetas.push({
2270
2290
  pubkey: market.marketAccount,
2271
2291
  isSigner: false,
@@ -2292,10 +2312,10 @@ var PerpetualsClient = (function () {
2292
2312
  .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2293
2313
  .transaction()];
2294
2314
  case 1:
2295
- transaction = _d.sent();
2315
+ transaction = _e.sent();
2296
2316
  return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2297
2317
  case 2:
2298
- result = _d.sent();
2318
+ result = _e.sent();
2299
2319
  index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveCompoundingLiquidityAmountAndFee'; });
2300
2320
  if (result.value.err) {
2301
2321
  return [2, {
@@ -2476,14 +2496,18 @@ var PerpetualsClient = (function () {
2476
2496
  }
2477
2497
  });
2478
2498
  }); };
2479
- this.openPosition = function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
2480
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2481
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2482
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2483
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2484
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2485
- return __awaiter(_this, void 0, void 0, function () {
2499
+ this.openPosition = function (targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1) {
2500
+ var args_1 = [];
2501
+ for (var _i = 8; _i < arguments.length; _i++) {
2502
+ args_1[_i - 8] = arguments[_i];
2503
+ }
2504
+ 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) {
2486
2505
  var publicKey, targetCustodyConfig, collateralCustodyConfig, collateralToken, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
2506
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2507
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2508
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2509
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2510
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2487
2511
  return __generator(this, function (_c) {
2488
2512
  switch (_c.label) {
2489
2513
  case 0:
@@ -2587,15 +2611,19 @@ var PerpetualsClient = (function () {
2587
2611
  });
2588
2612
  });
2589
2613
  };
2590
- this.closePosition = function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
2591
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2592
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2593
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2594
- if (createUserATA === void 0) { createUserATA = true; }
2595
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
2596
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2597
- return __awaiter(_this, void 0, void 0, function () {
2614
+ this.closePosition = function (marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
2615
+ var args_1 = [];
2616
+ for (var _i = 6; _i < arguments.length; _i++) {
2617
+ args_1[_i - 6] = arguments[_i];
2618
+ }
2619
+ 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) {
2598
2620
  var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_1;
2621
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2622
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2623
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2624
+ if (createUserATA === void 0) { createUserATA = true; }
2625
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
2626
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2599
2627
  return __generator(this, function (_b) {
2600
2628
  switch (_b.label) {
2601
2629
  case 0:
@@ -2692,14 +2720,18 @@ var PerpetualsClient = (function () {
2692
2720
  });
2693
2721
  });
2694
2722
  };
2695
- this.swapAndOpen = function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, minCollateralAmountOut, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
2696
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2697
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2698
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2699
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2700
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2701
- return __awaiter(_this, void 0, void 0, function () {
2723
+ this.swapAndOpen = function (targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, minCollateralAmountOut_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1) {
2724
+ var args_1 = [];
2725
+ for (var _i = 10; _i < arguments.length; _i++) {
2726
+ args_1[_i - 10] = arguments[_i];
2727
+ }
2728
+ 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) {
2702
2729
  var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, targetToken, userInputTokenAccount, userInputToken, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, rebateMintAccount, inx, err_3;
2730
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2731
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2732
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2733
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2734
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2703
2735
  return __generator(this, function (_c) {
2704
2736
  switch (_c.label) {
2705
2737
  case 0:
@@ -2850,13 +2882,17 @@ var PerpetualsClient = (function () {
2850
2882
  });
2851
2883
  });
2852
2884
  };
2853
- this.closeAndSwap = function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, minSwapAmountOut, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, ephemeralSignerPubkey) {
2854
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2855
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2856
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2857
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2858
- return __awaiter(_this, void 0, void 0, function () {
2885
+ this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, minSwapAmountOut_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
2886
+ var args_1 = [];
2887
+ for (var _i = 8; _i < arguments.length; _i++) {
2888
+ args_1[_i - 8] = arguments[_i];
2889
+ }
2890
+ 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) {
2859
2891
  var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, collateralToken, userOutputToken, lamports, userCollateralTokenAccount, rebateMintAccount, inx, err_4;
2892
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
2893
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
2894
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
2895
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2860
2896
  return __generator(this, function (_a) {
2861
2897
  switch (_a.label) {
2862
2898
  case 0:
@@ -2979,11 +3015,15 @@ var PerpetualsClient = (function () {
2979
3015
  });
2980
3016
  });
2981
3017
  };
2982
- this.addCollateral = function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
2983
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
2984
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2985
- return __awaiter(_this, void 0, void 0, function () {
3018
+ this.addCollateral = function (collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
3019
+ var args_1 = [];
3020
+ for (var _i = 6; _i < arguments.length; _i++) {
3021
+ args_1[_i - 6] = arguments[_i];
3022
+ }
3023
+ 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) {
2986
3024
  var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
3025
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3026
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
2987
3027
  return __generator(this, function (_c) {
2988
3028
  switch (_c.label) {
2989
3029
  case 0:
@@ -3078,11 +3118,15 @@ var PerpetualsClient = (function () {
3078
3118
  });
3079
3119
  });
3080
3120
  };
3081
- this.swapAndAddCollateral = function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minCollateralAmountOut, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
3082
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3083
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3084
- return __awaiter(_this, void 0, void 0, function () {
3121
+ this.swapAndAddCollateral = function (targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1) {
3122
+ var args_1 = [];
3123
+ for (var _i = 8; _i < arguments.length; _i++) {
3124
+ args_1[_i - 8] = arguments[_i];
3125
+ }
3126
+ 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) {
3085
3127
  var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
3128
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3129
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3086
3130
  return __generator(this, function (_c) {
3087
3131
  switch (_c.label) {
3088
3132
  case 0:
@@ -3193,12 +3237,16 @@ var PerpetualsClient = (function () {
3193
3237
  });
3194
3238
  });
3195
3239
  };
3196
- this.removeCollateral = function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
3197
- if (createUserATA === void 0) { createUserATA = true; }
3198
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
3199
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3200
- return __awaiter(_this, void 0, void 0, function () {
3240
+ this.removeCollateral = function (collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
3241
+ var args_1 = [];
3242
+ for (var _i = 6; _i < arguments.length; _i++) {
3243
+ args_1[_i - 6] = arguments[_i];
3244
+ }
3245
+ 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) {
3201
3246
  var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns, error_2;
3247
+ if (createUserATA === void 0) { createUserATA = true; }
3248
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
3249
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3202
3250
  return __generator(this, function (_b) {
3203
3251
  switch (_b.label) {
3204
3252
  case 0:
@@ -3300,10 +3348,14 @@ var PerpetualsClient = (function () {
3300
3348
  });
3301
3349
  });
3302
3350
  };
3303
- this.removeCollateralAndSwap = function (targetSymbol, collateralSymbol, outputSymbol, minSwapAmountOut, collateralDelta, side, poolConfig, ephemeralSignerPubkey) {
3304
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3305
- return __awaiter(_this, void 0, void 0, function () {
3351
+ this.removeCollateralAndSwap = function (targetSymbol_1, collateralSymbol_1, outputSymbol_1, minSwapAmountOut_1, collateralDelta_1, side_1, poolConfig_1) {
3352
+ var args_1 = [];
3353
+ for (var _i = 7; _i < arguments.length; _i++) {
3354
+ args_1[_i - 7] = arguments[_i];
3355
+ }
3356
+ 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) {
3306
3357
  var publicKey, targetCustodyConfig, collateralCustodyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, instruction;
3358
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3307
3359
  return __generator(this, function (_a) {
3308
3360
  switch (_a.label) {
3309
3361
  case 0:
@@ -3396,12 +3448,16 @@ var PerpetualsClient = (function () {
3396
3448
  });
3397
3449
  });
3398
3450
  };
3399
- this.increaseSize = function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
3400
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3401
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3402
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3403
- return __awaiter(_this, void 0, void 0, function () {
3451
+ this.increaseSize = function (targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
3452
+ var args_1 = [];
3453
+ for (var _i = 8; _i < arguments.length; _i++) {
3454
+ args_1[_i - 8] = arguments[_i];
3455
+ }
3456
+ 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) {
3404
3457
  var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
3458
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3459
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3460
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3405
3461
  return __generator(this, function (_a) {
3406
3462
  switch (_a.label) {
3407
3463
  case 0:
@@ -3456,12 +3512,16 @@ var PerpetualsClient = (function () {
3456
3512
  });
3457
3513
  });
3458
3514
  };
3459
- this.decreaseSize = function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
3460
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3461
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3462
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3463
- return __awaiter(_this, void 0, void 0, function () {
3515
+ this.decreaseSize = function (targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
3516
+ var args_1 = [];
3517
+ for (var _i = 8; _i < arguments.length; _i++) {
3518
+ args_1[_i - 8] = arguments[_i];
3519
+ }
3520
+ 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) {
3464
3521
  var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
3522
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
3523
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
3524
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
3465
3525
  return __generator(this, function (_a) {
3466
3526
  switch (_a.label) {
3467
3527
  case 0:
@@ -3516,13 +3576,17 @@ var PerpetualsClient = (function () {
3516
3576
  });
3517
3577
  });
3518
3578
  };
3519
- this.addLiquidity = function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
3520
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3521
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3522
- return __awaiter(_this, void 0, void 0, function () {
3523
- var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, payToken, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, tokenAccountBalance, _e, instruction, err_5;
3524
- return __generator(this, function (_f) {
3525
- switch (_f.label) {
3579
+ this.addLiquidity = function (payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1) {
3580
+ var args_1 = [];
3581
+ for (var _i = 4; _i < arguments.length; _i++) {
3582
+ args_1[_i - 4] = arguments[_i];
3583
+ }
3584
+ return __awaiter(_this, __spreadArray([payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
3585
+ var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, payToken, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, tokenAccountBalance, _f, instruction, err_5;
3586
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3587
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3588
+ return __generator(this, function (_g) {
3589
+ switch (_g.label) {
3526
3590
  case 0:
3527
3591
  publicKey = this.provider.wallet.publicKey;
3528
3592
  payTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey); });
@@ -3534,16 +3598,16 @@ var PerpetualsClient = (function () {
3534
3598
  postInstructions = [];
3535
3599
  additionalSigners = [];
3536
3600
  payToken = poolConfig.getTokenFromSymbol(payTokenSymbol);
3537
- _f.label = 1;
3601
+ _g.label = 1;
3538
3602
  case 1:
3539
- _f.trys.push([1, 10, , 11]);
3603
+ _g.trys.push([1, 10, , 11]);
3540
3604
  userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true, payToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
3541
3605
  lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
3542
3606
  custodyAccountMetas = [];
3543
3607
  custodyOracleAccountMetas = [];
3544
3608
  markets = [];
3545
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
3546
- custody = _a[_i];
3609
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
3610
+ custody = _b[_a];
3547
3611
  custodyAccountMetas.push({
3548
3612
  pubkey: custody.custodyAccount,
3549
3613
  isSigner: false,
@@ -3555,8 +3619,8 @@ var PerpetualsClient = (function () {
3555
3619
  isWritable: false,
3556
3620
  });
3557
3621
  }
3558
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
3559
- market = _c[_b];
3622
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
3623
+ market = _d[_c];
3560
3624
  markets.push({
3561
3625
  pubkey: market.marketAccount,
3562
3626
  isSigner: false,
@@ -3565,21 +3629,21 @@ var PerpetualsClient = (function () {
3565
3629
  }
3566
3630
  return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
3567
3631
  case 2:
3568
- if (!(_f.sent())) {
3632
+ if (!(_g.sent())) {
3569
3633
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
3570
3634
  }
3571
3635
  if (!(payTokenSymbol == 'SOL')) return [3, 5];
3572
3636
  console.log("payTokenSymbol === SOL", payTokenSymbol);
3573
3637
  lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
3574
3638
  if (!!skipBalanceChecks) return [3, 4];
3575
- _d = anchor_1.BN.bind;
3639
+ _e = anchor_1.BN.bind;
3576
3640
  return [4, this.provider.connection.getBalance(publicKey)];
3577
3641
  case 3:
3578
- unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _f.sent()]))();
3642
+ unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _g.sent()]))();
3579
3643
  if (unWrappedSolBalance.lt(lamports)) {
3580
3644
  throw "Insufficient SOL Funds";
3581
3645
  }
3582
- _f.label = 4;
3646
+ _g.label = 4;
3583
3647
  case 4:
3584
3648
  if (!ephemeralSignerPubkey) {
3585
3649
  wrappedSolAccount = new web3_js_1.Keypair();
@@ -3603,17 +3667,17 @@ var PerpetualsClient = (function () {
3603
3667
  if (!!skipBalanceChecks) return [3, 8];
3604
3668
  return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
3605
3669
  case 6:
3606
- if (!(_f.sent())) {
3670
+ if (!(_g.sent())) {
3607
3671
  throw "Insufficient Funds , token Account doesn't exist";
3608
3672
  }
3609
- _e = anchor_1.BN.bind;
3673
+ _f = anchor_1.BN.bind;
3610
3674
  return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
3611
3675
  case 7:
3612
- tokenAccountBalance = new (_e.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
3676
+ tokenAccountBalance = new (_f.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
3613
3677
  if (tokenAccountBalance.lt(tokenAmountIn)) {
3614
3678
  throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
3615
3679
  }
3616
- _f.label = 8;
3680
+ _g.label = 8;
3617
3681
  case 8: return [4, this.program.methods
3618
3682
  .addLiquidity({
3619
3683
  amountIn: tokenAmountIn,
@@ -3640,11 +3704,11 @@ var PerpetualsClient = (function () {
3640
3704
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
3641
3705
  .instruction()];
3642
3706
  case 9:
3643
- instruction = _f.sent();
3707
+ instruction = _g.sent();
3644
3708
  instructions.push(instruction);
3645
3709
  return [3, 11];
3646
3710
  case 10:
3647
- err_5 = _f.sent();
3711
+ err_5 = _g.sent();
3648
3712
  console.error("perpClient addLiquidity error:: ", err_5);
3649
3713
  throw err_5;
3650
3714
  case 11: return [2, {
@@ -3655,14 +3719,18 @@ var PerpetualsClient = (function () {
3655
3719
  });
3656
3720
  });
3657
3721
  };
3658
- this.addLiquidityAndStake = function (inputSymbol, amountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
3659
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3660
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3661
- if (userPublicKey === void 0) { userPublicKey = undefined; }
3662
- return __awaiter(_this, void 0, void 0, function () {
3663
- var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, inputToken, flpStakeAccount, poolStakedLpVault, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _c, custody, _d, _e, market, instruction;
3664
- return __generator(this, function (_f) {
3665
- switch (_f.label) {
3722
+ this.addLiquidityAndStake = function (inputSymbol_1, amountIn_1, minLpAmountOut_1, poolConfig_1) {
3723
+ var args_1 = [];
3724
+ for (var _i = 4; _i < arguments.length; _i++) {
3725
+ args_1[_i - 4] = arguments[_i];
3726
+ }
3727
+ 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) {
3728
+ var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, inputToken, flpStakeAccount, poolStakedLpVault, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, instruction;
3729
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3730
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3731
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
3732
+ return __generator(this, function (_g) {
3733
+ switch (_g.label) {
3666
3734
  case 0:
3667
3735
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
3668
3736
  preInstructions = [];
@@ -3683,14 +3751,14 @@ var PerpetualsClient = (function () {
3683
3751
  _a = anchor_1.BN.bind;
3684
3752
  return [4, this.provider.connection.getBalance(publicKey)];
3685
3753
  case 1:
3686
- unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
3754
+ unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
3687
3755
  if (unWrappedSolBalance.lt(lamports)) {
3688
3756
  throw "Insufficient SOL Funds";
3689
3757
  }
3690
- _f.label = 2;
3758
+ _g.label = 2;
3691
3759
  case 2: return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
3692
3760
  case 3:
3693
- if (!(_f.sent())) {
3761
+ if (!(_g.sent())) {
3694
3762
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
3695
3763
  }
3696
3764
  if (!ephemeralSignerPubkey) {
@@ -3716,23 +3784,23 @@ var PerpetualsClient = (function () {
3716
3784
  if (!!skipBalanceChecks) return [3, 7];
3717
3785
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
3718
3786
  case 5:
3719
- if (!(_f.sent())) {
3787
+ if (!(_g.sent())) {
3720
3788
  throw "Insufficient Funds , token Account doesn't exist";
3721
3789
  }
3722
3790
  _b = anchor_1.BN.bind;
3723
3791
  return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
3724
3792
  case 6:
3725
- tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
3793
+ tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
3726
3794
  if (tokenAccountBalance.lt(amountIn)) {
3727
3795
  throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
3728
3796
  }
3729
- _f.label = 7;
3797
+ _g.label = 7;
3730
3798
  case 7:
3731
3799
  custodyAccountMetas = [];
3732
3800
  custodyOracleAccountMetas = [];
3733
3801
  markets = [];
3734
- for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
3735
- custody = _c[_i];
3802
+ for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
3803
+ custody = _d[_c];
3736
3804
  custodyAccountMetas.push({
3737
3805
  pubkey: custody.custodyAccount,
3738
3806
  isSigner: false,
@@ -3744,8 +3812,8 @@ var PerpetualsClient = (function () {
3744
3812
  isWritable: false,
3745
3813
  });
3746
3814
  }
3747
- for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
3748
- market = _e[_d];
3815
+ for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
3816
+ market = _f[_e];
3749
3817
  markets.push({
3750
3818
  pubkey: market.marketAccount,
3751
3819
  isSigner: false,
@@ -3779,7 +3847,7 @@ var PerpetualsClient = (function () {
3779
3847
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
3780
3848
  .instruction()];
3781
3849
  case 8:
3782
- instruction = _f.sent();
3850
+ instruction = _g.sent();
3783
3851
  instructions.push(instruction);
3784
3852
  return [2, {
3785
3853
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
@@ -3789,16 +3857,20 @@ var PerpetualsClient = (function () {
3789
3857
  });
3790
3858
  });
3791
3859
  };
3792
- this.removeLiquidity = function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey, userPublicKey) {
3793
- if (closeLpATA === void 0) { closeLpATA = false; }
3794
- if (createUserATA === void 0) { createUserATA = true; }
3795
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
3796
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3797
- if (userPublicKey === void 0) { userPublicKey = undefined; }
3798
- return __awaiter(_this, void 0, void 0, function () {
3799
- var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, recieveToken, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, _d, removeLiquidityTx, closeInx, closeWsolATAIns, err_6;
3800
- return __generator(this, function (_e) {
3801
- switch (_e.label) {
3860
+ this.removeLiquidity = function (recieveTokenSymbol_1, liquidityAmountIn_1, minTokenAmountOut_1, poolConfig_1) {
3861
+ var args_1 = [];
3862
+ for (var _i = 4; _i < arguments.length; _i++) {
3863
+ args_1[_i - 4] = arguments[_i];
3864
+ }
3865
+ 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) {
3866
+ var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, recieveToken, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, _e, removeLiquidityTx, closeInx, closeWsolATAIns, err_6;
3867
+ if (closeLpATA === void 0) { closeLpATA = false; }
3868
+ if (createUserATA === void 0) { createUserATA = true; }
3869
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
3870
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3871
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
3872
+ return __generator(this, function (_f) {
3873
+ switch (_f.label) {
3802
3874
  case 0:
3803
3875
  recieveTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey); });
3804
3876
  if (!recieveTokenCustodyConfig) {
@@ -3810,15 +3882,15 @@ var PerpetualsClient = (function () {
3810
3882
  postInstructions = [];
3811
3883
  additionalSigners = [];
3812
3884
  recieveToken = poolConfig.getTokenFromSymbol(recieveTokenSymbol);
3813
- _e.label = 1;
3885
+ _f.label = 1;
3814
3886
  case 1:
3815
- _e.trys.push([1, 7, , 8]);
3887
+ _f.trys.push([1, 7, , 8]);
3816
3888
  stakedLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
3817
3889
  custodyAccountMetas = [];
3818
3890
  custodyOracleAccountMetas = [];
3819
3891
  markets = [];
3820
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
3821
- custody = _a[_i];
3892
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
3893
+ custody = _b[_a];
3822
3894
  custodyAccountMetas.push({
3823
3895
  pubkey: custody.custodyAccount,
3824
3896
  isSigner: false,
@@ -3830,8 +3902,8 @@ var PerpetualsClient = (function () {
3830
3902
  isWritable: false,
3831
3903
  });
3832
3904
  }
3833
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
3834
- market = _c[_b];
3905
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
3906
+ market = _d[_c];
3835
3907
  markets.push({
3836
3908
  pubkey: market.marketAccount,
3837
3909
  isSigner: false,
@@ -3860,17 +3932,17 @@ var PerpetualsClient = (function () {
3860
3932
  return [3, 5];
3861
3933
  case 2:
3862
3934
  userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(recieveToken.mintKey, publicKey, true, recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
3863
- _d = createUserATA;
3864
- if (!_d) return [3, 4];
3935
+ _e = createUserATA;
3936
+ if (!_e) return [3, 4];
3865
3937
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
3866
3938
  case 3:
3867
- _d = !(_e.sent());
3868
- _e.label = 4;
3939
+ _e = !(_f.sent());
3940
+ _f.label = 4;
3869
3941
  case 4:
3870
- if (_d) {
3942
+ if (_e) {
3871
3943
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, recieveToken.mintKey, recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
3872
3944
  }
3873
- _e.label = 5;
3945
+ _f.label = 5;
3874
3946
  case 5: return [4, this.program.methods
3875
3947
  .removeLiquidity({
3876
3948
  lpAmountIn: liquidityAmountIn,
@@ -3897,7 +3969,7 @@ var PerpetualsClient = (function () {
3897
3969
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
3898
3970
  .instruction()];
3899
3971
  case 6:
3900
- removeLiquidityTx = _e.sent();
3972
+ removeLiquidityTx = _f.sent();
3901
3973
  instructions.push(removeLiquidityTx);
3902
3974
  if (closeLpATA) {
3903
3975
  closeInx = (0, spl_token_1.createCloseAccountInstruction)(stakedLpTokenAccount, publicKey, publicKey);
@@ -3909,7 +3981,7 @@ var PerpetualsClient = (function () {
3909
3981
  }
3910
3982
  return [3, 8];
3911
3983
  case 7:
3912
- err_6 = _e.sent();
3984
+ err_6 = _f.sent();
3913
3985
  console.log("perpClient removeLiquidity error:: ", err_6);
3914
3986
  throw err_6;
3915
3987
  case 8: return [2, {
@@ -4177,22 +4249,26 @@ var PerpetualsClient = (function () {
4177
4249
  }
4178
4250
  });
4179
4251
  }); };
4180
- this.refreshStakeWithTokenStake = function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
4181
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4182
- return __awaiter(_this, void 0, void 0, function () {
4183
- var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_12;
4184
- return __generator(this, function (_b) {
4185
- switch (_b.label) {
4252
+ this.refreshStakeWithTokenStake = function (rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1) {
4253
+ var args_1 = [];
4254
+ for (var _i = 3; _i < arguments.length; _i++) {
4255
+ args_1[_i - 3] = arguments[_i];
4256
+ }
4257
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
4258
+ var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_12;
4259
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4260
+ return __generator(this, function (_c) {
4261
+ switch (_c.label) {
4186
4262
  case 0:
4187
- _b.trys.push([0, 2, , 3]);
4263
+ _c.trys.push([0, 2, , 3]);
4188
4264
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
4189
4265
  rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
4190
4266
  rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
4191
4267
  pool = poolConfig.poolAddress;
4192
4268
  feeDistributionTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("custody_token_account"), pool.toBuffer(), rewardCustodyMint.toBuffer()], this.programId)[0];
4193
4269
  custodyAccountMetas = [];
4194
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
4195
- custody = _a[_i];
4270
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
4271
+ custody = _b[_a];
4196
4272
  custodyAccountMetas.push({
4197
4273
  pubkey: custody.custodyAccount,
4198
4274
  isSigner: false,
@@ -4224,10 +4300,10 @@ var PerpetualsClient = (function () {
4224
4300
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
4225
4301
  .instruction()];
4226
4302
  case 1:
4227
- refreshStakeInstruction = _b.sent();
4303
+ refreshStakeInstruction = _c.sent();
4228
4304
  return [2, refreshStakeInstruction];
4229
4305
  case 2:
4230
- err_12 = _b.sent();
4306
+ err_12 = _c.sent();
4231
4307
  console.log("perpClient refreshStaking error:: ", err_12);
4232
4308
  throw err_12;
4233
4309
  case 3: return [2];
@@ -4235,10 +4311,14 @@ var PerpetualsClient = (function () {
4235
4311
  });
4236
4312
  });
4237
4313
  };
4238
- this.unstakeInstant = function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
4239
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4240
- return __awaiter(_this, void 0, void 0, function () {
4314
+ this.unstakeInstant = function (rewardSymbol_1, unstakeAmount_1, poolConfig_1) {
4315
+ var args_1 = [];
4316
+ for (var _i = 3; _i < arguments.length; _i++) {
4317
+ args_1[_i - 3] = arguments[_i];
4318
+ }
4319
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
4241
4320
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_13;
4321
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4242
4322
  return __generator(this, function (_b) {
4243
4323
  switch (_b.label) {
4244
4324
  case 0:
@@ -4397,13 +4477,17 @@ var PerpetualsClient = (function () {
4397
4477
  }
4398
4478
  });
4399
4479
  }); };
4400
- this.withdrawStake = function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
4401
- if (pendingActivation === void 0) { pendingActivation = true; }
4402
- if (deactivated === void 0) { deactivated = true; }
4403
- if (createUserLPTA === void 0) { createUserLPTA = true; }
4404
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4405
- return __awaiter(_this, void 0, void 0, function () {
4480
+ this.withdrawStake = function (poolConfig_1) {
4481
+ var args_1 = [];
4482
+ for (var _i = 1; _i < arguments.length; _i++) {
4483
+ args_1[_i - 1] = arguments[_i];
4484
+ }
4485
+ return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
4406
4486
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_16;
4487
+ if (pendingActivation === void 0) { pendingActivation = true; }
4488
+ if (deactivated === void 0) { deactivated = true; }
4489
+ if (createUserLPTA === void 0) { createUserLPTA = true; }
4490
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4407
4491
  return __generator(this, function (_b) {
4408
4492
  switch (_b.label) {
4409
4493
  case 0:
@@ -4465,10 +4549,14 @@ var PerpetualsClient = (function () {
4465
4549
  });
4466
4550
  });
4467
4551
  };
4468
- this.collectStakeFees = function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
4469
- if (createUserATA === void 0) { createUserATA = true; }
4470
- return __awaiter(_this, void 0, void 0, function () {
4552
+ this.collectStakeFees = function (rewardSymbol_1, poolConfig_1, tokenStakeAccount_1) {
4553
+ var args_1 = [];
4554
+ for (var _i = 3; _i < arguments.length; _i++) {
4555
+ args_1[_i - 3] = arguments[_i];
4556
+ }
4557
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
4471
4558
  var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_17;
4559
+ if (createUserATA === void 0) { createUserATA = true; }
4472
4560
  return __generator(this, function (_b) {
4473
4561
  switch (_b.label) {
4474
4562
  case 0:
@@ -4538,14 +4626,18 @@ var PerpetualsClient = (function () {
4538
4626
  });
4539
4627
  });
4540
4628
  };
4541
- this.addCompoundingLiquidity = function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
4542
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4543
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4544
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4545
- return __awaiter(_this, void 0, void 0, function () {
4546
- 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_18;
4547
- return __generator(this, function (_e) {
4548
- switch (_e.label) {
4629
+ this.addCompoundingLiquidity = function (amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
4630
+ var args_1 = [];
4631
+ for (var _i = 5; _i < arguments.length; _i++) {
4632
+ args_1[_i - 5] = arguments[_i];
4633
+ }
4634
+ 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) {
4635
+ 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_18;
4636
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4637
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4638
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4639
+ return __generator(this, function (_f) {
4640
+ switch (_f.label) {
4549
4641
  case 0:
4550
4642
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
4551
4643
  preInstructions = [];
@@ -4562,8 +4654,8 @@ var PerpetualsClient = (function () {
4562
4654
  custodyAccountMetas = [];
4563
4655
  custodyOracleAccountMetas = [];
4564
4656
  markets = [];
4565
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
4566
- custody = _a[_i];
4657
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
4658
+ custody = _b[_a];
4567
4659
  custodyAccountMetas.push({
4568
4660
  pubkey: custody.custodyAccount,
4569
4661
  isSigner: false,
@@ -4575,8 +4667,8 @@ var PerpetualsClient = (function () {
4575
4667
  isWritable: false,
4576
4668
  });
4577
4669
  }
4578
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
4579
- market = _c[_b];
4670
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
4671
+ market = _d[_c];
4580
4672
  markets.push({
4581
4673
  pubkey: market.marketAccount,
4582
4674
  isSigner: false,
@@ -4585,26 +4677,26 @@ var PerpetualsClient = (function () {
4585
4677
  }
4586
4678
  return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
4587
4679
  case 1:
4588
- if (!(_e.sent())) {
4680
+ if (!(_f.sent())) {
4589
4681
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
4590
4682
  }
4591
4683
  return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
4592
4684
  case 2:
4593
- if (!(_e.sent())) {
4685
+ if (!(_f.sent())) {
4594
4686
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
4595
4687
  }
4596
4688
  if (!(inTokenSymbol == 'SOL')) return [3, 5];
4597
4689
  console.log("inTokenSymbol === SOL", inTokenSymbol);
4598
4690
  lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
4599
4691
  if (!!skipBalanceChecks) return [3, 4];
4600
- _d = anchor_1.BN.bind;
4692
+ _e = anchor_1.BN.bind;
4601
4693
  return [4, this.provider.connection.getBalance(publicKey)];
4602
4694
  case 3:
4603
- unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _e.sent()]))();
4695
+ unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _f.sent()]))();
4604
4696
  if (unWrappedSolBalance.lt(lamports)) {
4605
4697
  throw "Insufficient SOL Funds";
4606
4698
  }
4607
- _e.label = 4;
4699
+ _f.label = 4;
4608
4700
  case 4:
4609
4701
  if (!ephemeralSignerPubkey) {
4610
4702
  wrappedSolAccount = new web3_js_1.Keypair();
@@ -4628,12 +4720,12 @@ var PerpetualsClient = (function () {
4628
4720
  if (!!skipBalanceChecks) return [3, 7];
4629
4721
  return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
4630
4722
  case 6:
4631
- if (!(_e.sent())) {
4723
+ if (!(_f.sent())) {
4632
4724
  throw "Insufficient Funds , token Account doesn't exist";
4633
4725
  }
4634
- _e.label = 7;
4726
+ _f.label = 7;
4635
4727
  case 7:
4636
- _e.trys.push([7, 9, , 10]);
4728
+ _f.trys.push([7, 9, , 10]);
4637
4729
  return [4, this.program.methods
4638
4730
  .addCompoundingLiquidity({
4639
4731
  amountIn: amountIn,
@@ -4662,11 +4754,11 @@ var PerpetualsClient = (function () {
4662
4754
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4663
4755
  .instruction()];
4664
4756
  case 8:
4665
- addCompoundingLiquidity = _e.sent();
4757
+ addCompoundingLiquidity = _f.sent();
4666
4758
  instructions.push(addCompoundingLiquidity);
4667
4759
  return [3, 10];
4668
4760
  case 9:
4669
- err_18 = _e.sent();
4761
+ err_18 = _f.sent();
4670
4762
  console.log("perpClient addCompoundingLiquidity error:: ", err_18);
4671
4763
  return [3, 10];
4672
4764
  case 10: return [2, {
@@ -4677,14 +4769,18 @@ var PerpetualsClient = (function () {
4677
4769
  });
4678
4770
  });
4679
4771
  };
4680
- this.removeCompoundingLiquidity = function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey, userPublicKey) {
4681
- if (createUserATA === void 0) { createUserATA = true; }
4682
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4683
- if (userPublicKey === void 0) { userPublicKey = undefined; }
4684
- return __awaiter(_this, void 0, void 0, function () {
4685
- 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_19;
4686
- return __generator(this, function (_e) {
4687
- switch (_e.label) {
4772
+ this.removeCompoundingLiquidity = function (compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
4773
+ var args_1 = [];
4774
+ for (var _i = 5; _i < arguments.length; _i++) {
4775
+ args_1[_i - 5] = arguments[_i];
4776
+ }
4777
+ 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) {
4778
+ 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_19;
4779
+ if (createUserATA === void 0) { createUserATA = true; }
4780
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4781
+ if (userPublicKey === void 0) { userPublicKey = undefined; }
4782
+ return __generator(this, function (_f) {
4783
+ switch (_f.label) {
4688
4784
  case 0:
4689
4785
  publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
4690
4786
  preInstructions = [];
@@ -4721,19 +4817,19 @@ var PerpetualsClient = (function () {
4721
4817
  if (!_a) return [3, 3];
4722
4818
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
4723
4819
  case 2:
4724
- _a = !(_e.sent());
4725
- _e.label = 3;
4820
+ _a = !(_f.sent());
4821
+ _f.label = 3;
4726
4822
  case 3:
4727
4823
  if (_a) {
4728
4824
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
4729
4825
  }
4730
- _e.label = 4;
4826
+ _f.label = 4;
4731
4827
  case 4:
4732
4828
  custodyAccountMetas = [];
4733
4829
  custodyOracleAccountMetas = [];
4734
4830
  markets = [];
4735
- for (_i = 0, _b = poolConfig.custodies; _i < _b.length; _i++) {
4736
- custody = _b[_i];
4831
+ for (_b = 0, _c = poolConfig.custodies; _b < _c.length; _b++) {
4832
+ custody = _c[_b];
4737
4833
  custodyAccountMetas.push({
4738
4834
  pubkey: custody.custodyAccount,
4739
4835
  isSigner: false,
@@ -4745,8 +4841,8 @@ var PerpetualsClient = (function () {
4745
4841
  isWritable: false,
4746
4842
  });
4747
4843
  }
4748
- for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
4749
- market = _d[_c];
4844
+ for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
4845
+ market = _e[_d];
4750
4846
  markets.push({
4751
4847
  pubkey: market.marketAccount,
4752
4848
  isSigner: false,
@@ -4754,9 +4850,9 @@ var PerpetualsClient = (function () {
4754
4850
  });
4755
4851
  }
4756
4852
  compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
4757
- _e.label = 5;
4853
+ _f.label = 5;
4758
4854
  case 5:
4759
- _e.trys.push([5, 7, , 8]);
4855
+ _f.trys.push([5, 7, , 8]);
4760
4856
  return [4, this.program.methods
4761
4857
  .removeCompoundingLiquidity({
4762
4858
  compoundingAmountIn: compoundingAmountIn,
@@ -4785,11 +4881,11 @@ var PerpetualsClient = (function () {
4785
4881
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4786
4882
  .instruction()];
4787
4883
  case 6:
4788
- removeCompoundingLiquidity = _e.sent();
4884
+ removeCompoundingLiquidity = _f.sent();
4789
4885
  instructions.push(removeCompoundingLiquidity);
4790
4886
  return [3, 8];
4791
4887
  case 7:
4792
- err_19 = _e.sent();
4888
+ err_19 = _f.sent();
4793
4889
  console.log("perpClient removeCompoundingLiquidity error:: ", err_19);
4794
4890
  return [3, 8];
4795
4891
  case 8: return [2, {
@@ -4800,12 +4896,16 @@ var PerpetualsClient = (function () {
4800
4896
  });
4801
4897
  });
4802
4898
  };
4803
- this.migrateStake = function (amount, rewardTokenMint, poolConfig, createUserATA) {
4804
- if (createUserATA === void 0) { createUserATA = true; }
4805
- return __awaiter(_this, void 0, void 0, function () {
4806
- 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_20;
4807
- return __generator(this, function (_f) {
4808
- switch (_f.label) {
4899
+ this.migrateStake = function (amount_1, rewardTokenMint_1, poolConfig_1) {
4900
+ var args_1 = [];
4901
+ for (var _i = 3; _i < arguments.length; _i++) {
4902
+ args_1[_i - 3] = arguments[_i];
4903
+ }
4904
+ return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
4905
+ 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_20;
4906
+ if (createUserATA === void 0) { createUserATA = true; }
4907
+ return __generator(this, function (_g) {
4908
+ switch (_g.label) {
4809
4909
  case 0:
4810
4910
  publicKey = this.provider.wallet.publicKey;
4811
4911
  preInstructions = [];
@@ -4820,8 +4920,8 @@ var PerpetualsClient = (function () {
4820
4920
  if (!_a) return [3, 2];
4821
4921
  return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
4822
4922
  case 1:
4823
- _a = !(_f.sent());
4824
- _f.label = 2;
4923
+ _a = !(_g.sent());
4924
+ _g.label = 2;
4825
4925
  case 2:
4826
4926
  if (_a) {
4827
4927
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
@@ -4833,8 +4933,8 @@ var PerpetualsClient = (function () {
4833
4933
  if (!_b) return [3, 4];
4834
4934
  return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
4835
4935
  case 3:
4836
- _b = (_f.sent());
4837
- _f.label = 4;
4936
+ _b = (_g.sent());
4937
+ _g.label = 4;
4838
4938
  case 4:
4839
4939
  if (_b) {
4840
4940
  tokenStakeAccounts.push({
@@ -4847,8 +4947,8 @@ var PerpetualsClient = (function () {
4847
4947
  custodyAccountMetas = [];
4848
4948
  custodyOracleAccountMetas = [];
4849
4949
  markets = [];
4850
- for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
4851
- custody = _c[_i];
4950
+ for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
4951
+ custody = _d[_c];
4852
4952
  custodyAccountMetas.push({
4853
4953
  pubkey: custody.custodyAccount,
4854
4954
  isSigner: false,
@@ -4860,17 +4960,17 @@ var PerpetualsClient = (function () {
4860
4960
  isWritable: false,
4861
4961
  });
4862
4962
  }
4863
- for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
4864
- market = _e[_d];
4963
+ for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
4964
+ market = _f[_e];
4865
4965
  markets.push({
4866
4966
  pubkey: market.marketAccount,
4867
4967
  isSigner: false,
4868
4968
  isWritable: false,
4869
4969
  });
4870
4970
  }
4871
- _f.label = 5;
4971
+ _g.label = 5;
4872
4972
  case 5:
4873
- _f.trys.push([5, 7, , 8]);
4973
+ _g.trys.push([5, 7, , 8]);
4874
4974
  return [4, this.program.methods
4875
4975
  .migrateStake({
4876
4976
  amount: amount
@@ -4896,11 +4996,11 @@ var PerpetualsClient = (function () {
4896
4996
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
4897
4997
  .instruction()];
4898
4998
  case 6:
4899
- migrateStake = _f.sent();
4999
+ migrateStake = _g.sent();
4900
5000
  instructions.push(migrateStake);
4901
5001
  return [3, 8];
4902
5002
  case 7:
4903
- err_20 = _f.sent();
5003
+ err_20 = _g.sent();
4904
5004
  console.log("perpClient migrateStake error:: ", err_20);
4905
5005
  return [3, 8];
4906
5006
  case 8: return [2, {
@@ -4994,12 +5094,16 @@ var PerpetualsClient = (function () {
4994
5094
  }
4995
5095
  });
4996
5096
  }); };
4997
- this.compoundingFee = function (poolConfig, rewardTokenSymbol) {
4998
- if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
4999
- return __awaiter(_this, void 0, void 0, function () {
5000
- var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, compoundingFee, err_22;
5001
- return __generator(this, function (_d) {
5002
- switch (_d.label) {
5097
+ this.compoundingFee = function (poolConfig_1) {
5098
+ var args_1 = [];
5099
+ for (var _i = 1; _i < arguments.length; _i++) {
5100
+ args_1[_i - 1] = arguments[_i];
5101
+ }
5102
+ return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
5103
+ var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_22;
5104
+ if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
5105
+ return __generator(this, function (_e) {
5106
+ switch (_e.label) {
5003
5107
  case 0:
5004
5108
  instructions = [];
5005
5109
  additionalSigners = [];
@@ -5008,8 +5112,8 @@ var PerpetualsClient = (function () {
5008
5112
  custodyAccountMetas = [];
5009
5113
  custodyOracleAccountMetas = [];
5010
5114
  markets = [];
5011
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
5012
- custody = _a[_i];
5115
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
5116
+ custody = _b[_a];
5013
5117
  custodyAccountMetas.push({
5014
5118
  pubkey: custody.custodyAccount,
5015
5119
  isSigner: false,
@@ -5021,17 +5125,17 @@ var PerpetualsClient = (function () {
5021
5125
  isWritable: false,
5022
5126
  });
5023
5127
  }
5024
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
5025
- market = _c[_b];
5128
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
5129
+ market = _d[_c];
5026
5130
  markets.push({
5027
5131
  pubkey: market.marketAccount,
5028
5132
  isSigner: false,
5029
5133
  isWritable: false,
5030
5134
  });
5031
5135
  }
5032
- _d.label = 1;
5136
+ _e.label = 1;
5033
5137
  case 1:
5034
- _d.trys.push([1, 3, , 4]);
5138
+ _e.trys.push([1, 3, , 4]);
5035
5139
  return [4, this.program.methods
5036
5140
  .compoundFees({})
5037
5141
  .accounts({
@@ -5050,11 +5154,11 @@ var PerpetualsClient = (function () {
5050
5154
  .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
5051
5155
  .instruction()];
5052
5156
  case 2:
5053
- compoundingFee = _d.sent();
5157
+ compoundingFee = _e.sent();
5054
5158
  instructions.push(compoundingFee);
5055
5159
  return [3, 4];
5056
5160
  case 3:
5057
- err_22 = _d.sent();
5161
+ err_22 = _e.sent();
5058
5162
  console.log("perpClient compoundingFee error:: ", err_22);
5059
5163
  return [3, 4];
5060
5164
  case 4: return [2, {
@@ -5436,10 +5540,14 @@ var PerpetualsClient = (function () {
5436
5540
  }
5437
5541
  });
5438
5542
  }); };
5439
- this.collectTokenReward = function (owner, poolConfig, createUserATA) {
5440
- if (createUserATA === void 0) { createUserATA = true; }
5441
- return __awaiter(_this, void 0, void 0, function () {
5543
+ this.collectTokenReward = function (owner_1, poolConfig_1) {
5544
+ var args_1 = [];
5545
+ for (var _i = 2; _i < arguments.length; _i++) {
5546
+ args_1[_i - 2] = arguments[_i];
5547
+ }
5548
+ return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
5442
5549
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_30;
5550
+ if (createUserATA === void 0) { createUserATA = true; }
5443
5551
  return __generator(this, function (_b) {
5444
5552
  switch (_b.label) {
5445
5553
  case 0:
@@ -5494,10 +5602,14 @@ var PerpetualsClient = (function () {
5494
5602
  });
5495
5603
  });
5496
5604
  };
5497
- this.collectRevenue = function (owner, rewardSymbol, poolConfig, createUserATA) {
5498
- if (createUserATA === void 0) { createUserATA = true; }
5499
- return __awaiter(_this, void 0, void 0, function () {
5605
+ this.collectRevenue = function (owner_1, rewardSymbol_1, poolConfig_1) {
5606
+ var args_1 = [];
5607
+ for (var _i = 3; _i < arguments.length; _i++) {
5608
+ args_1[_i - 3] = arguments[_i];
5609
+ }
5610
+ return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
5500
5611
  var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_31;
5612
+ if (createUserATA === void 0) { createUserATA = true; }
5501
5613
  return __generator(this, function (_b) {
5502
5614
  switch (_b.label) {
5503
5615
  case 0:
@@ -5643,10 +5755,14 @@ var PerpetualsClient = (function () {
5643
5755
  }
5644
5756
  });
5645
5757
  }); };
5646
- this.collectNftReward = function (rewardSymbol, poolConfig, nftMint, createUserATA) {
5647
- if (createUserATA === void 0) { createUserATA = true; }
5648
- return __awaiter(_this, void 0, void 0, function () {
5758
+ this.collectNftReward = function (rewardSymbol_1, poolConfig_1, nftMint_1) {
5759
+ var args_1 = [];
5760
+ for (var _i = 3; _i < arguments.length; _i++) {
5761
+ args_1[_i - 3] = arguments[_i];
5762
+ }
5763
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
5649
5764
  var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_34;
5765
+ if (createUserATA === void 0) { createUserATA = true; }
5650
5766
  return __generator(this, function (_b) {
5651
5767
  switch (_b.label) {
5652
5768
  case 0:
@@ -5707,10 +5823,14 @@ var PerpetualsClient = (function () {
5707
5823
  });
5708
5824
  });
5709
5825
  };
5710
- this.collectAndDistributeFee = function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
5711
- if (createUserATA === void 0) { createUserATA = true; }
5712
- return __awaiter(_this, void 0, void 0, function () {
5826
+ this.collectAndDistributeFee = function (rewardSymbol_1, poolConfig_1) {
5827
+ var args_1 = [];
5828
+ for (var _i = 2; _i < arguments.length; _i++) {
5829
+ args_1[_i - 2] = arguments[_i];
5830
+ }
5831
+ return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
5713
5832
  var publicKey, rewardToken, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_35;
5833
+ if (createUserATA === void 0) { createUserATA = true; }
5714
5834
  return __generator(this, function (_b) {
5715
5835
  switch (_b.label) {
5716
5836
  case 0:
@@ -5836,12 +5956,16 @@ var PerpetualsClient = (function () {
5836
5956
  }
5837
5957
  });
5838
5958
  }); };
5839
- this.forceClosePosition = function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
5840
- if (createUserATA === void 0) { createUserATA = true; }
5841
- if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
5842
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5843
- return __awaiter(_this, void 0, void 0, function () {
5959
+ this.forceClosePosition = function (positionAccount_2, targetSymbol_1, collateralSymbol_1, side_1, isStopLoss_1, poolConfig_1) {
5960
+ var args_1 = [];
5961
+ for (var _i = 6; _i < arguments.length; _i++) {
5962
+ args_1[_i - 6] = arguments[_i];
5963
+ }
5964
+ 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) {
5844
5965
  var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_37;
5966
+ if (createUserATA === void 0) { createUserATA = true; }
5967
+ if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
5968
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5845
5969
  return __generator(this, function (_b) {
5846
5970
  switch (_b.label) {
5847
5971
  case 0:
@@ -5912,11 +6036,15 @@ var PerpetualsClient = (function () {
5912
6036
  });
5913
6037
  });
5914
6038
  };
5915
- this.placeLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
5916
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
5917
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5918
- return __awaiter(_this, void 0, void 0, function () {
6039
+ 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) {
6040
+ var args_1 = [];
6041
+ for (var _i = 11; _i < arguments.length; _i++) {
6042
+ args_1[_i - 11] = arguments[_i];
6043
+ }
6044
+ 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) {
5919
6045
  var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_38;
6046
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
6047
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
5920
6048
  return __generator(this, function (_c) {
5921
6049
  switch (_c.label) {
5922
6050
  case 0:
@@ -6031,11 +6159,15 @@ var PerpetualsClient = (function () {
6031
6159
  });
6032
6160
  });
6033
6161
  };
6034
- this.editLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
6035
- if (createUserATA === void 0) { createUserATA = true; }
6036
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6037
- return __awaiter(_this, void 0, void 0, function () {
6162
+ 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) {
6163
+ var args_1 = [];
6164
+ for (var _i = 11; _i < arguments.length; _i++) {
6165
+ args_1[_i - 11] = arguments[_i];
6166
+ }
6167
+ 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) {
6038
6168
  var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_39;
6169
+ if (createUserATA === void 0) { createUserATA = true; }
6170
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6039
6171
  return __generator(this, function (_b) {
6040
6172
  switch (_b.label) {
6041
6173
  case 0:
@@ -6134,12 +6266,16 @@ var PerpetualsClient = (function () {
6134
6266
  });
6135
6267
  });
6136
6268
  };
6137
- this.executeLimitOrder = function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6138
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6139
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6140
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6141
- return __awaiter(_this, void 0, void 0, function () {
6269
+ this.executeLimitOrder = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
6270
+ var args_1 = [];
6271
+ for (var _i = 7; _i < arguments.length; _i++) {
6272
+ args_1[_i - 7] = arguments[_i];
6273
+ }
6274
+ 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) {
6142
6275
  var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_40;
6276
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6277
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6278
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6143
6279
  return __generator(this, function (_a) {
6144
6280
  switch (_a.label) {
6145
6281
  case 0:
@@ -6199,12 +6335,16 @@ var PerpetualsClient = (function () {
6199
6335
  });
6200
6336
  });
6201
6337
  };
6202
- this.executeLimitWithSwap = function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6203
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6204
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6205
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6206
- return __awaiter(_this, void 0, void 0, function () {
6338
+ this.executeLimitWithSwap = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
6339
+ var args_1 = [];
6340
+ for (var _i = 8; _i < arguments.length; _i++) {
6341
+ args_1[_i - 8] = arguments[_i];
6342
+ }
6343
+ 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) {
6207
6344
  var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_41;
6345
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6346
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6347
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6208
6348
  return __generator(this, function (_a) {
6209
6349
  switch (_a.label) {
6210
6350
  case 0:
@@ -6470,16 +6610,20 @@ var PerpetualsClient = (function () {
6470
6610
  }
6471
6611
  });
6472
6612
  }); };
6473
- this.executeTriggerWithSwap = function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6474
- if (createUserATA === void 0) { createUserATA = true; }
6475
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6476
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6477
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6478
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6479
- return __awaiter(_this, void 0, void 0, function () {
6480
- var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, collateralToken, receivingToken, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, executeTriggerWithSwap, err_46;
6481
- return __generator(this, function (_d) {
6482
- switch (_d.label) {
6613
+ this.executeTriggerWithSwap = function (owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
6614
+ var args_1 = [];
6615
+ for (var _i = 9; _i < arguments.length; _i++) {
6616
+ args_1[_i - 9] = arguments[_i];
6617
+ }
6618
+ 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) {
6619
+ var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, collateralToken, receivingToken, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap, err_46;
6620
+ if (createUserATA === void 0) { createUserATA = true; }
6621
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6622
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6623
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6624
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6625
+ return __generator(this, function (_e) {
6626
+ switch (_e.label) {
6483
6627
  case 0:
6484
6628
  payerPubkey = this.provider.wallet.publicKey;
6485
6629
  targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
@@ -6492,9 +6636,9 @@ var PerpetualsClient = (function () {
6492
6636
  additionalSigners = [];
6493
6637
  collateralToken = poolConfig.getTokenFromSymbol(collateralSymbol);
6494
6638
  receivingToken = poolConfig.getTokenFromSymbol(receivingSymbol);
6495
- _d.label = 1;
6639
+ _e.label = 1;
6496
6640
  case 1:
6497
- _d.trys.push([1, 9, , 10]);
6641
+ _e.trys.push([1, 9, , 10]);
6498
6642
  if (!false) return [3, 2];
6499
6643
  return [3, 7];
6500
6644
  case 2:
@@ -6503,8 +6647,8 @@ var PerpetualsClient = (function () {
6503
6647
  if (!_a) return [3, 4];
6504
6648
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
6505
6649
  case 3:
6506
- _a = !(_d.sent());
6507
- _d.label = 4;
6650
+ _a = !(_e.sent());
6651
+ _e.label = 4;
6508
6652
  case 4:
6509
6653
  if (_a) {
6510
6654
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
@@ -6514,20 +6658,20 @@ var PerpetualsClient = (function () {
6514
6658
  if (!_b) return [3, 6];
6515
6659
  return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
6516
6660
  case 5:
6517
- _b = !(_d.sent());
6518
- _d.label = 6;
6661
+ _b = !(_e.sent());
6662
+ _e.label = 6;
6519
6663
  case 6:
6520
6664
  if (_b) {
6521
6665
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
6522
6666
  }
6523
- _d.label = 7;
6667
+ _e.label = 7;
6524
6668
  case 7:
6525
6669
  positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
6526
6670
  orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
6527
6671
  custodyAccountMetas = [];
6528
6672
  custodyOracleAccountMetas = [];
6529
- for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
6530
- custody = _c[_i];
6673
+ for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
6674
+ custody = _d[_c];
6531
6675
  custodyAccountMetas.push({
6532
6676
  pubkey: custody.custodyAccount,
6533
6677
  isSigner: false,
@@ -6575,11 +6719,11 @@ var PerpetualsClient = (function () {
6575
6719
  .remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
6576
6720
  .instruction()];
6577
6721
  case 8:
6578
- executeTriggerWithSwap = _d.sent();
6722
+ executeTriggerWithSwap = _e.sent();
6579
6723
  instructions.push(executeTriggerWithSwap);
6580
6724
  return [3, 10];
6581
6725
  case 9:
6582
- err_46 = _d.sent();
6726
+ err_46 = _e.sent();
6583
6727
  console.log("perpClient executeTriggerWithSwap error:: ", err_46);
6584
6728
  throw err_46;
6585
6729
  case 10: return [2, {
@@ -6590,14 +6734,18 @@ var PerpetualsClient = (function () {
6590
6734
  });
6591
6735
  });
6592
6736
  };
6593
- this.executeTriggerOrder = function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
6594
- if (createUserATA === void 0) { createUserATA = true; }
6595
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6596
- if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6597
- if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6598
- if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6599
- return __awaiter(_this, void 0, void 0, function () {
6737
+ this.executeTriggerOrder = function (owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
6738
+ var args_1 = [];
6739
+ for (var _i = 8; _i < arguments.length; _i++) {
6740
+ args_1[_i - 8] = arguments[_i];
6741
+ }
6742
+ 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) {
6600
6743
  var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_47;
6744
+ if (createUserATA === void 0) { createUserATA = true; }
6745
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6746
+ if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
6747
+ if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
6748
+ if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
6601
6749
  return __generator(this, function (_b) {
6602
6750
  switch (_b.label) {
6603
6751
  case 0:
@@ -6716,16 +6864,20 @@ var PerpetualsClient = (function () {
6716
6864
  }
6717
6865
  });
6718
6866
  }); };
6719
- this.swap = function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey) {
6720
- if (useFeesPool === void 0) { useFeesPool = false; }
6721
- if (createUserATA === void 0) { createUserATA = true; }
6722
- if (unWrapSol === void 0) { unWrapSol = false; }
6723
- if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
6724
- if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6725
- return __awaiter(_this, void 0, void 0, function () {
6726
- 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_49;
6727
- return __generator(this, function (_f) {
6728
- switch (_f.label) {
6867
+ this.swap = function (userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1) {
6868
+ var args_1 = [];
6869
+ for (var _i = 5; _i < arguments.length; _i++) {
6870
+ args_1[_i - 5] = arguments[_i];
6871
+ }
6872
+ 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) {
6873
+ 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_49;
6874
+ if (useFeesPool === void 0) { useFeesPool = false; }
6875
+ if (createUserATA === void 0) { createUserATA = true; }
6876
+ if (unWrapSol === void 0) { unWrapSol = false; }
6877
+ if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
6878
+ if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6879
+ return __generator(this, function (_g) {
6880
+ switch (_g.label) {
6729
6881
  case 0:
6730
6882
  userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
6731
6883
  if (!userInputCustodyConfig) {
@@ -6743,10 +6895,10 @@ var PerpetualsClient = (function () {
6743
6895
  if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
6744
6896
  return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
6745
6897
  case 1:
6746
- wsolAssociatedTokenAccount = _f.sent();
6898
+ wsolAssociatedTokenAccount = _g.sent();
6747
6899
  return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
6748
6900
  case 2:
6749
- wsolATAExist = _f.sent();
6901
+ wsolATAExist = _g.sent();
6750
6902
  if (!wsolATAExist) {
6751
6903
  instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
6752
6904
  }
@@ -6754,11 +6906,11 @@ var PerpetualsClient = (function () {
6754
6906
  _a = anchor_1.BN.bind;
6755
6907
  return [4, this.provider.connection.getBalance(publicKey)];
6756
6908
  case 3:
6757
- unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
6909
+ unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
6758
6910
  if (unWrappedSolBalance.lt(amountIn)) {
6759
6911
  throw "Insufficient SOL Funds";
6760
6912
  }
6761
- _f.label = 4;
6913
+ _g.label = 4;
6762
6914
  case 4:
6763
6915
  instructions.push(web3_js_1.SystemProgram.transfer({
6764
6916
  fromPubkey: publicKey,
@@ -6780,20 +6932,20 @@ var PerpetualsClient = (function () {
6780
6932
  additionalSigners: additionalSigners
6781
6933
  }];
6782
6934
  }
6783
- _f.label = 6;
6935
+ _g.label = 6;
6784
6936
  case 6:
6785
- _f.trys.push([6, 19, , 20]);
6937
+ _g.trys.push([6, 19, , 20]);
6786
6938
  if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
6787
6939
  console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
6788
6940
  return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
6789
6941
  case 7:
6790
- accCreationLamports = (_f.sent());
6942
+ accCreationLamports = (_g.sent());
6791
6943
  console.log("accCreationLamports:", accCreationLamports);
6792
6944
  lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
6793
6945
  _b = anchor_1.BN.bind;
6794
6946
  return [4, this.provider.connection.getBalance(publicKey)];
6795
6947
  case 8:
6796
- unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _f.sent()]))();
6948
+ unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _g.sent()]))();
6797
6949
  if (unWrappedSolBalance.lt(amountIn)) {
6798
6950
  throw "Insufficient SOL Funds";
6799
6951
  }
@@ -6820,18 +6972,18 @@ var PerpetualsClient = (function () {
6820
6972
  userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
6821
6973
  return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
6822
6974
  case 10:
6823
- if (!(_f.sent())) {
6975
+ if (!(_g.sent())) {
6824
6976
  throw "Insufficient Funds , Token Account doesn't exist";
6825
6977
  }
6826
6978
  if (!!skipBalanceChecks) return [3, 12];
6827
6979
  _c = anchor_1.BN.bind;
6828
6980
  return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
6829
6981
  case 11:
6830
- tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
6982
+ tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
6831
6983
  if (tokenAccountBalance.lt(amountIn)) {
6832
6984
  throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
6833
6985
  }
6834
- _f.label = 12;
6986
+ _g.label = 12;
6835
6987
  case 12:
6836
6988
  if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
6837
6989
  lamports = (this.minimumBalanceForRentExemptAccountLamports);
@@ -6856,23 +7008,23 @@ var PerpetualsClient = (function () {
6856
7008
  return [3, 17];
6857
7009
  case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
6858
7010
  case 14:
6859
- userOutputTokenAccount = _f.sent();
7011
+ userOutputTokenAccount = _g.sent();
6860
7012
  _d = createUserATA;
6861
7013
  if (!_d) return [3, 16];
6862
7014
  return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
6863
7015
  case 15:
6864
- _d = !(_f.sent());
6865
- _f.label = 16;
7016
+ _d = !(_g.sent());
7017
+ _g.label = 16;
6866
7018
  case 16:
6867
7019
  if (_d) {
6868
7020
  preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
6869
7021
  }
6870
- _f.label = 17;
7022
+ _g.label = 17;
6871
7023
  case 17:
6872
7024
  custodyAccountMetas = [];
6873
7025
  custodyOracleAccountMetas = [];
6874
- for (_i = 0, _e = poolConfig.custodies; _i < _e.length; _i++) {
6875
- custody = _e[_i];
7026
+ for (_e = 0, _f = poolConfig.custodies; _e < _f.length; _e++) {
7027
+ custody = _f[_e];
6876
7028
  custodyAccountMetas.push({
6877
7029
  pubkey: custody.custodyAccount,
6878
7030
  isSigner: false,
@@ -6915,7 +7067,7 @@ var PerpetualsClient = (function () {
6915
7067
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
6916
7068
  .instruction()];
6917
7069
  case 18:
6918
- inx = _f.sent();
7070
+ inx = _g.sent();
6919
7071
  instructions.push(inx);
6920
7072
  if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
6921
7073
  closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
@@ -6923,7 +7075,7 @@ var PerpetualsClient = (function () {
6923
7075
  }
6924
7076
  return [3, 20];
6925
7077
  case 19:
6926
- err_49 = _f.sent();
7078
+ err_49 = _g.sent();
6927
7079
  console.error("perpClient Swap error:: ", err_49);
6928
7080
  throw err_49;
6929
7081
  case 20: return [2, {
@@ -8233,9 +8385,9 @@ var PerpetualsClient = (function () {
8233
8385
  }
8234
8386
  }
8235
8387
  };
8236
- PerpetualsClient.prototype.sendTransaction = function (ixs, opts) {
8237
- if (opts === void 0) { opts = {}; }
8238
- return __awaiter(this, void 0, void 0, function () {
8388
+ PerpetualsClient.prototype.sendTransaction = function (ixs_1) {
8389
+ return __awaiter(this, arguments, void 0, function (ixs, opts) {
8390
+ if (opts === void 0) { opts = {}; }
8239
8391
  return __generator(this, function (_a) {
8240
8392
  switch (_a.label) {
8241
8393
  case 0: return [4, (0, rpc_1.sendTransaction)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
@@ -8244,9 +8396,9 @@ var PerpetualsClient = (function () {
8244
8396
  });
8245
8397
  });
8246
8398
  };
8247
- PerpetualsClient.prototype.sendTransactionV3 = function (ixs, opts) {
8248
- if (opts === void 0) { opts = {}; }
8249
- return __awaiter(this, void 0, void 0, function () {
8399
+ PerpetualsClient.prototype.sendTransactionV3 = function (ixs_1) {
8400
+ return __awaiter(this, arguments, void 0, function (ixs, opts) {
8401
+ if (opts === void 0) { opts = {}; }
8250
8402
  return __generator(this, function (_a) {
8251
8403
  switch (_a.label) {
8252
8404
  case 0: return [4, (0, rpc_1.sendTransactionV3)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];